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 *******************************************************************************/
68 #include "cesa/mvMD5.h"
69 #include "cesa/mvSHA1.h"
71 #include "cesa/mvCesa.h"
72 #include "cesa/mvCesaRegs.h"
73 #include "cesa/AES/mvAes.h"
75 static const char* mvCesaDebugStateStr(MV_CESA_STATE state
)
97 static const char* mvCesaDebugOperStr(MV_CESA_OPERATION oper
)
101 case MV_CESA_MAC_ONLY
:
104 case MV_CESA_CRYPTO_ONLY
:
107 case MV_CESA_MAC_THEN_CRYPTO
:
110 case MV_CESA_CRYPTO_THEN_MAC
:
119 static const char* mvCesaDebugCryptoAlgStr(MV_CESA_CRYPTO_ALG cryptoAlg
)
123 case MV_CESA_CRYPTO_DES
:
126 case MV_CESA_CRYPTO_3DES
:
129 case MV_CESA_CRYPTO_AES
:
138 static const char* mvCesaDebugMacModeStr(MV_CESA_MAC_MODE macMode
)
142 case MV_CESA_MAC_MD5
:
145 case MV_CESA_MAC_SHA1
:
148 case MV_CESA_MAC_HMAC_MD5
:
151 case MV_CESA_MAC_HMAC_SHA1
:
160 void mvCesaDebugCmd(MV_CESA_COMMAND
* pCmd
, int mode
)
162 mvOsPrintf("pCmd=%p, pReqPrv=%p, pSrc=%p, pDst=%p, pCB=%p, sid=%d\n",
163 pCmd
, pCmd
->pReqPrv
, pCmd
->pSrc
, pCmd
->pDst
,
164 pCmd
->pFuncCB
, pCmd
->sessionId
);
165 mvOsPrintf("isUser=%d, ivOffs=%d, crOffs=%d, crLen=%d, digest=%d, macOffs=%d, macLen=%d\n",
166 pCmd
->ivFromUser
, pCmd
->ivOffset
, pCmd
->cryptoOffset
, pCmd
->cryptoLength
,
167 pCmd
->digestOffset
, pCmd
->macOffset
, pCmd
->macLength
);
170 /* no need to use in tool */
171 void mvCesaDebugMbuf(const char* str
, MV_CESA_MBUF
*pMbuf
, int offset
, int size
)
173 int frag
, len
, fragOffset
;
176 mvOsPrintf("%s: pMbuf=%p, numFrags=%d, mbufSize=%d\n",
177 str
, pMbuf
, pMbuf
->numFrags
, pMbuf
->mbufSize
);
179 frag
= mvCesaMbufOffset(pMbuf
, offset
, &fragOffset
);
180 if(frag
== MV_INVALID
)
182 mvOsPrintf("CESA Mbuf Error: offset (%d) out of range\n", offset
);
186 for(; frag
<pMbuf
->numFrags
; frag
++)
188 mvOsPrintf("#%2d. bufVirt=%p, bufSize=%d\n",
189 frag
, pMbuf
->pFrags
[frag
].bufVirtPtr
,
190 pMbuf
->pFrags
[frag
].bufSize
);
193 len
= MV_MIN(pMbuf
->pFrags
[frag
].bufSize
, size
);
194 mvDebugMemDump(pMbuf
->pFrags
[frag
].bufVirtPtr
+fragOffset
, len
, 1);
201 void mvCesaDebugRegs(void)
203 mvOsPrintf("\t CESA Registers:\n");
205 mvOsPrintf("MV_CESA_CMD_REG : 0x%X = 0x%08x\n",
207 MV_REG_READ( MV_CESA_CMD_REG
) );
209 mvOsPrintf("MV_CESA_CHAN_DESC_OFFSET_REG : 0x%X = 0x%08x\n",
210 MV_CESA_CHAN_DESC_OFFSET_REG
,
211 MV_REG_READ(MV_CESA_CHAN_DESC_OFFSET_REG
) );
213 mvOsPrintf("MV_CESA_CFG_REG : 0x%X = 0x%08x\n",
215 MV_REG_READ( MV_CESA_CFG_REG
) );
217 mvOsPrintf("MV_CESA_STATUS_REG : 0x%X = 0x%08x\n",
219 MV_REG_READ( MV_CESA_STATUS_REG
) );
221 mvOsPrintf("MV_CESA_ISR_CAUSE_REG : 0x%X = 0x%08x\n",
222 MV_CESA_ISR_CAUSE_REG
,
223 MV_REG_READ( MV_CESA_ISR_CAUSE_REG
) );
225 mvOsPrintf("MV_CESA_ISR_MASK_REG : 0x%X = 0x%08x\n",
226 MV_CESA_ISR_MASK_REG
,
227 MV_REG_READ( MV_CESA_ISR_MASK_REG
) );
228 #if (MV_CESA_VERSION >= 2)
229 mvOsPrintf("MV_CESA_TDMA_CTRL_REG : 0x%X = 0x%08x\n",
230 MV_CESA_TDMA_CTRL_REG
,
231 MV_REG_READ( MV_CESA_TDMA_CTRL_REG
) );
233 mvOsPrintf("MV_CESA_TDMA_BYTE_COUNT_REG : 0x%X = 0x%08x\n",
234 MV_CESA_TDMA_BYTE_COUNT_REG
,
235 MV_REG_READ( MV_CESA_TDMA_BYTE_COUNT_REG
) );
237 mvOsPrintf("MV_CESA_TDMA_SRC_ADDR_REG : 0x%X = 0x%08x\n",
238 MV_CESA_TDMA_SRC_ADDR_REG
,
239 MV_REG_READ( MV_CESA_TDMA_SRC_ADDR_REG
) );
241 mvOsPrintf("MV_CESA_TDMA_DST_ADDR_REG : 0x%X = 0x%08x\n",
242 MV_CESA_TDMA_DST_ADDR_REG
,
243 MV_REG_READ( MV_CESA_TDMA_DST_ADDR_REG
) );
245 mvOsPrintf("MV_CESA_TDMA_NEXT_DESC_PTR_REG : 0x%X = 0x%08x\n",
246 MV_CESA_TDMA_NEXT_DESC_PTR_REG
,
247 MV_REG_READ( MV_CESA_TDMA_NEXT_DESC_PTR_REG
) );
249 mvOsPrintf("MV_CESA_TDMA_CURR_DESC_PTR_REG : 0x%X = 0x%08x\n",
250 MV_CESA_TDMA_CURR_DESC_PTR_REG
,
251 MV_REG_READ( MV_CESA_TDMA_CURR_DESC_PTR_REG
) );
253 mvOsPrintf("MV_CESA_TDMA_ERROR_CAUSE_REG : 0x%X = 0x%08x\n",
254 MV_CESA_TDMA_ERROR_CAUSE_REG
,
255 MV_REG_READ( MV_CESA_TDMA_ERROR_CAUSE_REG
) );
257 mvOsPrintf("MV_CESA_TDMA_ERROR_MASK_REG : 0x%X = 0x%08x\n",
258 MV_CESA_TDMA_ERROR_MASK_REG
,
259 MV_REG_READ( MV_CESA_TDMA_ERROR_CAUSE_REG
) );
264 void mvCesaDebugStatus(void)
266 mvOsPrintf("\n\t CESA Status\n\n");
268 mvOsPrintf("pReqQ=%p, qDepth=%d, reqSize=%ld bytes, qRes=%d, ",
269 pCesaReqFirst
, cesaQueueDepth
, sizeof(MV_CESA_REQ
),
271 #if (MV_CESA_VERSION >= 3)
272 mvOsPrintf("chainLength=%u\n",cesaChainLength
);
277 mvOsPrintf("pSAD=%p, maxSA=%d, sizeSA=%ld bytes\n",
278 pCesaSAD
, cesaMaxSA
, sizeof(MV_CESA_SA
));
284 mvCesaDebugStatsClear();
287 void mvCesaDebugDescriptor(MV_CESA_DESC
* pDesc
)
289 mvOsPrintf("config=0x%08x, crSrcOffs=0x%04x, crDstOffs=0x%04x\n",
290 pDesc
->config
, pDesc
->cryptoSrcOffset
, pDesc
->cryptoDstOffset
);
292 mvOsPrintf("crLen=0x%04x, crKeyOffs=0x%04x, ivOffs=0x%04x, ivBufOffs=0x%04x\n",
293 pDesc
->cryptoDataLen
, pDesc
->cryptoKeyOffset
,
294 pDesc
->cryptoIvOffset
, pDesc
->cryptoIvBufOffset
);
296 mvOsPrintf("macSrc=0x%04x, digest=0x%04x, macLen=0x%04x, inIv=0x%04x, outIv=0x%04x\n",
297 pDesc
->macSrcOffset
, pDesc
->macDigestOffset
, pDesc
->macDataLen
,
298 pDesc
->macInnerIvOffset
, pDesc
->macOuterIvOffset
);
301 void mvCesaDebugQueue(int mode
)
303 mvOsPrintf("\n\t CESA Request Queue:\n\n");
305 mvOsPrintf("pFirstReq=%p, pLastReq=%p, qDepth=%d, reqSize=%ld bytes\n",
306 pCesaReqFirst
, pCesaReqLast
, cesaQueueDepth
, sizeof(MV_CESA_REQ
));
308 mvOsPrintf("pEmpty=%p, pProcess=%p, qResources=%d\n",
309 pCesaReqEmpty
, pCesaReqProcess
,
315 MV_CESA_REQ
* pReq
= pCesaReqFirst
;
317 for(count
=0; count
<cesaQueueDepth
; count
++)
319 /* Print out requsts */
320 mvOsPrintf("%02d. pReq=%p, state=%s, frag=0x%x, pCmd=%p, pDma=%p, pDesc=%p\n",
321 count
, pReq
, mvCesaDebugStateStr(pReq
->state
),
322 pReq
->fragMode
, pReq
->pCmd
, pReq
->dma
[0].pDmaFirst
, &pReq
->pCesaDesc
[0]);
323 if(pReq
->fragMode
!= MV_CESA_FRAG_NONE
)
327 mvOsPrintf("pFrags=%p, num=%d, next=%d, bufOffset=%d, cryptoSize=%d, macSize=%d\n",
328 &pReq
->frags
, pReq
->frags
.numFrag
, pReq
->frags
.nextFrag
,
329 pReq
->frags
.bufOffset
, pReq
->frags
.cryptoSize
, pReq
->frags
.macSize
);
330 for(frag
=0; frag
<pReq
->frags
.numFrag
; frag
++)
332 mvOsPrintf("#%d: pDmaFirst=%p, pDesc=%p\n", frag
,
333 pReq
->dma
[frag
].pDmaFirst
, &pReq
->pCesaDesc
[frag
]);
338 /* Print out Command */
339 mvCesaDebugCmd(pReq
->pCmd
, mode
);
341 /* Print out Descriptor */
342 mvCesaDebugDescriptor(&pReq
->pCesaDesc
[0]);
350 void mvCesaDebugSramSA(MV_CESA_SRAM_SA
* pSramSA
, int mode
)
354 mvOsPrintf("cesaSramSA: Unexpected pSramSA=%p\n", pSramSA
);
357 mvOsPrintf("pSramSA=%p, sizeSramSA=%ld bytes\n",
358 pSramSA
, sizeof(MV_CESA_SRAM_SA
));
362 mvOsPrintf("cryptoKey=%p, maxCryptoKey=%d bytes\n",
363 pSramSA
->cryptoKey
, MV_CESA_MAX_CRYPTO_KEY_LENGTH
);
364 mvDebugMemDump(pSramSA
->cryptoKey
, MV_CESA_MAX_CRYPTO_KEY_LENGTH
, 1);
366 mvOsPrintf("macInnerIV=%p, maxInnerIV=%d bytes\n",
367 pSramSA
->macInnerIV
, MV_CESA_MAX_DIGEST_SIZE
);
368 mvDebugMemDump(pSramSA
->macInnerIV
, MV_CESA_MAX_DIGEST_SIZE
, 1);
370 mvOsPrintf("macOuterIV=%p, maxOuterIV=%d bytes\n",
371 pSramSA
->macOuterIV
, MV_CESA_MAX_DIGEST_SIZE
);
372 mvDebugMemDump(pSramSA
->macOuterIV
, MV_CESA_MAX_DIGEST_SIZE
, 1);
376 void mvCesaDebugSA(short sid
, int mode
)
378 MV_CESA_OPERATION oper
;
379 MV_CESA_DIRECTION dir
;
380 MV_CESA_CRYPTO_ALG cryptoAlg
;
381 MV_CESA_CRYPTO_MODE cryptoMode
;
382 MV_CESA_MAC_MODE macMode
;
383 MV_CESA_SA
* pSA
= &pCesaSAD
[sid
];
385 if( (pSA
->valid
) || ((pSA
->count
!= 0) && (mode
> 0)) || (mode
>= 2) )
387 mvOsPrintf("\n\nCESA SA Entry #%d (%p) - %s (count=%d)\n",
389 pSA
->valid
? "Valid" : "Invalid", pSA
->count
);
391 oper
= (pSA
->config
& MV_CESA_OPERATION_MASK
) >> MV_CESA_OPERATION_OFFSET
;
392 dir
= (pSA
->config
& MV_CESA_DIRECTION_MASK
) >> MV_CESA_DIRECTION_BIT
;
393 mvOsPrintf("%s - %s ", mvCesaDebugOperStr(oper
),
394 (dir
== MV_CESA_DIR_ENCODE
) ? "Encode" : "Decode");
395 if(oper
!= MV_CESA_MAC_ONLY
)
397 cryptoAlg
= (pSA
->config
& MV_CESA_CRYPTO_ALG_MASK
) >> MV_CESA_CRYPTO_ALG_OFFSET
;
398 cryptoMode
= (pSA
->config
& MV_CESA_CRYPTO_MODE_MASK
) >> MV_CESA_CRYPTO_MODE_BIT
;
399 mvOsPrintf("- %s - %s ", mvCesaDebugCryptoAlgStr(cryptoAlg
),
400 (cryptoMode
== MV_CESA_CRYPTO_ECB
) ? "ECB" : "CBC");
402 if(oper
!= MV_CESA_CRYPTO_ONLY
)
404 macMode
= (pSA
->config
& MV_CESA_MAC_MODE_MASK
) >> MV_CESA_MAC_MODE_OFFSET
;
405 mvOsPrintf("- %s ", mvCesaDebugMacModeStr(macMode
));
411 mvOsPrintf("config=0x%08x, cryptoKeySize=%d, digestSize=%d\n",
412 pCesaSAD
[sid
].config
, pCesaSAD
[sid
].cryptoKeyLength
,
413 pCesaSAD
[sid
].digestSize
);
415 mvCesaDebugSramSA(pCesaSAD
[sid
].pSramSA
, mode
);
422 void mvCesaDebugSram(int mode
)
424 mvOsPrintf("\n\t SRAM contents: size=%ld, pVirt=%p\n\n",
425 sizeof(MV_CESA_SRAM_MAP
), cesaSramVirtPtr
);
427 mvOsPrintf("\n\t Sram buffer: size=%d, pVirt=%p\n",
428 MV_CESA_MAX_BUF_SIZE
, cesaSramVirtPtr
->buf
);
430 mvDebugMemDump(cesaSramVirtPtr
->buf
, 64, 1);
433 mvOsPrintf("\n\t Sram descriptor: size=%ld, pVirt=%p\n",
434 sizeof(MV_CESA_DESC
), &cesaSramVirtPtr
->desc
);
438 mvCesaDebugDescriptor(&cesaSramVirtPtr
->desc
);
440 mvOsPrintf("\n\t Sram IV: size=%d, pVirt=%p\n",
441 MV_CESA_MAX_IV_LENGTH
, &cesaSramVirtPtr
->cryptoIV
);
445 mvDebugMemDump(cesaSramVirtPtr
->cryptoIV
, MV_CESA_MAX_IV_LENGTH
, 1);
448 mvCesaDebugSramSA(&cesaSramVirtPtr
->sramSA
, 0);
451 void mvCesaDebugSAD(int mode
)
455 mvOsPrintf("\n\t Cesa SAD status: pSAD=%p, maxSA=%d\n",
456 pCesaSAD
, cesaMaxSA
);
458 for(sid
=0; sid
<cesaMaxSA
; sid
++)
460 mvCesaDebugSA(sid
, mode
);
464 void mvCesaDebugStats(void)
466 mvOsPrintf("\n\t Cesa Statistics\n");
468 mvOsPrintf("Opened=%u, Closed=%u\n",
469 cesaStats
.openedCount
, cesaStats
.closedCount
);
470 mvOsPrintf("Req=%u, maxReq=%u, frags=%u, start=%u\n",
471 cesaStats
.reqCount
, cesaStats
.maxReqCount
,
472 cesaStats
.fragCount
, cesaStats
.startCount
);
473 #if (MV_CESA_VERSION >= 3)
474 mvOsPrintf("maxChainUsage=%u\n",cesaStats
.maxChainUsage
);
477 mvOsPrintf("proc=%u, ready=%u, notReady=%u\n",
478 cesaStats
.procCount
, cesaStats
.readyCount
, cesaStats
.notReadyCount
);
481 void mvCesaDebugStatsClear(void)
483 memset(&cesaStats
, 0, sizeof(cesaStats
));