Skip to content

Commit 19e9bfa

Browse files
w1ldptrSaeed Mahameed
authored andcommitted
net/mlx5: Bridge, add offload infrastructure
Create new files bridge.{c|h} in en/rep directory that implement bridge interaction with representor netdevices and handle required events/notifications, bridge.{c|h} in esw directory that implement all necessary eswitch offloading infrastructure and works on vport/eswitch level. Provide new kconfig MLX5_BRIDGE which is automatically selected when both kernel bridge and mlx5 eswitch configs are enabled. Provide basic infrastructure for bridge offloads: - struct mlx5_esw_bridge_offloads - per-eswitch bridge offload structure that encapsulates generic bridge-offloads data (notifier blocks, ingress flow table/group, etc.) that is created/deleted on enable/disable eswitch offloads. - struct mlx5_esw_bridge - per-bridge structure that encapsulates per-bridge data (reference counter, FDB, egress flow table/group, etc.) that is created when first eswitch represetor is attached to new bridge and deleted when last representor is removed from the bridge as a result of NETDEV_CHANGEUPPER event. The bridge tables are created with new priority FDB_BR_OFFLOAD in FDB namespace. The new priority is between tc-miss and slow path priorities. Priority consist of two levels: the ingress table that is global per eswitch and matches incoming packets by src_mac/vid and redirects them to next level (egress table) that is chosen according to ingress port bridge membership and matches on dst_mac/vid in order to redirect packet to vport according to the following diagram: + | +---------v----------+ | | | FDB_TC_OFFLOAD | | | +---------+----------+ | | +---------v----------+ | | | FDB_FT_OFFLOAD | | | +---------+----------+ | | +---------v----------+ | | | FDB_TC_MISS | | | +---------+----------+ | +--------------------------------------+ | | | | +------+ | | | | | +------v--------+ FDB_BR_OFFLOAD | | | INGRESS_TABLE | | | +------+---+----+ | | | | match | | | +---------+ | | | | | +-------+ | | +-------v-------+ match | | | | | | EGRESS_TABLE +------------> vport | | | +-------+-------+ | | | | | | | +-------+ | | miss | | | +------+------+ | | | | +--------------------------------------+ | | +---------v----------+ | | | FDB_SLOW_PATH | | | +---------+----------+ | v Signed-off-by: Vlad Buslov <vladbu@nvidia.com> Reviewed-by: Jianbo Liu <jianbol@nvidia.com> Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
1 parent 0781015 commit 19e9bfa

10 files changed

Lines changed: 540 additions & 0 deletions

File tree

‎drivers/net/ethernet/mellanox/mlx5/core/Kconfig‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ config MLX5_ESWITCH
7979
Legacy SRIOV mode (L2 mac vlan steering based).
8080
Switchdev mode (eswitch offloads).
8181

82+
config MLX5_BRIDGE
83+
bool
84+
depends on MLX5_ESWITCH && BRIDGE
85+
default y
86+
help
87+
mlx5 ConnectX offloads support for Ethernet Bridging (BRIDGE).
88+
Enable adding representors of mlx5 uplink and VF ports to Bridge and
89+
offloading rules for traffic between such ports. Supports VLANs (trunk and
90+
access modes).
91+
8292
config MLX5_CLS_ACT
8393
bool "MLX5 TC classifier action support"
8494
depends on MLX5_ESWITCH && NET_CLS_ACT

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ mlx5_core-$(CONFIG_MLX5_ESWITCH) += esw/acl/helper.o \
5656
esw/acl/ingress_lgcy.o esw/acl/ingress_ofld.o \
5757
esw/devlink_port.o esw/vporttbl.o
5858
mlx5_core-$(CONFIG_MLX5_TC_SAMPLE) += esw/sample.o
59+
mlx5_core-$(CONFIG_MLX5_BRIDGE) += esw/bridge.o en/rep/bridge.o
5960

