Merge branch 'akpm' (patches from Andrew)
[cascardo/linux.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/crypto.h>
27 #include <asm/cputable.h>
28 #include <crypto/internal/hash.h>
29
30 extern struct shash_alg p8_ghash_alg;
31 extern struct crypto_alg p8_aes_alg;
32 extern struct crypto_alg p8_aes_cbc_alg;
33 extern struct crypto_alg p8_aes_ctr_alg;
34 extern struct crypto_alg p8_aes_xts_alg;
35 static struct crypto_alg *algs[] = {
36         &p8_aes_alg,
37         &p8_aes_cbc_alg,
38         &p8_aes_ctr_alg,
39         &p8_aes_xts_alg,
40         NULL,
41 };
42
43 int __init p8_init(void)
44 {
45         int ret = 0;
46         struct crypto_alg **alg_it;
47
48         if (!(cur_cpu_spec->cpu_user_features2 & PPC_FEATURE2_VEC_CRYPTO))
49                 return -ENODEV;
50
51         for (alg_it = algs; *alg_it; alg_it++) {
52                 ret = crypto_register_alg(*alg_it);
53                 printk(KERN_INFO "crypto_register_alg '%s' = %d\n",
54                        (*alg_it)->cra_name, ret);
55                 if (ret) {
56                         for (alg_it--; alg_it >= algs; alg_it--)
57                                 crypto_unregister_alg(*alg_it);
58                         break;
59                 }
60         }
61         if (ret)
62                 return ret;
63
64         ret = crypto_register_shash(&p8_ghash_alg);
65         if (ret) {
66                 for (alg_it = algs; *alg_it; alg_it++)
67                         crypto_unregister_alg(*alg_it);
68         }
69         return ret;
70 }
71
72 void __exit p8_exit(void)
73 {
74         struct crypto_alg **alg_it;
75
76         for (alg_it = algs; *alg_it; alg_it++) {
77                 printk(KERN_INFO "Removing '%s'\n", (*alg_it)->cra_name);
78                 crypto_unregister_alg(*alg_it);
79         }
80         crypto_unregister_shash(&p8_ghash_alg);
81 }
82
83 module_init(p8_init);
84 module_exit(p8_exit);
85
86 MODULE_AUTHOR("Marcelo Cerri<mhcerri@br.ibm.com>");
87 MODULE_DESCRIPTION("IBM VMX cryptographic acceleration instructions "
88                    "support on Power 8");
89 MODULE_LICENSE("GPL");
90 MODULE_VERSION("1.0.0");