misc: remove GNU Indent directives
[vpp.git] / src / plugins / vmxnet3 / vmxnet3.c
index de10023..e64e0d1 100644 (file)
@@ -19,7 +19,8 @@
 #include <vnet/ethernet/ethernet.h>
 #include <vnet/plugin/plugin.h>
 #include <vpp/app/version.h>
-
+#include <vnet/interface/rx_queue_funcs.h>
+#include <vnet/interface/tx_queue_funcs.h>
 #include <vmxnet3/vmxnet3.h>
 
 #define PCI_VENDOR_ID_VMWARE                           0x15ad
@@ -62,17 +63,29 @@ vmxnet3_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index,
 
 static clib_error_t *
 vmxnet3_interface_rx_mode_change (vnet_main_t * vnm, u32 hw_if_index, u32 qid,
-                                 vnet_hw_interface_rx_mode mode)
+                                 vnet_hw_if_rx_mode mode)
 {
   vmxnet3_main_t *vmxm = &vmxnet3_main;
   vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
   vmxnet3_device_t *vd = pool_elt_at_index (vmxm->devices, hw->dev_instance);
   vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, qid);
+  vmxnet3_per_thread_data_t *ptd;
 
-  if (mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
-    rxq->int_mode = 0;
+  if (mode == rxq->mode)
+    return 0;
+  if ((mode != VNET_HW_IF_RX_MODE_POLLING) &&
+      (mode != VNET_HW_IF_RX_MODE_INTERRUPT))
+    return clib_error_return (0, "Rx mode %U not supported",
+                             format_vnet_hw_if_rx_mode, mode);
+  rxq->mode = mode;
+  ptd = vec_elt_at_index (vmxm->per_thread_data, rxq->thread_index);
+  if (rxq->mode == VNET_HW_IF_RX_MODE_POLLING)
+    ptd->polling_q_count++;
   else
-    rxq->int_mode = 1;
+    {
+      ASSERT (ptd->polling_q_count != 0);
+      ptd->polling_q_count--;
+    }
 
   return 0;
 }
@@ -132,7 +145,6 @@ static char *vmxnet3_tx_func_error_strings[] = {
 #undef _
 };
 
-/* *INDENT-OFF* */
 VNET_DEVICE_CLASS (vmxnet3_device_class,) =
 {
   .name = "VMXNET3 interface",
@@ -145,7 +157,6 @@ VNET_DEVICE_CLASS (vmxnet3_device_class,) =
   .tx_function_n_errors = VMXNET3_TX_N_ERROR,
   .tx_function_error_strings = vmxnet3_tx_func_error_strings,
 };
-/* *INDENT-ON* */
 
 static u32
 vmxnet3_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hw, u32 flags)
@@ -220,7 +231,7 @@ vmxnet3_provision_driver_shared (vlib_main_t * vm, vmxnet3_device_t * vd)
   shared->misc.guest_info |= VMXNET3_GOS_TYPE_LINUX;
   shared->misc.version_support = VMXNET3_VERSION_SELECT;
   shared->misc.upt_features = VMXNET3_F_RXCSUM;
