virtio: fix the interrupt
[vpp.git] / src / vnet / devices / virtio / virtio.c
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>
24 #include <sys/eventfd.h>
25
26 #include <vlib/vlib.h>
27 #include <vlib/pci/pci.h>
28 #include <vlib/unix/unix.h>
29 #include <vnet/ethernet/ethernet.h>
30 #include <vnet/ip/ip4_packet.h>
31 #include <vnet/ip/ip6_packet.h>
32 #include <vnet/devices/virtio/virtio.h>
33 #include <vnet/devices/virtio/virtio_inline.h>
34 #include <vnet/devices/virtio/pci.h>
35 #include <vnet/interface/rx_queue_funcs.h>
36
37 virtio_main_t virtio_main;
38
39 #define _IOCTL(fd,a,...) \
40   if (ioctl (fd, a, __VA_ARGS__) < 0) \
41     { \
42       err = clib_error_return_unix (0, "ioctl(" #a ")"); \
43       goto error; \
44     }
45
46 static clib_error_t *
47 call_read_ready (clib_file_t * uf)
48 {
49   vnet_main_t *vnm = vnet_get_main ();
50   u64 b;
51
52   CLIB_UNUSED (ssize_t size) = read (uf->file_descriptor, &b, sizeof (b));
53   vnet_hw_if_rx_queue_set_int_pending (vnm, uf->private_data);
54
55   return 0;
56 }
57
58
59 clib_error_t *
60 virtio_vring_init (vlib_main_t * vm, virtio_if_t * vif, u16 idx, u16 sz)
61 {
62   virtio_vring_t *vring;
63   int i;
64
65   if (!is_pow2 (sz))
66     return clib_error_return (0, "ring size must be power of 2");
67
68   if (sz > 32768)
69     return clib_error_return (0, "ring size must be 32768 or lower");
70
71   if (sz == 0)
72     sz = 256;
73
74   if (idx % 2)
75     {
76       vlib_thread_main_t *thm = vlib_get_thread_main ();
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));
80       if (thm->n_vlib_mains > vif->num_txqs)
81         clib_spinlock_init (&vring->lockp);
82     }
83   else
84     {
85       vec_validate_aligned (vif->rxq_vrings, RX_QUEUE_ACCESS (idx),
86                             CLIB_CACHE_LINE_BYTES);
87       vring = vec_elt_at_index (vif->rxq_vrings, RX_QUEUE_ACCESS (idx));
88     }
89   i = sizeof (vring_desc_t) * sz;
90   i = round_pow2 (i, CLIB_CACHE_LINE_BYTES);
91   vring->desc = clib_mem_alloc_aligned (i, CLIB_CACHE_LINE_BYTES);
92   clib_memset (vring->desc, 0, i);
93
94   i = sizeof (vring_avail_t) + sz * sizeof (vring->avail->ring[0]);
95   i = round_pow2 (i, CLIB_CACHE_LINE_BYTES);
96   vring->avail = clib_mem_alloc_aligned (i, CLIB_CACHE_LINE_BYTES);
97   clib_memset (vring->avail, 0, i);
98   // tell kernel that we don't need interrupt
99   vring->avail->flags = VRING_AVAIL_F_NO_INTERRUPT;
100
101   i = sizeof (vring_used_t) + sz * sizeof (vring_used_elem_t);
102   i = round_pow2 (i, CLIB_CACHE_LINE_BYTES);
103   vring->used = clib_mem_alloc_aligned (i, CLIB_CACHE_LINE_BYTES);
104   clib_memset (vring->used, 0, i);
105
106   vring->queue_id = idx;
107   ASSERT (vring->buffers == 0);
108   vec_validate_aligned (vring->buffers, sz, CLIB_CACHE_LINE_BYTES);
109
110   if (idx & 1)
111     {
112       clib_memset_u32 (vring->buffers, ~0, sz);
113       // tx path: suppress the interrupts from kernel
114       vring->call_fd = -1;
115     }
116   else
117     vring->call_fd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC);
118
119   vring->size = sz;
120   vring->kick_fd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC);
121   virtio_log_debug (vif, "vring %u size %u call_fd %d kick_fd %d", idx,
122                     vring->size, vring->call_fd, vring->kick_fd);
123
124   return 0;
125 }
126
127 inline void
128 virtio_free_buffers (vlib_main_t * vm, virtio_vring_t * vring)
129 {
130   u16 used = vring->desc_in_use;
131   u16 last = vring->last_used_idx;
132   u16 mask = vring->size - 1;
133
134   while (used)
135     {
136       vlib_buffer_free (vm, &vring->buffers[last & mask], 1);
137       last++;
138       used--;
139     }
140 }
141
142 clib_error_t *
143 virtio_vring_free_rx (vlib_main_t * vm, virtio_if_t * vif, u32 idx)
144 {
145   virtio_vring_t *vring =
146     vec_elt_at_index (vif->rxq_vrings, RX_QUEUE_ACCESS (idx));
147
148   clib_file_del_by_index (&file_main, vring->call_file_index);
149   close (vring->kick_fd);
150   close (vring->call_fd);
151   if (vring->used)
152     {
153       virtio_free_buffers (vm, vring);
154       clib_mem_free (vring->used);
155     }
156   if (vring->desc)
157     clib_mem_free (vring->desc);
158   if (vring->avail)
159     clib_mem_free (vring->avail);
160   vec_free (vring->buffers);
161   return 0;
162 }
163
164 clib_error_t *
165 virtio_vring_free_tx (vlib_main_t * vm, virtio_if_t * vif, u32 idx)
166 {
167   virtio_vring_t *vring =
168     vec_elt_at_index (vif->txq_vrings, TX_QUEUE_ACCESS (idx));
169
170   close (vring->kick_fd);
171   if (vring->used)
172     {
173       virtio_free_buffers (vm, vring);
174       clib_mem_free (vring->used);
175     }
176   if (vring->desc)
177     clib_mem_free (vring->desc);
178   if (vring->avail)
179     clib_mem_free (vring->avail);
180   vec_free (vring->buffers);
181   gro_flow_table_free (vring->flow_table);
182   virtio_vring_buffering_free (vm, vring->buffering);
183   clib_spinlock_free (&vring->lockp);
184   return 0;
185 }
186
187 void
188 virtio_set_packet_coalesce (virtio_if_t * vif)
189 {
190   vnet_main_t *vnm = vnet_get_main ();
191   vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vif->hw_if_index);
192   virtio_vring_t *vring;
193   vif->packet_coalesce = 1;
194   vec_foreach (vring, vif->txq_vrings)
195   {
196     gro_flow_table_init (&vring->flow_table,
197                          vif->type & (VIRTIO_IF_TYPE_TAP |
198                                       VIRTIO_IF_TYPE_PCI), hw->tx_node_index);
199   }
200 }
201
202 clib_error_t *
203 virtio_set_packet_buffering (virtio_if_t * vif, u16 buffering_size)
204 {
205   vnet_main_t *vnm = vnet_get_main ();
206   vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vif->hw_if_index);
207   virtio_vring_t *vring;
208   clib_error_t *error = 0;
209   vif->packet_buffering = 1;
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
224 static void
225 virtio_vring_fill (vlib_main_t *vm, virtio_if_t *vif, virtio_vring_t *vring)
226 {
227   if (vif->is_packed)
228     virtio_refill_vring_packed (vm, vif, vif->type, vring,
229                                 vif->virtio_net_hdr_sz,
230                                 virtio_input_node.index);
231   else
232     virtio_refill_vring_split (vm, vif, vif->type, vring,
233                                vif->virtio_net_hdr_sz,
234                                virtio_input_node.index);
235 }
236
237 void
238 virtio_vring_set_rx_queues (vlib_main_t *vm, virtio_if_t *vif)
239 {
240   vnet_main_t *vnm = vnet_get_main ();
241   virtio_vring_t *vring;
242   u32 i = 0;
243
244   vnet_hw_if_set_input_node (vnm, vif->hw_if_index, virtio_input_node.index);
245
246   vec_foreach (vring, vif->rxq_vrings)
247     {
248       vring->queue_index = vnet_hw_if_register_rx_queue (
249         vnm, vif->hw_if_index, RX_QUEUE_ACCESS (vring->queue_id),
250         VNET_HW_IF_RXQ_THREAD_ANY);
251       vring->buffer_pool_index = vlib_buffer_pool_get_default_for_numa (
252         vm, vnet_hw_if_get_rx_queue_numa_node (vnm, vring->queue_index));
253       if (vif->type == VIRTIO_IF_TYPE_TAP || vif->type == VIRTIO_IF_TYPE_TUN)
254         {
255
256           clib_file_t f = {
257             .read_function = call_read_ready,
258             .flags = UNIX_FILE_EVENT_EDGE_TRIGGERED,
259             .file_descriptor = vring->call_fd,
260             .private_data = vring->queue_index,
261             .description = format (0, "%U vring %u", format_virtio_device_name,
262                                    vif->dev_instance, vring->queue_id),
263           };
264
265           vring->call_file_index = clib_file_add (&file_main, &f);
266           vnet_hw_if_set_rx_queue_file_index (vnm, vring->queue_index,
267                                               vring->call_file_index);
268         }
269       else if ((vif->type == VIRTIO_IF_TYPE_PCI) && (vif->support_int_mode) &&
270                (vif->msix_enabled == VIRTIO_MSIX_ENABLED))
271         {
272           u32 file_index;
273           file_index =
274             vlib_pci_get_msix_file_index (vm, vif->pci_dev_handle, i + 1);
275           vnet_hw_if_set_rx_queue_file_index (vnm, vring->queue_index,
276                                               file_index);
277           i++;
278         }
279       vnet_hw_if_set_rx_queue_mode (vnm, vring->queue_index,
280                                     VNET_HW_IF_RX_MODE_POLLING);
281       vring->mode = VNET_HW_IF_RX_MODE_POLLING;
282       virtio_vring_fill (vm, vif, vring);
283     }
284   vnet_hw_if_update_runtime_data (vnm, vif->hw_if_index);
285 }
286
287 inline void
288 virtio_set_net_hdr_size (virtio_if_t * vif)
289 {
290   if (vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_MRG_RXBUF) ||
291       vif->features & VIRTIO_FEATURE (VIRTIO_F_VERSION_1))
292     vif->virtio_net_hdr_sz = sizeof (virtio_net_hdr_v1_t);
293   else
294     vif->virtio_net_hdr_sz = sizeof (virtio_net_hdr_t);
295 }
296
297 inline void
298 virtio_show (vlib_main_t * vm, u32 * hw_if_indices, u8 show_descr, u32 type)
299 {
300   u32 i, j, hw_if_index;
301   virtio_if_t *vif;
302   vnet_main_t *vnm = &vnet_main;
303   virtio_main_t *mm = &virtio_main;
304   virtio_vring_t *vring;
305   struct feat_struct
306   {
307     u8 bit;
308     char *str;
309   };
310   struct feat_struct *feat_entry;
311
312   static struct feat_struct feat_array[] = {
313 #define _(s,b) { .str = #s, .bit = b, },
314     foreach_virtio_net_features
315 #undef _
316     {.str = NULL}
317   };
318
319   struct feat_struct *flag_entry;
320   static struct feat_struct flags_array[] = {
321 #define _(b,e,s) { .bit = b, .str = s, },
322     foreach_virtio_if_flag
323 #undef _
324     {.str = NULL}
325   };
326
327   if (!hw_if_indices)
328     return;
329
330   for (hw_if_index = 0; hw_if_index < vec_len (hw_if_indices); hw_if_index++)
331     {
332       vnet_hw_interface_t *hi =
333         vnet_get_hw_interface (vnm, hw_if_indices[hw_if_index]);
334       vif = pool_elt_at_index (mm->interfaces, hi->dev_instance);
335       if (vif->type != type)
336         continue;
337       vlib_cli_output (vm, "Interface: %U (ifindex %d)",
338                        format_vnet_hw_if_index_name, vnm,
339                        hw_if_indices[hw_if_index], vif->hw_if_index);
340       if (type == VIRTIO_IF_TYPE_PCI)
341         {
342           vlib_cli_output (vm, "  PCI Address: %U", format_vlib_pci_addr,
343                            &vif->pci_addr);
344         }
345       if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_TUN))
346         {
347           u8 *str = 0;
348           if (vif->host_if_name)
349             vlib_cli_output (vm, "  name \"%s\"", vif->host_if_name);
350           if (vif->net_ns)
351             vlib_cli_output (vm, "  host-ns \"%s\"", vif->net_ns);
352           if (vif->host_mtu_size)
353             vlib_cli_output (vm, "  host-mtu-size \"%d\"",
354                              vif->host_mtu_size);
355           if (type == VIRTIO_IF_TYPE_TAP)
356             vlib_cli_output (vm, "  host-mac-addr: %U",
357                              format_ethernet_address, vif->host_mac_addr);
358           vlib_cli_output (vm, "  host-carrier-up: %u", vif->host_carrier_up);
359
360           vec_foreach_index (i, vif->vhost_fds)
361             str = format (str, " %d", vif->vhost_fds[i]);
362           vlib_cli_output (vm, "  vhost-fds%v", str);
363           vec_free (str);
364           vec_foreach_index (i, vif->tap_fds)
365             str = format (str, " %d", vif->tap_fds[i]);
366           vlib_cli_output (vm, "  tap-fds%v", str);
367           vec_free (str);
368         }
369       vlib_cli_output (vm, "  gso-enabled %d", vif->gso_enabled);
370       vlib_cli_output (vm, "  csum-enabled %d", vif->csum_offload_enabled);
371       vlib_cli_output (vm, "  packet-coalesce %d", vif->packet_coalesce);
372       vlib_cli_output (vm, "  packet-buffering %d", vif->packet_buffering);
373       if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_PCI))
374         vlib_cli_output (vm, "  Mac Address: %U", format_ethernet_address,
375                          vif->mac_addr);
376       vlib_cli_output (vm, "  Device instance: %u", vif->dev_instance);
377       vlib_cli_output (vm, "  flags 0x%x", vif->flags);
378       flag_entry = (struct feat_struct *) &flags_array;
379       while (flag_entry->str)
380         {
381           if (vif->flags & (1ULL << flag_entry->bit))
382             vlib_cli_output (vm, "    %s (%d)", flag_entry->str,
383                              flag_entry->bit);
384           flag_entry++;
385         }
386       if (type == VIRTIO_IF_TYPE_PCI)
387         {
388           device_status (vm, vif);
389         }
390       vlib_cli_output (vm, "  features 0x%lx", vif->features);
391       feat_entry = (struct feat_struct *) &feat_array;
392       while (feat_entry->str)
393         {
394           if (vif->features & (1ULL << feat_entry->bit))
395             vlib_cli_output (vm, "    %s (%d)", feat_entry->str,
396                              feat_entry->bit);
397           feat_entry++;
398         }
399       vlib_cli_output (vm, "  remote-features 0x%lx", vif->remote_features);
400       feat_entry = (struct feat_struct *) &feat_array;
401       while (feat_entry->str)
402         {
403           if (vif->remote_features & (1ULL << feat_entry->bit))
404             vlib_cli_output (vm, "    %s (%d)", feat_entry->str,
405                              feat_entry->bit);
406           feat_entry++;
407         }
408       vlib_cli_output (vm, "  Number of RX Virtqueue  %u", vif->num_rxqs);
409       vlib_cli_output (vm, "  Number of TX Virtqueue  %u", vif->num_txqs);
410       if (vif->cxq_vring != NULL
411           && vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ))
412         vlib_cli_output (vm, "  Number of CTRL Virtqueue 1");
413       vec_foreach_index (i, vif->rxq_vrings)
414       {
415         vring = vec_elt_at_index (vif->rxq_vrings, i);
416         vlib_cli_output (vm, "  Virtqueue (RX) %d", vring->queue_id);
417         vlib_cli_output (vm,
418                          "    qsz %d, last_used_idx %d, desc_next %d, desc_in_use %d",
419                          vring->size, vring->last_used_idx, vring->desc_next,
420                          vring->desc_in_use);
421         if (vif->is_packed)
422           {
423             vlib_cli_output (vm,
424                              "    driver_event.flags 0x%x driver_event.off_wrap %d device_event.flags 0x%x device_event.off_wrap %d",
425                              vring->driver_event->flags,
426                              vring->driver_event->off_wrap,
427                              vring->device_event->flags,
428                              vring->device_event->off_wrap);
429             vlib_cli_output (vm,
430                              "    avail wrap counter %d, used wrap counter %d",
431                              vring->avail_wrap_counter,
432                              vring->used_wrap_counter);
433           }
434         else
435           vlib_cli_output (vm,
436                            "    avail.flags 0x%x avail.idx %d used.flags 0x%x used.idx %d",
437                            vring->avail->flags, vring->avail->idx,
438                            vring->used->flags, vring->used->idx);
439         if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_TUN))
440           {
441             vlib_cli_output (vm, "    kickfd %d, callfd %d", vring->kick_fd,
442                              vring->call_fd);
443           }
444         if (show_descr)
445           {
446             vlib_cli_output (vm, "\n  descriptor table:\n");
447             vlib_cli_output (vm,
448                              "   id          addr         len  flags  next/id      user_addr\n");
449             vlib_cli_output (vm,
450                              "  ===== ================== ===== ====== ======= ==================\n");
451             for (j = 0; j < vring->size; j++)
452               {
453                 if (vif->is_packed)
454                   {
455                     vring_packed_desc_t *desc = &vring->packed_desc[j];
456                     vlib_cli_output (vm,
457                                      "  %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n",
458                                      j, desc->addr,
459                                      desc->len,
460                                      desc->flags, desc->id, desc->addr);
461                   }
462                 else
463                   {
464                     vring_desc_t *desc = &vring->desc[j];
465                     vlib_cli_output (vm,
466                                      "  %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n",
467                                      j, desc->addr,
468                                      desc->len,
469                                      desc->flags, desc->next, desc->addr);
470                   }
471               }
472           }
473       }
474       vec_foreach_index (i, vif->txq_vrings)
475       {
476         vring = vec_elt_at_index (vif->txq_vrings, i);
477         vlib_cli_output (vm, "  Virtqueue (TX) %d", vring->queue_id);
478         vlib_cli_output (vm,
479                          "    qsz %d, last_used_idx %d, desc_next %d, desc_in_use %d",
480                          vring->size, vring->last_used_idx, vring->desc_next,
481                          vring->desc_in_use);
482         if (vif->is_packed)
483           {
484             vlib_cli_output (vm,
485                              "    driver_event.flags 0x%x driver_event.off_wrap %d device_event.flags 0x%x device_event.off_wrap %d",
486                              vring->driver_event->flags,
487                              vring->driver_event->off_wrap,
488                              vring->device_event->flags,
489                              vring->device_event->off_wrap);
490             vlib_cli_output (vm,
491                              "    avail wrap counter %d, used wrap counter %d",
492                              vring->avail_wrap_counter,
493                              vring->used_wrap_counter);
494           }
495         else
496           vlib_cli_output (vm,
497                            "    avail.flags 0x%x avail.idx %d used.flags 0x%x used.idx %d",
498                            vring->avail->flags, vring->avail->idx,
499                            vring->used->flags, vring->used->idx);
500         if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_TUN))
501           {
502             vlib_cli_output (vm, "    kickfd %d, callfd %d", vring->kick_fd,
503                              vring->call_fd);
504           }
505         if (vring->flow_table)
506           {
507             vlib_cli_output (vm, "    %U", gro_flow_table_format,
508                              vring->flow_table);
509           }
510         if (vif->packet_buffering)
511           {
512             vlib_cli_output (vm, "    %U", virtio_vring_buffering_format,
513                              vring->buffering);
514           }
515         if (show_descr)
516           {
517             vlib_cli_output (vm, "\n  descriptor table:\n");
518             vlib_cli_output (vm,
519                              "   id          addr         len  flags  next/id      user_addr\n");
520             vlib_cli_output (vm,
521                              "  ===== ================== ===== ====== ======== ==================\n");
522             for (j = 0; j < vring->size; j++)
523               {
524                 if (vif->is_packed)
525                   {
526                     vring_packed_desc_t *desc = &vring->packed_desc[j];
527                     vlib_cli_output (vm,
528                                      "  %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n",
529                                      j, desc->addr,
530                                      desc->len,
531                                      desc->flags, desc->id, desc->addr);
532                   }
533                 else
534                   {
535                     vring_desc_t *desc = &vring->desc[j];
536                     vlib_cli_output (vm,
537                                      "  %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n",
538                                      j, desc->addr,
539                                      desc->len,
540                                      desc->flags, desc->next, desc->addr);
541                   }
542               }
543           }
544       }
545       if (vif->cxq_vring != NULL
546           && vif->features & VIRTIO_FEATURE (VIRTIO_NET_F_CTRL_VQ))
547         {
548           vring = vif->cxq_vring;
549           vlib_cli_output (vm, "  Virtqueue (CTRL) %d", vring->queue_id);
550           vlib_cli_output (vm,
551                            "    qsz %d, last_used_idx %d, desc_next %d, desc_in_use %d",
552                            vring->size, vring->last_used_idx,
553                            vring->desc_next, vring->desc_in_use);
554           if (vif->is_packed)
555             {
556               vlib_cli_output (vm,
557                                "    driver_event.flags 0x%x driver_event.off_wrap %d device_event.flags 0x%x device_event.off_wrap %d",
558                                vring->driver_event->flags,
559                                vring->driver_event->off_wrap,
560                                vring->device_event->flags,
561                                vring->device_event->off_wrap);
562               vlib_cli_output (vm,
563                                "    avail wrap counter %d, used wrap counter %d",
564                                vring->avail_wrap_counter,
565                                vring->used_wrap_counter);
566             }
567           else
568             {
569               vlib_cli_output (vm,
570                                "    avail.flags 0x%x avail.idx %d used.flags 0x%x used.idx %d",
571                                vring->avail->flags, vring->avail->idx,
572                                vring->used->flags, vring->used->idx);
573             }
574           if (type & (VIRTIO_IF_TYPE_TAP | VIRTIO_IF_TYPE_TUN))
575             {
576               vlib_cli_output (vm, "    kickfd %d, callfd %d", vring->kick_fd,
577                                vring->call_fd);
578             }
579           if (show_descr)
580             {
581               vlib_cli_output (vm, "\n  descriptor table:\n");
582               vlib_cli_output (vm,
583                                "   id          addr         len  flags  next/id      user_addr\n");
584               vlib_cli_output (vm,
585                                "  ===== ================== ===== ====== ======== ==================\n");
586               for (j = 0; j < vring->size; j++)
587                 {
588                   if (vif->is_packed)
589                     {
590                       vring_packed_desc_t *desc = &vring->packed_desc[j];
591                       vlib_cli_output (vm,
592                                        "  %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n",
593                                        j, desc->addr,
594                                        desc->len,
595                                        desc->flags, desc->id, desc->addr);
596                     }
597                   else
598                     {
599                       vring_desc_t *desc = &vring->desc[j];
600                       vlib_cli_output (vm,
601                                        "  %-5d 0x%016lx %-5d 0x%04x %-8d 0x%016lx\n",
602                                        j, desc->addr,
603                                        desc->len,
604                                        desc->flags, desc->next, desc->addr);
605                     }
606                 }
607             }
608         }
609
610     }
611
612 }
613
614 static clib_error_t *
615 virtio_init (vlib_main_t * vm)
616 {
617   virtio_main_t *vim = &virtio_main;
618   clib_error_t *error = 0;
619
620   vim->log_default = vlib_log_register_class ("virtio", 0);
621   vlib_log_debug (vim->log_default, "initialized");
622
623   return error;
624 }
625
626 VLIB_INIT_FUNCTION (virtio_init);
627
628 /*
629  * fd.io coding-style-patch-verification: ON
630  *
631  * Local Variables:
632  * eval: (c-set-style "gnu")
633  * End:
634  */