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

TOMOYO Linux Cross Reference
Linux/arch/sparc/crypto/crc32c_glue.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ 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.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/sparc/crypto/crc32c_glue.c (Architecture m68k) and /arch/sparc64/crypto/crc32c_glue.c (Architecture sparc64)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 
  2 /* Glue code for CRC32C optimized for sparc64     
  3  *                                                
  4  * This is based largely upon arch/x86/crypto/    
  5  *                                                
  6  * Copyright (C) 2008 Intel Corporation           
  7  * Authors: Austin Zhang <austin_zhang@linux.i    
  8  *          Kent Liu <kent.liu@intel.com>         
  9  */                                               
 10                                                   
 11 #define pr_fmt(fmt)     KBUILD_MODNAME ": " fm    
 12                                                   
 13 #include <linux/init.h>                           
 14 #include <linux/module.h>                         
 15 #include <linux/string.h>                         
 16 #include <linux/kernel.h>                         
 17 #include <linux/crc32.h>                          
 18                                                   
 19 #include <crypto/internal/hash.h>                 
 20                                                   
 21 #include <asm/pstate.h>                           
 22 #include <asm/elf.h>                              
 23 #include <linux/unaligned.h>                      
 24                                                   
 25 #include "opcodes.h"                              
 26                                                   
 27 /*                                                
 28  * Setting the seed allows arbitrary accumulat    
 29  * If your algorithm starts with ~0, then XOR     
 30  * the seed.                                      
 31  */                                               
 32 static int crc32c_sparc64_setkey(struct crypto    
 33                                  unsigned int     
 34 {                                                 
 35         u32 *mctx = crypto_shash_ctx(hash);       
 36                                                   
 37         if (keylen != sizeof(u32))                
 38                 return -EINVAL;                   
 39         *mctx = get_unaligned_le32(key);          
 40         return 0;                                 
 41 }                                                 
 42                                                   
 43 static int crc32c_sparc64_init(struct shash_de    
 44 {                                                 
 45         u32 *mctx = crypto_shash_ctx(desc->tfm    
 46         u32 *crcp = shash_desc_ctx(desc);         
 47                                                   
 48         *crcp = *mctx;                            
 49                                                   
 50         return 0;                                 
 51 }                                                 
 52                                                   
 53 extern void crc32c_sparc64(u32 *crcp, const u6    
 54                                                   
 55 static u32 crc32c_compute(u32 crc, const u8 *d    
 56 {                                                 
 57         unsigned int n = -(uintptr_t)data & 7;    
 58                                                   
 59         if (n) {                                  
 60                 /* Data isn't 8-byte aligned.     
 61                 n = min(n, len);                  
 62                 crc = __crc32c_le(crc, data, n    
 63                 data += n;                        
 64                 len -= n;                         
 65         }                                         
 66         n = len & ~7U;                            
 67         if (n) {                                  
 68                 crc32c_sparc64(&crc, (const u6    
 69                 data += n;                        
 70                 len -= n;                         
 71         }                                         
 72         if (len)                                  
 73                 crc = __crc32c_le(crc, data, l    
 74         return crc;                               
 75 }                                                 
 76                                                   
 77 static int crc32c_sparc64_update(struct shash_    
 78                                  unsigned int     
 79 {                                                 
 80         u32 *crcp = shash_desc_ctx(desc);         
 81                                                   
 82         *crcp = crc32c_compute(*crcp, data, le    
 83         return 0;                                 
 84 }                                                 
 85                                                   
 86 static int __crc32c_sparc64_finup(const u32 *c    
 87                                   unsigned int    
 88 {                                                 
 89         put_unaligned_le32(~crc32c_compute(*cr    
 90         return 0;                                 
 91 }                                                 
 92                                                   
 93 static int crc32c_sparc64_finup(struct shash_d    
 94                                 unsigned int l    
 95 {                                                 
 96         return __crc32c_sparc64_finup(shash_de    
 97 }                                                 
 98                                                   
 99 static int crc32c_sparc64_final(struct shash_d    
100 {                                                 
101         u32 *crcp = shash_desc_ctx(desc);         
102                                                   
103         put_unaligned_le32(~*crcp, out);          
104         return 0;                                 
105 }                                                 
106                                                   
107 static int crc32c_sparc64_digest(struct shash_    
108                                  unsigned int     
109 {                                                 
110         return __crc32c_sparc64_finup(crypto_s    
111                                       out);       
112 }                                                 
113                                                   
114 static int crc32c_sparc64_cra_init(struct cryp    
115 {                                                 
116         u32 *key = crypto_tfm_ctx(tfm);           
117                                                   
118         *key = ~0;                                
119                                                   
120         return 0;                                 
121 }                                                 
122                                                   
123 #define CHKSUM_BLOCK_SIZE       1                 
124 #define CHKSUM_DIGEST_SIZE      4                 
125                                                   
126 static struct shash_alg alg = {                   
127         .setkey                 =       crc32c    
128         .init                   =       crc32c    
129         .update                 =       crc32c    
130         .final                  =       crc32c    
131         .finup                  =       crc32c    
132         .digest                 =       crc32c    
133         .descsize               =       sizeof    
134         .digestsize             =       CHKSUM    
135         .base                   =       {         
136                 .cra_name               =         
137                 .cra_driver_name        =         
138                 .cra_priority           =         
139                 .cra_flags              =         
140                 .cra_blocksize          =         
141                 .cra_ctxsize            =         
142                 .cra_module             =         
143                 .cra_init               =         
144         }                                         
145 };                                                
146                                                   
147 static bool __init sparc64_has_crc32c_opcode(v    
148 {                                                 
149         unsigned long cfr;                        
150                                                   
151         if (!(sparc64_elf_hwcap & HWCAP_SPARC_    
152                 return false;                     
153                                                   
154         __asm__ __volatile__("rd %%asr26, %0"     
155         if (!(cfr & CFR_CRC32C))                  
156                 return false;                     
157                                                   
158         return true;                              
159 }                                                 
160                                                   
161 static int __init crc32c_sparc64_mod_init(void    
162 {                                                 
163         if (sparc64_has_crc32c_opcode()) {        
164                 pr_info("Using sparc64 crc32c     
165                 return crypto_register_shash(&    
166         }                                         
167         pr_info("sparc64 crc32c opcode not ava    
168         return -ENODEV;                           
169 }                                                 
170                                                   
171 static void __exit crc32c_sparc64_mod_fini(voi    
172 {                                                 
173         crypto_unregister_shash(&alg);            
174 }                                                 
175                                                   
176 module_init(crc32c_sparc64_mod_init);             
177 module_exit(crc32c_sparc64_mod_fini);             
178                                                   
179 MODULE_LICENSE("GPL");                            
180 MODULE_DESCRIPTION("CRC32c (Castagnoli), sparc    
181                                                   
182 MODULE_ALIAS_CRYPTO("crc32c");                    
183                                                   
184 #include "crop_devid.c"                           
185                                                   

~ [ 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