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

[Minios-devel] [UNIKRAFT PATCH v2 06/12] plat/xen/drivers/net: Create netfront queues


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 1 Apr 2019 16:42:46 +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:06 +0000
  • Ironport-phdr: 9a23:G2GQPBA/WUphxRwiEeFCUyQJP3N1i/DPJgcQr6AfoPdwSP36r86wAkXT6L1XgUPTWs2DsrQY0rKQ4vyrBzBIyK3CmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TW94jEIBxrwKxd+KPjrFY7OlcS30P2594HObwlSizexfK9+IA+yoAjeucUbgIRvIbstxxXUpXdFZ/5Yzn5yK1KJmBb86Maw/Jp9/ClVpvks6c1OX7jkcqohVbBXAygoPG4z5M3wqBnMVhCP6WcGUmUXiRVHHQ7I5wznU5jrsyv6su192DSGPcDzULs5Vyiu47ttRRT1kyoMKSI3/3/LhcxxlKJboQyupxpjw47PfYqZMONycr7Bcd8GQGZMWNtaWS5cDYOmd4YBD/QPM/tWoYf+oFUBrxW+CBKwCO/z0DJEmmX70bEm3+knDArI3BYgH9ULsHnMstj1M7wSUfy0zKnO0D7Nae5W2S/g6IPVdR0uvfaMXalsccrQz0kjDQfFjkiIqYz4JD6ayv8Nv3KD7+p9Tu2jkXQnqwZorzWp28wiiZHJi5oIxl3L6Cl12oU4KN2iREJlf9KpEoFcui+CO4drTc4uXntktSU6x7Ecp5K2ciYHxI46yxPQdfCKdZWD7Aj5W+aLOzh4gWpoeLe4hxmv70et0vb8Vsyo0FZSqSpFj8XMumgN1xPN7siHTeNw/lmk2TmV1gDT7vtILlwvlabBM54h36U/moAJsUTEBiP2mUP2g7GKdkg85+Sl5Pnrbq/lq5KcLYN4lB/yP6Y0lsGxGeg4NxIBX2mf+eSyzr3j+kj5Ta1Wgf0xianZrJHaJcIBqq69Hg9Vypsj5g2jADe9ytgYhWQHI0lfdBKdiIjlI0vOL+zgDfejn1Ssly9mx+rcMbzgHJXCNH7DnK39crZ66U5czxY8wspF55JJDrwMLun+WkD0tNPCDx85Nxa4zPrgCNV4zokeQ36AAreFMKPOtl+F/ucvI+iKZI8Uvzb9MOEp6OPwgn8nh1AdebKk3Z8WaHCjAvRmOF+VYHXyjdcHC2sKuRA+TOPygl2YTTFTf2qyX7475jwjCIymCYDDRpqsgLOb2ie3BIBYaXxGClCJEHfnapmEVuwKaC2MPsBhliYLWqO7R4A/yBGkrBX6xKZ/LurI5i0Ysoru1NZr6O3XlBEy7SJ7A96d02GQTmF7gmIISiQw3K9hvUN9zk2M3rNij/NGCNxZ/+lJXRsiNZ7A0+x6DMj/WhnBftiTUlapWNOmDSsqTt0rxd8Of0Z9FM+kjh/Z2iqnGLkVmKKXC5ww6K3TxGL9KNhgy3zezqkuk0EmQtdTNW2hnqN/7AnTB4vOk0Wfjaqqdrkc0zDL9GaC02WOplpVUAhuXqrZWXAQfFDZoc7n6UPfV7WuE6goMhNdyc6eLatHct3ojUhcRPfiItjefWWxm2OsChaIxbOMa5Tqdn4b3CrDFEcElxoc8m2cOQcgGyfy617ZWTlvE1PoeAbg/PdzrFu/T1Qo1EeaYksn0KC6qTAPgvnJYPQIwrMC8AM8syg8SF26xM7XDZyEuhJ8VK5HJ8sg6hFd0jSK5ERGIpW8IvU61RYleANtsharjk0vBw==
  • Ironport-sdr: 0VwWZrx85lWnsURvxVGcnsrHmZ/FqjCK85O65zThGQoBDtNfrdYOOFobaEm1bf5t71aR29i4bD N18RfjycesxA==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Netfront devices operate pairs of Rx/Tx queues.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@xxxxxxxxx>
---
 plat/xen/drivers/net/netfront.c    | 82 ++++++++++++++++++++++++++++++++++++++
 plat/xen/drivers/net/netfront.h    | 20 ++++++++++
 plat/xen/drivers/net/netfront_xs.c | 18 ++++++++-
 3 files changed, 118 insertions(+), 2 deletions(-)

diff --git a/plat/xen/drivers/net/netfront.c b/plat/xen/drivers/net/netfront.c
index f6ec8497..dff667af 100644
--- a/plat/xen/drivers/net/netfront.c
+++ b/plat/xen/drivers/net/netfront.c
@@ -49,6 +49,85 @@
 
 static struct uk_alloc *drv_allocator;
 
