net: Reflect all pernet_operations are converted
[linux/fpc-iii.git] / include / crypto / mcryptd.h
blobb67404fc4b34bab495086b4b1e969f53a0921b39
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Software async multibuffer crypto daemon headers
5 * Author:
6 * Tim Chen <tim.c.chen@linux.intel.com>
8 * Copyright (c) 2014, Intel Corporation.
9 */
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 spinlock_t q_lock;
31 struct work_struct work;
34 struct mcryptd_queue {
35 struct mcryptd_cpu_queue __percpu *cpu_queue;
38 struct mcryptd_instance_ctx {
39 struct crypto_spawn spawn;
40 struct mcryptd_queue *queue;
43 struct mcryptd_hash_ctx {
44 struct crypto_ahash *child;
45 struct mcryptd_alg_state *alg_state;
48 struct mcryptd_tag {
49 /* seq number of request */
50 unsigned seq_num;
51 /* arrival time of request */
52 unsigned long arrival;
53 unsigned long expire;
54 int cpu;
57 struct mcryptd_hash_request_ctx {
58 struct list_head waiter;
59 crypto_completion_t complete;
60 struct mcryptd_tag tag;
61 struct crypto_hash_walk walk;
62 u8 *out;
63 int flag;
64 struct ahash_request areq;
67 struct mcryptd_ahash *mcryptd_alloc_ahash(const char *alg_name,
68 u32 type, u32 mask);
69 struct crypto_ahash *mcryptd_ahash_child(struct mcryptd_ahash *tfm);
70 struct ahash_request *mcryptd_ahash_desc(struct ahash_request *req);
71 void mcryptd_free_ahash(struct mcryptd_ahash *tfm);
72 void mcryptd_flusher(struct work_struct *work);
74 enum mcryptd_req_type {
75 MCRYPTD_NONE,
76 MCRYPTD_UPDATE,
77 MCRYPTD_FINUP,
78 MCRYPTD_DIGEST,
79 MCRYPTD_FINAL
82 struct mcryptd_alg_cstate {
83 unsigned long next_flush;
84 unsigned next_seq_num;
85 bool flusher_engaged;
86 struct delayed_work flush;
87 int cpu;
88 struct mcryptd_alg_state *alg_state;
89 void *mgr;
90 spinlock_t work_lock;
91 struct list_head work_list;
92 struct list_head flush_list;
95 struct mcryptd_alg_state {
96 struct mcryptd_alg_cstate __percpu *alg_cstate;
97 unsigned long (*flusher)(struct mcryptd_alg_cstate *cstate);
100 /* return delay in jiffies from current time */
101 static inline unsigned long get_delay(unsigned long t)
103 long delay;
105 delay = (long) t - (long) jiffies;
106 if (delay <= 0)
107 return 0;
108 else
109 return (unsigned long) delay;
112 void mcryptd_arm_flusher(struct mcryptd_alg_cstate *cstate, unsigned long delay);
114 #endif