hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/scsi/qedf/qedf_debugfs.c
....@@ -1,78 +1,63 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * QLogic FCoE Offload Driver
34 * Copyright (c) 2016-2018 QLogic Corporation
4
- *
5
- * This software is available under the terms of the GNU General Public License
6
- * (GPL) Version 2, available from the file COPYING in the main directory of
7
- * this source tree.
85 */
96 #ifdef CONFIG_DEBUG_FS
107
118 #include <linux/uaccess.h>
129 #include <linux/debugfs.h>
1310 #include <linux/module.h>
11
+#include <linux/vmalloc.h>
1412
1513 #include "qedf.h"
1614 #include "qedf_dbg.h"
1715
1816 static struct dentry *qedf_dbg_root;
1917
20
-/**
18
+/*
2119 * qedf_dbg_host_init - setup the debugfs file for the pf
22
- * @pf: the pf that is starting up
23
- **/
20
+ */
2421 void
2522 qedf_dbg_host_init(struct qedf_dbg_ctx *qedf,
2623 const struct qedf_debugfs_ops *dops,
2724 const struct file_operations *fops)
2825 {
2926 char host_dirname[32];
30
- struct dentry *file_dentry = NULL;
3127
3228 QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Creating debugfs host node\n");
3329 /* create pf dir */
3430 sprintf(host_dirname, "host%u", qedf->host_no);
3531 qedf->bdf_dentry = debugfs_create_dir(host_dirname, qedf_dbg_root);
36
- if (!qedf->bdf_dentry)
37
- return;
3832
3933 /* create debugfs files */
4034 while (dops) {
4135 if (!(dops->name))
4236 break;
4337
44
- file_dentry = debugfs_create_file(dops->name, 0600,
45
- qedf->bdf_dentry, qedf,
46
- fops);
47
- if (!file_dentry) {
48
- QEDF_INFO(qedf, QEDF_LOG_DEBUGFS,
49
- "Debugfs entry %s creation failed\n",
50
- dops->name);
51
- debugfs_remove_recursive(qedf->bdf_dentry);
52
- return;
53
- }
38
+ debugfs_create_file(dops->name, 0600, qedf->bdf_dentry, qedf,
39
+ fops);
5440 dops++;
5541 fops++;
5642 }
5743 }
5844
59
-/**
45
+/*
6046 * qedf_dbg_host_exit - clear out the pf's debugfs entries
61
- * @pf: the pf that is stopping
62
- **/
47
+ */
6348 void
64
-qedf_dbg_host_exit(struct qedf_dbg_ctx *qedf)
49
+qedf_dbg_host_exit(struct qedf_dbg_ctx *qedf_dbg)
6550 {
66
- QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Destroying debugfs host "
51
+ QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "Destroying debugfs host "
6752 "entry\n");
6853 /* remove debugfs entries of this PF */
69
- debugfs_remove_recursive(qedf->bdf_dentry);
70
- qedf->bdf_dentry = NULL;
54
+ debugfs_remove_recursive(qedf_dbg->bdf_dentry);
55
+ qedf_dbg->bdf_dentry = NULL;
7156 }
7257
73
-/**
58
+/*
7459 * qedf_dbg_init - start up debugfs for the driver
75
- **/
60
+ */
7661 void
7762 qedf_dbg_init(char *drv_name)
7863 {
....@@ -80,14 +65,11 @@
8065
8166 /* create qed dir in root of debugfs. NULL means debugfs root */
8267 qedf_dbg_root = debugfs_create_dir(drv_name, NULL);
83
- if (!qedf_dbg_root)
84
- QEDF_INFO(NULL, QEDF_LOG_DEBUGFS, "Init of debugfs "
85
- "failed\n");
8668 }
8769
88
-/**
70
+/*
8971 * qedf_dbg_exit - clean out the driver's debugfs entries
90
- **/
72
+ */
9173 void
9274 qedf_dbg_exit(void)
9375 {
....@@ -117,7 +99,9 @@
11799 qedf_dbg_fp_int_cmd_read(struct file *filp, char __user *buffer, size_t count,
118100 loff_t *ppos)
119101 {
102
+ ssize_t ret;
120103 size_t cnt = 0;
104
+ char *cbuf;
121105 int id;
122106 struct qedf_fastpath *fp = NULL;
123107 struct qedf_dbg_ctx *qedf_dbg =
....@@ -127,19 +111,25 @@
127111
128112 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
129113
130
- cnt = sprintf(buffer, "\nFastpath I/O completions\n\n");
114
+ cbuf = vmalloc(QEDF_DEBUGFS_LOG_LEN);
115
+ if (!cbuf)
116
+ return 0;
117
+
118
+ cnt += scnprintf(cbuf + cnt, QEDF_DEBUGFS_LOG_LEN - cnt, "\nFastpath I/O completions\n\n");
131119
132120 for (id = 0; id < qedf->num_queues; id++) {
133121 fp = &(qedf->fp_array[id]);
134122 if (fp->sb_id == QEDF_SB_ID_NULL)
135123 continue;
136
- cnt += sprintf((buffer + cnt), "#%d: %lu\n", id,
137
- fp->completions);
124
+ cnt += scnprintf(cbuf + cnt, QEDF_DEBUGFS_LOG_LEN - cnt,
125
+ "#%d: %lu\n", id, fp->completions);
138126 }
139127
140
- cnt = min_t(int, count, cnt - *ppos);
141
- *ppos += cnt;
142
- return cnt;
128
+ ret = simple_read_from_buffer(buffer, count, ppos, cbuf, cnt);
129
+
130
+ vfree(cbuf);
131
+
132
+ return ret;
143133 }
144134
145135 static ssize_t
....@@ -157,15 +147,14 @@
157147 loff_t *ppos)
158148 {
159149 int cnt;
160
- struct qedf_dbg_ctx *qedf =
150
+ char cbuf[32];
151
+ struct qedf_dbg_ctx *qedf_dbg =
161152 (struct qedf_dbg_ctx *)filp->private_data;
162153
163
- QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "entered\n");
164
- cnt = sprintf(buffer, "debug mask = 0x%x\n", qedf_debug);
154
+ QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "debug mask=0x%x\n", qedf_debug);
155
+ cnt = scnprintf(cbuf, sizeof(cbuf), "debug mask = 0x%x\n", qedf_debug);
165156
166
- cnt = min_t(int, count, cnt - *ppos);
167
- *ppos += cnt;
168
- return cnt;
157
+ return simple_read_from_buffer(buffer, count, ppos, cbuf, cnt);
169158 }
170159
171160 static ssize_t
....@@ -175,7 +164,7 @@
175164 uint32_t val;
176165 void *kern_buf;
177166 int rval;
178
- struct qedf_dbg_ctx *qedf =
167
+ struct qedf_dbg_ctx *qedf_dbg =
179168 (struct qedf_dbg_ctx *)filp->private_data;
180169
181170 if (!count || *ppos)
....@@ -195,7 +184,7 @@
195184 else
196185 qedf_debug = val;
197186
198
- QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Setting debug=0x%x.\n", val);
187
+ QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "Setting debug=0x%x.\n", val);
199188 return count;
200189 }
201190
....@@ -204,18 +193,17 @@
204193 size_t count, loff_t *ppos)
205194 {
206195 int cnt;
196
+ char cbuf[7];
207197 struct qedf_dbg_ctx *qedf_dbg =
208198 (struct qedf_dbg_ctx *)filp->private_data;
209199 struct qedf_ctx *qedf = container_of(qedf_dbg,
210200 struct qedf_ctx, dbg_ctx);
211201
212202 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
213
- cnt = sprintf(buffer, "%s\n",
203
+ cnt = scnprintf(cbuf, sizeof(cbuf), "%s\n",
214204 qedf->stop_io_on_error ? "true" : "false");
215205
216
- cnt = min_t(int, count, cnt - *ppos);
217
- *ppos += cnt;
218
- return cnt;
206
+ return simple_read_from_buffer(buffer, count, ppos, cbuf, cnt);
219207 }
220208
221209 static ssize_t
....@@ -307,6 +295,33 @@
307295 return single_open(file, qedf_io_trace_show, qedf);
308296 }
309297
298
+/* Based on fip_state enum from libfcoe.h */
299
+static char *fip_state_names[] = {
300
+ "FIP_ST_DISABLED",
301
+ "FIP_ST_LINK_WAIT",
302
+ "FIP_ST_AUTO",
303
+ "FIP_ST_NON_FIP",
304
+ "FIP_ST_ENABLED",
305
+ "FIP_ST_VNMP_START",
306
+ "FIP_ST_VNMP_PROBE1",
307
+ "FIP_ST_VNMP_PROBE2",
308
+ "FIP_ST_VNMP_CLAIM",
309
+ "FIP_ST_VNMP_UP",
310
+};
311
+
312
+/* Based on fc_rport_state enum from libfc.h */
313
+static char *fc_rport_state_names[] = {
314
+ "RPORT_ST_INIT",
315
+ "RPORT_ST_FLOGI",
316
+ "RPORT_ST_PLOGI_WAIT",
317
+ "RPORT_ST_PLOGI",
318
+ "RPORT_ST_PRLI",
319
+ "RPORT_ST_RTV",
320
+ "RPORT_ST_READY",
321
+ "RPORT_ST_ADISC",
322
+ "RPORT_ST_DELETE",
323
+};
324
+
310325 static int
311326 qedf_driver_stats_show(struct seq_file *s, void *unused)
312327 {
....@@ -314,10 +329,28 @@
314329 struct qedf_rport *fcport;
315330 struct fc_rport_priv *rdata;
316331
332
+ seq_printf(s, "Host WWNN/WWPN: %016llx/%016llx\n",
333
+ qedf->wwnn, qedf->wwpn);
334
+ seq_printf(s, "Host NPortID: %06x\n", qedf->lport->port_id);
335
+ seq_printf(s, "Link State: %s\n", atomic_read(&qedf->link_state) ?
336
+ "Up" : "Down");
337
+ seq_printf(s, "Logical Link State: %s\n", qedf->lport->link_up ?
338
+ "Up" : "Down");
339
+ seq_printf(s, "FIP state: %s\n", fip_state_names[qedf->ctlr.state]);
340
+ seq_printf(s, "FIP VLAN ID: %d\n", qedf->vlan_id & 0xfff);
341
+ seq_printf(s, "FIP 802.1Q Priority: %d\n", qedf->prio);
342
+ if (qedf->ctlr.sel_fcf) {
343
+ seq_printf(s, "FCF WWPN: %016llx\n",
344
+ qedf->ctlr.sel_fcf->switch_name);
345
+ seq_printf(s, "FCF MAC: %pM\n", qedf->ctlr.sel_fcf->fcf_mac);
346
+ } else {
347
+ seq_puts(s, "FCF not selected\n");
348
+ }
349
+
350
+ seq_puts(s, "\nSGE stats:\n\n");
317351 seq_printf(s, "cmg_mgr free io_reqs: %d\n",
318352 atomic_read(&qedf->cmd_mgr->free_list_cnt));
319353 seq_printf(s, "slow SGEs: %d\n", qedf->slow_sge_ios);
320
- seq_printf(s, "single SGEs: %d\n", qedf->single_sge_ios);
321354 seq_printf(s, "fast SGEs: %d\n\n", qedf->fast_sge_ios);
322355
323356 seq_puts(s, "Offloaded ports:\n\n");
....@@ -327,9 +360,12 @@
327360 rdata = fcport->rdata;
328361 if (rdata == NULL)
329362 continue;
330
- seq_printf(s, "%06x: free_sqes: %d, num_active_ios: %d\n",
331
- rdata->ids.port_id, atomic_read(&fcport->free_sqes),
332
- atomic_read(&fcport->num_active_ios));
363
+ seq_printf(s, "%016llx/%016llx/%06x: state=%s, free_sqes=%d, num_active_ios=%d\n",
364
+ rdata->rport->node_name, rdata->rport->port_name,
365
+ rdata->ids.port_id,
366
+ fc_rport_state_names[rdata->rp_state],
367
+ atomic_read(&fcport->free_sqes),
368
+ atomic_read(&fcport->num_active_ios));
333369 }
334370 rcu_read_unlock();
335371
....@@ -375,7 +411,6 @@
375411
376412 /* Clear stat counters exposed by 'stats' node */
377413 qedf->slow_sge_ios = 0;
378
- qedf->single_sge_ios = 0;
379414 qedf->fast_sge_ios = 0;
380415
381416 return count;