engine.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #include <crypto/algapi.h>
  11. #include <crypto/engine.h>
  12. #include <linux/kthread.h>
  13. #include <linux/spinlock_types.h>
  14. #include <linux/types.h>
  15. #define ENGINE_NAME_LEN 30
  16. struct device;
  17. /*
  18. * struct crypto_engine - crypto hardware engine
  19. * @name: the engine name
  20. * @idling: the engine is entering idle state
  21. * @busy: request pump is busy
  22. * @running: the engine is on working
  23. * @retry_support: indication that the hardware allows re-execution
  24. * of a failed backlog request
  25. * crypto-engine, in head position to keep order
  26. * @list: link with the global crypto engine list
  27. * @queue_lock: spinlock to synchronise access to request queue
  28. * @queue: the crypto queue of the engine
  29. * @rt: whether this queue is set to run as a realtime task
  30. * @prepare_crypt_hardware: a request will soon arrive from the queue
  31. * so the subsystem requests the driver to prepare the hardware
  32. * by issuing this call
  33. * @unprepare_crypt_hardware: there are currently no more requests on the
  34. * queue so the subsystem notifies the driver that it may relax the
  35. * hardware by issuing this call
  36. * @do_batch_requests: execute a batch of requests. Depends on multiple
  37. * requests support.
  38. * @kworker: kthread worker struct for request pump
  39. * @pump_requests: work struct for scheduling work to the request pump
  40. * @priv_data: the engine private data
  41. * @cur_req: the current request which is on processing
  42. */
  43. struct crypto_engine {
  44. char name[ENGINE_NAME_LEN];
  45. bool idling;
  46. bool busy;
  47. bool running;
  48. bool retry_support;
  49. struct list_head list;
  50. spinlock_t queue_lock;
  51. struct crypto_queue queue;
  52. struct device *dev;
  53. bool rt;
  54. int (*prepare_crypt_hardware)(struct crypto_engine *engine);
  55. int (*unprepare_crypt_hardware)(struct crypto_engine *engine);
  56. int (*do_batch_requests)(struct crypto_engine *engine);
  57. struct kthread_worker *kworker;
  58. struct kthread_work pump_requests;
  59. void *priv_data;
  60. struct crypto_async_request *cur_req;
  61. };
  62. #endif