2 * AMCC SoC PPC4xx Crypto Driver
4 * Copyright (c) 2008 Applied Micro Circuits Corporation.
5 * All rights reserved. James Hsiao <jhsiao@amcc.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * This is the header file for AMCC Crypto offload Linux device driver for
18 * use with Linux CryptoAPI.
22 #ifndef __CRYPTO4XX_CORE_H__
23 #define __CRYPTO4XX_CORE_H__
25 #include <crypto/internal/hash.h>
27 #define MODULE_NAME "crypto4xx"
29 #define PPC460SX_SDR0_SRST 0x201
30 #define PPC405EX_SDR0_SRST 0x200
31 #define PPC460EX_SDR0_SRST 0x201
32 #define PPC460EX_CE_RESET 0x08000000
33 #define PPC460SX_CE_RESET 0x20000000
34 #define PPC405EX_CE_RESET 0x00000008
36 #define CRYPTO4XX_CRYPTO_PRIORITY 300
37 #define PPC4XX_LAST_PD 63
38 #define PPC4XX_NUM_PD 64
39 #define PPC4XX_LAST_GD 1023
40 #define PPC4XX_NUM_GD 1024
41 #define PPC4XX_LAST_SD 63
42 #define PPC4XX_NUM_SD 64
43 #define PPC4XX_SD_BUFFER_SIZE 2048
45 #define PD_ENTRY_INUSE 1
46 #define PD_ENTRY_FREE 0
47 #define ERING_WAS_FULL 0xffffffff
49 struct crypto4xx_device
;
52 struct crypto4xx_device
*dev
;
55 u32 first_gd
; /* first gather discriptor
56 used by this packet */
57 u32 num_gd
; /* number of gather discriptor
58 used by this packet */
59 u32 first_sd
; /* first scatter discriptor
60 used by this packet */
61 u32 num_sd
; /* number of scatter discriptors
62 used by this packet */
63 void *sa_va
; /* shadow sa, when using cp from ctx->sa */
65 void *sr_va
; /* state record for shadow sa */
67 struct scatterlist
*dest_va
;
68 struct crypto_async_request
*async_req
; /* base crypto request
72 struct crypto4xx_device
{
73 struct crypto4xx_core_device
*core_dev
;
76 void __iomem
*ce_base
;
77 void __iomem
*trng_base
;
79 void *pdr
; /* base address of packet
81 dma_addr_t pdr_pa
; /* physical address used to
82 program ce pdr_base_register */
83 void *gdr
; /* gather descriptor ring */
84 dma_addr_t gdr_pa
; /* physical address used to
85 program ce gdr_base_register */
86 void *sdr
; /* scatter descriptor ring */
87 dma_addr_t sdr_pa
; /* physical address used to
88 program ce sdr_base_register */
89 void *scatter_buffer_va
;
90 dma_addr_t scatter_buffer_pa
;
91 u32 scatter_buffer_size
;
93 void *shadow_sa_pool
; /* pool of memory for sa in pd_uinfo */
94 dma_addr_t shadow_sa_pool_pa
;
95 void *shadow_sr_pool
; /* pool of memory for sr in pd_uinfo */
96 dma_addr_t shadow_sr_pool_pa
;
104 struct list_head alg_list
; /* List of algorithm supported
108 struct crypto4xx_core_device
{
109 struct device
*device
;
110 struct platform_device
*ofdev
;
111 struct crypto4xx_device
*dev
;
115 struct tasklet_struct tasklet
;
119 struct crypto4xx_ctx
{
120 struct crypto4xx_device
*dev
;
122 dma_addr_t sa_in_dma_addr
;
124 dma_addr_t sa_out_dma_addr
;
126 dma_addr_t state_record_dma_addr
;
128 u32 offset_to_sr_ptr
; /* offset to state ptr, in dynamic sa */
139 struct crypto4xx_req_ctx
{
140 struct crypto4xx_device
*dev
; /* Device in which
141 operation to send to */
147 struct crypto4xx_alg_common
{
150 struct crypto_alg cipher
;
151 struct ahash_alg hash
;
155 struct crypto4xx_alg
{
156 struct list_head entry
;
157 struct crypto4xx_alg_common alg
;
158 struct crypto4xx_device
*dev
;
161 static inline struct crypto4xx_alg
*crypto_alg_to_crypto4xx_alg(
162 struct crypto_alg
*x
)
164 switch (x
->cra_flags
& CRYPTO_ALG_TYPE_MASK
) {
165 case CRYPTO_ALG_TYPE_AHASH
:
166 return container_of(__crypto_ahash_alg(x
),
167 struct crypto4xx_alg
, alg
.u
.hash
);
170 return container_of(x
, struct crypto4xx_alg
, alg
.u
.cipher
);
173 extern int crypto4xx_alloc_sa(struct crypto4xx_ctx
*ctx
, u32 size
);
174 extern void crypto4xx_free_sa(struct crypto4xx_ctx
*ctx
);
175 extern u32
crypto4xx_alloc_sa_rctx(struct crypto4xx_ctx
*ctx
,
176 struct crypto4xx_ctx
*rctx
);
177 extern void crypto4xx_free_sa_rctx(struct crypto4xx_ctx
*rctx
);
178 extern void crypto4xx_free_ctx(struct crypto4xx_ctx
*ctx
);
179 extern u32
crypto4xx_alloc_state_record(struct crypto4xx_ctx
*ctx
);
180 extern u32
get_dynamic_sa_offset_state_ptr_field(struct crypto4xx_ctx
*ctx
);
181 extern u32
get_dynamic_sa_offset_key_field(struct crypto4xx_ctx
*ctx
);
182 extern u32
get_dynamic_sa_iv_size(struct crypto4xx_ctx
*ctx
);
183 extern void crypto4xx_memcpy_le(unsigned int *dst
,
184 const unsigned char *buf
, int len
);
185 extern u32
crypto4xx_build_pd(struct crypto_async_request
*req
,
186 struct crypto4xx_ctx
*ctx
,
187 struct scatterlist
*src
,
188 struct scatterlist
*dst
,
189 unsigned int datalen
,
190 void *iv
, u32 iv_len
);
191 extern int crypto4xx_setkey_aes_cbc(struct crypto_ablkcipher
*cipher
,
192 const u8
*key
, unsigned int keylen
);
193 extern int crypto4xx_encrypt(struct ablkcipher_request
*req
);
194 extern int crypto4xx_decrypt(struct ablkcipher_request
*req
);
195 extern int crypto4xx_sha1_alg_init(struct crypto_tfm
*tfm
);
196 extern int crypto4xx_hash_digest(struct ahash_request
*req
);
197 extern int crypto4xx_hash_final(struct ahash_request
*req
);
198 extern int crypto4xx_hash_update(struct ahash_request
*req
);
199 extern int crypto4xx_hash_init(struct ahash_request
*req
);