2023-11-21 11:23:29

by Ronak Jain

[permalink] [raw]
Subject: [PATCH 0/2] Add support for last reset reason

Add support to get the last reset reason using IOCTL API and sysfs
usage. Accordingly, the end user can know the reason behind the last
system reset by querying the IOCTL API or the sysfs interface.

Ronak Jain (2):
firmware: xilinx: Add support for GET_LAST_RESET_REASON IOCTL
xilinx: firmware: Add sysfs to get last reset reason

.../ABI/stable/sysfs-driver-firmware-zynqmp | 13 ++++++
drivers/firmware/xilinx/zynqmp.c | 43 +++++++++++++++++++
include/linux/firmware/xlnx-zynqmp.h | 19 ++++++++
3 files changed, 75 insertions(+)

--
2.25.1


2023-11-21 11:23:31

by Ronak Jain

[permalink] [raw]
Subject: [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reason

Add sysfs interface to get the last reset reason of the system from
a user space.

When the system reset happens whether intentionally or due to some
errors, the firmware used to store the last reset reason and the same
be queried by using the IOCTL API or the sysfs entry to know the
reason behind the system reset and accordingly, the error can be
diagnostic.

Signed-off-by: Ronak Jain <[email protected]>
---
.../ABI/stable/sysfs-driver-firmware-zynqmp | 13 +++++++
drivers/firmware/xilinx/zynqmp.c | 36 +++++++++++++++++++
include/linux/firmware/xlnx-zynqmp.h | 11 ++++++
3 files changed, 60 insertions(+)

diff --git a/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp b/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp
index c3fec3c835af..77ae69870767 100644
--- a/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp
+++ b/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp
@@ -254,3 +254,16 @@ Description:
The expected result is 500.

Users: Xilinx
+
+What: /sys/devices/platform/firmware\:zynqmp-firmware/last_reset_reason
+Date: Nov 2023
+KernelVersion: 6.7
+Contact: "Ronak Jain" <[email protected]>
+Description:
+ This sysfs interface allows to get last reset reason.
+
+ Usage:
+ Get last reset reason
+ # cat /sys/devices/platform/firmware\:zynqmp-firmware/last_reset_reason
+
+Users: Xilinx
diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
index 5815d1e94407..8f49861ebbb3 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -1902,6 +1902,41 @@ static ssize_t feature_config_value_store(struct device *device,

static DEVICE_ATTR_RW(feature_config_value);

+static ssize_t last_reset_reason_show(struct device *device,
+ struct device_attribute *attr,
+ char *buf)
+{
+ u32 ret_payload[PAYLOAD_ARG_CNT];
+ int ret;
+
+ ret = zynqmp_pm_get_last_reset_reason(ret_payload);
+ if (ret)
+ return ret;
+
+ switch (ret_payload[1]) {
+ case PM_RESET_REASON_EXT_POR:
+ return sprintf(buf, "ext_por\n");
+ case PM_RESET_REASON_SW_POR:
+ return sprintf(buf, "sw_por\n");
+ case PM_RESET_REASON_SLR_POR:
+ return sprintf(buf, "slr_por\n");
+ case PM_RESET_REASON_ERR_POR:
+ return sprintf(buf, "err_por\n");
+ case PM_RESET_REASON_DAP_SRST:
+ return sprintf(buf, "dap_srst\n");
+ case PM_RESET_REASON_ERR_SRST:
+ return sprintf(buf, "err_srst\n");
+ case PM_RESET_REASON_SW_SRST:
+ return sprintf(buf, "sw_srst\n");
+ case PM_RESET_REASON_SLR_SRST:
+ return sprintf(buf, "slr_srst\n");
+ default:
+ return sprintf(buf, "unknown reset\n");
+ }
+}
+
+static DEVICE_ATTR_RO(last_reset_reason);
+
static struct attribute *zynqmp_firmware_attrs[] = {
&dev_attr_ggs0.attr,
&dev_attr_ggs1.attr,
@@ -1915,6 +1950,7 @@ static struct attribute *zynqmp_firmware_attrs[] = {
&dev_attr_health_status.attr,
&dev_attr_feature_config_id.attr,
&dev_attr_feature_config_value.attr,
+ &dev_attr_last_reset_reason.attr,
NULL,
};

diff --git a/include/linux/firmware/xlnx-zynqmp.h b/include/linux/firmware/xlnx-zynqmp.h
index 2d8c5e88391b..6d4015b6d964 100644
--- a/include/linux/firmware/xlnx-zynqmp.h
+++ b/include/linux/firmware/xlnx-zynqmp.h
@@ -497,6 +497,17 @@ enum pm_gem_config_type {
GEM_CONFIG_FIXED = 2,
};

+enum pm_reset_reason {
+ PM_RESET_REASON_EXT_POR = 0,
+ PM_RESET_REASON_SW_POR = 1,
+ PM_RESET_REASON_SLR_POR = 2,
+ PM_RESET_REASON_ERR_POR = 3,
+ PM_RESET_REASON_DAP_SRST = 7,
+ PM_RESET_REASON_ERR_SRST = 8,
+ PM_RESET_REASON_SW_SRST = 9,
+ PM_RESET_REASON_SLR_SRST = 10,
+};
+
/**
* struct zynqmp_pm_query_data - PM query data
* @qid: query ID
--
2.25.1

2023-11-21 12:33:26

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reason

On Tue, Nov 21, 2023, at 12:20, Ronak Jain wrote:
> Add sysfs interface to get the last reset reason of the system from
> a user space.
>
> When the system reset happens whether intentionally or due to some
> errors, the firmware used to store the last reset reason and the same
> be queried by using the IOCTL API or the sysfs entry to know the
> reason behind the system reset and accordingly, the error can be
> diagnostic.
>
> Signed-off-by: Ronak Jain <[email protected]>

I'm fairly sure we already have other interfaces to access
the reset reason, please see if you can either reuse one
of the existing ones, or come up with a generic one that
can be used by others as well.

Arnd

2023-11-29 11:53:37

by Ronak Jain

[permalink] [raw]
Subject: RE: [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reason

Hi Arnd,

> -----Original Message-----
> From: Arnd Bergmann <[email protected]>
> Sent: Tuesday, November 21, 2023 6:01 PM
> To: Jain, Ronak <[email protected]>; Simek, Michal
> <[email protected]>; Greg Kroah-Hartman
> <[email protected]>; Linus Walleij <[email protected]>;
> Potthuri, Sai Krishna <[email protected]>; Shah, Tanmay
> <[email protected]>; Levinsky, Ben <[email protected]>; Manne,
> Nava kishore <[email protected]>; Rob Herring
> <[email protected]>; [email protected]; Marek Vasut
> <[email protected]>; Roman Gushchin <[email protected]>; Mathieu
> Poirier <[email protected]>; Datta, Shubhrajyoti
> <[email protected]>
> Cc: [email protected]
> Subject: Re: [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reason
>
> On Tue, Nov 21, 2023, at 12:20, Ronak Jain wrote:
> > Add sysfs interface to get the last reset reason of the system from
> > a user space.
> >
> > When the system reset happens whether intentionally or due to some
> > errors, the firmware used to store the last reset reason and the same
> > be queried by using the IOCTL API or the sysfs entry to know the
> > reason behind the system reset and accordingly, the error can be
> > diagnostic.
> >
> > Signed-off-by: Ronak Jain <[email protected]>
>
> I'm fairly sure we already have other interfaces to access
> the reset reason, please see if you can either reuse one
> of the existing ones, or come up with a generic one that
> can be used by others as well.
Could you please provide more information regarding the interface you're talking about?

Thanks,
Ronak
>
> Arnd