Skip to content

Commit 4b89251

Browse files
Huy NguyenSaeed Mahameed
authored andcommitted
net/mlx5: Support ndo bridge_setlink and getlink
Allow enabling VEPA mode on the HCA's port in legacy devlink mode. Example: bridge link set dev ens1f0 hwmode vepa will turn on VEPA mode on the netdev ens1f0. Signed-off-by: Huy Nguyen <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 8da202b commit 4b89251

File tree

1 file changed

+59
-0
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+59
-0
lines changed

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/mlx5/fs.h>
3636
#include <net/vxlan.h>
3737
#include <linux/bpf.h>
38+
#include <linux/if_bridge.h>
3839
#include <net/page_pool.h>
3940
#include "eswitch.h"
4041
#include "en.h"
@@ -4305,6 +4306,61 @@ static int mlx5e_xdp(struct net_device *dev, struct netdev_bpf *xdp)
43054306
}
43064307
}
43074308

4309+
#ifdef CONFIG_MLX5_ESWITCH
4310+
static int mlx5e_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
4311+
struct net_device *dev, u32 filter_mask,
4312+
int nlflags)
4313+
{
4314+
struct mlx5e_priv *priv = netdev_priv(dev);
4315+
struct mlx5_core_dev *mdev = priv->mdev;
4316+
u8 mode, setting;
4317+
int err;
4318+
4319+
err = mlx5_eswitch_get_vepa(mdev->priv.eswitch, &setting);
4320+
if (err)
4321+
return err;
4322+
mode = setting ? BRIDGE_MODE_VEPA : BRIDGE_MODE_VEB;
4323+
return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
4324+
mode,
4325+
0, 0, nlflags, filter_mask, NULL);
4326+
}
4327+
4328+
static int mlx5e_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
4329+
u16 flags, struct netlink_ext_ack *extack)
4330+
{
4331+
struct mlx5e_priv *priv = netdev_priv(dev);
4332+
struct mlx5_core_dev *mdev = priv->mdev;
4333+
struct nlattr *attr, *br_spec;
4334+
u16 mode = BRIDGE_MODE_UNDEF;
4335+
u8 setting;
4336+
int rem;
4337+
4338+
br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
4339+
if (!br_spec)
4340+
return -EINVAL;
4341+
4342+
nla_for_each_nested(attr, br_spec, rem) {
4343+
if (nla_type(attr) != IFLA_BRIDGE_MODE)
4344+
continue;
4345+
4346+
if (nla_len(attr) < sizeof(mode))
4347+
return -EINVAL;
4348+
4349+
mode = nla_get_u16(attr);
4350+
if (mode > BRIDGE_MODE_VEPA)
4351+
return -EINVAL;
4352+
4353+
break;
4354+
}
4355+
4356+
if (mode == BRIDGE_MODE_UNDEF)
4357+
return -EINVAL;
4358+
4359+
setting = (mode == BRIDGE_MODE_VEPA) ? 1 : 0;
4360+
return mlx5_eswitch_set_vepa(mdev->priv.eswitch, setting);
4361+
}
4362+
#endif
4363+
43084364
const struct net_device_ops mlx5e_netdev_ops = {
43094365
.ndo_open = mlx5e_open,
43104366
.ndo_stop = mlx5e_close,
@@ -4331,6 +4387,9 @@ const struct net_device_ops mlx5e_netdev_ops = {
43314387
.ndo_rx_flow_steer = mlx5e_rx_flow_steer,
43324388
#endif
43334389
#ifdef CONFIG_MLX5_ESWITCH
4390+
.ndo_bridge_setlink = mlx5e_bridge_setlink,
4391+
.ndo_bridge_getlink = mlx5e_bridge_getlink,
4392+
43344393
/* SRIOV E-Switch NDOs */
43354394
.ndo_set_vf_mac = mlx5e_set_vf_mac,
43364395
.ndo_set_vf_vlan = mlx5e_set_vf_vlan,

0 commit comments

Comments
 (0)