From: Maxime Coquelin Date: Sun, 12 Mar 2017 16:34:01 +0000 (+0100) Subject: vhost: add API to get MTU value X-Git-Tag: spdx-start~3912 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=72e8543093df4b03b24c53ef00c9b18b3a6e58d9;p=dpdk.git vhost: add API to get MTU value This patch implements the function for the application to get the MTU value. rte_vhost_get_mtu() fills the mtu parameter with the MTU value set in QEMU if VIRTIO_NET_F_MTU has been negotiated and returns 0, -ENOTSUP otherwise. The function returns -EAGAIN if Virtio feature negotiation didn't happened yet. Signed-off-by: Maxime Coquelin Acked-by: Yuanhan Liu --- diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index 5ceaa8a567..30b4671e16 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -30,3 +30,10 @@ DPDK_16.07 { rte_vhost_get_queue_num; } DPDK_2.1; + +DPDK_17.05 { + global: + + rte_vhost_get_mtu; + +} DPDK_16.07; diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h index 926039c5af..56829aaa18 100644 --- a/lib/librte_vhost/rte_virtio_net.h +++ b/lib/librte_vhost/rte_virtio_net.h @@ -99,6 +99,21 @@ int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * cons /* Start vhost driver session blocking loop. */ int rte_vhost_driver_session_start(void); +/** + * Get the MTU value of the device if set in QEMU. + * + * @param vid + * virtio-net device ID + * @param mtu + * The variable to store the MTU value + * + * @return + * 0: success + * -EAGAIN: device not yet started + * -ENOTSUP: device does not support MTU feature + */ +int rte_vhost_get_mtu(int vid, uint16_t *mtu); + /** * Get the numa node from which the virtio net device's memory * is allocated. diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 3e87ecca07..dfb08dba49 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -312,6 +312,25 @@ vhost_enable_dequeue_zero_copy(int vid) dev->dequeue_zero_copy = 1; } +int +rte_vhost_get_mtu(int vid, uint16_t *mtu) +{ + struct virtio_net *dev = get_device(vid); + + if (!dev) + return -ENODEV; + + if (!(dev->flags & VIRTIO_DEV_READY)) + return -EAGAIN; + + if (!(dev->features & VIRTIO_NET_F_MTU)) + return -ENOTSUP; + + *mtu = dev->mtu; + + return 0; +} + int rte_vhost_get_numa_node(int vid) {