DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v2] vhost: add external message handling callbacks to the public API
@ 2019-01-14  4:28 Darek Stojaczyk
  2019-01-15 11:22 ` Tiwei Bie
  2019-01-17 15:32 ` [dpdk-dev] [PATCH v3] " Darek Stojaczyk
  0 siblings, 2 replies; 6+ messages in thread
From: Darek Stojaczyk @ 2019-01-14  4:28 UTC (permalink / raw)
  To: dev, Zhihong Wang, Cunming Liang, Tiwei Bie, Maxime Coquelin
  Cc: James R Harris, Changpeng Liu, Darek Stojaczyk

External message callbacks are used e.g. by vhost crypto
to parse crypto-specific vhost-user messages.

We are now publishing the API to register those callbacks,
so that other backends outside of DPDK can use them as well.

Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
---
 lib/librte_vhost/rte_vhost.h | 66 ++++++++++++++++++++++++++++++++++++
 lib/librte_vhost/vhost.c     | 13 +++++++
 lib/librte_vhost/vhost.h     | 54 ++---------------------------
 3 files changed, 81 insertions(+), 52 deletions(-)

diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
index d280ac420..a11f9ca04 100644
--- a/lib/librte_vhost/rte_vhost.h
+++ b/lib/librte_vhost/rte_vhost.h
@@ -111,6 +111,56 @@ struct rte_vhost_vring {
 	uint16_t		size;
 };
 
+/* The possible results of a message handling function */
+enum vh_result {
+	/* Message handling failed */
+	VH_RESULT_ERR   = -1,
+	/* Message handling successful */
+	VH_RESULT_OK    =  0,
+	/* Message handling successful and reply prepared */
+	VH_RESULT_REPLY =  1,
+};
+
+/**
+ * Function prototype for the vhost backend to handler specific vhost user
+ * messages prior to the master message handling
+ *
+ * @param vid
+ *  vhost device id
+ * @param msg
+ *  Message pointer.
+ * @param skip_master
+ *  If the handler requires skipping the master message handling, this variable
+ *  shall be written 1, otherwise 0.
+ * @return
+ *  VH_RESULT_OK on success, VH_RESULT_REPLY on success with reply,
+ *  VH_RESULT_ERR on failure
+ */
+typedef enum vh_result (*rte_vhost_msg_pre_handle)(int vid, void *msg,
+		uint32_t *skip_master);
+
+/**
+ * Function prototype for the vhost backend to handler specific vhost user
+ * messages after the master message handling is done
+ *
+ * @param vid
+ *  vhost device id
+ * @param msg
+ *  Message pointer.
+ * @return
+ *  VH_RESULT_OK on success, VH_RESULT_REPLY on success with reply,
+ *  VH_RESULT_ERR on failure
+ */
+typedef enum vh_result (*rte_vhost_msg_post_handle)(int vid, void *msg);
+
+/**
+ * Optional vhost user message handlers.
+ */
+struct rte_vhost_user_extern_ops {
+	rte_vhost_msg_pre_handle pre_msg_handle;
+	rte_vhost_msg_post_handle post_msg_handle;
+};
+
 /**
  * Device and vring operations.
  */
@@ -640,6 +690,22 @@ int __rte_experimental
 rte_vhost_set_vring_base(int vid, uint16_t queue_id,
 		uint16_t last_avail_idx, uint16_t last_used_idx);
 
+/**
+ * Register external message handling callbacks
+ *
+ * @param vid
+ *  vhost device ID
+ * @param ops
+ *  virtio external callbacks to register
+ * @param ctx
+ *  additional context passed to the callbacks
+ * @return
+ *  0 on success, -1 on failure
+ */
+int __rte_experimental
+rte_vhost_extern_callback_register(int vid,
+		struct rte_vhost_user_extern_ops const * const ops, void *ctx);
+
 /**
  * Get vdpa device id for vhost device.
  *
diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index b32babee4..00ec58e01 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -820,3 +820,16 @@ int rte_vhost_set_vring_base(int vid, uint16_t queue_id,
 
 	return 0;
 }
+
+int rte_vhost_extern_callback_register(int vid,
+		struct rte_vhost_user_extern_ops const * const ops, void *ctx)
+{
+	struct virtio_net *dev = get_device(vid);
+
+	if (!dev)
+		return -1;
+
+	dev->extern_ops = *ops;
+	dev->extern_data = ctx;
+	return 0;
+}
diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
index f267f898c..fc31796bf 100644
--- a/lib/librte_vhost/vhost.h
+++ b/lib/librte_vhost/vhost.h
@@ -286,56 +286,6 @@ struct guest_page {
 	uint64_t size;
 };
 
-/* The possible results of a message handling function */
-enum vh_result {
-	/* Message handling failed */
-	VH_RESULT_ERR   = -1,
-	/* Message handling successful */
-	VH_RESULT_OK    =  0,
-	/* Message handling successful and reply prepared */
-	VH_RESULT_REPLY =  1,
-};
-
-/**
- * function prototype for the vhost backend to handler specific vhost user
- * messages prior to the master message handling
- *
- * @param vid
- *  vhost device id
- * @param msg
- *  Message pointer.
- * @param skip_master
- *  If the handler requires skipping the master message handling, this variable
- *  shall be written 1, otherwise 0.
- * @return
- *  VH_RESULT_OK on success, VH_RESULT_REPLY on success with reply,
- *  VH_RESULT_ERR on failure
- */
-typedef enum vh_result (*vhost_msg_pre_handle)(int vid, void *msg,
-		uint32_t *skip_master);
-
-/**
- * function prototype for the vhost backend to handler specific vhost user
- * messages after the master message handling is done
- *
- * @param vid
- *  vhost device id
- * @param msg
- *  Message pointer.
- * @return
- *  VH_RESULT_OK on success, VH_RESULT_REPLY on success with reply,
- *  VH_RESULT_ERR on failure
- */
-typedef enum vh_result (*vhost_msg_post_handle)(int vid, void *msg);
-
-/**
- * pre and post vhost user message handlers
- */
-struct vhost_user_extern_ops {
-	vhost_msg_pre_handle pre_msg_handle;
-	vhost_msg_post_handle post_msg_handle;
-};
-
 /**
  * Device structure contains all configuration information relating
  * to the device.
@@ -379,10 +329,10 @@ struct virtio_net {
 	 */
 	int			vdpa_dev_id;
 
-	/* private data for virtio device */
+	/* context data for the external message handlers */
 	void			*extern_data;
 	/* pre and post vhost user message handlers for the device */
-	struct vhost_user_extern_ops extern_ops;
+	struct rte_vhost_user_extern_ops extern_ops;
 } __rte_cache_aligned;
 
 static __rte_always_inline bool
-- 
2.17.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-02-08 18:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-14  4:28 [dpdk-dev] [PATCH v2] vhost: add external message handling callbacks to the public API Darek Stojaczyk
2019-01-15 11:22 ` Tiwei Bie
2019-01-16 12:22   ` Stojaczyk, Dariusz
2019-01-17 15:32 ` [dpdk-dev] [PATCH v3] " Darek Stojaczyk
2019-01-21  8:25   ` Maxime Coquelin
2019-02-08 18:04   ` Maxime Coquelin

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).