~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/powerpc/crypto/crct10dif-vpmsum_glue.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Calculate a CRC T10-DIF with vpmsum acceleration
  4  *
  5  * Copyright 2017, Daniel Axtens, IBM Corporation.
  6  * [based on crc32c-vpmsum_glue.c]
  7  */
  8 
  9 #include <linux/crc-t10dif.h>
 10 #include <crypto/internal/hash.h>
 11 #include <crypto/internal/simd.h>
 12 #include <linux/init.h>
 13 #include <linux/module.h>
 14 #include <linux/string.h>
 15 #include <linux/kernel.h>
 16 #include <linux/cpufeature.h>
 17 #include <asm/simd.h>
 18 #include <asm/switch_to.h>
 19 
 20 #define VMX_ALIGN               16
 21 #define VMX_ALIGN_MASK          (VMX_ALIGN-1)
 22 
 23 #define VECTOR_BREAKPOINT       64
 24 
 25 u32 __crct10dif_vpmsum(u32 crc, unsigned char const *p, size_t len);
 26 
 27 static u16 crct10dif_vpmsum(u16 crci, unsigned char const *p, size_t len)
 28 {
 29         unsigned int prealign;
 30         unsigned int tail;
 31         u32 crc = crci;
 32 
 33         if (len < (VECTOR_BREAKPOINT + VMX_ALIGN) || !crypto_simd_usable())
 34                 return crc_t10dif_generic(crc, p, len);
 35 
 36         if ((unsigned long)p & VMX_ALIGN_MASK) {
 37                 prealign = VMX_ALIGN - ((unsigned long)p & VMX_ALIGN_MASK);
 38                 crc = crc_t10dif_generic(crc, p, prealign);
 39                 len -= prealign;
 40                 p += prealign;
 41         }
 42 
 43         if (len & ~VMX_ALIGN_MASK) {
 44                 crc <<= 16;
 45                 preempt_disable();
 46                 pagefault_disable();
 47                 enable_kernel_altivec();
 48                 crc = __crct10dif_vpmsum(crc, p, len & ~VMX_ALIGN_MASK);
 49                 disable_kernel_altivec();
 50                 pagefault_enable();
 51                 preempt_enable();
 52                 crc >>= 16;
 53         }
 54 
 55         tail = len & VMX_ALIGN_MASK;
 56         if (tail) {
 57                 p += len & ~VMX_ALIGN_MASK;
 58                 crc = crc_t10dif_generic(crc, p, tail);
 59         }
 60 
 61         return crc & 0xffff;
 62 }
 63 
 64 static int crct10dif_vpmsum_init(struct shash_desc *desc)
 65 {
 66         u16 *crc = shash_desc_ctx(desc);
 67 
 68         *crc = 0;
 69         return 0;
 70 }
 71 
 72 static int crct10dif_vpmsum_update(struct shash_desc *desc, const u8 *data,
 73                             unsigned int length)
 74 {
 75         u16 *crc = shash_desc_ctx(desc);
 76 
 77         *crc = crct10dif_vpmsum(*crc, data, length);
 78 
 79         return 0;
 80 }
 81 
 82 
 83 static int crct10dif_vpmsum_final(struct shash_desc *desc, u8 *out)
 84 {
 85         u16 *crcp = shash_desc_ctx(desc);
 86 
 87         *(u16 *)out = *crcp;
 88         return 0;
 89 }
 90 
 91 static struct shash_alg alg = {
 92         .init           = crct10dif_vpmsum_init,
 93         .update         = crct10dif_vpmsum_update,
 94         .final          = crct10dif_vpmsum_final,
 95         .descsize       = CRC_T10DIF_DIGEST_SIZE,
 96         .digestsize     = CRC_T10DIF_DIGEST_SIZE,
 97         .base           = {
 98                 .cra_name               = "crct10dif",
 99                 .cra_driver_name        = "crct10dif-vpmsum",
100                 .cra_priority           = 200,
101                 .cra_blocksize          = CRC_T10DIF_BLOCK_SIZE,
102                 .cra_module             = THIS_MODULE,
103         }
104 };
105 
106 static int __init crct10dif_vpmsum_mod_init(void)
107 {
108         if (!cpu_has_feature(CPU_FTR_ARCH_207S))
109                 return -ENODEV;
110 
111         return crypto_register_shash(&alg);
112 }
113 
114 static void __exit crct10dif_vpmsum_mod_fini(void)
115 {
116         crypto_unregister_shash(&alg);
117 }
118 
119 module_cpu_feature_match(PPC_MODULE_FEATURE_VEC_CRYPTO, crct10dif_vpmsum_mod_init);
120 module_exit(crct10dif_vpmsum_mod_fini);
121 
122 MODULE_AUTHOR("Daniel Axtens <dja@axtens.net>");
123 MODULE_DESCRIPTION("CRCT10DIF using vector polynomial multiply-sum instructions");
124 MODULE_LICENSE("GPL");
125 MODULE_ALIAS_CRYPTO("crct10dif");
126 MODULE_ALIAS_CRYPTO("crct10dif-vpmsum");
127 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php