1 From ffa8fd090afaf3631e6abd0ab8daa6780be7c31c Mon Sep 17 00:00:00 2001
2 From: Yashpal Dutta <yashpal.dutta@freescale.com>
3 Date: Fri, 7 Mar 2014 07:24:00 +0545
4 Subject: [[Patch][fsl 11/16] Asynchronous interface changes in cryptodev
6 Upstream-status: Pending
8 Signed-off-by: Yashpal Dutta <yashpal.dutta@freescale.com>
11 crypto/cryptodev.h | 10 ++++++-
12 cryptodev_int.h | 10 ++++++-
13 ioctl.c | 76 +++++++++++++++++++++++++++++++++++-----------------
14 4 files changed, 76 insertions(+), 27 deletions(-)
16 diff --git a/cryptlib.h b/cryptlib.h
17 index e77edc5..947d845 100644
20 @@ -113,7 +113,12 @@ struct cryptodev_pkc {
21 struct pkc_request req; /* PKC request structure allocated
23 enum offload_type type; /* Synchronous Vs Asynchronous request */
24 - void *cookie; /*Additional opaque cookie to be used in future */
26 + * cookie used for transfering tranparent information from async
27 + * submission to async fetch. Currently some dynamic allocated
28 + * buffers are maintained which will be freed later during fetch
31 struct crypt_priv *priv;
34 diff --git a/crypto/cryptodev.h b/crypto/cryptodev.h
35 index 575ce63..0d65899 100644
36 --- a/crypto/cryptodev.h
37 +++ b/crypto/cryptodev.h
38 @@ -255,6 +255,14 @@ struct crypt_kop {
42 +#define MAX_COOKIES 4
44 +struct pkc_cookie_list_s {
45 + int cookie_available;
46 + void *cookie[MAX_COOKIES];
47 + int status[MAX_COOKIES];
50 enum cryptodev_crk_op_t {
53 @@ -299,5 +307,5 @@ enum cryptodev_crk_op_t {
54 #define CIOCASYNCFETCH _IOR('c', 111, struct crypt_op)
55 /* additional ioctls for asynchronous operation for asymmetric ciphers*/
56 #define CIOCASYMASYNCRYPT _IOW('c', 112, struct crypt_kop)
57 -#define CIOCASYMASYNFETCH _IOR('c', 113, struct crypt_kop)
58 +#define CIOCASYMFETCHCOOKIE _IOR('c', 113, struct pkc_cookie_list_s)
59 #endif /* L_CRYPTODEV_H */
60 diff --git a/cryptodev_int.h b/cryptodev_int.h
61 index 229fcd0..8beeef0 100644
64 @@ -93,6 +93,12 @@ struct compat_crypt_kop {
68 +struct compat_pkc_cookie_list_s {
69 + int cookie_available;
70 + compat_uptr_t cookie[MAX_COOKIES];
71 + int status[MAX_COOKIES];
74 /* input of CIOCAUTHCRYPT */
75 struct compat_crypt_auth_op {
76 uint32_t ses; /* session identifier */
77 @@ -127,11 +133,13 @@ struct compat_crypt_auth_op {
78 /* compat ioctls, defined for the above structs */
79 #define COMPAT_CIOCGSESSION _IOWR('c', 102, struct compat_session_op)
80 #define COMPAT_CIOCCRYPT _IOWR('c', 104, struct compat_crypt_op)
81 +#define COMPAT_CIOCKEY _IOW('c', 105, struct compat_crypt_kop)
82 #define COMPAT_CIOCASYNCCRYPT _IOW('c', 107, struct compat_crypt_op)
83 #define COMPAT_CIOCASYNCFETCH _IOR('c', 108, struct compat_crypt_op)
84 #define COMPAT_CIOCAUTHCRYPT _IOWR('c', 109, struct compat_crypt_auth_op)
85 #define COMPAT_CIOCASYMASYNCRYPT _IOW('c', 110, struct compat_crypt_kop)
86 -#define COMPAT_CIOCASYMASYNFETCH _IOR('c', 111, struct compat_crypt_kop)
87 +#define COMPAT_CIOCASYMFETCHCOOKIE _IOR('c', 111, \
88 + struct compat_pkc_cookie_list_s)
90 #endif /* CONFIG_COMPAT */
92 diff --git a/ioctl.c b/ioctl.c
93 index ec82c69..9f57d46 100644
96 @@ -103,8 +103,6 @@ void cryptodev_complete_asym(struct crypto_async_request *req, int err)
97 crypto_free_pkc(pkc->s);
99 if (pkc->type == SYNCHRONOUS) {
100 - if (err == -EINPROGRESS)
102 complete(&res->completion);
104 struct crypt_priv *pcr = pkc->priv;
105 @@ -1046,26 +1044,41 @@ cryptodev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg_)
109 - case CIOCASYMASYNFETCH:
110 + case CIOCASYMFETCHCOOKIE:
112 struct cryptodev_pkc *pkc;
115 + struct pkc_cookie_list_s cookie_list;
117 spin_lock_irqsave(&pcr->completion_lock, flags);
118 - if (list_empty(&pcr->asym_completed_list)) {
119 - spin_unlock_irqrestore(&pcr->completion_lock, flags);
121 + cookie_list.cookie_available = 0;
122 + for (i = 0; i < MAX_COOKIES; i++) {
123 + if (!list_empty(&pcr->asym_completed_list)) {
124 + /* Run a loop in the list for upto elements
125 + and copy their response back */
127 + list_first_entry(&pcr->asym_completed_list,
128 + struct cryptodev_pkc, list);
129 + list_del(&pkc->list);
130 + ret = crypto_async_fetch_asym(pkc);
132 + cookie_list.cookie_available++;
133 + cookie_list.cookie[i] =
134 + pkc->kop.kop.cookie;
135 + cookie_list.status[i] = pkc->result.err;
142 - pkc = list_first_entry(&pcr->asym_completed_list,
143 - struct cryptodev_pkc, list);
144 - list_del(&pkc->list);
145 spin_unlock_irqrestore(&pcr->completion_lock, flags);
146 - ret = crypto_async_fetch_asym(pkc);
148 /* Reflect the updated request to user-space */
150 - kop_to_user(&pkc->kop, arg);
152 + if (cookie_list.cookie_available)
153 + copy_to_user(arg, &cookie_list,
154 + sizeof(struct pkc_cookie_list_s));
158 @@ -1340,26 +1353,41 @@ cryptodev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg_)
162 - case COMPAT_CIOCASYMASYNFETCH:
163 + case COMPAT_CIOCASYMFETCHCOOKIE:
165 struct cryptodev_pkc *pkc;
168 + struct compat_pkc_cookie_list_s cookie_list;
170 spin_lock_irqsave(&pcr->completion_lock, flags);
171 - if (list_empty(&pcr->asym_completed_list)) {
172 - spin_unlock_irqrestore(&pcr->completion_lock, flags);
174 + cookie_list.cookie_available = 0;
176 + for (i = 0; i < MAX_COOKIES; i++) {
177 + if (!list_empty(&pcr->asym_completed_list)) {
178 + /* Run a loop in the list for upto elements
179 + and copy their response back */
181 + list_first_entry(&pcr->asym_completed_list,
182 + struct cryptodev_pkc, list);
183 + list_del(&pkc->list);
184 + ret = crypto_async_fetch_asym(pkc);
186 + cookie_list.cookie_available++;
187 + cookie_list.cookie[i] =
188 + pkc->kop.kop.cookie;
195 - pkc = list_first_entry(&pcr->asym_completed_list,
196 - struct cryptodev_pkc, list);
197 - list_del(&pkc->list);
198 spin_unlock_irqrestore(&pcr->completion_lock, flags);
199 - ret = crypto_async_fetch_asym(pkc);
201 /* Reflect the updated request to user-space */
203 - compat_kop_to_user(&pkc->kop, arg);
205 + if (cookie_list.cookie_available)
206 + copy_to_user(arg, &cookie_list,
207 + sizeof(struct compat_pkc_cookie_list_s));