Marcelo H. Cerri | 20a26fa | 2015-02-06 14:56:50 -0200 | [diff] [blame] | 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> |
Alastair D'Silva | ccf5c44 | 2016-07-19 14:03:53 +1000 | [diff] [blame] | 26 | #include <linux/cpufeature.h> |
Marcelo H. Cerri | 20a26fa | 2015-02-06 14:56:50 -0200 | [diff] [blame] | 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; |
Leonidas S. Barbosa | c07f5d3 | 2016-07-18 12:26:26 -0300 | [diff] [blame] | 35 | extern struct crypto_alg p8_aes_xts_alg; |
Marcelo H. Cerri | 20a26fa | 2015-02-06 14:56:50 -0200 | [diff] [blame] | 36 | static struct crypto_alg *algs[] = { |
Herbert Xu | 4beb106 | 2015-06-15 16:55:46 +0800 | [diff] [blame] | 37 | &p8_aes_alg, |
| 38 | &p8_aes_cbc_alg, |
| 39 | &p8_aes_ctr_alg, |
Leonidas S. Barbosa | c07f5d3 | 2016-07-18 12:26:26 -0300 | [diff] [blame] | 40 | &p8_aes_xts_alg, |
Herbert Xu | 4beb106 | 2015-06-15 16:55:46 +0800 | [diff] [blame] | 41 | NULL, |
Marcelo H. Cerri | 20a26fa | 2015-02-06 14:56:50 -0200 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | int __init p8_init(void) |
| 45 | { |
Herbert Xu | 4beb106 | 2015-06-15 16:55:46 +0800 | [diff] [blame] | 46 | int ret = 0; |
| 47 | struct crypto_alg **alg_it; |
Marcelo H. Cerri | 20a26fa | 2015-02-06 14:56:50 -0200 | [diff] [blame] | 48 | |
Herbert Xu | 4beb106 | 2015-06-15 16:55:46 +0800 | [diff] [blame] | 49 | for (alg_it = algs; *alg_it; alg_it++) { |
| 50 | ret = crypto_register_alg(*alg_it); |
| 51 | printk(KERN_INFO "crypto_register_alg '%s' = %d\n", |
| 52 | (*alg_it)->cra_name, ret); |
| 53 | if (ret) { |
| 54 | for (alg_it--; alg_it >= algs; alg_it--) |
| 55 | crypto_unregister_alg(*alg_it); |
| 56 | break; |
| 57 | } |
| 58 | } |
| 59 | if (ret) |
| 60 | return ret; |
Marcelo H. Cerri | 20a26fa | 2015-02-06 14:56:50 -0200 | [diff] [blame] | 61 | |
Herbert Xu | 4beb106 | 2015-06-15 16:55:46 +0800 | [diff] [blame] | 62 | ret = crypto_register_shash(&p8_ghash_alg); |
| 63 | if (ret) { |
| 64 | for (alg_it = algs; *alg_it; alg_it++) |
| 65 | crypto_unregister_alg(*alg_it); |
| 66 | } |
| 67 | return ret; |
Marcelo H. Cerri | 20a26fa | 2015-02-06 14:56:50 -0200 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void __exit p8_exit(void) |
| 71 | { |
Herbert Xu | 4beb106 | 2015-06-15 16:55:46 +0800 | [diff] [blame] | 72 | struct crypto_alg **alg_it; |
Marcelo H. Cerri | 20a26fa | 2015-02-06 14:56:50 -0200 | [diff] [blame] | 73 | |
Herbert Xu | 4beb106 | 2015-06-15 16:55:46 +0800 | [diff] [blame] | 74 | for (alg_it = algs; *alg_it; alg_it++) { |
| 75 | printk(KERN_INFO "Removing '%s'\n", (*alg_it)->cra_name); |
| 76 | crypto_unregister_alg(*alg_it); |
| 77 | } |
| 78 | crypto_unregister_shash(&p8_ghash_alg); |
Marcelo H. Cerri | 20a26fa | 2015-02-06 14:56:50 -0200 | [diff] [blame] | 79 | } |
| 80 | |
Alastair D'Silva | ccf5c44 | 2016-07-19 14:03:53 +1000 | [diff] [blame] | 81 | module_cpu_feature_match(PPC_MODULE_FEATURE_VEC_CRYPTO, p8_init); |
Marcelo H. Cerri | 20a26fa | 2015-02-06 14:56:50 -0200 | [diff] [blame] | 82 | module_exit(p8_exit); |
| 83 | |
| 84 | MODULE_AUTHOR("Marcelo Cerri<mhcerri@br.ibm.com>"); |
Herbert Xu | 4beb106 | 2015-06-15 16:55:46 +0800 | [diff] [blame] | 85 | MODULE_DESCRIPTION("IBM VMX cryptographic acceleration instructions " |
| 86 | "support on Power 8"); |
Marcelo H. Cerri | 20a26fa | 2015-02-06 14:56:50 -0200 | [diff] [blame] | 87 | MODULE_LICENSE("GPL"); |
| 88 | MODULE_VERSION("1.0.0"); |