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 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
121 module_param(disable_multiblock
, int, 0);
123 MODULE_PARM_DESC(disable_multiblock
, "Disable encryption of whole multiblock buffers");
126 static int disable_deudma
= 1;
128 struct des_container
{
140 struct ablkcipher_request arequest
;
143 des_priv_t
*des_queue
;
144 extern deu_drv_priv_t deu_dma_priv
;
146 void hexdump1(unsigned char *buf
, unsigned int len
)
148 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
154 /*! \fn int lq_des_setkey(struct crypto_ablkcipher *tfm, const u8 *key, unsigned int keylen)
155 * \ingroup IFX_DES_FUNCTIONS
156 * \brief sets DES key
157 * \param tfm linux crypto algo transform
158 * \param key input key
159 * \param keylen key length
161 static int lq_des_setkey(struct crypto_ablkcipher
*tfm
, const u8
*key
,
164 struct des_ctx
*dctx
= crypto_ablkcipher_ctx(tfm
);
166 //printk("setkey in %s\n", __FILE__);
168 dctx
->controlr_M
= 0; // des
169 dctx
->key_length
= keylen
;
171 memcpy ((u8
*) (dctx
->expkey
), key
, keylen
);
176 /*! \fn int lq_des3_ede_setkey(struct crypto_ablkcipher *tfm, const u8 *key, unsigned int keylen)
177 * \ingroup IFX_DES_FUNCTIONS
178 * \brief sets DES key
179 * \param tfm linux crypto algo transform
180 * \param key input key
181 * \param keylen key length
184 static int lq_des3_ede_setkey(struct crypto_ablkcipher
*tfm
, const u8
*in_key
,
187 struct des_ctx
*dctx
= crypto_ablkcipher_ctx(tfm
);
189 //printk("setkey in %s\n", __FILE__);
191 dctx
->controlr_M
= keylen
/8 + 1; // des
192 dctx
->key_length
= keylen
;
194 memcpy ((u8
*) (dctx
->expkey
), in_key
, keylen
);
199 /*! \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)
200 * \ingroup IFX_DES_FUNCTIONS
201 * \brief main interface to DES hardware
202 * \param ctx_arg crypto algo context
203 * \param out_arg output bytestream
204 * \param in_arg input bytestream
205 * \param iv_arg initialization vector
206 * \param nbytes length of bytestream
207 * \param encdec 1 for encrypt; 0 for decrypt
208 * \param mode operation mode such as ebc, cbc
211 static int lq_deu_des_core (void *ctx_arg
, u8
*out_arg
, const u8
*in_arg
,
212 u8
*iv_arg
, u32 nbytes
, int encdec
, int mode
)
214 volatile struct des_t
*des
= (struct des_t
*) DES_3DES_START
;
215 struct des_ctx
*dctx
= ctx_arg
;
216 u32
*key
= dctx
->expkey
;
224 des
->controlr
.M
= dctx
->controlr_M
;
225 if (dctx
->controlr_M
== 0) // des
227 des
->K1HR
= DEU_ENDIAN_SWAP(*((u32
*) key
+ 0));
228 des
->K1LR
= DEU_ENDIAN_SWAP(*((u32
*) key
+ 1));
232 /* Hardware Section */
233 switch (dctx
->key_length
) {
235 des
->K3HR
= DEU_ENDIAN_SWAP(*((u32
*) key
+ 4));
236 des
->K3LR
= DEU_ENDIAN_SWAP(*((u32
*) key
+ 5));
240 des
->K2HR
= DEU_ENDIAN_SWAP(*((u32
*) key
+ 2));
241 des
->K2LR
= DEU_ENDIAN_SWAP(*((u32
*) key
+ 3));
245 des
->K1HR
= DEU_ENDIAN_SWAP(*((u32
*) key
+ 0));
246 des
->K1LR
= DEU_ENDIAN_SWAP(*((u32
*) key
+ 1));
255 des
->controlr
.E_D
= !encdec
; //encryption
256 des
->controlr
.O
= mode
; //0 ECB 1 CBC 2 OFB 3 CFB 4 CTR hexdump(prin,sizeof(*des));
259 des
->IVHR
= DEU_ENDIAN_SWAP(*(u32
*) iv_arg
);
260 des
->IVLR
= DEU_ENDIAN_SWAP(*((u32
*) iv_arg
+ 1));
263 /* memory alignment issue */
264 dword_mem_aligned_in
= (u32
*) DEU_DWORD_REORDERING(in_arg
, des_buff_in
, BUFFER_IN
, nbytes
);
266 deu_priv
->deu_rx_buf
= (u32
*) out_arg
;
267 deu_priv
->deu_rx_len
= nbytes
;
269 dma
->controlr
.ALGO
= 0; //DES
270 des
->controlr
.DAU
= 0;
271 dma
->controlr
.BS
= 0;
272 dma
->controlr
.EN
= 1;
274 while (des
->controlr
.BUS
) {
277 wlen
= dma_device_write (dma_device
, (u8
*) dword_mem_aligned_in
, nbytes
, NULL
);
278 if (wlen
!= nbytes
) {
279 dma
->controlr
.EN
= 0;
281 printk (KERN_ERR
"[%s %s %d]: dma_device_write fail!\n", __FILE__
, __func__
, __LINE__
);
286 /* Prepare Rx buf length used in dma psuedo interrupt */
287 outcopy
= (u32
*) DEU_DWORD_REORDERING(out_arg
, des_buff_out
, BUFFER_OUT
, nbytes
);
288 deu_priv
->outcopy
= outcopy
;
289 deu_priv
->event_src
= DES_ASYNC_EVENT
;
292 *(u32
*) iv_arg
= DEU_ENDIAN_SWAP(des
->IVHR
);
293 *((u32
*) iv_arg
+ 1) = DEU_ENDIAN_SWAP(des
->IVLR
);
302 static int count_sgs(struct scatterlist
*sl
, unsigned int total_bytes
)
307 total_bytes
-= sl
[i
].length
;
310 } while (total_bytes
> 0);
315 /* \fn static inline struct des_container *des_container_cast (
316 * struct scatterlist *dst)
317 * \ingroup IFX_DES_FUNCTIONS
318 * \brief Locate the structure des_container in memory.
319 * \param *areq Pointer to memory location where ablkcipher_request is located
320 * \return *des_cointainer The function pointer to des_container
323 static inline struct des_container
*des_container_cast(
324 struct ablkcipher_request
*areq
)
326 return container_of(areq
, struct des_container
, arequest
);
329 /* \fn static void lq_sg_complete(struct des_container *des_con)
330 * \ingroup IFX_DES_FUNCTIONS
331 * \brief Free the used up memory after encryt/decrypt.
334 static void lq_sg_complete(struct des_container
*des_con
)
336 unsigned long queue_flag
;
338 spin_lock_irqsave(&des_queue
->lock
, queue_flag
);
340 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
343 /* \fn void lq_sg_init(struct scatterlist *src,
344 * struct scatterlist *dst)
345 * \ingroup IFX_DES_FUNCTIONS
346 * \brief Maps the scatterlists into a source/destination page.
347 * \param *src Pointer to the source scatterlist
348 * \param *dst Pointer to the destination scatterlist
351 static void lq_sg_init(struct des_container
*des_con
, struct scatterlist
*src
,
352 struct scatterlist
*dst
)
354 struct page
*dst_page
, *src_page
;
356 src_page
= sg_virt(src
);
357 des_con
->src_buf
= (char *) src_page
;
359 dst_page
= sg_virt(dst
);
360 des_con
->dst_buf
= (char *) dst_page
;
363 /* \fn static int process_next_packet(struct des_container *des_con, struct ablkcipher_request *areq,
365 * \ingroup IFX_DES_FUNCTIONS
366 * \brief Process the next packet after dequeuing the packet from crypto queue
367 * \param *des_con Pointer to DES container structure
368 * \param *areq Pointer to ablkcipher_request container
369 * \param state State of the packet (scattered packet or new packet to be processed)
370 * \return -EINVAL: DEU failure, -EINPROGRESS: DEU encrypt/decrypt in progress, 1: no scatterlist left
373 static int process_next_packet(struct des_container
*des_con
, struct ablkcipher_request
*areq
,
377 int mode
, encdec
, err
= -EINVAL
;
378 u32 remain
, inc
, chunk_size
, nbytes
;
379 struct scatterlist
*src
= NULL
;
380 struct scatterlist
*dst
= NULL
;
381 struct crypto_ablkcipher
*cipher
;
383 unsigned long queue_flag
;
385 spin_lock_irqsave(&des_queue
->lock
, queue_flag
);
387 mode
= des_con
->mode
;
388 encdec
= des_con
->encdec
;
391 if (state
& PROCESS_SCATTER
) {
392 src
= scatterwalk_sg_next(areq
->src
);
393 dst
= scatterwalk_sg_next(areq
->dst
);
396 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
400 else if (state
& PROCESS_NEW_PACKET
) {
405 remain
= des_con
->bytes_processed
;
406 chunk_size
= src
->length
;
408 //printk("debug ln: %d, func: %s, reqsize: %d, scattersize: %d\n",
409 // __LINE__, __func__, areq->nbytes, chunk_size);
411 if (remain
> DEU_MAX_PACKET_SIZE
)
412 inc
= DEU_MAX_PACKET_SIZE
;
413 else if(remain
> chunk_size
)
419 des_con
->nbytes
= inc
;
421 if (state
& PROCESS_SCATTER
) {
422 des_con
->src_buf
+= des_con
->nbytes
;
423 des_con
->dst_buf
+= des_con
->nbytes
;
426 lq_sg_init(des_con
, src
, dst
);
428 nbytes
= des_con
->nbytes
;
430 cipher
= crypto_ablkcipher_reqtfm(areq
);
431 ctx
= crypto_ablkcipher_ctx(cipher
);
433 if (des_queue
->hw_status
== DES_IDLE
) {
434 des_queue
->hw_status
= DES_STARTED
;
437 des_con
->bytes_processed
-= des_con
->nbytes
;
438 err
= ablkcipher_enqueue_request(&des_queue
->list
, &des_con
->arequest
);
440 printk("Failed to enqueue request, ln: %d, err: %d\n",
442 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
446 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
447 err
= lq_deu_des_core(ctx
, des_con
->dst_buf
, des_con
->src_buf
, iv
, nbytes
, encdec
, mode
);
452 /* \fn static void process_queue(unsigned long data)
453 * \ingroup IFX_DES_FUNCTIONS
454 * \brief Process next packet in queue
455 * \param data not used
459 static void process_queue(unsigned long data
)
461 DEU_WAKEUP_EVENT(deu_dma_priv
.deu_thread_wait
, DES_ASYNC_EVENT
,
462 deu_dma_priv
.des_event_flags
);
466 /* \fn static int des_crypto_thread (void *data)
467 * \ingroup IFX_DES_FUNCTIONS
468 * \brief DES thread that handles crypto requests from upper layer & DMA
469 * \param *data Not used
470 * \return -EINVAL: DEU failure, -EBUSY: DEU HW busy, 0: exit thread
473 static int des_crypto_thread(void *data
)
475 struct des_container
*des_con
= NULL
;
476 struct ablkcipher_request
*areq
= NULL
;
478 unsigned long queue_flag
;
480 daemonize("lq_des_thread");
484 DEU_WAIT_EVENT(deu_dma_priv
.deu_thread_wait
, DES_ASYNC_EVENT
,
485 deu_dma_priv
.des_event_flags
);
486 spin_lock_irqsave(&des_queue
->lock
, queue_flag
);
488 /* wait to prevent starting a crypto session before
489 * exiting the dma interrupt thread.
492 if (des_queue
->hw_status
== DES_STARTED
) {
493 areq
= ablkcipher_dequeue_request(&des_queue
->list
);
494 des_con
= des_container_cast(areq
);
495 des_queue
->hw_status
= DES_BUSY
;
497 else if (des_queue
->hw_status
== DES_IDLE
) {
498 areq
= ablkcipher_dequeue_request(&des_queue
->list
);
499 des_con
= des_container_cast(areq
);
500 des_queue
->hw_status
= DES_STARTED
;
502 else if (des_queue
->hw_status
== DES_BUSY
) {
503 areq
= ablkcipher_dequeue_request(&des_queue
->list
);
504 des_con
= des_container_cast(areq
);
506 else if (des_queue
->hw_status
== DES_COMPLETED
) {
507 areq
->base
.complete(&areq
->base
, 0);
508 lq_sg_complete(des_con
);
509 des_queue
->hw_status
= DES_IDLE
;
510 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
513 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
515 if ((des_con
->bytes_processed
== 0)) {
523 if (des_con
->flag
& PROCESS_NEW_PACKET
) {
524 des_con
->flag
= PROCESS_SCATTER
;
525 err
= process_next_packet(des_con
, areq
, PROCESS_NEW_PACKET
);
528 err
= process_next_packet(des_con
, areq
, PROCESS_SCATTER
);
530 if (err
== -EINVAL
) {
531 areq
->base
.complete(&areq
->base
, err
);
532 lq_sg_complete(des_con
);
533 printk("src/dst returned -EINVAL in func: %s\n", __func__
);
536 printk("src/dst returned zero in func: %s\n", __func__
);
543 //printk("debug line - %d, func: %s, qlen: %d\n", __LINE__, __func__, des_queue->list.qlen);
544 areq
->base
.complete(&areq
->base
, 0);
545 lq_sg_complete(des_con
);
547 spin_lock_irqsave(&des_queue
->lock
, queue_flag
);
548 if (des_queue
->list
.qlen
> 0) {
549 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
550 tasklet_schedule(&des_queue
->des_task
);
553 des_queue
->hw_status
= DES_IDLE
;
554 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
562 /* \fn static int lq_des_queue_mgr(struct des_ctx *ctx, struct ablkcipher_request *areq,
563 u8 *iv, int encdec, int mode)
564 * \ingroup IFX_DES_FUNCTIONS
565 * \brief starts the process of queuing DEU requests
566 * \param *ctx crypto algo contax
567 * \param *areq Pointer to the balkcipher requests
568 * \param *iv Pointer to intput vector location
569 * \param dir Encrypt/Decrypt
570 * \mode The mode DES algo is running
571 * \return 0 if success
574 static int lq_queue_mgr(struct des_ctx
*ctx
, struct ablkcipher_request
*areq
,
575 u8
*iv
, int encdec
, int mode
)
578 unsigned long queue_flag
;
579 struct scatterlist
*src
= areq
->src
;
580 struct scatterlist
*dst
= areq
->dst
;
581 struct des_container
*des_con
= NULL
;
582 u32 remain
, inc
, nbytes
= areq
->nbytes
;
583 u32 chunk_bytes
= src
->length
;
585 des_con
= (struct des_container
*)kmalloc(sizeof(struct des_container
),
589 printk("Cannot allocate memory for AES container, fn %s, ln %d\n",
594 /* DES encrypt/decrypt mode */
596 nbytes
= DES_BLOCK_SIZE
;
597 chunk_bytes
= DES_BLOCK_SIZE
;
601 des_con
->bytes_processed
= nbytes
;
602 des_con
->arequest
= (*areq
);
605 //printk("debug - Line: %d, func: %s, reqsize: %d, scattersize: %d\n",
606 // __LINE__, __func__, nbytes, chunk_bytes);
608 if (remain
> DEU_MAX_PACKET_SIZE
)
609 inc
= DEU_MAX_PACKET_SIZE
;
610 else if(remain
> chunk_bytes
)
616 lq_sg_init(des_con
, src
, dst
);
619 des_con
->complete
= 1;
622 des_con
->complete
= 0;
624 des_con
->nbytes
= inc
;
626 des_con
->mode
= mode
;
627 des_con
->encdec
= encdec
;
629 spin_lock_irqsave(&des_queue
->lock
, queue_flag
);
631 if (des_queue
->hw_status
== DES_STARTED
|| des_queue
->hw_status
== DES_BUSY
||
632 des_queue
->list
.qlen
> 0) {
634 des_con
->flag
= PROCESS_NEW_PACKET
;
635 err
= ablkcipher_enqueue_request(&des_queue
->list
, &des_con
->arequest
);
637 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
638 printk("Fail to enqueue ablkcipher request ln: %d, err: %d\n",
643 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
647 else if (des_queue
->hw_status
== DES_IDLE
) {
648 des_queue
->hw_status
= DES_STARTED
;
651 des_con
->flag
= PROCESS_SCATTER
;
652 des_con
->bytes_processed
-= des_con
->nbytes
;
654 err
= ablkcipher_enqueue_request(&des_queue
->list
, &des_con
->arequest
);
656 printk("Fail to enqueue ablkcipher request ln: %d, err: %d\n",
659 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
663 spin_unlock_irqrestore(&des_queue
->lock
, queue_flag
);
664 return lq_deu_des_core(ctx
, des_con
->dst_buf
, des_con
->src_buf
, iv
, inc
, encdec
, mode
);
668 /* \fn static int lq_des_encrypt(struct ablkcipher_request *areq)
669 * \ingroup IFX_DES_FUNCTIONS
670 * \brief Decrypt function for DES algo
671 * \param *areq Pointer to ablkcipher request in memory
672 * \return 0 is success, -EINPROGRESS if encryting, EINVAL if failure
675 static int lq_des_encrypt(struct ablkcipher_request
*areq
)
677 struct crypto_ablkcipher
*cipher
= crypto_ablkcipher_reqtfm(areq
);
678 struct des_ctx
*ctx
= crypto_ablkcipher_ctx(cipher
);
680 return lq_queue_mgr(ctx
, areq
, NULL
, CRYPTO_DIR_ENCRYPT
, 5);
684 /* \fn static int lq_des_decrypt(struct ablkcipher_request *areq)
685 * \ingroup IFX_DES_FUNCTIONS
686 * \brief Decrypt function for DES algo
687 * \param *areq Pointer to ablkcipher request in memory
688 * \return 0 is success, -EINPROGRESS if encryting, EINVAL if failure
691 static int lq_des_decrypt(struct ablkcipher_request
*areq
)
693 struct crypto_ablkcipher
*cipher
= crypto_ablkcipher_reqtfm(areq
);
694 struct des_ctx
*ctx
= crypto_ablkcipher_ctx(cipher
);
696 return lq_queue_mgr(ctx
, areq
, NULL
, CRYPTO_DIR_DECRYPT
, 5);
699 /* \fn static int lq_ecb_des_encrypt(struct ablkcipher_request *areq)
700 * \ingroup IFX_DES_FUNCTIONS
701 * \brief Decrypt function for DES algo
702 * \param *areq Pointer to ablkcipher request in memory
703 * \return 0 is success, -EINPROGRESS if encryting, EINVAL if failure
706 static int lq_ecb_des_encrypt(struct ablkcipher_request
*areq
)
708 struct crypto_ablkcipher
*cipher
= crypto_ablkcipher_reqtfm(areq
);
709 struct des_ctx
*ctx
= crypto_ablkcipher_ctx(cipher
);
711 return lq_queue_mgr(ctx
, areq
, areq
->info
, CRYPTO_DIR_ENCRYPT
, 0);
714 /* \fn static int lq_ecb_des_decrypt(struct ablkcipher_request *areq)
715 * \ingroup IFX_DES_FUNCTIONS
716 * \brief Decrypt function for DES algo
717 * \param *areq Pointer to ablkcipher request in memory
718 * \return 0 is success, -EINPROGRESS if encryting, EINVAL if failure
720 static int lq_ecb_des_decrypt(struct ablkcipher_request
*areq
)
722 struct crypto_ablkcipher
*cipher
= crypto_ablkcipher_reqtfm(areq
);
723 struct des_ctx
*ctx
= crypto_ablkcipher_ctx(cipher
);
725 return lq_queue_mgr(ctx
, areq
, areq
->info
, CRYPTO_DIR_DECRYPT
, 0);
729 /* \fn static int lq_cbc_ecb_des_encrypt(struct ablkcipher_request *areq)
730 * \ingroup IFX_DES_FUNCTIONS
731 * \brief Decrypt function for DES algo
732 * \param *areq Pointer to ablkcipher request in memory
733 * \return 0 is success, -EINPROGRESS if encryting, EINVAL if failure
736 static int lq_cbc_des_encrypt(struct ablkcipher_request
*areq
)
738 struct crypto_ablkcipher
*cipher
= crypto_ablkcipher_reqtfm(areq
);
739 struct des_ctx
*ctx
= crypto_ablkcipher_ctx(cipher
);
741 return lq_queue_mgr(ctx
, areq
, areq
->info
, CRYPTO_DIR_ENCRYPT
, 1);
743 /* \fn static int lq_cbc_des_decrypt(struct ablkcipher_request *areq)
744 * \ingroup IFX_DES_FUNCTIONS
745 * \brief Decrypt function for DES algo
746 * \param *areq Pointer to ablkcipher request in memory
747 * \return 0 is success, -EINPROGRESS if encryting, EINVAL if failure
750 static int lq_cbc_des_decrypt(struct ablkcipher_request
*areq
)
752 struct crypto_ablkcipher
*cipher
= crypto_ablkcipher_reqtfm(areq
);
753 struct des_ctx
*ctx
= crypto_ablkcipher_ctx(cipher
);
755 return lq_queue_mgr(ctx
, areq
, areq
->info
, CRYPTO_DIR_DECRYPT
, 1);
759 struct crypto_alg alg
;
762 /* DES Supported algo array */
763 static struct lq_des_alg des_drivers_alg
[] = {
767 .cra_driver_name
= "lqdeu-des",
768 .cra_flags
= CRYPTO_ALG_TYPE_ABLKCIPHER
| CRYPTO_ALG_ASYNC
,
769 .cra_blocksize
= DES_BLOCK_SIZE
,
770 .cra_ctxsize
= sizeof(struct des_ctx
),
771 .cra_type
= &crypto_ablkcipher_type
,
773 .cra_module
= THIS_MODULE
,
775 .setkey
= lq_des_setkey
,
776 .encrypt
= lq_des_encrypt
,
777 .decrypt
= lq_des_decrypt
,
779 .min_keysize
= DES_KEY_SIZE
,
780 .max_keysize
= DES_KEY_SIZE
,
781 .ivsize
= DES_BLOCK_SIZE
,
787 .cra_name
= "ecb(des)",
788 .cra_driver_name
= "lqdeu-ecb(des)",
789 .cra_flags
= CRYPTO_ALG_TYPE_ABLKCIPHER
| CRYPTO_ALG_ASYNC
,
790 .cra_blocksize
= DES_BLOCK_SIZE
,
791 .cra_ctxsize
= sizeof(struct des_ctx
),
792 .cra_type
= &crypto_ablkcipher_type
,
794 .cra_module
= THIS_MODULE
,
796 .setkey
= lq_des_setkey
,
797 .encrypt
= lq_ecb_des_encrypt
,
798 .decrypt
= lq_ecb_des_decrypt
,
800 .min_keysize
= DES_KEY_SIZE
,
801 .max_keysize
= DES_KEY_SIZE
,
802 .ivsize
= DES_BLOCK_SIZE
,
807 .cra_name
= "cbc(des)",
808 .cra_driver_name
= "lqdeu-cbc(des)",
809 .cra_flags
= CRYPTO_ALG_TYPE_ABLKCIPHER
| CRYPTO_ALG_ASYNC
,
810 .cra_blocksize
= DES_BLOCK_SIZE
,
811 .cra_ctxsize
= sizeof(struct des_ctx
),
812 .cra_type
= &crypto_ablkcipher_type
,
814 .cra_module
= THIS_MODULE
,
816 .setkey
= lq_des_setkey
,
817 .encrypt
= lq_cbc_des_encrypt
,
818 .decrypt
= lq_cbc_des_decrypt
,
820 .min_keysize
= DES3_EDE_KEY_SIZE
,
821 .max_keysize
= DES3_EDE_KEY_SIZE
,
822 .ivsize
= DES3_EDE_BLOCK_SIZE
,
827 .cra_name
= "des3_ede",
828 .cra_driver_name
= "lqdeu-des3_ede",
829 .cra_flags
= CRYPTO_ALG_TYPE_ABLKCIPHER
| CRYPTO_ALG_ASYNC
,
830 .cra_blocksize
= DES_BLOCK_SIZE
,
831 .cra_ctxsize
= sizeof(struct des_ctx
),
832 .cra_type
= &crypto_ablkcipher_type
,
834 .cra_module
= THIS_MODULE
,
836 .setkey
= lq_des3_ede_setkey
,
837 .encrypt
= lq_des_encrypt
,
838 .decrypt
= lq_des_decrypt
,
840 .min_keysize
= DES_KEY_SIZE
,
841 .max_keysize
= DES_KEY_SIZE
,
842 .ivsize
= DES_BLOCK_SIZE
,
847 .cra_name
= "ecb(des3_ede)",
848 .cra_driver_name
= "lqdeu-ecb(des3_ede)",
849 .cra_flags
= CRYPTO_ALG_TYPE_ABLKCIPHER
| CRYPTO_ALG_ASYNC
,
850 .cra_blocksize
= DES_BLOCK_SIZE
,
851 .cra_ctxsize
= sizeof(struct des_ctx
),
852 .cra_type
= &crypto_ablkcipher_type
,
854 .cra_module
= THIS_MODULE
,
856 .setkey
= lq_des3_ede_setkey
,
857 .encrypt
= lq_ecb_des_encrypt
,
858 .decrypt
= lq_ecb_des_decrypt
,
860 .min_keysize
= DES3_EDE_KEY_SIZE
,
861 .max_keysize
= DES3_EDE_KEY_SIZE
,
862 .ivsize
= DES3_EDE_BLOCK_SIZE
,
867 .cra_name
= "cbc(des3_ede)",
868 .cra_driver_name
= "lqdeu-cbc(des3_ede)",
869 .cra_flags
= CRYPTO_ALG_TYPE_ABLKCIPHER
| CRYPTO_ALG_ASYNC
,
870 .cra_blocksize
= DES_BLOCK_SIZE
,
871 .cra_ctxsize
= sizeof(struct des_ctx
),
872 .cra_type
= &crypto_ablkcipher_type
,
874 .cra_module
= THIS_MODULE
,
876 .setkey
= lq_des3_ede_setkey
,
877 .encrypt
= lq_cbc_des_encrypt
,
878 .decrypt
= lq_cbc_des_decrypt
,
880 .min_keysize
= DES3_EDE_KEY_SIZE
,
881 .max_keysize
= DES3_EDE_KEY_SIZE
,
882 .ivsize
= DES3_EDE_BLOCK_SIZE
,
888 /*! \fn int __init lqdeu_async_des_init (void)
889 * \ingroup IFX_DES_FUNCTIONS
890 * \brief initialize des driver
892 int __init
lqdeu_async_des_init (void)
894 int i
, j
, ret
= -EINVAL
;
896 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20))
897 if (!disable_multiblock
) {
898 ifxdeu_des_alg
.cra_u
.cipher
.cia_max_nbytes
= DES_BLOCK_SIZE
; //(size_t)-1;
899 ifxdeu_des_alg
.cra_u
.cipher
.cia_req_align
= 16;
900 ifxdeu_des_alg
.cra_u
.cipher
.cia_ecb
= ifx_deu_des_ecb
;
901 ifxdeu_des_alg
.cra_u
.cipher
.cia_cbc
= ifx_deu_des_cbc
;
902 ifxdeu_des_alg
.cra_u
.cipher
.cia_cfb
= ifx_deu_des_cfb
;
903 ifxdeu_des_alg
.cra_u
.cipher
.cia_ofb
= ifx_deu_des_ofb
;
906 for (i
= 0; i
< ARRAY_SIZE(des_drivers_alg
); i
++) {
907 ret
= crypto_register_alg(&des_drivers_alg
[i
].alg
);
908 //printk("driver: %s\n", des_drivers_alg[i].alg.cra_name);
917 printk (KERN_NOTICE
"IFX DEU DES initialized%s%s.\n", disable_multiblock
? "" : " (multiblock)", disable_deudma
? "" : " (DMA)");
921 for (j
= 0; j
< i
; j
++)
922 crypto_unregister_alg(&des_drivers_alg
[i
].alg
);
924 printk(KERN_ERR
"Lantiq %s driver initialization failed!\n", (char *)&des_drivers_alg
[i
].alg
.cra_driver_name
);
928 for (i
= 0; i
< ARRAY_SIZE(des_drivers_alg
); i
++) {
929 if (!strcmp((char *)&des_drivers_alg
[i
].alg
.cra_name
, "cbc(des3_ede)"))
930 crypto_unregister_alg(&des_drivers_alg
[i
].alg
);
933 printk(KERN_ERR
"Lantiq %s driver initialization failed!\n", (char *)&des_drivers_alg
[i
].alg
.cra_driver_name
);
937 /*! \fn void __exit lqdeu_fini_async_des (void)
938 * \ingroup IFX_DES_FUNCTIONS
939 * \brief unregister des driver
941 void __exit
lqdeu_fini_async_des (void)
945 for (i
= 0; i
< ARRAY_SIZE(des_drivers_alg
); i
++)
946 crypto_unregister_alg(&des_drivers_alg
[i
].alg
);
948 des_queue
->hw_status
= DES_COMPLETED
;
949 DEU_WAKEUP_EVENT(deu_dma_priv
.deu_thread_wait
, DES_ASYNC_EVENT
,
950 deu_dma_priv
.des_event_flags
);