devices: adapt af_packet to new rxq framework
[vpp.git] / src / vnet / devices / af_packet / node.c
index 243a38a..d444b3b 100644 (file)
@@ -23,7 +23,7 @@
 #include <vlib/unix/unix.h>
 #include <vnet/ip/ip.h>
 #include <vnet/ethernet/ethernet.h>
-#include <vnet/devices/devices.h>
+#include <vnet/interface/rx_queue_funcs.h>
 #include <vnet/feature/feature.h>
 #include <vnet/ethernet/packet.h>
 
@@ -192,12 +192,9 @@ af_packet_device_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
   u8 *block_start = apif->rx_ring + block * block_size;
   uword n_trace = vlib_get_trace_count (vm, node);
   u32 thread_index = vm->thread_index;
-  u32 n_buffer_bytes = VLIB_BUFFER_DATA_SIZE;
+  u32 n_buffer_bytes = vlib_buffer_get_default_data_size (vm);
   u32 min_bufs = apif->rx_req->tp_frame_size / n_buffer_bytes;
 
-  if (apif->per_interface_next_index != ~0)
-    next_index = apif->per_interface_next_index;
-
   n_free_bufs = vec_len (apm->rx_buffers[thread_index]);
   if (PREDICT_FALSE (n_free_bufs < VLIB_FRAME_SIZE))
     {
@@ -302,6 +299,10 @@ af_packet_device_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
          else
            {
              next0 = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT;
+
+             if (PREDICT_FALSE (apif->per_interface_next_index != ~0))
+               next0 = apif->per_interface_next_index;
+
              /* redirect if feature path enabled */
              vnet_feature_start_device_input_x1 (apif->sw_if_index, &next0,
                                                  first_b0);
@@ -309,11 +310,11 @@ af_packet_device_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
 
          /* trace */
          VLIB_BUFFER_TRACE_TRAJECTORY_INIT (first_b0);
-         if (PREDICT_FALSE (n_trace > 0))
+         if (PREDICT_FALSE
+             (n_trace > 0 && vlib_trace_buffer (vm, node, next0, first_b0,
+                                                /* follow_chain */ 0)))
            {
              af_packet_input_trace_t *tr;
-             vlib_trace_buffer (vm, node, next0, first_b0,     /* follow_chain */
-                                0);
              vlib_set_trace_count (vm, node, --n_trace);
              tr = vlib_add_trace (vm, node, first_b0, sizeof (*tr));
              tr->next_index = next0;
@@ -345,30 +346,29 @@ af_packet_device_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
   return n_rx_packets;
 }
 
-static uword
-af_packet_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
-                   vlib_frame_t * frame)
+VLIB_NODE_FN (af_packet_input_node) (vlib_main_t * vm,
+                                    vlib_node_runtime_t * node,
+                                    vlib_frame_t * frame)
 {
   u32 n_rx_packets = 0;
   af_packet_main_t *apm = &af_packet_main;
-  vnet_device_input_runtime_t *rt = (void *) node->runtime_data;
-  vnet_device_and_queue_t *dq;
-
-  foreach_device_and_queue (dq, rt->devices_and_queues)
-  {
-    af_packet_if_t *apif;
-    apif = vec_elt_at_index (apm->interfaces, dq->dev_instance);
-    if (apif->is_admin_up)
-      n_rx_packets += af_packet_device_input_fn (vm, node, frame, apif);
-  }
+  vnet_hw_if_rxq_poll_vector_t *pv;
+  pv = vnet_hw_if_get_rxq_poll_vector (vm, node);
+  for (int i = 0; i < vec_len (pv); i++)
+    {
+      af_packet_if_t *apif;
+      apif = vec_elt_at_index (apm->interfaces, pv[i].dev_instance);
+      if (apif->is_admin_up)
+       n_rx_packets += af_packet_device_input_fn (vm, node, frame, apif);
+    }
 
   return n_rx_packets;
 }
 
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (af_packet_input_node) = {
-  .function = af_packet_input_fn,
   .name = "af-packet-input",
+  .flags = VLIB_NODE_FLAG_TRACE_SUPPORTED,
   .sibling_of = "device-input",
   .format_trace = format_af_packet_input_trace,
   .type = VLIB_NODE_TYPE_INPUT,
@@ -376,8 +376,6 @@ VLIB_REGISTER_NODE (af_packet_input_node) = {
   .n_errors = AF_PACKET_INPUT_N_ERROR,
   .error_strings = af_packet_input_error_strings,
 };
-
-VLIB_NODE_FUNCTION_MULTIARCH (af_packet_input_node, af_packet_input_fn)
 /* *INDENT-ON* */