+static int netfront_rxtx_alloc(struct netfront_dev *nfdev,
+               const struct uk_netdev_conf *conf)
+{
+       int rc = 0;
+
+       if (conf->nb_tx_queues != conf->nb_rx_queues) {
+               uk_pr_err("Different number of queues not supported\n");
+               rc = -ENOTSUP;
+               goto err_free_txrx;
+       }
+
+       nfdev->max_queue_pairs =
+               MIN(nfdev->max_queue_pairs, conf->nb_tx_queues);
+
+       nfdev->txqs = uk_calloc(drv_allocator,
+               nfdev->max_queue_pairs, sizeof(*nfdev->txqs));
+       if (unlikely(!nfdev->txqs)) {
+               uk_pr_err("Failed to allocate memory for tx queues\n");
+               rc = -ENOMEM;
+               goto err_free_txrx;
+       }
+
+       nfdev->rxqs = uk_calloc(drv_allocator,
+               nfdev->max_queue_pairs, sizeof(*nfdev->rxqs));
+       if (unlikely(!nfdev->rxqs)) {
+               uk_pr_err("Failed to allocate memory for rx queues\n");
+               rc = -ENOMEM;
+               goto err_free_txrx;
+       }
+
+       return rc;
+
+err_free_txrx:
+       if (!nfdev->rxqs)
+               uk_free(drv_allocator, nfdev->rxqs);
+       if (!nfdev->txqs)
+               uk_free(drv_allocator, nfdev->txqs);
+
+       return rc;
+}
+
+static int netfront_configure(struct uk_netdev *n,
+               const struct uk_netdev_conf *conf)
+{
+       int rc;
+       struct netfront_dev *nfdev;
+
+       UK_ASSERT(n != NULL);
+       UK_ASSERT(conf != NULL);
+
+       nfdev = to_netfront_dev(n);
+
+       rc = netfront_rxtx_alloc(nfdev, conf);
+       if (rc != 0) {
+               uk_pr_err("Failed to allocate rx and tx rings %d\n", rc);
+               goto out;
+       }
+
+out:
+       return rc;
+}
+
+static void netfront_info_get(struct uk_netdev *n,
+               struct uk_netdev_info *dev_info)
+{
+       struct netfront_dev *nfdev;
+
+       UK_ASSERT(n != NULL);
+       UK_ASSERT(dev_info != NULL);
+
+       nfdev = to_netfront_dev(n);
+       dev_info->max_rx_queues = nfdev->max_queue_pairs;
+       dev_info->max_tx_queues = nfdev->max_queue_pairs;
+       dev_info->max_mtu = nfdev->mtu;
+       dev_info->nb_encap_tx = 0;
+       dev_info->nb_encap_rx = 0;
+       dev_info->align = PAGE_SIZE;
+}
+
 static const void *netfront_einfo_get(struct uk_netdev *n,
                enum uk_netdev_einfo_type einfo_type)
 {
@@ -100,6 +179,8 @@ static unsigned int netfront_promisc_get(struct uk_netdev 
*n)
 }
 
 static const struct uk_netdev_ops netfront_ops = {
+       .configure = netfront_configure,
+       .info_get = netfront_info_get,
        .einfo_get = netfront_einfo_get,
        .hwaddr_get = netfront_mac_get,
        .mtu_get = netfront_mtu_get,
@@ -121,6 +202,7 @@ static int netfront_add_dev(struct xenbus_device *xendev)
 
        nfdev->xendev = xendev;
        nfdev->mtu = ETH_PKT_PAYLOAD_LEN;
+       nfdev->max_queue_pairs = 1;
 
        /* Xenbus initialization */
        rc = netfront_xb_init(nfdev, drv_allocator);
diff --git a/plat/xen/drivers/net/netfront.h b/plat/xen/drivers/net/netfront.h
index 362440f6..15dd3f42 100644
--- a/plat/xen/drivers/net/netfront.h
+++ b/plat/xen/drivers/net/netfront.h
@@ -38,6 +38,18 @@
 
 #include <uk/netdev.h>
 
+/**
+ * internal structure to represent the transmit queue.
+ */
+struct uk_netdev_tx_queue {
+};
+
+/**
+ * internal structure to represent the receive queue.
+ */
+struct uk_netdev_rx_queue {
+};
+
 struct xs_econf {
        char *ipv4addr;
        char *ipv4mask;
@@ -50,6 +62,14 @@ struct netfront_dev {
        /* Network device */
        struct uk_netdev netdev;
 
+       /* List of the Rx/Tx queues */
+       struct uk_netdev_tx_queue *txqs;
+       struct uk_netdev_rx_queue *rxqs;
+       /* Maximum number of queue pairs */
+       uint16_t  max_queue_pairs;
+       /* True if using split event channels */
+       bool split_evtchn;
+
        /* Configuration parameters */
        struct xs_econf econf;
 
diff --git a/plat/xen/drivers/net/netfront_xs.c 
b/plat/xen/drivers/net/netfront_xs.c
index 24a6e428..df675b79 100644
--- a/plat/xen/drivers/net/netfront_xs.c
+++ b/plat/xen/drivers/net/netfront_xs.c
@@ -122,7 +122,7 @@ out_err:
 int netfront_xb_init(struct netfront_dev *nfdev, struct uk_alloc *a)
 {
        struct xenbus_device *xendev;
-       char *mac_str, *p, *ip_str;
+       char *mac_str, *p, *ip_str, *int_str;
        int rc;
 
        UK_ASSERT(nfdev != NULL);
@@ -173,7 +173,21 @@ int netfront_xb_init(struct netfront_dev *nfdev, struct 
uk_alloc *a)
                goto no_conf;
        free(ip_str);
 
-       /* TODO spit event channels */
+       /* maximum queues number */
+       int_str = xs_read(XBT_NIL, xendev->otherend,
+               "multi-queue-max-queues");
+       if (!PTRISERR(int_str)) {
+               nfdev->max_queue_pairs = (uint16_t) strtoul(int_str, NULL, 10);
+               free(int_str);
+       }
+
+       /* spit event channels */
+       int_str = xs_read(XBT_NIL, xendev->otherend,
+               "feature-split-event-channels");
+       if (!PTRISERR(int_str)) {
+               nfdev->split_evtchn = (bool) strtoul(int_str, NULL, 10);
+               free(int_str);
+       }
 
        /* TODO netmap */
 
-- 
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®.