dpaa2-eth-debugfs.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
  2. /* Copyright 2015 Freescale Semiconductor Inc.
  3. * Copyright 2018-2019 NXP
  4. */
  5. #include <linux/module.h>
  6. #include <linux/debugfs.h>
  7. #include "dpaa2-eth.h"
  8. #include "dpaa2-eth-debugfs.h"
  9. #define DPAA2_ETH_DBG_ROOT "dpaa2-eth"
  10. static struct dentry *dpaa2_dbg_root;
  11. static int dpaa2_dbg_cpu_show(struct seq_file *file, void *offset)
  12. {
  13. struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private;
  14. struct rtnl_link_stats64 *stats;
  15. struct dpaa2_eth_drv_stats *extras;
  16. int i;
  17. seq_printf(file, "Per-CPU stats for %s\n", priv->net_dev->name);
  18. seq_printf(file, "%s%16s%16s%16s%16s%16s%16s%16s%16s%16s\n",
  19. "CPU", "Rx", "Rx Err", "Rx SG", "Tx", "Tx Err", "Tx conf",
  20. "Tx SG", "Tx converted to SG", "Enq busy");
  21. for_each_online_cpu(i) {
  22. stats = per_cpu_ptr(priv->percpu_stats, i);
  23. extras = per_cpu_ptr(priv->percpu_extras, i);
  24. seq_printf(file, "%3d%16llu%16llu%16llu%16llu%16llu%16llu%16llu%16llu%16llu\n",
  25. i,
  26. stats->rx_packets,
  27. stats->rx_errors,
  28. extras->rx_sg_frames,
  29. stats->tx_packets,
  30. stats->tx_errors,
  31. extras->tx_conf_frames,
  32. extras->tx_sg_frames,
  33. extras->tx_converted_sg_frames,
  34. extras->tx_portal_busy);
  35. }
  36. return 0;
  37. }
  38. DEFINE_SHOW_ATTRIBUTE(dpaa2_dbg_cpu);
  39. static char *fq_type_to_str(struct dpaa2_eth_fq *fq)
  40. {
  41. switch (fq->type) {
  42. case DPAA2_RX_FQ:
  43. return "Rx";
  44. case DPAA2_TX_CONF_FQ:
  45. return "Tx conf";
  46. default:
  47. return "N/A";
  48. }
  49. }
  50. static int dpaa2_dbg_fqs_show(struct seq_file *file, void *offset)
  51. {
  52. struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private;
  53. struct dpaa2_eth_fq *fq;
  54. u32 fcnt, bcnt;
  55. int i, err;
  56. seq_printf(file, "FQ stats for %s:\n", priv->net_dev->name);
  57. seq_printf(file, "%s%16s%16s%16s%16s%16s\n",
  58. "VFQID", "CPU", "TC", "Type", "Frames", "Pending frames");
  59. for (i = 0; i < priv->num_fqs; i++) {
  60. fq = &priv->fq[i];
  61. err = dpaa2_io_query_fq_count(NULL, fq->fqid, &fcnt, &bcnt);
  62. if (err)
  63. fcnt = 0;
  64. /* Skip FQs with no traffic */
  65. if (!fq->stats.frames && !fcnt)
  66. continue;
  67. seq_printf(file, "%5d%16d%16d%16s%16llu%16u\n",
  68. fq->fqid,
  69. fq->target_cpu,
  70. fq->tc,
  71. fq_type_to_str(fq),
  72. fq->stats.frames,
  73. fcnt);
  74. }
  75. return 0;
  76. }
  77. DEFINE_SHOW_ATTRIBUTE(dpaa2_dbg_fqs);
  78. static int dpaa2_dbg_ch_show(struct seq_file *file, void *offset)
  79. {
  80. struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private;
  81. struct dpaa2_eth_channel *ch;
  82. int i;
  83. seq_printf(file, "Channel stats for %s:\n", priv->net_dev->name);
  84. seq_printf(file, "%s%16s%16s%16s%16s%16s%16s\n",
  85. "CHID", "CPU", "Deq busy", "Frames", "CDANs",
  86. "Avg Frm/CDAN", "Buf count");
  87. for (i = 0; i < priv->num_channels; i++) {
  88. ch = priv->channel[i];
  89. seq_printf(file, "%4d%16d%16llu%16llu%16llu%16llu%16d\n",
  90. ch->ch_id,
  91. ch->nctx.desired_cpu,
  92. ch->stats.dequeue_portal_busy,
  93. ch->stats.frames,
  94. ch->stats.cdan,
  95. div64_u64(ch->stats.frames, ch->stats.cdan),
  96. ch->buf_count);
  97. }
  98. return 0;
  99. }
  100. DEFINE_SHOW_ATTRIBUTE(dpaa2_dbg_ch);
  101. void dpaa2_dbg_add(struct dpaa2_eth_priv *priv)
  102. {
  103. struct fsl_mc_device *dpni_dev;
  104. struct dentry *dir;
  105. char name[10];
  106. /* Create a directory for the interface */
  107. dpni_dev = to_fsl_mc_device(priv->net_dev->dev.parent);
  108. snprintf(name, 10, "dpni.%d", dpni_dev->obj_desc.id);
  109. dir = debugfs_create_dir(name, dpaa2_dbg_root);
  110. priv->dbg.dir = dir;
  111. /* per-cpu stats file */
  112. debugfs_create_file("cpu_stats", 0444, dir, priv, &dpaa2_dbg_cpu_fops);
  113. /* per-fq stats file */
  114. debugfs_create_file("fq_stats", 0444, dir, priv, &dpaa2_dbg_fqs_fops);
  115. /* per-fq stats file */
  116. debugfs_create_file("ch_stats", 0444, dir, priv, &dpaa2_dbg_ch_fops);
  117. }
  118. void dpaa2_dbg_remove(struct dpaa2_eth_priv *priv)
  119. {
  120. debugfs_remove_recursive(priv->dbg.dir);
  121. }
  122. void dpaa2_eth_dbg_init(void)
  123. {
  124. dpaa2_dbg_root = debugfs_create_dir(DPAA2_ETH_DBG_ROOT, NULL);
  125. pr_debug("DPAA2-ETH: debugfs created\n");
  126. }
  127. void dpaa2_eth_dbg_exit(void)
  128. {
  129. debugfs_remove(dpaa2_dbg_root);
  130. }