1 // SPDX-License-Identifier: GPL-2.0
2 /****************************************************************************
3  *   -----------------------------DEGUGFS STUFF-------------------------
4  ****************************************************************************/
5 #include <linux/debugfs.h>
6 #include <linux/seq_file.h>
7 #include "r8192U.h"
8 
9 #define KBUILD_MODNAME "r8192u_usb"
10 
rtl8192_usb_stats_ap_show(struct seq_file * m,void * v)11 static int rtl8192_usb_stats_ap_show(struct seq_file *m, void *v)
12 {
13 	struct net_device *dev = m->private;
14 	struct r8192_priv *priv = ieee80211_priv(dev);
15 	struct ieee80211_device *ieee = priv->ieee80211;
16 	struct ieee80211_network *target;
17 
18 	list_for_each_entry(target, &ieee->network_list, list) {
19 		const char *wpa = "non_WPA";
20 
21 		if (target->wpa_ie_len > 0 || target->rsn_ie_len > 0)
22 			wpa = "WPA";
23 
24 		seq_printf(m, "%s %s\n", target->ssid, wpa);
25 	}
26 
27 	return 0;
28 }
29 
rtl8192_usb_registers_show(struct seq_file * m,void * v)30 static int rtl8192_usb_registers_show(struct seq_file *m, void *v)
31 {
32 	struct net_device *dev = m->private;
33 	int i, n, max = 0xff;
34 	u8 byte_rd;
35 
36 	seq_puts(m, "\n####################page 0##################\n ");
37 
38 	for (n = 0; n <= max;) {
39 		seq_printf(m, "\nD:  %2x > ", n);
40 
41 		for (i = 0; i < 16 && n <= max; i++, n++) {
42 			read_nic_byte(dev, 0x000 | n, &byte_rd);
43 			seq_printf(m, "%2x ", byte_rd);
44 		}
45 	}
46 
47 	seq_puts(m, "\n####################page 1##################\n ");
48 	for (n = 0; n <= max;) {
49 		seq_printf(m, "\nD:  %2x > ", n);
50 
51 		for (i = 0; i < 16 && n <= max; i++, n++) {
52 			read_nic_byte(dev, 0x100 | n, &byte_rd);
53 			seq_printf(m, "%2x ", byte_rd);
54 		}
55 	}
56 
57 	seq_puts(m, "\n####################page 3##################\n ");
58 	for (n = 0; n <= max;) {
59 		seq_printf(m, "\nD:  %2x > ", n);
60 
61 		for (i = 0; i < 16 && n <= max; i++, n++) {
62 			read_nic_byte(dev, 0x300 | n, &byte_rd);
63 			seq_printf(m, "%2x ", byte_rd);
64 		}
65 	}
66 
67 	seq_putc(m, '\n');
68 	return 0;
69 }
70 
rtl8192_usb_stats_tx_show(struct seq_file * m,void * v)71 static int rtl8192_usb_stats_tx_show(struct seq_file *m, void *v)
72 {
73 	struct net_device *dev = m->private;
74 	struct r8192_priv *priv = ieee80211_priv(dev);
75 
76 	seq_printf(m,
77 		   "TX VI priority ok int: %lu\n"
78 		   "TX VI priority error int: %lu\n"
79 		   "TX VO priority ok int: %lu\n"
80 		   "TX VO priority error int: %lu\n"
81 		   "TX BE priority ok int: %lu\n"
82 		   "TX BE priority error int: %lu\n"
83 		   "TX BK priority ok int: %lu\n"
84 		   "TX BK priority error int: %lu\n"
85 		   "TX MANAGE priority ok int: %lu\n"
86 		   "TX MANAGE priority error int: %lu\n"
87 		   "TX BEACON priority ok int: %lu\n"
88 		   "TX BEACON priority error int: %lu\n"
89 		   "TX queue resume: %lu\n"
90 		   "TX queue stopped?: %d\n"
91 		   "TX fifo overflow: %lu\n"
92 		   "TX VI queue: %d\n"
93 		   "TX VO queue: %d\n"
94 		   "TX BE queue: %d\n"
95 		   "TX BK queue: %d\n"
96 		   "TX VI dropped: %lu\n"
97 		   "TX VO dropped: %lu\n"
98 		   "TX BE dropped: %lu\n"
99 		   "TX BK dropped: %lu\n"
100 		   "TX total data packets %lu\n",
101 		   priv->stats.txviokint,
102 		   priv->stats.txvierr,
103 		   priv->stats.txvookint,
104 		   priv->stats.txvoerr,
105 		   priv->stats.txbeokint,
106 		   priv->stats.txbeerr,
107 		   priv->stats.txbkokint,
108 		   priv->stats.txbkerr,
109 		   priv->stats.txmanageokint,
110 		   priv->stats.txmanageerr,
111 		   priv->stats.txbeaconokint,
112 		   priv->stats.txbeaconerr,
113 		   priv->stats.txresumed,
114 		   netif_queue_stopped(dev),
115 		   priv->stats.txoverflow,
116 		   atomic_read(&(priv->tx_pending[VI_PRIORITY])),
117 		   atomic_read(&(priv->tx_pending[VO_PRIORITY])),
118 		   atomic_read(&(priv->tx_pending[BE_PRIORITY])),
119 		   atomic_read(&(priv->tx_pending[BK_PRIORITY])),
120 		   priv->stats.txvidrop,
121 		   priv->stats.txvodrop,
122 		   priv->stats.txbedrop,
123 		   priv->stats.txbkdrop,
124 		   priv->stats.txdatapkt
125 		);
126 
127 	return 0;
128 }
129 
rtl8192_usb_stats_rx_show(struct seq_file * m,void * v)130 static int rtl8192_usb_stats_rx_show(struct seq_file *m, void *v)
131 {
132 	struct net_device *dev = m->private;
133 	struct r8192_priv *priv = ieee80211_priv(dev);
134 
135 	seq_printf(m,
136 		   "RX packets: %lu\n"
137 		   "RX urb status error: %lu\n"
138 		   "RX invalid urb error: %lu\n",
139 		   priv->stats.rxoktotal,
140 		   priv->stats.rxstaterr,
141 		   priv->stats.rxurberr);
142 
143 	return 0;
144 }
145 
146 DEFINE_SHOW_ATTRIBUTE(rtl8192_usb_stats_rx);
147 DEFINE_SHOW_ATTRIBUTE(rtl8192_usb_stats_tx);
148 DEFINE_SHOW_ATTRIBUTE(rtl8192_usb_stats_ap);
149 DEFINE_SHOW_ATTRIBUTE(rtl8192_usb_registers);
150 
rtl8192_debugfs_init_one(struct net_device * dev)151 void rtl8192_debugfs_init_one(struct net_device *dev)
152 {
153 	struct r8192_priv *priv = ieee80211_priv(dev);
154 	struct dentry *parent_dir = debugfs_lookup(KBUILD_MODNAME, NULL);
155 	struct dentry *dir = debugfs_create_dir(dev->name, parent_dir);
156 
157 	debugfs_create_file("stats-rx", 0444, dir, dev, &rtl8192_usb_stats_rx_fops);
158 	debugfs_create_file("stats-tx", 0444, dir, dev, &rtl8192_usb_stats_tx_fops);
159 	debugfs_create_file("stats-ap", 0444, dir, dev, &rtl8192_usb_stats_ap_fops);
160 	debugfs_create_file("registers", 0444, dir, dev, &rtl8192_usb_registers_fops);
161 
162 	priv->debugfs_dir = dir;
163 }
164 
rtl8192_debugfs_exit_one(struct net_device * dev)165 void rtl8192_debugfs_exit_one(struct net_device *dev)
166 {
167 	struct r8192_priv *priv = ieee80211_priv(dev);
168 
169 	debugfs_remove_recursive(priv->debugfs_dir);
170 }
171 
rtl8192_debugfs_rename_one(struct net_device * dev)172 void rtl8192_debugfs_rename_one(struct net_device *dev)
173 {
174 	struct r8192_priv *priv = ieee80211_priv(dev);
175 	struct dentry *parent_dir = debugfs_lookup(KBUILD_MODNAME, NULL);
176 
177 	debugfs_rename(parent_dir, priv->debugfs_dir, parent_dir, dev->name);
178 }
179 
rtl8192_debugfs_init(void)180 void rtl8192_debugfs_init(void)
181 {
182 	debugfs_create_dir(KBUILD_MODNAME, NULL);
183 }
184 
rtl8192_debugfs_exit(void)185 void rtl8192_debugfs_exit(void)
186 {
187 	debugfs_remove_recursive(debugfs_lookup(KBUILD_MODNAME, NULL));
188 }
189