From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id A4AADBD32 for ; Fri, 3 Mar 2017 10:53:05 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP; 03 Mar 2017 01:53:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,236,1484035200"; d="scan'208";a="1137400983" Received: from yliu-dev.sh.intel.com ([10.239.67.162]) by fmsmga002.fm.intel.com with ESMTP; 03 Mar 2017 01:53:04 -0800 From: Yuanhan Liu To: dev@dpdk.org Cc: Maxime Coquelin , Harris James R , Liu Changpeng , Yuanhan Liu Date: Fri, 3 Mar 2017 17:51:21 +0800 Message-Id: <1488534682-3494-17-git-send-email-yuanhan.liu@linux.intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1488534682-3494-1-git-send-email-yuanhan.liu@linux.intel.com> References: <1488534682-3494-1-git-send-email-yuanhan.liu@linux.intel.com> Subject: [dpdk-dev] [PATCH 16/17] vhost: rename header file 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: Fri, 03 Mar 2017 09:53:07 -0000 Rename "rte_virtio_net.h" to "rte_vhost.h", to not let it be virtio net specific. Signed-off-by: Yuanhan Liu --- doc/guides/rel_notes/deprecation.rst | 9 -- drivers/net/vhost/rte_eth_vhost.c | 2 +- drivers/net/vhost/rte_eth_vhost.h | 2 +- examples/tep_termination/main.c | 2 +- examples/tep_termination/vxlan_setup.c | 2 +- examples/vhost/main.c | 2 +- lib/librte_vhost/Makefile | 2 +- lib/librte_vhost/rte_vhost.h | 259 +++++++++++++++++++++++++++++++++ lib/librte_vhost/rte_virtio_net.h | 259 --------------------------------- lib/librte_vhost/vhost.c | 2 +- lib/librte_vhost/vhost.h | 2 +- lib/librte_vhost/vhost_user.h | 2 +- lib/librte_vhost/virtio_net.c | 2 +- 13 files changed, 269 insertions(+), 278 deletions(-) create mode 100644 lib/librte_vhost/rte_vhost.h delete mode 100644 lib/librte_vhost/rte_virtio_net.h diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst index 9d4dfcc..84c8b9d 100644 --- a/doc/guides/rel_notes/deprecation.rst +++ b/doc/guides/rel_notes/deprecation.rst @@ -104,15 +104,6 @@ Deprecation Notices Target release for removal of the legacy API will be defined once most PMDs have switched to rte_flow. -* vhost: API/ABI changes are planned for 17.05, for making DPDK vhost library - generic enough so that applications can build different vhost-user drivers - (instead of vhost-user net only) on top of that. - Specifically, ``virtio_net_device_ops`` will be renamed to ``vhost_device_ops``. - Correspondingly, some API's parameter need be changed. Few more functions also - need be reworked to let it be device aware. For example, different virtio device - has different feature set, meaning functions like ``rte_vhost_feature_disable`` - need be changed. Last, file rte_virtio_net.h will be renamed to rte_vhost.h. - * kni: Remove :ref:`kni_vhost_backend-label` feature (KNI_VHOST) in 17.05 release. :doc:`Vhost Library ` is currently preferred method for guest - host communication. Just for clarification, this is not to remove KNI diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index df1e386..f7c370e 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include "rte_eth_vhost.h" diff --git a/drivers/net/vhost/rte_eth_vhost.h b/drivers/net/vhost/rte_eth_vhost.h index ea4bce4..39ca771 100644 --- a/drivers/net/vhost/rte_eth_vhost.h +++ b/drivers/net/vhost/rte_eth_vhost.h @@ -41,7 +41,7 @@ #include #include -#include +#include /* * Event description. diff --git a/examples/tep_termination/main.c b/examples/tep_termination/main.c index fa1c7a4..63a5dd3 100644 --- a/examples/tep_termination/main.c +++ b/examples/tep_termination/main.c @@ -49,7 +49,7 @@ #include #include #include -#include +#include #include "main.h" #include "vxlan.h" diff --git a/examples/tep_termination/vxlan_setup.c b/examples/tep_termination/vxlan_setup.c index 8f1f15b..87de74d 100644 --- a/examples/tep_termination/vxlan_setup.c +++ b/examples/tep_termination/vxlan_setup.c @@ -49,7 +49,7 @@ #include #include "main.h" -#include "rte_virtio_net.h" +#include "rte_vhost.h" #include "vxlan.h" #include "vxlan_setup.h" diff --git a/examples/vhost/main.c b/examples/vhost/main.c index 080c60b..a9b5352 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -49,7 +49,7 @@ #include #include #include -#include +#include #include #include diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile index 5cf4e93..4847069 100644 --- a/lib/librte_vhost/Makefile +++ b/lib/librte_vhost/Makefile @@ -51,7 +51,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c socket.c vhost.c vhost_user.c \ virtio_net.c # install includes -SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_virtio_net.h +SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h # dependencies DEPDIRS-$(CONFIG_RTE_LIBRTE_VHOST) += lib/librte_eal diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h new file mode 100644 index 0000000..cfb3507 --- /dev/null +++ b/lib/librte_vhost/rte_vhost.h @@ -0,0 +1,259 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2010-2017 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _RTE_VHOST_H_ +#define _RTE_VHOST_H_ + +/** + * @file + * Interface to vhost-user + */ + +#include +#include +#include +#include + +#include +#include + +#define RTE_VHOST_USER_CLIENT (1ULL << 0) +#define RTE_VHOST_USER_NO_RECONNECT (1ULL << 1) +#define RTE_VHOST_USER_DEQUEUE_ZERO_COPY (1ULL << 2) + +/** + * Information relating to memory regions including offsets to + * addresses in QEMUs memory file. + */ +struct rte_vhost_mem_region { + uint64_t guest_phys_addr; + uint64_t guest_user_addr; + uint64_t host_user_addr; + uint64_t size; + void *mmap_addr; + uint64_t mmap_size; + int fd; +}; + +/** + * Memory structure includes region and mapping information. + */ +struct rte_vhost_memory { + uint32_t nregions; + struct rte_vhost_mem_region regions[0]; +}; + +struct rte_vhost_vring { + struct vring_desc *desc; + struct vring_avail *avail; + struct vring_used *used; + uint64_t log_guest_addr; + + int callfd; + int kickfd; + uint16_t size; +}; + +/** + * Device and vring operations. + */ +struct vhost_device_ops { + int (*new_device)(int vid); /**< Add device. */ + void (*destroy_device)(int vid); /**< Remove device. */ + + int (*vring_state_changed)(int vid, uint16_t queue_id, int enable); /**< triggered when a vring is enabled or disabled */ + + void *reserved[5]; /**< Reserved for future extension */ +}; + +/** + * Convert guest physical Address to host virtual address + */ +static inline uint64_t __attribute__((always_inline)) +rte_vhost_gpa_to_vva(struct rte_vhost_memory *mem, uint64_t gpa) +{ + struct rte_vhost_mem_region *reg; + uint32_t i; + + for (i = 0; i < mem->nregions; i++) { + reg = &mem->regions[i]; + if (gpa >= reg->guest_phys_addr && + gpa < reg->guest_phys_addr + reg->size) { + return gpa - reg->guest_phys_addr + + reg->host_user_addr; + } + } + + return 0; +} + +int rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable); + +/** + * Register vhost driver. path could be different for multiple + * instance support. + */ +int rte_vhost_driver_register(const char *path, uint64_t flags); + +/* Unregister vhost driver. This is only meaningful to vhost user. */ +int rte_vhost_driver_unregister(const char *path); + +/** + * Set feature bits the vhost driver supports. + */ +int rte_vhost_driver_set_features(const char *path, uint64_t features); +uint64_t rte_vhost_driver_get_features(const char *path); + +int rte_vhost_driver_enable_features(const char *path, uint64_t features); +int rte_vhost_driver_disable_features(const char *path, uint64_t features); + +/* Register callbacks. */ +int rte_vhost_driver_callback_register(const char *path, + struct vhost_device_ops const * const); +/* Start vhost driver session blocking loop. */ +int rte_vhost_driver_session_start(void); + +/** + * Get the numa node from which the virtio net device's memory + * is allocated. + * + * @param vid + * vhost device ID + * + * @return + * The numa node, -1 on failure + */ +int rte_vhost_get_numa_node(int vid); + +/** + * @deprecated + * Get the number of queues the device supports. + * + * Note this function is deprecated, as it returns a queue pair number, + * which is vhost specific. Instead, rte_vhost_get_vring_num should + * be used. + * + * @param vid + * vhost device ID + * + * @return + * The number of queues, 0 on failure + */ +__rte_deprecated +uint32_t rte_vhost_get_queue_num(int vid); + +/** + * Get the number of vrings the device supports. + * + * @param vid + * vhost device ID + * + * @return + * The number of vrings, 0 on failure + */ +uint16_t rte_vhost_get_vring_num(int vid); + +/** + * Get the virtio net device's ifname, which is the vhost-user socket + * file path. + * + * @param vid + * vhost device ID + * @param buf + * The buffer to stored the queried ifname + * @param len + * The length of buf + * + * @return + * 0 on success, -1 on failure + */ +int rte_vhost_get_ifname(int vid, char *buf, size_t len); + +/** + * Get how many avail entries are left in the queue + * + * @param vid + * vhost device ID + * @param queue_id + * virtio queue index + * + * @return + * num of avail entires left + */ +uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id); + +/** + * This function adds buffers to the virtio devices RX virtqueue. Buffers can + * be received from the physical port or from another virtual device. A packet + * count is returned to indicate the number of packets that were succesfully + * added to the RX queue. + * @param vid + * vhost device ID + * @param queue_id + * virtio queue index in mq case + * @param pkts + * array to contain packets to be enqueued + * @param count + * packets num to be enqueued + * @return + * num of packets enqueued + */ +uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id, + struct rte_mbuf **pkts, uint16_t count); + +/** + * This function gets guest buffers from the virtio device TX virtqueue, + * construct host mbufs, copies guest buffer content to host mbufs and + * store them in pkts to be processed. + * @param vid + * vhost device ID + * @param queue_id + * virtio queue index in mq case + * @param mbuf_pool + * mbuf_pool where host mbuf is allocated. + * @param pkts + * array to contain packets to be dequeued + * @param count + * packets num to be dequeued + * @return + * num of packets dequeued + */ +uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id, + struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count); + +int rte_vhost_get_vhost_memory(int vid, struct rte_vhost_memory **mem); +uint64_t rte_vhost_get_negotiated_features(int vid); +int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx, + struct rte_vhost_vring *vring); + +#endif /* _RTE_VHOST_H_ */ diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h deleted file mode 100644 index 2f761da..0000000 --- a/lib/librte_vhost/rte_virtio_net.h +++ /dev/null @@ -1,259 +0,0 @@ -/*- - * BSD LICENSE - * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _VIRTIO_NET_H_ -#define _VIRTIO_NET_H_ - -/** - * @file - * Interface to vhost net - */ - -#include -#include -#include -#include - -#include -#include - -#define RTE_VHOST_USER_CLIENT (1ULL << 0) -#define RTE_VHOST_USER_NO_RECONNECT (1ULL << 1) -#define RTE_VHOST_USER_DEQUEUE_ZERO_COPY (1ULL << 2) - -/** - * Information relating to memory regions including offsets to - * addresses in QEMUs memory file. - */ -struct rte_vhost_mem_region { - uint64_t guest_phys_addr; - uint64_t guest_user_addr; - uint64_t host_user_addr; - uint64_t size; - void *mmap_addr; - uint64_t mmap_size; - int fd; -}; - -/** - * Memory structure includes region and mapping information. - */ -struct rte_vhost_memory { - uint32_t nregions; - struct rte_vhost_mem_region regions[0]; -}; - -struct rte_vhost_vring { - struct vring_desc *desc; - struct vring_avail *avail; - struct vring_used *used; - uint64_t log_guest_addr; - - int callfd; - int kickfd; - uint16_t size; -}; - -/** - * Device and vring operations. - */ -struct vhost_device_ops { - int (*new_device)(int vid); /**< Add device. */ - void (*destroy_device)(int vid); /**< Remove device. */ - - int (*vring_state_changed)(int vid, uint16_t queue_id, int enable); /**< triggered when a vring is enabled or disabled */ - - void *reserved[5]; /**< Reserved for future extension */ -}; - -/** - * Convert guest physical Address to host virtual address - */ -static inline uint64_t __attribute__((always_inline)) -rte_vhost_gpa_to_vva(struct rte_vhost_memory *mem, uint64_t gpa) -{ - struct rte_vhost_mem_region *reg; - uint32_t i; - - for (i = 0; i < mem->nregions; i++) { - reg = &mem->regions[i]; - if (gpa >= reg->guest_phys_addr && - gpa < reg->guest_phys_addr + reg->size) { - return gpa - reg->guest_phys_addr + - reg->host_user_addr; - } - } - - return 0; -} - -int rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable); - -/** - * Register vhost driver. path could be different for multiple - * instance support. - */ -int rte_vhost_driver_register(const char *path, uint64_t flags); - -/* Unregister vhost driver. This is only meaningful to vhost user. */ -int rte_vhost_driver_unregister(const char *path); - -/** - * Set feature bits the vhost driver supports. - */ -int rte_vhost_driver_set_features(const char *path, uint64_t features); -uint64_t rte_vhost_driver_get_features(const char *path); - -int rte_vhost_driver_enable_features(const char *path, uint64_t features); -int rte_vhost_driver_disable_features(const char *path, uint64_t features); - -/* Register callbacks. */ -int rte_vhost_driver_callback_register(const char *path, - struct vhost_device_ops const * const); -/* Start vhost driver session blocking loop. */ -int rte_vhost_driver_session_start(void); - -/** - * Get the numa node from which the virtio net device's memory - * is allocated. - * - * @param vid - * vhost device ID - * - * @return - * The numa node, -1 on failure - */ -int rte_vhost_get_numa_node(int vid); - -/** - * @deprecated - * Get the number of queues the device supports. - * - * Note this function is deprecated, as it returns a queue pair number, - * which is vhost specific. Instead, rte_vhost_get_vring_num should - * be used. - * - * @param vid - * vhost device ID - * - * @return - * The number of queues, 0 on failure - */ -__rte_deprecated -uint32_t rte_vhost_get_queue_num(int vid); - -/** - * Get the number of vrings the device supports. - * - * @param vid - * vhost device ID - * - * @return - * The number of vrings, 0 on failure - */ -uint16_t rte_vhost_get_vring_num(int vid); - -/** - * Get the virtio net device's ifname, which is the vhost-user socket - * file path. - * - * @param vid - * vhost device ID - * @param buf - * The buffer to stored the queried ifname - * @param len - * The length of buf - * - * @return - * 0 on success, -1 on failure - */ -int rte_vhost_get_ifname(int vid, char *buf, size_t len); - -/** - * Get how many avail entries are left in the queue - * - * @param vid - * vhost device ID - * @param queue_id - * virtio queue index - * - * @return - * num of avail entires left - */ -uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id); - -/** - * This function adds buffers to the virtio devices RX virtqueue. Buffers can - * be received from the physical port or from another virtual device. A packet - * count is returned to indicate the number of packets that were succesfully - * added to the RX queue. - * @param vid - * vhost device ID - * @param queue_id - * virtio queue index in mq case - * @param pkts - * array to contain packets to be enqueued - * @param count - * packets num to be enqueued - * @return - * num of packets enqueued - */ -uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id, - struct rte_mbuf **pkts, uint16_t count); - -/** - * This function gets guest buffers from the virtio device TX virtqueue, - * construct host mbufs, copies guest buffer content to host mbufs and - * store them in pkts to be processed. - * @param vid - * vhost device ID - * @param queue_id - * virtio queue index in mq case - * @param mbuf_pool - * mbuf_pool where host mbuf is allocated. - * @param pkts - * array to contain packets to be dequeued - * @param count - * packets num to be dequeued - * @return - * num of packets dequeued - */ -uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id, - struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count); - -int rte_vhost_get_vhost_memory(int vid, struct rte_vhost_memory **mem); -uint64_t rte_vhost_get_negotiated_features(int vid); -int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx, - struct rte_vhost_vring *vring); - -#endif /* _VIRTIO_NET_H_ */ diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 0a27888..e0548fe 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include "vhost.h" diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index fc9e431..29132f3 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -46,7 +46,7 @@ #include #include -#include "rte_virtio_net.h" +#include "rte_vhost.h" #define VHOST_USER_F_PROTOCOL_FEATURES 30 diff --git a/lib/librte_vhost/vhost_user.h b/lib/librte_vhost/vhost_user.h index 179e441..f1a7823 100644 --- a/lib/librte_vhost/vhost_user.h +++ b/lib/librte_vhost/vhost_user.h @@ -37,7 +37,7 @@ #include #include -#include "rte_virtio_net.h" +#include "rte_vhost.h" /* refer to hw/virtio/vhost-user.c */ diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c index 8ed2b93..6287c7a 100644 --- a/lib/librte_vhost/virtio_net.c +++ b/lib/librte_vhost/virtio_net.c @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include #include -- 1.9.0