1 /*******************************************************************************
2 Copyright (C) Marvell International Ltd. and its affiliates
4 This software file (the "File") is owned and distributed by Marvell
5 International Ltd. and/or its affiliates ("Marvell") under the following
6 alternative licensing terms. Once you have made an election to distribute the
7 File under one of the following license alternatives, please (i) delete this
8 introductory statement regarding license alternatives, (ii) delete the two
9 license alternatives that you have not elected to use and (iii) preserve the
10 Marvell copyright notice above.
12 ********************************************************************************
13 Marvell Commercial License Option
15 If you received this File from Marvell and you have entered into a commercial
16 license agreement (a "Commercial License") with Marvell, the File is licensed
17 to you under the terms of the applicable Commercial License.
19 ********************************************************************************
20 Marvell GPL License Option
22 If you received this File from Marvell, you may opt to use, redistribute and/or
23 modify this File in accordance with the terms and conditions of the General
24 Public License Version 2, June 1991 (the "GPL License"), a copy of which is
25 available along with the File in the license.txt file or by writing to the Free
26 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or
27 on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
29 THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
30 WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
31 DISCLAIMED. The GPL License provides additional details about this warranty
33 ********************************************************************************
34 Marvell BSD License Option
36 If you received this File from Marvell, you may opt to use, redistribute and/or
37 modify this File under the following licensing terms.
38 Redistribution and use in source and binary forms, with or without modification,
39 are permitted provided that the following conditions are met:
41 * Redistributions of source code must retain the above copyright notice,
42 this list of conditions and the following disclaimer.
44 * Redistributions in binary form must reproduce the above copyright
45 notice, this list of conditions and the following disclaimer in the
46 documentation and/or other materials provided with the distribution.
48 * Neither the name of Marvell nor the names of its contributors may be
49 used to endorse or promote products derived from this software without
50 specific prior written permission.
52 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
53 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
54 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
55 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
56 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
57 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
58 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
59 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
61 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *******************************************************************************/
65 /*******************************************************************************
66 * mvCesa.h - Header File for Cryptographic Engines and Security Accelerator
69 * This header file contains macros typedefs and function declaration for
70 * the Marvell Cryptographic Engines and Security Accelerator.
72 *******************************************************************************/
81 #include "ctrlEnv/mvCtrlEnvSpec.h"
83 #include "cesa/mvMD5.h"
84 #include "cesa/mvSHA1.h"
86 #include "cesa/mvCesa.h"
87 #include "cesa/AES/mvAes.h"
88 #include "mvSysHwConfig.h"
90 #ifdef MV_INCLUDE_IDMA
91 #include "idma/mvIdma.h"
92 #include "idma/mvIdmaRegs.h"
94 /* Redefine MV_DMA_DESC structure */
95 typedef struct _mvDmaDesc
97 MV_U32 byteCnt
; /* The total number of bytes to transfer */
98 MV_U32 phySrcAdd
; /* The physical source address */
99 MV_U32 phyDestAdd
; /* The physical destination address */
100 MV_U32 phyNextDescPtr
; /* If we are using chain mode DMA transfer, */
101 /* then this pointer should point to the */
102 /* physical address of the next descriptor, */
103 /* otherwise it should be NULL. */
105 #endif /* MV_INCLUDE_IDMA */
107 #include "cesa/mvCesaRegs.h"
109 #define MV_CESA_AUTH_BLOCK_SIZE 64 /* bytes */
111 #define MV_CESA_MD5_DIGEST_SIZE 16 /* bytes */
112 #define MV_CESA_SHA1_DIGEST_SIZE 20 /* bytes */
114 #define MV_CESA_MAX_DIGEST_SIZE MV_CESA_SHA1_DIGEST_SIZE
116 #define MV_CESA_DES_KEY_LENGTH 8 /* bytes = 64 bits */
117 #define MV_CESA_3DES_KEY_LENGTH 24 /* bytes = 192 bits */
118 #define MV_CESA_AES_128_KEY_LENGTH 16 /* bytes = 128 bits */
119 #define MV_CESA_AES_192_KEY_LENGTH 24 /* bytes = 192 bits */
120 #define MV_CESA_AES_256_KEY_LENGTH 32 /* bytes = 256 bits */
122 #define MV_CESA_MAX_CRYPTO_KEY_LENGTH MV_CESA_AES_256_KEY_LENGTH
124 #define MV_CESA_DES_BLOCK_SIZE 8 /* bytes = 64 bits */
125 #define MV_CESA_3DES_BLOCK_SIZE 8 /* bytes = 64 bits */
127 #define MV_CESA_AES_BLOCK_SIZE 16 /* bytes = 128 bits */
129 #define MV_CESA_MAX_IV_LENGTH MV_CESA_AES_BLOCK_SIZE
131 #define MV_CESA_MAX_MAC_KEY_LENGTH 64 /* bytes */
135 MV_U8 cryptoKey
[MV_CESA_MAX_CRYPTO_KEY_LENGTH
];
136 MV_U8 macKey
[MV_CESA_MAX_MAC_KEY_LENGTH
];
137 MV_CESA_OPERATION operation
;
138 MV_CESA_DIRECTION direction
;
139 MV_CESA_CRYPTO_ALG cryptoAlgorithm
;
140 MV_CESA_CRYPTO_MODE cryptoMode
;
141 MV_U8 cryptoKeyLength
;
142 MV_CESA_MAC_MODE macMode
;
146 } MV_CESA_OPEN_SESSION
;
158 void* pReqPrv
; /* instead of reqId */
164 typedef void (*MV_CESA_CALLBACK
) (MV_CESA_RESULT
* pResult
);
169 void* pReqPrv
; /* instead of reqId */
172 MV_CESA_CALLBACK
* pFuncCB
;
186 MV_STATUS
mvCesaHalInit (int numOfSession
, int queueDepth
, char* pSramBase
, MV_U32 cryptEngBase
, void *osHandle
);
187 MV_STATUS
mvCesaFinish (void);
188 MV_STATUS
mvCesaSessionOpen(MV_CESA_OPEN_SESSION
*pSession
, short* pSid
);
189 MV_STATUS
mvCesaSessionClose(short sid
);
190 MV_STATUS
mvCesaCryptoIvSet(MV_U8
* pIV
, int ivSize
);
192 MV_STATUS
mvCesaAction (MV_CESA_COMMAND
* pCmd
);
194 MV_U32
mvCesaInProcessGet(void);
195 MV_STATUS
mvCesaReadyDispatch(void);
196 MV_STATUS
mvCesaReadyGet(MV_CESA_RESULT
* pResult
);
197 MV_BOOL
mvCesaIsReady(void);
199 int mvCesaMbufOffset(MV_CESA_MBUF
* pMbuf
, int offset
, int* pBufOffset
);
200 MV_STATUS
mvCesaCopyFromMbuf(MV_U8
* pDst
, MV_CESA_MBUF
* pSrcMbuf
,
201 int offset
, int size
);
202 MV_STATUS
mvCesaCopyToMbuf(MV_U8
* pSrc
, MV_CESA_MBUF
* pDstMbuf
,
203 int offset
, int size
);
204 MV_STATUS
mvCesaMbufCopy(MV_CESA_MBUF
* pMbufDst
, int dstMbufOffset
,
205 MV_CESA_MBUF
* pMbufSrc
, int srcMbufOffset
, int size
);
207 /********** Debug functions ********/
209 void mvCesaDebugMbuf(const char* str
, MV_CESA_MBUF
*pMbuf
, int offset
, int size
);
210 void mvCesaDebugSA(short sid
, int mode
);
211 void mvCesaDebugStats(void);
212 void mvCesaDebugStatsClear(void);
213 void mvCesaDebugRegs(void);
214 void mvCesaDebugStatus(void);
215 void mvCesaDebugQueue(int mode
);
216 void mvCesaDebugSram(int mode
);
217 void mvCesaDebugSAD(int mode
);
220 /******** CESA Private definitions ********/
221 #if (MV_CESA_VERSION >= 2)
222 #if (MV_CACHE_COHERENCY == MV_CACHE_COHER_SW)
223 #define MV_CESA_TDMA_CTRL_VALUE MV_CESA_TDMA_DST_BURST_MASK(MV_CESA_TDMA_BURST_128B) \
224 | MV_CESA_TDMA_SRC_BURST_MASK(MV_CESA_TDMA_BURST_128B) \
225 | MV_CESA_TDMA_OUTSTAND_READ_EN_MASK \
226 | MV_CESA_TDMA_NO_BYTE_SWAP_MASK \
227 | MV_CESA_TDMA_ENABLE_MASK
229 #define MV_CESA_TDMA_CTRL_VALUE MV_CESA_TDMA_DST_BURST_MASK(MV_CESA_TDMA_BURST_32B) \
230 | MV_CESA_TDMA_SRC_BURST_MASK(MV_CESA_TDMA_BURST_128B) \
231 /*| MV_CESA_TDMA_OUTSTAND_READ_EN_MASK */\
232 | MV_CESA_TDMA_ENABLE_MASK
236 #define MV_CESA_IDMA_CTRL_LOW_VALUE ICCLR_DST_BURST_LIM_128BYTE \
237 | ICCLR_SRC_BURST_LIM_128BYTE \
238 | ICCLR_INT_MODE_MASK \
240 | ICCLR_CHAN_ENABLE \
241 | ICCLR_DESC_MODE_16M
242 #endif /* MV_CESA_VERSION >= 2 */
244 #define MV_CESA_MAX_PKT_SIZE (64 * 1024)
245 #define MV_CESA_MAX_MBUF_FRAGS 20
247 #define MV_CESA_MAX_REQ_FRAGS ( (MV_CESA_MAX_PKT_SIZE / MV_CESA_MAX_BUF_SIZE) + 1)
249 #define MV_CESA_MAX_DMA_DESC (MV_CESA_MAX_MBUF_FRAGS*2 + 5)
251 #define MAX_CESA_CHAIN_LENGTH 20
259 #if (MV_CESA_VERSION >= 3)
265 /* Session database */
267 /* Map of Key materials of the session in SRAM.
268 * Each field must be 8 byte aligned
269 * Total size: 32 + 24 + 24 = 80 bytes
273 MV_U8 cryptoKey
[MV_CESA_MAX_CRYPTO_KEY_LENGTH
];
274 MV_U8 macInnerIV
[MV_CESA_MAX_DIGEST_SIZE
];
275 MV_U8 reservedInner
[4];
276 MV_U8 macOuterIV
[MV_CESA_MAX_DIGEST_SIZE
];
277 MV_U8 reservedOuter
[4];
283 MV_CESA_SRAM_SA
* pSramSA
;
285 MV_U8 cryptoKeyLength
;
287 MV_U8 cryptoBlockSize
;
296 /* DMA list management */
299 MV_DMA_DESC
* pDmaFirst
;
300 MV_DMA_DESC
* pDmaLast
;
313 MV_U8 orgDigest
[MV_CESA_MAX_DIGEST_SIZE
];
323 MV_CESA_COMMAND
* pCmd
;
324 MV_CESA_COMMAND
* pOrgCmd
;
325 MV_BUF_INFO dmaDescBuf
;
326 MV_CESA_DMA dma
[MV_CESA_MAX_REQ_FRAGS
];
327 MV_BUF_INFO cesaDescBuf
;
328 MV_CESA_DESC
* pCesaDesc
;
336 /* Total SRAM size calculation */
338 * MV_CESA_MAX_BUF_SIZE +
339 * sizeof(MV_CESA_DESC) +
340 * MV_CESA_MAX_IV_LENGTH +
341 * MV_CESA_MAX_IV_LENGTH +
342 * MV_CESA_MAX_DIGEST_SIZE +
343 * sizeof(MV_CESA_SRAM_SA)
344 * = 1600 + 32 + 16 + 16 + 24 + 80 + 280 (reserved) = 2048 bytes
345 * = 3200 + 32 + 16 + 16 + 24 + 80 + 728 (reserved) = 4096 bytes
349 MV_U8 buf
[MV_CESA_MAX_BUF_SIZE
];
351 MV_U8 cryptoIV
[MV_CESA_MAX_IV_LENGTH
];
352 MV_U8 tempCryptoIV
[MV_CESA_MAX_IV_LENGTH
];
353 MV_U8 tempDigest
[MV_CESA_MAX_DIGEST_SIZE
+4];
354 MV_CESA_SRAM_SA sramSA
;
368 MV_U32 notReadyCount
;
370 #if (MV_CESA_VERSION >= 3)
371 MV_U32 maxChainUsage
;
377 /* External variables */
379 extern MV_CESA_STATS cesaStats
;
380 extern MV_CESA_FRAGS cesaFrags
;
382 extern MV_BUF_INFO cesaSramSaBuf
;
384 extern MV_CESA_SA
* pCesaSAD
;
385 extern MV_U16 cesaMaxSA
;
387 extern MV_CESA_REQ
* pCesaReqFirst
;
388 extern MV_CESA_REQ
* pCesaReqLast
;
389 extern MV_CESA_REQ
* pCesaReqEmpty
;
390 extern MV_CESA_REQ
* pCesaReqProcess
;
391 extern int cesaQueueDepth
;
392 extern int cesaReqResources
;
393 #if (MV_CESA_VERSION>= 3)
394 extern MV_U32 cesaChainLength
;
397 extern MV_CESA_SRAM_MAP
* cesaSramVirtPtr
;
398 extern MV_U32 cesaSramPhysAddr
;
400 static INLINE MV_ULONG
mvCesaVirtToPhys(MV_BUF_INFO
* pBufInfo
, void* pVirt
)
402 return (pBufInfo
->bufPhysAddr
+ ((MV_U8
*)pVirt
- pBufInfo
->bufVirtPtr
));
405 /* Additional DEBUG functions */
406 void mvCesaDebugSramSA(MV_CESA_SRAM_SA
* pSramSA
, int mode
);
407 void mvCesaDebugCmd(MV_CESA_COMMAND
* pCmd
, int mode
);
408 void mvCesaDebugDescriptor(MV_CESA_DESC
* pDesc
);
412 #endif /* __mvCesa_h__ */