l2: Separating scan-delay and learn-limit into a separate API from want_l2_macs_events
[vpp.git] / src / vnet / devices / devices.c
index 2eb8e30..82b46f7 100644 (file)
@@ -52,10 +52,21 @@ device_input_next_node_advance[((VNET_DEVICE_INPUT_N_NEXT_NODES /
       [VNET_DEVICE_INPUT_NEXT_MPLS_INPUT] = sizeof (ethernet_header_t),
 };
 
+const u32 __attribute__((aligned (CLIB_CACHE_LINE_BYTES)))
+device_input_next_node_flags[((VNET_DEVICE_INPUT_N_NEXT_NODES /
+                               CLIB_CACHE_LINE_BYTES) +1) * CLIB_CACHE_LINE_BYTES] =
+{
+      [VNET_DEVICE_INPUT_NEXT_IP4_INPUT] = VNET_BUFFER_F_L3_HDR_OFFSET_VALID,
+      [VNET_DEVICE_INPUT_NEXT_IP4_NCS_INPUT] = VNET_BUFFER_F_L3_HDR_OFFSET_VALID,
+      [VNET_DEVICE_INPUT_NEXT_IP6_INPUT] = VNET_BUFFER_F_L3_HDR_OFFSET_VALID,
+      [VNET_DEVICE_INPUT_NEXT_MPLS_INPUT] = VNET_BUFFER_F_L3_HDR_OFFSET_VALID,
+};
+
 VNET_FEATURE_ARC_INIT (device_input, static) =
 {
   .arc_name  = "device-input",
   .start_nodes = VNET_FEATURES ("device-input"),
+  .last_in_arc = "ethernet-input",
   .arc_index_ptr = &feature_main.device_input_feature_arc_index,
 };
 
@@ -159,14 +170,14 @@ vnet_hw_interface_assign_rx_thread (vnet_main_t * vnm, u32 hw_if_index,
   dq->hw_if_index = hw_if_index;
   dq->dev_instance = hw->dev_instance;
   dq->queue_id = queue_id;
-  dq->mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
+  dq->mode = VNET_HW_IF_RX_MODE_POLLING;
   rt->enabled_node_state = VLIB_NODE_STATE_POLLING;
 
   vnet_device_queue_update (vnm, rt);
   vec_validate (hw->input_node_thread_index_by_queue, queue_id);
   vec_validate (hw->rx_mode_by_queue, queue_id);
   hw->input_node_thread_index_by_queue[queue_id] = thread_index;
-  hw->rx_mode_by_queue[queue_id] = VNET_HW_INTERFACE_RX_MODE_POLLING;
+  hw->rx_mode_by_queue[queue_id] = VNET_HW_IF_RX_MODE_POLLING;
 
   vlib_worker_thread_barrier_release (vm0);
 
@@ -182,7 +193,7 @@ vnet_hw_interface_unassign_rx_thread (vnet_main_t * vnm, u32 hw_if_index,
   vnet_device_input_runtime_t *rt;
   vnet_device_and_queue_t *dq;
   uword old_thread_index;
-  vnet_hw_interface_rx_mode mode;
+  vnet_hw_if_rx_mode mode;
 
   if (hw->input_node_thread_index_by_queue == 0)
     return VNET_API_ERROR_INVALID_INTERFACE;
@@ -211,12 +222,12 @@ delete:
   vlib_worker_thread_barrier_sync (vm0);
   vec_del1 (rt->devices_and_queues, dq - rt->devices_and_queues);
   vnet_device_queue_update (vnm, rt);
-  hw->rx_mode_by_queue[queue_id] = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
+  hw->rx_mode_by_queue[queue_id] = VNET_HW_IF_RX_MODE_UNKNOWN;
   vlib_worker_thread_barrier_release (vm0);
 
   if (vec_len (rt->devices_and_queues) == 0)
     vlib_node_set_state (vm, hw->input_node_index, VLIB_NODE_STATE_DISABLED);
-  else if (mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
+  else if (mode == VNET_HW_IF_RX_MODE_POLLING)
     {
       /*
        * if the deleted interface is polling, we may need to set the node state
@@ -227,7 +238,7 @@ delete:
        */
       vec_foreach (dq, rt->devices_and_queues)
       {
-       if (dq->mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
+       if (dq->mode == VNET_HW_IF_RX_MODE_POLLING)
          return 0;
       }
       rt->enabled_node_state = VLIB_NODE_STATE_INTERRUPT;
@@ -240,18 +251,18 @@ delete:
 
 int
 vnet_hw_interface_set_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
-                              u16 queue_id, vnet_hw_interface_rx_mode mode)
+                              u16 queue_id, vnet_hw_if_rx_mode mode)
 {
   vlib_main_t *vm;
   uword thread_index;
   vnet_device_and_queue_t *dq;
   vlib_node_state_t enabled_node_state;
-  ASSERT (mode < VNET_HW_INTERFACE_NUM_RX_MODES);
+  ASSERT (mode < VNET_HW_IF_NUM_RX_MODES);
   vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
   vnet_device_input_runtime_t *rt;
   int is_polling = 0;
 
-  if (mode == VNET_HW_INTERFACE_RX_MODE_DEFAULT)
+  if (mode == VNET_HW_IF_RX_MODE_DEFAULT)
     mode = hw->default_rx_mode;
 
   if (hw->input_node_thread_index_by_queue == 0 || hw->rx_mode_by_queue == 0)
@@ -260,10 +271,14 @@ vnet_hw_interface_set_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
   if (hw->rx_mode_by_queue[queue_id] == mode)
     return 0;
 
-  if (mode != VNET_HW_INTERFACE_RX_MODE_POLLING &&
+  if (mode != VNET_HW_IF_RX_MODE_POLLING &&
       (hw->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE) == 0)
     return VNET_API_ERROR_UNSUPPORTED;
 
+  if ((vec_len (hw->input_node_thread_index_by_queue) < queue_id + 1) ||
+      (vec_len (hw->rx_mode_by_queue) < queue_id + 1))
+    return VNET_API_ERROR_INVALID_QUEUE;
+
   hw->rx_mode_by_queue[queue_id] = mode;
   thread_index = hw->input_node_thread_index_by_queue[queue_id];
   vm = vlib_mains[thread_index];
@@ -274,7 +289,7 @@ vnet_hw_interface_set_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
   {
     if (dq->hw_if_index == hw_if_index && dq->queue_id == queue_id)
       dq->mode = mode;
-    if (dq->mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
+    if (dq->mode == VNET_HW_IF_RX_MODE_POLLING)
       is_polling = 1;
   }
 
@@ -296,7 +311,7 @@ vnet_hw_interface_set_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
 
 int
 vnet_hw_interface_get_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
-                              u16 queue_id, vnet_hw_interface_rx_mode * mode)
+                              u16 queue_id, vnet_hw_if_rx_mode * mode)
 {
   vlib_main_t *vm;
   uword thread_index;
@@ -307,6 +322,10 @@ vnet_hw_interface_get_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
   if (hw->input_node_thread_index_by_queue == 0)
     return VNET_API_ERROR_INVALID_INTERFACE;
 
+  if ((vec_len (hw->input_node_thread_index_by_queue) < queue_id + 1) ||
+      (vec_len (hw->rx_mode_by_queue) < queue_id + 1))
+    return VNET_API_ERROR_INVALID_QUEUE;
+
   thread_index = hw->input_node_thread_index_by_queue[queue_id];
   vm = vlib_mains[thread_index];
 
@@ -322,8 +341,6 @@ vnet_hw_interface_get_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
   return VNET_API_ERROR_INVALID_INTERFACE;
 }
 
-
-
 static clib_error_t *
 vnet_device_init (vlib_main_t * vm)
 {