|
| 1 | +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
| 2 | +/* Copyright (c) 2020 Mellanox Technologies Inc. All rights reserved. */ |
| 3 | + |
| 4 | +#include <net/lag.h> |
| 5 | + |
| 6 | +#include "mlx5_core.h" |
| 7 | +#include "eswitch.h" |
| 8 | +#include "esw/acl/ofld.h" |
| 9 | +#include "en_rep.h" |
| 10 | + |
| 11 | +struct mlx5e_rep_bond { |
| 12 | + struct notifier_block nb; |
| 13 | + struct netdev_net_notifier nn; |
| 14 | +}; |
| 15 | + |
| 16 | +static bool mlx5e_rep_is_lag_netdev(struct net_device *netdev) |
| 17 | +{ |
| 18 | + struct mlx5e_priv *priv = netdev_priv(netdev); |
| 19 | + struct mlx5e_rep_priv *rpriv = priv->ppriv; |
| 20 | + |
| 21 | + /* A given netdev is not a representor or not a slave of LAG configuration */ |
| 22 | + if (!mlx5e_eswitch_rep(netdev) || !bond_slave_get_rtnl(netdev)) |
| 23 | + return false; |
| 24 | + |
| 25 | + /* Egress acl forward to vport is supported only non-uplink representor */ |
| 26 | + return rpriv->rep->vport != MLX5_VPORT_UPLINK; |
| 27 | +} |
| 28 | + |
| 29 | +static void mlx5e_rep_changelowerstate_event(struct net_device *netdev, void *ptr) |
| 30 | +{ |
| 31 | + struct netdev_notifier_changelowerstate_info *info; |
| 32 | + struct netdev_lag_lower_state_info *lag_info; |
| 33 | + struct mlx5e_rep_priv *rpriv; |
| 34 | + struct net_device *lag_dev; |
| 35 | + struct mlx5e_priv *priv; |
| 36 | + struct list_head *iter; |
| 37 | + struct net_device *dev; |
| 38 | + u16 acl_vport_num; |
| 39 | + u16 fwd_vport_num; |
| 40 | + |
| 41 | + if (!mlx5e_rep_is_lag_netdev(netdev)) |
| 42 | + return; |
| 43 | + |
| 44 | + info = ptr; |
| 45 | + lag_info = info->lower_state_info; |
| 46 | + /* This is not an event of a representor becoming active slave */ |
| 47 | + if (!lag_info->tx_enabled) |
| 48 | + return; |
| 49 | + |
| 50 | + priv = netdev_priv(netdev); |
| 51 | + rpriv = priv->ppriv; |
| 52 | + fwd_vport_num = rpriv->rep->vport; |
| 53 | + lag_dev = netdev_master_upper_dev_get(netdev); |
| 54 | + |
| 55 | + netdev_dbg(netdev, "lag_dev(%s)'s slave vport(%d) is txable(%d)\n", |
| 56 | + lag_dev->name, fwd_vport_num, net_lag_port_dev_txable(netdev)); |
| 57 | + |
| 58 | + /* Point everyone's egress acl to the vport of the active representor */ |
| 59 | + netdev_for_each_lower_dev(lag_dev, dev, iter) { |
| 60 | + priv = netdev_priv(dev); |
| 61 | + rpriv = priv->ppriv; |
| 62 | + acl_vport_num = rpriv->rep->vport; |
| 63 | + if (acl_vport_num != fwd_vport_num) { |
| 64 | + mlx5_esw_acl_egress_vport_bond(priv->mdev->priv.eswitch, |
| 65 | + fwd_vport_num, |
| 66 | + acl_vport_num); |
| 67 | + } |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +static void mlx5e_rep_changeupper_event(struct net_device *netdev, void *ptr) |
| 72 | +{ |
| 73 | + struct netdev_notifier_changeupper_info *info = ptr; |
| 74 | + struct mlx5e_rep_priv *rpriv; |
| 75 | + struct mlx5e_priv *priv; |
| 76 | + |
| 77 | + if (!mlx5e_rep_is_lag_netdev(netdev)) |
| 78 | + return; |
| 79 | + |
| 80 | + /* Nothing to setup for new enslaved representor */ |
| 81 | + if (info->linking) |
| 82 | + return; |
| 83 | + |
| 84 | + priv = netdev_priv(netdev); |
| 85 | + rpriv = priv->ppriv; |
| 86 | + netdev_dbg(netdev, "Unslave, reset vport(%d) egress acl\n", rpriv->rep->vport); |
| 87 | + |
| 88 | + /* Reset all egress acl rules of unslave representor's vport */ |
| 89 | + mlx5_esw_acl_egress_vport_unbond(priv->mdev->priv.eswitch, |
| 90 | + rpriv->rep->vport); |
| 91 | +} |
| 92 | + |
| 93 | +/* Bond device of representors and netdev events are used here in specific way |
| 94 | + * to support eswitch vports bonding and to perform failover of eswitch vport |
| 95 | + * by modifying the vport's egress acl of lower dev representors. Thus this |
| 96 | + * also change the traditional behavior of lower dev under bond device. |
| 97 | + * All non-representor netdevs or representors of other vendors as lower dev |
| 98 | + * of bond device are not supported. |
| 99 | + */ |
| 100 | +static int mlx5e_rep_esw_bond_netevent(struct notifier_block *nb, |
| 101 | + unsigned long event, void *ptr) |
| 102 | +{ |
| 103 | + struct net_device *netdev = netdev_notifier_info_to_dev(ptr); |
| 104 | + |
| 105 | + switch (event) { |
| 106 | + case NETDEV_CHANGELOWERSTATE: |
| 107 | + mlx5e_rep_changelowerstate_event(netdev, ptr); |
| 108 | + break; |
| 109 | + case NETDEV_CHANGEUPPER: |
| 110 | + mlx5e_rep_changeupper_event(netdev, ptr); |
| 111 | + break; |
| 112 | + } |
| 113 | + return NOTIFY_DONE; |
| 114 | +} |
| 115 | + |
| 116 | +/* If HW support eswitch vports bonding, register a specific notifier to |
| 117 | + * handle it when two or more representors are bonded |
| 118 | + */ |
| 119 | +int mlx5e_rep_bond_init(struct mlx5e_rep_priv *rpriv) |
| 120 | +{ |
| 121 | + struct mlx5_rep_uplink_priv *uplink_priv = &rpriv->uplink_priv; |
| 122 | + struct net_device *netdev = rpriv->netdev; |
| 123 | + struct mlx5e_priv *priv; |
| 124 | + int ret = 0; |
| 125 | + |
| 126 | + priv = netdev_priv(netdev); |
| 127 | + if (!mlx5_esw_acl_egress_fwd2vport_supported(priv->mdev->priv.eswitch)) |
| 128 | + goto out; |
| 129 | + |
| 130 | + uplink_priv->bond = kvzalloc(sizeof(*uplink_priv->bond), GFP_KERNEL); |
| 131 | + if (!uplink_priv->bond) { |
| 132 | + ret = -ENOMEM; |
| 133 | + goto out; |
| 134 | + } |
| 135 | + |
| 136 | + uplink_priv->bond->nb.notifier_call = mlx5e_rep_esw_bond_netevent; |
| 137 | + ret = register_netdevice_notifier_dev_net(netdev, |
| 138 | + &uplink_priv->bond->nb, |
| 139 | + &uplink_priv->bond->nn); |
| 140 | + if (ret) { |
| 141 | + netdev_err(netdev, "register bonding netevent notifier, err(%d)\n", ret); |
| 142 | + kvfree(uplink_priv->bond); |
| 143 | + uplink_priv->bond = NULL; |
| 144 | + } |
| 145 | +out: |
| 146 | + return ret; |
| 147 | +} |
| 148 | + |
| 149 | +void mlx5e_rep_bond_cleanup(struct mlx5e_rep_priv *rpriv) |
| 150 | +{ |
| 151 | + struct mlx5e_priv *priv = netdev_priv(rpriv->netdev); |
| 152 | + |
| 153 | + if (!mlx5_esw_acl_egress_fwd2vport_supported(priv->mdev->priv.eswitch) || |
| 154 | + !rpriv->uplink_priv.bond) |
| 155 | + return; |
| 156 | + |
| 157 | + unregister_netdevice_notifier_dev_net(rpriv->netdev, |
| 158 | + &rpriv->uplink_priv.bond->nb, |
| 159 | + &rpriv->uplink_priv.bond->nn); |
| 160 | + kvfree(rpriv->uplink_priv.bond); |
| 161 | +} |
0 commit comments