aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStewart Smith2016-08-01 20:50:16 -0500
committerGreg Kroah-Hartman2018-02-22 08:44:59 -0600
commit99863c1bfdbf08d9a9001ac2c7c4d4e66fcdab6d (patch)
tree9db9d3582e1db37786afd41ed093eb860f81c186
parent0bb10b1679e2b5c817ad11354345c1d73121997b (diff)
downloadkernel-omap-99863c1bfdbf08d9a9001ac2c7c4d4e66fcdab6d.tar.gz
kernel-omap-99863c1bfdbf08d9a9001ac2c7c4d4e66fcdab6d.tar.xz
kernel-omap-99863c1bfdbf08d9a9001ac2c7c4d4e66fcdab6d.zip
rtc-opal: Fix handling of firmware error codes, prevent busy loops
commit 5b8b58063029f02da573120ef4dc9079822e3cda upstream. According to the OPAL docs: skiboot-5.2.5/doc/opal-api/opal-rtc-read-3.txt skiboot-5.2.5/doc/opal-api/opal-rtc-write-4.txt OPAL_HARDWARE may be returned from OPAL_RTC_READ or OPAL_RTC_WRITE and this indicates either a transient or permanent error. Prior to this patch, Linux was not dealing with OPAL_HARDWARE being a permanent error particularly well, in that you could end up in a busy loop. This was not too hard to trigger on an AMI BMC based OpenPOWER machine doing a continuous "ipmitool mc reset cold" to the BMC, the result of that being that we'd get stuck in an infinite loop in opal_get_rtc_time(). We now retry a few times before returning the error higher up the stack. Fixes: 16b1d26e77b1 ("rtc/tpo: Driver to support rtc and wakeup on PowerNV platform") Cc: stable@vger.kernel.org # v3.19+ Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/rtc/rtc-opal.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/drivers/rtc/rtc-opal.c b/drivers/rtc/rtc-opal.c
index df39ce02a99d..229dd2fe8f45 100644
--- a/drivers/rtc/rtc-opal.c
+++ b/drivers/rtc/rtc-opal.c
@@ -58,6 +58,7 @@ static void tm_to_opal(struct rtc_time *tm, u32 *y_m_d, u64 *h_m_s_ms)
58static int opal_get_rtc_time(struct device *dev, struct rtc_time *tm) 58static int opal_get_rtc_time(struct device *dev, struct rtc_time *tm)
59{ 59{
60 long rc = OPAL_BUSY; 60 long rc = OPAL_BUSY;
61 int retries = 10;
61 u32 y_m_d; 62 u32 y_m_d;
62 u64 h_m_s_ms; 63 u64 h_m_s_ms;
63 __be32 __y_m_d; 64 __be32 __y_m_d;
@@ -67,8 +68,11 @@ static int opal_get_rtc_time(struct device *dev, struct rtc_time *tm)
67 rc = opal_rtc_read(&__y_m_d, &__h_m_s_ms); 68 rc = opal_rtc_read(&__y_m_d, &__h_m_s_ms);
68 if (rc == OPAL_BUSY_EVENT) 69 if (rc == OPAL_BUSY_EVENT)
69 opal_poll_events(NULL); 70 opal_poll_events(NULL);
70 else 71 else if (retries-- && (rc == OPAL_HARDWARE
72 || rc == OPAL_INTERNAL_ERROR))
71 msleep(10); 73 msleep(10);
74 else if (rc != OPAL_BUSY && rc != OPAL_BUSY_EVENT)
75 break;
72 } 76 }
73 77
74 if (rc != OPAL_SUCCESS) 78 if (rc != OPAL_SUCCESS)
@@ -84,6 +88,7 @@ static int opal_get_rtc_time(struct device *dev, struct rtc_time *tm)
84static int opal_set_rtc_time(struct device *dev, struct rtc_time *tm) 88static int opal_set_rtc_time(struct device *dev, struct rtc_time *tm)
85{ 89{
86 long rc = OPAL_BUSY; 90 long rc = OPAL_BUSY;
91 int retries = 10;
87 u32 y_m_d = 0; 92 u32 y_m_d = 0;
88 u64 h_m_s_ms = 0; 93 u64 h_m_s_ms = 0;
89 94
@@ -92,8 +97,11 @@ static int opal_set_rtc_time(struct device *dev, struct rtc_time *tm)
92 rc = opal_rtc_write(y_m_d, h_m_s_ms); 97 rc = opal_rtc_write(y_m_d, h_m_s_ms);
93 if (rc == OPAL_BUSY_EVENT) 98 if (rc == OPAL_BUSY_EVENT)
94 opal_poll_events(NULL); 99 opal_poll_events(NULL);
95 else 100 else if (retries-- && (rc == OPAL_HARDWARE
101 || rc == OPAL_INTERNAL_ERROR))
96 msleep(10); 102 msleep(10);
103 else if (rc != OPAL_BUSY && rc != OPAL_BUSY_EVENT)
104 break;
97 } 105 }
98 106
99 return rc == OPAL_SUCCESS ? 0 : -EIO; 107 return rc == OPAL_SUCCESS ? 0 : -EIO;