chcr_crypto.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * This file is part of the Chelsio T6 Crypto driver for Linux.
  3. *
  4. * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. *
  34. */
  35. #ifndef __CHCR_CRYPTO_H__
  36. #define __CHCR_CRYPTO_H__
  37. /* Define following if h/w is not dropping the AAD and IV data before
  38. * giving the processed data
  39. */
  40. #define CHCR_CRA_PRIORITY 300
  41. #define CHCR_AES_MAX_KEY_LEN (2 * (AES_MAX_KEY_SIZE)) /* consider xts */
  42. #define CHCR_MAX_CRYPTO_IV_LEN 16 /* AES IV len */
  43. #define CHCR_MAX_AUTHENC_AES_KEY_LEN 32 /* max aes key length*/
  44. #define CHCR_MAX_AUTHENC_SHA_KEY_LEN 128 /* max sha key length*/
  45. #define CHCR_GIVENCRYPT_OP 2
  46. /* CPL/SCMD parameters */
  47. #define CHCR_ENCRYPT_OP 0
  48. #define CHCR_DECRYPT_OP 1
  49. #define CHCR_SCMD_SEQ_NO_CTRL_32BIT 1
  50. #define CHCR_SCMD_SEQ_NO_CTRL_48BIT 2
  51. #define CHCR_SCMD_SEQ_NO_CTRL_64BIT 3
  52. #define CHCR_SCMD_PROTO_VERSION_GENERIC 4
  53. #define CHCR_SCMD_AUTH_CTRL_AUTH_CIPHER 0
  54. #define CHCR_SCMD_AUTH_CTRL_CIPHER_AUTH 1
  55. #define CHCR_SCMD_CIPHER_MODE_NOP 0
  56. #define CHCR_SCMD_CIPHER_MODE_AES_CBC 1
  57. #define CHCR_SCMD_CIPHER_MODE_GENERIC_AES 4
  58. #define CHCR_SCMD_CIPHER_MODE_AES_XTS 6
  59. #define CHCR_SCMD_AUTH_MODE_NOP 0
  60. #define CHCR_SCMD_AUTH_MODE_SHA1 1
  61. #define CHCR_SCMD_AUTH_MODE_SHA224 2
  62. #define CHCR_SCMD_AUTH_MODE_SHA256 3
  63. #define CHCR_SCMD_AUTH_MODE_SHA512_224 5
  64. #define CHCR_SCMD_AUTH_MODE_SHA512_256 6
  65. #define CHCR_SCMD_AUTH_MODE_SHA512_384 7
  66. #define CHCR_SCMD_AUTH_MODE_SHA512_512 8
  67. #define CHCR_SCMD_HMAC_CTRL_NOP 0
  68. #define CHCR_SCMD_HMAC_CTRL_NO_TRUNC 1
  69. #define CHCR_SCMD_IVGEN_CTRL_HW 0
  70. #define CHCR_SCMD_IVGEN_CTRL_SW 1
  71. /* This are not really mac key size. They are intermediate values
  72. * of sha engine and its size
  73. */
  74. #define CHCR_KEYCTX_MAC_KEY_SIZE_128 0
  75. #define CHCR_KEYCTX_MAC_KEY_SIZE_160 1
  76. #define CHCR_KEYCTX_MAC_KEY_SIZE_192 2
  77. #define CHCR_KEYCTX_MAC_KEY_SIZE_256 3
  78. #define CHCR_KEYCTX_MAC_KEY_SIZE_512 4
  79. #define CHCR_KEYCTX_CIPHER_KEY_SIZE_128 0
  80. #define CHCR_KEYCTX_CIPHER_KEY_SIZE_192 1
  81. #define CHCR_KEYCTX_CIPHER_KEY_SIZE_256 2
  82. #define CHCR_KEYCTX_NO_KEY 15
  83. #define CHCR_CPL_FW4_PLD_IV_OFFSET (5 * 64) /* bytes. flt #5 and #6 */
  84. #define CHCR_CPL_FW4_PLD_HASH_RESULT_OFFSET (7 * 64) /* bytes. flt #7 */
  85. #define CHCR_CPL_FW4_PLD_DATA_SIZE (4 * 64) /* bytes. flt #4 to #7 */
  86. #define KEY_CONTEXT_HDR_SALT_AND_PAD 16
  87. #define flits_to_bytes(x) (x * 8)
  88. #define IV_NOP 0
  89. #define IV_IMMEDIATE 1
  90. #define IV_DSGL 2
  91. #define CRYPTO_ALG_SUB_TYPE_MASK 0x0f000000
  92. #define CRYPTO_ALG_SUB_TYPE_HASH_HMAC 0x01000000
  93. #define CRYPTO_ALG_TYPE_HMAC (CRYPTO_ALG_TYPE_AHASH |\
  94. CRYPTO_ALG_SUB_TYPE_HASH_HMAC)
  95. #define MAX_SALT 4
  96. #define MAX_SCRATCH_PAD_SIZE 32
  97. #define CHCR_HASH_MAX_BLOCK_SIZE_64 64
  98. #define CHCR_HASH_MAX_BLOCK_SIZE_128 128
  99. /* Aligned to 128 bit boundary */
  100. struct _key_ctx {
  101. __be32 ctx_hdr;
  102. u8 salt[MAX_SALT];
  103. __be64 reserverd;
  104. unsigned char key[0];
  105. };
  106. struct ablk_ctx {
  107. u8 enc;
  108. unsigned int processed_len;
  109. __be32 key_ctx_hdr;
  110. unsigned int enckey_len;
  111. unsigned int dst_nents;
  112. struct scatterlist iv_sg;
  113. u8 key[CHCR_AES_MAX_KEY_LEN];
  114. u8 iv[CHCR_MAX_CRYPTO_IV_LEN];
  115. unsigned char ciph_mode;
  116. };
  117. struct hmac_ctx {
  118. struct shash_desc *desc;
  119. u8 ipad[CHCR_HASH_MAX_BLOCK_SIZE_128];
  120. u8 opad[CHCR_HASH_MAX_BLOCK_SIZE_128];
  121. };
  122. struct __crypto_ctx {
  123. struct hmac_ctx hmacctx[0];
  124. struct ablk_ctx ablkctx[0];
  125. };
  126. struct chcr_context {
  127. struct chcr_dev *dev;
  128. unsigned char tx_channel_id;
  129. struct __crypto_ctx crypto_ctx[0];
  130. };
  131. struct chcr_ahash_req_ctx {
  132. u32 result;
  133. char bfr[CHCR_HASH_MAX_BLOCK_SIZE_128];
  134. u8 bfr_len;
  135. /* DMA the partial hash in it */
  136. u8 partial_hash[CHCR_HASH_MAX_DIGEST_SIZE];
  137. u64 data_len; /* Data len till time */
  138. void *dummy_payload_ptr;
  139. /* SKB which is being sent to the hardware for processing */
  140. struct sk_buff *skb;
  141. };
  142. struct chcr_blkcipher_req_ctx {
  143. struct sk_buff *skb;
  144. };
  145. struct chcr_alg_template {
  146. u32 type;
  147. u32 is_registered;
  148. union {
  149. struct crypto_alg crypto;
  150. struct ahash_alg hash;
  151. } alg;
  152. };
  153. struct chcr_req_ctx {
  154. union {
  155. struct ahash_request *ahash_req;
  156. struct ablkcipher_request *ablk_req;
  157. } req;
  158. union {
  159. struct chcr_ahash_req_ctx *ahash_ctx;
  160. struct chcr_blkcipher_req_ctx *ablk_ctx;
  161. } ctx;
  162. };
  163. struct sge_opaque_hdr {
  164. void *dev;
  165. dma_addr_t addr[MAX_SKB_FRAGS + 1];
  166. };
  167. typedef struct sk_buff *(*create_wr_t)(struct crypto_async_request *req,
  168. struct chcr_context *ctx,
  169. unsigned short qid,
  170. unsigned short op_type);
  171. #endif /* __CHCR_CRYPTO_H__ */