| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2012, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: berr.h $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/9 $ |
|---|
| 12 | * $brcm_Date: 2/21/12 1:59p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /magnum/basemodules/err/berr.h $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/9 2/21/12 1:59p erickson |
|---|
| 21 | * SW7425-2130: add new DBG options for compact debug mode |
|---|
| 22 | * |
|---|
| 23 | * Hydra_Software_Devel/8 6/17/04 5:52p jasonh |
|---|
| 24 | * PR 11575: fixed trace macro to prevent argument from being evaluated |
|---|
| 25 | * twice. |
|---|
| 26 | * |
|---|
| 27 | * Hydra_Software_Devel/7 10/22/03 3:20p vsilyaev |
|---|
| 28 | * Added BERR_NOT_SUPPORTED error code. |
|---|
| 29 | * |
|---|
| 30 | * Hydra_Software_Devel/6 5/20/03 3:57p dlwin |
|---|
| 31 | * Added a missing '(' with macro BERR_MAKE_CODE(). |
|---|
| 32 | * |
|---|
| 33 | * Hydra_Software_Devel/5 3/24/03 11:56a jasonh |
|---|
| 34 | * Added memory specific errors and leaked resource error. Added initial |
|---|
| 35 | * pass at documentation for all objects. |
|---|
| 36 | * |
|---|
| 37 | * Hydra_Software_Devel/4 3/11/03 9:53p vsilyaev |
|---|
| 38 | * Replace BERR_SYS_ERROR to BERR_OS_ERROR |
|---|
| 39 | * |
|---|
| 40 | * Hydra_Software_Devel/3 3/10/03 2:43p vsilyaev |
|---|
| 41 | * Use standard macro for debug builds. |
|---|
| 42 | * Defined new error code. |
|---|
| 43 | * Fixed in the BERR_TRACE macro. |
|---|
| 44 | * |
|---|
| 45 | * Hydra_Software_Devel/2 3/5/03 4:07p marcusk |
|---|
| 46 | * Removed space from end of multi-line macros (causes problems with some |
|---|
| 47 | * compilers) |
|---|
| 48 | * |
|---|
| 49 | ***************************************************************************/ |
|---|
| 50 | #ifndef BERR_H__ |
|---|
| 51 | #define BERR_H__ |
|---|
| 52 | |
|---|
| 53 | /*=Module Overview: ******************************************************** |
|---|
| 54 | The purpose of this module is to define error codes returned by all |
|---|
| 55 | modules, including the porting interface and syslib modules. |
|---|
| 56 | |
|---|
| 57 | It is recommended that all functions should return a BERR_Code. |
|---|
| 58 | It is required that APIs must propogate unhandled error codes. Therefore, |
|---|
| 59 | if a function calls another function that returns and error code, it must |
|---|
| 60 | be able to return an error code. |
|---|
| 61 | |
|---|
| 62 | This module includes support for two different kinds of error codes: |
|---|
| 63 | standard error codes and module specific error codes. Both of which can |
|---|
| 64 | be used simultaneously within the same module. |
|---|
| 65 | |
|---|
| 66 | Standard error codes are included as part of the BERR module header file. |
|---|
| 67 | Module specific error codes are defined in the module specific header |
|---|
| 68 | files using BERR_MAKE_CODE. |
|---|
| 69 | ****************************************************************************/ |
|---|
| 70 | |
|---|
| 71 | /*************************************************************************** |
|---|
| 72 | Summary: |
|---|
| 73 | Standard error code type. |
|---|
| 74 | |
|---|
| 75 | Description: |
|---|
| 76 | This error code may be a module specific error code created with |
|---|
| 77 | BERR_MAKE_CODE or be one of the standard error codes: |
|---|
| 78 | o BERR_SUCCESS |
|---|
| 79 | o BERR_NOT_INITIALIZED |
|---|
| 80 | o BERR_INVALID_PARAMETER |
|---|
| 81 | o BERR_OUT_OF_SYSTEM_MEMORY |
|---|
| 82 | o BERR_OUT_OF_DEVICE_MEMORY |
|---|
| 83 | o BERR_TIMEOUT |
|---|
| 84 | o BERR_OS_ERROR |
|---|
| 85 | o BERR_LEAKED_RESOURCE |
|---|
| 86 | o BERR_NOT_SUPPORTED |
|---|
| 87 | o BERR_UNKNOWN |
|---|
| 88 | ****************************************************************************/ |
|---|
| 89 | typedef uint32_t BERR_Code; |
|---|
| 90 | |
|---|
| 91 | /* standard error codes */ |
|---|
| 92 | |
|---|
| 93 | #define BERR_SUCCESS 0 /* success (always zero) */ |
|---|
| 94 | #define BERR_NOT_INITIALIZED 1 /* parameter not initialized */ |
|---|
| 95 | #define BERR_INVALID_PARAMETER 2 /* parameter is invalid */ |
|---|
| 96 | #define BERR_OUT_OF_SYSTEM_MEMORY 3 /* out of KNI module memory */ |
|---|
| 97 | #define BERR_OUT_OF_DEVICE_MEMORY 4 /* out of MEM module memory */ |
|---|
| 98 | #define BERR_TIMEOUT 5 /* reached timeout limit */ |
|---|
| 99 | #define BERR_OS_ERROR 6 /* generic OS error */ |
|---|
| 100 | #define BERR_LEAKED_RESOURCE 7 /* resource being freed has attached |
|---|
| 101 | resources that haven't been freed */ |
|---|
| 102 | #define BERR_NOT_SUPPORTED 8 /* requested feature is not supported */ |
|---|
| 103 | #define BERR_UNKNOWN 9 /* unknown */ |
|---|
| 104 | |
|---|
| 105 | /* {private} error code masks */ |
|---|
| 106 | #define BERR_P_ID_MASK UINT32_C(0xFFFF0000) /* {private} */ |
|---|
| 107 | #define BERR_P_ID_SHIFT 16 /* {private} */ |
|---|
| 108 | #define BERR_P_NUM_MASK UINT32_C(0x0000FFFF) /* {private} */ |
|---|
| 109 | |
|---|
| 110 | /*************************************************************************** |
|---|
| 111 | Summary: |
|---|
| 112 | Trace macro. |
|---|
| 113 | |
|---|
| 114 | Description: |
|---|
| 115 | Whenever an error code is stored (not BERR_SUCCESS), it must be wrapped |
|---|
| 116 | with the debugging macro BERR_TRACE(). This wrapping will occur when an |
|---|
| 117 | error code is initially detected and also occurs when a called function |
|---|
| 118 | returns a BERR_Code. |
|---|
| 119 | |
|---|
| 120 | When debugging is off, this macro does nothing. When debugging is on, |
|---|
| 121 | this macro allows logging of the initial location of the error with the |
|---|
| 122 | actual defined name (not just the hex number). By wrapping functions |
|---|
| 123 | that return error codes, this macro also allows logging of the actual |
|---|
| 124 | stack directly to the error itself. |
|---|
| 125 | |
|---|
| 126 | Input: |
|---|
| 127 | code - Specific error code or function capable of returning an error |
|---|
| 128 | code. |
|---|
| 129 | |
|---|
| 130 | Returns: |
|---|
| 131 | The error code specified is returned without modification. |
|---|
| 132 | ****************************************************************************/ |
|---|
| 133 | #if BDBG_DEBUG_BUILD |
|---|
| 134 | #if B_REFSW_DEBUG_COMPACT_ERR |
|---|
| 135 | #define BERR_TRACE(code) (BDBG_P_PrintError(__FILE__, __LINE__, NULL, code)) |
|---|
| 136 | #else |
|---|
| 137 | #define BERR_TRACE(code) (BDBG_P_PrintError(__FILE__, __LINE__, #code, code)) |
|---|
| 138 | #endif |
|---|
| 139 | #else |
|---|
| 140 | #define BERR_TRACE(code) (code) |
|---|
| 141 | #endif |
|---|
| 142 | |
|---|
| 143 | /*************************************************************************** |
|---|
| 144 | Summary: |
|---|
| 145 | Extracts the module ID from a given error code. |
|---|
| 146 | |
|---|
| 147 | Description: |
|---|
| 148 | If BERR_MAKE_CODE was used to create the error code, this macro returns |
|---|
| 149 | the ID used to create the error code. |
|---|
| 150 | |
|---|
| 151 | Input: |
|---|
| 152 | code - Source error code. |
|---|
| 153 | |
|---|
| 154 | Returns: |
|---|
| 155 | ID stored in error code. |
|---|
| 156 | ****************************************************************************/ |
|---|
| 157 | #define BERR_GET_ID(code) \ |
|---|
| 158 | ((((BERR_Code)(code)) & BERR_P_ID_MASK) >> BERR_P_ID_SHIFT) |
|---|
| 159 | |
|---|
| 160 | /*************************************************************************** |
|---|
| 161 | Summary: |
|---|
| 162 | Extracts the unique number from a given error code. |
|---|
| 163 | |
|---|
| 164 | Description: |
|---|
| 165 | If BERR_MAKE_CODE was used to create the error code, this macro returns |
|---|
| 166 | the unique number used to create the error code. |
|---|
| 167 | |
|---|
| 168 | Input: |
|---|
| 169 | code - Source error code. |
|---|
| 170 | |
|---|
| 171 | Returns: |
|---|
| 172 | Unique number stored in error code. |
|---|
| 173 | ****************************************************************************/ |
|---|
| 174 | #define BERR_GET_NUM(code) \ |
|---|
| 175 | (((BERR_Code)(code)) & BERR_P_NUM_MASK) |
|---|
| 176 | |
|---|
| 177 | /*************************************************************************** |
|---|
| 178 | Summary: |
|---|
| 179 | Module specific error code generator. |
|---|
| 180 | |
|---|
| 181 | Description: |
|---|
| 182 | If the module needs error codes that aren't standard, the module may |
|---|
| 183 | use this mechanism to create module specific error codes. These codes |
|---|
| 184 | are guaranteed not to conflict with another module's specific error |
|---|
| 185 | codes. |
|---|
| 186 | |
|---|
| 187 | If this mechanism is used, a unique ID must be assigned to the module |
|---|
| 188 | and placed in the berr_ids.h file. The module uses this ID along with |
|---|
| 189 | a unique number to create a unique error code. |
|---|
| 190 | |
|---|
| 191 | Input: |
|---|
| 192 | id - Module specific ID from berr_ids.h |
|---|
| 193 | num - Unique number assigned by the module. |
|---|
| 194 | |
|---|
| 195 | Returns: |
|---|
| 196 | Module specific error code. |
|---|
| 197 | ****************************************************************************/ |
|---|
| 198 | #define BERR_MAKE_CODE(id, num) \ |
|---|
| 199 | (((((BERR_Code)(id)) << BERR_P_ID_SHIFT) & BERR_P_ID_MASK) | \ |
|---|
| 200 | (((BERR_Code)(num)) & BERR_P_NUM_MASK)) |
|---|
| 201 | |
|---|
| 202 | #endif /* #ifndef BERR_H__ */ |
|---|
| 203 | |
|---|
| 204 | /* end of file */ |
|---|