plog.c 4.0 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. #include <bfa_os_inc.h>
  18. #include <cs/bfa_plog.h>
  19. #include <cs/bfa_debug.h>
  20. static int
  21. plkd_validate_logrec(struct bfa_plog_rec_s *pl_rec)
  22. {
  23. if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT)
  24. && (pl_rec->log_type != BFA_PL_LOG_TYPE_STRING))
  25. return 1;
  26. if ((pl_rec->log_type != BFA_PL_LOG_TYPE_INT)
  27. && (pl_rec->log_num_ints > BFA_PL_INT_LOG_SZ))
  28. return 1;
  29. return 0;
  30. }
  31. static void
  32. bfa_plog_add(struct bfa_plog_s *plog, struct bfa_plog_rec_s *pl_rec)
  33. {
  34. u16 tail;
  35. struct bfa_plog_rec_s *pl_recp;
  36. if (plog->plog_enabled == 0)
  37. return;
  38. if (plkd_validate_logrec(pl_rec)) {
  39. bfa_assert(0);
  40. return;
  41. }
  42. tail = plog->tail;
  43. pl_recp = &(plog->plog_recs[tail]);
  44. bfa_os_memcpy(pl_recp, pl_rec, sizeof(struct bfa_plog_rec_s));
  45. pl_recp->tv = BFA_TRC_TS(plog);
  46. BFA_PL_LOG_REC_INCR(plog->tail);
  47. if (plog->head == plog->tail)
  48. BFA_PL_LOG_REC_INCR(plog->head);
  49. }
  50. void
  51. bfa_plog_init(struct bfa_plog_s *plog)
  52. {
  53. bfa_os_memset((char *)plog, 0, sizeof(struct bfa_plog_s));
  54. bfa_os_memcpy(plog->plog_sig, BFA_PL_SIG_STR, BFA_PL_SIG_LEN);
  55. plog->head = plog->tail = 0;
  56. plog->plog_enabled = 1;
  57. }
  58. void
  59. bfa_plog_str(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  60. enum bfa_plog_eid event,
  61. u16 misc, char *log_str)
  62. {
  63. struct bfa_plog_rec_s lp;
  64. if (plog->plog_enabled) {
  65. bfa_os_memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  66. lp.mid = mid;
  67. lp.eid = event;
  68. lp.log_type = BFA_PL_LOG_TYPE_STRING;
  69. lp.misc = misc;
  70. strncpy(lp.log_entry.string_log, log_str,
  71. BFA_PL_STRING_LOG_SZ - 1);
  72. lp.log_entry.string_log[BFA_PL_STRING_LOG_SZ - 1] = '\0';
  73. bfa_plog_add(plog, &lp);
  74. }
  75. }
  76. void
  77. bfa_plog_intarr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  78. enum bfa_plog_eid event,
  79. u16 misc, u32 *intarr, u32 num_ints)
  80. {
  81. struct bfa_plog_rec_s lp;
  82. u32 i;
  83. if (num_ints > BFA_PL_INT_LOG_SZ)
  84. num_ints = BFA_PL_INT_LOG_SZ;
  85. if (plog->plog_enabled) {
  86. bfa_os_memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  87. lp.mid = mid;
  88. lp.eid = event;
  89. lp.log_type = BFA_PL_LOG_TYPE_INT;
  90. lp.misc = misc;
  91. for (i = 0; i < num_ints; i++)
  92. bfa_os_assign(lp.log_entry.int_log[i],
  93. intarr[i]);
  94. lp.log_num_ints = (u8) num_ints;
  95. bfa_plog_add(plog, &lp);
  96. }
  97. }
  98. void
  99. bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  100. enum bfa_plog_eid event,
  101. u16 misc, struct fchs_s *fchdr)
  102. {
  103. struct bfa_plog_rec_s lp;
  104. u32 *tmp_int = (u32 *) fchdr;
  105. u32 ints[BFA_PL_INT_LOG_SZ];
  106. if (plog->plog_enabled) {
  107. bfa_os_memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  108. ints[0] = tmp_int[0];
  109. ints[1] = tmp_int[1];
  110. ints[2] = tmp_int[4];
  111. bfa_plog_intarr(plog, mid, event, misc, ints, 3);
  112. }
  113. }
  114. void
  115. bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
  116. enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr,
  117. u32 pld_w0)
  118. {
  119. struct bfa_plog_rec_s lp;
  120. u32 *tmp_int = (u32 *) fchdr;
  121. u32 ints[BFA_PL_INT_LOG_SZ];
  122. if (plog->plog_enabled) {
  123. bfa_os_memset(&lp, 0, sizeof(struct bfa_plog_rec_s));
  124. ints[0] = tmp_int[0];
  125. ints[1] = tmp_int[1];
  126. ints[2] = tmp_int[4];
  127. ints[3] = pld_w0;
  128. bfa_plog_intarr(plog, mid, event, misc, ints, 4);
  129. }
  130. }
  131. void
  132. bfa_plog_clear(struct bfa_plog_s *plog)
  133. {
  134. plog->head = plog->tail = 0;
  135. }
  136. void
  137. bfa_plog_enable(struct bfa_plog_s *plog)
  138. {
  139. plog->plog_enabled = 1;
  140. }
  141. void
  142. bfa_plog_disable(struct bfa_plog_s *plog)
  143. {
  144. plog->plog_enabled = 0;
  145. }
  146. bfa_boolean_t
  147. bfa_plog_get_setting(struct bfa_plog_s *plog)
  148. {
  149. return (bfa_boolean_t)plog->plog_enabled;
  150. }