dpdk: Only use vmbus on Linux
[vpp.git] / src / plugins / dpdk / device / init.c
index b76455b..07e5225 100644 (file)
@@ -187,9 +187,11 @@ dpdk_find_startup_config (struct rte_eth_dev_info *di)
 {
   dpdk_main_t *dm = &dpdk_main;
   struct rte_pci_device *pci_dev;
-  struct rte_vmbus_device *vmbus_dev;
   vlib_pci_addr_t pci_addr;
+#ifdef __linux__
+  struct rte_vmbus_device *vmbus_dev;
   vlib_vmbus_addr_t vmbus_addr;
+#endif /* __linux__ */
   uword *p = 0;
 
   if ((pci_dev = dpdk_get_pci_device (di)))
@@ -202,6 +204,7 @@ dpdk_find_startup_config (struct rte_eth_dev_info *di)
        hash_get (dm->conf->device_config_index_by_pci_addr, pci_addr.as_u32);
     }
 
+#ifdef __linux__
   if ((vmbus_dev = dpdk_get_vmbus_device (di)))
     {
       unformat_input_t input_vmbus;
@@ -216,6 +219,7 @@ dpdk_find_startup_config (struct rte_eth_dev_info *di)
                       &vmbus_addr);
       unformat_free (&input_vmbus);
     }
+#endif /* __linux__ */
 
   if (p)
     return pool_elt_at_index (dm->conf->dev_confs, p[0]);
@@ -458,7 +462,7 @@ dpdk_lib_init (dpdk_main_t * dm)
        hi->numa_node = xd->cpu_socket = numa_node;
       sw = vnet_get_hw_sw_interface (vnm, xd->hw_if_index);
       xd->sw_if_index = sw->sw_if_index;
-      dpdk_log_debug ("[%u] interface %s created", port_id, hi->name);
+      dpdk_log_debug ("[%u] interface %v created", port_id, hi->name);
 
       if (devconf->tag)
        vnet_set_sw_interface_tag (vnm, devconf->tag, sw->sw_if_index);
@@ -548,7 +552,6 @@ dpdk_bind_devices_to_uio (dpdk_config_main_t * conf)
   int i;
 
   addrs = vlib_pci_get_all_dev_addrs ();
-  /* *INDENT-OFF* */
   vec_foreach (addr, addrs)
     {
     dpdk_device_config_t * devconf = 0;
@@ -641,7 +644,8 @@ dpdk_bind_devices_to_uio (dpdk_config_main_t * conf)
             (d->device_id == 0x0443 || d->device_id == 0x18a1 ||
              d->device_id == 0x19e3 || d->device_id == 0x37c9 ||
              d->device_id == 0x6f55 || d->device_id == 0x18ef ||
-             d->device_id == 0x4941))
+             d->device_id == 0x4941 || d->device_id == 0x4943 ||
+             d->device_id == 0x4945))
       ;
     /* Cisco VIC */
     else if (d->vendor_id == 0x1137 &&
@@ -733,7 +737,6 @@ dpdk_bind_devices_to_uio (dpdk_config_main_t * conf)
        clib_error_report (error);
       }
   }
-  /* *INDENT-ON* */
   vec_free (pci_addr);
   vlib_pci_free_device_info (d);
 }
@@ -748,7 +751,6 @@ dpdk_bind_vmbus_devices_to_uio (dpdk_config_main_t * conf)
 
   addrs = vlib_vmbus_get_all_dev_addrs ();
 
-  /* *INDENT-OFF* */
   vec_foreach (addr, addrs)
     {
       dpdk_device_config_t *devconf = 0;
@@ -813,7 +815,6 @@ dpdk_bind_vmbus_devices_to_uio (dpdk_config_main_t * conf)
          clib_error_report (error);
        }
     }
-  /* *INDENT-ON* */
 }
 
 uword
@@ -1008,6 +1009,26 @@ dpdk_log_read_ready (clib_file_t * uf)
   return 0;
 }
 