-  if (vd->lro_enable)
+  if (vd->gso_enable)
     shared->misc.upt_features |= VMXNET3_F_LRO;
   if (vd->num_rx_queues > 1)
     {
@@ -287,6 +298,7 @@ vmxnet3_rxq_init (vlib_main_t * vm, vmxnet3_device_t * vd, u16 qid, u16 qsz)
   rxq = vec_elt_at_index (vd->rxqs, qid);
   clib_memset (rxq, 0, sizeof (*rxq));
   rxq->size = qsz;
+  rxq->mode = VNET_HW_IF_RX_MODE_POLLING;
   for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
     {
       rxq->rx_desc[rid] = vlib_physmem_alloc_aligned_on_numa
@@ -325,23 +337,15 @@ vmxnet3_txq_init (vlib_main_t * vm, vmxnet3_device_t * vd, u16 qid, u16 qsz)
   vmxnet3_tx_stats *txs;
   u32 size;
 
-  if (qid >= vd->num_tx_queues)
-    {
-      qid = qid % vd->num_tx_queues;
-      txq = vec_elt_at_index (vd->txqs, qid);
-      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);
+  txq = vec_elt_at_index (vd->txqs, qid);
+  clib_memset (txq, 0, sizeof (*txq));
+  clib_spinlock_init (&txq->lock);
 
   vec_validate (vd->tx_stats, qid);
   txs = vec_elt_at_index (vd->tx_stats, qid);
   clib_memset (txs, 0, sizeof (*txs));
 
-  vec_validate_aligned (vd->txqs, qid, CLIB_CACHE_LINE_BYTES);
-  txq = vec_elt_at_index (vd->txqs, qid);
-  clib_memset (txq, 0, sizeof (*txq));
   txq->size = qsz;
   txq->reg_txprod = qid * 8 + VMXNET3_REG_TXPROD;
 
@@ -351,7 +355,7 @@ vmxnet3_txq_init (vlib_main_t * vm, vmxnet3_device_t * vd, u16 qid, u16 qsz)
   if (txq->tx_desc == 0)
     return vlib_physmem_last_error (vm);
 
-  memset (txq->tx_desc, 0, size);
+  clib_memset (txq->tx_desc, 0, size);
 
   size = qsz * sizeof (*txq->tx_comp);
   txq->tx_comp =
@@ -405,11 +409,8 @@ static clib_error_t *
 vmxnet3_device_init (vlib_main_t * vm, vmxnet3_device_t * vd,
                     vmxnet3_create_if_args_t * args)
 {
-  vnet_main_t *vnm = vnet_get_main ();
-  vmxnet3_main_t *vmxm = &vmxnet3_main;
   clib_error_t *error = 0;
   u32 ret, i, size;
-  vlib_thread_main_t *tm = vlib_get_thread_main ();
 
   /* Quiesce the device */
   vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_QUIESCE_DEV);
@@ -453,11 +454,19 @@ vmxnet3_device_init (vlib_main_t * vm, vmxnet3_device_t * vd,
       return error;
     }
 
-  /* LRO is only supported for version >= 3 */
-  if ((vmxm->lro_configured) && (vd->version >= 3))
+  /* GSO is only supported for version >= 3 */
+  if (args->enable_gso)
     {
-      vd->lro_enable = 1;
-      vnm->interface_main.gso_interface_count++;
+      if (vd->version >= 3)
+       vd->gso_enable = 1;
+      else
+       {
+         error =
+           clib_error_return (0,
+                              "GSO is not supported because hardware version"
+                              " is %u. It must be >= 3", vd->version);
+         return error;
+       }
     }
 
   vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_GET_LINK);
@@ -500,7 +509,7 @@ vmxnet3_device_init (vlib_main_t * vm, vmxnet3_device_t * vd,
        return error;
     }
 
-  for (i = 0; i < tm->n_vlib_mains; i++)
+  for (i = 0; i < vd->num_tx_queues; i++)
     {
       error = vmxnet3_txq_init (vm, vd, i, args->txq_size);
       if (error)
@@ -534,9 +543,15 @@ vmxnet3_rxq_irq_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
   uword pd = vlib_pci_get_private_data (vm, h);
   vmxnet3_device_t *vd = pool_elt_at_index (vmxm->devices, pd);
   u16 qid = line;
+  vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, qid);
 
-  if (vec_len (vd->rxqs) > qid && vd->rxqs[qid].int_mode != 0)
-    vnet_device_input_set_interrupt_pending (vnm, vd->hw_if_index, qid);
+  if (vec_len (vd->rxqs) > qid && (rxq->mode != VNET_HW_IF_RX_MODE_POLLING))
+    {
+      vmxnet3_per_thread_data_t *ptd =
+       vec_elt_at_index (vmxm->per_thread_data, rxq->thread_index);
+      if (ptd->polling_q_count == 0)
+       vnet_hw_if_rx_queue_set_int_pending (vnm, rxq->queue_index);
+    }
 }
 
 static void
@@ -555,8 +570,9 @@ vmxnet3_event_irq_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h,
     {
       vd->flags |= VMXNET3_DEVICE_F_LINK_UP;
       vd->link_speed = ret >> 16;
-      vnet_hw_interface_set_link_speed (vnm, vd->hw_if_index,
-                                       vd->link_speed * 1000);
+      vnet_hw_interface_set_link_speed (
+       vnm, vd->hw_if_index,
+       (vd->link_speed == UINT32_MAX) ? UINT32_MAX : vd->link_speed * 1000);
       vnet_hw_interface_set_flags (vnm, vd->hw_if_index,
                                   VNET_HW_INTERFACE_FLAG_LINK_UP);
     }
@@ -600,8 +616,11 @@ vmxnet3_create_if (vlib_main_t * vm, vmxnet3_create_if_args_t * args)
 {
   vnet_main_t *vnm = vnet_get_main ();
   vmxnet3_main_t *vmxm = &vmxnet3_main;
+  vnet_eth_interface_registration_t eir = {};
+
   vmxnet3_device_t *vd;
   vlib_pci_dev_handle_t h;
+  vnet_hw_if_caps_change_t cc = {};
   clib_error_t *error = 0;
   u16 qid;
   u32 num_intr;
@@ -654,8 +673,7 @@ vmxnet3_create_if (vlib_main_t * vm, vmxnet3_create_if_args_t * args)
       return;
     }
 
