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

[Minios-devel] [UNIKRAFT PATCH v5 10/11] lib/uknetdev: MTU interfaces



From: Razvan Cojocaru <razvan.cojocaru93@xxxxxxxxx>

Add interfaces to query and set the maximum transmission unit (MTU)
for a netdev. The getter is a mandatory interface to implement by
drivers.

Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@xxxxxxxxx>
---
 lib/uknetdev/exportsyms.uk            |  2 ++
 lib/uknetdev/include/uk/netdev.h      | 24 ++++++++++++++++++++++++
 lib/uknetdev/include/uk/netdev_core.h | 10 ++++++++++
 lib/uknetdev/netdev.c                 | 35 +++++++++++++++++++++++++++++++++++
 4 files changed, 71 insertions(+)

diff --git a/lib/uknetdev/exportsyms.uk b/lib/uknetdev/exportsyms.uk
index b0775cb..f4acdb2 100644
--- a/lib/uknetdev/exportsyms.uk
+++ b/lib/uknetdev/exportsyms.uk
@@ -25,3 +25,5 @@ uk_netdev_hwaddr_set
 uk_netdev_hwaddr_get
 uk_netdev_promiscuous_get
 uk_netdev_promiscuous_set
+uk_netdev_mtu_get
+uk_netdev_mtu_set
diff --git a/lib/uknetdev/include/uk/netdev.h b/lib/uknetdev/include/uk/netdev.h
index b618140..a98cf4c 100644
--- a/lib/uknetdev/include/uk/netdev.h
+++ b/lib/uknetdev/include/uk/netdev.h
@@ -335,6 +335,30 @@ unsigned uk_netdev_promiscuous_get(struct uk_netdev *dev);
  */
 int uk_netdev_promiscuous_set(struct uk_netdev *dev, unsigned mode);
 
+/**
+ * Returns the current MTU of an Unikraft network device.
+ *
+ * @param dev
+ *   The Unikraft Network Device.
+ * @return
+ *   - MTU of the uk_netdev
+ */
+uint16_t uk_netdev_mtu_get(struct uk_netdev *dev);
+
+/**
+ * Change the MTU of an Unikraft network device.
+ *
+ * @param dev
+ *   The Unikraft Network Device.
+ * @param mtu
+ *   A uint16_t for the MTU to be applied.
+ * @return
+ *   - (0): if successful.
+ *   - (-ENOTSUP): if operation is not supported.
+ *   - (<0): on error returned by driver
+ */
+int uk_netdev_mtu_set(struct uk_netdev *dev, uint16_t mtu);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/uknetdev/include/uk/netdev_core.h 
b/lib/uknetdev/include/uk/netdev_core.h
index 4174862..e0ce48a 100644
--- a/lib/uknetdev/include/uk/netdev_core.h
+++ b/lib/uknetdev/include/uk/netdev_core.h
@@ -248,6 +248,12 @@ typedef unsigned (*uk_netdev_promiscuous_get_t)(struct 
uk_netdev *dev);
 typedef int (*uk_netdev_promiscuous_set_t)(struct uk_netdev *dev,
                                           unsigned mode);
 
+/** Driver callback type to get the MTU. */
+typedef uint16_t (*uk_netdev_mtu_get_t)(struct uk_netdev *dev);
+
+/** Driver callback type to set the MTU */
+typedef int (*uk_netdev_mtu_set_t)(struct uk_netdev *dev, uint16_t mtu);
+
 /**
  * A structure containing the functions exported by a driver.
  */
@@ -256,6 +262,10 @@ struct uk_netdev_ops {
        uk_netdev_hwaddr_get_t          hwaddr_get;       /* recommended */
        uk_netdev_hwaddr_set_t          hwaddr_set;       /* optional */
 
+       /** Set/Get MTU. */
+       uk_netdev_mtu_get_t             mtu_get;
+       uk_netdev_mtu_set_t             mtu_set;          /* optional */
+
        /** Promiscuous mode. */
        uk_netdev_promiscuous_set_t     promiscuous_set;  /* optional */
        uk_netdev_promiscuous_get_t     promiscuous_get;
diff --git a/lib/uknetdev/netdev.c b/lib/uknetdev/netdev.c
index e2246dc..9dcfd15 100644
--- a/lib/uknetdev/netdev.c
+++ b/lib/uknetdev/netdev.c
@@ -79,6 +79,7 @@ int uk_netdev_drv_register(struct uk_netdev *dev, struct 
uk_alloc *a,
        UK_ASSERT(dev->ops->txq_configure);
        UK_ASSERT(dev->ops->start);
        UK_ASSERT(dev->ops->promiscuous_get);
+       UK_ASSERT(dev->ops->mtu_get);
 
        dev->_data = _alloc_data(a, netdev_count,  drv_name);
        if (!dev->_data)
@@ -484,3 +485,37 @@ int uk_netdev_promiscuous_set(struct uk_netdev *dev, 
unsigned mode)
 
        return dev->ops->promiscuous_set(dev, mode ? 1 : 0);
 }
+
+uint16_t uk_netdev_mtu_get(struct uk_netdev *dev)
+{
+       UK_ASSERT(dev);
+       UK_ASSERT(dev->_data);
+       UK_ASSERT(dev->ops);
+       UK_ASSERT(dev->ops->mtu_get);
+
+       /* We do support getting of MTU
+        * only when device was configured
+        */
+       UK_ASSERT(dev->_data->state == UK_NETDEV_CONFIGURED
+                 || dev->_data->state == UK_NETDEV_RUNNING);
+
+       return dev->ops->mtu_get(dev);
+}
+
+int uk_netdev_mtu_set(struct uk_netdev *dev, uint16_t mtu)
+{
+       UK_ASSERT(dev);
+       UK_ASSERT(dev->_data);
+       UK_ASSERT(dev->ops);
+
+       /* We do support setting of MTU
+        * only when device was configured
+        */
+       UK_ASSERT(dev->_data->state == UK_NETDEV_CONFIGURED
+                 || dev->_data->state == UK_NETDEV_RUNNING);
+
+       if (dev->ops->mtu_set == NULL)
+               return -ENOTSUP;
+
+       return dev->ops->mtu_set(dev, mtu);
+}
-- 
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®.