diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c b/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c index 5ab110890f31..13e43112dc46 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c @@ -430,7 +430,7 @@ static int mlxsw_linecard_device_attach(struct mlxsw_core *mlxsw_core, device->devlink_device = devlink_linecard_device_create(linecard->devlink_linecard, device_index, - component_name, + component_name, NULL, device); if (IS_ERR(device->devlink_device)) { err = PTR_ERR(device->devlink_device); diff --git a/include/net/devlink.h b/include/net/devlink.h index 89282d6fed74..529e9ebec3b4 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1606,7 +1606,8 @@ void devlink_linecard_destroy(struct devlink_linecard *linecard); struct devlink_linecard_device * devlink_linecard_device_create(struct devlink_linecard *linecard, unsigned int device_index, - const char *flash_component, void *priv); + const char *flash_component, + const char *type, void *priv); void devlink_linecard_device_destroy(struct devlink_linecard *linecard, struct devlink_linecard_device *linecard_device); diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index fb8c3864457f..79401f29a9fd 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -580,6 +580,7 @@ enum devlink_attr { DEVLINK_ATTR_LINECARD_DEVICE_LIST, /* nested */ DEVLINK_ATTR_LINECARD_DEVICE, /* nested */ DEVLINK_ATTR_LINECARD_DEVICE_INDEX, /* u32 */ + DEVLINK_ATTR_LINECARD_DEVICE_TYPE, /* string */ /* add new attributes above here, update the policy in devlink.c */ diff --git a/net/core/devlink.c b/net/core/devlink.c index 82d543c6a700..a22436ad3493 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -2063,6 +2063,7 @@ struct devlink_linecard_device { struct list_head list; unsigned int index; const char *flash_component; + const char *type; void *priv; }; @@ -2086,6 +2087,12 @@ devlink_nl_linecard_device_fill(struct sk_buff *msg, nla_nest_cancel(msg, attr); return -EMSGSIZE; } + if (linecard_device->type && + nla_put_string(msg, DEVLINK_ATTR_LINECARD_DEVICE_TYPE, + linecard_device->type)) { + nla_nest_cancel(msg, attr); + return -EMSGSIZE; + } nla_nest_end(msg, attr); return 0; @@ -10559,6 +10566,7 @@ EXPORT_SYMBOL_GPL(devlink_linecard_destroy); * @device_index: index of the linecard device * @flash_component: name of flash update component, * NULL if unable to flash + * @type: name of the device type * @priv: user priv pointer * * Return: Line card device structure or an ERR_PTR() encoded error code. @@ -10566,15 +10574,19 @@ EXPORT_SYMBOL_GPL(devlink_linecard_destroy); struct devlink_linecard_device * devlink_linecard_device_create(struct devlink_linecard *linecard, unsigned int device_index, - const char *flash_component, void *priv) + const char *flash_component, + const char *type, void *priv) { struct devlink_linecard_device *linecard_device; + if (WARN_ON(!type)) + return ERR_PTR(-EINVAL); linecard_device = kzalloc(sizeof(*linecard_device), GFP_KERNEL); if (!linecard_device) return ERR_PTR(-ENOMEM); linecard_device->index = device_index; linecard_device->flash_component = flash_component; + linecard_device->type = type; linecard_device->priv = priv; mutex_lock(&linecard->state_lock); list_add_tail(&linecard_device->list, &linecard->device_list);