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

[Minios-devel] [UNIKRAFT PATCH v2 11/12] plat/xen/drivers/net: Add transmit operation


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 1 Apr 2019 16:42:51 +0300
  • Cc: felipe.huici@xxxxxxxxx, Razvan Cojocaru <razvan.cojocaru93@xxxxxxxxx>, Florian.Schmidt@xxxxxxxxx, sharan.santhanam@xxxxxxxxx, simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx
  • Delivery-date: Mon, 01 Apr 2019 13:43:09 +0000
  • Ironport-phdr: 9a23:pGqXeReSsYMJsB5Q9oBwl6JAlGMj4u6mDksu8pMizoh2WeGdxc27bBaN2/xhgRfzUJnB7Loc0qyK6vimCDBLv8rJmUtBWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYdFRrlKAV6OPn+FJLMgMSrzeCy/IDYbxlViDanbr5+MQm6oR/Vu8QZjodvK6k8wQbVr3VVfOhb2XlmLk+JkRbm4cew8p9j8yBOtP8k6sVNT6b0cbkmQLJBFDgpPHw768PttRnYUAuA/WAcXXkMkhpJGAfK8hf3VYrsvyTgt+p93C6aPdDqTb0xRD+v4btnRAPuhSwaLDMy7n3ZhdJsg6JauBKhpgJww4jIYIGOKfFyerrRcc4GSWZdW8pcUTFKDIGhYIsVF+cPPfhWoZTzqVUNqhWxBwesCfjzxjNUnHL6wbc33/g9HQzAwQcuH8gOsHPRrNjtKqoSVvu1zLXJzTXFcvhY3yr96JDVchs8pvyDQbVwcdHNyUkuEQPJlFGQqZH9PzOIzekCr3Ob4/B4VeKykGErsRtxoj+2y8oql4LHhZoVx0jZ+Sh23Yo5P961RU5hbdK6DpddtTuWOoVuTs8/TGxkpTw2x74GtJKhYiQHxpoqywTCZ/GIbYSF5A/oWvyLLjdinn1lfaqyhxO18Ue91OLxTtK00FNWripdldnMq2wN2wTT6seZTvt9+V+s2SiK1w/J6+FEJVo4mrbAK5I72r4wi4EcvV7ZHi/xgEn2jamWeVs4+uWw9ujqbajqqoWfOoJ0kA3yLLoil86lDek2KgQOWnKU+eW41L3t5035R7BKg+Uqnaneq5DaOcUbpqijDw9Rz4Yj8wu/Aiy639QDh3UHNE9Fdwmdg4jzPFHCOOr4Auung1SwjDdrwOjLPqf7DZTMMHjMirHhcaxh5E5bygozysxQ6IhOCrEcJP/+VFT8tNPdDhAjMgy0x/zrB8l61oMbQWiPGLOWMLvOsV+U4eIiO+yMZI4TuDb8LPgl/OfigmInll8DY6ap2YAaaHS5HvR9P0WZemDgg9gfHmcMpAY+S/bqiFKaWz5Je3myR7485i08CI++DYnDQoetgKaA3CihGJ1afH1IBUyMEXftdoWLRusMZTmUIsB/jjMEUaKuRJQ72R6wqQ/w06BnIfbM+i0EqZLj08B45+PNmhE29Dx0F9qS33uNT2Fpn2MHWz420bt5oUNj1liD1bJ3jOdCGdNN+vNDSh06OoLEz+xmF9DyXRrMfsyJSFm8WNWpGzcxQsgqw9AUZUZ9B9WigQrF3yWwBr8YjLqLC4Io/aLYxXf+PNxxxGjb1KM5lVkpXtNPNXG6hq547wXTHI/Jk0Cel6asb6gc3zPN+3mFzWuPok5YShV9UaPbUn8DYkvZt8/26lncQL+zEb4nKBdOydaeKqtWbd3klVVHROr5ONTfeW6xhWCwBRKUybOMb4rqfHsd0T7bCEcajw8T+WyJOhMkCii/vmKNRABpQFfuZULr6qxypW22SmcwzhqWdAtx2rzz/QQa1tKGTPZG9bUfpCYn4xFpBEv1i9nREMaBoUxlYb1BSdgmpk9a3yTDsFoubdSbM6l+iwtGIExMtET02kAyU90YnA==
  • Ironport-sdr: wlyMPqeylV7GQ+gTkKSFpif/Jk+MqGJOfeLqmT4GPiCSUyBlZvKodvh7wQowkuHd7BWI+8HKpU GycSDpPwhBqA==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

This patch adds support for transmit operation.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@xxxxxxxxx>
---
 plat/xen/drivers/net/netfront.c | 102 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)

