1 /******************************************************************************
3 ** FILE NAME : ifxmips_async_des.c
5 ** MODULES : DEU Module
7 ** DATE : October 11, 2010
8 ** AUTHOR : Mohammad Firdaus
9 ** DESCRIPTION : Data Encryption Unit Driver for DES Algorithm
10 ** COPYRIGHT : Copyright (c) 2010
11 ** Infineon Technologies AG
12 ** Am Campeon 1-12, 85579 Neubiberg, Germany
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License as published by
16 ** the Free Software Foundation; either version 2 of the License, or
17 ** (at your option) any later version.
20 ** $Date $Author $Comment
21 ** 08,Sept 2009 Mohammad Firdaus Initial UEIP release
22 ** 11, Oct 2010 Mohammad Firdaus Kernel Port incl. Async. Ablkcipher mode
23 ** 21,March 2011 Mohammad Firdaus Changes for Kernel 2.6.32 and IPSec integration
24 *******************************************************************************/
26 \defgroup IFX_DEU IFX_DEU_DRIVERS
28 \brief ifx DEU driver module
32 \file ifxmips_async_des.c
34 \brief DES Encryption Driver main file
38 \defgroup IFX_DES_FUNCTIONS IFX_DES_FUNCTIONS
40 \brief IFX DES driver Functions
43 #include <linux/wait.h>
44 #include <linux/crypto.h>
45 #include <linux/kernel.h>
46 #include <linux/interrupt.h>
47 #include <linux/spinlock.h>
48 #include <linux/list.h>
49 #include <crypto/ctr.h>
50 #include <crypto/aes.h>
51 #include <crypto/algapi.h>
52 #include <crypto/scatterwalk.h>
54 #include <asm/ifx/ifx_regs.h>
55 #include <asm/ifx/ifx_types.h>
56 #include <asm/ifx/common_routines.h>
57 #include <asm/ifx/irq.h>
58 #include <asm/ifx/ifx_pmu.h>
59 #include <asm/ifx/ifx_gpio.h>
60 #include <asm/kmap_types.h>
62 #include "ifxmips_deu.h"
64 #if defined(CONFIG_DANUBE)
65 #include "ifxmips_deu_danube.h"
66 extern int ifx_danube_pre_1_4
;
67 #elif defined(CONFIG_AR9)
68 #include "ifxmips_deu_ar9.h"
69 #elif defined(CONFIG_VR9) || defined(CONFIG_AR10)
70 #include "ifxmips_deu_vr9.h"
72 #error "Unkown platform"
75 /* DMA specific header and variables */
78 #define CRTCL_SECT_INIT spin_lock_init(&des_lock)
79 #define CRTCL_SECT_START spin_lock_irqsave(&des_lock, flag)
80 #define CRTCL_SECT_END spin_unlock_irqrestore(&des_lock, flag)
82 /* Preprocessor declerations */
84 extern char debug_level
;
85 #define DPRINTF(level, format, args...) if (level < debug_level) printk(KERN_INFO "[%s %s %d]: " format, __FILE__, __func__, __LINE__, ##args);
87 #define DPRINTF(level, format, args...)
89 //#define DES_3DES_START IFX_DES_CON
90 #define DES_KEY_SIZE 8
91 #define DES_EXPKEY_WORDS 32
92 #define DES_BLOCK_SIZE 8
93 #define DES3_EDE_KEY_SIZE (3 * DES_KEY_SIZE)
94 #define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS)
95 #define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE
97 /* Function Declaration to prevent warning messages */
98 void des_chip_init (void);
99 u32
endian_swap(u32 input
);
100 u32
input_swap(u32 input
);
101 int aes_memory_allocate(int value
);
102 int des_memory_allocate(int value
);
103 void memory_release(u32
*buffer
);
104 u32
* memory_alignment(const u8
*arg
, u32
*buff_alloc
, int in_out
, int nbytes
);
105 void aes_dma_memory_copy(u32
*outcopy
, u32
*out_dma
, u8
*out_arg
, int nbytes
);
106 void des_dma_memory_copy(u32
*outcopy
, u32
*out_dma
, u8
*out_arg
, int nbytes
);
108 static int lq_deu_des_core (void *ctx_arg
, u8
*out_arg
, const u8
*in_arg
,
109 u8
*iv_arg
, u32 nbytes
, int encdec
, int mode
);
114 u8 iv
[DES_BLOCK_SIZE
];
115 u32 expkey
[DES3_EDE_EXPKEY_WORDS
];
119 static int disable_multiblock
= 0;
120 module_param(disable_multiblock
, int, 0);
122 static int disable_deudma
= 1;
124 struct des_container
{
136 struct ablkcipher_request arequest
;
139 des_priv_t
*des_queue
;
140 extern deu_drv_priv_t deu_dma_priv
;
142 void hexdump1(unsigned char *buf
, unsigned int len
)
144 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
150 /*! \fn int lq_des_setkey(struct crypto_ablkcipher *tfm, const u8 *key, unsigned int keylen)
151 * \ingroup IFX_DES_FUNCTIONS
152 * \brief sets DES key
153 * \param tfm linux crypto algo transform
154 * \param key input key
155 * \param keylen key length
157 static int lq_des_setkey(struct crypto_ablkcipher
*tfm
, const u8
*key
,
160 struct des_ctx
*dctx
= crypto_ablkcipher_ctx(tfm
);
162 //printk("setkey in %s\n", __FILE__);
164 dctx
->controlr_M
= 0; // des
165 dctx
->key_length
= keylen
;
167 memcpy ((u8
*) (dctx
->expkey
), key
, keylen
);
172 /*! \fn int lq_des3_ede_setkey(struct crypto_ablkcipher *tfm, const u8 *key, unsigned int keylen)
173 * \ingroup IFX_DES_FUNCTIONS
174 * \brief sets DES key
175 * \param tfm linux crypto algo transform
176 * \param key input key
177 * \param keylen key length
180 static int lq_des3_ede_setkey(struct crypto_ablkcipher
*tfm
, const u8
*in_key
,
183 struct des_ctx
*dctx
= crypto_ablkcipher_ctx(tfm
);
185 //printk("setkey in %s\n", __FILE__);
187 dctx
->controlr_M
= keylen
/8 + 1; // des
188 dctx
->key_length
= keylen
;
190 memcpy ((u8
*) (dctx
->expkey
), in_key
, keylen
);
195 /*! \fn void ifx_deu_des_core(void *ctx_arg, u8 *out_arg, const u8 *in_arg, u8 *iv_arg, u32 nbytes, int encdec, int mode)
196 * \ingroup IFX_DES_FUNCTIONS
197 * \brief main interface to DES hardware
198 * \param ctx_arg crypto algo context
199 * \param out_arg output bytestream
200 * \param in_arg input bytestream
201 * \param iv_arg initialization vector
202 * \param nbytes length of bytestream
203 * \param encdec 1 for encrypt; 0 for decrypt
204 * \param mode operation mode such as ebc, cbc
207 static int lq_deu_des_core (void *ctx_arg
, u8
*out_arg
, const u8
*in_arg
,
208 u8
*iv_arg
, u32 nbytes
, int encdec
, int mode
)
210 volatile struct des_t
*des
= (struct des_t
*) DES_3DES_START
;
211 struct des_ctx
*dctx
= ctx_arg
;
212 u32
*key
= dctx
->expkey
;
220 des
->controlr
.M
= dctx
->controlr_M
;
221 if (dctx
->controlr_M
== 0) // des
223 des
->K1HR
= DEU_ENDIAN_SWAP(*((u32
*) key
+ 0));
224 des
->K1LR
= DEU_ENDIAN_SWAP(*((u32
*) key
+ 1));
228 /* Hardware Section */
229 switch (dctx
->key_length
) {
231 des
->K3HR
= DEU_ENDIAN_SWAP(*((u32
*) key
+ 4));
232 des
->K3LR
= DEU_ENDIAN_SWAP(*((u32
*) key
+ 5));
236 des
->K2HR
= DEU_ENDIAN_SWAP(*((u32
*) key
+ 2));
237 des
->K2LR
= DEU_ENDIAN_SWAP(*((u32
*) key
+ 3));
241 des
->K1HR
= DEU_ENDIAN_SWAP(*((u32
*) key
+ 0));
242 des
->K1LR
= DEU_ENDIAN_SWAP(*((u32
*) key
+ 1));
251 des
->controlr
.E_D
= !encdec
; //encryption
252 des
->controlr
.O
= mode
; //0 ECB 1 CBC 2 OFB 3 CFB 4 CTR hexdump(prin,sizeof(*des));
255 des
->IVHR
= DEU_ENDIAN_SWAP(*(u32
*) iv_arg
);
256 des
->IVLR
= DEU_ENDIAN_SWAP(*((u32
*) iv_arg
+ 1));
259 /* memory alignment issue */
260 dword_mem_aligned_in
= (u32
*) DEU_DWORD_REORDERING(in_arg
, des_buff_in
, BUFFER_IN
, nbytes
);
262 deu_priv
->deu_rx_buf
= (u32
*) out_arg
;
263 deu_priv
->deu_rx_len
= nbytes
;
265 dma
->controlr
.ALGO
= 0; //DES
266 des
->controlr
.DAU
= 0;
267 dma
->controlr
.BS
= 0;
268 dma
->controlr
.EN
= 1;
270 while (des
->controlr
.BUS
) {
273 wlen
= dma_device_write (dma_device
, (u8
*) dword_mem_aligned_in
, nbytes
, NULL
);
274 if (wlen
!= nbytes
) {
275 dma
->controlr
.EN
= 0;
277 printk (KERN_ERR
"[%s %s %d]: dma_device_write fail!\n", __FILE__
, __func__
, __LINE__
);
282 /* Prepare Rx buf length used in dma psuedo interrupt */
283 outcopy
= (u32
*) DEU_DWORD_REORDERING(out_arg
, des_buff_out
, BUFFER_OUT
, nbytes
);
284 deu_priv
->outcopy
= outcopy
;
285 deu_priv
->event_src
= DES_ASYNC_EVENT
;
288 *(u32
*) iv_arg
= DEU_ENDIAN_SWAP(des
->IVHR
);
289 *((u32
*) iv_arg
+ 1) = DEU_ENDIAN_SWAP(des
->IVLR
);
298 static int count_sgs(struct scatterlist
*sl
, unsigned int total_bytes
)
303 total_bytes
-= sl
[i
].length
;
306 } while (total_bytes
> 0);
311 /* \fn static inline struct des_container *des_container_cast (
312 * struct scatterlist *dst)
313 * \ingroup IFX_DES_FUNCTIONS
314 * \brief Locate the structure des_container in memory.
315 * \param *areq Pointer to memory location where ablkcipher_request is located
316 * \return *des_cointainer The function pointer to des_container
319 static inline struct des_container
*des_container_cast(
320 struct ablkcipher_request
*areq
)
322 return container_of(areq
, struct des_container
, arequest
);
325 /* \fn static void lq_sg_complete(struct des_container *des_con)
326 * \ingroup IFX_DES_FUNCTIONS
327 * \brief Free the used up memory after encryt/decrypt.
330 static void lq_sg_complete(struct des_container
*des_con
)
332 unsigned long queue_flag
;
334 spin_lock_irqsave(&des_queue
->lock
, queue_flag
);
336 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
339 /* \fn void lq_sg_init(struct scatterlist *src,
340 * struct scatterlist *dst)
341 * \ingroup IFX_DES_FUNCTIONS
342 * \brief Maps the scatterlists into a source/destination page.
343 * \param *src Pointer to the source scatterlist
344 * \param *dst Pointer to the destination scatterlist
347 static void lq_sg_init(struct des_container
*des_con
, struct scatterlist
*src
,
348 struct scatterlist
*dst
)
350 struct page
*dst_page
, *src_page
;
352 src_page
= sg_virt(src
);
353 des_con
->src_buf
= (char *) src_page
;
355 dst_page
= sg_virt(dst
);
356 des_con
->dst_buf
= (char *) dst_page
;
359 /* \fn static int process_next_packet(struct des_container *des_con, struct ablkcipher_request *areq,
361 * \ingroup IFX_DES_FUNCTIONS
362 * \brief Process the next packet after dequeuing the packet from crypto queue
363 * \param *des_con Pointer to DES container structure
364 * \param *areq Pointer to ablkcipher_request container
365 * \param state State of the packet (scattered packet or new packet to be processed)
366 * \return -EINVAL: DEU failure, -EINPROGRESS: DEU encrypt/decrypt in progress, 1: no scatterlist left
369 static int process_next_packet(struct des_container
*des_con
, struct ablkcipher_request
*areq
,
373 int mode
, encdec
, err
= -EINVAL
;
374 u32 remain
, inc
, chunk_size
, nbytes
;
375 struct scatterlist
*src
= NULL
;
376 struct scatterlist
*dst
= NULL
;
377 struct crypto_ablkcipher
*cipher
;
379 unsigned long queue_flag
;
381 spin_lock_irqsave(&des_queue
->lock
, queue_flag
);
383 mode
= des_con
->mode
;
384 encdec
= des_con
->encdec
;
387 if (state
& PROCESS_SCATTER
) {
388 src
= scatterwalk_sg_next(areq
->src
);
389 dst
= scatterwalk_sg_next(areq
->dst
);
392 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
396 else if (state
& PROCESS_NEW_PACKET
) {
401 remain
= des_con
->bytes_processed
;
402 chunk_size
= src
->length
;
404 //printk("debug ln: %d, func: %s, reqsize: %d, scattersize: %d\n",
405 // __LINE__, __func__, areq->nbytes, chunk_size);
407 if (remain
> DEU_MAX_PACKET_SIZE
)
408 inc
= DEU_MAX_PACKET_SIZE
;
409 else if(remain
> chunk_size
)
415 des_con
->nbytes
= inc
;
417 if (state
& PROCESS_SCATTER
) {
418 des_con
->src_buf
+= des_con
->nbytes
;
419 des_con
->dst_buf
+= des_con
->nbytes
;
422 lq_sg_init(des_con
, src
, dst
);
424 nbytes
= des_con
->nbytes
;
426 cipher
= crypto_ablkcipher_reqtfm(areq
);
427 ctx
= crypto_ablkcipher_ctx(cipher
);
429 if (des_queue
->hw_status
== DES_IDLE
) {
430 des_queue
->hw_status
= DES_STARTED
;
433 des_con
->bytes_processed
-= des_con
->nbytes
;
434 err
= ablkcipher_enqueue_request(&des_queue
->list
, &des_con
->arequest
);
436 printk("Failed to enqueue request, ln: %d, err: %d\n",
438 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
442 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
443 err
= lq_deu_des_core(ctx
, des_con
->dst_buf
, des_con
->src_buf
, iv
, nbytes
, encdec
, mode
);
448 /* \fn static void process_queue(unsigned long data)
449 * \ingroup IFX_DES_FUNCTIONS
450 * \brief Process next packet in queue
451 * \param data not used
455 static void process_queue(unsigned long data
)
457 DEU_WAKEUP_EVENT(deu_dma_priv
.deu_thread_wait
, DES_ASYNC_EVENT
,
458 deu_dma_priv
.des_event_flags
);
462 /* \fn static int des_crypto_thread (void *data)
463 * \ingroup IFX_DES_FUNCTIONS
464 * \brief DES thread that handles crypto requests from upper layer & DMA
465 * \param *data Not used
466 * \return -EINVAL: DEU failure, -EBUSY: DEU HW busy, 0: exit thread
469 static int des_crypto_thread(void *data
)
471 struct des_container
*des_con
= NULL
;
472 struct ablkcipher_request
*areq
= NULL
;
474 unsigned long queue_flag
;
476 daemonize("lq_des_thread");
480 DEU_WAIT_EVENT(deu_dma_priv
.deu_thread_wait
, DES_ASYNC_EVENT
,
481 deu_dma_priv
.des_event_flags
);
482 spin_lock_irqsave(&des_queue
->lock
, queue_flag
);
484 /* wait to prevent starting a crypto session before
485 * exiting the dma interrupt thread.
488 if (des_queue
->hw_status
== DES_STARTED
) {
489 areq
= ablkcipher_dequeue_request(&des_queue
->list
);
490 des_con
= des_container_cast(areq
);
491 des_queue
->hw_status
= DES_BUSY
;
493 else if (des_queue
->hw_status
== DES_IDLE
) {
494 areq
= ablkcipher_dequeue_request(&des_queue
->list
);
495 des_con
= des_container_cast(areq
);
496 des_queue
->hw_status
= DES_STARTED
;
498 else if (des_queue
->hw_status
== DES_BUSY
) {
499 areq
= ablkcipher_dequeue_request(&des_queue
->list
);
500 des_con
= des_container_cast(areq
);
502 else if (des_queue
->hw_status
== DES_COMPLETED
) {
503 areq
->base
.complete(&areq
->base
, 0);
504 lq_sg_complete(des_con
);
505 des_queue
->hw_status
= DES_IDLE
;
506 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
509 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
511 if ((des_con
->bytes_processed
== 0)) {
519 if (des_con
->flag
& PROCESS_NEW_PACKET
) {
520 des_con
->flag
= PROCESS_SCATTER
;
521 err
= process_next_packet(des_con
, areq
, PROCESS_NEW_PACKET
);
524 err
= process_next_packet(des_con
, areq
, PROCESS_SCATTER
);
526 if (err
== -EINVAL
) {
527 areq
->base
.complete(&areq
->base
, err
);
528 lq_sg_complete(des_con
);
529 printk("src/dst returned -EINVAL in func: %s\n", __func__
);
532 printk("src/dst returned zero in func: %s\n", __func__
);
539 //printk("debug line - %d, func: %s, qlen: %d\n", __LINE__, __func__, des_queue->list.qlen);
540 areq
->base
.complete(&areq
->base
, 0);
541 lq_sg_complete(des_con
);
543 spin_lock_irqsave(&des_queue
->lock
, queue_flag
);
544 if (des_queue
->list
.qlen
> 0) {
545 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
546 tasklet_schedule(&des_queue
->des_task
);
549 des_queue
->hw_status
= DES_IDLE
;
550 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
558 /* \fn static int lq_des_queue_mgr(struct des_ctx *ctx, struct ablkcipher_request *areq,
559 u8 *iv, int encdec, int mode)
560 * \ingroup IFX_DES_FUNCTIONS
561 * \brief starts the process of queuing DEU requests
562 * \param *ctx crypto algo contax
563 * \param *areq Pointer to the balkcipher requests
564 * \param *iv Pointer to intput vector location
565 * \param dir Encrypt/Decrypt
566 * \mode The mode DES algo is running
567 * \return 0 if success
570 static int lq_queue_mgr(struct des_ctx
*ctx
, struct ablkcipher_request
*areq
,
571 u8
*iv
, int encdec
, int mode
)
574 unsigned long queue_flag
;
575 struct scatterlist
*src
= areq
->src
;
576 struct scatterlist
*dst
= areq
->dst
;
577 struct des_container
*des_con
= NULL
;
578 u32 remain
, inc
, nbytes
= areq
->nbytes
;
579 u32 chunk_bytes
= src
->length
;
581 des_con
= (struct des_container
*)kmalloc(sizeof(struct des_container
),
585 printk("Cannot allocate memory for AES container, fn %s, ln %d\n",
590 /* DES encrypt/decrypt mode */
592 nbytes
= DES_BLOCK_SIZE
;
593 chunk_bytes
= DES_BLOCK_SIZE
;
597 des_con
->bytes_processed
= nbytes
;
598 des_con
->arequest
= (*areq
);
601 //printk("debug - Line: %d, func: %s, reqsize: %d, scattersize: %d\n",
602 // __LINE__, __func__, nbytes, chunk_bytes);
604 if (remain
> DEU_MAX_PACKET_SIZE
)
605 inc
= DEU_MAX_PACKET_SIZE
;
606 else if(remain
> chunk_bytes
)
612 lq_sg_init(des_con
, src
, dst
);
615 des_con
->complete
= 1;
618 des_con
->complete
= 0;
620 des_con
->nbytes
= inc
;
622 des_con
->mode
= mode
;
623 des_con
->encdec
= encdec
;
625 spin_lock_irqsave(&des_queue
->lock
, queue_flag
);
627 if (des_queue
->hw_status
== DES_STARTED
|| des_queue
->hw_status
== DES_BUSY
||
628 des_queue
->list
.qlen
> 0) {
630 des_con
->flag
= PROCESS_NEW_PACKET
;
631 err
= ablkcipher_enqueue_request(&des_queue
->list
, &des_con
->arequest
);
633 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
634 printk("Fail to enqueue ablkcipher request ln: %d, err: %d\n",
639 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
643 else if (des_queue
->hw_status
== DES_IDLE
) {
644 des_queue
->hw_status
= DES_STARTED
;
647 des_con
->flag
= PROCESS_SCATTER
;
648 des_con
->bytes_processed
-= des_con
->nbytes
;
650 err
= ablkcipher_enqueue_request(&des_queue
->list
, &des_con
->arequest
);
652 printk("Fail to enqueue ablkcipher request ln: %d, err: %d\n",
655 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
659 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
660 return lq_deu_des_core(ctx
, des_con
->dst_buf
, des_con
->src_buf
, iv
, inc
, encdec
, mode
);
664 /* \fn static int lq_des_encrypt(struct ablkcipher_request *areq)
665 * \ingroup IFX_DES_FUNCTIONS
666 * \brief Decrypt function for DES algo
667 * \param *areq Pointer to ablkcipher request in memory
668 * \return 0 is success, -EINPROGRESS if encryting, EINVAL if failure
671 static int lq_des_encrypt(struct ablkcipher_request
*areq
)
673 struct crypto_ablkcipher
*cipher
= crypto_ablkcipher_reqtfm(areq
);
674 struct des_ctx
*ctx
= crypto_ablkcipher_ctx(cipher
);
676 return lq_queue_mgr(ctx
, areq
, NULL
, CRYPTO_DIR_ENCRYPT
, 5);
680 /* \fn static int lq_des_decrypt(struct ablkcipher_request *areq)
681 * \ingroup IFX_DES_FUNCTIONS
682 * \brief Decrypt function for DES algo
683 * \param *areq Pointer to ablkcipher request in memory
684 * \return 0 is success, -EINPROGRESS if encryting, EINVAL if failure
687 static int lq_des_decrypt(struct ablkcipher_request
*areq
)
689 struct crypto_ablkcipher
*cipher
= crypto_ablkcipher_reqtfm(areq
);
690 struct des_ctx
*ctx
= crypto_ablkcipher_ctx(cipher
);
692 return lq_queue_mgr(ctx
, areq
, NULL
, CRYPTO_DIR_DECRYPT
, 5);
695 /* \fn static int lq_ecb_des_encrypt(struct ablkcipher_request *areq)
696 * \ingroup IFX_DES_FUNCTIONS
697 * \brief Decrypt function for DES algo
698 * \param *areq Pointer to ablkcipher request in memory
699 * \return 0 is success, -EINPROGRESS if encryting, EINVAL if failure
702 static int lq_ecb_des_encrypt(struct ablkcipher_request
*areq
)
704 struct crypto_ablkcipher
*cipher
= crypto_ablkcipher_reqtfm(areq
);
705 struct des_ctx
*ctx
= crypto_ablkcipher_ctx(cipher
);
707 return lq_queue_mgr(ctx
, areq
, areq
->info
, CRYPTO_DIR_ENCRYPT
, 0);
710 /* \fn static int lq_ecb_des_decrypt(struct ablkcipher_request *areq)
711 * \ingroup IFX_DES_FUNCTIONS
712 * \brief Decrypt function for DES algo
713 * \param *areq Pointer to ablkcipher request in memory
714 * \return 0 is success, -EINPROGRESS if encryting, EINVAL if failure
716 static int lq_ecb_des_decrypt(struct ablkcipher_request
*areq
)
718 struct crypto_ablkcipher
*cipher
= crypto_ablkcipher_reqtfm(areq
);
719 struct des_ctx
*ctx
= crypto_ablkcipher_ctx(cipher
);
721 return lq_queue_mgr(ctx
, areq
, areq
->info
, CRYPTO_DIR_DECRYPT
, 0);
725 /* \fn static int lq_cbc_ecb_des_encrypt(struct ablkcipher_request *areq)
726 * \ingroup IFX_DES_FUNCTIONS
727 * \brief Decrypt function for DES algo
728 * \param *areq Pointer to ablkcipher request in memory
729 * \return 0 is success, -EINPROGRESS if encryting, EINVAL if failure
732 static int lq_cbc_des_encrypt(struct ablkcipher_request
*areq
)
734 struct crypto_ablkcipher
*cipher
= crypto_ablkcipher_reqtfm(areq
);
735 struct des_ctx
*ctx
= crypto_ablkcipher_ctx(cipher
);
737 return lq_queue_mgr(ctx
, areq
, areq
->info
, CRYPTO_DIR_ENCRYPT
, 1);
739 /* \fn static int lq_cbc_des_decrypt(struct ablkcipher_request *areq)
740 * \ingroup IFX_DES_FUNCTIONS
741 * \brief Decrypt function for DES algo
742 * \param *areq Pointer to ablkcipher request in memory
743 * \return 0 is success, -EINPROGRESS if encryting, EINVAL if failure
746 static int lq_cbc_des_decrypt(struct ablkcipher_request
*areq
)
748 struct crypto_ablkcipher
*cipher
= crypto_ablkcipher_reqtfm(areq
);
749 struct des_ctx
*ctx
= crypto_ablkcipher_ctx(cipher
);
751 return lq_queue_mgr(ctx
, areq
, areq
->info
, CRYPTO_DIR_DECRYPT
, 1);
755 struct crypto_alg alg
;
758 /* DES Supported algo array */
759 static struct lq_des_alg des_drivers_alg
[] = {
763 .cra_driver_name
= "lqdeu-des",
764 .cra_flags
= CRYPTO_ALG_TYPE_ABLKCIPHER
| CRYPTO_ALG_KERN_DRIVER_ONLY
| CRYPTO_ALG_ASYNC
,
765 .cra_blocksize
= DES_BLOCK_SIZE
,
766 .cra_ctxsize
= sizeof(struct des_ctx
),
767 .cra_type
= &crypto_ablkcipher_type
,
769 .cra_module
= THIS_MODULE
,
771 .setkey
= lq_des_setkey
,
772 .encrypt
= lq_des_encrypt
,
773 .decrypt
= lq_des_decrypt
,
775 .min_keysize
= DES_KEY_SIZE
,
776 .max_keysize
= DES_KEY_SIZE
,
777 .ivsize
= DES_BLOCK_SIZE
,
783 .cra_name
= "ecb(des)",
784 .cra_driver_name
= "lqdeu-ecb(des)",
785 .cra_flags
= CRYPTO_ALG_TYPE_ABLKCIPHER
| CRYPTO_ALG_KERN_DRIVER_ONLY
| CRYPTO_ALG_ASYNC
,
786 .cra_blocksize
= DES_BLOCK_SIZE
,
787 .cra_ctxsize
= sizeof(struct des_ctx
),
788 .cra_type
= &crypto_ablkcipher_type
,
790 .cra_module
= THIS_MODULE
,
792 .setkey
= lq_des_setkey
,
793 .encrypt
= lq_ecb_des_encrypt
,
794 .decrypt
= lq_ecb_des_decrypt
,
796 .min_keysize
= DES_KEY_SIZE
,
797 .max_keysize
= DES_KEY_SIZE
,
798 .ivsize
= DES_BLOCK_SIZE
,
803 .cra_name
= "cbc(des)",
804 .cra_driver_name
= "lqdeu-cbc(des)",
805 .cra_flags
= CRYPTO_ALG_TYPE_ABLKCIPHER
| CRYPTO_ALG_KERN_DRIVER_ONLY
| CRYPTO_ALG_ASYNC
,
806 .cra_blocksize
= DES_BLOCK_SIZE
,
807 .cra_ctxsize
= sizeof(struct des_ctx
),
808 .cra_type
= &crypto_ablkcipher_type
,
810 .cra_module
= THIS_MODULE
,
812 .setkey
= lq_des_setkey
,
813 .encrypt
= lq_cbc_des_encrypt
,
814 .decrypt
= lq_cbc_des_decrypt
,
816 .min_keysize
= DES3_EDE_KEY_SIZE
,
817 .max_keysize
= DES3_EDE_KEY_SIZE
,
818 .ivsize
= DES3_EDE_BLOCK_SIZE
,
823 .cra_name
= "des3_ede",
824 .cra_driver_name
= "lqdeu-des3_ede",
825 .cra_flags
= CRYPTO_ALG_TYPE_ABLKCIPHER
| CRYPTO_ALG_KERN_DRIVER_ONLY
| CRYPTO_ALG_ASYNC
,
826 .cra_blocksize
= DES_BLOCK_SIZE
,
827 .cra_ctxsize
= sizeof(struct des_ctx
),
828 .cra_type
= &crypto_ablkcipher_type
,
830 .cra_module
= THIS_MODULE
,
832 .setkey
= lq_des3_ede_setkey
,
833 .encrypt
= lq_des_encrypt
,
834 .decrypt
= lq_des_decrypt
,
836 .min_keysize
= DES_KEY_SIZE
,
837 .max_keysize
= DES_KEY_SIZE
,
838 .ivsize
= DES_BLOCK_SIZE
,
843 .cra_name
= "ecb(des3_ede)",
844 .cra_driver_name
= "lqdeu-ecb(des3_ede)",
845 .cra_flags
= CRYPTO_ALG_TYPE_ABLKCIPHER
| CRYPTO_ALG_KERN_DRIVER_ONLY
| CRYPTO_ALG_ASYNC
,
846 .cra_blocksize
= DES_BLOCK_SIZE
,
847 .cra_ctxsize
= sizeof(struct des_ctx
),
848 .cra_type
= &crypto_ablkcipher_type
,
850 .cra_module
= THIS_MODULE
,
852 .setkey
= lq_des3_ede_setkey
,
853 .encrypt
= lq_ecb_des_encrypt
,
854 .decrypt
= lq_ecb_des_decrypt
,
856 .min_keysize
= DES3_EDE_KEY_SIZE
,
857 .max_keysize
= DES3_EDE_KEY_SIZE
,
858 .ivsize
= DES3_EDE_BLOCK_SIZE
,
863 .cra_name
= "cbc(des3_ede)",
864 .cra_driver_name
= "lqdeu-cbc(des3_ede)",
865 .cra_flags
= CRYPTO_ALG_TYPE_ABLKCIPHER
| CRYPTO_ALG_KERN_DRIVER_ONLY
| CRYPTO_ALG_ASYNC
,
866 .cra_blocksize
= DES_BLOCK_SIZE
,
867 .cra_ctxsize
= sizeof(struct des_ctx
),
868 .cra_type
= &crypto_ablkcipher_type
,
870 .cra_module
= THIS_MODULE
,
872 .setkey
= lq_des3_ede_setkey
,
873 .encrypt
= lq_cbc_des_encrypt
,
874 .decrypt
= lq_cbc_des_decrypt
,
876 .min_keysize
= DES3_EDE_KEY_SIZE
,
877 .max_keysize
= DES3_EDE_KEY_SIZE
,
878 .ivsize
= DES3_EDE_BLOCK_SIZE
,
884 /*! \fn int __init lqdeu_async_des_init (void)
885 * \ingroup IFX_DES_FUNCTIONS
886 * \brief initialize des driver
888 int __init
lqdeu_async_des_init (void)
890 int i
, j
, ret
= -EINVAL
;
892 for (i
= 0; i
< ARRAY_SIZE(des_drivers_alg
); i
++) {
893 ret
= crypto_register_alg(&des_drivers_alg
[i
].alg
);
894 //printk("driver: %s\n", des_drivers_alg[i].alg.cra_name);
903 printk (KERN_NOTICE
"IFX DEU DES initialized%s%s.\n", disable_multiblock
? "" : " (multiblock)", disable_deudma
? "" : " (DMA)");
907 for (j
= 0; j
< i
; j
++)
908 crypto_unregister_alg(&des_drivers_alg
[i
].alg
);
910 printk(KERN_ERR
"Lantiq %s driver initialization failed!\n", (char *)&des_drivers_alg
[i
].alg
.cra_driver_name
);
914 for (i
= 0; i
< ARRAY_SIZE(des_drivers_alg
); i
++) {
915 if (!strcmp((char *)&des_drivers_alg
[i
].alg
.cra_name
, "cbc(des3_ede)"))
916 crypto_unregister_alg(&des_drivers_alg
[i
].alg
);
919 printk(KERN_ERR
"Lantiq %s driver initialization failed!\n", (char *)&des_drivers_alg
[i
].alg
.cra_driver_name
);
923 /*! \fn void __exit lqdeu_fini_async_des (void)
924 * \ingroup IFX_DES_FUNCTIONS
925 * \brief unregister des driver
927 void __exit
lqdeu_fini_async_des (void)
931 for (i
= 0; i
< ARRAY_SIZE(des_drivers_alg
); i
++)
932 crypto_unregister_alg(&des_drivers_alg
[i
].alg
);
934 des_queue
->hw_status
= DES_COMPLETED
;
935 DEU_WAKEUP_EVENT(deu_dma_priv
.deu_thread_wait
, DES_ASYNC_EVENT
,
936 deu_dma_priv
.des_event_flags
);