From dc9a645b84c65d8a1b353d8df4b9885951321641 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 7 Jan 2019 02:15:42 +0800 Subject: [PATCH] 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 --- lib/include/openamp/rpmsg.h | 1 + lib/include/openamp/rpmsg_virtio.h | 1 + lib/rpmsg/rpmsg.c | 5 ++++- lib/rpmsg/rpmsg_internal.h | 4 ++-- lib/rpmsg/rpmsg_virtio.c | 15 ++++++++++++--- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/include/openamp/rpmsg.h b/lib/include/openamp/rpmsg.h index 82371ea77..0754b7360 100644 --- a/lib/include/openamp/rpmsg.h +++ b/lib/include/openamp/rpmsg.h @@ -149,6 +149,7 @@ struct rpmsg_device { /** Create/destroy namespace message */ bool support_ns; + bool support_ack; }; /** diff --git a/lib/include/openamp/rpmsg_virtio.h b/lib/include/openamp/rpmsg_virtio.h index 58308f70a..b12a46876 100644 --- a/lib/include/openamp/rpmsg_virtio.h +++ b/lib/include/openamp/rpmsg_virtio.h @@ -29,6 +29,7 @@ extern "C" { /* The feature bitmap for virtio rpmsg */ #define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */ +#define VIRTIO_RPMSG_F_ACK 1 /* RP supports name service acknowledge */ #ifdef VIRTIO_CACHED_BUFFERS #warning "VIRTIO_CACHED_BUFFERS is deprecated, please use VIRTIO_USE_DCACHE" diff --git a/lib/rpmsg/rpmsg.c b/lib/rpmsg/rpmsg.c index 3be947d3c..ddd7f4fdd 100644 --- a/lib/rpmsg/rpmsg.c +++ b/lib/rpmsg/rpmsg.c @@ -326,10 +326,13 @@ int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev, rpmsg_register_endpoint(rdev, ept, name, addr, dest, cb, unbind_cb); metal_mutex_release(&rdev->lock); - /* Send NS announcement to remote processor */ + /* Send NS announcement/acknowledge to remote processor */ if (ept->name[0] && rdev->support_ns && ept->dest_addr == RPMSG_ADDR_ANY) status = rpmsg_send_ns_message(ept, RPMSG_NS_CREATE); + else if (ept->name[0] && rdev->support_ack && + ept->dest_addr != RPMSG_ADDR_ANY) + status = rpmsg_send_ns_message(ept, RPMSG_NS_CREATE_ACK); if (status) rpmsg_unregister_endpoint(ept); diff --git a/lib/rpmsg/rpmsg_internal.h b/lib/rpmsg/rpmsg_internal.h index f1c61c5f2..ede13e971 100644 --- a/lib/rpmsg/rpmsg_internal.h +++ b/lib/rpmsg/rpmsg_internal.h @@ -41,12 +41,12 @@ extern "C" { * * @RPMSG_NS_CREATE: a new remote service was just created * @RPMSG_NS_DESTROY: a known remote service was just destroyed - * @RPMSG_NS_CREATE_WITH_ACK: a new remote service was just created waiting - * acknowledgment. + * @RPMSG_NS_CREATE_ACK: acknowledge the previous creation message */ enum rpmsg_ns_flags { RPMSG_NS_CREATE = 0, RPMSG_NS_DESTROY = 1, + RPMSG_NS_CREATE_ACK = 2, }; /** diff --git a/lib/rpmsg/rpmsg_virtio.c b/lib/rpmsg/rpmsg_virtio.c index 66623e54b..b9bc3cfe7 100644 --- a/lib/rpmsg/rpmsg_virtio.c +++ b/lib/rpmsg/rpmsg_virtio.c @@ -669,7 +669,7 @@ static int rpmsg_virtio_ns_callback(struct rpmsg_endpoint *ept, void *data, */ ept_to_release = _ept && _ept->release_cb; - if (ns_msg->flags & RPMSG_NS_DESTROY) { + if (ns_msg->flags == RPMSG_NS_DESTROY) { if (_ept) _ept->dest_addr = RPMSG_ADDR_ANY; if (ept_to_release) @@ -684,7 +684,7 @@ static int rpmsg_virtio_ns_callback(struct rpmsg_endpoint *ept, void *data, rpmsg_ept_decref(_ept); metal_mutex_release(&rdev->lock); } - } else { + } else if (ns_msg->flags == RPMSG_NS_CREATE) { if (!_ept) { /* * send callback to application, that can @@ -698,7 +698,15 @@ static int rpmsg_virtio_ns_callback(struct rpmsg_endpoint *ept, void *data, } else { _ept->dest_addr = dest; metal_mutex_release(&rdev->lock); + if (_ept->name[0] && rdev->support_ack) + rpmsg_send_ns_message(_ept, + RPMSG_NS_CREATE_ACK); } + } else { /* RPMSG_NS_CREATE_ACK */ + /* save the received destination address */ + if (_ept) + _ept->dest_addr = dest; + metal_mutex_release(&rdev->lock); } return RPMSG_SUCCESS; @@ -853,6 +861,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev, #endif /*!VIRTIO_DRIVER_ONLY*/ vdev->features = rpmsg_virtio_get_features(rvdev); rdev->support_ns = !!(vdev->features & (1 << VIRTIO_RPMSG_F_NS)); + rdev->support_ack = !!(vdev->features & (1 << VIRTIO_RPMSG_F_ACK)); #ifndef VIRTIO_DEVICE_ONLY if (role == RPMSG_HOST) { @@ -961,7 +970,7 @@ int rpmsg_init_vdev_with_config(struct rpmsg_virtio_device *rvdev, * Create name service announcement endpoint if device supports name * service announcement feature. */ - if (rdev->support_ns) { + if (rdev->support_ns || rdev->support_ack) { rpmsg_register_endpoint(rdev, &rdev->ns_ept, "NS", RPMSG_NS_EPT_ADDR, RPMSG_NS_EPT_ADDR, rpmsg_virtio_ns_callback, NULL);