summaryrefslogtreecommitdiff
path: root/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth-debugfs.c
blob: 933412ebbba5a4abc04bfbb63612f2180d499916 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352

/* Copyright 2015 Freescale Semiconductor Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *	 notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *	 notice, this list of conditions and the following disclaimer in the
 *	 documentation and/or other materials provided with the distribution.
 *     * Neither the name of Freescale Semiconductor nor the
 *	 names of its contributors may be used to endorse or promote products
 *	 derived from this software without specific prior written permission.
 *
 *
 * ALTERNATIVELY, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") as published by the Free Software
 * Foundation, either version 2 of that License or (at your option) any
 * later version.
 *
 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <linux/module.h>
#include <linux/debugfs.h>
#include "dpaa2-eth.h"
#include "dpaa2-eth-debugfs.h"

#define DPAA2_ETH_DBG_ROOT "dpaa2-eth"

static struct dentry *dpaa2_dbg_root;

static int dpaa2_dbg_cpu_show(struct seq_file *file, void *offset)
{
	struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private;
	struct rtnl_link_stats64 *stats;
	struct dpaa2_eth_drv_stats *extras;
	int i;

	seq_printf(file, "Per-CPU stats for %s\n", priv->net_dev->name);
	seq_printf(file, "%s%16s%16s%16s%16s%16s%16s%16s%16s\n",
		   "CPU", "Rx", "Rx Err", "Rx SG", "Tx", "Tx Err", "Tx conf",
		   "Tx SG", "Enq busy");

	for_each_online_cpu(i) {
		stats = per_cpu_ptr(priv->percpu_stats, i);
		extras = per_cpu_ptr(priv->percpu_extras, i);
		seq_printf(file, "%3d%16llu%16llu%16llu%16llu%16llu%16llu%16llu%16llu\n",
			   i,
			   stats->rx_packets,
			   stats->rx_errors,
			   extras->rx_sg_frames,
			   stats->tx_packets,
			   stats->tx_errors,
			   extras->tx_conf_frames,
			   extras->tx_sg_frames,
			   extras->tx_portal_busy);
	}

	return 0;
}

static int dpaa2_dbg_cpu_open(struct inode *inode, struct file *file)
{
	int err;
	struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)inode->i_private;

	err = single_open(file, dpaa2_dbg_cpu_show, priv);
	if (err < 0)
		netdev_err(priv->net_dev, "single_open() failed\n");

	return err;
}

static const struct file_operations dpaa2_dbg_cpu_ops = {
	.open = dpaa2_dbg_cpu_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
};

static char *fq_type_to_str(struct dpaa2_eth_fq *fq)
{
	switch (fq->type) {
	case DPAA2_RX_FQ:
		return "Rx";
	case DPAA2_TX_CONF_FQ:
		return "Tx conf";
	case DPAA2_RX_ERR_FQ:
		return "Rx err";
	default:
		return "N/A";
	}
}

static int dpaa2_dbg_fqs_show(struct seq_file *file, void *offset)
{
	struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private;
	struct dpaa2_eth_fq *fq;
	u32 fcnt, bcnt;
	int i, err;

	seq_printf(file, "FQ stats for %s:\n", priv->net_dev->name);
	seq_printf(file, "%s%16s%16s%16s%16s%16s%16s\n",
		   "VFQID", "CPU", "Traffic Class", "Type", "Frames",
		   "Pending frames", "Congestion");

	for (i = 0; i <  priv->num_fqs; i++) {
		fq = &priv->fq[i];
		err = dpaa2_io_query_fq_count(NULL, fq->fqid, &fcnt, &bcnt);
		if (err)
			fcnt = 0;

		seq_printf(file, "%5d%16d%16d%16s%16llu%16u%16llu\n",
			   fq->fqid,
			   fq->target_cpu,
			   fq->tc,
			   fq_type_to_str(fq),
			   fq->stats.frames,
			   fcnt,
			   fq->stats.congestion_entry);
	}

	return 0;
}

static int dpaa2_dbg_fqs_open(struct inode *inode, struct file *file)
{
	int err;
	struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)inode->i_private;

	err = single_open(file, dpaa2_dbg_fqs_show, priv);
	if (err < 0)
		netdev_err(priv->net_dev, "single_open() failed\n");

	return err;
}

static const struct file_operations dpaa2_dbg_fq_ops = {
	.open = dpaa2_dbg_fqs_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
};

static int dpaa2_dbg_ch_show(struct seq_file *file, void *offset)
{
	struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private;
	struct dpaa2_eth_channel *ch;
	int i;

	seq_printf(file, "Channel stats for %s:\n", priv->net_dev->name);
	seq_printf(file, "%s%16s%16s%16s%16s%16s%16s\n",
		   "CHID", "CPU", "Deq busy", "Frames", "CDANs",
		   "Avg frm/CDAN", "Buf count");

	for (i = 0; i < priv->num_channels; i++) {
		ch = priv->channel[i];
		seq_printf(file, "%4d%16d%16llu%16llu%16llu%16llu%16d\n",
			   ch->ch_id,
			   ch->nctx.desired_cpu,
			   ch->stats.dequeue_portal_busy,
			   ch->stats.frames,
			   ch->stats.cdan,
			   ch->stats.frames / ch->stats.cdan,
			   ch->buf_count);
	}

	return 0;
}

static int dpaa2_dbg_ch_open(struct inode *inode, struct file *file)
{
	int err;
	struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)inode->i_private;

	err = single_open(file, dpaa2_dbg_ch_show, priv);
	if (err < 0)
		netdev_err(priv->net_dev, "single_open() failed\n");

	return err;
}

static const struct file_operations dpaa2_dbg_ch_ops = {
	.open = dpaa2_dbg_ch_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
};

static ssize_t dpaa2_dbg_reset_write(struct file *file, const char __user *buf,
				     size_t count, loff_t *offset)
{
	struct dpaa2_eth_priv *priv = file->private_data;
	struct rtnl_link_stats64 *percpu_stats;
	struct dpaa2_eth_drv_stats *percpu_extras;
	struct dpaa2_eth_fq *fq;
	struct dpaa2_eth_channel *ch;
	int i;

	for_each_online_cpu(i) {
		percpu_stats = per_cpu_ptr(priv->percpu_stats, i);
		memset(percpu_stats, 0, sizeof(*percpu_stats));

		percpu_extras = per_cpu_ptr(priv->percpu_extras, i);
		memset(percpu_extras, 0, sizeof(*percpu_extras));
	}

	for (i = 0; i < priv->num_fqs; i++) {
		fq = &priv->fq[i];
		memset(&fq->stats, 0, sizeof(fq->stats));
	}

	for (i = 0; i < priv->num_channels; i++) {
		ch = priv->channel[i];
		memset(&ch->stats, 0, sizeof(ch->stats));
	}

	return count;
}

static const struct file_operations dpaa2_dbg_reset_ops = {
	.open = simple_open,
	.write = dpaa2_dbg_reset_write,
};

static ssize_t dpaa2_dbg_reset_mc_write(struct file *file,
					const char __user *buf,
					size_t count, loff_t *offset)
{
	struct dpaa2_eth_priv *priv = file->private_data;
	int err;

	err = dpni_reset_statistics(priv->mc_io, 0, priv->mc_token);
	if (err)
		netdev_err(priv->net_dev,
			   "dpni_reset_statistics() failed %d\n", err);

	return count;
}

static const struct file_operations dpaa2_dbg_reset_mc_ops = {
	.open = simple_open,
	.write = dpaa2_dbg_reset_mc_write,
};

void dpaa2_dbg_add(struct dpaa2_eth_priv *priv)
{
	if (!dpaa2_dbg_root)
		return;

	/* Create a directory for the interface */
	priv->dbg.dir = debugfs_create_dir(priv->net_dev->name,
					   dpaa2_dbg_root);
	if (!priv->dbg.dir) {
		netdev_err(priv->net_dev, "debugfs_create_dir() failed\n");
		return;
	}

	/* per-cpu stats file */
	priv->dbg.cpu_stats = debugfs_create_file("cpu_stats", 0444,
						  priv->dbg.dir, priv,
						  &dpaa2_dbg_cpu_ops);
	if (!priv->dbg.cpu_stats) {
		netdev_err(priv->net_dev, "debugfs_create_file() failed\n");
		goto err_cpu_stats;
	}

	/* per-fq stats file */
	priv->dbg.fq_stats = debugfs_create_file("fq_stats", 0444,
						 priv->dbg.dir, priv,
						 &dpaa2_dbg_fq_ops);
	if (!priv->dbg.fq_stats) {
		netdev_err(priv->net_dev, "debugfs_create_file() failed\n");
		goto err_fq_stats;
	}

	/* per-fq stats file */
	priv->dbg.ch_stats = debugfs_create_file("ch_stats", 0444,
						 priv->dbg.dir, priv,
						 &dpaa2_dbg_ch_ops);
	if (!priv->dbg.fq_stats) {
		netdev_err(priv->net_dev, "debugfs_create_file() failed\n");
		goto err_ch_stats;
	}

	/* reset stats */
	priv->dbg.reset_stats = debugfs_create_file("reset_stats", 0200,
						    priv->dbg.dir, priv,
						    &dpaa2_dbg_reset_ops);
	if (!priv->dbg.reset_stats) {
		netdev_err(priv->net_dev, "debugfs_create_file() failed\n");
		goto err_reset_stats;
	}

	/* reset MC stats */
	priv->dbg.reset_mc_stats = debugfs_create_file("reset_mc_stats",
						0222, priv->dbg.dir, priv,
						&dpaa2_dbg_reset_mc_ops);
	if (!priv->dbg.reset_mc_stats) {
		netdev_err(priv->net_dev, "debugfs_create_file() failed\n");
		goto err_reset_mc_stats;
	}

	return;

