Skip to content

Commit d4a1312

Browse files
ns: acknowledge the received creation message
the two phase handsake make the client could initiate the transfer immediately without the server side send any dummy message first. Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
1 parent e9eef7c commit d4a1312

5 files changed

Lines changed: 21 additions & 4 deletions

File tree

lib/include/openamp/rpmsg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ struct rpmsg_device {
155155

156156
/** Create/destroy namespace message */
157157
bool support_ns;
158+
bool support_ack;
158159
};
159160

160161
/**

lib/include/openamp/rpmsg_virtio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern "C" {
2929

3030
/* The feature bitmap for virtio rpmsg */
3131
#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */
32+
#define VIRTIO_RPMSG_F_ACK 1 /* RP supports name service acknowledge */
3233

3334
#ifdef VIRTIO_CACHED_BUFFERS
3435
#warning "VIRTIO_CACHED_BUFFERS is deprecated, please use VIRTIO_USE_DCACHE"

lib/rpmsg/rpmsg.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,13 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev,
357357
rpmsg_register_endpoint(rdev, ept, name, addr, dest, cb, unbind_cb, NULL);
358358
metal_mutex_release(&rdev->lock);
359359

360-
/* Send NS announcement to remote processor */
360+
/* Send NS announcement/acknowledge to remote processor */
361361
if (ept->name[0] && rdev->support_ns &&
362362
ept->dest_addr == RPMSG_ADDR_ANY)
363363
status = rpmsg_send_ns_message(ept, RPMSG_NS_CREATE);
364+
else if (ept->name[0] && rdev->support_ack &&
365+
ept->dest_addr != RPMSG_ADDR_ANY)
366+
status = rpmsg_send_ns_message(ept, RPMSG_NS_CREATE_ACK);
364367

365368
if (status)
366369
rpmsg_unregister_endpoint(ept);

lib/rpmsg/rpmsg_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ enum rpmsg_ns_flags {
4444
RPMSG_NS_CREATE = 0,
4545
/** A known remote service was just destroyed */
4646
RPMSG_NS_DESTROY = 1,
47+
/** Acknowledge the previous creation message */
48+
RPMSG_NS_CREATE_ACK = 2,
4749
};
4850

4951
/**

lib/rpmsg/rpmsg_virtio.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ static int rpmsg_virtio_ns_callback(struct rpmsg_endpoint *ept, void *data,
656656
*/
657657
ept_to_release = _ept && _ept->release_cb;
658658

659-
if (ns_msg->flags & RPMSG_NS_DESTROY) {
659+
if (ns_msg->flags == RPMSG_NS_DESTROY) {
660660
if (_ept)
661661
_ept->dest_addr = RPMSG_ADDR_ANY;
662662
if (ept_to_release)
@@ -671,7 +671,7 @@ static int rpmsg_virtio_ns_callback(struct rpmsg_endpoint *ept, void *data,
671671
rpmsg_ept_decref(_ept);
672672
metal_mutex_release(&rdev->lock);
673673
}
674-
} else {
674+
} else if (ns_msg->flags == RPMSG_NS_CREATE) {
675675
if (!_ept) {
676676
/*
677677
* send callback to application, that can
@@ -685,7 +685,15 @@ static int rpmsg_virtio_ns_callback(struct rpmsg_endpoint *ept, void *data,
685685
} else {
686686
_ept->dest_addr = dest;
687687
metal_mutex_release(&rdev->lock);
688+
if (_ept->name[0] && rdev->support_ack)
689+
rpmsg_send_ns_message(_ept,
690+
RPMSG_NS_CREATE_ACK);
688691
}
692+
} else { /* RPMSG_NS_CREATE_ACK */
693+
/* save the received destination address */
694+
if (_ept)
695+
_ept->dest_addr = dest;
696+
metal_mutex_release(&rdev->lock);
689697
}
690698

691699
return RPMSG_SUCCESS;
@@ -827,7 +835,9 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
827835
status = virtio_get_features(rvdev->vdev, &features);
828836
if (status)
829837
return status;
838+
830839
rdev->support_ns = !!(features & (1 << VIRTIO_RPMSG_F_NS));
840+
rdev->support_ack = !!(features & (1 << VIRTIO_RPMSG_F_ACK));
831841

832842
if (VIRTIO_ROLE_IS_DRIVER(rvdev->vdev)) {
833843
/*
@@ -926,7 +936,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
926936
* Create name service announcement endpoint if device supports name
927937
* service announcement feature.
928938
*/
929-
if (rdev->support_ns) {
939+
if (rdev->support_ns || rdev->support_ack) {
930940
rpmsg_register_endpoint(rdev, &rdev->ns_ept, "NS",
931941
RPMSG_NS_EPT_ADDR, RPMSG_NS_EPT_ADDR,
932942
rpmsg_virtio_ns_callback, NULL, rvdev);

0 commit comments

Comments
 (0)