Skip to content

Commit b7c9400

Browse files
Lior Nahmansondavem330
authored andcommitted
net/mlx5e: Implement MACsec Rx data path using MACsec skb_metadata_dst
MACsec driver need to distinguish to which offload device the MACsec is target to, in order to handle them correctly. This can be done by attaching a metadata_dst to a SKB with a SCI, when there is a match on MACsec rule. To achieve that, there is a map between fs_id to SCI, so for each RX SC, there is a unique fs_id allocated when creating RX SC. fs_id passed to device driver as metadata for packets that passed Rx MACsec offload to aid the driver to retrieve the matching SCI. Signed-off-by: Lior Nahmanson <liorna@nvidia.com> Reviewed-by: Raed Salem <raeds@nvidia.com> Signed-off-by: Raed Salem <raeds@nvidia.com> Signed-off-by: Saeed Mahameed <saeedm@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3b20949 commit b7c9400

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
#include "en.h"
4040
#include "en/txrx.h"
4141

42-
/* Bit31: IPsec marker, Bit30-24: IPsec syndrome, Bit23-0: IPsec obj id */
42+
/* Bit31: IPsec marker, Bit30: reserved, Bit29-24: IPsec syndrome, Bit23-0: IPsec obj id */
4343
#define MLX5_IPSEC_METADATA_MARKER(metadata) (((metadata) >> 31) & 0x1)
44-
#define MLX5_IPSEC_METADATA_SYNDROM(metadata) (((metadata) >> 24) & GENMASK(6, 0))
44+
#define MLX5_IPSEC_METADATA_SYNDROM(metadata) (((metadata) >> 24) & GENMASK(5, 0))
4545
#define MLX5_IPSEC_METADATA_HANDLE(metadata) ((metadata) & GENMASK(23, 0))
4646

4747
struct mlx5e_accel_tx_ipsec_state {

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct mlx5e_macsec_rx_sc {
3939
struct mlx5e_macsec_sa *rx_sa[MACSEC_NUM_AN];
4040
struct list_head rx_sc_list_element;
4141
struct mlx5e_macsec_rx_sc_xarray_element *sc_xarray_element;
42+
struct metadata_dst *md_dst;
4243
struct rcu_head rcu_head;
4344
};
4445

@@ -455,16 +456,24 @@ static int mlx5e_macsec_add_rxsc(struct macsec_context *ctx)
455456
if (err)
456457
goto destroy_sc_xarray_elemenet;
457458

459+
rx_sc->md_dst = metadata_dst_alloc(0, METADATA_MACSEC, GFP_KERNEL);
460+
if (!rx_sc->md_dst) {
461+
err = -ENOMEM;
462+
goto erase_xa_alloc;
463+
}
464+
458465
rx_sc->sci = ctx_rx_sc->sci;
459466
rx_sc->active = ctx_rx_sc->active;
460467
list_add_rcu(&rx_sc->rx_sc_list_element, &macsec->macsec_rx_sc_list_head);
461468

462469
rx_sc->sc_xarray_element = sc_xarray_element;
463-
470+
rx_sc->md_dst->u.macsec_info.sci = rx_sc->sci;
464471
mutex_unlock(&macsec->lock);
465472

466473
return 0;
467474

475+
erase_xa_alloc:
476+
xa_erase(&macsec->sc_xarray, sc_xarray_element->fs_id);
468477
destroy_sc_xarray_elemenet:
469478
kfree(sc_xarray_element);
470479
destroy_rx_sc:
@@ -558,8 +567,15 @@ static int mlx5e_macsec_del_rxsc(struct macsec_context *ctx)
558567
rx_sc->rx_sa[i] = NULL;
559568
}
560569

570+
/*
571+
* At this point the relevant MACsec offload Rx rule already removed at
572+
* mlx5e_macsec_cleanup_sa need to wait for datapath to finish current
573+
* Rx related data propagating using xa_erase which uses rcu to sync,
574+
* once fs_id is erased then this rx_sc is hidden from datapath.
575+
*/
561576
list_del_rcu(&rx_sc->rx_sc_list_element);
562577
xa_erase(&macsec->sc_xarray, rx_sc->sc_xarray_element->fs_id);
578+
metadata_dst_free(rx_sc->md_dst);
563579
kfree(rx_sc->sc_xarray_element);
564580

565581
kfree_rcu(rx_sc);
@@ -821,6 +837,34 @@ void mlx5e_macsec_tx_build_eseg(struct mlx5e_macsec *macsec,
821837
eseg->flow_table_metadata = cpu_to_be32(MLX5_ETH_WQE_FT_META_MACSEC | fs_id << 2);
822838
}
823839

