Skip to content

Commit 27b9c5b

Browse files
Sricharan Randersson
authored andcommitted
rpmsg: glink: Request for intents when unavailable
While sending data, we search for suitable sized intent to map and simply fail if a intent is not found. Instead request for a intent of required size and wait till one is alloted. Acked-by: Arun Kumar Neelakantam <aneela@codeaurora.org> Signed-off-by: Sricharan R <sricharan@codeaurora.org> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
1 parent 11cb45a commit 27b9c5b

1 file changed

Lines changed: 74 additions & 2 deletions

File tree

‎drivers/rpmsg/qcom_glink_native.c‎

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ enum {
150150
* @buf_size: size of current @buf
151151
* @open_ack: completed once remote has acked the open-request
152152
* @open_req: completed once open-request has been received
153+
* @intent_req_lock: Synchronises multiple intent requests
154+
* @intent_req_result: Result of intent request
155+
* @intent_req_comp: Completion for intent_req signalling
153156
*/
154157
struct glink_channel {
155158
struct rpmsg_endpoint ept;
@@ -177,6 +180,10 @@ struct glink_channel {
177180

178181
struct completion open_ack;
179182
struct completion open_req;
183+
184+
struct mutex intent_req_lock;
185+
bool intent_req_result;
186+
struct completion intent_req_comp;
180187
};
181188

182189
#define to_glink_channel(_ept) container_of(_ept, struct glink_channel, ept)
@@ -343,6 +350,24 @@ static void qcom_glink_send_open_ack(struct qcom_glink *glink,
343350
qcom_glink_tx(glink, &msg, sizeof(msg), NULL, 0, true);
344351
}
345352

353+
static void qcom_glink_handle_intent_req_ack(struct qcom_glink *glink,
354+
unsigned int cid, bool granted)
355+
{
356+
struct glink_channel *channel;
357+
unsigned long flags;
358+
359+
spin_lock_irqsave(&glink->idr_lock, flags);
360+
channel = idr_find(&glink->rcids, cid);
361+
spin_unlock_irqrestore(&glink->idr_lock, flags);
362+
if (!channel) {
363+
dev_err(glink->dev, "unable to find channel\n");
364+
return;
365+
}
366+
367+
channel->intent_req_result = granted;
368+
complete(&channel->intent_req_comp);
369+
}
370+
346371
/**
347372
* qcom_glink_send_open_req() - send a RPM_CMD_OPEN request to the remote
348373
* @glink: Ptr to the glink edge
@@ -941,6 +966,10 @@ static irqreturn_t qcom_glink_native_intr(int irq, void *data)
941966
case RPM_CMD_INTENT:
942967
qcom_glink_handle_intent(glink, param1, param2, avail);
943968
break;
969+
case RPM_CMD_RX_INTENT_REQ_ACK:
970+
qcom_glink_handle_intent_req_ack(glink, param1, param2);
971+
qcom_glink_rx_advance(glink, ALIGN(sizeof(msg), 8));
972+
break;
944973
default:
945974
dev_err(glink->dev, "unhandled rx cmd: %d\n", cmd);
946975
ret = -EINVAL;
@@ -1106,6 +1135,42 @@ static void qcom_glink_destroy_ept(struct rpmsg_endpoint *ept)
11061135
qcom_glink_send_close_req(glink, channel);
11071136
}
11081137

1138+
static int qcom_glink_request_intent(struct qcom_glink *glink,
1139+
struct glink_channel *channel,
1140+
size_t size)
1141+
{
1142+
struct {
1143+
u16 id;
1144+
u16 cid;
1145+
u32 size;
1146+
} __packed cmd;
1147+
1148+
int ret;
1149+
1150+
mutex_lock(&channel->intent_req_lock);
1151+
1152+
reinit_completion(&channel->intent_req_comp);
1153+
1154+
cmd.id = RPM_CMD_RX_INTENT_REQ;
1155+
cmd.cid = channel->lcid;
1156+
cmd.size = size;
1157+
1158+
ret = qcom_glink_tx(glink, &cmd, sizeof(cmd), NULL, 0, true);
1159+
if (ret)
1160+
return ret;
1161+
1162+
ret = wait_for_completion_timeout(&channel->intent_req_comp, 10 * HZ);
1163+
if (!ret) {
1164+
dev_err(glink->dev, "intent request timed out\n");
1165+
ret = -ETIMEDOUT;
1166+
} else {
1167+
ret = channel->intent_req_result ? 0 : -ECANCELED;
1168+
}
1169+
1170+
mutex_unlock(&channel->intent_req_lock);
1171+
return ret;
1172+
}
1173+
11091174
static int __qcom_glink_send(struct glink_channel *channel,
11101175
void *data, int len, bool wait)
11111176
{
@@ -1122,7 +1187,7 @@ static int __qcom_glink_send(struct glink_channel *channel,
11221187
unsigned long flags;
11231188

11241189
if (!glink->intentless) {
1125-
if (!intent) {
1190+
while (!intent) {
11261191
spin_lock_irqsave(&channel->intent_lock, flags);
11271192
idr_for_each_entry(&channel->riids, tmp, iid) {
11281193
if (tmp->size >= len && !tmp->in_use) {
@@ -1134,8 +1199,15 @@ static int __qcom_glink_send(struct glink_channel *channel,
11341199
spin_unlock_irqrestore(&channel->intent_lock, flags);
11351200

11361201
/* We found an available intent */
1137-
if (!intent)
1202+
if (intent)
1203+
break;
1204+
1205+
if (!wait)
11381206
return -EBUSY;
1207+
1208+
ret = qcom_glink_request_intent(glink, channel, len);
1209+
if (ret < 0)
1210+
return ret;
11391211
}
11401212

11411213
iid = intent->id;

0 commit comments

Comments
 (0)