161d8658bSDupuis, Chad /* 261d8658bSDupuis, Chad * QLogic FCoE Offload Driver 312d0b12cSChad Dupuis * Copyright (c) 2016-2017 QLogic Corporation 461d8658bSDupuis, Chad * 561d8658bSDupuis, Chad * This software is available under the terms of the GNU General Public License 661d8658bSDupuis, Chad * (GPL) Version 2, available from the file COPYING in the main directory of 761d8658bSDupuis, Chad * this source tree. 861d8658bSDupuis, Chad */ 961d8658bSDupuis, Chad #ifdef CONFIG_DEBUG_FS 1061d8658bSDupuis, Chad 1161d8658bSDupuis, Chad #include <linux/uaccess.h> 1261d8658bSDupuis, Chad #include <linux/debugfs.h> 1361d8658bSDupuis, Chad #include <linux/module.h> 1461d8658bSDupuis, Chad 1561d8658bSDupuis, Chad #include "qedf.h" 1661d8658bSDupuis, Chad #include "qedf_dbg.h" 1761d8658bSDupuis, Chad 1861d8658bSDupuis, Chad static struct dentry *qedf_dbg_root; 1961d8658bSDupuis, Chad 2061d8658bSDupuis, Chad /** 2161d8658bSDupuis, Chad * qedf_dbg_host_init - setup the debugfs file for the pf 2261d8658bSDupuis, Chad * @pf: the pf that is starting up 2361d8658bSDupuis, Chad **/ 2461d8658bSDupuis, Chad void 2561d8658bSDupuis, Chad qedf_dbg_host_init(struct qedf_dbg_ctx *qedf, 26*d9ea463aSArnd Bergmann const struct qedf_debugfs_ops *dops, 27*d9ea463aSArnd Bergmann const struct file_operations *fops) 2861d8658bSDupuis, Chad { 2961d8658bSDupuis, Chad char host_dirname[32]; 3061d8658bSDupuis, Chad struct dentry *file_dentry = NULL; 3161d8658bSDupuis, Chad 3261d8658bSDupuis, Chad QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Creating debugfs host node\n"); 3361d8658bSDupuis, Chad /* create pf dir */ 3461d8658bSDupuis, Chad sprintf(host_dirname, "host%u", qedf->host_no); 3561d8658bSDupuis, Chad qedf->bdf_dentry = debugfs_create_dir(host_dirname, qedf_dbg_root); 3661d8658bSDupuis, Chad if (!qedf->bdf_dentry) 3761d8658bSDupuis, Chad return; 3861d8658bSDupuis, Chad 3961d8658bSDupuis, Chad /* create debugfs files */ 4061d8658bSDupuis, Chad while (dops) { 4161d8658bSDupuis, Chad if (!(dops->name)) 4261d8658bSDupuis, Chad break; 4361d8658bSDupuis, Chad 4461d8658bSDupuis, Chad file_dentry = debugfs_create_file(dops->name, 0600, 4561d8658bSDupuis, Chad qedf->bdf_dentry, qedf, 4661d8658bSDupuis, Chad fops); 4761d8658bSDupuis, Chad if (!file_dentry) { 4861d8658bSDupuis, Chad QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, 4961d8658bSDupuis, Chad "Debugfs entry %s creation failed\n", 5061d8658bSDupuis, Chad dops->name); 5161d8658bSDupuis, Chad debugfs_remove_recursive(qedf->bdf_dentry); 5261d8658bSDupuis, Chad return; 5361d8658bSDupuis, Chad } 5461d8658bSDupuis, Chad dops++; 5561d8658bSDupuis, Chad fops++; 5661d8658bSDupuis, Chad } 5761d8658bSDupuis, Chad } 5861d8658bSDupuis, Chad 5961d8658bSDupuis, Chad /** 6061d8658bSDupuis, Chad * qedf_dbg_host_exit - clear out the pf's debugfs entries 6161d8658bSDupuis, Chad * @pf: the pf that is stopping 6261d8658bSDupuis, Chad **/ 6361d8658bSDupuis, Chad void 6461d8658bSDupuis, Chad qedf_dbg_host_exit(struct qedf_dbg_ctx *qedf) 6561d8658bSDupuis, Chad { 6661d8658bSDupuis, Chad QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Destroying debugfs host " 6761d8658bSDupuis, Chad "entry\n"); 6861d8658bSDupuis, Chad /* remove debugfs entries of this PF */ 6961d8658bSDupuis, Chad debugfs_remove_recursive(qedf->bdf_dentry); 7061d8658bSDupuis, Chad qedf->bdf_dentry = NULL; 7161d8658bSDupuis, Chad } 7261d8658bSDupuis, Chad 7361d8658bSDupuis, Chad /** 7461d8658bSDupuis, Chad * qedf_dbg_init - start up debugfs for the driver 7561d8658bSDupuis, Chad **/ 7661d8658bSDupuis, Chad void 7761d8658bSDupuis, Chad qedf_dbg_init(char *drv_name) 7861d8658bSDupuis, Chad { 7961d8658bSDupuis, Chad QEDF_INFO(NULL, QEDF_LOG_DEBUGFS, "Creating debugfs root node\n"); 8061d8658bSDupuis, Chad 8161d8658bSDupuis, Chad /* create qed dir in root of debugfs. NULL means debugfs root */ 8261d8658bSDupuis, Chad qedf_dbg_root = debugfs_create_dir(drv_name, NULL); 8361d8658bSDupuis, Chad if (!qedf_dbg_root) 8461d8658bSDupuis, Chad QEDF_INFO(NULL, QEDF_LOG_DEBUGFS, "Init of debugfs " 8561d8658bSDupuis, Chad "failed\n"); 8661d8658bSDupuis, Chad } 8761d8658bSDupuis, Chad 8861d8658bSDupuis, Chad /** 8961d8658bSDupuis, Chad * qedf_dbg_exit - clean out the driver's debugfs entries 9061d8658bSDupuis, Chad **/ 9161d8658bSDupuis, Chad void 9261d8658bSDupuis, Chad qedf_dbg_exit(void) 9361d8658bSDupuis, Chad { 9461d8658bSDupuis, Chad QEDF_INFO(NULL, QEDF_LOG_DEBUGFS, "Destroying debugfs root " 9561d8658bSDupuis, Chad "entry\n"); 9661d8658bSDupuis, Chad 9761d8658bSDupuis, Chad /* remove qed dir in root of debugfs */ 9861d8658bSDupuis, Chad debugfs_remove_recursive(qedf_dbg_root); 9961d8658bSDupuis, Chad qedf_dbg_root = NULL; 10061d8658bSDupuis, Chad } 10161d8658bSDupuis, Chad 102*d9ea463aSArnd Bergmann const struct qedf_debugfs_ops qedf_debugfs_ops[] = { 10361d8658bSDupuis, Chad { "fp_int", NULL }, 10461d8658bSDupuis, Chad { "io_trace", NULL }, 10561d8658bSDupuis, Chad { "debug", NULL }, 10661d8658bSDupuis, Chad { "stop_io_on_error", NULL}, 10761d8658bSDupuis, Chad { "driver_stats", NULL}, 10861d8658bSDupuis, Chad { "clear_stats", NULL}, 10961d8658bSDupuis, Chad { "offload_stats", NULL}, 11061d8658bSDupuis, Chad /* This must be last */ 11161d8658bSDupuis, Chad { NULL, NULL } 11261d8658bSDupuis, Chad }; 11361d8658bSDupuis, Chad 11461d8658bSDupuis, Chad DECLARE_PER_CPU(struct qedf_percpu_iothread_s, qedf_percpu_iothreads); 11561d8658bSDupuis, Chad 11661d8658bSDupuis, Chad static ssize_t 11761d8658bSDupuis, Chad qedf_dbg_fp_int_cmd_read(struct file *filp, char __user *buffer, size_t count, 11861d8658bSDupuis, Chad loff_t *ppos) 11961d8658bSDupuis, Chad { 12061d8658bSDupuis, Chad size_t cnt = 0; 12161d8658bSDupuis, Chad int id; 12261d8658bSDupuis, Chad struct qedf_fastpath *fp = NULL; 12361d8658bSDupuis, Chad struct qedf_dbg_ctx *qedf_dbg = 12461d8658bSDupuis, Chad (struct qedf_dbg_ctx *)filp->private_data; 12561d8658bSDupuis, Chad struct qedf_ctx *qedf = container_of(qedf_dbg, 12661d8658bSDupuis, Chad struct qedf_ctx, dbg_ctx); 12761d8658bSDupuis, Chad 12861d8658bSDupuis, Chad QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n"); 12961d8658bSDupuis, Chad 13061d8658bSDupuis, Chad cnt = sprintf(buffer, "\nFastpath I/O completions\n\n"); 13161d8658bSDupuis, Chad 13261d8658bSDupuis, Chad for (id = 0; id < qedf->num_queues; id++) { 13361d8658bSDupuis, Chad fp = &(qedf->fp_array[id]); 13461d8658bSDupuis, Chad if (fp->sb_id == QEDF_SB_ID_NULL) 13561d8658bSDupuis, Chad continue; 13661d8658bSDupuis, Chad cnt += sprintf((buffer + cnt), "#%d: %lu\n", id, 13761d8658bSDupuis, Chad fp->completions); 13861d8658bSDupuis, Chad } 13961d8658bSDupuis, Chad 14061d8658bSDupuis, Chad cnt = min_t(int, count, cnt - *ppos); 14161d8658bSDupuis, Chad *ppos += cnt; 14261d8658bSDupuis, Chad return cnt; 14361d8658bSDupuis, Chad } 14461d8658bSDupuis, Chad 14561d8658bSDupuis, Chad static ssize_t 14661d8658bSDupuis, Chad qedf_dbg_fp_int_cmd_write(struct file *filp, const char __user *buffer, 14761d8658bSDupuis, Chad size_t count, loff_t *ppos) 14861d8658bSDupuis, Chad { 14961d8658bSDupuis, Chad if (!count || *ppos) 15061d8658bSDupuis, Chad return 0; 15161d8658bSDupuis, Chad 15261d8658bSDupuis, Chad return count; 15361d8658bSDupuis, Chad } 15461d8658bSDupuis, Chad 15561d8658bSDupuis, Chad static ssize_t 15661d8658bSDupuis, Chad qedf_dbg_debug_cmd_read(struct file *filp, char __user *buffer, size_t count, 15761d8658bSDupuis, Chad loff_t *ppos) 15861d8658bSDupuis, Chad { 15961d8658bSDupuis, Chad int cnt; 16061d8658bSDupuis, Chad struct qedf_dbg_ctx *qedf = 16161d8658bSDupuis, Chad (struct qedf_dbg_ctx *)filp->private_data; 16261d8658bSDupuis, Chad 16361d8658bSDupuis, Chad QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "entered\n"); 16461d8658bSDupuis, Chad cnt = sprintf(buffer, "debug mask = 0x%x\n", qedf_debug); 16561d8658bSDupuis, Chad 16661d8658bSDupuis, Chad cnt = min_t(int, count, cnt - *ppos); 16761d8658bSDupuis, Chad *ppos += cnt; 16861d8658bSDupuis, Chad return cnt; 16961d8658bSDupuis, Chad } 17061d8658bSDupuis, Chad 17161d8658bSDupuis, Chad static ssize_t 17261d8658bSDupuis, Chad qedf_dbg_debug_cmd_write(struct file *filp, const char __user *buffer, 17361d8658bSDupuis, Chad size_t count, loff_t *ppos) 17461d8658bSDupuis, Chad { 17561d8658bSDupuis, Chad uint32_t val; 17661d8658bSDupuis, Chad void *kern_buf; 17761d8658bSDupuis, Chad int rval; 17861d8658bSDupuis, Chad struct qedf_dbg_ctx *qedf = 17961d8658bSDupuis, Chad (struct qedf_dbg_ctx *)filp->private_data; 18061d8658bSDupuis, Chad 18161d8658bSDupuis, Chad if (!count || *ppos) 18261d8658bSDupuis, Chad return 0; 18361d8658bSDupuis, Chad 18461d8658bSDupuis, Chad kern_buf = memdup_user(buffer, count); 18561d8658bSDupuis, Chad if (IS_ERR(kern_buf)) 18661d8658bSDupuis, Chad return PTR_ERR(kern_buf); 18761d8658bSDupuis, Chad 18861d8658bSDupuis, Chad rval = kstrtouint(kern_buf, 10, &val); 18961d8658bSDupuis, Chad kfree(kern_buf); 19061d8658bSDupuis, Chad if (rval) 19161d8658bSDupuis, Chad return rval; 19261d8658bSDupuis, Chad 19361d8658bSDupuis, Chad if (val == 1) 19461d8658bSDupuis, Chad qedf_debug = QEDF_DEFAULT_LOG_MASK; 19561d8658bSDupuis, Chad else 19661d8658bSDupuis, Chad qedf_debug = val; 19761d8658bSDupuis, Chad 19861d8658bSDupuis, Chad QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Setting debug=0x%x.\n", val); 19961d8658bSDupuis, Chad return count; 20061d8658bSDupuis, Chad } 20161d8658bSDupuis, Chad 20261d8658bSDupuis, Chad static ssize_t 20361d8658bSDupuis, Chad qedf_dbg_stop_io_on_error_cmd_read(struct file *filp, char __user *buffer, 20461d8658bSDupuis, Chad size_t count, loff_t *ppos) 20561d8658bSDupuis, Chad { 20661d8658bSDupuis, Chad int cnt; 20761d8658bSDupuis, Chad struct qedf_dbg_ctx *qedf_dbg = 20861d8658bSDupuis, Chad (struct qedf_dbg_ctx *)filp->private_data; 20961d8658bSDupuis, Chad struct qedf_ctx *qedf = container_of(qedf_dbg, 21061d8658bSDupuis, Chad struct qedf_ctx, dbg_ctx); 21161d8658bSDupuis, Chad 21261d8658bSDupuis, Chad QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n"); 21361d8658bSDupuis, Chad cnt = sprintf(buffer, "%s\n", 21461d8658bSDupuis, Chad qedf->stop_io_on_error ? "true" : "false"); 21561d8658bSDupuis, Chad 21661d8658bSDupuis, Chad cnt = min_t(int, count, cnt - *ppos); 21761d8658bSDupuis, Chad *ppos += cnt; 21861d8658bSDupuis, Chad return cnt; 21961d8658bSDupuis, Chad } 22061d8658bSDupuis, Chad 22161d8658bSDupuis, Chad static ssize_t 22261d8658bSDupuis, Chad qedf_dbg_stop_io_on_error_cmd_write(struct file *filp, 22361d8658bSDupuis, Chad const char __user *buffer, size_t count, 22461d8658bSDupuis, Chad loff_t *ppos) 22561d8658bSDupuis, Chad { 22661d8658bSDupuis, Chad void *kern_buf; 22761d8658bSDupuis, Chad struct qedf_dbg_ctx *qedf_dbg = 22861d8658bSDupuis, Chad (struct qedf_dbg_ctx *)filp->private_data; 22961d8658bSDupuis, Chad struct qedf_ctx *qedf = container_of(qedf_dbg, struct qedf_ctx, 23061d8658bSDupuis, Chad dbg_ctx); 23161d8658bSDupuis, Chad 23261d8658bSDupuis, Chad QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n"); 23361d8658bSDupuis, Chad 23461d8658bSDupuis, Chad if (!count || *ppos) 23561d8658bSDupuis, Chad return 0; 23661d8658bSDupuis, Chad 23761d8658bSDupuis, Chad kern_buf = memdup_user(buffer, 6); 23861d8658bSDupuis, Chad if (IS_ERR(kern_buf)) 23961d8658bSDupuis, Chad return PTR_ERR(kern_buf); 24061d8658bSDupuis, Chad 24161d8658bSDupuis, Chad if (strncmp(kern_buf, "false", 5) == 0) 24261d8658bSDupuis, Chad qedf->stop_io_on_error = false; 24361d8658bSDupuis, Chad else if (strncmp(kern_buf, "true", 4) == 0) 24461d8658bSDupuis, Chad qedf->stop_io_on_error = true; 24561d8658bSDupuis, Chad else if (strncmp(kern_buf, "now", 3) == 0) 24661d8658bSDupuis, Chad /* Trigger from user to stop all I/O on this host */ 24761d8658bSDupuis, Chad set_bit(QEDF_DBG_STOP_IO, &qedf->flags); 24861d8658bSDupuis, Chad 24961d8658bSDupuis, Chad kfree(kern_buf); 25061d8658bSDupuis, Chad return count; 25161d8658bSDupuis, Chad } 25261d8658bSDupuis, Chad 25361d8658bSDupuis, Chad static int 25461d8658bSDupuis, Chad qedf_io_trace_show(struct seq_file *s, void *unused) 25561d8658bSDupuis, Chad { 25661d8658bSDupuis, Chad int i, idx = 0; 25761d8658bSDupuis, Chad struct qedf_ctx *qedf = s->private; 25861d8658bSDupuis, Chad struct qedf_dbg_ctx *qedf_dbg = &qedf->dbg_ctx; 25961d8658bSDupuis, Chad struct qedf_io_log *io_log; 26061d8658bSDupuis, Chad unsigned long flags; 26161d8658bSDupuis, Chad 26261d8658bSDupuis, Chad if (!qedf_io_tracing) { 26361d8658bSDupuis, Chad seq_puts(s, "I/O tracing not enabled.\n"); 26461d8658bSDupuis, Chad goto out; 26561d8658bSDupuis, Chad } 26661d8658bSDupuis, Chad 26761d8658bSDupuis, Chad QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n"); 26861d8658bSDupuis, Chad 26961d8658bSDupuis, Chad spin_lock_irqsave(&qedf->io_trace_lock, flags); 27061d8658bSDupuis, Chad idx = qedf->io_trace_idx; 27161d8658bSDupuis, Chad for (i = 0; i < QEDF_IO_TRACE_SIZE; i++) { 27261d8658bSDupuis, Chad io_log = &qedf->io_trace_buf[idx]; 27361d8658bSDupuis, Chad seq_printf(s, "%d:", io_log->direction); 27461d8658bSDupuis, Chad seq_printf(s, "0x%x:", io_log->task_id); 27561d8658bSDupuis, Chad seq_printf(s, "0x%06x:", io_log->port_id); 27661d8658bSDupuis, Chad seq_printf(s, "%d:", io_log->lun); 27761d8658bSDupuis, Chad seq_printf(s, "0x%02x:", io_log->op); 27861d8658bSDupuis, Chad seq_printf(s, "0x%02x%02x%02x%02x:", io_log->lba[0], 27961d8658bSDupuis, Chad io_log->lba[1], io_log->lba[2], io_log->lba[3]); 28061d8658bSDupuis, Chad seq_printf(s, "%d:", io_log->bufflen); 28161d8658bSDupuis, Chad seq_printf(s, "%d:", io_log->sg_count); 28261d8658bSDupuis, Chad seq_printf(s, "0x%08x:", io_log->result); 28361d8658bSDupuis, Chad seq_printf(s, "%lu:", io_log->jiffies); 28461d8658bSDupuis, Chad seq_printf(s, "%d:", io_log->refcount); 28561d8658bSDupuis, Chad seq_printf(s, "%d:", io_log->req_cpu); 28661d8658bSDupuis, Chad seq_printf(s, "%d:", io_log->int_cpu); 28761d8658bSDupuis, Chad seq_printf(s, "%d:", io_log->rsp_cpu); 28861d8658bSDupuis, Chad seq_printf(s, "%d\n", io_log->sge_type); 28961d8658bSDupuis, Chad 29061d8658bSDupuis, Chad idx++; 29161d8658bSDupuis, Chad if (idx == QEDF_IO_TRACE_SIZE) 29261d8658bSDupuis, Chad idx = 0; 29361d8658bSDupuis, Chad } 29461d8658bSDupuis, Chad spin_unlock_irqrestore(&qedf->io_trace_lock, flags); 29561d8658bSDupuis, Chad 29661d8658bSDupuis, Chad out: 29761d8658bSDupuis, Chad return 0; 29861d8658bSDupuis, Chad } 29961d8658bSDupuis, Chad 30061d8658bSDupuis, Chad static int 30161d8658bSDupuis, Chad qedf_dbg_io_trace_open(struct inode *inode, struct file *file) 30261d8658bSDupuis, Chad { 30361d8658bSDupuis, Chad struct qedf_dbg_ctx *qedf_dbg = inode->i_private; 30461d8658bSDupuis, Chad struct qedf_ctx *qedf = container_of(qedf_dbg, 30561d8658bSDupuis, Chad struct qedf_ctx, dbg_ctx); 30661d8658bSDupuis, Chad 30761d8658bSDupuis, Chad return single_open(file, qedf_io_trace_show, qedf); 30861d8658bSDupuis, Chad } 30961d8658bSDupuis, Chad 31061d8658bSDupuis, Chad static int 31161d8658bSDupuis, Chad qedf_driver_stats_show(struct seq_file *s, void *unused) 31261d8658bSDupuis, Chad { 31361d8658bSDupuis, Chad struct qedf_ctx *qedf = s->private; 31461d8658bSDupuis, Chad struct qedf_rport *fcport; 31561d8658bSDupuis, Chad struct fc_rport_priv *rdata; 31661d8658bSDupuis, Chad 31761d8658bSDupuis, Chad seq_printf(s, "cmg_mgr free io_reqs: %d\n", 31861d8658bSDupuis, Chad atomic_read(&qedf->cmd_mgr->free_list_cnt)); 31961d8658bSDupuis, Chad seq_printf(s, "slow SGEs: %d\n", qedf->slow_sge_ios); 32061d8658bSDupuis, Chad seq_printf(s, "single SGEs: %d\n", qedf->single_sge_ios); 32161d8658bSDupuis, Chad seq_printf(s, "fast SGEs: %d\n\n", qedf->fast_sge_ios); 32261d8658bSDupuis, Chad 32361d8658bSDupuis, Chad seq_puts(s, "Offloaded ports:\n\n"); 32461d8658bSDupuis, Chad 32561d8658bSDupuis, Chad rcu_read_lock(); 32661d8658bSDupuis, Chad list_for_each_entry_rcu(fcport, &qedf->fcports, peers) { 32761d8658bSDupuis, Chad rdata = fcport->rdata; 32861d8658bSDupuis, Chad if (rdata == NULL) 32961d8658bSDupuis, Chad continue; 33061d8658bSDupuis, Chad seq_printf(s, "%06x: free_sqes: %d, num_active_ios: %d\n", 33161d8658bSDupuis, Chad rdata->ids.port_id, atomic_read(&fcport->free_sqes), 33261d8658bSDupuis, Chad atomic_read(&fcport->num_active_ios)); 33361d8658bSDupuis, Chad } 33461d8658bSDupuis, Chad rcu_read_unlock(); 33561d8658bSDupuis, Chad 33661d8658bSDupuis, Chad return 0; 33761d8658bSDupuis, Chad } 33861d8658bSDupuis, Chad 33961d8658bSDupuis, Chad static int 34061d8658bSDupuis, Chad qedf_dbg_driver_stats_open(struct inode *inode, struct file *file) 34161d8658bSDupuis, Chad { 34261d8658bSDupuis, Chad struct qedf_dbg_ctx *qedf_dbg = inode->i_private; 34361d8658bSDupuis, Chad struct qedf_ctx *qedf = container_of(qedf_dbg, 34461d8658bSDupuis, Chad struct qedf_ctx, dbg_ctx); 34561d8658bSDupuis, Chad 34661d8658bSDupuis, Chad return single_open(file, qedf_driver_stats_show, qedf); 34761d8658bSDupuis, Chad } 34861d8658bSDupuis, Chad 34961d8658bSDupuis, Chad static ssize_t 35061d8658bSDupuis, Chad qedf_dbg_clear_stats_cmd_read(struct file *filp, char __user *buffer, 35161d8658bSDupuis, Chad size_t count, loff_t *ppos) 35261d8658bSDupuis, Chad { 35361d8658bSDupuis, Chad int cnt = 0; 35461d8658bSDupuis, Chad 35561d8658bSDupuis, Chad /* Essentially a read stub */ 35661d8658bSDupuis, Chad cnt = min_t(int, count, cnt - *ppos); 35761d8658bSDupuis, Chad *ppos += cnt; 35861d8658bSDupuis, Chad return cnt; 35961d8658bSDupuis, Chad } 36061d8658bSDupuis, Chad 36161d8658bSDupuis, Chad static ssize_t 36261d8658bSDupuis, Chad qedf_dbg_clear_stats_cmd_write(struct file *filp, 36361d8658bSDupuis, Chad const char __user *buffer, size_t count, 36461d8658bSDupuis, Chad loff_t *ppos) 36561d8658bSDupuis, Chad { 36661d8658bSDupuis, Chad struct qedf_dbg_ctx *qedf_dbg = 36761d8658bSDupuis, Chad (struct qedf_dbg_ctx *)filp->private_data; 36861d8658bSDupuis, Chad struct qedf_ctx *qedf = container_of(qedf_dbg, struct qedf_ctx, 36961d8658bSDupuis, Chad dbg_ctx); 37061d8658bSDupuis, Chad 37161d8658bSDupuis, Chad QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "Clearing stat counters.\n"); 37261d8658bSDupuis, Chad 37361d8658bSDupuis, Chad if (!count || *ppos) 37461d8658bSDupuis, Chad return 0; 37561d8658bSDupuis, Chad 37661d8658bSDupuis, Chad /* Clear stat counters exposed by 'stats' node */ 37761d8658bSDupuis, Chad qedf->slow_sge_ios = 0; 37861d8658bSDupuis, Chad qedf->single_sge_ios = 0; 37961d8658bSDupuis, Chad qedf->fast_sge_ios = 0; 38061d8658bSDupuis, Chad 38161d8658bSDupuis, Chad return count; 38261d8658bSDupuis, Chad } 38361d8658bSDupuis, Chad 38461d8658bSDupuis, Chad static int 38561d8658bSDupuis, Chad qedf_offload_stats_show(struct seq_file *s, void *unused) 38661d8658bSDupuis, Chad { 38761d8658bSDupuis, Chad struct qedf_ctx *qedf = s->private; 38861d8658bSDupuis, Chad struct qed_fcoe_stats *fw_fcoe_stats; 38961d8658bSDupuis, Chad 39061d8658bSDupuis, Chad fw_fcoe_stats = kmalloc(sizeof(struct qed_fcoe_stats), GFP_KERNEL); 39161d8658bSDupuis, Chad if (!fw_fcoe_stats) { 39261d8658bSDupuis, Chad QEDF_ERR(&(qedf->dbg_ctx), "Could not allocate memory for " 39361d8658bSDupuis, Chad "fw_fcoe_stats.\n"); 39461d8658bSDupuis, Chad goto out; 39561d8658bSDupuis, Chad } 39661d8658bSDupuis, Chad 39761d8658bSDupuis, Chad /* Query firmware for offload stats */ 39861d8658bSDupuis, Chad qed_ops->get_stats(qedf->cdev, fw_fcoe_stats); 39961d8658bSDupuis, Chad 40061d8658bSDupuis, Chad seq_printf(s, "fcoe_rx_byte_cnt=%llu\n" 40161d8658bSDupuis, Chad "fcoe_rx_data_pkt_cnt=%llu\n" 40261d8658bSDupuis, Chad "fcoe_rx_xfer_pkt_cnt=%llu\n" 40361d8658bSDupuis, Chad "fcoe_rx_other_pkt_cnt=%llu\n" 40461d8658bSDupuis, Chad "fcoe_silent_drop_pkt_cmdq_full_cnt=%u\n" 40561d8658bSDupuis, Chad "fcoe_silent_drop_pkt_crc_error_cnt=%u\n" 40661d8658bSDupuis, Chad "fcoe_silent_drop_pkt_task_invalid_cnt=%u\n" 40761d8658bSDupuis, Chad "fcoe_silent_drop_total_pkt_cnt=%u\n" 40861d8658bSDupuis, Chad "fcoe_silent_drop_pkt_rq_full_cnt=%u\n" 40961d8658bSDupuis, Chad "fcoe_tx_byte_cnt=%llu\n" 41061d8658bSDupuis, Chad "fcoe_tx_data_pkt_cnt=%llu\n" 41161d8658bSDupuis, Chad "fcoe_tx_xfer_pkt_cnt=%llu\n" 41261d8658bSDupuis, Chad "fcoe_tx_other_pkt_cnt=%llu\n", 41361d8658bSDupuis, Chad fw_fcoe_stats->fcoe_rx_byte_cnt, 41461d8658bSDupuis, Chad fw_fcoe_stats->fcoe_rx_data_pkt_cnt, 41561d8658bSDupuis, Chad fw_fcoe_stats->fcoe_rx_xfer_pkt_cnt, 41661d8658bSDupuis, Chad fw_fcoe_stats->fcoe_rx_other_pkt_cnt, 41761d8658bSDupuis, Chad fw_fcoe_stats->fcoe_silent_drop_pkt_cmdq_full_cnt, 41861d8658bSDupuis, Chad fw_fcoe_stats->fcoe_silent_drop_pkt_crc_error_cnt, 41961d8658bSDupuis, Chad fw_fcoe_stats->fcoe_silent_drop_pkt_task_invalid_cnt, 42061d8658bSDupuis, Chad fw_fcoe_stats->fcoe_silent_drop_total_pkt_cnt, 42161d8658bSDupuis, Chad fw_fcoe_stats->fcoe_silent_drop_pkt_rq_full_cnt, 42261d8658bSDupuis, Chad fw_fcoe_stats->fcoe_tx_byte_cnt, 42361d8658bSDupuis, Chad fw_fcoe_stats->fcoe_tx_data_pkt_cnt, 42461d8658bSDupuis, Chad fw_fcoe_stats->fcoe_tx_xfer_pkt_cnt, 42561d8658bSDupuis, Chad fw_fcoe_stats->fcoe_tx_other_pkt_cnt); 42661d8658bSDupuis, Chad 42761d8658bSDupuis, Chad kfree(fw_fcoe_stats); 42861d8658bSDupuis, Chad out: 42961d8658bSDupuis, Chad return 0; 43061d8658bSDupuis, Chad } 43161d8658bSDupuis, Chad 43261d8658bSDupuis, Chad static int 43361d8658bSDupuis, Chad qedf_dbg_offload_stats_open(struct inode *inode, struct file *file) 43461d8658bSDupuis, Chad { 43561d8658bSDupuis, Chad struct qedf_dbg_ctx *qedf_dbg = inode->i_private; 43661d8658bSDupuis, Chad struct qedf_ctx *qedf = container_of(qedf_dbg, 43761d8658bSDupuis, Chad struct qedf_ctx, dbg_ctx); 43861d8658bSDupuis, Chad 43961d8658bSDupuis, Chad return single_open(file, qedf_offload_stats_show, qedf); 44061d8658bSDupuis, Chad } 44161d8658bSDupuis, Chad 44261d8658bSDupuis, Chad 44361d8658bSDupuis, Chad const struct file_operations qedf_dbg_fops[] = { 44461d8658bSDupuis, Chad qedf_dbg_fileops(qedf, fp_int), 44561d8658bSDupuis, Chad qedf_dbg_fileops_seq(qedf, io_trace), 44661d8658bSDupuis, Chad qedf_dbg_fileops(qedf, debug), 44761d8658bSDupuis, Chad qedf_dbg_fileops(qedf, stop_io_on_error), 44861d8658bSDupuis, Chad qedf_dbg_fileops_seq(qedf, driver_stats), 44961d8658bSDupuis, Chad qedf_dbg_fileops(qedf, clear_stats), 45061d8658bSDupuis, Chad qedf_dbg_fileops_seq(qedf, offload_stats), 45161d8658bSDupuis, Chad /* This must be last */ 452efacae6dSKees Cook { }, 45361d8658bSDupuis, Chad }; 45461d8658bSDupuis, Chad 45561d8658bSDupuis, Chad #else /* CONFIG_DEBUG_FS */ 45661d8658bSDupuis, Chad void qedf_dbg_host_init(struct qedf_dbg_ctx *); 45761d8658bSDupuis, Chad void qedf_dbg_host_exit(struct qedf_dbg_ctx *); 45861d8658bSDupuis, Chad void qedf_dbg_init(char *); 45961d8658bSDupuis, Chad void qedf_dbg_exit(void); 46061d8658bSDupuis, Chad #endif /* CONFIG_DEBUG_FS */ 461