]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/crypto/vmx/vmx.c
crypto: vmx - Convert to CPU feature based module autoloading
[mirror_ubuntu-zesty-kernel.git] / drivers / crypto / vmx / vmx.c
1 /**
2 * Routines supporting VMX instructions on the Power 8
3 *
4 * Copyright (C) 2015 International Business Machines Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 only.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 * Author: Marcelo Henrique Cerri <mhcerri@br.ibm.com>
20 */
21
22 #include <linux/module.h>
23 #include <linux/moduleparam.h>
24 #include <linux/types.h>
25 #include <linux/err.h>
26 #include <linux/cpufeature.h>
27 #include <linux/crypto.h>
28 #include <asm/cputable.h>
29 #include <crypto/internal/hash.h>
30
31 extern struct shash_alg p8_ghash_alg;
32 extern struct crypto_alg p8_aes_alg;
33 extern struct crypto_alg p8_aes_cbc_alg;
34 extern struct crypto_alg p8_aes_ctr_alg;
35 static struct crypto_alg *algs[] = {
36 &p8_aes_alg,
37 &p8_aes_cbc_alg,
38 &p8_aes_ctr_alg,
39 NULL,
40 };
41
42 int __init p8_init(void)
43 {
44 int ret = 0;
45 struct crypto_alg **alg_it;
46
47 for (alg_it = algs; *alg_it; alg_it++) {
48 ret = crypto_register_alg(*alg_it);
49 printk(KERN_INFO "crypto_register_alg '%s' = %d\n",
50 (*alg_it)->cra_name, ret);
51 if (ret) {
52 for (alg_it--; alg_it >= algs; alg_it--)
53 crypto_unregister_alg(*alg_it);
54 break;
55 }
56 }
57 if (ret)
58 return ret;
59
60 ret = crypto_register_shash(&p8_ghash_alg);
61 if (ret) {
62 for (alg_it = algs; *alg_it; alg_it++)
63 crypto_unregister_alg(*alg_it);
64 }
65 return ret;
66 }
67
68 void __exit p8_exit(void)
69 {
70 struct crypto_alg **alg_it;
71
72 for (alg_it = algs; *alg_it; alg_it++) {
73 printk(KERN_INFO "Removing '%s'\n", (*alg_it)->cra_name);
74 crypto_unregister_alg(*alg_it);
75 }
76 crypto_unregister_shash(&p8_ghash_alg);
77 }
78
79 module_cpu_feature_match(PPC_MODULE_FEATURE_VEC_CRYPTO, p8_init);
80 module_exit(p8_exit);
81
82 MODULE_AUTHOR("Marcelo Cerri<mhcerri@br.ibm.com>");
83 MODULE_DESCRIPTION("IBM VMX cryptographic acceleration instructions "
84 "support on Power 8");
85 MODULE_LICENSE("GPL");
86 MODULE_VERSION("1.0.0");