Skip to contentSkip to conversation

Intel Keem Bay WDT bug fixes

PATCH In review [email protected] 3 participants 13 messages May 17, 2021 – May 24, 2021 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

v2 cover Intel Keem Bay WDT bug fixes

From: Shruthi Sanil <[email protected]>

The series of patches include the below bug fixes
in the Intel Keem Bay watchdog timer driver:

Patch 1/9:
- Update WDT pre-timeout during the initialization
The pretimeout register has a default reset value. Hence when a smaller WDT timeout is set which would be lesser than the default pretimeout, the system behaves abnormally, starts triggering the pretimeout interrupt even when the WDT is not enabled, most of the times leading to system crash. Hence an update in the pre-timeout is also required for the default timeout that is being configured.

Patch 2/9:
- Upadate WDT pretimeout for every update in timeout The pre-timeout value to be programmed to the register has to be calculated and updated for every change in the timeout value. Else the threshold time wouldn't be calculated to its corresponding timeout.

Patch 3/9:
- Update pretimeout to 0 in the TH ISR
The pretimeout has to be updated to 0 during the ISR of the ThresHold interrupt. Else the TH interrupt would be triggerred for every tick until the timeout.

Patch 4/9:
- Clear either the TO or TH interrupt bit
During the interrupt service routine of the TimeOut interrupt and the ThresHold interrupt, the respective interrupt clear bit have to be cleared and not both.

Patch 5/9:
- Remove timeout update in the WDT start function
Removed set timeout from the start WDT function. There is a function defined to set the timeout. Hence no need to set the timeout again in start function as the timeout would have been already updated before calling the start/enable.

Patch 6/9:
- Removed timeout update in the TO ISR
In the TO ISR removed updating the Timeout value because its not serving any purpose as the timer would have already expired and the system would be rebooting.

Patch 7/9:
- MACRO for WDT enable and disable values
Introduced MACRO's for WDT enable and disable values for better readability

Patch 8/9:
- WDT SMC handler MACRO name update
Updated the WDT SMC handler MACRO name to make it clear that its a ARM SMC handler that helps in clearing the WDT interrupt bit.

Patch 9/9:
- Typo corrections and other blank operations Corrected typos, aligned the tabs and added new lines wherever required for better readability

Changes since v1:
- Dropped a patch with the incorrect fix
regarding the WDT suspend/resume function.

Shruthi Sanil (9):
watchdog: keembay: Update WDT pre-timeout during the initialization
watchdog: keembay: Upadate WDT pretimeout for every update in timeout
watchdog: keembay: Update pretimeout to zero in the TH ISR
watchdog: keembay: Clear either the TO or TH interrupt bit
watchdog: keembay: Remove timeout update in the WDT start function
watchdog: keembay: Removed timeout update in the TO ISR
watchdog: keembay: MACRO for WDT enable and disable values
watchdog: keembay: WDT SMC handler MACRO name update
watchdog: keembay: Typo corrections and other blank operations

 drivers/watchdog/keembay_wdt.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

base-commit: 88b06399c9c766c283e070b022b5ceafa4f63f19

Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/9 watchdog: keembay: Update WDT pre-timeout during the initialization

From: Shruthi Sanil <[email protected]>

The pretimeout register has a default reset value. Hence when a smaller WDT timeout is set which would be lesser than the default pretimeout, the system behaves abnormally, starts triggering the pretimeout interrupt even when the WDT is not enabled, most of the times leading to system crash. Hence an update in the pre-timeout is also required for the default timeout that is being configured.

Fixes fa0f8d51e90d ("watchdog: Add watchdog driver for Intel Keembay Soc")
---
 drivers/watchdog/keembay_wdt.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/watchdog/keembay_wdt.c +3 -0
index 547d3fea33ff..f2f5c9fae29c 100644
@@ -29,6 +29,7 @@
 #define WDT_LOAD_MAX		U32_MAX
 #define WDT_LOAD_MIN		1
 #define WDT_TIMEOUT		5
