[package] base-files, ppp: fix interface shutdown
[openwrt.git] / target / linux / generic-2.6 / files / crypto / ocf / kirkwood / cesa / mvCesaDebug.c
1 /*******************************************************************************
2 Copyright (C) Marvell International Ltd. and its affiliates
3
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.
11
12 ********************************************************************************
13 Marvell Commercial License Option
14
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.
18
19 ********************************************************************************
20 Marvell GPL License Option
21
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.
28
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
32 disclaimer.
33 ********************************************************************************
34 Marvell BSD License Option
35
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:
40
41 * Redistributions of source code must retain the above copyright notice,
42 this list of conditions and the following disclaimer.
43
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.
47
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.
51
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.
62
63 *******************************************************************************/
64
65 #include "mvOs.h"
66 #include "mvDebug.h"
67
68 #include "cesa/mvMD5.h"
69 #include "cesa/mvSHA1.h"
70
71 #include "cesa/mvCesa.h"
72 #include "cesa/mvCesaRegs.h"
73 #include "cesa/AES/mvAes.h"
74
75 static const char* mvCesaDebugStateStr(MV_CESA_STATE state)
76 {
77 switch(state)
78 {
79 case MV_CESA_IDLE:
80 return "Idle";
81
82 case MV_CESA_PENDING:
83 return "Pend";
84
85 case MV_CESA_PROCESS:
86 return "Proc";
87
88 case MV_CESA_READY:
89 return "Ready";
90
91 default:
92 break;
93 }
94 return "Unknown";
95 }
96
97 static const char* mvCesaDebugOperStr(MV_CESA_OPERATION oper)
98 {
99 switch(oper)
100 {
101 case MV_CESA_MAC_ONLY:
102 return "MacOnly";
103
104 case MV_CESA_CRYPTO_ONLY:
105 return "CryptoOnly";
106
107 case MV_CESA_MAC_THEN_CRYPTO:
108 return "MacCrypto";
109
110 case MV_CESA_CRYPTO_THEN_MAC:
111 return "CryptoMac";
112
113 default:
114 break;
115 }
116 return "Null";
117 }
118
119 static const char* mvCesaDebugCryptoAlgStr(MV_CESA_CRYPTO_ALG cryptoAlg)
120 {
121 switch(cryptoAlg)
122 {
123 case MV_CESA_CRYPTO_DES:
124 return "DES";
125
126 case MV_CESA_CRYPTO_3DES:
127 return "3DES";
128
129 case MV_CESA_CRYPTO_AES:
130 return "AES";
131
132 default:
133 break;
134 }
135 return "Null";
136 }
137
138 static const char* mvCesaDebugMacModeStr(MV_CESA_MAC_MODE macMode)
139 {
140 switch(macMode)
141 {
142 case MV_CESA_MAC_MD5:
143 return "MD5";
144
145 case MV_CESA_MAC_SHA1:
146 return "SHA1";
147
148 case MV_CESA_MAC_HMAC_MD5:
149 return "HMAC-MD5";
150
151 case MV_CESA_MAC_HMAC_SHA1:
152 return "HMAC_SHA1";
153
154 default:
155 break;
156 }
157 return "Null";
158 }
159
160 void mvCesaDebugCmd(MV_CESA_COMMAND* pCmd, int mode)
161 {
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);
168 }
169
170 /* no need to use in tool */
171 void mvCesaDebugMbuf(const char* str, MV_CESA_MBUF *pMbuf, int offset, int size)
172 {
173 int frag, len, fragOffset;
174
175 if(str != NULL)
176 mvOsPrintf("%s: pMbuf=%p, numFrags=%d, mbufSize=%d\n",
177 str, pMbuf, pMbuf->numFrags, pMbuf->mbufSize);
178
179 frag = mvCesaMbufOffset(pMbuf, offset, &fragOffset);
180 if(frag == MV_INVALID)
181 {
182 mvOsPrintf("CESA Mbuf Error: offset (%d) out of range\n", offset);
183 return;
184 }
185
186 for(; frag<pMbuf->numFrags; frag++)
187 {
188 mvOsPrintf("#%2d. bufVirt=%p, bufSize=%d\n",
189 frag, pMbuf->pFrags[frag].bufVirtPtr,
190 pMbuf->pFrags[frag].bufSize);
191 if(size > 0)
192 {
193 len = MV_MIN(pMbuf->pFrags[frag].bufSize, size);
194 mvDebugMemDump(pMbuf->pFrags[frag].bufVirtPtr+fragOffset, len, 1);
195 size -= len;
196 fragOffset = 0;
197 }
198 }
199 }
200
201 void mvCesaDebugRegs(void)
202 {
203 mvOsPrintf("\t CESA Registers:\n");
204
205 mvOsPrintf("MV_CESA_CMD_REG : 0x%X = 0x%08x\n",
206 MV_CESA_CMD_REG,
207 MV_REG_READ( MV_CESA_CMD_REG ) );
208
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) );
212
213 mvOsPrintf("MV_CESA_CFG_REG : 0x%X = 0x%08x\n",
214 MV_CESA_CFG_REG,
215 MV_REG_READ( MV_CESA_CFG_REG ) );
216
217 mvOsPrintf("MV_CESA_STATUS_REG : 0x%X = 0x%08x\n",
218 MV_CESA_STATUS_REG,
219 MV_REG_READ( MV_CESA_STATUS_REG ) );
220
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 ) );
224
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 ) );
232
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 ) );
236
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 ) );
240
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 ) );
244
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 ) );
248
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 ) );
252
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 ) );
256
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 ) );
260
261 #endif
262 }
263
264 void mvCesaDebugStatus(void)
265 {
266 mvOsPrintf("\n\t CESA Status\n\n");
267
268 mvOsPrintf("pReqQ=%p, qDepth=%d, reqSize=%ld bytes, qRes=%d, ",
269 pCesaReqFirst, cesaQueueDepth, sizeof(MV_CESA_REQ),
270 cesaReqResources);
271 #if (MV_CESA_VERSION >= 3)
272 mvOsPrintf("chainLength=%u\n",cesaChainLength);
273 #else
274 mvOsPrintf("\n");
275 #endif
276
277 mvOsPrintf("pSAD=%p, maxSA=%d, sizeSA=%ld bytes\n",
278 pCesaSAD, cesaMaxSA, sizeof(MV_CESA_SA));
279
280 mvOsPrintf("\n");
281
282 mvCesaDebugRegs();
283 mvCesaDebugStats();
284 mvCesaDebugStatsClear();
285 }
286
287 void mvCesaDebugDescriptor(MV_CESA_DESC* pDesc)
288 {
289 mvOsPrintf("config=0x%08x, crSrcOffs=0x%04x, crDstOffs=0x%04x\n",
290 pDesc->config, pDesc->cryptoSrcOffset, pDesc->cryptoDstOffset);
291
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);
295
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);
299 }
300
301 void mvCesaDebugQueue(int mode)
302 {
303 mvOsPrintf("\n\t CESA Request Queue:\n\n");
304
305 mvOsPrintf("pFirstReq=%p, pLastReq=%p, qDepth=%d, reqSize=%ld bytes\n",
306 pCesaReqFirst, pCesaReqLast, cesaQueueDepth, sizeof(MV_CESA_REQ));
307
308 mvOsPrintf("pEmpty=%p, pProcess=%p, qResources=%d\n",
309 pCesaReqEmpty, pCesaReqProcess,
310 cesaReqResources);
311
312 if(mode != 0)
313 {
314 int count = 0;
315 MV_CESA_REQ* pReq = pCesaReqFirst;
316
317 for(count=0; count<cesaQueueDepth; count++)
318 {
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)
324 {
325 int frag;
326
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++)
331 {
332 mvOsPrintf("#%d: pDmaFirst=%p, pDesc=%p\n", frag,
333 pReq->dma[frag].pDmaFirst, &pReq->pCesaDesc[frag]);
334 }
335 }
336 if(mode > 1)
337 {
338 /* Print out Command */
339 mvCesaDebugCmd(pReq->pCmd, mode);
340
341 /* Print out Descriptor */
342 mvCesaDebugDescriptor(&pReq->pCesaDesc[0]);
343 }
344 pReq++;
345 }
346 }
347 }
348
349
350 void mvCesaDebugSramSA(MV_CESA_SRAM_SA* pSramSA, int mode)
351 {
352 if(pSramSA == NULL)
353 {
354 mvOsPrintf("cesaSramSA: Unexpected pSramSA=%p\n", pSramSA);
355 return;
356 }
357 mvOsPrintf("pSramSA=%p, sizeSramSA=%ld bytes\n",
358 pSramSA, sizeof(MV_CESA_SRAM_SA));
359
360 if(mode != 0)
361 {
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);
365
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);
369
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);
373 }
374 }
375
376 void mvCesaDebugSA(short sid, int mode)
377 {
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];
384
385 if( (pSA->valid) || ((pSA->count != 0) && (mode > 0)) || (mode >= 2) )
386 {
387 mvOsPrintf("\n\nCESA SA Entry #%d (%p) - %s (count=%d)\n",
388 sid, pSA,
389 pSA->valid ? "Valid" : "Invalid", pSA->count);
390
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)
396 {
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");
401 }
402 if(oper != MV_CESA_CRYPTO_ONLY)
403 {
404 macMode = (pSA->config & MV_CESA_MAC_MODE_MASK) >> MV_CESA_MAC_MODE_OFFSET;
405 mvOsPrintf("- %s ", mvCesaDebugMacModeStr(macMode));
406 }
407 mvOsPrintf("\n");
408
409 if(mode > 0)
410 {
411 mvOsPrintf("config=0x%08x, cryptoKeySize=%d, digestSize=%d\n",
412 pCesaSAD[sid].config, pCesaSAD[sid].cryptoKeyLength,
413 pCesaSAD[sid].digestSize);
414
415 mvCesaDebugSramSA(pCesaSAD[sid].pSramSA, mode);
416 }
417 }
418 }
419
420
421 /**/
422 void mvCesaDebugSram(int mode)
423 {
424 mvOsPrintf("\n\t SRAM contents: size=%ld, pVirt=%p\n\n",
425 sizeof(MV_CESA_SRAM_MAP), cesaSramVirtPtr);
426
427 mvOsPrintf("\n\t Sram buffer: size=%d, pVirt=%p\n",
428 MV_CESA_MAX_BUF_SIZE, cesaSramVirtPtr->buf);
429 if(mode != 0)
430 mvDebugMemDump(cesaSramVirtPtr->buf, 64, 1);
431
432 mvOsPrintf("\n");
433 mvOsPrintf("\n\t Sram descriptor: size=%ld, pVirt=%p\n",
434 sizeof(MV_CESA_DESC), &cesaSramVirtPtr->desc);
435 if(mode != 0)
436 {
437 mvOsPrintf("\n");
438 mvCesaDebugDescriptor(&cesaSramVirtPtr->desc);
439 }
440 mvOsPrintf("\n\t Sram IV: size=%d, pVirt=%p\n",
441 MV_CESA_MAX_IV_LENGTH, &cesaSramVirtPtr->cryptoIV);
442 if(mode != 0)
443 {
444 mvOsPrintf("\n");
445 mvDebugMemDump(cesaSramVirtPtr->cryptoIV, MV_CESA_MAX_IV_LENGTH, 1);
446 }
447 mvOsPrintf("\n");
448 mvCesaDebugSramSA(&cesaSramVirtPtr->sramSA, 0);
449 }
450
451 void mvCesaDebugSAD(int mode)
452 {
453 int sid;
454
455 mvOsPrintf("\n\t Cesa SAD status: pSAD=%p, maxSA=%d\n",
456 pCesaSAD, cesaMaxSA);
457
458 for(sid=0; sid<cesaMaxSA; sid++)
459 {
460 mvCesaDebugSA(sid, mode);
461 }
462 }
463
464 void mvCesaDebugStats(void)
465 {
466 mvOsPrintf("\n\t Cesa Statistics\n");
467
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);
475 #endif
476 mvOsPrintf("\n");
477 mvOsPrintf("proc=%u, ready=%u, notReady=%u\n",
478 cesaStats.procCount, cesaStats.readyCount, cesaStats.notReadyCount);
479 }
480
481 void mvCesaDebugStatsClear(void)
482 {
483 memset(&cesaStats, 0, sizeof(cesaStats));
484 }
This page took 0.071283 seconds and 5 git commands to generate.