9b83f8913dba7fe34481c68a35200c49acb82356
[vpp.git] / src / plugins / crypto_ia32 / main.c
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2019 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17
18 #include <vlib/vlib.h>
19 #include <vnet/plugin/plugin.h>
20 #include <vnet/crypto/crypto.h>
21 #include <crypto_ia32/crypto_ia32.h>
22
23 crypto_ia32_main_t crypto_ia32_main;
24
25 clib_error_t *
26 crypto_ia32_init (vlib_main_t * vm)
27 {
28   crypto_ia32_main_t *cm = &crypto_ia32_main;
29   vlib_thread_main_t *tm = vlib_get_thread_main ();
30   clib_error_t *error;
31
32   if ((error = vlib_call_init_function (vm, vnet_crypto_init)))
33     return error;
34
35   vec_validate_aligned (cm->per_thread_data, tm->n_vlib_mains - 1,
36                         CLIB_CACHE_LINE_BYTES);
37
38   cm->crypto_engine_index =
39     vnet_crypto_register_engine (vm, "ia32", 100,
40                                  "Intel IA32 ISA Optimized Crypto");
41
42   if (clib_cpu_supports_x86_aes () &&
43       (error = crypto_ia32_aesni_cbc_init (vm)))
44     goto error;
45
46 error:
47   if (error)
48     vec_free (cm->per_thread_data);
49
50   return error;
51 }
52
53 VLIB_INIT_FUNCTION (crypto_ia32_init);
54
55 #include <vpp/app/version.h>
56
57 /* *INDENT-OFF* */
58 VLIB_PLUGIN_REGISTER () = {
59   .version = VPP_BUILD_VER,
60   .description = "Intel AESNI Software Crypto Backend Plugin",
61 };
62 /* *INDENT-ON* */
63
64 /*
65  * fd.io coding-style-patch-verification: ON
66  *
67  * Local Variables:
68  * eval: (c-set-style "gnu")
69  * End:
70  */