FD.io VPP  v17.01.1-3-gc6833f8
Vector Packet Processing
crypto_node.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * crypto_node.c - DPDK Cryptodev input node
4  *
5  * Copyright (c) 2016 Intel and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #include <vlib/vlib.h>
21 #include <vnet/ip/ip.h>
22 #include <vnet/ethernet/ethernet.h>
23 #include <vnet/ipsec/ipsec.h>
24 
26 
27 #define foreach_dpdk_crypto_input_next \
28  _(DROP, "error-drop") \
29  _(ENCRYPT_POST, "dpdk-esp-encrypt-post") \
30  _(DECRYPT_POST, "dpdk-esp-decrypt-post")
31 
32 typedef enum
33 {
34 #define _(f,s) DPDK_CRYPTO_INPUT_NEXT_##f,
36 #undef _
39 
40 #define foreach_dpdk_crypto_input_error \
41  _(DQ_COPS, "Crypto ops dequeued") \
42  _(COP_FAILED, "Crypto op failed")
43 
44 typedef enum
45 {
46 #define _(f,s) DPDK_CRYPTO_INPUT_ERROR_##f,
48 #undef _
51 
53 #define _(n, s) s,
55 #undef _
56 };
57 
59 
60 typedef struct
61 {
68 
69 static u8 *
70 format_dpdk_crypto_input_trace (u8 * s, va_list * args)
71 {
72  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
73  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
75 
76  s = format (s, "dpdk_crypto: cryptodev-id %u queue-pair %u next-index %d",
77  t->cdev, t->qp, t->next_index);
78 
79  s = format (s, " status %u sa-idx %u\n", t->status, t->sa_idx);
80 
81  return s;
82 }
83 
86  crypto_qp_data_t * qpd)
87 {
88  u32 n_deq, *to_next = 0, next_index, n_cops, def_next_index;
89  struct rte_crypto_op **cops = qpd->cops;
90 
91  if (qpd->inflights == 0)
92  return 0;
93 
94  if (qpd->is_outbound)
95  def_next_index = DPDK_CRYPTO_INPUT_NEXT_ENCRYPT_POST;
96  else
97  def_next_index = DPDK_CRYPTO_INPUT_NEXT_DECRYPT_POST;
98 
99  n_cops = rte_cryptodev_dequeue_burst (qpd->dev_id, qpd->qp_id,
100  cops, VLIB_FRAME_SIZE);
101  n_deq = n_cops;
102  next_index = def_next_index;
103 
104  qpd->inflights -= n_cops;
105  ASSERT (qpd->inflights >= 0);
106 
107  while (n_cops > 0)
108  {
109  u32 n_left_to_next;
110 
111  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
112 
113  while (n_cops > 0 && n_left_to_next > 0)
114  {
115  u32 bi0, next0;
116  vlib_buffer_t *b0 = 0;
117  struct rte_crypto_op *cop;
118  struct rte_crypto_sym_op *sym_cop;
119 
120  cop = cops[0];
121  cops += 1;
122  n_cops -= 1;
123  n_left_to_next -= 1;
124 
125  next0 = def_next_index;
126 
127  if (PREDICT_FALSE (cop->status != RTE_CRYPTO_OP_STATUS_SUCCESS))
128  {
129  next0 = DPDK_CRYPTO_INPUT_NEXT_DROP;
131  DPDK_CRYPTO_INPUT_ERROR_COP_FAILED,
132  1);
133  }
134  cop->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
135 
136  sym_cop = (struct rte_crypto_sym_op *) (cop + 1);
137  b0 = vlib_buffer_from_rte_mbuf (sym_cop->m_src);
138  bi0 = vlib_get_buffer_index (vm, b0);
139 
140  to_next[0] = bi0;
141  to_next += 1;
142 
144  {
145  vlib_trace_next_frame (vm, node, next0);
147  vlib_add_trace (vm, node, b0, sizeof (*tr));
148  tr->cdev = qpd->dev_id;
149  tr->qp = qpd->qp_id;
150  tr->status = cop->status;
151  tr->next_index = next0;
152  tr->sa_idx = vnet_buffer (b0)->ipsec.sad_index;
153  }
154 
155  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
156  n_left_to_next, bi0, next0);
157  }
158  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
159  }
160 
161  crypto_free_cop (qpd, qpd->cops, n_deq);
162 
164  DPDK_CRYPTO_INPUT_ERROR_DQ_COPS, n_deq);
165  return n_deq;
166 }
167 
168 static uword
170  vlib_frame_t * frame)
171 {
172  u32 cpu_index = os_get_cpu_number ();
174  crypto_worker_main_t *cwm = &dcm->workers_main[cpu_index];
175  crypto_qp_data_t *qpd;
176  u32 n_deq = 0;
177 
178  /* *INDENT-OFF* */
179  vec_foreach (qpd, cwm->qp_data)
180  n_deq += dpdk_crypto_dequeue(vm, node, qpd);
181  /* *INDENT-ON* */
182 
183  return n_deq;
184 }
185 
187 {
188  .function = dpdk_crypto_input_fn,.name = "dpdk-crypto-input",.format_trace =
190  VLIB_NODE_STATE_DISABLED,.n_errors =
191  DPDK_CRYPTO_INPUT_N_ERROR,.error_strings =
192  dpdk_crypto_input_error_strings,.n_next_nodes =
193  DPDK_CRYPTO_INPUT_N_NEXT,.next_nodes =
194  {
195 #define _(s,n) [DPDK_CRYPTO_INPUT_NEXT_##s] = n,
197 #undef _
198  }
199 ,};
200 
201 #if DPDK_CRYPTO==1
203 #endif
204 /*
205  * fd.io coding-style-patch-verification: ON
206  *
207  * Local Variables:
208  * eval: (c-set-style "gnu")
209  * End:
210  */
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:459
dpdk_crypto_input_error_t
Definition: crypto_node.c:44
static_always_inline u32 dpdk_crypto_dequeue(vlib_main_t *vm, vlib_node_runtime_t *node, crypto_qp_data_t *qpd)
Definition: crypto_node.c:85
#define CLIB_UNUSED(x)
Definition: clib.h:79
u16 is_outbound
Definition: ipsec.h:61
struct _vlib_node_registration vlib_node_registration_t
vlib_node_registration_t dpdk_crypto_input_node
(constructor) VLIB_REGISTER_NODE (dpdk_crypto_input_node)
Definition: crypto_node.c:58
static_always_inline void crypto_free_cop(crypto_qp_data_t *qpd, struct rte_crypto_op **cops, u32 n)
Definition: ipsec.h:126
#define static_always_inline
Definition: clib.h:85
static void vlib_trace_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index)
Definition: trace_funcs.h:92
i16 inflights
Definition: ipsec.h:62
static u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
Definition: buffer_funcs.h:70
dpdk_crypto_main_t dpdk_crypto_main
Definition: ipsec.h:87
#define foreach_dpdk_crypto_input_error
Definition: crypto_node.c:40
dpdk_crypto_input_next_t
Definition: crypto_node.c:32
#define foreach_dpdk_crypto_input_next
Definition: crypto_node.c:27
uword os_get_cpu_number(void)
Definition: unix-misc.c:224
#define PREDICT_FALSE(x)
Definition: clib.h:97
static uword dpdk_crypto_input_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: crypto_node.c:169
#define VLIB_FRAME_SIZE
Definition: node.h:328
struct rte_crypto_op * cops[VLIB_FRAME_SIZE]
Definition: ipsec.h:64
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:216
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:350
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1113
static char * dpdk_crypto_input_error_strings[]
Definition: crypto_node.c:52
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
#define vnet_buffer(b)
Definition: buffer.h:361
crypto_worker_main_t * workers_main
Definition: ipsec.h:84
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:95
crypto_qp_data_t * qp_data
Definition: ipsec.h:77
u64 uword
Definition: types.h:112
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
static u8 * format_dpdk_crypto_input_trace(u8 *s, va_list *args)
Definition: crypto_node.c:70
unsigned char u8
Definition: types.h:56
#define VLIB_NODE_FUNCTION_MULTIARCH(node, fn)
Definition: node.h:158
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:143
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
#define vlib_buffer_from_rte_mbuf(x)
Definition: buffer.h:390
#define vec_foreach(var, vec)
Vector iterator.
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:85