Commit 24cc68ad authored by Arkadi Sharshevsky's avatar Arkadi Sharshevsky Committed by David S. Miller

mlxsw: core: Add support for reload

Add support for hot reload. First, all the driver/core resources are
released but the PCI and devlink instances, then reset is performed
through the PCI interface. Finally the driver performs initialization.

In case of reload failure the driver is left in a partially initialized
state. Special care is taken during the driver removal in order to
properly handle this state.
Signed-off-by: default avatarArkadi Sharshevsky <arkadis@mellanox.com>
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e21d21ca
...@@ -113,6 +113,7 @@ struct mlxsw_core { ...@@ -113,6 +113,7 @@ struct mlxsw_core {
struct mlxsw_thermal *thermal; struct mlxsw_thermal *thermal;
struct mlxsw_core_port *ports; struct mlxsw_core_port *ports;
unsigned int max_ports; unsigned int max_ports;
bool reload_fail;
unsigned long driver_priv[0]; unsigned long driver_priv[0];
/* driver_priv has to be always the last item */ /* driver_priv has to be always the last item */
}; };
...@@ -962,7 +963,28 @@ mlxsw_devlink_sb_occ_tc_port_bind_get(struct devlink_port *devlink_port, ...@@ -962,7 +963,28 @@ mlxsw_devlink_sb_occ_tc_port_bind_get(struct devlink_port *devlink_port,
pool_type, p_cur, p_max); pool_type, p_cur, p_max);
} }
static int mlxsw_devlink_core_bus_device_reload(struct devlink *devlink)
{
struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
const struct mlxsw_bus *mlxsw_bus = mlxsw_core->bus;
int err;
if (!mlxsw_bus->reset)
return -EOPNOTSUPP;
mlxsw_core_bus_device_unregister(mlxsw_core, true);
mlxsw_bus->reset(mlxsw_core->bus_priv);
err = mlxsw_core_bus_device_register(mlxsw_core->bus_info,
mlxsw_core->bus,
mlxsw_core->bus_priv, true,
devlink);
if (err)
mlxsw_core->reload_fail = true;
return err;
}
static const struct devlink_ops mlxsw_devlink_ops = { static const struct devlink_ops mlxsw_devlink_ops = {
.reload = mlxsw_devlink_core_bus_device_reload,
.port_type_set = mlxsw_devlink_port_type_set, .port_type_set = mlxsw_devlink_port_type_set,
.port_split = mlxsw_devlink_port_split, .port_split = mlxsw_devlink_port_split,
.port_unsplit = mlxsw_devlink_port_unsplit, .port_unsplit = mlxsw_devlink_port_unsplit,
...@@ -980,24 +1002,27 @@ static const struct devlink_ops mlxsw_devlink_ops = { ...@@ -980,24 +1002,27 @@ static const struct devlink_ops mlxsw_devlink_ops = {
int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
const struct mlxsw_bus *mlxsw_bus, const struct mlxsw_bus *mlxsw_bus,
void *bus_priv) void *bus_priv, bool reload,
struct devlink *devlink)
{ {
const char *device_kind = mlxsw_bus_info->device_kind; const char *device_kind = mlxsw_bus_info->device_kind;
struct mlxsw_core *mlxsw_core; struct mlxsw_core *mlxsw_core;
struct mlxsw_driver *mlxsw_driver; struct mlxsw_driver *mlxsw_driver;
struct devlink *devlink;
size_t alloc_size; size_t alloc_size;
int err; int err;
mlxsw_driver = mlxsw_core_driver_get(device_kind); mlxsw_driver = mlxsw_core_driver_get(device_kind);
if (!mlxsw_driver) if (!mlxsw_driver)
return -EINVAL; return -EINVAL;
if (!reload) {
alloc_size = sizeof(*mlxsw_core) + mlxsw_driver->priv_size; alloc_size = sizeof(*mlxsw_core) + mlxsw_driver->priv_size;
devlink = devlink_alloc(&mlxsw_devlink_ops, alloc_size); devlink = devlink_alloc(&mlxsw_devlink_ops, alloc_size);
if (!devlink) { if (!devlink) {
err = -ENOMEM; err = -ENOMEM;
goto err_devlink_alloc; goto err_devlink_alloc;
} }
}
mlxsw_core = devlink_priv(devlink); mlxsw_core = devlink_priv(devlink);
INIT_LIST_HEAD(&mlxsw_core->rx_listener_list); INIT_LIST_HEAD(&mlxsw_core->rx_listener_list);
...@@ -1012,7 +1037,7 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, ...@@ -1012,7 +1037,7 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
if (err) if (err)
goto err_bus_init; goto err_bus_init;
if (mlxsw_driver->resources_register) { if (mlxsw_driver->resources_register && !reload) {
err = mlxsw_driver->resources_register(mlxsw_core); err = mlxsw_driver->resources_register(mlxsw_core);
if (err) if (err)
goto err_register_resources; goto err_register_resources;
...@@ -1038,9 +1063,11 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, ...@@ -1038,9 +1063,11 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
if (err) if (err)
goto err_emad_init; goto err_emad_init;
if (!reload) {
err = devlink_register(devlink, mlxsw_bus_info->dev); err = devlink_register(devlink, mlxsw_bus_info->dev);
if (err) if (err)
goto err_devlink_register; goto err_devlink_register;
}
err = mlxsw_hwmon_init(mlxsw_core, mlxsw_bus_info, &mlxsw_core->hwmon); err = mlxsw_hwmon_init(mlxsw_core, mlxsw_bus_info, &mlxsw_core->hwmon);
if (err) if (err)
...@@ -1063,6 +1090,7 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, ...@@ -1063,6 +1090,7 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
mlxsw_thermal_fini(mlxsw_core->thermal); mlxsw_thermal_fini(mlxsw_core->thermal);
err_thermal_init: err_thermal_init:
err_hwmon_init: err_hwmon_init:
if (!reload)
devlink_unregister(devlink); devlink_unregister(devlink);
err_devlink_register: err_devlink_register:
mlxsw_emad_fini(mlxsw_core); mlxsw_emad_fini(mlxsw_core);
...@@ -1073,8 +1101,10 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, ...@@ -1073,8 +1101,10 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
err_ports_init: err_ports_init:
mlxsw_bus->fini(bus_priv); mlxsw_bus->fini(bus_priv);
err_bus_init: err_bus_init:
if (!reload)
devlink_resources_unregister(devlink, NULL); devlink_resources_unregister(devlink, NULL);
err_register_resources: err_register_resources:
if (!reload)
devlink_free(devlink); devlink_free(devlink);
err_devlink_alloc: err_devlink_alloc:
mlxsw_core_driver_put(device_kind); mlxsw_core_driver_put(device_kind);
...@@ -1082,20 +1112,29 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, ...@@ -1082,20 +1112,29 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
} }
EXPORT_SYMBOL(mlxsw_core_bus_device_register); EXPORT_SYMBOL(mlxsw_core_bus_device_register);
void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core) void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core,
bool reload)
{ {
const char *device_kind = mlxsw_core->bus_info->device_kind; const char *device_kind = mlxsw_core->bus_info->device_kind;
struct devlink *devlink = priv_to_devlink(mlxsw_core); struct devlink *devlink = priv_to_devlink(mlxsw_core);
if (mlxsw_core->reload_fail)
goto reload_fail;
if (mlxsw_core->driver->fini) if (mlxsw_core->driver->fini)
mlxsw_core->driver->fini(mlxsw_core); mlxsw_core->driver->fini(mlxsw_core);
mlxsw_thermal_fini(mlxsw_core->thermal); mlxsw_thermal_fini(mlxsw_core->thermal);
if (!reload)
devlink_unregister(devlink); devlink_unregister(devlink);
mlxsw_emad_fini(mlxsw_core); mlxsw_emad_fini(mlxsw_core);
kfree(mlxsw_core->lag.mapping); kfree(mlxsw_core->lag.mapping);
mlxsw_ports_fini(mlxsw_core); mlxsw_ports_fini(mlxsw_core);
if (!reload)
devlink_resources_unregister(devlink, NULL); devlink_resources_unregister(devlink, NULL);
mlxsw_core->bus->fini(mlxsw_core->bus_priv); mlxsw_core->bus->fini(mlxsw_core->bus_priv);
if (reload)
return;
reload_fail:
devlink_free(devlink); devlink_free(devlink);
mlxsw_core_driver_put(device_kind); mlxsw_core_driver_put(device_kind);
} }
......
...@@ -66,8 +66,9 @@ void mlxsw_core_driver_unregister(struct mlxsw_driver *mlxsw_driver); ...@@ -66,8 +66,9 @@ void mlxsw_core_driver_unregister(struct mlxsw_driver *mlxsw_driver);
int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
const struct mlxsw_bus *mlxsw_bus, const struct mlxsw_bus *mlxsw_bus,
void *bus_priv); void *bus_priv, bool reload,
void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core); struct devlink *devlink);
void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core, bool reload);
struct mlxsw_tx_info { struct mlxsw_tx_info {
u8 local_port; u8 local_port;
......
...@@ -539,7 +539,8 @@ static int mlxsw_i2c_probe(struct i2c_client *client, ...@@ -539,7 +539,8 @@ static int mlxsw_i2c_probe(struct i2c_client *client,
mlxsw_i2c->dev = &client->dev; mlxsw_i2c->dev = &client->dev;
err = mlxsw_core_bus_device_register(&mlxsw_i2c->bus_info, err = mlxsw_core_bus_device_register(&mlxsw_i2c->bus_info,
&mlxsw_i2c_bus, mlxsw_i2c); &mlxsw_i2c_bus, mlxsw_i2c, false,
NULL);
if (err) { if (err) {
dev_err(&client->dev, "Fail to register core bus\n"); dev_err(&client->dev, "Fail to register core bus\n");
return err; return err;
...@@ -557,7 +558,7 @@ static int mlxsw_i2c_remove(struct i2c_client *client) ...@@ -557,7 +558,7 @@ static int mlxsw_i2c_remove(struct i2c_client *client)
{ {
struct mlxsw_i2c *mlxsw_i2c = i2c_get_clientdata(client); struct mlxsw_i2c *mlxsw_i2c = i2c_get_clientdata(client);
mlxsw_core_bus_device_unregister(mlxsw_i2c->core); mlxsw_core_bus_device_unregister(mlxsw_i2c->core, false);
mutex_destroy(&mlxsw_i2c->cmd.lock); mutex_destroy(&mlxsw_i2c->cmd.lock);
return 0; return 0;
......
...@@ -1739,7 +1739,8 @@ static int mlxsw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -1739,7 +1739,8 @@ static int mlxsw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
mlxsw_pci->id = id; mlxsw_pci->id = id;
err = mlxsw_core_bus_device_register(&mlxsw_pci->bus_info, err = mlxsw_core_bus_device_register(&mlxsw_pci->bus_info,
&mlxsw_pci_bus, mlxsw_pci); &mlxsw_pci_bus, mlxsw_pci, false,
NULL);
if (err) { if (err) {
dev_err(&pdev->dev, "cannot register bus device\n"); dev_err(&pdev->dev, "cannot register bus device\n");
goto err_bus_device_register; goto err_bus_device_register;
...@@ -1767,7 +1768,7 @@ static void mlxsw_pci_remove(struct pci_dev *pdev) ...@@ -1767,7 +1768,7 @@ static void mlxsw_pci_remove(struct pci_dev *pdev)
{ {
struct mlxsw_pci *mlxsw_pci = pci_get_drvdata(pdev); struct mlxsw_pci *mlxsw_pci = pci_get_drvdata(pdev);
mlxsw_core_bus_device_unregister(mlxsw_pci->core); mlxsw_core_bus_device_unregister(mlxsw_pci->core, false);
mlxsw_pci_free_irq_vectors(mlxsw_pci); mlxsw_pci_free_irq_vectors(mlxsw_pci);
iounmap(mlxsw_pci->hw_addr); iounmap(mlxsw_pci->hw_addr);
pci_release_regions(mlxsw_pci->pdev); pci_release_regions(mlxsw_pci->pdev);
......
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