acl-plugin: refactor the "show acl-plugin" CLI, use vlib_cli_output() vs. format()
[vpp.git] / src / plugins / dpdk / device / common.c
index df52c58..c65cec6 100644 (file)
@@ -78,8 +78,11 @@ dpdk_device_setup (dpdk_device_t * xd)
        dpdk_device_error (xd, "rte_eth_tx_queue_setup", rv);
     }
 
+  vec_validate_aligned (xd->buffer_pool_for_queue, xd->rx_q_used - 1,
+                       CLIB_CACHE_LINE_BYTES);
   for (j = 0; j < xd->rx_q_used; j++)
     {
+      dpdk_mempool_private_t *privp;
       uword tidx = vnet_get_device_input_thread_index (dm->vnet_main,
                                                       xd->hw_if_index, j);
       unsigned lcore = vlib_worker_threads[tidx].lcore_id;
@@ -95,6 +98,9 @@ dpdk_device_setup (dpdk_device_t * xd)
                                     SOCKET_ID_ANY, 0,
                                     dm->pktmbuf_pools[socket_id]);
 
+      privp = rte_mempool_get_priv (dm->pktmbuf_pools[socket_id]);
+      xd->buffer_pool_for_queue[j] = privp->buffer_pool_index;
+
       if (rv < 0)
        dpdk_device_error (xd, "rte_eth_rx_queue_setup", rv);
     }
@@ -181,19 +187,76 @@ dpdk_device_stop (dpdk_device_t * xd)
     }
 }
 
-void
-dpdk_port_state_callback (uint8_t port_id,
-                         enum rte_eth_event_type type, void *param)
+/* Even type for send_garp_na_process */
+enum
+{
+  SEND_GARP_NA = 1,
+} dpdk_send_garp_na_process_event_t;
+
+static vlib_node_registration_t send_garp_na_proc_node;
+
+static uword
+send_garp_na_process (vlib_main_t * vm,
+                     vlib_node_runtime_t * rt, vlib_frame_t * f)
+{
+  vnet_main_t *vnm = vnet_get_main ();
+  uword event_type, *event_data = 0;
+
+  while (1)
+    {
+      u32 i;
+      uword dpdk_port;
+      vlib_process_wait_for_event (vm);
+      event_type = vlib_process_get_events (vm, &event_data);
+      ASSERT (event_type == SEND_GARP_NA);
+      for (i = 0; i < vec_len (event_data); i++)
+       {
+         dpdk_port = event_data[i];
+         if (i < 5)            /* wait 0.2 sec for link to settle, max total 1 sec */
+           vlib_process_suspend (vm, 0.2);
+         dpdk_device_t *xd = &dpdk_main.devices[dpdk_port];
+         u32 hw_if_index = xd->hw_if_index;
+         vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
+         dpdk_update_link_state (xd, vlib_time_now (vm));
+         send_ip4_garp (vm, hi);
+         send_ip6_na (vm, hi);
+       }
+      vec_reset_length (event_data);
+    }
+  return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (send_garp_na_proc_node, static) = {
+    .function = send_garp_na_process,
+    .type = VLIB_NODE_TYPE_PROCESS,
+    .name = "send-garp-na-process",
+};
+/* *INDENT-ON* */
+
+void vl_api_force_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
+
+static void
+garp_na_proc_callback (uword * dpdk_port)
 {
-  struct rte_eth_link link;
   vlib_main_t *vm = vlib_get_main ();
+  ASSERT (vlib_get_thread_index () == 0);
+  vlib_process_signal_event
+    (vm, send_garp_na_proc_node.index, SEND_GARP_NA, *dpdk_port);
+}
+
+always_inline int
+dpdk_port_state_callback_inline (uint8_t port_id,
+                                enum rte_eth_event_type type, void *param)
+{
+  struct rte_eth_link link;
   dpdk_device_t *xd = &dpdk_main.devices[port_id];
 
   RTE_SET_USED (param);
   if (type != RTE_ETH_EVENT_INTR_LSC)
     {
       clib_warning ("Unknown event %d received for port %d", type, port_id);
-      return;
+      return -1;
     }
 
   rte_eth_link_get_nowait (port_id, &link);
@@ -201,32 +264,21 @@ dpdk_port_state_callback (uint8_t port_id,
 
   if (xd->flags & DPDK_DEVICE_FLAG_BOND_SLAVE)
     {
-      u8 bd_port = xd->bond_port;
+      uword bd_port = xd->bond_port;
       int bd_mode = rte_eth_bond_mode_get (bd_port);
-
-      if ((link_up && !(xd->flags & DPDK_DEVICE_FLAG_BOND_SLAVE_UP)) ||
-         (!link_up && (xd->flags & DPDK_DEVICE_FLAG_BOND_SLAVE_UP)))
+#if 0
+      clib_warning ("Port %d state to %s, "
+                   "slave of port %d BondEthernet%d in mode %d",
+                   port_id, (link_up) ? "UP" : "DOWN",
+                   bd_port, xd->port_id, bd_mode);
+#endif
+      if (bd_mode == BONDING_MODE_ACTIVE_BACKUP)
        {
-         clib_warning ("Port %d state to %s, "
-                       "slave of port %d BondEthernet%d in mode %d",
-                       port_id, (link_up) ? "UP" : "DOWN",
-                       bd_port, xd->port_id, bd_mode);
-         if (bd_mode == BONDING_MODE_ACTIVE_BACKUP)
-           {
-             rte_eth_link_get_nowait (bd_port, &link);
-             if (link.link_status)     /* bonded interface up */
-               {
-                 u32 hw_if_index = dpdk_main.devices[bd_port].hw_if_index;
-                 vlib_process_signal_event
-                   (vm, send_garp_na_process_node_index, SEND_GARP_NA,
-                    hw_if_index);
-               }
-           }
+         vl_api_force_rpc_call_main_thread
+           (garp_na_proc_callback, (u8 *) & bd_port, sizeof (uword));
        }
-      if (link_up)             /* Update slave link status */
-       xd->flags |= DPDK_DEVICE_FLAG_BOND_SLAVE_UP;
-      else
-       xd->flags &= ~DPDK_DEVICE_FLAG_BOND_SLAVE_UP;
+      xd->flags |= link_up ?
+       DPDK_DEVICE_FLAG_BOND_SLAVE_UP : ~DPDK_DEVICE_FLAG_BOND_SLAVE_UP;
     }
   else                         /* Should not happen as callback not setup for "normal" links */
     {
@@ -238,8 +290,28 @@ dpdk_port_state_callback (uint8_t port_id,
       else
        clib_warning ("Port %d Link Down\n\n", port_id);
     }
+
+  return 0;
 }
 
+#if DPDK_VOID_CALLBACK
+void
+dpdk_port_state_callback (uint8_t port_id,
+                         enum rte_eth_event_type type, void *param)
+{
+  dpdk_port_state_callback_inline (port_id, type, param);
+}
+
+#else
+int
+dpdk_port_state_callback (uint8_t port_id,
+                         enum rte_eth_event_type type,
+                         void *param,
+                         void *ret_param __attribute__ ((unused)))
+{
+  return dpdk_port_state_callback_inline (port_id, type, param);
+}
+#endif
 /*
  * fd.io coding-style-patch-verification: ON
  *