Skip to content

Commit 4bba492

Browse files
Emeel Hakimdavem330
authored andcommitted
net/mlx5: Support MACsec over VLAN
MACsec device may have a VLAN device on top of it. Detect MACsec state correctly under this condition, and return the correct net device accordingly. Signed-off-by: Emeel Hakim <ehakim@nvidia.com> Reviewed-by: Subbaraya Sundeep <sbhatta@marvell.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 339ccec commit 4bba492

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

  • drivers/net/ethernet/mellanox/mlx5/core/en_accel

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

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/mlx5/device.h>
55
#include <linux/mlx5/mlx5_ifc.h>
66
#include <linux/xarray.h>
7+
#include <linux/if_vlan.h>
78

89
#include "en.h"
910
#include "lib/aso.h"
@@ -348,12 +349,21 @@ static void mlx5e_macsec_cleanup_sa(struct mlx5e_macsec *macsec,
348349
sa->macsec_rule = NULL;
349350
}
350351

352+
static struct mlx5e_priv *macsec_netdev_priv(const struct net_device *dev)
353+
{
354+
#if IS_ENABLED(CONFIG_VLAN_8021Q)
355+
if (is_vlan_dev(dev))
356+
return netdev_priv(vlan_dev_priv(dev)->real_dev);
357+
#endif
358+
return netdev_priv(dev);
359+
}
360+
351361
static int mlx5e_macsec_init_sa(struct macsec_context *ctx,
352362
struct mlx5e_macsec_sa *sa,
353363
bool encrypt,
354364
bool is_tx)
355365
{
356-
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
366+
struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
357367
struct mlx5e_macsec *macsec = priv->macsec;
358368
struct mlx5_macsec_rule_attrs rule_attrs;
359369
struct mlx5_core_dev *mdev = priv->mdev;
@@ -427,7 +437,7 @@ static int macsec_rx_sa_active_update(struct macsec_context *ctx,
427437
struct mlx5e_macsec_sa *rx_sa,
428438
bool active)
429439
{
430-
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
440+
struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
431441
struct mlx5e_macsec *macsec = priv->macsec;
432442
int err = 0;
433443

@@ -508,9 +518,9 @@ static void update_macsec_epn(struct mlx5e_macsec_sa *sa, const struct macsec_ke
508518

509519
static int mlx5e_macsec_add_txsa(struct macsec_context *ctx)
510520
{
521+
struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
511522
const struct macsec_tx_sc *tx_sc = &ctx->secy->tx_sc;
512523
const struct macsec_tx_sa *ctx_tx_sa = ctx->sa.tx_sa;
513-
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
514524
const struct macsec_secy *secy = ctx->secy;
515525
struct mlx5e_macsec_device *macsec_device;
516526
struct mlx5_core_dev *mdev = priv->mdev;
@@ -583,9 +593,9 @@ static int mlx5e_macsec_add_txsa(struct macsec_context *ctx)
583593

584594
static int mlx5e_macsec_upd_txsa(struct macsec_context *ctx)
585595
{
596+
struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
586597
const struct macsec_tx_sc *tx_sc = &ctx->secy->tx_sc;
587598
const struct macsec_tx_sa *ctx_tx_sa = ctx->sa.tx_sa;
588-
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
589599
struct mlx5e_macsec_device *macsec_device;
590600
u8 assoc_num = ctx->sa.assoc_num;
591601
struct mlx5e_macsec_sa *tx_sa;
@@ -645,7 +655,7 @@ static int mlx5e_macsec_upd_txsa(struct macsec_context *ctx)
645655

646656
static int mlx5e_macsec_del_txsa(struct macsec_context *ctx)
647657
{
648-
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
658+
struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
649659
struct mlx5e_macsec_device *macsec_device;
650660
u8 assoc_num = ctx->sa.assoc_num;
651661
struct mlx5e_macsec_sa *tx_sa;
@@ -696,7 +706,7 @@ static u32 mlx5e_macsec_get_sa_from_hashtable(struct rhashtable *sci_hash, sci_t
696706
static int mlx5e_macsec_add_rxsc(struct macsec_context *ctx)
697707
{
698708
struct mlx5e_macsec_rx_sc_xarray_element *sc_xarray_element;
699-
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
709+
struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
700710
const struct macsec_rx_sc *ctx_rx_sc = ctx->rx_sc;
701711
struct mlx5e_macsec_device *macsec_device;
702712
struct mlx5e_macsec_rx_sc *rx_sc;
@@ -776,7 +786,7 @@ static int mlx5e_macsec_add_rxsc(struct macsec_context *ctx)
776786

777787
static int mlx5e_macsec_upd_rxsc(struct macsec_context *ctx)
778788
{
779-
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
789+
struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
780790
const struct macsec_rx_sc *ctx_rx_sc = ctx->rx_sc;
781791
struct mlx5e_macsec_device *macsec_device;
782792
struct mlx5e_macsec_rx_sc *rx_sc;
@@ -854,7 +864,7 @@ static void macsec_del_rxsc_ctx(struct mlx5e_macsec *macsec, struct mlx5e_macsec
854864

855865
static int mlx5e_macsec_del_rxsc(struct macsec_context *ctx)
856866
{
857-
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
867+
struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
858868
struct mlx5e_macsec_device *macsec_device;
859869
struct mlx5e_macsec_rx_sc *rx_sc;
860870
struct mlx5e_macsec *macsec;
@@ -890,8 +900,8 @@ static int mlx5e_macsec_del_rxsc(struct macsec_context *ctx)
890900

891901
static int mlx5e_macsec_add_rxsa(struct macsec_context *ctx)
892902
{
903+
struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
893904
const struct macsec_rx_sa *ctx_rx_sa = ctx->sa.rx_sa;
894-
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
895905
struct mlx5e_macsec_device *macsec_device;
896906
struct mlx5_core_dev *mdev = priv->mdev;
897907
u8 assoc_num = ctx->sa.assoc_num;
@@ -976,8 +986,8 @@ static int mlx5e_macsec_add_rxsa(struct macsec_context *ctx)
976986

977987
static int mlx5e_macsec_upd_rxsa(struct macsec_context *ctx)
978988
{
989+
struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
979990
const struct macsec_rx_sa *ctx_rx_sa = ctx->sa.rx_sa;
980-
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
981991
struct mlx5e_macsec_device *macsec_device;
982992
u8 assoc_num = ctx->sa.assoc_num;
983993
struct mlx5e_macsec_rx_sc *rx_sc;
@@ -1033,7 +1043,7 @@ static int mlx5e_macsec_upd_rxsa(struct macsec_context *ctx)
10331043

10341044
static int mlx5e_macsec_del_rxsa(struct macsec_context *ctx)
10351045
{
1036-
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
1046+
struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
10371047
struct mlx5e_macsec_device *macsec_device;
10381048
sci_t sci = ctx->sa.rx_sa->sc->sci;
10391049
struct mlx5e_macsec_rx_sc *rx_sc;
@@ -1085,7 +1095,7 @@ static int mlx5e_macsec_del_rxsa(struct macsec_context *ctx)
10851095

10861096
static int mlx5e_macsec_add_secy(struct macsec_context *ctx)
10871097
{
1088-
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
1098+
struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
10891099
const struct net_device *dev = ctx->secy->netdev;
10901100
const struct net_device *netdev = ctx->netdev;
10911101
struct mlx5e_macsec_device *macsec_device;
@@ -1137,7 +1147,7 @@ static int mlx5e_macsec_add_secy(struct macsec_context *ctx)
11371147
static int macsec_upd_secy_hw_address(struct macsec_context *ctx,
11381148
struct mlx5e_macsec_device *macsec_device)
11391149
{
1140-
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
1150+
struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
11411151
const struct net_device *dev = ctx->secy->netdev;
11421152
struct mlx5e_macsec *macsec = priv->macsec;
11431153
struct mlx5e_macsec_rx_sc *rx_sc, *tmp;
@@ -1184,8 +1194,8 @@ static int macsec_upd_secy_hw_address(struct macsec_context *ctx,
11841194
*/
11851195
static int mlx5e_macsec_upd_secy(struct macsec_context *ctx)
11861196
{
1197+
struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
11871198
const struct macsec_tx_sc *tx_sc = &ctx->secy->tx_sc;
1188-
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
11891199
const struct net_device *dev = ctx->secy->netdev;
11901200
struct mlx5e_macsec_device *macsec_device;
11911201
struct mlx5e_macsec_sa *tx_sa;
@@ -1240,7 +1250,7 @@ static int mlx5e_macsec_upd_secy(struct macsec_context *ctx)
12401250

12411251
static int mlx5e_macsec_del_secy(struct macsec_context *ctx)
12421252
{
1243-
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
1253+
struct mlx5e_priv *priv = macsec_netdev_priv(ctx->netdev);
12441254
struct mlx5e_macsec_device *macsec_device;
12451255
struct mlx5e_macsec_rx_sc *rx_sc, *tmp;
12461256
struct mlx5e_macsec_sa *tx_sa;
@@ -1741,7 +1751,7 @@ void mlx5e_macsec_offload_handle_rx_skb(struct net_device *netdev,
17411751
{
17421752
struct mlx5e_macsec_rx_sc_xarray_element *sc_xarray_element;
17431753
u32 macsec_meta_data = be32_to_cpu(cqe->ft_metadata);
1744-
struct mlx5e_priv *priv = netdev_priv(netdev);
1754+
struct mlx5e_priv *priv = macsec_netdev_priv(netdev);
17451755
struct mlx5e_macsec_rx_sc *rx_sc;
17461756
struct mlx5e_macsec *macsec;
17471757
u32 fs_id;

0 commit comments

Comments
 (0)