Skip to content

Commit e58376e

Browse files
dsaherndavem330
authored andcommitted
mlxsw: spectrum: Add extack messages for enslave failures
mlxsw fails device enslavement for a number of reasons. Use the extack facility to return an error message to the user stating why the enslave is failing. Messages are prefixed with "spectrum" so users know it is a constraint imposed by the hardware driver. For example: $ ip li add br0.11 link br0 type vlan id 11 $ ip li set swp11 master br0 Error: spectrum: Enslaving a port to a device that already has an upper device is not supported. Signed-off-by: David Ahern <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Tested-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ca752be commit e58376e

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4019,14 +4019,21 @@ static int mlxsw_sp_lag_index_get(struct mlxsw_sp *mlxsw_sp,
40194019
static bool
40204020
mlxsw_sp_master_lag_check(struct mlxsw_sp *mlxsw_sp,
40214021
struct net_device *lag_dev,
4022-
struct netdev_lag_upper_info *lag_upper_info)
4022+
struct netdev_lag_upper_info *lag_upper_info,
4023+
struct netlink_ext_ack *extack)
40234024
{
40244025
u16 lag_id;
40254026

4026-
if (mlxsw_sp_lag_index_get(mlxsw_sp, lag_dev, &lag_id) != 0)
4027+
if (mlxsw_sp_lag_index_get(mlxsw_sp, lag_dev, &lag_id) != 0) {
4028+
NL_SET_ERR_MSG(extack,
4029+
"spectrum: Exceeded number of supported LAG devices");
40274030
return false;
4028-
if (lag_upper_info->tx_type != NETDEV_LAG_TX_TYPE_HASH)
4031+
}
4032+
if (lag_upper_info->tx_type != NETDEV_LAG_TX_TYPE_HASH) {
4033+
NL_SET_ERR_MSG(extack,
4034+
"spectrum: LAG device using unsupported Tx type");
40294035
return false;
4036+
}
40304037
return true;
40314038
}
40324039

@@ -4231,39 +4238,59 @@ static int mlxsw_sp_netdevice_port_upper_event(struct net_device *lower_dev,
42314238
{
42324239
struct netdev_notifier_changeupper_info *info;
42334240
struct mlxsw_sp_port *mlxsw_sp_port;
4241+
struct netlink_ext_ack *extack;
42344242
struct net_device *upper_dev;
42354243
struct mlxsw_sp *mlxsw_sp;
42364244
int err = 0;
42374245

42384246
mlxsw_sp_port = netdev_priv(dev);
42394247
mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
42404248
info = ptr;
4249+
extack = netdev_notifier_info_to_extack(&info->info);
42414250

42424251
switch (event) {
42434252
case NETDEV_PRECHANGEUPPER:
42444253
upper_dev = info->upper_dev;
42454254
if (!is_vlan_dev(upper_dev) &&
42464255
!netif_is_lag_master(upper_dev) &&
42474256
!netif_is_bridge_master(upper_dev) &&
4248-
!netif_is_ovs_master(upper_dev))
4257+
!netif_is_ovs_master(upper_dev)) {
4258+
NL_SET_ERR_MSG(extack,
4259+
"spectrum: Unknown upper device type");
42494260
return -EINVAL;
4261+
}
42504262
if (!info->linking)
42514263
break;
4252-
if (netdev_has_any_upper_dev(upper_dev))
4264+
if (netdev_has_any_upper_dev(upper_dev)) {
4265+
NL_SET_ERR_MSG(extack,
4266+
"spectrum: Enslaving a port to a device that already has an upper device is not supported");
42534267
return -EINVAL;
4268+
}
42544269
if (netif_is_lag_master(upper_dev) &&
42554270
!mlxsw_sp_master_lag_check(mlxsw_sp, upper_dev,
4256-
info->upper_info))
4271+
info->upper_info, extack))
42574272
return -EINVAL;
4258-
if (netif_is_lag_master(upper_dev) && vlan_uses_dev(dev))
4273+
if (netif_is_lag_master(upper_dev) && vlan_uses_dev(dev)) {
4274+
NL_SET_ERR_MSG(extack,
4275+
"spectrum: Master device is a LAG master and this device has a VLAN");
42594276
return -EINVAL;
4277+
}
42604278
if (netif_is_lag_port(dev) && is_vlan_dev(upper_dev) &&
4261-
!netif_is_lag_master(vlan_dev_real_dev(upper_dev)))
4279+
!netif_is_lag_master(vlan_dev_real_dev(upper_dev))) {
4280+
NL_SET_ERR_MSG(extack,
4281+
"spectrum: Can not put a VLAN on a LAG port");
42624282
return -EINVAL;
4263-
if (netif_is_ovs_master(upper_dev) && vlan_uses_dev(dev))
4283+
}
4284+
if (netif_is_ovs_master(upper_dev) && vlan_uses_dev(dev)) {
4285+
NL_SET_ERR_MSG(extack,
4286+
"spectrum: Master device is an OVS master and this device has a VLAN");
42644287
return -EINVAL;
4265-
if (netif_is_ovs_port(dev) && is_vlan_dev(upper_dev))
4288+
}
4289+
if (netif_is_ovs_port(dev) && is_vlan_dev(upper_dev)) {
4290+
NL_SET_ERR_MSG(extack,
4291+
"spectrum: Can not put a VLAN on an OVS port");
42664292
return -EINVAL;
4293+
}
42674294
break;
42684295
case NETDEV_CHANGEUPPER:
42694296
upper_dev = info->upper_dev;

0 commit comments

Comments
 (0)