Skip to content

Commit 77069ba

Browse files
Moshe Shemeshkuba-moo
authored andcommitted
devlink: Add remote reload stats
Add remote reload stats to hold the history of actions performed due devlink reload commands initiated by remote host. For example, in case firmware activation with reset finished successfully but was initiated by remote host. The function devlink_remote_reload_actions_performed() is exported to enable drivers update on remote reload actions performed as it was not initiated by their own devlink instance. Expose devlink remote reload stats to the user through devlink dev get command. Examples: $ devlink dev show pci/0000:82:00.0: stats: reload: driver_reinit 2 fw_activate 1 fw_activate_no_reset 0 remote_reload: driver_reinit 0 fw_activate 0 fw_activate_no_reset 0 pci/0000:82:00.1: stats: reload: driver_reinit 1 fw_activate 0 fw_activate_no_reset 0 remote_reload: driver_reinit 1 fw_activate 1 fw_activate_no_reset 0 $ devlink dev show -jp { "dev": { "pci/0000:82:00.0": { "stats": { "reload": { "driver_reinit": 2, "fw_activate": 1, "fw_activate_no_reset": 0 }, "remote_reload": { "driver_reinit": 0, "fw_activate": 0, "fw_activate_no_reset": 0 } } }, "pci/0000:82:00.1": { "stats": { "reload": { "driver_reinit": 1, "fw_activate": 0, "fw_activate_no_reset": 0 }, "remote_reload": { "driver_reinit": 1, "fw_activate": 1, "fw_activate_no_reset": 0 } } } } } Signed-off-by: Moshe Shemesh <moshe@mellanox.com> Reviewed-by: Jakub Kicinski <kuba@kernel.org> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent a254c26 commit 77069ba

3 files changed

Lines changed: 59 additions & 6 deletions

File tree

‎include/net/devlink.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
struct devlink_dev_stats {
2727
u32 reload_stats[DEVLINK_RELOAD_STATS_ARRAY_SIZE];
28+
u32 remote_reload_stats[DEVLINK_RELOAD_STATS_ARRAY_SIZE];
2829
};
2930

3031
struct devlink_ops;
@@ -1567,6 +1568,9 @@ void
15671568
devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
15681569

15691570
bool devlink_is_reload_failed(const struct devlink *devlink);
1571+
void devlink_remote_reload_actions_performed(struct devlink *devlink,
1572+
enum devlink_reload_limit limit,
1573+
u32 actions_performed);
15701574

15711575
void devlink_flash_update_begin_notify(struct devlink *devlink);
15721576
void devlink_flash_update_end_notify(struct devlink *devlink);

