Commit 9473bc01 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

devlink: convert linecard nested devlink to new rel infrastructure

Benefit from the newly introduced rel infrastructure, treat the linecard
nested devlink instances in the same way as port function instances.
Convert the code to use the rel infrastructure.
Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ac5f3956
...@@ -132,6 +132,7 @@ static int mlxsw_linecard_bdev_probe(struct auxiliary_device *adev, ...@@ -132,6 +132,7 @@ static int mlxsw_linecard_bdev_probe(struct auxiliary_device *adev,
struct mlxsw_linecard *linecard = linecard_bdev->linecard; struct mlxsw_linecard *linecard = linecard_bdev->linecard;
struct mlxsw_linecard_dev *linecard_dev; struct mlxsw_linecard_dev *linecard_dev;
struct devlink *devlink; struct devlink *devlink;
int err;
devlink = devlink_alloc(&mlxsw_linecard_dev_devlink_ops, devlink = devlink_alloc(&mlxsw_linecard_dev_devlink_ops,
sizeof(*linecard_dev), &adev->dev); sizeof(*linecard_dev), &adev->dev);
...@@ -141,8 +142,12 @@ static int mlxsw_linecard_bdev_probe(struct auxiliary_device *adev, ...@@ -141,8 +142,12 @@ static int mlxsw_linecard_bdev_probe(struct auxiliary_device *adev,
linecard_dev->linecard = linecard_bdev->linecard; linecard_dev->linecard = linecard_bdev->linecard;
linecard_bdev->linecard_dev = linecard_dev; linecard_bdev->linecard_dev = linecard_dev;
err = devlink_linecard_nested_dl_set(linecard->devlink_linecard, devlink);
if (err) {
devlink_free(devlink);
return err;
}
devlink_register(devlink); devlink_register(devlink);
devlink_linecard_nested_dl_set(linecard->devlink_linecard, devlink);
return 0; return 0;
} }
...@@ -151,9 +156,7 @@ static void mlxsw_linecard_bdev_remove(struct auxiliary_device *adev) ...@@ -151,9 +156,7 @@ static void mlxsw_linecard_bdev_remove(struct auxiliary_device *adev)
struct mlxsw_linecard_bdev *linecard_bdev = struct mlxsw_linecard_bdev *linecard_bdev =
container_of(adev, struct mlxsw_linecard_bdev, adev); container_of(adev, struct mlxsw_linecard_bdev, adev);
struct devlink *devlink = priv_to_devlink(linecard_bdev->linecard_dev); struct devlink *devlink = priv_to_devlink(linecard_bdev->linecard_dev);
struct mlxsw_linecard *linecard = linecard_bdev->linecard;
devlink_linecard_nested_dl_set(linecard->devlink_linecard, NULL);
devlink_unregister(devlink); devlink_unregister(devlink);
devlink_free(devlink); devlink_free(devlink);
} }
......
...@@ -1720,8 +1720,8 @@ void devlink_linecard_provision_clear(struct devlink_linecard *linecard); ...@@ -1720,8 +1720,8 @@ void devlink_linecard_provision_clear(struct devlink_linecard *linecard);
void devlink_linecard_provision_fail(struct devlink_linecard *linecard); void devlink_linecard_provision_fail(struct devlink_linecard *linecard);
void devlink_linecard_activate(struct devlink_linecard *linecard); void devlink_linecard_activate(struct devlink_linecard *linecard);
void devlink_linecard_deactivate(struct devlink_linecard *linecard); void devlink_linecard_deactivate(struct devlink_linecard *linecard);
void devlink_linecard_nested_dl_set(struct devlink_linecard *linecard, int devlink_linecard_nested_dl_set(struct devlink_linecard *linecard,
struct devlink *nested_devlink); struct devlink *nested_devlink);
int devl_sb_register(struct devlink *devlink, unsigned int sb_index, int devl_sb_register(struct devlink *devlink, unsigned int sb_index,
u32 size, u16 ingress_pools_count, u32 size, u16 ingress_pools_count,
u16 egress_pools_count, u16 ingress_tc_count, u16 egress_pools_count, u16 ingress_tc_count,
......
...@@ -17,7 +17,7 @@ struct devlink_linecard { ...@@ -17,7 +17,7 @@ struct devlink_linecard {
const char *type; const char *type;
struct devlink_linecard_type *types; struct devlink_linecard_type *types;
unsigned int types_count; unsigned int types_count;
struct devlink *nested_devlink; u32 rel_index;
}; };
unsigned int devlink_linecard_index(struct devlink_linecard *linecard) unsigned int devlink_linecard_index(struct devlink_linecard *linecard)
...@@ -112,10 +112,10 @@ static int devlink_nl_linecard_fill(struct sk_buff *msg, ...@@ -112,10 +112,10 @@ static int devlink_nl_linecard_fill(struct sk_buff *msg,
nla_nest_end(msg, attr); nla_nest_end(msg, attr);
} }
if (linecard->nested_devlink && if (devlink_rel_devlink_handle_put(msg, devlink,
devlink_nl_put_nested_handle(msg, devlink_net(devlink), linecard->rel_index,
linecard->nested_devlink, DEVLINK_ATTR_NESTED_DEVLINK,
DEVLINK_ATTR_NESTED_DEVLINK)) NULL))
goto nla_put_failure; goto nla_put_failure;
genlmsg_end(msg, hdr); genlmsg_end(msg, hdr);
...@@ -524,7 +524,6 @@ EXPORT_SYMBOL_GPL(devlink_linecard_provision_set); ...@@ -524,7 +524,6 @@ EXPORT_SYMBOL_GPL(devlink_linecard_provision_set);
void devlink_linecard_provision_clear(struct devlink_linecard *linecard) void devlink_linecard_provision_clear(struct devlink_linecard *linecard)
{ {
mutex_lock(&linecard->state_lock); mutex_lock(&linecard->state_lock);
WARN_ON(linecard->nested_devlink);
linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED; linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED;
linecard->type = NULL; linecard->type = NULL;
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
...@@ -543,7 +542,6 @@ EXPORT_SYMBOL_GPL(devlink_linecard_provision_clear); ...@@ -543,7 +542,6 @@ EXPORT_SYMBOL_GPL(devlink_linecard_provision_clear);
void devlink_linecard_provision_fail(struct devlink_linecard *linecard) void devlink_linecard_provision_fail(struct devlink_linecard *linecard)
{ {
mutex_lock(&linecard->state_lock); mutex_lock(&linecard->state_lock);
WARN_ON(linecard->nested_devlink);
linecard->state = DEVLINK_LINECARD_STATE_PROVISIONING_FAILED; linecard->state = DEVLINK_LINECARD_STATE_PROVISIONING_FAILED;
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
mutex_unlock(&linecard->state_lock); mutex_unlock(&linecard->state_lock);
...@@ -591,6 +589,27 @@ void devlink_linecard_deactivate(struct devlink_linecard *linecard) ...@@ -591,6 +589,27 @@ void devlink_linecard_deactivate(struct devlink_linecard *linecard)
} }
EXPORT_SYMBOL_GPL(devlink_linecard_deactivate); EXPORT_SYMBOL_GPL(devlink_linecard_deactivate);
static void devlink_linecard_rel_notify_cb(struct devlink *devlink,
u32 linecard_index)
{
struct devlink_linecard *linecard;
linecard = devlink_linecard_get_by_index(devlink, linecard_index);
if (!linecard)
return;
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
}
static void devlink_linecard_rel_cleanup_cb(struct devlink *devlink,
u32 linecard_index, u32 rel_index)
{
struct devlink_linecard *linecard;
linecard = devlink_linecard_get_by_index(devlink, linecard_index);
if (linecard && linecard->rel_index == rel_index)
linecard->rel_index = 0;
}
/** /**
* devlink_linecard_nested_dl_set - Attach/detach nested devlink * devlink_linecard_nested_dl_set - Attach/detach nested devlink
* instance to linecard. * instance to linecard.
...@@ -598,12 +617,14 @@ EXPORT_SYMBOL_GPL(devlink_linecard_deactivate); ...@@ -598,12 +617,14 @@ EXPORT_SYMBOL_GPL(devlink_linecard_deactivate);
* @linecard: devlink linecard * @linecard: devlink linecard
* @nested_devlink: devlink instance to attach or NULL to detach * @nested_devlink: devlink instance to attach or NULL to detach
*/ */
void devlink_linecard_nested_dl_set(struct devlink_linecard *linecard, int devlink_linecard_nested_dl_set(struct devlink_linecard *linecard,
struct devlink *nested_devlink) struct devlink *nested_devlink)
{ {
mutex_lock(&linecard->state_lock); return devlink_rel_nested_in_add(&linecard->rel_index,
linecard->nested_devlink = nested_devlink; linecard->devlink->index,
devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); linecard->index,
mutex_unlock(&linecard->state_lock); devlink_linecard_rel_notify_cb,
devlink_linecard_rel_cleanup_cb,
nested_devlink);
} }
EXPORT_SYMBOL_GPL(devlink_linecard_nested_dl_set); EXPORT_SYMBOL_GPL(devlink_linecard_nested_dl_set);
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