fnic_trace.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright 2012 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 __FNIC_TRACE_H__
  18. #define __FNIC_TRACE_H__
  19. #define FNIC_ENTRY_SIZE_BYTES 64
  20. #define FC_TRC_SIZE_BYTES 256
  21. #define FC_TRC_HEADER_SIZE sizeof(struct fc_trace_hdr)
  22. /*
  23. * Fisrt bit of FNIC_FC_RECV and FNIC_FC_SEND is used to represent the type
  24. * of frame 1 => Eth frame, 0=> FC frame
  25. */
  26. #define FNIC_FC_RECV 0x52 /* Character R */
  27. #define FNIC_FC_SEND 0x54 /* Character T */
  28. #define FNIC_FC_LE 0x4C /* Character L */
  29. extern ssize_t simple_read_from_buffer(void __user *to,
  30. size_t count,
  31. loff_t *ppos,
  32. const void *from,
  33. size_t available);
  34. extern unsigned int fnic_trace_max_pages;
  35. extern int fnic_tracing_enabled;
  36. extern unsigned int trace_max_pages;
  37. extern unsigned int fnic_fc_trace_max_pages;
  38. extern int fnic_fc_tracing_enabled;
  39. extern int fnic_fc_trace_cleared;
  40. typedef struct fnic_trace_dbg {
  41. int wr_idx;
  42. int rd_idx;
  43. unsigned long *page_offset;
  44. } fnic_trace_dbg_t;
  45. typedef struct fnic_dbgfs {
  46. int buffer_len;
  47. char *buffer;
  48. } fnic_dbgfs_t;
  49. struct fnic_trace_data {
  50. union {
  51. struct {
  52. u32 low;
  53. u32 high;
  54. };
  55. u64 val;
  56. } timestamp, fnaddr;
  57. u32 host_no;
  58. u32 tag;
  59. u64 data[5];
  60. } __attribute__((__packed__));
  61. typedef struct fnic_trace_data fnic_trace_data_t;
  62. struct fc_trace_hdr {
  63. struct timespec time_stamp;
  64. u32 host_no;
  65. u8 frame_type;
  66. u8 frame_len;
  67. } __attribute__((__packed__));
  68. #define FC_TRACE_ADDRESS(a) \
  69. ((unsigned long)(a) + sizeof(struct fc_trace_hdr))
  70. #define FNIC_TRACE_ENTRY_SIZE \
  71. (FNIC_ENTRY_SIZE_BYTES - sizeof(fnic_trace_data_t))
  72. #define FNIC_TRACE(_fn, _hn, _t, _a, _b, _c, _d, _e) \
  73. if (unlikely(fnic_tracing_enabled)) { \
  74. fnic_trace_data_t *trace_buf = fnic_trace_get_buf(); \
  75. if (trace_buf) { \
  76. if (sizeof(unsigned long) < 8) { \
  77. trace_buf->timestamp.low = jiffies; \
  78. trace_buf->fnaddr.low = (u32)(unsigned long)_fn; \
  79. } else { \
  80. trace_buf->timestamp.val = jiffies; \
  81. trace_buf->fnaddr.val = (u64)(unsigned long)_fn; \
  82. } \
  83. trace_buf->host_no = _hn; \
  84. trace_buf->tag = _t; \
  85. trace_buf->data[0] = (u64)(unsigned long)_a; \
  86. trace_buf->data[1] = (u64)(unsigned long)_b; \
  87. trace_buf->data[2] = (u64)(unsigned long)_c; \
  88. trace_buf->data[3] = (u64)(unsigned long)_d; \
  89. trace_buf->data[4] = (u64)(unsigned long)_e; \
  90. } \
  91. }
  92. fnic_trace_data_t *fnic_trace_get_buf(void);
  93. int fnic_get_trace_data(fnic_dbgfs_t *);
  94. int fnic_trace_buf_init(void);
  95. void fnic_trace_free(void);
  96. int fnic_debugfs_init(void);
  97. void fnic_debugfs_terminate(void);
  98. int fnic_trace_debugfs_init(void);
  99. void fnic_trace_debugfs_terminate(void);
  100. /* Fnic FC CTLR Trace releated function */
  101. int fnic_fc_trace_init(void);
  102. void fnic_fc_trace_free(void);
  103. int fnic_fc_trace_set_data(u32 host_no, u8 frame_type,
  104. char *frame, u32 fc_frame_len);
  105. int fnic_fc_trace_get_data(fnic_dbgfs_t *fnic_dbgfs_prt, u8 rdata_flag);
  106. void copy_and_format_trace_data(struct fc_trace_hdr *tdata,
  107. fnic_dbgfs_t *fnic_dbgfs_prt,
  108. int *len, u8 rdata_flag);
  109. int fnic_fc_trace_debugfs_init(void);
  110. void fnic_fc_trace_debugfs_terminate(void);
  111. #endif