err_reset_mc_stats:
	debugfs_remove(priv->dbg.reset_stats);
err_reset_stats:
	debugfs_remove(priv->dbg.ch_stats);
err_ch_stats:
	debugfs_remove(priv->dbg.fq_stats);
err_fq_stats:
	debugfs_remove(priv->dbg.cpu_stats);
err_cpu_stats:
	debugfs_remove(priv->dbg.dir);
}

void dpaa2_dbg_remove(struct dpaa2_eth_priv *priv)
{
	debugfs_remove(priv->dbg.reset_mc_stats);
	debugfs_remove(priv->dbg.reset_stats);
	debugfs_remove(priv->dbg.fq_stats);
	debugfs_remove(priv->dbg.ch_stats);
	debugfs_remove(priv->dbg.cpu_stats);
	debugfs_remove(priv->dbg.dir);
}

void dpaa2_eth_dbg_init(void)
{
	dpaa2_dbg_root = debugfs_create_dir(DPAA2_ETH_DBG_ROOT, NULL);
	if (!dpaa2_dbg_root) {
		pr_err("DPAA2-ETH: debugfs create failed\n");
		return;
	}

	pr_info("DPAA2-ETH: debugfs created\n");
}

void __exit dpaa2_eth_dbg_exit(void)
{
	debugfs_remove(dpaa2_dbg_root);
}