[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH 13/15] plat/tap: Support tap_netdev_recv



Implement tap_receive.

Signed-off-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>
---
 plat/drivers/tap/tap.c           | 47 +++++++++++++++++++++++++++++++++++++++-
 plat/linuxu/include/linuxu/tap.h |  1 +
 plat/linuxu/tap_io.c             | 13 +++++++++++
 3 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index ab864a1..69a042a 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -236,12 +236,57 @@ static int tap_netdev_recv(struct uk_netdev *dev,
                           struct uk_netdev_rx_queue *queue,
                           struct uk_netbuf **pkt)
 {
-       int rc = -EINVAL;
+       int rc = 0;
+       struct tap_net_dev *tdev __maybe_unused;
+       struct uk_netbuf *_pkt = NULL;
 
        UK_ASSERT(dev);
        UK_ASSERT(queue && pkt);
 
+       tdev = to_tapnetdev(dev);
+
+       if (!queue->alloc_rxpkts)
+               return -EINVAL;
+
+
+       /**
+        * Allocate the packet in which the packet will be received.
+        */
+       rc = queue->alloc_rxpkts(queue->alloc_rxpkts_argp, &_pkt, 1);
+       if (rc == 0) {
+               uk_pr_err(DRIVER_NAME": Failed to allocate the memory\n");
+               rc = -ENOMEM;
+               _pkt = NULL;
+               goto err_exit;
+       }
+       uk_pr_debug(DRIVER_NAME": Receiving on interface %s(%d) %p(%d)\n", 
tdev->name,
+                   queue->fd, _pkt->data, _pkt->len);
+       rc = tap_read(queue->fd, _pkt->data, _pkt->len);
+
+       if (rc > 0) {
+               uk_pr_debug(DRIVER_NAME": Recv pkt size: %d\n", rc);
+               /* Setting the length of the packet */
+               _pkt->len = rc;
+               rc = UK_NETDEV_STATUS_SUCCESS | UK_NETDEV_STATUS_MORE;
+       } else if (rc == 0 || rc == -EWOULDBLOCK || rc == -EAGAIN) {
+               rc = 0;
+               goto err_exit;
+       } else {
+               uk_pr_err(DRIVER_NAME": Failed(%d) to read the packet\n", rc);
+               goto err_exit;
+       }
+       uk_pr_debug("setting the buf %p\n", *pkt);
+
+       *pkt = _pkt;
+
+exit:
        return rc;
+
+err_exit:
+       if (_pkt)
+               uk_netbuf_free(_pkt);
+       *pkt = NULL;
+       goto exit;
 }
 
 static int tap_netdev_xmit(struct uk_netdev *dev,
diff --git a/plat/linuxu/include/linuxu/tap.h b/plat/linuxu/include/linuxu/tap.h
index 97cf4a1..fd1c773 100644
--- a/plat/linuxu/include/linuxu/tap.h
+++ b/plat/linuxu/include/linuxu/tap.h
@@ -153,5 +153,6 @@ int tap_open(__u32 flags);
 int tap_close(int fd);
 int tap_dev_configure(int fd, __u32 feature_flags, void *arg);
 int tap_netif_configure(int fd, __u32 request, void *arg);
+__ssz tap_read(int fd, void *buf, size_t count);
 
 #endif /* LINUXU_TAP_H */
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index 50cd32e..c29dfe7 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -105,6 +105,19 @@ exit_error:
        return rc;
 }
 
+ssize_t tap_read(int fd, void *buf, size_t count)
+{
+       ssize_t rc = -EINTR;
+
+       while (rc == -EINTR)
+               rc = sys_read(fd, buf, count);
+
+       if (rc < 0)
+               uk_pr_err("Failed(%ld) to read from the tap device\n", rc);
+
+       return rc;
+}
+
 int tap_close(int fd)
 {
        return sys_close(fd);
-- 
2.7.4


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.