crypto: allow changing dispatch mode

This change aims to affect crypto_sw_scheduler behavior,
but all the edits end up in vnet/crypto.

Previous release CSIT tests were testing async crypto in polling mode.
After 9a9604b09f15691d7c4ddf29afd99a31e7e31eed introduced adaptive mode
for crypto dispatch, the CSIT performance got way worse.

Possibly, there is another VPP bug related to adaptive mode
(it should not lose as many packets as seen in CSIT),
but the next release is too close for trying to fix that.

This change (instead of fixing adaptive mode)
allows CSIT to continue testing polling mode (after explicit API call),
while keeping the adaptive mode as default behavior.

The deprecated crypto_set_async_dispatch always disable adaptive mode,
crypto_set_async_dispatch_v2 has parameter to enable or disable it.
The mode parameter is still used for the inital state of adaptive mode.

Type: feature

Change-Id: Ib98080eefb4be291207af543884f2c3837f92f59
Signed-off-by: Vratko Polak <vrpolak@cisco.com>
diff --git a/src/vnet/crypto/crypto.c b/src/vnet/crypto/crypto.c
index 81cbda8..0f99492 100644
--- a/src/vnet/crypto/crypto.c
+++ b/src/vnet/crypto/crypto.c
@@ -605,6 +605,23 @@
   return nn->next_idx;
 }
 
+void
+vnet_crypto_set_async_dispatch (u8 mode, u8 adaptive)
+{
+  vlib_thread_main_t *tm = vlib_get_thread_main ();
+  u32 i, node_index = crypto_main.crypto_node_index;
+  vlib_node_state_t state =
+    mode ? VLIB_NODE_STATE_INTERRUPT : VLIB_NODE_STATE_POLLING;
+
+  for (i = vlib_num_workers () > 0; i < tm->n_vlib_mains; i++)
+    {
+      vlib_main_t *ovm = vlib_get_main_by_index (i);
+      vlib_node_set_state (ovm, node_index, state);
+      vlib_node_set_flag (ovm, node_index, VLIB_NODE_FLAG_ADAPTIVE_MODE,
+			  adaptive);
+    }
+}
+
 int
 vnet_crypto_is_set_async_handler (vnet_crypto_async_op_id_t op)
 {