840+
void mlx5e_macsec_offload_handle_rx_skb(struct net_device *netdev,
841+
struct sk_buff *skb,
842+
struct mlx5_cqe64 *cqe)
843+
{
844+
struct mlx5e_macsec_rx_sc_xarray_element *sc_xarray_element;
845+
u32 macsec_meta_data = be32_to_cpu(cqe->ft_metadata);
846+
struct mlx5e_priv *priv = netdev_priv(netdev);
847+
struct mlx5e_macsec_rx_sc *rx_sc;
848+
struct mlx5e_macsec *macsec;
849+
u32 fs_id;
850+
851+
macsec = priv->macsec;
852+
if (!macsec)
853+
return;
854+
855+
fs_id = MLX5_MACSEC_METADATA_HANDLE(macsec_meta_data);
856+
857+
rcu_read_lock();
858+
sc_xarray_element = xa_load(&macsec->sc_xarray, fs_id);
859+
rx_sc = sc_xarray_element->rx_sc;
860+
if (rx_sc) {
861+
dst_hold(&rx_sc->md_dst->dst);
862+
skb_dst_set(skb, &rx_sc->md_dst->dst);
863+
}
864+
865+
rcu_read_unlock();
866+
}
867+
824868
void mlx5e_macsec_build_netdev(struct mlx5e_priv *priv)
825869
{
826870
struct net_device *netdev = priv->netdev;

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#include <net/macsec.h>
1111
#include <net/dst_metadata.h>
1212

13+
/* Bit31 - 30: MACsec marker, Bit3-0: MACsec id */
14+
#define MLX5_MACSEC_METADATA_MARKER(metadata) ((((metadata) >> 30) & 0x3) == 0x1)
15+
#define MLX5_MACSEC_METADATA_HANDLE(metadata) ((metadata) & GENMASK(3, 0))
16+
1317
struct mlx5e_priv;
1418
struct mlx5e_macsec;
1519

@@ -28,12 +32,25 @@ static inline bool mlx5e_macsec_skb_is_offload(struct sk_buff *skb)
2832
return md_dst && (md_dst->type == METADATA_MACSEC);
2933
}
3034

35+
static inline bool mlx5e_macsec_is_rx_flow(struct mlx5_cqe64 *cqe)
36+
{
37+
return MLX5_MACSEC_METADATA_MARKER(be32_to_cpu(cqe->ft_metadata));
38+
}
39+
40+
void mlx5e_macsec_offload_handle_rx_skb(struct net_device *netdev, struct sk_buff *skb,
41+
struct mlx5_cqe64 *cqe);
42+
3143
#else
3244

3345
static inline void mlx5e_macsec_build_netdev(struct mlx5e_priv *priv) {}
3446
static inline int mlx5e_macsec_init(struct mlx5e_priv *priv) { return 0; }
3547
static inline void mlx5e_macsec_cleanup(struct mlx5e_priv *priv) {}
3648
static inline bool mlx5e_macsec_skb_is_offload(struct sk_buff *skb) { return false; }
49+
static inline bool mlx5e_macsec_is_rx_flow(struct mlx5_cqe64 *cqe) { return false; }
50+
static inline void mlx5e_macsec_offload_handle_rx_skb(struct net_device *netdev,
51+
struct sk_buff *skb,
52+
struct mlx5_cqe64 *cqe)
53+
{}
3754

3855
#endif /* CONFIG_MLX5_EN_MACSEC */
3956

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "en/rep/tc.h"
5050
#include "ipoib/ipoib.h"
5151
#include "en_accel/ipsec.h"
52+
#include "en_accel/macsec.h"
5253
#include "en_accel/ipsec_rxtx.h"
5354
#include "en_accel/ktls_txrx.h"
5455
#include "en/xdp.h"
@@ -1421,6 +1422,9 @@ static inline void mlx5e_build_rx_skb(struct mlx5_cqe64 *cqe,
14211422
if (unlikely(mlx5_ipsec_is_rx_flow(cqe)))
14221423
mlx5e_ipsec_offload_handle_rx_skb(netdev, skb, cqe);
14231424

1425+
if (unlikely(mlx5e_macsec_is_rx_flow(cqe)))
1426+
mlx5e_macsec_offload_handle_rx_skb(netdev, skb, cqe);
1427+
14241428
if (lro_num_seg > 1) {
14251429
mlx5e_lro_update_hdr(skb, cqe, cqe_bcnt);
14261430
skb_shinfo(skb)->gso_size = DIV_ROUND_UP(cqe_bcnt, lro_num_seg);

0 commit comments

Comments
 (0)