-  /* *INDENT-OFF* */
-  pool_foreach (vd, vmxm->devices, ({
+  pool_foreach (vd, vmxm->devices)  {
     if (vd->pci_addr.as_u32 == args->addr.as_u32)
       {
        args->rv = VNET_API_ERROR_ADDRESS_IN_USE;
@@ -666,12 +684,12 @@ vmxnet3_create_if (vlib_main_t * vm, vmxnet3_create_if_args_t * args)
                  format_vlib_pci_addr, &args->addr, "pci address in use");
        return;
       }
-  }));
-  /* *INDENT-ON* */
+  }
 
   if (args->bind)
     {
-      error = vlib_pci_bind_to_uio (vm, &args->addr, (char *) "auto");
+      error = vlib_pci_bind_to_uio (vm, &args->addr, (char *) "auto",
+                                   VMXNET3_BIND_FORCE == args->bind);
       if (error)
        {
          args->rv = VNET_API_ERROR_INVALID_INTERFACE;
@@ -744,6 +762,10 @@ vmxnet3_create_if (vlib_main_t * vm, vmxnet3_create_if_args_t * args)
       vmxnet3_log_error (vd,
                         "No sufficient interrupt lines (%u) for rx queues",
                         num_intr);
+      error =
+       clib_error_return (0,
+                          "No sufficient interrupt lines (%u) for rx queues",
+                          num_intr);
       goto error;
     }
   if ((error = vlib_pci_register_msix_handler (vm, h, 0, vd->num_rx_queues,
@@ -781,50 +803,71 @@ vmxnet3_create_if (vlib_main_t * vm, vmxnet3_create_if_args_t * args)
     }
 
   /* create interface */
-  error = ethernet_register_interface (vnm, vmxnet3_device_class.index,
-                                      vd->dev_instance, vd->mac_addr,
-                                      &vd->hw_if_index, vmxnet3_flag_change);
-
-  if (error)
-    {
-      vmxnet3_log_error (vd,
-                        "error encountered on ethernet register interface");
-      goto error;
-    }
+  eir.dev_class_index = vmxnet3_device_class.index;
+  eir.dev_instance = vd->dev_instance;
+  eir.address = vd->mac_addr;
+  eir.cb.flag_change = vmxnet3_flag_change;
+  vd->hw_if_index = vnet_eth_register_interface (vnm, &eir);
 
   vnet_sw_interface_t *sw = vnet_get_hw_sw_interface (vnm, vd->hw_if_index);
   vd->sw_if_index = sw->sw_if_index;
   args->sw_if_index = sw->sw_if_index;
 
-  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, vd->hw_if_index);
-  hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE;
-  if (vd->lro_enable)
-    hw->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO;
+  cc.mask = VNET_HW_IF_CAP_INT_MODE | VNET_HW_IF_CAP_TCP_GSO |
+           VNET_HW_IF_CAP_TX_TCP_CKSUM | VNET_HW_IF_CAP_TX_UDP_CKSUM;
+  if (vd->gso_enable)
+    cc.val = cc.mask;
+  else
+    cc.val = VNET_HW_IF_CAP_INT_MODE;
+
+  vnet_hw_if_change_caps (vnm, vd->hw_if_index, &cc);
 
-  vnet_hw_interface_set_input_node (vnm, vd->hw_if_index,
-                                   vmxnet3_input_node.index);
+  vnet_hw_if_set_input_node (vnm, vd->hw_if_index, vmxnet3_input_node.index);
   /* Disable interrupts */
   vmxnet3_disable_interrupt (vd);
   vec_foreach_index (qid, vd->rxqs)
   {
     vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, qid);
-    u32 thread_index;
-    u32 numa_node;
-
-    vnet_hw_interface_assign_rx_thread (vnm, vd->hw_if_index, qid, ~0);
-    thread_index = vnet_get_device_input_thread_index (vnm, vd->hw_if_index,
-                                                      qid);
-    numa_node = vlib_mains[thread_index]->numa_node;
+    u32 qi, fi;
+    vmxnet3_per_thread_data_t *ptd;
+
+    qi = vnet_hw_if_register_rx_queue (vnm, vd->hw_if_index, qid,
+                                      VNET_HW_IF_RXQ_THREAD_ANY);
+    fi = vlib_pci_get_msix_file_index (vm, vd->pci_dev_handle, qid);
+    vnet_hw_if_set_rx_queue_file_index (vnm, qi, fi);
+    rxq->queue_index = qi;
+    rxq->thread_index =
+      vnet_hw_if_get_rx_queue_thread_index (vnm, rxq->queue_index);
+    if (rxq->mode == VNET_HW_IF_RX_MODE_POLLING)
+      {
+       ptd = vec_elt_at_index (vmxm->per_thread_data, rxq->thread_index);
+       ptd->polling_q_count++;
+      }
     rxq->buffer_pool_index =
-      vlib_buffer_pool_get_default_for_numa (vm, numa_node);
+      vnet_hw_if_get_rx_queue_numa_node (vnm, rxq->queue_index);
     vmxnet3_rxq_refill_ring0 (vm, vd, rxq);
     vmxnet3_rxq_refill_ring1 (vm, vd, rxq);
   }
+
+  vec_foreach_index (qid, vd->txqs)
+    {
+      vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, qid);
+      txq->queue_index =
+       vnet_hw_if_register_tx_queue (vnm, vd->hw_if_index, qid);
+    }
+  for (u32 i = 0; i < vlib_get_n_threads (); i++)
+    {
+      u32 qi = vd->txqs[i % vd->num_tx_queues].queue_index;
+      vnet_hw_if_tx_queue_assign_thread (vnm, qi, i);
+    }
+  vnet_hw_if_update_runtime_data (vnm, vd->hw_if_index);
+
   vd->flags |= VMXNET3_DEVICE_F_INITIALIZED;
   vmxnet3_enable_interrupt (vd);
 
