blob: 8fdda020a77af1787df497fd2bb154a229dff703 [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:
144 * @cliexsart{clear dpdk crypto devices statistics}
145 * vpp# clear dpdk crypto devices statistics
146 * @cliexend
147 * Example of clearing the DPDK Crypto device statistic data:
148 * @cliexend
149?*/
150/* *INDENT-OFF* */
151VLIB_CLI_COMMAND (clear_dpdk_crypto_stats, static) = {
152 .path = "clear dpdk crypto devices statistics",
153 .short_help = "clear dpdk crypto devices statistics",
154 .function = clear_crypto_stats_fn,
155};
156/* *INDENT-ON* */
157
158
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000159static clib_error_t *
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100160show_dpdk_crypto_fn (vlib_main_t * vm, unformat_input_t * input,
161 vlib_cli_command_t * cmd)
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000162{
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100163 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
164 crypto_dev_t *dev;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000165
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100166 /* *INDENT-OFF* */
167 vec_foreach (dev, dcm->dev)
168 vlib_cli_output (vm, "%U", format_crypto, dev);
169 /* *INDENT-ON* */
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000170
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100171 return NULL;
172}
173
174/*?
175 * This command is used to display the DPDK Crypto device information.
176 *
177 * @cliexpar
178 * Example of how to display the DPDK Crypto device information:
179 * @cliexsart{show dpdk crypto devices}
180 * vpp# show dpdk crypto devices
Kingwel Xie3b3464e2019-02-13 02:48:41 -0500181 * aesni_mb0 crypto_aesni_mb up
182 * numa_node 0, max_queues 4
183 * SYMMETRIC_CRYPTO, SYM_OPERATION_CHAINING, CPU_AVX2, CPU_AESNI
184 * Cipher: aes-cbc-128, aes-cbc-192, aes-cbc-256, aes-ctr-128, aes-ctr-192, aes-ctr-256, aes-gcm-128, aes-gcm-192, aes-gcm-256
185 * Auth: md5-96, sha1-96, sha-256-128, sha-384-192, sha-512-256
186 * enqueue 2 dequeue 2 enqueue_err 0 dequeue_err 0
187 * free_resources 3 :
188 * thr_id -1 qp 3 inflight 0
189 * thr_id -1 qp 2 inflight 0
190 * thr_id -1 qp 1 inflight 0
191 * used_resources 1 :
192 * thr_id 1 qp 0 inflight 0
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100193 * @cliexend
194 * Example of displaying the DPDK Crypto device data when enabled:
195 * @cliexend
196?*/
197/* *INDENT-OFF* */
198VLIB_CLI_COMMAND (show_dpdk_crypto, static) = {
199 .path = "show dpdk crypto devices",
200 .short_help = "show dpdk crypto devices",
201 .function = show_dpdk_crypto_fn,
202};
203
204/* *INDENT-ON* */
205static u8 *
206format_crypto_worker (u8 * s, va_list * args)
207{
208 u32 thread_idx = va_arg (*args, u32);
209 u8 verbose = (u8) va_arg (*args, u32);
210 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
211 crypto_worker_main_t *cwm;
212 crypto_resource_t *res;
213 u16 *res_idx;
Damjan Marionffe9d212018-05-30 09:26:11 +0200214 char *pre, *ind;
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100215 u32 i;
216
217 cwm = vec_elt_at_index (dcm->workers_main, thread_idx);
218
219 s = format (s, "Thread %u (%v):\n", thread_idx,
220 vlib_worker_threads[thread_idx].name);
221
222 /* *INDENT-OFF* */
223 vec_foreach (res_idx, cwm->resource_idx)
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000224 {
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100225 ind = " ";
226 res = vec_elt_at_index (dcm->resource, res_idx[0]);
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100227 s = format (s, "%s%-20s dev-id %2u queue-pair %2u\n",
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100228 ind, vec_elt_at_index (dcm->dev, res->dev_id)->name,
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100229 res->dev_id, res->qp_id);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100230
231 ind = " ";
232 if (verbose)
Billy McFalla9a20e72017-02-15 11:39:12 -0500233 {
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100234 s = format (s, "%sCipher:", ind);
235 pre = " ";
236 for (i = 0; i < IPSEC_CRYPTO_N_ALG; i++)
237 if (cwm->cipher_resource_idx[i] == res_idx[0])
238 {
239 s = format (s, "%s%s", pre, dcm->cipher_algs[i].name);
240 pre = ", ";
241 }
242 s = format (s, "\n");
243
244 s = format (s, "%sAuth:", ind);
245 pre = " ";
246 for (i = 0; i < IPSEC_INTEG_N_ALG; i++)
247 if (cwm->auth_resource_idx[i] == res_idx[0])
248 {
249 s = format (s, "%s%s", pre, dcm->auth_algs[i].name);
250 pre = ", ";
251 }
252 s = format (s, "\n");
Billy McFalla9a20e72017-02-15 11:39:12 -0500253 }
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000254 }
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100255 /* *INDENT-ON* */
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000256
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100257 return s;
258}
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000259
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100260static clib_error_t *
261common_crypto_placement_fn (vlib_main_t * vm, unformat_input_t * input,
262 vlib_cli_command_t * cmd, u8 verbose)
263{
264 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
265 clib_error_t *error = NULL;
266 u32 i;
267 u8 skip_master;
268
269 if (!dcm->enabled)
270 {
271 vlib_cli_output (vm, "\nDPDK Cryptodev support is disabled\n");
272 return error;
273 }
274
275 skip_master = vlib_num_workers () > 0;
276
277 /* *INDENT-OFF* */
278 vec_foreach_index (i, dcm->workers_main)
279 {
280 if (i < skip_master)
281 continue;
282
283 vlib_cli_output (vm, "%U\n", format_crypto_worker, i, verbose);
284 }
285 /* *INDENT-ON* */
Billy McFalla9a20e72017-02-15 11:39:12 -0500286
287 return error;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000288}
289
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100290static clib_error_t *
291show_dpdk_crypto_placement_fn (vlib_main_t * vm, unformat_input_t * input,
292 vlib_cli_command_t * cmd)
293{
294 return common_crypto_placement_fn (vm, input, cmd, 0);
295}
296
297static clib_error_t *
298show_dpdk_crypto_placement_v_fn (vlib_main_t * vm, unformat_input_t * input,
299 vlib_cli_command_t * cmd)
300{
301 return common_crypto_placement_fn (vm, input, cmd, 1);
302}
303
Billy McFalldfde53a2017-03-10 14:49:15 -0500304/*?
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100305 * This command is used to display the DPDK Crypto device placement.
Billy McFalldfde53a2017-03-10 14:49:15 -0500306 *
307 * @cliexpar
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100308 * Example of displaying the DPDK Crypto device placement:
309 * @cliexstart{show dpdk crypto placement}
310 * vpp# show dpdk crypto placement
311 * Thread 1 (vpp_wk_0):
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100312 * cryptodev_aesni_mb_p dev-id 0 queue-pair 0
313 * cryptodev_aesni_gcm_ dev-id 1 queue-pair 0
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100314 *
315 * Thread 2 (vpp_wk_1):
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100316 * cryptodev_aesni_mb_p dev-id 0 queue-pair 1
317 * cryptodev_aesni_gcm_ dev-id 1 queue-pair 1
Billy McFalldfde53a2017-03-10 14:49:15 -0500318 * @cliexend
319?*/
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000320/* *INDENT-OFF* */
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100321VLIB_CLI_COMMAND (show_dpdk_crypto_placement, static) = {
322 .path = "show dpdk crypto placement",
323 .short_help = "show dpdk crypto placement",
324 .function = show_dpdk_crypto_placement_fn,
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000325};
326/* *INDENT-ON* */
327
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100328/*?
329 * This command is used to display the DPDK Crypto device placement
330 * with verbose output.
331 *
332 * @cliexpar
333 * Example of displaying the DPDK Crypto device placement verbose:
334 * @cliexstart{show dpdk crypto placement verbose}
335 * vpp# show dpdk crypto placement verbose
336 * Thread 1 (vpp_wk_0):
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100337 * cryptodev_aesni_mb_p dev-id 0 queue-pair 0
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100338 * Cipher: aes-cbc-128, aes-cbc-192, aes-cbc-256, aes-ctr-128, aes-ctr-192, aes-ctr-256
339 * Auth: md5-96, sha1-96, sha-256-128, sha-384-192, sha-512-256
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100340 * cryptodev_aesni_gcm_ dev-id 1 queue-pair 0
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100341 * Cipher: aes-gcm-128, aes-gcm-192, aes-gcm-256
342 * Auth:
343 *
344 * Thread 2 (vpp_wk_1):
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100345 * cryptodev_aesni_mb_p dev-id 0 queue-pair 1
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100346 * Cipher: aes-cbc-128, aes-cbc-192, aes-cbc-256, aes-ctr-128, aes-ctr-192, aes-ctr-256
347 * Auth: md5-96, sha1-96, sha-256-128, sha-384-192, sha-512-256
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100348 * cryptodev_aesni_gcm_ dev-id 1 queue-pair 1
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100349 * Cipher: aes-gcm-128, aes-gcm-192, aes-gcm-256
350 * Auth:
351 *
352 * @cliexend
353?*/
354/* *INDENT-OFF* */
355VLIB_CLI_COMMAND (show_dpdk_crypto_placement_v, static) = {
356 .path = "show dpdk crypto placement verbose",
357 .short_help = "show dpdk crypto placement verbose",
358 .function = show_dpdk_crypto_placement_v_fn,
359};
360/* *INDENT-ON* */
361
362static clib_error_t *
363set_dpdk_crypto_placement_fn (vlib_main_t * vm,
364 unformat_input_t * input,
365 vlib_cli_command_t * cmd)
366{
367 unformat_input_t _line_input, *line_input = &_line_input;
368 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
369 crypto_worker_main_t *cwm;
370 crypto_dev_t *dev;
371 u32 thread_idx, i;
372 u16 res_idx, *idx;
Sergio Gonzalez Monroy20960632017-10-12 11:43:41 +0100373 u8 dev_idx, auto_en = 0;
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100374
375 if (!unformat_user (input, unformat_line_input, line_input))
376 return clib_error_return (0, "invalid syntax");
377
378 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
379 {
380 if (unformat (line_input, "%u %u", &dev_idx, &thread_idx))
381 ;
382 else if (unformat (line_input, "auto"))
383 auto_en = 1;
384 else
385 {
386 unformat_free (line_input);
387 return clib_error_return (0, "parse error: '%U'",
388 format_unformat_error, line_input);
389 }
390 }
391
392 unformat_free (line_input);
393
394 if (auto_en)
395 {
396 crypto_auto_placement ();
397 return 0;
398 }
399
400 /* TODO support device name */
401
402 if (!(dev_idx < vec_len (dcm->dev)))
403 return clib_error_return (0, "please specify valid device index");
404
405 if (thread_idx != (u32) ~ 0 && !(thread_idx < vec_len (dcm->workers_main)))
406 return clib_error_return (0, "invalid thread index");
407
408 dev = vec_elt_at_index (dcm->dev, dev_idx);
409 if (!(vec_len (dev->free_resources)))
410 return clib_error_return (0, "all device resources are being used");
411
412 /* Check thread is not already using the device */
413 /* *INDENT-OFF* */
414 vec_foreach (idx, dev->used_resources)
415 if (dcm->resource[idx[0]].thread_idx == thread_idx)
416 return clib_error_return (0, "thread %u already using device %u",
417 thread_idx, dev_idx);
418 /* *INDENT-ON* */
419
420 res_idx = vec_pop (dev->free_resources);
421 vec_add1 (dev->used_resources, res_idx);
422
423 cwm = vec_elt_at_index (dcm->workers_main, thread_idx);
424
425 ASSERT (dcm->resource[res_idx].thread_idx == (u16) ~ 0);
426 dcm->resource[res_idx].thread_idx = thread_idx;
427
428 /* Add device to vector of polling resources */
429 vec_add1 (cwm->resource_idx, res_idx);
430
431 /* Set device as default for all supported algos */
432 for (i = 0; i < IPSEC_CRYPTO_N_ALG; i++)
433 if (dev->cipher_support[i])
434 {
435 if (cwm->cipher_resource_idx[i] == (u16) ~ 0)
436 dcm->cipher_algs[i].disabled--;
437 cwm->cipher_resource_idx[i] = res_idx;
438 }
439
440 for (i = 0; i < IPSEC_INTEG_N_ALG; i++)
441 if (dev->auth_support[i])
442 {
443 if (cwm->auth_resource_idx[i] == (u16) ~ 0)
444 dcm->auth_algs[i].disabled--;
445 cwm->auth_resource_idx[i] = res_idx;
446 }
447
448 /* Check if any unused resource */
449
450 u8 used = 0;
451 /* *INDENT-OFF* */
452 vec_foreach (idx, cwm->resource_idx)
453 {
454 if (idx[0] == res_idx)
455 continue;
456
457 for (i = 0; i < IPSEC_CRYPTO_N_ALG; i++)
458 used |= cwm->cipher_resource_idx[i] == idx[0];
459
460 for (i = 0; i < IPSEC_INTEG_N_ALG; i++)
461 used |= cwm->auth_resource_idx[i] == idx[0];
462
463 vec_elt_at_index (dcm->resource, idx[0])->remove = !used;
464 }
465 /* *INDENT-ON* */
466
467 return 0;
468}
469
470/* *INDENT-OFF* */
471VLIB_CLI_COMMAND (set_dpdk_crypto_placement, static) = {
472 .path = "set dpdk crypto placement",
473 .short_help = "set dpdk crypto placement (<device> <thread> | auto)",
474 .function = set_dpdk_crypto_placement_fn,
475};
476/* *INDENT-ON* */
477
478/*
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700479 * The thread will not enqueue more operations to the device but will poll
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100480 * from it until there are no more inflight operations.
481*/
482static void
483dpdk_crypto_clear_resource (u16 res_idx)
484{
485 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
486 crypto_resource_t *res = vec_elt_at_index (dcm->resource, res_idx);
487 crypto_worker_main_t *cwm = &dcm->workers_main[res->thread_idx];
488 u32 i;
489
490 for (i = 0; i < IPSEC_CRYPTO_N_ALG; i++)
491 if (cwm->cipher_resource_idx[i] == res_idx)
492 {
493 cwm->cipher_resource_idx[i] = (u16) ~ 0;
494 dcm->cipher_algs[i].disabled++;
495 }
496
497 for (i = 0; i < IPSEC_INTEG_N_ALG; i++)
498 if (cwm->auth_resource_idx[i] == res_idx)
499 {
500 cwm->auth_resource_idx[i] = (u16) ~ 0;
501 dcm->auth_algs[i].disabled++;
502 }
503
504 /* Fully remove device on crypto_node once there are no inflights */
505 res->remove = 1;
506}
507
508static clib_error_t *
509clear_dpdk_crypto_placement_fn (vlib_main_t * vm,
510 unformat_input_t *
511 input, vlib_cli_command_t * cmd)
512{
513 unformat_input_t _line_input, *line_input = &_line_input;
514 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
515 crypto_dev_t *dev;
516 u32 thread_idx = (u32) ~ 0;
517 u16 *res_idx;
518 u8 dev_idx = (u8) ~ 0;
519 u8 free_all = 0;
520
521 if (!unformat_user (input, unformat_line_input, line_input))
522 return clib_error_return (0, "invalid syntax");
523
524 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
525 {
526 if (unformat (line_input, "%u %u", &dev_idx, &thread_idx))
527 ;
528 else if (unformat (line_input, "%u", &dev_idx))
529 free_all = 1;
530 else
531 {
532 unformat_free (line_input);
533 return clib_error_return (0, "parse error: '%U'",
534 format_unformat_error, line_input);
535 }
536 }
537
538 unformat_free (line_input);
539
540 if (!(dev_idx < vec_len (dcm->dev)))
541 return clib_error_return (0, "invalid device index");
542
543 dev = vec_elt_at_index (dcm->dev, dev_idx);
544
545 /* Clear all resources placements */
546 if (free_all)
547 {
548 /* *INDENT-OFF* */
549 vec_foreach (res_idx, dev->used_resources)
550 dpdk_crypto_clear_resource (res_idx[0]);
551 /* *INDENT-ON* */
552
553 return 0;
554 }
555
556 if (!(thread_idx < vec_len (dcm->workers_main)))
557 return clib_error_return (0, "invalid thread index");
558
559 /* Clear placement of device for given thread index */
560 /* *INDENT-OFF* */
561 vec_foreach (res_idx, dev->used_resources)
562 if (dcm->resource[res_idx[0]].thread_idx == thread_idx)
563 break;
564 /* *INDENT-ON* */
565
566 if (!(res_idx < vec_end (dev->used_resources)))
567 return clib_error_return (0, "thread %u is not using device %u",
568 thread_idx, dev_idx);
569
570 dpdk_crypto_clear_resource (res_idx[0]);
571
572 return 0;
573}
574
575/* *INDENT-OFF* */
576VLIB_CLI_COMMAND (clear_dpdk_crypto_placement, static) = {
577 .path = "clear dpdk crypto placement",
578 .short_help = "clear dpdk crypto placement <device> [<thread>]",
579 .function = clear_dpdk_crypto_placement_fn,
580};
581/* *INDENT-ON* */
582
583u8 *
584format_dpdk_mempool (u8 * s, va_list * args)
585{
586 struct rte_mempool *mp = va_arg (*args, struct rte_mempool *);
Gabriel Gannee3ea7972017-10-12 10:53:31 +0200587 u32 indent = format_get_indent (s);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100588 u32 count = rte_mempool_avail_count (mp);
589
590 s = format (s, "%s\n%Uavailable %7d, allocated %7d total %7d\n",
591 mp->name, format_white_space, indent + 2,
592 count, mp->size - count, mp->size);
593 s = format (s, "%Uphys_addr %p, flags %08x, nb_mem_chunks %u\n",
594 format_white_space, indent + 2,
Fan Zhangf0419a02020-12-01 15:10:43 +0000595 mp->mz->iova, mp->flags, mp->nb_mem_chunks);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100596 s = format (s, "%Uelt_size %4u, header_size %3u, trailer_size %u\n",
597 format_white_space, indent + 2,
598 mp->elt_size, mp->header_size, mp->trailer_size);
599 s = format (s, "%Uprivate_data_size %3u, total_elt_size %u\n",
600 format_white_space, indent + 2,
601 mp->private_data_size,
602 mp->elt_size + mp->header_size + mp->trailer_size);
603 return s;
604}
605
606static clib_error_t *
607show_dpdk_crypto_pools_fn (vlib_main_t * vm,
608 unformat_input_t * input, vlib_cli_command_t * cmd)
609{
610 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
611 crypto_data_t *data;
612
613 /* *INDENT-OFF* */
614 vec_foreach (data, dcm->data)
615 {
616 if (data->crypto_op)
617 vlib_cli_output (vm, "%U\n", format_dpdk_mempool, data->crypto_op);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100618 if (data->session_h)
619 vlib_cli_output (vm, "%U\n", format_dpdk_mempool, data->session_h);
620
621 struct rte_mempool **mp;
622 vec_foreach (mp, data->session_drv)
623 if (mp[0])
Kingwel Xie3b3464e2019-02-13 02:48:41 -0500624 vlib_cli_output (vm, "%U\n", format_dpdk_mempool, mp[0]);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100625 }
626 /* *INDENT-ON* */
627
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100628 return NULL;
629}
630
631/*?
632 * This command is used to display the DPDK Crypto pools information.
633 *
634 * @cliexpar
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700635 * Example of how to display the DPDK Crypto pools information:
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100636 * @cliexstart{show crypto device mapping}
637 * vpp# show dpdk crypto pools
638 * crypto_pool_numa1
639 * available 15872, allocated 512 total 16384
640 * phys_addr 0xf3d2086c0, flags 00000010, nb_mem_chunks 1
641 * elt_size 160, header_size 64, trailer_size 96
642 * private_data_size 64, total_elt_size 320
643 *
644 * session_h_pool_numa1
645 * available 19998, allocated 2 total 20000
646 * phys_addr 0xf3c9c4380, flags 00000010, nb_mem_chunks 1
647 * elt_size 40, header_size 64, trailer_size 88
648 * private_data_size 0, total_elt_size 192
649 *
650 * session_drv0_pool_numa1
651 * available 19998, allocated 2 total 20000
652 * phys_addr 0xf3ad42d80, flags 00000010, nb_mem_chunks 1
653 * elt_size 512, header_size 64, trailer_size 0
654 * private_data_size 0, total_elt_size 576
655 * @cliexend
656?*/
657/* *INDENT-OFF* */
658VLIB_CLI_COMMAND (show_dpdk_crypto_pools, static) = {
659 .path = "show dpdk crypto pools",
660 .short_help = "show dpdk crypto pools",
661 .function = show_dpdk_crypto_pools_fn,
662};
663/* *INDENT-ON* */
664
665/* TODO Allow user define number of sessions supported */
666/* TODO Allow user define descriptor queue size */
667
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000668/*
669 * fd.io coding-style-patch-verification: ON
670 *
671 * Local Variables:
672 * eval: (c-set-style "gnu")
673 * End:
674 */