Remove c-11 memcpy checks from perf-critical code
[vpp.git] / src / vnet / devices / virtio / vhost_user_output.c
1 /*
2  *------------------------------------------------------------------
3  * vhost-user-output
4  *
5  * Copyright (c) 2014-2018 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19
20 #include <fcntl.h>              /* for open */
21 #include <sys/ioctl.h>
22 #include <sys/socket.h>
23 #include <sys/un.h>
24 #include <sys/stat.h>
25 #include <sys/types.h>
26 #include <sys/uio.h>            /* for iovec */
27 #include <netinet/in.h>
28 #include <sys/vfs.h>
29
30 #include <linux/if_arp.h>
31 #include <linux/if_tun.h>
32
33 #include <vlib/vlib.h>
34 #include <vlib/unix/unix.h>
35
36 #include <vnet/ip/ip.h>
37
38 #include <vnet/ethernet/ethernet.h>
39 #include <vnet/devices/devices.h>
40 #include <vnet/feature/feature.h>
41
42 #include <vnet/devices/virtio/vhost_user.h>
43 #include <vnet/devices/virtio/vhost_user_inline.h>
44
45 /*
46  * On the transmit side, we keep processing the buffers from vlib in the while
47  * loop and prepare the copy order to be executed later. However, the static
48  * array which we keep the copy order is limited to VHOST_USER_COPY_ARRAY_N
49  * entries. In order to not corrupt memory, we have to do the copy when the
50  * static array reaches the copy threshold. We subtract 40 in case the code
51  * goes into the inner loop for a maximum of 64k frames which may require
52  * more array entries.
53  */
54 #define VHOST_USER_TX_COPY_THRESHOLD (VHOST_USER_COPY_ARRAY_N - 40)
55
56 vnet_device_class_t vhost_user_device_class;
57
58 #define foreach_vhost_user_tx_func_error      \
59   _(NONE, "no error")  \
60   _(NOT_READY, "vhost vring not ready")  \
61   _(DOWN, "vhost interface is down")  \
62   _(PKT_DROP_NOBUF, "tx packet drops (no available descriptors)")  \
63   _(PKT_DROP_NOMRG, "tx packet drops (cannot merge descriptors)")  \
64   _(MMAP_FAIL, "mmap failure") \
65   _(INDIRECT_OVERFLOW, "indirect descriptor table overflow")
66
67 typedef enum
68 {
69 #define _(f,s) VHOST_USER_TX_FUNC_ERROR_##f,
70   foreach_vhost_user_tx_func_error
71 #undef _
72     VHOST_USER_TX_FUNC_N_ERROR,
73 } vhost_user_tx_func_error_t;
74
75 static __clib_unused char *vhost_user_tx_func_error_strings[] = {
76 #define _(n,s) s,
77   foreach_vhost_user_tx_func_error
78 #undef _
79 };
80
81 static __clib_unused u8 *
82 format_vhost_user_interface_name (u8 * s, va_list * args)
83 {
84   u32 i = va_arg (*args, u32);
85   u32 show_dev_instance = ~0;
86   vhost_user_main_t *vum = &vhost_user_main;
87
88   if (i < vec_len (vum->show_dev_instance_by_real_dev_instance))
89     show_dev_instance = vum->show_dev_instance_by_real_dev_instance[i];
90
91   if (show_dev_instance != ~0)
92     i = show_dev_instance;
93
94   s = format (s, "VirtualEthernet0/0/%d", i);
95   return s;
96 }
97
98 static __clib_unused int
99 vhost_user_name_renumber (vnet_hw_interface_t * hi, u32 new_dev_instance)
100 {
101   // FIXME: check if the new dev instance is already used
102   vhost_user_main_t *vum = &vhost_user_main;
103   vhost_user_intf_t *vui = pool_elt_at_index (vum->vhost_user_interfaces,
104                                               hi->dev_instance);
105
106   vec_validate_init_empty (vum->show_dev_instance_by_real_dev_instance,
107                            hi->dev_instance, ~0);
108
109   vum->show_dev_instance_by_real_dev_instance[hi->dev_instance] =
110     new_dev_instance;
111
112   vu_log_debug (vui, "renumbered vhost-user interface dev_instance %d to %d",
113                 hi->dev_instance, new_dev_instance);
114
115   return 0;
116 }
117
118 /**
119  * @brief Try once to lock the vring
120  * @return 0 on success, non-zero on failure.
121  */
122 static_always_inline int
123 vhost_user_vring_try_lock (vhost_user_intf_t * vui, u32 qid)
124 {
125   return clib_atomic_test_and_set (vui->vring_locks[qid]);
126 }
127
128 /**
129  * @brief Spin until the vring is successfully locked
130  */
131 static_always_inline void
132 vhost_user_vring_lock (vhost_user_intf_t * vui, u32 qid)
133 {
134   while (vhost_user_vring_try_lock (vui, qid))
135     ;
136 }
137
138 /**
139  * @brief Unlock the vring lock
140  */
141 static_always_inline void
142 vhost_user_vring_unlock (vhost_user_intf_t * vui, u32 qid)
143 {
144   clib_atomic_release (vui->vring_locks[qid]);
145 }
146
147 static_always_inline void
148 vhost_user_tx_trace (vhost_trace_t * t,
149                      vhost_user_intf_t * vui, u16 qid,
150                      vlib_buffer_t * b, vhost_user_vring_t * rxvq)
151 {
152   vhost_user_main_t *vum = &vhost_user_main;
153   u32 last_avail_idx = rxvq->last_avail_idx;
154   u32 desc_current = rxvq->avail->ring[last_avail_idx & rxvq->qsz_mask];
155   vring_desc_t *hdr_desc = 0;
156   u32 hint = 0;
157
158   clib_memset (t, 0, sizeof (*t));
159   t->device_index = vui - vum->vhost_user_interfaces;
160   t->qid = qid;
161
162   hdr_desc = &rxvq->desc[desc_current];
163   if (rxvq->desc[desc_current].flags & VIRTQ_DESC_F_INDIRECT)
164     {
165       t->virtio_ring_flags |= 1 << VIRTIO_TRACE_F_INDIRECT;
166       /* Header is the first here */
167       hdr_desc = map_guest_mem (vui, rxvq->desc[desc_current].addr, &hint);
168     }
169   if (rxvq->desc[desc_current].flags & VIRTQ_DESC_F_NEXT)
170     {
171       t->virtio_ring_flags |= 1 << VIRTIO_TRACE_F_SIMPLE_CHAINED;
172     }
173   if (!(rxvq->desc[desc_current].flags & VIRTQ_DESC_F_NEXT) &&
174       !(rxvq->desc[desc_current].flags & VIRTQ_DESC_F_INDIRECT))
175     {
176       t->virtio_ring_flags |= 1 << VIRTIO_TRACE_F_SINGLE_DESC;
177     }
178
179   t->first_desc_len = hdr_desc ? hdr_desc->len : 0;
180 }
181
182 static_always_inline u32
183 vhost_user_tx_copy (vhost_user_intf_t * vui, vhost_copy_t * cpy,
184                     u16 copy_len, u32 * map_hint)
185 {
186   void *dst0, *dst1, *dst2, *dst3;
187   if (PREDICT_TRUE (copy_len >= 4))
188     {
189       if (PREDICT_FALSE (!(dst2 = map_guest_mem (vui, cpy[0].dst, map_hint))))
190         return 1;
191       if (PREDICT_FALSE (!(dst3 = map_guest_mem (vui, cpy[1].dst, map_hint))))
192         return 1;
193       while (PREDICT_TRUE (copy_len >= 4))
194         {
195           dst0 = dst2;
196           dst1 = dst3;
197
198           if (PREDICT_FALSE
199               (!(dst2 = map_guest_mem (vui, cpy[2].dst, map_hint))))
200             return 1;
201           if (PREDICT_FALSE
202               (!(dst3 = map_guest_mem (vui, cpy[3].dst, map_hint))))
203             return 1;
204
205           CLIB_PREFETCH ((void *) cpy[2].src, 64, LOAD);
206           CLIB_PREFETCH ((void *) cpy[3].src, 64, LOAD);
207
208           clib_memcpy_fast (dst0, (void *) cpy[0].src, cpy[0].len);
209           clib_memcpy_fast (dst1, (void *) cpy[1].src, cpy[1].len);
210
211           vhost_user_log_dirty_pages_2 (vui, cpy[0].dst, cpy[0].len, 1);
212           vhost_user_log_dirty_pages_2 (vui, cpy[1].dst, cpy[1].len, 1);
213           copy_len -= 2;
214           cpy += 2;
215         }
216     }
217   while (copy_len)
218     {
219       if (PREDICT_FALSE (!(dst0 = map_guest_mem (vui, cpy->dst, map_hint))))
220         return 1;
221       clib_memcpy_fast (dst0, (void *) cpy->src, cpy->len);
222       vhost_user_log_dirty_pages_2 (vui, cpy->dst, cpy->len, 1);
223       copy_len -= 1;
224       cpy += 1;
225     }
226   return 0;
227 }
228
229 VNET_DEVICE_CLASS_TX_FN (vhost_user_device_class) (vlib_main_t * vm,
230                                                    vlib_node_runtime_t *
231                                                    node, vlib_frame_t * frame)
232 {
233   u32 *buffers = vlib_frame_vector_args (frame);
234   u32 n_left = frame->n_vectors;
235   vhost_user_main_t *vum = &vhost_user_main;
236   vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
237   vhost_user_intf_t *vui =
238     pool_elt_at_index (vum->vhost_user_interfaces, rd->dev_instance);
239   u32 qid = ~0;
240   vhost_user_vring_t *rxvq;
241   u8 error;
242   u32 thread_index = vm->thread_index;
243   u32 map_hint = 0;
244   u8 retry = 8;
245   u16 copy_len;
246   u16 tx_headers_len;
247
248   if (PREDICT_FALSE (!vui->admin_up))
249     {
250       error = VHOST_USER_TX_FUNC_ERROR_DOWN;
251       goto done3;
252     }
253
254   if (PREDICT_FALSE (!vui->is_ready))
255     {
256       error = VHOST_USER_TX_FUNC_ERROR_NOT_READY;
257       goto done3;
258     }
259
260   qid =
261     VHOST_VRING_IDX_RX (*vec_elt_at_index
262                         (vui->per_cpu_tx_qid, thread_index));
263   rxvq = &vui->vrings[qid];
264   if (PREDICT_FALSE (rxvq->avail == 0))
265     {
266       error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
267       goto done3;
268     }
269
270   if (PREDICT_FALSE (vui->use_tx_spinlock))
271     vhost_user_vring_lock (vui, qid);
272
273 retry:
274   error = VHOST_USER_TX_FUNC_ERROR_NONE;
275   tx_headers_len = 0;
276   copy_len = 0;
277   while (n_left > 0)
278     {
279       vlib_buffer_t *b0, *current_b0;
280       u16 desc_head, desc_index, desc_len;
281       vring_desc_t *desc_table;
282       uword buffer_map_addr;
283       u32 buffer_len;
284       u16 bytes_left;
285
286       if (PREDICT_TRUE (n_left > 1))
287         vlib_prefetch_buffer_with_index (vm, buffers[1], LOAD);
288
289       b0 = vlib_get_buffer (vm, buffers[0]);
290
291       if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
292         {
293           vum->cpus[thread_index].current_trace =
294             vlib_add_trace (vm, node, b0,
295                             sizeof (*vum->cpus[thread_index].current_trace));
296           vhost_user_tx_trace (vum->cpus[thread_index].current_trace,
297                                vui, qid / 2, b0, rxvq);
298         }
299
300       if (PREDICT_FALSE (rxvq->last_avail_idx == rxvq->avail->idx))
301         {
302           error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF;
303           goto done;
304         }
305
306       desc_table = rxvq->desc;
307       desc_head = desc_index =
308         rxvq->avail->ring[rxvq->last_avail_idx & rxvq->qsz_mask];
309
310       /* Go deeper in case of indirect descriptor
311        * I don't know of any driver providing indirect for RX. */
312       if (PREDICT_FALSE (rxvq->desc[desc_head].flags & VIRTQ_DESC_F_INDIRECT))
313         {
314           if (PREDICT_FALSE
315               (rxvq->desc[desc_head].len < sizeof (vring_desc_t)))
316             {
317               error = VHOST_USER_TX_FUNC_ERROR_INDIRECT_OVERFLOW;
318               goto done;
319             }
320           if (PREDICT_FALSE
321               (!(desc_table =
322                  map_guest_mem (vui, rxvq->desc[desc_index].addr,
323                                 &map_hint))))
324             {
325               error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
326               goto done;
327             }
328           desc_index = 0;
329         }
330
331       desc_len = vui->virtio_net_hdr_sz;
332       buffer_map_addr = desc_table[desc_index].addr;
333       buffer_len = desc_table[desc_index].len;
334
335       {
336         // Get a header from the header array
337         virtio_net_hdr_mrg_rxbuf_t *hdr =
338           &vum->cpus[thread_index].tx_headers[tx_headers_len];
339         tx_headers_len++;
340         hdr->hdr.flags = 0;
341         hdr->hdr.gso_type = 0;
342         hdr->num_buffers = 1;   //This is local, no need to check
343
344         // Prepare a copy order executed later for the header
345         vhost_copy_t *cpy = &vum->cpus[thread_index].copy[copy_len];
346         copy_len++;
347         cpy->len = vui->virtio_net_hdr_sz;
348         cpy->dst = buffer_map_addr;
349         cpy->src = (uword) hdr;
350       }
351
352       buffer_map_addr += vui->virtio_net_hdr_sz;
353       buffer_len -= vui->virtio_net_hdr_sz;
354       bytes_left = b0->current_length;
355       current_b0 = b0;
356       while (1)
357         {
358           if (buffer_len == 0)
359             {                   //Get new output
360               if (desc_table[desc_index].flags & VIRTQ_DESC_F_NEXT)
361                 {
362                   //Next one is chained
363                   desc_index = desc_table[desc_index].next;
364                   buffer_map_addr = desc_table[desc_index].addr;
365                   buffer_len = desc_table[desc_index].len;
366                 }
367               else if (vui->virtio_net_hdr_sz == 12)    //MRG is available
368                 {
369                   virtio_net_hdr_mrg_rxbuf_t *hdr =
370                     &vum->cpus[thread_index].tx_headers[tx_headers_len - 1];
371
372                   //Move from available to used buffer
373                   rxvq->used->ring[rxvq->last_used_idx & rxvq->qsz_mask].id =
374                     desc_head;
375                   rxvq->used->ring[rxvq->last_used_idx & rxvq->qsz_mask].len =
376                     desc_len;
377                   vhost_user_log_dirty_ring (vui, rxvq,
378                                              ring[rxvq->last_used_idx &
379                                                   rxvq->qsz_mask]);
380
381                   rxvq->last_avail_idx++;
382                   rxvq->last_used_idx++;
383                   hdr->num_buffers++;
384                   desc_len = 0;
385
386                   if (PREDICT_FALSE
387                       (rxvq->last_avail_idx == rxvq->avail->idx))
388                     {
389                       //Dequeue queued descriptors for this packet
390                       rxvq->last_used_idx -= hdr->num_buffers - 1;
391                       rxvq->last_avail_idx -= hdr->num_buffers - 1;
392                       error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF;
393                       goto done;
394                     }
395
396                   desc_table = rxvq->desc;
397                   desc_head = desc_index =
398                     rxvq->avail->ring[rxvq->last_avail_idx & rxvq->qsz_mask];
399                   if (PREDICT_FALSE
400                       (rxvq->desc[desc_head].flags & VIRTQ_DESC_F_INDIRECT))
401                     {
402                       //It is seriously unlikely that a driver will put indirect descriptor
403                       //after non-indirect descriptor.
404                       if (PREDICT_FALSE
405                           (rxvq->desc[desc_head].len < sizeof (vring_desc_t)))
406                         {
407                           error = VHOST_USER_TX_FUNC_ERROR_INDIRECT_OVERFLOW;
408                           goto done;
409                         }
410                       if (PREDICT_FALSE
411                           (!(desc_table =
412                              map_guest_mem (vui,
413                                             rxvq->desc[desc_index].addr,
414                                             &map_hint))))
415                         {
416                           error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
417                           goto done;
418                         }
419                       desc_index = 0;
420                     }
421                   buffer_map_addr = desc_table[desc_index].addr;
422                   buffer_len = desc_table[desc_index].len;
423                 }
424               else
425                 {
426                   error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOMRG;
427                   goto done;
428                 }
429             }
430
431           {
432             vhost_copy_t *cpy = &vum->cpus[thread_index].copy[copy_len];
433             copy_len++;
434             cpy->len = bytes_left;
435             cpy->len = (cpy->len > buffer_len) ? buffer_len : cpy->len;
436             cpy->dst = buffer_map_addr;
437             cpy->src = (uword) vlib_buffer_get_current (current_b0) +
438               current_b0->current_length - bytes_left;
439
440             bytes_left -= cpy->len;
441             buffer_len -= cpy->len;
442             buffer_map_addr += cpy->len;
443             desc_len += cpy->len;
444
445             CLIB_PREFETCH (&rxvq->desc, CLIB_CACHE_LINE_BYTES, LOAD);
446           }
447
448           // Check if vlib buffer has more data. If not, get more or break.
449           if (PREDICT_TRUE (!bytes_left))
450             {
451               if (PREDICT_FALSE
452                   (current_b0->flags & VLIB_BUFFER_NEXT_PRESENT))
453                 {
454                   current_b0 = vlib_get_buffer (vm, current_b0->next_buffer);
455                   bytes_left = current_b0->current_length;
456                 }
457               else
458                 {
459                   //End of packet
460                   break;
461                 }
462             }
463         }
464
465       //Move from available to used ring
466       rxvq->used->ring[rxvq->last_used_idx & rxvq->qsz_mask].id = desc_head;
467       rxvq->used->ring[rxvq->last_used_idx & rxvq->qsz_mask].len = desc_len;
468       vhost_user_log_dirty_ring (vui, rxvq,
469                                  ring[rxvq->last_used_idx & rxvq->qsz_mask]);
470       rxvq->last_avail_idx++;
471       rxvq->last_used_idx++;
472
473       if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
474         {
475           vum->cpus[thread_index].current_trace->hdr =
476             vum->cpus[thread_index].tx_headers[tx_headers_len - 1];
477         }
478
479       n_left--;                 //At the end for error counting when 'goto done' is invoked
480
481       /*
482        * Do the copy periodically to prevent
483        * vum->cpus[thread_index].copy array overflow and corrupt memory
484        */
485       if (PREDICT_FALSE (copy_len >= VHOST_USER_TX_COPY_THRESHOLD))
486         {
487           if (PREDICT_FALSE
488               (vhost_user_tx_copy (vui, vum->cpus[thread_index].copy,
489                                    copy_len, &map_hint)))
490             {
491               vlib_error_count (vm, node->node_index,
492                                 VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL, 1);
493             }
494           copy_len = 0;
495
496           /* give buffers back to driver */
497           CLIB_MEMORY_BARRIER ();
498           rxvq->used->idx = rxvq->last_used_idx;
499           vhost_user_log_dirty_ring (vui, rxvq, idx);
500         }
501       buffers++;
502     }
503
504 done:
505   //Do the memory copies
506   if (PREDICT_FALSE
507       (vhost_user_tx_copy (vui, vum->cpus[thread_index].copy,
508                            copy_len, &map_hint)))
509     {
510       vlib_error_count (vm, node->node_index,
511                         VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL, 1);
512     }
513
514   CLIB_MEMORY_BARRIER ();
515   rxvq->used->idx = rxvq->last_used_idx;
516   vhost_user_log_dirty_ring (vui, rxvq, idx);
517
518   /*
519    * When n_left is set, error is always set to something too.
520    * In case error is due to lack of remaining buffers, we go back up and
521    * retry.
522    * The idea is that it is better to waste some time on packets
523    * that have been processed already than dropping them and get
524    * more fresh packets with a good likelyhood that they will be dropped too.
525    * This technique also gives more time to VM driver to pick-up packets.
526    * In case the traffic flows from physical to virtual interfaces, this
527    * technique will end-up leveraging the physical NIC buffer in order to
528    * absorb the VM's CPU jitter.
529    */
530   if (n_left && (error == VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF) && retry)
531     {
532       retry--;
533       goto retry;
534     }
535
536   /* interrupt (call) handling */
537   if ((rxvq->callfd_idx != ~0) &&
538       !(rxvq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT))
539     {
540       rxvq->n_since_last_int += frame->n_vectors - n_left;
541
542       if (rxvq->n_since_last_int > vum->coalesce_frames)
543         vhost_user_send_call (vm, rxvq);
544     }
545
546   vhost_user_vring_unlock (vui, qid);
547
548 done3:
549   if (PREDICT_FALSE (n_left && error != VHOST_USER_TX_FUNC_ERROR_NONE))
550     {
551       vlib_error_count (vm, node->node_index, error, n_left);
552       vlib_increment_simple_counter
553         (vnet_main.interface_main.sw_if_counters
554          + VNET_INTERFACE_COUNTER_DROP,
555          thread_index, vui->sw_if_index, n_left);
556     }
557
558   vlib_buffer_free (vm, vlib_frame_vector_args (frame), frame->n_vectors);
559   return frame->n_vectors;
560 }
561
562 static __clib_unused clib_error_t *
563 vhost_user_interface_rx_mode_change (vnet_main_t * vnm, u32 hw_if_index,
564                                      u32 qid, vnet_hw_interface_rx_mode mode)
565 {
566   vlib_main_t *vm = vnm->vlib_main;
567   vnet_hw_interface_t *hif = vnet_get_hw_interface (vnm, hw_if_index);
568   vhost_user_main_t *vum = &vhost_user_main;
569   vhost_user_intf_t *vui =
570     pool_elt_at_index (vum->vhost_user_interfaces, hif->dev_instance);
571   vhost_user_vring_t *txvq = &vui->vrings[VHOST_VRING_IDX_TX (qid)];
572
573   if ((mode == VNET_HW_INTERFACE_RX_MODE_INTERRUPT) ||
574       (mode == VNET_HW_INTERFACE_RX_MODE_ADAPTIVE))
575     {
576       if (txvq->kickfd_idx == ~0)
577         {
578           // We cannot support interrupt mode if the driver opts out
579           return clib_error_return (0, "Driver does not support interrupt");
580         }
581       if (txvq->mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
582         {
583           vum->ifq_count++;
584           // Start the timer if this is the first encounter on interrupt
585           // interface/queue
586           if ((vum->ifq_count == 1) &&
587               (vum->coalesce_time > 0.0) && (vum->coalesce_frames > 0))
588             vlib_process_signal_event (vm,
589                                        vhost_user_send_interrupt_node.index,
590                                        VHOST_USER_EVENT_START_TIMER, 0);
591         }
592     }
593   else if (mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
594     {
595       if (((txvq->mode == VNET_HW_INTERFACE_RX_MODE_INTERRUPT) ||
596            (txvq->mode == VNET_HW_INTERFACE_RX_MODE_ADAPTIVE)) &&
597           vum->ifq_count)
598         {
599           vum->ifq_count--;
600           // Stop the timer if there is no more interrupt interface/queue
601           if ((vum->ifq_count == 0) &&
602               (vum->coalesce_time > 0.0) && (vum->coalesce_frames > 0))
603             vlib_process_signal_event (vm,
604                                        vhost_user_send_interrupt_node.index,
605                                        VHOST_USER_EVENT_STOP_TIMER, 0);
606         }
607     }
608
609   txvq->mode = mode;
610   if (mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
611     txvq->used->flags = VRING_USED_F_NO_NOTIFY;
612   else if ((mode == VNET_HW_INTERFACE_RX_MODE_ADAPTIVE) ||
613            (mode == VNET_HW_INTERFACE_RX_MODE_INTERRUPT))
614     txvq->used->flags = 0;
615   else
616     {
617       vu_log_err (vui, "unhandled mode %d changed for if %d queue %d", mode,
618                   hw_if_index, qid);
619       return clib_error_return (0, "unsupported");
620     }
621
622   return 0;
623 }
624
625 static __clib_unused clib_error_t *
626 vhost_user_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
627                                     u32 flags)
628 {
629   vnet_hw_interface_t *hif = vnet_get_hw_interface (vnm, hw_if_index);
630   vhost_user_main_t *vum = &vhost_user_main;
631   vhost_user_intf_t *vui =
632     pool_elt_at_index (vum->vhost_user_interfaces, hif->dev_instance);
633   u8 link_old, link_new;
634
635   link_old = vui_is_link_up (vui);
636
637   vui->admin_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
638
639   link_new = vui_is_link_up (vui);
640
641   if (link_old != link_new)
642     vnet_hw_interface_set_flags (vnm, vui->hw_if_index, link_new ?
643                                  VNET_HW_INTERFACE_FLAG_LINK_UP : 0);
644
645   return /* no error */ 0;
646 }
647
648 /* *INDENT-OFF* */
649 VNET_DEVICE_CLASS (vhost_user_device_class) = {
650   .name = "vhost-user",
651   .tx_function_n_errors = VHOST_USER_TX_FUNC_N_ERROR,
652   .tx_function_error_strings = vhost_user_tx_func_error_strings,
653   .format_device_name = format_vhost_user_interface_name,
654   .name_renumber = vhost_user_name_renumber,
655   .admin_up_down_function = vhost_user_interface_admin_up_down,
656   .rx_mode_change_function = vhost_user_interface_rx_mode_change,
657   .format_tx_trace = format_vhost_trace,
658 };
659
660 /* *INDENT-ON* */
661
662 /*
663  * fd.io coding-style-patch-verification: ON
664  *
665  * Local Variables:
666  * eval: (c-set-style "gnu")
667  * End:
668  */