[dpdk-dev,v5,3/3] vhost: Add helper function to convert port id to virtio device pointer

Message ID 1448355603-21275-4-git-send-email-mukawa@igel.co.jp (mailing list archive)
State Changes Requested, archived
Headers

Commit Message

Tetsuya Mukawa Nov. 24, 2015, 9 a.m. UTC
  This helper function is used to convert port id to virtio device
pointer. To use this function, a port should be managed by vhost PMD.
After getting virtio device pointer, it can be used for calling vhost
library APIs. But some library APIs should not be called with vhost PMD.

Here is.
 - rte_vhost_driver_session_start()
 - rte_vhost_driver_unregister()

Above APIs will not work with vhost PMD.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 drivers/net/vhost/Makefile        |  5 +++
 drivers/net/vhost/rte_eth_vhost.c | 25 +++++++++++++++
 drivers/net/vhost/rte_eth_vhost.h | 65 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+)
 create mode 100644 drivers/net/vhost/rte_eth_vhost.h
  

Comments

Yuanhan Liu Dec. 17, 2015, 11:47 a.m. UTC | #1
On Tue, Nov 24, 2015 at 06:00:03PM +0900, Tetsuya Mukawa wrote:
> This helper function is used to convert port id to virtio device
> pointer. To use this function, a port should be managed by vhost PMD.
> After getting virtio device pointer, it can be used for calling vhost
> library APIs.

I'm thinking why is that necessary. I mean, hey, can we simply treat
it as a normal pmd driver, and don't consider any vhost lib functions
any more while using vhost pmd?

	--yliu
  
Tetsuya Mukawa Dec. 18, 2015, 3:15 a.m. UTC | #2
On 2015/12/17 20:47, Yuanhan Liu wrote:
> On Tue, Nov 24, 2015 at 06:00:03PM +0900, Tetsuya Mukawa wrote:
>> This helper function is used to convert port id to virtio device
>> pointer. To use this function, a port should be managed by vhost PMD.
>> After getting virtio device pointer, it can be used for calling vhost
>> library APIs.
> I'm thinking why is that necessary. I mean, hey, can we simply treat
> it as a normal pmd driver, and don't consider any vhost lib functions
> any more while using vhost pmd?

I guess vhost PMD cannot  hide some of vhost features.
Because of this, we may need to add ethdev APIs to wraps these features.
I described more in one more email. Could you please see it also?

Thanks,
Tetsuya
  
Yuanhan Liu Dec. 18, 2015, 4:19 a.m. UTC | #3
On Fri, Dec 18, 2015 at 12:15:49PM +0900, Tetsuya Mukawa wrote:
> On 2015/12/17 20:47, Yuanhan Liu wrote:
> > On Tue, Nov 24, 2015 at 06:00:03PM +0900, Tetsuya Mukawa wrote:
> >> This helper function is used to convert port id to virtio device
> >> pointer. To use this function, a port should be managed by vhost PMD.
> >> After getting virtio device pointer, it can be used for calling vhost
> >> library APIs.
> > I'm thinking why is that necessary. I mean, hey, can we simply treat
> > it as a normal pmd driver, and don't consider any vhost lib functions
> > any more while using vhost pmd?
> 
> I guess vhost PMD cannot  hide some of vhost features.

Sorry, a "guess" could not convice me to have it.

On the other hand, it does no harm but brings great benefit to make
things simple in the first time. __If__ there really is a need for
them, we could add it back, isn't it? ;)

	--yliu

> Because of this, we may need to add ethdev APIs to wraps these features.
> I described more in one more email. Could you please see it also?
> 
> Thanks,
> Tetsuya
>
  

Patch

diff --git a/drivers/net/vhost/Makefile b/drivers/net/vhost/Makefile
index 8bec47a..8186a80 100644
--- a/drivers/net/vhost/Makefile
+++ b/drivers/net/vhost/Makefile
@@ -48,6 +48,11 @@  LIBABIVER := 1
 #
 SRCS-$(CONFIG_RTE_LIBRTE_PMD_VHOST) += rte_eth_vhost.c
 
+#
+# Export include files
+#
+SYMLINK-y-include += rte_eth_vhost.h
+
 # this lib depends upon:
 DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_VHOST) += lib/librte_mbuf
 DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_VHOST) += lib/librte_ether
diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 9ef05bc..bfe1f18 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -41,6 +41,8 @@ 
 #include <rte_kvargs.h>
 #include <rte_virtio_net.h>
 
+#include "rte_eth_vhost.h"
+
 #define ETH_VHOST_IFACE_ARG		"iface"
 #define ETH_VHOST_QUEUES_ARG		"queues"
 
@@ -768,4 +770,27 @@  static struct rte_driver pmd_vhost_drv = {
 	.uninit = rte_pmd_vhost_devuninit,
 };
 
+struct
+virtio_net *rte_eth_vhost_portid2vdev(uint16_t port_id)
+{
+	struct rte_eth_dev *eth_dev;
+
+	if (rte_eth_dev_is_valid_port(port_id) == 0)
+		return NULL;
+
+	eth_dev = &rte_eth_devices[port_id];
+	if (strncmp("eth_vhost", eth_dev->data->drv_name,
+				strlen("eth_vhost")) == 0) {
+		struct pmd_internal *internal;
+		struct vhost_queue *vq;
+
+		internal = eth_dev->data->dev_private;
+		vq = internal->rx_vhost_queues[0];
+		if ((vq != NULL) && (vq->device != NULL))
+			return vq->device;
+	}
+
+	return NULL;
+}
+
 PMD_REGISTER_DRIVER(pmd_vhost_drv);
diff --git a/drivers/net/vhost/rte_eth_vhost.h b/drivers/net/vhost/rte_eth_vhost.h
new file mode 100644
index 0000000..22a880f
--- /dev/null
+++ b/drivers/net/vhost/rte_eth_vhost.h
@@ -0,0 +1,65 @@ 
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 IGEL Co., Ltd.
+ *   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 IGEL Co., Ltd. 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_ETH_AF_PACKET_H_
+#define _RTE_ETH_AF_PACKET_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rte_virtio_net.h>
+
+/**
+ * The function convert specified port_id to virtio device structure.
+ * The retured device can be used for vhost library APIs.
+ * To use vhost library APIs and vhost PMD parallely, below API should
+ * not be called, because the API will be called by vhost PMD.
+ * - rte_vhost_driver_session_start()
+ * Once a device is managed by vhost PMD, below API should not be called.
+ * - rte_vhost_driver_unregister()
+ * To unregister the device, call Port Hotplug APIs.
+ *
+ * @param port_id
+ *  port number
+ * @return
+ *  virtio net device structure corresponding to the specified port
+ *  NULL will be returned in error cases.
+ */
+struct virtio_net *rte_eth_vhost_portid2vdev(uint16_t port_id);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif