Skip to content

Commit 0a7eee8

Browse files
quic-bjorandeandersson
authored andcommitted
rpmsg: glink: Transition intent request signaling to wait queue
Transition the intent request acknowledgement to use a wait queue so that it's possible, in the next commit, to extend the wait to also wait for an incoming intent. Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com> Reviewed-by: Chris Lew <quic_clew@quicinc.com> Signed-off-by: Bjorn Andersson <andersson@kernel.org> Link: https://lore.kernel.org/r/20230327144617.3134175-2-quic_bjorande@quicinc.com
1 parent 38be895 commit 0a7eee8

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

drivers/rpmsg/qcom_glink_native.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/rpmsg.h>
1717
#include <linux/sizes.h>
1818
#include <linux/slab.h>
19+
#include <linux/wait.h>
1920
#include <linux/workqueue.h>
2021
#include <linux/mailbox_client.h>
2122

@@ -145,7 +146,7 @@ enum {
145146
* @open_req: completed once open-request has been received
146147
* @intent_req_lock: Synchronises multiple intent requests
147148
* @intent_req_result: Result of intent request
148-
* @intent_req_comp: Completion for intent_req signalling
149+
* @intent_req_wq: wait queue for intent_req signalling
149150
*/
150151
struct glink_channel {
151152
struct rpmsg_endpoint ept;
@@ -175,8 +176,8 @@ struct glink_channel {
175176
struct completion open_req;
176177

177178
struct mutex intent_req_lock;
178-
bool intent_req_result;
179-
struct completion intent_req_comp;
179+
int intent_req_result;
180+
wait_queue_head_t intent_req_wq;
180181
};
181182

182183
#define to_glink_channel(_ept) container_of(_ept, struct glink_channel, ept)
@@ -221,7 +222,7 @@ static struct glink_channel *qcom_glink_alloc_channel(struct qcom_glink *glink,
221222

222223
init_completion(&channel->open_req);
223224
init_completion(&channel->open_ack);
224-
init_completion(&channel->intent_req_comp);
225+
init_waitqueue_head(&channel->intent_req_wq);
225226

226227
INIT_LIST_HEAD(&channel->done_intents);
227228
INIT_WORK(&channel->intent_work, qcom_glink_rx_done_work);
@@ -420,13 +421,13 @@ static void qcom_glink_handle_intent_req_ack(struct qcom_glink *glink,
420421
}
421422

422423
channel->intent_req_result = granted;
423-
complete(&channel->intent_req_comp);
424+
wake_up_all(&channel->intent_req_wq);
424425
}
425426

426427
static void qcom_glink_intent_req_abort(struct glink_channel *channel)
427428
{
428429
channel->intent_req_result = 0;
429-
complete(&channel->intent_req_comp);
430+
wake_up_all(&channel->intent_req_wq);
430431
}
431432

432433
/**
@@ -1271,7 +1272,7 @@ static int qcom_glink_request_intent(struct qcom_glink *glink,
12711272

12721273
mutex_lock(&channel->intent_req_lock);
12731274

1274-
reinit_completion(&channel->intent_req_comp);
1275+
WRITE_ONCE(channel->intent_req_result, -1);
12751276

12761277
cmd.id = GLINK_CMD_RX_INTENT_REQ;
12771278
cmd.cid = channel->lcid;
@@ -1281,12 +1282,14 @@ static int qcom_glink_request_intent(struct qcom_glink *glink,
12811282
if (ret)
12821283
goto unlock;
12831284

1284-
ret = wait_for_completion_timeout(&channel->intent_req_comp, 10 * HZ);
1285+
ret = wait_event_timeout(channel->intent_req_wq,
1286+
READ_ONCE(channel->intent_req_result) >= 0,
1287+
10 * HZ);
12851288
if (!ret) {
12861289
dev_err(glink->dev, "intent request timed out\n");
12871290
ret = -ETIMEDOUT;
12881291
} else {
1289-
ret = channel->intent_req_result ? 0 : -ECANCELED;
1292+
ret = READ_ONCE(channel->intent_req_result) ? 0 : -ECANCELED;
12901293
}
12911294

12921295
unlock:

0 commit comments

Comments
 (0)