PageRenderTime 35ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/sys/contrib/octeon-sdk/cvmx-error.h

https://bitbucket.org/freebsd/freebsd-head/
C++ Header | 318 lines | 86 code | 21 blank | 211 comment | 0 complexity | e3b74188d06783ab99879b81f7f51f46 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, BSD-3-Clause, LGPL-2.0, LGPL-2.1, BSD-2-Clause, 0BSD, JSON, AGPL-1.0, GPL-2.0
  1. /***********************license start***************
  2. * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights
  3. * reserved.
  4. *
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. *
  13. * * Redistributions in binary form must reproduce the above
  14. * copyright notice, this list of conditions and the following
  15. * disclaimer in the documentation and/or other materials provided
  16. * with the distribution.
  17. * * Neither the name of Cavium Networks nor the names of
  18. * its contributors may be used to endorse or promote products
  19. * derived from this software without specific prior written
  20. * permission.
  21. * This Software, including technical data, may be subject to U.S. export control
  22. * laws, including the U.S. Export Administration Act and its associated
  23. * regulations, and may be subject to export or import regulations in other
  24. * countries.
  25. * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
  26. * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
  27. * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
  28. * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
  29. * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
  30. * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
  31. * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
  32. * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
  33. * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR
  34. * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
  35. ***********************license end**************************************/
  36. /**
  37. * @file
  38. *
  39. * Interface to the Octeon extended error status.
  40. *
  41. * <hr>$Revision: 44252 $<hr>
  42. */
  43. #ifndef __CVMX_ERROR_H__
  44. #define __CVMX_ERROR_H__
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. /**
  49. * There are generally many error status bits associated with a
  50. * single logical group. The enumeration below is used to
  51. * communicate high level groups to the error infastructure so
  52. * error status bits can be enable or disabled in large groups.
  53. */
  54. typedef enum
  55. {
  56. CVMX_ERROR_GROUP_INTERNAL, /* All internal blocks that can always be enabled */
  57. CVMX_ERROR_GROUP_ETHERNET, /* All errors related to network traffic that should be enabled when a port is up. Indexed by IPD number */
  58. CVMX_ERROR_GROUP_MGMT_PORT, /* All errors related to the management ethernet ports that should be enabled when a port is up. Indexed by port number (0-1) */
  59. CVMX_ERROR_GROUP_PCI, /* All errors related to PCI/PCIe when the bus is up. Index by port number (0-1) */
  60. CVMX_ERROR_GROUP_SRIO, /* All errors related to SRIO when the bus is up. Index by port number (0-1) */
  61. CVMX_ERROR_GROUP_USB, /* All errors related to USB when the port is enabled. Index by port number (0-1) */
  62. CVMX_ERROR_GROUP_LMC, /* All errors related to LMC when the controller is enabled. Index by controller number (0-1) */
  63. } cvmx_error_group_t;
  64. /**
  65. * When registering for interest in an error status register, the
  66. * type of the register needs to be known by cvmx-error. Most
  67. * registers are either IO64 or IO32, but some blocks contain
  68. * registers that can't be directly accessed. A good example of
  69. * would be PCIe extended error state stored in config space.
  70. */
  71. typedef enum
  72. {
  73. __CVMX_ERROR_REGISTER_NONE, /* Used internally */
  74. CVMX_ERROR_REGISTER_IO64, /* Status and enable registers are Octeon 64bit CSRs */
  75. CVMX_ERROR_REGISTER_IO32, /* Status and enable registers are Octeon 32bit CSRs */
  76. CVMX_ERROR_REGISTER_PCICONFIG, /* Status and enable registers are in PCI config space */
  77. CVMX_ERROR_REGISTER_SRIOMAINT, /* Status and enable registers are in SRIO maintenance space */
  78. } cvmx_error_register_t;
  79. /**
  80. * Flags representing special handling for some error registers.
  81. * These flags are passed to cvmx_error_initialize() to control
  82. * the handling of bits where the same flags were passed to the
  83. * added cvmx_error_info_t.
  84. */
  85. typedef enum
  86. {
  87. CVMX_ERROR_FLAGS_ECC_SINGLE_BIT = 1<<0, /* This is a ECC single bit error. Normally these can be ignored */
  88. CVMX_ERROR_FLAGS_CORRECTABLE = 1<<1, /* Some blocks have errors that can be silently corrected. This flags reports these */
  89. CVMX_ERROR_FLAGS_DISABLED = 1<<2, /* Flag used to signal a register should not be enable as part of the groups */
  90. } cvmx_error_flags_t;
  91. struct cvmx_error_info;
  92. /**
  93. * Error handling functions must have the following prototype.
  94. */
  95. typedef int (*cvmx_error_func_t)(const struct cvmx_error_info *info);
  96. /**
  97. * This structure is passed to all error handling functions.
  98. */
  99. typedef struct cvmx_error_info
  100. {
  101. cvmx_error_register_t reg_type; /* Type of registers used for the error */
  102. uint64_t status_addr; /* The address of the status register */
  103. uint64_t status_mask; /* Mask to apply to status register to detect asserted error */
  104. uint64_t enable_addr; /* The address of the enable register */
  105. uint64_t enable_mask; /* Mask to apply to enable register to allow error detection */
  106. cvmx_error_flags_t flags; /* Flags indicating special handling of this error */
  107. cvmx_error_group_t group; /* Group to associate this error register with */
  108. int group_index; /* Group index to associate this error register with */
  109. cvmx_error_func_t func; /* Function to call when the error is detected */
  110. uint64_t user_info; /* User supplied information for the error handler */
  111. struct
  112. {
  113. cvmx_error_register_t reg_type; /* Type of parent's register */
  114. uint64_t status_addr; /* The address of the parent's register */
  115. uint64_t status_mask; /* Mask to apply to parent's register */
  116. } parent;
  117. } cvmx_error_info_t;
  118. /**
  119. * Initalize the error status system. This should be called once
  120. * before any other functions are called. This function adds default
  121. * handlers for most all error events but does not enable them. Later
  122. * calls to cvmx_error_enable() are needed.
  123. *
  124. * @param flags Optional flags.
  125. *
  126. * @return Zero on success, negative on failure.
  127. */
  128. int cvmx_error_initialize(cvmx_error_flags_t flags);
  129. /**
  130. * Poll the error status registers and call the appropriate error
  131. * handlers. This should be called in the RSL interrupt handler
  132. * for your application or operating system.
  133. *
  134. * @return Number of error handlers called. Zero means this call
  135. * found no errors and was spurious.
  136. */
  137. int cvmx_error_poll(void);
  138. /**
  139. * Register to be called when an error status bit is set. Most users
  140. * will not need to call this function as cvmx_error_initialize()
  141. * registers default handlers for most error conditions. This function
  142. * is normally used to add more handlers without changing the existing
  143. * handlers.
  144. *
  145. * @param new_info Information about the handler for a error register. The
  146. * structure passed is copied and can be destroyed after the
  147. * call. All members of the structure must be populated, even the
  148. * parent information.
  149. *
  150. * @return Zero on success, negative on failure.
  151. */
  152. int cvmx_error_add(const cvmx_error_info_t *new_info);
  153. /**
  154. * Remove all handlers for a status register and mask. Normally
  155. * this function should not be called. Instead a new handler should be
  156. * installed to replace the existing handler. In the even that all
  157. * reporting of a error bit should be removed, then use this
  158. * function.
  159. *
  160. * @param reg_type Type of the status register to remove
  161. * @param status_addr
  162. * Status register to remove.
  163. * @param status_mask
  164. * All handlers for this status register with this mask will be
  165. * removed.
  166. * @param old_info If not NULL, this is filled with information about the handler
  167. * that was removed.
  168. *
  169. * @return Zero on success, negative on failure (not found).
  170. */
  171. int cvmx_error_remove(cvmx_error_register_t reg_type,
  172. uint64_t status_addr, uint64_t status_mask,
  173. cvmx_error_info_t *old_info);
  174. /**
  175. * Change the function and user_info for an existing error status
  176. * register. This function should be used to replace the default
  177. * handler with an application specific version as needed.
  178. *
  179. * @param reg_type Type of the status register to change
  180. * @param status_addr
  181. * Status register to change.
  182. * @param status_mask
  183. * All handlers for this status register with this mask will be
  184. * changed.
  185. * @param new_func New function to use to handle the error status
  186. * @param new_user_info
  187. * New user info parameter for the function
  188. * @param old_func If not NULL, the old function is returned. Useful for restoring
  189. * the old handler.
  190. * @param old_user_info
  191. * If not NULL, the old user info parameter.
  192. *
  193. * @return Zero on success, negative on failure
  194. */
  195. int cvmx_error_change_handler(cvmx_error_register_t reg_type,
  196. uint64_t status_addr, uint64_t status_mask,
  197. cvmx_error_func_t new_func, uint64_t new_user_info,
  198. cvmx_error_func_t *old_func, uint64_t *old_user_info);
  199. /**
  200. * Enable all error registers for a logical group. This should be
  201. * called whenever a logical group is brought online.
  202. *
  203. * @param group Logical group to enable
  204. * @param group_index
  205. * Index for the group as defined in the cvmx_error_group_t
  206. * comments.
  207. *
  208. * @return Zero on success, negative on failure.
  209. */
  210. #ifndef CVMX_BUILD_FOR_UBOOT
  211. int cvmx_error_enable_group(cvmx_error_group_t group, int group_index);
  212. #else
  213. /* Rather than conditionalize the calls throughout the executive to not enable
  214. interrupts in Uboot, simply make the enable function do nothing */
  215. static inline int cvmx_error_enable_group(cvmx_error_group_t group, int group_index)
  216. {
  217. return 0;
  218. }
  219. #endif
  220. /**
  221. * Disable all error registers for a logical group. This should be
  222. * called whenever a logical group is brought offline. Many blocks
  223. * will report spurious errors when offline unless this function
  224. * is called.
  225. *
  226. * @param group Logical group to disable
  227. * @param group_index
  228. * Index for the group as defined in the cvmx_error_group_t
  229. * comments.
  230. *
  231. * @return Zero on success, negative on failure.
  232. */
  233. #ifndef CVMX_BUILD_FOR_UBOOT
  234. int cvmx_error_disable_group(cvmx_error_group_t group, int group_index);
  235. #else
  236. /* Rather than conditionalize the calls throughout the executive to not disable
  237. interrupts in Uboot, simply make the enable function do nothing */
  238. static inline int cvmx_error_disable_group(cvmx_error_group_t group, int group_index)
  239. {
  240. return 0;
  241. }
  242. #endif
  243. /**
  244. * Enable all handlers for a specific status register mask.
  245. *
  246. * @param reg_type Type of the status register
  247. * @param status_addr
  248. * Status register address
  249. * @param status_mask
  250. * All handlers for this status register with this mask will be
  251. * enabled.
  252. *
  253. * @return Zero on success, negative on failure.
  254. */
  255. int cvmx_error_enable(cvmx_error_register_t reg_type,
  256. uint64_t status_addr, uint64_t status_mask);
  257. /**
  258. * Disable all handlers for a specific status register and mask.
  259. *
  260. * @param reg_type Type of the status register
  261. * @param status_addr
  262. * Status register address
  263. * @param status_mask
  264. * All handlers for this status register with this mask will be
  265. * disabled.
  266. *
  267. * @return Zero on success, negative on failure.
  268. */
  269. int cvmx_error_disable(cvmx_error_register_t reg_type,
  270. uint64_t status_addr, uint64_t status_mask);
  271. /**
  272. * @INTERNAL
  273. * Function for processing non leaf error status registers. This function
  274. * calls all handlers for this passed register and all children linked
  275. * to it.
  276. *
  277. * @param info Error register to check
  278. *
  279. * @return Number of error status bits found or zero if no bits were set.
  280. */
  281. int __cvmx_error_decode(const cvmx_error_info_t *info);
  282. /**
  283. * @INTERNAL
  284. * This error bit handler simply prints a message and clears the status bit
  285. *
  286. * @param info Error register to check
  287. *
  288. * @return
  289. */
  290. int __cvmx_error_display(const cvmx_error_info_t *info);
  291. #ifdef __cplusplus
  292. }
  293. #endif
  294. #endif