diff options
| author | Corentin LABBE <clabbe.montjoie@gmail.com> | 2016-08-31 08:02:57 -0400 |
|---|---|---|
| committer | Herbert Xu <herbert@gondor.apana.org.au> | 2016-09-07 09:08:26 -0400 |
| commit | 2589ad84047f1dbed741b48785680b152db2e5db (patch) | |
| tree | 3e621205912912c5dd2bb7d9a2d4e1d89cc186bc /include/crypto | |
| parent | 1548a37da044aa123492638e61283a23cb4b475d (diff) | |
crypto: engine - move crypto engine to its own header
This patch move the whole crypto engine API to its own header
crypto/engine.h.
Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'include/crypto')
| -rw-r--r-- | include/crypto/algapi.h | 70 | ||||
| -rw-r--r-- | include/crypto/engine.h | 90 |
2 files changed, 90 insertions, 70 deletions
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 8637cdfe382a..404e9558e879 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h | |||
| @@ -15,7 +15,6 @@ | |||
| 15 | #include <linux/crypto.h> | 15 | #include <linux/crypto.h> |
| 16 | #include <linux/list.h> | 16 | #include <linux/list.h> |
| 17 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
| 18 | #include <linux/kthread.h> | ||
| 19 | #include <linux/skbuff.h> | 18 | #include <linux/skbuff.h> |
| 20 | 19 | ||
| 21 | struct crypto_aead; | 20 | struct crypto_aead; |
| @@ -129,75 +128,6 @@ struct ablkcipher_walk { | |||
| 129 | unsigned int blocksize; | 128 | unsigned int blocksize; |
| 130 | }; | 129 | }; |
| 131 | 130 | ||
| 132 | #define ENGINE_NAME_LEN 30 | ||
| 133 | /* | ||
| 134 | * struct crypto_engine - crypto hardware engine | ||
| 135 | * @name: the engine name | ||
| 136 | * @idling: the engine is entering idle state | ||
| 137 | * @busy: request pump is busy | ||
| 138 | * @running: the engine is on working | ||
| 139 | * @cur_req_prepared: current request is prepared | ||
| 140 | * @list: link with the global crypto engine list | ||
| 141 | * @queue_lock: spinlock to syncronise access to request queue | ||
| 142 | * @queue: the crypto queue of the engine | ||
| 143 | * @rt: whether this queue is set to run as a realtime task | ||
| 144 | * @prepare_crypt_hardware: a request will soon arrive from the queue | ||
| 145 | * so the subsystem requests the driver to prepare the hardware | ||
| 146 | * by issuing this call | ||
| 147 | * @unprepare_crypt_hardware: there are currently no more requests on the | ||
| 148 | * queue so the subsystem notifies the driver that it may relax the | ||
| 149 | * hardware by issuing this call | ||
| 150 | * @prepare_request: do some prepare if need before handle the current request | ||
| 151 | * @unprepare_request: undo any work done by prepare_message() | ||
| 152 | * @crypt_one_request: do encryption for current request | ||
| 153 | * @kworker: thread struct for request pump | ||
| 154 | * @kworker_task: pointer to task for request pump kworker thread | ||
| 155 | * @pump_requests: work struct for scheduling work to the request pump | ||
| 156 | * @priv_data: the engine private data | ||
| 157 | * @cur_req: the current request which is on processing | ||
| 158 | */ | ||
| 159 | struct crypto_engine { | ||
| 160 | char name[ENGINE_NAME_LEN]; | ||
| 161 | bool idling; | ||
| 162 | bool busy; | ||
| 163 | bool running; | ||
| 164 | bool cur_req_prepared; | ||
| 165 | |||
| 166 | struct list_head list; | ||
| 167 | spinlock_t queue_lock; | ||
| 168 | struct crypto_queue queue; | ||
| 169 | |||
| 170 | bool rt; | ||
| 171 | |||
| 172 | int (*prepare_crypt_hardware)(struct crypto_engine *engine); | ||
| 173 | int (*unprepare_crypt_hardware)(struct crypto_engine *engine); | ||
| 174 | |||
| 175 | int (*prepare_request)(struct crypto_engine *engine, | ||
| 176 | struct ablkcipher_request *req); | ||
| 177 | int (*unprepare_request)(struct crypto_engine *engine, | ||
| 178 | struct ablkcipher_request *req); | ||
| 179 | int (*crypt_one_request)(struct crypto_engine *engine, | ||
| 180 | struct ablkcipher_request *req); | ||
| 181 | |||
| 182 | struct kthread_worker kworker; | ||
| 183 | struct task_struct *kworker_task; | ||
| 184 | struct kthread_work pump_requests; | ||
| 185 | |||
| 186 | void *priv_data; | ||
| 187 | struct ablkcipher_request *cur_req; | ||
| 188 | }; | ||
| 189 | |||
| 190 | int crypto_transfer_request(struct crypto_engine *engine, | ||
| 191 | struct ablkcipher_request *req, bool need_pump); | ||
| 192 | int crypto_transfer_request_to_engine(struct crypto_engine *engine, | ||
| 193 | struct ablkcipher_request *req); | ||
| 194 | void crypto_finalize_request(struct crypto_engine *engine, | ||
| 195 | struct ablkcipher_request *req, int err); | ||
| 196 | int crypto_engine_start(struct crypto_engine *engine); | ||
| 197 | int crypto_engine_stop(struct crypto_engine *engine); | ||
| 198 | struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt); | ||
| 199 | int crypto_engine_exit(struct crypto_engine *engine); | ||
| 200 | |||
| 201 | extern const struct crypto_type crypto_ablkcipher_type; | 131 | extern const struct crypto_type crypto_ablkcipher_type; |
| 202 | extern const struct crypto_type crypto_blkcipher_type; | 132 | extern const struct crypto_type crypto_blkcipher_type; |
| 203 | 133 | ||
diff --git a/include/crypto/engine.h b/include/crypto/engine.h new file mode 100644 index 000000000000..40899bd246ec --- /dev/null +++ b/include/crypto/engine.h | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | /* | ||
| 2 | * Crypto engine API | ||
| 3 | * | ||
| 4 | * Copyright (c) 2016 Baolin Wang <baolin.wang@linaro.org> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify it | ||
| 7 | * under the terms of the GNU General Public License as published by the Free | ||
| 8 | * Software Foundation; either version 2 of the License, or (at your option) | ||
| 9 | * any later version. | ||
| 10 | * | ||
| 11 | */ | ||
| 12 | #ifndef _CRYPTO_ENGINE_H | ||
| 13 | #define _CRYPTO_ENGINE_H | ||
| 14 | |||
| 15 | #include <linux/crypto.h> | ||
| 16 | #include <linux/list.h> | ||
| 17 | #include <linux/kernel.h> | ||
| 18 | #include <linux/kthread.h> | ||
| 19 | #include <crypto/algapi.h> | ||
| 20 | |||
| 21 | #define ENGINE_NAME_LEN 30 | ||
| 22 | /* | ||
| 23 | * struct crypto_engine - crypto hardware engine | ||
| 24 | * @name: the engine name | ||
| 25 | * @idling: the engine is entering idle state | ||
| 26 | * @busy: request pump is busy | ||
| 27 | * @running: the engine is on working | ||
| 28 | * @cur_req_prepared: current request is prepared | ||
| 29 | * @list: link with the global crypto engine list | ||
| 30 | * @queue_lock: spinlock to syncronise access to request queue | ||
| 31 | * @queue: the crypto queue of the engine | ||
| 32 | * @rt: whether this queue is set to run as a realtime task | ||
| 33 | * @prepare_crypt_hardware: a request will soon arrive from the queue | ||
| 34 | * so the subsystem requests the driver to prepare the hardware | ||
| 35 | * by issuing this call | ||
| 36 | * @unprepare_crypt_hardware: there are currently no more requests on the | ||
| 37 | * queue so the subsystem notifies the driver that it may relax the | ||
| 38 | * hardware by issuing this call | ||
| 39 | * @prepare_request: do some prepare if need before handle the current request | ||
| 40 | * @unprepare_request: undo any work done by prepare_message() | ||
| 41 | * @crypt_one_request: do encryption for current request | ||
| 42 | * @kworker: thread struct for request pump | ||
| 43 | * @kworker_task: pointer to task for request pump kworker thread | ||
| 44 | * @pump_requests: work struct for scheduling work to the request pump | ||
| 45 | * @priv_data: the engine private data | ||
| 46 | * @cur_req: the current request which is on processing | ||
| 47 | */ | ||
| 48 | struct crypto_engine { | ||
| 49 | char name[ENGINE_NAME_LEN]; | ||
| 50 | bool idling; | ||
| 51 | bool busy; | ||
| 52 | bool running; | ||
| 53 | bool cur_req_prepared; | ||
| 54 | |||
| 55 | struct list_head list; | ||
| 56 | spinlock_t queue_lock; | ||
| 57 | struct crypto_queue queue; | ||
| 58 | |||
| 59 | bool rt; | ||
| 60 | |||
| 61 | int (*prepare_crypt_hardware)(struct crypto_engine *engine); | ||
| 62 | int (*unprepare_crypt_hardware)(struct crypto_engine *engine); | ||
| 63 | |||
| 64 | int (*prepare_request)(struct crypto_engine *engine, | ||
| 65 | struct ablkcipher_request *req); | ||
| 66 | int (*unprepare_request)(struct crypto_engine *engine, | ||
| 67 | struct ablkcipher_request *req); | ||
| 68 | int (*crypt_one_request)(struct crypto_engine *engine, | ||
| 69 | struct ablkcipher_request *req); | ||
| 70 | |||
| 71 | struct kthread_worker kworker; | ||
| 72 | struct task_struct *kworker_task; | ||
| 73 | struct kthread_work pump_requests; | ||
| 74 | |||
| 75 | void *priv_data; | ||
| 76 | struct ablkcipher_request *cur_req; | ||
| 77 | }; | ||
| 78 | |||
| 79 | int crypto_transfer_request(struct crypto_engine *engine, | ||
| 80 | struct ablkcipher_request *req, bool need_pump); | ||
| 81 | int crypto_transfer_request_to_engine(struct crypto_engine *engine, | ||
| 82 | struct ablkcipher_request *req); | ||
| 83 | void crypto_finalize_request(struct crypto_engine *engine, | ||
| 84 | struct ablkcipher_request *req, int err); | ||
| 85 | int crypto_engine_start(struct crypto_engine *engine); | ||
| 86 | int crypto_engine_stop(struct crypto_engine *engine); | ||
| 87 | struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt); | ||
| 88 | int crypto_engine_exit(struct crypto_engine *engine); | ||
| 89 | |||
| 90 | #endif /* _CRYPTO_ENGINE_H */ | ||
