dpaa2-eth-debugfs.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 %5s%16s%16s%16s%16s%16s%16s\n",
  85. "IDX", "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, "%3s%d%6d%16d%16llu%16llu%16llu%16llu%16d\n",
  90. "CH#", i, 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. static int dpaa2_dbg_bp_show(struct seq_file *file, void *offset)
  102. {
  103. struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private;
  104. int i, j, num_queues, buf_cnt;
  105. struct dpaa2_eth_bp *bp;
  106. char ch_name[10];
  107. int err;
  108. /* Print out the header */
  109. seq_printf(file, "Buffer pool info for %s:\n", priv->net_dev->name);
  110. seq_printf(file, "%s %10s%15s", "IDX", "BPID", "Buf count");
  111. num_queues = dpaa2_eth_queue_count(priv);
  112. for (i = 0; i < num_queues; i++) {
  113. snprintf(ch_name, sizeof(ch_name), "CH#%d", i);
  114. seq_printf(file, "%10s", ch_name);
  115. }
  116. seq_printf(file, "\n");
  117. /* For each buffer pool, print out its BPID, the number of buffers in
  118. * that buffer pool and the channels which are using it.
  119. */
  120. for (i = 0; i < priv->num_bps; i++) {
  121. bp = priv->bp[i];
  122. err = dpaa2_io_query_bp_count(NULL, bp->bpid, &buf_cnt);
  123. if (err) {
  124. netdev_warn(priv->net_dev, "Buffer count query error %d\n", err);
  125. return err;
  126. }
  127. seq_printf(file, "%3s%d%10d%15d", "BP#", i, bp->bpid, buf_cnt);
  128. for (j = 0; j < num_queues; j++) {
  129. if (priv->channel[j]->bp == bp)
  130. seq_printf(file, "%10s", "x");
  131. else
  132. seq_printf(file, "%10s", "");
  133. }
  134. seq_printf(file, "\n");
  135. }
  136. return 0;
  137. }
  138. DEFINE_SHOW_ATTRIBUTE(dpaa2_dbg_bp);
  139. void dpaa2_dbg_add(struct dpaa2_eth_priv *priv)
  140. {
  141. struct fsl_mc_device *dpni_dev;
  142. struct dentry *dir;
  143. char name[10];
  144. /* Create a directory for the interface */
  145. dpni_dev = to_fsl_mc_device(priv->net_dev->dev.parent);
  146. snprintf(name, 10, "dpni.%d", dpni_dev->obj_desc.id);
  147. dir = debugfs_create_dir(name, dpaa2_dbg_root);
  148. priv->dbg.dir = dir;
  149. /* per-cpu stats file */
  150. debugfs_create_file("cpu_stats", 0444, dir, priv, &dpaa2_dbg_cpu_fops);
  151. /* per-fq stats file */
  152. debugfs_create_file("fq_stats", 0444, dir, priv, &dpaa2_dbg_fqs_fops);
  153. /* per-fq stats file */
  154. debugfs_create_file("ch_stats", 0444, dir, priv, &dpaa2_dbg_ch_fops);
  155. /* per buffer pool stats file */
  156. debugfs_create_file("bp_stats", 0444, dir, priv, &dpaa2_dbg_bp_fops);
  157. }
  158. void dpaa2_dbg_remove(struct dpaa2_eth_priv *priv)
  159. {
  160. debugfs_remove_recursive(priv->dbg.dir);
  161. }
  162. void dpaa2_eth_dbg_init(void)
  163. {
  164. dpaa2_dbg_root = debugfs_create_dir(DPAA2_ETH_DBG_ROOT, NULL);
  165. pr_debug("DPAA2-ETH: debugfs created\n");
  166. }
  167. void dpaa2_eth_dbg_exit(void)
  168. {
  169. debugfs_remove(dpaa2_dbg_root);
  170. }