mcryptd.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Software async multibuffer crypto daemon headers
  3. *
  4. * Author:
  5. * Tim Chen <tim.c.chen@linux.intel.com>
  6. *
  7. * Copyright (c) 2014, Intel Corporation.
  8. */
  9. #ifndef _CRYPTO_MCRYPT_H
  10. #define _CRYPTO_MCRYPT_H
  11. #include <linux/crypto.h>
  12. #include <linux/kernel.h>
  13. #include <crypto/hash.h>
  14. struct mcryptd_ahash {
  15. struct crypto_ahash base;
  16. };
  17. static inline struct mcryptd_ahash *__mcryptd_ahash_cast(
  18. struct crypto_ahash *tfm)
  19. {
  20. return (struct mcryptd_ahash *)tfm;
  21. }
  22. struct mcryptd_cpu_queue {
  23. struct crypto_queue queue;
  24. spinlock_t q_lock;
  25. struct work_struct work;
  26. };
  27. struct mcryptd_queue {
  28. struct mcryptd_cpu_queue __percpu *cpu_queue;
  29. };
  30. struct mcryptd_instance_ctx {
  31. struct crypto_spawn spawn;
  32. struct mcryptd_queue *queue;
  33. };
  34. struct mcryptd_hash_ctx {
  35. struct crypto_ahash *child;
  36. struct mcryptd_alg_state *alg_state;
  37. };
  38. struct mcryptd_tag {
  39. /* seq number of request */
  40. unsigned seq_num;
  41. /* arrival time of request */
  42. unsigned long arrival;
  43. unsigned long expire;
  44. int cpu;
  45. };
  46. struct mcryptd_hash_request_ctx {
  47. struct list_head waiter;
  48. crypto_completion_t complete;
  49. struct mcryptd_tag tag;
  50. struct crypto_hash_walk walk;
  51. u8 *out;
  52. int flag;
  53. struct ahash_request areq;
  54. };
  55. struct mcryptd_ahash *mcryptd_alloc_ahash(const char *alg_name,
  56. u32 type, u32 mask);
  57. struct crypto_ahash *mcryptd_ahash_child(struct mcryptd_ahash *tfm);
  58. struct ahash_request *mcryptd_ahash_desc(struct ahash_request *req);
  59. void mcryptd_free_ahash(struct mcryptd_ahash *tfm);
  60. void mcryptd_flusher(struct work_struct *work);
  61. enum mcryptd_req_type {
  62. MCRYPTD_NONE,
  63. MCRYPTD_UPDATE,
  64. MCRYPTD_FINUP,
  65. MCRYPTD_DIGEST,
  66. MCRYPTD_FINAL
  67. };
  68. struct mcryptd_alg_cstate {
  69. unsigned long next_flush;
  70. unsigned next_seq_num;
  71. bool flusher_engaged;
  72. struct delayed_work flush;
  73. int cpu;
  74. struct mcryptd_alg_state *alg_state;
  75. void *mgr;
  76. spinlock_t work_lock;
  77. struct list_head work_list;
  78. struct list_head flush_list;
  79. };
  80. struct mcryptd_alg_state {
  81. struct mcryptd_alg_cstate __percpu *alg_cstate;
  82. unsigned long (*flusher)(struct mcryptd_alg_cstate *cstate);
  83. };
  84. /* return delay in jiffies from current time */
  85. static inline unsigned long get_delay(unsigned long t)
  86. {
  87. long delay;
  88. delay = (long) t - (long) jiffies;
  89. if (delay <= 0)
  90. return 0;
  91. else
  92. return (unsigned long) delay;
  93. }
  94. void mcryptd_arm_flusher(struct mcryptd_alg_cstate *cstate, unsigned long delay);
  95. #endif