Commit 852e85a7 authored by Jiri Pirko's avatar Jiri Pirko Committed by Jakub Kicinski

net: devlink: add unlocked variants of devling_trap*() functions

Add unlocked variants of devl_trap*() functions to be used in drivers
called-in with devlink->lock held.
Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent e26fde2f
...@@ -1745,9 +1745,15 @@ void devlink_flash_update_timeout_notify(struct devlink *devlink, ...@@ -1745,9 +1745,15 @@ void devlink_flash_update_timeout_notify(struct devlink *devlink,
const char *component, const char *component,
unsigned long timeout); unsigned long timeout);
int devl_traps_register(struct devlink *devlink,
const struct devlink_trap *traps,
size_t traps_count, void *priv);
int devlink_traps_register(struct devlink *devlink, int devlink_traps_register(struct devlink *devlink,
const struct devlink_trap *traps, const struct devlink_trap *traps,
size_t traps_count, void *priv); size_t traps_count, void *priv);
void devl_traps_unregister(struct devlink *devlink,
const struct devlink_trap *traps,
size_t traps_count);
void devlink_traps_unregister(struct devlink *devlink, void devlink_traps_unregister(struct devlink *devlink,
const struct devlink_trap *traps, const struct devlink_trap *traps,
size_t traps_count); size_t traps_count);
...@@ -1755,17 +1761,31 @@ void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb, ...@@ -1755,17 +1761,31 @@ void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
void *trap_ctx, struct devlink_port *in_devlink_port, void *trap_ctx, struct devlink_port *in_devlink_port,
const struct flow_action_cookie *fa_cookie); const struct flow_action_cookie *fa_cookie);
void *devlink_trap_ctx_priv(void *trap_ctx); void *devlink_trap_ctx_priv(void *trap_ctx);
int devl_trap_groups_register(struct devlink *devlink,
const struct devlink_trap_group *groups,
size_t groups_count);
int devlink_trap_groups_register(struct devlink *devlink, int devlink_trap_groups_register(struct devlink *devlink,
const struct devlink_trap_group *groups, const struct devlink_trap_group *groups,
size_t groups_count); size_t groups_count);
void devl_trap_groups_unregister(struct devlink *devlink,
const struct devlink_trap_group *groups,
size_t groups_count);
void devlink_trap_groups_unregister(struct devlink *devlink, void devlink_trap_groups_unregister(struct devlink *devlink,
const struct devlink_trap_group *groups, const struct devlink_trap_group *groups,
size_t groups_count); size_t groups_count);
int int
devl_trap_policers_register(struct devlink *devlink,
const struct devlink_trap_policer *policers,
size_t policers_count);
int
devlink_trap_policers_register(struct devlink *devlink, devlink_trap_policers_register(struct devlink *devlink,
const struct devlink_trap_policer *policers, const struct devlink_trap_policer *policers,
size_t policers_count); size_t policers_count);
void void
devl_trap_policers_unregister(struct devlink *devlink,
const struct devlink_trap_policer *policers,
size_t policers_count);
void
devlink_trap_policers_unregister(struct devlink *devlink, devlink_trap_policers_unregister(struct devlink *devlink,
const struct devlink_trap_policer *policers, const struct devlink_trap_policer *policers,
size_t policers_count); size_t policers_count);
......
...@@ -11544,7 +11544,7 @@ static void devlink_trap_disable(struct devlink *devlink, ...@@ -11544,7 +11544,7 @@ static void devlink_trap_disable(struct devlink *devlink,
} }
/** /**
* devlink_traps_register - Register packet traps with devlink. * devl_traps_register - Register packet traps with devlink.
* @devlink: devlink. * @devlink: devlink.
* @traps: Packet traps. * @traps: Packet traps.
* @traps_count: Count of provided packet traps. * @traps_count: Count of provided packet traps.
...@@ -11552,16 +11552,16 @@ static void devlink_trap_disable(struct devlink *devlink, ...@@ -11552,16 +11552,16 @@ static void devlink_trap_disable(struct devlink *devlink,
* *
* Return: Non-zero value on failure. * Return: Non-zero value on failure.
*/ */
int devlink_traps_register(struct devlink *devlink, int devl_traps_register(struct devlink *devlink,
const struct devlink_trap *traps, const struct devlink_trap *traps,
size_t traps_count, void *priv) size_t traps_count, void *priv)
{ {
int i, err; int i, err;
if (!devlink->ops->trap_init || !devlink->ops->trap_action_set) if (!devlink->ops->trap_init || !devlink->ops->trap_action_set)
return -EINVAL; return -EINVAL;
devl_lock(devlink); devl_assert_locked(devlink);
for (i = 0; i < traps_count; i++) { for (i = 0; i < traps_count; i++) {
const struct devlink_trap *trap = &traps[i]; const struct devlink_trap *trap = &traps[i];
...@@ -11573,7 +11573,6 @@ int devlink_traps_register(struct devlink *devlink, ...@@ -11573,7 +11573,6 @@ int devlink_traps_register(struct devlink *devlink,
if (err) if (err)
goto err_trap_register; goto err_trap_register;
} }
devl_unlock(devlink);
return 0; return 0;
...@@ -11581,24 +11580,47 @@ int devlink_traps_register(struct devlink *devlink, ...@@ -11581,24 +11580,47 @@ int devlink_traps_register(struct devlink *devlink,
err_trap_verify: err_trap_verify:
for (i--; i >= 0; i--) for (i--; i >= 0; i--)
devlink_trap_unregister(devlink, &traps[i]); devlink_trap_unregister(devlink, &traps[i]);
return err;
}
EXPORT_SYMBOL_GPL(devl_traps_register);
/**
* devlink_traps_register - Register packet traps with devlink.
* @devlink: devlink.
* @traps: Packet traps.
* @traps_count: Count of provided packet traps.
* @priv: Driver private information.
*
* Context: Takes and release devlink->lock <mutex>.
*
* Return: Non-zero value on failure.
*/
int devlink_traps_register(struct devlink *devlink,
const struct devlink_trap *traps,
size_t traps_count, void *priv)
{
int err;
devl_lock(devlink);
err = devl_traps_register(devlink, traps, traps_count, priv);
devl_unlock(devlink); devl_unlock(devlink);
return err; return err;
} }
EXPORT_SYMBOL_GPL(devlink_traps_register); EXPORT_SYMBOL_GPL(devlink_traps_register);
/** /**
* devlink_traps_unregister - Unregister packet traps from devlink. * devl_traps_unregister - Unregister packet traps from devlink.
* @devlink: devlink. * @devlink: devlink.
* @traps: Packet traps. * @traps: Packet traps.
* @traps_count: Count of provided packet traps. * @traps_count: Count of provided packet traps.
*/ */
void devlink_traps_unregister(struct devlink *devlink, void devl_traps_unregister(struct devlink *devlink,
const struct devlink_trap *traps, const struct devlink_trap *traps,
size_t traps_count) size_t traps_count)
{ {
int i; int i;
devl_lock(devlink); devl_assert_locked(devlink);
/* Make sure we do not have any packets in-flight while unregistering /* Make sure we do not have any packets in-flight while unregistering
* traps by disabling all of them and waiting for a grace period. * traps by disabling all of them and waiting for a grace period.
*/ */
...@@ -11607,6 +11629,23 @@ void devlink_traps_unregister(struct devlink *devlink, ...@@ -11607,6 +11629,23 @@ void devlink_traps_unregister(struct devlink *devlink,
synchronize_rcu(); synchronize_rcu();
for (i = traps_count - 1; i >= 0; i--) for (i = traps_count - 1; i >= 0; i--)
devlink_trap_unregister(devlink, &traps[i]); devlink_trap_unregister(devlink, &traps[i]);
}
EXPORT_SYMBOL_GPL(devl_traps_unregister);
/**
* devlink_traps_unregister - Unregister packet traps from devlink.
* @devlink: devlink.
* @traps: Packet traps.
* @traps_count: Count of provided packet traps.
*
* Context: Takes and release devlink->lock <mutex>.
*/
void devlink_traps_unregister(struct devlink *devlink,
const struct devlink_trap *traps,
size_t traps_count)
{
devl_lock(devlink);
devl_traps_unregister(devlink, traps, traps_count);
devl_unlock(devlink); devl_unlock(devlink);
} }
EXPORT_SYMBOL_GPL(devlink_traps_unregister); EXPORT_SYMBOL_GPL(devlink_traps_unregister);
...@@ -11766,20 +11805,20 @@ devlink_trap_group_unregister(struct devlink *devlink, ...@@ -11766,20 +11805,20 @@ devlink_trap_group_unregister(struct devlink *devlink,
} }
/** /**
* devlink_trap_groups_register - Register packet trap groups with devlink. * devl_trap_groups_register - Register packet trap groups with devlink.
* @devlink: devlink. * @devlink: devlink.
* @groups: Packet trap groups. * @groups: Packet trap groups.
* @groups_count: Count of provided packet trap groups. * @groups_count: Count of provided packet trap groups.
* *
* Return: Non-zero value on failure. * Return: Non-zero value on failure.
*/ */
int devlink_trap_groups_register(struct devlink *devlink, int devl_trap_groups_register(struct devlink *devlink,
const struct devlink_trap_group *groups, const struct devlink_trap_group *groups,
size_t groups_count) size_t groups_count)
{ {
int i, err; int i, err;
devl_lock(devlink); devl_assert_locked(devlink);
for (i = 0; i < groups_count; i++) { for (i = 0; i < groups_count; i++) {
const struct devlink_trap_group *group = &groups[i]; const struct devlink_trap_group *group = &groups[i];
...@@ -11791,7 +11830,6 @@ int devlink_trap_groups_register(struct devlink *devlink, ...@@ -11791,7 +11830,6 @@ int devlink_trap_groups_register(struct devlink *devlink,
if (err) if (err)
goto err_trap_group_register; goto err_trap_group_register;
} }
devl_unlock(devlink);
return 0; return 0;
...@@ -11799,26 +11837,65 @@ int devlink_trap_groups_register(struct devlink *devlink, ...@@ -11799,26 +11837,65 @@ int devlink_trap_groups_register(struct devlink *devlink,
err_trap_group_verify: err_trap_group_verify:
for (i--; i >= 0; i--) for (i--; i >= 0; i--)
devlink_trap_group_unregister(devlink, &groups[i]); devlink_trap_group_unregister(devlink, &groups[i]);
return err;
}
EXPORT_SYMBOL_GPL(devl_trap_groups_register);
/**
* devlink_trap_groups_register - Register packet trap groups with devlink.
* @devlink: devlink.
* @groups: Packet trap groups.
* @groups_count: Count of provided packet trap groups.
*
* Context: Takes and release devlink->lock <mutex>.
*
* Return: Non-zero value on failure.
*/
int devlink_trap_groups_register(struct devlink *devlink,
const struct devlink_trap_group *groups,
size_t groups_count)
{
int err;
devl_lock(devlink);
err = devl_trap_groups_register(devlink, groups, groups_count);
devl_unlock(devlink); devl_unlock(devlink);
return err; return err;
} }
EXPORT_SYMBOL_GPL(devlink_trap_groups_register); EXPORT_SYMBOL_GPL(devlink_trap_groups_register);
/**
* devl_trap_groups_unregister - Unregister packet trap groups from devlink.
* @devlink: devlink.
* @groups: Packet trap groups.
* @groups_count: Count of provided packet trap groups.
*/
void devl_trap_groups_unregister(struct devlink *devlink,
const struct devlink_trap_group *groups,
size_t groups_count)
{
int i;
devl_assert_locked(devlink);
for (i = groups_count - 1; i >= 0; i--)
devlink_trap_group_unregister(devlink, &groups[i]);
}
EXPORT_SYMBOL_GPL(devl_trap_groups_unregister);
/** /**
* devlink_trap_groups_unregister - Unregister packet trap groups from devlink. * devlink_trap_groups_unregister - Unregister packet trap groups from devlink.
* @devlink: devlink. * @devlink: devlink.
* @groups: Packet trap groups. * @groups: Packet trap groups.
* @groups_count: Count of provided packet trap groups. * @groups_count: Count of provided packet trap groups.
*
* Context: Takes and release devlink->lock <mutex>.
*/ */
void devlink_trap_groups_unregister(struct devlink *devlink, void devlink_trap_groups_unregister(struct devlink *devlink,
const struct devlink_trap_group *groups, const struct devlink_trap_group *groups,
size_t groups_count) size_t groups_count)
{ {
int i;
devl_lock(devlink); devl_lock(devlink);
for (i = groups_count - 1; i >= 0; i--) devl_trap_groups_unregister(devlink, groups, groups_count);
devlink_trap_group_unregister(devlink, &groups[i]);
devl_unlock(devlink); devl_unlock(devlink);
} }
EXPORT_SYMBOL_GPL(devlink_trap_groups_unregister); EXPORT_SYMBOL_GPL(devlink_trap_groups_unregister);
...@@ -11905,7 +11982,7 @@ devlink_trap_policer_unregister(struct devlink *devlink, ...@@ -11905,7 +11982,7 @@ devlink_trap_policer_unregister(struct devlink *devlink,
} }
/** /**
* devlink_trap_policers_register - Register packet trap policers with devlink. * devl_trap_policers_register - Register packet trap policers with devlink.
* @devlink: devlink. * @devlink: devlink.
* @policers: Packet trap policers. * @policers: Packet trap policers.
* @policers_count: Count of provided packet trap policers. * @policers_count: Count of provided packet trap policers.
...@@ -11913,13 +11990,13 @@ devlink_trap_policer_unregister(struct devlink *devlink, ...@@ -11913,13 +11990,13 @@ devlink_trap_policer_unregister(struct devlink *devlink,
* Return: Non-zero value on failure. * Return: Non-zero value on failure.
*/ */
int int
devlink_trap_policers_register(struct devlink *devlink, devl_trap_policers_register(struct devlink *devlink,
const struct devlink_trap_policer *policers, const struct devlink_trap_policer *policers,
size_t policers_count) size_t policers_count)
{ {
int i, err; int i, err;
devl_lock(devlink); devl_assert_locked(devlink);
for (i = 0; i < policers_count; i++) { for (i = 0; i < policers_count; i++) {
const struct devlink_trap_policer *policer = &policers[i]; const struct devlink_trap_policer *policer = &policers[i];
...@@ -11934,35 +12011,74 @@ devlink_trap_policers_register(struct devlink *devlink, ...@@ -11934,35 +12011,74 @@ devlink_trap_policers_register(struct devlink *devlink,
if (err) if (err)
goto err_trap_policer_register; goto err_trap_policer_register;
} }
devl_unlock(devlink);
return 0; return 0;
err_trap_policer_register: err_trap_policer_register:
err_trap_policer_verify: err_trap_policer_verify:
for (i--; i >= 0; i--) for (i--; i >= 0; i--)
devlink_trap_policer_unregister(devlink, &policers[i]); devlink_trap_policer_unregister(devlink, &policers[i]);
return err;
}
EXPORT_SYMBOL_GPL(devl_trap_policers_register);
/**
* devlink_trap_policers_register - Register packet trap policers with devlink.
* @devlink: devlink.
* @policers: Packet trap policers.
* @policers_count: Count of provided packet trap policers.
*
* Return: Non-zero value on failure.
*
* Context: Takes and release devlink->lock <mutex>.
*/
int
devlink_trap_policers_register(struct devlink *devlink,
const struct devlink_trap_policer *policers,
size_t policers_count)
{
int err;
devl_lock(devlink);
err = devl_trap_policers_register(devlink, policers, policers_count);
devl_unlock(devlink); devl_unlock(devlink);
return err; return err;
} }
EXPORT_SYMBOL_GPL(devlink_trap_policers_register); EXPORT_SYMBOL_GPL(devlink_trap_policers_register);
/**
* devl_trap_policers_unregister - Unregister packet trap policers from devlink.
* @devlink: devlink.
* @policers: Packet trap policers.
* @policers_count: Count of provided packet trap policers.
*/
void
devl_trap_policers_unregister(struct devlink *devlink,
const struct devlink_trap_policer *policers,
size_t policers_count)
{
int i;
devl_assert_locked(devlink);
for (i = policers_count - 1; i >= 0; i--)
devlink_trap_policer_unregister(devlink, &policers[i]);
}
EXPORT_SYMBOL_GPL(devl_trap_policers_unregister);
/** /**
* devlink_trap_policers_unregister - Unregister packet trap policers from devlink. * devlink_trap_policers_unregister - Unregister packet trap policers from devlink.
* @devlink: devlink. * @devlink: devlink.
* @policers: Packet trap policers. * @policers: Packet trap policers.
* @policers_count: Count of provided packet trap policers. * @policers_count: Count of provided packet trap policers.
*
* Context: Takes and release devlink->lock <mutex>.
*/ */
void void
devlink_trap_policers_unregister(struct devlink *devlink, devlink_trap_policers_unregister(struct devlink *devlink,
const struct devlink_trap_policer *policers, const struct devlink_trap_policer *policers,
size_t policers_count) size_t policers_count)
{ {
int i;
devl_lock(devlink); devl_lock(devlink);
for (i = policers_count - 1; i >= 0; i--) devl_trap_policers_unregister(devlink, policers, policers_count);
devlink_trap_policer_unregister(devlink, &policers[i]);
devl_unlock(devlink); devl_unlock(devlink);
} }
EXPORT_SYMBOL_GPL(devlink_trap_policers_unregister); EXPORT_SYMBOL_GPL(devlink_trap_policers_unregister);
......
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