Commit 3de1484b authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'mlxsw-introduce-modular-system-support-by-minimal-driver'

Petr Machata says:

====================
mlxsw: Introduce modular system support by minimal driver

Vadim Pasternak writes:

This patchset adds line cards support in mlxsw_minimal, which is used
for monitoring purposes on BMC systems. The BMC is connected to the
ASIC over I2C bus, unlike the host CPU that is connected to the ASIC
via PCI bus.

The BMC system needs to be notified whenever line cards become active
or inactive, so that, for example, netdevs will be registered /
unregistered by mlxsw_minimal. However, traps cannot be generated
towards the BMC over the I2C bus. To overcome that, the I2C bus driver
(i.e., mlxsw_i2c) registers an handler for an IRQ that is fired upon
specific system wide changes, like line card activation and
deactivation.

The generated event is handled by mlxsw_core, which checks whether
anything changed in the state of available line cards. If a line card
becomes active or inactive, interested parties such as mlxsw_minimal
are notified via their registered line card event callback.

Patch set overview:

Patches #1 is preparations.

Patches #2-#3 extend mlxsw_core with an infrastructure to handle the
	previously mentioned system events.

Patch #4 extends the I2C bus driver to register an handler for the IRQ
	fired upon specific system wide changes.

Patches #5-#8 gradually add line cards support in mlxsw_minimal by
	dynamically registering / unregistering netdevs for ports found on
	line cards, whenever a line card becomes active / inactive.
====================

