rpmsg: change channel state if nameservice is sent
authorWendy Liang <jliang@xilinx.com>
Tue, 13 Dec 2016 01:15:56 +0000 (17:15 -0800)
committerWendy Liang <jliang@xilinx.com>
Tue, 13 Dec 2016 01:22:43 +0000 (17:22 -0800)
Should not blindly change the channel state after
sending the name service message.
because it is possible that name service fails to send.
e.g. it fails to get the buffer to send the name service
message.

Signed-off-by: Wendy Liang <jliang@xilinx.com>
lib/include/openamp/rpmsg_core.h
lib/rpmsg/rpmsg_core.c

index ed17a2a3cf70606fd28e6307c0c0e251700b3b5b..62a410b2a6b7e5c7bf8bd0b9b7b530593caea0ba 100644 (file)
@@ -146,7 +146,7 @@ struct rpmsg_endpoint *_create_endpoint(struct remote_device *rdev,
                                        unsigned long addr);
 void _destroy_endpoint(struct remote_device *rdev,
                       struct rpmsg_endpoint *rp_ept);
-void rpmsg_send_ns_message(struct remote_device *rdev,
+int rpmsg_send_ns_message(struct remote_device *rdev,
                           struct rpmsg_channel *rp_chnl, unsigned long flags);
 int rpmsg_enqueue_buffer(struct remote_device *rdev, void *buffer,
                         unsigned long len, unsigned short idx);
index cd14ef5fdad9d817be9361ceccf1b59ef31b1220..06faa053d938df346ecd54be1f39f3ca9587d8e8 100644 (file)
@@ -291,7 +291,7 @@ void _destroy_endpoint(struct remote_device *rdev,
  * @param flags   - Channel creation/deletion flags
  *
  */
-void rpmsg_send_ns_message(struct remote_device *rdev,
+int rpmsg_send_ns_message(struct remote_device *rdev,
                           struct rpmsg_channel *rp_chnl, unsigned long flags)
 {
 
@@ -306,7 +306,7 @@ void rpmsg_send_ns_message(struct remote_device *rdev,
        rp_hdr = (struct rpmsg_hdr *)rpmsg_get_tx_buffer(rdev, &len, &idx);
        if (!rp_hdr) {
                metal_mutex_release(&rdev->lock);
-               return;
+               return -RPMSG_ERR_NO_BUFF;
        }
 
        /* Fill out name service data. */
@@ -324,6 +324,7 @@ void rpmsg_send_ns_message(struct remote_device *rdev,
        virtqueue_kick(rdev->tvq);
 
        metal_mutex_release(&rdev->lock);
+       return RPMSG_SUCCESS;
 }
 
 /**
@@ -513,16 +514,16 @@ static void rpmsg_tx_callback(struct virtqueue *vq)
                        if (rp_chnl->state == RPMSG_CHNL_STATE_IDLE) {
 
                                if (rdev->support_ns) {
-                                       rp_chnl->state = RPMSG_CHNL_STATE_NS;
+                                       if (rpmsg_send_ns_message(rdev, rp_chnl,
+                                                     RPMSG_NS_CREATE) ==
+                                               RPMSG_SUCCESS)
+                                               rp_chnl->state =
+                                                       RPMSG_CHNL_STATE_NS;
                                } else {
                                        rp_chnl->state =
                                            RPMSG_CHNL_STATE_ACTIVE;
                                }
 
-                               if (rp_chnl->state == RPMSG_CHNL_STATE_NS) {
-                                       rpmsg_send_ns_message(rdev, rp_chnl,
-                                                             RPMSG_NS_CREATE);
-                               }
                        }
 
                }
@@ -558,9 +559,11 @@ void rpmsg_rx_callback(struct virtqueue *vq)
                                struct rpmsg_channel, node);
                        if (rp_chnl->state == RPMSG_CHNL_STATE_IDLE) {
                                if (rdev->support_ns) {
-                                       rp_chnl->state = RPMSG_CHNL_STATE_NS;
-                                       rpmsg_send_ns_message(rdev, rp_chnl,
-                                                     RPMSG_NS_CREATE);
+                                       if (rpmsg_send_ns_message(rdev, rp_chnl,
+                                                     RPMSG_NS_CREATE) ==
+                                               RPMSG_SUCCESS)
+                                               rp_chnl->state =
+                                                       RPMSG_CHNL_STATE_NS;
                                } else {
                                        rp_chnl->state = RPMSG_CHNL_STATE_ACTIVE;
                                }