+static clib_error_t *
+dpdk_set_stat_poll_interval (f64 interval)
+{
+  if (interval < DPDK_MIN_STATS_POLL_INTERVAL)
+    return clib_error_return (0, "wrong stats-poll-interval value");
+
+  dpdk_main.stat_poll_interval = interval;
+  return 0;
+}
+
+static clib_error_t *
+dpdk_set_link_state_poll_interval (f64 interval)
+{
+  if (interval < DPDK_MIN_LINK_POLL_INTERVAL)
+    return clib_error_return (0, "wrong link-state-poll-interval value");
+
+  dpdk_main.link_state_poll_interval = interval;
+  return 0;
+}
+
 static clib_error_t *
 dpdk_config (vlib_main_t * vm, unformat_input_t * input)
 {
@@ -1032,6 +1053,7 @@ dpdk_config (vlib_main_t * vm, unformat_input_t * input)
   u32 vendor, device, domain, bus, func;
   void *fmt_func;
   void *fmt_addr;
+  f64 poll_interval;
 
   huge_dir_path =
     format (0, "%s/hugepages%c", vlib_unix_get_runtime_dir (), 0);
@@ -1070,6 +1092,18 @@ dpdk_config (vlib_main_t * vm, unformat_input_t * input)
       else if (unformat (input, "max-simd-bitwidth %U",
                         unformat_max_simd_bitwidth, &conf->max_simd_bitwidth))
        ;
+      else if (unformat (input, "link-state-poll-interval %f", &poll_interval))
+       {
+         error = dpdk_set_link_state_poll_interval (poll_interval);
+         if (error != 0)
+           return error;
+       }
+      else if (unformat (input, "stats-poll-interval %f", &poll_interval))
+       {
+         error = dpdk_set_stat_poll_interval (poll_interval);
+         if (error != 0)
+           return error;
+       }
       else if (unformat (input, "dev default %U", unformat_vlib_cli_sub_input,
                         &sub_input))
        {
@@ -1220,7 +1254,6 @@ dpdk_config (vlib_main_t * vm, unformat_input_t * input)
 
       default_hugepage_sz = clib_mem_get_default_hugepage_size ();
 
-      /* *INDENT-OFF* */
       clib_bitmap_foreach (x, tm->cpu_socket_bitmap)
        {
          clib_error_t *e;
@@ -1233,7 +1266,6 @@ dpdk_config (vlib_main_t * vm, unformat_input_t * input)
          if ((e = clib_sysfs_prealloc_hugepages(x, 0, n_pages)))
            clib_error_report (e);
         }
-      /* *INDENT-ON* */
     }
 
   /* on/off dpdk's telemetry thread */
@@ -1498,16 +1530,17 @@ dpdk_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
     dpdk_update_link_state (xd, now);
   }
 
+  f64 timeout =
+    clib_min (dm->link_state_poll_interval, dm->stat_poll_interval);
+
   while (1)
     {
-      /*
-       * check each time through the loop in case intervals are changed
-       */
-      f64 min_wait = dm->link_state_poll_interval < dm->stat_poll_interval ?
-       dm->link_state_poll_interval : dm->stat_poll_interval;
-
+      f64 min_wait = clib_max (timeout, DPDK_MIN_POLL_INTERVAL);
       vlib_process_wait_for_event_or_clock (vm, min_wait);
 
+      timeout =
+       clib_min (dm->link_state_poll_interval, dm->stat_poll_interval);
+
       if (dm->admin_up_down_in_progress)
        /* skip the poll if an admin up down is in progress (on any interface) */
        continue;
@@ -1521,19 +1554,25 @@ dpdk_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
          dpdk_update_link_state (xd, now);
 
       }
-    }
 
+      now = vlib_time_now (vm);
+      vec_foreach (xd, dm->devices)
+       {
+         timeout = clib_min (timeout, xd->time_last_stats_update +
+                                        dm->stat_poll_interval - now);
+         timeout = clib_min (timeout, xd->time_last_link_update +
+                                        dm->link_state_poll_interval - now);
+       }
+    }
   return 0;
 }
 
-/* *INDENT-OFF* */
 VLIB_REGISTER_NODE (dpdk_process_node,static) = {
     .function = dpdk_process,
     .type = VLIB_NODE_TYPE_PROCESS,
     .name = "dpdk-process",
     .process_log2_n_stack_bytes = 17,
 };
-/* *INDENT-ON* */
 
 static clib_error_t *
 dpdk_init (vlib_main_t * vm)