License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-2.6-block.git] / include / crypto / mcryptd.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1e65b81a
TC
2/*
3 * Software async multibuffer crypto daemon headers
4 *
5 * Author:
6 * Tim Chen <tim.c.chen@linux.intel.com>
7 *
8 * Copyright (c) 2014, Intel Corporation.
9 */
10
11#ifndef _CRYPTO_MCRYPT_H
12#define _CRYPTO_MCRYPT_H
13
14#include <linux/crypto.h>
15#include <linux/kernel.h>
16#include <crypto/hash.h>
17
18struct mcryptd_ahash {
19 struct crypto_ahash base;
20};
21
22static inline struct mcryptd_ahash *__mcryptd_ahash_cast(
23 struct crypto_ahash *tfm)
24{
25 return (struct mcryptd_ahash *)tfm;
26}
27
28struct mcryptd_cpu_queue {
29 struct crypto_queue queue;
30 struct work_struct work;
31};
32
33struct mcryptd_queue {
34 struct mcryptd_cpu_queue __percpu *cpu_queue;
35};
36
37struct mcryptd_instance_ctx {
38 struct crypto_spawn spawn;
39 struct mcryptd_queue *queue;
40};
41
42struct mcryptd_hash_ctx {
331bf739 43 struct crypto_ahash *child;
1e65b81a
TC
44 struct mcryptd_alg_state *alg_state;
45};
46
47struct mcryptd_tag {
48 /* seq number of request */
49 unsigned seq_num;
50 /* arrival time of request */
51 unsigned long arrival;
52 unsigned long expire;
53 int cpu;
54};
55
56struct 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;
61 u8 *out;
62 int flag;
331bf739 63 struct ahash_request areq;
1e65b81a
TC
64};
65
66struct mcryptd_ahash *mcryptd_alloc_ahash(const char *alg_name,
67 u32 type, u32 mask);
331bf739
MD
68struct crypto_ahash *mcryptd_ahash_child(struct mcryptd_ahash *tfm);
69struct ahash_request *mcryptd_ahash_desc(struct ahash_request *req);
1e65b81a
TC
70void mcryptd_free_ahash(struct mcryptd_ahash *tfm);
71void mcryptd_flusher(struct work_struct *work);
72
73enum mcryptd_req_type {
74 MCRYPTD_NONE,
75 MCRYPTD_UPDATE,
76 MCRYPTD_FINUP,
77 MCRYPTD_DIGEST,
78 MCRYPTD_FINAL
79};
80
81struct mcryptd_alg_cstate {
82 unsigned long next_flush;
83 unsigned next_seq_num;
84 bool flusher_engaged;
85 struct delayed_work flush;
86 int cpu;
87 struct mcryptd_alg_state *alg_state;
88 void *mgr;
89 spinlock_t work_lock;
90 struct list_head work_list;
91 struct list_head flush_list;
92};
93
94struct mcryptd_alg_state {
95 struct mcryptd_alg_cstate __percpu *alg_cstate;
96 unsigned long (*flusher)(struct mcryptd_alg_cstate *cstate);
97};
98
99/* return delay in jiffies from current time */
100static inline unsigned long get_delay(unsigned long t)
101{
102 long delay;
103
104 delay = (long) t - (long) jiffies;
105 if (delay <= 0)
106 return 0;
107 else
108 return (unsigned long) delay;
109}
110
111void mcryptd_arm_flusher(struct mcryptd_alg_cstate *cstate, unsigned long delay);
112
113#endif