bonding: Add GSO support

Add GSO support, configurable from the CLI.

Type: feature
Ticket: VPP-1820

Signed-off-by: Steven Luong <sluong@cisco.com>
Change-Id: I65885a071b24c74437e6cfe5eff237b01bc1744b
(cherry picked from commit a06f68556e506a6ff7f31a617a036614c84f71c0)
diff --git a/src/vnet/bonding/cli.c b/src/vnet/bonding/cli.c
index 66aaa2e..09ef10f 100644
--- a/src/vnet/bonding/cli.c
+++ b/src/vnet/bonding/cli.c
@@ -379,6 +379,7 @@
   vnet_main_t *vnm = vnet_get_main ();
   vnet_sw_interface_t *sw;
   bond_if_t *bif;
+  vnet_hw_interface_t *hw;
 
   if ((args->mode == BOND_MODE_LACP) && bm->lacp_plugin_loaded == 0)
     {
@@ -404,6 +405,7 @@
   bif->id = args->id;
   bif->lb = args->lb;
   bif->mode = args->mode;
+  bif->gso = args->gso;
 
   // Adjust requested interface id
   if (bif->id == ~0)
@@ -454,6 +456,10 @@
   bif->sw_if_index = sw->sw_if_index;
   bif->group = bif->sw_if_index;
   bif->numa_only = args->numa_only;
+
+  hw = vnet_get_hw_interface (vnm, bif->hw_if_index);
+  hw->flags |= (VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO |
+		VNET_HW_INTERFACE_FLAG_SUPPORTS_TX_L4_CKSUM_OFFLOAD);
   if (vlib_get_thread_main ()->n_vlib_mains > 1)
     clib_spinlock_init (&bif->lockp);
 
@@ -496,6 +502,8 @@
 	args.hw_addr_set = 1;
       else if (unformat (line_input, "id %u", &args.id))
 	;
+      else if (unformat (line_input, "gso"))
+	args.gso = 1;
       else if (unformat (line_input, "numa-only"))
 	{
 	  if (args.mode == BOND_MODE_LACP)
@@ -526,8 +534,8 @@
 VLIB_CLI_COMMAND (bond_create_command, static) = {
   .path = "create bond",
   .short_help = "create bond mode {round-robin | active-backup | broadcast | "
-    "{lacp | xor} [load-balance { l2 | l23 | l34 } [numa-only]]} [hw-addr <mac-address>] "
-    "[id <if-id>]",
+    "{lacp | xor} [load-balance { l2 | l23 | l34 } [numa-only]]} "
+    "[hw-addr <mac-address>] [id <if-id>] [gso]",
   .function = bond_create_command_fn,
 };
 /* *INDENT-ON* */
@@ -615,6 +623,13 @@
 	clib_error_return (0, "bond interface cannot be enslaved");
       return;
     }
+  if (bif->gso && !(sif_hw->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO))
+    {
+      args->rv = VNET_API_ERROR_INVALID_INTERFACE;
+      args->error =
+	clib_error_return (0, "slave interface is not gso capable");
+      return;
+    }
   if (bif->mode == BOND_MODE_LACP)
     {
       u8 *name = format (0, "/if/lacp/%u/%u/state%c", bif->sw_if_index,
@@ -901,6 +916,8 @@
 		     format_bond_mode, bif->mode);
     vlib_cli_output (vm, "  load balance: %U",
 		     format_bond_load_balance, bif->lb);
+    if (bif->gso)
+      vlib_cli_output (vm, "  gso enable");
     if (bif->mode == BOND_MODE_ROUND_ROBIN)
       vlib_cli_output (vm, "  last xmit slave index: %u",
 		       bif->lb_rr_last_index);