Subject: Re: [PATCH net-next 3/3] mlxsw: Add extack messages for port_{un,}split failures

From: Jiri Pirko <[email-masked]>
Date: Tue, 5 Jun 2018 09:52:30 +0200

Tue, Jun 05, 2018 at 12:15:03AM CEST, [email-masked] wrote:
>From: David Ahern <[email-masked]>
>
>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 <[email-masked]>
>---
> drivers/net/ethernet/mellanox/mlxsw/core.c     | 14 ++++++++++----
> drivers/net/ethernet/mellanox/mlxsw/core.h     |  5 +++--
> drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 13 +++++++++++--
> 3 files changed, 24 insertions(+), 8 deletions(-)
>
>diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c
>index 7ed38d80bc08..f9c724752a32 100644
>--- a/drivers/net/ethernet/mellanox/mlxsw/core.c
>+++ b/drivers/net/ethernet/mellanox/mlxsw/core.c
>@@ -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
>diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.h b/drivers/net/ethernet/mellanox/mlxsw/core.h
>index 4a8d4c7f89d9..552cfa29c2f7 100644
>--- a/drivers/net/ethernet/mellanox/mlxsw/core.h
>+++ b/drivers/net/ethernet/mellanox/mlxsw/core.h
>@@ -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);
>diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
>index fc39f22e5c70..1b6d930e452d 100644
>--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
>+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
>@@ -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 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
> 	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");
>+		NL_SET_ERR_MSG_MOD(extack, "Port was not split");

I wonder if we need the dmesg for these as well. Plus it is not the same
(wasn't/was not) which is maybe confusing. Any objection against the
original dmesg messages removal?

> 		return -EINVAL;
> 	}
>-- 
>2.11.0