Link: https://lore.kernel.org/r/cover.1661093502.git.petrm@nvidia.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 510156a7 706ddb78
...@@ -70,6 +70,8 @@ struct mlxsw_core { ...@@ -70,6 +70,8 @@ struct mlxsw_core {
struct workqueue_struct *emad_wq; struct workqueue_struct *emad_wq;
struct list_head rx_listener_list; struct list_head rx_listener_list;
struct list_head event_listener_list; struct list_head event_listener_list;
struct list_head irq_event_handler_list;
struct mutex irq_event_handler_lock; /* Locks access to handlers list */
struct { struct {
atomic64_t tid; atomic64_t tid;
struct list_head trans_list; struct list_head trans_list;
...@@ -2090,6 +2092,18 @@ static void mlxsw_core_health_fini(struct mlxsw_core *mlxsw_core) ...@@ -2090,6 +2092,18 @@ static void mlxsw_core_health_fini(struct mlxsw_core *mlxsw_core)
devlink_health_reporter_destroy(mlxsw_core->health.fw_fatal); devlink_health_reporter_destroy(mlxsw_core->health.fw_fatal);
} }
static void mlxsw_core_irq_event_handler_init(struct mlxsw_core *mlxsw_core)
{
INIT_LIST_HEAD(&mlxsw_core->irq_event_handler_list);
mutex_init(&mlxsw_core->irq_event_handler_lock);
}
static void mlxsw_core_irq_event_handler_fini(struct mlxsw_core *mlxsw_core)
{
mutex_destroy(&mlxsw_core->irq_event_handler_lock);
WARN_ON(!list_empty(&mlxsw_core->irq_event_handler_list));
}
static int static int
__mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, __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,
...@@ -2125,6 +2139,7 @@ __mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, ...@@ -2125,6 +2139,7 @@ __mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
mlxsw_core->bus = mlxsw_bus; mlxsw_core->bus = mlxsw_bus;
mlxsw_core->bus_priv = bus_priv; mlxsw_core->bus_priv = bus_priv;
mlxsw_core->bus_info = mlxsw_bus_info; mlxsw_core->bus_info = mlxsw_bus_info;
mlxsw_core_irq_event_handler_init(mlxsw_core);
err = mlxsw_bus->init(bus_priv, mlxsw_core, mlxsw_driver->profile, err = mlxsw_bus->init(bus_priv, mlxsw_core, mlxsw_driver->profile,
&mlxsw_core->res); &mlxsw_core->res);
...@@ -2233,6 +2248,7 @@ __mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, ...@@ -2233,6 +2248,7 @@ __mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
err_register_resources: err_register_resources:
mlxsw_bus->fini(bus_priv); mlxsw_bus->fini(bus_priv);
err_bus_init: err_bus_init:
mlxsw_core_irq_event_handler_fini(mlxsw_core);
if (!reload) { if (!reload) {
devl_unlock(devlink); devl_unlock(devlink);
devlink_free(devlink); devlink_free(devlink);
...@@ -2302,6 +2318,7 @@ void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core, ...@@ -2302,6 +2318,7 @@ void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core,
if (!reload) if (!reload)
devl_resources_unregister(devlink); devl_resources_unregister(devlink);
mlxsw_core->bus->fini(mlxsw_core->bus_priv); mlxsw_core->bus->fini(mlxsw_core->bus_priv);
mlxsw_core_irq_event_handler_fini(mlxsw_core);
if (!reload) { if (!reload) {
devl_unlock(devlink); devl_unlock(devlink);
devlink_free(devlink); devlink_free(devlink);
...@@ -2772,6 +2789,57 @@ int mlxsw_reg_trans_bulk_wait(struct list_head *bulk_list) ...@@ -2772,6 +2789,57 @@ int mlxsw_reg_trans_bulk_wait(struct list_head *bulk_list)
} }
EXPORT_SYMBOL(mlxsw_reg_trans_bulk_wait); EXPORT_SYMBOL(mlxsw_reg_trans_bulk_wait);
struct mlxsw_core_irq_event_handler_item {
struct list_head list;
void (*cb)(struct mlxsw_core *mlxsw_core);
};
int mlxsw_core_irq_event_handler_register(struct mlxsw_core *mlxsw_core,
mlxsw_irq_event_cb_t cb)
{
struct mlxsw_core_irq_event_handler_item *item;
item = kzalloc(sizeof(*item), GFP_KERNEL);
if (!item)
return -ENOMEM;
item->cb = cb;
mutex_lock(&mlxsw_core->irq_event_handler_lock);
list_add_tail(&item->list, &mlxsw_core->irq_event_handler_list);
mutex_unlock(&mlxsw_core->irq_event_handler_lock);
return 0;
}
EXPORT_SYMBOL(mlxsw_core_irq_event_handler_register);
void mlxsw_core_irq_event_handler_unregister(struct mlxsw_core *mlxsw_core,
mlxsw_irq_event_cb_t cb)
{
struct mlxsw_core_irq_event_handler_item *item, *tmp;
mutex_lock(&mlxsw_core->irq_event_handler_lock);
list_for_each_entry_safe(item, tmp,
&mlxsw_core->irq_event_handler_list, list) {
if (item->cb == cb) {
list_del(&item->list);
kfree(item);
}
}
mutex_unlock(&mlxsw_core->irq_event_handler_lock);
}
EXPORT_SYMBOL(mlxsw_core_irq_event_handler_unregister);
void mlxsw_core_irq_event_handlers_call(struct mlxsw_core *mlxsw_core)
{
struct mlxsw_core_irq_event_handler_item *item;
mutex_lock(&mlxsw_core->irq_event_handler_lock);
list_for_each_entry(item, &mlxsw_core->irq_event_handler_list, list) {
if (item->cb)
item->cb(mlxsw_core);
}
mutex_unlock(&mlxsw_core->irq_event_handler_lock);
}
EXPORT_SYMBOL(mlxsw_core_irq_event_handlers_call);
static int mlxsw_core_reg_access_cmd(struct mlxsw_core *mlxsw_core, static int mlxsw_core_reg_access_cmd(struct mlxsw_core *mlxsw_core,
const struct mlxsw_reg_info *reg, const struct mlxsw_reg_info *reg,
char *payload, char *payload,
......
...@@ -215,6 +215,14 @@ int mlxsw_reg_trans_write(struct mlxsw_core *mlxsw_core, ...@@ -215,6 +215,14 @@ int mlxsw_reg_trans_write(struct mlxsw_core *mlxsw_core,
mlxsw_reg_trans_cb_t *cb, unsigned long cb_priv); mlxsw_reg_trans_cb_t *cb, unsigned long cb_priv);
int mlxsw_reg_trans_bulk_wait(struct list_head *bulk_list); int mlxsw_reg_trans_bulk_wait(struct list_head *bulk_list);
typedef void mlxsw_irq_event_cb_t(struct mlxsw_core *mlxsw_core);
int mlxsw_core_irq_event_handler_register(struct mlxsw_core *mlxsw_core,
mlxsw_irq_event_cb_t cb);
void mlxsw_core_irq_event_handler_unregister(struct mlxsw_core *mlxsw_core,
mlxsw_irq_event_cb_t cb);
void mlxsw_core_irq_event_handlers_call(struct mlxsw_core *mlxsw_core);
int mlxsw_reg_query(struct mlxsw_core *mlxsw_core, int mlxsw_reg_query(struct mlxsw_core *mlxsw_core,
const struct mlxsw_reg_info *reg, char *payload); const struct mlxsw_reg_info *reg, char *payload);
int mlxsw_reg_write(struct mlxsw_core *mlxsw_core, int mlxsw_reg_write(struct mlxsw_core *mlxsw_core,
......
...@@ -785,6 +785,21 @@ static int mlxsw_linecard_status_get_and_process(struct mlxsw_core *mlxsw_core, ...@@ -785,6 +785,21 @@ static int mlxsw_linecard_status_get_and_process(struct mlxsw_core *mlxsw_core,
return mlxsw_linecard_status_process(linecards, linecard, mddq_pl); return mlxsw_linecard_status_process(linecards, linecard, mddq_pl);
} }
static void mlxsw_linecards_irq_event_handler(struct mlxsw_core *mlxsw_core)
{
struct mlxsw_linecards *linecards = mlxsw_core_linecards(mlxsw_core);
int i;
/* Handle change of line card active state. */
for (i = 0; i < linecards->count; i++) {
struct mlxsw_linecard *linecard = mlxsw_linecard_get(linecards,
i + 1);
mlxsw_linecard_status_get_and_process(mlxsw_core, linecards,
linecard);
}
}
static const char * const mlxsw_linecard_status_event_type_name[] = { static const char * const mlxsw_linecard_status_event_type_name[] = {
[MLXSW_LINECARD_STATUS_EVENT_TYPE_PROVISION] = "provision", [MLXSW_LINECARD_STATUS_EVENT_TYPE_PROVISION] = "provision",
[MLXSW_LINECARD_STATUS_EVENT_TYPE_UNPROVISION] = "unprovision", [MLXSW_LINECARD_STATUS_EVENT_TYPE_UNPROVISION] = "unprovision",
...@@ -1238,7 +1253,6 @@ static int mlxsw_linecard_init(struct mlxsw_core *mlxsw_core, ...@@ -1238,7 +1253,6 @@ static int mlxsw_linecard_init(struct mlxsw_core *mlxsw_core,
{ {
struct devlink_linecard *devlink_linecard; struct devlink_linecard *devlink_linecard;
struct mlxsw_linecard *linecard; struct mlxsw_linecard *linecard;
int err;
linecard = mlxsw_linecard_get(linecards, slot_index); linecard = mlxsw_linecard_get(linecards, slot_index);
linecard->slot_index = slot_index; linecard->slot_index = slot_index;
...@@ -1248,17 +1262,45 @@ static int mlxsw_linecard_init(struct mlxsw_core *mlxsw_core, ...@@ -1248,17 +1262,45 @@ static int mlxsw_linecard_init(struct mlxsw_core *mlxsw_core,
devlink_linecard = devlink_linecard_create(priv_to_devlink(mlxsw_core), devlink_linecard = devlink_linecard_create(priv_to_devlink(mlxsw_core),
slot_index, &mlxsw_linecard_ops, slot_index, &mlxsw_linecard_ops,
linecard); linecard);
if (IS_ERR(devlink_linecard)) { if (IS_ERR(devlink_linecard))
err = PTR_ERR(devlink_linecard); return PTR_ERR(devlink_linecard);
goto err_devlink_linecard_create;
}
linecard->devlink_linecard = devlink_linecard; linecard->devlink_linecard = devlink_linecard;
INIT_DELAYED_WORK(&linecard->status_event_to_dw, INIT_DELAYED_WORK(&linecard->status_event_to_dw,
&mlxsw_linecard_status_event_to_work); &mlxsw_linecard_status_event_to_work);
return 0;
}
static void mlxsw_linecard_fini(struct mlxsw_core *mlxsw_core,
struct mlxsw_linecards *linecards,
u8 slot_index)
{
struct mlxsw_linecard *linecard;
linecard = mlxsw_linecard_get(linecards, slot_index);
cancel_delayed_work_sync(&linecard->status_event_to_dw);
/* Make sure all scheduled events are processed */
mlxsw_core_flush_owq();
if (linecard->active)
mlxsw_linecard_active_clear(linecard);
mlxsw_linecard_bdev_del(linecard);
devlink_linecard_destroy(linecard->devlink_linecard);
mutex_destroy(&linecard->lock);
}
static int
mlxsw_linecard_event_delivery_init(struct mlxsw_core *mlxsw_core,
struct mlxsw_linecards *linecards,
u8 slot_index)
{
struct mlxsw_linecard *linecard;
int err;
linecard = mlxsw_linecard_get(linecards, slot_index);
err = mlxsw_linecard_event_delivery_set(mlxsw_core, linecard, true); err = mlxsw_linecard_event_delivery_set(mlxsw_core, linecard, true);
if (err) if (err)
goto err_event_delivery_set; return err;
err = mlxsw_linecard_status_get_and_process(mlxsw_core, linecards, err = mlxsw_linecard_status_get_and_process(mlxsw_core, linecards,
linecard); linecard);
...@@ -1269,29 +1311,18 @@ static int mlxsw_linecard_init(struct mlxsw_core *mlxsw_core, ...@@ -1269,29 +1311,18 @@ static int mlxsw_linecard_init(struct mlxsw_core *mlxsw_core,
err_status_get_and_process: err_status_get_and_process:
mlxsw_linecard_event_delivery_set(mlxsw_core, linecard, false); mlxsw_linecard_event_delivery_set(mlxsw_core, linecard, false);
err_event_delivery_set:
devlink_linecard_destroy(linecard->devlink_linecard);
err_devlink_linecard_create:
mutex_destroy(&linecard->lock);
return err; return err;
} }
static void mlxsw_linecard_fini(struct mlxsw_core *mlxsw_core, static void
struct mlxsw_linecards *linecards, mlxsw_linecard_event_delivery_fini(struct mlxsw_core *mlxsw_core,
u8 slot_index) struct mlxsw_linecards *linecards,
u8 slot_index)
{ {
struct mlxsw_linecard *linecard; struct mlxsw_linecard *linecard;
linecard = mlxsw_linecard_get(linecards, slot_index); linecard = mlxsw_linecard_get(linecards, slot_index);
mlxsw_linecard_event_delivery_set(mlxsw_core, linecard, false); mlxsw_linecard_event_delivery_set(mlxsw_core, linecard, false);
cancel_delayed_work_sync(&linecard->status_event_to_dw);
/* Make sure all scheduled events are processed */
mlxsw_core_flush_owq();
if (linecard->active)
mlxsw_linecard_active_clear(linecard);
mlxsw_linecard_bdev_del(linecard);
devlink_linecard_destroy(linecard->devlink_linecard);
mutex_destroy(&linecard->lock);
} }
/* LINECARDS INI BUNDLE FILE /* LINECARDS INI BUNDLE FILE
...@@ -1505,6 +1536,11 @@ int mlxsw_linecards_init(struct mlxsw_core *mlxsw_core, ...@@ -1505,6 +1536,11 @@ int mlxsw_linecards_init(struct mlxsw_core *mlxsw_core,
if (err) if (err)
goto err_traps_register; goto err_traps_register;
err = mlxsw_core_irq_event_handler_register(mlxsw_core,
mlxsw_linecards_irq_event_handler);
if (err)
goto err_irq_event_handler_register;
mlxsw_core_linecards_set(mlxsw_core, linecards); mlxsw_core_linecards_set(mlxsw_core, linecards);
for (i = 0; i < linecards->count; i++) { for (i = 0; i < linecards->count; i++) {
...@@ -1513,11 +1549,25 @@ int mlxsw_linecards_init(struct mlxsw_core *mlxsw_core, ...@@ -1513,11 +1549,25 @@ int mlxsw_linecards_init(struct mlxsw_core *mlxsw_core,
goto err_linecard_init; goto err_linecard_init;
} }
for (i = 0; i < linecards->count; i++) {
err = mlxsw_linecard_event_delivery_init(mlxsw_core, linecards,
i + 1);
if (err)
goto err_linecard_event_delivery_init;
}
return 0; return 0;
err_linecard_event_delivery_init:
for (i--; i >= 0; i--)
mlxsw_linecard_event_delivery_fini(mlxsw_core, linecards, i + 1);
i = linecards->count;
err_linecard_init: err_linecard_init:
for (i--; i >= 0; i--) for (i--; i >= 0; i--)
mlxsw_linecard_fini(mlxsw_core, linecards, i + 1); mlxsw_linecard_fini(mlxsw_core, linecards, i + 1);
mlxsw_core_irq_event_handler_unregister(mlxsw_core,
mlxsw_linecards_irq_event_handler);
err_irq_event_handler_register:
mlxsw_core_traps_unregister(mlxsw_core, mlxsw_linecard_listener, mlxsw_core_traps_unregister(mlxsw_core, mlxsw_linecard_listener,
ARRAY_SIZE(mlxsw_linecard_listener), ARRAY_SIZE(mlxsw_linecard_listener),
mlxsw_core); mlxsw_core);
...@@ -1535,8 +1585,12 @@ void mlxsw_linecards_fini(struct mlxsw_core *mlxsw_core) ...@@ -1535,8 +1585,12 @@ void mlxsw_linecards_fini(struct mlxsw_core *mlxsw_core)
if (!linecards) if (!linecards)
return; return;
for (i = 0; i < linecards->count; i++)
mlxsw_linecard_event_delivery_fini(mlxsw_core, linecards, i + 1);
for (i = 0; i < linecards->count; i++) for (i = 0; i < linecards->count; i++)
mlxsw_linecard_fini(mlxsw_core, linecards, i + 1); mlxsw_linecard_fini(mlxsw_core, linecards, i + 1);
mlxsw_core_irq_event_handler_unregister(mlxsw_core,
mlxsw_linecards_irq_event_handler);
mlxsw_core_traps_unregister(mlxsw_core, mlxsw_linecard_listener, mlxsw_core_traps_unregister(mlxsw_core, mlxsw_linecard_listener,
ARRAY_SIZE(mlxsw_linecard_listener), ARRAY_SIZE(mlxsw_linecard_listener),
mlxsw_core); mlxsw_core);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/mod_devicetable.h> #include <linux/mod_devicetable.h>
#include <linux/platform_data/mlxreg.h>
#include <linux/slab.h> #include <linux/slab.h>
#include "cmd.h" #include "cmd.h"
...@@ -51,6 +52,15 @@ ...@@ -51,6 +52,15 @@
#define MLXSW_I2C_TIMEOUT_MSECS 5000 #define MLXSW_I2C_TIMEOUT_MSECS 5000
#define MLXSW_I2C_MAX_DATA_SIZE 256 #define MLXSW_I2C_MAX_DATA_SIZE 256
/* Driver can be initialized by kernel platform driver or from the user
* space. In the first case IRQ line number is passed through the platform
* data, otherwise default IRQ line is to be used. Default IRQ is relevant
* only for specific I2C slave address, allowing 3.4 MHz I2C path to the chip
* (special hardware feature for I2C acceleration).
*/
#define MLXSW_I2C_DEFAULT_IRQ 17
#define MLXSW_FAST_I2C_SLAVE 0x37
/** /**
* struct mlxsw_i2c - device private data: * struct mlxsw_i2c - device private data:
* @cmd: command attributes; * @cmd: command attributes;
...@@ -63,6 +73,9 @@ ...@@ -63,6 +73,9 @@
* @core: switch core pointer; * @core: switch core pointer;
* @bus_info: bus info block; * @bus_info: bus info block;
* @block_size: maximum block size allowed to pass to under layer; * @block_size: maximum block size allowed to pass to under layer;
* @pdata: device platform data;
* @irq_work: interrupts work item;
* @irq: IRQ line number;
*/ */
struct mlxsw_i2c { struct mlxsw_i2c {
struct { struct {
...@@ -76,6 +89,9 @@ struct mlxsw_i2c { ...@@ -76,6 +89,9 @@ struct mlxsw_i2c {
struct mlxsw_core *core; struct mlxsw_core *core;
struct mlxsw_bus_info bus_info; struct mlxsw_bus_info bus_info;
u16 block_size; u16 block_size;
struct mlxreg_core_hotplug_platform_data *pdata;
struct work_struct irq_work;
int irq;
}; };
#define MLXSW_I2C_READ_MSG(_client, _addr_buf, _buf, _len) { \ #define MLXSW_I2C_READ_MSG(_client, _addr_buf, _buf, _len) { \
...@@ -546,6 +562,67 @@ static void mlxsw_i2c_fini(void *bus_priv) ...@@ -546,6 +562,67 @@ static void mlxsw_i2c_fini(void *bus_priv)
mlxsw_i2c->core = NULL; mlxsw_i2c->core = NULL;
} }
static void mlxsw_i2c_work_handler(struct work_struct *work)
{
struct mlxsw_i2c *mlxsw_i2c;
mlxsw_i2c = container_of(work, struct mlxsw_i2c, irq_work);
mlxsw_core_irq_event_handlers_call(mlxsw_i2c->core);
}
static irqreturn_t mlxsw_i2c_irq_handler(int irq, void *dev)
{
struct mlxsw_i2c *mlxsw_i2c = dev;
mlxsw_core_schedule_work(&mlxsw_i2c->irq_work);
/* Interrupt handler shares IRQ line with 'main' interrupt handler.
* Return here IRQ_NONE, while main handler will return IRQ_HANDLED.
*/
return IRQ_NONE;
}
static int mlxsw_i2c_irq_init(struct mlxsw_i2c *mlxsw_i2c, u8 addr)
{
int err;
/* Initialize interrupt handler if system hotplug driver is reachable,
* otherwise interrupt line is not enabled and interrupts will not be
* raised to CPU. Also request_irq() call will be not valid.
*/
if (!IS_REACHABLE(CONFIG_MLXREG_HOTPLUG))
return 0;
/* Set default interrupt line. */
if (mlxsw_i2c->pdata && mlxsw_i2c->pdata->irq)
mlxsw_i2c->irq = mlxsw_i2c->pdata->irq;
else if (addr == MLXSW_FAST_I2C_SLAVE)
mlxsw_i2c->irq = MLXSW_I2C_DEFAULT_IRQ;
if (!mlxsw_i2c->irq)
return 0;
INIT_WORK(&mlxsw_i2c->irq_work, mlxsw_i2c_work_handler);
err = request_irq(mlxsw_i2c->irq, mlxsw_i2c_irq_handler,
IRQF_TRIGGER_FALLING | IRQF_SHARED, "mlxsw-i2c",
mlxsw_i2c);
if (err) {
dev_err(mlxsw_i2c->bus_info.dev, "Failed to request irq: %d\n",
err);
return err;
}
return 0;
}
static void mlxsw_i2c_irq_fini(struct mlxsw_i2c *mlxsw_i2c)
{
if (!IS_REACHABLE(CONFIG_MLXREG_HOTPLUG) || !mlxsw_i2c->irq)
return;
cancel_work_sync(&mlxsw_i2c->irq_work);
free_irq(mlxsw_i2c->irq, mlxsw_i2c);
}
static const struct mlxsw_bus mlxsw_i2c_bus = { static const struct mlxsw_bus mlxsw_i2c_bus = {
.kind = "i2c", .kind = "i2c",
.init = mlxsw_i2c_init, .init = mlxsw_i2c_init,
...@@ -638,17 +715,24 @@ static int mlxsw_i2c_probe(struct i2c_client *client, ...@@ -638,17 +715,24 @@ static int mlxsw_i2c_probe(struct i2c_client *client,
mlxsw_i2c->bus_info.dev = &client->dev; mlxsw_i2c->bus_info.dev = &client->dev;
mlxsw_i2c->bus_info.low_frequency = true; mlxsw_i2c->bus_info.low_frequency = true;
mlxsw_i2c->dev = &client->dev; mlxsw_i2c->dev = &client->dev;
mlxsw_i2c->pdata = client->dev.platform_data;
err = mlxsw_i2c_irq_init(mlxsw_i2c, client->addr);
if (err)
goto errout;
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, false, &mlxsw_i2c_bus, mlxsw_i2c, false,
NULL, NULL); NULL, 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; goto err_bus_device_register;
} }
return 0; return 0;
err_bus_device_register:
mlxsw_i2c_irq_fini(mlxsw_i2c);
errout: errout:
mutex_destroy(&mlxsw_i2c->cmd.lock); mutex_destroy(&mlxsw_i2c->cmd.lock);
i2c_set_clientdata(client, NULL); i2c_set_clientdata(client, NULL);
...@@ -661,6 +745,7 @@ static int mlxsw_i2c_remove(struct i2c_client *client) ...@@ -661,6 +745,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, false); mlxsw_core_bus_device_unregister(mlxsw_i2c->core, false);
mlxsw_i2c_irq_fini(mlxsw_i2c);
mutex_destroy(&mlxsw_i2c->cmd.lock); mutex_destroy(&mlxsw_i2c->cmd.lock);
return 0; return 0;
......
...@@ -26,20 +26,29 @@ static const struct mlxsw_fw_rev mlxsw_m_fw_rev = { ...@@ -26,20 +26,29 @@ static const struct mlxsw_fw_rev mlxsw_m_fw_rev = {
struct mlxsw_m_port; struct mlxsw_m_port;
struct mlxsw_m_line_card {
bool active;
int module_to_port[];
};
struct mlxsw_m { struct mlxsw_m {
struct mlxsw_m_port **ports; struct mlxsw_m_port **ports;
int *module_to_port;
struct mlxsw_core *core; struct mlxsw_core *core;
const struct mlxsw_bus_info *bus_info; const struct mlxsw_bus_info *bus_info;
u8 base_mac[ETH_ALEN]; u8 base_mac[ETH_ALEN];
u8 max_ports; u8 max_ports;
u8 max_modules_per_slot; /* Maximum number of modules per-slot. */
u8 num_of_slots; /* Including the main board. */
struct mlxsw_m_line_card **line_cards;
}; };
struct mlxsw_m_port { struct mlxsw_m_port {
struct net_device *dev; struct net_device *dev;
struct mlxsw_m *mlxsw_m; struct mlxsw_m *mlxsw_m;
u16 local_port; u16 local_port;
u8 slot_index;
u8 module; u8 module;
u8 module_offset;
}; };
static int mlxsw_m_base_mac_get(struct mlxsw_m *mlxsw_m) static int mlxsw_m_base_mac_get(struct mlxsw_m *mlxsw_m)
...@@ -111,8 +120,9 @@ static int mlxsw_m_get_module_info(struct net_device *netdev, ...@@ -111,8 +120,9 @@ static int mlxsw_m_get_module_info(struct net_device *netdev,
struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev); struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev);
struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core;
return mlxsw_env_get_module_info(netdev, core, 0, mlxsw_m_port->module, return mlxsw_env_get_module_info(netdev, core,
modinfo); mlxsw_m_port->slot_index,
mlxsw_m_port->module, modinfo);
} }
static int static int
...@@ -122,7 +132,8 @@ mlxsw_m_get_module_eeprom(struct net_device *netdev, struct ethtool_eeprom *ee, ...@@ -122,7 +132,8 @@ mlxsw_m_get_module_eeprom(struct net_device *netdev, struct ethtool_eeprom *ee,
struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev); struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev);
struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core;
return mlxsw_env_get_module_eeprom(netdev, core, 0, return mlxsw_env_get_module_eeprom(netdev, core,
mlxsw_m_port->slot_index,
mlxsw_m_port->module, ee, data); mlxsw_m_port->module, ee, data);
} }
...@@ -134,7 +145,8 @@ mlxsw_m_get_module_eeprom_by_page(struct net_device *netdev, ...@@ -134,7 +145,8 @@ mlxsw_m_get_module_eeprom_by_page(struct net_device *netdev,
struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev); struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev);
struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core;
return mlxsw_env_get_module_eeprom_by_page(core, 0, return mlxsw_env_get_module_eeprom_by_page(core,
mlxsw_m_port->slot_index,
mlxsw_m_port->module, mlxsw_m_port->module,
page, extack); page, extack);
} }
...@@ -144,7 +156,8 @@ static int mlxsw_m_reset(struct net_device *netdev, u32 *flags) ...@@ -144,7 +156,8 @@ static int mlxsw_m_reset(struct net_device *netdev, u32 *flags)
struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev); struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev);
struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core;
return mlxsw_env_reset_module(netdev, core, 0, mlxsw_m_port->module, return mlxsw_env_reset_module(netdev, core, mlxsw_m_port->slot_index,
mlxsw_m_port->module,
flags); flags);
} }
...@@ -156,7 +169,8 @@ mlxsw_m_get_module_power_mode(struct net_device *netdev, ...@@ -156,7 +169,8 @@ mlxsw_m_get_module_power_mode(struct net_device *netdev,
struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev); struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev);
struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core;
return mlxsw_env_get_module_power_mode(core, 0, mlxsw_m_port->module, return mlxsw_env_get_module_power_mode(core, mlxsw_m_port->slot_index,
mlxsw_m_port->module,
params, extack); params, extack);
} }
...@@ -168,7 +182,8 @@ mlxsw_m_set_module_power_mode(struct net_device *netdev, ...@@ -168,7 +182,8 @@ mlxsw_m_set_module_power_mode(struct net_device *netdev,
struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev); struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev);
struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core;
return mlxsw_env_set_module_power_mode(core, 0, mlxsw_m_port->module, return mlxsw_env_set_module_power_mode(core, mlxsw_m_port->slot_index,
mlxsw_m_port->module,
params->policy, extack); params->policy, extack);
} }
...@@ -184,7 +199,7 @@ static const struct ethtool_ops mlxsw_m_port_ethtool_ops = { ...@@ -184,7 +199,7 @@ static const struct ethtool_ops mlxsw_m_port_ethtool_ops = {
static int static int
mlxsw_m_port_module_info_get(struct mlxsw_m *mlxsw_m, u16 local_port, mlxsw_m_port_module_info_get(struct mlxsw_m *mlxsw_m, u16 local_port,
u8 *p_module, u8 *p_width) u8 *p_module, u8 *p_width, u8 *p_slot_index)
{ {
char pmlp_pl[MLXSW_REG_PMLP_LEN]; char pmlp_pl[MLXSW_REG_PMLP_LEN];
int err; int err;
...@@ -195,6 +210,7 @@ mlxsw_m_port_module_info_get(struct mlxsw_m *mlxsw_m, u16 local_port, ...@@ -195,6 +210,7 @@ mlxsw_m_port_module_info_get(struct mlxsw_m *mlxsw_m, u16 local_port,
return err; return err;
*p_module = mlxsw_reg_pmlp_module_get(pmlp_pl, 0); *p_module = mlxsw_reg_pmlp_module_get(pmlp_pl, 0);
*p_width = mlxsw_reg_pmlp_width_get(pmlp_pl); *p_width = mlxsw_reg_pmlp_width_get(pmlp_pl);
*p_slot_index = mlxsw_reg_pmlp_slot_index_get(pmlp_pl, 0);
return 0; return 0;
} }
...@@ -212,18 +228,25 @@ mlxsw_m_port_dev_addr_get(struct mlxsw_m_port *mlxsw_m_port) ...@@ -212,18 +228,25 @@ mlxsw_m_port_dev_addr_get(struct mlxsw_m_port *mlxsw_m_port)
if (err) if (err)
return err; return err;
mlxsw_reg_ppad_mac_memcpy_from(ppad_pl, addr); mlxsw_reg_ppad_mac_memcpy_from(ppad_pl, addr);
eth_hw_addr_gen(mlxsw_m_port->dev, addr, mlxsw_m_port->module + 1); eth_hw_addr_gen(mlxsw_m_port->dev, addr, mlxsw_m_port->module + 1 +
mlxsw_m_port->module_offset);
return 0; return 0;
} }
static bool mlxsw_m_port_created(struct mlxsw_m *mlxsw_m, u16 local_port)
{
return mlxsw_m->ports[local_port];
}
static int static int
mlxsw_m_port_create(struct mlxsw_m *mlxsw_m, u16 local_port, u8 module) mlxsw_m_port_create(struct mlxsw_m *mlxsw_m, u16 local_port, u8 slot_index,
u8 module)
{ {
struct mlxsw_m_port *mlxsw_m_port; struct mlxsw_m_port *mlxsw_m_port;
struct net_device *dev; struct net_device *dev;
int err; int err;
err = mlxsw_core_port_init(mlxsw_m->core, local_port, 0, err = mlxsw_core_port_init(mlxsw_m->core, local_port, slot_index,
module + 1, false, 0, false, module + 1, false, 0, false,
0, mlxsw_m->base_mac, 0, mlxsw_m->base_mac,
sizeof(mlxsw_m->base_mac)); sizeof(mlxsw_m->base_mac));
...@@ -246,6 +269,15 @@ mlxsw_m_port_create(struct mlxsw_m *mlxsw_m, u16 local_port, u8 module) ...@@ -246,6 +269,15 @@ mlxsw_m_port_create(struct mlxsw_m *mlxsw_m, u16 local_port, u8 module)
mlxsw_m_port->mlxsw_m = mlxsw_m; mlxsw_m_port->mlxsw_m = mlxsw_m;
mlxsw_m_port->local_port = local_port; mlxsw_m_port->local_port = local_port;
mlxsw_m_port->module = module; mlxsw_m_port->module = module;
mlxsw_m_port->slot_index = slot_index;
/* Add module offset for line card. Offset for main board iz zero.
* For line card in slot #n offset is calculated as (#n - 1)
* multiplied by maximum modules number, which could be found on a line
* card.
*/
mlxsw_m_port->module_offset = mlxsw_m_port->slot_index ?
(mlxsw_m_port->slot_index - 1) *
mlxsw_m->max_modules_per_slot : 0;
dev->netdev_ops = &mlxsw_m_port_netdev_ops; dev->netdev_ops = &mlxsw_m_port_netdev_ops;
dev->ethtool_ops = &mlxsw_m_port_ethtool_ops; dev->ethtool_ops = &mlxsw_m_port_ethtool_ops;
...@@ -291,19 +323,29 @@ static void mlxsw_m_port_remove(struct mlxsw_m *mlxsw_m, u16 local_port) ...@@ -291,19 +323,29 @@ static void mlxsw_m_port_remove(struct mlxsw_m *mlxsw_m, u16 local_port)
mlxsw_core_port_fini(mlxsw_m->core, local_port); mlxsw_core_port_fini(mlxsw_m->core, local_port);
} }
static int*
mlxsw_m_port_mapping_get(struct mlxsw_m *mlxsw_m, u8 slot_index, u8 module)
{
return &mlxsw_m->line_cards[slot_index]->module_to_port[module];
}
static int mlxsw_m_port_module_map(struct mlxsw_m *mlxsw_m, u16 local_port, static int mlxsw_m_port_module_map(struct mlxsw_m *mlxsw_m, u16 local_port,
u8 *last_module) u8 *last_module)
{ {
unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core); unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core);
u8 module, width; u8 module, width, slot_index;
int *module_to_port;
int err; int err;
/* Fill out to local port mapping array */ /* Fill out to local port mapping array */
err = mlxsw_m_port_module_info_get(mlxsw_m, local_port, &module, err = mlxsw_m_port_module_info_get(mlxsw_m, local_port, &module,
&width); &width, &slot_index);
if (err) if (err)
return err; return err;
/* Skip if line card has been already configured */
if (mlxsw_m->line_cards[slot_index]->active)
return 0;
if (!width) if (!width)
return 0; return 0;
/* Skip, if port belongs to the cluster */ /* Skip, if port belongs to the cluster */
...@@ -313,91 +355,216 @@ static int mlxsw_m_port_module_map(struct mlxsw_m *mlxsw_m, u16 local_port, ...@@ -313,91 +355,216 @@ static int mlxsw_m_port_module_map(struct mlxsw_m *mlxsw_m, u16 local_port,
if (WARN_ON_ONCE(module >= max_ports)) if (WARN_ON_ONCE(module >= max_ports))
return -EINVAL; return -EINVAL;
mlxsw_env_module_port_map(mlxsw_m->core, 0, module); mlxsw_env_module_port_map(mlxsw_m->core, slot_index, module);
mlxsw_m->module_to_port[module] = ++mlxsw_m->max_ports; module_to_port = mlxsw_m_port_mapping_get(mlxsw_m, slot_index, module);
*module_to_port = local_port;
return 0; return 0;
} }
static void mlxsw_m_port_module_unmap(struct mlxsw_m *mlxsw_m, u8 module) static void
mlxsw_m_port_module_unmap(struct mlxsw_m *mlxsw_m, u8 slot_index, u8 module)
{ {
mlxsw_m->module_to_port[module] = -1; int *module_to_port = mlxsw_m_port_mapping_get(mlxsw_m, slot_index,
mlxsw_env_module_port_unmap(mlxsw_m->core, 0, module); module);
*module_to_port = -1;
mlxsw_env_module_port_unmap(mlxsw_m->core, slot_index, module);
} }
static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m) static int mlxsw_m_linecards_init(struct mlxsw_m *mlxsw_m)
{ {
unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core); unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core);
u8 last_module = max_ports; char mgpir_pl[MLXSW_REG_MGPIR_LEN];
int i; u8 num_of_modules;
int err; int i, j, err;
mlxsw_reg_mgpir_pack(mgpir_pl, 0);
err = mlxsw_reg_query(mlxsw_m->core, MLXSW_REG(mgpir), mgpir_pl);
if (err)
return err;
mlxsw_reg_mgpir_unpack(mgpir_pl, NULL, NULL, NULL, &num_of_modules,
&mlxsw_m->num_of_slots);
/* If the system is modular, get the maximum number of modules per-slot.
* Otherwise, get the maximum number of modules on the main board.
*/
if (mlxsw_m->num_of_slots)
mlxsw_m->max_modules_per_slot =
mlxsw_reg_mgpir_max_modules_per_slot_get(mgpir_pl);
else
mlxsw_m->max_modules_per_slot = num_of_modules;
/* Add slot for main board. */
mlxsw_m->num_of_slots += 1;
mlxsw_m->ports = kcalloc(max_ports, sizeof(*mlxsw_m->ports), mlxsw_m->ports = kcalloc(max_ports, sizeof(*mlxsw_m->ports),
GFP_KERNEL); GFP_KERNEL);
if (!mlxsw_m->ports) if (!mlxsw_m->ports)
return -ENOMEM; return -ENOMEM;
mlxsw_m->module_to_port = kmalloc_array(max_ports, sizeof(int), mlxsw_m->line_cards = kcalloc(mlxsw_m->num_of_slots,
GFP_KERNEL); sizeof(*mlxsw_m->line_cards),
if (!mlxsw_m->module_to_port) { GFP_KERNEL);
err = -ENOMEM; if (!mlxsw_m->line_cards)
goto err_module_to_port_alloc; goto err_kcalloc;
for (i = 0; i < mlxsw_m->num_of_slots; i++) {
mlxsw_m->line_cards[i] =
kzalloc(struct_size(mlxsw_m->line_cards[i],
module_to_port,
mlxsw_m->max_modules_per_slot),
GFP_KERNEL);
if (!mlxsw_m->line_cards[i])
goto err_kmalloc_array;
/* Invalidate the entries of module to local port mapping array. */
for (j = 0; j < mlxsw_m->max_modules_per_slot; j++)
mlxsw_m->line_cards[i]->module_to_port[j] = -1;
} }
/* Invalidate the entries of module to local port mapping array */ return 0;
for (i = 0; i < max_ports; i++)
mlxsw_m->module_to_port[i] = -1;
/* Fill out module to local port mapping array */ err_kmalloc_array:
for (i = 1; i < max_ports; i++) { for (i--; i >= 0; i--)
err = mlxsw_m_port_module_map(mlxsw_m, i, &last_module); kfree(mlxsw_m->line_cards[i]);
if (err) err_kcalloc:
goto err_module_to_port_map; kfree(mlxsw_m->ports);
return err;
}
static void mlxsw_m_linecards_fini(struct mlxsw_m *mlxsw_m)
{
int i = mlxsw_m->num_of_slots;
for (i--; i >= 0; i--)
kfree(mlxsw_m->line_cards[i]);
kfree(mlxsw_m->line_cards);
kfree(mlxsw_m->ports);
}
static void
mlxsw_m_linecard_port_module_unmap(struct mlxsw_m *mlxsw_m, u8 slot_index)
{
int i;
for (i = mlxsw_m->max_modules_per_slot - 1; i >= 0; i--) {
int *module_to_port;
module_to_port = mlxsw_m_port_mapping_get(mlxsw_m, slot_index, i);
if (*module_to_port > 0)
mlxsw_m_port_module_unmap(mlxsw_m, slot_index, i);
} }
}
/* Create port objects for each valid entry */ static int
for (i = 0; i < mlxsw_m->max_ports; i++) { mlxsw_m_linecard_ports_create(struct mlxsw_m *mlxsw_m, u8 slot_index)
if (mlxsw_m->module_to_port[i] > 0) { {
err = mlxsw_m_port_create(mlxsw_m, int *module_to_port;
mlxsw_m->module_to_port[i], int i, err;
i);
for (i = 0; i < mlxsw_m->max_modules_per_slot; i++) {
module_to_port = mlxsw_m_port_mapping_get(mlxsw_m, slot_index, i);
if (*module_to_port > 0) {
err = mlxsw_m_port_create(mlxsw_m, *module_to_port,
slot_index, i);
if (err) if (err)
goto err_module_to_port_create; goto err_port_create;
/* Mark slot as active */
if (!mlxsw_m->line_cards[slot_index]->active)
mlxsw_m->line_cards[slot_index]->active = true;
} }
} }
return 0; return 0;
err_module_to_port_create: err_port_create:
for (i--; i >= 0; i--) { for (i--; i >= 0; i--) {
if (mlxsw_m->module_to_port[i] > 0) module_to_port = mlxsw_m_port_mapping_get(mlxsw_m, slot_index, i);
mlxsw_m_port_remove(mlxsw_m, if (*module_to_port > 0 &&
mlxsw_m->module_to_port[i]); mlxsw_m_port_created(mlxsw_m, *module_to_port)) {
mlxsw_m_port_remove(mlxsw_m, *module_to_port);
/* Mark slot as inactive */
if (mlxsw_m->line_cards[slot_index]->active)
mlxsw_m->line_cards[slot_index]->active = false;
}
} }
i = max_ports;
err_module_to_port_map:
for (i--; i > 0; i--)
mlxsw_m_port_module_unmap(mlxsw_m, i);
kfree(mlxsw_m->module_to_port);
err_module_to_port_alloc:
kfree(mlxsw_m->ports);
return err; return err;
} }
static void mlxsw_m_ports_remove(struct mlxsw_m *mlxsw_m) static void
mlxsw_m_linecard_ports_remove(struct mlxsw_m *mlxsw_m, u8 slot_index)
{ {
int i; int i;
for (i = 0; i < mlxsw_m->max_ports; i++) { for (i = 0; i < mlxsw_m->max_modules_per_slot; i++) {
if (mlxsw_m->module_to_port[i] > 0) { int *module_to_port = mlxsw_m_port_mapping_get(mlxsw_m,
mlxsw_m_port_remove(mlxsw_m, slot_index, i);
mlxsw_m->module_to_port[i]);
mlxsw_m_port_module_unmap(mlxsw_m, i); if (*module_to_port > 0 &&
mlxsw_m_port_created(mlxsw_m, *module_to_port)) {
mlxsw_m_port_remove(mlxsw_m, *module_to_port);
mlxsw_m_port_module_unmap(mlxsw_m, slot_index, i);
} }
} }
}
kfree(mlxsw_m->module_to_port); static int mlxsw_m_ports_module_map(struct mlxsw_m *mlxsw_m)
kfree(mlxsw_m->ports); {
unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core);
u8 last_module = max_ports;
int i, err;
for (i = 1; i < max_ports; i++) {
err = mlxsw_m_port_module_map(mlxsw_m, i, &last_module);
if (err)
return err;
}
return 0;
}
static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m)
{
int err;
/* Fill out module to local port mapping array */
err = mlxsw_m_ports_module_map(mlxsw_m);
if (err)
goto err_ports_module_map;
/* Create port objects for each valid entry */
err = mlxsw_m_linecard_ports_create(mlxsw_m, 0);
if (err)
goto err_linecard_ports_create;
return 0;
err_linecard_ports_create:
err_ports_module_map:
mlxsw_m_linecard_port_module_unmap(mlxsw_m, 0);
return err;
}
static void mlxsw_m_ports_remove(struct mlxsw_m *mlxsw_m)
{
mlxsw_m_linecard_ports_remove(mlxsw_m, 0);
}
static void
mlxsw_m_ports_remove_selected(struct mlxsw_core *mlxsw_core,
bool (*selector)(void *priv, u16 local_port),
void *priv)
{
struct mlxsw_m *mlxsw_m = mlxsw_core_driver_priv(mlxsw_core);
struct mlxsw_linecard *linecard_priv = priv;
struct mlxsw_m_line_card *linecard;
linecard = mlxsw_m->line_cards[linecard_priv->slot_index];
if (WARN_ON(!linecard->active))
return;
mlxsw_m_linecard_ports_remove(mlxsw_m, linecard_priv->slot_index);
linecard->active = false;
} }
static int mlxsw_m_fw_rev_validate(struct mlxsw_m *mlxsw_m) static int mlxsw_m_fw_rev_validate(struct mlxsw_m *mlxsw_m)
...@@ -418,6 +585,60 @@ static int mlxsw_m_fw_rev_validate(struct mlxsw_m *mlxsw_m) ...@@ -418,6 +585,60 @@ static int mlxsw_m_fw_rev_validate(struct mlxsw_m *mlxsw_m)
return -EINVAL; return -EINVAL;
} }
static void
mlxsw_m_got_active(struct mlxsw_core *mlxsw_core, u8 slot_index, void *priv)
{
struct mlxsw_m_line_card *linecard;
struct mlxsw_m *mlxsw_m = priv;
int err;
linecard = mlxsw_m->line_cards[slot_index];
/* Skip if line card has been already configured during init */
if (linecard->active)
return;
/* Fill out module to local port mapping array */
err = mlxsw_m_ports_module_map(mlxsw_m);
if (err)
goto err_ports_module_map;
/* Create port objects for each valid entry */
err = mlxsw_m_linecard_ports_create(mlxsw_m, slot_index);
if (err) {
dev_err(mlxsw_m->bus_info->dev, "Failed to create port for line card at slot %d\n",
slot_index);
goto err_linecard_ports_create;
}
linecard->active = true;
return;
err_linecard_ports_create:
err_ports_module_map:
mlxsw_m_linecard_port_module_unmap(mlxsw_m, slot_index);
}
static void
mlxsw_m_got_inactive(struct mlxsw_core *mlxsw_core, u8 slot_index, void *priv)
{
struct mlxsw_m_line_card *linecard;
struct mlxsw_m *mlxsw_m = priv;
linecard = mlxsw_m->line_cards[slot_index];
if (WARN_ON(!linecard->active))
return;
mlxsw_m_linecard_ports_remove(mlxsw_m, slot_index);
linecard->active = false;
}
static struct mlxsw_linecards_event_ops mlxsw_m_event_ops = {
.got_active = mlxsw_m_got_active,
.got_inactive = mlxsw_m_got_inactive,
};
static int mlxsw_m_init(struct mlxsw_core *mlxsw_core, static int mlxsw_m_init(struct mlxsw_core *mlxsw_core,
const struct mlxsw_bus_info *mlxsw_bus_info, const struct mlxsw_bus_info *mlxsw_bus_info,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
...@@ -438,13 +659,33 @@ static int mlxsw_m_init(struct mlxsw_core *mlxsw_core, ...@@ -438,13 +659,33 @@ static int mlxsw_m_init(struct mlxsw_core *mlxsw_core,
return err; return err;
} }
err = mlxsw_m_linecards_init(mlxsw_m);
if (err) {
dev_err(mlxsw_m->bus_info->dev, "Failed to create line cards\n");
return err;
}
err = mlxsw_linecards_event_ops_register(mlxsw_core,
&mlxsw_m_event_ops, mlxsw_m);
if (err) {
dev_err(mlxsw_m->bus_info->dev, "Failed to register line cards operations\n");
goto linecards_event_ops_register;
}
err = mlxsw_m_ports_create(mlxsw_m); err = mlxsw_m_ports_create(mlxsw_m);
if (err) { if (err) {
dev_err(mlxsw_m->bus_info->dev, "Failed to create ports\n"); dev_err(mlxsw_m->bus_info->dev, "Failed to create ports\n");
return err; goto err_ports_create;
} }
return 0; return 0;
err_ports_create:
mlxsw_linecards_event_ops_unregister(mlxsw_core,
&mlxsw_m_event_ops, mlxsw_m);
linecards_event_ops_register:
mlxsw_m_linecards_fini(mlxsw_m);
return err;
} }
static void mlxsw_m_fini(struct mlxsw_core *mlxsw_core) static void mlxsw_m_fini(struct mlxsw_core *mlxsw_core)
...@@ -452,6 +693,9 @@ static void mlxsw_m_fini(struct mlxsw_core *mlxsw_core) ...@@ -452,6 +693,9 @@ static void mlxsw_m_fini(struct mlxsw_core *mlxsw_core)
struct mlxsw_m *mlxsw_m = mlxsw_core_driver_priv(mlxsw_core); struct mlxsw_m *mlxsw_m = mlxsw_core_driver_priv(mlxsw_core);
mlxsw_m_ports_remove(mlxsw_m); mlxsw_m_ports_remove(mlxsw_m);
mlxsw_linecards_event_ops_unregister(mlxsw_core,
&mlxsw_m_event_ops, mlxsw_m);
mlxsw_m_linecards_fini(mlxsw_m);
} }
static const struct mlxsw_config_profile mlxsw_m_config_profile; static const struct mlxsw_config_profile mlxsw_m_config_profile;
...@@ -461,6 +705,7 @@ static struct mlxsw_driver mlxsw_m_driver = { ...@@ -461,6 +705,7 @@ static struct mlxsw_driver mlxsw_m_driver = {
.priv_size = sizeof(struct mlxsw_m), .priv_size = sizeof(struct mlxsw_m),
.init = mlxsw_m_init, .init = mlxsw_m_init,
.fini = mlxsw_m_fini, .fini = mlxsw_m_fini,
.ports_remove_selected = mlxsw_m_ports_remove_selected,
.profile = &mlxsw_m_config_profile, .profile = &mlxsw_m_config_profile,
}; };
......
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