blob: b37f8867bfde5b6712ab8550ea9e66394d79d552 [file] [log] [blame]
Narsimhulu Musinic8806b62015-05-29 01:04:01 -07001/*
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
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/* Global Data structure for trace to manage trace functionality */
32struct snic_trc_data {
33 u64 ts; /* Time Stamp */
34 char *fn; /* Ptr to Function Name */
35 u32 hno; /* SCSI Host ID */
36 u32 tag; /* Command Tag */
37 u64 data[5];
38} __attribute__((__packed__));
39
40#define SNIC_TRC_ENTRY_SZ 64 /* in Bytes */
41
42struct snic_trc {
43 spinlock_t lock;
44 struct snic_trc_data *buf; /* Trace Buffer */
45 u32 max_idx; /* Max Index into trace buffer */
46 u32 rd_idx;
47 u32 wr_idx;
Viresh Kumar621a5f72015-09-26 15:04:07 -070048 bool enable; /* Control Variable for Tracing */
Narsimhulu Musinic8806b62015-05-29 01:04:01 -070049
50 struct dentry *trc_enable; /* debugfs file object */
51 struct dentry *trc_file;
52};
53
54int snic_trc_init(void);
55void snic_trc_free(void);
56int snic_trc_debugfs_init(void);
57void snic_trc_debugfs_term(void);
58struct snic_trc_data *snic_get_trc_buf(void);
59int snic_get_trc_data(char *buf, int buf_sz);
60
61int snic_debugfs_init(void);
62void snic_debugfs_term(void);
63
64static inline void
65snic_trace(char *fn, u16 hno, u32 tag, u64 d1, u64 d2, u64 d3, u64 d4, u64 d5)
66{
67 struct snic_trc_data *tr_rec = snic_get_trc_buf();
68
69 if (!tr_rec)
70 return;
71
72 tr_rec->fn = (char *)fn;
73 tr_rec->hno = hno;
74 tr_rec->tag = tag;
75 tr_rec->data[0] = d1;
76 tr_rec->data[1] = d2;
77 tr_rec->data[2] = d3;
78 tr_rec->data[3] = d4;
79 tr_rec->data[4] = d5;
80 tr_rec->ts = jiffies; /* Update time stamp at last */
81}
82
83#define SNIC_TRC(_hno, _tag, d1, d2, d3, d4, d5) \
84 do { \
85 if (unlikely(snic_glob->trc.enable)) \
86 snic_trace((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#else
96
97#define SNIC_TRC(_hno, _tag, d1, d2, d3, d4, d5) \
98 do { \
99 if (unlikely(snic_log_level & 0x2)) \
100 SNIC_DBG("SnicTrace: %s %2u %2u %llx %llx %llx %llx %llx", \
101 (char *)__func__, \
102 (u16)(_hno), \
103 (u32)(_tag), \
104 (u64)(d1), \
105 (u64)(d2), \
106 (u64)(d3), \
107 (u64)(d4), \
108 (u64)(d5)); \
109 } while (0)
110#endif /* end of CONFIG_SCSI_SNIC_DEBUG_FS */
111
112#define SNIC_TRC_CMD(sc) \
113 ((u64)sc->cmnd[0] << 56 | (u64)sc->cmnd[7] << 40 | \
114 (u64)sc->cmnd[8] << 32 | (u64)sc->cmnd[2] << 24 | \
115 (u64)sc->cmnd[3] << 16 | (u64)sc->cmnd[4] << 8 | \
116 (u64)sc->cmnd[5])
117
118#define SNIC_TRC_CMD_STATE_FLAGS(sc) \
119 ((u64) CMD_FLAGS(sc) << 32 | CMD_STATE(sc))
120
121#endif /* end of __SNIC_TRC_H */