Skip to content

Commit f8c8791

Browse files
quic-bjorandeandersson
authored andcommitted
soc: qcom: pmic_glink: Handle GLINK intent allocation rejections
Some versions of the pmic_glink firmware does not allow dynamic GLINK intent allocations, attempting to send a message before the firmware has allocated its receive buffers and announced these intent allocations will fail. When this happens something like this showns up in the log: pmic_glink_altmode.pmic_glink_altmode pmic_glink.altmode.0: failed to send altmode request: 0x10 (-125) pmic_glink_altmode.pmic_glink_altmode pmic_glink.altmode.0: failed to request altmode notifications: -125 ucsi_glink.pmic_glink_ucsi pmic_glink.ucsi.0: failed to send UCSI read request: -125 qcom_battmgr.pmic_glink_power_supply pmic_glink.power-supply.0: failed to request power notifications GLINK has been updated to distinguish between the cases where the remote is going down (-ECANCELED) and the intent allocation being rejected (-EAGAIN). Retry the send until intent buffers becomes available, or an actual error occur. To avoid infinitely waiting for the firmware in the event that this misbehaves and no intents arrive, an arbitrary 5 second timeout is used. This patch was developed with input from Chris Lew. Reported-by: Johan Hovold <johan@kernel.org> Closes: https://lore.kernel.org/all/Zqet8iInnDhnxkT9@hovoldconsulting.com/#t Cc: stable@vger.kernel.org # rpmsg: glink: Handle rejected intent request better Fixes: 58ef4ec ("soc: qcom: pmic_glink: Introduce base PMIC GLINK driver") Tested-by: Johan Hovold <johan+linaro@kernel.org> Reviewed-by: Johan Hovold <johan+linaro@kernel.org> Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com> Reviewed-by: Chris Lew <quic_clew@quicinc.com> Link: https://lore.kernel.org/r/20241023-pmic-glink-ecancelled-v2-2-ebc268129407@oss.qualcomm.com Signed-off-by: Bjorn Andersson <andersson@kernel.org>
1 parent a387e73 commit f8c8791

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

drivers/soc/qcom/pmic_glink.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (c) 2022, Linaro Ltd
55
*/
66
#include <linux/auxiliary_bus.h>
7+
#include <linux/delay.h>
78
#include <linux/module.h>
89
#include <linux/of.h>
910
#include <linux/platform_device.h>
@@ -13,6 +14,8 @@
1314
#include <linux/soc/qcom/pmic_glink.h>
1415
#include <linux/spinlock.h>
1516

17+
#define PMIC_GLINK_SEND_TIMEOUT (5 * HZ)
18+
1619
enum {
1720
PMIC_GLINK_CLIENT_BATT = 0,
1821
PMIC_GLINK_CLIENT_ALTMODE,
@@ -112,13 +115,29 @@ EXPORT_SYMBOL_GPL(pmic_glink_client_register);
112115
int pmic_glink_send(struct pmic_glink_client *client, void *data, size_t len)
113116
{
114117
struct pmic_glink *pg = client->pg;
118+
bool timeout_reached = false;
119+
unsigned long start;
115120
int ret;
116121

117122
mutex_lock(&pg->state_lock);
118-
if (!pg->ept)
123+
if (!pg->ept) {
119124
ret = -ECONNRESET;
120-
else
121-
ret = rpmsg_send(pg->ept, data, len);
125+
} else {
126+
start = jiffies;
127+
for (;;) {
128+
ret = rpmsg_send(pg->ept, data, len);
129+
if (ret != -EAGAIN)
130+
break;
131+
132+
if (timeout_reached) {
133+
ret = -ETIMEDOUT;
134+
break;
135+
}
136+
137+
usleep_range(1000, 5000);
138+
timeout_reached = time_after(jiffies, start + PMIC_GLINK_SEND_TIMEOUT);
139+
}
140+
}
122141
mutex_unlock(&pg->state_lock);
123142

124143
return ret;

0 commit comments

Comments
 (0)