+#define WDT_PRETIMEOUT		4
 
 static unsigned int timeout = WDT_TIMEOUT;
 module_param(timeout, int, 0);
@@ -224,11 +225,13 @@ static int keembay_wdt_probe(struct platform_device *pdev)
 	wdt->wdd.min_timeout	= WDT_LOAD_MIN;
 	wdt->wdd.max_timeout	= WDT_LOAD_MAX / wdt->rate;
 	wdt->wdd.timeout	= WDT_TIMEOUT;
+	wdt->wdd.pretimeout	= WDT_PRETIMEOUT;
 
 	watchdog_set_drvdata(&wdt->wdd, wdt);
 	watchdog_set_nowayout(&wdt->wdd, nowayout);
 	watchdog_init_timeout(&wdt->wdd, timeout, dev);
 	keembay_wdt_set_timeout(&wdt->wdd, wdt->wdd.timeout);
+	keembay_wdt_set_pretimeout(&wdt->wdd, wdt->wdd.pretimeout);
 
 	ret = devm_watchdog_register_device(dev, &wdt->wdd);
 	if (ret)
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 2/9 watchdog: keembay: Upadate WDT pretimeout for every update in timeout

In reply to [email protected]

From: Shruthi Sanil <[email protected]>

The pre-timeout value to be programmed to the register has to be calculated and updated for every change in the timeout value. Else the threshold time wouldn't be calculated to its corresponding timeout.

Fixes fa0f8d51e90d ("watchdog: Add watchdog driver for Intel Keembay Soc")
---
 drivers/watchdog/keembay_wdt.c | 1 +
 1 file changed, 1 insertion(+)
drivers/watchdog/keembay_wdt.c +1 -0
index f2f5c9fae29c..b2afeb4a60e3 100644
@@ -109,6 +109,7 @@ static int keembay_wdt_set_timeout(struct watchdog_device *wdog, u32 t)
 {
 	wdog->timeout = t;
 	keembay_wdt_set_timeout_reg(wdog);
+	keembay_wdt_set_pretimeout_reg(wdog);
 
 	return 0;
 }
Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 3/9 watchdog: keembay: Update pretimeout to zero in the TH ISR

In reply to [email protected]

From: Shruthi Sanil <[email protected]>

The pretimeout has to be updated to zero during the ISR of the ThresHold interrupt. Else the TH interrupt would be triggerred for every tick until the timeout.

Fixes fa0f8d51e90d ("watchdog: Add watchdog driver for Intel Keembay Soc")
---
 drivers/watchdog/keembay_wdt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/watchdog/keembay_wdt.c +2 -0
index b2afeb4a60e3..6053416b8d3d 100644
@@ -154,6 +154,8 @@ static irqreturn_t keembay_wdt_th_isr(int irq, void *dev_id)
 	struct keembay_wdt *wdt = dev_id;
 	struct arm_smccc_res res;
 
+	keembay_wdt_set_pretimeout(&wdt->wdd, 0x0);
+
 	arm_smccc_smc(WDT_ISR_CLEAR, WDT_ISR_MASK, 0, 0, 0, 0, 0, 0, &res);
 	dev_crit(wdt->wdd.parent, "Intel Keem Bay non-sec wdt pre-timeout.\n");
 	watchdog_notify_pretimeout(&wdt->wdd);
Signature · 1 line
2.17.1
#4 lore raw

PATCH v2 4/9 watchdog: keembay: Clear either the TO or TH interrupt bit

In reply to [email protected]

From: Shruthi Sanil <[email protected]>

During the interrupt service routine of the TimeOut interrupt and the ThresHold interrupt, the respective interrupt clear bit have to be cleared and not both.

Fixes fa0f8d51e90d ("watchdog: Add watchdog driver for Intel Keembay Soc")
---
 drivers/watchdog/keembay_wdt.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/watchdog/keembay_wdt.c +4 -3
index 6053416b8d3d..f2a16c9933c3 100644
@@ -23,7 +23,8 @@
 #define TIM_WDOG_EN		0x8
 #define TIM_SAFE		0xc
 
