1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Crypto engine API
4  *
5  * Copyright (c) 2016 Baolin Wang <baolin.wang@linaro.org>
6  * Copyright (c) 2023 Herbert Xu <herbert@gondor.apana.org.au>
7  */
8 #ifndef _CRYPTO_INTERNAL_ENGINE_H
9 #define _CRYPTO_INTERNAL_ENGINE_H
10 
11 #include <crypto/algapi.h>
12 #include <crypto/engine.h>
13 #include <linux/kthread.h>
14 #include <linux/spinlock_types.h>
15 #include <linux/types.h>
16 
17 #define ENGINE_NAME_LEN	30
18 
19 struct device;
20 
21 /*
22  * struct crypto_engine - crypto hardware engine
23  * @name: the engine name
24  * @idling: the engine is entering idle state
25  * @busy: request pump is busy
26  * @running: the engine is on working
27  * @retry_support: indication that the hardware allows re-execution
28  * of a failed backlog request
29  * crypto-engine, in head position to keep order
30  * @list: link with the global crypto engine list
31  * @queue_lock: spinlock to synchronise access to request queue
32  * @queue: the crypto queue of the engine
33  * @rt: whether this queue is set to run as a realtime task
34  * @prepare_crypt_hardware: a request will soon arrive from the queue
35  * so the subsystem requests the driver to prepare the hardware
36  * by issuing this call
37  * @unprepare_crypt_hardware: there are currently no more requests on the
38  * queue so the subsystem notifies the driver that it may relax the
39  * hardware by issuing this call
40  * @do_batch_requests: execute a batch of requests. Depends on multiple
41  * requests support.
42  * @kworker: kthread worker struct for request pump
43  * @pump_requests: work struct for scheduling work to the request pump
44  * @priv_data: the engine private data
45  * @cur_req: the current request which is on processing
46  */
47 struct crypto_engine {
48 	char			name[ENGINE_NAME_LEN];
49 	bool			idling;
50 	bool			busy;
51 	bool			running;
52 
53 	bool			retry_support;
54 
55 	struct list_head	list;
56 	spinlock_t		queue_lock;
57 	struct crypto_queue	queue;
58 	struct device		*dev;
59 
60 	bool			rt;
61 
62 	int (*prepare_crypt_hardware)(struct crypto_engine *engine);
63 	int (*unprepare_crypt_hardware)(struct crypto_engine *engine);
64 	int (*do_batch_requests)(struct crypto_engine *engine);
65 
66 
67 	struct kthread_worker           *kworker;
68 	struct kthread_work             pump_requests;
69 
70 	void				*priv_data;
71 	struct crypto_async_request	*cur_req;
72 };
73 
74 #endif
75