DPDK patches and discussions
 help / color / mirror / Atom feed
From: Zhihong Wang <zhihong.wang@intel.com>
To: dev@dpdk.org
Cc: jianfeng.tan@intel.com, tiwei.bie@intel.com,
	maxime.coquelin@redhat.com, yliu@fridaylinux.org,
	cunming.liang@intel.com, xiao.w.wang@intel.com,
	dan.daly@intel.com, Zhihong Wang <zhihong.wang@intel.com>
Subject: [dpdk-dev] [PATCH 3/7] vhost: support selective datapath
Date: Fri,  2 Feb 2018 18:28:53 -0500	[thread overview]
Message-ID: <1517614137-62926-4-git-send-email-zhihong.wang@intel.com> (raw)
In-Reply-To: <1517614137-62926-1-git-send-email-zhihong.wang@intel.com>

This patch introduces support for selective datapath in DPDK vhost-user lib
to enable various types of virtio-compatible devices to do data transfer
with virtio driver directly to enable acceleration. The default datapath is
the existing software implementation, more options will be available when
new engines are registered.

An engine is a group of virtio-compatible devices under a single address.
The engine driver includes:

 1. A set of engine ops is defined in rte_vdpa_eng_ops to perform engine
    init, uninit, and attributes reporting.
    
 2. A set of device ops is defined in rte_vdpa_dev_ops for virtio devices
    in the engine to do device specific operations:

     a. dev_conf: Called to configure the actual device when the virtio
        device becomes ready.

     b. dev_close: Called to close the actual device when the virtio device
        is stopped.

     c. vring_state_set: Called to change the state of the vring in the
        actual device when vring state changes.

     d. feature_set: Called to set the negotiated features to device.

     e. migration_done: Called to allow the device to response to RARP
        sending.

Signed-off-by: Zhihong Wang <zhihong.wang@intel.com>
---
 lib/librte_vhost/Makefile   |   4 +-
 lib/librte_vhost/rte_vdpa.h | 113 +++++++++++++++++++++++++++++++++++++++
 lib/librte_vhost/vdpa.c     | 125 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 240 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_vhost/rte_vdpa.h
 create mode 100644 lib/librte_vhost/vdpa.c

diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile
index 5d6c6ab..37044ac 100644
--- a/lib/librte_vhost/Makefile
+++ b/lib/librte_vhost/Makefile
@@ -22,9 +22,9 @@ LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_ethdev -lrte_net
 
 # all source are stored in SRCS-y
 SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c iotlb.c socket.c vhost.c \
-					vhost_user.c virtio_net.c
+					vhost_user.c virtio_net.c vdpa.c
 
 # install includes
-SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h
+SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h rte_vdpa.h
 
 include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/lib/librte_vhost/rte_vdpa.h b/lib/librte_vhost/rte_vdpa.h
new file mode 100644
index 0000000..729849b
--- /dev/null
+++ b/lib/librte_vhost/rte_vdpa.h
@@ -0,0 +1,113 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#ifndef _RTE_VDPA_H_
+#define _RTE_VDPA_H_
+
+/**
+ * @file
+ *
+ * Device specific vhost lib
+ */
+
+#include <rte_memory.h>
+#include <rte_pci.h>
+#include "rte_vhost.h"
+
+#define MAX_VDPA_ENGINE_NUM 128
+#define MAX_VDPA_NAME_LEN 128
+
+
+struct rte_vdpa_eng_addr {
+	union {
+		uint8_t __dummy[64];
+
+		struct {
+			struct rte_pci_addr pci_addr;
+		};
+	};
+};
+
+struct rte_vdpa_eng_info {
+	char name[MAX_VDPA_NAME_LEN];
+	struct rte_vdpa_eng_addr *addr;
+};
+
+struct rte_vdpa_eng_attr {
+	uint64_t features;
+	uint64_t protocol_features;
+	uint32_t queue_num;
+	uint32_t dev_num;
+};
+
+/* register/remove engine */
+typedef int (*vdpa_eng_init_t)(int eid, struct rte_vdpa_eng_addr *addr);
+typedef int (*vdpa_eng_uninit_t)(int eid);
+
+/* query info of this engine */
+typedef int (*vdpa_info_query_t)(int eid,
+		struct rte_vdpa_eng_attr *attr);
+
+/* driver configure/close the port based on connection */
+typedef int (*vdpa_dev_conf_t)(int vid);
+typedef int (*vdpa_dev_close_t)(int vid);
+
+/* enable/disable this vring */
+typedef int (*vdpa_vring_state_set_t)(int vid, int vring, int state);
+
+/* set features when changed */
+typedef int (*vdpa_feature_set_t)(int vid);
+
+/* destination operations when migration done, e.g. send rarp */
+typedef int (*vdpa_migration_done_t)(int vid);
+
+/* device ops */
+struct rte_vdpa_dev_ops {
+	vdpa_dev_conf_t        dev_conf;
+	vdpa_dev_close_t       dev_close;
+	vdpa_vring_state_set_t vring_state_set;
+	vdpa_feature_set_t     feature_set;
+	vdpa_migration_done_t  migration_done;
+};
+
+/* engine ops */
+struct rte_vdpa_eng_ops {
+	vdpa_eng_init_t eng_init;
+	vdpa_eng_uninit_t eng_uninit;
+	vdpa_info_query_t info_query;
+};
+
+struct rte_vdpa_eng_driver {
+	const char *name;
+	struct rte_vdpa_eng_ops eng_ops;
+	struct rte_vdpa_dev_ops dev_ops;
+} __rte_cache_aligned;
+
+struct rte_vdpa_engine {
+	struct rte_vdpa_eng_info eng_info;
+	struct rte_vdpa_eng_driver *eng_drv;
+} __rte_cache_aligned;
+
+extern struct rte_vdpa_engine *vdpa_engines[];
+extern uint32_t vdpa_engine_num;
+
+/* engine management */
+int rte_vdpa_register_engine(const char *name, struct rte_vdpa_eng_addr *addr);
+int rte_vdpa_unregister_engine(int eid);
+
+int rte_vdpa_find_engine_id(struct rte_vdpa_eng_addr *addr);
+
+int rte_vdpa_info_query(int eid, struct rte_vdpa_eng_attr *attr);
+
+/* driver register api */
+void rte_vdpa_register_driver(struct rte_vdpa_eng_driver *drv);
+
+#define RTE_VDPA_REGISTER_DRIVER(nm, drv) \
+RTE_INIT(vdpainitfn_ ##nm); \
+static void vdpainitfn_ ##nm(void) \
+{ \
+	rte_vdpa_register_driver(&drv); \
+} \
+
+#endif /* _RTE_VDPA_H_ */
diff --git a/lib/librte_vhost/vdpa.c b/lib/librte_vhost/vdpa.c
new file mode 100644
index 0000000..1fc2d0b
--- /dev/null
+++ b/lib/librte_vhost/vdpa.c
@@ -0,0 +1,125 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+/**
+ * @file
+ *
+ * Device specific vhost lib
+ */
+
+#include <rte_malloc.h>
+#include "rte_vdpa.h"
+#include "vhost.h"
+
+static struct rte_vdpa_eng_driver *vdpa_drivers[MAX_VDPA_ENGINE_NUM];
+static uint32_t vdpa_driver_num;
+
+struct rte_vdpa_engine *vdpa_engines[MAX_VDPA_ENGINE_NUM];
+uint32_t vdpa_engine_num;
+
+static int is_same_eng(struct rte_vdpa_eng_addr *a, struct rte_vdpa_eng_addr *b)
+{
+	if (a->pci_addr.domain != b->pci_addr.domain
+			|| a->pci_addr.bus != b->pci_addr.bus
+			|| a->pci_addr.devid != b->pci_addr.devid
+			|| a->pci_addr.function != b->pci_addr.function)
+		return -1;
+
+	return 0;
+}
+
+void rte_vdpa_register_driver(struct rte_vdpa_eng_driver *driver)
+{
+	if (vdpa_driver_num >= MAX_VDPA_ENGINE_NUM)
+		return;
+
+	vdpa_drivers[vdpa_driver_num] = driver;
+	vdpa_driver_num++;
+}
+
+int rte_vdpa_register_engine(const char *name, struct rte_vdpa_eng_addr *addr)
+{
+	static int engine_idx;
+
+	struct rte_vdpa_engine *eng;
+	struct rte_vdpa_eng_driver *cur;
+	char engine_name[MAX_VDPA_NAME_LEN];
+	int i;
+
+	for (i = 0; i < MAX_VDPA_ENGINE_NUM; ++i) {
+		eng = vdpa_engines[i];
+		if (eng && is_same_eng(eng->eng_info.addr, addr) == 0)
+			return i;
+	}
+
+	sprintf(engine_name, "vdpa-%s-%d", name, engine_idx++);
+	eng = rte_zmalloc(engine_name, sizeof(struct rte_vdpa_engine),
+			RTE_CACHE_LINE_SIZE);
+	if (!eng)
+		return -1;
+
+	for (i = 0; i < MAX_VDPA_ENGINE_NUM; ++i) {
+		cur = vdpa_drivers[i];
+		if (cur && 0 == strncmp(name, cur->name,
+					MAX_VDPA_NAME_LEN)) {
+			eng->eng_drv = cur;
+			strcpy(eng->eng_info.name, name);
+			eng->eng_info.addr = addr;
+			for (i = 0; i < MAX_VDPA_ENGINE_NUM; ++i) {
+				if (vdpa_engines[i])
+					continue;
+				vdpa_engines[i] = eng;
+				if (eng->eng_drv->eng_ops.eng_init)
+					eng->eng_drv->eng_ops.eng_init(i, addr);
+				vdpa_engine_num++;
+				return i;
+			}
+		}
+	}
+
+	return -1;
+}
+
+int rte_vdpa_unregister_engine(int eid)
+{
+	if (eid < 0 || eid >= MAX_VDPA_ENGINE_NUM || vdpa_engines[eid]
+			== NULL)
+		return -1;
+
+	if (vdpa_engines[eid]->eng_drv->eng_ops.eng_uninit)
+		vdpa_engines[eid]->eng_drv->eng_ops.eng_uninit(eid);
+
+	rte_free(vdpa_engines[eid]);
+	vdpa_engines[eid] = NULL;
+	vdpa_engine_num--;
+
+	return eid;
+}
+
+int rte_vdpa_find_engine_id(struct rte_vdpa_eng_addr *addr)
+{
+	struct rte_vdpa_engine *eng;
+	int i;
+
+	for (i = 0; i < MAX_VDPA_ENGINE_NUM; ++i) {
+		eng = vdpa_engines[i];
+		if (eng && is_same_eng(eng->eng_info.addr, addr) == 0)
+			return i;
+	}
+
+	return -1;
+}
+
+int rte_vdpa_info_query(int eid, struct rte_vdpa_eng_attr *attr)
+{
+	if (eid < 0 || eid >= MAX_VDPA_ENGINE_NUM || vdpa_engines[eid]
+			== NULL)
+		return -1;
+
+	if (vdpa_engines[eid]->eng_drv->eng_ops.info_query == NULL)
+		return -1;
+
+	return vdpa_engines[eid]->eng_drv->eng_ops.info_query(eid, attr);
+
+}
-- 
2.7.5

  parent reply	other threads:[~2018-02-02 11:33 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-02 23:28 [dpdk-dev] [PATCH 0/7] " Zhihong Wang
2018-02-02 23:28 ` [dpdk-dev] [PATCH 1/7] vhost: make capabilities configurable Zhihong Wang
2018-02-06 10:19   ` Maxime Coquelin
2018-02-08  3:03     ` Wang, Zhihong
2018-02-02 23:28 ` [dpdk-dev] [PATCH 2/7] vhost: export vhost feature definitions Zhihong Wang
2018-02-02 23:28 ` Zhihong Wang [this message]
2018-02-02 23:28 ` [dpdk-dev] [PATCH 4/7] vhost: add apis for datapath configuration Zhihong Wang
2018-02-02 23:28 ` [dpdk-dev] [PATCH 5/7] vhost: adapt vhost lib for selective datapath Zhihong Wang
2018-02-02 23:28 ` [dpdk-dev] [PATCH 6/7] vhost: get callfd before device setup Zhihong Wang
2018-02-02 23:28 ` [dpdk-dev] [PATCH 7/7] vhost: export new apis Zhihong Wang
2018-03-05  9:20 ` [dpdk-dev] [PATCH v2 0/6] vhost: support selective datapath Zhihong Wang
2018-03-05  9:20   ` [dpdk-dev] [PATCH v2 1/6] vhost: export vhost feature definitions Zhihong Wang
2018-03-06  9:37     ` Tan, Jianfeng
2018-03-06 14:03       ` Maxime Coquelin
2018-03-15 10:58         ` Wang, Zhihong
2018-03-05  9:20   ` [dpdk-dev] [PATCH v2 2/6] vhost: support selective datapath Zhihong Wang
2018-03-05  9:20   ` [dpdk-dev] [PATCH v2 3/6] vhost: add apis for datapath configuration Zhihong Wang
2018-03-05  9:20   ` [dpdk-dev] [PATCH v2 5/6] vhost: add apis for live migration Zhihong Wang
2018-03-05  9:20   ` [dpdk-dev] [PATCH v2 4/6] vhost: adapt vhost lib for selective datapath Zhihong Wang
2018-03-05  9:20   ` [dpdk-dev] [PATCH v2 6/6] vhost: export new apis Zhihong Wang
2018-03-06  9:51     ` Tan, Jianfeng
2018-03-15 10:55       ` Wang, Zhihong
2018-03-19 10:12 ` [dpdk-dev] [PATCH v3 0/5] vhost: support selective datapath Zhihong Wang
2018-03-19 10:12   ` [dpdk-dev] [PATCH v3 1/5] vhost: export vhost feature definitions Zhihong Wang
2018-03-19 10:12   ` [dpdk-dev] [PATCH v3 2/5] vhost: support selective datapath Zhihong Wang
2018-03-21 21:05     ` Maxime Coquelin
2018-03-22  7:55       ` Wang, Zhihong
2018-03-22  8:31         ` Maxime Coquelin
2018-03-19 10:12   ` [dpdk-dev] [PATCH v3 3/5] vhost: add apis for datapath configuration Zhihong Wang
2018-03-21 21:08     ` Maxime Coquelin
2018-03-22  8:22       ` Wang, Zhihong
2018-03-22 14:18         ` Maxime Coquelin
2018-03-23 10:35           ` Wang, Zhihong
2018-03-19 10:12   ` [dpdk-dev] [PATCH v3 4/5] vhost: adapt vhost lib for selective datapath Zhihong Wang
2018-03-19 10:13   ` [dpdk-dev] [PATCH v3 5/5] vhost: add apis for live migration Zhihong Wang
2018-03-29 12:15   ` [dpdk-dev] [PATCH v3 0/5] vhost: support selective datapath Wodkowski, PawelX
2018-03-30  9:35     ` Wang, Zhihong
2018-03-30 10:00 ` [dpdk-dev] [PATCH v4 " Zhihong Wang
2018-03-30 10:00   ` [dpdk-dev] [PATCH v4 1/5] vhost: export vhost feature definitions Zhihong Wang
2018-03-31  5:56     ` Maxime Coquelin
2018-03-30 10:01   ` [dpdk-dev] [PATCH v4 2/5] vhost: support selective datapath Zhihong Wang
2018-03-31  6:10     ` Maxime Coquelin
2018-04-02  1:58       ` Wang, Zhihong
2018-03-31  7:38     ` Maxime Coquelin
2018-04-02  2:03       ` Wang, Zhihong
2018-03-30 10:01   ` [dpdk-dev] [PATCH v4 3/5] vhost: add apis for datapath configuration Zhihong Wang
2018-03-31  7:04     ` Maxime Coquelin
2018-04-02  2:01       ` Wang, Zhihong
2018-03-30 10:01   ` [dpdk-dev] [PATCH v4 4/5] vhost: adapt vhost lib for selective datapath Zhihong Wang
2018-03-31  7:35     ` Maxime Coquelin
2018-04-02 11:52       ` Wang, Zhihong
2018-03-30 10:01   ` [dpdk-dev] [PATCH v4 5/5] vhost: add apis for live migration Zhihong Wang
2018-03-31  7:39     ` Maxime Coquelin
2018-04-02 11:46 ` [dpdk-dev] [PATCH v5 0/5] vhost: support selective datapath Zhihong Wang
2018-04-02 11:46   ` [dpdk-dev] [PATCH v5 1/5] vhost: export vhost feature definitions Zhihong Wang
2018-04-02 11:46   ` [dpdk-dev] [PATCH v5 2/5] vhost: support selective datapath Zhihong Wang
2018-04-03  8:02     ` Maxime Coquelin
2018-04-15 17:39       ` Thomas Monjalon
2018-04-16  7:26         ` Maxime Coquelin
2018-04-03  8:19     ` Maxime Coquelin
2018-04-03 14:35       ` Wang, Zhihong
2018-04-02 11:46   ` [dpdk-dev] [PATCH v5 3/5] vhost: add apis for datapath configuration Zhihong Wang
2018-04-03  8:07     ` Maxime Coquelin
2018-04-02 11:46   ` [dpdk-dev] [PATCH v5 4/5] vhost: adapt vhost lib for selective datapath Zhihong Wang
2018-04-03  8:05     ` Maxime Coquelin
2018-04-02 11:46   ` [dpdk-dev] [PATCH v5 5/5] vhost: add apis for live migration Zhihong Wang
2018-04-03  8:27   ` [dpdk-dev] [PATCH v5 0/5] vhost: support selective datapath Maxime Coquelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1517614137-62926-4-git-send-email-zhihong.wang@intel.com \
    --to=zhihong.wang@intel.com \
    --cc=cunming.liang@intel.com \
    --cc=dan.daly@intel.com \
    --cc=dev@dpdk.org \
    --cc=jianfeng.tan@intel.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=tiwei.bie@intel.com \
    --cc=xiao.w.wang@intel.com \
    --cc=yliu@fridaylinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).