x86/oprofile: Fix bogus GCC-8 warning in nmi_setup()
[cris-mirror.git] / arch / arm64 / crypto / crct10dif-ce-glue.c
blob96f0cae4a02258bad9cf63639da45190499d1696
1 /*
2 * Accelerated CRC-T10DIF using arm64 NEON and Crypto Extensions instructions
4 * Copyright (C) 2016 - 2017 Linaro Ltd <ard.biesheuvel@linaro.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
11 #include <linux/cpufeature.h>
12 #include <linux/crc-t10dif.h>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/string.h>
18 #include <crypto/internal/hash.h>
20 #include <asm/neon.h>
21 #include <asm/simd.h>
23 #define CRC_T10DIF_PMULL_CHUNK_SIZE 16U
25 asmlinkage u16 crc_t10dif_pmull(u16 init_crc, const u8 buf[], u64 len);
27 static int crct10dif_init(struct shash_desc *desc)
29 u16 *crc = shash_desc_ctx(desc);
31 *crc = 0;
32 return 0;
35 static int crct10dif_update(struct shash_desc *desc, const u8 *data,
36 unsigned int length)
38 u16 *crc = shash_desc_ctx(desc);
39 unsigned int l;
41 if (unlikely((u64)data % CRC_T10DIF_PMULL_CHUNK_SIZE)) {
42 l = min_t(u32, length, CRC_T10DIF_PMULL_CHUNK_SIZE -
43 ((u64)data % CRC_T10DIF_PMULL_CHUNK_SIZE));
45 *crc = crc_t10dif_generic(*crc, data, l);
47 length -= l;
48 data += l;
51 if (length > 0) {
52 if (may_use_simd()) {
53 kernel_neon_begin();
54 *crc = crc_t10dif_pmull(*crc, data, length);
55 kernel_neon_end();
56 } else {
57 *crc = crc_t10dif_generic(*crc, data, length);
61 return 0;
64 static int crct10dif_final(struct shash_desc *desc, u8 *out)
66 u16 *crc = shash_desc_ctx(desc);
68 *(u16 *)out = *crc;
69 return 0;
72 static struct shash_alg crc_t10dif_alg = {
73 .digestsize = CRC_T10DIF_DIGEST_SIZE,
74 .init = crct10dif_init,
75 .update = crct10dif_update,
76 .final = crct10dif_final,
77 .descsize = CRC_T10DIF_DIGEST_SIZE,
79 .base.cra_name = "crct10dif",
80 .base.cra_driver_name = "crct10dif-arm64-ce",
81 .base.cra_priority = 200,
82 .base.cra_blocksize = CRC_T10DIF_BLOCK_SIZE,
83 .base.cra_module = THIS_MODULE,
86 static int __init crc_t10dif_mod_init(void)
88 return crypto_register_shash(&crc_t10dif_alg);
91 static void __exit crc_t10dif_mod_exit(void)
93 crypto_unregister_shash(&crc_t10dif_alg);
96 module_cpu_feature_match(PMULL, crc_t10dif_mod_init);
97 module_exit(crc_t10dif_mod_exit);
99 MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
100 MODULE_LICENSE("GPL v2");