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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
23 #include <vmxnet3/vmxnet3.h>
25 #define PCI_VENDOR_ID_VMWARE 0x15ad
26 #define PCI_DEVICE_ID_VMWARE_VMXNET3 0x07b0
28 vmxnet3_main_t vmxnet3_main;
30 static pci_device_id_t vmxnet3_pci_device_ids[] = {
32 .vendor_id = PCI_VENDOR_ID_VMWARE,
33 .device_id = PCI_DEVICE_ID_VMWARE_VMXNET3},
38 vmxnet3_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
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;
46 if (vd->flags & VMXNET3_DEVICE_F_ERROR)
47 return clib_error_return (0, "device is in error state");
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;
57 vnet_hw_interface_set_flags (vnm, vd->hw_if_index, 0);
58 vd->flags &= ~VMXNET3_DEVICE_F_ADMIN_UP;
64 vmxnet3_interface_rx_mode_change (vnet_main_t * vnm, u32 hw_if_index, u32 qid,
65 vnet_hw_interface_rx_mode mode)
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);
72 if (mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
81 vmxnet3_set_interface_next_node (vnet_main_t * vnm, u32 hw_if_index,
84 vmxnet3_main_t *vmxm = &vmxnet3_main;
85 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
86 vmxnet3_device_t *vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
88 /* Shut off redirection */
91 vd->per_interface_next_index = node_index;
95 vd->per_interface_next_index =
96 vlib_node_add_next (vlib_get_main (), vmxnet3_input_node.index,
101 vmxnet3_clear_hw_interface_counters (u32 instance)
103 vmxnet3_main_t *vmxm = &vmxnet3_main;
104 vmxnet3_device_t *vd = pool_elt_at_index (vmxm->devices, instance);
105 vmxnet3_queues *q = &vd->dma->queues;
108 * Set the "last_cleared_stats" to the current stats, so that
109 * things appear to clear from a display perspective.
111 vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
113 clib_memcpy (&vd->tx_stats, &q->tx.stats, sizeof (vd->tx_stats));
114 clib_memcpy (&vd->rx_stats, &q->rx.stats, sizeof (vd->rx_stats));
117 static char *vmxnet3_tx_func_error_strings[] = {
119 foreach_vmxnet3_tx_func_error
124 VNET_DEVICE_CLASS (vmxnet3_device_class,) =
126 .name = "VMXNET3 interface",
127 .format_device = format_vmxnet3_device,
128 .format_device_name = format_vmxnet3_device_name,
129 .admin_up_down_function = vmxnet3_interface_admin_up_down,
130 .clear_counters = vmxnet3_clear_hw_interface_counters,
131 .rx_mode_change_function = vmxnet3_interface_rx_mode_change,
132 .rx_redirect_to_node = vmxnet3_set_interface_next_node,
133 .tx_function_n_errors = VMXNET3_TX_N_ERROR,
134 .tx_function_error_strings = vmxnet3_tx_func_error_strings,
139 vmxnet3_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hw, u32 flags)
145 vmxnet3_write_mac (vmxnet3_device_t * vd)
149 memcpy (&val, vd->mac_addr, 4);
150 vmxnet3_reg_write (vd, 1, VMXNET3_REG_MACL, val);
153 memcpy (&val, vd->mac_addr + 4, 2);
154 vmxnet3_reg_write (vd, 1, VMXNET3_REG_MACH, val);
157 static clib_error_t *
158 vmxnet3_provision_driver_shared (vlib_main_t * vm, vmxnet3_device_t * vd)
160 vmxnet3_shared *shared;
164 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, qid);
165 vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, qid);
167 vd->dma = vlib_physmem_alloc_aligned_on_numa (vm, sizeof (*vd->dma), 512,
170 return vlib_physmem_last_error (vm);
172 clib_memset (vd->dma, 0, sizeof (*vd->dma));
174 q = &vd->dma->queues;
175 q->tx.cfg.desc_address = vmxnet3_dma_addr (vm, vd, txq->tx_desc);
176 q->tx.cfg.comp_address = vmxnet3_dma_addr (vm, vd, txq->tx_comp);
177 q->tx.cfg.num_desc = txq->size;
178 q->tx.cfg.num_comp = txq->size;
179 for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
181 q->rx.cfg.desc_address[rid] = vmxnet3_dma_addr (vm, vd,
183 q->rx.cfg.num_desc[rid] = rxq->size;
185 q->rx.cfg.comp_address = vmxnet3_dma_addr (vm, vd, rxq->rx_comp);
186 q->rx.cfg.num_comp = rxq->size;
188 shared = &vd->dma->shared;
189 shared->magic = VMXNET3_SHARED_MAGIC;
190 shared->misc.version = VMXNET3_VERSION_MAGIC;
191 if (sizeof (void *) == 4)
192 shared->misc.guest_info = VMXNET3_GOS_BITS_32;
194 shared->misc.guest_info = VMXNET3_GOS_BITS_64;
195 shared->misc.guest_info |= VMXNET3_GOS_TYPE_LINUX;
196 shared->misc.version_support = VMXNET3_VERSION_SELECT;
197 shared->misc.upt_version_support = VMXNET3_UPT_VERSION_SELECT;
198 shared->misc.queue_desc_address = vmxnet3_dma_addr (vm, vd, q);
199 shared->misc.queue_desc_len = sizeof (*q);
200 shared->misc.mtu = VMXNET3_MTU;
201 shared->misc.num_tx_queues = vd->num_tx_queues;
202 shared->misc.num_rx_queues = vd->num_rx_queues;
203 shared->interrupt.num_intrs = vd->num_intrs;
204 shared->interrupt.event_intr_index = 1;
205 shared->interrupt.control = VMXNET3_IC_DISABLE_ALL;
206 shared->rx_filter.mode = VMXNET3_RXMODE_UCAST | VMXNET3_RXMODE_BCAST |
207 VMXNET3_RXMODE_ALL_MULTI | VMXNET3_RXMODE_PROMISC;
208 shared_dma = vmxnet3_dma_addr (vm, vd, shared);
210 vmxnet3_reg_write (vd, 1, VMXNET3_REG_DSAL, shared_dma);
211 vmxnet3_reg_write (vd, 1, VMXNET3_REG_DSAH, shared_dma >> 32);
217 vmxnet3_enable_interrupt (vmxnet3_device_t * vd)
220 vmxnet3_shared *shared = &vd->dma->shared;
222 shared->interrupt.control &= ~VMXNET3_IC_DISABLE_ALL;
223 for (i = 0; i < vd->num_intrs; i++)
224 vmxnet3_reg_write (vd, 0, VMXNET3_REG_IMR + i * 8, 0);
228 vmxnet3_disable_interrupt (vmxnet3_device_t * vd)
231 vmxnet3_shared *shared = &vd->dma->shared;
233 shared->interrupt.control |= VMXNET3_IC_DISABLE_ALL;
234 for (i = 0; i < vd->num_intrs; i++)
235 vmxnet3_reg_write (vd, 0, VMXNET3_REG_IMR + i * 8, 1);
238 static clib_error_t *
239 vmxnet3_rxq_init (vlib_main_t * vm, vmxnet3_device_t * vd, u16 qid, u16 qsz)
244 vec_validate_aligned (vd->rxqs, qid, CLIB_CACHE_LINE_BYTES);
245 rxq = vec_elt_at_index (vd->rxqs, qid);
246 clib_memset (rxq, 0, sizeof (*rxq));
248 for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
250 rxq->rx_desc[rid] = vlib_physmem_alloc_aligned_on_numa
251 (vm, qsz * sizeof (*rxq->rx_desc[rid]), 512, vd->numa_node);
253 if (rxq->rx_desc[rid] == 0)
254 return vlib_physmem_last_error (vm);
256 clib_memset (rxq->rx_desc[rid], 0, qsz * sizeof (*rxq->rx_desc[rid]));
259 vlib_physmem_alloc_aligned_on_numa (vm, qsz * sizeof (*rxq->rx_comp), 512,
261 if (rxq->rx_comp == 0)
262 return vlib_physmem_last_error (vm);
264 clib_memset (rxq->rx_comp, 0, qsz * sizeof (*rxq->rx_comp));
265 for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
267 vmxnet3_rx_ring *ring;
269 ring = &rxq->rx_ring[rid];
270 ring->gen = VMXNET3_RXF_GEN;
272 vec_validate_aligned (ring->bufs, rxq->size, CLIB_CACHE_LINE_BYTES);
274 rxq->rx_comp_ring.gen = VMXNET3_RXCF_GEN;
279 static clib_error_t *
280 vmxnet3_txq_init (vlib_main_t * vm, vmxnet3_device_t * vd, u16 qid, u16 qsz)
284 if (qid >= vd->num_tx_queues)
286 qid = qid % vd->num_tx_queues;
287 txq = vec_elt_at_index (vd->txqs, qid);
289 clib_spinlock_init (&txq->lock);
290 vd->flags |= VMXNET3_DEVICE_F_SHARED_TXQ_LOCK;
294 vec_validate_aligned (vd->txqs, qid, CLIB_CACHE_LINE_BYTES);
295 txq = vec_elt_at_index (vd->txqs, qid);
296 clib_memset (txq, 0, sizeof (*txq));
299 vlib_physmem_alloc_aligned_on_numa (vm, qsz * sizeof (*txq->tx_desc), 512,
301 if (txq->tx_desc == 0)
302 return vlib_physmem_last_error (vm);
304 memset (txq->tx_desc, 0, qsz * sizeof (*txq->tx_desc));
306 vlib_physmem_alloc_aligned_on_numa (vm, qsz * sizeof (*txq->tx_comp), 512,
308 if (txq->tx_comp == 0)
309 return vlib_physmem_last_error (vm);
311 clib_memset (txq->tx_comp, 0, qsz * sizeof (*txq->tx_comp));
312 vec_validate_aligned (txq->tx_ring.bufs, txq->size, CLIB_CACHE_LINE_BYTES);
313 txq->tx_ring.gen = VMXNET3_TXF_GEN;
314 txq->tx_comp_ring.gen = VMXNET3_TXCF_GEN;
319 static clib_error_t *
320 vmxnet3_device_init (vlib_main_t * vm, vmxnet3_device_t * vd,
321 vmxnet3_create_if_args_t * args)
323 clib_error_t *error = 0;
325 vlib_thread_main_t *tm = vlib_get_thread_main ();
327 vd->num_tx_queues = 1;
328 vd->num_rx_queues = 1;
331 /* Quiesce the device */
332 vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_QUIESCE_DEV);
333 ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_CMD);
336 error = clib_error_return (0, "error on quiescing device rc (%u)", ret);
340 /* Reset the device */
341 vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_RESET_DEV);
342 ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_CMD);
345 error = clib_error_return (0, "error on resetting device rc (%u)", ret);
349 ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_VRRS);
350 vd->version = count_leading_zeros (ret);
351 vd->version = uword_bits - vd->version;
353 if (vd->version == 0)
355 error = clib_error_return (0, "unsupported hardware version %u",
360 /* cap support version to 3 */
361 vmxnet3_reg_write (vd, 1, VMXNET3_REG_VRRS,
362 1 << (clib_min (3, vd->version) - 1));
364 ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_UVRS);
366 vmxnet3_reg_write (vd, 1, VMXNET3_REG_UVRS, 1);
369 error = clib_error_return (0, "unsupported upt version %u", ret);
373 vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_GET_LINK);
374 ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_CMD);
377 vd->flags |= VMXNET3_DEVICE_F_LINK_UP;
378 vd->link_speed = ret >> 16;
382 vd->flags &= ~VMXNET3_DEVICE_F_LINK_UP;
385 /* Get the mac address */
386 ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_MACL);
387 clib_memcpy (vd->mac_addr, &ret, 4);
388 ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_MACH);
389 clib_memcpy (vd->mac_addr + 4, &ret, 2);
391 error = vmxnet3_rxq_init (vm, vd, 0, args->rxq_size);
395 for (i = 0; i < tm->n_vlib_mains; i++)
397 error = vmxnet3_txq_init (vm, vd, i, args->txq_size);
402 error = vmxnet3_provision_driver_shared (vm, vd);
406 vmxnet3_write_mac (vd);
408 /* Activate device */
409 vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_ACTIVATE_DEV);
410 ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_CMD);
414 clib_error_return (0, "error on activating device rc (%u)", ret);
418 /* Disable interrupts */
419 vmxnet3_disable_interrupt (vd);
421 vec_foreach_index (i, vd->rxqs)
423 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, i);
425 vmxnet3_rxq_refill_ring0 (vm, vd, rxq);
426 vmxnet3_rxq_refill_ring1 (vm, vd, rxq);
428 vd->flags |= VMXNET3_DEVICE_F_INITIALIZED;
430 vmxnet3_enable_interrupt (vd);
436 vmxnet3_irq_0_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
438 vnet_main_t *vnm = vnet_get_main ();
439 vmxnet3_main_t *vmxm = &vmxnet3_main;
440 uword pd = vlib_pci_get_private_data (vm, h);
441 vmxnet3_device_t *vd = pool_elt_at_index (vmxm->devices, pd);
444 if (vec_len (vd->rxqs) > qid && vd->rxqs[qid].int_mode != 0)
445 vnet_device_input_set_interrupt_pending (vnm, vd->hw_if_index, qid);
449 vmxnet3_irq_1_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
451 vnet_main_t *vnm = vnet_get_main ();
452 vmxnet3_main_t *vmxm = &vmxnet3_main;
453 uword pd = vlib_pci_get_private_data (vm, h);
454 vmxnet3_device_t *vd = pool_elt_at_index (vmxm->devices, pd);
457 vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_GET_LINK);
458 ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_CMD);
461 vd->flags |= VMXNET3_DEVICE_F_LINK_UP;
462 vd->link_speed = ret >> 16;
463 vnet_hw_interface_set_link_speed (vnm, vd->hw_if_index,
464 vd->link_speed * 1000);
465 vnet_hw_interface_set_flags (vnm, vd->hw_if_index,
466 VNET_HW_INTERFACE_FLAG_LINK_UP);
470 vd->flags &= ~VMXNET3_DEVICE_F_LINK_UP;
471 vnet_hw_interface_set_flags (vnm, vd->hw_if_index, 0);
476 vmxnet3_queue_size_valid (u16 qsz)
478 if (qsz < 64 || qsz > 4096)
486 vmxnet3_create_if (vlib_main_t * vm, vmxnet3_create_if_args_t * args)
488 vnet_main_t *vnm = vnet_get_main ();
489 vmxnet3_main_t *vmxm = &vmxnet3_main;
490 vmxnet3_device_t *vd;
491 vlib_pci_dev_handle_t h;
492 clib_error_t *error = 0;
494 if (args->rxq_size == 0)
495 args->rxq_size = VMXNET3_NUM_RX_DESC;
496 if (args->txq_size == 0)
497 args->txq_size = VMXNET3_NUM_TX_DESC;
499 if (!vmxnet3_queue_size_valid (args->rxq_size) ||
500 !vmxnet3_queue_size_valid (args->txq_size))
502 args->rv = VNET_API_ERROR_INVALID_VALUE;
504 clib_error_return (error,
505 "queue size must be <= 4096, >= 64, "
506 "and multiples of 64");
507 vlib_log (VLIB_LOG_LEVEL_ERR, vmxm->log_default, "%U: %s",
508 format_vlib_pci_addr, &args->addr,
509 "queue size must be <= 4096, >= 64, and multiples of 64");
514 pool_foreach (vd, vmxm->devices, ({
515 if (vd->pci_addr.as_u32 == args->addr.as_u32)
517 args->rv = VNET_API_ERROR_INVALID_VALUE;
519 clib_error_return (error, "PCI address in use");
520 vlib_log (VLIB_LOG_LEVEL_ERR, vmxm->log_default, "%U: %s",
521 format_vlib_pci_addr, &args->addr, "pci address in use");
527 pool_get (vmxm->devices, vd);
528 vd->dev_instance = vd - vmxm->devices;
529 vd->per_interface_next_index = ~0;
530 vd->pci_addr = args->addr;
532 if (args->enable_elog)
533 vd->flags |= VMXNET3_DEVICE_F_ELOG;
536 vlib_pci_device_open (vm, &args->addr, vmxnet3_pci_device_ids, &h)))
538 pool_put (vmxm->devices, vd);
539 args->rv = VNET_API_ERROR_INVALID_INTERFACE;
541 clib_error_return (error, "pci-addr %U", format_vlib_pci_addr,
543 vlib_log (VLIB_LOG_LEVEL_ERR, vmxm->log_default, "%U: %s",
544 format_vlib_pci_addr, &args->addr,
545 "error encountered on pci device open");
550 * Do not use vmxnet3_log_error prior to this line since the macro
551 * references vd->pci_dev_handle
553 vd->pci_dev_handle = h;
554 vd->numa_node = vlib_pci_get_numa_node (vm, h);
555 vlib_pci_set_private_data (vm, h, vd->dev_instance);
557 if ((error = vlib_pci_bus_master_enable (vm, h)))
559 vmxnet3_log_error (vd, "error encountered on pci bus master enable");
563 if ((error = vlib_pci_map_region (vm, h, 0, (void **) &vd->bar[0])))
565 vmxnet3_log_error (vd, "error encountered on pci map region for bar 0");
569 if ((error = vlib_pci_map_region (vm, h, 1, (void **) &vd->bar[1])))
571 vmxnet3_log_error (vd, "error encountered on pci map region for bar 1");
575 if ((error = vlib_pci_register_msix_handler (vm, h, 0, 1,
576 &vmxnet3_irq_0_handler)))
578 vmxnet3_log_error (vd,
579 "error encountered on pci register msix handler 0");
583 if ((error = vlib_pci_register_msix_handler (vm, h, 1, 1,
584 &vmxnet3_irq_1_handler)))
586 vmxnet3_log_error (vd,
587 "error encountered on pci register msix handler 1");
591 if ((error = vlib_pci_enable_msix_irq (vm, h, 0, 2)))
593 vmxnet3_log_error (vd, "error encountered on pci enable msix irq");
597 if ((error = vlib_pci_intr_enable (vm, h)))
599 vmxnet3_log_error (vd, "error encountered on pci interrupt enable");
603 if ((error = vmxnet3_device_init (vm, vd, args)))
605 vmxnet3_log_error (vd, "error encountered on device init");
609 /* create interface */
610 error = ethernet_register_interface (vnm, vmxnet3_device_class.index,
611 vd->dev_instance, vd->mac_addr,
612 &vd->hw_if_index, vmxnet3_flag_change);
616 vmxnet3_log_error (vd,
617 "error encountered on ethernet register interface");
621 vnet_sw_interface_t *sw = vnet_get_hw_sw_interface (vnm, vd->hw_if_index);
622 vd->sw_if_index = sw->sw_if_index;
623 args->sw_if_index = sw->sw_if_index;
625 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vd->hw_if_index);
626 hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE;
627 vnet_hw_interface_set_input_node (vnm, vd->hw_if_index,
628 vmxnet3_input_node.index);
629 vnet_hw_interface_assign_rx_thread (vnm, vd->hw_if_index, 0, ~0);
630 vnet_hw_interface_set_link_speed (vnm, vd->hw_if_index,
631 vd->link_speed * 1000);
632 if (vd->flags & VMXNET3_DEVICE_F_LINK_UP)
633 vnet_hw_interface_set_flags (vnm, vd->hw_if_index,
634 VNET_HW_INTERFACE_FLAG_LINK_UP);
636 vnet_hw_interface_set_flags (vnm, vd->hw_if_index, 0);
640 vmxnet3_delete_if (vm, vd);
641 args->rv = VNET_API_ERROR_INVALID_INTERFACE;
646 vmxnet3_delete_if (vlib_main_t * vm, vmxnet3_device_t * vd)
648 vnet_main_t *vnm = vnet_get_main ();
649 vmxnet3_main_t *vmxm = &vmxnet3_main;
653 /* Quiesce the device */
654 vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_QUIESCE_DEV);
656 /* Reset the device */
657 vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_RESET_DEV);
661 vnet_hw_interface_set_flags (vnm, vd->hw_if_index, 0);
662 vnet_hw_interface_unassign_rx_thread (vnm, vd->hw_if_index, 0);
663 ethernet_delete_interface (vnm, vd->hw_if_index);
666 vlib_pci_device_close (vm, vd->pci_dev_handle);
669 vec_foreach_index (i, vd->rxqs)
671 vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, i);
672 u16 mask = rxq->size - 1;
675 for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
677 vmxnet3_rx_ring *ring;
679 ring = &rxq->rx_ring[rid];
680 desc_idx = (ring->consume + 1) & mask;
681 vlib_buffer_free_from_ring (vm, ring->bufs, desc_idx, rxq->size,
683 vec_free (ring->bufs);
684 vlib_physmem_free (vm, rxq->rx_desc[rid]);
686 vlib_physmem_free (vm, rxq->rx_comp);
692 vec_foreach_index (i, vd->txqs)
694 vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, i);
695 u16 mask = txq->size - 1;
698 desc_idx = txq->tx_ring.consume;
699 end_idx = txq->tx_ring.produce;
700 while (desc_idx != end_idx)
702 bi = txq->tx_ring.bufs[desc_idx];
703 vlib_buffer_free_no_next (vm, &bi, 1);
707 clib_spinlock_free (&txq->lock);
708 vec_free (txq->tx_ring.bufs);
709 vlib_physmem_free (vm, txq->tx_desc);
710 vlib_physmem_free (vm, txq->tx_comp);
715 vlib_physmem_free (vm, vd->dma);
717 clib_error_free (vd->error);
718 clib_memset (vd, 0, sizeof (*vd));
719 pool_put (vmxm->devices, vd);
723 * fd.io coding-style-patch-verification: ON
726 * eval: (c-set-style "gnu")