1f421258dSAaro Koskinen /* 2f421258dSAaro Koskinen * This file is subject to the terms and conditions of the GNU General Public 3f421258dSAaro Koskinen * License. See the file "COPYING" in the main directory of this archive 4f421258dSAaro Koskinen * for more details. 5f421258dSAaro Koskinen * 6f421258dSAaro Koskinen * Copyright (C) 2012-2013 Cavium Inc., All Rights Reserved. 71e585ef5SAaro Koskinen * 8da3cd5d7SAaro Koskinen * MD5/SHA1/SHA256/SHA512 instruction definitions added by 9da3cd5d7SAaro Koskinen * Aaro Koskinen <aaro.koskinen@iki.fi>. 101e585ef5SAaro Koskinen * 11f421258dSAaro Koskinen */ 12f421258dSAaro Koskinen #ifndef __LINUX_OCTEON_CRYPTO_H 13f421258dSAaro Koskinen #define __LINUX_OCTEON_CRYPTO_H 14f421258dSAaro Koskinen 15f421258dSAaro Koskinen #include <linux/sched.h> 161e585ef5SAaro Koskinen #include <asm/mipsregs.h> 17f421258dSAaro Koskinen 181953c22fSAaro Koskinen #define OCTEON_CR_OPCODE_PRIORITY 300 191953c22fSAaro Koskinen 20f421258dSAaro Koskinen extern unsigned long octeon_crypto_enable(struct octeon_cop2_state *state); 21f421258dSAaro Koskinen extern void octeon_crypto_disable(struct octeon_cop2_state *state, 22f421258dSAaro Koskinen unsigned long flags); 23f421258dSAaro Koskinen 241e585ef5SAaro Koskinen /* 25da3cd5d7SAaro Koskinen * Macros needed to implement MD5/SHA1/SHA256: 261e585ef5SAaro Koskinen */ 271e585ef5SAaro Koskinen 281e585ef5SAaro Koskinen /* 29da3cd5d7SAaro Koskinen * The index can be 0-1 (MD5) or 0-2 (SHA1), 0-3 (SHA256). 301e585ef5SAaro Koskinen */ 311e585ef5SAaro Koskinen #define write_octeon_64bit_hash_dword(value, index) \ 321e585ef5SAaro Koskinen do { \ 331e585ef5SAaro Koskinen __asm__ __volatile__ ( \ 341e585ef5SAaro Koskinen "dmtc2 %[rt],0x0048+" STR(index) \ 351e585ef5SAaro Koskinen : \ 36d2a948d2SPaul Martin : [rt] "d" (cpu_to_be64(value))); \ 371e585ef5SAaro Koskinen } while (0) 381e585ef5SAaro Koskinen 391e585ef5SAaro Koskinen /* 40da3cd5d7SAaro Koskinen * The index can be 0-1 (MD5) or 0-2 (SHA1), 0-3 (SHA256). 411e585ef5SAaro Koskinen */ 421e585ef5SAaro Koskinen #define read_octeon_64bit_hash_dword(index) \ 431e585ef5SAaro Koskinen ({ \ 44*7c2f5537SHerbert Xu __be64 __value; \ 451e585ef5SAaro Koskinen \ 461e585ef5SAaro Koskinen __asm__ __volatile__ ( \ 471e585ef5SAaro Koskinen "dmfc2 %[rt],0x0048+" STR(index) \ 481e585ef5SAaro Koskinen : [rt] "=d" (__value) \ 491e585ef5SAaro Koskinen : ); \ 501e585ef5SAaro Koskinen \ 51d2a948d2SPaul Martin be64_to_cpu(__value); \ 521e585ef5SAaro Koskinen }) 531e585ef5SAaro Koskinen 541e585ef5SAaro Koskinen /* 551e585ef5SAaro Koskinen * The index can be 0-6. 561e585ef5SAaro Koskinen */ 571e585ef5SAaro Koskinen #define write_octeon_64bit_block_dword(value, index) \ 581e585ef5SAaro Koskinen do { \ 591e585ef5SAaro Koskinen __asm__ __volatile__ ( \ 601e585ef5SAaro Koskinen "dmtc2 %[rt],0x0040+" STR(index) \ 611e585ef5SAaro Koskinen : \ 62d2a948d2SPaul Martin : [rt] "d" (cpu_to_be64(value))); \ 631e585ef5SAaro Koskinen } while (0) 641e585ef5SAaro Koskinen 651e585ef5SAaro Koskinen /* 661e585ef5SAaro Koskinen * The value is the final block dword (64-bit). 671e585ef5SAaro Koskinen */ 681e585ef5SAaro Koskinen #define octeon_md5_start(value) \ 691e585ef5SAaro Koskinen do { \ 701e585ef5SAaro Koskinen __asm__ __volatile__ ( \ 711e585ef5SAaro Koskinen "dmtc2 %[rt],0x4047" \ 721e585ef5SAaro Koskinen : \ 73d2a948d2SPaul Martin : [rt] "d" (cpu_to_be64(value))); \ 741e585ef5SAaro Koskinen } while (0) 751e585ef5SAaro Koskinen 76a3d2a10bSAaro Koskinen /* 77a3d2a10bSAaro Koskinen * The value is the final block dword (64-bit). 78a3d2a10bSAaro Koskinen */ 79a3d2a10bSAaro Koskinen #define octeon_sha1_start(value) \ 80a3d2a10bSAaro Koskinen do { \ 81a3d2a10bSAaro Koskinen __asm__ __volatile__ ( \ 82a3d2a10bSAaro Koskinen "dmtc2 %[rt],0x4057" \ 83a3d2a10bSAaro Koskinen : \ 84a3d2a10bSAaro Koskinen : [rt] "d" (value)); \ 85a3d2a10bSAaro Koskinen } while (0) 86a3d2a10bSAaro Koskinen 87a3d2a10bSAaro Koskinen /* 88a3d2a10bSAaro Koskinen * The value is the final block dword (64-bit). 89a3d2a10bSAaro Koskinen */ 90a3d2a10bSAaro Koskinen #define octeon_sha256_start(value) \ 91a3d2a10bSAaro Koskinen do { \ 92a3d2a10bSAaro Koskinen __asm__ __volatile__ ( \ 93a3d2a10bSAaro Koskinen "dmtc2 %[rt],0x404f" \ 94a3d2a10bSAaro Koskinen : \ 95a3d2a10bSAaro Koskinen : [rt] "d" (value)); \ 96a3d2a10bSAaro Koskinen } while (0) 97a3d2a10bSAaro Koskinen 98a3d2a10bSAaro Koskinen /* 99a3d2a10bSAaro Koskinen * Macros needed to implement SHA512: 100a3d2a10bSAaro Koskinen */ 101a3d2a10bSAaro Koskinen 102a3d2a10bSAaro Koskinen /* 103a3d2a10bSAaro Koskinen * The index can be 0-7. 104a3d2a10bSAaro Koskinen */ 105a3d2a10bSAaro Koskinen #define write_octeon_64bit_hash_sha512(value, index) \ 106a3d2a10bSAaro Koskinen do { \ 107a3d2a10bSAaro Koskinen __asm__ __volatile__ ( \ 108a3d2a10bSAaro Koskinen "dmtc2 %[rt],0x0250+" STR(index) \ 109a3d2a10bSAaro Koskinen : \ 110a3d2a10bSAaro Koskinen : [rt] "d" (value)); \ 111a3d2a10bSAaro Koskinen } while (0) 112a3d2a10bSAaro Koskinen 113a3d2a10bSAaro Koskinen /* 114a3d2a10bSAaro Koskinen * The index can be 0-7. 115a3d2a10bSAaro Koskinen */ 116a3d2a10bSAaro Koskinen #define read_octeon_64bit_hash_sha512(index) \ 117a3d2a10bSAaro Koskinen ({ \ 118a3d2a10bSAaro Koskinen u64 __value; \ 119a3d2a10bSAaro Koskinen \ 120a3d2a10bSAaro Koskinen __asm__ __volatile__ ( \ 121a3d2a10bSAaro Koskinen "dmfc2 %[rt],0x0250+" STR(index) \ 122a3d2a10bSAaro Koskinen : [rt] "=d" (__value) \ 123a3d2a10bSAaro Koskinen : ); \ 124a3d2a10bSAaro Koskinen \ 125a3d2a10bSAaro Koskinen __value; \ 126a3d2a10bSAaro Koskinen }) 127a3d2a10bSAaro Koskinen 128a3d2a10bSAaro Koskinen /* 129a3d2a10bSAaro Koskinen * The index can be 0-14. 130a3d2a10bSAaro Koskinen */ 131a3d2a10bSAaro Koskinen #define write_octeon_64bit_block_sha512(value, index) \ 132a3d2a10bSAaro Koskinen do { \ 133a3d2a10bSAaro Koskinen __asm__ __volatile__ ( \ 134a3d2a10bSAaro Koskinen "dmtc2 %[rt],0x0240+" STR(index) \ 135a3d2a10bSAaro Koskinen : \ 136a3d2a10bSAaro Koskinen : [rt] "d" (value)); \ 137a3d2a10bSAaro Koskinen } while (0) 138a3d2a10bSAaro Koskinen 139a3d2a10bSAaro Koskinen /* 140a3d2a10bSAaro Koskinen * The value is the final block word (64-bit). 141a3d2a10bSAaro Koskinen */ 142a3d2a10bSAaro Koskinen #define octeon_sha512_start(value) \ 143a3d2a10bSAaro Koskinen do { \ 144a3d2a10bSAaro Koskinen __asm__ __volatile__ ( \ 145a3d2a10bSAaro Koskinen "dmtc2 %[rt],0x424f" \ 146a3d2a10bSAaro Koskinen : \ 147f421258dSAaro Koskinen : [rt] "d" (value)); \ 148f421258dSAaro Koskinen } while (0) 149f421258dSAaro Koskinen 150da3cd5d7SAaro Koskinen /* 151da3cd5d7SAaro Koskinen * The value is the final block dword (64-bit). 152da3cd5d7SAaro Koskinen */ 153da3cd5d7SAaro Koskinen #define octeon_sha1_start(value) \ 154da3cd5d7SAaro Koskinen do { \ 155da3cd5d7SAaro Koskinen __asm__ __volatile__ ( \ 156da3cd5d7SAaro Koskinen "dmtc2 %[rt],0x4057" \ 157da3cd5d7SAaro Koskinen : \ 158da3cd5d7SAaro Koskinen : [rt] "d" (value)); \ 159da3cd5d7SAaro Koskinen } while (0) 160da3cd5d7SAaro Koskinen 161da3cd5d7SAaro Koskinen /* 162da3cd5d7SAaro Koskinen * The value is the final block dword (64-bit). 163da3cd5d7SAaro Koskinen */ 164da3cd5d7SAaro Koskinen #define octeon_sha256_start(value) \ 165da3cd5d7SAaro Koskinen do { \ 166da3cd5d7SAaro Koskinen __asm__ __volatile__ ( \ 167da3cd5d7SAaro Koskinen "dmtc2 %[rt],0x404f" \ 168da3cd5d7SAaro Koskinen : \ 169da3cd5d7SAaro Koskinen : [rt] "d" (value)); \ 170da3cd5d7SAaro Koskinen } while (0) 171da3cd5d7SAaro Koskinen 172da3cd5d7SAaro Koskinen /* 173da3cd5d7SAaro Koskinen * Macros needed to implement SHA512: 174da3cd5d7SAaro Koskinen */ 175da3cd5d7SAaro Koskinen 176da3cd5d7SAaro Koskinen /* 177da3cd5d7SAaro Koskinen * The index can be 0-7. 178da3cd5d7SAaro Koskinen */ 179da3cd5d7SAaro Koskinen #define write_octeon_64bit_hash_sha512(value, index) \ 180da3cd5d7SAaro Koskinen do { \ 181da3cd5d7SAaro Koskinen __asm__ __volatile__ ( \ 182da3cd5d7SAaro Koskinen "dmtc2 %[rt],0x0250+" STR(index) \ 183da3cd5d7SAaro Koskinen : \ 184da3cd5d7SAaro Koskinen : [rt] "d" (value)); \ 185da3cd5d7SAaro Koskinen } while (0) 186da3cd5d7SAaro Koskinen 187da3cd5d7SAaro Koskinen /* 188da3cd5d7SAaro Koskinen * The index can be 0-7. 189da3cd5d7SAaro Koskinen */ 190da3cd5d7SAaro Koskinen #define read_octeon_64bit_hash_sha512(index) \ 191da3cd5d7SAaro Koskinen ({ \ 192da3cd5d7SAaro Koskinen u64 __value; \ 193da3cd5d7SAaro Koskinen \ 194da3cd5d7SAaro Koskinen __asm__ __volatile__ ( \ 195da3cd5d7SAaro Koskinen "dmfc2 %[rt],0x0250+" STR(index) \ 196da3cd5d7SAaro Koskinen : [rt] "=d" (__value) \ 197da3cd5d7SAaro Koskinen : ); \ 198da3cd5d7SAaro Koskinen \ 199da3cd5d7SAaro Koskinen __value; \ 200da3cd5d7SAaro Koskinen }) 201da3cd5d7SAaro Koskinen 202da3cd5d7SAaro Koskinen /* 203da3cd5d7SAaro Koskinen * The index can be 0-14. 204da3cd5d7SAaro Koskinen */ 205da3cd5d7SAaro Koskinen #define write_octeon_64bit_block_sha512(value, index) \ 206da3cd5d7SAaro Koskinen do { \ 207da3cd5d7SAaro Koskinen __asm__ __volatile__ ( \ 208da3cd5d7SAaro Koskinen "dmtc2 %[rt],0x0240+" STR(index) \ 209da3cd5d7SAaro Koskinen : \ 210da3cd5d7SAaro Koskinen : [rt] "d" (value)); \ 211da3cd5d7SAaro Koskinen } while (0) 212da3cd5d7SAaro Koskinen 213da3cd5d7SAaro Koskinen /* 214da3cd5d7SAaro Koskinen * The value is the final block word (64-bit). 215da3cd5d7SAaro Koskinen */ 216da3cd5d7SAaro Koskinen #define octeon_sha512_start(value) \ 217da3cd5d7SAaro Koskinen do { \ 218da3cd5d7SAaro Koskinen __asm__ __volatile__ ( \ 219da3cd5d7SAaro Koskinen "dmtc2 %[rt],0x424f" \ 220da3cd5d7SAaro Koskinen : \ 221da3cd5d7SAaro Koskinen : [rt] "d" (value)); \ 222da3cd5d7SAaro Koskinen } while (0) 223da3cd5d7SAaro Koskinen 224f421258dSAaro Koskinen #endif /* __LINUX_OCTEON_CRYPTO_H */ 225