1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Software async multibuffer crypto daemon headers
6 * Tim Chen <tim.c.chen@linux.intel.com>
8 * Copyright (c) 2014, Intel Corporation.
11 #ifndef _CRYPTO_MCRYPT_H
12 #define _CRYPTO_MCRYPT_H
14 #include <linux/crypto.h>
15 #include <linux/kernel.h>
16 #include <crypto/hash.h>
18 struct mcryptd_ahash {
19 struct crypto_ahash base;
22 static inline struct mcryptd_ahash *__mcryptd_ahash_cast(
23 struct crypto_ahash *tfm)
25 return (struct mcryptd_ahash *)tfm;
28 struct mcryptd_cpu_queue {
29 struct crypto_queue queue;
30 struct work_struct work;
33 struct mcryptd_queue {
34 struct mcryptd_cpu_queue __percpu *cpu_queue;
37 struct mcryptd_instance_ctx {
38 struct crypto_spawn spawn;
39 struct mcryptd_queue *queue;
42 struct mcryptd_hash_ctx {
43 struct crypto_ahash *child;
44 struct mcryptd_alg_state *alg_state;
48 /* seq number of request */
50 /* arrival time of request */
51 unsigned long arrival;
56 struct mcryptd_hash_request_ctx {
57 struct list_head waiter;
58 crypto_completion_t complete;
59 struct mcryptd_tag tag;
60 struct crypto_hash_walk walk;
63 struct ahash_request areq;
66 struct mcryptd_ahash *mcryptd_alloc_ahash(const char *alg_name,
68 struct crypto_ahash *mcryptd_ahash_child(struct mcryptd_ahash *tfm);
69 struct ahash_request *mcryptd_ahash_desc(struct ahash_request *req);
70 void mcryptd_free_ahash(struct mcryptd_ahash *tfm);
71 void mcryptd_flusher(struct work_struct *work);
73 enum mcryptd_req_type {
81 struct mcryptd_alg_cstate {
82 unsigned long next_flush;
83 unsigned next_seq_num;
85 struct delayed_work flush;
87 struct mcryptd_alg_state *alg_state;
90 struct list_head work_list;
91 struct list_head flush_list;
94 struct mcryptd_alg_state {
95 struct mcryptd_alg_cstate __percpu *alg_cstate;
96 unsigned long (*flusher)(struct mcryptd_alg_cstate *cstate);
99 /* return delay in jiffies from current time */
100 static inline unsigned long get_delay(unsigned long t)
104 delay = (long) t - (long) jiffies;
108 return (unsigned long) delay;
111 void mcryptd_arm_flusher(struct mcryptd_alg_cstate *cstate, unsigned long delay);