mlxsw: spectrum: Register CPU port with devlink
Register CPU port with devlink. Signed-off-by: Shalom Toledo <shalomt@mellanox.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
9d0aa053ea
commit
28b1987ef5
|
@ -1864,11 +1864,12 @@ u64 mlxsw_core_res_get(struct mlxsw_core *mlxsw_core,
|
|||
}
|
||||
EXPORT_SYMBOL(mlxsw_core_res_get);
|
||||
|
||||
int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port,
|
||||
u32 port_number, bool split,
|
||||
u32 split_port_subnumber,
|
||||
const unsigned char *switch_id,
|
||||
unsigned char switch_id_len)
|
||||
static int __mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port,
|
||||
enum devlink_port_flavour flavour,
|
||||
u32 port_number, bool split,
|
||||
u32 split_port_subnumber,
|
||||
const unsigned char *switch_id,
|
||||
unsigned char switch_id_len)
|
||||
{
|
||||
struct devlink *devlink = priv_to_devlink(mlxsw_core);
|
||||
struct mlxsw_core_port *mlxsw_core_port =
|
||||
|
@ -1877,17 +1878,16 @@ int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port,
|
|||
int err;
|
||||
|
||||
mlxsw_core_port->local_port = local_port;
|
||||
devlink_port_attrs_set(devlink_port, DEVLINK_PORT_FLAVOUR_PHYSICAL,
|
||||
port_number, split, split_port_subnumber,
|
||||
devlink_port_attrs_set(devlink_port, flavour, port_number,
|
||||
split, split_port_subnumber,
|
||||
switch_id, switch_id_len);
|
||||
err = devlink_port_register(devlink, devlink_port, local_port);
|
||||
if (err)
|
||||
memset(mlxsw_core_port, 0, sizeof(*mlxsw_core_port));
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(mlxsw_core_port_init);
|
||||
|
||||
void mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u8 local_port)
|
||||
static void __mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u8 local_port)
|
||||
{
|
||||
struct mlxsw_core_port *mlxsw_core_port =
|
||||
&mlxsw_core->ports[local_port];
|
||||
|
@ -1896,8 +1896,53 @@ void mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u8 local_port)
|
|||
devlink_port_unregister(devlink_port);
|
||||
memset(mlxsw_core_port, 0, sizeof(*mlxsw_core_port));
|
||||
}
|
||||
|
||||
int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port,
|
||||
u32 port_number, bool split,
|
||||
u32 split_port_subnumber,
|
||||
const unsigned char *switch_id,
|
||||
unsigned char switch_id_len)
|
||||
{
|
||||
return __mlxsw_core_port_init(mlxsw_core, local_port,
|
||||
DEVLINK_PORT_FLAVOUR_PHYSICAL,
|
||||
port_number, split, split_port_subnumber,
|
||||
switch_id, switch_id_len);
|
||||
}
|
||||
EXPORT_SYMBOL(mlxsw_core_port_init);
|
||||
|
||||
void mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u8 local_port)
|
||||
{
|
||||
__mlxsw_core_port_fini(mlxsw_core, local_port);
|
||||
}
|
||||
EXPORT_SYMBOL(mlxsw_core_port_fini);
|
||||
|
||||
int mlxsw_core_cpu_port_init(struct mlxsw_core *mlxsw_core,
|
||||
void *port_driver_priv,
|
||||
const unsigned char *switch_id,
|
||||
unsigned char switch_id_len)
|
||||
{
|
||||
struct mlxsw_core_port *mlxsw_core_port =
|
||||
&mlxsw_core->ports[MLXSW_PORT_CPU_PORT];
|
||||
int err;
|
||||
|
||||
err = __mlxsw_core_port_init(mlxsw_core, MLXSW_PORT_CPU_PORT,
|
||||
DEVLINK_PORT_FLAVOUR_CPU,
|
||||
0, false, 0,
|
||||
switch_id, switch_id_len);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
mlxsw_core_port->port_driver_priv = port_driver_priv;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(mlxsw_core_cpu_port_init);
|
||||
|
||||
void mlxsw_core_cpu_port_fini(struct mlxsw_core *mlxsw_core)
|
||||
{
|
||||
__mlxsw_core_port_fini(mlxsw_core, MLXSW_PORT_CPU_PORT);
|
||||
}
|
||||
EXPORT_SYMBOL(mlxsw_core_cpu_port_fini);
|
||||
|
||||
void mlxsw_core_port_eth_set(struct mlxsw_core *mlxsw_core, u8 local_port,
|
||||
void *port_driver_priv, struct net_device *dev)
|
||||
{
|
||||
|
|
|
@ -177,6 +177,11 @@ int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port,
|
|||
const unsigned char *switch_id,
|
||||
unsigned char switch_id_len);
|
||||
void mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u8 local_port);
|
||||
int mlxsw_core_cpu_port_init(struct mlxsw_core *mlxsw_core,
|
||||
void *port_driver_priv,
|
||||
const unsigned char *switch_id,
|
||||
unsigned char switch_id_len);
|
||||
void mlxsw_core_cpu_port_fini(struct mlxsw_core *mlxsw_core);
|
||||
void mlxsw_core_port_eth_set(struct mlxsw_core *mlxsw_core, u8 local_port,
|
||||
void *port_driver_priv, struct net_device *dev);
|
||||
void mlxsw_core_port_ib_set(struct mlxsw_core *mlxsw_core, u8 local_port,
|
||||
|
|
|
@ -3872,6 +3872,45 @@ static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u8 local_port)
|
|||
mlxsw_core_port_fini(mlxsw_sp->core, local_port);
|
||||
}
|
||||
|
||||
static int mlxsw_sp_cpu_port_create(struct mlxsw_sp *mlxsw_sp)
|
||||
{
|
||||
struct mlxsw_sp_port *mlxsw_sp_port;
|
||||
int err;
|
||||
|
||||
mlxsw_sp_port = kzalloc(sizeof(*mlxsw_sp_port), GFP_KERNEL);
|
||||
if (!mlxsw_sp_port)
|
||||
return -ENOMEM;
|
||||
|
||||
mlxsw_sp_port->mlxsw_sp = mlxsw_sp;
|
||||
mlxsw_sp_port->local_port = MLXSW_PORT_CPU_PORT;
|
||||
|
||||
err = mlxsw_core_cpu_port_init(mlxsw_sp->core,
|
||||
mlxsw_sp_port,
|
||||
mlxsw_sp->base_mac,
|
||||
sizeof(mlxsw_sp->base_mac));
|
||||
if (err) {
|
||||
dev_err(mlxsw_sp->bus_info->dev, "Failed to initialize core CPU port\n");
|
||||
goto err_core_cpu_port_init;
|
||||
}
|
||||
|
||||
mlxsw_sp->ports[MLXSW_PORT_CPU_PORT] = mlxsw_sp_port;
|
||||
return 0;
|
||||
|
||||
err_core_cpu_port_init:
|
||||
kfree(mlxsw_sp_port);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void mlxsw_sp_cpu_port_remove(struct mlxsw_sp *mlxsw_sp)
|
||||
{
|
||||
struct mlxsw_sp_port *mlxsw_sp_port =
|
||||
mlxsw_sp->ports[MLXSW_PORT_CPU_PORT];
|
||||
|
||||
mlxsw_core_cpu_port_fini(mlxsw_sp->core);
|
||||
mlxsw_sp->ports[MLXSW_PORT_CPU_PORT] = NULL;
|
||||
kfree(mlxsw_sp_port);
|
||||
}
|
||||
|
||||
static bool mlxsw_sp_port_created(struct mlxsw_sp *mlxsw_sp, u8 local_port)
|
||||
{
|
||||
return mlxsw_sp->ports[local_port] != NULL;
|
||||
|
@ -3884,6 +3923,7 @@ static void mlxsw_sp_ports_remove(struct mlxsw_sp *mlxsw_sp)
|
|||
for (i = 1; i < mlxsw_core_max_ports(mlxsw_sp->core); i++)
|
||||
if (mlxsw_sp_port_created(mlxsw_sp, i))
|
||||
mlxsw_sp_port_remove(mlxsw_sp, i);
|
||||
mlxsw_sp_cpu_port_remove(mlxsw_sp);
|
||||
kfree(mlxsw_sp->port_to_module);
|
||||
kfree(mlxsw_sp->ports);
|
||||
}
|
||||
|
@ -3908,6 +3948,10 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp)
|
|||
goto err_port_to_module_alloc;
|
||||
}
|
||||
|
||||
err = mlxsw_sp_cpu_port_create(mlxsw_sp);
|
||||
if (err)
|
||||
goto err_cpu_port_create;
|
||||
|
||||
for (i = 1; i < max_ports; i++) {
|
||||
/* Mark as invalid */
|
||||
mlxsw_sp->port_to_module[i] = -1;
|
||||
|
@ -3931,6 +3975,8 @@ err_port_module_info_get:
|
|||
for (i--; i >= 1; i--)
|
||||
if (mlxsw_sp_port_created(mlxsw_sp, i))
|
||||
mlxsw_sp_port_remove(mlxsw_sp, i);
|
||||
mlxsw_sp_cpu_port_remove(mlxsw_sp);
|
||||
err_cpu_port_create:
|
||||
kfree(mlxsw_sp->port_to_module);
|
||||
err_port_to_module_alloc:
|
||||
kfree(mlxsw_sp->ports);
|
||||
|
|
Loading…
Reference in New Issue