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

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

Version: ~ [ linux-6.0-rc6 ] ~ [ linux-5.19.10 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.69 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.144 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.214 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.259 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.294 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.329 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ 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 /*
  2  * Calculate a CRC T10-DIF with vpmsum acceleration
  3  *
  4  * Copyright 2017, Daniel Axtens, IBM Corporation.
  5  * [based on crc32c-vpmsum_glue.c]
  6  *
  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.
 11  */
 12 
 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>
 21 
 22 #define VMX_ALIGN               16
 23 #define VMX_ALIGN_MASK          (VMX_ALIGN-1)
 24 
 25 #define VECTOR_BREAKPOINT       64
 26 
 27 u32 __crct10dif_vpmsum(u32 crc, unsigned char const *p, size_t len);
 28 
 29 static u16 crct10dif_vpmsum(u16 crci, unsigned char const *p, size_t len)
 30 {
 31         unsigned int prealign;
 32         unsigned int tail;
 33         u32 crc = crci;
 34 
 35         if (len < (VECTOR_BREAKPOINT + VMX_ALIGN) || in_interrupt())
 36                 return crc_t10dif_generic(crc, p, len);
 37 
 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;
 43         }
 44 
 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;
 55         }
 56 
 57         tail = len & VMX_ALIGN_MASK;
 58         if (tail) {
 59                 p += len & ~VMX_ALIGN_MASK;
 60                 crc = crc_t10dif_generic(crc, p, tail);
 61         }
 62 
 63         return crc & 0xffff;
 64 }
 65 
 66 static int crct10dif_vpmsum_init(struct shash_desc *desc)
 67 {
 68         u16 *crc = shash_desc_ctx(desc);
 69 
 70         *crc = 0;
 71         return 0;
 72 }
 73 
 74 static int crct10dif_vpmsum_update(struct shash_desc *desc, const u8 *data,
 75                             unsigned int length)
 76 {
 77         u16 *crc = shash_desc_ctx(desc);
 78 
 79         *crc = crct10dif_vpmsum(*crc, data, length);
 80 
 81         return 0;
 82 }
 83 
 84 
 85 static int crct10dif_vpmsum_final(struct shash_desc *desc, u8 *out)
 86 {
 87         u16 *crcp = shash_desc_ctx(desc);
 88 
 89         *(u16 *)out = *crcp;
 90         return 0;
 91 }
 92 
 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,
105         }
106 };
107 
108 static int __init crct10dif_vpmsum_mod_init(void)
109 {
110         if (!cpu_has_feature(CPU_FTR_ARCH_207S))
111                 return -ENODEV;
112 
113         return crypto_register_shash(&alg);
114 }
115 
116 static void __exit crct10dif_vpmsum_mod_fini(void)
117 {
118         crypto_unregister_shash(&alg);
119 }
120 
121 module_cpu_feature_match(PPC_MODULE_FEATURE_VEC_CRYPTO, crct10dif_vpmsum_mod_init);
122 module_exit(crct10dif_vpmsum_mod_fini);
123 
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");
129 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp