x86/speculation/mds: Fix documentation typo
[linux/fpc-iii.git] / arch / powerpc / crypto / crct10dif-vpmsum_glue.c
blob02ea277863d15001be3c919aa17c7f2ccd73aa1a
1 /*
2 * Calculate a CRC T10-DIF with vpmsum acceleration
4 * Copyright 2017, Daniel Axtens, IBM Corporation.
5 * [based on crc32c-vpmsum_glue.c]
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
13 #include <linux/crc-t10dif.h>
14 #include <crypto/internal/hash.h>
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/string.h>
18 #include <linux/kernel.h>
19 #include <linux/cpufeature.h>
20 #include <asm/switch_to.h>
22 #define VMX_ALIGN 16
23 #define VMX_ALIGN_MASK (VMX_ALIGN-1)
25 #define VECTOR_BREAKPOINT 64
27 u32 __crct10dif_vpmsum(u32 crc, unsigned char const *p, size_t len);
29 static u16 crct10dif_vpmsum(u16 crci, unsigned char const *p, size_t len)
31 unsigned int prealign;
32 unsigned int tail;
33 u32 crc = crci;
35 if (len < (VECTOR_BREAKPOINT + VMX_ALIGN) || in_interrupt())
36 return crc_t10dif_generic(crc, p, len);
38 if ((unsigned long)p & VMX_ALIGN_MASK) {
39 prealign = VMX_ALIGN - ((unsigned long)p & VMX_ALIGN_MASK);
40 crc = crc_t10dif_generic(crc, p, prealign);
41 len -= prealign;
42 p += prealign;
45 if (len & ~VMX_ALIGN_MASK) {
46 crc <<= 16;
47 preempt_disable();
48 pagefault_disable();
49 enable_kernel_altivec();
50 crc = __crct10dif_vpmsum(crc, p, len & ~VMX_ALIGN_MASK);
51 disable_kernel_altivec();
52 pagefault_enable();
53 preempt_enable();
54 crc >>= 16;
57 tail = len & VMX_ALIGN_MASK;
58 if (tail) {
59 p += len & ~VMX_ALIGN_MASK;
60 crc = crc_t10dif_generic(crc, p, tail);
63 return crc & 0xffff;
66 static int crct10dif_vpmsum_init(struct shash_desc *desc)
68 u16 *crc = shash_desc_ctx(desc);
70 *crc = 0;
71 return 0;
74 static int crct10dif_vpmsum_update(struct shash_desc *desc, const u8 *data,
75 unsigned int length)
77 u16 *crc = shash_desc_ctx(desc);
79 *crc = crct10dif_vpmsum(*crc, data, length);
81 return 0;
85 static int crct10dif_vpmsum_final(struct shash_desc *desc, u8 *out)
87 u16 *crcp = shash_desc_ctx(desc);
89 *(u16 *)out = *crcp;
90 return 0;
93 static struct shash_alg alg = {
94 .init = crct10dif_vpmsum_init,
95 .update = crct10dif_vpmsum_update,
96 .final = crct10dif_vpmsum_final,
97 .descsize = CRC_T10DIF_DIGEST_SIZE,
98 .digestsize = CRC_T10DIF_DIGEST_SIZE,
99 .base = {
100 .cra_name = "crct10dif",
101 .cra_driver_name = "crct10dif-vpmsum",
102 .cra_priority = 200,
103 .cra_blocksize = CRC_T10DIF_BLOCK_SIZE,
104 .cra_module = THIS_MODULE,
108 static int __init crct10dif_vpmsum_mod_init(void)
110 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
111 return -ENODEV;
113 return crypto_register_shash(&alg);
116 static void __exit crct10dif_vpmsum_mod_fini(void)
118 crypto_unregister_shash(&alg);
121 module_cpu_feature_match(PPC_MODULE_FEATURE_VEC_CRYPTO, crct10dif_vpmsum_mod_init);
122 module_exit(crct10dif_vpmsum_mod_fini);
124 MODULE_AUTHOR("Daniel Axtens <dja@axtens.net>");
125 MODULE_DESCRIPTION("CRCT10DIF using vector polynomial multiply-sum instructions");
126 MODULE_LICENSE("GPL");
127 MODULE_ALIAS_CRYPTO("crct10dif");
128 MODULE_ALIAS_CRYPTO("crct10dif-vpmsum");