2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2012-2013 Cavium Inc., All Rights Reserved.
8 * MD5/SHA1/SHA256/SHA512 instruction definitions added by
9 * Aaro Koskinen <aaro.koskinen@iki.fi>.
12 #ifndef __LINUX_OCTEON_CRYPTO_H
13 #define __LINUX_OCTEON_CRYPTO_H
15 #include <linux/sched.h>
16 #include <asm/mipsregs.h>
18 #define OCTEON_CR_OPCODE_PRIORITY 300
20 extern unsigned long octeon_crypto_enable(struct octeon_cop2_state
*state
);
21 extern void octeon_crypto_disable(struct octeon_cop2_state
*state
,
25 * Macros needed to implement MD5/SHA1/SHA256:
29 * The index can be 0-1 (MD5) or 0-2 (SHA1), 0-3 (SHA256).
31 #define write_octeon_64bit_hash_dword(value, index) \
33 __asm__ __volatile__ ( \
34 "dmtc2 %[rt],0x0048+" STR(index) \
36 : [rt] "d" (cpu_to_be64(value))); \
40 * The index can be 0-1 (MD5) or 0-2 (SHA1), 0-3 (SHA256).
42 #define read_octeon_64bit_hash_dword(index) \
46 __asm__ __volatile__ ( \
47 "dmfc2 %[rt],0x0048+" STR(index) \
48 : [rt] "=d" (__value) \
51 be64_to_cpu(__value); \
55 * The index can be 0-6.
57 #define write_octeon_64bit_block_dword(value, index) \
59 __asm__ __volatile__ ( \
60 "dmtc2 %[rt],0x0040+" STR(index) \
62 : [rt] "d" (cpu_to_be64(value))); \
66 * The value is the final block dword (64-bit).
68 #define octeon_md5_start(value) \
70 __asm__ __volatile__ ( \
71 "dmtc2 %[rt],0x4047" \
73 : [rt] "d" (cpu_to_be64(value))); \
77 * The value is the final block dword (64-bit).
79 #define octeon_sha1_start(value) \
81 __asm__ __volatile__ ( \
82 "dmtc2 %[rt],0x4057" \
84 : [rt] "d" (value)); \
88 * The value is the final block dword (64-bit).
90 #define octeon_sha256_start(value) \
92 __asm__ __volatile__ ( \
93 "dmtc2 %[rt],0x404f" \
95 : [rt] "d" (value)); \
99 * Macros needed to implement SHA512:
103 * The index can be 0-7.
105 #define write_octeon_64bit_hash_sha512(value, index) \
107 __asm__ __volatile__ ( \
108 "dmtc2 %[rt],0x0250+" STR(index) \
110 : [rt] "d" (value)); \
114 * The index can be 0-7.
116 #define read_octeon_64bit_hash_sha512(index) \
120 __asm__ __volatile__ ( \
121 "dmfc2 %[rt],0x0250+" STR(index) \
122 : [rt] "=d" (__value) \
129 * The index can be 0-14.
131 #define write_octeon_64bit_block_sha512(value, index) \
133 __asm__ __volatile__ ( \
134 "dmtc2 %[rt],0x0240+" STR(index) \
136 : [rt] "d" (value)); \
140 * The value is the final block word (64-bit).
142 #define octeon_sha512_start(value) \
144 __asm__ __volatile__ ( \
145 "dmtc2 %[rt],0x424f" \
147 : [rt] "d" (value)); \
151 * The value is the final block dword (64-bit).
153 #define octeon_sha1_start(value) \
155 __asm__ __volatile__ ( \
156 "dmtc2 %[rt],0x4057" \
158 : [rt] "d" (value)); \
162 * The value is the final block dword (64-bit).
164 #define octeon_sha256_start(value) \
166 __asm__ __volatile__ ( \
167 "dmtc2 %[rt],0x404f" \
169 : [rt] "d" (value)); \
173 * Macros needed to implement SHA512:
177 * The index can be 0-7.
179 #define write_octeon_64bit_hash_sha512(value, index) \
181 __asm__ __volatile__ ( \
182 "dmtc2 %[rt],0x0250+" STR(index) \
184 : [rt] "d" (value)); \
188 * The index can be 0-7.
190 #define read_octeon_64bit_hash_sha512(index) \
194 __asm__ __volatile__ ( \
195 "dmfc2 %[rt],0x0250+" STR(index) \
196 : [rt] "=d" (__value) \
203 * The index can be 0-14.
205 #define write_octeon_64bit_block_sha512(value, index) \
207 __asm__ __volatile__ ( \
208 "dmtc2 %[rt],0x0240+" STR(index) \
210 : [rt] "d" (value)); \
214 * The value is the final block word (64-bit).
216 #define octeon_sha512_start(value) \
218 __asm__ __volatile__ ( \
219 "dmtc2 %[rt],0x424f" \
221 : [rt] "d" (value)); \
224 #endif /* __LINUX_OCTEON_CRYPTO_H */