From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id EE676F616 for ; Mon, 13 Feb 2017 15:28:46 +0100 (CET) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 32A2A61B9C; Mon, 13 Feb 2017 14:28:47 +0000 (UTC) Received: from max-t460s.redhat.com (ovpn-117-88.ams2.redhat.com [10.36.117.88]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DESW1A014561; Mon, 13 Feb 2017 09:28:44 -0500 From: Maxime Coquelin To: aconole@redhat.com, sodey@sonusnet.com, yuanhan.liu@linux.intel.com, jianfeng.tan@intel.com, dev@dpdk.org Cc: Maxime Coquelin Date: Mon, 13 Feb 2017 15:28:17 +0100 Message-Id: <20170213142820.8964-5-maxime.coquelin@redhat.com> In-Reply-To: <20170213142820.8964-1-maxime.coquelin@redhat.com> References: <20170213142820.8964-1-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 13 Feb 2017 14:28:47 +0000 (UTC) Subject: [dpdk-dev] [PATCH 4/7] vhost: Add API to get/set MTU value X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Feb 2017 14:28:47 -0000 This patch implements two functions for the application to get/set the MTU value. rte_vhost_mtu_get() set the mtu parameter with the MTU value set in QEMU if VIRTIO_NET_F_MTU has been negotiated and returns 0, -ENOTSUP otherwise. rte_vhost_mtu_set() doesn't actually permit to change the MTU, which can only be set once before feature negotiation, but the function returns 0 if the MTU value the application tries to set is the same that have been set in QEMU, -EINVAL if different and -ENOTSUP if VIRTIO_NET_F_MTU hasn't been negotiated. The two functions returns -EAGAIN if Virtio feature negotiation didn't happened yet. Signed-off-by: Maxime Coquelin --- lib/librte_vhost/rte_virtio_net.h | 31 +++++++++++++++++++++++++++++++ lib/librte_vhost/vhost.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h index 926039c..8d84dbf 100644 --- a/lib/librte_vhost/rte_virtio_net.h +++ b/lib/librte_vhost/rte_virtio_net.h @@ -100,6 +100,37 @@ int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * cons 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_mtu_get(int vid, uint16_t *mtu); + +/** + * Set the MTU value of the device. + * + * @param vid + * virtio-net device ID + * @param mtu + * The MTU value + * + * @return + * 0: success + * -EAGAIN: device not yet started + * -ENOTSUP: device does not support MTU feature + * -EINVAL: MTU value different from the one set in QEMU + */ +int rte_vhost_mtu_set(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 3974087..20d0061 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -313,6 +313,45 @@ vhost_enable_dequeue_zero_copy(int vid) } int +rte_vhost_mtu_get(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_mtu_set(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; + + if (dev->mtu != mtu) + return -EINVAL; + + return 0; +} + +int rte_vhost_get_numa_node(int vid) { #ifdef RTE_LIBRTE_VHOST_NUMA -- 2.9.3