-  vnet_hw_interface_set_link_speed (vnm, vd->hw_if_index,
-                                   vd->link_speed * 1000);
+  vnet_hw_interface_set_link_speed (
+    vnm, vd->hw_if_index,
+    (vd->link_speed == UINT32_MAX) ? UINT32_MAX : vd->link_speed * 1000);
   if (vd->flags & VMXNET3_DEVICE_F_LINK_UP)
     vnet_hw_interface_set_flags (vnm, vd->hw_if_index,
                                 VNET_HW_INTERFACE_FLAG_LINK_UP);
@@ -844,7 +887,7 @@ vmxnet3_delete_if (vlib_main_t * vm, vmxnet3_device_t * vd)
   vnet_main_t *vnm = vnet_get_main ();
   vmxnet3_main_t *vmxm = &vmxnet3_main;
   u32 i, bi;
-  u16 desc_idx, qid;
+  u16 desc_idx;
 
   /* Quiesce the device */
   vmxnet3_reg_write (vd, 1, VMXNET3_REG_CMD, VMXNET3_CMD_QUIESCE_DEV);
@@ -855,20 +898,24 @@ vmxnet3_delete_if (vlib_main_t * vm, vmxnet3_device_t * vd)
   if (vd->hw_if_index)
     {
       vnet_hw_interface_set_flags (vnm, vd->hw_if_index, 0);
-      vec_foreach_index (qid, vd->rxqs)
-       vnet_hw_interface_unassign_rx_thread (vnm, vd->hw_if_index, qid);
       ethernet_delete_interface (vnm, vd->hw_if_index);
     }
 
   vlib_pci_device_close (vm, vd->pci_dev_handle);
 
-  /* *INDENT-OFF* */
   vec_foreach_index (i, vd->rxqs)
     {
       vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, i);
       u16 mask = rxq->size - 1;
       u16 rid;
+      vmxnet3_per_thread_data_t *ptd =
+       vec_elt_at_index (vmxm->per_thread_data, rxq->thread_index);
 
+      if (rxq->mode == VNET_HW_IF_RX_MODE_POLLING)
+       {
+         ASSERT (ptd->polling_q_count != 0);
+         ptd->polling_q_count--;
+       }
       for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
        {
          vmxnet3_rx_ring *ring;
@@ -882,11 +929,9 @@ vmxnet3_delete_if (vlib_main_t * vm, vmxnet3_device_t * vd)
        }
       vlib_physmem_free (vm, rxq->rx_comp);
     }
-  /* *INDENT-ON* */
   vec_free (vd->rxqs);
   vec_free (vd->rx_stats);
 
-  /* *INDENT-OFF* */
   vec_foreach_index (i, vd->txqs)
     {
       vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, i);
@@ -907,7 +952,6 @@ vmxnet3_delete_if (vlib_main_t * vm, vmxnet3_device_t * vd)
       vlib_physmem_free (vm, txq->tx_desc);
       vlib_physmem_free (vm, txq->tx_comp);
     }
-  /* *INDENT-ON* */
   vec_free (vd->txqs);
   vec_free (vd->tx_stats);
 
@@ -919,8 +963,6 @@ vmxnet3_delete_if (vlib_main_t * vm, vmxnet3_device_t * vd)
   clib_memset (vd, 0, sizeof (*vd));
   pool_put (vmxm->devices, vd);
 
-  if (vd->lro_enable)
-    vnm->interface_main.gso_interface_count--;
 }
 
 /*