[PATCH v3 0/6] watchdog: report effective timeout

Juuso Rinta <[email protected]>
Newsgroups org.u-boot-project.lists.u-boot
Message-ID <[email protected]>
This series provides a fix for the wdt_start() function, which can
print incorrect timeout values in cases where the function is
called with a timeout value greater than the hardware-supported
maximum. The current implementation prints the requested value, so,
for example, the console may show that the watchdog timeout is set to
60 seconds when it is in practice clamped to 10 seconds by the device.

The series introduces the max_timeout_ms value into the per-device
uclass-plat data. By default, this value is initialized to 0, and
drivers should write the hardware-limited max_timeout_ms value into
the plat-data typically during probing.

If the driver has reported a max_timeout_ms value, wdt_start() clamps
the requested timeout_ms value before calling ops->start(). The default
value 0 is considered "limitless", i.e. on drivers that do not set the
value, the prints and the functionality are unaffected by this series.

The series implements this support in sbsa_gwdt, octeontx_wdt and
sandbox_wdt drivers.

This fix improves the overall correctness of the console output and
can be helpful in debugging cases, since the console prints reflect the
real timeout on the device when the driver supports the feature.
If it is unsupported on the device, the print remains as it was before.

Patch summary:
- Patch 1: Cleanup wdt_start() as a preparation for patch 2. Rename existing
str to svc_str, replace memset with svc_str[0] = '\0' and use sizeof(svc_str)
in the snprintf instead of the hardcoded magic number.
- Patch 2: Add per_device_plat_auto to the wdt uclass and a max_timeout_ms
field in a new wdt_uc_plat struct. wdt_start() uses the field to clamp the
requested timeout and report the effective (clamped) timeout when the originally
requested value is greater than the reported maximum value.
- Patch 3: Set max_timeout_ms in sbsa_gwdt_probe()
- Patch 4: Set max_timeout_ms in octeontx_wdt_probe()
- Patch 5: Set max_timeout_ms in sandbox_wdt_probe()
- Patch 6: Add a DM test for clamped and unclamped cases.

Signed-off-by: Juuso Rinta <[email protected]>
---
Changes in v3:
- Split the wdt_start() str -> svc_str cleanup into its own patch
- Clamp timeout_ms in wdt_start() before ops->start() when the driver
has set max_timeout_ms
- octeontx_wdt_probe(): calculate max_timeout_ms with the same u64 division
as octeontx_wdt_start()
- Drop the extra clamp in sandbox_wdt_start()
- Tests match a fixed start line instead of reconstructing it, and
cover the sub-second clamp case
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Reworked approach. Dropped the get_timeout operation and switched to
per-device uclass-plat data (max_timeout_ms) for reporting effective
timeout in wdt_start().
- Added struct wdt_uc_plat and .per_device_plat_auto in the WDT uclass.
max_timeout_ms = 0 is treated as no driver-reported limit.
- Dropped the wdt gettimeout subcommand changes from v1.
- Updated sbsa_gwdt, octeontx_wdt and sandbox_wdt drivers to set 
max_timeout_ms in probe.
- Extended sandbox_wdt for testability by adding an emulated max timeout
and clamp path.
- Reworked DM tests to cover unclamped and clamped startup print paths, as
well as max_timeout_ms set/not-set behavior
- Minor cleanup in wdt_start() string handling
- Link to v1: https://patch.msgid.link/[email protected]

To: [email protected]
To: [email protected]
Cc: Stefan Roese <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Peng Fan <[email protected]>
Cc: Yao Zi <[email protected]>
Cc: Juuso Rinta <[email protected]>
Cc: Antonio Borneo <[email protected]>
Cc: Aaro Koskinen <[email protected]>
Cc: Simon Glass <[email protected]>

---
Juuso Rinta (6):
      watchdog: wdt-uclass: rename str to svc_str in wdt_start()
      watchdog: wdt-uclass: report effective timeout in start print
      watchdog: sbsa_gwdt: set max_timeout_ms in probe
      watchdog: octeontx_wdt: set max_timeout_ms in probe
      watchdog: sandbox_wdt: set max_timeout_ms in probe
      test: wdt: add a test for max_timeout_ms

 arch/sandbox/include/asm/state.h |  2 ++
 drivers/watchdog/octeontx_wdt.c  | 16 ++++++++++++++
 drivers/watchdog/sandbox_wdt.c   | 11 ++++++++++
 drivers/watchdog/sbsa_gwdt.c     | 12 ++++++++++
 drivers/watchdog/wdt-uclass.c    | 30 ++++++++++++++++++++-----
 include/wdt.h                    | 11 ++++++++++
 test/dm/wdt.c                    | 47 ++++++++++++++++++++++++++++++++++++----
 7 files changed, 120 insertions(+), 9 deletions(-)
---
base-commit: 1b8283bd3220e898d338fb98929f0b06ed63da84
change-id: 20260427-rinta-watchdog-gettime-6ae2e0a76983

Best regards,
--  
Juuso Rinta <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.