devices: vhost API cleanup
Use consistent API types.
Type: fix
Change-Id: I2dec594cb834a45004edc9ca58ad7c7b4bd7ff06
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
diff --git a/src/vnet/devices/virtio/vhost_user.api b/src/vnet/devices/virtio/vhost_user.api
index e08c735..9b05755 100644
--- a/src/vnet/devices/virtio/vhost_user.api
+++ b/src/vnet/devices/virtio/vhost_user.api
@@ -13,7 +13,11 @@
* limitations under the License.
*/
-option version = "3.0.0";
+option version = "4.0.0";
+
+import "vnet/interface_types.api";
+import "vnet/ethernet/ethernet_types.api";
+import "vnet/devices/virtio/virtio_types.api";
/** \brief vhost-user interface create request
@param client_index - opaque cookie to identify the sender
@@ -29,16 +33,16 @@
{
u32 client_index;
u32 context;
- u8 is_server;
- u8 sock_filename[256];
- u8 renumber;
- u8 disable_mrg_rxbuf;
- u8 disable_indirect_desc;
- u8 enable_gso;
+ bool is_server;
+ string sock_filename[256];
+ bool renumber;
+ bool disable_mrg_rxbuf;
+ bool disable_indirect_desc;
+ bool enable_gso;
u32 custom_dev_instance;
- u8 use_custom_mac;
- u8 mac_address[6];
- u8 tag[64];
+ bool use_custom_mac;
+ vl_api_mac_address_t mac_address;
+ string tag[64];
};
/** \brief vhost-user interface create response
@@ -50,7 +54,7 @@
{
u32 context;
i32 retval;
- u32 sw_if_index;
+ vl_api_interface_index_t sw_if_index;
};
/** \brief vhost-user interface modify request
@@ -63,11 +67,11 @@
{
u32 client_index;
u32 context;
- u32 sw_if_index;
- u8 is_server;
- u8 sock_filename[256];
- u8 renumber;
- u8 enable_gso;
+ vl_api_interface_index_t sw_if_index;
+ bool is_server;
+ string sock_filename[256];
+ bool renumber;
+ bool enable_gso;
u32 custom_dev_instance;
};
@@ -78,35 +82,42 @@
{
u32 client_index;
u32 context;
- u32 sw_if_index;
+ vl_api_interface_index_t sw_if_index;
};
/** \brief Vhost-user interface details structure (fix this)
@param sw_if_index - index of the interface
@param interface_name - name of interface
@param virtio_net_hdr_sz - net header size
- @param features - interface features
+ @param features_first_32 - interface features, first 32 bits
+ @param features_last_32 - interface features, last 32 bits
@param is_server - vhost-user server socket
@param sock_filename - socket filename
@param num_regions - number of used memory regions
+ @param sock_errno - socket errno
*/
define sw_interface_vhost_user_details
{
u32 context;
- u32 sw_if_index;
- u8 interface_name[64];
+ vl_api_interface_index_t sw_if_index;
+ string interface_name[64];
u32 virtio_net_hdr_sz;
- u64 features;
- u8 is_server;
- u8 sock_filename[256];
+ vl_api_virtio_net_features_first_32_t features_first_32;
+ vl_api_virtio_net_features_last_32_t features_last_32;
+ bool is_server;
+ string sock_filename[256];
u32 num_regions;
i32 sock_errno;
};
+/** \brief Vhost-user interface dump request
+ @param sw_if_index - filter by sw_if_index UNIMPLEMENTED
+*/
define sw_interface_vhost_user_dump
{
u32 client_index;
u32 context;
+ vl_api_interface_index_t sw_if_index [default=0xffffffff];
};
/*
* Local Variables:
diff --git a/src/vnet/devices/virtio/vhost_user_api.c b/src/vnet/devices/virtio/vhost_user_api.c
index c8c9b59..2ab87a6 100644
--- a/src/vnet/devices/virtio/vhost_user_api.c
+++ b/src/vnet/devices/virtio/vhost_user_api.c
@@ -23,6 +23,9 @@
#include <vnet/interface.h>
#include <vnet/api_errno.h>
#include <vnet/devices/virtio/vhost_user.h>
+#include <vnet/ethernet/ethernet.h>
+#include <vnet/ethernet/ethernet_types_api.h>
+#include <vnet/devices/virtio/virtio_types_api.h>
#include <vnet/vnet_msg_enum.h>
@@ -58,6 +61,8 @@
vlib_main_t *vm = vlib_get_main ();
u64 features = (u64) ~ (0ULL);
u64 disabled_features = (u64) (0ULL);
+ mac_address_t mac;
+ u8 *mac_p = NULL;
if (mp->disable_mrg_rxbuf)
disabled_features = (1ULL << FEAT_VIRTIO_NET_F_MRG_RXBUF);
@@ -72,11 +77,16 @@
disabled_features |= FEATURE_VIRTIO_NET_F_HOST_GUEST_TSO_FEATURE_BITS;
features &= ~disabled_features;
+ if (mp->use_custom_mac)
+ {
+ mac_address_decode (mp->mac_address, &mac);
+ mac_p = (u8 *) & mac;
+ }
+
rv = vhost_user_create_if (vnm, vm, (char *) mp->sock_filename,
mp->is_server, &sw_if_index, features,
mp->renumber, ntohl (mp->custom_dev_instance),
- (mp->use_custom_mac) ? mp->mac_address : NULL,
- mp->enable_gso);
+ mac_p, mp->enable_gso);
/* Remember an interface tag for the new interface */
if (rv == 0)
@@ -163,7 +173,8 @@
mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_VHOST_USER_DETAILS);
mp->sw_if_index = ntohl (vui->sw_if_index);
mp->virtio_net_hdr_sz = ntohl (vui->virtio_net_hdr_sz);
- mp->features = clib_net_to_host_u64 (vui->features);
+ virtio_features_encode (vui->features, (u32 *) & mp->features_first_32,
+ (u32 *) & mp->features_last_32);
mp->is_server = vui->is_server;
mp->num_regions = ntohl (vui->num_regions);
mp->sock_errno = ntohl (vui->sock_errno);
@@ -188,11 +199,16 @@
vhost_user_intf_details_t *ifaces = NULL;
vhost_user_intf_details_t *vuid = NULL;
vl_api_registration_t *reg;
+ u32 filter_sw_if_index;
reg = vl_api_client_index_to_registration (mp->client_index);
if (!reg)
return;
+ filter_sw_if_index = htonl (mp->sw_if_index);
+ if (filter_sw_if_index != ~0)
+ return; /* UNIMPLEMENTED */
+
rv = vhost_user_dump_ifs (vnm, vm, &ifaces);
if (rv)
return;
diff --git a/src/vnet/devices/virtio/virtio_types.api b/src/vnet/devices/virtio/virtio_types.api
new file mode 100644
index 0000000..4ed43cb
--- /dev/null
+++ b/src/vnet/devices/virtio/virtio_types.api
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+option version = "1.0.0";
+
+enum virtio_net_features_first_32
+{
+ VIRTIO_NET_F_API_CSUM = 0x0001, /* 0 */
+ VIRTIO_NET_F_API_GUEST_CSUM = 0x0002, /* 1 */
+ VIRTIO_NET_F_API_GUEST_TSO4 = 0x0080, /* 7 */
+ VIRTIO_NET_F_API_GUEST_TSO6 = 0x0100, /* 8 */
+ VIRTIO_NET_F_API_GUEST_UFO = 0x0400, /* 10 */
+ VIRTIO_NET_F_API_HOST_TSO4 = 0x0800, /* 11 */
+ VIRTIO_NET_F_API_HOST_TSO6 = 0x1000, /* 12 */
+ VIRTIO_NET_F_API_HOST_UFO = 0x4000, /* 14 */
+ VIRTIO_NET_F_API_MRG_RXBUF = 0x8000, /* 15 */
+ VIRTIO_NET_F_API_CTRL_VQ = 0x00020000, /* 17 */
+ VIRTIO_NET_F_API_GUEST_ANNOUNCE = 0x00200000, /* 21 */
+ VIRTIO_NET_F_API_MQ = 0x00400000, /* 22 */
+ VHOST_F_API_LOG_ALL = 0x04000000, /* 26 */
+ VIRTIO_F_API_ANY_LAYOUT = 0x08000000, /* 27 */
+ VIRTIO_F_API_INDIRECT_DESC = 0x10000000, /* 28*/
+ VHOST_USER_F_API_PROTOCOL_FEATURES = 0x40000000, /* 30 */
+};
+
+enum virtio_net_features_last_32
+{
+ VIRTIO_F_API_VERSION_1 = 0x0001, /* 32 */
+};
+
+/*
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/devices/virtio/virtio_types_api.c b/src/vnet/devices/virtio/virtio_types_api.c
new file mode 100644
index 0000000..48e0ab9
--- /dev/null
+++ b/src/vnet/devices/virtio/virtio_types_api.c
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vnet/vnet.h>
+
+#include <vlibapi/api_types.h>
+#include <vnet/devices/virtio/virtio_types_api.h>
+
+
+u64
+virtio_features_decode (u32 first, u32 last)
+{
+ return clib_net_to_host_u32 (first) | ((u64)clib_net_to_host_u32 (last) << 32);
+}
+
+void
+virtio_features_encode (u64 features, u32 *first, u32 *last)
+{
+ *first = clib_net_to_host_u32 (features);
+ *last = clib_net_to_host_u32 (features >> 32);
+}
diff --git a/src/vnet/devices/virtio/virtio_types_api.h b/src/vnet/devices/virtio/virtio_types_api.h
new file mode 100644
index 0000000..ff35fa3
--- /dev/null
+++ b/src/vnet/devices/virtio/virtio_types_api.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __VIRTIO_TYPES_API_H__
+#define __VIRTIO_TYPES_API_H__
+
+/**
+ * Conversion functions to/from (decode/encode) API types to VPP internal types
+ */
+
+/**
+ * These enum decode/encodes use 'u32' as the type for the enum because
+ * one cannot forward declare an enum
+ */
+extern u64 virtio_features_decode (u32 first, u32 last);
+extern void virtio_features_encode (u64 features, u32 * first, u32 * last);
+
+#endif /* __VIRTIO_TYPES_API_H__ */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */