Commit abc1de25 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

mlxsw: switchx2: Check if port is usable before calling port create

Do it in a same way we do it in spectrum. Check if port is usable first
and only in that case create a port instance.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Reviewed-by: default avatarElad Raz <eladr@mellanox.com>
Reviewed-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5b090740
...@@ -256,18 +256,17 @@ mlxsw_sx_port_system_port_mapping_set(struct mlxsw_sx_port *mlxsw_sx_port) ...@@ -256,18 +256,17 @@ mlxsw_sx_port_system_port_mapping_set(struct mlxsw_sx_port *mlxsw_sx_port)
return mlxsw_reg_write(mlxsw_sx->core, MLXSW_REG(sspr), sspr_pl); return mlxsw_reg_write(mlxsw_sx->core, MLXSW_REG(sspr), sspr_pl);
} }
static int mlxsw_sx_port_module_check(struct mlxsw_sx_port *mlxsw_sx_port, static int mlxsw_sx_port_module_info_get(struct mlxsw_sx *mlxsw_sx,
bool *p_usable) u8 local_port, u8 *p_width)
{ {
struct mlxsw_sx *mlxsw_sx = mlxsw_sx_port->mlxsw_sx;
char pmlp_pl[MLXSW_REG_PMLP_LEN]; char pmlp_pl[MLXSW_REG_PMLP_LEN];
int err; int err;
mlxsw_reg_pmlp_pack(pmlp_pl, mlxsw_sx_port->local_port); mlxsw_reg_pmlp_pack(pmlp_pl, local_port);
err = mlxsw_reg_query(mlxsw_sx->core, MLXSW_REG(pmlp), pmlp_pl); err = mlxsw_reg_query(mlxsw_sx->core, MLXSW_REG(pmlp), pmlp_pl);
if (err) if (err)
return err; return err;
*p_usable = mlxsw_reg_pmlp_width_get(pmlp_pl) ? true : false; *p_width = mlxsw_reg_pmlp_width_get(pmlp_pl);
return 0; return 0;
} }
...@@ -962,7 +961,6 @@ static int mlxsw_sx_port_create(struct mlxsw_sx *mlxsw_sx, u8 local_port) ...@@ -962,7 +961,6 @@ static int mlxsw_sx_port_create(struct mlxsw_sx *mlxsw_sx, u8 local_port)
{ {
struct mlxsw_sx_port *mlxsw_sx_port; struct mlxsw_sx_port *mlxsw_sx_port;
struct net_device *dev; struct net_device *dev;
bool usable;
int err; int err;
dev = alloc_etherdev(sizeof(struct mlxsw_sx_port)); dev = alloc_etherdev(sizeof(struct mlxsw_sx_port));
...@@ -1005,19 +1003,6 @@ static int mlxsw_sx_port_create(struct mlxsw_sx *mlxsw_sx, u8 local_port) ...@@ -1005,19 +1003,6 @@ static int mlxsw_sx_port_create(struct mlxsw_sx *mlxsw_sx, u8 local_port)
*/ */
dev->needed_headroom = MLXSW_TXHDR_LEN; dev->needed_headroom = MLXSW_TXHDR_LEN;
err = mlxsw_sx_port_module_check(mlxsw_sx_port, &usable);
if (err) {
dev_err(mlxsw_sx->bus_info->dev, "Port %d: Failed to check module\n",
mlxsw_sx_port->local_port);
goto err_port_module_check;
}
if (!usable) {
dev_dbg(mlxsw_sx->bus_info->dev, "Port %d: Not usable, skipping initialization\n",
mlxsw_sx_port->local_port);
goto port_not_usable;
}
err = mlxsw_sx_port_system_port_mapping_set(mlxsw_sx_port); err = mlxsw_sx_port_system_port_mapping_set(mlxsw_sx_port);
if (err) { if (err) {
dev_err(mlxsw_sx->bus_info->dev, "Port %d: Failed to set system port mapping\n", dev_err(mlxsw_sx->bus_info->dev, "Port %d: Failed to set system port mapping\n",
...@@ -1097,8 +1082,6 @@ static int mlxsw_sx_port_create(struct mlxsw_sx *mlxsw_sx, u8 local_port) ...@@ -1097,8 +1082,6 @@ static int mlxsw_sx_port_create(struct mlxsw_sx *mlxsw_sx, u8 local_port)
mlxsw_sx_port_swid_set(mlxsw_sx_port, MLXSW_PORT_SWID_DISABLED_PORT); mlxsw_sx_port_swid_set(mlxsw_sx_port, MLXSW_PORT_SWID_DISABLED_PORT);
err_port_swid_set: err_port_swid_set:
err_port_system_port_mapping_set: err_port_system_port_mapping_set:
port_not_usable:
err_port_module_check:
err_dev_addr_get: err_dev_addr_get:
free_percpu(mlxsw_sx_port->pcpu_stats); free_percpu(mlxsw_sx_port->pcpu_stats);
err_alloc_stats: err_alloc_stats:
...@@ -1131,6 +1114,7 @@ static void mlxsw_sx_ports_remove(struct mlxsw_sx *mlxsw_sx) ...@@ -1131,6 +1114,7 @@ static void mlxsw_sx_ports_remove(struct mlxsw_sx *mlxsw_sx)
static int mlxsw_sx_ports_create(struct mlxsw_sx *mlxsw_sx) static int mlxsw_sx_ports_create(struct mlxsw_sx *mlxsw_sx)
{ {
size_t alloc_size; size_t alloc_size;
u8 width;
int i; int i;
int err; int err;
...@@ -1140,6 +1124,11 @@ static int mlxsw_sx_ports_create(struct mlxsw_sx *mlxsw_sx) ...@@ -1140,6 +1124,11 @@ static int mlxsw_sx_ports_create(struct mlxsw_sx *mlxsw_sx)
return -ENOMEM; return -ENOMEM;
for (i = 1; i < MLXSW_PORT_MAX_PORTS; i++) { for (i = 1; i < MLXSW_PORT_MAX_PORTS; i++) {
err = mlxsw_sx_port_module_info_get(mlxsw_sx, i, &width);
if (err)
goto err_port_module_info_get;
if (!width)
continue;
err = mlxsw_sx_port_create(mlxsw_sx, i); err = mlxsw_sx_port_create(mlxsw_sx, i);
if (err) if (err)
goto err_port_create; goto err_port_create;
...@@ -1147,6 +1136,7 @@ static int mlxsw_sx_ports_create(struct mlxsw_sx *mlxsw_sx) ...@@ -1147,6 +1136,7 @@ static int mlxsw_sx_ports_create(struct mlxsw_sx *mlxsw_sx)
return 0; return 0;
err_port_create: err_port_create:
err_port_module_info_get:
for (i--; i >= 1; i--) for (i--; i >= 1; i--)
mlxsw_sx_port_remove(mlxsw_sx, i); mlxsw_sx_port_remove(mlxsw_sx, i);
kfree(mlxsw_sx->ports); kfree(mlxsw_sx->ports);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment