bfa_trc.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. #ifndef __BFA_TRC_H__
  18. #define __BFA_TRC_H__
  19. #include <bfa_os_inc.h>
  20. #ifndef BFA_TRC_MAX
  21. #define BFA_TRC_MAX (4 * 1024)
  22. #endif
  23. #ifndef BFA_TRC_TS
  24. #define BFA_TRC_TS(_trcm) ((_trcm)->ticks++)
  25. #endif
  26. struct bfa_trc_s {
  27. #ifdef __BIGENDIAN
  28. u16 fileno;
  29. u16 line;
  30. #else
  31. u16 line;
  32. u16 fileno;
  33. #endif
  34. u32 timestamp;
  35. union {
  36. struct {
  37. u32 rsvd;
  38. u32 u32;
  39. } u32;
  40. u64 u64;
  41. } data;
  42. };
  43. struct bfa_trc_mod_s {
  44. u32 head;
  45. u32 tail;
  46. u32 ntrc;
  47. u32 stopped;
  48. u32 ticks;
  49. u32 rsvd[3];
  50. struct bfa_trc_s trc[BFA_TRC_MAX];
  51. };
  52. enum {
  53. BFA_TRC_FW = 1, /* firmware modules */
  54. BFA_TRC_HAL = 2, /* BFA modules */
  55. BFA_TRC_FCS = 3, /* BFA FCS modules */
  56. BFA_TRC_LDRV = 4, /* Linux driver modules */
  57. BFA_TRC_SDRV = 5, /* Solaris driver modules */
  58. BFA_TRC_VDRV = 6, /* vmware driver modules */
  59. BFA_TRC_WDRV = 7, /* windows driver modules */
  60. BFA_TRC_AEN = 8, /* AEN module */
  61. BFA_TRC_BIOS = 9, /* bios driver modules */
  62. BFA_TRC_EFI = 10, /* EFI driver modules */
  63. BNA_TRC_WDRV = 11, /* BNA windows driver modules */
  64. BNA_TRC_VDRV = 12, /* BNA vmware driver modules */
  65. BNA_TRC_SDRV = 13, /* BNA Solaris driver modules */
  66. BNA_TRC_LDRV = 14, /* BNA Linux driver modules */
  67. BNA_TRC_HAL = 15, /* BNA modules */
  68. BFA_TRC_CNA = 16, /* Common modules */
  69. BNA_TRC_IMDRV = 17 /* BNA windows intermediate driver modules */
  70. };
  71. #define BFA_TRC_MOD_SH 10
  72. #define BFA_TRC_MOD(__mod) ((BFA_TRC_ ## __mod) << BFA_TRC_MOD_SH)
  73. /**
  74. * Define a new tracing file (module). Module should match one defined above.
  75. */
  76. #define BFA_TRC_FILE(__mod, __submod) \
  77. static int __trc_fileno = ((BFA_TRC_ ## __mod ## _ ## __submod) | \
  78. BFA_TRC_MOD(__mod))
  79. #define bfa_trc32(_trcp, _data) \
  80. __bfa_trc((_trcp)->trcmod, __trc_fileno, __LINE__, (u32)_data)
  81. #ifndef BFA_BOOT_BUILD
  82. #define bfa_trc(_trcp, _data) \
  83. __bfa_trc((_trcp)->trcmod, __trc_fileno, __LINE__, (u64)_data)
  84. #else
  85. void bfa_boot_trc(struct bfa_trc_mod_s *trcmod, u16 fileno,
  86. u16 line, u32 data);
  87. #define bfa_trc(_trcp, _data) \
  88. bfa_boot_trc((_trcp)->trcmod, __trc_fileno, __LINE__, (u32)_data)
  89. #endif
  90. static inline void
  91. bfa_trc_init(struct bfa_trc_mod_s *trcm)
  92. {
  93. trcm->head = trcm->tail = trcm->stopped = 0;
  94. trcm->ntrc = BFA_TRC_MAX;
  95. }
  96. static inline void
  97. bfa_trc_stop(struct bfa_trc_mod_s *trcm)
  98. {
  99. trcm->stopped = 1;
  100. }
  101. #ifdef FWTRC
  102. extern void dc_flush(void *data);
  103. #else
  104. #define dc_flush(data)
  105. #endif
  106. static inline void
  107. __bfa_trc(struct bfa_trc_mod_s *trcm, int fileno, int line, u64 data)
  108. {
  109. int tail = trcm->tail;
  110. struct bfa_trc_s *trc = &trcm->trc[tail];
  111. if (trcm->stopped)
  112. return;
  113. trc->fileno = (u16) fileno;
  114. trc->line = (u16) line;
  115. trc->data.u64 = data;
  116. trc->timestamp = BFA_TRC_TS(trcm);
  117. dc_flush(trc);
  118. trcm->tail = (trcm->tail + 1) & (BFA_TRC_MAX - 1);
  119. if (trcm->tail == trcm->head)
  120. trcm->head = (trcm->head + 1) & (BFA_TRC_MAX - 1);
  121. dc_flush(trcm);
  122. }
  123. static inline void
  124. __bfa_trc32(struct bfa_trc_mod_s *trcm, int fileno, int line, u32 data)
  125. {
  126. int tail = trcm->tail;
  127. struct bfa_trc_s *trc = &trcm->trc[tail];
  128. if (trcm->stopped)
  129. return;
  130. trc->fileno = (u16) fileno;
  131. trc->line = (u16) line;
  132. trc->data.u32.u32 = data;
  133. trc->timestamp = BFA_TRC_TS(trcm);
  134. dc_flush(trc);
  135. trcm->tail = (trcm->tail + 1) & (BFA_TRC_MAX - 1);
  136. if (trcm->tail == trcm->head)
  137. trcm->head = (trcm->head + 1) & (BFA_TRC_MAX - 1);
  138. dc_flush(trcm);
  139. }
  140. #ifndef BFA_PERF_BUILD
  141. #define bfa_trc_fp(_trcp, _data) bfa_trc(_trcp, _data)
  142. #else
  143. #define bfa_trc_fp(_trcp, _data)
  144. #endif
  145. #endif /* __BFA_TRC_H__ */