Skip to content

Commit

Permalink
TMP: devlink device type
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
  • Loading branch information
Jiri Pirko committed Apr 12, 2022
1 parent 1df923d commit f39238e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlxsw/core_linecards.c
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion include/net/devlink.h
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions include/uapi/linux/devlink.h
Expand Up @@ -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 */

Expand Down
14 changes: 13 additions & 1 deletion net/core/devlink.c
Expand Up @@ -2063,6 +2063,7 @@ struct devlink_linecard_device {
struct list_head list;
unsigned int index;
const char *flash_component;
const char *type;
void *priv;
};

Expand All @@ -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;
Expand Down Expand Up @@ -10559,22 +10566,27 @@ 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.
*/
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);
Expand Down

0 comments on commit f39238e

Please sign in to comment.