-#define WDT_ISR_MASK		GENMASK(9, 8)
+#define WDT_TH_INT_MASK		BIT(8)
+#define WDT_TO_INT_MASK		BIT(9)
 #define WDT_ISR_CLEAR		0x8200ff18
 #define WDT_UNLOCK		0xf1d0dead
 #define WDT_LOAD_MAX		U32_MAX
@@ -142,7 +143,7 @@ static irqreturn_t keembay_wdt_to_isr(int irq, void *dev_id)
 	struct arm_smccc_res res;
 
 	keembay_wdt_writel(wdt, TIM_WATCHDOG, 1);
-	arm_smccc_smc(WDT_ISR_CLEAR, WDT_ISR_MASK, 0, 0, 0, 0, 0, 0, &res);
+	arm_smccc_smc(WDT_ISR_CLEAR, WDT_TO_INT_MASK, 0, 0, 0, 0, 0, 0, &res);
 	dev_crit(wdt->wdd.parent, "Intel Keem Bay non-sec wdt timeout.\n");
 	emergency_restart();
 
@@ -156,7 +157,7 @@ static irqreturn_t keembay_wdt_th_isr(int irq, void *dev_id)
 
 	keembay_wdt_set_pretimeout(&wdt->wdd, 0x0);
 
-	arm_smccc_smc(WDT_ISR_CLEAR, WDT_ISR_MASK, 0, 0, 0, 0, 0, 0, &res);
+	arm_smccc_smc(WDT_ISR_CLEAR, WDT_TH_INT_MASK, 0, 0, 0, 0, 0, 0, &res);
 	dev_crit(wdt->wdd.parent, "Intel Keem Bay non-sec wdt pre-timeout.\n");
 	watchdog_notify_pretimeout(&wdt->wdd);
 
Signature · 1 line
2.17.1
#5 lore raw

PATCH v2 5/9 watchdog: keembay: Remove timeout update in the WDT start function

In reply to [email protected]

From: Shruthi Sanil <[email protected]>

Removed set timeout from the start WDT function. There is a function defined to set the timeout. Hence no need to set the timeout again in start function as the timeout would have been already updated before calling the start/enable.

Fixes fa0f8d51e90d ("watchdog: Add watchdog driver for Intel Keembay Soc")
---
 drivers/watchdog/keembay_wdt.c | 1 -
 1 file changed, 1 deletion(-)
