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 CFF641B441 for ; Mon, 14 Jan 2019 05:31:35 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Jan 2019 20:31:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,476,1539673200"; d="scan'208";a="125658788" Received: from violet.igk.intel.com ([10.102.54.137]) by FMSMGA003.fm.intel.com with ESMTP; 13 Jan 2019 20:31:32 -0800 From: Darek Stojaczyk To: dev@dpdk.org, Zhihong Wang , Cunming Liang , Tiwei Bie , Maxime Coquelin Cc: James R Harris , Changpeng Liu , Darek Stojaczyk Date: Mon, 14 Jan 2019 05:28:29 +0100 Message-Id: <20190114042829.24499-1-dariusz.stojaczyk@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH v2] vhost: add external message handling callbacks to the public API 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, 14 Jan 2019 04:31:36 -0000 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 --- 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