nx.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #ifndef __NX_H__
  2. #define __NX_H__
  3. #define NX_NAME "nx-crypto"
  4. #define NX_STRING "IBM Power7+ Nest Accelerator Crypto Driver"
  5. #define NX_VERSION "1.0"
  6. static const char nx_driver_string[] = NX_STRING;
  7. static const char nx_driver_version[] = NX_VERSION;
  8. /* a scatterlist in the format PHYP is expecting */
  9. struct nx_sg {
  10. u64 addr;
  11. u32 rsvd;
  12. u32 len;
  13. } __attribute((packed));
  14. #define NX_PAGE_SIZE (4096)
  15. #define NX_MAX_SG_ENTRIES (NX_PAGE_SIZE/(sizeof(struct nx_sg)))
  16. enum nx_status {
  17. NX_DISABLED,
  18. NX_WAITING,
  19. NX_OKAY
  20. };
  21. /* msc_triplet and max_sync_cop are used only to assist in parsing the
  22. * openFirmware property */
  23. struct msc_triplet {
  24. u32 keybitlen;
  25. u32 databytelen;
  26. u32 sglen;
  27. } __packed;
  28. struct max_sync_cop {
  29. u32 fc;
  30. u32 mode;
  31. u32 triplets;
  32. struct msc_triplet trip[0];
  33. } __packed;
  34. struct alg_props {
  35. u32 databytelen;
  36. u32 sglen;
  37. };
  38. #define NX_OF_FLAG_MAXSGLEN_SET (1)
  39. #define NX_OF_FLAG_STATUS_SET (2)
  40. #define NX_OF_FLAG_MAXSYNCCOP_SET (4)
  41. #define NX_OF_FLAG_MASK_READY (NX_OF_FLAG_MAXSGLEN_SET | \
  42. NX_OF_FLAG_STATUS_SET | \
  43. NX_OF_FLAG_MAXSYNCCOP_SET)
  44. struct nx_of {
  45. u32 flags;
  46. u32 max_sg_len;
  47. enum nx_status status;
  48. struct alg_props ap[NX_MAX_FC][NX_MAX_MODE][3];
  49. };
  50. struct nx_stats {
  51. atomic_t aes_ops;
  52. atomic64_t aes_bytes;
  53. atomic_t sha256_ops;
  54. atomic64_t sha256_bytes;
  55. atomic_t sha512_ops;
  56. atomic64_t sha512_bytes;
  57. atomic_t sync_ops;
  58. atomic_t errors;
  59. atomic_t last_error;
  60. atomic_t last_error_pid;
  61. };
  62. struct nx_debugfs {
  63. struct dentry *dfs_root;
  64. struct dentry *dfs_aes_ops, *dfs_aes_bytes;
  65. struct dentry *dfs_sha256_ops, *dfs_sha256_bytes;
  66. struct dentry *dfs_sha512_ops, *dfs_sha512_bytes;
  67. struct dentry *dfs_errors, *dfs_last_error, *dfs_last_error_pid;
  68. };
  69. struct nx_crypto_driver {
  70. struct nx_stats stats;
  71. struct nx_of of;
  72. struct vio_dev *viodev;
  73. struct vio_driver viodriver;
  74. struct nx_debugfs dfs;
  75. };
  76. #define NX_GCM4106_NONCE_LEN (4)
  77. #define NX_GCM_CTR_OFFSET (12)
  78. struct nx_gcm_priv {
  79. u8 iv[16];
  80. u8 iauth_tag[16];
  81. u8 nonce[NX_GCM4106_NONCE_LEN];
  82. };
  83. #define NX_CCM_AES_KEY_LEN (16)
  84. #define NX_CCM4309_AES_KEY_LEN (19)
  85. #define NX_CCM4309_NONCE_LEN (3)
  86. struct nx_ccm_priv {
  87. u8 iv[16];
  88. u8 b0[16];
  89. u8 iauth_tag[16];
  90. u8 oauth_tag[16];
  91. u8 nonce[NX_CCM4309_NONCE_LEN];
  92. };
  93. struct nx_xcbc_priv {
  94. u8 key[16];
  95. };
  96. struct nx_ctr_priv {
  97. u8 iv[16];
  98. };
  99. struct nx_crypto_ctx {
  100. void *kmem; /* unaligned, kmalloc'd buffer */
  101. size_t kmem_len; /* length of kmem */
  102. struct nx_csbcpb *csbcpb; /* aligned page given to phyp @ hcall time */
  103. struct vio_pfo_op op; /* operation struct with hcall parameters */
  104. struct nx_csbcpb *csbcpb_aead; /* secondary csbcpb used by AEAD algs */
  105. struct vio_pfo_op op_aead;/* operation struct for csbcpb_aead */
  106. struct nx_sg *in_sg; /* aligned pointer into kmem to an sg list */
  107. struct nx_sg *out_sg; /* aligned pointer into kmem to an sg list */
  108. struct alg_props *ap; /* pointer into props based on our key size */
  109. struct alg_props props[3];/* openFirmware properties for requests */
  110. struct nx_stats *stats; /* pointer into an nx_crypto_driver for stats
  111. reporting */
  112. union {
  113. struct nx_gcm_priv gcm;
  114. struct nx_ccm_priv ccm;
  115. struct nx_xcbc_priv xcbc;
  116. struct nx_ctr_priv ctr;
  117. } priv;
  118. };
  119. /* prototypes */
  120. int nx_crypto_ctx_aes_ccm_init(struct crypto_tfm *tfm);
  121. int nx_crypto_ctx_aes_gcm_init(struct crypto_tfm *tfm);
  122. int nx_crypto_ctx_aes_xcbc_init(struct crypto_tfm *tfm);
  123. int nx_crypto_ctx_aes_ctr_init(struct crypto_tfm *tfm);
  124. int nx_crypto_ctx_aes_cbc_init(struct crypto_tfm *tfm);
  125. int nx_crypto_ctx_aes_ecb_init(struct crypto_tfm *tfm);
  126. int nx_crypto_ctx_sha_init(struct crypto_tfm *tfm);
  127. void nx_crypto_ctx_exit(struct crypto_tfm *tfm);
  128. void nx_ctx_init(struct nx_crypto_ctx *nx_ctx, unsigned int function);
  129. int nx_hcall_sync(struct nx_crypto_ctx *ctx, struct vio_pfo_op *op,
  130. u32 may_sleep);
  131. struct nx_sg *nx_build_sg_list(struct nx_sg *, u8 *, unsigned int, u32);
  132. int nx_build_sg_lists(struct nx_crypto_ctx *, struct blkcipher_desc *,
  133. struct scatterlist *, struct scatterlist *, unsigned int,
  134. u8 *);
  135. struct nx_sg *nx_walk_and_build(struct nx_sg *, unsigned int,
  136. struct scatterlist *, unsigned int,
  137. unsigned int);
  138. #ifdef CONFIG_DEBUG_FS
  139. #define NX_DEBUGFS_INIT(drv) nx_debugfs_init(drv)
  140. #define NX_DEBUGFS_FINI(drv) nx_debugfs_fini(drv)
  141. int nx_debugfs_init(struct nx_crypto_driver *);
  142. void nx_debugfs_fini(struct nx_crypto_driver *);
  143. #else
  144. #define NX_DEBUGFS_INIT(drv) (0)
  145. #define NX_DEBUGFS_FINI(drv) (0)
  146. #endif
  147. #define NX_PAGE_NUM(x) ((u64)(x) & 0xfffffffffffff000ULL)
  148. extern struct crypto_alg nx_cbc_aes_alg;
  149. extern struct crypto_alg nx_ecb_aes_alg;
  150. extern struct crypto_alg nx_gcm_aes_alg;
  151. extern struct crypto_alg nx_gcm4106_aes_alg;
  152. extern struct crypto_alg nx_ctr_aes_alg;
  153. extern struct crypto_alg nx_ctr3686_aes_alg;
  154. extern struct crypto_alg nx_ccm_aes_alg;
  155. extern struct crypto_alg nx_ccm4309_aes_alg;
  156. extern struct shash_alg nx_shash_aes_xcbc_alg;
  157. extern struct shash_alg nx_shash_sha512_alg;
  158. extern struct shash_alg nx_shash_sha256_alg;
  159. extern struct nx_crypto_driver nx_driver;
  160. #define SCATTERWALK_TO_SG 1
  161. #define SCATTERWALK_FROM_SG 0
  162. #endif