1// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2/* Copyright 2019 NXP */
3
4#include <linux/module.h>
5#include <linux/device.h>
6#include <linux/debugfs.h>
7#include "dpseci-debugfs.h"
8
9static int dpseci_dbg_fqs_show(struct seq_file *file, void *offset)
10{
11	struct dpaa2_caam_priv *priv = file->private;
12	u32 fqid, fcnt, bcnt;
13	int i, err;
14
15	seq_printf(file, "FQ stats for %s:\n", dev_name(priv->dev));
16	seq_printf(file, "%s%16s%16s\n",
17		   "Rx-VFQID",
18		   "Pending frames",
19		   "Pending bytes");
20
21	for (i = 0; i <  priv->num_pairs; i++) {
22		fqid = priv->rx_queue_attr[i].fqid;
23		err = dpaa2_io_query_fq_count(NULL, fqid, &fcnt, &bcnt);
24		if (err)
25			continue;
26
27		seq_printf(file, "%5d%16u%16u\n", fqid, fcnt, bcnt);
28	}
29
30	seq_printf(file, "%s%16s%16s\n",
31		   "Tx-VFQID",
32		   "Pending frames",
33		   "Pending bytes");
34
35	for (i = 0; i <  priv->num_pairs; i++) {
36		fqid = priv->tx_queue_attr[i].fqid;
37		err = dpaa2_io_query_fq_count(NULL, fqid, &fcnt, &bcnt);
38		if (err)
39			continue;
40
41		seq_printf(file, "%5d%16u%16u\n", fqid, fcnt, bcnt);
42	}
43
44	return 0;
45}
46
47DEFINE_SHOW_ATTRIBUTE(dpseci_dbg_fqs);
48
49void dpaa2_dpseci_debugfs_init(struct dpaa2_caam_priv *priv)
50{
51	priv->dfs_root = debugfs_create_dir(dev_name(priv->dev), NULL);
52
53	debugfs_create_file("fq_stats", 0444, priv->dfs_root, priv,
54			    &dpseci_dbg_fqs_fops);
55}
56
57void dpaa2_dpseci_debugfs_exit(struct dpaa2_caam_priv *priv)
58{
59	debugfs_remove_recursive(priv->dfs_root);
60}
61