blob: 99f581a1f1b318ffb5a0ab4f06bd0ca3046bac08 [file] [log] [blame]
Damjan Marion8389fb92017-10-13 18:29:53 +02001/*
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 Marion8389fb92017-10-13 18:29:53 +020024#include <sys/eventfd.h>
25
26#include <vlib/vlib.h>
Mohsin Kazmid6c15af2018-10-23 18:00:47 +020027#include <vlib/pci/pci.h>
Damjan Marion8389fb92017-10-13 18:29:53 +020028#include <vlib/unix/unix.h>
29#include <vnet/ethernet/ethernet.h>
Milan Lenco73e7f422017-12-14 10:04:25 +010030#include <vnet/ip/ip4_packet.h>
31#include <vnet/ip/ip6_packet.h>
Damjan Marion8389fb92017-10-13 18:29:53 +020032#include <vnet/devices/virtio/virtio.h>
Mohsin Kazmid6c15af2018-10-23 18:00:47 +020033#include <vnet/devices/virtio/pci.h>
Damjan Marion8389fb92017-10-13 18:29:53 +020034
35virtio_main_t virtio_main;
36
37#define _IOCTL(fd,a,...) \
38 if (ioctl (fd, a, __VA_ARGS__) < 0) \
39 { \
40 err = clib_error_return_unix (0, "ioctl(" #a ")"); \
41 goto error; \
42 }
43
44static clib_error_t *
45call_read_ready (clib_file_t * uf)
46{
47 virtio_main_t *nm = &virtio_main;
48 vnet_main_t *vnm = vnet_get_main ();
49 u16 qid = uf->private_data & 0xFFFF;
50 virtio_if_t *vif =
51 vec_elt_at_index (nm->interfaces, uf->private_data >> 16);
52 u64 b;
53
54 CLIB_UNUSED (ssize_t size) = read (uf->file_descriptor, &b, sizeof (b));
55 if ((qid & 1) == 0)
Mohsin Kazmi04f4d912020-05-26 14:34:34 +020056 vnet_device_input_set_interrupt_pending (vnm, vif->hw_if_index,
57 RX_QUEUE_ACCESS (qid));
Damjan Marion8389fb92017-10-13 18:29:53 +020058
59 return 0;
60}
61
62
63clib_error_t *
64virtio_vring_init (vlib_main_t * vm, virtio_if_t * vif, u16 idx, u16 sz)
65{
Damjan Marion8389fb92017-10-13 18:29:53 +020066 virtio_vring_t *vring;
Damjan Marion8389fb92017-10-13 18:29:53 +020067 clib_file_t t = { 0 };
68 int i;
69
70 if (!is_pow2 (sz))
71 return clib_error_return (0, "ring size must be power of 2");
72
73 if (sz > 32768)
74 return clib_error_return (0, "ring size must be 32768 or lower");
75
76 if (sz == 0)
77 sz = 256;
78
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +000079 if (idx % 2)
80 {
Mohsin Kazmi3f340172019-05-27 15:53:25 +020081 vlib_thread_main_t *thm = vlib_get_thread_main ();
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +000082 vec_validate_aligned (vif->txq_vrings, TX_QUEUE_ACCESS (idx),
83 CLIB_CACHE_LINE_BYTES);
84 vring = vec_elt_at_index (vif->txq_vrings, TX_QUEUE_ACCESS (idx));
Damjan Marion7c6102b2019-11-08 17:59:56 +010085 if (thm->n_vlib_mains > vif->num_txqs)
Mohsin Kazmi3f340172019-05-27 15:53:25 +020086 clib_spinlock_init (&vring->lockp);
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +000087 }
88 else
89 {
90 vec_validate_aligned (vif->rxq_vrings, RX_QUEUE_ACCESS (idx),
91 CLIB_CACHE_LINE_BYTES);
92 vring = vec_elt_at_index (vif->rxq_vrings, RX_QUEUE_ACCESS (idx));
93 }
Mohsin Kazmia7a22812020-08-31 17:17:16 +020094 i = sizeof (vring_desc_t) * sz;
Damjan Marion8389fb92017-10-13 18:29:53 +020095 i = round_pow2 (i, CLIB_CACHE_LINE_BYTES);
96 vring->desc = clib_mem_alloc_aligned (i, CLIB_CACHE_LINE_BYTES);
Dave Barachb7b92992018-10-17 10:38:51 -040097 clib_memset (vring->desc, 0, i);
Damjan Marion8389fb92017-10-13 18:29:53 +020098
Mohsin Kazmia7a22812020-08-31 17:17:16 +020099 i = sizeof (vring_avail_t) + sz * sizeof (vring->avail->ring[0]);
Damjan Marion8389fb92017-10-13 18:29:53 +0200100 i = round_pow2 (i, CLIB_CACHE_LINE_BYTES);
101 vring->avail = clib_mem_alloc_aligned (i, CLIB_CACHE_LINE_BYTES);
Dave Barachb7b92992018-10-17 10:38:51 -0400102 clib_memset (vring->avail, 0, i);
Damjan Marion8389fb92017-10-13 18:29:53 +0200103 // tell kernel that we don't need interrupt
Mohsin Kazmia7a22812020-08-31 17:17:16 +0200104 vring->avail->flags = VRING_AVAIL_F_NO_INTERRUPT;
Damjan Marion8389fb92017-10-13 18:29:53 +0200105
Mohsin Kazmia7a22812020-08-31 17:17:16 +0200106 i = sizeof (vring_used_t) + sz * sizeof (vring_used_elem_t);
Damjan Marion8389fb92017-10-13 18:29:53 +0200107 i = round_pow2 (i, CLIB_CACHE_LINE_BYTES);
108 vring->used = clib_mem_alloc_aligned (i, CLIB_CACHE_LINE_BYTES);
Dave Barachb7b92992018-10-17 10:38:51 -0400109 clib_memset (vring->used, 0, i);
Damjan Marion8389fb92017-10-13 18:29:53 +0200110
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000111 vring->queue_id = idx;
Damjan Marion8389fb92017-10-13 18:29:53 +0200112 ASSERT (vring->buffers == 0);
Damjan Marionc58408c2018-01-18 14:54:04 +0100113 vec_validate_aligned (vring->buffers, sz, CLIB_CACHE_LINE_BYTES);
Damjan Marion8389fb92017-10-13 18:29:53 +0200114
Mohsin Kazmi7f6d1452020-02-27 11:49:21 +0100115 if (idx & 1)
116 {
117 clib_memset_u32 (vring->buffers, ~0, sz);
118 }
119
Damjan Marion8389fb92017-10-13 18:29:53 +0200120 vring->size = sz;
121 vring->call_fd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC);
Damjan Marion7c6102b2019-11-08 17:59:56 +0100122 vring->kick_fd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC);
123 virtio_log_debug (vif, "vring %u size %u call_fd %d kick_fd %d", idx,
124 vring->size, vring->call_fd, vring->kick_fd);
Damjan Marion8389fb92017-10-13 18:29:53 +0200125
126 t.read_function = call_read_ready;
127 t.file_descriptor = vring->call_fd;
128 t.private_data = vif->dev_instance << 16 | idx;
Damjan Marionceab7882018-01-19 20:56:12 +0100129 t.description = format (0, "%U vring %u", format_virtio_device_name,
130 vif->dev_instance, idx);
Damjan Marion8389fb92017-10-13 18:29:53 +0200131 vring->call_file_index = clib_file_add (&file_main, &t);
132
Damjan Marion7c6102b2019-11-08 17:59:56 +0100133 return 0;
Damjan Marion8389fb92017-10-13 18:29:53 +0200134}
135
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200136inline void
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100137virtio_free_buffers (vlib_main_t * vm, virtio_vring_t * vring)
Damjan Marion8389fb92017-10-13 18:29:53 +0200138{
Stevena624dbe2018-01-09 11:13:29 -0800139 u16 used = vring->desc_in_use;
Steven074f6982018-03-30 22:18:11 -0700140 u16 last = vring->last_used_idx;
Stevena624dbe2018-01-09 11:13:29 -0800141 u16 mask = vring->size - 1;
142
143 while (used)
144 {
Steven074f6982018-03-30 22:18:11 -0700145 vlib_buffer_free (vm, &vring->buffers[last & mask], 1);
146 last++;
Stevena624dbe2018-01-09 11:13:29 -0800147 used--;
148 }
149}
150
151clib_error_t *
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000152virtio_vring_free_rx (vlib_main_t * vm, virtio_if_t * vif, u32 idx)
Stevena624dbe2018-01-09 11:13:29 -0800153{
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000154 virtio_vring_t *vring =
155 vec_elt_at_index (vif->rxq_vrings, RX_QUEUE_ACCESS (idx));
Stevena624dbe2018-01-09 11:13:29 -0800156
157 clib_file_del_by_index (&file_main, vring->call_file_index);
158 close (vring->kick_fd);
159 close (vring->call_fd);
160 if (vring->used)
161 {
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100162 virtio_free_buffers (vm, vring);
Stevena624dbe2018-01-09 11:13:29 -0800163 clib_mem_free (vring->used);
164 }
Damjan Marion8389fb92017-10-13 18:29:53 +0200165 if (vring->desc)
166 clib_mem_free (vring->desc);
167 if (vring->avail)
168 clib_mem_free (vring->avail);
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000169 vec_free (vring->buffers);
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000170 return 0;
171}
172
173clib_error_t *
174virtio_vring_free_tx (vlib_main_t * vm, virtio_if_t * vif, u32 idx)
175{
176 virtio_vring_t *vring =
177 vec_elt_at_index (vif->txq_vrings, TX_QUEUE_ACCESS (idx));
178
179 clib_file_del_by_index (&file_main, vring->call_file_index);
180 close (vring->kick_fd);
181 close (vring->call_fd);
182 if (vring->used)
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200183 {
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100184 virtio_free_buffers (vm, vring);
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000185 clib_mem_free (vring->used);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200186 }
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000187 if (vring->desc)
188 clib_mem_free (vring->desc);
189 if (vring->avail)
190 clib_mem_free (vring->avail);
Damjan Marion8389fb92017-10-13 18:29:53 +0200191 vec_free (vring->buffers);
Mohsin Kazmi9e2a7852020-08-13 18:57:26 +0200192 gro_flow_table_free (vring->flow_table);
Mohsin Kazmie347acb2020-09-28 10:26:33 +0000193 virtio_vring_buffering_free (vm, vring->buffering);
Mohsin Kazmi3f340172019-05-27 15:53:25 +0200194 clib_spinlock_free (&vring->lockp);
Damjan Marion8389fb92017-10-13 18:29:53 +0200195 return 0;
196}
197
Mohsin Kazmi80659b42019-01-31 13:18:00 +0000198void
Mohsin Kazmi9e2a7852020-08-13 18:57:26 +0200199virtio_set_packet_coalesce (virtio_if_t * vif)
200{
201 vnet_main_t *vnm = vnet_get_main ();
202 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vif->hw_if_index);
203 virtio_vring_t *vring;
Mohsin Kazmi1017a1d2020-09-25 15:36:19 +0200204 vif->packet_coalesce = 1;
Mohsin Kazmi9e2a7852020-08-13 18:57:26 +0200205 vec_foreach (vring, vif->txq_vrings)
206 {
207 gro_flow_table_init (&vring->flow_table,
208 vif->type & (VIRTIO_IF_TYPE_TAP |
209 VIRTIO_IF_TYPE_PCI), hw->tx_node_index);
210 }
211}
212
Mohsin Kazmie347acb2020-09-28 10:26:33 +0000213clib_error_t *
214virtio_set_packet_buffering (virtio_if_t * vif, u16 buffering_size)
215{
216 vnet_main_t *vnm = vnet_get_main ();
217 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vif->hw_if_index);
218 virtio_vring_t *vring;
219 clib_error_t *error = 0;
220 vif->packet_buffering = 1;
221
222 vec_foreach (vring, vif->txq_vrings)
223 {
224 if ((error =
225 virtio_vring_buffering_init (&vring->buffering, hw->tx_node_index,
226 buffering_size)))
227 {
228 break;
229 }
230 }
231
232 return error;
233}
234
Mohsin Kazmi9e2a7852020-08-13 18:57:26 +0200235void
Mohsin Kazmi80659b42019-01-31 13:18:00 +0000236virtio_vring_set_numa_node (vlib_main_t * vm, virtio_if_t * vif, u32 idx)
237{
238 vnet_main_t *vnm = vnet_get_main ();
239 u32 thread_index;
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000240 virtio_vring_t *vring =
241 vec_elt_at_index (vif->rxq_vrings, RX_QUEUE_ACCESS (idx));
Mohsin Kazmi80659b42019-01-31 13:18:00 +0000242 thread_index =
243 vnet_get_device_input_thread_index (vnm, vif->hw_if_index,
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000244 RX_QUEUE_ACCESS (idx));
Mohsin Kazmi80659b42019-01-31 13:18:00 +0000245 vring->buffer_pool_index =
246 vlib_buffer_pool_get_default_for_numa (vm,
247 vlib_mains
248 [thread_index]->numa_node);
249}
250
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200251inline void
252virtio_set_net_hdr_size (virtio_if_t * vif)
253{
254 if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MRG_RXBUF) ||
255 vif->features & VIRTIO_FEATURE (VIRTIO_F_VERSION_1))
Mohsin Kazmia7a22812020-08-31 17:17:16 +0200256 vif->virtio_net_hdr_sz = sizeof (virtio_net_hdr_v1_t);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200257 else
Mohsin Kazmia7a22812020-08-31 17:17:16 +0200258 vif->virtio_net_hdr_sz = sizeof (virtio_net_hdr_t);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200259}
260
261inline void
262virtio_show (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr, u32 type)
263{
264 u32 i, j, hw_if_index;
265 virtio_if_t *vif;
266 vnet_main_t *vnm = &vnet_main;
267 virtio_main_t *mm = &virtio_main;
268 virtio_vring_t *vring;
269 struct feat_struct
270 {
271 u8 bit;
272 char *str;
273 };
274 struct feat_struct *feat_entry;
275
276 static struct feat_struct feat_array[] = {
277#define _(s,b) { .str = #s, .bit = b, },
278 foreach_virtio_net_features
279#undef _
280 {.str = NULL}
281 };
282
283 struct feat_struct *flag_entry;
284 static struct feat_struct flags_array[] = {
285#define _(b,e,s) { .bit = b, .str = s, },
286 foreach_virtio_if_flag
287#undef _
288 {.str = NULL}
289 };
290
291 if (!hw_if_indices)
292 return;
293
294 for (hw_if_index = 0; hw_if_index < vec_len (hw_if_indices); hw_if_index++)
295 {
296 vnet_hw_interface_t *hi =
297 vnet_get_hw_interface (vnm, hw_if_indices[hw_if_index]);
298 vif = pool_elt_at_index (mm->interfaces, hi->dev_instance);
299 if (vif->type != type)
300 continue;
301 vlib_cli_output (vm, "Interface: %U (ifindex %d)",
302 format_vnet_hw_if_index_name, vnm,
303 hw_if_indices[hw_if_index], vif->hw_if_index);
304 if (type == VIRTIO_IF_TYPE_PCI)
305 {
306 vlib_cli_output (vm, " PCI Address: %U", format_vlib_pci_addr,
307 &vif->pci_addr);
308 }
Mohsin Kazmi206acf82020-04-06 14:19:54 +0200309 if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_TUN))
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200310 {
Damjan Marion7c6102b2019-11-08 17:59:56 +0100311 u8 *str = 0;
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200312 if (vif->host_if_name)
313 vlib_cli_output (vm, " name \"%s\"", vif->host_if_name);
314 if (vif->net_ns)
315 vlib_cli_output (vm, " host-ns \"%s\"", vif->net_ns);
Mohsin Kazmi97d54ed2019-06-10 11:20:15 +0200316 if (vif->host_mtu_size)
317 vlib_cli_output (vm, " host-mtu-size \"%d\"",
318 vif->host_mtu_size);
Mohsin Kazmi206acf82020-04-06 14:19:54 +0200319 if (type == VIRTIO_IF_TYPE_TAP)
320 vlib_cli_output (vm, " host-mac-addr: %U",
321 format_ethernet_address, vif->host_mac_addr);
Matthew Smithbd50ed12020-07-24 13:38:03 -0500322 vlib_cli_output (vm, " host-carrier-up: %u", vif->host_carrier_up);
Damjan Marion7c6102b2019-11-08 17:59:56 +0100323
324 vec_foreach_index (i, vif->vhost_fds)
325 str = format (str, " %d", vif->vhost_fds[i]);
326 vlib_cli_output (vm, " vhost-fds%v", str);
327 vec_free (str);
Aloys Augustin2857e782020-03-16 17:29:52 +0100328 vec_foreach_index (i, vif->tap_fds)
329 str = format (str, " %d", vif->tap_fds[i]);
330 vlib_cli_output (vm, " tap-fds%v", str);
331 vec_free (str);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200332 }
Chenmin Sun7c615ae2019-07-18 23:19:28 +0800333 vlib_cli_output (vm, " gso-enabled %d", vif->gso_enabled);
Mohsin Kazmiba0061f2019-12-18 17:08:54 +0100334 vlib_cli_output (vm, " csum-enabled %d", vif->csum_offload_enabled);
Mohsin Kazmi9e2a7852020-08-13 18:57:26 +0200335 vlib_cli_output (vm, " packet-coalesce %d", vif->packet_coalesce);
Mohsin Kazmie347acb2020-09-28 10:26:33 +0000336 vlib_cli_output (vm, " packet-buffering %d", vif->packet_buffering);
Mohsin Kazmi206acf82020-04-06 14:19:54 +0200337 if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_PCI))
338 vlib_cli_output (vm, " Mac Address: %U", format_ethernet_address,
339 vif->mac_addr);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200340 vlib_cli_output (vm, " Device instance: %u", vif->dev_instance);
341 vlib_cli_output (vm, " flags 0x%x", vif->flags);
342 flag_entry = (struct feat_struct *) &flags_array;
343 while (flag_entry->str)
344 {
345 if (vif->flags & (1ULL << flag_entry->bit))
346 vlib_cli_output (vm, " %s (%d)", flag_entry->str,
347 flag_entry->bit);
348 flag_entry++;
349 }
350 if (type == VIRTIO_IF_TYPE_PCI)
351 {
352 device_status (vm, vif);
353 }
354 vlib_cli_output (vm, " features 0x%lx", vif->features);
355 feat_entry = (struct feat_struct *) &feat_array;
356 while (feat_entry->str)
357 {
358 if (vif->features & (1ULL << feat_entry->bit))
359 vlib_cli_output (vm, " %s (%d)", feat_entry->str,
360 feat_entry->bit);
361 feat_entry++;
362 }
363 vlib_cli_output (vm, " remote-features 0x%lx", vif->remote_features);
364 feat_entry = (struct feat_struct *) &feat_array;
365 while (feat_entry->str)
366 {
367 if (vif->remote_features & (1ULL << feat_entry->bit))
368 vlib_cli_output (vm, " %s (%d)", feat_entry->str,
369 feat_entry->bit);
370 feat_entry++;
371 }
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000372 vlib_cli_output (vm, " Number of RX Virtqueue %u", vif->num_rxqs);
373 vlib_cli_output (vm, " Number of TX Virtqueue %u", vif->num_txqs);
374 if (vif->cxq_vring != NULL
375 && vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ))
376 vlib_cli_output (vm, " Number of CTRL Virtqueue 1");
377 vec_foreach_index (i, vif->rxq_vrings)
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200378 {
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000379 vring = vec_elt_at_index (vif->rxq_vrings, i);
380 vlib_cli_output (vm, " Virtqueue (RX) %d", vring->queue_id);
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200381 vlib_cli_output (vm,
382 " qsz %d, last_used_idx %d, desc_next %d, desc_in_use %d",
383 vring->size, vring->last_used_idx, vring->desc_next,
384 vring->desc_in_use);
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100385 if (vif->is_packed)
386 {
387 vlib_cli_output (vm,
388 " driver_event.flags 0x%x driver_event.off_wrap %d device_event.flags 0x%x device_event.off_wrap %d",
389 vring->driver_event->flags,
390 vring->driver_event->off_wrap,
391 vring->device_event->flags,
392 vring->device_event->off_wrap);
393 vlib_cli_output (vm,
394 " avail wrap counter %d, used wrap counter %d",
395 vring->avail_wrap_counter,
396 vring->used_wrap_counter);
397 }
398 else
399 vlib_cli_output (vm,
400 " avail.flags 0x%x avail.idx %d used.flags 0x%x used.idx %d",
401 vring->avail->flags, vring->avail->idx,
402 vring->used->flags, vring->used->idx);
Mohsin Kazmi206acf82020-04-06 14:19:54 +0200403 if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_TUN))
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200404 {
405 vlib_cli_output (vm, " kickfd %d, callfd %d", vring->kick_fd,
406 vring->call_fd);
407 }
408 if (show_descr)
409 {
410 vlib_cli_output (vm, "\n descriptor table:\n");
411 vlib_cli_output (vm,
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100412 " id addr len flags next/id user_addr\n");
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200413 vlib_cli_output (vm,
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100414 " ===== ================== ===== ====== ======= ==================\n");
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200415 for (j = 0; j < vring->size; j++)
416 {
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100417 if (vif->is_packed)
418 {
419 vring_packed_desc_t *desc = &vring->packed_desc[j];
420 vlib_cli_output (vm,
421 " %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n",
422 j, desc->addr,
423 desc->len,
424 desc->flags, desc->id, desc->addr);
425 }
426 else
427 {
428 vring_desc_t *desc = &vring->desc[j];
429 vlib_cli_output (vm,
430 " %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n",
431 j, desc->addr,
432 desc->len,
433 desc->flags, desc->next, desc->addr);
434 }
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200435 }
436 }
437 }
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000438 vec_foreach_index (i, vif->txq_vrings)
439 {
440 vring = vec_elt_at_index (vif->txq_vrings, i);
441 vlib_cli_output (vm, " Virtqueue (TX) %d", vring->queue_id);
442 vlib_cli_output (vm,
443 " qsz %d, last_used_idx %d, desc_next %d, desc_in_use %d",
444 vring->size, vring->last_used_idx, vring->desc_next,
445 vring->desc_in_use);
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100446 if (vif->is_packed)
447 {
448 vlib_cli_output (vm,
449 " driver_event.flags 0x%x driver_event.off_wrap %d device_event.flags 0x%x device_event.off_wrap %d",
450 vring->driver_event->flags,
451 vring->driver_event->off_wrap,
452 vring->device_event->flags,
453 vring->device_event->off_wrap);
454 vlib_cli_output (vm,
455 " avail wrap counter %d, used wrap counter %d",
456 vring->avail_wrap_counter,
457 vring->used_wrap_counter);
458 }
459 else
460 vlib_cli_output (vm,
461 " avail.flags 0x%x avail.idx %d used.flags 0x%x used.idx %d",
462 vring->avail->flags, vring->avail->idx,
463 vring->used->flags, vring->used->idx);
Mohsin Kazmi206acf82020-04-06 14:19:54 +0200464 if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_TUN))
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000465 {
466 vlib_cli_output (vm, " kickfd %d, callfd %d", vring->kick_fd,
467 vring->call_fd);
468 }
Mohsin Kazmi9e2a7852020-08-13 18:57:26 +0200469 if (vring->flow_table)
470 {
471 vlib_cli_output (vm, " %U", gro_flow_table_format,
472 vring->flow_table);
473 }
Mohsin Kazmie347acb2020-09-28 10:26:33 +0000474 if (vif->packet_buffering)
475 {
476 vlib_cli_output (vm, " %U", virtio_vring_buffering_format,
477 vring->buffering);
478 }
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000479 if (show_descr)
480 {
481 vlib_cli_output (vm, "\n descriptor table:\n");
482 vlib_cli_output (vm,
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100483 " id addr len flags next/id user_addr\n");
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000484 vlib_cli_output (vm,
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100485 " ===== ================== ===== ====== ======== ==================\n");
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000486 for (j = 0; j < vring->size; j++)
487 {
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100488 if (vif->is_packed)
489 {
490 vring_packed_desc_t *desc = &vring->packed_desc[j];
491 vlib_cli_output (vm,
492 " %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n",
493 j, desc->addr,
494 desc->len,
495 desc->flags, desc->id, desc->addr);
496 }
497 else
498 {
499 vring_desc_t *desc = &vring->desc[j];
500 vlib_cli_output (vm,
501 " %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n",
502 j, desc->addr,
503 desc->len,
504 desc->flags, desc->next, desc->addr);
505 }
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000506 }
507 }
508 }
509 if (vif->cxq_vring != NULL
510 && vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ))
511 {
512 vring = vif->cxq_vring;
513 vlib_cli_output (vm, " Virtqueue (CTRL) %d", vring->queue_id);
514 vlib_cli_output (vm,
515 " qsz %d, last_used_idx %d, desc_next %d, desc_in_use %d",
516 vring->size, vring->last_used_idx,
517 vring->desc_next, vring->desc_in_use);
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100518 if (vif->is_packed)
519 {
520 vlib_cli_output (vm,
521 " driver_event.flags 0x%x driver_event.off_wrap %d device_event.flags 0x%x device_event.off_wrap %d",
522 vring->driver_event->flags,
523 vring->driver_event->off_wrap,
524 vring->device_event->flags,
525 vring->device_event->off_wrap);
526 vlib_cli_output (vm,
527 " avail wrap counter %d, used wrap counter %d",
528 vring->avail_wrap_counter,
529 vring->used_wrap_counter);
530 }
531 else
532 {
533 vlib_cli_output (vm,
534 " avail.flags 0x%x avail.idx %d used.flags 0x%x used.idx %d",
535 vring->avail->flags, vring->avail->idx,
536 vring->used->flags, vring->used->idx);
537 }
Mohsin Kazmi206acf82020-04-06 14:19:54 +0200538 if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_TUN))
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000539 {
540 vlib_cli_output (vm, " kickfd %d, callfd %d", vring->kick_fd,
541 vring->call_fd);
542 }
543 if (show_descr)
544 {
545 vlib_cli_output (vm, "\n descriptor table:\n");
546 vlib_cli_output (vm,
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100547 " id addr len flags next/id user_addr\n");
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000548 vlib_cli_output (vm,
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100549 " ===== ================== ===== ====== ======== ==================\n");
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000550 for (j = 0; j < vring->size; j++)
551 {
Mohsin Kazmib977d3f2020-11-16 16:49:30 +0100552 if (vif->is_packed)
553 {
554 vring_packed_desc_t *desc = &vring->packed_desc[j];
555 vlib_cli_output (vm,
556 " %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n",
557 j, desc->addr,
558 desc->len,
559 desc->flags, desc->id, desc->addr);
560 }
561 else
562 {
563 vring_desc_t *desc = &vring->desc[j];
564 vlib_cli_output (vm,
565 " %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n",
566 j, desc->addr,
567 desc->len,
568 desc->flags, desc->next, desc->addr);
569 }
Mohsin Kazmi09a3bc52019-04-02 11:45:08 +0000570 }
571 }
572 }
573
Mohsin Kazmid6c15af2018-10-23 18:00:47 +0200574 }
575
576}
577
Damjan Marionf41244f2019-11-08 17:41:06 +0100578static clib_error_t *
579virtio_init (vlib_main_t * vm)
580{
581 virtio_main_t *vim = &virtio_main;
582 clib_error_t *error = 0;
583
584 vim->log_default = vlib_log_register_class ("virtio", 0);
585 vlib_log_debug (vim->log_default, "initialized");
586
587 return error;
588}
589
590VLIB_INIT_FUNCTION (virtio_init);
591
Damjan Marion8389fb92017-10-13 18:29:53 +0200592/*
593 * fd.io coding-style-patch-verification: ON
594 *
595 * Local Variables:
596 * eval: (c-set-style "gnu")
597 * End:
598 */