snic_trc.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright 2014 Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This program is free software; you may redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; version 2 of the License.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  9. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  12. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  13. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  15. * SOFTWARE.
  16. */
  17. #ifndef __SNIC_TRC_H
  18. #define __SNIC_TRC_H
  19. #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
  20. extern ssize_t simple_read_from_buffer(void __user *to,
  21. size_t count,
  22. loff_t *ppos,
  23. const void *from,
  24. size_t available);
  25. extern unsigned int snic_trace_max_pages;
  26. /* Global Data structure for trace to manage trace functionality */
  27. struct snic_trc_data {
  28. u64 ts; /* Time Stamp */
  29. char *fn; /* Ptr to Function Name */
  30. u32 hno; /* SCSI Host ID */
  31. u32 tag; /* Command Tag */
  32. u64 data[5];
  33. } __attribute__((__packed__));
  34. #define SNIC_TRC_ENTRY_SZ 64 /* in Bytes */
  35. struct snic_trc {
  36. spinlock_t lock;
  37. struct snic_trc_data *buf; /* Trace Buffer */
  38. u32 max_idx; /* Max Index into trace buffer */
  39. u32 rd_idx;
  40. u32 wr_idx;
  41. bool enable; /* Control Variable for Tracing */
  42. struct dentry *trc_enable; /* debugfs file object */
  43. struct dentry *trc_file;
  44. };
  45. int snic_trc_init(void);
  46. void snic_trc_free(void);
  47. int snic_trc_debugfs_init(void);
  48. void snic_trc_debugfs_term(void);
  49. struct snic_trc_data *snic_get_trc_buf(void);
  50. int snic_get_trc_data(char *buf, int buf_sz);
  51. int snic_debugfs_init(void);
  52. void snic_debugfs_term(void);
  53. static inline void
  54. snic_trace(char *fn, u16 hno, u32 tag, u64 d1, u64 d2, u64 d3, u64 d4, u64 d5)
  55. {
  56. struct snic_trc_data *tr_rec = snic_get_trc_buf();
  57. if (!tr_rec)
  58. return;
  59. tr_rec->fn = (char *)fn;
  60. tr_rec->hno = hno;
  61. tr_rec->tag = tag;
  62. tr_rec->data[0] = d1;
  63. tr_rec->data[1] = d2;
  64. tr_rec->data[2] = d3;
  65. tr_rec->data[3] = d4;
  66. tr_rec->data[4] = d5;
  67. tr_rec->ts = jiffies; /* Update time stamp at last */
  68. }
  69. #define SNIC_TRC(_hno, _tag, d1, d2, d3, d4, d5) \
  70. do { \
  71. if (unlikely(snic_glob->trc.enable)) \
  72. snic_trace((char *)__func__, \
  73. (u16)(_hno), \
  74. (u32)(_tag), \
  75. (u64)(d1), \
  76. (u64)(d2), \
  77. (u64)(d3), \
  78. (u64)(d4), \
  79. (u64)(d5)); \
  80. } while (0)
  81. #else
  82. #define SNIC_TRC(_hno, _tag, d1, d2, d3, d4, d5) \
  83. do { \
  84. if (unlikely(snic_log_level & 0x2)) \
  85. SNIC_DBG("SnicTrace: %s %2u %2u %llx %llx %llx %llx %llx", \
  86. (char *)__func__, \
  87. (u16)(_hno), \
  88. (u32)(_tag), \
  89. (u64)(d1), \
  90. (u64)(d2), \
  91. (u64)(d3), \
  92. (u64)(d4), \
  93. (u64)(d5)); \
  94. } while (0)
  95. #endif /* end of CONFIG_SCSI_SNIC_DEBUG_FS */
  96. #define SNIC_TRC_CMD(sc) \
  97. ((u64)sc->cmnd[0] << 56 | (u64)sc->cmnd[7] << 40 | \
  98. (u64)sc->cmnd[8] << 32 | (u64)sc->cmnd[2] << 24 | \
  99. (u64)sc->cmnd[3] << 16 | (u64)sc->cmnd[4] << 8 | \
  100. (u64)sc->cmnd[5])
  101. #define SNIC_TRC_CMD_STATE_FLAGS(sc) \
  102. ((u64) CMD_FLAGS(sc) << 32 | CMD_STATE(sc))
  103. #endif /* end of __SNIC_TRC_H */