diff options
-rw-r--r-- | vnet/Makefile.am | 2 | ||||
-rw-r--r-- | vnet/vnet/devices/dpdk/vhost_user.c | 14 | ||||
-rw-r--r-- | vnet/vnet/devices/virtio/vhost-user.c | 50 | ||||
-rw-r--r-- | vnet/vnet/devices/virtio/vhost-user.h | 4 | ||||
-rw-r--r-- | vpp/vpp-api/api.c | 49 |
5 files changed, 84 insertions, 35 deletions
diff --git a/vnet/Makefile.am b/vnet/Makefile.am index 72bdd11f54b..a763291c2af 100644 --- a/vnet/Makefile.am +++ b/vnet/Makefile.am @@ -626,13 +626,11 @@ endif # virtio ######################################## -if WITH_DPDK libvnet_la_SOURCES += \ vnet/devices/virtio/vhost-user.c nobase_include_HEADERS += \ vnet/devices/virtio/vhost-user.h -endif WITH_DPDK ######################################## # ssvm ethernet diff --git a/vnet/vnet/devices/dpdk/vhost_user.c b/vnet/vnet/devices/dpdk/vhost_user.c index 11a81c2d7cb..58cff7b940f 100644 --- a/vnet/vnet/devices/dpdk/vhost_user.c +++ b/vnet/vnet/devices/dpdk/vhost_user.c @@ -1790,6 +1790,7 @@ dpdk_vhost_user_process_if (vlib_main_t * vm, dpdk_device_t * xd, void *ctx) } return 0; } +#endif /* * CLI functions @@ -1800,6 +1801,7 @@ dpdk_vhost_user_connect_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { +#if DPDK_VHOST_USER dpdk_main_t *dm = &dpdk_main; unformat_input_t _line_input, *line_input = &_line_input; u8 *sock_filename = NULL; @@ -1813,7 +1815,9 @@ dpdk_vhost_user_connect_command_fn (vlib_main_t * vm, if (dm->conf->use_virtio_vhost) { +#endif return vhost_user_connect_command_fn (vm, input, cmd); +#if DPDK_VHOST_USER } /* Get a line of input. */ @@ -1854,6 +1858,7 @@ dpdk_vhost_user_connect_command_fn (vlib_main_t * vm, vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index); return 0; +#endif } /* *INDENT-OFF* */ @@ -1902,7 +1907,11 @@ dpdk_vhost_user_delete_command_fn (vlib_main_t * vm, vnet_main_t *vnm = vnet_get_main (); +#if DPDK_VHOST_USER dpdk_vhost_user_delete_if (vnm, vm, sw_if_index); +#else + vhost_user_delete_if (vnm, vm, sw_if_index); +#endif return 0; } @@ -1925,6 +1934,7 @@ show_dpdk_vhost_user_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { +#if DPDK_VHOST_USER clib_error_t *error = 0; dpdk_main_t *dm = &dpdk_main; vnet_main_t *vnm = vnet_get_main (); @@ -1952,7 +1962,9 @@ show_dpdk_vhost_user_command_fn (vlib_main_t * vm, if (dm->conf->use_virtio_vhost) { +#endif return show_vhost_user_command_fn (vm, input, cmd); +#if DPDK_VHOST_USER } while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) @@ -2089,6 +2101,7 @@ show_dpdk_vhost_user_command_fn (vlib_main_t * vm, done: vec_free (hw_if_indices); return error; +#endif } /* *INDENT-OFF* */ @@ -2098,7 +2111,6 @@ VLIB_CLI_COMMAND (show_vhost_user_command, static) = { .function = show_dpdk_vhost_user_command_fn, }; /* *INDENT-ON* */ -#endif /* * fd.io coding-style-patch-verification: ON diff --git a/vnet/vnet/devices/virtio/vhost-user.c b/vnet/vnet/devices/virtio/vhost-user.c index 51b0c409d2a..6fa1c652c8f 100644 --- a/vnet/vnet/devices/virtio/vhost-user.c +++ b/vnet/vnet/devices/virtio/vhost-user.c @@ -293,7 +293,7 @@ vhost_user_log_dirty_pages (vhost_user_intf_t * vui, u64 addr, u64 len) #define vhost_user_log_dirty_ring(vui, vq, member) \ if (PREDICT_FALSE(vq->log_used)) { \ - vhost_user_log_dirty_pages(vui, vq->log_guest_addr + offsetof(vring_used_t, member), \ + vhost_user_log_dirty_pages(vui, vq->log_guest_addr + STRUCT_OFFSET_OF(vring_used_t, member), \ sizeof(vq->used->member)); \ } @@ -1210,19 +1210,25 @@ vhost_user_input (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * f) { vhost_user_main_t *vum = &vhost_user_main; +#if DPDK > 0 dpdk_main_t *dm = &dpdk_main; + u32 cpu_index = os_get_cpu_number (); +#endif vhost_user_intf_t *vui; uword n_rx_packets = 0; - u32 cpu_index = os_get_cpu_number (); int i; for (i = 0; i < vec_len (vum->vhost_user_interfaces); i++) { vui = vec_elt_at_index (vum->vhost_user_interfaces, i); - if (vui->is_up && - (i % dm->input_cpu_count) == - (cpu_index - dm->input_cpu_first_index)) - n_rx_packets += vhost_user_if_input (vm, vum, vui, node); + if (vui->is_up) + { +#if DPDK > 0 + if ((i % dm->input_cpu_count) == + (cpu_index - dm->input_cpu_first_index)) +#endif + n_rx_packets += vhost_user_if_input (vm, vum, vui, node); + } } return n_rx_packets; } @@ -1813,9 +1819,11 @@ static void vhost_user_vui_register (vlib_main_t * vm, vhost_user_intf_t * vui) { vhost_user_main_t *vum = &vhost_user_main; +#if DPDK > 0 dpdk_main_t *dm = &dpdk_main; int cpu_index; vlib_thread_main_t *tm = vlib_get_thread_main (); +#endif hash_set (vum->vhost_user_interface_index_by_listener_fd, vui->unix_fd, vui - vum->vhost_user_interfaces); @@ -1823,15 +1831,19 @@ vhost_user_vui_register (vlib_main_t * vm, vhost_user_intf_t * vui) vui - vum->vhost_user_interfaces); /* start polling */ +#if DPDK > 0 cpu_index = dm->input_cpu_first_index + (vui - vum->vhost_user_interfaces) % dm->input_cpu_count; if (tm->n_vlib_mains == 1) +#endif vlib_node_set_state (vm, vhost_user_input_node.index, VLIB_NODE_STATE_POLLING); +#if DPDK > 0 else vlib_node_set_state (vlib_mains[cpu_index], vhost_user_input_node.index, VLIB_NODE_STATE_POLLING); +#endif /* tell process to start polling for sockets */ vlib_process_signal_event (vm, vhost_user_process_node.index, 0, 0); @@ -2221,6 +2233,32 @@ done: return error; } +/* + * CLI functions + */ + +#if DPDK == 0 +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (vhost_user_connect_command, static) = { + .path = "create vhost-user", + .short_help = "create vhost-user socket <socket-filename> [server] [feature-mask <hex>] [renumber <dev_instance>]", + .function = vhost_user_connect_command_fn, +}; + +VLIB_CLI_COMMAND (vhost_user_delete_command, static) = { + .path = "delete vhost-user", + .short_help = "delete vhost-user sw_if_index <nn>", + .function = vhost_user_delete_command_fn, +}; + +VLIB_CLI_COMMAND (show_vhost_user_command, static) = { + .path = "show vhost-user", + .short_help = "show vhost-user interface", + .function = show_vhost_user_command_fn, +}; +/* *INDENT-ON* */ +#endif + static clib_error_t * vhost_user_config (vlib_main_t * vm, unformat_input_t * input) { diff --git a/vnet/vnet/devices/virtio/vhost-user.h b/vnet/vnet/devices/virtio/vhost-user.h index fc413609362..4934a8c0c1e 100644 --- a/vnet/vnet/devices/virtio/vhost-user.h +++ b/vnet/vnet/devices/virtio/vhost-user.h @@ -31,6 +31,10 @@ #define VHOST_VRING_F_LOG 0 #define VHOST_USER_F_PROTOCOL_FEATURES 30 +#if DPDK == 0 +#define RTE_VERSION_NUM(a,b,c,d) 1 +#define RTE_VERSION 0 +#endif #if RTE_VERSION >= RTE_VERSION_NUM(16, 4, 0, 0) #define VHOST_USER_PROTOCOL_FEATURES ((1ULL << VHOST_USER_PROTOCOL_F_MQ) | \ (1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD)) diff --git a/vpp/vpp-api/api.c b/vpp/vpp-api/api.c index 2ba5ee4045f..15a7bf416ed 100644 --- a/vpp/vpp-api/api.c +++ b/vpp/vpp-api/api.c @@ -92,9 +92,7 @@ #include <vnet/ipsec/ipsec.h> #include <vnet/ipsec/ikev2.h> #endif /* IPSEC */ -#if DPDK > 0 #include <vnet/devices/virtio/vhost-user.h> -#endif #include <stats/stats.h> #include <oam/oam.h> @@ -4027,16 +4025,20 @@ vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp) { int rv = 0; vl_api_create_vhost_user_if_reply_t *rmp; -#if DPDK > 0 u32 sw_if_index = (u32) ~ 0; vnet_main_t *vnm = vnet_get_main (); vlib_main_t *vm = vlib_get_main (); - rv = vhost_user_create_if (vnm, vm, (char *) mp->sock_filename, - mp->is_server, &sw_if_index, (u64) ~ 0, - mp->renumber, ntohl (mp->custom_dev_instance), - (mp->use_custom_mac) ? mp->mac_address : NULL); +#if DPDK > 0 && DPDK_VHOST_USER + rv = dpdk_vhost_user_create_if ( +#else + rv = vhost_user_create_if ( +#endif + vnm, vm, (char *) mp->sock_filename, + mp->is_server, &sw_if_index, (u64) ~ 0, + mp->renumber, ntohl (mp->custom_dev_instance), + (mp->use_custom_mac) ? mp->mac_address : NULL); /* *INDENT-OFF* */ REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY, @@ -4044,10 +4046,6 @@ vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t * mp) rmp->sw_if_index = ntohl (sw_if_index); })); /* *INDENT-ON* */ -#else - rv = VNET_API_ERROR_UNIMPLEMENTED; - REPLY_MACRO (VL_API_CREATE_VHOST_USER_IF_REPLY); -#endif } static void @@ -4055,19 +4053,19 @@ vl_api_modify_vhost_user_if_t_handler (vl_api_modify_vhost_user_if_t * mp) { int rv = 0; vl_api_modify_vhost_user_if_reply_t *rmp; -#if DPDK > 0 && DPDK_VHOST_USER u32 sw_if_index = ntohl (mp->sw_if_index); vnet_main_t *vnm = vnet_get_main (); vlib_main_t *vm = vlib_get_main (); - rv = dpdk_vhost_user_modify_if (vnm, vm, (char *) mp->sock_filename, - mp->is_server, sw_if_index, (u64) ~ 0, - mp->renumber, - ntohl (mp->custom_dev_instance)); +#if DPDK > 0 && DPDK_VHOST_USER + rv = dpdk_vhost_user_modify_if ( #else - rv = VNET_API_ERROR_UNIMPLEMENTED; + rv = vhost_user_modify_if ( #endif + vnm, vm, (char *) mp->sock_filename, + mp->is_server, sw_if_index, (u64) ~ 0, + mp->renumber, ntohl (mp->custom_dev_instance)); REPLY_MACRO (VL_API_MODIFY_VHOST_USER_IF_REPLY); } @@ -4076,14 +4074,17 @@ vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp) { int rv = 0; vl_api_delete_vhost_user_if_reply_t *rmp; -#if DPDK > 0 && DPDK_VHOST_USER vpe_api_main_t *vam = &vpe_api_main; u32 sw_if_index = ntohl (mp->sw_if_index); vnet_main_t *vnm = vnet_get_main (); vlib_main_t *vm = vlib_get_main (); +#if DPDK > 0 && DPDK_VHOST_USER rv = dpdk_vhost_user_delete_if (vnm, vm, sw_if_index); +#else + rv = vhost_user_delete_if (vnm, vm, sw_if_index); +#endif REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY); if (!rv) @@ -4095,10 +4096,6 @@ vl_api_delete_vhost_user_if_t_handler (vl_api_delete_vhost_user_if_t * mp) send_sw_interface_flags_deleted (vam, q, sw_if_index); } -#else - rv = VNET_API_ERROR_UNIMPLEMENTED; - REPLY_MACRO (VL_API_DELETE_VHOST_USER_IF_REPLY); -#endif } static void @@ -4108,7 +4105,6 @@ static void clib_warning ("BUG"); } -#if DPDK > 0 && DPDK_VHOST_USER static void send_sw_interface_vhost_user_details (vpe_api_main_t * am, unix_shared_memory_queue_t * q, @@ -4135,13 +4131,11 @@ send_sw_interface_vhost_user_details (vpe_api_main_t * am, vl_msg_api_send_shmem (q, (u8 *) & mp); } -#endif static void vl_api_sw_interface_vhost_user_dump_t_handler (vl_api_sw_interface_vhost_user_dump_t * mp) { -#if DPDK > 0 && DPDK_VHOST_USER int rv = 0; vpe_api_main_t *am = &vpe_api_main; vnet_main_t *vnm = vnet_get_main (); @@ -4154,7 +4148,11 @@ static void if (q == 0) return; +#if DPDK > 0 && DPDK_VHOST_USER rv = dpdk_vhost_user_dump_ifs (vnm, vm, &ifaces); +#else + rv = vhost_user_dump_ifs (vnm, vm, &ifaces); +#endif if (rv) return; @@ -4163,7 +4161,6 @@ static void send_sw_interface_vhost_user_details (am, q, vuid, mp->context); } vec_free (ifaces); -#endif } static void |