blob: 2c8647576b00a3e8390c807422339c0823d3eb9b [file] [log] [blame]
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +00001/*
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +01002 * Copyright (c) 2017 Intel and/or its affiliates.
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +00003 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include <vnet/vnet.h>
Damjan Marionc3a814b2017-02-28 19:22:22 +010017#include <dpdk/device/dpdk.h>
18#include <dpdk/ipsec/ipsec.h>
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000019
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010020static u8 *
Kingwel Xie3b3464e2019-02-13 02:48:41 -050021format_crypto_resource (u8 * s, va_list * args)
22{
23 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
24
25 u32 indent = va_arg (*args, u32);
26 u32 res_idx = va_arg (*args, u32);
27
28 crypto_resource_t *res = vec_elt_at_index (dcm->resource, res_idx);
29
Sergio Gonzalez Monroyd8a34a52019-05-06 22:44:14 +020030
Christian Hopps942b9802020-07-14 09:41:43 -040031 s = format (s, "%U thr_id %3d qp %2u dec_inflight %u, enc_inflights %u\n",
Sergio Gonzalez Monroyd8a34a52019-05-06 22:44:14 +020032 format_white_space, indent, (i16) res->thread_idx,
33 res->qp_id, res->inflights[0], res->inflights[1]);
Kingwel Xie3b3464e2019-02-13 02:48:41 -050034
35 return s;
36}
37
38static u8 *
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010039format_crypto (u8 * s, va_list * args)
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000040{
41 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010042 crypto_dev_t *dev = va_arg (*args, crypto_dev_t *);
43 crypto_drv_t *drv = vec_elt_at_index (dcm->drv, dev->drv_id);
44 u64 feat, mask;
45 u32 i;
Damjan Marionffe9d212018-05-30 09:26:11 +020046 char *pre = " ";
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000047
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010048 s = format (s, "%-25s%-20s%-10s\n", dev->name, drv->name,
49 rte_cryptodevs[dev->id].data->dev_started ? "up" : "down");
50 s = format (s, " numa_node %u, max_queues %u\n", dev->numa, dev->max_qp);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010051
52 if (dev->features)
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +000053 {
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010054 for (mask = 1; mask != 0; mask <<= 1)
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000055 {
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010056 feat = dev->features & mask;
57 if (feat)
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000058 {
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010059 s =
60 format (s, "%s%s", pre,
61 rte_cryptodev_get_feature_name (feat));
62 pre = ", ";
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000063 }
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000064 }
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010065 s = format (s, "\n");
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000066 }
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010067
68 s = format (s, " Cipher:");
69 pre = " ";
70 for (i = 0; i < IPSEC_CRYPTO_N_ALG; i++)
71 if (dev->cipher_support[i])
72 {
73 s = format (s, "%s%s", pre, dcm->cipher_algs[i].name);
74 pre = ", ";
75 }
76 s = format (s, "\n");
77
78 s = format (s, " Auth:");
79 pre = " ";
80 for (i = 0; i < IPSEC_INTEG_N_ALG; i++)
81 if (dev->auth_support[i])
82 {
83 s = format (s, "%s%s", pre, dcm->auth_algs[i].name);
84 pre = ", ";
85 }
Kingwel Xie3b3464e2019-02-13 02:48:41 -050086 s = format (s, "\n");
87
88 struct rte_cryptodev_stats stats;
89 rte_cryptodev_stats_get (dev->id, &stats);
90
91 s =
92 format (s,
93 " enqueue %-10lu dequeue %-10lu enqueue_err %-10lu dequeue_err %-10lu \n",
94 stats.enqueued_count, stats.dequeued_count,
95 stats.enqueue_err_count, stats.dequeue_err_count);
96
97 u16 *res_idx;
98 s = format (s, " free_resources %u :", vec_len (dev->free_resources));
99
100 u32 indent = format_get_indent (s);
101 s = format (s, "\n");
102
103 /* *INDENT-OFF* */
104 vec_foreach (res_idx, dev->free_resources)
105 s = format (s, "%U", format_crypto_resource, indent, res_idx[0]);
106 /* *INDENT-ON* */
107
108 s = format (s, " used_resources %u :", vec_len (dev->used_resources));
109 indent = format_get_indent (s);
110
111 s = format (s, "\n");
112
113 /* *INDENT-OFF* */
114 vec_foreach (res_idx, dev->used_resources)
115 s = format (s, "%U", format_crypto_resource, indent, res_idx[0]);
116 /* *INDENT-ON* */
117
118 s = format (s, "\n");
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100119
120 return s;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000121}
122
Kingwel Xie3b3464e2019-02-13 02:48:41 -0500123
124static clib_error_t *
125clear_crypto_stats_fn (vlib_main_t * vm, unformat_input_t * input,
126 vlib_cli_command_t * cmd)
127{
128 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
129 crypto_dev_t *dev;
130
131 /* *INDENT-OFF* */
132 vec_foreach (dev, dcm->dev)
133 rte_cryptodev_stats_reset (dev->id);
134 /* *INDENT-ON* */
135
136 return NULL;
137}
138
139/*?
140 * This command is used to clear the DPDK Crypto device statistics.
141 *
142 * @cliexpar
143 * Example of how to clear the DPDK Crypto device statistics:
Nathan Skrzypczak6f38f1c2021-09-29 15:38:50 +0200144 * @cliexstart{clear dpdk crypto devices statistics}
Kingwel Xie3b3464e2019-02-13 02:48:41 -0500145 * vpp# clear dpdk crypto devices statistics
146 * @cliexend
Kingwel Xie3b3464e2019-02-13 02:48:41 -0500147?*/
148/* *INDENT-OFF* */
149VLIB_CLI_COMMAND (clear_dpdk_crypto_stats, static) = {
150 .path = "clear dpdk crypto devices statistics",
151 .short_help = "clear dpdk crypto devices statistics",
152 .function = clear_crypto_stats_fn,
153};
154/* *INDENT-ON* */
155
156
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000157static clib_error_t *
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100158show_dpdk_crypto_fn (vlib_main_t * vm, unformat_input_t * input,
159 vlib_cli_command_t * cmd)
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000160{
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100161 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
162 crypto_dev_t *dev;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000163
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100164 /* *INDENT-OFF* */
165 vec_foreach (dev, dcm->dev)
166 vlib_cli_output (vm, "%U", format_crypto, dev);
167 /* *INDENT-ON* */
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000168
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100169 return NULL;
170}
171
172/*?
173 * This command is used to display the DPDK Crypto device information.
174 *
175 * @cliexpar
176 * Example of how to display the DPDK Crypto device information:
Nathan Skrzypczak6f38f1c2021-09-29 15:38:50 +0200177 * @cliexstart{show dpdk crypto devices}
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100178 * vpp# show dpdk crypto devices
Kingwel Xie3b3464e2019-02-13 02:48:41 -0500179 * aesni_mb0 crypto_aesni_mb up
180 * numa_node 0, max_queues 4
181 * SYMMETRIC_CRYPTO, SYM_OPERATION_CHAINING, CPU_AVX2, CPU_AESNI
Nathan Skrzypczak6f38f1c2021-09-29 15:38:50 +0200182 * Cipher: aes-cbc-128, aes-cbc-192, aes-cbc-256, aes-ctr-128, aes-ctr-192,
183 * aes-ctr-256, aes-gcm-128, aes-gcm-192, aes-gcm-256
Kingwel Xie3b3464e2019-02-13 02:48:41 -0500184 * Auth: md5-96, sha1-96, sha-256-128, sha-384-192, sha-512-256
185 * enqueue 2 dequeue 2 enqueue_err 0 dequeue_err 0
186 * free_resources 3 :
187 * thr_id -1 qp 3 inflight 0
188 * thr_id -1 qp 2 inflight 0
189 * thr_id -1 qp 1 inflight 0
190 * used_resources 1 :
191 * thr_id 1 qp 0 inflight 0
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100192 * @cliexend
193 * Example of displaying the DPDK Crypto device data when enabled:
194 * @cliexend
195?*/
196/* *INDENT-OFF* */
197VLIB_CLI_COMMAND (show_dpdk_crypto, static) = {
198 .path = "show dpdk crypto devices",
199 .short_help = "show dpdk crypto devices",
200 .function = show_dpdk_crypto_fn,
201};
202
203/* *INDENT-ON* */
204static u8 *
205format_crypto_worker (u8 * s, va_list * args)
206{
207 u32 thread_idx = va_arg (*args, u32);
208 u8 verbose = (u8) va_arg (*args, u32);
209 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
210 crypto_worker_main_t *cwm;
211 crypto_resource_t *res;
212 u16 *res_idx;
Damjan Marionffe9d212018-05-30 09:26:11 +0200213 char *pre, *ind;
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100214 u32 i;
215
216 cwm = vec_elt_at_index (dcm->workers_main, thread_idx);
217
218 s = format (s, "Thread %u (%v):\n", thread_idx,
219 vlib_worker_threads[thread_idx].name);
220
221 /* *INDENT-OFF* */
222 vec_foreach (res_idx, cwm->resource_idx)
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000223 {
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100224 ind = " ";
225 res = vec_elt_at_index (dcm->resource, res_idx[0]);
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100226 s = format (s, "%s%-20s dev-id %2u queue-pair %2u\n",
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100227 ind, vec_elt_at_index (dcm->dev, res->dev_id)->name,
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100228 res->dev_id, res->qp_id);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100229
230 ind = " ";
231 if (verbose)
Billy McFalla9a20e72017-02-15 11:39:12 -0500232 {
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100233 s = format (s, "%sCipher:", ind);
234 pre = " ";
235 for (i = 0; i < IPSEC_CRYPTO_N_ALG; i++)
236 if (cwm->cipher_resource_idx[i] == res_idx[0])
237 {
238 s = format (s, "%s%s", pre, dcm->cipher_algs[i].name);
239 pre = ", ";
240 }
241 s = format (s, "\n");
242
243 s = format (s, "%sAuth:", ind);
244 pre = " ";
245 for (i = 0; i < IPSEC_INTEG_N_ALG; i++)
246 if (cwm->auth_resource_idx[i] == res_idx[0])
247 {
248 s = format (s, "%s%s", pre, dcm->auth_algs[i].name);
249 pre = ", ";
250 }
251 s = format (s, "\n");
Billy McFalla9a20e72017-02-15 11:39:12 -0500252 }
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000253 }
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100254 /* *INDENT-ON* */
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000255
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100256 return s;
257}
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000258
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100259static clib_error_t *
260common_crypto_placement_fn (vlib_main_t * vm, unformat_input_t * input,
261 vlib_cli_command_t * cmd, u8 verbose)
262{
263 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
264 clib_error_t *error = NULL;
265 u32 i;
266 u8 skip_master;
267
268 if (!dcm->enabled)
269 {
270 vlib_cli_output (vm, "\nDPDK Cryptodev support is disabled\n");
271 return error;
272 }
273
274 skip_master = vlib_num_workers () > 0;
275
276 /* *INDENT-OFF* */
277 vec_foreach_index (i, dcm->workers_main)
278 {
279 if (i < skip_master)
280 continue;
281
282 vlib_cli_output (vm, "%U\n", format_crypto_worker, i, verbose);
283 }
284 /* *INDENT-ON* */
Billy McFalla9a20e72017-02-15 11:39:12 -0500285
286 return error;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000287}
288
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100289static clib_error_t *
290show_dpdk_crypto_placement_fn (vlib_main_t * vm, unformat_input_t * input,
291 vlib_cli_command_t * cmd)
292{
293 return common_crypto_placement_fn (vm, input, cmd, 0);
294}
295
296static clib_error_t *
297show_dpdk_crypto_placement_v_fn (vlib_main_t * vm, unformat_input_t * input,
298 vlib_cli_command_t * cmd)
299{
300 return common_crypto_placement_fn (vm, input, cmd, 1);
301}
302
Billy McFalldfde53a2017-03-10 14:49:15 -0500303/*?
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100304 * This command is used to display the DPDK Crypto device placement.
Billy McFalldfde53a2017-03-10 14:49:15 -0500305 *
306 * @cliexpar
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100307 * Example of displaying the DPDK Crypto device placement:
308 * @cliexstart{show dpdk crypto placement}
309 * vpp# show dpdk crypto placement
310 * Thread 1 (vpp_wk_0):
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100311 * cryptodev_aesni_mb_p dev-id 0 queue-pair 0
312 * cryptodev_aesni_gcm_ dev-id 1 queue-pair 0
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100313 *
314 * Thread 2 (vpp_wk_1):
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100315 * cryptodev_aesni_mb_p dev-id 0 queue-pair 1
316 * cryptodev_aesni_gcm_ dev-id 1 queue-pair 1
Billy McFalldfde53a2017-03-10 14:49:15 -0500317 * @cliexend
318?*/
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000319/* *INDENT-OFF* */
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100320VLIB_CLI_COMMAND (show_dpdk_crypto_placement, static) = {
321 .path = "show dpdk crypto placement",
322 .short_help = "show dpdk crypto placement",
323 .function = show_dpdk_crypto_placement_fn,
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000324};
325/* *INDENT-ON* */
326
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100327/*?
328 * This command is used to display the DPDK Crypto device placement
329 * with verbose output.
330 *
331 * @cliexpar
332 * Example of displaying the DPDK Crypto device placement verbose:
333 * @cliexstart{show dpdk crypto placement verbose}
334 * vpp# show dpdk crypto placement verbose
335 * Thread 1 (vpp_wk_0):
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100336 * cryptodev_aesni_mb_p dev-id 0 queue-pair 0
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100337 * Cipher: aes-cbc-128, aes-cbc-192, aes-cbc-256, aes-ctr-128, aes-ctr-192, aes-ctr-256
338 * Auth: md5-96, sha1-96, sha-256-128, sha-384-192, sha-512-256
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100339 * cryptodev_aesni_gcm_ dev-id 1 queue-pair 0
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100340 * Cipher: aes-gcm-128, aes-gcm-192, aes-gcm-256
341 * Auth:
342 *
343 * Thread 2 (vpp_wk_1):
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100344 * cryptodev_aesni_mb_p dev-id 0 queue-pair 1
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100345 * Cipher: aes-cbc-128, aes-cbc-192, aes-cbc-256, aes-ctr-128, aes-ctr-192, aes-ctr-256
346 * Auth: md5-96, sha1-96, sha-256-128, sha-384-192, sha-512-256
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100347 * cryptodev_aesni_gcm_ dev-id 1 queue-pair 1
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100348 * Cipher: aes-gcm-128, aes-gcm-192, aes-gcm-256
349 * Auth:
350 *
351 * @cliexend
352?*/
353/* *INDENT-OFF* */
354VLIB_CLI_COMMAND (show_dpdk_crypto_placement_v, static) = {
355 .path = "show dpdk crypto placement verbose",
356 .short_help = "show dpdk crypto placement verbose",
357 .function = show_dpdk_crypto_placement_v_fn,
358};
359/* *INDENT-ON* */
360
361static clib_error_t *
362set_dpdk_crypto_placement_fn (vlib_main_t * vm,
363 unformat_input_t * input,
364 vlib_cli_command_t * cmd)
365{
366 unformat_input_t _line_input, *line_input = &_line_input;
367 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
368 crypto_worker_main_t *cwm;
369 crypto_dev_t *dev;
370 u32 thread_idx, i;
371 u16 res_idx, *idx;
Sergio Gonzalez Monroy20960632017-10-12 11:43:41 +0100372 u8 dev_idx, auto_en = 0;
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100373
374 if (!unformat_user (input, unformat_line_input, line_input))
375 return clib_error_return (0, "invalid syntax");
376
377 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
378 {
379 if (unformat (line_input, "%u %u", &dev_idx, &thread_idx))
380 ;
381 else if (unformat (line_input, "auto"))
382 auto_en = 1;
383 else
384 {
385 unformat_free (line_input);
386 return clib_error_return (0, "parse error: '%U'",
387 format_unformat_error, line_input);
388 }
389 }
390
391 unformat_free (line_input);
392
393 if (auto_en)
394 {
395 crypto_auto_placement ();
396 return 0;
397 }
398
399 /* TODO support device name */
400
401 if (!(dev_idx < vec_len (dcm->dev)))
402 return clib_error_return (0, "please specify valid device index");
403
404 if (thread_idx != (u32) ~ 0 && !(thread_idx < vec_len (dcm->workers_main)))
405 return clib_error_return (0, "invalid thread index");
406
407 dev = vec_elt_at_index (dcm->dev, dev_idx);
408 if (!(vec_len (dev->free_resources)))
409 return clib_error_return (0, "all device resources are being used");
410
411 /* Check thread is not already using the device */
412 /* *INDENT-OFF* */
413 vec_foreach (idx, dev->used_resources)
414 if (dcm->resource[idx[0]].thread_idx == thread_idx)
415 return clib_error_return (0, "thread %u already using device %u",
416 thread_idx, dev_idx);
417 /* *INDENT-ON* */
418
419 res_idx = vec_pop (dev->free_resources);
420 vec_add1 (dev->used_resources, res_idx);
421
422 cwm = vec_elt_at_index (dcm->workers_main, thread_idx);
423
424 ASSERT (dcm->resource[res_idx].thread_idx == (u16) ~ 0);
425 dcm->resource[res_idx].thread_idx = thread_idx;
426
427 /* Add device to vector of polling resources */
428 vec_add1 (cwm->resource_idx, res_idx);
429
430 /* Set device as default for all supported algos */
431 for (i = 0; i < IPSEC_CRYPTO_N_ALG; i++)
432 if (dev->cipher_support[i])
433 {
434 if (cwm->cipher_resource_idx[i] == (u16) ~ 0)
435 dcm->cipher_algs[i].disabled--;
436 cwm->cipher_resource_idx[i] = res_idx;
437 }
438
439 for (i = 0; i < IPSEC_INTEG_N_ALG; i++)
440 if (dev->auth_support[i])
441 {
442 if (cwm->auth_resource_idx[i] == (u16) ~ 0)
443 dcm->auth_algs[i].disabled--;
444 cwm->auth_resource_idx[i] = res_idx;
445 }
446
447 /* Check if any unused resource */
448
449 u8 used = 0;
450 /* *INDENT-OFF* */
451 vec_foreach (idx, cwm->resource_idx)
452 {
453 if (idx[0] == res_idx)
454 continue;
455
456 for (i = 0; i < IPSEC_CRYPTO_N_ALG; i++)
457 used |= cwm->cipher_resource_idx[i] == idx[0];
458
459 for (i = 0; i < IPSEC_INTEG_N_ALG; i++)
460 used |= cwm->auth_resource_idx[i] == idx[0];
461
462 vec_elt_at_index (dcm->resource, idx[0])->remove = !used;
463 }
464 /* *INDENT-ON* */
465
466 return 0;
467}
468
469/* *INDENT-OFF* */
470VLIB_CLI_COMMAND (set_dpdk_crypto_placement, static) = {
471 .path = "set dpdk crypto placement",
472 .short_help = "set dpdk crypto placement (<device> <thread> | auto)",
473 .function = set_dpdk_crypto_placement_fn,
474};
475/* *INDENT-ON* */
476
477/*
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700478 * The thread will not enqueue more operations to the device but will poll
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100479 * from it until there are no more inflight operations.
480*/
481static void
482dpdk_crypto_clear_resource (u16 res_idx)
483{
484 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
485 crypto_resource_t *res = vec_elt_at_index (dcm->resource, res_idx);
486 crypto_worker_main_t *cwm = &dcm->workers_main[res->thread_idx];
487 u32 i;
488
489 for (i = 0; i < IPSEC_CRYPTO_N_ALG; i++)
490 if (cwm->cipher_resource_idx[i] == res_idx)
491 {
492 cwm->cipher_resource_idx[i] = (u16) ~ 0;
493 dcm->cipher_algs[i].disabled++;
494 }
495
496 for (i = 0; i < IPSEC_INTEG_N_ALG; i++)
497 if (cwm->auth_resource_idx[i] == res_idx)
498 {
499 cwm->auth_resource_idx[i] = (u16) ~ 0;
500 dcm->auth_algs[i].disabled++;
501 }
502
503 /* Fully remove device on crypto_node once there are no inflights */
504 res->remove = 1;
505}
506
507static clib_error_t *
508clear_dpdk_crypto_placement_fn (vlib_main_t * vm,
509 unformat_input_t *
510 input, vlib_cli_command_t * cmd)
511{
512 unformat_input_t _line_input, *line_input = &_line_input;
513 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
514 crypto_dev_t *dev;
515 u32 thread_idx = (u32) ~ 0;
516 u16 *res_idx;
517 u8 dev_idx = (u8) ~ 0;
518 u8 free_all = 0;
519
520 if (!unformat_user (input, unformat_line_input, line_input))
521 return clib_error_return (0, "invalid syntax");
522
523 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
524 {
525 if (unformat (line_input, "%u %u", &dev_idx, &thread_idx))
526 ;
527 else if (unformat (line_input, "%u", &dev_idx))
528 free_all = 1;
529 else
530 {
531 unformat_free (line_input);
532 return clib_error_return (0, "parse error: '%U'",
533 format_unformat_error, line_input);
534 }
535 }
536
537 unformat_free (line_input);
538
539 if (!(dev_idx < vec_len (dcm->dev)))
540 return clib_error_return (0, "invalid device index");
541
542 dev = vec_elt_at_index (dcm->dev, dev_idx);
543
544 /* Clear all resources placements */
545 if (free_all)
546 {
547 /* *INDENT-OFF* */
548 vec_foreach (res_idx, dev->used_resources)
549 dpdk_crypto_clear_resource (res_idx[0]);
550 /* *INDENT-ON* */
551
552 return 0;
553 }
554
555 if (!(thread_idx < vec_len (dcm->workers_main)))
556 return clib_error_return (0, "invalid thread index");
557
558 /* Clear placement of device for given thread index */
559 /* *INDENT-OFF* */
560 vec_foreach (res_idx, dev->used_resources)
561 if (dcm->resource[res_idx[0]].thread_idx == thread_idx)
562 break;
563 /* *INDENT-ON* */
564
565 if (!(res_idx < vec_end (dev->used_resources)))
566 return clib_error_return (0, "thread %u is not using device %u",
567 thread_idx, dev_idx);
568
569 dpdk_crypto_clear_resource (res_idx[0]);
570
571 return 0;
572}
573
574/* *INDENT-OFF* */
575VLIB_CLI_COMMAND (clear_dpdk_crypto_placement, static) = {
576 .path = "clear dpdk crypto placement",
577 .short_help = "clear dpdk crypto placement <device> [<thread>]",
578 .function = clear_dpdk_crypto_placement_fn,
579};
580/* *INDENT-ON* */
581
582u8 *
583format_dpdk_mempool (u8 * s, va_list * args)
584{
585 struct rte_mempool *mp = va_arg (*args, struct rte_mempool *);
Gabriel Gannee3ea7972017-10-12 10:53:31 +0200586 u32 indent = format_get_indent (s);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100587 u32 count = rte_mempool_avail_count (mp);
588
589 s = format (s, "%s\n%Uavailable %7d, allocated %7d total %7d\n",
590 mp->name, format_white_space, indent + 2,
591 count, mp->size - count, mp->size);
592 s = format (s, "%Uphys_addr %p, flags %08x, nb_mem_chunks %u\n",
593 format_white_space, indent + 2,
Fan Zhangf0419a02020-12-01 15:10:43 +0000594 mp->mz->iova, mp->flags, mp->nb_mem_chunks);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100595 s = format (s, "%Uelt_size %4u, header_size %3u, trailer_size %u\n",
596 format_white_space, indent + 2,
597 mp->elt_size, mp->header_size, mp->trailer_size);
598 s = format (s, "%Uprivate_data_size %3u, total_elt_size %u\n",
599 format_white_space, indent + 2,
600 mp->private_data_size,
601 mp->elt_size + mp->header_size + mp->trailer_size);
602 return s;
603}
604
605static clib_error_t *
606show_dpdk_crypto_pools_fn (vlib_main_t * vm,
607 unformat_input_t * input, vlib_cli_command_t * cmd)
608{
609 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
610 crypto_data_t *data;
611
612 /* *INDENT-OFF* */
613 vec_foreach (data, dcm->data)
614 {
615 if (data->crypto_op)
616 vlib_cli_output (vm, "%U\n", format_dpdk_mempool, data->crypto_op);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100617 if (data->session_h)
618 vlib_cli_output (vm, "%U\n", format_dpdk_mempool, data->session_h);
619
620 struct rte_mempool **mp;
621 vec_foreach (mp, data->session_drv)
622 if (mp[0])
Kingwel Xie3b3464e2019-02-13 02:48:41 -0500623 vlib_cli_output (vm, "%U\n", format_dpdk_mempool, mp[0]);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100624 }
625 /* *INDENT-ON* */
626
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100627 return NULL;
628}
629
630/*?
631 * This command is used to display the DPDK Crypto pools information.
632 *
633 * @cliexpar
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700634 * Example of how to display the DPDK Crypto pools information:
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100635 * @cliexstart{show crypto device mapping}
636 * vpp# show dpdk crypto pools
637 * crypto_pool_numa1
638 * available 15872, allocated 512 total 16384
639 * phys_addr 0xf3d2086c0, flags 00000010, nb_mem_chunks 1
640 * elt_size 160, header_size 64, trailer_size 96
641 * private_data_size 64, total_elt_size 320
642 *
643 * session_h_pool_numa1
644 * available 19998, allocated 2 total 20000
645 * phys_addr 0xf3c9c4380, flags 00000010, nb_mem_chunks 1
646 * elt_size 40, header_size 64, trailer_size 88
647 * private_data_size 0, total_elt_size 192
648 *
649 * session_drv0_pool_numa1
650 * available 19998, allocated 2 total 20000
651 * phys_addr 0xf3ad42d80, flags 00000010, nb_mem_chunks 1
652 * elt_size 512, header_size 64, trailer_size 0
653 * private_data_size 0, total_elt_size 576
654 * @cliexend
655?*/
656/* *INDENT-OFF* */
657VLIB_CLI_COMMAND (show_dpdk_crypto_pools, static) = {
658 .path = "show dpdk crypto pools",
659 .short_help = "show dpdk crypto pools",
660 .function = show_dpdk_crypto_pools_fn,
661};
662/* *INDENT-ON* */
663
664/* TODO Allow user define number of sessions supported */
665/* TODO Allow user define descriptor queue size */
666
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000667/*
668 * fd.io coding-style-patch-verification: ON
669 *
670 * Local Variables:
671 * eval: (c-set-style "gnu")
672 * End:
673 */