diff options
Diffstat (limited to 'drivers/rpmsg/qcom_glink_native.c')
-rw-r--r-- | drivers/rpmsg/qcom_glink_native.c | 87 |
1 files changed, 42 insertions, 45 deletions
diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c index 01d2805fe30f..1beb40a1d3df 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -16,6 +16,7 @@ #include <linux/rpmsg.h> #include <linux/sizes.h> #include <linux/slab.h> +#include <linux/wait.h> #include <linux/workqueue.h> #include <linux/mailbox_client.h> @@ -145,7 +146,8 @@ enum { * @open_req: completed once open-request has been received * @intent_req_lock: Synchronises multiple intent requests * @intent_req_result: Result of intent request - * @intent_req_comp: Completion for intent_req signalling + * @intent_received: flag indicating that an intent has been received + * @intent_req_wq: wait queue for intent_req signalling */ struct glink_channel { struct rpmsg_endpoint ept; @@ -175,8 +177,9 @@ struct glink_channel { struct completion open_req; struct mutex intent_req_lock; - bool intent_req_result; - struct completion intent_req_comp; + int intent_req_result; + bool intent_received; + wait_queue_head_t intent_req_wq; }; #define to_glink_channel(_ept) container_of(_ept, struct glink_channel, ept) @@ -221,7 +224,7 @@ static struct glink_channel *qcom_glink_alloc_channel(struct qcom_glink *glink, init_completion(&channel->open_req); init_completion(&channel->open_ack); - init_completion(&channel->intent_req_comp); + init_waitqueue_head(&channel->intent_req_wq); INIT_LIST_HEAD(&channel->done_intents); INIT_WORK(&channel->intent_work, qcom_glink_rx_done_work); @@ -419,14 +422,14 @@ static void qcom_glink_handle_intent_req_ack(struct qcom_glink *glink, return; } - channel->intent_req_result = granted; - complete(&channel->intent_req_comp); + WRITE_ONCE(channel->intent_req_result, granted); + wake_up_all(&channel->intent_req_wq); } static void qcom_glink_intent_req_abort(struct glink_channel *channel) { - channel->intent_req_result = 0; - complete(&channel->intent_req_comp); + WRITE_ONCE(channel->intent_req_result, 0); + wake_up_all(&channel->intent_req_wq); } /** @@ -756,6 +759,11 @@ static void qcom_glink_handle_rx_done(struct qcom_glink *glink, kfree(intent); } spin_unlock_irqrestore(&channel->intent_lock, flags); + + if (reuse) { + WRITE_ONCE(channel->intent_received, true); + wake_up_all(&channel->intent_req_wq); + } } /** @@ -993,6 +1001,9 @@ static void qcom_glink_handle_intent(struct qcom_glink *glink, dev_err(glink->dev, "failed to store remote intent\n"); } + WRITE_ONCE(channel->intent_received, true); + wake_up_all(&channel->intent_req_wq); + kfree(msg); qcom_glink_rx_advance(glink, ALIGN(msglen, 8)); } @@ -1271,7 +1282,8 @@ static int qcom_glink_request_intent(struct qcom_glink *glink, mutex_lock(&channel->intent_req_lock); - reinit_completion(&channel->intent_req_comp); + WRITE_ONCE(channel->intent_req_result, -1); + WRITE_ONCE(channel->intent_received, false); cmd.id = GLINK_CMD_RX_INTENT_REQ; cmd.cid = channel->lcid; @@ -1281,12 +1293,15 @@ static int qcom_glink_request_intent(struct qcom_glink *glink, if (ret) goto unlock; - ret = wait_for_completion_timeout(&channel->intent_req_comp, 10 * HZ); + ret = wait_event_timeout(channel->intent_req_wq, + READ_ONCE(channel->intent_req_result) >= 0 && + READ_ONCE(channel->intent_received), + 10 * HZ); if (!ret) { dev_err(glink->dev, "intent request timed out\n"); ret = -ETIMEDOUT; } else { - ret = channel->intent_req_result ? 0 : -ECANCELED; + ret = READ_ONCE(channel->intent_req_result) ? 0 : -ECANCELED; } unlock: @@ -1309,7 +1324,7 @@ static int __qcom_glink_send(struct glink_channel *channel, int ret; unsigned long flags; int chunk_size = len; - int left_size = 0; + size_t offset = 0; if (!glink->intentless) { while (!intent) { @@ -1343,47 +1358,29 @@ static int __qcom_glink_send(struct glink_channel *channel, iid = intent->id; } - if (wait && chunk_size > SZ_8K) { - chunk_size = SZ_8K; - left_size = len - chunk_size; - } - req.msg.cmd = cpu_to_le16(GLINK_CMD_TX_DATA); - req.msg.param1 = cpu_to_le16(channel->lcid); - req.msg.param2 = cpu_to_le32(iid); - req.chunk_size = cpu_to_le32(chunk_size); - req.left_size = cpu_to_le32(left_size); - - ret = qcom_glink_tx(glink, &req, sizeof(req), data, chunk_size, wait); - - /* Mark intent available if we failed */ - if (ret && intent) { - intent->in_use = false; - return ret; - } - - while (left_size > 0) { - data = (void *)((char *)data + chunk_size); - chunk_size = left_size; - if (chunk_size > SZ_8K) + while (offset < len) { + chunk_size = len - offset; + if (chunk_size > SZ_8K && wait) chunk_size = SZ_8K; - left_size -= chunk_size; - req.msg.cmd = cpu_to_le16(GLINK_CMD_TX_DATA_CONT); + req.msg.cmd = cpu_to_le16(offset == 0 ? GLINK_CMD_TX_DATA : GLINK_CMD_TX_DATA_CONT); req.msg.param1 = cpu_to_le16(channel->lcid); req.msg.param2 = cpu_to_le32(iid); req.chunk_size = cpu_to_le32(chunk_size); - req.left_size = cpu_to_le32(left_size); - - ret = qcom_glink_tx(glink, &req, sizeof(req), data, - chunk_size, wait); + req.left_size = cpu_to_le32(len - offset - chunk_size); - /* Mark intent available if we failed */ - if (ret && intent) { - intent->in_use = false; - break; + ret = qcom_glink_tx(glink, &req, sizeof(req), data + offset, chunk_size, wait); + if (ret) { + /* Mark intent available if we failed */ + if (intent) + intent->in_use = false; + return ret; } + + offset += chunk_size; } - return ret; + + return 0; } static int qcom_glink_send(struct rpmsg_endpoint *ept, void *data, int len) |