‎include/uapi/linux/devlink.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ enum devlink_attr {
525525
DEVLINK_ATTR_RELOAD_STATS_ENTRY, /* nested */
526526
DEVLINK_ATTR_RELOAD_STATS_LIMIT, /* u8 */
527527
DEVLINK_ATTR_RELOAD_STATS_VALUE, /* u32 */
528+
DEVLINK_ATTR_REMOTE_RELOAD_STATS, /* nested */
528529

529530
/* add new attributes above here, update the policy in devlink.c */
530531

‎net/core/devlink.c‎

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,28 +538,39 @@ static int devlink_reload_stat_put(struct sk_buff *msg, enum devlink_reload_acti
538538
return -EMSGSIZE;
539539
}
540540

541-
static int devlink_reload_stats_put(struct sk_buff *msg, struct devlink *devlink)
541+
static int devlink_reload_stats_put(struct sk_buff *msg, struct devlink *devlink, bool is_remote)
542542
{
543543
struct nlattr *reload_stats_attr;
544544
int i, j, stat_idx;
545545
u32 value;
546546

547-
reload_stats_attr = nla_nest_start(msg, DEVLINK_ATTR_RELOAD_STATS);
547+
if (!is_remote)
548+
reload_stats_attr = nla_nest_start(msg, DEVLINK_ATTR_RELOAD_STATS);
549+
else
550+
reload_stats_attr = nla_nest_start(msg, DEVLINK_ATTR_REMOTE_RELOAD_STATS);
548551

549552
if (!reload_stats_attr)
550553
return -EMSGSIZE;
551554

552555
for (j = 0; j <= DEVLINK_RELOAD_LIMIT_MAX; j++) {
553-
if (j != DEVLINK_RELOAD_LIMIT_UNSPEC &&
556+
/* Remote stats are shown even if not locally supported. Stats
557+
* of actions with unspecified limit are shown though drivers
558+
* don't need to register unspecified limit.
559+
*/
560+
if (!is_remote && j != DEVLINK_RELOAD_LIMIT_UNSPEC &&
554561
!devlink_reload_limit_is_supported(devlink, j))
555562
continue;
556563
for (i = 0; i <= DEVLINK_RELOAD_ACTION_MAX; i++) {
557-
if (!devlink_reload_action_is_supported(devlink, i) ||
564+
if ((!is_remote && !devlink_reload_action_is_supported(devlink, i)) ||
565+
i == DEVLINK_RELOAD_ACTION_UNSPEC ||
558566
devlink_reload_combination_is_invalid(i, j))
559567
continue;
560568

561569
stat_idx = j * __DEVLINK_RELOAD_ACTION_MAX + i;
562-
value = devlink->stats.reload_stats[stat_idx];
570+
if (!is_remote)
571+
value = devlink->stats.reload_stats[stat_idx];
572+
else
573+
value = devlink->stats.remote_reload_stats[stat_idx];
563574
if (devlink_reload_stat_put(msg, i, j, value))
564575
goto nla_put_failure;
565576
}
@@ -592,7 +603,9 @@ static int devlink_nl_fill(struct sk_buff *msg, struct devlink *devlink,
592603
if (!dev_stats)
593604
goto nla_put_failure;
594605

595-
if (devlink_reload_stats_put(msg, devlink))
606+
if (devlink_reload_stats_put(msg, devlink, false))
607+
goto dev_stats_nest_cancel;
608+
if (devlink_reload_stats_put(msg, devlink, true))
596609
goto dev_stats_nest_cancel;
597610

598611
nla_nest_end(msg, dev_stats);
@@ -3110,15 +3123,47 @@ devlink_reload_stats_update(struct devlink *devlink, enum devlink_reload_limit l
31103123
actions_performed);
31113124
}
31123125

3126+
/**
3127+
* devlink_remote_reload_actions_performed - Update devlink on reload actions
3128+
* performed which are not a direct result of devlink reload call.
3129+
*
3130+
* This should be called by a driver after performing reload actions in case it was not
3131+
* a result of devlink reload call. For example fw_activate was performed as a result
3132+
* of devlink reload triggered fw_activate on another host.
3133+
* The motivation for this function is to keep data on reload actions performed on this
3134+
* function whether it was done due to direct devlink reload call or not.
3135+
*
3136+
* @devlink: devlink
3137+
* @limit: reload limit
3138+
* @actions_performed: bitmask of actions performed
3139+
*/
3140+
void devlink_remote_reload_actions_performed(struct devlink *devlink,
3141+
enum devlink_reload_limit limit,
3142+
u32 actions_performed)
3143+
{
3144+
if (WARN_ON(!actions_performed ||
3145+
actions_performed & BIT(DEVLINK_RELOAD_ACTION_UNSPEC) ||
3146+
actions_performed >= BIT(__DEVLINK_RELOAD_ACTION_MAX) ||
3147+
limit > DEVLINK_RELOAD_LIMIT_MAX))
3148+
return;
3149+
3150+
__devlink_reload_stats_update(devlink, devlink->stats.remote_reload_stats, limit,
3151+
actions_performed);
3152+
}
3153+
EXPORT_SYMBOL_GPL(devlink_remote_reload_actions_performed);
3154+
31133155
static int devlink_reload(struct devlink *devlink, struct net *dest_net,
31143156
enum devlink_reload_action action, enum devlink_reload_limit limit,
31153157
u32 *actions_performed, struct netlink_ext_ack *extack)
31163158
{
3159+
u32 remote_reload_stats[DEVLINK_RELOAD_STATS_ARRAY_SIZE];
31173160
int err;
31183161

31193162
if (!devlink->reload_enabled)
31203163
return -EOPNOTSUPP;
31213164

3165+
memcpy(remote_reload_stats, devlink->stats.remote_reload_stats,
3166+
sizeof(remote_reload_stats));
31223167
err = devlink->ops->reload_down(devlink, !!dest_net, action, limit, extack);
31233168
if (err)
31243169
return err;
@@ -3132,6 +3177,9 @@ static int devlink_reload(struct devlink *devlink, struct net *dest_net,
31323177
return err;
31333178

31343179
WARN_ON(!(*actions_performed & BIT(action)));
3180+
/* Catch driver on updating the remote action within devlink reload */
3181+
WARN_ON(memcmp(remote_reload_stats, devlink->stats.remote_reload_stats,
3182+
sizeof(remote_reload_stats)));
31353183
devlink_reload_stats_update(devlink, limit, *actions_performed);
31363184
return 0;
31373185
}

0 commit comments

Comments
 (0)