From 9f562cd9e651df8579ea05f5f3b77b8b912938c2 Mon Sep 17 00:00:00 2001 From: Filip Tehlar Date: Wed, 23 Jun 2021 00:23:05 +0000 Subject: virtio: api cleanup Use autogenerated code. Does not change API definitions. Type: improvement Signed-off-by: Filip Tehlar Change-Id: I4f9316b16f16a48e2042aa17db596bfd181bd314 --- src/vnet/devices/virtio/virtio.h | 1 + src/vnet/devices/virtio/virtio_api.c | 61 +++++++----------------------------- src/vnet/vnet_all_api_h.h | 1 - 3 files changed, 13 insertions(+), 50 deletions(-) (limited to 'src/vnet') diff --git a/src/vnet/devices/virtio/virtio.h b/src/vnet/devices/virtio/virtio.h index c149ce482e6..48996052e2b 100644 --- a/src/vnet/devices/virtio/virtio.h +++ b/src/vnet/devices/virtio/virtio.h @@ -218,6 +218,7 @@ typedef struct vlib_log_class_t log_default; virtio_if_t *interfaces; + u16 msg_id_base; } virtio_main_t; extern virtio_main_t virtio_main; diff --git a/src/vnet/devices/virtio/virtio_api.c b/src/vnet/devices/virtio/virtio_api.c index 4d0b663b3dd..11514c75c59 100644 --- a/src/vnet/devices/virtio/virtio_api.c +++ b/src/vnet/devices/virtio/virtio_api.c @@ -26,30 +26,13 @@ #include #include -#include - -#define vl_typedefs /* define message structures */ -#include -#undef vl_typedefs - -#define vl_endianfun /* define message structures */ -#include -#undef vl_endianfun - -/* instantiate all the print functions we know about */ -#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) -#define vl_printfun -#include -#undef vl_printfun +#include +#include +#include +#define REPLY_MSG_ID_BASE virtio_main.msg_id_base #include -#define foreach_virtio_pci_api_msg \ -_(VIRTIO_PCI_CREATE, virtio_pci_create) \ -_(VIRTIO_PCI_CREATE_V2, virtio_pci_create_v2) \ -_(VIRTIO_PCI_DELETE, virtio_pci_delete) \ -_(SW_INTERFACE_VIRTIO_PCI_DUMP, sw_interface_virtio_pci_dump) - /* It will be deprecated in 21.01 */ static void vl_api_virtio_pci_create_t_handler (vl_api_virtio_pci_create_t * mp) @@ -86,7 +69,7 @@ vl_api_virtio_pci_create_t_handler (vl_api_virtio_pci_create_t * mp) return;; rmp = vl_msg_api_alloc (sizeof (*rmp)); - rmp->_vl_msg_id = htons (VL_API_VIRTIO_PCI_CREATE_REPLY); + rmp->_vl_msg_id = htons (REPLY_MSG_ID_BASE + VL_API_VIRTIO_PCI_CREATE_REPLY); rmp->context = mp->context; rmp->retval = htonl (ap->rv); rmp->sw_if_index = htonl (ap->sw_if_index); @@ -148,7 +131,8 @@ vl_api_virtio_pci_create_v2_t_handler (vl_api_virtio_pci_create_v2_t * mp) return;; rmp = vl_msg_api_alloc (sizeof (*rmp)); - rmp->_vl_msg_id = htons (VL_API_VIRTIO_PCI_CREATE_V2_REPLY); + rmp->_vl_msg_id = + htons (REPLY_MSG_ID_BASE + VL_API_VIRTIO_PCI_CREATE_V2_REPLY); rmp->context = mp->context; rmp->retval = htonl (ap->rv); rmp->sw_if_index = htonl (ap->sw_if_index); @@ -187,7 +171,7 @@ reply: return; rmp = vl_msg_api_alloc (sizeof (*rmp)); - rmp->_vl_msg_id = htons (VL_API_VIRTIO_PCI_DELETE_REPLY); + rmp->_vl_msg_id = htons (REPLY_MSG_ID_BASE + VL_API_VIRTIO_PCI_DELETE_REPLY); rmp->context = mp->context; rmp->retval = htonl (rv); @@ -204,7 +188,8 @@ virtio_pci_send_sw_interface_details (vpe_api_main_t * am, clib_memset (mp, 0, sizeof (*mp)); - mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_VIRTIO_PCI_DETAILS); + mp->_vl_msg_id = + htons (REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_VIRTIO_PCI_DETAILS); pci_address_encode ((vlib_pci_addr_t *) & vif->pci_addr.as_u32, &mp->pci_addr); mp->sw_if_index = htonl (vif->sw_if_index); @@ -241,37 +226,15 @@ static void } } -#define vl_msg_name_crc_list -#include -#undef vl_msg_name_crc_list - -static void -setup_message_id_table (api_main_t * am) -{ -#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); - foreach_vl_msg_name_crc_virtio; -#undef _ -} +#include static clib_error_t * virtio_pci_api_hookup (vlib_main_t * vm) { - api_main_t *am = vlibapi_get_main (); - -#define _(N,n) \ - vl_msg_api_set_handlers(VL_API_##N, #n, \ - vl_api_##n##_t_handler, \ - vl_noop_handler, \ - vl_api_##n##_t_endian, \ - vl_api_##n##_t_print, \ - sizeof(vl_api_##n##_t), 1); - foreach_virtio_pci_api_msg; -#undef _ - /* * Set up the (msg_name, crc, message-id) table */ - setup_message_id_table (am); + REPLY_MSG_ID_BASE = setup_message_id_table (); return 0; } diff --git a/src/vnet/vnet_all_api_h.h b/src/vnet/vnet_all_api_h.h index ddb64ea0030..9978181c78e 100644 --- a/src/vnet/vnet_all_api_h.h +++ b/src/vnet/vnet_all_api_h.h @@ -38,7 +38,6 @@ #include #include #include -#include /* * fd.io coding-style-patch-verification: ON -- cgit 1.2.3-korg