Merge branch 'mlxsw-fixes'

Jiri Pirko says:

====================
mlxsw: couple of fixes

Couple of fixes from Ido.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
David S. Miller 2016-06-09 11:20:05 -07:00
commit 60d6f36f5c
2 changed files with 117 additions and 91 deletions

View File

@ -247,13 +247,21 @@ static int mlxsw_sp_port_mtu_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 mtu)
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pmtu), pmtu_pl); return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pmtu), pmtu_pl);
} }
static int __mlxsw_sp_port_swid_set(struct mlxsw_sp *mlxsw_sp, u8 local_port,
u8 swid)
{
char pspa_pl[MLXSW_REG_PSPA_LEN];
mlxsw_reg_pspa_pack(pspa_pl, swid, local_port);
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pspa), pspa_pl);
}
static int mlxsw_sp_port_swid_set(struct mlxsw_sp_port *mlxsw_sp_port, u8 swid) static int mlxsw_sp_port_swid_set(struct mlxsw_sp_port *mlxsw_sp_port, u8 swid)
{ {
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
char pspa_pl[MLXSW_REG_PSPA_LEN];
mlxsw_reg_pspa_pack(pspa_pl, swid, mlxsw_sp_port->local_port); return __mlxsw_sp_port_swid_set(mlxsw_sp, mlxsw_sp_port->local_port,
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pspa), pspa_pl); swid);
} }
static int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, static int mlxsw_sp_port_vp_mode_set(struct mlxsw_sp_port *mlxsw_sp_port,
@ -305,7 +313,7 @@ mlxsw_sp_port_system_port_mapping_set(struct mlxsw_sp_port *mlxsw_sp_port)
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sspr), sspr_pl); return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sspr), sspr_pl);
} }
static int __mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp, static int mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp,
u8 local_port, u8 *p_module, u8 local_port, u8 *p_module,
u8 *p_width, u8 *p_lane) u8 *p_width, u8 *p_lane)
{ {
@ -322,16 +330,6 @@ static int __mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp,
return 0; return 0;
} }
static int mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp,
u8 local_port, u8 *p_module,
u8 *p_width)
{
u8 lane;
return __mlxsw_sp_port_module_info_get(mlxsw_sp, local_port, p_module,
p_width, &lane);
}
static int mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u8 local_port, static int mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u8 local_port,
u8 module, u8 width, u8 lane) u8 module, u8 width, u8 lane)
{ {
@ -949,17 +947,11 @@ static int mlxsw_sp_port_get_phys_port_name(struct net_device *dev, char *name,
size_t len) size_t len)
{ {
struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev); struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
u8 module, width, lane; u8 module = mlxsw_sp_port->mapping.module;
u8 width = mlxsw_sp_port->mapping.width;
u8 lane = mlxsw_sp_port->mapping.lane;
int err; int err;
err = __mlxsw_sp_port_module_info_get(mlxsw_sp_port->mlxsw_sp,
mlxsw_sp_port->local_port,
&module, &width, &lane);
if (err) {
netdev_err(dev, "Failed to retrieve module information\n");
return err;
}
if (!mlxsw_sp_port->split) if (!mlxsw_sp_port->split)
err = snprintf(name, len, "p%d", module + 1); err = snprintf(name, len, "p%d", module + 1);
else else
@ -1681,8 +1673,8 @@ static int mlxsw_sp_port_ets_init(struct mlxsw_sp_port *mlxsw_sp_port)
return 0; return 0;
} }
static int __mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port, static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,
bool split, u8 module, u8 width) bool split, u8 module, u8 width, u8 lane)
{ {
struct mlxsw_sp_port *mlxsw_sp_port; struct mlxsw_sp_port *mlxsw_sp_port;
struct net_device *dev; struct net_device *dev;
@ -1697,6 +1689,9 @@ static int __mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,
mlxsw_sp_port->mlxsw_sp = mlxsw_sp; mlxsw_sp_port->mlxsw_sp = mlxsw_sp;
mlxsw_sp_port->local_port = local_port; mlxsw_sp_port->local_port = local_port;
mlxsw_sp_port->split = split; mlxsw_sp_port->split = split;
mlxsw_sp_port->mapping.module = module;
mlxsw_sp_port->mapping.width = width;
mlxsw_sp_port->mapping.lane = lane;
bytes = DIV_ROUND_UP(VLAN_N_VID, BITS_PER_BYTE); bytes = DIV_ROUND_UP(VLAN_N_VID, BITS_PER_BYTE);
mlxsw_sp_port->active_vlans = kzalloc(bytes, GFP_KERNEL); mlxsw_sp_port->active_vlans = kzalloc(bytes, GFP_KERNEL);
if (!mlxsw_sp_port->active_vlans) { if (!mlxsw_sp_port->active_vlans) {
@ -1839,28 +1834,6 @@ err_port_active_vlans_alloc:
return err; return err;
} }
static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,
bool split, u8 module, u8 width, u8 lane)
{
int err;
err = mlxsw_sp_port_module_map(mlxsw_sp, local_port, module, width,
lane);
if (err)
return err;
err = __mlxsw_sp_port_create(mlxsw_sp, local_port, split, module,
width);
if (err)
goto err_port_create;
return 0;
err_port_create:
mlxsw_sp_port_module_unmap(mlxsw_sp, local_port);
return err;
}
static void mlxsw_sp_port_vports_fini(struct mlxsw_sp_port *mlxsw_sp_port) static void mlxsw_sp_port_vports_fini(struct mlxsw_sp_port *mlxsw_sp_port)
{ {
struct net_device *dev = mlxsw_sp_port->dev; struct net_device *dev = mlxsw_sp_port->dev;
@ -1909,8 +1882,8 @@ static void mlxsw_sp_ports_remove(struct mlxsw_sp *mlxsw_sp)
static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp) static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp)
{ {
u8 module, width, lane;
size_t alloc_size; size_t alloc_size;
u8 module, width;
int i; int i;
int err; int err;
@ -1921,13 +1894,14 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp)
for (i = 1; i < MLXSW_PORT_MAX_PORTS; i++) { for (i = 1; i < MLXSW_PORT_MAX_PORTS; i++) {
err = mlxsw_sp_port_module_info_get(mlxsw_sp, i, &module, err = mlxsw_sp_port_module_info_get(mlxsw_sp, i, &module,
&width); &width, &lane);
if (err) if (err)
goto err_port_module_info_get; goto err_port_module_info_get;
if (!width) if (!width)
continue; continue;
mlxsw_sp->port_to_module[i] = module; mlxsw_sp->port_to_module[i] = module;
err = __mlxsw_sp_port_create(mlxsw_sp, i, false, module, width); err = mlxsw_sp_port_create(mlxsw_sp, i, false, module, width,
lane);
if (err) if (err)
goto err_port_create; goto err_port_create;
} }
@ -1948,12 +1922,85 @@ static u8 mlxsw_sp_cluster_base_port_get(u8 local_port)
return local_port - offset; return local_port - offset;
} }
static int mlxsw_sp_port_split_create(struct mlxsw_sp *mlxsw_sp, u8 base_port,
u8 module, unsigned int count)
{
u8 width = MLXSW_PORT_MODULE_MAX_WIDTH / count;
int err, i;
for (i = 0; i < count; i++) {
err = mlxsw_sp_port_module_map(mlxsw_sp, base_port + i, module,
width, i * width);
if (err)
goto err_port_module_map;
}
for (i = 0; i < count; i++) {
err = __mlxsw_sp_port_swid_set(mlxsw_sp, base_port + i, 0);
if (err)
goto err_port_swid_set;
}
for (i = 0; i < count; i++) {
err = mlxsw_sp_port_create(mlxsw_sp, base_port + i, true,
module, width, i * width);
if (err)
goto err_port_create;
}
return 0;
err_port_create:
for (i--; i >= 0; i--)
mlxsw_sp_port_remove(mlxsw_sp, base_port + i);
i = count;
err_port_swid_set:
for (i--; i >= 0; i--)
__mlxsw_sp_port_swid_set(mlxsw_sp, base_port + i,
MLXSW_PORT_SWID_DISABLED_PORT);
i = count;
err_port_module_map:
for (i--; i >= 0; i--)
mlxsw_sp_port_module_unmap(mlxsw_sp, base_port + i);
return err;
}
static void mlxsw_sp_port_unsplit_create(struct mlxsw_sp *mlxsw_sp,
u8 base_port, unsigned int count)
{
u8 local_port, module, width = MLXSW_PORT_MODULE_MAX_WIDTH;
int i;
/* Split by four means we need to re-create two ports, otherwise
* only one.
*/
count = count / 2;
for (i = 0; i < count; i++) {
local_port = base_port + i * 2;
module = mlxsw_sp->port_to_module[local_port];
mlxsw_sp_port_module_map(mlxsw_sp, local_port, module, width,
0);
}
for (i = 0; i < count; i++)
__mlxsw_sp_port_swid_set(mlxsw_sp, base_port + i * 2, 0);
for (i = 0; i < count; i++) {
local_port = base_port + i * 2;
module = mlxsw_sp->port_to_module[local_port];
mlxsw_sp_port_create(mlxsw_sp, local_port, false, module,
width, 0);
}
}
static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port, static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
unsigned int count) unsigned int count)
{ {
struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
struct mlxsw_sp_port *mlxsw_sp_port; struct mlxsw_sp_port *mlxsw_sp_port;
u8 width = MLXSW_PORT_MODULE_MAX_WIDTH / count;
u8 module, cur_width, base_port; u8 module, cur_width, base_port;
int i; int i;
int err; int err;
@ -1965,18 +2012,14 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
return -EINVAL; return -EINVAL;
} }
module = mlxsw_sp_port->mapping.module;
cur_width = mlxsw_sp_port->mapping.width;
if (count != 2 && count != 4) { if (count != 2 && count != 4) {
netdev_err(mlxsw_sp_port->dev, "Port can only be split into 2 or 4 ports\n"); netdev_err(mlxsw_sp_port->dev, "Port can only be split into 2 or 4 ports\n");
return -EINVAL; return -EINVAL;
} }
err = mlxsw_sp_port_module_info_get(mlxsw_sp, local_port, &module,
&cur_width);
if (err) {
netdev_err(mlxsw_sp_port->dev, "Failed to get port's width\n");
return err;
}
if (cur_width != MLXSW_PORT_MODULE_MAX_WIDTH) { if (cur_width != MLXSW_PORT_MODULE_MAX_WIDTH) {
netdev_err(mlxsw_sp_port->dev, "Port cannot be split further\n"); netdev_err(mlxsw_sp_port->dev, "Port cannot be split further\n");
return -EINVAL; return -EINVAL;
@ -2001,25 +2044,16 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
mlxsw_sp_port_remove(mlxsw_sp, base_port + i); mlxsw_sp_port_remove(mlxsw_sp, base_port + i);
for (i = 0; i < count; i++) { err = mlxsw_sp_port_split_create(mlxsw_sp, base_port, module, count);
err = mlxsw_sp_port_create(mlxsw_sp, base_port + i, true,
module, width, i * width);
if (err) { if (err) {
dev_err(mlxsw_sp->bus_info->dev, "Failed to create split port\n"); dev_err(mlxsw_sp->bus_info->dev, "Failed to create split ports\n");
goto err_port_create; goto err_port_split_create;
}
} }
return 0; return 0;
err_port_create: err_port_split_create:
for (i--; i >= 0; i--) mlxsw_sp_port_unsplit_create(mlxsw_sp, base_port, count);
mlxsw_sp_port_remove(mlxsw_sp, base_port + i);
for (i = 0; i < count / 2; i++) {
module = mlxsw_sp->port_to_module[base_port + i * 2];
mlxsw_sp_port_create(mlxsw_sp, base_port + i * 2, false,
module, MLXSW_PORT_MODULE_MAX_WIDTH, 0);
}
return err; return err;
} }
@ -2027,10 +2061,9 @@ static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u8 local_port)
{ {
struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
struct mlxsw_sp_port *mlxsw_sp_port; struct mlxsw_sp_port *mlxsw_sp_port;
u8 module, cur_width, base_port; u8 cur_width, base_port;
unsigned int count; unsigned int count;
int i; int i;
int err;
mlxsw_sp_port = mlxsw_sp->ports[local_port]; mlxsw_sp_port = mlxsw_sp->ports[local_port];
if (!mlxsw_sp_port) { if (!mlxsw_sp_port) {
@ -2044,12 +2077,7 @@ static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u8 local_port)
return -EINVAL; return -EINVAL;
} }
err = mlxsw_sp_port_module_info_get(mlxsw_sp, local_port, &module, cur_width = mlxsw_sp_port->mapping.width;
&cur_width);
if (err) {
netdev_err(mlxsw_sp_port->dev, "Failed to get port's width\n");
return err;
}
count = cur_width == 1 ? 4 : 2; count = cur_width == 1 ? 4 : 2;
base_port = mlxsw_sp_cluster_base_port_get(local_port); base_port = mlxsw_sp_cluster_base_port_get(local_port);
@ -2061,14 +2089,7 @@ static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u8 local_port)
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
mlxsw_sp_port_remove(mlxsw_sp, base_port + i); mlxsw_sp_port_remove(mlxsw_sp, base_port + i);
for (i = 0; i < count / 2; i++) { mlxsw_sp_port_unsplit_create(mlxsw_sp, base_port, count);
module = mlxsw_sp->port_to_module[base_port + i * 2];
err = mlxsw_sp_port_create(mlxsw_sp, base_port + i * 2, false,
module, MLXSW_PORT_MODULE_MAX_WIDTH,
0);
if (err)
dev_err(mlxsw_sp->bus_info->dev, "Failed to reinstantiate port\n");
}
return 0; return 0;
} }

View File

@ -229,6 +229,11 @@ struct mlxsw_sp_port {
struct ieee_maxrate *maxrate; struct ieee_maxrate *maxrate;
struct ieee_pfc *pfc; struct ieee_pfc *pfc;
} dcb; } dcb;
struct {
u8 module;
u8 width;
u8 lane;
} mapping;
/* 802.1Q bridge VLANs */ /* 802.1Q bridge VLANs */
unsigned long *active_vlans; unsigned long *active_vlans;
unsigned long *untagged_vlans; unsigned long *untagged_vlans;