Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 1 | /* |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017 Intel and/or its affiliates. |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 3 | * 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 Marion | c3a814b | 2017-02-28 19:22:22 +0100 | [diff] [blame] | 17 | #include <dpdk/device/dpdk.h> |
| 18 | #include <dpdk/ipsec/ipsec.h> |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 19 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 20 | static u8 * |
Kingwel Xie | 3b3464e | 2019-02-13 02:48:41 -0500 | [diff] [blame] | 21 | format_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 Monroy | d8a34a5 | 2019-05-06 22:44:14 +0200 | [diff] [blame] | 30 | |
Christian Hopps | 942b980 | 2020-07-14 09:41:43 -0400 | [diff] [blame] | 31 | s = format (s, "%U thr_id %3d qp %2u dec_inflight %u, enc_inflights %u\n", |
Sergio Gonzalez Monroy | d8a34a5 | 2019-05-06 22:44:14 +0200 | [diff] [blame] | 32 | format_white_space, indent, (i16) res->thread_idx, |
| 33 | res->qp_id, res->inflights[0], res->inflights[1]); |
Kingwel Xie | 3b3464e | 2019-02-13 02:48:41 -0500 | [diff] [blame] | 34 | |
| 35 | return s; |
| 36 | } |
| 37 | |
| 38 | static u8 * |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 39 | format_crypto (u8 * s, va_list * args) |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 40 | { |
| 41 | dpdk_crypto_main_t *dcm = &dpdk_crypto_main; |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 42 | 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 Marion | ffe9d21 | 2018-05-30 09:26:11 +0200 | [diff] [blame] | 46 | char *pre = " "; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 47 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 48 | 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 Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 51 | |
| 52 | if (dev->features) |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 53 | { |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 54 | for (mask = 1; mask != 0; mask <<= 1) |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 55 | { |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 56 | feat = dev->features & mask; |
| 57 | if (feat) |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 58 | { |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 59 | s = |
| 60 | format (s, "%s%s", pre, |
| 61 | rte_cryptodev_get_feature_name (feat)); |
| 62 | pre = ", "; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 63 | } |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 64 | } |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 65 | s = format (s, "\n"); |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 66 | } |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 67 | |
| 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 Xie | 3b3464e | 2019-02-13 02:48:41 -0500 | [diff] [blame] | 86 | 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 Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 119 | |
| 120 | return s; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Kingwel Xie | 3b3464e | 2019-02-13 02:48:41 -0500 | [diff] [blame] | 123 | |
| 124 | static clib_error_t * |
| 125 | clear_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* */ |
| 151 | VLIB_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 Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 159 | static clib_error_t * |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 160 | show_dpdk_crypto_fn (vlib_main_t * vm, unformat_input_t * input, |
| 161 | vlib_cli_command_t * cmd) |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 162 | { |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 163 | dpdk_crypto_main_t *dcm = &dpdk_crypto_main; |
| 164 | crypto_dev_t *dev; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 165 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 166 | /* *INDENT-OFF* */ |
| 167 | vec_foreach (dev, dcm->dev) |
| 168 | vlib_cli_output (vm, "%U", format_crypto, dev); |
| 169 | /* *INDENT-ON* */ |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 170 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 171 | 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 Xie | 3b3464e | 2019-02-13 02:48:41 -0500 | [diff] [blame] | 181 | * 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 Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 193 | * @cliexend |
| 194 | * Example of displaying the DPDK Crypto device data when enabled: |
| 195 | * @cliexend |
| 196 | ?*/ |
| 197 | /* *INDENT-OFF* */ |
| 198 | VLIB_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* */ |
| 205 | static u8 * |
| 206 | format_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 Marion | ffe9d21 | 2018-05-30 09:26:11 +0200 | [diff] [blame] | 214 | char *pre, *ind; |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 215 | 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 Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 224 | { |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 225 | ind = " "; |
| 226 | res = vec_elt_at_index (dcm->resource, res_idx[0]); |
Sergio Gonzalez Monroy | 35467f1 | 2019-01-30 11:26:00 +0100 | [diff] [blame] | 227 | s = format (s, "%s%-20s dev-id %2u queue-pair %2u\n", |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 228 | ind, vec_elt_at_index (dcm->dev, res->dev_id)->name, |
Sergio Gonzalez Monroy | 35467f1 | 2019-01-30 11:26:00 +0100 | [diff] [blame] | 229 | res->dev_id, res->qp_id); |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 230 | |
| 231 | ind = " "; |
| 232 | if (verbose) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 233 | { |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 234 | 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 McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 253 | } |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 254 | } |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 255 | /* *INDENT-ON* */ |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 256 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 257 | return s; |
| 258 | } |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 259 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 260 | static clib_error_t * |
| 261 | common_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 McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 286 | |
| 287 | return error; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 290 | static clib_error_t * |
| 291 | show_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 | |
| 297 | static clib_error_t * |
| 298 | show_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 McFall | dfde53a | 2017-03-10 14:49:15 -0500 | [diff] [blame] | 304 | /*? |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 305 | * This command is used to display the DPDK Crypto device placement. |
Billy McFall | dfde53a | 2017-03-10 14:49:15 -0500 | [diff] [blame] | 306 | * |
| 307 | * @cliexpar |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 308 | * 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 Monroy | 35467f1 | 2019-01-30 11:26:00 +0100 | [diff] [blame] | 312 | * cryptodev_aesni_mb_p dev-id 0 queue-pair 0 |
| 313 | * cryptodev_aesni_gcm_ dev-id 1 queue-pair 0 |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 314 | * |
| 315 | * Thread 2 (vpp_wk_1): |
Sergio Gonzalez Monroy | 35467f1 | 2019-01-30 11:26:00 +0100 | [diff] [blame] | 316 | * cryptodev_aesni_mb_p dev-id 0 queue-pair 1 |
| 317 | * cryptodev_aesni_gcm_ dev-id 1 queue-pair 1 |
Billy McFall | dfde53a | 2017-03-10 14:49:15 -0500 | [diff] [blame] | 318 | * @cliexend |
| 319 | ?*/ |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 320 | /* *INDENT-OFF* */ |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 321 | VLIB_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 Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 325 | }; |
| 326 | /* *INDENT-ON* */ |
| 327 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 328 | /*? |
| 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 Monroy | 35467f1 | 2019-01-30 11:26:00 +0100 | [diff] [blame] | 337 | * cryptodev_aesni_mb_p dev-id 0 queue-pair 0 |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 338 | * 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 Monroy | 35467f1 | 2019-01-30 11:26:00 +0100 | [diff] [blame] | 340 | * cryptodev_aesni_gcm_ dev-id 1 queue-pair 0 |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 341 | * Cipher: aes-gcm-128, aes-gcm-192, aes-gcm-256 |
| 342 | * Auth: |
| 343 | * |
| 344 | * Thread 2 (vpp_wk_1): |
Sergio Gonzalez Monroy | 35467f1 | 2019-01-30 11:26:00 +0100 | [diff] [blame] | 345 | * cryptodev_aesni_mb_p dev-id 0 queue-pair 1 |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 346 | * 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 Monroy | 35467f1 | 2019-01-30 11:26:00 +0100 | [diff] [blame] | 348 | * cryptodev_aesni_gcm_ dev-id 1 queue-pair 1 |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 349 | * Cipher: aes-gcm-128, aes-gcm-192, aes-gcm-256 |
| 350 | * Auth: |
| 351 | * |
| 352 | * @cliexend |
| 353 | ?*/ |
| 354 | /* *INDENT-OFF* */ |
| 355 | VLIB_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 | |
| 362 | static clib_error_t * |
| 363 | set_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 Monroy | 2096063 | 2017-10-12 11:43:41 +0100 | [diff] [blame] | 373 | u8 dev_idx, auto_en = 0; |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 374 | |
| 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* */ |
| 471 | VLIB_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 Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 479 | * The thread will not enqueue more operations to the device but will poll |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 480 | * from it until there are no more inflight operations. |
| 481 | */ |
| 482 | static void |
| 483 | dpdk_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 | |
| 508 | static clib_error_t * |
| 509 | clear_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* */ |
| 576 | VLIB_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 | |
| 583 | u8 * |
| 584 | format_dpdk_mempool (u8 * s, va_list * args) |
| 585 | { |
| 586 | struct rte_mempool *mp = va_arg (*args, struct rte_mempool *); |
Gabriel Ganne | e3ea797 | 2017-10-12 10:53:31 +0200 | [diff] [blame] | 587 | u32 indent = format_get_indent (s); |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 588 | 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 Zhang | f0419a0 | 2020-12-01 15:10:43 +0000 | [diff] [blame^] | 595 | mp->mz->iova, mp->flags, mp->nb_mem_chunks); |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 596 | 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 | |
| 606 | static clib_error_t * |
| 607 | show_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 Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 618 | 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 Xie | 3b3464e | 2019-02-13 02:48:41 -0500 | [diff] [blame] | 624 | vlib_cli_output (vm, "%U\n", format_dpdk_mempool, mp[0]); |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 625 | } |
| 626 | /* *INDENT-ON* */ |
| 627 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 628 | return NULL; |
| 629 | } |
| 630 | |
| 631 | /*? |
| 632 | * This command is used to display the DPDK Crypto pools information. |
| 633 | * |
| 634 | * @cliexpar |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 635 | * Example of how to display the DPDK Crypto pools information: |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 636 | * @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* */ |
| 658 | VLIB_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 Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 668 | /* |
| 669 | * fd.io coding-style-patch-verification: ON |
| 670 | * |
| 671 | * Local Variables: |
| 672 | * eval: (c-set-style "gnu") |
| 673 | * End: |
| 674 | */ |