summaryrefslogtreecommitdiff
path: root/drivers/crypto/vmx/vmx.c
blob: 44d8d5cfe40d2d6f6a48ab49ed131cbdd8228481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
 * Routines supporting VMX instructions on the Power 8
 *
 * Copyright (C) 2015 International Business Machines Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 only.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * Author: Marcelo Henrique Cerri <mhcerri@br.ibm.com>
 */

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/types.h>
#include <linux/err.h>
#include <linux/crypto.h>
#include <asm/cputable.h>
#include <crypto/internal/hash.h>

extern struct shash_alg p8_ghash_alg;
extern struct crypto_alg p8_aes_alg;
extern struct crypto_alg p8_aes_cbc_alg;
extern struct crypto_alg p8_aes_ctr_alg;
static struct crypto_alg *algs[] = {
    &p8_aes_alg,
    &p8_aes_cbc_alg,
    &p8_aes_ctr_alg,
    NULL,
};

int __init p8_init(void)
{
    int ret = 0;
    struct crypto_alg **alg_it;

    if (!(cur_cpu_spec->cpu_user_features2 & PPC_FEATURE2_VEC_CRYPTO))
        return -ENODEV;

    for (alg_it = algs; *alg_it; alg_it++) {
        ret = crypto_register_alg(*alg_it);
        printk(KERN_INFO "crypto_register_alg '%s' = %d\n",
                (*alg_it)->cra_name, ret);
        if (ret) {
            for (alg_it--; alg_it >= algs; alg_it--)
                crypto_unregister_alg(*alg_it);
            break;
        }
    }
    if (ret)
        return ret;

    ret = crypto_register_shash(&p8_ghash_alg);
    if (ret) {
        for (alg_it = algs; *alg_it; alg_it++)
            crypto_unregister_alg(*alg_it);
    }
    return ret;
}

void __exit p8_exit(void)
{
    struct crypto_alg **alg_it;

    for (alg_it = algs; *alg_it; alg_it++) {
        printk(KERN_INFO "Removing '%s'\n", (*alg_it)->cra_name);
        crypto_unregister_alg(*alg_it);
    }
    crypto_unregister_shash(&p8_ghash_alg);
}

module_init(p8_init);
module_exit(p8_exit);

MODULE_AUTHOR("Marcelo Cerri<mhcerri@br.ibm.com>");
MODULE_DESCRIPTION("IBM VMX cryptogaphic acceleration instructions support on Power 8");
MODULE_LICENSE("GPL");
MODULE_VERSION("1.0.0");