6061
mlx5_core-$(CONFIG_MLX5_MPFS) += lib/mpfs.o
6162
mlx5_core-$(CONFIG_VXLAN) += lib/vxlan.o
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2+
/* Copyright (c) 2021 Mellanox Technologies. */
3+
4+
#include <linux/netdevice.h>
5+
#include <net/netevent.h>
6+
#include <net/switchdev.h>
7+
#include "bridge.h"
8+
#include "esw/bridge.h"
9+
#include "en_rep.h"
10+
11+
static int mlx5_esw_bridge_port_changeupper(struct notifier_block *nb, void *ptr)
12+
{
13+
struct mlx5_esw_bridge_offloads *br_offloads = container_of(nb,
14+
struct mlx5_esw_bridge_offloads,
15+
netdev_nb);
16+
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
17+
struct netdev_notifier_changeupper_info *info = ptr;
18+
struct netlink_ext_ack *extack;
19+
struct mlx5e_rep_priv *rpriv;
20+
struct mlx5_eswitch *esw;
21+
struct mlx5_vport *vport;
22+
struct net_device *upper;
23+
struct mlx5e_priv *priv;
24+
u16 vport_num;
25+
26+
if (!mlx5e_eswitch_rep(dev))
27+
return 0;
28+
29+
upper = info->upper_dev;
30+
if (!netif_is_bridge_master(upper))
31+
return 0;
32+
33+
esw = br_offloads->esw;
34+
priv = netdev_priv(dev);
35+
if (esw != priv->mdev->priv.eswitch)
36+
return 0;
37+
38+
rpriv = priv->ppriv;
39+
vport_num = rpriv->rep->vport;
40+
vport = mlx5_eswitch_get_vport(esw, vport_num);
41+
if (IS_ERR(vport))
42+
return PTR_ERR(vport);
43+
44+
extack = netdev_notifier_info_to_extack(&info->info);
45+
46+
return info->linking ?
47+
mlx5_esw_bridge_vport_link(upper->ifindex, br_offloads, vport, extack) :
48+
mlx5_esw_bridge_vport_unlink(upper->ifindex, br_offloads, vport, extack);
49+
}
50+
51+
static int mlx5_esw_bridge_switchdev_port_event(struct notifier_block *nb,
52+
unsigned long event, void *ptr)
53+
{
54+
int err = 0;
55+
56+
switch (event) {
57+
case NETDEV_PRECHANGEUPPER:
58+
break;
59+
60+
case NETDEV_CHANGEUPPER:
61+
err = mlx5_esw_bridge_port_changeupper(nb, ptr);
62+
break;
63+
}
64+
65+
return notifier_from_errno(err);
66+
}
67+
68+
void mlx5e_rep_bridge_init(struct mlx5e_priv *priv)
69+
{
70+
struct mlx5_esw_bridge_offloads *br_offloads;
71+
struct mlx5_core_dev *mdev = priv->mdev;
72+
struct mlx5_eswitch *esw =
73+
mdev->priv.eswitch;
74+
int err;
75+
76+
rtnl_lock();
77+
br_offloads = mlx5_esw_bridge_init(esw);
78+
rtnl_unlock();
79+
if (IS_ERR(br_offloads)) {
80+
esw_warn(mdev, "Failed to init esw bridge (err=%ld)\n", PTR_ERR(br_offloads));
81+
return;
82+
}
83+
84+
br_offloads->netdev_nb.notifier_call = mlx5_esw_bridge_switchdev_port_event;
85+
err = register_netdevice_notifier(&br_offloads->netdev_nb);
86+
if (err) {
87+
esw_warn(mdev, "Failed to register bridge offloads netdevice notifier (err=%d)\n",
88+
err);
89+
mlx5_esw_bridge_cleanup(esw);
90+
}
91+
}
92+
93+
void mlx5e_rep_bridge_cleanup(struct mlx5e_priv *priv)
94+
{
95+
struct mlx5_esw_bridge_offloads *br_offloads;
96+
struct mlx5_core_dev *mdev = priv->mdev;
97+
struct mlx5_eswitch *esw =
98+
mdev->priv.eswitch;
99+
100+
br_offloads = esw->br_offloads;
101+
if (!br_offloads)
102+
return;
103+
104+
unregister_netdevice_notifier(&br_offloads->netdev_nb);
105+
rtnl_lock();
106+
mlx5_esw_bridge_cleanup(esw);
107+
rtnl_unlock();
108+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2+
/* Copyright (c) 2021 Mellanox Technologies. */
3+
4+
#ifndef __MLX5_EN_REP_BRIDGE__
5+
#define __MLX5_EN_REP_BRIDGE__
6+
7+
#include "en.h"
8+
9+
#if IS_ENABLED(CONFIG_MLX5_BRIDGE)
10+
11+
void mlx5e_rep_bridge_init(struct mlx5e_priv *priv);
12+
void mlx5e_rep_bridge_cleanup(struct mlx5e_priv *priv);
13+
14+
#else /* CONFIG_MLX5_BRIDGE */
15+
16+
static inline void mlx5e_rep_bridge_init(struct mlx5e_priv *priv) {}
17+
static inline void mlx5e_rep_bridge_cleanup(struct mlx5e_priv *priv) {}
18+
19+
#endif /* CONFIG_MLX5_BRIDGE */
20+
21+
#endif /* __MLX5_EN_REP_BRIDGE__ */

‎drivers/net/ethernet/mellanox/mlx5/core/en_rep.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "en_tc.h"
4646
#include "en/rep/tc.h"
4747
#include "en/rep/neigh.h"
48+
#include "en/rep/bridge.h"
4849
#include "en/devlink.h"
4950
#include "fs_core.h"
5051
#include "lib/mlx5.h"
@@ -981,6 +982,7 @@ static void mlx5e_uplink_rep_enable(struct mlx5e_priv *priv)
981982
mlx5e_dcbnl_initialize(priv);
982983
mlx5e_dcbnl_init_app(priv);
983984
mlx5e_rep_neigh_init(rpriv);
985+
mlx5e_rep_bridge_init(priv);
984986

985987
netdev->wanted_features |= NETIF_F_HW_TC;
986988

@@ -1002,6 +1004,7 @@ static void mlx5e_uplink_rep_disable(struct mlx5e_priv *priv)
10021004
netif_device_detach(priv->netdev);
10031005
rtnl_unlock();
10041006

1007+
mlx5e_rep_bridge_cleanup(priv);
10051008
mlx5e_rep_neigh_cleanup(rpriv);
10061009
mlx5e_dcbnl_delete_app(priv);
10071010
mlx5_notifier_unregister(mdev, &priv->events_nb);

0 commit comments

Comments
 (0)