mirror of https://gitee.com/openkylin/linux.git
net/mlx5: LAG, Use port enumerators
Instead of using explicit array indexes, simply use
ports enumerators to make the code more readable.
Fixes: 7907f23adc
("net/mlx5: Implement RoCE LAG feature")
Signed-off-by: Erez Alfasi <ereza@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
This commit is contained in:
parent
5a212e0cac
commit
84d2dbb0aa
|
@ -145,34 +145,35 @@ static void mlx5_infer_tx_affinity_mapping(struct lag_tracker *tracker,
|
||||||
{
|
{
|
||||||
*port1 = 1;
|
*port1 = 1;
|
||||||
*port2 = 2;
|
*port2 = 2;
|
||||||
if (!tracker->netdev_state[0].tx_enabled ||
|
if (!tracker->netdev_state[MLX5_LAG_P1].tx_enabled ||
|
||||||
!tracker->netdev_state[0].link_up) {
|
!tracker->netdev_state[MLX5_LAG_P1].link_up) {
|
||||||
*port1 = 2;
|
*port1 = 2;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tracker->netdev_state[1].tx_enabled ||
|
if (!tracker->netdev_state[MLX5_LAG_P2].tx_enabled ||
|
||||||
!tracker->netdev_state[1].link_up)
|
!tracker->netdev_state[MLX5_LAG_P2].link_up)
|
||||||
*port2 = 1;
|
*port2 = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mlx5_modify_lag(struct mlx5_lag *ldev,
|
void mlx5_modify_lag(struct mlx5_lag *ldev,
|
||||||
struct lag_tracker *tracker)
|
struct lag_tracker *tracker)
|
||||||
{
|
{
|
||||||
struct mlx5_core_dev *dev0 = ldev->pf[0].dev;
|
struct mlx5_core_dev *dev0 = ldev->pf[MLX5_LAG_P1].dev;
|
||||||
u8 v2p_port1, v2p_port2;
|
u8 v2p_port1, v2p_port2;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
mlx5_infer_tx_affinity_mapping(tracker, &v2p_port1,
|
mlx5_infer_tx_affinity_mapping(tracker, &v2p_port1,
|
||||||
&v2p_port2);
|
&v2p_port2);
|
||||||
|
|
||||||
if (v2p_port1 != ldev->v2p_map[0] ||
|
if (v2p_port1 != ldev->v2p_map[MLX5_LAG_P1] ||
|
||||||
v2p_port2 != ldev->v2p_map[1]) {
|
v2p_port2 != ldev->v2p_map[MLX5_LAG_P2]) {
|
||||||
ldev->v2p_map[0] = v2p_port1;
|
ldev->v2p_map[MLX5_LAG_P1] = v2p_port1;
|
||||||
ldev->v2p_map[1] = v2p_port2;
|
ldev->v2p_map[MLX5_LAG_P2] = v2p_port2;
|
||||||
|
|
||||||
mlx5_core_info(dev0, "modify lag map port 1:%d port 2:%d",
|
mlx5_core_info(dev0, "modify lag map port 1:%d port 2:%d",
|
||||||
ldev->v2p_map[0], ldev->v2p_map[1]);
|
ldev->v2p_map[MLX5_LAG_P1],
|
||||||
|
ldev->v2p_map[MLX5_LAG_P2]);
|
||||||
|
|
||||||
err = mlx5_cmd_modify_lag(dev0, v2p_port1, v2p_port2);
|
err = mlx5_cmd_modify_lag(dev0, v2p_port1, v2p_port2);
|
||||||
if (err)
|
if (err)
|
||||||
|
@ -185,16 +186,17 @@ void mlx5_modify_lag(struct mlx5_lag *ldev,
|
||||||
static int mlx5_create_lag(struct mlx5_lag *ldev,
|
static int mlx5_create_lag(struct mlx5_lag *ldev,
|
||||||
struct lag_tracker *tracker)
|
struct lag_tracker *tracker)
|
||||||
{
|
{
|
||||||
struct mlx5_core_dev *dev0 = ldev->pf[0].dev;
|
struct mlx5_core_dev *dev0 = ldev->pf[MLX5_LAG_P1].dev;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
mlx5_infer_tx_affinity_mapping(tracker, &ldev->v2p_map[0],
|
mlx5_infer_tx_affinity_mapping(tracker, &ldev->v2p_map[MLX5_LAG_P1],
|
||||||
&ldev->v2p_map[1]);
|
&ldev->v2p_map[MLX5_LAG_P2]);
|
||||||
|
|
||||||
mlx5_core_info(dev0, "lag map port 1:%d port 2:%d",
|
mlx5_core_info(dev0, "lag map port 1:%d port 2:%d",
|
||||||
ldev->v2p_map[0], ldev->v2p_map[1]);
|
ldev->v2p_map[MLX5_LAG_P1], ldev->v2p_map[MLX5_LAG_P2]);
|
||||||
|
|
||||||
err = mlx5_cmd_create_lag(dev0, ldev->v2p_map[0], ldev->v2p_map[1]);
|
err = mlx5_cmd_create_lag(dev0, ldev->v2p_map[MLX5_LAG_P1],
|
||||||
|
ldev->v2p_map[MLX5_LAG_P2]);
|
||||||
if (err)
|
if (err)
|
||||||
mlx5_core_err(dev0,
|
mlx5_core_err(dev0,
|
||||||
"Failed to create LAG (%d)\n",
|
"Failed to create LAG (%d)\n",
|
||||||
|
@ -207,7 +209,7 @@ int mlx5_activate_lag(struct mlx5_lag *ldev,
|
||||||
u8 flags)
|
u8 flags)
|
||||||
{
|
{
|
||||||
bool roce_lag = !!(flags & MLX5_LAG_FLAG_ROCE);
|
bool roce_lag = !!(flags & MLX5_LAG_FLAG_ROCE);
|
||||||
struct mlx5_core_dev *dev0 = ldev->pf[0].dev;
|
struct mlx5_core_dev *dev0 = ldev->pf[MLX5_LAG_P1].dev;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = mlx5_create_lag(ldev, tracker);
|
err = mlx5_create_lag(ldev, tracker);
|
||||||
|
@ -229,7 +231,7 @@ int mlx5_activate_lag(struct mlx5_lag *ldev,
|
||||||
|
|
||||||
static int mlx5_deactivate_lag(struct mlx5_lag *ldev)
|
static int mlx5_deactivate_lag(struct mlx5_lag *ldev)
|
||||||
{
|
{
|
||||||
struct mlx5_core_dev *dev0 = ldev->pf[0].dev;
|
struct mlx5_core_dev *dev0 = ldev->pf[MLX5_LAG_P1].dev;
|
||||||
bool roce_lag = __mlx5_lag_is_roce(ldev);
|
bool roce_lag = __mlx5_lag_is_roce(ldev);
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -252,14 +254,15 @@ static int mlx5_deactivate_lag(struct mlx5_lag *ldev)
|
||||||
|
|
||||||
static bool mlx5_lag_check_prereq(struct mlx5_lag *ldev)
|
static bool mlx5_lag_check_prereq(struct mlx5_lag *ldev)
|
||||||
{
|
{
|
||||||
if (!ldev->pf[0].dev || !ldev->pf[1].dev)
|
if (!ldev->pf[MLX5_LAG_P1].dev || !ldev->pf[MLX5_LAG_P2].dev)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#ifdef CONFIG_MLX5_ESWITCH
|
#ifdef CONFIG_MLX5_ESWITCH
|
||||||
return mlx5_esw_lag_prereq(ldev->pf[0].dev, ldev->pf[1].dev);
|
return mlx5_esw_lag_prereq(ldev->pf[MLX5_LAG_P1].dev,
|
||||||
|
ldev->pf[MLX5_LAG_P2].dev);
|
||||||
#else
|
#else
|
||||||
return (!mlx5_sriov_is_enabled(ldev->pf[0].dev) &&
|
return (!mlx5_sriov_is_enabled(ldev->pf[MLX5_LAG_P1].dev) &&
|
||||||
!mlx5_sriov_is_enabled(ldev->pf[1].dev));
|
!mlx5_sriov_is_enabled(ldev->pf[MLX5_LAG_P2].dev));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,8 +288,8 @@ static void mlx5_lag_remove_ib_devices(struct mlx5_lag *ldev)
|
||||||
|
|
||||||
static void mlx5_do_bond(struct mlx5_lag *ldev)
|
static void mlx5_do_bond(struct mlx5_lag *ldev)
|
||||||
{
|
{
|
||||||
struct mlx5_core_dev *dev0 = ldev->pf[0].dev;
|
struct mlx5_core_dev *dev0 = ldev->pf[MLX5_LAG_P1].dev;
|
||||||
struct mlx5_core_dev *dev1 = ldev->pf[1].dev;
|
struct mlx5_core_dev *dev1 = ldev->pf[MLX5_LAG_P2].dev;
|
||||||
struct lag_tracker tracker;
|
struct lag_tracker tracker;
|
||||||
bool do_bond, roce_lag;
|
bool do_bond, roce_lag;
|
||||||
int err;
|
int err;
|
||||||
|
@ -692,10 +695,11 @@ struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev)
|
||||||
goto unlock;
|
goto unlock;
|
||||||
|
|
||||||
if (ldev->tracker.tx_type == NETDEV_LAG_TX_TYPE_ACTIVEBACKUP) {
|
if (ldev->tracker.tx_type == NETDEV_LAG_TX_TYPE_ACTIVEBACKUP) {
|
||||||
ndev = ldev->tracker.netdev_state[0].tx_enabled ?
|
ndev = ldev->tracker.netdev_state[MLX5_LAG_P1].tx_enabled ?
|
||||||
ldev->pf[0].netdev : ldev->pf[1].netdev;
|
ldev->pf[MLX5_LAG_P1].netdev :
|
||||||
|
ldev->pf[MLX5_LAG_P2].netdev;
|
||||||
} else {
|
} else {
|
||||||
ndev = ldev->pf[0].netdev;
|
ndev = ldev->pf[MLX5_LAG_P1].netdev;
|
||||||
}
|
}
|
||||||
if (ndev)
|
if (ndev)
|
||||||
dev_hold(ndev);
|
dev_hold(ndev);
|
||||||
|
@ -717,7 +721,8 @@ bool mlx5_lag_intf_add(struct mlx5_interface *intf, struct mlx5_priv *priv)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
ldev = mlx5_lag_dev_get(dev);
|
ldev = mlx5_lag_dev_get(dev);
|
||||||
if (!ldev || !__mlx5_lag_is_roce(ldev) || ldev->pf[0].dev == dev)
|
if (!ldev || !__mlx5_lag_is_roce(ldev) ||
|
||||||
|
ldev->pf[MLX5_LAG_P1].dev == dev)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
/* If bonded, we do not add an IB device for PF1. */
|
/* If bonded, we do not add an IB device for PF1. */
|
||||||
|
@ -746,11 +751,11 @@ int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,
|
||||||
ldev = mlx5_lag_dev_get(dev);
|
ldev = mlx5_lag_dev_get(dev);
|
||||||
if (ldev && __mlx5_lag_is_roce(ldev)) {
|
if (ldev && __mlx5_lag_is_roce(ldev)) {
|
||||||
num_ports = MLX5_MAX_PORTS;
|
num_ports = MLX5_MAX_PORTS;
|
||||||
mdev[0] = ldev->pf[0].dev;
|
mdev[MLX5_LAG_P1] = ldev->pf[MLX5_LAG_P1].dev;
|
||||||
mdev[1] = ldev->pf[1].dev;
|
mdev[MLX5_LAG_P2] = ldev->pf[MLX5_LAG_P2].dev;
|
||||||
} else {
|
} else {
|
||||||
num_ports = 1;
|
num_ports = 1;
|
||||||
mdev[0] = dev;
|
mdev[MLX5_LAG_P1] = dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < num_ports; ++i) {
|
for (i = 0; i < num_ports; ++i) {
|
||||||
|
|
|
@ -7,6 +7,11 @@
|
||||||
#include "mlx5_core.h"
|
#include "mlx5_core.h"
|
||||||
#include "lag_mp.h"
|
#include "lag_mp.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
MLX5_LAG_P1,
|
||||||
|
MLX5_LAG_P2,
|
||||||
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
MLX5_LAG_FLAG_ROCE = 1 << 0,
|
MLX5_LAG_FLAG_ROCE = 1 << 0,
|
||||||
MLX5_LAG_FLAG_SRIOV = 1 << 1,
|
MLX5_LAG_FLAG_SRIOV = 1 << 1,
|
||||||
|
|
|
@ -11,10 +11,11 @@
|
||||||
|
|
||||||
static bool mlx5_lag_multipath_check_prereq(struct mlx5_lag *ldev)
|
static bool mlx5_lag_multipath_check_prereq(struct mlx5_lag *ldev)
|
||||||
{
|
{
|
||||||
if (!ldev->pf[0].dev || !ldev->pf[1].dev)
|
if (!ldev->pf[MLX5_LAG_P1].dev || !ldev->pf[MLX5_LAG_P2].dev)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return mlx5_esw_multipath_prereq(ldev->pf[0].dev, ldev->pf[1].dev);
|
return mlx5_esw_multipath_prereq(ldev->pf[MLX5_LAG_P1].dev,
|
||||||
|
ldev->pf[MLX5_LAG_P2].dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool __mlx5_lag_is_multipath(struct mlx5_lag *ldev)
|
static bool __mlx5_lag_is_multipath(struct mlx5_lag *ldev)
|
||||||
|
@ -52,36 +53,36 @@ static void mlx5_lag_set_port_affinity(struct mlx5_lag *ldev, int port)
|
||||||
|
|
||||||
switch (port) {
|
switch (port) {
|
||||||
case 0:
|
case 0:
|
||||||
tracker.netdev_state[0].tx_enabled = true;
|
tracker.netdev_state[MLX5_LAG_P1].tx_enabled = true;
|
||||||
tracker.netdev_state[1].tx_enabled = true;
|
tracker.netdev_state[MLX5_LAG_P2].tx_enabled = true;
|
||||||
tracker.netdev_state[0].link_up = true;
|
tracker.netdev_state[MLX5_LAG_P1].link_up = true;
|
||||||
tracker.netdev_state[1].link_up = true;
|
tracker.netdev_state[MLX5_LAG_P2].link_up = true;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
tracker.netdev_state[0].tx_enabled = true;
|
tracker.netdev_state[MLX5_LAG_P1].tx_enabled = true;
|
||||||
tracker.netdev_state[0].link_up = true;
|
tracker.netdev_state[MLX5_LAG_P1].link_up = true;
|
||||||
tracker.netdev_state[1].tx_enabled = false;
|
tracker.netdev_state[MLX5_LAG_P2].tx_enabled = false;
|
||||||
tracker.netdev_state[1].link_up = false;
|
tracker.netdev_state[MLX5_LAG_P2].link_up = false;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
tracker.netdev_state[0].tx_enabled = false;
|
tracker.netdev_state[MLX5_LAG_P1].tx_enabled = false;
|
||||||
tracker.netdev_state[0].link_up = false;
|
tracker.netdev_state[MLX5_LAG_P1].link_up = false;
|
||||||
tracker.netdev_state[1].tx_enabled = true;
|
tracker.netdev_state[MLX5_LAG_P2].tx_enabled = true;
|
||||||
tracker.netdev_state[1].link_up = true;
|
tracker.netdev_state[MLX5_LAG_P2].link_up = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
mlx5_core_warn(ldev->pf[0].dev, "Invalid affinity port %d",
|
mlx5_core_warn(ldev->pf[MLX5_LAG_P1].dev,
|
||||||
port);
|
"Invalid affinity port %d", port);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tracker.netdev_state[0].tx_enabled)
|
if (tracker.netdev_state[MLX5_LAG_P1].tx_enabled)
|
||||||
mlx5_notifier_call_chain(ldev->pf[0].dev->priv.events,
|
mlx5_notifier_call_chain(ldev->pf[MLX5_LAG_P1].dev->priv.events,
|
||||||
MLX5_DEV_EVENT_PORT_AFFINITY,
|
MLX5_DEV_EVENT_PORT_AFFINITY,
|
||||||
(void *)0);
|
(void *)0);
|
||||||
|
|
||||||
if (tracker.netdev_state[1].tx_enabled)
|
if (tracker.netdev_state[MLX5_LAG_P2].tx_enabled)
|
||||||
mlx5_notifier_call_chain(ldev->pf[1].dev->priv.events,
|
mlx5_notifier_call_chain(ldev->pf[MLX5_LAG_P2].dev->priv.events,
|
||||||
MLX5_DEV_EVENT_PORT_AFFINITY,
|
MLX5_DEV_EVENT_PORT_AFFINITY,
|
||||||
(void *)0);
|
(void *)0);
|
||||||
|
|
||||||
|
@ -141,11 +142,12 @@ static void mlx5_lag_fib_route_event(struct mlx5_lag *ldev,
|
||||||
/* Verify next hops are ports of the same hca */
|
/* Verify next hops are ports of the same hca */
|
||||||
fib_nh0 = fib_info_nh(fi, 0);
|
fib_nh0 = fib_info_nh(fi, 0);
|
||||||
fib_nh1 = fib_info_nh(fi, 1);
|
fib_nh1 = fib_info_nh(fi, 1);
|
||||||
if (!(fib_nh0->fib_nh_dev == ldev->pf[0].netdev &&
|
if (!(fib_nh0->fib_nh_dev == ldev->pf[MLX5_LAG_P1].netdev &&
|
||||||
fib_nh1->fib_nh_dev == ldev->pf[1].netdev) &&
|
fib_nh1->fib_nh_dev == ldev->pf[MLX5_LAG_P2].netdev) &&
|
||||||
!(fib_nh0->fib_nh_dev == ldev->pf[1].netdev &&
|
!(fib_nh0->fib_nh_dev == ldev->pf[MLX5_LAG_P2].netdev &&
|
||||||
fib_nh1->fib_nh_dev == ldev->pf[0].netdev)) {
|
fib_nh1->fib_nh_dev == ldev->pf[MLX5_LAG_P1].netdev)) {
|
||||||
mlx5_core_warn(ldev->pf[0].dev, "Multipath offload require two ports of the same HCA\n");
|
mlx5_core_warn(ldev->pf[MLX5_LAG_P1].dev,
|
||||||
|
"Multipath offload require two ports of the same HCA\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,8 +269,8 @@ static int mlx5_lag_fib_event(struct notifier_block *nb,
|
||||||
return notifier_from_errno(-EINVAL);
|
return notifier_from_errno(-EINVAL);
|
||||||
}
|
}
|
||||||
fib_dev = fib_info_nh(fen_info->fi, 0)->fib_nh_dev;
|
fib_dev = fib_info_nh(fen_info->fi, 0)->fib_nh_dev;
|
||||||
if (fib_dev != ldev->pf[0].netdev &&
|
if (fib_dev != ldev->pf[MLX5_LAG_P1].netdev &&
|
||||||
fib_dev != ldev->pf[1].netdev) {
|
fib_dev != ldev->pf[MLX5_LAG_P2].netdev) {
|
||||||
return NOTIFY_DONE;
|
return NOTIFY_DONE;
|
||||||
}
|
}
|
||||||
fib_work = mlx5_lag_init_fib_work(ldev, event);
|
fib_work = mlx5_lag_init_fib_work(ldev, event);
|
||||||
|
|
Loading…
Reference in New Issue