xref: /openbmc/linux/drivers/net/wireless/mediatek/mt76/debugfs.c (revision 9dae47aba0a055f761176d9297371d5bb24289ec)
1 /*
2  * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 #include "mt76.h"
17 
18 static int
19 mt76_reg_set(void *data, u64 val)
20 {
21 	struct mt76_dev *dev = data;
22 
23 	dev->bus->wr(dev, dev->debugfs_reg, val);
24 	return 0;
25 }
26 
27 static int
28 mt76_reg_get(void *data, u64 *val)
29 {
30 	struct mt76_dev *dev = data;
31 
32 	*val = dev->bus->rr(dev, dev->debugfs_reg);
33 	return 0;
34 }
35 
36 DEFINE_SIMPLE_ATTRIBUTE(fops_regval, mt76_reg_get, mt76_reg_set, "0x%08llx\n");
37 
38 static int
39 mt76_queues_read(struct seq_file *s, void *data)
40 {
41 	struct mt76_dev *dev = dev_get_drvdata(s->private);
42 	int i;
43 
44 	for (i = 0; i < ARRAY_SIZE(dev->q_tx); i++) {
45 		struct mt76_queue *q = &dev->q_tx[i];
46 
47 		if (!q->ndesc)
48 			continue;
49 
50 		seq_printf(s,
51 			   "%d:	queued=%d head=%d tail=%d swq_queued=%d\n",
52 			   i, q->queued, q->head, q->tail, q->swq_queued);
53 	}
54 
55 	return 0;
56 }
57 
58 struct dentry *mt76_register_debugfs(struct mt76_dev *dev)
59 {
60 	struct dentry *dir;
61 
62 	dir = debugfs_create_dir("mt76", dev->hw->wiphy->debugfsdir);
63 	if (!dir)
64 		return NULL;
65 
66 	debugfs_create_u8("led_pin", S_IRUSR | S_IWUSR, dir, &dev->led_pin);
67 	debugfs_create_u32("regidx", S_IRUSR | S_IWUSR, dir, &dev->debugfs_reg);
68 	debugfs_create_file("regval", S_IRUSR | S_IWUSR, dir, dev,
69 			    &fops_regval);
70 	debugfs_create_blob("eeprom", S_IRUSR, dir, &dev->eeprom);
71 	if (dev->otp.data)
72 		debugfs_create_blob("otp", S_IRUSR, dir, &dev->otp);
73 	debugfs_create_devm_seqfile(dev->dev, "queues", dir, mt76_queues_read);
74 
75 	return dir;
76 }
77 EXPORT_SYMBOL_GPL(mt76_register_debugfs);
78