drivers/watchdog/keembay_wdt.c +0 -1
index f2a16c9933c3..039753b9932b 100644
@@ -84,7 +84,6 @@ static int keembay_wdt_start(struct watchdog_device *wdog)
 {
 	struct keembay_wdt *wdt = watchdog_get_drvdata(wdog);
 
-	keembay_wdt_set_timeout_reg(wdog);
 	keembay_wdt_writel(wdt, TIM_WDOG_EN, 1);
 
 	return 0;
Signature · 1 line
2.17.1
#6 lore raw

PATCH v2 6/9 watchdog: keembay: Removed timeout update in the TO ISR

In reply to [email protected]

From: Shruthi Sanil <[email protected]>

In the TO ISR removed updating the Timeout value because its not serving any purpose as the timer would have already expired and the system would be rebooting.

Fixes fa0f8d51e90d ("watchdog: Add watchdog driver for Intel Keembay Soc")
---
 drivers/watchdog/keembay_wdt.c | 1 -
 1 file changed, 1 deletion(-)
drivers/watchdog/keembay_wdt.c +0 -1
index 039753b9932b..dd192b8dff55 100644
@@ -141,7 +141,6 @@ static irqreturn_t keembay_wdt_to_isr(int irq, void *dev_id)
 	struct keembay_wdt *wdt = dev_id;
 	struct arm_smccc_res res;
 
-	keembay_wdt_writel(wdt, TIM_WATCHDOG, 1);
 	arm_smccc_smc(WDT_ISR_CLEAR, WDT_TO_INT_MASK, 0, 0, 0, 0, 0, 0, &res);
 	dev_crit(wdt->wdd.parent, "Intel Keem Bay non-sec wdt timeout.\n");
 	emergency_restart();
Signature · 1 line
2.17.1
#7 lore raw

PATCH v2 7/9 watchdog: keembay: MACRO for WDT enable and disable values

In reply to [email protected]

From: Shruthi Sanil <[email protected]>

Introduced MACRO's for WDT enable and disable values for better readability

---
 drivers/watchdog/keembay_wdt.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/watchdog/keembay_wdt.c +4 -2
index dd192b8dff55..d8c50b6291cd 100644
@@ -27,6 +27,8 @@
 #define WDT_TO_INT_MASK		BIT(9)
 #define WDT_ISR_CLEAR		0x8200ff18
 #define WDT_UNLOCK		0xf1d0dead
+#define WDT_DISABLE		0x0
+#define WDT_ENABLE		0x1
 #define WDT_LOAD_MAX		U32_MAX
 #define WDT_LOAD_MIN		1
 #define WDT_TIMEOUT		5
@@ -84,7 +86,7 @@ static int keembay_wdt_start(struct watchdog_device *wdog)
 {
 	struct keembay_wdt *wdt = watchdog_get_drvdata(wdog);
 
-	keembay_wdt_writel(wdt, TIM_WDOG_EN, 1);
+	keembay_wdt_writel(wdt, TIM_WDOG_EN, WDT_ENABLE);
 
 	return 0;
 }
@@ -93,7 +95,7 @@ static int keembay_wdt_stop(struct watchdog_device *wdog)
 {
 	struct keembay_wdt *wdt = watchdog_get_drvdata(wdog);
 
-	keembay_wdt_writel(wdt, TIM_WDOG_EN, 0);
+	keembay_wdt_writel(wdt, TIM_WDOG_EN, WDT_DISABLE);
 
 	return 0;
 }
Signature · 1 line
2.17.1
#8 lore raw

PATCH v2 8/9 watchdog: keembay: WDT SMC handler MACRO name update

In reply to [email protected]

From: Shruthi Sanil <[email protected]>

Updated the WDT SMC handler MACRO name to make it clear that its a ARM SMC handler that helps in clearing the WDT interrupt bit.

---
 drivers/watchdog/keembay_wdt.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/watchdog/keembay_wdt.c +3 -3
index d8c50b6291cd..5ac823487b70 100644
@@ -25,7 +25,7 @@
 
 #define WDT_TH_INT_MASK		BIT(8)
 #define WDT_TO_INT_MASK		BIT(9)
-#define WDT_ISR_CLEAR		0x8200ff18
+#define WDT_INT_CLEAR_SMC	0x8200ff18
 #define WDT_UNLOCK		0xf1d0dead
 #define WDT_DISABLE		0x0
 #define WDT_ENABLE		0x1
@@ -143,7 +143,7 @@ static irqreturn_t keembay_wdt_to_isr(int irq, void *dev_id)
 	struct keembay_wdt *wdt = dev_id;
 	struct arm_smccc_res res;
 
-	arm_smccc_smc(WDT_ISR_CLEAR, WDT_TO_INT_MASK, 0, 0, 0, 0, 0, 0, &res);
+	arm_smccc_smc(WDT_INT_CLEAR_SMC, WDT_TO_INT_MASK, 0, 0, 0, 0, 0, 0, &res);
 	dev_crit(wdt->wdd.parent, "Intel Keem Bay non-sec wdt timeout.\n");
 	emergency_restart();
 
@@ -157,7 +157,7 @@ static irqreturn_t keembay_wdt_th_isr(int irq, void *dev_id)
 
 	keembay_wdt_set_pretimeout(&wdt->wdd, 0x0);
 
-	arm_smccc_smc(WDT_ISR_CLEAR, WDT_TH_INT_MASK, 0, 0, 0, 0, 0, 0, &res);
+	arm_smccc_smc(WDT_INT_CLEAR_SMC, WDT_TH_INT_MASK, 0, 0, 0, 0, 0, 0, &res);
 	dev_crit(wdt->wdd.parent, "Intel Keem Bay non-sec wdt pre-timeout.\n");
 	watchdog_notify_pretimeout(&wdt->wdd);
 
Signature · 1 line
2.17.1
#9 lore raw

PATCH v2 9/9 watchdog: keembay: Typo corrections and other blank operations

In reply to [email protected]

From: Shruthi Sanil <[email protected]>

Corrected typos, aligned the tabs and added new lines wherever required for better readability

---
 drivers/watchdog/keembay_wdt.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/watchdog/keembay_wdt.c +7 -4
index 5ac823487b70..2a39114dbc64 100644
@@ -26,11 +26,14 @@
 #define WDT_TH_INT_MASK		BIT(8)
 #define WDT_TO_INT_MASK		BIT(9)
 #define WDT_INT_CLEAR_SMC	0x8200ff18
+
 #define WDT_UNLOCK		0xf1d0dead
 #define WDT_DISABLE		0x0
 #define WDT_ENABLE		0x1
+
 #define WDT_LOAD_MAX		U32_MAX
 #define WDT_LOAD_MIN		1
+
 #define WDT_TIMEOUT		5
 #define WDT_PRETIMEOUT		4
 
@@ -144,7 +147,7 @@ static irqreturn_t keembay_wdt_to_isr(int irq, void *dev_id)
 	struct arm_smccc_res res;
 
 	arm_smccc_smc(WDT_INT_CLEAR_SMC, WDT_TO_INT_MASK, 0, 0, 0, 0, 0, 0, &res);
-	dev_crit(wdt->wdd.parent, "Intel Keem Bay non-sec wdt timeout.\n");
+	dev_crit(wdt->wdd.parent, "Intel Keem Bay non-secure wdt timeout.\n");
 	emergency_restart();
 
 	return IRQ_HANDLED;
@@ -158,7 +161,7 @@ static irqreturn_t keembay_wdt_th_isr(int irq, void *dev_id)
 	keembay_wdt_set_pretimeout(&wdt->wdd, 0x0);
 
 	arm_smccc_smc(WDT_INT_CLEAR_SMC, WDT_TH_INT_MASK, 0, 0, 0, 0, 0, 0, &res);
-	dev_crit(wdt->wdd.parent, "Intel Keem Bay non-sec wdt pre-timeout.\n");
+	dev_crit(wdt->wdd.parent, "Intel Keem Bay non-secure wdt pre-timeout.\n");
 	watchdog_notify_pretimeout(&wdt->wdd);
 
 	return IRQ_HANDLED;
@@ -278,8 +281,8 @@ static const struct of_device_id keembay_wdt_match[] = {
 MODULE_DEVICE_TABLE(of, keembay_wdt_match);
 
 static struct platform_driver keembay_wdt_driver = {
-	.probe		= keembay_wdt_probe,
-	.driver		= {
+	.probe	= keembay_wdt_probe,
+	.driver	= {
 		.name		= "keembay_wdt",
 		.of_match_table	= keembay_wdt_match,
 		.pm		= &keembay_wdt_pm_ops,
Signature · 1 line
2.17.1
#10 lore raw
In reply to [email protected]

Hi Roeck,

I have addressed your review comments in the v2 version of this patch series. Could you please review?

If no comments, can I get an Acked-by tag?
Thanks!

Regards,
Shruthi

Quoted 96 lines

-----Original Message-----
From: Sanil, Shruthi <[email protected]>
Sent: Monday, May 17, 2021 11:20 PM
To: [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Thokala, Srikanth <[email protected]>; Raja Subramanian, Lakshmi Bai <[email protected]>; Sangannavar, Mallikarjunappa <[email protected]>; Sanil, Shruthi <[email protected]>
Subject: [PATCH v2 0/9] Intel Keem Bay WDT bug fixes

From: Shruthi Sanil <[email protected]>

The series of patches include the below bug fixes in the Intel Keem Bay watchdog timer driver:

Patch 1/9:
- Update WDT pre-timeout during the initialization
The pretimeout register has a default reset value. Hence when a smaller WDT timeout is set which would be lesser than the default pretimeout, the system behaves abnormally, starts triggering the pretimeout interrupt even when the WDT is not enabled, most of the times leading to system crash. Hence an update in the pre-timeout is also required for the default timeout that is being configured.

Patch 2/9:
- Upadate WDT pretimeout for every update in timeout The pre-timeout value to be programmed to the register has to be calculated and updated for every change in the timeout value. Else the threshold time wouldn't be calculated to its corresponding timeout.

Patch 3/9:
- Update pretimeout to 0 in the TH ISR
The pretimeout has to be updated to 0 during the ISR of the ThresHold interrupt. Else the TH interrupt would be triggerred for every tick until the timeout.

Patch 4/9:
- Clear either the TO or TH interrupt bit
During the interrupt service routine of the TimeOut interrupt and the ThresHold interrupt, the respective interrupt clear bit have to be cleared and not both.

Patch 5/9:
- Remove timeout update in the WDT start function
Removed set timeout from the start WDT function. There is a function defined to set the timeout. Hence no need to set the timeout again in start function as the timeout would have been already updated before calling the start/enable.

Patch 6/9:
- Removed timeout update in the TO ISR
In the TO ISR removed updating the Timeout value because its not serving any purpose as the timer would have already expired and the system would be rebooting.

Patch 7/9:
- MACRO for WDT enable and disable values
Introduced MACRO's for WDT enable and disable values for better
readability

Patch 8/9:
- WDT SMC handler MACRO name update
Updated the WDT SMC handler MACRO name to make it clear that its a ARM SMC handler that helps in clearing the WDT interrupt bit.

Patch 9/9:
- Typo corrections and other blank operations Corrected typos, aligned the tabs and added new lines wherever required for better readability

Changes since v1:
- Dropped a patch with the incorrect fix
regarding the WDT suspend/resume function.

Shruthi Sanil (9):
watchdog: keembay: Update WDT pre-timeout during the initialization
watchdog: keembay: Upadate WDT pretimeout for every update in timeout
watchdog: keembay: Update pretimeout to zero in the TH ISR
watchdog: keembay: Clear either the TO or TH interrupt bit
watchdog: keembay: Remove timeout update in the WDT start function
watchdog: keembay: Removed timeout update in the TO ISR
watchdog: keembay: MACRO for WDT enable and disable values
watchdog: keembay: WDT SMC handler MACRO name update
watchdog: keembay: Typo corrections and other blank operations

 drivers/watchdog/keembay_wdt.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

base-commit: 88b06399c9c766c283e070b022b5ceafa4f63f19 --
2.17.1

#11 lore raw
Quoted 7 lines · Shruthi

Hi Roeck,

I have addressed your review comments in the v2 version of this patch series. Could you please review?

If no comments, can I get an Acked-by tag?
Thanks!

First of all, do not top post!

Quoted 2 lines
Quoted 2 lines

From: Sanil, Shruthi <[email protected]>
Sent: Monday, May 17, 2021 11:20 PM

AFAICS Guenter had reviewed (as you put his tags into commits). It means that maintainer will pickup patches when they feel it's a good time.

Quoted 2 lines
Quoted 2 lines

The series of patches include the below bug fixes in the Intel Keem Bay watchdog timer driver:

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#12 lore raw
Quoted 9 lines · On 5/24/21 3:36 AM, [email protected] wrote:
Quoted 7 lines · Shruthi

Hi Roeck,

I have addressed your review comments in the v2 version of this patch series. Could you please review?

If no comments, can I get an Acked-by tag?
Thanks!

Quoted 8 lines

First of all, do not top post!

Quoted 2 lines
Quoted 2 lines

From: Sanil, Shruthi <[email protected]>
Sent: Monday, May 17, 2021 11:20 PM

AFAICS Guenter had reviewed (as you put his tags into commits). It means that maintainer will pickup patches when they feel it's a good time.

Yes, and the patches are queued in my own watchdog-next branch. At this point we'll have to wait for the Wim to pick up the series.

Guenter