bfa_log.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. /**
  18. * bfa_log.h BFA log library data structure and function definition
  19. */
  20. #ifndef __BFA_LOG_H__
  21. #define __BFA_LOG_H__
  22. #include <bfa_os_inc.h>
  23. #include <defs/bfa_defs_status.h>
  24. #include <defs/bfa_defs_aen.h>
  25. /*
  26. * BFA log module definition
  27. *
  28. * To create a new module id:
  29. * Add a #define at the end of the list below. Select a value for your
  30. * definition so that it is one (1) greater than the previous
  31. * definition. Modify the definition of BFA_LOG_MODULE_ID_MAX to become
  32. * your new definition.
  33. * Should have no gaps in between the values because this is used in arrays.
  34. * IMPORTANT: AEN_IDs must be at the begining, otherwise update bfa_defs_aen.h
  35. */
  36. enum bfa_log_module_id {
  37. BFA_LOG_UNUSED_ID = 0,
  38. /* AEN defs begin */
  39. BFA_LOG_AEN_MIN = BFA_LOG_UNUSED_ID,
  40. BFA_LOG_AEN_ID_ADAPTER = BFA_LOG_AEN_MIN + BFA_AEN_CAT_ADAPTER,/* 1 */
  41. BFA_LOG_AEN_ID_PORT = BFA_LOG_AEN_MIN + BFA_AEN_CAT_PORT, /* 2 */
  42. BFA_LOG_AEN_ID_LPORT = BFA_LOG_AEN_MIN + BFA_AEN_CAT_LPORT, /* 3 */
  43. BFA_LOG_AEN_ID_RPORT = BFA_LOG_AEN_MIN + BFA_AEN_CAT_RPORT, /* 4 */
  44. BFA_LOG_AEN_ID_ITNIM = BFA_LOG_AEN_MIN + BFA_AEN_CAT_ITNIM, /* 5 */
  45. BFA_LOG_AEN_ID_TIN = BFA_LOG_AEN_MIN + BFA_AEN_CAT_TIN, /* 6 */
  46. BFA_LOG_AEN_ID_IPFC = BFA_LOG_AEN_MIN + BFA_AEN_CAT_IPFC, /* 7 */
  47. BFA_LOG_AEN_ID_AUDIT = BFA_LOG_AEN_MIN + BFA_AEN_CAT_AUDIT, /* 8 */
  48. BFA_LOG_AEN_ID_IOC = BFA_LOG_AEN_MIN + BFA_AEN_CAT_IOC, /* 9 */
  49. BFA_LOG_AEN_ID_ETHPORT = BFA_LOG_AEN_MIN + BFA_AEN_CAT_ETHPORT,/* 10 */
  50. BFA_LOG_AEN_MAX = BFA_LOG_AEN_ID_ETHPORT,
  51. /* AEN defs end */
  52. BFA_LOG_MODULE_ID_MIN = BFA_LOG_AEN_MAX,
  53. BFA_LOG_FW_ID = BFA_LOG_MODULE_ID_MIN + 1,
  54. BFA_LOG_HAL_ID = BFA_LOG_MODULE_ID_MIN + 2,
  55. BFA_LOG_FCS_ID = BFA_LOG_MODULE_ID_MIN + 3,
  56. BFA_LOG_WDRV_ID = BFA_LOG_MODULE_ID_MIN + 4,
  57. BFA_LOG_LINUX_ID = BFA_LOG_MODULE_ID_MIN + 5,
  58. BFA_LOG_SOLARIS_ID = BFA_LOG_MODULE_ID_MIN + 6,
  59. BFA_LOG_MODULE_ID_MAX = BFA_LOG_SOLARIS_ID,
  60. /* Not part of any arrays */
  61. BFA_LOG_MODULE_ID_ALL = BFA_LOG_MODULE_ID_MAX + 1,
  62. BFA_LOG_AEN_ALL = BFA_LOG_MODULE_ID_MAX + 2,
  63. BFA_LOG_DRV_ALL = BFA_LOG_MODULE_ID_MAX + 3,
  64. };
  65. /*
  66. * BFA log catalog name
  67. */
  68. #define BFA_LOG_CAT_NAME "BFA"
  69. /*
  70. * bfa log severity values
  71. */
  72. enum bfa_log_severity {
  73. BFA_LOG_INVALID = 0,
  74. BFA_LOG_CRITICAL = 1,
  75. BFA_LOG_ERROR = 2,
  76. BFA_LOG_WARNING = 3,
  77. BFA_LOG_INFO = 4,
  78. BFA_LOG_NONE = 5,
  79. BFA_LOG_LEVEL_MAX = BFA_LOG_NONE
  80. };
  81. #define BFA_LOG_MODID_OFFSET 16
  82. struct bfa_log_msgdef_s {
  83. u32 msg_id; /* message id */
  84. int attributes; /* attributes */
  85. int severity; /* severity level */
  86. char *msg_value;
  87. /* msg string */
  88. char *message;
  89. /* msg format string */
  90. int arg_type; /* argument type */
  91. int arg_num; /* number of argument */
  92. };
  93. /*
  94. * supported argument type
  95. */
  96. enum bfa_log_arg_type {
  97. BFA_LOG_S = 0, /* string */
  98. BFA_LOG_D, /* decimal */
  99. BFA_LOG_I, /* integer */
  100. BFA_LOG_O, /* oct number */
  101. BFA_LOG_U, /* unsigned integer */
  102. BFA_LOG_X, /* hex number */
  103. BFA_LOG_F, /* floating */
  104. BFA_LOG_C, /* character */
  105. BFA_LOG_L, /* double */
  106. BFA_LOG_P /* pointer */
  107. };
  108. #define BFA_LOG_ARG_TYPE 2
  109. #define BFA_LOG_ARG0 (0 * BFA_LOG_ARG_TYPE)
  110. #define BFA_LOG_ARG1 (1 * BFA_LOG_ARG_TYPE)
  111. #define BFA_LOG_ARG2 (2 * BFA_LOG_ARG_TYPE)
  112. #define BFA_LOG_ARG3 (3 * BFA_LOG_ARG_TYPE)
  113. #define BFA_LOG_GET_MOD_ID(msgid) ((msgid >> BFA_LOG_MODID_OFFSET) & 0xff)
  114. #define BFA_LOG_GET_MSG_IDX(msgid) (msgid & 0xffff)
  115. #define BFA_LOG_GET_MSG_ID(msgdef) ((msgdef)->msg_id)
  116. #define BFA_LOG_GET_MSG_FMT_STRING(msgdef) ((msgdef)->message)
  117. #define BFA_LOG_GET_SEVERITY(msgdef) ((msgdef)->severity)
  118. /*
  119. * Event attributes
  120. */
  121. #define BFA_LOG_ATTR_NONE 0
  122. #define BFA_LOG_ATTR_AUDIT 1
  123. #define BFA_LOG_ATTR_LOG 2
  124. #define BFA_LOG_ATTR_FFDC 4
  125. #define BFA_LOG_CREATE_ID(msw, lsw) \
  126. (((u32)msw << BFA_LOG_MODID_OFFSET) | lsw)
  127. struct bfa_log_mod_s;
  128. /**
  129. * callback function
  130. */
  131. typedef void (*bfa_log_cb_t)(struct bfa_log_mod_s *log_mod, u32 msg_id,
  132. const char *format, ...);
  133. struct bfa_log_mod_s {
  134. char instance_info[16]; /* instance info */
  135. int log_level[BFA_LOG_MODULE_ID_MAX + 1];
  136. /* log level for modules */
  137. bfa_log_cb_t cbfn; /* callback function */
  138. };
  139. extern int bfa_log_init(struct bfa_log_mod_s *log_mod,
  140. char *instance_name, bfa_log_cb_t cbfn);
  141. extern int bfa_log(struct bfa_log_mod_s *log_mod, u32 msg_id, ...);
  142. extern bfa_status_t bfa_log_set_level(struct bfa_log_mod_s *log_mod,
  143. int mod_id, enum bfa_log_severity log_level);
  144. extern bfa_status_t bfa_log_set_level_all(struct bfa_log_mod_s *log_mod,
  145. enum bfa_log_severity log_level);
  146. extern bfa_status_t bfa_log_set_level_aen(struct bfa_log_mod_s *log_mod,
  147. enum bfa_log_severity log_level);
  148. extern enum bfa_log_severity bfa_log_get_level(struct bfa_log_mod_s *log_mod,
  149. int mod_id);
  150. extern enum bfa_log_severity bfa_log_get_msg_level(
  151. struct bfa_log_mod_s *log_mod, u32 msg_id);
  152. /*
  153. * array of messages generated from xml files
  154. */
  155. extern struct bfa_log_msgdef_s bfa_log_msg_array[];
  156. #endif