• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: ISC
2 /*
3  * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
4  */
5 #include "mt76.h"
6 
7 static int
mt76_reg_set(void * data,u64 val)8 mt76_reg_set(void *data, u64 val)
9 {
10 	struct mt76_dev *dev = data;
11 
12 	__mt76_wr(dev, dev->debugfs_reg, val);
13 	return 0;
14 }
15 
16 static int
mt76_reg_get(void * data,u64 * val)17 mt76_reg_get(void *data, u64 *val)
18 {
19 	struct mt76_dev *dev = data;
20 
21 	*val = __mt76_rr(dev, dev->debugfs_reg);
22 	return 0;
23 }
24 
25 DEFINE_DEBUGFS_ATTRIBUTE(fops_regval, mt76_reg_get, mt76_reg_set,
26 			 "0x%08llx\n");
27 
28 static int
mt76_napi_threaded_set(void * data,u64 val)29 mt76_napi_threaded_set(void *data, u64 val)
30 {
31 	struct mt76_dev *dev = data;
32 
33 	if (!mt76_is_mmio(dev))
34 		return -EOPNOTSUPP;
35 
36 	if (dev->napi_dev.threaded != val)
37 		return dev_set_threaded(&dev->napi_dev, val);
38 
39 	return 0;
40 }
41 
42 static int
mt76_napi_threaded_get(void * data,u64 * val)43 mt76_napi_threaded_get(void *data, u64 *val)
44 {
45 	struct mt76_dev *dev = data;
46 
47 	*val = dev->napi_dev.threaded;
48 	return 0;
49 }
50 
51 DEFINE_DEBUGFS_ATTRIBUTE(fops_napi_threaded, mt76_napi_threaded_get,
52 			 mt76_napi_threaded_set, "%llu\n");
53 
mt76_queues_read(struct seq_file * s,void * data)54 int mt76_queues_read(struct seq_file *s, void *data)
55 {
56 	struct mt76_dev *dev = dev_get_drvdata(s->private);
57 	int i;
58 
59 	for (i = 0; i < ARRAY_SIZE(dev->phy.q_tx); i++) {
60 		struct mt76_queue *q = dev->phy.q_tx[i];
61 
62 		if (!q)
63 			continue;
64 
65 		seq_printf(s,
66 			   "%d:	queued=%d head=%d tail=%d\n",
67 			   i, q->queued, q->head, q->tail);
68 	}
69 
70 	return 0;
71 }
72 EXPORT_SYMBOL_GPL(mt76_queues_read);
73 
mt76_rx_queues_read(struct seq_file * s,void * data)74 static int mt76_rx_queues_read(struct seq_file *s, void *data)
75 {
76 	struct mt76_dev *dev = dev_get_drvdata(s->private);
77 	int i, queued;
78 
79 	mt76_for_each_q_rx(dev, i) {
80 		struct mt76_queue *q = &dev->q_rx[i];
81 
82 		queued = mt76_is_usb(dev) ? q->ndesc - q->queued : q->queued;
83 		seq_printf(s, "%d:	queued=%d head=%d tail=%d\n",
84 			   i, queued, q->head, q->tail);
85 	}
86 
87 	return 0;
88 }
89 
mt76_seq_puts_array(struct seq_file * file,const char * str,s8 * val,int len)90 void mt76_seq_puts_array(struct seq_file *file, const char *str,
91 			 s8 *val, int len)
92 {
93 	int i;
94 
95 	seq_printf(file, "%10s:", str);
96 	for (i = 0; i < len; i++)
97 		seq_printf(file, " %2d", val[i]);
98 	seq_puts(file, "\n");
99 }
100 EXPORT_SYMBOL_GPL(mt76_seq_puts_array);
101 
mt76_read_rate_txpower(struct seq_file * s,void * data)102 static int mt76_read_rate_txpower(struct seq_file *s, void *data)
103 {
104 	struct mt76_dev *dev = dev_get_drvdata(s->private);
105 
106 	mt76_seq_puts_array(s, "CCK", dev->rate_power.cck,
107 			    ARRAY_SIZE(dev->rate_power.cck));
108 	mt76_seq_puts_array(s, "OFDM", dev->rate_power.ofdm,
109 			    ARRAY_SIZE(dev->rate_power.ofdm));
110 	mt76_seq_puts_array(s, "STBC", dev->rate_power.stbc,
111 			    ARRAY_SIZE(dev->rate_power.stbc));
112 	mt76_seq_puts_array(s, "HT", dev->rate_power.ht,
113 			    ARRAY_SIZE(dev->rate_power.ht));
114 	mt76_seq_puts_array(s, "VHT", dev->rate_power.vht,
115 			    ARRAY_SIZE(dev->rate_power.vht));
116 	return 0;
117 }
118 
119 struct dentry *
mt76_register_debugfs_fops(struct mt76_dev * dev,const struct file_operations * ops)120 mt76_register_debugfs_fops(struct mt76_dev *dev,
121 			   const struct file_operations *ops)
122 {
123 	const struct file_operations *fops = ops ? ops : &fops_regval;
124 	struct dentry *dir;
125 
126 	dir = debugfs_create_dir("mt76", dev->hw->wiphy->debugfsdir);
127 	if (!dir)
128 		return NULL;
129 
130 	debugfs_create_u8("led_pin", 0600, dir, &dev->led_pin);
131 	debugfs_create_u32("regidx", 0600, dir, &dev->debugfs_reg);
132 	debugfs_create_file_unsafe("regval", 0600, dir, dev, fops);
133 	debugfs_create_file_unsafe("napi_threaded", 0600, dir, dev,
134 				   &fops_napi_threaded);
135 	debugfs_create_blob("eeprom", 0400, dir, &dev->eeprom);
136 	if (dev->otp.data)
137 		debugfs_create_blob("otp", 0400, dir, &dev->otp);
138 	debugfs_create_devm_seqfile(dev->dev, "rate_txpower", dir,
139 				    mt76_read_rate_txpower);
140 	debugfs_create_devm_seqfile(dev->dev, "rx-queues", dir,
141 				    mt76_rx_queues_read);
142 
143 	return dir;
144 }
145 EXPORT_SYMBOL_GPL(mt76_register_debugfs_fops);
146