a9cf250298b181fdfef3fe54b76c9e841244895b
[vpp.git] / src / plugins / dpdk / ipsec / cli.c
1 /*
2  * Copyright (c) 2016 Intel and/or its affiliates.
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>
17 #include <dpdk/device/dpdk.h>
18 #include <dpdk/ipsec/ipsec.h>
19
20 static void
21 dpdk_ipsec_show_mapping (vlib_main_t * vm, u16 detail_display)
22 {
23   dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
24   vlib_thread_main_t *tm = vlib_get_thread_main ();
25   u32 i, skip_master;
26
27   if (!dcm->enabled)
28     {
29       vlib_cli_output (vm, "DPDK Cryptodev support is disabled\n");
30       return;
31     }
32
33   if (detail_display)
34     vlib_cli_output (vm, "worker\t%10s\t%15s\tdir\tdev\tqp\n",
35                      "cipher", "auth");
36   else
37     vlib_cli_output (vm, "worker\tcrypto device id(type)\n");
38
39   skip_master = vlib_num_workers () > 0;
40
41   for (i = 0; i < tm->n_vlib_mains; i++)
42     {
43       uword key, data;
44       u32 thread_index = vlib_mains[i]->thread_index;
45       crypto_worker_main_t *cwm = &dcm->workers_main[thread_index];
46       u8 *s = 0;
47
48       if (skip_master)
49         {
50           skip_master = 0;
51           continue;
52         }
53
54       if (!detail_display)
55         {
56           i32 last_cdev = -1;
57           crypto_qp_data_t *qpd;
58
59           s = format (s, "%u\t", thread_index);
60
61           /* *INDENT-OFF* */
62           vec_foreach (qpd, cwm->qp_data)
63             {
64               u32 dev_id = qpd->dev_id;
65
66               if ((u16) last_cdev != dev_id)
67                 {
68                   struct rte_cryptodev_info cdev_info;
69
70                   rte_cryptodev_info_get (dev_id, &cdev_info);
71
72                   s = format(s, "%u(%s)\t", dev_id, cdev_info.feature_flags &
73                              RTE_CRYPTODEV_FF_HW_ACCELERATED ? "HW" : "SW");
74                 }
75               last_cdev = dev_id;
76             }
77           /* *INDENT-ON* */
78           vlib_cli_output (vm, "%s", s);
79         }
80       else
81         {
82           char cipher_str[15], auth_str[15];
83           struct rte_cryptodev_capabilities cap;
84           crypto_worker_qp_key_t *p_key = (crypto_worker_qp_key_t *) & key;
85           /* *INDENT-OFF* */
86           hash_foreach (key, data, cwm->algo_qp_map,
87           ({
88             cap.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC;
89 #if DPDK_NO_AEAD
90             cap.sym.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER;
91             cap.sym.cipher.algo = p_key->cipher_algo;
92 #else
93             if (p_key->is_aead)
94               {
95                 cap.sym.xform_type = RTE_CRYPTO_SYM_XFORM_AEAD;
96                 cap.sym.aead.algo = p_key->cipher_algo;
97               }
98             else
99               {
100                 cap.sym.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER;
101                 cap.sym.cipher.algo = p_key->cipher_algo;
102               }
103 #endif
104             check_algo_is_supported (&cap, cipher_str);
105
106             cap.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC;
107             cap.sym.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH;
108             cap.sym.auth.algo = p_key->auth_algo;
109             check_algo_is_supported (&cap, auth_str);
110
111             vlib_cli_output (vm, "%u\t%10s\t%15s\t%3s\t%u\t%u\n",
112                              vlib_mains[i]->thread_index, cipher_str, auth_str,
113                              p_key->is_outbound ? "out" : "in",
114                              cwm->qp_data[data].dev_id,
115                              cwm->qp_data[data].qp_id);
116           }));
117           /* *INDENT-ON* */
118         }
119     }
120 }
121
122 static clib_error_t *
123 lcore_cryptodev_map_fn (vlib_main_t * vm, unformat_input_t * input,
124                         vlib_cli_command_t * cmd)
125 {
126   unformat_input_t _line_input, *line_input = &_line_input;
127   u16 detail = 0;
128   clib_error_t *error = NULL;
129
130   if (!unformat_user (input, unformat_line_input, line_input))
131     return 0;
132
133   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
134     {
135       if (unformat (line_input, "verbose"))
136         detail = 1;
137       else
138         {
139           error = clib_error_return (0, "parse error: '%U'",
140                                      format_unformat_error, line_input);
141           goto done;
142         }
143     }
144
145   dpdk_ipsec_show_mapping (vm, detail);
146
147 done:
148   unformat_free (line_input);
149
150   return error;
151 }
152
153 /*?
154  * This command is used to display the DPDK Crypto device data. See
155  * @ref dpdk_crypto_ipsec_doc for more details on initializing the
156  * DPDK Crypto device.
157  *
158  * @cliexpar
159  * Example of displaying the DPDK Crypto device data when disabled:
160  * @cliexstart{show crypto device mapping}
161  * DPDK Cryptodev support is disabled
162  * @cliexend
163  * Example of displaying the DPDK Crypto device data when enabled:
164  * @cliexstart{show crypto device mapping}
165  * worker  crypto device id(type)
166  * 1       1(SW)
167  * 2       1(SW)
168  * @cliexend
169  * Example of displaying the DPDK Crypto device data when enabled with verbose:
170  * @cliexstart{show crypto device mapping verbose}
171  * worker      cipher                 auth dir     dev     qp
172  * 1          AES_CTR         AES-XCBC-MAC  in     1       0
173  * 1          AES_CTR          HMAC-SHA384  in     1       0
174  * 1          AES_CTR          HMAC-SHA384 out     1       1
175  * 1          AES_CBC          HMAC-SHA512  in     1       0
176  * 1          AES_CBC          HMAC-SHA256  in     1       0
177  * 1          AES_CBC         AES-XCBC-MAC out     1       1
178  * 1          AES_CTR         AES-XCBC-MAC out     1       1
179  * 1          AES_CBC          HMAC-SHA256 out     1       1
180  * 1          AES_CTR          HMAC-SHA512 out     1       1
181  * 1          AES_CTR          HMAC-SHA256  in     1       0
182  * 1          AES_CTR            HMAC-SHA1  in     1       0
183  * 1          AES_CBC          HMAC-SHA512 out     1       1
184  * 1          AES_CBC          HMAC-SHA384 out     1       1
185  * 1          AES_CTR            HMAC-SHA1 out     1       1
186  * 1          AES_CTR          HMAC-SHA256 out     1       1
187  * 1          AES_CBC            HMAC-SHA1  in     1       0
188  * 1          AES_CBC         AES-XCBC-MAC  in     1       0
189  * 1          AES_CTR          HMAC-SHA512  in     1       0
190  * 1          AES_CBC            HMAC-SHA1 out     1       1
191  * 1          AES_CBC          HMAC-SHA384  in     1       0
192  * 2          AES_CTR         AES-XCBC-MAC  in     1       2
193  * 2          AES_CTR          HMAC-SHA384  in     1       2
194  * 2          AES_CTR          HMAC-SHA384 out     1       3
195  * 2          AES_CBC          HMAC-SHA512  in     1       2
196  * 2          AES_CBC          HMAC-SHA256  in     1       2
197  * 2          AES_CBC         AES-XCBC-MAC out     1       3
198  * 2          AES_CTR         AES-XCBC-MAC out     1       3
199  * 2          AES_CBC          HMAC-SHA256 out     1       3
200  * 2          AES_CTR          HMAC-SHA512 out     1       3
201  * 2          AES_CTR          HMAC-SHA256  in     1       2
202  * 2          AES_CTR            HMAC-SHA1  in     1       2
203  * 2          AES_CBC          HMAC-SHA512 out     1       3
204  * 2          AES_CBC          HMAC-SHA384 out     1       3
205  * 2          AES_CTR            HMAC-SHA1 out     1       3
206  * 2          AES_CTR          HMAC-SHA256 out     1       3
207  * 2          AES_CBC            HMAC-SHA1  in     1       2
208  * 2          AES_CBC         AES-XCBC-MAC  in     1       2
209  * 2          AES_CTR          HMAC-SHA512  in     1       2
210  * 2          AES_CBC            HMAC-SHA1 out     1       3
211  * 2          AES_CBC          HMAC-SHA384  in     1       2
212  * @cliexend
213 ?*/
214 /* *INDENT-OFF* */
215 VLIB_CLI_COMMAND (lcore_cryptodev_map, static) = {
216     .path = "show crypto device mapping",
217     .short_help =
218     "show cryptodev device mapping [verbose]",
219     .function = lcore_cryptodev_map_fn,
220 };
221 /* *INDENT-ON* */
222
223 /*
224  * fd.io coding-style-patch-verification: ON
225  *
226  * Local Variables:
227  * eval: (c-set-style "gnu")
228  * End:
229  */