gso: packet coalesce library
[vpp.git] / src / vnet / pg / stream.c
index c60c584..88c8937 100644 (file)
@@ -178,8 +178,26 @@ pg_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags)
   return 0;
 }
 
+void
+pg_interface_enable_disable_coalesce (pg_interface_t * pi, u8 enable,
+                                     u32 tx_node_index)
+{
+  if (enable)
+    {
+      gro_flow_table_init (&pi->flow_table, 1 /* is_l2 */ ,
+                          tx_node_index);
+      pi->coalesce_enabled = 1;
+    }
+  else
+    {
+      pi->coalesce_enabled = 0;
+      gro_flow_table_free (pi->flow_table);
+    }
+}
+
 u32
-pg_interface_add_or_get (pg_main_t * pg, uword if_id)
+pg_interface_add_or_get (pg_main_t * pg, uword if_id, u8 gso_enabled,
+                        u32 gso_size, u8 coalesce_enabled)
 {
   vnet_main_t *vnm = vnet_get_main ();
   vlib_main_t *vm = vlib_get_main ();
@@ -213,6 +231,16 @@ pg_interface_add_or_get (pg_main_t * pg, uword if_id)
       ethernet_register_interface (vnm, pg_dev_class.index, i, hw_addr,
                                   &pi->hw_if_index, pg_eth_flag_change);
       hi = vnet_get_hw_interface (vnm, pi->hw_if_index);
+      if (gso_enabled)
+       {
+         hi->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO;
+         pi->gso_enabled = 1;
+         pi->gso_size = gso_size;
+         if (coalesce_enabled)
+           {
+             pg_interface_enable_disable_coalesce (pi, 1, hi->tx_node_index);
+           }
+       }
       pi->sw_if_index = hi->sw_if_index;
 
       hash_set (pg->if_index_by_if_id, if_id, i);
@@ -445,18 +473,20 @@ pg_stream_add (pg_main_t * pg, pg_stream_t * s_init)
   }
 
   /* Find an interface to use. */
-  s->pg_if_index = pg_interface_add_or_get (pg, s->if_id);
+  s->pg_if_index =
+    pg_interface_add_or_get (pg, s->if_id, 0 /* gso_enabled */ ,
+                            0 /* gso_size */ , 0 /* coalesce_enabled */ );
 
-  {
-    pg_interface_t *pi = pool_elt_at_index (pg->interfaces, s->pg_if_index);
-    vlib_rx_or_tx_t rx_or_tx;
-
-    vlib_foreach_rx_tx (rx_or_tx)
+  if (s->sw_if_index[VLIB_RX] == ~0)
     {
-      if (s->sw_if_index[rx_or_tx] == ~0)
-       s->sw_if_index[rx_or_tx] = pi->sw_if_index;
+      pg_interface_t *pi = pool_elt_at_index (pg->interfaces, s->pg_if_index);
+      /*
+       * Default the RX interface if unset. It's a bad mistake to
+       * set [VLIB_TX] prior to ip lookup, since the ip lookup code
+       * interprets [VLIB_TX] as a fib index...
+       */
+      s->sw_if_index[VLIB_RX] = pi->sw_if_index;
     }
-  }
 
   /* Connect the graph. */
   s->next_index = vlib_node_add_next (vm, device_input_node.index,