| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * QLogic FCoE Offload Driver |
|---|
| 3 | 4 | * 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. |
|---|
| 8 | 5 | */ |
|---|
| 9 | 6 | #ifdef CONFIG_DEBUG_FS |
|---|
| 10 | 7 | |
|---|
| 11 | 8 | #include <linux/uaccess.h> |
|---|
| 12 | 9 | #include <linux/debugfs.h> |
|---|
| 13 | 10 | #include <linux/module.h> |
|---|
| 11 | +#include <linux/vmalloc.h> |
|---|
| 14 | 12 | |
|---|
| 15 | 13 | #include "qedf.h" |
|---|
| 16 | 14 | #include "qedf_dbg.h" |
|---|
| 17 | 15 | |
|---|
| 18 | 16 | static struct dentry *qedf_dbg_root; |
|---|
| 19 | 17 | |
|---|
| 20 | | -/** |
|---|
| 18 | +/* |
|---|
| 21 | 19 | * qedf_dbg_host_init - setup the debugfs file for the pf |
|---|
| 22 | | - * @pf: the pf that is starting up |
|---|
| 23 | | - **/ |
|---|
| 20 | + */ |
|---|
| 24 | 21 | void |
|---|
| 25 | 22 | qedf_dbg_host_init(struct qedf_dbg_ctx *qedf, |
|---|
| 26 | 23 | const struct qedf_debugfs_ops *dops, |
|---|
| 27 | 24 | const struct file_operations *fops) |
|---|
| 28 | 25 | { |
|---|
| 29 | 26 | char host_dirname[32]; |
|---|
| 30 | | - struct dentry *file_dentry = NULL; |
|---|
| 31 | 27 | |
|---|
| 32 | 28 | QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Creating debugfs host node\n"); |
|---|
| 33 | 29 | /* create pf dir */ |
|---|
| 34 | 30 | sprintf(host_dirname, "host%u", qedf->host_no); |
|---|
| 35 | 31 | qedf->bdf_dentry = debugfs_create_dir(host_dirname, qedf_dbg_root); |
|---|
| 36 | | - if (!qedf->bdf_dentry) |
|---|
| 37 | | - return; |
|---|
| 38 | 32 | |
|---|
| 39 | 33 | /* create debugfs files */ |
|---|
| 40 | 34 | while (dops) { |
|---|
| 41 | 35 | if (!(dops->name)) |
|---|
| 42 | 36 | break; |
|---|
| 43 | 37 | |
|---|
| 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); |
|---|
| 54 | 40 | dops++; |
|---|
| 55 | 41 | fops++; |
|---|
| 56 | 42 | } |
|---|
| 57 | 43 | } |
|---|
| 58 | 44 | |
|---|
| 59 | | -/** |
|---|
| 45 | +/* |
|---|
| 60 | 46 | * qedf_dbg_host_exit - clear out the pf's debugfs entries |
|---|
| 61 | | - * @pf: the pf that is stopping |
|---|
| 62 | | - **/ |
|---|
| 47 | + */ |
|---|
| 63 | 48 | void |
|---|
| 64 | | -qedf_dbg_host_exit(struct qedf_dbg_ctx *qedf) |
|---|
| 49 | +qedf_dbg_host_exit(struct qedf_dbg_ctx *qedf_dbg) |
|---|
| 65 | 50 | { |
|---|
| 66 | | - QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Destroying debugfs host " |
|---|
| 51 | + QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "Destroying debugfs host " |
|---|
| 67 | 52 | "entry\n"); |
|---|
| 68 | 53 | /* 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; |
|---|
| 71 | 56 | } |
|---|
| 72 | 57 | |
|---|
| 73 | | -/** |
|---|
| 58 | +/* |
|---|
| 74 | 59 | * qedf_dbg_init - start up debugfs for the driver |
|---|
| 75 | | - **/ |
|---|
| 60 | + */ |
|---|
| 76 | 61 | void |
|---|
| 77 | 62 | qedf_dbg_init(char *drv_name) |
|---|
| 78 | 63 | { |
|---|
| .. | .. |
|---|
| 80 | 65 | |
|---|
| 81 | 66 | /* create qed dir in root of debugfs. NULL means debugfs root */ |
|---|
| 82 | 67 | 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"); |
|---|
| 86 | 68 | } |
|---|
| 87 | 69 | |
|---|
| 88 | | -/** |
|---|
| 70 | +/* |
|---|
| 89 | 71 | * qedf_dbg_exit - clean out the driver's debugfs entries |
|---|
| 90 | | - **/ |
|---|
| 72 | + */ |
|---|
| 91 | 73 | void |
|---|
| 92 | 74 | qedf_dbg_exit(void) |
|---|
| 93 | 75 | { |
|---|
| .. | .. |
|---|
| 117 | 99 | qedf_dbg_fp_int_cmd_read(struct file *filp, char __user *buffer, size_t count, |
|---|
| 118 | 100 | loff_t *ppos) |
|---|
| 119 | 101 | { |
|---|
| 102 | + ssize_t ret; |
|---|
| 120 | 103 | size_t cnt = 0; |
|---|
| 104 | + char *cbuf; |
|---|
| 121 | 105 | int id; |
|---|
| 122 | 106 | struct qedf_fastpath *fp = NULL; |
|---|
| 123 | 107 | struct qedf_dbg_ctx *qedf_dbg = |
|---|
| .. | .. |
|---|
| 127 | 111 | |
|---|
| 128 | 112 | QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n"); |
|---|
| 129 | 113 | |
|---|
| 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"); |
|---|
| 131 | 119 | |
|---|
| 132 | 120 | for (id = 0; id < qedf->num_queues; id++) { |
|---|
| 133 | 121 | fp = &(qedf->fp_array[id]); |
|---|
| 134 | 122 | if (fp->sb_id == QEDF_SB_ID_NULL) |
|---|
| 135 | 123 | 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); |
|---|
| 138 | 126 | } |
|---|
| 139 | 127 | |
|---|
| 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; |
|---|
| 143 | 133 | } |
|---|
| 144 | 134 | |
|---|
| 145 | 135 | static ssize_t |
|---|
| .. | .. |
|---|
| 157 | 147 | loff_t *ppos) |
|---|
| 158 | 148 | { |
|---|
| 159 | 149 | int cnt; |
|---|
| 160 | | - struct qedf_dbg_ctx *qedf = |
|---|
| 150 | + char cbuf[32]; |
|---|
| 151 | + struct qedf_dbg_ctx *qedf_dbg = |
|---|
| 161 | 152 | (struct qedf_dbg_ctx *)filp->private_data; |
|---|
| 162 | 153 | |
|---|
| 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); |
|---|
| 165 | 156 | |
|---|
| 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); |
|---|
| 169 | 158 | } |
|---|
| 170 | 159 | |
|---|
| 171 | 160 | static ssize_t |
|---|
| .. | .. |
|---|
| 175 | 164 | uint32_t val; |
|---|
| 176 | 165 | void *kern_buf; |
|---|
| 177 | 166 | int rval; |
|---|
| 178 | | - struct qedf_dbg_ctx *qedf = |
|---|
| 167 | + struct qedf_dbg_ctx *qedf_dbg = |
|---|
| 179 | 168 | (struct qedf_dbg_ctx *)filp->private_data; |
|---|
| 180 | 169 | |
|---|
| 181 | 170 | if (!count || *ppos) |
|---|
| .. | .. |
|---|
| 195 | 184 | else |
|---|
| 196 | 185 | qedf_debug = val; |
|---|
| 197 | 186 | |
|---|
| 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); |
|---|
| 199 | 188 | return count; |
|---|
| 200 | 189 | } |
|---|
| 201 | 190 | |
|---|
| .. | .. |
|---|
| 204 | 193 | size_t count, loff_t *ppos) |
|---|
| 205 | 194 | { |
|---|
| 206 | 195 | int cnt; |
|---|
| 196 | + char cbuf[7]; |
|---|
| 207 | 197 | struct qedf_dbg_ctx *qedf_dbg = |
|---|
| 208 | 198 | (struct qedf_dbg_ctx *)filp->private_data; |
|---|
| 209 | 199 | struct qedf_ctx *qedf = container_of(qedf_dbg, |
|---|
| 210 | 200 | struct qedf_ctx, dbg_ctx); |
|---|
| 211 | 201 | |
|---|
| 212 | 202 | QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n"); |
|---|
| 213 | | - cnt = sprintf(buffer, "%s\n", |
|---|
| 203 | + cnt = scnprintf(cbuf, sizeof(cbuf), "%s\n", |
|---|
| 214 | 204 | qedf->stop_io_on_error ? "true" : "false"); |
|---|
| 215 | 205 | |
|---|
| 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); |
|---|
| 219 | 207 | } |
|---|
| 220 | 208 | |
|---|
| 221 | 209 | static ssize_t |
|---|
| .. | .. |
|---|
| 307 | 295 | return single_open(file, qedf_io_trace_show, qedf); |
|---|
| 308 | 296 | } |
|---|
| 309 | 297 | |
|---|
| 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 | + |
|---|
| 310 | 325 | static int |
|---|
| 311 | 326 | qedf_driver_stats_show(struct seq_file *s, void *unused) |
|---|
| 312 | 327 | { |
|---|
| .. | .. |
|---|
| 314 | 329 | struct qedf_rport *fcport; |
|---|
| 315 | 330 | struct fc_rport_priv *rdata; |
|---|
| 316 | 331 | |
|---|
| 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"); |
|---|
| 317 | 351 | seq_printf(s, "cmg_mgr free io_reqs: %d\n", |
|---|
| 318 | 352 | atomic_read(&qedf->cmd_mgr->free_list_cnt)); |
|---|
| 319 | 353 | seq_printf(s, "slow SGEs: %d\n", qedf->slow_sge_ios); |
|---|
| 320 | | - seq_printf(s, "single SGEs: %d\n", qedf->single_sge_ios); |
|---|
| 321 | 354 | seq_printf(s, "fast SGEs: %d\n\n", qedf->fast_sge_ios); |
|---|
| 322 | 355 | |
|---|
| 323 | 356 | seq_puts(s, "Offloaded ports:\n\n"); |
|---|
| .. | .. |
|---|
| 327 | 360 | rdata = fcport->rdata; |
|---|
| 328 | 361 | if (rdata == NULL) |
|---|
| 329 | 362 | 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)); |
|---|
| 333 | 369 | } |
|---|
| 334 | 370 | rcu_read_unlock(); |
|---|
| 335 | 371 | |
|---|
| .. | .. |
|---|
| 375 | 411 | |
|---|
| 376 | 412 | /* Clear stat counters exposed by 'stats' node */ |
|---|
| 377 | 413 | qedf->slow_sge_ios = 0; |
|---|
| 378 | | - qedf->single_sge_ios = 0; |
|---|
| 379 | 414 | qedf->fast_sge_ios = 0; |
|---|
| 380 | 415 | |
|---|
| 381 | 416 | return count; |
|---|