1 /*
2  * This file is part of wl18xx
3  *
4  * Copyright (C) 2009 Nokia Corporation
5  * Copyright (C) 2011-2012 Texas Instruments
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19  * 02110-1301 USA
20  *
21  */
22 
23 #include <linux/pm_runtime.h>
24 
25 #include "../wlcore/debugfs.h"
26 #include "../wlcore/wlcore.h"
27 #include "../wlcore/debug.h"
28 #include "../wlcore/ps.h"
29 
30 #include "wl18xx.h"
31 #include "acx.h"
32 #include "cmd.h"
33 #include "debugfs.h"
34 
35 #define WL18XX_DEBUGFS_FWSTATS_FILE(a, b, c) \
36 	DEBUGFS_FWSTATS_FILE(a, b, c, wl18xx_acx_statistics)
37 #define WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(a, b, c) \
38 	DEBUGFS_FWSTATS_FILE_ARRAY(a, b, c, wl18xx_acx_statistics)
39 
40 
41 WL18XX_DEBUGFS_FWSTATS_FILE(error, error_frame_non_ctrl, "%u");
42 WL18XX_DEBUGFS_FWSTATS_FILE(error, error_frame_ctrl, "%u");
43 WL18XX_DEBUGFS_FWSTATS_FILE(error, error_frame_during_protection, "%u");
44 WL18XX_DEBUGFS_FWSTATS_FILE(error, null_frame_tx_start, "%u");
45 WL18XX_DEBUGFS_FWSTATS_FILE(error, null_frame_cts_start, "%u");
46 WL18XX_DEBUGFS_FWSTATS_FILE(error, bar_retry, "%u");
47 WL18XX_DEBUGFS_FWSTATS_FILE(error, num_frame_cts_nul_flid, "%u");
48 WL18XX_DEBUGFS_FWSTATS_FILE(error, tx_abort_failure, "%u");
49 WL18XX_DEBUGFS_FWSTATS_FILE(error, tx_resume_failure, "%u");
50 WL18XX_DEBUGFS_FWSTATS_FILE(error, rx_cmplt_db_overflow_cnt, "%u");
51 WL18XX_DEBUGFS_FWSTATS_FILE(error, elp_while_rx_exch, "%u");
52 WL18XX_DEBUGFS_FWSTATS_FILE(error, elp_while_tx_exch, "%u");
53 WL18XX_DEBUGFS_FWSTATS_FILE(error, elp_while_tx, "%u");
54 WL18XX_DEBUGFS_FWSTATS_FILE(error, elp_while_nvic_pending, "%u");
55 WL18XX_DEBUGFS_FWSTATS_FILE(error, rx_excessive_frame_len, "%u");
56 WL18XX_DEBUGFS_FWSTATS_FILE(error, burst_mismatch, "%u");
57 WL18XX_DEBUGFS_FWSTATS_FILE(error, tbc_exch_mismatch, "%u");
58 
59 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_prepared_descs, "%u");
60 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_cmplt, "%u");
61 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_template_prepared, "%u");
62 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_data_prepared, "%u");
63 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_template_programmed, "%u");
64 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_data_programmed, "%u");
65 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_burst_programmed, "%u");
66 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_starts, "%u");
67 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_stop, "%u");
68 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_start_templates, "%u");
69 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_start_int_templates, "%u");
70 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_start_fw_gen, "%u");
71 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_start_data, "%u");
72 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_start_null_frame, "%u");
73 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_exch, "%u");
74 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_retry_template, "%u");
75 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_retry_data, "%u");
76 WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(tx, tx_retry_per_rate,
77 				  NUM_OF_RATES_INDEXES);
78 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_exch_pending, "%u");
79 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_exch_expiry, "%u");
80 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_done_template, "%u");
81 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_done_data, "%u");
82 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_done_int_template, "%u");
83 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_cfe1, "%u");
84 WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_cfe2, "%u");
85 WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_called, "%u");
86 WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_mpdu_alloc_failed, "%u");
87 WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_init_called, "%u");
88 WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_in_process_called, "%u");
89 WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_tkip_called, "%u");
90 WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_key_not_found, "%u");
91 WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_need_fragmentation, "%u");
92 WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_bad_mblk_num, "%u");
93 WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_failed, "%u");
94 WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_cache_hit, "%u");
95 WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_cache_miss, "%u");
96 
97 WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_beacon_early_term, "%u");
98 WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_out_of_mpdu_nodes, "%u");
99 WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_hdr_overflow, "%u");
100 WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_dropped_frame, "%u");
101 WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_done, "%u");
102 WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_defrag, "%u");
103 WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_defrag_end, "%u");
104 WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_cmplt, "%u");
105 WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_pre_complt, "%u");
106 WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_cmplt_task, "%u");
107 WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_phy_hdr, "%u");
108 WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_timeout, "%u");
109 WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_rts_timeout, "%u");
110 WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_timeout_wa, "%u");
111 WL18XX_DEBUGFS_FWSTATS_FILE(rx, defrag_called, "%u");
112 WL18XX_DEBUGFS_FWSTATS_FILE(rx, defrag_init_called, "%u");
113 WL18XX_DEBUGFS_FWSTATS_FILE(rx, defrag_in_process_called, "%u");
114 WL18XX_DEBUGFS_FWSTATS_FILE(rx, defrag_tkip_called, "%u");
115 WL18XX_DEBUGFS_FWSTATS_FILE(rx, defrag_need_defrag, "%u");
116 WL18XX_DEBUGFS_FWSTATS_FILE(rx, defrag_decrypt_failed, "%u");
117 WL18XX_DEBUGFS_FWSTATS_FILE(rx, decrypt_key_not_found, "%u");
118 WL18XX_DEBUGFS_FWSTATS_FILE(rx, defrag_need_decrypt, "%u");
119 WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_tkip_replays, "%u");
120 WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_xfr, "%u");
121 
122 WL18XX_DEBUGFS_FWSTATS_FILE(isr, irqs, "%u");
123 
124 WL18XX_DEBUGFS_FWSTATS_FILE(pwr, missing_bcns_cnt, "%u");
125 WL18XX_DEBUGFS_FWSTATS_FILE(pwr, rcvd_bcns_cnt, "%u");
126 WL18XX_DEBUGFS_FWSTATS_FILE(pwr, connection_out_of_sync, "%u");
127 WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(pwr, cont_miss_bcns_spread,
128 				  PWR_STAT_MAX_CONT_MISSED_BCNS_SPREAD);
129 WL18XX_DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_bcns_cnt, "%u");
130 WL18XX_DEBUGFS_FWSTATS_FILE(pwr, sleep_time_count, "%u");
131 WL18XX_DEBUGFS_FWSTATS_FILE(pwr, sleep_time_avg, "%u");
132 WL18XX_DEBUGFS_FWSTATS_FILE(pwr, sleep_cycle_avg, "%u");
133 WL18XX_DEBUGFS_FWSTATS_FILE(pwr, sleep_percent, "%u");
134 WL18XX_DEBUGFS_FWSTATS_FILE(pwr, ap_sleep_active_conf, "%u");
135 WL18XX_DEBUGFS_FWSTATS_FILE(pwr, ap_sleep_user_conf, "%u");
136 WL18XX_DEBUGFS_FWSTATS_FILE(pwr, ap_sleep_counter, "%u");
137 
138 WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, beacon_filter, "%u");
139 WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, arp_filter, "%u");
140 WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, mc_filter, "%u");
141 WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, dup_filter, "%u");
142 WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, data_filter, "%u");
143 WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, ibss_filter, "%u");
144 WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, protection_filter, "%u");
145 WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, accum_arp_pend_requests, "%u");
146 WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, max_arp_queue_dep, "%u");
147 
148 WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(rx_rate, rx_frames_per_rates, 50);
149 
150 WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(aggr_size, tx_agg_rate,
151 				  AGGR_STATS_TX_AGG);
152 WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(aggr_size, tx_agg_len,
153 				  AGGR_STATS_TX_AGG);
154 WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(aggr_size, rx_size,
155 				  AGGR_STATS_RX_SIZE_LEN);
156 
157 WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, hs_tx_stat_fifo_int, "%u");
158 WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, enc_tx_stat_fifo_int, "%u");
159 WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, enc_rx_stat_fifo_int, "%u");
160 WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, rx_complete_stat_fifo_int, "%u");
161 WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, pre_proc_swi, "%u");
162 WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, post_proc_swi, "%u");
163 WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, sec_frag_swi, "%u");
164 WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, pre_to_defrag_swi, "%u");
165 WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, defrag_to_rx_xfer_swi, "%u");
166 WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, dec_packet_in, "%u");
167 WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, dec_packet_in_fifo_full, "%u");
168 WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, dec_packet_out, "%u");
169 
170 WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(pipeline, pipeline_fifo_full,
171 				  PIPE_STATS_HW_FIFO);
172 
173 WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(diversity, num_of_packets_per_ant,
174 				  DIVERSITY_STATS_NUM_OF_ANT);
175 WL18XX_DEBUGFS_FWSTATS_FILE(diversity, total_num_of_toggles, "%u");
176 
177 WL18XX_DEBUGFS_FWSTATS_FILE(thermal, irq_thr_low, "%u");
178 WL18XX_DEBUGFS_FWSTATS_FILE(thermal, irq_thr_high, "%u");
179 WL18XX_DEBUGFS_FWSTATS_FILE(thermal, tx_stop, "%u");
180 WL18XX_DEBUGFS_FWSTATS_FILE(thermal, tx_resume, "%u");
181 WL18XX_DEBUGFS_FWSTATS_FILE(thermal, false_irq, "%u");
182 WL18XX_DEBUGFS_FWSTATS_FILE(thermal, adc_source_unexpected, "%u");
183 
184 WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(calib, fail_count,
185 				  WL18XX_NUM_OF_CALIBRATIONS_ERRORS);
186 WL18XX_DEBUGFS_FWSTATS_FILE(calib, calib_count, "%u");
187 
188 WL18XX_DEBUGFS_FWSTATS_FILE(roaming, rssi_level, "%d");
189 
190 WL18XX_DEBUGFS_FWSTATS_FILE(dfs, num_of_radar_detections, "%d");
191 
192 static ssize_t conf_read(struct file *file, char __user *user_buf,
193 			 size_t count, loff_t *ppos)
194 {
195 	struct wl1271 *wl = file->private_data;
196 	struct wl18xx_priv *priv = wl->priv;
197 	struct wlcore_conf_header header;
198 	char *buf, *pos;
199 	size_t len;
200 	int ret;
201 
202 	len = WL18XX_CONF_SIZE;
203 	buf = kmalloc(len, GFP_KERNEL);
204 	if (!buf)
205 		return -ENOMEM;
206 
207 	header.magic	= cpu_to_le32(WL18XX_CONF_MAGIC);
208 	header.version	= cpu_to_le32(WL18XX_CONF_VERSION);
209 	header.checksum	= 0;
210 
211 	mutex_lock(&wl->mutex);
212 
213 	pos = buf;
214 	memcpy(pos, &header, sizeof(header));
215 	pos += sizeof(header);
216 	memcpy(pos, &wl->conf, sizeof(wl->conf));
217 	pos += sizeof(wl->conf);
218 	memcpy(pos, &priv->conf, sizeof(priv->conf));
219 
220 	mutex_unlock(&wl->mutex);
221 
222 	ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
223 
224 	kfree(buf);
225 	return ret;
226 }
227 
228 static const struct file_operations conf_ops = {
229 	.read = conf_read,
230 	.open = simple_open,
231 	.llseek = default_llseek,
232 };
233 
234 static ssize_t clear_fw_stats_write(struct file *file,
235 			      const char __user *user_buf,
236 			      size_t count, loff_t *ppos)
237 {
238 	struct wl1271 *wl = file->private_data;
239 	int ret;
240 
241 	mutex_lock(&wl->mutex);
242 
243 	if (unlikely(wl->state != WLCORE_STATE_ON))
244 		goto out;
245 
246 	ret = wl18xx_acx_clear_statistics(wl);
247 	if (ret < 0) {
248 		count = ret;
249 		goto out;
250 	}
251 out:
252 	mutex_unlock(&wl->mutex);
253 	return count;
254 }
255 
256 static const struct file_operations clear_fw_stats_ops = {
257 	.write = clear_fw_stats_write,
258 	.open = simple_open,
259 	.llseek = default_llseek,
260 };
261 
262 static ssize_t radar_detection_write(struct file *file,
263 				     const char __user *user_buf,
264 				     size_t count, loff_t *ppos)
265 {
266 	struct wl1271 *wl = file->private_data;
267 	int ret;
268 	u8 channel;
269 
270 	ret = kstrtou8_from_user(user_buf, count, 10, &channel);
271 	if (ret < 0) {
272 		wl1271_warning("illegal channel");
273 		return -EINVAL;
274 	}
275 
276 	mutex_lock(&wl->mutex);
277 
278 	if (unlikely(wl->state != WLCORE_STATE_ON))
279 		goto out;
280 
281 	ret = pm_runtime_get_sync(wl->dev);
282 	if (ret < 0) {
283 		pm_runtime_put_noidle(wl->dev);
284 		goto out;
285 	}
286 
287 	ret = wl18xx_cmd_radar_detection_debug(wl, channel);
288 	if (ret < 0)
289 		count = ret;
290 
291 	pm_runtime_mark_last_busy(wl->dev);
292 	pm_runtime_put_autosuspend(wl->dev);
293 out:
294 	mutex_unlock(&wl->mutex);
295 	return count;
296 }
297 
298 static const struct file_operations radar_detection_ops = {
299 	.write = radar_detection_write,
300 	.open = simple_open,
301 	.llseek = default_llseek,
302 };
303 
304 static ssize_t dynamic_fw_traces_write(struct file *file,
305 					const char __user *user_buf,
306 					size_t count, loff_t *ppos)
307 {
308 	struct wl1271 *wl = file->private_data;
309 	unsigned long value;
310 	int ret;
311 
312 	ret = kstrtoul_from_user(user_buf, count, 0, &value);
313 	if (ret < 0)
314 		return ret;
315 
316 	mutex_lock(&wl->mutex);
317 
318 	wl->dynamic_fw_traces = value;
319 
320 	if (unlikely(wl->state != WLCORE_STATE_ON))
321 		goto out;
322 
323 	ret = pm_runtime_get_sync(wl->dev);
324 	if (ret < 0) {
325 		pm_runtime_put_noidle(wl->dev);
326 		goto out;
327 	}
328 
329 	ret = wl18xx_acx_dynamic_fw_traces(wl);
330 	if (ret < 0)
331 		count = ret;
332 
333 	pm_runtime_mark_last_busy(wl->dev);
334 	pm_runtime_put_autosuspend(wl->dev);
335 out:
336 	mutex_unlock(&wl->mutex);
337 	return count;
338 }
339 
340 static ssize_t dynamic_fw_traces_read(struct file *file,
341 					char __user *userbuf,
342 					size_t count, loff_t *ppos)
343 {
344 	struct wl1271 *wl = file->private_data;
345 	return wl1271_format_buffer(userbuf, count, ppos,
346 				    "%d\n", wl->dynamic_fw_traces);
347 }
348 
349 static const struct file_operations dynamic_fw_traces_ops = {
350 	.read = dynamic_fw_traces_read,
351 	.write = dynamic_fw_traces_write,
352 	.open = simple_open,
353 	.llseek = default_llseek,
354 };
355 
356 #ifdef CONFIG_CFG80211_CERTIFICATION_ONUS
357 static ssize_t radar_debug_mode_write(struct file *file,
358 				      const char __user *user_buf,
359 				      size_t count, loff_t *ppos)
360 {
361 	struct wl1271 *wl = file->private_data;
362 	struct wl12xx_vif *wlvif;
363 	unsigned long value;
364 	int ret;
365 
366 	ret = kstrtoul_from_user(user_buf, count, 10, &value);
367 	if (ret < 0) {
368 		wl1271_warning("illegal radar_debug_mode value!");
369 		return -EINVAL;
370 	}
371 
372 	/* valid values: 0/1 */
373 	if (!(value == 0 || value == 1)) {
374 		wl1271_warning("value is not in valid!");
375 		return -EINVAL;
376 	}
377 
378 	mutex_lock(&wl->mutex);
379 
380 	wl->radar_debug_mode = value;
381 
382 	if (unlikely(wl->state != WLCORE_STATE_ON))
383 		goto out;
384 
385 	ret = pm_runtime_get_sync(wl->dev);
386 	if (ret < 0) {
387 		pm_runtime_put_noidle(wl->dev);
388 		goto out;
389 	}
390 
391 	wl12xx_for_each_wlvif_ap(wl, wlvif) {
392 		wlcore_cmd_generic_cfg(wl, wlvif,
393 				       WLCORE_CFG_FEATURE_RADAR_DEBUG,
394 				       wl->radar_debug_mode, 0);
395 	}
396 
397 	pm_runtime_mark_last_busy(wl->dev);
398 	pm_runtime_put_autosuspend(wl->dev);
399 out:
400 	mutex_unlock(&wl->mutex);
401 	return count;
402 }
403 
404 static ssize_t radar_debug_mode_read(struct file *file,
405 				     char __user *userbuf,
406 				     size_t count, loff_t *ppos)
407 {
408 	struct wl1271 *wl = file->private_data;
409 
410 	return wl1271_format_buffer(userbuf, count, ppos,
411 				    "%d\n", wl->radar_debug_mode);
412 }
413 
414 static const struct file_operations radar_debug_mode_ops = {
415 	.write = radar_debug_mode_write,
416 	.read = radar_debug_mode_read,
417 	.open = simple_open,
418 	.llseek = default_llseek,
419 };
420 #endif /* CFG80211_CERTIFICATION_ONUS */
421 
422 int wl18xx_debugfs_add_files(struct wl1271 *wl,
423 			     struct dentry *rootdir)
424 {
425 	int ret = 0;
426 	struct dentry *entry, *stats, *moddir;
427 
428 	moddir = debugfs_create_dir(KBUILD_MODNAME, rootdir);
429 	if (!moddir || IS_ERR(moddir)) {
430 		entry = moddir;
431 		goto err;
432 	}
433 
434 	stats = debugfs_create_dir("fw_stats", moddir);
435 	if (!stats || IS_ERR(stats)) {
436 		entry = stats;
437 		goto err;
438 	}
439 
440 	DEBUGFS_ADD(clear_fw_stats, stats);
441 
442 	DEBUGFS_FWSTATS_ADD(error, error_frame_non_ctrl);
443 	DEBUGFS_FWSTATS_ADD(error, error_frame_ctrl);
444 	DEBUGFS_FWSTATS_ADD(error, error_frame_during_protection);
445 	DEBUGFS_FWSTATS_ADD(error, null_frame_tx_start);
446 	DEBUGFS_FWSTATS_ADD(error, null_frame_cts_start);
447 	DEBUGFS_FWSTATS_ADD(error, bar_retry);
448 	DEBUGFS_FWSTATS_ADD(error, num_frame_cts_nul_flid);
449 	DEBUGFS_FWSTATS_ADD(error, tx_abort_failure);
450 	DEBUGFS_FWSTATS_ADD(error, tx_resume_failure);
451 	DEBUGFS_FWSTATS_ADD(error, rx_cmplt_db_overflow_cnt);
452 	DEBUGFS_FWSTATS_ADD(error, elp_while_rx_exch);
453 	DEBUGFS_FWSTATS_ADD(error, elp_while_tx_exch);
454 	DEBUGFS_FWSTATS_ADD(error, elp_while_tx);
455 	DEBUGFS_FWSTATS_ADD(error, elp_while_nvic_pending);
456 	DEBUGFS_FWSTATS_ADD(error, rx_excessive_frame_len);
457 	DEBUGFS_FWSTATS_ADD(error, burst_mismatch);
458 	DEBUGFS_FWSTATS_ADD(error, tbc_exch_mismatch);
459 
460 	DEBUGFS_FWSTATS_ADD(tx, tx_prepared_descs);
461 	DEBUGFS_FWSTATS_ADD(tx, tx_cmplt);
462 	DEBUGFS_FWSTATS_ADD(tx, tx_template_prepared);
463 	DEBUGFS_FWSTATS_ADD(tx, tx_data_prepared);
464 	DEBUGFS_FWSTATS_ADD(tx, tx_template_programmed);
465 	DEBUGFS_FWSTATS_ADD(tx, tx_data_programmed);
466 	DEBUGFS_FWSTATS_ADD(tx, tx_burst_programmed);
467 	DEBUGFS_FWSTATS_ADD(tx, tx_starts);
468 	DEBUGFS_FWSTATS_ADD(tx, tx_stop);
469 	DEBUGFS_FWSTATS_ADD(tx, tx_start_templates);
470 	DEBUGFS_FWSTATS_ADD(tx, tx_start_int_templates);
471 	DEBUGFS_FWSTATS_ADD(tx, tx_start_fw_gen);
472 	DEBUGFS_FWSTATS_ADD(tx, tx_start_data);
473 	DEBUGFS_FWSTATS_ADD(tx, tx_start_null_frame);
474 	DEBUGFS_FWSTATS_ADD(tx, tx_exch);
475 	DEBUGFS_FWSTATS_ADD(tx, tx_retry_template);
476 	DEBUGFS_FWSTATS_ADD(tx, tx_retry_data);
477 	DEBUGFS_FWSTATS_ADD(tx, tx_retry_per_rate);
478 	DEBUGFS_FWSTATS_ADD(tx, tx_exch_pending);
479 	DEBUGFS_FWSTATS_ADD(tx, tx_exch_expiry);
480 	DEBUGFS_FWSTATS_ADD(tx, tx_done_template);
481 	DEBUGFS_FWSTATS_ADD(tx, tx_done_data);
482 	DEBUGFS_FWSTATS_ADD(tx, tx_done_int_template);
483 	DEBUGFS_FWSTATS_ADD(tx, tx_cfe1);
484 	DEBUGFS_FWSTATS_ADD(tx, tx_cfe2);
485 	DEBUGFS_FWSTATS_ADD(tx, frag_called);
486 	DEBUGFS_FWSTATS_ADD(tx, frag_mpdu_alloc_failed);
487 	DEBUGFS_FWSTATS_ADD(tx, frag_init_called);
488 	DEBUGFS_FWSTATS_ADD(tx, frag_in_process_called);
489 	DEBUGFS_FWSTATS_ADD(tx, frag_tkip_called);
490 	DEBUGFS_FWSTATS_ADD(tx, frag_key_not_found);
491 	DEBUGFS_FWSTATS_ADD(tx, frag_need_fragmentation);
492 	DEBUGFS_FWSTATS_ADD(tx, frag_bad_mblk_num);
493 	DEBUGFS_FWSTATS_ADD(tx, frag_failed);
494 	DEBUGFS_FWSTATS_ADD(tx, frag_cache_hit);
495 	DEBUGFS_FWSTATS_ADD(tx, frag_cache_miss);
496 
497 	DEBUGFS_FWSTATS_ADD(rx, rx_beacon_early_term);
498 	DEBUGFS_FWSTATS_ADD(rx, rx_out_of_mpdu_nodes);
499 	DEBUGFS_FWSTATS_ADD(rx, rx_hdr_overflow);
500 	DEBUGFS_FWSTATS_ADD(rx, rx_dropped_frame);
501 	DEBUGFS_FWSTATS_ADD(rx, rx_done);
502 	DEBUGFS_FWSTATS_ADD(rx, rx_defrag);
503 	DEBUGFS_FWSTATS_ADD(rx, rx_defrag_end);
504 	DEBUGFS_FWSTATS_ADD(rx, rx_cmplt);
505 	DEBUGFS_FWSTATS_ADD(rx, rx_pre_complt);
506 	DEBUGFS_FWSTATS_ADD(rx, rx_cmplt_task);
507 	DEBUGFS_FWSTATS_ADD(rx, rx_phy_hdr);
508 	DEBUGFS_FWSTATS_ADD(rx, rx_timeout);
509 	DEBUGFS_FWSTATS_ADD(rx, rx_rts_timeout);
510 	DEBUGFS_FWSTATS_ADD(rx, rx_timeout_wa);
511 	DEBUGFS_FWSTATS_ADD(rx, defrag_called);
512 	DEBUGFS_FWSTATS_ADD(rx, defrag_init_called);
513 	DEBUGFS_FWSTATS_ADD(rx, defrag_in_process_called);
514 	DEBUGFS_FWSTATS_ADD(rx, defrag_tkip_called);
515 	DEBUGFS_FWSTATS_ADD(rx, defrag_need_defrag);
516 	DEBUGFS_FWSTATS_ADD(rx, defrag_decrypt_failed);
517 	DEBUGFS_FWSTATS_ADD(rx, decrypt_key_not_found);
518 	DEBUGFS_FWSTATS_ADD(rx, defrag_need_decrypt);
519 	DEBUGFS_FWSTATS_ADD(rx, rx_tkip_replays);
520 	DEBUGFS_FWSTATS_ADD(rx, rx_xfr);
521 
522 	DEBUGFS_FWSTATS_ADD(isr, irqs);
523 
524 	DEBUGFS_FWSTATS_ADD(pwr, missing_bcns_cnt);
525 	DEBUGFS_FWSTATS_ADD(pwr, rcvd_bcns_cnt);
526 	DEBUGFS_FWSTATS_ADD(pwr, connection_out_of_sync);
527 	DEBUGFS_FWSTATS_ADD(pwr, cont_miss_bcns_spread);
528 	DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_bcns_cnt);
529 	DEBUGFS_FWSTATS_ADD(pwr, sleep_time_count);
530 	DEBUGFS_FWSTATS_ADD(pwr, sleep_time_avg);
531 	DEBUGFS_FWSTATS_ADD(pwr, sleep_cycle_avg);
532 	DEBUGFS_FWSTATS_ADD(pwr, sleep_percent);
533 	DEBUGFS_FWSTATS_ADD(pwr, ap_sleep_active_conf);
534 	DEBUGFS_FWSTATS_ADD(pwr, ap_sleep_user_conf);
535 	DEBUGFS_FWSTATS_ADD(pwr, ap_sleep_counter);
536 
537 	DEBUGFS_FWSTATS_ADD(rx_filter, beacon_filter);
538 	DEBUGFS_FWSTATS_ADD(rx_filter, arp_filter);
539 	DEBUGFS_FWSTATS_ADD(rx_filter, mc_filter);
540 	DEBUGFS_FWSTATS_ADD(rx_filter, dup_filter);
541 	DEBUGFS_FWSTATS_ADD(rx_filter, data_filter);
542 	DEBUGFS_FWSTATS_ADD(rx_filter, ibss_filter);
543 	DEBUGFS_FWSTATS_ADD(rx_filter, protection_filter);
544 	DEBUGFS_FWSTATS_ADD(rx_filter, accum_arp_pend_requests);
545 	DEBUGFS_FWSTATS_ADD(rx_filter, max_arp_queue_dep);
546 
547 	DEBUGFS_FWSTATS_ADD(rx_rate, rx_frames_per_rates);
548 
549 	DEBUGFS_FWSTATS_ADD(aggr_size, tx_agg_rate);
550 	DEBUGFS_FWSTATS_ADD(aggr_size, tx_agg_len);
551 	DEBUGFS_FWSTATS_ADD(aggr_size, rx_size);
552 
553 	DEBUGFS_FWSTATS_ADD(pipeline, hs_tx_stat_fifo_int);
554 	DEBUGFS_FWSTATS_ADD(pipeline, enc_tx_stat_fifo_int);
555 	DEBUGFS_FWSTATS_ADD(pipeline, enc_rx_stat_fifo_int);
556 	DEBUGFS_FWSTATS_ADD(pipeline, rx_complete_stat_fifo_int);
557 	DEBUGFS_FWSTATS_ADD(pipeline, pre_proc_swi);
558 	DEBUGFS_FWSTATS_ADD(pipeline, post_proc_swi);
559 	DEBUGFS_FWSTATS_ADD(pipeline, sec_frag_swi);
560 	DEBUGFS_FWSTATS_ADD(pipeline, pre_to_defrag_swi);
561 	DEBUGFS_FWSTATS_ADD(pipeline, defrag_to_rx_xfer_swi);
562 	DEBUGFS_FWSTATS_ADD(pipeline, dec_packet_in);
563 	DEBUGFS_FWSTATS_ADD(pipeline, dec_packet_in_fifo_full);
564 	DEBUGFS_FWSTATS_ADD(pipeline, dec_packet_out);
565 	DEBUGFS_FWSTATS_ADD(pipeline, pipeline_fifo_full);
566 
567 	DEBUGFS_FWSTATS_ADD(diversity, num_of_packets_per_ant);
568 	DEBUGFS_FWSTATS_ADD(diversity, total_num_of_toggles);
569 
570 	DEBUGFS_FWSTATS_ADD(thermal, irq_thr_low);
571 	DEBUGFS_FWSTATS_ADD(thermal, irq_thr_high);
572 	DEBUGFS_FWSTATS_ADD(thermal, tx_stop);
573 	DEBUGFS_FWSTATS_ADD(thermal, tx_resume);
574 	DEBUGFS_FWSTATS_ADD(thermal, false_irq);
575 	DEBUGFS_FWSTATS_ADD(thermal, adc_source_unexpected);
576 
577 	DEBUGFS_FWSTATS_ADD(calib, fail_count);
578 
579 	DEBUGFS_FWSTATS_ADD(calib, calib_count);
580 
581 	DEBUGFS_FWSTATS_ADD(roaming, rssi_level);
582 
583 	DEBUGFS_FWSTATS_ADD(dfs, num_of_radar_detections);
584 
585 	DEBUGFS_ADD(conf, moddir);
586 	DEBUGFS_ADD(radar_detection, moddir);
587 #ifdef CONFIG_CFG80211_CERTIFICATION_ONUS
588 	DEBUGFS_ADD(radar_debug_mode, moddir);
589 #endif
590 	DEBUGFS_ADD(dynamic_fw_traces, moddir);
591 
592 	return 0;
593 
594 err:
595 	if (IS_ERR(entry))
596 		ret = PTR_ERR(entry);
597 	else
598 		ret = -ENOMEM;
599 
600 	return ret;
601 }
602