mlxsw: Add extack messages for port_{un, }split failures
authorDavid Ahern <dsahern@gmail.com>
Tue, 5 Jun 2018 15:14:11 +0000 (08:14 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 5 Jun 2018 16:32:38 +0000 (12:32 -0400)
Return messages in extack for port split/unsplit errors. e.g.,
    $ devlink port split swp1s1 count 4
    Error: mlxsw_spectrum: Port cannot be split further.
    devlink answers: Invalid argument

    $ devlink port unsplit swp4
    Error: mlxsw_spectrum: Port was not split.
    devlink answers: Invalid argument

Signed-off-by: David Ahern <dsahern@gmail.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/core.c
drivers/net/ethernet/mellanox/mlxsw/core.h
drivers/net/ethernet/mellanox/mlxsw/spectrum.c

index 7ed38d80bc081e6bf4a7c137f123577a202ebd7e..f9c724752a326c782eeb3c1a4f8d1f8e250f2d68 100644 (file)
@@ -775,11 +775,14 @@ static int mlxsw_devlink_port_split(struct devlink *devlink,
 {
        struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
 
-       if (port_index >= mlxsw_core->max_ports)
+       if (port_index >= mlxsw_core->max_ports) {
+               NL_SET_ERR_MSG_MOD(extack, "Port index exceeds maximum number of ports");
                return -EINVAL;
+       }
        if (!mlxsw_core->driver->port_split)
                return -EOPNOTSUPP;
-       return mlxsw_core->driver->port_split(mlxsw_core, port_index, count);
+       return mlxsw_core->driver->port_split(mlxsw_core, port_index, count,
+                                             extack);
 }
 
 static int mlxsw_devlink_port_unsplit(struct devlink *devlink,
@@ -788,11 +791,14 @@ static int mlxsw_devlink_port_unsplit(struct devlink *devlink,
 {
        struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
 
-       if (port_index >= mlxsw_core->max_ports)
+       if (port_index >= mlxsw_core->max_ports) {
+               NL_SET_ERR_MSG_MOD(extack, "Port index exceeds maximum number of ports");
                return -EINVAL;
+       }
        if (!mlxsw_core->driver->port_unsplit)
                return -EOPNOTSUPP;
-       return mlxsw_core->driver->port_unsplit(mlxsw_core, port_index);
+       return mlxsw_core->driver->port_unsplit(mlxsw_core, port_index,
+                                               extack);
 }
 
 static int
index 4a8d4c7f89d95c0f1a69b57dc065c37a2ac46b3b..552cfa29c2f7488624abfc579192e6f3faf160cf 100644 (file)
@@ -274,8 +274,9 @@ struct mlxsw_driver {
        int (*port_type_set)(struct mlxsw_core *mlxsw_core, u8 local_port,
                             enum devlink_port_type new_type);
        int (*port_split)(struct mlxsw_core *mlxsw_core, u8 local_port,
-                         unsigned int count);
-       int (*port_unsplit)(struct mlxsw_core *mlxsw_core, u8 local_port);
+                         unsigned int count, struct netlink_ext_ack *extack);
+       int (*port_unsplit)(struct mlxsw_core *mlxsw_core, u8 local_port,
+                           struct netlink_ext_ack *extack);
        int (*sb_pool_get)(struct mlxsw_core *mlxsw_core,
                           unsigned int sb_index, u16 pool_index,
                           struct devlink_sb_pool_info *pool_info);
index fc39f22e5c70f89870224ee43003452f987e2eb1..968b88af2ef5ea93077186ff72d41d95aae60803 100644 (file)
@@ -3092,7 +3092,8 @@ static void mlxsw_sp_port_unsplit_create(struct mlxsw_sp *mlxsw_sp,
 }
 
 static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
-                              unsigned int count)
+                              unsigned int count,
+                              struct netlink_ext_ack *extack)
 {
        struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
        struct mlxsw_sp_port *mlxsw_sp_port;
@@ -3104,6 +3105,7 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
        if (!mlxsw_sp_port) {
                dev_err(mlxsw_sp->bus_info->dev, "Port number \"%d\" does not exist\n",
                        local_port);
+               NL_SET_ERR_MSG_MOD(extack, "Port number does not exist");
                return -EINVAL;
        }
 
@@ -3112,11 +3114,13 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
 
        if (count != 2 && count != 4) {
                netdev_err(mlxsw_sp_port->dev, "Port can only be split into 2 or 4 ports\n");
+               NL_SET_ERR_MSG_MOD(extack, "Port can only be split into 2 or 4 ports");
                return -EINVAL;
        }
 
        if (cur_width != MLXSW_PORT_MODULE_MAX_WIDTH) {
                netdev_err(mlxsw_sp_port->dev, "Port cannot be split further\n");
+               NL_SET_ERR_MSG_MOD(extack, "Port cannot be split further");
                return -EINVAL;
        }
 
@@ -3125,6 +3129,7 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
                base_port = local_port;
                if (mlxsw_sp->ports[base_port + 1]) {
                        netdev_err(mlxsw_sp_port->dev, "Invalid split configuration\n");
+                       NL_SET_ERR_MSG_MOD(extack, "Invalid split configuration");
                        return -EINVAL;
                }
        } else {
@@ -3132,6 +3137,7 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
                if (mlxsw_sp->ports[base_port + 1] ||
                    mlxsw_sp->ports[base_port + 3]) {
                        netdev_err(mlxsw_sp_port->dev, "Invalid split configuration\n");
+                       NL_SET_ERR_MSG_MOD(extack, "Invalid split configuration");
                        return -EINVAL;
                }
        }
@@ -3153,7 +3159,8 @@ err_port_split_create:
        return err;
 }
 
-static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u8 local_port)
+static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u8 local_port,
+                                struct netlink_ext_ack *extack)
 {
        struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
        struct mlxsw_sp_port *mlxsw_sp_port;
@@ -3165,11 +3172,13 @@ static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u8 local_port)
        if (!mlxsw_sp_port) {
                dev_err(mlxsw_sp->bus_info->dev, "Port number \"%d\" does not exist\n",
                        local_port);
+               NL_SET_ERR_MSG_MOD(extack, "Port number does not exist");
                return -EINVAL;
        }
 
        if (!mlxsw_sp_port->split) {
-               netdev_err(mlxsw_sp_port->dev, "Port wasn't split\n");
+               netdev_err(mlxsw_sp_port->dev, "Port was not split\n");
+               NL_SET_ERR_MSG_MOD(extack, "Port was not split");
                return -EINVAL;
        }