qedf_debugfs.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * QLogic FCoE Offload Driver
  4. * Copyright (c) 2016-2018 QLogic Corporation
  5. */
  6. #ifdef CONFIG_DEBUG_FS
  7. #include <linux/uaccess.h>
  8. #include <linux/debugfs.h>
  9. #include <linux/module.h>
  10. #include <linux/vmalloc.h>
  11. #include "qedf.h"
  12. #include "qedf_dbg.h"
  13. static struct dentry *qedf_dbg_root;
  14. /*
  15. * qedf_dbg_host_init - setup the debugfs file for the pf
  16. */
  17. void
  18. qedf_dbg_host_init(struct qedf_dbg_ctx *qedf,
  19. const struct qedf_debugfs_ops *dops,
  20. const struct file_operations *fops)
  21. {
  22. char host_dirname[32];
  23. QEDF_INFO(qedf, QEDF_LOG_DEBUGFS, "Creating debugfs host node\n");
  24. /* create pf dir */
  25. sprintf(host_dirname, "host%u", qedf->host_no);
  26. qedf->bdf_dentry = debugfs_create_dir(host_dirname, qedf_dbg_root);
  27. /* create debugfs files */
  28. while (dops) {
  29. if (!(dops->name))
  30. break;
  31. debugfs_create_file(dops->name, 0600, qedf->bdf_dentry, qedf,
  32. fops);
  33. dops++;
  34. fops++;
  35. }
  36. }
  37. /*
  38. * qedf_dbg_host_exit - clear out the pf's debugfs entries
  39. */
  40. void
  41. qedf_dbg_host_exit(struct qedf_dbg_ctx *qedf_dbg)
  42. {
  43. QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "Destroying debugfs host "
  44. "entry\n");
  45. /* remove debugfs entries of this PF */
  46. debugfs_remove_recursive(qedf_dbg->bdf_dentry);
  47. qedf_dbg->bdf_dentry = NULL;
  48. }
  49. /*
  50. * qedf_dbg_init - start up debugfs for the driver
  51. */
  52. void
  53. qedf_dbg_init(char *drv_name)
  54. {
  55. QEDF_INFO(NULL, QEDF_LOG_DEBUGFS, "Creating debugfs root node\n");
  56. /* create qed dir in root of debugfs. NULL means debugfs root */
  57. qedf_dbg_root = debugfs_create_dir(drv_name, NULL);
  58. }
  59. /*
  60. * qedf_dbg_exit - clean out the driver's debugfs entries
  61. */
  62. void
  63. qedf_dbg_exit(void)
  64. {
  65. QEDF_INFO(NULL, QEDF_LOG_DEBUGFS, "Destroying debugfs root "
  66. "entry\n");
  67. /* remove qed dir in root of debugfs */
  68. debugfs_remove_recursive(qedf_dbg_root);
  69. qedf_dbg_root = NULL;
  70. }
  71. const struct qedf_debugfs_ops qedf_debugfs_ops[] = {
  72. { "fp_int", NULL },
  73. { "io_trace", NULL },
  74. { "debug", NULL },
  75. { "stop_io_on_error", NULL},
  76. { "driver_stats", NULL},
  77. { "clear_stats", NULL},
  78. { "offload_stats", NULL},
  79. /* This must be last */
  80. { NULL, NULL }
  81. };
  82. DECLARE_PER_CPU(struct qedf_percpu_iothread_s, qedf_percpu_iothreads);
  83. static ssize_t
  84. qedf_dbg_fp_int_cmd_read(struct file *filp, char __user *buffer, size_t count,
  85. loff_t *ppos)
  86. {
  87. ssize_t ret;
  88. size_t cnt = 0;
  89. char *cbuf;
  90. int id;
  91. struct qedf_fastpath *fp = NULL;
  92. struct qedf_dbg_ctx *qedf_dbg =
  93. (struct qedf_dbg_ctx *)filp->private_data;
  94. struct qedf_ctx *qedf = container_of(qedf_dbg,
  95. struct qedf_ctx, dbg_ctx);
  96. QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
  97. cbuf = vmalloc(QEDF_DEBUGFS_LOG_LEN);
  98. if (!cbuf)
  99. return 0;
  100. cnt += scnprintf(cbuf + cnt, QEDF_DEBUGFS_LOG_LEN - cnt, "\nFastpath I/O completions\n\n");
  101. for (id = 0; id < qedf->num_queues; id++) {
  102. fp = &(qedf->fp_array[id]);
  103. if (fp->sb_id == QEDF_SB_ID_NULL)
  104. continue;
  105. cnt += scnprintf(cbuf + cnt, QEDF_DEBUGFS_LOG_LEN - cnt,
  106. "#%d: %lu\n", id, fp->completions);
  107. }
  108. ret = simple_read_from_buffer(buffer, count, ppos, cbuf, cnt);
  109. vfree(cbuf);
  110. return ret;
  111. }
  112. static ssize_t
  113. qedf_dbg_fp_int_cmd_write(struct file *filp, const char __user *buffer,
  114. size_t count, loff_t *ppos)
  115. {
  116. if (!count || *ppos)
  117. return 0;
  118. return count;
  119. }
  120. static ssize_t
  121. qedf_dbg_debug_cmd_read(struct file *filp, char __user *buffer, size_t count,
  122. loff_t *ppos)
  123. {
  124. int cnt;
  125. char cbuf[32];
  126. struct qedf_dbg_ctx *qedf_dbg =
  127. (struct qedf_dbg_ctx *)filp->private_data;
  128. QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "debug mask=0x%x\n", qedf_debug);
  129. cnt = scnprintf(cbuf, sizeof(cbuf), "debug mask = 0x%x\n", qedf_debug);
  130. return simple_read_from_buffer(buffer, count, ppos, cbuf, cnt);
  131. }
  132. static ssize_t
  133. qedf_dbg_debug_cmd_write(struct file *filp, const char __user *buffer,
  134. size_t count, loff_t *ppos)
  135. {
  136. uint32_t val;
  137. void *kern_buf;
  138. int rval;
  139. struct qedf_dbg_ctx *qedf_dbg =
  140. (struct qedf_dbg_ctx *)filp->private_data;
  141. if (!count || *ppos)
  142. return 0;
  143. kern_buf = memdup_user(buffer, count);
  144. if (IS_ERR(kern_buf))
  145. return PTR_ERR(kern_buf);
  146. rval = kstrtouint(kern_buf, 10, &val);
  147. kfree(kern_buf);
  148. if (rval)
  149. return rval;
  150. if (val == 1)
  151. qedf_debug = QEDF_DEFAULT_LOG_MASK;
  152. else
  153. qedf_debug = val;
  154. QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "Setting debug=0x%x.\n", val);
  155. return count;
  156. }
  157. static ssize_t
  158. qedf_dbg_stop_io_on_error_cmd_read(struct file *filp, char __user *buffer,
  159. size_t count, loff_t *ppos)
  160. {
  161. int cnt;
  162. char cbuf[7];
  163. struct qedf_dbg_ctx *qedf_dbg =
  164. (struct qedf_dbg_ctx *)filp->private_data;
  165. struct qedf_ctx *qedf = container_of(qedf_dbg,
  166. struct qedf_ctx, dbg_ctx);
  167. QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
  168. cnt = scnprintf(cbuf, sizeof(cbuf), "%s\n",
  169. qedf->stop_io_on_error ? "true" : "false");
  170. return simple_read_from_buffer(buffer, count, ppos, cbuf, cnt);
  171. }
  172. static ssize_t
  173. qedf_dbg_stop_io_on_error_cmd_write(struct file *filp,
  174. const char __user *buffer, size_t count,
  175. loff_t *ppos)
  176. {
  177. void *kern_buf;
  178. struct qedf_dbg_ctx *qedf_dbg =
  179. (struct qedf_dbg_ctx *)filp->private_data;
  180. struct qedf_ctx *qedf = container_of(qedf_dbg, struct qedf_ctx,
  181. dbg_ctx);
  182. QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
  183. if (!count || *ppos)
  184. return 0;
  185. kern_buf = memdup_user(buffer, 6);
  186. if (IS_ERR(kern_buf))
  187. return PTR_ERR(kern_buf);
  188. if (strncmp(kern_buf, "false", 5) == 0)
  189. qedf->stop_io_on_error = false;
  190. else if (strncmp(kern_buf, "true", 4) == 0)
  191. qedf->stop_io_on_error = true;
  192. else if (strncmp(kern_buf, "now", 3) == 0)
  193. /* Trigger from user to stop all I/O on this host */
  194. set_bit(QEDF_DBG_STOP_IO, &qedf->flags);
  195. kfree(kern_buf);
  196. return count;
  197. }
  198. static int
  199. qedf_io_trace_show(struct seq_file *s, void *unused)
  200. {
  201. int i, idx = 0;
  202. struct qedf_ctx *qedf = s->private;
  203. struct qedf_dbg_ctx *qedf_dbg = &qedf->dbg_ctx;
  204. struct qedf_io_log *io_log;
  205. unsigned long flags;
  206. if (!qedf_io_tracing) {
  207. seq_puts(s, "I/O tracing not enabled.\n");
  208. goto out;
  209. }
  210. QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
  211. spin_lock_irqsave(&qedf->io_trace_lock, flags);
  212. idx = qedf->io_trace_idx;
  213. for (i = 0; i < QEDF_IO_TRACE_SIZE; i++) {
  214. io_log = &qedf->io_trace_buf[idx];
  215. seq_printf(s, "%d:", io_log->direction);
  216. seq_printf(s, "0x%x:", io_log->task_id);
  217. seq_printf(s, "0x%06x:", io_log->port_id);
  218. seq_printf(s, "%d:", io_log->lun);
  219. seq_printf(s, "0x%02x:", io_log->op);
  220. seq_printf(s, "0x%02x%02x%02x%02x:", io_log->lba[0],
  221. io_log->lba[1], io_log->lba[2], io_log->lba[3]);
  222. seq_printf(s, "%d:", io_log->bufflen);
  223. seq_printf(s, "%d:", io_log->sg_count);
  224. seq_printf(s, "0x%08x:", io_log->result);
  225. seq_printf(s, "%lu:", io_log->jiffies);
  226. seq_printf(s, "%d:", io_log->refcount);
  227. seq_printf(s, "%d:", io_log->req_cpu);
  228. seq_printf(s, "%d:", io_log->int_cpu);
  229. seq_printf(s, "%d:", io_log->rsp_cpu);
  230. seq_printf(s, "%d\n", io_log->sge_type);
  231. idx++;
  232. if (idx == QEDF_IO_TRACE_SIZE)
  233. idx = 0;
  234. }
  235. spin_unlock_irqrestore(&qedf->io_trace_lock, flags);
  236. out:
  237. return 0;
  238. }
  239. static int
  240. qedf_dbg_io_trace_open(struct inode *inode, struct file *file)
  241. {
  242. struct qedf_dbg_ctx *qedf_dbg = inode->i_private;
  243. struct qedf_ctx *qedf = container_of(qedf_dbg,
  244. struct qedf_ctx, dbg_ctx);
  245. return single_open(file, qedf_io_trace_show, qedf);
  246. }
  247. /* Based on fip_state enum from libfcoe.h */
  248. static char *fip_state_names[] = {
  249. "FIP_ST_DISABLED",
  250. "FIP_ST_LINK_WAIT",
  251. "FIP_ST_AUTO",
  252. "FIP_ST_NON_FIP",
  253. "FIP_ST_ENABLED",
  254. "FIP_ST_VNMP_START",
  255. "FIP_ST_VNMP_PROBE1",
  256. "FIP_ST_VNMP_PROBE2",
  257. "FIP_ST_VNMP_CLAIM",
  258. "FIP_ST_VNMP_UP",
  259. };
  260. /* Based on fc_rport_state enum from libfc.h */
  261. static char *fc_rport_state_names[] = {
  262. "RPORT_ST_INIT",
  263. "RPORT_ST_FLOGI",
  264. "RPORT_ST_PLOGI_WAIT",
  265. "RPORT_ST_PLOGI",
  266. "RPORT_ST_PRLI",
  267. "RPORT_ST_RTV",
  268. "RPORT_ST_READY",
  269. "RPORT_ST_ADISC",
  270. "RPORT_ST_DELETE",
  271. };
  272. static int
  273. qedf_driver_stats_show(struct seq_file *s, void *unused)
  274. {
  275. struct qedf_ctx *qedf = s->private;
  276. struct qedf_rport *fcport;
  277. struct fc_rport_priv *rdata;
  278. seq_printf(s, "Host WWNN/WWPN: %016llx/%016llx\n",
  279. qedf->wwnn, qedf->wwpn);
  280. seq_printf(s, "Host NPortID: %06x\n", qedf->lport->port_id);
  281. seq_printf(s, "Link State: %s\n", atomic_read(&qedf->link_state) ?
  282. "Up" : "Down");
  283. seq_printf(s, "Logical Link State: %s\n", qedf->lport->link_up ?
  284. "Up" : "Down");
  285. seq_printf(s, "FIP state: %s\n", fip_state_names[qedf->ctlr.state]);
  286. seq_printf(s, "FIP VLAN ID: %d\n", qedf->vlan_id & 0xfff);
  287. seq_printf(s, "FIP 802.1Q Priority: %d\n", qedf->prio);
  288. if (qedf->ctlr.sel_fcf) {
  289. seq_printf(s, "FCF WWPN: %016llx\n",
  290. qedf->ctlr.sel_fcf->switch_name);
  291. seq_printf(s, "FCF MAC: %pM\n", qedf->ctlr.sel_fcf->fcf_mac);
  292. } else {
  293. seq_puts(s, "FCF not selected\n");
  294. }
  295. seq_puts(s, "\nSGE stats:\n\n");
  296. seq_printf(s, "cmg_mgr free io_reqs: %d\n",
  297. atomic_read(&qedf->cmd_mgr->free_list_cnt));
  298. seq_printf(s, "slow SGEs: %d\n", qedf->slow_sge_ios);
  299. seq_printf(s, "fast SGEs: %d\n\n", qedf->fast_sge_ios);
  300. seq_puts(s, "Offloaded ports:\n\n");
  301. rcu_read_lock();
  302. list_for_each_entry_rcu(fcport, &qedf->fcports, peers) {
  303. rdata = fcport->rdata;
  304. if (rdata == NULL)
  305. continue;
  306. seq_printf(s, "%016llx/%016llx/%06x: state=%s, free_sqes=%d, num_active_ios=%d\n",
  307. rdata->rport->node_name, rdata->rport->port_name,
  308. rdata->ids.port_id,
  309. fc_rport_state_names[rdata->rp_state],
  310. atomic_read(&fcport->free_sqes),
  311. atomic_read(&fcport->num_active_ios));
  312. }
  313. rcu_read_unlock();
  314. return 0;
  315. }
  316. static int
  317. qedf_dbg_driver_stats_open(struct inode *inode, struct file *file)
  318. {
  319. struct qedf_dbg_ctx *qedf_dbg = inode->i_private;
  320. struct qedf_ctx *qedf = container_of(qedf_dbg,
  321. struct qedf_ctx, dbg_ctx);
  322. return single_open(file, qedf_driver_stats_show, qedf);
  323. }
  324. static ssize_t
  325. qedf_dbg_clear_stats_cmd_read(struct file *filp, char __user *buffer,
  326. size_t count, loff_t *ppos)
  327. {
  328. int cnt = 0;
  329. /* Essentially a read stub */
  330. cnt = min_t(int, count, cnt - *ppos);
  331. *ppos += cnt;
  332. return cnt;
  333. }
  334. static ssize_t
  335. qedf_dbg_clear_stats_cmd_write(struct file *filp,
  336. const char __user *buffer, size_t count,
  337. loff_t *ppos)
  338. {
  339. struct qedf_dbg_ctx *qedf_dbg =
  340. (struct qedf_dbg_ctx *)filp->private_data;
  341. struct qedf_ctx *qedf = container_of(qedf_dbg, struct qedf_ctx,
  342. dbg_ctx);
  343. QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "Clearing stat counters.\n");
  344. if (!count || *ppos)
  345. return 0;
  346. /* Clear stat counters exposed by 'stats' node */
  347. qedf->slow_sge_ios = 0;
  348. qedf->fast_sge_ios = 0;
  349. return count;
  350. }
  351. static int
  352. qedf_offload_stats_show(struct seq_file *s, void *unused)
  353. {
  354. struct qedf_ctx *qedf = s->private;
  355. struct qed_fcoe_stats *fw_fcoe_stats;
  356. fw_fcoe_stats = kmalloc(sizeof(struct qed_fcoe_stats), GFP_KERNEL);
  357. if (!fw_fcoe_stats) {
  358. QEDF_ERR(&(qedf->dbg_ctx), "Could not allocate memory for "
  359. "fw_fcoe_stats.\n");
  360. goto out;
  361. }
  362. /* Query firmware for offload stats */
  363. qed_ops->get_stats(qedf->cdev, fw_fcoe_stats);
  364. seq_printf(s, "fcoe_rx_byte_cnt=%llu\n"
  365. "fcoe_rx_data_pkt_cnt=%llu\n"
  366. "fcoe_rx_xfer_pkt_cnt=%llu\n"
  367. "fcoe_rx_other_pkt_cnt=%llu\n"
  368. "fcoe_silent_drop_pkt_cmdq_full_cnt=%u\n"
  369. "fcoe_silent_drop_pkt_crc_error_cnt=%u\n"
  370. "fcoe_silent_drop_pkt_task_invalid_cnt=%u\n"
  371. "fcoe_silent_drop_total_pkt_cnt=%u\n"
  372. "fcoe_silent_drop_pkt_rq_full_cnt=%u\n"
  373. "fcoe_tx_byte_cnt=%llu\n"
  374. "fcoe_tx_data_pkt_cnt=%llu\n"
  375. "fcoe_tx_xfer_pkt_cnt=%llu\n"
  376. "fcoe_tx_other_pkt_cnt=%llu\n",
  377. fw_fcoe_stats->fcoe_rx_byte_cnt,
  378. fw_fcoe_stats->fcoe_rx_data_pkt_cnt,
  379. fw_fcoe_stats->fcoe_rx_xfer_pkt_cnt,
  380. fw_fcoe_stats->fcoe_rx_other_pkt_cnt,
  381. fw_fcoe_stats->fcoe_silent_drop_pkt_cmdq_full_cnt,
  382. fw_fcoe_stats->fcoe_silent_drop_pkt_crc_error_cnt,
  383. fw_fcoe_stats->fcoe_silent_drop_pkt_task_invalid_cnt,
  384. fw_fcoe_stats->fcoe_silent_drop_total_pkt_cnt,
  385. fw_fcoe_stats->fcoe_silent_drop_pkt_rq_full_cnt,
  386. fw_fcoe_stats->fcoe_tx_byte_cnt,
  387. fw_fcoe_stats->fcoe_tx_data_pkt_cnt,
  388. fw_fcoe_stats->fcoe_tx_xfer_pkt_cnt,
  389. fw_fcoe_stats->fcoe_tx_other_pkt_cnt);
  390. kfree(fw_fcoe_stats);
  391. out:
  392. return 0;
  393. }
  394. static int
  395. qedf_dbg_offload_stats_open(struct inode *inode, struct file *file)
  396. {
  397. struct qedf_dbg_ctx *qedf_dbg = inode->i_private;
  398. struct qedf_ctx *qedf = container_of(qedf_dbg,
  399. struct qedf_ctx, dbg_ctx);
  400. return single_open(file, qedf_offload_stats_show, qedf);
  401. }
  402. const struct file_operations qedf_dbg_fops[] = {
  403. qedf_dbg_fileops(qedf, fp_int),
  404. qedf_dbg_fileops_seq(qedf, io_trace),
  405. qedf_dbg_fileops(qedf, debug),
  406. qedf_dbg_fileops(qedf, stop_io_on_error),
  407. qedf_dbg_fileops_seq(qedf, driver_stats),
  408. qedf_dbg_fileops(qedf, clear_stats),
  409. qedf_dbg_fileops_seq(qedf, offload_stats),
  410. /* This must be last */
  411. { },
  412. };
  413. #else /* CONFIG_DEBUG_FS */
  414. void qedf_dbg_host_init(struct qedf_dbg_ctx *);
  415. void qedf_dbg_host_exit(struct qedf_dbg_ctx *);
  416. void qedf_dbg_init(char *);
  417. void qedf_dbg_exit(void);
  418. #endif /* CONFIG_DEBUG_FS */