error.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * SPDX-License-Identifier: GPL-2.0-only
  3. *
  4. * Copyright (c) 2023 Realtek Semiconductor Corp. All rights reserved.
  5. */
  6. #ifndef __COMMON_ERROR_H__
  7. #define __COMMON_ERROR_H__
  8. /*
  9. * Include Files
  10. */
  11. #if defined(RTK_PHYDRV_IN_LINUX)
  12. #include "type.h"
  13. #else
  14. #include <common/type.h>
  15. #endif
  16. /*
  17. * Data Type Declaration
  18. */
  19. typedef enum rt_error_common_e
  20. {
  21. RT_ERR_FAILED = -1, /* General Error */
  22. /* 0x0000xxxx for common error code */
  23. RT_ERR_OK = 0, /* 0x00000000, OK */
  24. RT_ERR_INPUT = 0xF001, /* 0x0000F001, invalid input parameter */
  25. RT_ERR_UNIT_ID, /* 0x0000F002, invalid unit id */
  26. RT_ERR_PORT_ID, /* 0x0000F003, invalid port id */
  27. RT_ERR_PORT_MASK, /* 0x0000F004, invalid port mask */
  28. RT_ERR_PORT_LINKDOWN, /* 0x0000F005, link down port status */
  29. RT_ERR_ENTRY_INDEX, /* 0x0000F006, invalid entry index */
  30. RT_ERR_NULL_POINTER, /* 0x0000F007, input parameter is null pointer */
  31. RT_ERR_QUEUE_ID, /* 0x0000F008, invalid queue id */
  32. RT_ERR_QUEUE_NUM, /* 0x0000F009, invalid queue number */
  33. RT_ERR_BUSYWAIT_TIMEOUT, /* 0x0000F00a, busy watting time out */
  34. RT_ERR_MAC, /* 0x0000F00b, invalid mac address */
  35. RT_ERR_OUT_OF_RANGE, /* 0x0000F00c, input parameter out of range */
  36. RT_ERR_CHIP_NOT_SUPPORTED, /* 0x0000F00d, functions not supported by this chip model */
  37. RT_ERR_SMI, /* 0x0000F00e, SMI error */
  38. RT_ERR_NOT_INIT, /* 0x0000F00f, The module is not initial */
  39. RT_ERR_CHIP_NOT_FOUND, /* 0x0000F010, The chip can not found */
  40. RT_ERR_NOT_ALLOWED, /* 0x0000F011, actions not allowed by the function */
  41. RT_ERR_DRIVER_NOT_FOUND, /* 0x0000F012, The driver can not found */
  42. RT_ERR_SEM_LOCK_FAILED, /* 0x0000F013, Failed to lock semaphore */
  43. RT_ERR_SEM_UNLOCK_FAILED, /* 0x0000F014, Failed to unlock semaphore */
  44. RT_ERR_THREAD_EXIST, /* 0x0000F015, Thread exist */
  45. RT_ERR_THREAD_CREATE_FAILED, /* 0x0000F016, Thread create fail */
  46. RT_ERR_FWD_ACTION, /* 0x0000F017, Invalid forwarding Action */
  47. RT_ERR_IPV4_ADDRESS, /* 0x0000F018, Invalid IPv4 address */
  48. RT_ERR_IPV6_ADDRESS, /* 0x0000F019, Invalid IPv6 address */
  49. RT_ERR_PRIORITY, /* 0x0000F01a, Invalid Priority value */
  50. RT_ERR_FID, /* 0x0000F01b, invalid fid */
  51. RT_ERR_ENTRY_NOTFOUND, /* 0x0000F01c, specified entry not found */
  52. RT_ERR_DROP_PRECEDENCE, /* 0x0000F01d, invalid drop precedence */
  53. RT_ERR_NOT_FINISH, /* 0x0000F01e, Action not finish, still need to wait */
  54. RT_ERR_TIMEOUT, /* 0x0000F01f, Time out */
  55. RT_ERR_REG_ARRAY_INDEX_1, /* 0x0000F020, invalid index 1 of register array */
  56. RT_ERR_REG_ARRAY_INDEX_2, /* 0x0000F021, invalid index 2 of register array */
  57. RT_ERR_ETHER_TYPE, /* 0x0000F022, invalid ether type */
  58. RT_ERR_MBUF_PKT_NOT_AVAILABLE, /* 0x0000F023, mbuf->packet is not available */
  59. RT_ERR_QOS_INVLD_RSN, /* 0x0000F024, invalid pkt to CPU reason */
  60. RT_ERR_CB_FUNCTION_EXIST, /* 0x0000F025, Callback function exist */
  61. RT_ERR_CB_FUNCTION_FULL, /* 0x0000F026, Callback function number is full */
  62. RT_ERR_CB_FUNCTION_NOT_FOUND, /* 0x0000F027, Callback function can not found */
  63. RT_ERR_TBL_FULL, /* 0x0000F028, The table is full */
  64. RT_ERR_TRUNK_ID, /* 0x0000F029, invalid trunk id */
  65. RT_ERR_TYPE, /* 0x0000F02a, invalid type */
  66. RT_ERR_ENTRY_EXIST, /* 0x0000F02b, entry exists */
  67. RT_ERR_CHIP_UNDEFINED_VALUE, /* 0x0000F02c, chip returned an undefined value */
  68. RT_ERR_EXCEEDS_CAPACITY, /* 0x0000F02d, exceeds the capacity of hardware */
  69. RT_ERR_ENTRY_REFERRED, /* 0x0000F02e, entry is still being referred */
  70. RT_ERR_OPER_DENIED, /* 0x0000F02f, operation denied */
  71. RT_ERR_PORT_NOT_SUPPORTED, /* 0x0000F030, functions not supported by this port */
  72. RT_ERR_SOCKET, /* 0x0000F031, socket error */
  73. RT_ERR_MEM_ALLOC, /* 0x0000F032, insufficient memory resource */
  74. RT_ERR_ABORT, /* 0x0000F033, operation aborted */
  75. RT_ERR_DEV_ID, /* 0x0000F034, invalid device id */
  76. RT_ERR_DRIVER_NOT_SUPPORTED, /* 0x0000F035, functions not supported by this driver */
  77. RT_ERR_NOT_SUPPORTED, /* 0x0000F036, functions not supported */
  78. RT_ERR_SER, /* 0x0000F037, ECC or parity error */
  79. RT_ERR_MEM_NOT_ALIGN, /* 0x0000F038, memory address is not aligned */
  80. RT_ERR_SEM_FAKELOCK_OK, /* 0x0000F039, attach thread lock a semaphore which was already locked */
  81. RT_ERR_CHECK_FAILED, /* 0x0000F03a, check result is failed */
  82. RT_ERR_COMMON_END = 0xFFFF /* The symbol is the latest symbol of common error */
  83. } rt_error_common_t;
  84. /*
  85. * Macro Definition
  86. */
  87. #define RT_PARAM_CHK(expr, errCode)\
  88. do {\
  89. if ((int32)(expr)) {\
  90. return errCode; \
  91. }\
  92. } while (0)
  93. #define RT_PARAM_CHK_EHDL(expr, errCode, err_hdl)\
  94. do {\
  95. if ((int32)(expr)) {\
  96. {err_hdl}\
  97. return errCode; \
  98. }\
  99. } while (0)
  100. #define RT_INIT_CHK(state)\
  101. do {\
  102. if (INIT_COMPLETED != (state)) {\
  103. return RT_ERR_NOT_INIT;\
  104. }\
  105. } while (0)
  106. #define RT_INIT_REENTRY_CHK(state)\
  107. do {\
  108. if (INIT_COMPLETED == (state)) {\
  109. osal_printf(" %s had already been initialized!\n", __FUNCTION__);\
  110. return RT_ERR_OK;\
  111. }\
  112. } while (0)
  113. #define RT_INIT_REENTRY_CHK_NO_WARNING(state)\
  114. do {\
  115. if (INIT_COMPLETED == (state)) {\
  116. return RT_ERR_OK;\
  117. }\
  118. } while (0)
  119. #define RT_ERR_CHK(op, ret)\
  120. do {\
  121. if ((ret = (op)) != RT_ERR_OK)\
  122. return ret;\
  123. } while(0)
  124. #define RT_ERR_HDL(op, errHandle, ret)\
  125. do {\
  126. if ((ret = (op)) != RT_ERR_OK)\
  127. goto errHandle;\
  128. } while(0)
  129. #define RT_ERR_CHK_EHDL(op, ret, err_hdl)\
  130. do {\
  131. if ((ret = (op)) != RT_ERR_OK)\
  132. {\
  133. {err_hdl}\
  134. return ret;\
  135. }\
  136. } while(0)
  137. #define RT_NULL_HDL(pointer, err_label)\
  138. do {\
  139. if (NULL == (pointer)) {\
  140. goto err_label;\
  141. }\
  142. } while (0)
  143. #define RT_ERR_VOID_CHK(op, ret)\
  144. do {\
  145. if ((ret = (op)) != RT_ERR_OK) {\
  146. osal_printf("Fail in %s %d, ret %x!\n", __FUNCTION__, __LINE__, ret);\
  147. return ;}\
  148. } while(0)
  149. #endif /* __COMMON_ERROR_H__ */