3b634e036da232253aba69b5d74e72abd617cce4
[vpp.git] / vnet / vnet / devices / 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 <vnet/devices/dpdk/ipsec/ipsec.h>
18
19 static void
20 dpdk_ipsec_show_mapping (vlib_main_t * vm, u16 detail_display)
21 {
22   dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
23   vlib_thread_main_t *tm = vlib_get_thread_main ();
24   u32 i, skip_master;
25
26   if (detail_display)
27     vlib_cli_output (vm, "worker\t%10s\t%15s\tdir\tdev\tqp\n",
28                      "cipher", "auth");
29   else
30     vlib_cli_output (vm, "worker\tcrypto device id(type)\n");
31
32   skip_master = vlib_num_workers () > 0;
33
34   for (i = 0; i < tm->n_vlib_mains; i++)
35     {
36       uword key, data;
37       u32 cpu_index = vlib_mains[i]->cpu_index;
38       crypto_worker_main_t *cwm = &dcm->workers_main[cpu_index];
39       u8 *s = 0;
40
41       if (skip_master)
42         {
43           skip_master = 0;
44           continue;
45         }
46
47       if (!detail_display)
48         {
49           i32 last_cdev = -1;
50           crypto_qp_data_t *qpd;
51
52           s = format (s, "%u\t", cpu_index);
53
54           /* *INDENT-OFF* */
55           vec_foreach (qpd, cwm->qp_data)
56             {
57               u32 dev_id = qpd->dev_id;
58
59               if ((u16) last_cdev != dev_id)
60                 {
61                   struct rte_cryptodev_info cdev_info;
62
63                   rte_cryptodev_info_get (dev_id, &cdev_info);
64
65                   s = format(s, "%u(%s)\t", dev_id, cdev_info.feature_flags &
66                              RTE_CRYPTODEV_FF_HW_ACCELERATED ? "HW" : "SW");
67                 }
68               last_cdev = dev_id;
69             }
70           /* *INDENT-ON* */
71           vlib_cli_output (vm, "%s", s);
72         }
73       else
74         {
75           char cipher_str[15], auth_str[15];
76           struct rte_cryptodev_capabilities cap;
77           crypto_worker_qp_key_t *p_key = (crypto_worker_qp_key_t *) & key;
78           /* *INDENT-OFF* */
79           hash_foreach (key, data, cwm->algo_qp_map,
80           ({
81             cap.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC;
82             cap.sym.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER;
83             cap.sym.cipher.algo = p_key->cipher_algo;
84             check_algo_is_supported (&cap, cipher_str);
85             cap.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC;
86             cap.sym.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH;
87             cap.sym.auth.algo = p_key->auth_algo;
88             check_algo_is_supported (&cap, auth_str);
89             vlib_cli_output (vm, "%u\t%10s\t%15s\t%3s\t%u\t%u\n",
90                              vlib_mains[i]->cpu_index, cipher_str, auth_str,
91                              p_key->is_outbound ? "out" : "in",
92                              cwm->qp_data[data].dev_id,
93                              cwm->qp_data[data].qp_id);
94           }));
95           /* *INDENT-ON* */
96         }
97     }
98 }
99
100 static clib_error_t *
101 lcore_cryptodev_map_fn (vlib_main_t * vm, unformat_input_t * input,
102                         vlib_cli_command_t * cmd)
103 {
104   unformat_input_t _line_input, *line_input = &_line_input;
105   u16 detail = 0;
106
107   if (!unformat_user (input, unformat_line_input, line_input))
108     return 0;
109
110   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
111     {
112       if (unformat (line_input, "verbose"))
113         detail = 1;
114       else
115         return clib_error_return (0, "parse error: '%U'",
116                                   format_unformat_error, line_input);
117     }
118
119   unformat_free (line_input);
120
121   dpdk_ipsec_show_mapping (vm, detail);
122
123   return 0;
124 }
125
126 /* *INDENT-OFF* */
127 VLIB_CLI_COMMAND (lcore_cryptodev_map, static) = {
128     .path = "show crypto device mapping",
129     .short_help =
130     "show cryptodev device mapping <verbose>",
131     .function = lcore_cryptodev_map_fn,
132 };
133 /* *INDENT-ON* */
134
135 /*
136  * fd.io coding-style-patch-verification: ON
137  *
138  * Local Variables:
139  * eval: (c-set-style "gnu")
140  * End:
141  */