2 * QLogic FCoE Offload Driver
3 * Copyright (c) 2016-2017 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>
14 #include <linux/vmalloc.h>
19 static struct dentry *qedf_dbg_root;
22 * qedf_dbg_host_init - setup the debugfs file for the pf
23 * @pf: the pf that is starting up
26 qedf_dbg_host_init(struct qedf_dbg_ctx *qedf,
27 struct qedf_debugfs_ops *dops,
28 struct file_operations *fops)
30 char host_dirname[32];
31 struct dentry *file_dentry = NULL;
33 QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Creating debugfs host node\n");
35 sprintf(host_dirname, "host%u", qedf->host_no);
36 qedf->bdf_dentry = debugfs_create_dir(host_dirname, qedf_dbg_root);
37 if (!qedf->bdf_dentry)
40 /* create debugfs files */
45 file_dentry = debugfs_create_file(dops->name, 0600,
46 qedf->bdf_dentry, qedf,
49 QEDF_INFO(qedf, QEDF_LOG_DEBUGFS,
50 "Debugfs entry %s creation failed\n",
52 debugfs_remove_recursive(qedf->bdf_dentry);
61 * qedf_dbg_host_exit - clear out the pf's debugfs entries
62 * @pf: the pf that is stopping
65 qedf_dbg_host_exit(struct qedf_dbg_ctx *qedf)
67 QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Destroying debugfs host "
69 /* remove debugfs entries of this PF */
70 debugfs_remove_recursive(qedf->bdf_dentry);
71 qedf->bdf_dentry = NULL;
75 * qedf_dbg_init - start up debugfs for the driver
78 qedf_dbg_init(char *drv_name)
80 QEDF_INFO(NULL, QEDF_LOG_DEBUGFS, "Creating debugfs root node\n");
82 /* create qed dir in root of debugfs. NULL means debugfs root */
83 qedf_dbg_root = debugfs_create_dir(drv_name, NULL);
85 QEDF_INFO(NULL, QEDF_LOG_DEBUGFS, "Init of debugfs "
90 * qedf_dbg_exit - clean out the driver's debugfs entries
95 QEDF_INFO(NULL, QEDF_LOG_DEBUGFS, "Destroying debugfs root "
98 /* remove qed dir in root of debugfs */
99 debugfs_remove_recursive(qedf_dbg_root);
100 qedf_dbg_root = NULL;
103 struct qedf_debugfs_ops qedf_debugfs_ops[] = {
105 { "io_trace", NULL },
107 { "stop_io_on_error", NULL},
108 { "driver_stats", NULL},
109 { "clear_stats", NULL},
110 { "offload_stats", NULL},
111 /* This must be last */
115 DECLARE_PER_CPU(struct qedf_percpu_iothread_s, qedf_percpu_iothreads);
118 qedf_dbg_fp_int_cmd_read(struct file *filp, char __user *buffer, size_t count,
125 struct qedf_fastpath *fp = NULL;
126 struct qedf_dbg_ctx *qedf_dbg =
127 (struct qedf_dbg_ctx *)filp->private_data;
128 struct qedf_ctx *qedf = container_of(qedf_dbg,
129 struct qedf_ctx, dbg_ctx);
131 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
133 cbuf = vmalloc(QEDF_DEBUGFS_LOG_LEN);
137 cnt += scnprintf(cbuf + cnt, QEDF_DEBUGFS_LOG_LEN - cnt, "\nFastpath I/O completions\n\n");
139 for (id = 0; id < qedf->num_queues; id++) {
140 fp = &(qedf->fp_array[id]);
141 if (fp->sb_id == QEDF_SB_ID_NULL)
143 cnt += scnprintf(cbuf + cnt, QEDF_DEBUGFS_LOG_LEN - cnt,
144 "#%d: %lu\n", id, fp->completions);
147 ret = simple_read_from_buffer(buffer, count, ppos, cbuf, cnt);
155 qedf_dbg_fp_int_cmd_write(struct file *filp, const char __user *buffer,
156 size_t count, loff_t *ppos)
165 qedf_dbg_debug_cmd_read(struct file *filp, char __user *buffer, size_t count,
169 struct qedf_dbg_ctx *qedf =
170 (struct qedf_dbg_ctx *)filp->private_data;
172 QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "entered\n");
173 cnt = sprintf(buffer, "debug mask = 0x%x\n", qedf_debug);
175 cnt = min_t(int, count, cnt - *ppos);
181 qedf_dbg_debug_cmd_write(struct file *filp, const char __user *buffer,
182 size_t count, loff_t *ppos)
187 struct qedf_dbg_ctx *qedf =
188 (struct qedf_dbg_ctx *)filp->private_data;
193 kern_buf = memdup_user(buffer, count);
194 if (IS_ERR(kern_buf))
195 return PTR_ERR(kern_buf);
197 rval = kstrtouint(kern_buf, 10, &val);
203 qedf_debug = QEDF_DEFAULT_LOG_MASK;
207 QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Setting debug=0x%x.\n", val);
212 qedf_dbg_stop_io_on_error_cmd_read(struct file *filp, char __user *buffer,
213 size_t count, loff_t *ppos)
217 struct qedf_dbg_ctx *qedf_dbg =
218 (struct qedf_dbg_ctx *)filp->private_data;
219 struct qedf_ctx *qedf = container_of(qedf_dbg,
220 struct qedf_ctx, dbg_ctx);
222 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
223 cnt = scnprintf(cbuf, sizeof(cbuf), "%s\n",
224 qedf->stop_io_on_error ? "true" : "false");
226 return simple_read_from_buffer(buffer, count, ppos, cbuf, cnt);
230 qedf_dbg_stop_io_on_error_cmd_write(struct file *filp,
231 const char __user *buffer, size_t count,
235 struct qedf_dbg_ctx *qedf_dbg =
236 (struct qedf_dbg_ctx *)filp->private_data;
237 struct qedf_ctx *qedf = container_of(qedf_dbg, struct qedf_ctx,
240 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
245 kern_buf = memdup_user(buffer, 6);
246 if (IS_ERR(kern_buf))
247 return PTR_ERR(kern_buf);
249 if (strncmp(kern_buf, "false", 5) == 0)
250 qedf->stop_io_on_error = false;
251 else if (strncmp(kern_buf, "true", 4) == 0)
252 qedf->stop_io_on_error = true;
253 else if (strncmp(kern_buf, "now", 3) == 0)
254 /* Trigger from user to stop all I/O on this host */
255 set_bit(QEDF_DBG_STOP_IO, &qedf->flags);
262 qedf_io_trace_show(struct seq_file *s, void *unused)
265 struct qedf_ctx *qedf = s->private;
266 struct qedf_dbg_ctx *qedf_dbg = &qedf->dbg_ctx;
267 struct qedf_io_log *io_log;
270 if (!qedf_io_tracing) {
271 seq_puts(s, "I/O tracing not enabled.\n");
275 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
277 spin_lock_irqsave(&qedf->io_trace_lock, flags);
278 idx = qedf->io_trace_idx;
279 for (i = 0; i < QEDF_IO_TRACE_SIZE; i++) {
280 io_log = &qedf->io_trace_buf[idx];
281 seq_printf(s, "%d:", io_log->direction);
282 seq_printf(s, "0x%x:", io_log->task_id);
283 seq_printf(s, "0x%06x:", io_log->port_id);
284 seq_printf(s, "%d:", io_log->lun);
285 seq_printf(s, "0x%02x:", io_log->op);
286 seq_printf(s, "0x%02x%02x%02x%02x:", io_log->lba[0],
287 io_log->lba[1], io_log->lba[2], io_log->lba[3]);
288 seq_printf(s, "%d:", io_log->bufflen);
289 seq_printf(s, "%d:", io_log->sg_count);
290 seq_printf(s, "0x%08x:", io_log->result);
291 seq_printf(s, "%lu:", io_log->jiffies);
292 seq_printf(s, "%d:", io_log->refcount);
293 seq_printf(s, "%d:", io_log->req_cpu);
294 seq_printf(s, "%d:", io_log->int_cpu);
295 seq_printf(s, "%d:", io_log->rsp_cpu);
296 seq_printf(s, "%d\n", io_log->sge_type);
299 if (idx == QEDF_IO_TRACE_SIZE)
302 spin_unlock_irqrestore(&qedf->io_trace_lock, flags);
309 qedf_dbg_io_trace_open(struct inode *inode, struct file *file)
311 struct qedf_dbg_ctx *qedf_dbg = inode->i_private;
312 struct qedf_ctx *qedf = container_of(qedf_dbg,
313 struct qedf_ctx, dbg_ctx);
315 return single_open(file, qedf_io_trace_show, qedf);
319 qedf_driver_stats_show(struct seq_file *s, void *unused)
321 struct qedf_ctx *qedf = s->private;
322 struct qedf_rport *fcport;
323 struct fc_rport_priv *rdata;
325 seq_printf(s, "cmg_mgr free io_reqs: %d\n",
326 atomic_read(&qedf->cmd_mgr->free_list_cnt));
327 seq_printf(s, "slow SGEs: %d\n", qedf->slow_sge_ios);
328 seq_printf(s, "single SGEs: %d\n", qedf->single_sge_ios);
329 seq_printf(s, "fast SGEs: %d\n\n", qedf->fast_sge_ios);
331 seq_puts(s, "Offloaded ports:\n\n");
334 list_for_each_entry_rcu(fcport, &qedf->fcports, peers) {
335 rdata = fcport->rdata;
338 seq_printf(s, "%06x: free_sqes: %d, num_active_ios: %d\n",
339 rdata->ids.port_id, atomic_read(&fcport->free_sqes),
340 atomic_read(&fcport->num_active_ios));
348 qedf_dbg_driver_stats_open(struct inode *inode, struct file *file)
350 struct qedf_dbg_ctx *qedf_dbg = inode->i_private;
351 struct qedf_ctx *qedf = container_of(qedf_dbg,
352 struct qedf_ctx, dbg_ctx);
354 return single_open(file, qedf_driver_stats_show, qedf);
358 qedf_dbg_clear_stats_cmd_read(struct file *filp, char __user *buffer,
359 size_t count, loff_t *ppos)
363 /* Essentially a read stub */
364 cnt = min_t(int, count, cnt - *ppos);
370 qedf_dbg_clear_stats_cmd_write(struct file *filp,
371 const char __user *buffer, size_t count,
374 struct qedf_dbg_ctx *qedf_dbg =
375 (struct qedf_dbg_ctx *)filp->private_data;
376 struct qedf_ctx *qedf = container_of(qedf_dbg, struct qedf_ctx,
379 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "Clearing stat counters.\n");
384 /* Clear stat counters exposed by 'stats' node */
385 qedf->slow_sge_ios = 0;
386 qedf->single_sge_ios = 0;
387 qedf->fast_sge_ios = 0;
393 qedf_offload_stats_show(struct seq_file *s, void *unused)
395 struct qedf_ctx *qedf = s->private;
396 struct qed_fcoe_stats *fw_fcoe_stats;
398 fw_fcoe_stats = kmalloc(sizeof(struct qed_fcoe_stats), GFP_KERNEL);
399 if (!fw_fcoe_stats) {
400 QEDF_ERR(&(qedf->dbg_ctx), "Could not allocate memory for "
405 /* Query firmware for offload stats */
406 qed_ops->get_stats(qedf->cdev, fw_fcoe_stats);
408 seq_printf(s, "fcoe_rx_byte_cnt=%llu\n"
409 "fcoe_rx_data_pkt_cnt=%llu\n"
410 "fcoe_rx_xfer_pkt_cnt=%llu\n"
411 "fcoe_rx_other_pkt_cnt=%llu\n"
412 "fcoe_silent_drop_pkt_cmdq_full_cnt=%u\n"
413 "fcoe_silent_drop_pkt_crc_error_cnt=%u\n"
414 "fcoe_silent_drop_pkt_task_invalid_cnt=%u\n"
415 "fcoe_silent_drop_total_pkt_cnt=%u\n"
416 "fcoe_silent_drop_pkt_rq_full_cnt=%u\n"
417 "fcoe_tx_byte_cnt=%llu\n"
418 "fcoe_tx_data_pkt_cnt=%llu\n"
419 "fcoe_tx_xfer_pkt_cnt=%llu\n"
420 "fcoe_tx_other_pkt_cnt=%llu\n",
421 fw_fcoe_stats->fcoe_rx_byte_cnt,
422 fw_fcoe_stats->fcoe_rx_data_pkt_cnt,
423 fw_fcoe_stats->fcoe_rx_xfer_pkt_cnt,
424 fw_fcoe_stats->fcoe_rx_other_pkt_cnt,
425 fw_fcoe_stats->fcoe_silent_drop_pkt_cmdq_full_cnt,
426 fw_fcoe_stats->fcoe_silent_drop_pkt_crc_error_cnt,
427 fw_fcoe_stats->fcoe_silent_drop_pkt_task_invalid_cnt,
428 fw_fcoe_stats->fcoe_silent_drop_total_pkt_cnt,
429 fw_fcoe_stats->fcoe_silent_drop_pkt_rq_full_cnt,
430 fw_fcoe_stats->fcoe_tx_byte_cnt,
431 fw_fcoe_stats->fcoe_tx_data_pkt_cnt,
432 fw_fcoe_stats->fcoe_tx_xfer_pkt_cnt,
433 fw_fcoe_stats->fcoe_tx_other_pkt_cnt);
435 kfree(fw_fcoe_stats);
441 qedf_dbg_offload_stats_open(struct inode *inode, struct file *file)
443 struct qedf_dbg_ctx *qedf_dbg = inode->i_private;
444 struct qedf_ctx *qedf = container_of(qedf_dbg,
445 struct qedf_ctx, dbg_ctx);
447 return single_open(file, qedf_offload_stats_show, qedf);
451 const struct file_operations qedf_dbg_fops[] = {
452 qedf_dbg_fileops(qedf, fp_int),
453 qedf_dbg_fileops_seq(qedf, io_trace),
454 qedf_dbg_fileops(qedf, debug),
455 qedf_dbg_fileops(qedf, stop_io_on_error),
456 qedf_dbg_fileops_seq(qedf, driver_stats),
457 qedf_dbg_fileops(qedf, clear_stats),
458 qedf_dbg_fileops_seq(qedf, offload_stats),
459 /* This must be last */
463 #else /* CONFIG_DEBUG_FS */
464 void qedf_dbg_host_init(struct qedf_dbg_ctx *);
465 void qedf_dbg_host_exit(struct qedf_dbg_ctx *);
466 void qedf_dbg_init(char *);
467 void qedf_dbg_exit(void);
468 #endif /* CONFIG_DEBUG_FS */