vmxnet3 device driver
[vpp.git] / src / plugins / vmxnet3 / vmxnet3.c
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #include <vppinfra/types.h>
17 #include <vlib/vlib.h>
18 #include <vlib/pci/pci.h>
19 #include <vnet/ethernet/ethernet.h>
20 #include <vnet/plugin/plugin.h>
21 #include <vpp/app/version.h>
22
23 #include <vmxnet3/vmxnet3.h>
24
25 #define PCI_VENDOR_ID_VMWARE                            0x15ad
26 #define PCI_DEVICE_ID_VMWARE_VMXNET3                    0x07b0
27
28 vmxnet3_main_t vmxnet3_main;
29
30 static pci_device_id_t vmxnet3_pci_device_ids[] = {
31   {
32    .vendor_id = PCI_VENDOR_ID_VMWARE,
33    .device_id = PCI_DEVICE_ID_VMWARE_VMXNET3},
34   {0},
35 };
36
37 static clib_error_t *
38 vmxnet3_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
39                                  u32 flags)
40 {
41   vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
42   vmxnet3_main_t *vmxm = &vmxnet3_main;
43   vmxnet3_device_t *vd = vec_elt_at_index (vmxm->devices, hi->dev_instance);
44   uword is_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
45
46   if (vd->flags & VMXNET3_DEVICE_F_ERROR)
47     return clib_error_return (0, "device is in error state");
48
49   if (is_up)
50     {
51       vnet_hw_interface_set_flags (vnm, vd->hw_if_index,
52                                    VNET_HW_INTERFACE_FLAG_LINK_UP);
53       vd->flags |= VMXNET3_DEVICE_F_ADMIN_UP;
54     }
55   else
56     {
57       vnet_hw_interface_set_flags (vnm, vd->hw_if_index, 0);
58       vd->flags &= ~VMXNET3_DEVICE_F_ADMIN_UP;
59     }
60   return 0;
61 }
62
63 static clib_error_t *
64 vmxnet3_interface_rx_mode_change (vnet_main_t * vnm, u32 hw_if_index, u32 qid,
65                                   vnet_hw_interface_rx_mode mode)
66 {
67   vmxnet3_main_t *vmxm = &vmxnet3_main;
68   vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
69   vmxnet3_device_t *vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
70   vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, qid);
71
72   if (mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
73     rxq->int_mode = 0;
74   else
75     rxq->int_mode = 1;
76
77   return 0;
78 }
79
80 static char *vmxnet3_tx_func_error_strings[] = {
81 #define _(n,s) s,
82   foreach_vmxnet3_tx_func_error
83 #undef _
84 };
85
86 /* *INDENT-OFF* */
87 VNET_DEVICE_CLASS (vmxnet3_device_class,) =
88 {
89   .name = "VMXNET3 interface",
90   .format_device = format_vmxnet3_device,
91   .format_device_name = format_vmxnet3_device_name,
92   .admin_up_down_function = vmxnet3_interface_admin_up_down,
93   .rx_mode_change_function = vmxnet3_interface_rx_mode_change,
94   .tx_function_n_errors = VMXNET3_TX_N_ERROR,
95   .tx_function_error_strings = vmxnet3_tx_func_error_strings,
96 };
97 /* *INDENT-ON* */
98
99 static u32
100 vmxnet3_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hw, u32 flags)
101 {
102   return 0;
103 }
104
105 static void
106 vmxnet3_write_mac (vmxnet3_device_t * vd)
107 {
108   u32 val;
109
110   memcpy (&val, vd->mac_addr, 4);
111   vmxnet3_reg_write (vd, 1, VMXNET3_REG_MACL, val);
112
113   val = 0;
114   memcpy (&val, vd->mac_addr + 4, 2);
115   vmxnet3_reg_write (vd, 1, VMXNET3_REG_MACH, val);
116 }
117
118 static clib_error_t *
119 vmxnet3_provision_driver_shared (vlib_main_t * vm, vmxnet3_device_t * vd)
120 {
121   vmxnet3_main_t *vmxm = &vmxnet3_main;
122   vmxnet3_shared *shared;
123   vmxnet3_queues *q;
124   u64 shared_dma;
125   clib_error_t *error;
126   u16 qid = 0, rid;
127   vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, qid);
128   vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, qid);
129
130   vd->dma = vlib_physmem_alloc_aligned (vm, vmxm->physmem_region, &error,
131                                         sizeof (*vd->dma), 512);
132   if (error)
133     return error;
134
135   memset (vd->dma, 0, sizeof (*vd->dma));
136
137   q = &vd->dma->queues;
138   q->tx.cfg.desc_address = vmxnet3_dma_addr (vm, vd, txq->tx_desc);
139   q->tx.cfg.comp_address = vmxnet3_dma_addr (vm, vd, txq->tx_comp);
140   q->tx.cfg.num_desc = txq->size;
141   q->tx.cfg.num_comp = txq->size;
142   for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
143     {
144       q->rx.cfg.desc_address[rid] = vmxnet3_dma_addr (vm, vd,
145                                                       rxq->rx_desc[rid]);
146       q->rx.cfg.num_desc[rid] = rxq->size;
147     }
148   q->rx.cfg.comp_address = vmxnet3_dma_addr (vm, vd, rxq->rx_comp);
149   q->rx.cfg.num_comp = rxq->size;
150
151   shared = &vd->dma->shared;
152   shared->magic = VMXNET3_SHARED_MAGIC;
153   shared->misc.version = VMXNET3_VERSION_MAGIC;
154   if (sizeof (void *) == 4)
155     shared->misc.guest_info = VMXNET3_GOS_BITS_32;
156   else
157     shared->misc.guest_info = VMXNET3_GOS_BITS_64;
158   shared->misc.guest_info |= VMXNET3_GOS_TYPE_LINUX;
159   shared->misc.version_support = VMXNET3_VERSION_SELECT;
160   shared->misc.upt_version_support = VMXNET3_UPT_VERSION_SELECT;
161   shared->misc.queue_desc_address = vmxnet3_dma_addr (vm, vd, q);
162   shared->misc.queue_desc_len = sizeof (*q);
163   shared->misc.mtu = VMXNET3_MTU;
164   shared->misc.num_tx_queues = vd->num_tx_queues;
165   shared->misc.num_rx_queues = vd->num_rx_queues;
166   shared->interrupt.num_intrs = vd->num_intrs;
167   shared->interrupt.control = VMXNET3_IC_DISABLE_ALL;
168   shared->rx_filter.mode = VMXNET3_RXMODE_UCAST | VMXNET3_RXMODE_BCAST |
169     VMXNET3_RXMODE_ALL_MULTI;
170   shared_dma = vmxnet3_dma_addr (vm, vd, shared);
171
172   vmxnet3_reg_write (vd, 1, VMXNET3_REG_DSAL, shared_dma);
173   vmxnet3_reg_write (vd, 1, VMXNET3_REG_DSAH, shared_dma >> 32);
174
175   return 0;
176 }
177
178 static inline void
179 vmxnet3_enable_interrupt (vmxnet3_device_t * vd)
180 {
181   int i;
182   vmxnet3_shared *shared = &vd->dma->shared;
183
184   shared->interrupt.control &= ~VMXNET3_IC_DISABLE_ALL;
185   for (i = 0; i < vd->num_intrs; i++)
186     vmxnet3_reg_write (vd, 0, VMXNET3_REG_IMR + i * 8, 0);
187 }
188
189 static inline void
190 vmxnet3_disable_interrupt (vmxnet3_device_t * vd)
191 {
192   int i;
193   vmxnet3_shared *shared = &vd->dma->shared;
194
195   shared->interrupt.control |= VMXNET3_IC_DISABLE_ALL;
196   for (i = 0; i < vd->num_intrs; i++)
197     vmxnet3_reg_write (vd, 0, VMXNET3_REG_IMR + i * 8, 1);
198 }
199
200 static clib_error_t *
201 vmxnet3_rxq_init (vlib_main_t * vm, vmxnet3_device_t * vd, u16 qid, u16 qsz)
202 {
203   vmxnet3_main_t *vmxm = &vmxnet3_main;
204   vmxnet3_rxq_t *rxq;
205   clib_error_t *error;
206   u16 rid;
207
208   vec_validate_aligned (vd->rxqs, qid, CLIB_CACHE_LINE_BYTES);
209   rxq = vec_elt_at_index (vd->rxqs, qid);
210   memset (rxq, 0, sizeof (*rxq));
211   rxq->size = qsz;
212   for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
213     {
214       rxq->rx_desc[rid] =
215         vlib_physmem_alloc_aligned (vm, vmxm->physmem_region,
216                                     &error, qsz * sizeof (*rxq->rx_desc[rid]),
217                                     512);
218       if (error)
219         return error;
220       memset (rxq->rx_desc[rid], 0, qsz * sizeof (*rxq->rx_desc[rid]));
221     }
222   rxq->rx_comp = vlib_physmem_alloc_aligned (vm, vmxm->physmem_region, &error,
223                                              qsz * sizeof (*rxq->rx_comp),
224                                              512);
225   if (error)
226     return error;
227   memset (rxq->rx_comp, 0, qsz * sizeof (*rxq->rx_comp));
228   for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
229     {
230       vmxnet3_rx_ring *ring;
231
232       ring = &rxq->rx_ring[rid];
233       ring->gen = VMXNET3_RXF_GEN;
234       vec_validate_aligned (ring->bufs, rxq->size, CLIB_CACHE_LINE_BYTES);
235     }
236   rxq->rx_comp_ring.gen = VMXNET3_RXCF_GEN;
237
238   return 0;
239 }
240
241 static clib_error_t *
242 vmxnet3_txq_init (vlib_main_t * vm, vmxnet3_device_t * vd, u16 qid, u16 qsz)
243 {
244   vmxnet3_main_t *vmxm = &vmxnet3_main;
245   vmxnet3_txq_t *txq;
246   clib_error_t *error;
247
248   if (qid >= vd->num_tx_queues)
249     {
250       qid = qid % vd->num_tx_queues;
251       txq = vec_elt_at_index (vd->txqs, qid);
252       if (txq->lock == 0)
253         clib_spinlock_init (&txq->lock);
254       vd->flags |= VMXNET3_DEVICE_F_SHARED_TXQ_LOCK;
255     }
256
257   vec_validate_aligned (vd->txqs, qid, CLIB_CACHE_LINE_BYTES);
258   txq = vec_elt_at_index (vd->txqs, qid);
259   memset (txq, 0, sizeof (*txq));
260   txq->size = qsz;
261   txq->tx_desc = vlib_physmem_alloc_aligned (vm, vmxm->physmem_region, &error,
262                                              qsz * sizeof (*txq->tx_desc),
263                                              512);
264   if (error)
265     return error;
266   memset (txq->tx_desc, 0, qsz * sizeof (*txq->tx_desc));
267   txq->tx_comp = vlib_physmem_alloc_aligned (vm, vmxm->physmem_region, &error,
268                                              qsz * sizeof (*txq->tx_comp),
269                                              512);
270   if (error)
271     return error;
272   memset (txq->tx_comp, 0, qsz * sizeof (*txq->tx_comp));
273   vec_validate_aligned (txq->tx_ring.bufs, txq->size, CLIB_CACHE_LINE_BYTES);
274   txq->tx_ring.gen = VMXNET3_TXF_GEN;
275   txq->tx_comp_ring.gen = VMXNET3_TXCF_GEN;
276
277   return 0;
278 }
279
280 static clib_error_t *
281 vmxnet3_device_init (vlib_main_t * vm, vmxnet3_device_t * vd,
282                      vmxnet3_create_if_args_t * args)
283 {
284   clib_error_t *error = 0;
285   u32 ret, i;
286   vmxnet3_main_t *vmxm = &vmxnet3_main;
287   vlib_thread_main_t *tm = vlib_get_thread_main ();
288
289   vd->num_tx_queues = 1;
290   vd->num_rx_queues = 1;
291   vd->num_intrs = 1;
292
293   /* Quiesce the device */
294   vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_QUIESCE_DEV);
295   ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_CMD);
296   if (ret != 0)
297     {
298       error = clib_error_return (0, "error on quisecing device rc (%u)", ret);
299       return error;
300     }
301
302   /* Reset the device */
303   vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_RESET_DEV);
304   ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_CMD);
305   if (ret != 0)
306     {
307       error = clib_error_return (0, "error on resetting device rc (%u)", ret);
308       return error;
309     }
310
311   ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_VRRS);
312   vd->version = count_leading_zeros (ret);
313   vd->version = uword_bits - vd->version;
314
315   if (vd->version == 0 || vd->version > 3)
316     {
317       error = clib_error_return (0, "unsupported hardware version %u",
318                                  vd->version);
319       return error;
320     }
321
322   vmxnet3_reg_write (vd, 1, VMXNET3_REG_VRRS, 1 << (vd->version - 1));
323
324   ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_UVRS);
325   if (ret & 1)
326     vmxnet3_reg_write (vd, 1, VMXNET3_REG_UVRS, 1);
327   else
328     {
329       error = clib_error_return (0, "unsupported upt version %u", ret);
330       return error;
331     }
332
333   /* Get the mac address */
334   ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_MACL);
335   clib_memcpy (vd->mac_addr, &ret, 4);
336   ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_MACH);
337   clib_memcpy (vd->mac_addr + 4, &ret, 2);
338
339   if (vmxm->physmem_region_alloc == 0)
340     {
341       u32 flags = VLIB_PHYSMEM_F_INIT_MHEAP | VLIB_PHYSMEM_F_HUGETLB;
342       error =
343         vlib_physmem_region_alloc (vm, "vmxnet3 descriptors", 4 << 20, 0,
344                                    flags, &vmxm->physmem_region);
345       if (error)
346         return error;
347       vmxm->physmem_region_alloc = 1;
348     }
349
350   error = vmxnet3_rxq_init (vm, vd, 0, args->rxq_size);
351   if (error)
352     return error;
353
354   for (i = 0; i < tm->n_vlib_mains; i++)
355     {
356       error = vmxnet3_txq_init (vm, vd, i, args->txq_size);
357       if (error)
358         return error;
359     }
360
361   error = vmxnet3_provision_driver_shared (vm, vd);
362   if (error)
363     return error;
364
365   vmxnet3_write_mac (vd);
366
367   /* Activate device */
368   vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_ACTIVATE_DEV);
369   ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_CMD);
370   if (ret != 0)
371     {
372       error =
373         clib_error_return (0, "error on activating device rc (%u)", ret);
374       return error;
375     }
376
377   /* Disable interrupts */
378   vmxnet3_disable_interrupt (vd);
379
380   vec_foreach_index (i, vd->rxqs)
381   {
382     vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, i);
383
384     vmxnet3_rxq_refill_ring0 (vm, vd, rxq);
385     vmxnet3_rxq_refill_ring1 (vm, vd, rxq);
386   }
387   vd->flags |= VMXNET3_DEVICE_F_INITIALIZED;
388
389   vmxnet3_enable_interrupt (vd);
390
391   return error;
392 }
393
394 static void
395 vmxnet3_irq_handler (vlib_pci_dev_handle_t h, u16 line)
396 {
397   vnet_main_t *vnm = vnet_get_main ();
398   vmxnet3_main_t *vmxm = &vmxnet3_main;
399   uword pd = vlib_pci_get_private_data (h);
400   vmxnet3_device_t *vd = pool_elt_at_index (vmxm->devices, pd);
401   u16 qid = line;
402
403   if (vec_len (vd->rxqs) > qid && vd->rxqs[qid].int_mode != 0)
404     vnet_device_input_set_interrupt_pending (vnm, vd->hw_if_index, qid);
405 }
406
407 static u8
408 vmxnet3_queue_size_valid (u16 qsz)
409 {
410   if (qsz < 64 || qsz > 4096)
411     return 0;
412   if ((qsz % 64) != 0)
413     return 0;
414   return 1;
415 }
416
417 void
418 vmxnet3_create_if (vlib_main_t * vm, vmxnet3_create_if_args_t * args)
419 {
420   vnet_main_t *vnm = vnet_get_main ();
421   vmxnet3_main_t *vmxm = &vmxnet3_main;
422   vmxnet3_device_t *vd;
423   vlib_pci_dev_handle_t h;
424   clib_error_t *error = 0;
425
426   if (args->rxq_size == 0)
427     args->rxq_size = VMXNET3_NUM_RX_DESC;
428   if (args->txq_size == 0)
429     args->txq_size = VMXNET3_NUM_TX_DESC;
430
431   if (!vmxnet3_queue_size_valid (args->rxq_size) ||
432       !vmxnet3_queue_size_valid (args->txq_size))
433     {
434       args->rv = VNET_API_ERROR_INVALID_VALUE;
435       args->error =
436         clib_error_return (error,
437                            "queue size must be <= 4096, >= 64, "
438                            "and multiples of 64");
439       return;
440     }
441
442   /* *INDENT-OFF* */
443   pool_foreach (vd, vmxm->devices, ({
444     if (vd->pci_addr.as_u32 == args->addr.as_u32)
445       {
446         args->rv = VNET_API_ERROR_INVALID_VALUE;
447         args->error =
448           clib_error_return (error, "PCI address in use");
449         return;
450       }
451   }));
452   /* *INDENT-ON* */
453
454   pool_get (vmxm->devices, vd);
455   vd->dev_instance = vd - vmxm->devices;
456   vd->per_interface_next_index = ~0;
457   vd->pci_addr = args->addr;
458
459   if (args->enable_elog)
460     vd->flags |= VMXNET3_DEVICE_F_ELOG;
461
462   if ((error =
463        vlib_pci_device_open (&args->addr, vmxnet3_pci_device_ids, &h)))
464     {
465       pool_put (vmxm->devices, vd);
466       args->rv = VNET_API_ERROR_INVALID_INTERFACE;
467       args->error =
468         clib_error_return (error, "pci-addr %U", format_vlib_pci_addr,
469                            &args->addr);
470       return;
471     }
472   vd->pci_dev_handle = h;
473
474   vlib_pci_set_private_data (h, vd->dev_instance);
475
476   if ((error = vlib_pci_bus_master_enable (h)))
477     goto error;
478
479   if ((error = vlib_pci_map_region (h, 0, (void **) &vd->bar[0])))
480     goto error;
481
482   if ((error = vlib_pci_map_region (h, 1, (void **) &vd->bar[1])))
483     goto error;
484
485   if ((error = vlib_pci_register_msix_handler (h, 0, 1,
486                                                &vmxnet3_irq_handler)))
487     goto error;
488
489   if ((error = vlib_pci_enable_msix_irq (h, 0, 1)))
490     goto error;
491
492   if ((error = vlib_pci_intr_enable (h)))
493     goto error;
494
495   if ((error = vmxnet3_device_init (vm, vd, args)))
496     goto error;
497
498   /* create interface */
499   error = ethernet_register_interface (vnm, vmxnet3_device_class.index,
500                                        vd->dev_instance, vd->mac_addr,
501                                        &vd->hw_if_index, vmxnet3_flag_change);
502
503   if (error)
504     goto error;
505
506   vnet_sw_interface_t *sw = vnet_get_hw_sw_interface (vnm, vd->hw_if_index);
507   vd->sw_if_index = sw->sw_if_index;
508   args->sw_if_index = sw->sw_if_index;
509
510   vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vd->hw_if_index);
511   hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE;
512   vnet_hw_interface_set_input_node (vnm, vd->hw_if_index,
513                                     vmxnet3_input_node.index);
514   vnet_hw_interface_assign_rx_thread (vnm, vd->hw_if_index, 0, ~0);
515   return;
516
517 error:
518   vmxnet3_delete_if (vm, vd);
519   args->rv = VNET_API_ERROR_INVALID_INTERFACE;
520   args->error = error;
521 }
522
523 void
524 vmxnet3_delete_if (vlib_main_t * vm, vmxnet3_device_t * vd)
525 {
526   vnet_main_t *vnm = vnet_get_main ();
527   vmxnet3_main_t *vmxm = &vmxnet3_main;
528   u32 i, bi;
529   u16 desc_idx;
530
531   /* Quiesce the device */
532   vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_QUIESCE_DEV);
533
534   /* Reset the device */
535   vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_RESET_DEV);
536
537   if (vd->hw_if_index)
538     {
539       vnet_hw_interface_set_flags (vnm, vd->hw_if_index, 0);
540       vnet_hw_interface_unassign_rx_thread (vnm, vd->hw_if_index, 0);
541       ethernet_delete_interface (vnm, vd->hw_if_index);
542     }
543
544   vlib_pci_device_close (vd->pci_dev_handle);
545
546   /* *INDENT-OFF* */
547   vec_foreach_index (i, vd->rxqs)
548     {
549       vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, i);
550       u16 mask = rxq->size - 1;
551       u16 rid;
552
553       for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
554         {
555           vmxnet3_rx_ring *ring;
556
557           ring = &rxq->rx_ring[rid];
558           desc_idx = ring->consume;
559           while (ring->fill)
560             {
561               desc_idx &= mask;
562               bi = ring->bufs[desc_idx];
563               vlib_buffer_free_no_next (vm, &bi, 1);
564               ring->fill--;
565               desc_idx++;
566             }
567           vec_free (ring->bufs);
568           vlib_physmem_free (vm, vmxm->physmem_region, rxq->rx_desc[rid]);
569         }
570       vlib_physmem_free (vm, vmxm->physmem_region, rxq->rx_comp);
571     }
572   /* *INDENT-ON* */
573   vec_free (vd->rxqs);
574
575   /* *INDENT-OFF* */
576   vec_foreach_index (i, vd->txqs)
577     {
578       vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, i);
579       u16 mask = txq->size - 1;
580       u16 end_idx;
581
582       desc_idx = txq->tx_ring.consume;
583       end_idx = txq->tx_ring.produce;
584       while (desc_idx != end_idx)
585         {
586           bi = txq->tx_ring.bufs[desc_idx];
587           vlib_buffer_free_no_next (vm, &bi, 1);
588           desc_idx++;
589           desc_idx &= mask;
590         }
591       clib_spinlock_free (&txq->lock);
592       vec_free (txq->tx_ring.bufs);
593       vlib_physmem_free (vm, vmxm->physmem_region, txq->tx_desc);
594       vlib_physmem_free (vm, vmxm->physmem_region, txq->tx_comp);
595     }
596   /* *INDENT-ON* */
597   vec_free (vd->txqs);
598
599   vlib_physmem_free (vm, vmxm->physmem_region, vd->dma);
600
601   clib_error_free (vd->error);
602   memset (vd, 0, sizeof (*vd));
603   pool_put (vmxm->devices, vd);
604 }
605
606 /*
607  * fd.io coding-style-patch-verification: ON
608  *
609  * Local Variables:
610  * eval: (c-set-style "gnu")
611  * End:
612  */