Drivers may need to reset per-device PSP statistics to zero.
Add a reset-stats netlink command and a corresponding optional
driver callback to support this.
Signed-off-by: Akhilesh Samineni <akhilesh.samineni@broadcom.com>
Reviewed-by: Kiran Kella <kiran.kella@broadcom.com>
Reviewed-by: Ajit Kumar Khaparde <ajit.khaparde@broadcom.com>
---
Documentation/netlink/specs/psp.yaml | 13 +++++++++++++
include/net/psp/types.h | 6 ++++++
include/uapi/linux/psp.h | 1 +
net/psp/psp-nl-gen.c | 14 ++++++++++++++
net/psp/psp-nl-gen.h | 1 +
net/psp/psp_nl.c | 24 ++++++++++++++++++++++++
6 files changed, 59 insertions(+)
diff --git a/Documentation/netlink/specs/psp.yaml b/Documentation/netlink/specs/psp.yaml
index f3a57782d2cf..e37ca142af54 100644
--- a/Documentation/netlink/specs/psp.yaml
+++ b/Documentation/netlink/specs/psp.yaml
@@ -272,6 +272,19 @@ operations:
dump:
reply: *stats-all
+ -
+ name: reset-stats
+ doc: Reset device statistics.
+ attribute-set: dev
+ do:
+ request:
+ attributes:
+ - id
+ reply:
+ attributes: []
+ pre: psp-device-get-locked
+ post: psp-device-unlock
+
mcast-groups:
list:
-
diff --git a/include/net/psp/types.h b/include/net/psp/types.h
index 25a9096d4e7d..7f9924e8ab0d 100644
--- a/include/net/psp/types.h
+++ b/include/net/psp/types.h
@@ -211,6 +211,12 @@ struct psp_dev_ops {
* Stats must be filled in member-by-member, never memset the struct.
*/
void (*get_stats)(struct psp_dev *psd, struct psp_dev_stats *stats);
+
+ /**
+ * @reset_stats: reset the statistics
+ */
+ int (*reset_stats)(struct psp_dev *psd, struct netlink_ext_ack *extack);
+
};
#endif /* __NET_PSP_H */
diff --git a/include/uapi/linux/psp.h b/include/uapi/linux/psp.h
index a3a336488dc3..6e0c217a8366 100644
--- a/include/uapi/linux/psp.h
+++ b/include/uapi/linux/psp.h
@@ -74,6 +74,7 @@ enum {
PSP_CMD_RX_ASSOC,
PSP_CMD_TX_ASSOC,
PSP_CMD_GET_STATS,
+ PSP_CMD_RESET_STATS,
__PSP_CMD_MAX,
PSP_CMD_MAX = (__PSP_CMD_MAX - 1)
diff --git a/net/psp/psp-nl-gen.c b/net/psp/psp-nl-gen.c
index 22a48d0fa378..c8691f7a61ce 100644
--- a/net/psp/psp-nl-gen.c
+++ b/net/psp/psp-nl-gen.c
@@ -53,6 +53,11 @@ static const struct nla_policy psp_get_stats_nl_policy[PSP_A_STATS_DEV_ID + 1] =
[PSP_A_STATS_DEV_ID] = NLA_POLICY_MIN(NLA_U32, 1),
};
+/* PSP_CMD_RESET_STATS - do */
+static const struct nla_policy psp_reset_stats_nl_policy[PSP_A_DEV_ID + 1] = {
+ [PSP_A_DEV_ID] = NLA_POLICY_MIN(NLA_U32, 1),
+};
+
/* Ops table for psp */
static const struct genl_split_ops psp_nl_ops[] = {
{
@@ -119,6 +124,15 @@ static const struct genl_split_ops psp_nl_ops[] = {
.dumpit = psp_nl_get_stats_dumpit,
.flags = GENL_CMD_CAP_DUMP,
},
+ {
+ .cmd = PSP_CMD_RESET_STATS,
+ .pre_doit = psp_device_get_locked,
+ .doit = psp_nl_reset_stats_doit,
+ .post_doit = psp_device_unlock,
+ .policy = psp_reset_stats_nl_policy,
+ .maxattr = PSP_A_DEV_ID,
+ .flags = GENL_CMD_CAP_DO,
+ },
};
static const struct genl_multicast_group psp_nl_mcgrps[] = {
diff --git a/net/psp/psp-nl-gen.h b/net/psp/psp-nl-gen.h
index 599c5f1c82f2..67577c898f99 100644
--- a/net/psp/psp-nl-gen.h
+++ b/net/psp/psp-nl-gen.h
@@ -31,6 +31,7 @@ int psp_nl_rx_assoc_doit(struct sk_buff *skb, struct genl_info *info);
int psp_nl_tx_assoc_doit(struct sk_buff *skb, struct genl_info *info);
int psp_nl_get_stats_doit(struct sk_buff *skb, struct genl_info *info);
int psp_nl_get_stats_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
+int psp_nl_reset_stats_doit(struct sk_buff *skb, struct genl_info *info);
enum {
PSP_NLGRP_MGMT,
diff --git a/net/psp/psp_nl.c b/net/psp/psp_nl.c
index 6afd7707ec12..aa8960c8d4d1 100644
--- a/net/psp/psp_nl.c
+++ b/net/psp/psp_nl.c
@@ -277,6 +277,27 @@ int psp_nl_key_rotate_doit(struct sk_buff *skb, struct genl_info *info)
return err;
}
+int psp_nl_reset_stats_doit(struct sk_buff *skb, struct genl_info *info)
+{
+ struct psp_dev *psd = info->user_ptr[0];
+ struct sk_buff *rsp;
+ int err;
+
+ if (!psd->ops->reset_stats)
+ return -EOPNOTSUPP;
+
+ rsp = psp_nl_reply_new(info);
+ if (!rsp)
+ return -ENOMEM;
+
+ err = psd->ops->reset_stats(psd, info->extack);
+ if (err)
+ goto err_free_rsp;
+
+ return psp_nl_reply_send(rsp, info);
+
+err_free_rsp:
+ nlmsg_free(rsp);
+ return err;
+}
+
/* Key etc. */
int psp_assoc_device_get_locked(const struct genl_split_ops *ops,
--
2.45.4
Akhilesh Samineni wrote: > Drivers may need to reset per-device PSP statistics to zero. The series does not include rationale why this may be needed. What makes PSP counters special in this regard? > Add a reset-stats netlink command and a corresponding optional > driver callback to support this. > > Signed-off-by: Akhilesh Samineni <akhilesh.samineni@broadcom.com> > Reviewed-by: Kiran Kella <kiran.kella@broadcom.com> > Reviewed-by: Ajit Kumar Khaparde <ajit.khaparde@broadcom.com>
© 2016 - 2026 Red Hat, Inc.