1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef __SNIC_TRC_H
19#define __SNIC_TRC_H
20
21#ifdef CONFIG_SCSI_SNIC_DEBUG_FS
22
23extern ssize_t simple_read_from_buffer(void __user *to,
24 size_t count,
25 loff_t *ppos,
26 const void *from,
27 size_t available);
28
29extern unsigned int snic_trace_max_pages;
30
31
32struct snic_trc_data {
33 u64 ts;
34 char *fn;
35 u32 hno;
36 u32 tag;
37 u64 data[5];
38} __attribute__((__packed__));
39
40#define SNIC_TRC_ENTRY_SZ 64
41
42struct snic_trc {
43 spinlock_t lock;
44 struct snic_trc_data *buf;
45 u32 max_idx;
46 u32 rd_idx;
47 u32 wr_idx;
48 bool enable;
49};
50
51int snic_trc_init(void);
52void snic_trc_free(void);
53void snic_trc_debugfs_init(void);
54void snic_trc_debugfs_term(void);
55struct snic_trc_data *snic_get_trc_buf(void);
56int snic_get_trc_data(char *buf, int buf_sz);
57
58void snic_debugfs_init(void);
59void snic_debugfs_term(void);
60
61static inline void
62snic_trace(char *fn, u16 hno, u32 tag, u64 d1, u64 d2, u64 d3, u64 d4, u64 d5)
63{
64 struct snic_trc_data *tr_rec = snic_get_trc_buf();
65
66 if (!tr_rec)
67 return;
68
69 tr_rec->fn = (char *)fn;
70 tr_rec->hno = hno;
71 tr_rec->tag = tag;
72 tr_rec->data[0] = d1;
73 tr_rec->data[1] = d2;
74 tr_rec->data[2] = d3;
75 tr_rec->data[3] = d4;
76 tr_rec->data[4] = d5;
77 tr_rec->ts = jiffies;
78}
79
80#define SNIC_TRC(_hno, _tag, d1, d2, d3, d4, d5) \
81 do { \
82 if (unlikely(snic_glob->trc.enable)) \
83 snic_trace((char *)__func__, \
84 (u16)(_hno), \
85 (u32)(_tag), \
86 (u64)(d1), \
87 (u64)(d2), \
88 (u64)(d3), \
89 (u64)(d4), \
90 (u64)(d5)); \
91 } while (0)
92#else
93
94#define SNIC_TRC(_hno, _tag, d1, d2, d3, d4, d5) \
95 do { \
96 if (unlikely(snic_log_level & 0x2)) \
97 SNIC_DBG("SnicTrace: %s %2u %2u %llx %llx %llx %llx %llx", \
98 (char *)__func__, \
99 (u16)(_hno), \
100 (u32)(_tag), \
101 (u64)(d1), \
102 (u64)(d2), \
103 (u64)(d3), \
104 (u64)(d4), \
105 (u64)(d5)); \
106 } while (0)
107#endif
108
109#define SNIC_TRC_CMD(sc) \
110 ((u64)sc->cmnd[0] << 56 | (u64)sc->cmnd[7] << 40 | \
111 (u64)sc->cmnd[8] << 32 | (u64)sc->cmnd[2] << 24 | \
112 (u64)sc->cmnd[3] << 16 | (u64)sc->cmnd[4] << 8 | \
113 (u64)sc->cmnd[5])
114
115#define SNIC_TRC_CMD_STATE_FLAGS(sc) \
116 ((u64) CMD_FLAGS(sc) << 32 | CMD_STATE(sc))
117
118#endif
119