| 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 | |
| 66 | |
| 67 | /* includes */ |
| 68 | #include "mvOs.h" |
| 69 | #include "mv802_3.h" |
| 70 | #include "mvCommon.h" |
| 71 | #include "mvDebug.h" |
| 72 | |
| 73 | /* Global variables effect on behave MV_DEBUG_PRINT and MV_DEBUG_CODE macros |
| 74 | * mvDebug - map of bits (one for each module) bit=1 means enable |
| 75 | * debug code and messages for this module |
| 76 | * mvModuleDebug - array of 32 bits varables one for each module |
| 77 | */ |
| 78 | MV_U32 mvDebug = 0; |
| 79 | MV_U32 mvDebugModules[MV_MODULE_MAX]; |
| 80 | |
| 81 | /* Init mvModuleDebug array to default values */ |
| 82 | void mvDebugInit(void) |
| 83 | { |
| 84 | int bit; |
| 85 | |
| 86 | mvDebug = 0; |
| 87 | for(bit=0; bit<MV_MODULE_MAX; bit++) |
| 88 | { |
| 89 | mvDebugModules[bit] = MV_DEBUG_FLAG_ERR | MV_DEBUG_FLAG_STATS; |
| 90 | mvDebug |= MV_BIT_MASK(bit); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | void mvDebugModuleEnable(MV_MODULE_ID module, MV_BOOL isEnable) |
| 95 | { |
| 96 | if (isEnable) |
| 97 | { |
| 98 | MV_BIT_SET(mvDebug, module); |
| 99 | } |
| 100 | else |
| 101 | MV_BIT_CLEAR(mvDebug, module); |
| 102 | } |
| 103 | |
| 104 | void mvDebugModuleSetFlags(MV_MODULE_ID module, MV_U32 flags) |
| 105 | { |
| 106 | mvDebugModules[module] |= flags; |
| 107 | } |
| 108 | |
| 109 | void mvDebugModuleClearFlags(MV_MODULE_ID module, MV_U32 flags) |
| 110 | { |
| 111 | mvDebugModules[module] &= ~flags; |
| 112 | } |
| 113 | |
| 114 | /* Dump memory in specific format: |
| 115 | * address: X1X1X1X1 X2X2X2X2 ... X8X8X8X8 |
| 116 | */ |
| 117 | void mvDebugMemDump(void* addr, int size, int access) |
| 118 | { |
| 119 | int i, j; |
| 120 | MV_U32 memAddr = (MV_U32)addr; |
| 121 | |
| 122 | if(access == 0) |
| 123 | access = 1; |
| 124 | |
| 125 | if( (access != 4) && (access != 2) && (access != 1) ) |
| 126 | { |
| 127 | mvOsPrintf("%d wrong access size. Access must be 1 or 2 or 4\n", |
| 128 | access); |
| 129 | return; |
| 130 | } |
| 131 | memAddr = MV_ALIGN_DOWN( (unsigned int)addr, 4); |
| 132 | size = MV_ALIGN_UP(size, 4); |
| 133 | addr = (void*)MV_ALIGN_DOWN( (unsigned int)addr, access); |
| 134 | while(size > 0) |
| 135 | { |
| 136 | mvOsPrintf("%08x: ", memAddr); |
| 137 | i = 0; |
| 138 | /* 32 bytes in the line */ |
| 139 | while(i < 32) |
| 140 | { |
| 141 | if(memAddr >= (MV_U32)addr) |
| 142 | { |
| 143 | switch(access) |
| 144 | { |
| 145 | case 1: |
| 146 | if( memAddr == CPU_PHY_MEM(memAddr) ) |
| 147 | { |
| 148 | mvOsPrintf("%02x ", MV_MEMIO8_READ(memAddr)); |
| 149 | } |
| 150 | else |
| 151 | { |
| 152 | mvOsPrintf("%02x ", *((MV_U8*)memAddr)); |
| 153 | } |
| 154 | break; |
| 155 | |
| 156 | case 2: |
| 157 | if( memAddr == CPU_PHY_MEM(memAddr) ) |
| 158 | { |
| 159 | mvOsPrintf("%04x ", MV_MEMIO16_READ(memAddr)); |
| 160 | } |
| 161 | else |
| 162 | { |
| 163 | mvOsPrintf("%04x ", *((MV_U16*)memAddr)); |
| 164 | } |
| 165 | break; |
| 166 | |
| 167 | case 4: |
| 168 | if( memAddr == CPU_PHY_MEM(memAddr) ) |
| 169 | { |
| 170 | mvOsPrintf("%08x ", MV_MEMIO32_READ(memAddr)); |
| 171 | } |
| 172 | else |
| 173 | { |
| 174 | mvOsPrintf("%08x ", *((MV_U32*)memAddr)); |
| 175 | } |
| 176 | break; |
| 177 | } |
| 178 | } |
| 179 | else |
| 180 | { |
| 181 | for(j=0; j<(access*2+1); j++) |
| 182 | mvOsPrintf(" "); |
| 183 | } |
| 184 | i += access; |
| 185 | memAddr += access; |
| 186 | size -= access; |
| 187 | if(size <= 0) |
| 188 | break; |
| 189 | } |
| 190 | mvOsPrintf("\n"); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | void mvDebugPrintBufInfo(BUF_INFO* pBufInfo, int size, int access) |
| 195 | { |
| 196 | if(pBufInfo == NULL) |
| 197 | { |
| 198 | mvOsPrintf("\n!!! pBufInfo = NULL\n"); |
| 199 | return; |
| 200 | } |
| 201 | mvOsPrintf("\n*** pBufInfo=0x%x, cmdSts=0x%08x, pBuf=0x%x, bufSize=%d\n", |
| 202 | (unsigned int)pBufInfo, |
| 203 | (unsigned int)pBufInfo->cmdSts, |
| 204 | (unsigned int)pBufInfo->pBuff, |
| 205 | (unsigned int)pBufInfo->bufSize); |
| 206 | mvOsPrintf("pData=0x%x, byteCnt=%d, pNext=0x%x, uInfo1=0x%x, uInfo2=0x%x\n", |
| 207 | (unsigned int)pBufInfo->pData, |
| 208 | (unsigned int)pBufInfo->byteCnt, |
| 209 | (unsigned int)pBufInfo->pNextBufInfo, |
| 210 | (unsigned int)pBufInfo->userInfo1, |
| 211 | (unsigned int)pBufInfo->userInfo2); |
| 212 | if(pBufInfo->pData != NULL) |
| 213 | { |
| 214 | if(size > pBufInfo->byteCnt) |
| 215 | size = pBufInfo->byteCnt; |
| 216 | mvDebugMemDump(pBufInfo->pData, size, access); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | void mvDebugPrintPktInfo(MV_PKT_INFO* pPktInfo, int size, int access) |
| 221 | { |
| 222 | int frag, len; |
| 223 | |
| 224 | if(pPktInfo == NULL) |
| 225 | { |
| 226 | mvOsPrintf("\n!!! pPktInfo = NULL\n"); |
| 227 | return; |
| 228 | } |
| 229 | mvOsPrintf("\npPkt=%p, stat=0x%08x, numFr=%d, size=%d, pFr=%p, osInfo=0x%lx\n", |
| 230 | pPktInfo, pPktInfo->status, pPktInfo->numFrags, pPktInfo->pktSize, |
| 231 | pPktInfo->pFrags, pPktInfo->osInfo); |
| 232 | |
| 233 | for(frag=0; frag<pPktInfo->numFrags; frag++) |
| 234 | { |
| 235 | mvOsPrintf("#%2d. bufVirt=%p, bufSize=%d\n", |
| 236 | frag, pPktInfo->pFrags[frag].bufVirtPtr, |
| 237 | pPktInfo->pFrags[frag].bufSize); |
| 238 | if(size > 0) |
| 239 | { |
| 240 | len = MV_MIN((int)pPktInfo->pFrags[frag].bufSize, size); |
| 241 | mvDebugMemDump(pPktInfo->pFrags[frag].bufVirtPtr, len, access); |
| 242 | size -= len; |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | } |
| 247 | |
| 248 | void mvDebugPrintIpAddr(MV_U32 ipAddr) |
| 249 | { |
| 250 | mvOsPrintf("%d.%d.%d.%d", ((ipAddr >> 24) & 0xFF), ((ipAddr >> 16) & 0xFF), |
| 251 | ((ipAddr >> 8) & 0xFF), ((ipAddr >> 0) & 0xFF)); |
| 252 | } |
| 253 | |
| 254 | void mvDebugPrintMacAddr(const MV_U8* pMacAddr) |
| 255 | { |
| 256 | int i; |
| 257 | |
| 258 | mvOsPrintf("%02x", (unsigned int)pMacAddr[0]); |
| 259 | for(i=1; i<MV_MAC_ADDR_SIZE; i++) |
| 260 | { |
| 261 | mvOsPrintf(":%02x", pMacAddr[i]); |
| 262 | } |
| 263 | /* mvOsPrintf("\n");*/ |
| 264 | } |
| 265 | |
| 266 | |
| 267 | /******* There are three functions deals with MV_DEBUG_TIMES structure ********/ |
| 268 | |
| 269 | /* Reset MV_DEBUG_TIMES entry */ |
| 270 | void mvDebugResetTimeEntry(MV_DEBUG_TIMES* pTimeEntry, int count, char* pName) |
| 271 | { |
| 272 | pTimeEntry->begin = 0; |
| 273 | pTimeEntry->count = count; |
| 274 | pTimeEntry->end = 0; |
| 275 | pTimeEntry->left = pTimeEntry->count; |
| 276 | pTimeEntry->total = 0; |
| 277 | pTimeEntry->min = 0xFFFFFFFF; |
| 278 | pTimeEntry->max = 0x0; |
| 279 | strncpy(pTimeEntry->name, pName, sizeof(pTimeEntry->name)-1); |
| 280 | pTimeEntry->name[sizeof(pTimeEntry->name)-1] = '\0'; |
| 281 | } |
| 282 | |
| 283 | /* Print out MV_DEBUG_TIMES entry */ |
| 284 | void mvDebugPrintTimeEntry(MV_DEBUG_TIMES* pTimeEntry, MV_BOOL isTitle) |
| 285 | { |
| 286 | int num; |
| 287 | |
| 288 | if(isTitle == MV_TRUE) |
| 289 | mvOsPrintf("Event NumOfEvents TotalTime Average Min Max\n"); |
| 290 | |
| 291 | num = pTimeEntry->count-pTimeEntry->left; |
| 292 | if(num > 0) |
| 293 | { |
| 294 | mvOsPrintf("%-11s %6u 0x%08lx %6lu %6lu %6lu\n", |
| 295 | pTimeEntry->name, num, pTimeEntry->total, pTimeEntry->total/num, |
| 296 | pTimeEntry->min, pTimeEntry->max); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | /* Update MV_DEBUG_TIMES entry */ |
| 301 | void mvDebugUpdateTimeEntry(MV_DEBUG_TIMES* pTimeEntry) |
| 302 | { |
| 303 | MV_U32 delta; |
| 304 | |
| 305 | if(pTimeEntry->left > 0) |
| 306 | { |
| 307 | if(pTimeEntry->end <= pTimeEntry->begin) |
| 308 | { |
| 309 | delta = pTimeEntry->begin - pTimeEntry->end; |
| 310 | } |
| 311 | else |
| 312 | { |
| 313 | delta = ((MV_U32)0x10000 - pTimeEntry->end) + pTimeEntry->begin; |
| 314 | } |
| 315 | pTimeEntry->total += delta; |
| 316 | |
| 317 | if(delta < pTimeEntry->min) |
| 318 | pTimeEntry->min = delta; |
| 319 | |
| 320 | if(delta > pTimeEntry->max) |
| 321 | pTimeEntry->max = delta; |
| 322 | |
| 323 | pTimeEntry->left--; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | |