Skip to content

Commit dc9a645

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 79b795e commit dc9a645

5 files changed

Lines changed: 20 additions & 6 deletions

File tree

lib/include/openamp/rpmsg.h

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

150150
/** Create/destroy namespace message */
151151
bool support_ns;
152+
bool support_ack;
152153
};
153154

154155
/**

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
@@ -326,10 +326,13 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev,
326326
rpmsg_register_endpoint(rdev, ept, name, addr, dest, cb, unbind_cb);
327327
metal_mutex_release(&rdev->lock);
328328

329-
/* Send NS announcement to remote processor */
329+
/* Send NS announcement/acknowledge to remote processor */
330330
if (ept->name[0] && rdev->support_ns &&
331331
ept->dest_addr == RPMSG_ADDR_ANY)
332332
status = rpmsg_send_ns_message(ept, RPMSG_NS_CREATE);
333+
else if (ept->name[0] && rdev->support_ack &&
334+
ept->dest_addr != RPMSG_ADDR_ANY)
335+
status = rpmsg_send_ns_message(ept, RPMSG_NS_CREATE_ACK);
333336

334337
if (status)
335338
rpmsg_unregister_endpoint(ept);

lib/rpmsg/rpmsg_internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ extern "C" {
4141
*
4242
* @RPMSG_NS_CREATE: a new remote service was just created
4343
* @RPMSG_NS_DESTROY: a known remote service was just destroyed
44-
* @RPMSG_NS_CREATE_WITH_ACK: a new remote service was just created waiting
45-
* acknowledgment.
44+
* @RPMSG_NS_CREATE_ACK: acknowledge the previous creation message
4645
*/
4746
enum rpmsg_ns_flags {
4847
RPMSG_NS_CREATE = 0,
4948
RPMSG_NS_DESTROY = 1,
49+
RPMSG_NS_CREATE_ACK = 2,
5050
};
5151

5252
/**

lib/rpmsg/rpmsg_virtio.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ static int rpmsg_virtio_ns_callback(struct rpmsg_endpoint *ept, void *data,
669669
*/
670670
ept_to_release = _ept && _ept->release_cb;
671671

672-
if (ns_msg->flags & RPMSG_NS_DESTROY) {
672+
if (ns_msg->flags == RPMSG_NS_DESTROY) {
673673
if (_ept)
674674
_ept->dest_addr = RPMSG_ADDR_ANY;
675675
if (ept_to_release)
@@ -684,7 +684,7 @@ static int rpmsg_virtio_ns_callback(struct rpmsg_endpoint *ept, void *data,
684684
rpmsg_ept_decref(_ept);
685685
metal_mutex_release(&rdev->lock);
686686
}
687-
} else {
687+
} else if (ns_msg->flags == RPMSG_NS_CREATE) {
688688
if (!_ept) {
689689
/*
690690
* send callback to application, that can
@@ -698,7 +698,15 @@ static int rpmsg_virtio_ns_callback(struct rpmsg_endpoint *ept, void *data,
698698
} else {
699699
_ept->dest_addr = dest;
700700
metal_mutex_release(&rdev->lock);
701+
if (_ept->name[0] && rdev->support_ack)
702+
rpmsg_send_ns_message(_ept,
703+
RPMSG_NS_CREATE_ACK);
701704
}
705+
} else { /* RPMSG_NS_CREATE_ACK */
706+
/* save the received destination address */
707+
if (_ept)
708+
_ept->dest_addr = dest;
709+
metal_mutex_release(&rdev->lock);
702710
}
703711

704712
return RPMSG_SUCCESS;
@@ -853,6 +861,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
853861
#endif /*!VIRTIO_DRIVER_ONLY*/
854862
vdev->features = rpmsg_virtio_get_features(rvdev);
855863
rdev->support_ns = !!(vdev->features & (1 << VIRTIO_RPMSG_F_NS));
864+
rdev->support_ack = !!(vdev->features & (1 << VIRTIO_RPMSG_F_ACK));
856865

857866
#ifndef VIRTIO_DEVICE_ONLY
858867
if (role == RPMSG_HOST) {
@@ -961,7 +970,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev,
961970
* Create name service announcement endpoint if device supports name
962971
* service announcement feature.
963972
*/
964-
if (rdev->support_ns) {
973+
if (rdev->support_ns || rdev->support_ack) {
965974
rpmsg_register_endpoint(rdev, &rdev->ns_ept, "NS",
966975
RPMSG_NS_EPT_ADDR, RPMSG_NS_EPT_ADDR,
967976
rpmsg_virtio_ns_callback, NULL);

0 commit comments

Comments
 (0)