in qcom_glink_native.c [1290:1380]
static int __qcom_glink_send(struct glink_channel *channel,
void *data, int len, bool wait)
{
struct qcom_glink *glink = channel->glink;
struct glink_core_rx_intent *intent = NULL;
struct glink_core_rx_intent *tmp;
int iid = 0;
struct {
struct glink_msg msg;
__le32 chunk_size;
__le32 left_size;
} __packed req;
int ret;
unsigned long flags;
int chunk_size = len;
int left_size = 0;
if (!glink->intentless) {
while (!intent) {
spin_lock_irqsave(&channel->intent_lock, flags);
idr_for_each_entry(&channel->riids, tmp, iid) {
if (tmp->size >= len && !tmp->in_use) {
if (!intent)
intent = tmp;
else if (intent->size > tmp->size)
intent = tmp;
if (intent->size == len)
break;
}
}
if (intent)
intent->in_use = true;
spin_unlock_irqrestore(&channel->intent_lock, flags);
/* We found an available intent */
if (intent)
break;
if (!wait)
return -EBUSY;
ret = qcom_glink_request_intent(glink, channel, len);
if (ret < 0)
return ret;
}
iid = intent->id;
}
if (wait && chunk_size > SZ_8K) {
chunk_size = SZ_8K;
left_size = len - chunk_size;
}
req.msg.cmd = cpu_to_le16(RPM_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)
chunk_size = SZ_8K;
left_size -= chunk_size;
req.msg.cmd = cpu_to_le16(RPM_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);
/* Mark intent available if we failed */
if (ret && intent) {
intent->in_use = false;
break;
}
}
return ret;
}