Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * Copyright (c) 2017 Cisco and/or its affiliates. |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at: |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | *------------------------------------------------------------------ |
| 16 | */ |
| 17 | |
| 18 | #include <sys/types.h> |
| 19 | #include <sys/stat.h> |
| 20 | #include <fcntl.h> |
| 21 | #include <net/if.h> |
| 22 | #include <linux/if_tun.h> |
| 23 | #include <sys/ioctl.h> |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 24 | #include <sys/eventfd.h> |
| 25 | |
| 26 | #include <vlib/vlib.h> |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 27 | #include <vlib/pci/pci.h> |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 28 | #include <vlib/unix/unix.h> |
| 29 | #include <vnet/ethernet/ethernet.h> |
Milan Lenco | 73e7f42 | 2017-12-14 10:04:25 +0100 | [diff] [blame] | 30 | #include <vnet/ip/ip4_packet.h> |
| 31 | #include <vnet/ip/ip6_packet.h> |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 32 | #include <vnet/devices/virtio/virtio.h> |
Mohsin Kazmi | 6799f9b | 2021-04-28 18:55:45 +0200 | [diff] [blame] | 33 | #include <vnet/devices/virtio/virtio_inline.h> |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 34 | #include <vnet/devices/virtio/pci.h> |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 35 | #include <vnet/interface/rx_queue_funcs.h> |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 36 | #include <vnet/interface/tx_queue_funcs.h> |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 37 | |
| 38 | virtio_main_t virtio_main; |
| 39 | |
| 40 | #define _IOCTL(fd,a,...) \ |
| 41 | if (ioctl (fd, a, __VA_ARGS__) < 0) \ |
| 42 | { \ |
| 43 | err = clib_error_return_unix (0, "ioctl(" #a ")"); \ |
| 44 | goto error; \ |
| 45 | } |
| 46 | |
| 47 | static clib_error_t * |
| 48 | call_read_ready (clib_file_t * uf) |
| 49 | { |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 50 | vnet_main_t *vnm = vnet_get_main (); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 51 | u64 b; |
| 52 | |
| 53 | CLIB_UNUSED (ssize_t size) = read (uf->file_descriptor, &b, sizeof (b)); |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 54 | vnet_hw_if_rx_queue_set_int_pending (vnm, uf->private_data); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | |
| 60 | clib_error_t * |
| 61 | virtio_vring_init (vlib_main_t * vm, virtio_if_t * vif, u16 idx, u16 sz) |
| 62 | { |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 63 | vnet_virtio_vring_t *vring; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 64 | int i; |
| 65 | |
| 66 | if (!is_pow2 (sz)) |
| 67 | return clib_error_return (0, "ring size must be power of 2"); |
| 68 | |
| 69 | if (sz > 32768) |
| 70 | return clib_error_return (0, "ring size must be 32768 or lower"); |
| 71 | |
| 72 | if (sz == 0) |
| 73 | sz = 256; |
| 74 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 75 | if (idx % 2) |
| 76 | { |
| 77 | vec_validate_aligned (vif->txq_vrings, TX_QUEUE_ACCESS (idx), |
| 78 | CLIB_CACHE_LINE_BYTES); |
| 79 | vring = vec_elt_at_index (vif->txq_vrings, TX_QUEUE_ACCESS (idx)); |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 80 | clib_spinlock_init (&vring->lockp); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 81 | } |
| 82 | else |
| 83 | { |
| 84 | vec_validate_aligned (vif->rxq_vrings, RX_QUEUE_ACCESS (idx), |
| 85 | CLIB_CACHE_LINE_BYTES); |
| 86 | vring = vec_elt_at_index (vif->rxq_vrings, RX_QUEUE_ACCESS (idx)); |
| 87 | } |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 88 | i = sizeof (vnet_virtio_vring_desc_t) * sz; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 89 | i = round_pow2 (i, CLIB_CACHE_LINE_BYTES); |
| 90 | vring->desc = clib_mem_alloc_aligned (i, CLIB_CACHE_LINE_BYTES); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 91 | clib_memset (vring->desc, 0, i); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 92 | |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 93 | i = sizeof (vnet_virtio_vring_avail_t) + sz * sizeof (vring->avail->ring[0]); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 94 | i = round_pow2 (i, CLIB_CACHE_LINE_BYTES); |
| 95 | vring->avail = clib_mem_alloc_aligned (i, CLIB_CACHE_LINE_BYTES); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 96 | clib_memset (vring->avail, 0, i); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 97 | // tell kernel that we don't need interrupt |
Mohsin Kazmi | a7a2281 | 2020-08-31 17:17:16 +0200 | [diff] [blame] | 98 | vring->avail->flags = VRING_AVAIL_F_NO_INTERRUPT; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 99 | |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 100 | i = sizeof (vnet_virtio_vring_used_t) + |
| 101 | sz * sizeof (vnet_virtio_vring_used_elem_t); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 102 | i = round_pow2 (i, CLIB_CACHE_LINE_BYTES); |
| 103 | vring->used = clib_mem_alloc_aligned (i, CLIB_CACHE_LINE_BYTES); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 104 | clib_memset (vring->used, 0, i); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 105 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 106 | vring->queue_id = idx; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 107 | ASSERT (vring->buffers == 0); |
Damjan Marion | c58408c | 2018-01-18 14:54:04 +0100 | [diff] [blame] | 108 | vec_validate_aligned (vring->buffers, sz, CLIB_CACHE_LINE_BYTES); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 109 | |
Mohsin Kazmi | 7f6d145 | 2020-02-27 11:49:21 +0100 | [diff] [blame] | 110 | if (idx & 1) |
| 111 | { |
| 112 | clib_memset_u32 (vring->buffers, ~0, sz); |
Mohsin Kazmi | 4b56340 | 2021-01-27 14:16:56 +0000 | [diff] [blame] | 113 | // tx path: suppress the interrupts from kernel |
| 114 | vring->call_fd = -1; |
Mohsin Kazmi | 7f6d145 | 2020-02-27 11:49:21 +0100 | [diff] [blame] | 115 | } |
Mohsin Kazmi | 4b56340 | 2021-01-27 14:16:56 +0000 | [diff] [blame] | 116 | else |
| 117 | vring->call_fd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
Mohsin Kazmi | 7f6d145 | 2020-02-27 11:49:21 +0100 | [diff] [blame] | 118 | |
Mohsin Kazmi | dd0144a | 2022-09-14 11:25:54 +0000 | [diff] [blame] | 119 | vring->total_packets = 0; |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 120 | vring->queue_size = sz; |
Damjan Marion | 7c6102b | 2019-11-08 17:59:56 +0100 | [diff] [blame] | 121 | vring->kick_fd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
| 122 | virtio_log_debug (vif, "vring %u size %u call_fd %d kick_fd %d", idx, |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 123 | vring->queue_size, vring->call_fd, vring->kick_fd); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 124 | |
Damjan Marion | 7c6102b | 2019-11-08 17:59:56 +0100 | [diff] [blame] | 125 | return 0; |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 126 | } |
| 127 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 128 | inline void |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 129 | virtio_free_buffers (vlib_main_t *vm, vnet_virtio_vring_t *vring) |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 130 | { |
Steven | a624dbe | 2018-01-09 11:13:29 -0800 | [diff] [blame] | 131 | u16 used = vring->desc_in_use; |
Steven | 074f698 | 2018-03-30 22:18:11 -0700 | [diff] [blame] | 132 | u16 last = vring->last_used_idx; |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 133 | u16 mask = vring->queue_size - 1; |
Steven | a624dbe | 2018-01-09 11:13:29 -0800 | [diff] [blame] | 134 | |
| 135 | while (used) |
| 136 | { |
Steven | 074f698 | 2018-03-30 22:18:11 -0700 | [diff] [blame] | 137 | vlib_buffer_free (vm, &vring->buffers[last & mask], 1); |
| 138 | last++; |
Steven | a624dbe | 2018-01-09 11:13:29 -0800 | [diff] [blame] | 139 | used--; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | clib_error_t * |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 144 | virtio_vring_free_rx (vlib_main_t * vm, virtio_if_t * vif, u32 idx) |
Steven | a624dbe | 2018-01-09 11:13:29 -0800 | [diff] [blame] | 145 | { |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 146 | vnet_virtio_vring_t *vring = |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 147 | vec_elt_at_index (vif->rxq_vrings, RX_QUEUE_ACCESS (idx)); |
Steven | a624dbe | 2018-01-09 11:13:29 -0800 | [diff] [blame] | 148 | |
| 149 | clib_file_del_by_index (&file_main, vring->call_file_index); |
| 150 | close (vring->kick_fd); |
| 151 | close (vring->call_fd); |
| 152 | if (vring->used) |
| 153 | { |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 154 | virtio_free_buffers (vm, vring); |
Steven | a624dbe | 2018-01-09 11:13:29 -0800 | [diff] [blame] | 155 | clib_mem_free (vring->used); |
| 156 | } |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 157 | if (vring->desc) |
| 158 | clib_mem_free (vring->desc); |
| 159 | if (vring->avail) |
| 160 | clib_mem_free (vring->avail); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 161 | vec_free (vring->buffers); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | clib_error_t * |
| 166 | virtio_vring_free_tx (vlib_main_t * vm, virtio_if_t * vif, u32 idx) |
| 167 | { |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 168 | vnet_virtio_vring_t *vring = |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 169 | vec_elt_at_index (vif->txq_vrings, TX_QUEUE_ACCESS (idx)); |
| 170 | |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 171 | close (vring->kick_fd); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 172 | if (vring->used) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 173 | { |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 174 | virtio_free_buffers (vm, vring); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 175 | clib_mem_free (vring->used); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 176 | } |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 177 | if (vring->desc) |
| 178 | clib_mem_free (vring->desc); |
| 179 | if (vring->avail) |
| 180 | clib_mem_free (vring->avail); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 181 | vec_free (vring->buffers); |
Mohsin Kazmi | 9e2a785 | 2020-08-13 18:57:26 +0200 | [diff] [blame] | 182 | gro_flow_table_free (vring->flow_table); |
Mohsin Kazmi | e347acb | 2020-09-28 10:26:33 +0000 | [diff] [blame] | 183 | virtio_vring_buffering_free (vm, vring->buffering); |
Mohsin Kazmi | 3f34017 | 2019-05-27 15:53:25 +0200 | [diff] [blame] | 184 | clib_spinlock_free (&vring->lockp); |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 185 | return 0; |
| 186 | } |
| 187 | |
Mohsin Kazmi | 80659b4 | 2019-01-31 13:18:00 +0000 | [diff] [blame] | 188 | void |
Mohsin Kazmi | 9e2a785 | 2020-08-13 18:57:26 +0200 | [diff] [blame] | 189 | virtio_set_packet_coalesce (virtio_if_t * vif) |
| 190 | { |
| 191 | vnet_main_t *vnm = vnet_get_main (); |
| 192 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vif->hw_if_index); |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 193 | vnet_virtio_vring_t *vring; |
Mohsin Kazmi | 1017a1d | 2020-09-25 15:36:19 +0200 | [diff] [blame] | 194 | vif->packet_coalesce = 1; |
Mohsin Kazmi | 9e2a785 | 2020-08-13 18:57:26 +0200 | [diff] [blame] | 195 | vec_foreach (vring, vif->txq_vrings) |
| 196 | { |
| 197 | gro_flow_table_init (&vring->flow_table, |
| 198 | vif->type & (VIRTIO_IF_TYPE_TAP | |
| 199 | VIRTIO_IF_TYPE_PCI), hw->tx_node_index); |
| 200 | } |
| 201 | } |
| 202 | |
Mohsin Kazmi | e347acb | 2020-09-28 10:26:33 +0000 | [diff] [blame] | 203 | clib_error_t * |
| 204 | virtio_set_packet_buffering (virtio_if_t * vif, u16 buffering_size) |
| 205 | { |
| 206 | vnet_main_t *vnm = vnet_get_main (); |
| 207 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vif->hw_if_index); |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 208 | vnet_virtio_vring_t *vring; |
Mohsin Kazmi | e347acb | 2020-09-28 10:26:33 +0000 | [diff] [blame] | 209 | clib_error_t *error = 0; |
Mohsin Kazmi | e347acb | 2020-09-28 10:26:33 +0000 | [diff] [blame] | 210 | |
| 211 | vec_foreach (vring, vif->txq_vrings) |
| 212 | { |
| 213 | if ((error = |
| 214 | virtio_vring_buffering_init (&vring->buffering, hw->tx_node_index, |
| 215 | buffering_size))) |
| 216 | { |
| 217 | break; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | return error; |
| 222 | } |
| 223 | |
Mohsin Kazmi | 6799f9b | 2021-04-28 18:55:45 +0200 | [diff] [blame] | 224 | static void |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 225 | virtio_vring_fill (vlib_main_t *vm, virtio_if_t *vif, |
| 226 | vnet_virtio_vring_t *vring) |
Mohsin Kazmi | 6799f9b | 2021-04-28 18:55:45 +0200 | [diff] [blame] | 227 | { |
| 228 | if (vif->is_packed) |
| 229 | virtio_refill_vring_packed (vm, vif, vif->type, vring, |
| 230 | vif->virtio_net_hdr_sz, |
| 231 | virtio_input_node.index); |
| 232 | else |
| 233 | virtio_refill_vring_split (vm, vif, vif->type, vring, |
| 234 | vif->virtio_net_hdr_sz, |
| 235 | virtio_input_node.index); |
| 236 | } |
| 237 | |
Mohsin Kazmi | 9e2a785 | 2020-08-13 18:57:26 +0200 | [diff] [blame] | 238 | void |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 239 | virtio_vring_set_rx_queues (vlib_main_t *vm, virtio_if_t *vif) |
Mohsin Kazmi | 80659b4 | 2019-01-31 13:18:00 +0000 | [diff] [blame] | 240 | { |
| 241 | vnet_main_t *vnm = vnet_get_main (); |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 242 | vnet_virtio_vring_t *vring; |
Mohsin Kazmi | 90ffe06 | 2021-02-23 12:46:14 +0100 | [diff] [blame] | 243 | u32 i = 0; |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 244 | |
| 245 | vnet_hw_if_set_input_node (vnm, vif->hw_if_index, virtio_input_node.index); |
| 246 | |
| 247 | vec_foreach (vring, vif->rxq_vrings) |
| 248 | { |
| 249 | vring->queue_index = vnet_hw_if_register_rx_queue ( |
| 250 | vnm, vif->hw_if_index, RX_QUEUE_ACCESS (vring->queue_id), |
| 251 | VNET_HW_IF_RXQ_THREAD_ANY); |
| 252 | vring->buffer_pool_index = vlib_buffer_pool_get_default_for_numa ( |
| 253 | vm, vnet_hw_if_get_rx_queue_numa_node (vnm, vring->queue_index)); |
| 254 | if (vif->type == VIRTIO_IF_TYPE_TAP || vif->type == VIRTIO_IF_TYPE_TUN) |
| 255 | { |
| 256 | |
| 257 | clib_file_t f = { |
| 258 | .read_function = call_read_ready, |
| 259 | .flags = UNIX_FILE_EVENT_EDGE_TRIGGERED, |
| 260 | .file_descriptor = vring->call_fd, |
| 261 | .private_data = vring->queue_index, |
| 262 | .description = format (0, "%U vring %u", format_virtio_device_name, |
| 263 | vif->dev_instance, vring->queue_id), |
| 264 | }; |
| 265 | |
| 266 | vring->call_file_index = clib_file_add (&file_main, &f); |
| 267 | vnet_hw_if_set_rx_queue_file_index (vnm, vring->queue_index, |
| 268 | vring->call_file_index); |
| 269 | } |
Mohsin Kazmi | 90ffe06 | 2021-02-23 12:46:14 +0100 | [diff] [blame] | 270 | else if ((vif->type == VIRTIO_IF_TYPE_PCI) && (vif->support_int_mode) && |
| 271 | (vif->msix_enabled == VIRTIO_MSIX_ENABLED)) |
| 272 | { |
| 273 | u32 file_index; |
| 274 | file_index = |
| 275 | vlib_pci_get_msix_file_index (vm, vif->pci_dev_handle, i + 1); |
| 276 | vnet_hw_if_set_rx_queue_file_index (vnm, vring->queue_index, |
| 277 | file_index); |
| 278 | i++; |
| 279 | } |
Mohsin Kazmi | 6799f9b | 2021-04-28 18:55:45 +0200 | [diff] [blame] | 280 | vnet_hw_if_set_rx_queue_mode (vnm, vring->queue_index, |
| 281 | VNET_HW_IF_RX_MODE_POLLING); |
| 282 | vring->mode = VNET_HW_IF_RX_MODE_POLLING; |
| 283 | virtio_vring_fill (vm, vif, vring); |
Damjan Marion | 9410053 | 2020-11-06 23:25:57 +0100 | [diff] [blame] | 284 | } |
| 285 | vnet_hw_if_update_runtime_data (vnm, vif->hw_if_index); |
Mohsin Kazmi | 80659b4 | 2019-01-31 13:18:00 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 288 | void |
| 289 | virtio_vring_set_tx_queues (vlib_main_t *vm, virtio_if_t *vif) |
| 290 | { |
| 291 | vnet_main_t *vnm = vnet_get_main (); |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 292 | vnet_virtio_vring_t *vring; |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 293 | |
| 294 | vec_foreach (vring, vif->txq_vrings) |
| 295 | { |
| 296 | vring->queue_index = vnet_hw_if_register_tx_queue ( |
| 297 | vnm, vif->hw_if_index, TX_QUEUE_ACCESS (vring->queue_id)); |
| 298 | } |
| 299 | |
Steven Luong | c4a48f2 | 2022-01-19 09:08:27 -0800 | [diff] [blame] | 300 | if (vif->num_txqs == 0) |
| 301 | { |
| 302 | virtio_log_error (vif, "Interface %U has 0 txq", |
| 303 | format_vnet_hw_if_index_name, vnm, vif->hw_if_index); |
| 304 | return; |
| 305 | } |
| 306 | |
Mohsin Kazmi | b7e4e6d | 2021-12-13 18:32:42 +0000 | [diff] [blame] | 307 | for (u32 j = 0; j < vlib_get_n_threads (); j++) |
| 308 | { |
| 309 | u32 qi = vif->txq_vrings[j % vif->num_txqs].queue_index; |
| 310 | vnet_hw_if_tx_queue_assign_thread (vnm, qi, j); |
| 311 | } |
| 312 | |
| 313 | vnet_hw_if_update_runtime_data (vnm, vif->hw_if_index); |
| 314 | } |
| 315 | |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 316 | inline void |
| 317 | virtio_set_net_hdr_size (virtio_if_t * vif) |
| 318 | { |
| 319 | if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MRG_RXBUF) || |
| 320 | vif->features & VIRTIO_FEATURE (VIRTIO_F_VERSION_1)) |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 321 | vif->virtio_net_hdr_sz = sizeof (vnet_virtio_net_hdr_v1_t); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 322 | else |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 323 | vif->virtio_net_hdr_sz = sizeof (vnet_virtio_net_hdr_t); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | inline void |
Mohsin Kazmi | e4efbe7 | 2021-09-22 18:56:05 +0000 | [diff] [blame] | 327 | virtio_show (vlib_main_t *vm, u32 *hw_if_indices, u8 show_descr, |
| 328 | virtio_if_type_t type) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 329 | { |
| 330 | u32 i, j, hw_if_index; |
| 331 | virtio_if_t *vif; |
| 332 | vnet_main_t *vnm = &vnet_main; |
| 333 | virtio_main_t *mm = &virtio_main; |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 334 | vnet_virtio_vring_t *vring; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 335 | struct feat_struct |
| 336 | { |
| 337 | u8 bit; |
| 338 | char *str; |
| 339 | }; |
| 340 | struct feat_struct *feat_entry; |
| 341 | |
| 342 | static struct feat_struct feat_array[] = { |
| 343 | #define _(s,b) { .str = #s, .bit = b, }, |
| 344 | foreach_virtio_net_features |
| 345 | #undef _ |
| 346 | {.str = NULL} |
| 347 | }; |
| 348 | |
| 349 | struct feat_struct *flag_entry; |
| 350 | static struct feat_struct flags_array[] = { |
| 351 | #define _(b,e,s) { .bit = b, .str = s, }, |
| 352 | foreach_virtio_if_flag |
| 353 | #undef _ |
| 354 | {.str = NULL} |
| 355 | }; |
| 356 | |
| 357 | if (!hw_if_indices) |
| 358 | return; |
| 359 | |
| 360 | for (hw_if_index = 0; hw_if_index < vec_len (hw_if_indices); hw_if_index++) |
| 361 | { |
| 362 | vnet_hw_interface_t *hi = |
| 363 | vnet_get_hw_interface (vnm, hw_if_indices[hw_if_index]); |
| 364 | vif = pool_elt_at_index (mm->interfaces, hi->dev_instance); |
| 365 | if (vif->type != type) |
| 366 | continue; |
| 367 | vlib_cli_output (vm, "Interface: %U (ifindex %d)", |
| 368 | format_vnet_hw_if_index_name, vnm, |
| 369 | hw_if_indices[hw_if_index], vif->hw_if_index); |
| 370 | if (type == VIRTIO_IF_TYPE_PCI) |
| 371 | { |
| 372 | vlib_cli_output (vm, " PCI Address: %U", format_vlib_pci_addr, |
| 373 | &vif->pci_addr); |
| 374 | } |
Mohsin Kazmi | 206acf8 | 2020-04-06 14:19:54 +0200 | [diff] [blame] | 375 | if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_TUN)) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 376 | { |
Damjan Marion | 7c6102b | 2019-11-08 17:59:56 +0100 | [diff] [blame] | 377 | u8 *str = 0; |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 378 | if (vif->host_if_name) |
| 379 | vlib_cli_output (vm, " name \"%s\"", vif->host_if_name); |
| 380 | if (vif->net_ns) |
| 381 | vlib_cli_output (vm, " host-ns \"%s\"", vif->net_ns); |
Mohsin Kazmi | 97d54ed | 2019-06-10 11:20:15 +0200 | [diff] [blame] | 382 | if (vif->host_mtu_size) |
| 383 | vlib_cli_output (vm, " host-mtu-size \"%d\"", |
| 384 | vif->host_mtu_size); |
Mohsin Kazmi | 206acf8 | 2020-04-06 14:19:54 +0200 | [diff] [blame] | 385 | if (type == VIRTIO_IF_TYPE_TAP) |
| 386 | vlib_cli_output (vm, " host-mac-addr: %U", |
| 387 | format_ethernet_address, vif->host_mac_addr); |
Matthew Smith | bd50ed1 | 2020-07-24 13:38:03 -0500 | [diff] [blame] | 388 | vlib_cli_output (vm, " host-carrier-up: %u", vif->host_carrier_up); |
Damjan Marion | 7c6102b | 2019-11-08 17:59:56 +0100 | [diff] [blame] | 389 | |
| 390 | vec_foreach_index (i, vif->vhost_fds) |
| 391 | str = format (str, " %d", vif->vhost_fds[i]); |
| 392 | vlib_cli_output (vm, " vhost-fds%v", str); |
| 393 | vec_free (str); |
Aloys Augustin | 2857e78 | 2020-03-16 17:29:52 +0100 | [diff] [blame] | 394 | vec_foreach_index (i, vif->tap_fds) |
| 395 | str = format (str, " %d", vif->tap_fds[i]); |
| 396 | vlib_cli_output (vm, " tap-fds%v", str); |
| 397 | vec_free (str); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 398 | } |
Chenmin Sun | 7c615ae | 2019-07-18 23:19:28 +0800 | [diff] [blame] | 399 | vlib_cli_output (vm, " gso-enabled %d", vif->gso_enabled); |
Mohsin Kazmi | ba0061f | 2019-12-18 17:08:54 +0100 | [diff] [blame] | 400 | vlib_cli_output (vm, " csum-enabled %d", vif->csum_offload_enabled); |
Mohsin Kazmi | 9e2a785 | 2020-08-13 18:57:26 +0200 | [diff] [blame] | 401 | vlib_cli_output (vm, " packet-coalesce %d", vif->packet_coalesce); |
Mohsin Kazmi | e347acb | 2020-09-28 10:26:33 +0000 | [diff] [blame] | 402 | vlib_cli_output (vm, " packet-buffering %d", vif->packet_buffering); |
Mohsin Kazmi | 206acf8 | 2020-04-06 14:19:54 +0200 | [diff] [blame] | 403 | if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_PCI)) |
| 404 | vlib_cli_output (vm, " Mac Address: %U", format_ethernet_address, |
| 405 | vif->mac_addr); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 406 | vlib_cli_output (vm, " Device instance: %u", vif->dev_instance); |
| 407 | vlib_cli_output (vm, " flags 0x%x", vif->flags); |
| 408 | flag_entry = (struct feat_struct *) &flags_array; |
| 409 | while (flag_entry->str) |
| 410 | { |
| 411 | if (vif->flags & (1ULL << flag_entry->bit)) |
| 412 | vlib_cli_output (vm, " %s (%d)", flag_entry->str, |
| 413 | flag_entry->bit); |
| 414 | flag_entry++; |
| 415 | } |
| 416 | if (type == VIRTIO_IF_TYPE_PCI) |
| 417 | { |
| 418 | device_status (vm, vif); |
| 419 | } |
| 420 | vlib_cli_output (vm, " features 0x%lx", vif->features); |
| 421 | feat_entry = (struct feat_struct *) &feat_array; |
| 422 | while (feat_entry->str) |
| 423 | { |
| 424 | if (vif->features & (1ULL << feat_entry->bit)) |
| 425 | vlib_cli_output (vm, " %s (%d)", feat_entry->str, |
| 426 | feat_entry->bit); |
| 427 | feat_entry++; |
| 428 | } |
| 429 | vlib_cli_output (vm, " remote-features 0x%lx", vif->remote_features); |
| 430 | feat_entry = (struct feat_struct *) &feat_array; |
| 431 | while (feat_entry->str) |
| 432 | { |
| 433 | if (vif->remote_features & (1ULL << feat_entry->bit)) |
| 434 | vlib_cli_output (vm, " %s (%d)", feat_entry->str, |
| 435 | feat_entry->bit); |
| 436 | feat_entry++; |
| 437 | } |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 438 | vlib_cli_output (vm, " Number of RX Virtqueue %u", vif->num_rxqs); |
| 439 | vlib_cli_output (vm, " Number of TX Virtqueue %u", vif->num_txqs); |
Mohsin Kazmi | e4efbe7 | 2021-09-22 18:56:05 +0000 | [diff] [blame] | 440 | if (type == VIRTIO_IF_TYPE_PCI && vif->cxq_vring != NULL && |
| 441 | vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ)) |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 442 | vlib_cli_output (vm, " Number of CTRL Virtqueue 1"); |
| 443 | vec_foreach_index (i, vif->rxq_vrings) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 444 | { |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 445 | vring = vec_elt_at_index (vif->rxq_vrings, i); |
| 446 | vlib_cli_output (vm, " Virtqueue (RX) %d", vring->queue_id); |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 447 | vlib_cli_output ( |
| 448 | vm, " qsz %d, last_used_idx %d, desc_next %d, desc_in_use %d", |
| 449 | vring->queue_size, vring->last_used_idx, vring->desc_next, |
| 450 | vring->desc_in_use); |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 451 | if (vif->is_packed) |
| 452 | { |
| 453 | vlib_cli_output (vm, |
| 454 | " driver_event.flags 0x%x driver_event.off_wrap %d device_event.flags 0x%x device_event.off_wrap %d", |
| 455 | vring->driver_event->flags, |
| 456 | vring->driver_event->off_wrap, |
| 457 | vring->device_event->flags, |
| 458 | vring->device_event->off_wrap); |
| 459 | vlib_cli_output (vm, |
| 460 | " avail wrap counter %d, used wrap counter %d", |
| 461 | vring->avail_wrap_counter, |
| 462 | vring->used_wrap_counter); |
| 463 | } |
| 464 | else |
| 465 | vlib_cli_output (vm, |
| 466 | " avail.flags 0x%x avail.idx %d used.flags 0x%x used.idx %d", |
| 467 | vring->avail->flags, vring->avail->idx, |
| 468 | vring->used->flags, vring->used->idx); |
Mohsin Kazmi | 206acf8 | 2020-04-06 14:19:54 +0200 | [diff] [blame] | 469 | if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_TUN)) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 470 | { |
| 471 | vlib_cli_output (vm, " kickfd %d, callfd %d", vring->kick_fd, |
| 472 | vring->call_fd); |
| 473 | } |
| 474 | if (show_descr) |
| 475 | { |
| 476 | vlib_cli_output (vm, "\n descriptor table:\n"); |
| 477 | vlib_cli_output (vm, |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 478 | " id addr len flags next/id user_addr\n"); |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 479 | vlib_cli_output (vm, |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 480 | " ===== ================== ===== ====== ======= ==================\n"); |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 481 | for (j = 0; j < vring->queue_size; j++) |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 482 | { |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 483 | if (vif->is_packed) |
| 484 | { |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 485 | vnet_virtio_vring_packed_desc_t *desc = |
| 486 | &vring->packed_desc[j]; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 487 | vlib_cli_output (vm, |
| 488 | " %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n", |
| 489 | j, desc->addr, |
| 490 | desc->len, |
| 491 | desc->flags, desc->id, desc->addr); |
| 492 | } |
| 493 | else |
| 494 | { |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 495 | vnet_virtio_vring_desc_t *desc = &vring->desc[j]; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 496 | vlib_cli_output (vm, |
| 497 | " %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n", |
| 498 | j, desc->addr, |
| 499 | desc->len, |
| 500 | desc->flags, desc->next, desc->addr); |
| 501 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | } |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 505 | vec_foreach_index (i, vif->txq_vrings) |
| 506 | { |
| 507 | vring = vec_elt_at_index (vif->txq_vrings, i); |
| 508 | vlib_cli_output (vm, " Virtqueue (TX) %d", vring->queue_id); |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 509 | vlib_cli_output ( |
| 510 | vm, " qsz %d, last_used_idx %d, desc_next %d, desc_in_use %d", |
| 511 | vring->queue_size, vring->last_used_idx, vring->desc_next, |
| 512 | vring->desc_in_use); |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 513 | if (vif->is_packed) |
| 514 | { |
| 515 | vlib_cli_output (vm, |
| 516 | " driver_event.flags 0x%x driver_event.off_wrap %d device_event.flags 0x%x device_event.off_wrap %d", |
| 517 | vring->driver_event->flags, |
| 518 | vring->driver_event->off_wrap, |
| 519 | vring->device_event->flags, |
| 520 | vring->device_event->off_wrap); |
| 521 | vlib_cli_output (vm, |
| 522 | " avail wrap counter %d, used wrap counter %d", |
| 523 | vring->avail_wrap_counter, |
| 524 | vring->used_wrap_counter); |
| 525 | } |
| 526 | else |
| 527 | vlib_cli_output (vm, |
| 528 | " avail.flags 0x%x avail.idx %d used.flags 0x%x used.idx %d", |
| 529 | vring->avail->flags, vring->avail->idx, |
| 530 | vring->used->flags, vring->used->idx); |
Mohsin Kazmi | 206acf8 | 2020-04-06 14:19:54 +0200 | [diff] [blame] | 531 | if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_TUN)) |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 532 | { |
| 533 | vlib_cli_output (vm, " kickfd %d, callfd %d", vring->kick_fd, |
| 534 | vring->call_fd); |
| 535 | } |
Mohsin Kazmi | 9e2a785 | 2020-08-13 18:57:26 +0200 | [diff] [blame] | 536 | if (vring->flow_table) |
| 537 | { |
| 538 | vlib_cli_output (vm, " %U", gro_flow_table_format, |
| 539 | vring->flow_table); |
| 540 | } |
Mohsin Kazmi | e347acb | 2020-09-28 10:26:33 +0000 | [diff] [blame] | 541 | if (vif->packet_buffering) |
| 542 | { |
| 543 | vlib_cli_output (vm, " %U", virtio_vring_buffering_format, |
| 544 | vring->buffering); |
| 545 | } |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 546 | if (show_descr) |
| 547 | { |
| 548 | vlib_cli_output (vm, "\n descriptor table:\n"); |
| 549 | vlib_cli_output (vm, |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 550 | " id addr len flags next/id user_addr\n"); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 551 | vlib_cli_output (vm, |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 552 | " ===== ================== ===== ====== ======== ==================\n"); |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 553 | for (j = 0; j < vring->queue_size; j++) |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 554 | { |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 555 | if (vif->is_packed) |
| 556 | { |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 557 | vnet_virtio_vring_packed_desc_t *desc = |
| 558 | &vring->packed_desc[j]; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 559 | vlib_cli_output (vm, |
| 560 | " %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n", |
| 561 | j, desc->addr, |
| 562 | desc->len, |
| 563 | desc->flags, desc->id, desc->addr); |
| 564 | } |
| 565 | else |
| 566 | { |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 567 | vnet_virtio_vring_desc_t *desc = &vring->desc[j]; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 568 | vlib_cli_output (vm, |
| 569 | " %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n", |
| 570 | j, desc->addr, |
| 571 | desc->len, |
| 572 | desc->flags, desc->next, desc->addr); |
| 573 | } |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | } |
Mohsin Kazmi | e4efbe7 | 2021-09-22 18:56:05 +0000 | [diff] [blame] | 577 | if (type == VIRTIO_IF_TYPE_PCI && vif->cxq_vring != NULL && |
| 578 | vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ)) |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 579 | { |
| 580 | vring = vif->cxq_vring; |
| 581 | vlib_cli_output (vm, " Virtqueue (CTRL) %d", vring->queue_id); |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 582 | vlib_cli_output ( |
| 583 | vm, " qsz %d, last_used_idx %d, desc_next %d, desc_in_use %d", |
| 584 | vring->queue_size, vring->last_used_idx, vring->desc_next, |
| 585 | vring->desc_in_use); |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 586 | if (vif->is_packed) |
| 587 | { |
| 588 | vlib_cli_output (vm, |
| 589 | " driver_event.flags 0x%x driver_event.off_wrap %d device_event.flags 0x%x device_event.off_wrap %d", |
| 590 | vring->driver_event->flags, |
| 591 | vring->driver_event->off_wrap, |
| 592 | vring->device_event->flags, |
| 593 | vring->device_event->off_wrap); |
| 594 | vlib_cli_output (vm, |
| 595 | " avail wrap counter %d, used wrap counter %d", |
| 596 | vring->avail_wrap_counter, |
| 597 | vring->used_wrap_counter); |
| 598 | } |
| 599 | else |
| 600 | { |
| 601 | vlib_cli_output (vm, |
| 602 | " avail.flags 0x%x avail.idx %d used.flags 0x%x used.idx %d", |
| 603 | vring->avail->flags, vring->avail->idx, |
| 604 | vring->used->flags, vring->used->idx); |
| 605 | } |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 606 | if (show_descr) |
| 607 | { |
| 608 | vlib_cli_output (vm, "\n descriptor table:\n"); |
| 609 | vlib_cli_output (vm, |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 610 | " id addr len flags next/id user_addr\n"); |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 611 | vlib_cli_output (vm, |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 612 | " ===== ================== ===== ====== ======== ==================\n"); |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 613 | for (j = 0; j < vring->queue_size; j++) |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 614 | { |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 615 | if (vif->is_packed) |
| 616 | { |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 617 | vnet_virtio_vring_packed_desc_t *desc = |
| 618 | &vring->packed_desc[j]; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 619 | vlib_cli_output (vm, |
| 620 | " %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n", |
| 621 | j, desc->addr, |
| 622 | desc->len, |
| 623 | desc->flags, desc->id, desc->addr); |
| 624 | } |
| 625 | else |
| 626 | { |
Mohsin Kazmi | 0f8912f | 2022-02-01 18:35:59 +0000 | [diff] [blame] | 627 | vnet_virtio_vring_desc_t *desc = &vring->desc[j]; |
Mohsin Kazmi | b977d3f | 2020-11-16 16:49:30 +0100 | [diff] [blame] | 628 | vlib_cli_output (vm, |
| 629 | " %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n", |
| 630 | j, desc->addr, |
| 631 | desc->len, |
| 632 | desc->flags, desc->next, desc->addr); |
| 633 | } |
Mohsin Kazmi | 09a3bc5 | 2019-04-02 11:45:08 +0000 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | } |
Mohsin Kazmi | d6c15af | 2018-10-23 18:00:47 +0200 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | } |
| 640 | |
Damjan Marion | f41244f | 2019-11-08 17:41:06 +0100 | [diff] [blame] | 641 | static clib_error_t * |
| 642 | virtio_init (vlib_main_t * vm) |
| 643 | { |
| 644 | virtio_main_t *vim = &virtio_main; |
| 645 | clib_error_t *error = 0; |
| 646 | |
| 647 | vim->log_default = vlib_log_register_class ("virtio", 0); |
| 648 | vlib_log_debug (vim->log_default, "initialized"); |
| 649 | |
| 650 | return error; |
| 651 | } |
| 652 | |
| 653 | VLIB_INIT_FUNCTION (virtio_init); |
| 654 | |
Damjan Marion | 8389fb9 | 2017-10-13 18:29:53 +0200 | [diff] [blame] | 655 | /* |
| 656 | * fd.io coding-style-patch-verification: ON |
| 657 | * |
| 658 | * Local Variables: |
| 659 | * eval: (c-set-style "gnu") |
| 660 | * End: |
| 661 | */ |