blob: 34272fde8a5b0d8def9be94adcdce045f16e9540 [file] [log] [blame]
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001/*
2 * QLogic Fibre Channel HBA Driver
Armen Baloyanbd21eaf2014-04-11 16:54:24 -04003 * Copyright (c) 2003-2014 QLogic Corporation
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004 *
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
12static struct dentry *qla2x00_dfs_root;
13static atomic_t qla2x00_dfs_root_count;
14
15static int
Quinn Tran36c78452016-02-04 11:45:18 -050016qla2x00_dfs_tgt_sess_show(struct seq_file *s, void *unused)
17{
18 scsi_qla_host_t *vha = s->private;
19 struct qla_hw_data *ha = vha->hw;
20 unsigned long flags;
21 struct qla_tgt_sess *sess = NULL;
22 struct qla_tgt *tgt= vha->vha_tgt.qla_tgt;
23
24 seq_printf(s, "%s\n",vha->host_str);
25 if (tgt) {
26 seq_printf(s, "Port ID Port Name Handle\n");
27
28 spin_lock_irqsave(&ha->tgt.sess_lock, flags);
29 list_for_each_entry(sess, &tgt->sess_list, sess_list_entry) {
30 seq_printf(s, "%02x:%02x:%02x %8phC %d\n",
31 sess->s_id.b.domain,sess->s_id.b.area,
32 sess->s_id.b.al_pa, sess->port_name,
33 sess->loop_id);
34 }
35 spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
36 }
37
38 return 0;
39}
40
41static int
42qla2x00_dfs_tgt_sess_open(struct inode *inode, struct file *file)
43{
44 scsi_qla_host_t *vha = inode->i_private;
45 return single_open(file, qla2x00_dfs_tgt_sess_show, vha);
46}
47
48
49static const struct file_operations dfs_tgt_sess_ops = {
50 .open = qla2x00_dfs_tgt_sess_open,
51 .read = seq_read,
52 .llseek = seq_lseek,
53 .release = single_release,
54};
55
56static int
Quinn Tran03e8c682015-12-17 14:56:59 -050057qla_dfs_fw_resource_cnt_show(struct seq_file *s, void *unused)
58{
59 struct scsi_qla_host *vha = s->private;
60 struct qla_hw_data *ha = vha->hw;
61
62 seq_puts(s, "FW Resource count\n\n");
63 seq_printf(s, "Original TGT exchg count[%d]\n",
64 ha->orig_fw_tgt_xcb_count);
65 seq_printf(s, "current TGT exchg count[%d]\n",
66 ha->cur_fw_tgt_xcb_count);
67 seq_printf(s, "original Initiator Exchange count[%d]\n",
68 ha->orig_fw_xcb_count);
69 seq_printf(s, "Current Initiator Exchange count[%d]\n",
70 ha->cur_fw_xcb_count);
71 seq_printf(s, "Original IOCB count[%d]\n", ha->orig_fw_iocb_count);
72 seq_printf(s, "Current IOCB count[%d]\n", ha->cur_fw_iocb_count);
73 seq_printf(s, "MAX VP count[%d]\n", ha->max_npiv_vports);
74 seq_printf(s, "MAX FCF count[%d]\n", ha->fw_max_fcf_count);
75
76 return 0;
77}
78
79static int
80qla_dfs_fw_resource_cnt_open(struct inode *inode, struct file *file)
81{
82 struct scsi_qla_host *vha = inode->i_private;
83 return single_open(file, qla_dfs_fw_resource_cnt_show, vha);
84}
85
86static const struct file_operations dfs_fw_resource_cnt_ops = {
87 .open = qla_dfs_fw_resource_cnt_open,
88 .read = seq_read,
89 .llseek = seq_lseek,
90 .release = single_release,
91};
92
93static int
Himanshu Madhanice1025c2015-12-17 14:56:58 -050094qla_dfs_tgt_counters_show(struct seq_file *s, void *unused)
95{
96 struct scsi_qla_host *vha = s->private;
97
98 seq_puts(s, "Target Counters\n");
99 seq_printf(s, "qla_core_sbt_cmd = %lld\n",
100 vha->tgt_counters.qla_core_sbt_cmd);
101 seq_printf(s, "qla_core_ret_sta_ctio = %lld\n",
102 vha->tgt_counters.qla_core_ret_sta_ctio);
103 seq_printf(s, "qla_core_ret_ctio = %lld\n",
104 vha->tgt_counters.qla_core_ret_ctio);
105 seq_printf(s, "core_qla_que_buf = %lld\n",
106 vha->tgt_counters.core_qla_que_buf);
107 seq_printf(s, "core_qla_snd_status = %lld\n",
108 vha->tgt_counters.core_qla_snd_status);
109 seq_printf(s, "core_qla_free_cmd = %lld\n",
110 vha->tgt_counters.core_qla_free_cmd);
111 seq_printf(s, "num alloc iocb failed = %lld\n",
112 vha->tgt_counters.num_alloc_iocb_failed);
113 seq_printf(s, "num term exchange sent = %lld\n",
114 vha->tgt_counters.num_term_xchg_sent);
115 seq_printf(s, "num Q full sent = %lld\n",
116 vha->tgt_counters.num_q_full_sent);
117
118 return 0;
119}
120
121static int
122qla_dfs_tgt_counters_open(struct inode *inode, struct file *file)
123{
124 struct scsi_qla_host *vha = inode->i_private;
125 return single_open(file, qla_dfs_tgt_counters_show, vha);
126}
127
128static const struct file_operations dfs_tgt_counters_ops = {
129 .open = qla_dfs_tgt_counters_open,
130 .read = seq_read,
131 .llseek = seq_lseek,
132 .release = single_release,
133};
134
135static int
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800136qla2x00_dfs_fce_show(struct seq_file *s, void *unused)
137{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800138 scsi_qla_host_t *vha = s->private;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800139 uint32_t cnt;
140 uint32_t *fce;
141 uint64_t fce_start;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800142 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800143
144 mutex_lock(&ha->fce_mutex);
145
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100146 seq_puts(s, "FCE Trace Buffer\n");
FUJITA Tomonori279e7f52008-02-16 15:24:41 +0900147 seq_printf(s, "In Pointer = %llx\n\n", (unsigned long long)ha->fce_wr);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800148 seq_printf(s, "Base = %llx\n\n", (unsigned long long) ha->fce_dma);
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100149 seq_puts(s, "FCE Enable Registers\n");
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800150 seq_printf(s, "%08x %08x %08x %08x %08x %08x\n",
151 ha->fce_mb[0], ha->fce_mb[2], ha->fce_mb[3], ha->fce_mb[4],
152 ha->fce_mb[5], ha->fce_mb[6]);
153
154 fce = (uint32_t *) ha->fce;
155 fce_start = (unsigned long long) ha->fce_dma;
156 for (cnt = 0; cnt < fce_calc_size(ha->fce_bufs) / 4; cnt++) {
157 if (cnt % 8 == 0)
158 seq_printf(s, "\n%llx: ",
159 (unsigned long long)((cnt * 4) + fce_start));
160 else
Rasmus Villemoesf50332f2014-12-03 00:10:54 +0100161 seq_putc(s, ' ');
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800162 seq_printf(s, "%08x", *fce++);
163 }
164
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100165 seq_puts(s, "\nEnd\n");
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800166
167 mutex_unlock(&ha->fce_mutex);
168
169 return 0;
170}
171
172static int
173qla2x00_dfs_fce_open(struct inode *inode, struct file *file)
174{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800175 scsi_qla_host_t *vha = inode->i_private;
176 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800177 int rval;
178
179 if (!ha->flags.fce_enabled)
180 goto out;
181
182 mutex_lock(&ha->fce_mutex);
183
184 /* Pause tracing to flush FCE buffers. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800185 rval = qla2x00_disable_fce_trace(vha, &ha->fce_wr, &ha->fce_rd);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800186 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700187 ql_dbg(ql_dbg_user, vha, 0x705c,
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800188 "DebugFS: Unable to disable FCE (%d).\n", rval);
189
190 ha->flags.fce_enabled = 0;
191
192 mutex_unlock(&ha->fce_mutex);
193out:
Giridhar Malavali94279ed2009-03-24 09:07:57 -0700194 return single_open(file, qla2x00_dfs_fce_show, vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800195}
196
197static int
198qla2x00_dfs_fce_release(struct inode *inode, struct file *file)
199{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800200 scsi_qla_host_t *vha = inode->i_private;
201 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800202 int rval;
203
204 if (ha->flags.fce_enabled)
205 goto out;
206
207 mutex_lock(&ha->fce_mutex);
208
209 /* Re-enable FCE tracing. */
210 ha->flags.fce_enabled = 1;
211 memset(ha->fce, 0, fce_calc_size(ha->fce_bufs));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800212 rval = qla2x00_enable_fce_trace(vha, ha->fce_dma, ha->fce_bufs,
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800213 ha->fce_mb, &ha->fce_bufs);
214 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700215 ql_dbg(ql_dbg_user, vha, 0x700d,
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800216 "DebugFS: Unable to reinitialize FCE (%d).\n", rval);
217 ha->flags.fce_enabled = 0;
218 }
219
220 mutex_unlock(&ha->fce_mutex);
221out:
222 return single_release(inode, file);
223}
224
225static const struct file_operations dfs_fce_ops = {
226 .open = qla2x00_dfs_fce_open,
227 .read = seq_read,
228 .llseek = seq_lseek,
229 .release = qla2x00_dfs_fce_release,
230};
231
232int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800233qla2x00_dfs_setup(scsi_qla_host_t *vha)
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800234{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800235 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800236
Chad Dupuisf73cb692014-02-26 04:15:06 -0500237 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
238 !IS_QLA27XX(ha))
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800239 goto out;
240 if (!ha->fce)
241 goto out;
242
243 if (qla2x00_dfs_root)
244 goto create_dir;
245
246 atomic_set(&qla2x00_dfs_root_count, 0);
247 qla2x00_dfs_root = debugfs_create_dir(QLA2XXX_DRIVER_NAME, NULL);
248 if (!qla2x00_dfs_root) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700249 ql_log(ql_log_warn, vha, 0x00f7,
250 "Unable to create debugfs root directory.\n");
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800251 goto out;
252 }
253
254create_dir:
255 if (ha->dfs_dir)
256 goto create_nodes;
257
258 mutex_init(&ha->fce_mutex);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800259 ha->dfs_dir = debugfs_create_dir(vha->host_str, qla2x00_dfs_root);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800260 if (!ha->dfs_dir) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700261 ql_log(ql_log_warn, vha, 0x00f8,
262 "Unable to create debugfs ha directory.\n");
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800263 goto out;
264 }
265
266 atomic_inc(&qla2x00_dfs_root_count);
267
268create_nodes:
Quinn Tran03e8c682015-12-17 14:56:59 -0500269 ha->dfs_fw_resource_cnt = debugfs_create_file("fw_resource_count",
270 S_IRUSR, ha->dfs_dir, vha, &dfs_fw_resource_cnt_ops);
271 if (!ha->dfs_fw_resource_cnt) {
272 ql_log(ql_log_warn, vha, 0x00fd,
273 "Unable to create debugFS fw_resource_count node.\n");
274 goto out;
275 }
276
Himanshu Madhanice1025c2015-12-17 14:56:58 -0500277 ha->dfs_tgt_counters = debugfs_create_file("tgt_counters", S_IRUSR,
278 ha->dfs_dir, vha, &dfs_tgt_counters_ops);
279 if (!ha->dfs_tgt_counters) {
280 ql_log(ql_log_warn, vha, 0xd301,
281 "Unable to create debugFS tgt_counters node.\n");
282 goto out;
283 }
284
Giridhar Malavali94279ed2009-03-24 09:07:57 -0700285 ha->dfs_fce = debugfs_create_file("fce", S_IRUSR, ha->dfs_dir, vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800286 &dfs_fce_ops);
287 if (!ha->dfs_fce) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700288 ql_log(ql_log_warn, vha, 0x00f9,
289 "Unable to create debugfs fce node.\n");
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800290 goto out;
291 }
Quinn Tran36c78452016-02-04 11:45:18 -0500292
293 ha->tgt.dfs_tgt_sess = debugfs_create_file("tgt_sess",
294 S_IRUSR, ha->dfs_dir, vha, &dfs_tgt_sess_ops);
295 if (!ha->tgt.dfs_tgt_sess) {
296 ql_log(ql_log_warn, vha, 0xffff,
297 "Unable to create debugFS tgt_sess node.\n");
298 goto out;
299 }
300
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800301out:
302 return 0;
303}
304
305int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800306qla2x00_dfs_remove(scsi_qla_host_t *vha)
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800307{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800308 struct qla_hw_data *ha = vha->hw;
Himanshu Madhanice1025c2015-12-17 14:56:58 -0500309
Quinn Tran36c78452016-02-04 11:45:18 -0500310 if (ha->tgt.dfs_tgt_sess) {
311 debugfs_remove(ha->tgt.dfs_tgt_sess);
312 ha->tgt.dfs_tgt_sess = NULL;
313 }
314
Quinn Tran03e8c682015-12-17 14:56:59 -0500315 if (ha->dfs_fw_resource_cnt) {
316 debugfs_remove(ha->dfs_fw_resource_cnt);
317 ha->dfs_fw_resource_cnt = NULL;
318 }
319
Himanshu Madhanice1025c2015-12-17 14:56:58 -0500320 if (ha->dfs_tgt_counters) {
321 debugfs_remove(ha->dfs_tgt_counters);
322 ha->dfs_tgt_counters = NULL;
323 }
324
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800325 if (ha->dfs_fce) {
326 debugfs_remove(ha->dfs_fce);
327 ha->dfs_fce = NULL;
328 }
329
330 if (ha->dfs_dir) {
331 debugfs_remove(ha->dfs_dir);
332 ha->dfs_dir = NULL;
333 atomic_dec(&qla2x00_dfs_root_count);
334 }
335
336 if (atomic_read(&qla2x00_dfs_root_count) == 0 &&
337 qla2x00_dfs_root) {
338 debugfs_remove(qla2x00_dfs_root);
339 qla2x00_dfs_root = NULL;
340 }
341
342 return 0;
343}