diff --git a/plat/xen/drivers/net/netfront.c b/plat/xen/drivers/net/netfront.c
index d7610748..be338791 100644
--- a/plat/xen/drivers/net/netfront.c
+++ b/plat/xen/drivers/net/netfront.c
@@ -39,6 +39,7 @@
 #include <uk/alloc.h>
 #include <uk/netdev_driver.h>
 #include <xen-x86/mm.h>
+#include <xen-x86/irq.h>
 #include <xenbus/xenbus.h>
 #include "netfront.h"
 #include "netfront_xb.h"
@@ -78,6 +79,106 @@ static uint16_t get_id_from_freelist(uint16_t *freelist)
        return id;
 }
 
+static int network_tx_buf_gc(struct uk_netdev_tx_queue *txq)
+{
+       RING_IDX prod, cons;
+       netif_tx_response_t *tx_rsp;
+       uint16_t id;
+       bool more_to_do;
+       int count = 0;
+
+       do {
+               prod = txq->ring.sring->rsp_prod;
+               rmb(); /* Ensure we see responses up to 'rp'. */
+
+               for (cons = txq->ring.rsp_cons; cons != prod; cons++) {
+                       tx_rsp = RING_GET_RESPONSE(&txq->ring, cons);
+
+                       if (tx_rsp->status == NETIF_RSP_NULL)
+                               continue;
+
+                       if (tx_rsp->status == NETIF_RSP_ERROR)
+                               uk_pr_err("packet error\n");
+
+                       id  = tx_rsp->id;
+                       UK_ASSERT(id < NET_TX_RING_SIZE);
+
+                       gnttab_end_access(txq->gref[id]);
+                       txq->gref[id] = GRANT_INVALID_REF;
+
+                       add_id_to_freelist(id, txq->freelist);
+                       uk_semaphore_up(&txq->sem);
+
+                       count++;
+               }
+
+               txq->ring.rsp_cons = prod;
+
+               RING_FINAL_CHECK_FOR_RESPONSES(&txq->ring, more_to_do);
+       } while (more_to_do);
+
+       return count;
+}
+
+static int netfront_xmit(struct uk_netdev *n,
+               struct uk_netdev_tx_queue *txq,
+               struct uk_netbuf *pkt)
+{
+       struct netfront_dev *nfdev;
+       unsigned long flags;
+       uint16_t id;
+       RING_IDX req_prod;
+       netif_tx_request_t *tx_req;
+       int notify;
+       int status = 0, count;
+
+       UK_ASSERT(n != NULL);
+       UK_ASSERT(txq != NULL);
+       UK_ASSERT(pkt != NULL);
+       UK_ASSERT(pkt->len < PAGE_SIZE);
+
+       nfdev = to_netfront_dev(n);
+
+       /* get request id */
+       uk_semaphore_down(&txq->sem);
+       local_irq_save(flags);
+       id = get_id_from_freelist(txq->freelist);
+       local_irq_restore(flags);
+
+       /* get request */
+       req_prod = txq->ring.req_prod_pvt;
+       tx_req = RING_GET_REQUEST(&txq->ring, req_prod);
+
+       /* setup grant for buffer data */
+       txq->gref[id] = tx_req->gref =
+               gnttab_grant_access(nfdev->xendev->otherend_id,
+                       virt_to_mfn(pkt->data), 1);
+       UK_ASSERT(tx_req->gref != GRANT_INVALID_REF);
+
+       tx_req->offset = 0;
+       tx_req->size = (uint16_t) pkt->len;
+       tx_req->flags = 0;
+       tx_req->id = id;
+
+       txq->ring.req_prod_pvt = req_prod + 1;
+       wmb(); /* Ensure backend sees requests */
+
+       RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&txq->ring, notify);
+       if (notify)
+               notify_remote_via_evtchn(txq->evtchn);
+
+       status |= UK_NETDEV_STATUS_SUCCESS;
+
+       /* some cleanup */
+       local_irq_save(flags);
+       count = network_tx_buf_gc(txq);
+       local_irq_restore(flags);
+
+       status |= likely(count > 0) ? UK_NETDEV_STATUS_MORE : 0x0;
+
+       return status;
+}
+
 static int netfront_rxq_enqueue(struct uk_netdev_rx_queue *rxq,
                struct uk_netbuf *netbuf)
 {
@@ -599,6 +700,7 @@ static int netfront_add_dev(struct xenbus_device *xendev)
        }
 
        /* register netdev */
+       nfdev->netdev.tx_one = netfront_xmit;
        nfdev->netdev.ops = &netfront_ops;
        rc = uk_netdev_drv_register(&nfdev->netdev, drv_allocator, DRIVER_NAME);
        if (rc < 0) {
-- 
2.11.0


_______________________________________________
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®.