crypto4xx_core.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 PPC460SX_SDR0_SRST 0x201
  24. #define PPC405EX_SDR0_SRST 0x200
  25. #define PPC460EX_SDR0_SRST 0x201
  26. #define PPC460EX_CE_RESET 0x08000000
  27. #define PPC460SX_CE_RESET 0x20000000
  28. #define PPC405EX_CE_RESET 0x00000008
  29. #define CRYPTO4XX_CRYPTO_PRIORITY 300
  30. #define PPC4XX_LAST_PD 63
  31. #define PPC4XX_NUM_PD 64
  32. #define PPC4XX_LAST_GD 1023
  33. #define PPC4XX_NUM_GD 1024
  34. #define PPC4XX_LAST_SD 63
  35. #define PPC4XX_NUM_SD 64
  36. #define PPC4XX_SD_BUFFER_SIZE 2048
  37. #define PD_ENTRY_INUSE 1
  38. #define PD_ENTRY_FREE 0
  39. #define ERING_WAS_FULL 0xffffffff
  40. struct crypto4xx_device;
  41. struct pd_uinfo {
  42. struct crypto4xx_device *dev;
  43. u32 state;
  44. u32 using_sd;
  45. u32 first_gd; /* first gather discriptor
  46. used by this packet */
  47. u32 num_gd; /* number of gather discriptor
  48. used by this packet */
  49. u32 first_sd; /* first scatter discriptor
  50. used by this packet */
  51. u32 num_sd; /* number of scatter discriptors
  52. used by this packet */
  53. void *sa_va; /* shadow sa, when using cp from ctx->sa */
  54. u32 sa_pa;
  55. void *sr_va; /* state record for shadow sa */
  56. u32 sr_pa;
  57. struct scatterlist *dest_va;
  58. struct crypto_async_request *async_req; /* base crypto request
  59. for this packet */
  60. };
  61. struct crypto4xx_device {
  62. struct crypto4xx_core_device *core_dev;
  63. char *name;
  64. u64 ce_phy_address;
  65. void __iomem *ce_base;
  66. void *pdr; /* base address of packet
  67. descriptor ring */
  68. dma_addr_t pdr_pa; /* physical address used to
  69. program ce pdr_base_register */
  70. void *gdr; /* gather descriptor ring */
  71. dma_addr_t gdr_pa; /* physical address used to
  72. program ce gdr_base_register */
  73. void *sdr; /* scatter descriptor ring */
  74. dma_addr_t sdr_pa; /* physical address used to
  75. program ce sdr_base_register */
  76. void *scatter_buffer_va;
  77. dma_addr_t scatter_buffer_pa;
  78. u32 scatter_buffer_size;
  79. void *shadow_sa_pool; /* pool of memory for sa in pd_uinfo */
  80. dma_addr_t shadow_sa_pool_pa;
  81. void *shadow_sr_pool; /* pool of memory for sr in pd_uinfo */
  82. dma_addr_t shadow_sr_pool_pa;
  83. u32 pdr_tail;
  84. u32 pdr_head;
  85. u32 gdr_tail;
  86. u32 gdr_head;
  87. u32 sdr_tail;
  88. u32 sdr_head;
  89. void *pdr_uinfo;
  90. struct list_head alg_list; /* List of algorithm supported
  91. by this device */
  92. };
  93. struct crypto4xx_core_device {
  94. struct device *device;
  95. struct platform_device *ofdev;
  96. struct crypto4xx_device *dev;
  97. u32 int_status;
  98. u32 irq;
  99. struct tasklet_struct tasklet;
  100. spinlock_t lock;
  101. };
  102. struct crypto4xx_ctx {
  103. struct crypto4xx_device *dev;
  104. void *sa_in;
  105. dma_addr_t sa_in_dma_addr;
  106. void *sa_out;
  107. dma_addr_t sa_out_dma_addr;
  108. void *state_record;
  109. dma_addr_t state_record_dma_addr;
  110. u32 sa_len;
  111. u32 offset_to_sr_ptr; /* offset to state ptr, in dynamic sa */
  112. u32 direction;
  113. u32 next_hdr;
  114. u32 save_iv;
  115. u32 pd_ctl_len;
  116. u32 pd_ctl;
  117. u32 bypass;
  118. u32 is_hash;
  119. u32 hash_final;
  120. };
  121. struct crypto4xx_req_ctx {
  122. struct crypto4xx_device *dev; /* Device in which
  123. operation to send to */
  124. void *sa;
  125. u32 sa_dma_addr;
  126. u16 sa_len;
  127. };
  128. struct crypto4xx_alg_common {
  129. u32 type;
  130. union {
  131. struct crypto_alg cipher;
  132. struct ahash_alg hash;
  133. } u;
  134. };
  135. struct crypto4xx_alg {
  136. struct list_head entry;
  137. struct crypto4xx_alg_common alg;
  138. struct crypto4xx_device *dev;
  139. };
  140. static inline struct crypto4xx_alg *crypto_alg_to_crypto4xx_alg(
  141. struct crypto_alg *x)
  142. {
  143. switch (x->cra_flags & CRYPTO_ALG_TYPE_MASK) {
  144. case CRYPTO_ALG_TYPE_AHASH:
  145. return container_of(__crypto_ahash_alg(x),
  146. struct crypto4xx_alg, alg.u.hash);
  147. }
  148. return container_of(x, struct crypto4xx_alg, alg.u.cipher);
  149. }
  150. extern int crypto4xx_alloc_sa(struct crypto4xx_ctx *ctx, u32 size);
  151. extern void crypto4xx_free_sa(struct crypto4xx_ctx *ctx);
  152. extern u32 crypto4xx_alloc_sa_rctx(struct crypto4xx_ctx *ctx,
  153. struct crypto4xx_ctx *rctx);
  154. extern void crypto4xx_free_sa_rctx(struct crypto4xx_ctx *rctx);
  155. extern void crypto4xx_free_ctx(struct crypto4xx_ctx *ctx);
  156. extern u32 crypto4xx_alloc_state_record(struct crypto4xx_ctx *ctx);
  157. extern u32 get_dynamic_sa_offset_state_ptr_field(struct crypto4xx_ctx *ctx);
  158. extern u32 get_dynamic_sa_offset_key_field(struct crypto4xx_ctx *ctx);
  159. extern u32 get_dynamic_sa_iv_size(struct crypto4xx_ctx *ctx);
  160. extern void crypto4xx_memcpy_le(unsigned int *dst,
  161. const unsigned char *buf, int len);
  162. extern u32 crypto4xx_build_pd(struct crypto_async_request *req,
  163. struct crypto4xx_ctx *ctx,
  164. struct scatterlist *src,
  165. struct scatterlist *dst,
  166. unsigned int datalen,
  167. void *iv, u32 iv_len);
  168. extern int crypto4xx_setkey_aes_cbc(struct crypto_ablkcipher *cipher,
  169. const u8 *key, unsigned int keylen);
  170. extern int crypto4xx_encrypt(struct ablkcipher_request *req);
  171. extern int crypto4xx_decrypt(struct ablkcipher_request *req);
  172. extern int crypto4xx_sha1_alg_init(struct crypto_tfm *tfm);
  173. extern int crypto4xx_hash_digest(struct ahash_request *req);
  174. extern int crypto4xx_hash_final(struct ahash_request *req);
  175. extern int crypto4xx_hash_update(struct ahash_request *req);
  176. extern int crypto4xx_hash_init(struct ahash_request *req);
  177. #endif