2 * QLogic FCoE Offload Driver
3 * Copyright (c) 2016-2018 QLogic Corporation
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
11 #include <linux/uaccess.h>
12 #include <linux/debugfs.h>
13 #include <linux/module.h>
18 static struct dentry *qedf_dbg_root;
21 * qedf_dbg_host_init - setup the debugfs file for the pf
22 * @pf: the pf that is starting up
25 qedf_dbg_host_init(struct qedf_dbg_ctx *qedf,
26 const struct qedf_debugfs_ops *dops,
27 const struct file_operations *fops)
29 char host_dirname[32];
31 QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Creating debugfs host node\n");
33 sprintf(host_dirname, "host%u", qedf->host_no);
34 qedf->bdf_dentry = debugfs_create_dir(host_dirname, qedf_dbg_root);
36 /* create debugfs files */
41 debugfs_create_file(dops->name, 0600, qedf->bdf_dentry, qedf,
49 * qedf_dbg_host_exit - clear out the pf's debugfs entries
50 * @pf: the pf that is stopping
53 qedf_dbg_host_exit(struct qedf_dbg_ctx *qedf)
55 QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Destroying debugfs host "
57 /* remove debugfs entries of this PF */
58 debugfs_remove_recursive(qedf->bdf_dentry);
59 qedf->bdf_dentry = NULL;
63 * qedf_dbg_init - start up debugfs for the driver
66 qedf_dbg_init(char *drv_name)
68 QEDF_INFO(NULL, QEDF_LOG_DEBUGFS, "Creating debugfs root node\n");
70 /* create qed dir in root of debugfs. NULL means debugfs root */
71 qedf_dbg_root = debugfs_create_dir(drv_name, NULL);
75 * qedf_dbg_exit - clean out the driver's debugfs entries
80 QEDF_INFO(NULL, QEDF_LOG_DEBUGFS, "Destroying debugfs root "
83 /* remove qed dir in root of debugfs */
84 debugfs_remove_recursive(qedf_dbg_root);
88 const struct qedf_debugfs_ops qedf_debugfs_ops[] = {
92 { "stop_io_on_error", NULL},
93 { "driver_stats", NULL},
94 { "clear_stats", NULL},
95 { "offload_stats", NULL},
96 /* This must be last */
100 DECLARE_PER_CPU(struct qedf_percpu_iothread_s, qedf_percpu_iothreads);
103 qedf_dbg_fp_int_cmd_read(struct file *filp, char __user *buffer, size_t count,
108 struct qedf_fastpath *fp = NULL;
109 struct qedf_dbg_ctx *qedf_dbg =
110 (struct qedf_dbg_ctx *)filp->private_data;
111 struct qedf_ctx *qedf = container_of(qedf_dbg,
112 struct qedf_ctx, dbg_ctx);
114 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
116 cnt = sprintf(buffer, "\nFastpath I/O completions\n\n");
118 for (id = 0; id < qedf->num_queues; id++) {
119 fp = &(qedf->fp_array[id]);
120 if (fp->sb_id == QEDF_SB_ID_NULL)
122 cnt += sprintf((buffer + cnt), "#%d: %lu\n", id,
126 cnt = min_t(int, count, cnt - *ppos);
132 qedf_dbg_fp_int_cmd_write(struct file *filp, const char __user *buffer,
133 size_t count, loff_t *ppos)
142 qedf_dbg_debug_cmd_read(struct file *filp, char __user *buffer, size_t count,
146 struct qedf_dbg_ctx *qedf =
147 (struct qedf_dbg_ctx *)filp->private_data;
149 QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "entered\n");
150 cnt = sprintf(buffer, "debug mask = 0x%x\n", qedf_debug);
152 cnt = min_t(int, count, cnt - *ppos);
158 qedf_dbg_debug_cmd_write(struct file *filp, const char __user *buffer,
159 size_t count, loff_t *ppos)
164 struct qedf_dbg_ctx *qedf =
165 (struct qedf_dbg_ctx *)filp->private_data;
170 kern_buf = memdup_user(buffer, count);
171 if (IS_ERR(kern_buf))
172 return PTR_ERR(kern_buf);
174 rval = kstrtouint(kern_buf, 10, &val);
180 qedf_debug = QEDF_DEFAULT_LOG_MASK;
184 QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Setting debug=0x%x.\n", val);
189 qedf_dbg_stop_io_on_error_cmd_read(struct file *filp, char __user *buffer,
190 size_t count, loff_t *ppos)
193 struct qedf_dbg_ctx *qedf_dbg =
194 (struct qedf_dbg_ctx *)filp->private_data;
195 struct qedf_ctx *qedf = container_of(qedf_dbg,
196 struct qedf_ctx, dbg_ctx);
198 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
199 cnt = sprintf(buffer, "%s\n",
200 qedf->stop_io_on_error ? "true" : "false");
202 cnt = min_t(int, count, cnt - *ppos);
208 qedf_dbg_stop_io_on_error_cmd_write(struct file *filp,
209 const char __user *buffer, size_t count,
213 struct qedf_dbg_ctx *qedf_dbg =
214 (struct qedf_dbg_ctx *)filp->private_data;
215 struct qedf_ctx *qedf = container_of(qedf_dbg, struct qedf_ctx,
218 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
223 kern_buf = memdup_user(buffer, 6);
224 if (IS_ERR(kern_buf))
225 return PTR_ERR(kern_buf);
227 if (strncmp(kern_buf, "false", 5) == 0)
228 qedf->stop_io_on_error = false;
229 else if (strncmp(kern_buf, "true", 4) == 0)
230 qedf->stop_io_on_error = true;
231 else if (strncmp(kern_buf, "now", 3) == 0)
232 /* Trigger from user to stop all I/O on this host */
233 set_bit(QEDF_DBG_STOP_IO, &qedf->flags);
240 qedf_io_trace_show(struct seq_file *s, void *unused)
243 struct qedf_ctx *qedf = s->private;
244 struct qedf_dbg_ctx *qedf_dbg = &qedf->dbg_ctx;
245 struct qedf_io_log *io_log;
248 if (!qedf_io_tracing) {
249 seq_puts(s, "I/O tracing not enabled.\n");
253 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
255 spin_lock_irqsave(&qedf->io_trace_lock, flags);
256 idx = qedf->io_trace_idx;
257 for (i = 0; i < QEDF_IO_TRACE_SIZE; i++) {
258 io_log = &qedf->io_trace_buf[idx];
259 seq_printf(s, "%d:", io_log->direction);
260 seq_printf(s, "0x%x:", io_log->task_id);
261 seq_printf(s, "0x%06x:", io_log->port_id);
262 seq_printf(s, "%d:", io_log->lun);
263 seq_printf(s, "0x%02x:", io_log->op);
264 seq_printf(s, "0x%02x%02x%02x%02x:", io_log->lba[0],
265 io_log->lba[1], io_log->lba[2], io_log->lba[3]);
266 seq_printf(s, "%d:", io_log->bufflen);
267 seq_printf(s, "%d:", io_log->sg_count);
268 seq_printf(s, "0x%08x:", io_log->result);
269 seq_printf(s, "%lu:", io_log->jiffies);
270 seq_printf(s, "%d:", io_log->refcount);
271 seq_printf(s, "%d:", io_log->req_cpu);
272 seq_printf(s, "%d:", io_log->int_cpu);
273 seq_printf(s, "%d:", io_log->rsp_cpu);
274 seq_printf(s, "%d\n", io_log->sge_type);
277 if (idx == QEDF_IO_TRACE_SIZE)
280 spin_unlock_irqrestore(&qedf->io_trace_lock, flags);
287 qedf_dbg_io_trace_open(struct inode *inode, struct file *file)
289 struct qedf_dbg_ctx *qedf_dbg = inode->i_private;
290 struct qedf_ctx *qedf = container_of(qedf_dbg,
291 struct qedf_ctx, dbg_ctx);
293 return single_open(file, qedf_io_trace_show, qedf);
297 qedf_driver_stats_show(struct seq_file *s, void *unused)
299 struct qedf_ctx *qedf = s->private;
300 struct qedf_rport *fcport;
301 struct fc_rport_priv *rdata;
303 seq_printf(s, "cmg_mgr free io_reqs: %d\n",
304 atomic_read(&qedf->cmd_mgr->free_list_cnt));
305 seq_printf(s, "slow SGEs: %d\n", qedf->slow_sge_ios);
306 seq_printf(s, "single SGEs: %d\n", qedf->single_sge_ios);
307 seq_printf(s, "fast SGEs: %d\n\n", qedf->fast_sge_ios);
309 seq_puts(s, "Offloaded ports:\n\n");
312 list_for_each_entry_rcu(fcport, &qedf->fcports, peers) {
313 rdata = fcport->rdata;
316 seq_printf(s, "%06x: free_sqes: %d, num_active_ios: %d\n",
317 rdata->ids.port_id, atomic_read(&fcport->free_sqes),
318 atomic_read(&fcport->num_active_ios));
326 qedf_dbg_driver_stats_open(struct inode *inode, struct file *file)
328 struct qedf_dbg_ctx *qedf_dbg = inode->i_private;
329 struct qedf_ctx *qedf = container_of(qedf_dbg,
330 struct qedf_ctx, dbg_ctx);
332 return single_open(file, qedf_driver_stats_show, qedf);
336 qedf_dbg_clear_stats_cmd_read(struct file *filp, char __user *buffer,
337 size_t count, loff_t *ppos)
341 /* Essentially a read stub */
342 cnt = min_t(int, count, cnt - *ppos);
348 qedf_dbg_clear_stats_cmd_write(struct file *filp,
349 const char __user *buffer, size_t count,
352 struct qedf_dbg_ctx *qedf_dbg =
353 (struct qedf_dbg_ctx *)filp->private_data;
354 struct qedf_ctx *qedf = container_of(qedf_dbg, struct qedf_ctx,
357 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "Clearing stat counters.\n");
362 /* Clear stat counters exposed by 'stats' node */
363 qedf->slow_sge_ios = 0;
364 qedf->single_sge_ios = 0;
365 qedf->fast_sge_ios = 0;
371 qedf_offload_stats_show(struct seq_file *s, void *unused)
373 struct qedf_ctx *qedf = s->private;
374 struct qed_fcoe_stats *fw_fcoe_stats;
376 fw_fcoe_stats = kmalloc(sizeof(struct qed_fcoe_stats), GFP_KERNEL);
377 if (!fw_fcoe_stats) {
378 QEDF_ERR(&(qedf->dbg_ctx), "Could not allocate memory for "
383 /* Query firmware for offload stats */
384 qed_ops->get_stats(qedf->cdev, fw_fcoe_stats);
386 seq_printf(s, "fcoe_rx_byte_cnt=%llu\n"
387 "fcoe_rx_data_pkt_cnt=%llu\n"
388 "fcoe_rx_xfer_pkt_cnt=%llu\n"
389 "fcoe_rx_other_pkt_cnt=%llu\n"
390 "fcoe_silent_drop_pkt_cmdq_full_cnt=%u\n"
391 "fcoe_silent_drop_pkt_crc_error_cnt=%u\n"
392 "fcoe_silent_drop_pkt_task_invalid_cnt=%u\n"
393 "fcoe_silent_drop_total_pkt_cnt=%u\n"
394 "fcoe_silent_drop_pkt_rq_full_cnt=%u\n"
395 "fcoe_tx_byte_cnt=%llu\n"
396 "fcoe_tx_data_pkt_cnt=%llu\n"
397 "fcoe_tx_xfer_pkt_cnt=%llu\n"
398 "fcoe_tx_other_pkt_cnt=%llu\n",
399 fw_fcoe_stats->fcoe_rx_byte_cnt,
400 fw_fcoe_stats->fcoe_rx_data_pkt_cnt,
401 fw_fcoe_stats->fcoe_rx_xfer_pkt_cnt,
402 fw_fcoe_stats->fcoe_rx_other_pkt_cnt,
403 fw_fcoe_stats->fcoe_silent_drop_pkt_cmdq_full_cnt,
404 fw_fcoe_stats->fcoe_silent_drop_pkt_crc_error_cnt,
405 fw_fcoe_stats->fcoe_silent_drop_pkt_task_invalid_cnt,
406 fw_fcoe_stats->fcoe_silent_drop_total_pkt_cnt,
407 fw_fcoe_stats->fcoe_silent_drop_pkt_rq_full_cnt,
408 fw_fcoe_stats->fcoe_tx_byte_cnt,
409 fw_fcoe_stats->fcoe_tx_data_pkt_cnt,
410 fw_fcoe_stats->fcoe_tx_xfer_pkt_cnt,
411 fw_fcoe_stats->fcoe_tx_other_pkt_cnt);
413 kfree(fw_fcoe_stats);
419 qedf_dbg_offload_stats_open(struct inode *inode, struct file *file)
421 struct qedf_dbg_ctx *qedf_dbg = inode->i_private;
422 struct qedf_ctx *qedf = container_of(qedf_dbg,
423 struct qedf_ctx, dbg_ctx);
425 return single_open(file, qedf_offload_stats_show, qedf);
428 const struct file_operations qedf_dbg_fops[] = {
429 qedf_dbg_fileops(qedf, fp_int),
430 qedf_dbg_fileops_seq(qedf, io_trace),
431 qedf_dbg_fileops(qedf, debug),
432 qedf_dbg_fileops(qedf, stop_io_on_error),
433 qedf_dbg_fileops_seq(qedf, driver_stats),
434 qedf_dbg_fileops(qedf, clear_stats),
435 qedf_dbg_fileops_seq(qedf, offload_stats),
436 /* This must be last */
440 #else /* CONFIG_DEBUG_FS */
441 void qedf_dbg_host_init(struct qedf_dbg_ctx *);
442 void qedf_dbg_host_exit(struct qedf_dbg_ctx *);
443 void qedf_dbg_init(char *);
444 void qedf_dbg_exit(void);
445 #endif /* CONFIG_DEBUG_FS */