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