[PATCH v4 5/5] firmware: arm_scmi: Reset counters

Luke Parkin luke.parkin at arm.com
Tue Jul 30 02:33:42 PDT 2024


Allow writing to atomics to reset
Create reset_all counters debugfs file to reset all counters

Signed-off-by: Luke Parkin <luke.parkin at arm.com>
---
v3->v4
Use basic writing to allow any number to be set rather than forcing
	a set to 0
---
 drivers/firmware/arm_scmi/driver.c | 45 +++++++++++++++++++++---------
 1 file changed, 32 insertions(+), 13 deletions(-)

diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index ec6434692d1a..9e8720c27d51 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -2847,6 +2847,24 @@ static int scmi_device_request_notifier(struct notifier_block *nb,
 	return NOTIFY_OK;
 }
 
+static ssize_t reset_all_on_write(struct file *filp, const char __user *buf,
+				  size_t count, loff_t *ppos)
+{
+	struct scmi_debug_info *dbg = filp->private_data;
+
+	for (int i = 0; i < SCMI_DEBUG_COUNTERS_LAST; i++)
+		atomic_set(&dbg->counters[i], 0);
+
+	return count;
+}
+
+static const struct file_operations fops_reset_counts = {
+	.owner = THIS_MODULE,
+	.open = simple_open,
+	.llseek = no_llseek,
+	.write = reset_all_on_write,
+};
+
 static void scmi_debugfs_counters_setup(struct scmi_debug_info *dbg,
 					struct dentry *trans)
 {
@@ -2854,32 +2872,33 @@ static void scmi_debugfs_counters_setup(struct scmi_debug_info *dbg,
 
 	counters = debugfs_create_dir("counters", trans);
 
-	debugfs_create_atomic_t("sent_ok", 0400, counters,
+	debugfs_create_atomic_t("sent_ok", 0600, counters,
 				&dbg->counters[SENT_OK]);
-	debugfs_create_atomic_t("sent_fail", 0400, counters,
+	debugfs_create_atomic_t("sent_fail", 0600, counters,
 				&dbg->counters[SENT_FAIL]);
-	debugfs_create_atomic_t("sent_fail_polling_unsupported", 0400, counters,
+	debugfs_create_atomic_t("sent_fail_polling_unsupported", 0600, counters,
 				&dbg->counters[SENT_FAIL_POLLING_UNSUPPORTED]);
-	debugfs_create_atomic_t("sent_fail_channel_not_found", 0400, counters,
+	debugfs_create_atomic_t("sent_fail_channel_not_found", 0600, counters,
 				&dbg->counters[SENT_FAIL_CHANNEL_NOT_FOUND]);
-	debugfs_create_atomic_t("response_ok", 0400, counters,
+	debugfs_create_atomic_t("response_ok", 0600, counters,
 				&dbg->counters[RESPONSE_OK]);
-	debugfs_create_atomic_t("notif_ok", 0400, counters,
+	debugfs_create_atomic_t("notif_ok", 0600, counters,
 				&dbg->counters[NOTIF_OK]);
-	debugfs_create_atomic_t("dlyd_resp_ok", 0400, counters,
+	debugfs_create_atomic_t("dlyd_resp_ok", 0600, counters,
 				&dbg->counters[DLYD_RESPONSE_OK]);
-	debugfs_create_atomic_t("xfers_resp_timeout", 0400, counters,
+	debugfs_create_atomic_t("xfers_resp_timeout", 0600, counters,
 				&dbg->counters[XFERS_RESPONSE_TIMEOUT]);
-	debugfs_create_atomic_t("response_polled_ok", 0400, counters,
+	debugfs_create_atomic_t("response_polled_ok", 0600, counters,
 				&dbg->counters[RESPONSE_POLLED_OK]);
-	debugfs_create_atomic_t("err_msg_unexpected", 0400, counters,
+	debugfs_create_atomic_t("err_msg_unexpected", 0600, counters,
 				&dbg->counters[ERR_MSG_UNEXPECTED]);
-	debugfs_create_atomic_t("err_msg_invalid", 0400, counters,
+	debugfs_create_atomic_t("err_msg_invalid", 0600, counters,
 				&dbg->counters[ERR_MSG_INVALID]);
-	debugfs_create_atomic_t("err_msg_nomem", 0400, counters,
+	debugfs_create_atomic_t("err_msg_nomem", 0600, counters,
 				&dbg->counters[ERR_MSG_NOMEM]);
-	debugfs_create_atomic_t("err_protocol", 0400, counters,
+	debugfs_create_atomic_t("err_protocol", 0600, counters,
 				&dbg->counters[ERR_PROTOCOL]);
+	debugfs_create_file("reset", 0200, counters, dbg, &fops_reset_counts);
 }
 
 static void scmi_debugfs_common_cleanup(void *d)
-- 
2.34.1




More information about the linux-arm-kernel mailing list