2 * A loadable module that benchmarks the OCF crypto speed from kernel space.
4 * Copyright (C) 2004-2007 David McCullough <david_mccullough@securecomputing.com>
8 * The free distribution and use of this software in both source and binary
9 * form is allowed (with or without changes) provided that:
11 * 1. distributions of this source code include the above copyright
12 * notice, this list of conditions and the following disclaimer;
14 * 2. distributions in binary form include the above copyright
15 * notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other associated materials;
18 * 3. the copyright holder's name is not used to endorse products
19 * built using this software without specific written permission.
21 * ALTERNATIVELY, provided that this notice is retained in full, this product
22 * may be distributed under the terms of the GNU General Public License (GPL),
23 * in which case the provisions of the GPL apply INSTEAD OF those given above.
27 * This software is provided 'as is' with no explicit or implied warranties
28 * in respect of its properties, including, but not limited to, correctness
29 * and/or fitness for purpose.
33 #ifndef AUTOCONF_INCLUDED
34 #include <linux/config.h>
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/list.h>
39 #include <linux/slab.h>
40 #include <linux/wait.h>
41 #include <linux/sched.h>
42 #include <linux/spinlock.h>
43 #include <linux/version.h>
44 #include <linux/interrupt.h>
45 #include <cryptodev.h>
47 #ifdef I_HAVE_AN_XSCALE_WITH_INTEL_SDK
48 #define BENCH_IXP_ACCESS_LIB 1
50 #ifdef BENCH_IXP_ACCESS_LIB
52 #include <IxOsBuffMgt.h>
54 #include <IxCryptoAcc.h>
56 #include <IxOsServices.h>
57 #include <IxOsCacheMMU.h>
61 * support for access lib version 1.4
64 #define IX_MBUF_PRIV(x) ((x)->priv)
68 * the number of simultaneously active requests
70 static int request_q_len
= 20;
71 module_param(request_q_len
, int, 0);
72 MODULE_PARM_DESC(request_q_len
, "Number of outstanding requests");
74 * how many requests we want to have processed
76 static int request_num
= 1024;
77 module_param(request_num
, int, 0);
78 MODULE_PARM_DESC(request_num
, "run for at least this many requests");
80 * the size of each request
82 static int request_size
= 1500;
83 module_param(request_size
, int, 0);
84 MODULE_PARM_DESC(request_size
, "size of each request");
87 * a structure for each request
90 struct work_struct work
;
91 #ifdef BENCH_IXP_ACCESS_LIB
94 unsigned char *buffer
;
97 static request_t
*requests
;
99 static int outstanding
;
102 /*************************************************************************/
104 * OCF benchmark routines
107 static uint64_t ocf_cryptoid
;
108 static int ocf_init(void);
109 static int ocf_cb(struct cryptop
*crp
);
110 static void ocf_request(void *arg
);
111 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
112 static void ocf_request_wq(struct work_struct
*work
);
119 struct cryptoini crie
, cria
;
120 struct cryptodesc crda
, crde
;
122 memset(&crie
, 0, sizeof(crie
));
123 memset(&cria
, 0, sizeof(cria
));
124 memset(&crde
, 0, sizeof(crde
));
125 memset(&crda
, 0, sizeof(crda
));
127 cria
.cri_alg
= CRYPTO_SHA1_HMAC
;
128 cria
.cri_klen
= 20 * 8;
129 cria
.cri_key
= "0123456789abcdefghij";
131 crie
.cri_alg
= CRYPTO_3DES_CBC
;
132 crie
.cri_klen
= 24 * 8;
133 crie
.cri_key
= "0123456789abcdefghijklmn";
135 crie
.cri_next
= &cria
;
137 error
= crypto_newsession(&ocf_cryptoid
, &crie
, 0);
139 printk("crypto_newsession failed %d\n", error
);
146 ocf_cb(struct cryptop
*crp
)
148 request_t
*r
= (request_t
*) crp
->crp_opaque
;
151 printk("Error in OCF processing: %d\n", crp
->crp_etype
);
156 if (total
> request_num
) {
161 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
162 INIT_WORK(&r
->work
, ocf_request_wq
);
164 INIT_WORK(&r
->work
, ocf_request
, r
);
166 schedule_work(&r
->work
);
172 ocf_request(void *arg
)
175 struct cryptop
*crp
= crypto_getreq(2);
176 struct cryptodesc
*crde
, *crda
;
183 crde
= crp
->crp_desc
;
184 crda
= crde
->crd_next
;
188 crda
->crd_len
= request_size
;
189 crda
->crd_inject
= request_size
;
190 crda
->crd_alg
= CRYPTO_SHA1_HMAC
;
191 crda
->crd_key
= "0123456789abcdefghij";
192 crda
->crd_klen
= 20 * 8;
195 crde
->crd_flags
= CRD_F_IV_EXPLICIT
| CRD_F_ENCRYPT
;
196 crde
->crd_len
= request_size
;
197 crde
->crd_inject
= request_size
;
198 crde
->crd_alg
= CRYPTO_3DES_CBC
;
199 crde
->crd_key
= "0123456789abcdefghijklmn";
200 crde
->crd_klen
= 24 * 8;
202 crp
->crp_ilen
= request_size
+ 64;
203 crp
->crp_flags
= CRYPTO_F_CBIMM
;
204 crp
->crp_buf
= (caddr_t
) r
->buffer
;
205 crp
->crp_callback
= ocf_cb
;
206 crp
->crp_sid
= ocf_cryptoid
;
207 crp
->crp_opaque
= (caddr_t
) r
;
208 crypto_dispatch(crp
);
211 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
213 ocf_request_wq(struct work_struct
*work
)
215 request_t
*r
= container_of(work
, request_t
, work
);
220 /*************************************************************************/
221 #ifdef BENCH_IXP_ACCESS_LIB
222 /*************************************************************************/
224 * CryptoAcc benchmark routines
227 static IxCryptoAccCtx ixp_ctx
;
228 static UINT32 ixp_ctx_id
;
229 static IX_MBUF ixp_pri
;
230 static IX_MBUF ixp_sec
;
231 static int ixp_registered
= 0;
233 static void ixp_register_cb(UINT32 ctx_id
, IX_MBUF
*bufp
,
234 IxCryptoAccStatus status
);
235 static void ixp_perform_cb(UINT32 ctx_id
, IX_MBUF
*sbufp
, IX_MBUF
*dbufp
,
236 IxCryptoAccStatus status
);
237 static void ixp_request(void *arg
);
238 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
239 static void ixp_request_wq(struct work_struct
*work
);
245 IxCryptoAccStatus status
;
247 ixp_ctx
.cipherCtx
.cipherAlgo
= IX_CRYPTO_ACC_CIPHER_3DES
;
248 ixp_ctx
.cipherCtx
.cipherMode
= IX_CRYPTO_ACC_MODE_CBC
;
249 ixp_ctx
.cipherCtx
.cipherKeyLen
= 24;
250 ixp_ctx
.cipherCtx
.cipherBlockLen
= IX_CRYPTO_ACC_DES_BLOCK_64
;
251 ixp_ctx
.cipherCtx
.cipherInitialVectorLen
= IX_CRYPTO_ACC_DES_IV_64
;
252 memcpy(ixp_ctx
.cipherCtx
.key
.cipherKey
, "0123456789abcdefghijklmn", 24);
254 ixp_ctx
.authCtx
.authAlgo
= IX_CRYPTO_ACC_AUTH_SHA1
;
255 ixp_ctx
.authCtx
.authDigestLen
= 12;
256 ixp_ctx
.authCtx
.aadLen
= 0;
257 ixp_ctx
.authCtx
.authKeyLen
= 20;
258 memcpy(ixp_ctx
.authCtx
.key
.authKey
, "0123456789abcdefghij", 20);
260 ixp_ctx
.useDifferentSrcAndDestMbufs
= 0;
261 ixp_ctx
.operation
= IX_CRYPTO_ACC_OP_ENCRYPT_AUTH
;
263 IX_MBUF_MLEN(&ixp_pri
) = IX_MBUF_PKT_LEN(&ixp_pri
) = 128;
264 IX_MBUF_MDATA(&ixp_pri
) = (unsigned char *) kmalloc(128, SLAB_ATOMIC
);
265 IX_MBUF_MLEN(&ixp_sec
) = IX_MBUF_PKT_LEN(&ixp_sec
) = 128;
266 IX_MBUF_MDATA(&ixp_sec
) = (unsigned char *) kmalloc(128, SLAB_ATOMIC
);
268 status
= ixCryptoAccCtxRegister(&ixp_ctx
, &ixp_pri
, &ixp_sec
,
269 ixp_register_cb
, ixp_perform_cb
, &ixp_ctx_id
);
271 if (IX_CRYPTO_ACC_STATUS_SUCCESS
== status
) {
272 while (!ixp_registered
)
274 return ixp_registered
< 0 ? -1 : 0;
277 printk("ixp: ixCryptoAccCtxRegister failed %d\n", status
);
282 ixp_register_cb(UINT32 ctx_id
, IX_MBUF
*bufp
, IxCryptoAccStatus status
)
285 IX_MBUF_MLEN(bufp
) = IX_MBUF_PKT_LEN(bufp
) = 0;
286 kfree(IX_MBUF_MDATA(bufp
));
287 IX_MBUF_MDATA(bufp
) = NULL
;
290 if (IX_CRYPTO_ACC_STATUS_WAIT
== status
)
292 if (IX_CRYPTO_ACC_STATUS_SUCCESS
== status
)
303 IxCryptoAccStatus status
)
308 if (total
> request_num
) {
313 if (!sbufp
|| !(r
= IX_MBUF_PRIV(sbufp
))) {
314 printk("crappo %p %p\n", sbufp
, r
);
319 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
320 INIT_WORK(&r
->work
, ixp_request_wq
);
322 INIT_WORK(&r
->work
, ixp_request
, r
);
324 schedule_work(&r
->work
);
328 ixp_request(void *arg
)
331 IxCryptoAccStatus status
;
333 memset(&r
->mbuf
, 0, sizeof(r
->mbuf
));
334 IX_MBUF_MLEN(&r
->mbuf
) = IX_MBUF_PKT_LEN(&r
->mbuf
) = request_size
+ 64;
335 IX_MBUF_MDATA(&r
->mbuf
) = r
->buffer
;
336 IX_MBUF_PRIV(&r
->mbuf
) = r
;
337 status
= ixCryptoAccAuthCryptPerform(ixp_ctx_id
, &r
->mbuf
, NULL
,
338 0, request_size
, 0, request_size
, request_size
, r
->buffer
);
339 if (IX_CRYPTO_ACC_STATUS_SUCCESS
!= status
) {
340 printk("status1 = %d\n", status
);
347 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
349 ixp_request_wq(struct work_struct
*work
)
351 request_t
*r
= container_of(work
, request_t
, work
);
356 /*************************************************************************/
357 #endif /* BENCH_IXP_ACCESS_LIB */
358 /*************************************************************************/
363 int i
, jstart
, jstop
;
365 printk("Crypto Speed tests\n");
367 requests
= kmalloc(sizeof(request_t
) * request_q_len
, GFP_KERNEL
);
369 printk("malloc failed\n");
373 for (i
= 0; i
< request_q_len
; i
++) {
374 /* +64 for return data */
375 requests
[i
].buffer
= kmalloc(request_size
+ 128, GFP_DMA
);
376 if (!requests
[i
].buffer
) {
377 printk("malloc failed\n");
380 memset(requests
[i
].buffer
, '0' + i
, request_size
+ 128);
386 printk("OCF: testing ...\n");
388 total
= outstanding
= 0;
390 for (i
= 0; i
< request_q_len
; i
++) {
392 ocf_request(&requests
[i
]);
394 while (outstanding
> 0)
398 printk("OCF: %d requests of %d bytes in %d jiffies\n", total
, request_size
,
401 #ifdef BENCH_IXP_ACCESS_LIB
405 printk("IXP: testing ...\n");
407 total
= outstanding
= 0;
409 for (i
= 0; i
< request_q_len
; i
++) {
411 ixp_request(&requests
[i
]);
413 while (outstanding
> 0)
417 printk("IXP: %d requests of %d bytes in %d jiffies\n", total
, request_size
,
419 #endif /* BENCH_IXP_ACCESS_LIB */
421 for (i
= 0; i
< request_q_len
; i
++)
422 kfree(requests
[i
].buffer
);
424 return -EINVAL
; /* always fail to load so it can be re-run quickly ;-) */
427 static void __exit
ocfbench_exit(void)
431 module_init(ocfbench_init
);
432 module_exit(ocfbench_exit
);
434 MODULE_LICENSE("BSD");
435 MODULE_AUTHOR("David McCullough <david_mccullough@securecomputing.com>");
436 MODULE_DESCRIPTION("Benchmark various in-kernel crypto speeds");