crypto4xx_core.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /**
  2. * AMCC SoC PPC4xx Crypto Driver
  3. *
  4. * Copyright (c) 2008 Applied Micro Circuits Corporation.
  5. * All rights reserved. James Hsiao <jhsiao@amcc.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * This is the header file for AMCC Crypto offload Linux device driver for
  18. * use with Linux CryptoAPI.
  19. */
  20. #ifndef __CRYPTO4XX_CORE_H__
  21. #define __CRYPTO4XX_CORE_H__
  22. #include <crypto/internal/hash.h>
  23. #define MODULE_NAME "crypto4xx"
  24. #define PPC460SX_SDR0_SRST 0x201
  25. #define PPC405EX_SDR0_SRST 0x200
  26. #define PPC460EX_SDR0_SRST 0x201
  27. #define PPC460EX_CE_RESET 0x08000000
  28. #define PPC460SX_CE_RESET 0x20000000
  29. #define PPC405EX_CE_RESET 0x00000008
  30. #define CRYPTO4XX_CRYPTO_PRIORITY 300
  31. #define PPC4XX_NUM_PD 256
  32. #define PPC4XX_LAST_PD (PPC4XX_NUM_PD - 1)
  33. #define PPC4XX_NUM_GD 1024
  34. #define PPC4XX_LAST_GD (PPC4XX_NUM_GD - 1)
  35. #define PPC4XX_NUM_SD 256
  36. #define PPC4XX_LAST_SD (PPC4XX_NUM_SD - 1)
  37. #define PPC4XX_SD_BUFFER_SIZE 2048
  38. #define PD_ENTRY_INUSE 1
  39. #define PD_ENTRY_FREE 0
  40. #define ERING_WAS_FULL 0xffffffff
  41. struct crypto4xx_device;
  42. struct pd_uinfo {
  43. struct crypto4xx_device *dev;
  44. u32 state;
  45. u32 using_sd;
  46. u32 first_gd; /* first gather discriptor
  47. used by this packet */
  48. u32 num_gd; /* number of gather discriptor
  49. used by this packet */
  50. u32 first_sd; /* first scatter discriptor
  51. used by this packet */
  52. u32 num_sd; /* number of scatter discriptors
  53. used by this packet */
  54. void *sa_va; /* shadow sa, when using cp from ctx->sa */
  55. u32 sa_pa;
  56. void *sr_va; /* state record for shadow sa */
  57. u32 sr_pa;
  58. struct scatterlist *dest_va;
  59. struct crypto_async_request *async_req; /* base crypto request
  60. for this packet */
  61. };
  62. struct crypto4xx_device {
  63. struct crypto4xx_core_device *core_dev;
  64. char *name;
  65. u64 ce_phy_address;
  66. void __iomem *ce_base;
  67. void __iomem *trng_base;
  68. void *pdr; /* base address of packet
  69. descriptor ring */
  70. dma_addr_t pdr_pa; /* physical address used to
  71. program ce pdr_base_register */
  72. void *gdr; /* gather descriptor ring */
  73. dma_addr_t gdr_pa; /* physical address used to
  74. program ce gdr_base_register */
  75. void *sdr; /* scatter descriptor ring */
  76. dma_addr_t sdr_pa; /* physical address used to
  77. program ce sdr_base_register */
  78. void *scatter_buffer_va;
  79. dma_addr_t scatter_buffer_pa;
  80. u32 scatter_buffer_size;
  81. void *shadow_sa_pool; /* pool of memory for sa in pd_uinfo */
  82. dma_addr_t shadow_sa_pool_pa;
  83. void *shadow_sr_pool; /* pool of memory for sr in pd_uinfo */
  84. dma_addr_t shadow_sr_pool_pa;
  85. u32 pdr_tail;
  86. u32 pdr_head;
  87. u32 gdr_tail;
  88. u32 gdr_head;
  89. u32 sdr_tail;
  90. u32 sdr_head;
  91. void *pdr_uinfo;
  92. struct list_head alg_list; /* List of algorithm supported
  93. by this device */
  94. };
  95. struct crypto4xx_core_device {
  96. struct device *device;
  97. struct platform_device *ofdev;
  98. struct crypto4xx_device *dev;
  99. struct hwrng *trng;
  100. u32 int_status;
  101. u32 irq;
  102. struct tasklet_struct tasklet;
  103. spinlock_t lock;
  104. };
  105. struct crypto4xx_ctx {
  106. struct crypto4xx_device *dev;
  107. void *sa_in;
  108. dma_addr_t sa_in_dma_addr;
  109. void *sa_out;
  110. dma_addr_t sa_out_dma_addr;
  111. void *state_record;
  112. dma_addr_t state_record_dma_addr;
  113. u32 sa_len;
  114. u32 offset_to_sr_ptr; /* offset to state ptr, in dynamic sa */
  115. u32 direction;
  116. u32 next_hdr;
  117. u32 save_iv;
  118. u32 pd_ctl_len;
  119. u32 pd_ctl;
  120. u32 bypass;
  121. u32 is_hash;
  122. u32 hash_final;
  123. };
  124. struct crypto4xx_req_ctx {
  125. struct crypto4xx_device *dev; /* Device in which
  126. operation to send to */
  127. void *sa;
  128. u32 sa_dma_addr;
  129. u16 sa_len;
  130. };
  131. struct crypto4xx_alg_common {
  132. u32 type;
  133. union {
  134. struct crypto_alg cipher;
  135. struct ahash_alg hash;
  136. } u;
  137. };
  138. struct crypto4xx_alg {
  139. struct list_head entry;
  140. struct crypto4xx_alg_common alg;
  141. struct crypto4xx_device *dev;
  142. };
  143. static inline struct crypto4xx_alg *crypto_alg_to_crypto4xx_alg(
  144. struct crypto_alg *x)
  145. {
  146. switch (x->cra_flags & CRYPTO_ALG_TYPE_MASK) {
  147. case CRYPTO_ALG_TYPE_AHASH:
  148. return container_of(__crypto_ahash_alg(x),
  149. struct crypto4xx_alg, alg.u.hash);
  150. }
  151. return container_of(x, struct crypto4xx_alg, alg.u.cipher);
  152. }
  153. extern int crypto4xx_alloc_sa(struct crypto4xx_ctx *ctx, u32 size);
  154. extern void crypto4xx_free_sa(struct crypto4xx_ctx *ctx);
  155. extern u32 crypto4xx_alloc_sa_rctx(struct crypto4xx_ctx *ctx,
  156. struct crypto4xx_ctx *rctx);
  157. extern void crypto4xx_free_sa_rctx(struct crypto4xx_ctx *rctx);
  158. extern void crypto4xx_free_ctx(struct crypto4xx_ctx *ctx);
  159. extern u32 crypto4xx_alloc_state_record(struct crypto4xx_ctx *ctx);
  160. extern u32 get_dynamic_sa_offset_state_ptr_field(struct crypto4xx_ctx *ctx);
  161. extern u32 get_dynamic_sa_offset_key_field(struct crypto4xx_ctx *ctx);
  162. extern u32 get_dynamic_sa_iv_size(struct crypto4xx_ctx *ctx);
  163. extern void crypto4xx_memcpy_le(unsigned int *dst,
  164. const unsigned char *buf, int len);
  165. extern u32 crypto4xx_build_pd(struct crypto_async_request *req,
  166. struct crypto4xx_ctx *ctx,
  167. struct scatterlist *src,
  168. struct scatterlist *dst,
  169. unsigned int datalen,
  170. void *iv, u32 iv_len);
  171. extern int crypto4xx_setkey_aes_cbc(struct crypto_ablkcipher *cipher,
  172. const u8 *key, unsigned int keylen);
  173. extern int crypto4xx_encrypt(struct ablkcipher_request *req);
  174. extern int crypto4xx_decrypt(struct ablkcipher_request *req);
  175. extern int crypto4xx_sha1_alg_init(struct crypto_tfm *tfm);
  176. extern int crypto4xx_hash_digest(struct ahash_request *req);
  177. extern int crypto4xx_hash_final(struct ahash_request *req);
  178. extern int crypto4xx_hash_update(struct ahash_request *req);
  179. extern int crypto4xx_hash_init(struct ahash_request *req);
  180. #endif