162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Crypto engine API
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (c) 2016 Baolin Wang <baolin.wang@linaro.org>
662306a36Sopenharmony_ci * Copyright (c) 2023 Herbert Xu <herbert@gondor.apana.org.au>
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci#ifndef _CRYPTO_INTERNAL_ENGINE_H
962306a36Sopenharmony_ci#define _CRYPTO_INTERNAL_ENGINE_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <crypto/algapi.h>
1262306a36Sopenharmony_ci#include <crypto/engine.h>
1362306a36Sopenharmony_ci#include <linux/kthread.h>
1462306a36Sopenharmony_ci#include <linux/spinlock_types.h>
1562306a36Sopenharmony_ci#include <linux/types.h>
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#define ENGINE_NAME_LEN	30
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_cistruct device;
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci/*
2262306a36Sopenharmony_ci * struct crypto_engine - crypto hardware engine
2362306a36Sopenharmony_ci * @name: the engine name
2462306a36Sopenharmony_ci * @idling: the engine is entering idle state
2562306a36Sopenharmony_ci * @busy: request pump is busy
2662306a36Sopenharmony_ci * @running: the engine is on working
2762306a36Sopenharmony_ci * @retry_support: indication that the hardware allows re-execution
2862306a36Sopenharmony_ci * of a failed backlog request
2962306a36Sopenharmony_ci * crypto-engine, in head position to keep order
3062306a36Sopenharmony_ci * @list: link with the global crypto engine list
3162306a36Sopenharmony_ci * @queue_lock: spinlock to synchronise access to request queue
3262306a36Sopenharmony_ci * @queue: the crypto queue of the engine
3362306a36Sopenharmony_ci * @rt: whether this queue is set to run as a realtime task
3462306a36Sopenharmony_ci * @prepare_crypt_hardware: a request will soon arrive from the queue
3562306a36Sopenharmony_ci * so the subsystem requests the driver to prepare the hardware
3662306a36Sopenharmony_ci * by issuing this call
3762306a36Sopenharmony_ci * @unprepare_crypt_hardware: there are currently no more requests on the
3862306a36Sopenharmony_ci * queue so the subsystem notifies the driver that it may relax the
3962306a36Sopenharmony_ci * hardware by issuing this call
4062306a36Sopenharmony_ci * @do_batch_requests: execute a batch of requests. Depends on multiple
4162306a36Sopenharmony_ci * requests support.
4262306a36Sopenharmony_ci * @kworker: kthread worker struct for request pump
4362306a36Sopenharmony_ci * @pump_requests: work struct for scheduling work to the request pump
4462306a36Sopenharmony_ci * @priv_data: the engine private data
4562306a36Sopenharmony_ci * @cur_req: the current request which is on processing
4662306a36Sopenharmony_ci */
4762306a36Sopenharmony_cistruct crypto_engine {
4862306a36Sopenharmony_ci	char			name[ENGINE_NAME_LEN];
4962306a36Sopenharmony_ci	bool			idling;
5062306a36Sopenharmony_ci	bool			busy;
5162306a36Sopenharmony_ci	bool			running;
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci	bool			retry_support;
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci	struct list_head	list;
5662306a36Sopenharmony_ci	spinlock_t		queue_lock;
5762306a36Sopenharmony_ci	struct crypto_queue	queue;
5862306a36Sopenharmony_ci	struct device		*dev;
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci	bool			rt;
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci	int (*prepare_crypt_hardware)(struct crypto_engine *engine);
6362306a36Sopenharmony_ci	int (*unprepare_crypt_hardware)(struct crypto_engine *engine);
6462306a36Sopenharmony_ci	int (*do_batch_requests)(struct crypto_engine *engine);
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci	struct kthread_worker           *kworker;
6862306a36Sopenharmony_ci	struct kthread_work             pump_requests;
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci	void				*priv_data;
7162306a36Sopenharmony_ci	struct crypto_async_request	*cur_req;
7262306a36Sopenharmony_ci};
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#endif
75