summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2019-11-08 17:41:06 +0100
committerFlorin Coras <florin.coras@gmail.com>2019-11-14 17:54:51 +0000
commitf41244f423a44c6d295895b011eec4bbeef08a8d (patch)
tree6e88a44f43d1970bc1f11b5c5cbbb9d8f6ece376 /src
parentaa27dcb84cb312277370b77370a69b2a3596c4c5 (diff)
virtio: refactor virtio-pci logging
Type: refactor Change-Id: I34306c1206b2bf5f521be6c6b78074ccf9259a08 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/vnet/CMakeLists.txt5
-rw-r--r--src/vnet/devices/virtio/cli.c2
-rw-r--r--src/vnet/devices/virtio/device.c21
-rw-r--r--src/vnet/devices/virtio/format.c66
-rw-r--r--src/vnet/devices/virtio/pci.c90
-rw-r--r--src/vnet/devices/virtio/pci.h21
-rw-r--r--src/vnet/devices/virtio/virtio.c14
-rw-r--r--src/vnet/devices/virtio/virtio.h25
8 files changed, 146 insertions, 98 deletions
diff --git a/src/vnet/CMakeLists.txt b/src/vnet/CMakeLists.txt
index 620af8f5fd2..8afbc1cec13 100644
--- a/src/vnet/CMakeLists.txt
+++ b/src/vnet/CMakeLists.txt
@@ -1032,16 +1032,17 @@ list(APPEND VNET_API_FILES pg/pg.api)
##############################################################################
list(APPEND VNET_SOURCES
+ devices/virtio/cli.c
devices/virtio/device.c
+ devices/virtio/format.c
devices/virtio/node.c
+ devices/virtio/pci.c
devices/virtio/vhost_user.c
devices/virtio/vhost_user_input.c
devices/virtio/vhost_user_output.c
devices/virtio/vhost_user_api.c
devices/virtio/virtio.c
devices/virtio/virtio_api.c
- devices/virtio/cli.c
- devices/virtio/pci.c
)
list(APPEND VNET_HEADERS
diff --git a/src/vnet/devices/virtio/cli.c b/src/vnet/devices/virtio/cli.c
index dbc2ad2c345..7291f17e645 100644
--- a/src/vnet/devices/virtio/cli.c
+++ b/src/vnet/devices/virtio/cli.c
@@ -186,8 +186,6 @@ VLIB_CLI_COMMAND (show_virtio_pci_command, static) = {
clib_error_t *
virtio_pci_cli_init (vlib_main_t * vm)
{
- virtio_main_t *vim = &virtio_main;
- vim->log_default = vlib_log_register_class ("virtio-pci", 0);
return 0;
}
diff --git a/src/vnet/devices/virtio/device.c b/src/vnet/devices/virtio/device.c
index e560c29e5e7..f9a1677f53f 100644
--- a/src/vnet/devices/virtio/device.c
+++ b/src/vnet/devices/virtio/device.c
@@ -46,27 +46,6 @@ static char *virtio_tx_func_error_strings[] = {
#undef _
};
-#ifndef CLIB_MARCH_VARIANT
-u8 *
-format_virtio_device_name (u8 * s, va_list * args)
-{
- u32 dev_instance = va_arg (*args, u32);
- virtio_main_t *mm = &virtio_main;
- virtio_if_t *vif = pool_elt_at_index (mm->interfaces, dev_instance);
-
- if (vif->type == VIRTIO_IF_TYPE_TAP)
- s = format (s, "tap%u", vif->id);
- else if (vif->type == VIRTIO_IF_TYPE_PCI)
- s = format (s, "virtio-%x/%x/%x/%x", vif->pci_addr.domain,
- vif->pci_addr.bus, vif->pci_addr.slot,
- vif->pci_addr.function);
- else
- s = format (s, "virtio-%lu", vif->dev_instance);
-
- return s;
-}
-#endif /* CLIB_MARCH_VARIANT */
-
static u8 *
format_virtio_device (u8 * s, va_list * args)
{
diff --git a/src/vnet/devices/virtio/format.c b/src/vnet/devices/virtio/format.c
new file mode 100644
index 00000000000..729635de35b
--- /dev/null
+++ b/src/vnet/devices/virtio/format.c
@@ -0,0 +1,66 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2018 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 <vlib/vlib.h>
+#include <vlib/unix/unix.h>
+#include <vlib/pci/pci.h>
+#include <vnet/ethernet/ethernet.h>
+#include <vnet/ip/ip4_packet.h>
+#include <vnet/ip/ip6_packet.h>
+#include <vnet/devices/virtio/virtio.h>
+#include <vnet/devices/virtio/pci.h>
+
+u8 *
+format_virtio_device_name (u8 * s, va_list * args)
+{
+ u32 dev_instance = va_arg (*args, u32);
+ virtio_main_t *mm = &virtio_main;
+ virtio_if_t *vif = pool_elt_at_index (mm->interfaces, dev_instance);
+
+ if (vif->type == VIRTIO_IF_TYPE_TAP)
+ s = format (s, "tap%u", vif->id);
+ else if (vif->type == VIRTIO_IF_TYPE_PCI)
+ s = format (s, "virtio-%x/%x/%x/%x", vif->pci_addr.domain,
+ vif->pci_addr.bus, vif->pci_addr.slot,
+ vif->pci_addr.function);
+ else
+ s = format (s, "virtio-%lu", vif->dev_instance);
+
+ return s;
+}
+
+u8 *
+format_virtio_log_name (u8 * s, va_list * args)
+{
+ virtio_if_t *vif = va_arg (*args, virtio_if_t *);
+
+ if (vif->type == VIRTIO_IF_TYPE_TAP)
+ s = format (s, "tap%u", vif->id);
+ else if (vif->type == VIRTIO_IF_TYPE_PCI)
+ s = format (s, "%U", format_vlib_pci_addr, &vif->pci_addr);
+ else
+ s = format (s, "virtio-%lu", vif->dev_instance);
+
+ return s;
+}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/devices/virtio/pci.c b/src/vnet/devices/virtio/pci.c
index d83df990d4a..1f569acb008 100644
--- a/src/vnet/devices/virtio/pci.c
+++ b/src/vnet/devices/virtio/pci.c
@@ -247,7 +247,6 @@ virtio_pci_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hw,
static clib_error_t *
virtio_pci_get_max_virtqueue_pairs (vlib_main_t * vm, virtio_if_t * vif)
{
- virtio_main_t *vim = &virtio_main;
virtio_net_config_t config;
clib_error_t *error = 0;
u16 max_queue_pairs = 1;
@@ -261,7 +260,7 @@ virtio_pci_get_max_virtqueue_pairs (vlib_main_t * vm, virtio_if_t * vif)
max_queue_pairs = config.max_virtqueue_pairs;
}
- virtio_log_debug (vim, vif, "max queue pair is %x", max_queue_pairs);
+ virtio_log_debug (vif, "max queue pair is %x", max_queue_pairs);
if (max_queue_pairs < 1 || max_queue_pairs > 0x8000)
return clib_error_return (error, "max queue pair is %x", max_queue_pairs);
@@ -463,7 +462,6 @@ static int
virtio_pci_send_ctrl_msg (vlib_main_t * vm, virtio_if_t * vif,
struct virtio_ctrl_msg *data, u32 len)
{
- virtio_main_t *vim = &virtio_main;
virtio_vring_t *vring = vif->cxq_vring;
virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
struct virtio_ctrl_msg result;
@@ -550,7 +548,7 @@ virtio_pci_send_ctrl_msg (vlib_main_t * vm, virtio_if_t * vif,
CLIB_MEMORY_BARRIER ();
clib_memcpy (&result, vlib_buffer_get_current (b),
sizeof (struct virtio_ctrl_msg));
- virtio_log_debug (vim, vif, "ctrl-queue: status %u", result.status);
+ virtio_log_debug (vif, "ctrl-queue: status %u", result.status);
status = result.status;
vlib_buffer_free (vm, &buffer_index, 1);
return status;
@@ -559,7 +557,6 @@ virtio_pci_send_ctrl_msg (vlib_main_t * vm, virtio_if_t * vif,
static int
virtio_pci_enable_gso (vlib_main_t * vm, virtio_if_t * vif)
{
- virtio_main_t *vim = &virtio_main;
struct virtio_ctrl_msg gso_hdr;
virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
@@ -573,7 +570,7 @@ virtio_pci_enable_gso (vlib_main_t * vm, virtio_if_t * vif)
clib_memcpy (gso_hdr.data, &offloads, sizeof (offloads));
status = virtio_pci_send_ctrl_msg (vm, vif, &gso_hdr, sizeof (offloads));
- virtio_log_debug (vim, vif, "enable gso");
+ virtio_log_debug (vif, "enable gso");
return status;
}
@@ -581,7 +578,6 @@ static int
virtio_pci_enable_multiqueue (vlib_main_t * vm, virtio_if_t * vif,
u16 num_queues)
{
- virtio_main_t *vim = &virtio_main;
struct virtio_ctrl_msg mq_hdr;
virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
@@ -591,7 +587,7 @@ virtio_pci_enable_multiqueue (vlib_main_t * vm, virtio_if_t * vif,
clib_memcpy (mq_hdr.data, &num_queues, sizeof (num_queues));
status = virtio_pci_send_ctrl_msg (vm, vif, &mq_hdr, sizeof (num_queues));
- virtio_log_debug (vim, vif, "multi-queue enable %u queues", num_queues);
+ virtio_log_debug (vif, "multi-queue enable %u queues", num_queues);
return status;
}
@@ -610,7 +606,6 @@ virtio_pci_control_vring_init (vlib_main_t * vm, virtio_if_t * vif,
u16 queue_num)
{
clib_error_t *error = 0;
- virtio_main_t *vim = &virtio_main;
u16 queue_size = 0;
virtio_vring_t *vring;
struct vring vr;
@@ -650,7 +645,7 @@ virtio_pci_control_vring_init (vlib_main_t * vm, virtio_if_t * vif,
ASSERT (vring->buffers == 0);
vring->size = queue_size;
- virtio_log_debug (vim, vif, "control-queue: number %u, size %u", queue_num,
+ virtio_log_debug (vif, "control-queue: number %u, size %u", queue_num,
queue_size);
virtio_pci_legacy_setup_queue (vm, vif, queue_num, ptr);
vring->kick_fd = -1;
@@ -662,7 +657,6 @@ clib_error_t *
virtio_pci_vring_init (vlib_main_t * vm, virtio_if_t * vif, u16 queue_num)
{
clib_error_t *error = 0;
- virtio_main_t *vim = &virtio_main;
vlib_thread_main_t *vtm = vlib_get_thread_main ();
u16 queue_size = 0;
virtio_vring_t *vring;
@@ -717,12 +711,12 @@ virtio_pci_vring_init (vlib_main_t * vm, virtio_if_t * vif, u16 queue_num)
vec_validate_aligned (vring->buffers, queue_size, CLIB_CACHE_LINE_BYTES);
if (queue_num % 2)
{
- virtio_log_debug (vim, vif, "tx-queue: number %u, size %u", queue_num,
+ virtio_log_debug (vif, "tx-queue: number %u, size %u", queue_num,
queue_size);
}
else
{
- virtio_log_debug (vim, vif, "rx-queue: number %u, size %u", queue_num,
+ virtio_log_debug (vif, "rx-queue: number %u, size %u", queue_num,
queue_size);
}
vring->size = queue_size;
@@ -825,14 +819,13 @@ clib_error_t *
virtio_pci_read_caps (vlib_main_t * vm, virtio_if_t * vif)
{
clib_error_t *error = 0;
- virtio_main_t *vim = &virtio_main;
struct virtio_pci_cap cap;
u8 pos, common_cfg = 0, notify_base = 0, dev_cfg = 0, isr = 0, pci_cfg = 0;
vlib_pci_dev_handle_t h = vif->pci_dev_handle;
if ((error = vlib_pci_read_config_u8 (vm, h, PCI_CAPABILITY_LIST, &pos)))
{
- virtio_log_error (vim, vif, "error in reading capabilty list position");
+ virtio_log_error (vif, "error in reading capabilty list position");
clib_error_return (error, "error in reading capabilty list position");
}
while (pos)
@@ -841,7 +834,7 @@ virtio_pci_read_caps (vlib_main_t * vm, virtio_if_t * vif)
vlib_pci_read_write_config (vm, h, VLIB_READ, pos, &cap,
sizeof (cap))))
{
- virtio_log_error (vim, vif, "%s [%2x]",
+ virtio_log_error (vif, "%s [%2x]",
"error in reading the capability at", pos);
clib_error_return (error,
"error in reading the capability at [%2x]", pos);
@@ -859,29 +852,29 @@ virtio_pci_read_caps (vlib_main_t * vm, virtio_if_t * vif)
pos + 2);
table_size = flags & table_size_mask;
- virtio_log_debug (vim, vif, "flags:0x%x %s 0x%x", flags,
+ virtio_log_debug (vif, "flags:0x%x %s 0x%x", flags,
"msix interrupt vector table-size", table_size);
if (flags & PCI_MSIX_ENABLE)
{
- virtio_log_debug (vim, vif, "msix interrupt enabled");
+ virtio_log_debug (vif, "msix interrupt enabled");
vif->msix_enabled = VIRTIO_MSIX_ENABLED;
}
else
{
- virtio_log_debug (vim, vif, "msix interrupt disabled");
+ virtio_log_debug (vif, "msix interrupt disabled");
vif->msix_enabled = VIRTIO_MSIX_DISABLED;
}
}
if (cap.cap_vndr != PCI_CAP_ID_VNDR)
{
- virtio_log_debug (vim, vif, "[%2x] %s %2x ", pos,
+ virtio_log_debug (vif, "[%2x] %s %2x ", pos,
"skipping non VNDR cap id:", cap.cap_vndr);
goto next;
}
- virtio_log_debug (vim, vif,
+ virtio_log_debug (vif,
"[%4x] cfg type: %u, bar: %u, offset: %04x, len: %u",
pos, cap.cfg_type, cap.bar, cap.offset, cap.length);
switch (cap.cfg_type)
@@ -909,14 +902,14 @@ virtio_pci_read_caps (vlib_main_t * vm, virtio_if_t * vif)
if (common_cfg == 0 || notify_base == 0 || dev_cfg == 0 || isr == 0)
{
- virtio_log_debug (vim, vif, "legacy virtio pci device found");
+ virtio_log_debug (vif, "legacy virtio pci device found");
return error;
}
if (!pci_cfg)
clib_error_return (error, "modern virtio pci device found");
- virtio_log_debug (vim, vif, "transitional virtio pci device found");
+ virtio_log_debug (vif, "transitional virtio pci device found");
return error;
}
@@ -925,7 +918,6 @@ virtio_pci_device_init (vlib_main_t * vm, virtio_if_t * vif,
virtio_pci_create_if_args_t * args)
{
clib_error_t *error = 0;
- virtio_main_t *vim = &virtio_main;
u8 status = 0;
if ((error = virtio_pci_read_caps (vm, vif)))
@@ -933,7 +925,7 @@ virtio_pci_device_init (vlib_main_t * vm, virtio_if_t * vif,
if (virtio_pci_reset_device (vm, vif) < 0)
{
- virtio_log_error (vim, vif, "Failed to reset the device");
+ virtio_log_error (vif, "Failed to reset the device");
clib_error_return (error, "Failed to reset the device");
}
/*
@@ -949,7 +941,7 @@ virtio_pci_device_init (vlib_main_t * vm, virtio_if_t * vif,
status = virtio_pci_legacy_get_status (vm, vif);
if (!(status & VIRTIO_CONFIG_STATUS_FEATURES_OK))
{
- virtio_log_error (vim, vif,
+ virtio_log_error (vif,
"error encountered: Device doesn't support requested features");
clib_error_return (error, "Device doesn't support requested features");
}
@@ -983,7 +975,7 @@ virtio_pci_device_init (vlib_main_t * vm, virtio_if_t * vif,
{
if ((error = virtio_pci_vring_init (vm, vif, RX_QUEUE (i))))
{
- virtio_log_warning (vim, vif, "%s (%u) %s", "error in rxq-queue",
+ virtio_log_warning (vif, "%s (%u) %s", "error in rxq-queue",
RX_QUEUE (i), "initialization");
}
else
@@ -993,7 +985,7 @@ virtio_pci_device_init (vlib_main_t * vm, virtio_if_t * vif,
if ((error = virtio_pci_vring_init (vm, vif, TX_QUEUE (i))))
{
- virtio_log_warning (vim, vif, "%s (%u) %s", "error in txq-queue",
+ virtio_log_warning (vif, "%s (%u) %s", "error in txq-queue",
TX_QUEUE (i), "initialization");
}
else
@@ -1007,8 +999,7 @@ virtio_pci_device_init (vlib_main_t * vm, virtio_if_t * vif,
if ((error =
virtio_pci_control_vring_init (vm, vif, vif->max_queue_pairs * 2)))
{
- virtio_log_warning (vim, vif, "%s (%u) %s",
- "error in control-queue",
+ virtio_log_warning (vif, "%s (%u) %s", "error in control-queue",
vif->max_queue_pairs * 2, "initialization");
if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MQ))
vif->features &= ~VIRTIO_FEATURE (VIRTIO_NET_F_MQ);
@@ -1016,7 +1007,7 @@ virtio_pci_device_init (vlib_main_t * vm, virtio_if_t * vif,
}
else
{
- virtio_log_debug (vim, vif, "control queue is not available");
+ virtio_log_debug (vif, "control queue is not available");
vif->cxq_vring = NULL;
}
@@ -1027,10 +1018,10 @@ virtio_pci_device_init (vlib_main_t * vm, virtio_if_t * vif,
{
if (virtio_pci_legacy_set_config_irq (vm, vif, 1) ==
VIRTIO_MSI_NO_VECTOR)
- virtio_log_warning (vim, vif, "config vector 1 is not set");
+ virtio_log_warning (vif, "config vector 1 is not set");
if (virtio_pci_legacy_set_queue_irq (vm, vif, 0, 0) ==
VIRTIO_MSI_NO_VECTOR)
- virtio_log_warning (vim, vif, "queue vector 0 is not set");
+ virtio_log_warning (vif, "queue vector 0 is not set");
}
/*
@@ -1088,17 +1079,17 @@ virtio_pci_create_if (vlib_main_t * vm, virtio_pci_create_if_args_t * args)
vif->pci_dev_handle = h;
vlib_pci_set_private_data (vm, h, vif->dev_instance);
vif->numa_node = vlib_pci_get_numa_node (vm, h);
+ vif->type = VIRTIO_IF_TYPE_PCI;
if ((error = vlib_pci_bus_master_enable (vm, h)))
{
- virtio_log_error (vim, vif,
- "error encountered on pci bus master enable");
+ virtio_log_error (vif, "error encountered on pci bus master enable");
goto error;
}
if ((error = vlib_pci_io_region (vm, h, 0)))
{
- virtio_log_error (vim, vif, "error encountered on pci io region");
+ virtio_log_error (vif, "error encountered on pci io region");
goto error;
}
@@ -1107,26 +1098,25 @@ virtio_pci_create_if (vlib_main_t * vm, virtio_pci_create_if_args_t * args)
if ((error = vlib_pci_register_msix_handler (vm, h, 0, 1,
&virtio_pci_irq_0_handler)))
{
- virtio_log_error (vim, vif,
+ virtio_log_error (vif,
"error encountered on pci register msix handler 0");
goto error;
}
if ((error = vlib_pci_register_msix_handler (vm, h, 1, 1,
&virtio_pci_irq_1_handler)))
{
- virtio_log_error (vim, vif,
+ virtio_log_error (vif,
"error encountered on pci register msix handler 1");
goto error;
}
if ((error = vlib_pci_enable_msix_irq (vm, h, 0, 2)))
{
- virtio_log_error (vim, vif,
- "error encountered on pci enable msix irq");
+ virtio_log_error (vif, "error encountered on pci enable msix irq");
goto error;
}
vif->support_int_mode = 1;
- virtio_log_debug (vim, vif, "device supports msix interrupts");
+ virtio_log_debug (vif, "device supports msix interrupts");
}
else if (vlib_pci_get_num_msix_interrupts (vm, h) == 1)
{
@@ -1136,12 +1126,12 @@ virtio_pci_create_if (vlib_main_t * vm, virtio_pci_create_if_args_t * args)
if ((error =
vlib_pci_register_intx_handler (vm, h, &virtio_pci_irq_handler)))
{
- virtio_log_error (vim, vif,
+ virtio_log_error (vif,
"error encountered on pci register interrupt handler");
goto error;
}
vif->support_int_mode = 1;
- virtio_log_debug (vim, vif, "pci register interrupt handler");
+ virtio_log_debug (vif, "pci register interrupt handler");
}
else
{
@@ -1150,23 +1140,21 @@ virtio_pci_create_if (vlib_main_t * vm, virtio_pci_create_if_args_t * args)
* Please don't use interrupt mode with UIO driver.
*/
vif->support_int_mode = 0;
- virtio_log_debug (vim, vif, "driver is configured in poll mode only");
+ virtio_log_debug (vif, "driver is configured in poll mode only");
}
if ((error = vlib_pci_intr_enable (vm, h)))
{
- virtio_log_error (vim, vif,
- "error encountered on pci interrupt enable");
+ virtio_log_error (vif, "error encountered on pci interrupt enable");
goto error;
}
if ((error = virtio_pci_device_init (vm, vif, args)))
{
- virtio_log_error (vim, vif, "error encountered on device init");
+ virtio_log_error (vif, "error encountered on device init");
goto error;
}
- vif->type = VIRTIO_IF_TYPE_PCI;
/* create interface */
error = ethernet_register_interface (vnm, virtio_device_class.index,
vif->dev_instance, vif->mac_addr,
@@ -1175,7 +1163,7 @@ virtio_pci_create_if (vlib_main_t * vm, virtio_pci_create_if_args_t * args)
if (error)
{
- virtio_log_error (vim, vif,
+ virtio_log_error (vif,
"error encountered on ethernet register interface");
goto error;
}
@@ -1213,7 +1201,7 @@ virtio_pci_create_if (vlib_main_t * vm, virtio_pci_create_if_args_t * args)
{
if (virtio_pci_enable_gso (vm, vif))
{
- virtio_log_warning (vim, vif, "gso is not enabled");
+ virtio_log_warning (vif, "gso is not enabled");
}
else
{
@@ -1225,7 +1213,7 @@ virtio_pci_create_if (vlib_main_t * vm, virtio_pci_create_if_args_t * args)
if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MQ))
{
if (virtio_pci_enable_multiqueue (vm, vif, vif->max_queue_pairs))
- virtio_log_warning (vim, vif, "multiqueue is not set");
+ virtio_log_warning (vif, "multiqueue is not set");
}
}
return;
diff --git a/src/vnet/devices/virtio/pci.h b/src/vnet/devices/virtio/pci.h
index b1e29162108..4c62885adbf 100644
--- a/src/vnet/devices/virtio/pci.h
+++ b/src/vnet/devices/virtio/pci.h
@@ -132,27 +132,6 @@ typedef enum
#define VIRTIO_PCI_VRING_ALIGN 4096
-#define virtio_log_debug(vim, vif, f, ...) \
-{ \
- vlib_log(VLIB_LOG_LEVEL_DEBUG, vim->log_default, "%U: " f, \
- format_vlib_pci_addr, &vif->pci_addr, \
- ##__VA_ARGS__); \
-};
-
-#define virtio_log_warning(vim, vif, f, ...) \
-{ \
- vlib_log(VLIB_LOG_LEVEL_WARNING, vim->log_default, "%U: " f, \
- format_vlib_pci_addr, &vif->pci_addr, \
- ##__VA_ARGS__); \
-};
-
-#define virtio_log_error(vim, vif, f, ...) \
-{ \
- vlib_log(VLIB_LOG_LEVEL_ERR, vim->log_default, "%U: " f, \
- format_vlib_pci_addr, &vif->pci_addr, \
- ##__VA_ARGS__); \
-};
-
typedef enum
{
VIRTIO_MSIX_NONE = 0,
diff --git a/src/vnet/devices/virtio/virtio.c b/src/vnet/devices/virtio/virtio.c
index 90adf97dc3c..da4f755ec10 100644
--- a/src/vnet/devices/virtio/virtio.c
+++ b/src/vnet/devices/virtio/virtio.c
@@ -474,6 +474,20 @@ virtio_show (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr, u32 type)
}
+static clib_error_t *
+virtio_init (vlib_main_t * vm)
+{
+ virtio_main_t *vim = &virtio_main;
+ clib_error_t *error = 0;
+
+ vim->log_default = vlib_log_register_class ("virtio", 0);
+ vlib_log_debug (vim->log_default, "initialized");
+
+ return error;
+}
+
+VLIB_INIT_FUNCTION (virtio_init);
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vnet/devices/virtio/virtio.h b/src/vnet/devices/virtio/virtio.h
index dcbf865d706..2cf1653d1c2 100644
--- a/src/vnet/devices/virtio/virtio.h
+++ b/src/vnet/devices/virtio/virtio.h
@@ -82,7 +82,7 @@ typedef enum
typedef enum
{
- VIRTIO_IF_TYPE_TAP,
+ VIRTIO_IF_TYPE_TAP = 1,
VIRTIO_IF_TYPE_PCI,
VIRTIO_IF_N_TYPES,
} virtio_if_type_t;
@@ -212,6 +212,7 @@ extern void virtio_show (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr,
extern void virtio_pci_legacy_notify_queue (vlib_main_t * vm,
virtio_if_t * vif, u16 queue_id);
format_function_t format_virtio_device_name;
+format_function_t format_virtio_log_name;
static_always_inline void
virtio_kick (vlib_main_t * vm, virtio_vring_t * vring, virtio_if_t * vif)
@@ -228,6 +229,28 @@ virtio_kick (vlib_main_t * vm, virtio_vring_t * vring, virtio_if_t * vif)
}
}
+
+#define virtio_log_debug(vif, f, ...) \
+{ \
+ vlib_log(VLIB_LOG_LEVEL_DEBUG, virtio_main.log_default, \
+ "%U: " f, format_virtio_log_name, vif, \
+ ##__VA_ARGS__); \
+};
+
+#define virtio_log_warning(vif, f, ...) \
+{ \
+ vlib_log(VLIB_LOG_LEVEL_WARNING, virtio_main.log_default, \
+ "%U: " f, format_virtio_log_name, vif, \
+ ##__VA_ARGS__); \
+};
+
+#define virtio_log_error(vif, f, ...) \
+{ \
+ vlib_log(VLIB_LOG_LEVEL_ERR, virtio_main.log_default, \
+ "%U: " f, format_virtio_log_name, vif, \
+ ##__VA_ARGS__); \
+};
+
#endif /* _VNET_DEVICES_VIRTIO_VIRTIO_H_ */
/*