Lines Matching defs:channel
63 * @in_use: To mark if intent is already in use for the channel
88 * @lcids: idr of all channels with a known local channel id
89 * @rcids: idr of all channels with a known remote channel id
128 * struct glink_channel - internal representation of a channel
130 * @ept: rpmsg endpoint this channel is associated with
132 * @refcount: refcount for the channel object
134 * @name: unique channel name/identifier
135 * @lcid: channel id, in local space
136 * @rcid: channel id, in remote space
217 struct glink_channel *channel;
219 channel = kzalloc(sizeof(*channel), GFP_KERNEL);
220 if (!channel)
224 spin_lock_init(&channel->recv_lock);
225 spin_lock_init(&channel->intent_lock);
226 mutex_init(&channel->intent_req_lock);
228 channel->glink = glink;
229 channel->name = kstrdup(name, GFP_KERNEL);
230 if (!channel->name) {
231 kfree(channel);
235 init_completion(&channel->open_req);
236 init_completion(&channel->open_ack);
237 init_waitqueue_head(&channel->intent_req_wq);
239 INIT_LIST_HEAD(&channel->done_intents);
240 INIT_WORK(&channel->intent_work, qcom_glink_rx_done_work);
242 idr_init(&channel->liids);
243 idr_init(&channel->riids);
244 kref_init(&channel->refcount);
246 return channel;
251 struct glink_channel *channel = container_of(ref, struct glink_channel,
259 cancel_work_sync(&channel->intent_work);
261 spin_lock_irqsave(&channel->intent_lock, flags);
263 list_for_each_entry_safe(intent, tmp, &channel->done_intents, node) {
270 idr_for_each_entry(&channel->liids, tmp, iid) {
274 idr_destroy(&channel->liids);
276 idr_for_each_entry(&channel->riids, tmp, iid)
278 idr_destroy(&channel->riids);
279 spin_unlock_irqrestore(&channel->intent_lock, flags);
281 kfree(channel->name);
282 kfree(channel);
410 struct glink_channel *channel)
415 msg.param1 = cpu_to_le16(channel->rcid);
424 struct glink_channel *channel;
428 channel = idr_find(&glink->rcids, cid);
430 if (!channel) {
431 dev_err(glink->dev, "unable to find channel\n");
435 WRITE_ONCE(channel->intent_req_result, granted);
436 wake_up_all(&channel->intent_req_wq);
439 static void qcom_glink_intent_req_abort(struct glink_channel *channel)
441 WRITE_ONCE(channel->intent_req_result, 0);
442 wake_up_all(&channel->intent_req_wq);
448 * @channel: Ptr to the channel that the open req is sent
450 * Allocates a local channel id and sends a GLINK_CMD_OPEN message to the remote.
456 struct glink_channel *channel)
462 int name_len = strlen(channel->name) + 1;
467 kref_get(&channel->refcount);
470 ret = idr_alloc_cyclic(&glink->lcids, channel,
477 channel->lcid = ret;
480 req.msg.param1 = cpu_to_le16(channel->lcid);
482 strcpy(req.name, channel->name);
492 idr_remove(&glink->lcids, channel->lcid);
493 channel->lcid = 0;
500 struct glink_channel *channel)
505 req.param1 = cpu_to_le16(channel->lcid);
525 struct glink_channel *channel = container_of(work, struct glink_channel,
527 struct qcom_glink *glink = channel->glink;
535 unsigned int cid = channel->lcid;
540 spin_lock_irqsave(&channel->intent_lock, flags);
541 list_for_each_entry_safe(intent, tmp, &channel->done_intents, node) {
543 spin_unlock_irqrestore(&channel->intent_lock, flags);
556 spin_lock_irqsave(&channel->intent_lock, flags);
558 spin_unlock_irqrestore(&channel->intent_lock, flags);
562 struct glink_channel *channel,
574 spin_lock(&channel->intent_lock);
575 idr_remove(&channel->liids, intent->id);
576 spin_unlock(&channel->intent_lock);
580 spin_lock(&channel->intent_lock);
581 list_add_tail(&intent->node, &channel->done_intents);
582 spin_unlock(&channel->intent_lock);
584 schedule_work(&channel->intent_work);
648 * @channel: The glink channel
654 struct glink_channel *channel,
660 msg.param1 = cpu_to_le16(channel->lcid);
672 * @channel: The local channel
678 struct glink_channel *channel,
691 cmd.lcid = cpu_to_le16(channel->lcid);
703 struct glink_channel *channel,
719 spin_lock_irqsave(&channel->intent_lock, flags);
720 ret = idr_alloc_cyclic(&channel->liids, intent, 1, -1, GFP_ATOMIC);
722 spin_unlock_irqrestore(&channel->intent_lock, flags);
725 spin_unlock_irqrestore(&channel->intent_lock, flags);
745 struct glink_channel *channel;
749 channel = idr_find(&glink->rcids, cid);
751 if (!channel) {
752 dev_err(glink->dev, "invalid channel id received\n");
756 spin_lock_irqsave(&channel->intent_lock, flags);
757 intent = idr_find(&channel->riids, iid);
760 spin_unlock_irqrestore(&channel->intent_lock, flags);
768 idr_remove(&channel->riids, intent->id);
771 spin_unlock_irqrestore(&channel->intent_lock, flags);
774 WRITE_ONCE(channel->intent_received, true);
775 wake_up_all(&channel->intent_req_wq);
783 * @cid: Remote channel ID
786 * The function searches for the local channel to which the request for
793 struct glink_channel *channel;
797 channel = idr_find(&glink->rcids, cid);
800 if (!channel) {
801 pr_err("%s channel not found for cid %d\n", __func__, cid);
805 intent = qcom_glink_alloc_intent(glink, channel, size, false);
807 qcom_glink_advertise_intent(glink, channel, intent);
809 qcom_glink_send_intent_req_ack(glink, channel, !!intent);
844 struct glink_channel *channel;
873 channel = idr_find(&glink->rcids, rcid);
875 if (!channel) {
876 dev_dbg(glink->dev, "Data on non-existing channel\n");
884 if (!channel->buf) {
900 channel->buf = intent;
902 intent = channel->buf;
907 spin_lock_irqsave(&channel->intent_lock, flags);
908 intent = idr_find(&channel->liids, liid);
909 spin_unlock_irqrestore(&channel->intent_lock, flags);
913 "no intent found for channel %s intent %d",
914 channel->name, liid);
933 spin_lock(&channel->recv_lock);
934 if (channel->ept.cb) {
935 channel->ept.cb(channel->ept.rpdev,
938 channel->ept.priv,
941 spin_unlock(&channel->recv_lock);
944 channel->buf = NULL;
946 qcom_glink_rx_done(glink, channel, intent);
961 struct glink_channel *channel;
983 channel = idr_find(&glink->rcids, cid);
985 if (!channel) {
986 dev_err(glink->dev, "intents for non-existing channel\n");
1005 spin_lock_irqsave(&channel->intent_lock, flags);
1006 ret = idr_alloc(&channel->riids, intent,
1008 spin_unlock_irqrestore(&channel->intent_lock, flags);
1014 WRITE_ONCE(channel->intent_received, true);
1015 wake_up_all(&channel->intent_req_wq);
1023 struct glink_channel *channel;
1026 channel = idr_find(&glink->lcids, lcid);
1028 if (!channel) {
1033 complete_all(&channel->open_ack);
1040 * @ept: Rpmsg endpoint for channel.
1048 struct glink_channel *channel = to_glink_channel(ept);
1049 struct qcom_glink *glink = channel->glink;
1057 msg.param1 = cpu_to_le16(channel->lcid);
1066 struct glink_channel *channel;
1071 channel = idr_find(&glink->rcids, rcid);
1073 if (!channel) {
1074 dev_err(glink->dev, "signal for non-existing channel\n");
1080 if (channel->ept.flow_cb)
1081 channel->ept.flow_cb(channel->ept.rpdev, channel->ept.priv, enable);
1165 struct glink_channel *channel;
1169 channel = qcom_glink_alloc_channel(glink, name);
1170 if (IS_ERR(channel))
1171 return ERR_CAST(channel);
1173 ret = qcom_glink_send_open_req(glink, channel);
1177 ret = wait_for_completion_timeout(&channel->open_ack, 5 * HZ);
1181 ret = wait_for_completion_timeout(&channel->open_req, 5 * HZ);
1185 qcom_glink_send_open_ack(glink, channel);
1187 return channel;
1190 /* qcom_glink_send_open_req() did register the channel in lcids*/
1192 idr_remove(&glink->lcids, channel->lcid);
1197 kref_put(&channel->refcount, qcom_glink_channel_release);
1199 kref_put(&channel->refcount, qcom_glink_channel_release);
1206 struct glink_channel *channel)
1210 qcom_glink_send_open_ack(glink, channel);
1212 ret = qcom_glink_send_open_req(glink, channel);
1216 ret = wait_for_completion_timeout(&channel->open_ack, 5 * HZ);
1231 qcom_glink_send_close_req(glink, channel);
1243 struct glink_channel *channel;
1252 idr_for_each_entry(&glink->rcids, channel, cid) {
1253 if (!strcmp(channel->name, name))
1258 if (!channel) {
1259 channel = qcom_glink_create_local(glink, name);
1260 if (IS_ERR(channel))
1263 ret = qcom_glink_create_remote(glink, channel);
1268 ept = &channel->ept;
1279 struct glink_channel *channel = to_glink_channel(rpdev->ept);
1281 struct qcom_glink *glink = channel->glink;
1290 if (glink->intentless || !completion_done(&channel->open_ack))
1304 intent = qcom_glink_alloc_intent(glink, channel, size,
1309 qcom_glink_advertise_intent(glink, channel, intent);
1317 struct glink_channel *channel = to_glink_channel(ept);
1318 struct qcom_glink *glink = channel->glink;
1321 spin_lock_irqsave(&channel->recv_lock, flags);
1322 channel->ept.cb = NULL;
1323 spin_unlock_irqrestore(&channel->recv_lock, flags);
1325 /* Decouple the potential rpdev from the channel */
1326 channel->rpdev = NULL;
1328 qcom_glink_send_close_req(glink, channel);
1332 struct glink_channel *channel,
1343 mutex_lock(&channel->intent_req_lock);
1345 WRITE_ONCE(channel->intent_req_result, -1);
1346 WRITE_ONCE(channel->intent_received, false);
1349 cmd.cid = channel->lcid;
1356 ret = wait_event_timeout(channel->intent_req_wq,
1357 READ_ONCE(channel->intent_req_result) >= 0 &&
1358 READ_ONCE(channel->intent_received),
1364 ret = READ_ONCE(channel->intent_req_result) ? 0 : -ECANCELED;
1368 mutex_unlock(&channel->intent_req_lock);
1372 static int __qcom_glink_send(struct glink_channel *channel,
1375 struct qcom_glink *glink = channel->glink;
1391 spin_lock_irqsave(&channel->intent_lock, flags);
1392 idr_for_each_entry(&channel->riids, tmp, iid) {
1404 spin_unlock_irqrestore(&channel->intent_lock, flags);
1413 ret = qcom_glink_request_intent(glink, channel, len);
1427 req.msg.param1 = cpu_to_le16(channel->lcid);
1448 struct glink_channel *channel = to_glink_channel(ept);
1450 return __qcom_glink_send(channel, data, len, true);
1455 struct glink_channel *channel = to_glink_channel(ept);
1457 return __qcom_glink_send(channel, data, len, false);
1462 struct glink_channel *channel = to_glink_channel(ept);
1464 return __qcom_glink_send(channel, data, len, true);
1469 struct glink_channel *channel = to_glink_channel(ept);
1471 return __qcom_glink_send(channel, data, len, false);
1475 * Finds the device_node for the glink child interested in this channel.
1478 const char *channel)
1491 if (strcmp(name, channel) == 0)
1523 struct glink_channel *channel;
1532 idr_for_each_entry(&glink->lcids, channel, lcid) {
1533 if (!strcmp(channel->name, name))
1538 if (!channel) {
1539 channel = qcom_glink_alloc_channel(glink, name);
1540 if (IS_ERR(channel))
1541 return PTR_ERR(channel);
1548 ret = idr_alloc(&glink->rcids, channel, rcid, rcid + 1, GFP_ATOMIC);
1550 dev_err(glink->dev, "Unable to insert channel into rcid list\n");
1554 channel->rcid = ret;
1557 complete_all(&channel->open_req);
1566 rpdev->ept = &channel->ept;
1581 channel->rpdev = rpdev;
1588 idr_remove(&glink->rcids, channel->rcid);
1589 channel->rcid = 0;
1594 kref_put(&channel->refcount, qcom_glink_channel_release);
1602 struct glink_channel *channel;
1606 channel = idr_find(&glink->rcids, rcid);
1608 if (WARN(!channel, "close request on unknown channel\n"))
1612 cancel_work_sync(&channel->intent_work);
1614 if (channel->rpdev) {
1615 strscpy_pad(chinfo.name, channel->name, sizeof(chinfo.name));
1621 channel->rpdev = NULL;
1623 qcom_glink_send_close_ack(glink, channel->rcid);
1626 idr_remove(&glink->rcids, channel->rcid);
1627 channel->rcid = 0;
1630 kref_put(&channel->refcount, qcom_glink_channel_release);
1636 struct glink_channel *channel;
1643 channel = idr_find(&glink->lcids, lcid);
1644 if (WARN(!channel, "close ack on unknown channel\n")) {
1649 idr_remove(&glink->lcids, channel->lcid);
1650 channel->lcid = 0;
1653 /* Decouple the potential rpdev from the channel */
1654 if (channel->rpdev) {
1655 strscpy(chinfo.name, channel->name, sizeof(chinfo.name));
1661 channel->rpdev = NULL;
1663 kref_put(&channel->refcount, qcom_glink_channel_release);
1756 struct glink_channel *channel = to_glink_channel(rpdev->ept);
1759 kref_put(&channel->refcount, qcom_glink_channel_release);
1767 struct glink_channel *channel;
1773 channel = qcom_glink_alloc_channel(glink, "rpmsg_chrdev");
1774 if (IS_ERR(channel)) {
1776 return PTR_ERR(channel);
1778 channel->rpdev = rpdev;
1780 rpdev->ept = &channel->ept;
1845 struct glink_channel *channel;
1860 idr_for_each_entry(&glink->lcids, channel, cid)
1861 qcom_glink_intent_req_abort(channel);
1869 idr_for_each_entry(&glink->lcids, channel, cid)
1870 kref_put(&channel->refcount, qcom_glink_channel_release);
1873 idr_for_each_entry(&glink->rcids, channel, cid)
1874 kref_put(&channel->refcount, qcom_glink_channel_release);