snic_trc.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright 2014 Cisco Systems, Inc. All rights reserved. */
  3. #ifndef __SNIC_TRC_H
  4. #define __SNIC_TRC_H
  5. #ifdef CONFIG_SCSI_SNIC_DEBUG_FS
  6. extern ssize_t simple_read_from_buffer(void __user *to,
  7. size_t count,
  8. loff_t *ppos,
  9. const void *from,
  10. size_t available);
  11. extern unsigned int snic_trace_max_pages;
  12. /* Global Data structure for trace to manage trace functionality */
  13. struct snic_trc_data {
  14. u64 ts; /* Time Stamp */
  15. char *fn; /* Ptr to Function Name */
  16. u32 hno; /* SCSI Host ID */
  17. u32 tag; /* Command Tag */
  18. u64 data[5];
  19. } __attribute__((__packed__));
  20. #define SNIC_TRC_ENTRY_SZ 64 /* in Bytes */
  21. struct snic_trc {
  22. spinlock_t lock;
  23. struct snic_trc_data *buf; /* Trace Buffer */
  24. u32 max_idx; /* Max Index into trace buffer */
  25. u32 rd_idx;
  26. u32 wr_idx;
  27. bool enable; /* Control Variable for Tracing */
  28. };
  29. int snic_trc_init(void);
  30. void snic_trc_free(void);
  31. void snic_trc_debugfs_init(void);
  32. void snic_trc_debugfs_term(void);
  33. struct snic_trc_data *snic_get_trc_buf(void);
  34. int snic_get_trc_data(char *buf, int buf_sz);
  35. void snic_debugfs_init(void);
  36. void snic_debugfs_term(void);
  37. static inline void
  38. snic_trace(char *fn, u16 hno, u32 tag, u64 d1, u64 d2, u64 d3, u64 d4, u64 d5)
  39. {
  40. struct snic_trc_data *tr_rec = snic_get_trc_buf();
  41. if (!tr_rec)
  42. return;
  43. tr_rec->fn = (char *)fn;
  44. tr_rec->hno = hno;
  45. tr_rec->tag = tag;
  46. tr_rec->data[0] = d1;
  47. tr_rec->data[1] = d2;
  48. tr_rec->data[2] = d3;
  49. tr_rec->data[3] = d4;
  50. tr_rec->data[4] = d5;
  51. tr_rec->ts = jiffies; /* Update time stamp at last */
  52. }
  53. #define SNIC_TRC(_hno, _tag, d1, d2, d3, d4, d5) \
  54. do { \
  55. if (unlikely(snic_glob->trc.enable)) \
  56. snic_trace((char *)__func__, \
  57. (u16)(_hno), \
  58. (u32)(_tag), \
  59. (u64)(d1), \
  60. (u64)(d2), \
  61. (u64)(d3), \
  62. (u64)(d4), \
  63. (u64)(d5)); \
  64. } while (0)
  65. #else
  66. #define SNIC_TRC(_hno, _tag, d1, d2, d3, d4, d5) \
  67. do { \
  68. if (unlikely(snic_log_level & 0x2)) \
  69. SNIC_DBG("SnicTrace: %s %2u %2u %llx %llx %llx %llx %llx", \
  70. (char *)__func__, \
  71. (u16)(_hno), \
  72. (u32)(_tag), \
  73. (u64)(d1), \
  74. (u64)(d2), \
  75. (u64)(d3), \
  76. (u64)(d4), \
  77. (u64)(d5)); \
  78. } while (0)
  79. #endif /* end of CONFIG_SCSI_SNIC_DEBUG_FS */
  80. #define SNIC_TRC_CMD(sc) \
  81. ((u64)sc->cmnd[0] << 56 | (u64)sc->cmnd[7] << 40 | \
  82. (u64)sc->cmnd[8] << 32 | (u64)sc->cmnd[2] << 24 | \
  83. (u64)sc->cmnd[3] << 16 | (u64)sc->cmnd[4] << 8 | \
  84. (u64)sc->cmnd[5])
  85. #define SNIC_TRC_CMD_STATE_FLAGS(sc) \
  86. ((u64) CMD_FLAGS(sc) << 32 | CMD_STATE(sc))
  87. #endif /* end of __SNIC_TRC_H */