xref: /linux/drivers/net/wireless/broadcom/brcm80211/brcmsmac/debug.c (revision 7f71507851fc7764b36a3221839607d3a45c2025)
1 /*
2  * Copyright (c) 2012 Broadcom Corporation
3  * Copyright (c) 2012 Canonical Ltd.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 #include <linux/debugfs.h>
18 #include <linux/if_ether.h>
19 #include <linux/if.h>
20 #include <linux/net.h>
21 #include <linux/netdevice.h>
22 #include <linux/ieee80211.h>
23 #include <linux/module.h>
24 #include <net/mac80211.h>
25 
26 #include <defs.h>
27 #include <brcmu_wifi.h>
28 #include <brcmu_utils.h>
29 #include "types.h"
30 #include "main.h"
31 #include "debug.h"
32 #include "brcms_trace_events.h"
33 #include "phy/phy_int.h"
34 
35 static struct dentry *root_folder;
36 
37 void brcms_debugfs_init(void)
38 {
39 	root_folder = debugfs_create_dir(KBUILD_MODNAME, NULL);
40 }
41 
42 void brcms_debugfs_exit(void)
43 {
44 	debugfs_remove_recursive(root_folder);
45 	root_folder = NULL;
46 }
47 
48 void brcms_debugfs_attach(struct brcms_pub *drvr)
49 {
50 	drvr->dbgfs_dir = debugfs_create_dir(
51 		 dev_name(&drvr->wlc->hw->d11core->dev), root_folder);
52 }
53 
54 void brcms_debugfs_detach(struct brcms_pub *drvr)
55 {
56 	debugfs_remove_recursive(drvr->dbgfs_dir);
57 }
58 
59 static
60 int brcms_debugfs_hardware_read(struct seq_file *s, void *data)
61 {
62 	struct brcms_pub *drvr = s->private;
63 	struct brcms_hardware *hw = drvr->wlc->hw;
64 	struct bcma_device *core = hw->d11core;
65 	struct bcma_bus *bus = core->bus;
66 	char boardrev[BRCMU_BOARDREV_LEN];
67 
68 	seq_printf(s, "chipnum 0x%x\n"
69 		   "chiprev 0x%x\n"
70 		   "chippackage 0x%x\n"
71 		   "corerev 0x%x\n"
72 		   "boardid 0x%x\n"
73 		   "boardvendor 0x%x\n"
74 		   "boardrev %s\n"
75 		   "boardflags 0x%x\n"
76 		   "boardflags2 0x%x\n"
77 		   "ucoderev 0x%x\n"
78 		   "radiorev 0x%x\n"
79 		   "phytype 0x%x\n"
80 		   "phyrev 0x%x\n"
81 		   "anarev 0x%x\n"
82 		   "nvramrev %d\n",
83 		   bus->chipinfo.id, bus->chipinfo.rev, bus->chipinfo.pkg,
84 		   core->id.rev, bus->boardinfo.type, bus->boardinfo.vendor,
85 		   brcmu_boardrev_str(hw->boardrev, boardrev),
86 		   drvr->wlc->hw->boardflags, drvr->wlc->hw->boardflags2,
87 		   drvr->wlc->ucode_rev, hw->band->radiorev,
88 		   hw->band->phytype, hw->band->phyrev, hw->band->pi->ana_rev,
89 		   hw->sromrev);
90 	return 0;
91 }
92 
93 static int brcms_debugfs_macstat_read(struct seq_file *s, void *data)
94 {
95 	struct brcms_pub *drvr = s->private;
96 	struct brcms_info *wl = drvr->ieee_hw->priv;
97 	struct macstat stats;
98 	int i;
99 
100 	spin_lock_bh(&wl->lock);
101 	stats = *(drvr->wlc->core->macstat_snapshot);
102 	spin_unlock_bh(&wl->lock);
103 
104 	seq_printf(s, "txallfrm: %d\n", stats.txallfrm);
105 	seq_printf(s, "txrtsfrm: %d\n", stats.txrtsfrm);
106 	seq_printf(s, "txctsfrm: %d\n", stats.txctsfrm);
107 	seq_printf(s, "txackfrm: %d\n", stats.txackfrm);
108 	seq_printf(s, "txdnlfrm: %d\n", stats.txdnlfrm);
109 	seq_printf(s, "txbcnfrm: %d\n", stats.txbcnfrm);
110 	seq_printf(s, "txfunfl[8]:");
111 	for (i = 0; i < ARRAY_SIZE(stats.txfunfl); i++)
112 		seq_printf(s, " %d", stats.txfunfl[i]);
113 	seq_printf(s, "\ntxtplunfl: %d\n", stats.txtplunfl);
114 	seq_printf(s, "txphyerr: %d\n", stats.txphyerr);
115 	seq_printf(s, "pktengrxducast: %d\n", stats.pktengrxducast);
116 	seq_printf(s, "pktengrxdmcast: %d\n", stats.pktengrxdmcast);
117 	seq_printf(s, "rxfrmtoolong: %d\n", stats.rxfrmtoolong);
118 	seq_printf(s, "rxfrmtooshrt: %d\n", stats.rxfrmtooshrt);
119 	seq_printf(s, "rxinvmachdr: %d\n", stats.rxinvmachdr);
120 	seq_printf(s, "rxbadfcs: %d\n", stats.rxbadfcs);
121 	seq_printf(s, "rxbadplcp: %d\n", stats.rxbadplcp);
122 	seq_printf(s, "rxcrsglitch: %d\n", stats.rxcrsglitch);
123 	seq_printf(s, "rxstrt: %d\n", stats.rxstrt);
124 	seq_printf(s, "rxdfrmucastmbss: %d\n", stats.rxdfrmucastmbss);
125 	seq_printf(s, "rxmfrmucastmbss: %d\n", stats.rxmfrmucastmbss);
126 	seq_printf(s, "rxcfrmucast: %d\n", stats.rxcfrmucast);
127 	seq_printf(s, "rxrtsucast: %d\n", stats.rxrtsucast);
128 	seq_printf(s, "rxctsucast: %d\n", stats.rxctsucast);
129 	seq_printf(s, "rxackucast: %d\n", stats.rxackucast);
130 	seq_printf(s, "rxdfrmocast: %d\n", stats.rxdfrmocast);
131 	seq_printf(s, "rxmfrmocast: %d\n", stats.rxmfrmocast);
132 	seq_printf(s, "rxcfrmocast: %d\n", stats.rxcfrmocast);
133 	seq_printf(s, "rxrtsocast: %d\n", stats.rxrtsocast);
134 	seq_printf(s, "rxctsocast: %d\n", stats.rxctsocast);
135 	seq_printf(s, "rxdfrmmcast: %d\n", stats.rxdfrmmcast);
136 	seq_printf(s, "rxmfrmmcast: %d\n", stats.rxmfrmmcast);
137 	seq_printf(s, "rxcfrmmcast: %d\n", stats.rxcfrmmcast);
138 	seq_printf(s, "rxbeaconmbss: %d\n", stats.rxbeaconmbss);
139 	seq_printf(s, "rxdfrmucastobss: %d\n", stats.rxdfrmucastobss);
140 	seq_printf(s, "rxbeaconobss: %d\n", stats.rxbeaconobss);
141 	seq_printf(s, "rxrsptmout: %d\n", stats.rxrsptmout);
142 	seq_printf(s, "bcntxcancl: %d\n", stats.bcntxcancl);
143 	seq_printf(s, "rxf0ovfl: %d\n", stats.rxf0ovfl);
144 	seq_printf(s, "rxf1ovfl: %d\n", stats.rxf1ovfl);
145 	seq_printf(s, "rxf2ovfl: %d\n", stats.rxf2ovfl);
146 	seq_printf(s, "txsfovfl: %d\n", stats.txsfovfl);
147 	seq_printf(s, "pmqovfl: %d\n", stats.pmqovfl);
148 	seq_printf(s, "rxcgprqfrm: %d\n", stats.rxcgprqfrm);
149 	seq_printf(s, "rxcgprsqovfl: %d\n", stats.rxcgprsqovfl);
150 	seq_printf(s, "txcgprsfail: %d\n", stats.txcgprsfail);
151 	seq_printf(s, "txcgprssuc: %d\n", stats.txcgprssuc);
152 	seq_printf(s, "prs_timeout: %d\n", stats.prs_timeout);
153 	seq_printf(s, "rxnack: %d\n", stats.rxnack);
154 	seq_printf(s, "frmscons: %d\n", stats.frmscons);
155 	seq_printf(s, "txnack: %d\n", stats.txnack);
156 	seq_printf(s, "txglitch_nack: %d\n", stats.txglitch_nack);
157 	seq_printf(s, "txburst: %d\n", stats.txburst);
158 	seq_printf(s, "bphy_rxcrsglitch: %d\n", stats.bphy_rxcrsglitch);
159 	seq_printf(s, "phywatchdog: %d\n", stats.phywatchdog);
160 	seq_printf(s, "bphy_badplcp: %d\n", stats.bphy_badplcp);
161 	return 0;
162 }
163 
164 struct brcms_debugfs_entry {
165 	int (*read)(struct seq_file *seq, void *data);
166 	struct brcms_pub *drvr;
167 };
168 
169 static int brcms_debugfs_entry_open(struct inode *inode, struct file *f)
170 {
171 	struct brcms_debugfs_entry *entry = inode->i_private;
172 
173 	return single_open(f, entry->read, entry->drvr);
174 }
175 
176 static const struct file_operations brcms_debugfs_def_ops = {
177 	.owner = THIS_MODULE,
178 	.open = brcms_debugfs_entry_open,
179 	.release = single_release,
180 	.read = seq_read,
181 	.llseek = seq_lseek
182 };
183 
184 static void
185 brcms_debugfs_add_entry(struct brcms_pub *drvr, const char *fn,
186 			int (*read_fn)(struct seq_file *seq, void *data))
187 {
188 	struct device *dev = &drvr->wlc->hw->d11core->dev;
189 	struct dentry *dentry =  drvr->dbgfs_dir;
190 	struct brcms_debugfs_entry *entry;
191 
192 	entry = devm_kzalloc(dev, sizeof(*entry), GFP_KERNEL);
193 	if (!entry)
194 		return;
195 
196 	entry->read = read_fn;
197 	entry->drvr = drvr;
198 
199 	debugfs_create_file(fn, 0444, dentry, entry, &brcms_debugfs_def_ops);
200 }
201 
202 void brcms_debugfs_create_files(struct brcms_pub *drvr)
203 {
204 	brcms_debugfs_add_entry(drvr, "hardware", brcms_debugfs_hardware_read);
205 	brcms_debugfs_add_entry(drvr, "macstat", brcms_debugfs_macstat_read);
206 }
207 
208 #define __brcms_fn(fn)						\
209 void __brcms_ ##fn(struct device *dev, const char *fmt, ...)	\
210 {								\
211 	struct va_format vaf = {				\
212 		.fmt = fmt,					\
213 	};							\
214 	va_list args;						\
215 								\
216 	va_start(args, fmt);					\
217 	vaf.va = &args;						\
218 	dev_ ##fn(dev, "%pV", &vaf);				\
219 	trace_brcms_ ##fn(&vaf);				\
220 	va_end(args);						\
221 }
222 
223 __brcms_fn(info)
224 __brcms_fn(warn)
225 __brcms_fn(err)
226 __brcms_fn(crit)
227 
228 #if defined(CONFIG_BRCMDBG) || defined(CONFIG_BRCM_TRACING)
229 void __brcms_dbg(struct device *dev, u32 level, const char *func,
230 		 const char *fmt, ...)
231 {
232 	struct va_format vaf = {
233 		.fmt = fmt,
234 	};
235 	va_list args;
236 
237 	va_start(args, fmt);
238 	vaf.va = &args;
239 #ifdef CONFIG_BRCMDBG
240 	if ((brcm_msg_level & level) && net_ratelimit())
241 		dev_err(dev, "%s %pV", func, &vaf);
242 #endif
243 	trace_brcms_dbg(level, func, &vaf);
244 	va_end(args);
245 }
246 #endif
247