162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * This file is part of wl1251
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2009 Nokia Corporation
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include "debugfs.h"
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/skbuff.h>
1162306a36Sopenharmony_ci#include <linux/slab.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include "wl1251.h"
1462306a36Sopenharmony_ci#include "acx.h"
1562306a36Sopenharmony_ci#include "ps.h"
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci/* ms */
1862306a36Sopenharmony_ci#define WL1251_DEBUGFS_STATS_LIFETIME 1000
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/* debugfs macros idea from mac80211 */
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...)		\
2362306a36Sopenharmony_cistatic ssize_t name## _read(struct file *file, char __user *userbuf,	\
2462306a36Sopenharmony_ci			    size_t count, loff_t *ppos)			\
2562306a36Sopenharmony_ci{									\
2662306a36Sopenharmony_ci	struct wl1251 *wl = file->private_data;				\
2762306a36Sopenharmony_ci	char buf[buflen];						\
2862306a36Sopenharmony_ci	int res;							\
2962306a36Sopenharmony_ci									\
3062306a36Sopenharmony_ci	res = scnprintf(buf, buflen, fmt "\n", ##value);		\
3162306a36Sopenharmony_ci	return simple_read_from_buffer(userbuf, count, ppos, buf, res);	\
3262306a36Sopenharmony_ci}									\
3362306a36Sopenharmony_ci									\
3462306a36Sopenharmony_cistatic const struct file_operations name## _ops = {			\
3562306a36Sopenharmony_ci	.read = name## _read,						\
3662306a36Sopenharmony_ci	.open = simple_open,						\
3762306a36Sopenharmony_ci	.llseek	= generic_file_llseek,					\
3862306a36Sopenharmony_ci};
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci#define DEBUGFS_ADD(name, parent)					\
4162306a36Sopenharmony_ci	wl->debugfs.name = debugfs_create_file(#name, 0400, parent,	\
4262306a36Sopenharmony_ci					       wl, &name## _ops)	\
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci#define DEBUGFS_DEL(name)						\
4562306a36Sopenharmony_ci	do {								\
4662306a36Sopenharmony_ci		debugfs_remove(wl->debugfs.name);			\
4762306a36Sopenharmony_ci		wl->debugfs.name = NULL;				\
4862306a36Sopenharmony_ci	} while (0)
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci#define DEBUGFS_FWSTATS_FILE(sub, name, buflen, fmt)			\
5162306a36Sopenharmony_cistatic ssize_t sub## _ ##name## _read(struct file *file,		\
5262306a36Sopenharmony_ci				      char __user *userbuf,		\
5362306a36Sopenharmony_ci				      size_t count, loff_t *ppos)	\
5462306a36Sopenharmony_ci{									\
5562306a36Sopenharmony_ci	struct wl1251 *wl = file->private_data;				\
5662306a36Sopenharmony_ci	char buf[buflen];						\
5762306a36Sopenharmony_ci	int res;							\
5862306a36Sopenharmony_ci									\
5962306a36Sopenharmony_ci	wl1251_debugfs_update_stats(wl);				\
6062306a36Sopenharmony_ci									\
6162306a36Sopenharmony_ci	res = scnprintf(buf, buflen, fmt "\n",				\
6262306a36Sopenharmony_ci			wl->stats.fw_stats->sub.name);			\
6362306a36Sopenharmony_ci	return simple_read_from_buffer(userbuf, count, ppos, buf, res);	\
6462306a36Sopenharmony_ci}									\
6562306a36Sopenharmony_ci									\
6662306a36Sopenharmony_cistatic const struct file_operations sub## _ ##name## _ops = {		\
6762306a36Sopenharmony_ci	.read = sub## _ ##name## _read,					\
6862306a36Sopenharmony_ci	.open = simple_open,						\
6962306a36Sopenharmony_ci	.llseek	= generic_file_llseek,					\
7062306a36Sopenharmony_ci};
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci#define DEBUGFS_FWSTATS_ADD(sub, name)				\
7362306a36Sopenharmony_ci	DEBUGFS_ADD(sub## _ ##name, wl->debugfs.fw_statistics)
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci#define DEBUGFS_FWSTATS_DEL(sub, name)				\
7662306a36Sopenharmony_ci	DEBUGFS_DEL(sub## _ ##name)
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_cistatic void wl1251_debugfs_update_stats(struct wl1251 *wl)
7962306a36Sopenharmony_ci{
8062306a36Sopenharmony_ci	int ret;
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci	mutex_lock(&wl->mutex);
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci	ret = wl1251_ps_elp_wakeup(wl);
8562306a36Sopenharmony_ci	if (ret < 0)
8662306a36Sopenharmony_ci		goto out;
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci	if (wl->state == WL1251_STATE_ON &&
8962306a36Sopenharmony_ci	    time_after(jiffies, wl->stats.fw_stats_update +
9062306a36Sopenharmony_ci		       msecs_to_jiffies(WL1251_DEBUGFS_STATS_LIFETIME))) {
9162306a36Sopenharmony_ci		wl1251_acx_statistics(wl, wl->stats.fw_stats);
9262306a36Sopenharmony_ci		wl->stats.fw_stats_update = jiffies;
9362306a36Sopenharmony_ci	}
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci	wl1251_ps_elp_sleep(wl);
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ciout:
9862306a36Sopenharmony_ci	mutex_unlock(&wl->mutex);
9962306a36Sopenharmony_ci}
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, 20, "%u");
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(rx, out_of_mem, 20, "%u");
10462306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(rx, hdr_overflow, 20, "%u");
10562306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(rx, hw_stuck, 20, "%u");
10662306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(rx, dropped, 20, "%u");
10762306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(rx, fcs_err, 20, "%u");
10862306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, 20, "%u");
10962306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(rx, path_reset, 20, "%u");
11062306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(rx, reset_counter, 20, "%u");
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(dma, rx_requested, 20, "%u");
11362306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(dma, rx_errors, 20, "%u");
11462306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(dma, tx_requested, 20, "%u");
11562306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(dma, tx_errors, 20, "%u");
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, 20, "%u");
11862306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, fiqs, 20, "%u");
11962306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, rx_headers, 20, "%u");
12062306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, 20, "%u");
12162306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, rx_rdys, 20, "%u");
12262306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, irqs, 20, "%u");
12362306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, tx_procs, 20, "%u");
12462306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, decrypt_done, 20, "%u");
12562306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, dma0_done, 20, "%u");
12662306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, dma1_done, 20, "%u");
12762306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, 20, "%u");
12862306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, commands, 20, "%u");
12962306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, rx_procs, 20, "%u");
13062306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, 20, "%u");
13162306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, host_acknowledges, 20, "%u");
13262306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, pci_pm, 20, "%u");
13362306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, wakeups, 20, "%u");
13462306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(isr, low_rssi, 20, "%u");
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(wep, addr_key_count, 20, "%u");
13762306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(wep, default_key_count, 20, "%u");
13862306a36Sopenharmony_ci/* skipping wep.reserved */
13962306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(wep, key_not_found, 20, "%u");
14062306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(wep, decrypt_fail, 20, "%u");
14162306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(wep, packets, 20, "%u");
14262306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(wep, interrupt, 20, "%u");
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(pwr, ps_enter, 20, "%u");
14562306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(pwr, elp_enter, 20, "%u");
14662306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(pwr, missing_bcns, 20, "%u");
14762306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(pwr, wake_on_host, 20, "%u");
14862306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, 20, "%u");
14962306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, 20, "%u");
15062306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, 20, "%u");
15162306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, 20, "%u");
15262306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(pwr, power_save_off, 20, "%u");
15362306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(pwr, enable_ps, 20, "%u");
15462306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(pwr, disable_ps, 20, "%u");
15562306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, 20, "%u");
15662306a36Sopenharmony_ci/* skipping cont_miss_bcns_spread for now */
15762306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, 20, "%u");
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(mic, rx_pkts, 20, "%u");
16062306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(mic, calc_failure, 20, "%u");
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(aes, encrypt_fail, 20, "%u");
16362306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(aes, decrypt_fail, 20, "%u");
16462306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(aes, encrypt_packets, 20, "%u");
16562306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(aes, decrypt_packets, 20, "%u");
16662306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, 20, "%u");
16762306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, 20, "%u");
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(event, heart_beat, 20, "%u");
17062306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(event, calibration, 20, "%u");
17162306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(event, rx_mismatch, 20, "%u");
17262306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(event, rx_mem_empty, 20, "%u");
17362306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(event, rx_pool, 20, "%u");
17462306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(event, oom_late, 20, "%u");
17562306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(event, phy_transmit_error, 20, "%u");
17662306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(event, tx_stuck, 20, "%u");
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, 20, "%u");
17962306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, 20, "%u");
18062306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, 20, "%u");
18162306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, 20, "%u");
18262306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, 20, "%u");
18362306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, 20, "%u");
18462306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(ps, upsd_utilization, 20, "%u");
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, 20, "%u");
18762306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, 20, "%u");
18862306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data,
18962306a36Sopenharmony_ci		     20, "%u");
19062306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, 20, "%u");
19162306a36Sopenharmony_ciDEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, 20, "%u");
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ciDEBUGFS_READONLY_FILE(retry_count, 20, "%u", wl->stats.retry_count);
19462306a36Sopenharmony_ciDEBUGFS_READONLY_FILE(excessive_retries, 20, "%u",
19562306a36Sopenharmony_ci		      wl->stats.excessive_retries);
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_cistatic ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
19862306a36Sopenharmony_ci				 size_t count, loff_t *ppos)
19962306a36Sopenharmony_ci{
20062306a36Sopenharmony_ci	struct wl1251 *wl = file->private_data;
20162306a36Sopenharmony_ci	u32 queue_len;
20262306a36Sopenharmony_ci	char buf[20];
20362306a36Sopenharmony_ci	int res;
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci	queue_len = skb_queue_len(&wl->tx_queue);
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_ci	res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
20862306a36Sopenharmony_ci	return simple_read_from_buffer(userbuf, count, ppos, buf, res);
20962306a36Sopenharmony_ci}
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_cistatic const struct file_operations tx_queue_len_ops = {
21262306a36Sopenharmony_ci	.read = tx_queue_len_read,
21362306a36Sopenharmony_ci	.open = simple_open,
21462306a36Sopenharmony_ci	.llseek = generic_file_llseek,
21562306a36Sopenharmony_ci};
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_cistatic ssize_t tx_queue_status_read(struct file *file, char __user *userbuf,
21862306a36Sopenharmony_ci				    size_t count, loff_t *ppos)
21962306a36Sopenharmony_ci{
22062306a36Sopenharmony_ci	struct wl1251 *wl = file->private_data;
22162306a36Sopenharmony_ci	char buf[3], status;
22262306a36Sopenharmony_ci	int len;
22362306a36Sopenharmony_ci
22462306a36Sopenharmony_ci	if (wl->tx_queue_stopped)
22562306a36Sopenharmony_ci		status = 's';
22662306a36Sopenharmony_ci	else
22762306a36Sopenharmony_ci		status = 'r';
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci	len = scnprintf(buf, sizeof(buf), "%c\n", status);
23062306a36Sopenharmony_ci	return simple_read_from_buffer(userbuf, count, ppos, buf, len);
23162306a36Sopenharmony_ci}
23262306a36Sopenharmony_ci
23362306a36Sopenharmony_cistatic const struct file_operations tx_queue_status_ops = {
23462306a36Sopenharmony_ci	.read = tx_queue_status_read,
23562306a36Sopenharmony_ci	.open = simple_open,
23662306a36Sopenharmony_ci	.llseek = generic_file_llseek,
23762306a36Sopenharmony_ci};
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_cistatic void wl1251_debugfs_delete_files(struct wl1251 *wl)
24062306a36Sopenharmony_ci{
24162306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(tx, internal_desc_overflow);
24262306a36Sopenharmony_ci
24362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(rx, out_of_mem);
24462306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(rx, hdr_overflow);
24562306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(rx, hw_stuck);
24662306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(rx, dropped);
24762306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(rx, fcs_err);
24862306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(rx, xfr_hint_trig);
24962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(rx, path_reset);
25062306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(rx, reset_counter);
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(dma, rx_requested);
25362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(dma, rx_errors);
25462306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(dma, tx_requested);
25562306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(dma, tx_errors);
25662306a36Sopenharmony_ci
25762306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, cmd_cmplt);
25862306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, fiqs);
25962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, rx_headers);
26062306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, rx_mem_overflow);
26162306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, rx_rdys);
26262306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, irqs);
26362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, tx_procs);
26462306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, decrypt_done);
26562306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, dma0_done);
26662306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, dma1_done);
26762306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, tx_exch_complete);
26862306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, commands);
26962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, rx_procs);
27062306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, hw_pm_mode_changes);
27162306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, host_acknowledges);
27262306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, pci_pm);
27362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, wakeups);
27462306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(isr, low_rssi);
27562306a36Sopenharmony_ci
27662306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(wep, addr_key_count);
27762306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(wep, default_key_count);
27862306a36Sopenharmony_ci	/* skipping wep.reserved */
27962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(wep, key_not_found);
28062306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(wep, decrypt_fail);
28162306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(wep, packets);
28262306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(wep, interrupt);
28362306a36Sopenharmony_ci
28462306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(pwr, ps_enter);
28562306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(pwr, elp_enter);
28662306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(pwr, missing_bcns);
28762306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(pwr, wake_on_host);
28862306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(pwr, wake_on_timer_exp);
28962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(pwr, tx_with_ps);
29062306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(pwr, tx_without_ps);
29162306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(pwr, rcvd_beacons);
29262306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(pwr, power_save_off);
29362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(pwr, enable_ps);
29462306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(pwr, disable_ps);
29562306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(pwr, fix_tsf_ps);
29662306a36Sopenharmony_ci	/* skipping cont_miss_bcns_spread for now */
29762306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(pwr, rcvd_awake_beacons);
29862306a36Sopenharmony_ci
29962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(mic, rx_pkts);
30062306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(mic, calc_failure);
30162306a36Sopenharmony_ci
30262306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(aes, encrypt_fail);
30362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(aes, decrypt_fail);
30462306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(aes, encrypt_packets);
30562306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(aes, decrypt_packets);
30662306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(aes, encrypt_interrupt);
30762306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(aes, decrypt_interrupt);
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(event, heart_beat);
31062306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(event, calibration);
31162306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(event, rx_mismatch);
31262306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(event, rx_mem_empty);
31362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(event, rx_pool);
31462306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(event, oom_late);
31562306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(event, phy_transmit_error);
31662306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(event, tx_stuck);
31762306a36Sopenharmony_ci
31862306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(ps, pspoll_timeouts);
31962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(ps, upsd_timeouts);
32062306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(ps, upsd_max_sptime);
32162306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(ps, upsd_max_apturn);
32262306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(ps, pspoll_max_apturn);
32362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(ps, pspoll_utilization);
32462306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(ps, upsd_utilization);
32562306a36Sopenharmony_ci
32662306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(rxpipe, rx_prep_beacon_drop);
32762306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(rxpipe, descr_host_int_trig_rx_data);
32862306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
32962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(rxpipe, missed_beacon_host_int_trig_rx_data);
33062306a36Sopenharmony_ci	DEBUGFS_FWSTATS_DEL(rxpipe, tx_xfr_host_int_trig_rx_data);
33162306a36Sopenharmony_ci
33262306a36Sopenharmony_ci	DEBUGFS_DEL(tx_queue_len);
33362306a36Sopenharmony_ci	DEBUGFS_DEL(tx_queue_status);
33462306a36Sopenharmony_ci	DEBUGFS_DEL(retry_count);
33562306a36Sopenharmony_ci	DEBUGFS_DEL(excessive_retries);
33662306a36Sopenharmony_ci}
33762306a36Sopenharmony_ci
33862306a36Sopenharmony_cistatic void wl1251_debugfs_add_files(struct wl1251 *wl)
33962306a36Sopenharmony_ci{
34062306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
34162306a36Sopenharmony_ci
34262306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
34362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
34462306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
34562306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(rx, dropped);
34662306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(rx, fcs_err);
34762306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
34862306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(rx, path_reset);
34962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(rx, reset_counter);
35062306a36Sopenharmony_ci
35162306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(dma, rx_requested);
35262306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(dma, rx_errors);
35362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(dma, tx_requested);
35462306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(dma, tx_errors);
35562306a36Sopenharmony_ci
35662306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
35762306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, fiqs);
35862306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, rx_headers);
35962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
36062306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
36162306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, irqs);
36262306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, tx_procs);
36362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
36462306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, dma0_done);
36562306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, dma1_done);
36662306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
36762306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, commands);
36862306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, rx_procs);
36962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
37062306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
37162306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, pci_pm);
37262306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, wakeups);
37362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(isr, low_rssi);
37462306a36Sopenharmony_ci
37562306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
37662306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(wep, default_key_count);
37762306a36Sopenharmony_ci	/* skipping wep.reserved */
37862306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(wep, key_not_found);
37962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
38062306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(wep, packets);
38162306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(wep, interrupt);
38262306a36Sopenharmony_ci
38362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
38462306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
38562306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
38662306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
38762306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
38862306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
38962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
39062306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
39162306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
39262306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
39362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
39462306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
39562306a36Sopenharmony_ci	/* skipping cont_miss_bcns_spread for now */
39662306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
39762306a36Sopenharmony_ci
39862306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
39962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(mic, calc_failure);
40062306a36Sopenharmony_ci
40162306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
40262306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
40362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
40462306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
40562306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
40662306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
40762306a36Sopenharmony_ci
40862306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(event, heart_beat);
40962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(event, calibration);
41062306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
41162306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
41262306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(event, rx_pool);
41362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(event, oom_late);
41462306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
41562306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(event, tx_stuck);
41662306a36Sopenharmony_ci
41762306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
41862306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
41962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
42062306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
42162306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
42262306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
42362306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
42462306a36Sopenharmony_ci
42562306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
42662306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
42762306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
42862306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
42962306a36Sopenharmony_ci	DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
43062306a36Sopenharmony_ci
43162306a36Sopenharmony_ci	DEBUGFS_ADD(tx_queue_len, wl->debugfs.rootdir);
43262306a36Sopenharmony_ci	DEBUGFS_ADD(tx_queue_status, wl->debugfs.rootdir);
43362306a36Sopenharmony_ci	DEBUGFS_ADD(retry_count, wl->debugfs.rootdir);
43462306a36Sopenharmony_ci	DEBUGFS_ADD(excessive_retries, wl->debugfs.rootdir);
43562306a36Sopenharmony_ci}
43662306a36Sopenharmony_ci
43762306a36Sopenharmony_civoid wl1251_debugfs_reset(struct wl1251 *wl)
43862306a36Sopenharmony_ci{
43962306a36Sopenharmony_ci	if (wl->stats.fw_stats != NULL)
44062306a36Sopenharmony_ci		memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
44162306a36Sopenharmony_ci	wl->stats.retry_count = 0;
44262306a36Sopenharmony_ci	wl->stats.excessive_retries = 0;
44362306a36Sopenharmony_ci}
44462306a36Sopenharmony_ci
44562306a36Sopenharmony_ciint wl1251_debugfs_init(struct wl1251 *wl)
44662306a36Sopenharmony_ci{
44762306a36Sopenharmony_ci	wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats), GFP_KERNEL);
44862306a36Sopenharmony_ci	if (!wl->stats.fw_stats)
44962306a36Sopenharmony_ci		return -ENOMEM;
45062306a36Sopenharmony_ci
45162306a36Sopenharmony_ci	wl->debugfs.rootdir = debugfs_create_dir(KBUILD_MODNAME, NULL);
45262306a36Sopenharmony_ci
45362306a36Sopenharmony_ci	wl->debugfs.fw_statistics = debugfs_create_dir("fw-statistics",
45462306a36Sopenharmony_ci						       wl->debugfs.rootdir);
45562306a36Sopenharmony_ci
45662306a36Sopenharmony_ci	wl->stats.fw_stats_update = jiffies;
45762306a36Sopenharmony_ci
45862306a36Sopenharmony_ci	wl1251_debugfs_add_files(wl);
45962306a36Sopenharmony_ci
46062306a36Sopenharmony_ci	return 0;
46162306a36Sopenharmony_ci}
46262306a36Sopenharmony_ci
46362306a36Sopenharmony_civoid wl1251_debugfs_exit(struct wl1251 *wl)
46462306a36Sopenharmony_ci{
46562306a36Sopenharmony_ci	wl1251_debugfs_delete_files(wl);
46662306a36Sopenharmony_ci
46762306a36Sopenharmony_ci	kfree(wl->stats.fw_stats);
46862306a36Sopenharmony_ci	wl->stats.fw_stats = NULL;
46962306a36Sopenharmony_ci
47062306a36Sopenharmony_ci	debugfs_remove(wl->debugfs.fw_statistics);
47162306a36Sopenharmony_ci	wl->debugfs.fw_statistics = NULL;
47262306a36Sopenharmony_ci
47362306a36Sopenharmony_ci	debugfs_remove(wl->debugfs.rootdir);
47462306a36Sopenharmony_ci	wl->debugfs.rootdir = NULL;
47562306a36Sopenharmony_ci
47662306a36Sopenharmony_ci}
477