1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2 /* Copyright 2015 Freescale Semiconductor Inc.
3 * Copyright 2018-2019 NXP
5 #include <linux/module.h>
6 #include <linux/debugfs.h>
8 #include "dpaa2-eth-debugfs.h"
10 #define DPAA2_ETH_DBG_ROOT "dpaa2-eth"
12 static struct dentry *dpaa2_dbg_root;
14 static int dpaa2_dbg_cpu_show(struct seq_file *file, void *offset)
16 struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private;
17 struct rtnl_link_stats64 *stats;
18 struct dpaa2_eth_drv_stats *extras;
21 seq_printf(file, "Per-CPU stats for %s\n", priv->net_dev->name);
22 seq_printf(file, "%s%16s%16s%16s%16s%16s%16s%16s%16s%16s\n",
23 "CPU", "Rx", "Rx Err", "Rx SG", "Tx", "Tx Err", "Tx conf",
24 "Tx SG", "Tx realloc", "Enq busy");
26 for_each_online_cpu(i) {
27 stats = per_cpu_ptr(priv->percpu_stats, i);
28 extras = per_cpu_ptr(priv->percpu_extras, i);
29 seq_printf(file, "%3d%16llu%16llu%16llu%16llu%16llu%16llu%16llu%16llu%16llu\n",
36 extras->tx_conf_frames,
39 extras->tx_portal_busy);
45 static int dpaa2_dbg_cpu_open(struct inode *inode, struct file *file)
48 struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)inode->i_private;
50 err = single_open(file, dpaa2_dbg_cpu_show, priv);
52 netdev_err(priv->net_dev, "single_open() failed\n");
57 static const struct file_operations dpaa2_dbg_cpu_ops = {
58 .open = dpaa2_dbg_cpu_open,
61 .release = single_release,
64 static char *fq_type_to_str(struct dpaa2_eth_fq *fq)
69 case DPAA2_TX_CONF_FQ:
76 static int dpaa2_dbg_fqs_show(struct seq_file *file, void *offset)
78 struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private;
79 struct dpaa2_eth_fq *fq;
83 seq_printf(file, "FQ stats for %s:\n", priv->net_dev->name);
84 seq_printf(file, "%s%16s%16s%16s%16s\n",
85 "VFQID", "CPU", "Type", "Frames", "Pending frames");
87 for (i = 0; i < priv->num_fqs; i++) {
89 err = dpaa2_io_query_fq_count(NULL, fq->fqid, &fcnt, &bcnt);
93 seq_printf(file, "%5d%16d%16s%16llu%16u\n",
104 static int dpaa2_dbg_fqs_open(struct inode *inode, struct file *file)
107 struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)inode->i_private;
109 err = single_open(file, dpaa2_dbg_fqs_show, priv);
111 netdev_err(priv->net_dev, "single_open() failed\n");
116 static const struct file_operations dpaa2_dbg_fq_ops = {
117 .open = dpaa2_dbg_fqs_open,
120 .release = single_release,
123 static int dpaa2_dbg_ch_show(struct seq_file *file, void *offset)
125 struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private;
126 struct dpaa2_eth_channel *ch;
129 seq_printf(file, "Channel stats for %s:\n", priv->net_dev->name);
130 seq_printf(file, "%s%16s%16s%16s%16s\n",
131 "CHID", "CPU", "Deq busy", "CDANs", "Buf count");
133 for (i = 0; i < priv->num_channels; i++) {
134 ch = priv->channel[i];
135 seq_printf(file, "%4d%16d%16llu%16llu%16d\n",
137 ch->nctx.desired_cpu,
138 ch->stats.dequeue_portal_busy,
146 static int dpaa2_dbg_ch_open(struct inode *inode, struct file *file)
149 struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)inode->i_private;
151 err = single_open(file, dpaa2_dbg_ch_show, priv);
153 netdev_err(priv->net_dev, "single_open() failed\n");
158 static const struct file_operations dpaa2_dbg_ch_ops = {
159 .open = dpaa2_dbg_ch_open,
162 .release = single_release,
165 void dpaa2_dbg_add(struct dpaa2_eth_priv *priv)
170 /* Create a directory for the interface */
171 priv->dbg.dir = debugfs_create_dir(priv->net_dev->name,
173 if (!priv->dbg.dir) {
174 netdev_err(priv->net_dev, "debugfs_create_dir() failed\n");
178 /* per-cpu stats file */
179 priv->dbg.cpu_stats = debugfs_create_file("cpu_stats", 0444,
182 if (!priv->dbg.cpu_stats) {
183 netdev_err(priv->net_dev, "debugfs_create_file() failed\n");
187 /* per-fq stats file */
188 priv->dbg.fq_stats = debugfs_create_file("fq_stats", 0444,
191 if (!priv->dbg.fq_stats) {
192 netdev_err(priv->net_dev, "debugfs_create_file() failed\n");
196 /* per-fq stats file */
197 priv->dbg.ch_stats = debugfs_create_file("ch_stats", 0444,
200 if (!priv->dbg.fq_stats) {
201 netdev_err(priv->net_dev, "debugfs_create_file() failed\n");
208 debugfs_remove(priv->dbg.fq_stats);
210 debugfs_remove(priv->dbg.cpu_stats);
212 debugfs_remove(priv->dbg.dir);
215 void dpaa2_dbg_remove(struct dpaa2_eth_priv *priv)
217 debugfs_remove(priv->dbg.fq_stats);
218 debugfs_remove(priv->dbg.ch_stats);
219 debugfs_remove(priv->dbg.cpu_stats);
220 debugfs_remove(priv->dbg.dir);
223 void dpaa2_eth_dbg_init(void)
225 dpaa2_dbg_root = debugfs_create_dir(DPAA2_ETH_DBG_ROOT, NULL);
226 if (!dpaa2_dbg_root) {
227 pr_err("DPAA2-ETH: debugfs create failed\n");
231 pr_debug("DPAA2-ETH: debugfs created\n");
234 void dpaa2_eth_dbg_exit(void)
236 debugfs_remove(dpaa2_dbg_root);