vmxnet3: coverity woe
[vpp.git] / src / plugins / vmxnet3 / vmxnet3.c
index 74e6003..ac99411 100644 (file)
@@ -185,6 +185,7 @@ vmxnet3_provision_driver_shared (vlib_main_t * vm, vmxnet3_device_t * vd)
   shared->misc.num_tx_queues = vd->num_tx_queues;
   shared->misc.num_rx_queues = vd->num_rx_queues;
   shared->interrupt.num_intrs = vd->num_intrs;
+  shared->interrupt.event_intr_index = 1;
   shared->interrupt.control = VMXNET3_IC_DISABLE_ALL;
   shared->rx_filter.mode = VMXNET3_RXMODE_UCAST | VMXNET3_RXMODE_BCAST |
     VMXNET3_RXMODE_ALL_MULTI;
@@ -252,6 +253,7 @@ vmxnet3_rxq_init (vlib_main_t * vm, vmxnet3_device_t * vd, u16 qid, u16 qsz)
 
       ring = &rxq->rx_ring[rid];
       ring->gen = VMXNET3_RXF_GEN;
+      ring->rid = rid;
       vec_validate_aligned (ring->bufs, rxq->size, CLIB_CACHE_LINE_BYTES);
     }
   rxq->rx_comp_ring.gen = VMXNET3_RXCF_GEN;
@@ -273,6 +275,7 @@ vmxnet3_txq_init (vlib_main_t * vm, vmxnet3_device_t * vd, u16 qid, u16 qsz)
       if (txq->lock == 0)
        clib_spinlock_init (&txq->lock);
       vd->flags |= VMXNET3_DEVICE_F_SHARED_TXQ_LOCK;
+      return 0;
     }
 
   vec_validate_aligned (vd->txqs, qid, CLIB_CACHE_LINE_BYTES);
@@ -309,7 +312,7 @@ vmxnet3_device_init (vlib_main_t * vm, vmxnet3_device_t * vd,
 
   vd->num_tx_queues = 1;
   vd->num_rx_queues = 1;
-  vd->num_intrs = 1;
+  vd->num_intrs = 2;
 
   /* Quiesce the device */
   vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_QUIESCE_DEV);
@@ -351,6 +354,18 @@ vmxnet3_device_init (vlib_main_t * vm, vmxnet3_device_t * vd,
       return error;
     }
 
+  vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_GET_LINK);
+  ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_CMD);
+  if (ret & 1)
+    {
+      vd->flags |= VMXNET3_DEVICE_F_LINK_UP;
+      vd->link_speed = ret >> 16;
+    }
+  else
+    {
+      vd->flags &= ~VMXNET3_DEVICE_F_LINK_UP;
+    }
+
   /* Get the mac address */
   ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_MACL);
   clib_memcpy (vd->mac_addr, &ret, 4);
@@ -413,7 +428,7 @@ vmxnet3_device_init (vlib_main_t * vm, vmxnet3_device_t * vd,
 }
 
 static void
-vmxnet3_irq_handler (vlib_pci_dev_handle_t h, u16 line)
+vmxnet3_irq_0_handler (vlib_pci_dev_handle_t h, u16 line)
 {
   vnet_main_t *vnm = vnet_get_main ();
   vmxnet3_main_t *vmxm = &vmxnet3_main;
@@ -425,6 +440,31 @@ vmxnet3_irq_handler (vlib_pci_dev_handle_t h, u16 line)
     vnet_device_input_set_interrupt_pending (vnm, vd->hw_if_index, qid);
 }
 
+static void
+vmxnet3_irq_1_handler (vlib_pci_dev_handle_t h, u16 line)
+{
+  vnet_main_t *vnm = vnet_get_main ();
+  vmxnet3_main_t *vmxm = &vmxnet3_main;
+  uword pd = vlib_pci_get_private_data (h);
+  vmxnet3_device_t *vd = pool_elt_at_index (vmxm->devices, pd);
+  u32 ret;
+
+  vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_GET_LINK);
+  ret = vmxnet3_reg_read (vd, 1, VMXNET3_REG_CMD);
+  if (ret & 1)
+    {
+      vd->flags |= VMXNET3_DEVICE_F_LINK_UP;
+      vd->link_speed = ret >> 16;
+      vnet_hw_interface_set_flags (vnm, vd->hw_if_index,
+                                  VNET_HW_INTERFACE_FLAG_LINK_UP);
+    }
+  else
+    {
+      vd->flags &= ~VMXNET3_DEVICE_F_LINK_UP;
+      vnet_hw_interface_set_flags (vnm, vd->hw_if_index, 0);
+    }
+}
+
 static u8
 vmxnet3_queue_size_valid (u16 qsz)
 {
@@ -504,10 +544,14 @@ vmxnet3_create_if (vlib_main_t * vm, vmxnet3_create_if_args_t * args)
     goto error;
 
   if ((error = vlib_pci_register_msix_handler (h, 0, 1,
-                                              &vmxnet3_irq_handler)))
+                                              &vmxnet3_irq_0_handler)))
     goto error;
 
-  if ((error = vlib_pci_enable_msix_irq (h, 0, 1)))
+  if ((error = vlib_pci_register_msix_handler (h, 1, 1,
+                                              &vmxnet3_irq_1_handler)))
+    goto error;
+
+  if ((error = vlib_pci_enable_msix_irq (h, 0, 2)))
     goto error;
 
   if ((error = vlib_pci_intr_enable (h)))
@@ -533,6 +577,11 @@ vmxnet3_create_if (vlib_main_t * vm, vmxnet3_create_if_args_t * args)
   vnet_hw_interface_set_input_node (vnm, vd->hw_if_index,
                                    vmxnet3_input_node.index);
   vnet_hw_interface_assign_rx_thread (vnm, vd->hw_if_index, 0, ~0);
+  if (vd->flags & VMXNET3_DEVICE_F_LINK_UP)
+    vnet_hw_interface_set_flags (vnm, vd->hw_if_index,
+                                VNET_HW_INTERFACE_FLAG_LINK_UP);
+  else
+    vnet_hw_interface_set_flags (vnm, vd->hw_if_index, 0);
   return;
 
 error:
@@ -576,15 +625,9 @@ vmxnet3_delete_if (vlib_main_t * vm, vmxnet3_device_t * vd)
          vmxnet3_rx_ring *ring;
 
          ring = &rxq->rx_ring[rid];
-         desc_idx = ring->consume;
-         while (ring->fill)
-           {
-             desc_idx &= mask;
-             bi = ring->bufs[desc_idx];
-             vlib_buffer_free_no_next (vm, &bi, 1);
-             ring->fill--;
-             desc_idx++;
-           }
+         desc_idx = (ring->consume + 1) & mask;
+         vlib_buffer_free_from_ring (vm, ring->bufs, desc_idx, rxq->size,
+                                     ring->fill);
          vec_free (ring->bufs);
          vlib_physmem_free (vm, vmxm->physmem_region, rxq->rx_desc[rid]);
        }