qla2xxx: Enable Target counters in DebugFS.
[deliverable/linux.git] / drivers / scsi / qla2xxx / qla_dfs.c
1 /*
2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
4 *
5 * See LICENSE.qla2xxx for copyright and licensing details.
6 */
7 #include "qla_def.h"
8
9 #include <linux/debugfs.h>
10 #include <linux/seq_file.h>
11
12 static struct dentry *qla2x00_dfs_root;
13 static atomic_t qla2x00_dfs_root_count;
14
15 static int
16 qla_dfs_tgt_counters_show(struct seq_file *s, void *unused)
17 {
18 struct scsi_qla_host *vha = s->private;
19
20 seq_puts(s, "Target Counters\n");
21 seq_printf(s, "qla_core_sbt_cmd = %lld\n",
22 vha->tgt_counters.qla_core_sbt_cmd);
23 seq_printf(s, "qla_core_ret_sta_ctio = %lld\n",
24 vha->tgt_counters.qla_core_ret_sta_ctio);
25 seq_printf(s, "qla_core_ret_ctio = %lld\n",
26 vha->tgt_counters.qla_core_ret_ctio);
27 seq_printf(s, "core_qla_que_buf = %lld\n",
28 vha->tgt_counters.core_qla_que_buf);
29 seq_printf(s, "core_qla_snd_status = %lld\n",
30 vha->tgt_counters.core_qla_snd_status);
31 seq_printf(s, "core_qla_free_cmd = %lld\n",
32 vha->tgt_counters.core_qla_free_cmd);
33 seq_printf(s, "num alloc iocb failed = %lld\n",
34 vha->tgt_counters.num_alloc_iocb_failed);
35 seq_printf(s, "num term exchange sent = %lld\n",
36 vha->tgt_counters.num_term_xchg_sent);
37 seq_printf(s, "num Q full sent = %lld\n",
38 vha->tgt_counters.num_q_full_sent);
39
40 return 0;
41 }
42
43 static int
44 qla_dfs_tgt_counters_open(struct inode *inode, struct file *file)
45 {
46 struct scsi_qla_host *vha = inode->i_private;
47 return single_open(file, qla_dfs_tgt_counters_show, vha);
48 }
49
50 static const struct file_operations dfs_tgt_counters_ops = {
51 .open = qla_dfs_tgt_counters_open,
52 .read = seq_read,
53 .llseek = seq_lseek,
54 .release = single_release,
55 };
56
57 static int
58 qla2x00_dfs_fce_show(struct seq_file *s, void *unused)
59 {
60 scsi_qla_host_t *vha = s->private;
61 uint32_t cnt;
62 uint32_t *fce;
63 uint64_t fce_start;
64 struct qla_hw_data *ha = vha->hw;
65
66 mutex_lock(&ha->fce_mutex);
67
68 seq_puts(s, "FCE Trace Buffer\n");
69 seq_printf(s, "In Pointer = %llx\n\n", (unsigned long long)ha->fce_wr);
70 seq_printf(s, "Base = %llx\n\n", (unsigned long long) ha->fce_dma);
71 seq_puts(s, "FCE Enable Registers\n");
72 seq_printf(s, "%08x %08x %08x %08x %08x %08x\n",
73 ha->fce_mb[0], ha->fce_mb[2], ha->fce_mb[3], ha->fce_mb[4],
74 ha->fce_mb[5], ha->fce_mb[6]);
75
76 fce = (uint32_t *) ha->fce;
77 fce_start = (unsigned long long) ha->fce_dma;
78 for (cnt = 0; cnt < fce_calc_size(ha->fce_bufs) / 4; cnt++) {
79 if (cnt % 8 == 0)
80 seq_printf(s, "\n%llx: ",
81 (unsigned long long)((cnt * 4) + fce_start));
82 else
83 seq_putc(s, ' ');
84 seq_printf(s, "%08x", *fce++);
85 }
86
87 seq_puts(s, "\nEnd\n");
88
89 mutex_unlock(&ha->fce_mutex);
90
91 return 0;
92 }
93
94 static int
95 qla2x00_dfs_fce_open(struct inode *inode, struct file *file)
96 {
97 scsi_qla_host_t *vha = inode->i_private;
98 struct qla_hw_data *ha = vha->hw;
99 int rval;
100
101 if (!ha->flags.fce_enabled)
102 goto out;
103
104 mutex_lock(&ha->fce_mutex);
105
106 /* Pause tracing to flush FCE buffers. */
107 rval = qla2x00_disable_fce_trace(vha, &ha->fce_wr, &ha->fce_rd);
108 if (rval)
109 ql_dbg(ql_dbg_user, vha, 0x705c,
110 "DebugFS: Unable to disable FCE (%d).\n", rval);
111
112 ha->flags.fce_enabled = 0;
113
114 mutex_unlock(&ha->fce_mutex);
115 out:
116 return single_open(file, qla2x00_dfs_fce_show, vha);
117 }
118
119 static int
120 qla2x00_dfs_fce_release(struct inode *inode, struct file *file)
121 {
122 scsi_qla_host_t *vha = inode->i_private;
123 struct qla_hw_data *ha = vha->hw;
124 int rval;
125
126 if (ha->flags.fce_enabled)
127 goto out;
128
129 mutex_lock(&ha->fce_mutex);
130
131 /* Re-enable FCE tracing. */
132 ha->flags.fce_enabled = 1;
133 memset(ha->fce, 0, fce_calc_size(ha->fce_bufs));
134 rval = qla2x00_enable_fce_trace(vha, ha->fce_dma, ha->fce_bufs,
135 ha->fce_mb, &ha->fce_bufs);
136 if (rval) {
137 ql_dbg(ql_dbg_user, vha, 0x700d,
138 "DebugFS: Unable to reinitialize FCE (%d).\n", rval);
139 ha->flags.fce_enabled = 0;
140 }
141
142 mutex_unlock(&ha->fce_mutex);
143 out:
144 return single_release(inode, file);
145 }
146
147 static const struct file_operations dfs_fce_ops = {
148 .open = qla2x00_dfs_fce_open,
149 .read = seq_read,
150 .llseek = seq_lseek,
151 .release = qla2x00_dfs_fce_release,
152 };
153
154 int
155 qla2x00_dfs_setup(scsi_qla_host_t *vha)
156 {
157 struct qla_hw_data *ha = vha->hw;
158
159 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
160 !IS_QLA27XX(ha))
161 goto out;
162 if (!ha->fce)
163 goto out;
164
165 if (qla2x00_dfs_root)
166 goto create_dir;
167
168 atomic_set(&qla2x00_dfs_root_count, 0);
169 qla2x00_dfs_root = debugfs_create_dir(QLA2XXX_DRIVER_NAME, NULL);
170 if (!qla2x00_dfs_root) {
171 ql_log(ql_log_warn, vha, 0x00f7,
172 "Unable to create debugfs root directory.\n");
173 goto out;
174 }
175
176 create_dir:
177 if (ha->dfs_dir)
178 goto create_nodes;
179
180 mutex_init(&ha->fce_mutex);
181 ha->dfs_dir = debugfs_create_dir(vha->host_str, qla2x00_dfs_root);
182 if (!ha->dfs_dir) {
183 ql_log(ql_log_warn, vha, 0x00f8,
184 "Unable to create debugfs ha directory.\n");
185 goto out;
186 }
187
188 atomic_inc(&qla2x00_dfs_root_count);
189
190 create_nodes:
191 ha->dfs_tgt_counters = debugfs_create_file("tgt_counters", S_IRUSR,
192 ha->dfs_dir, vha, &dfs_tgt_counters_ops);
193 if (!ha->dfs_tgt_counters) {
194 ql_log(ql_log_warn, vha, 0xd301,
195 "Unable to create debugFS tgt_counters node.\n");
196 goto out;
197 }
198
199 ha->dfs_fce = debugfs_create_file("fce", S_IRUSR, ha->dfs_dir, vha,
200 &dfs_fce_ops);
201 if (!ha->dfs_fce) {
202 ql_log(ql_log_warn, vha, 0x00f9,
203 "Unable to create debugfs fce node.\n");
204 goto out;
205 }
206 out:
207 return 0;
208 }
209
210 int
211 qla2x00_dfs_remove(scsi_qla_host_t *vha)
212 {
213 struct qla_hw_data *ha = vha->hw;
214
215 if (ha->dfs_tgt_counters) {
216 debugfs_remove(ha->dfs_tgt_counters);
217 ha->dfs_tgt_counters = NULL;
218 }
219
220 if (ha->dfs_fce) {
221 debugfs_remove(ha->dfs_fce);
222 ha->dfs_fce = NULL;
223 }
224
225 if (ha->dfs_dir) {
226 debugfs_remove(ha->dfs_dir);
227 ha->dfs_dir = NULL;
228 atomic_dec(&qla2x00_dfs_root_count);
229 }
230
231 if (atomic_read(&qla2x00_dfs_root_count) == 0 &&
232 qla2x00_dfs_root) {
233 debugfs_remove(qla2x00_dfs_root);
234 qla2x00_dfs_root = NULL;
235 }
236
237 return 0;
238 }
This page took 0.062983 seconds and 6 git commands to generate.