nat: update ip4-udp src port for checksum == 0 pkts
[vpp.git] / src / plugins / dpdk / ipsec / crypto_node.c
index 6b57069..76e57a3 100644 (file)
@@ -123,39 +123,31 @@ dpdk_crypto_input_trace (vlib_main_t * vm, vlib_node_runtime_t * node,
 }
 
 static_always_inline u32
-dpdk_crypto_dequeue (vlib_main_t * vm, vlib_node_runtime_t * node,
-                    crypto_resource_t * res)
+dpdk_crypto_dequeue (vlib_main_t * vm, crypto_worker_main_t * cwm,
+                    vlib_node_runtime_t * node, crypto_resource_t * res)
 {
-  u32 thread_idx = vlib_get_thread_index ();
   u8 numa = rte_socket_id ();
-
-  dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
-  crypto_worker_main_t *cwm =
-    vec_elt_at_index (dcm->workers_main, thread_idx);
-
-  u32 n_ops, n_deq;
+  u32 n_ops, total_n_deq, n_deq[2];
   u32 bis[VLIB_FRAME_SIZE], *bi;
   u16 nexts[VLIB_FRAME_SIZE], *next;
   struct rte_crypto_op **ops;
 
+  n_deq[0] = 0;
+  n_deq[1] = 0;
   bi = bis;
   next = nexts;
   ops = cwm->ops;
 
-  n_ops = n_deq = rte_cryptodev_dequeue_burst (res->dev_id,
-                                              res->qp_id,
-                                              ops, VLIB_FRAME_SIZE);
-
+  n_ops = total_n_deq = rte_cryptodev_dequeue_burst (res->dev_id,
+                                                    res->qp_id,
+                                                    ops, VLIB_FRAME_SIZE);
   /* no op dequeued, do not proceed */
-  if (n_deq == 0)
+  if (n_ops == 0)
     return 0;
 
-  res->inflights -= n_ops;
-
   while (n_ops >= 4)
     {
       struct rte_crypto_op *op0, *op1, *op2, *op3;
-      vlib_buffer_t *b0, *b1, *b2, *b3;
 
       /* Prefetch next iteration. */
       if (n_ops >= 8)
@@ -185,21 +177,21 @@ dpdk_crypto_dequeue (vlib_main_t * vm, vlib_node_runtime_t * node,
       next[2] = crypto_op_get_priv (op2)->next;
       next[3] = crypto_op_get_priv (op3)->next;
 
+      bi[0] = crypto_op_get_priv (op0)->bi;
+      bi[1] = crypto_op_get_priv (op1)->bi;
+      bi[2] = crypto_op_get_priv (op2)->bi;
+      bi[3] = crypto_op_get_priv (op3)->bi;
+
+      n_deq[crypto_op_get_priv (op0)->encrypt] += 1;
+      n_deq[crypto_op_get_priv (op1)->encrypt] += 1;
+      n_deq[crypto_op_get_priv (op2)->encrypt] += 1;
+      n_deq[crypto_op_get_priv (op3)->encrypt] += 1;
+
       dpdk_crypto_input_check_op (vm, node, op0, next + 0);
       dpdk_crypto_input_check_op (vm, node, op1, next + 1);
       dpdk_crypto_input_check_op (vm, node, op2, next + 2);
       dpdk_crypto_input_check_op (vm, node, op3, next + 3);
 
-      b0 = vlib_buffer_from_rte_mbuf (op0->sym[0].m_src);
-      b1 = vlib_buffer_from_rte_mbuf (op1->sym[0].m_src);
-      b2 = vlib_buffer_from_rte_mbuf (op2->sym[0].m_src);
-      b3 = vlib_buffer_from_rte_mbuf (op3->sym[0].m_src);
-
-      bi[0] = vlib_get_buffer_index (vm, b0);
-      bi[1] = vlib_get_buffer_index (vm, b1);
-      bi[2] = vlib_get_buffer_index (vm, b2);
-      bi[3] = vlib_get_buffer_index (vm, b3);
-
       op0->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
       op1->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
       op2->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
@@ -214,17 +206,15 @@ dpdk_crypto_dequeue (vlib_main_t * vm, vlib_node_runtime_t * node,
   while (n_ops > 0)
     {
       struct rte_crypto_op *op0;
-      vlib_buffer_t *b0;
 
       op0 = ops[0];
 
       next[0] = crypto_op_get_priv (op0)->next;
+      bi[0] = crypto_op_get_priv (op0)->bi;
 
-      dpdk_crypto_input_check_op (vm, node, op0, next + 0);
+      n_deq[crypto_op_get_priv (op0)->encrypt] += 1;
 
-      /* XXX store bi0 and next0 in op0 private? */
-      b0 = vlib_buffer_from_rte_mbuf (op0->sym[0].m_src);
-      bi[0] = vlib_get_buffer_index (vm, b0);
+      dpdk_crypto_input_check_op (vm, node, op0, next + 0);
 
       op0->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
 
@@ -236,24 +226,26 @@ dpdk_crypto_dequeue (vlib_main_t * vm, vlib_node_runtime_t * node,
     }
 
   vlib_node_increment_counter (vm, node->node_index,
-                              DPDK_CRYPTO_INPUT_ERROR_DQ_COPS, n_deq);
+                              DPDK_CRYPTO_INPUT_ERROR_DQ_COPS, total_n_deq);
 
-  vlib_buffer_enqueue_to_next (vm, node, bis, nexts, n_deq);
+  res->inflights[0] -= n_deq[0];
+  res->inflights[1] -= n_deq[1];
 
-  dpdk_crypto_input_trace (vm, node, res->dev_id, bis, nexts, n_deq);
+  vlib_buffer_enqueue_to_next (vm, node, bis, nexts, total_n_deq);
 
-  crypto_free_ops (numa, cwm->ops, n_deq);
+  dpdk_crypto_input_trace (vm, node, res->dev_id, bis, nexts, total_n_deq);
 
-  return n_deq;
+  crypto_free_ops (numa, cwm->ops, total_n_deq);
+
+  return total_n_deq;
 }
 
 static_always_inline uword
 dpdk_crypto_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
                          vlib_frame_t * frame)
 {
-  u32 thread_index = vlib_get_thread_index ();
   dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
-  crypto_worker_main_t *cwm = &dcm->workers_main[thread_index];
+  crypto_worker_main_t *cwm = &dcm->workers_main[vm->thread_index];
   crypto_resource_t *res;
   u32 n_deq = 0;
   u16 *remove = NULL, *res_idx;
@@ -263,11 +255,13 @@ dpdk_crypto_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
   vec_foreach (res_idx, cwm->resource_idx)
     {
       res = vec_elt_at_index (dcm->resource, res_idx[0]);
+      u32 inflights = res->inflights[0] + res->inflights[1];
 
-      if (res->inflights)
-       n_deq += dpdk_crypto_dequeue (vm, node, res);
+      if (inflights)
+       n_deq += dpdk_crypto_dequeue (vm, cwm, node, res);
 
-      if (PREDICT_FALSE (res->remove && !(res->inflights)))
+      inflights = res->inflights[0] + res->inflights[1];
+      if (PREDICT_FALSE (res->remove && !(inflights)))
        vec_add1 (remove, res_idx[0]);
     }
   /* *INDENT-ON* */
@@ -309,6 +303,7 @@ VLIB_NODE_FN (dpdk_crypto_input_node) (vlib_main_t * vm,
 VLIB_REGISTER_NODE (dpdk_crypto_input_node) =
 {
   .name = "dpdk-crypto-input",
+  .flags = VLIB_NODE_FLAG_TRACE_SUPPORTED,
   .format_trace = format_dpdk_crypto_input_trace,
   .type = VLIB_NODE_TYPE_INPUT,
   .state = VLIB_NODE_STATE_DISABLED,