162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/******************************************************************************
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Contact Information:
762306a36Sopenharmony_ci *  Intel Linux Wireless <ilw@linux.intel.com>
862306a36Sopenharmony_ci * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
962306a36Sopenharmony_ci *****************************************************************************/
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include "common.h"
1262306a36Sopenharmony_ci#include "3945.h"
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_cistatic int
1562306a36Sopenharmony_ciil3945_stats_flag(struct il_priv *il, char *buf, int bufsz)
1662306a36Sopenharmony_ci{
1762306a36Sopenharmony_ci	int p = 0;
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci	p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n",
2062306a36Sopenharmony_ci		       le32_to_cpu(il->_3945.stats.flag));
2162306a36Sopenharmony_ci	if (le32_to_cpu(il->_3945.stats.flag) & UCODE_STATS_CLEAR_MSK)
2262306a36Sopenharmony_ci		p += scnprintf(buf + p, bufsz - p,
2362306a36Sopenharmony_ci			       "\tStatistics have been cleared\n");
2462306a36Sopenharmony_ci	p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
2562306a36Sopenharmony_ci		       (le32_to_cpu(il->_3945.stats.flag) &
2662306a36Sopenharmony_ci			UCODE_STATS_FREQUENCY_MSK) ? "2.4 GHz" : "5.2 GHz");
2762306a36Sopenharmony_ci	p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
2862306a36Sopenharmony_ci		       (le32_to_cpu(il->_3945.stats.flag) &
2962306a36Sopenharmony_ci			UCODE_STATS_NARROW_BAND_MSK) ? "enabled" : "disabled");
3062306a36Sopenharmony_ci	return p;
3162306a36Sopenharmony_ci}
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_cistatic ssize_t
3462306a36Sopenharmony_ciil3945_ucode_rx_stats_read(struct file *file, char __user *user_buf,
3562306a36Sopenharmony_ci			   size_t count, loff_t *ppos)
3662306a36Sopenharmony_ci{
3762306a36Sopenharmony_ci	struct il_priv *il = file->private_data;
3862306a36Sopenharmony_ci	int pos = 0;
3962306a36Sopenharmony_ci	char *buf;
4062306a36Sopenharmony_ci	int bufsz =
4162306a36Sopenharmony_ci	    sizeof(struct iwl39_stats_rx_phy) * 40 +
4262306a36Sopenharmony_ci	    sizeof(struct iwl39_stats_rx_non_phy) * 40 + 400;
4362306a36Sopenharmony_ci	ssize_t ret;
4462306a36Sopenharmony_ci	struct iwl39_stats_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm;
4562306a36Sopenharmony_ci	struct iwl39_stats_rx_phy *cck, *accum_cck, *delta_cck, *max_cck;
4662306a36Sopenharmony_ci	struct iwl39_stats_rx_non_phy *general, *accum_general;
4762306a36Sopenharmony_ci	struct iwl39_stats_rx_non_phy *delta_general, *max_general;
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci	if (!il_is_alive(il))
5062306a36Sopenharmony_ci		return -EAGAIN;
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
5362306a36Sopenharmony_ci	if (!buf) {
5462306a36Sopenharmony_ci		IL_ERR("Can not allocate Buffer\n");
5562306a36Sopenharmony_ci		return -ENOMEM;
5662306a36Sopenharmony_ci	}
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci	/*
5962306a36Sopenharmony_ci	 * The statistic information display here is based on
6062306a36Sopenharmony_ci	 * the last stats notification from uCode
6162306a36Sopenharmony_ci	 * might not reflect the current uCode activity
6262306a36Sopenharmony_ci	 */
6362306a36Sopenharmony_ci	ofdm = &il->_3945.stats.rx.ofdm;
6462306a36Sopenharmony_ci	cck = &il->_3945.stats.rx.cck;
6562306a36Sopenharmony_ci	general = &il->_3945.stats.rx.general;
6662306a36Sopenharmony_ci	accum_ofdm = &il->_3945.accum_stats.rx.ofdm;
6762306a36Sopenharmony_ci	accum_cck = &il->_3945.accum_stats.rx.cck;
6862306a36Sopenharmony_ci	accum_general = &il->_3945.accum_stats.rx.general;
6962306a36Sopenharmony_ci	delta_ofdm = &il->_3945.delta_stats.rx.ofdm;
7062306a36Sopenharmony_ci	delta_cck = &il->_3945.delta_stats.rx.cck;
7162306a36Sopenharmony_ci	delta_general = &il->_3945.delta_stats.rx.general;
7262306a36Sopenharmony_ci	max_ofdm = &il->_3945.max_delta.rx.ofdm;
7362306a36Sopenharmony_ci	max_cck = &il->_3945.max_delta.rx.cck;
7462306a36Sopenharmony_ci	max_general = &il->_3945.max_delta.rx.general;
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci	pos += il3945_stats_flag(il, buf, bufsz);
7762306a36Sopenharmony_ci	pos +=
7862306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
7962306a36Sopenharmony_ci		      "%-32s     current"
8062306a36Sopenharmony_ci		      "accumulative      delta         max\n",
8162306a36Sopenharmony_ci		      "Statistics_Rx - OFDM:");
8262306a36Sopenharmony_ci	pos +=
8362306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
8462306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "ina_cnt:",
8562306a36Sopenharmony_ci		      le32_to_cpu(ofdm->ina_cnt), accum_ofdm->ina_cnt,
8662306a36Sopenharmony_ci		      delta_ofdm->ina_cnt, max_ofdm->ina_cnt);
8762306a36Sopenharmony_ci	pos +=
8862306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
8962306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "fina_cnt:",
9062306a36Sopenharmony_ci		      le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt,
9162306a36Sopenharmony_ci		      delta_ofdm->fina_cnt, max_ofdm->fina_cnt);
9262306a36Sopenharmony_ci	pos +=
9362306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
9462306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "plcp_err:",
9562306a36Sopenharmony_ci		      le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err,
9662306a36Sopenharmony_ci		      delta_ofdm->plcp_err, max_ofdm->plcp_err);
9762306a36Sopenharmony_ci	pos +=
9862306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
9962306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "crc32_err:",
10062306a36Sopenharmony_ci		      le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err,
10162306a36Sopenharmony_ci		      delta_ofdm->crc32_err, max_ofdm->crc32_err);
10262306a36Sopenharmony_ci	pos +=
10362306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
10462306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "overrun_err:",
10562306a36Sopenharmony_ci		      le32_to_cpu(ofdm->overrun_err), accum_ofdm->overrun_err,
10662306a36Sopenharmony_ci		      delta_ofdm->overrun_err, max_ofdm->overrun_err);
10762306a36Sopenharmony_ci	pos +=
10862306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
10962306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "early_overrun_err:",
11062306a36Sopenharmony_ci		      le32_to_cpu(ofdm->early_overrun_err),
11162306a36Sopenharmony_ci		      accum_ofdm->early_overrun_err,
11262306a36Sopenharmony_ci		      delta_ofdm->early_overrun_err,
11362306a36Sopenharmony_ci		      max_ofdm->early_overrun_err);
11462306a36Sopenharmony_ci	pos +=
11562306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
11662306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "crc32_good:",
11762306a36Sopenharmony_ci		      le32_to_cpu(ofdm->crc32_good), accum_ofdm->crc32_good,
11862306a36Sopenharmony_ci		      delta_ofdm->crc32_good, max_ofdm->crc32_good);
11962306a36Sopenharmony_ci	pos +=
12062306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
12162306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "false_alarm_cnt:",
12262306a36Sopenharmony_ci		      le32_to_cpu(ofdm->false_alarm_cnt),
12362306a36Sopenharmony_ci		      accum_ofdm->false_alarm_cnt, delta_ofdm->false_alarm_cnt,
12462306a36Sopenharmony_ci		      max_ofdm->false_alarm_cnt);
12562306a36Sopenharmony_ci	pos +=
12662306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
12762306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "fina_sync_err_cnt:",
12862306a36Sopenharmony_ci		      le32_to_cpu(ofdm->fina_sync_err_cnt),
12962306a36Sopenharmony_ci		      accum_ofdm->fina_sync_err_cnt,
13062306a36Sopenharmony_ci		      delta_ofdm->fina_sync_err_cnt,
13162306a36Sopenharmony_ci		      max_ofdm->fina_sync_err_cnt);
13262306a36Sopenharmony_ci	pos +=
13362306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
13462306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "sfd_timeout:",
13562306a36Sopenharmony_ci		      le32_to_cpu(ofdm->sfd_timeout), accum_ofdm->sfd_timeout,
13662306a36Sopenharmony_ci		      delta_ofdm->sfd_timeout, max_ofdm->sfd_timeout);
13762306a36Sopenharmony_ci	pos +=
13862306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
13962306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "fina_timeout:",
14062306a36Sopenharmony_ci		      le32_to_cpu(ofdm->fina_timeout), accum_ofdm->fina_timeout,
14162306a36Sopenharmony_ci		      delta_ofdm->fina_timeout, max_ofdm->fina_timeout);
14262306a36Sopenharmony_ci	pos +=
14362306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
14462306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "unresponded_rts:",
14562306a36Sopenharmony_ci		      le32_to_cpu(ofdm->unresponded_rts),
14662306a36Sopenharmony_ci		      accum_ofdm->unresponded_rts, delta_ofdm->unresponded_rts,
14762306a36Sopenharmony_ci		      max_ofdm->unresponded_rts);
14862306a36Sopenharmony_ci	pos +=
14962306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
15062306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n",
15162306a36Sopenharmony_ci		      "rxe_frame_lmt_ovrun:",
15262306a36Sopenharmony_ci		      le32_to_cpu(ofdm->rxe_frame_limit_overrun),
15362306a36Sopenharmony_ci		      accum_ofdm->rxe_frame_limit_overrun,
15462306a36Sopenharmony_ci		      delta_ofdm->rxe_frame_limit_overrun,
15562306a36Sopenharmony_ci		      max_ofdm->rxe_frame_limit_overrun);
15662306a36Sopenharmony_ci	pos +=
15762306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
15862306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "sent_ack_cnt:",
15962306a36Sopenharmony_ci		      le32_to_cpu(ofdm->sent_ack_cnt), accum_ofdm->sent_ack_cnt,
16062306a36Sopenharmony_ci		      delta_ofdm->sent_ack_cnt, max_ofdm->sent_ack_cnt);
16162306a36Sopenharmony_ci	pos +=
16262306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
16362306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "sent_cts_cnt:",
16462306a36Sopenharmony_ci		      le32_to_cpu(ofdm->sent_cts_cnt), accum_ofdm->sent_cts_cnt,
16562306a36Sopenharmony_ci		      delta_ofdm->sent_cts_cnt, max_ofdm->sent_cts_cnt);
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci	pos +=
16862306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
16962306a36Sopenharmony_ci		      "%-32s     current"
17062306a36Sopenharmony_ci		      "accumulative      delta         max\n",
17162306a36Sopenharmony_ci		      "Statistics_Rx - CCK:");
17262306a36Sopenharmony_ci	pos +=
17362306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
17462306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "ina_cnt:",
17562306a36Sopenharmony_ci		      le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt,
17662306a36Sopenharmony_ci		      delta_cck->ina_cnt, max_cck->ina_cnt);
17762306a36Sopenharmony_ci	pos +=
17862306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
17962306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "fina_cnt:",
18062306a36Sopenharmony_ci		      le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt,
18162306a36Sopenharmony_ci		      delta_cck->fina_cnt, max_cck->fina_cnt);
18262306a36Sopenharmony_ci	pos +=
18362306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
18462306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "plcp_err:",
18562306a36Sopenharmony_ci		      le32_to_cpu(cck->plcp_err), accum_cck->plcp_err,
18662306a36Sopenharmony_ci		      delta_cck->plcp_err, max_cck->plcp_err);
18762306a36Sopenharmony_ci	pos +=
18862306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
18962306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "crc32_err:",
19062306a36Sopenharmony_ci		      le32_to_cpu(cck->crc32_err), accum_cck->crc32_err,
19162306a36Sopenharmony_ci		      delta_cck->crc32_err, max_cck->crc32_err);
19262306a36Sopenharmony_ci	pos +=
19362306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
19462306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "overrun_err:",
19562306a36Sopenharmony_ci		      le32_to_cpu(cck->overrun_err), accum_cck->overrun_err,
19662306a36Sopenharmony_ci		      delta_cck->overrun_err, max_cck->overrun_err);
19762306a36Sopenharmony_ci	pos +=
19862306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
19962306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "early_overrun_err:",
20062306a36Sopenharmony_ci		      le32_to_cpu(cck->early_overrun_err),
20162306a36Sopenharmony_ci		      accum_cck->early_overrun_err,
20262306a36Sopenharmony_ci		      delta_cck->early_overrun_err, max_cck->early_overrun_err);
20362306a36Sopenharmony_ci	pos +=
20462306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
20562306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "crc32_good:",
20662306a36Sopenharmony_ci		      le32_to_cpu(cck->crc32_good), accum_cck->crc32_good,
20762306a36Sopenharmony_ci		      delta_cck->crc32_good, max_cck->crc32_good);
20862306a36Sopenharmony_ci	pos +=
20962306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
21062306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "false_alarm_cnt:",
21162306a36Sopenharmony_ci		      le32_to_cpu(cck->false_alarm_cnt),
21262306a36Sopenharmony_ci		      accum_cck->false_alarm_cnt, delta_cck->false_alarm_cnt,
21362306a36Sopenharmony_ci		      max_cck->false_alarm_cnt);
21462306a36Sopenharmony_ci	pos +=
21562306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
21662306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "fina_sync_err_cnt:",
21762306a36Sopenharmony_ci		      le32_to_cpu(cck->fina_sync_err_cnt),
21862306a36Sopenharmony_ci		      accum_cck->fina_sync_err_cnt,
21962306a36Sopenharmony_ci		      delta_cck->fina_sync_err_cnt, max_cck->fina_sync_err_cnt);
22062306a36Sopenharmony_ci	pos +=
22162306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
22262306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "sfd_timeout:",
22362306a36Sopenharmony_ci		      le32_to_cpu(cck->sfd_timeout), accum_cck->sfd_timeout,
22462306a36Sopenharmony_ci		      delta_cck->sfd_timeout, max_cck->sfd_timeout);
22562306a36Sopenharmony_ci	pos +=
22662306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
22762306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "fina_timeout:",
22862306a36Sopenharmony_ci		      le32_to_cpu(cck->fina_timeout), accum_cck->fina_timeout,
22962306a36Sopenharmony_ci		      delta_cck->fina_timeout, max_cck->fina_timeout);
23062306a36Sopenharmony_ci	pos +=
23162306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
23262306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "unresponded_rts:",
23362306a36Sopenharmony_ci		      le32_to_cpu(cck->unresponded_rts),
23462306a36Sopenharmony_ci		      accum_cck->unresponded_rts, delta_cck->unresponded_rts,
23562306a36Sopenharmony_ci		      max_cck->unresponded_rts);
23662306a36Sopenharmony_ci	pos +=
23762306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
23862306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n",
23962306a36Sopenharmony_ci		      "rxe_frame_lmt_ovrun:",
24062306a36Sopenharmony_ci		      le32_to_cpu(cck->rxe_frame_limit_overrun),
24162306a36Sopenharmony_ci		      accum_cck->rxe_frame_limit_overrun,
24262306a36Sopenharmony_ci		      delta_cck->rxe_frame_limit_overrun,
24362306a36Sopenharmony_ci		      max_cck->rxe_frame_limit_overrun);
24462306a36Sopenharmony_ci	pos +=
24562306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
24662306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "sent_ack_cnt:",
24762306a36Sopenharmony_ci		      le32_to_cpu(cck->sent_ack_cnt), accum_cck->sent_ack_cnt,
24862306a36Sopenharmony_ci		      delta_cck->sent_ack_cnt, max_cck->sent_ack_cnt);
24962306a36Sopenharmony_ci	pos +=
25062306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
25162306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "sent_cts_cnt:",
25262306a36Sopenharmony_ci		      le32_to_cpu(cck->sent_cts_cnt), accum_cck->sent_cts_cnt,
25362306a36Sopenharmony_ci		      delta_cck->sent_cts_cnt, max_cck->sent_cts_cnt);
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci	pos +=
25662306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
25762306a36Sopenharmony_ci		      "%-32s     current"
25862306a36Sopenharmony_ci		      "accumulative      delta         max\n",
25962306a36Sopenharmony_ci		      "Statistics_Rx - GENERAL:");
26062306a36Sopenharmony_ci	pos +=
26162306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
26262306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "bogus_cts:",
26362306a36Sopenharmony_ci		      le32_to_cpu(general->bogus_cts), accum_general->bogus_cts,
26462306a36Sopenharmony_ci		      delta_general->bogus_cts, max_general->bogus_cts);
26562306a36Sopenharmony_ci	pos +=
26662306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
26762306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "bogus_ack:",
26862306a36Sopenharmony_ci		      le32_to_cpu(general->bogus_ack), accum_general->bogus_ack,
26962306a36Sopenharmony_ci		      delta_general->bogus_ack, max_general->bogus_ack);
27062306a36Sopenharmony_ci	pos +=
27162306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
27262306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "non_bssid_frames:",
27362306a36Sopenharmony_ci		      le32_to_cpu(general->non_bssid_frames),
27462306a36Sopenharmony_ci		      accum_general->non_bssid_frames,
27562306a36Sopenharmony_ci		      delta_general->non_bssid_frames,
27662306a36Sopenharmony_ci		      max_general->non_bssid_frames);
27762306a36Sopenharmony_ci	pos +=
27862306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
27962306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "filtered_frames:",
28062306a36Sopenharmony_ci		      le32_to_cpu(general->filtered_frames),
28162306a36Sopenharmony_ci		      accum_general->filtered_frames,
28262306a36Sopenharmony_ci		      delta_general->filtered_frames,
28362306a36Sopenharmony_ci		      max_general->filtered_frames);
28462306a36Sopenharmony_ci	pos +=
28562306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
28662306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n",
28762306a36Sopenharmony_ci		      "non_channel_beacons:",
28862306a36Sopenharmony_ci		      le32_to_cpu(general->non_channel_beacons),
28962306a36Sopenharmony_ci		      accum_general->non_channel_beacons,
29062306a36Sopenharmony_ci		      delta_general->non_channel_beacons,
29162306a36Sopenharmony_ci		      max_general->non_channel_beacons);
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
29462306a36Sopenharmony_ci	kfree(buf);
29562306a36Sopenharmony_ci	return ret;
29662306a36Sopenharmony_ci}
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_cistatic ssize_t
29962306a36Sopenharmony_ciil3945_ucode_tx_stats_read(struct file *file, char __user *user_buf,
30062306a36Sopenharmony_ci			   size_t count, loff_t *ppos)
30162306a36Sopenharmony_ci{
30262306a36Sopenharmony_ci	struct il_priv *il = file->private_data;
30362306a36Sopenharmony_ci	int pos = 0;
30462306a36Sopenharmony_ci	char *buf;
30562306a36Sopenharmony_ci	int bufsz = (sizeof(struct iwl39_stats_tx) * 48) + 250;
30662306a36Sopenharmony_ci	ssize_t ret;
30762306a36Sopenharmony_ci	struct iwl39_stats_tx *tx, *accum_tx, *delta_tx, *max_tx;
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_ci	if (!il_is_alive(il))
31062306a36Sopenharmony_ci		return -EAGAIN;
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
31362306a36Sopenharmony_ci	if (!buf) {
31462306a36Sopenharmony_ci		IL_ERR("Can not allocate Buffer\n");
31562306a36Sopenharmony_ci		return -ENOMEM;
31662306a36Sopenharmony_ci	}
31762306a36Sopenharmony_ci
31862306a36Sopenharmony_ci	/*
31962306a36Sopenharmony_ci	 * The statistic information display here is based on
32062306a36Sopenharmony_ci	 * the last stats notification from uCode
32162306a36Sopenharmony_ci	 * might not reflect the current uCode activity
32262306a36Sopenharmony_ci	 */
32362306a36Sopenharmony_ci	tx = &il->_3945.stats.tx;
32462306a36Sopenharmony_ci	accum_tx = &il->_3945.accum_stats.tx;
32562306a36Sopenharmony_ci	delta_tx = &il->_3945.delta_stats.tx;
32662306a36Sopenharmony_ci	max_tx = &il->_3945.max_delta.tx;
32762306a36Sopenharmony_ci	pos += il3945_stats_flag(il, buf, bufsz);
32862306a36Sopenharmony_ci	pos +=
32962306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
33062306a36Sopenharmony_ci		      "%-32s     current"
33162306a36Sopenharmony_ci		      "accumulative      delta         max\n",
33262306a36Sopenharmony_ci		      "Statistics_Tx:");
33362306a36Sopenharmony_ci	pos +=
33462306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
33562306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "preamble:",
33662306a36Sopenharmony_ci		      le32_to_cpu(tx->preamble_cnt), accum_tx->preamble_cnt,
33762306a36Sopenharmony_ci		      delta_tx->preamble_cnt, max_tx->preamble_cnt);
33862306a36Sopenharmony_ci	pos +=
33962306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
34062306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "rx_detected_cnt:",
34162306a36Sopenharmony_ci		      le32_to_cpu(tx->rx_detected_cnt),
34262306a36Sopenharmony_ci		      accum_tx->rx_detected_cnt, delta_tx->rx_detected_cnt,
34362306a36Sopenharmony_ci		      max_tx->rx_detected_cnt);
34462306a36Sopenharmony_ci	pos +=
34562306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
34662306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "bt_prio_defer_cnt:",
34762306a36Sopenharmony_ci		      le32_to_cpu(tx->bt_prio_defer_cnt),
34862306a36Sopenharmony_ci		      accum_tx->bt_prio_defer_cnt, delta_tx->bt_prio_defer_cnt,
34962306a36Sopenharmony_ci		      max_tx->bt_prio_defer_cnt);
35062306a36Sopenharmony_ci	pos +=
35162306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
35262306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "bt_prio_kill_cnt:",
35362306a36Sopenharmony_ci		      le32_to_cpu(tx->bt_prio_kill_cnt),
35462306a36Sopenharmony_ci		      accum_tx->bt_prio_kill_cnt, delta_tx->bt_prio_kill_cnt,
35562306a36Sopenharmony_ci		      max_tx->bt_prio_kill_cnt);
35662306a36Sopenharmony_ci	pos +=
35762306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
35862306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "few_bytes_cnt:",
35962306a36Sopenharmony_ci		      le32_to_cpu(tx->few_bytes_cnt), accum_tx->few_bytes_cnt,
36062306a36Sopenharmony_ci		      delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt);
36162306a36Sopenharmony_ci	pos +=
36262306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
36362306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "cts_timeout:",
36462306a36Sopenharmony_ci		      le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout,
36562306a36Sopenharmony_ci		      delta_tx->cts_timeout, max_tx->cts_timeout);
36662306a36Sopenharmony_ci	pos +=
36762306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
36862306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "ack_timeout:",
36962306a36Sopenharmony_ci		      le32_to_cpu(tx->ack_timeout), accum_tx->ack_timeout,
37062306a36Sopenharmony_ci		      delta_tx->ack_timeout, max_tx->ack_timeout);
37162306a36Sopenharmony_ci	pos +=
37262306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
37362306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "expected_ack_cnt:",
37462306a36Sopenharmony_ci		      le32_to_cpu(tx->expected_ack_cnt),
37562306a36Sopenharmony_ci		      accum_tx->expected_ack_cnt, delta_tx->expected_ack_cnt,
37662306a36Sopenharmony_ci		      max_tx->expected_ack_cnt);
37762306a36Sopenharmony_ci	pos +=
37862306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
37962306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "actual_ack_cnt:",
38062306a36Sopenharmony_ci		      le32_to_cpu(tx->actual_ack_cnt), accum_tx->actual_ack_cnt,
38162306a36Sopenharmony_ci		      delta_tx->actual_ack_cnt, max_tx->actual_ack_cnt);
38262306a36Sopenharmony_ci
38362306a36Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
38462306a36Sopenharmony_ci	kfree(buf);
38562306a36Sopenharmony_ci	return ret;
38662306a36Sopenharmony_ci}
38762306a36Sopenharmony_ci
38862306a36Sopenharmony_cistatic ssize_t
38962306a36Sopenharmony_ciil3945_ucode_general_stats_read(struct file *file, char __user *user_buf,
39062306a36Sopenharmony_ci				size_t count, loff_t *ppos)
39162306a36Sopenharmony_ci{
39262306a36Sopenharmony_ci	struct il_priv *il = file->private_data;
39362306a36Sopenharmony_ci	int pos = 0;
39462306a36Sopenharmony_ci	char *buf;
39562306a36Sopenharmony_ci	int bufsz = sizeof(struct iwl39_stats_general) * 10 + 300;
39662306a36Sopenharmony_ci	ssize_t ret;
39762306a36Sopenharmony_ci	struct iwl39_stats_general *general, *accum_general;
39862306a36Sopenharmony_ci	struct iwl39_stats_general *delta_general, *max_general;
39962306a36Sopenharmony_ci	struct stats_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg;
40062306a36Sopenharmony_ci	struct iwl39_stats_div *div, *accum_div, *delta_div, *max_div;
40162306a36Sopenharmony_ci
40262306a36Sopenharmony_ci	if (!il_is_alive(il))
40362306a36Sopenharmony_ci		return -EAGAIN;
40462306a36Sopenharmony_ci
40562306a36Sopenharmony_ci	buf = kzalloc(bufsz, GFP_KERNEL);
40662306a36Sopenharmony_ci	if (!buf) {
40762306a36Sopenharmony_ci		IL_ERR("Can not allocate Buffer\n");
40862306a36Sopenharmony_ci		return -ENOMEM;
40962306a36Sopenharmony_ci	}
41062306a36Sopenharmony_ci
41162306a36Sopenharmony_ci	/*
41262306a36Sopenharmony_ci	 * The statistic information display here is based on
41362306a36Sopenharmony_ci	 * the last stats notification from uCode
41462306a36Sopenharmony_ci	 * might not reflect the current uCode activity
41562306a36Sopenharmony_ci	 */
41662306a36Sopenharmony_ci	general = &il->_3945.stats.general;
41762306a36Sopenharmony_ci	dbg = &il->_3945.stats.general.dbg;
41862306a36Sopenharmony_ci	div = &il->_3945.stats.general.div;
41962306a36Sopenharmony_ci	accum_general = &il->_3945.accum_stats.general;
42062306a36Sopenharmony_ci	delta_general = &il->_3945.delta_stats.general;
42162306a36Sopenharmony_ci	max_general = &il->_3945.max_delta.general;
42262306a36Sopenharmony_ci	accum_dbg = &il->_3945.accum_stats.general.dbg;
42362306a36Sopenharmony_ci	delta_dbg = &il->_3945.delta_stats.general.dbg;
42462306a36Sopenharmony_ci	max_dbg = &il->_3945.max_delta.general.dbg;
42562306a36Sopenharmony_ci	accum_div = &il->_3945.accum_stats.general.div;
42662306a36Sopenharmony_ci	delta_div = &il->_3945.delta_stats.general.div;
42762306a36Sopenharmony_ci	max_div = &il->_3945.max_delta.general.div;
42862306a36Sopenharmony_ci	pos += il3945_stats_flag(il, buf, bufsz);
42962306a36Sopenharmony_ci	pos +=
43062306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
43162306a36Sopenharmony_ci		      "%-32s     current"
43262306a36Sopenharmony_ci		      "accumulative      delta         max\n",
43362306a36Sopenharmony_ci		      "Statistics_General:");
43462306a36Sopenharmony_ci	pos +=
43562306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
43662306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "burst_check:",
43762306a36Sopenharmony_ci		      le32_to_cpu(dbg->burst_check), accum_dbg->burst_check,
43862306a36Sopenharmony_ci		      delta_dbg->burst_check, max_dbg->burst_check);
43962306a36Sopenharmony_ci	pos +=
44062306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
44162306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "burst_count:",
44262306a36Sopenharmony_ci		      le32_to_cpu(dbg->burst_count), accum_dbg->burst_count,
44362306a36Sopenharmony_ci		      delta_dbg->burst_count, max_dbg->burst_count);
44462306a36Sopenharmony_ci	pos +=
44562306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
44662306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "sleep_time:",
44762306a36Sopenharmony_ci		      le32_to_cpu(general->sleep_time),
44862306a36Sopenharmony_ci		      accum_general->sleep_time, delta_general->sleep_time,
44962306a36Sopenharmony_ci		      max_general->sleep_time);
45062306a36Sopenharmony_ci	pos +=
45162306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
45262306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "slots_out:",
45362306a36Sopenharmony_ci		      le32_to_cpu(general->slots_out), accum_general->slots_out,
45462306a36Sopenharmony_ci		      delta_general->slots_out, max_general->slots_out);
45562306a36Sopenharmony_ci	pos +=
45662306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
45762306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "slots_idle:",
45862306a36Sopenharmony_ci		      le32_to_cpu(general->slots_idle),
45962306a36Sopenharmony_ci		      accum_general->slots_idle, delta_general->slots_idle,
46062306a36Sopenharmony_ci		      max_general->slots_idle);
46162306a36Sopenharmony_ci	pos +=
46262306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos, "ttl_timestamp:\t\t\t%u\n",
46362306a36Sopenharmony_ci		      le32_to_cpu(general->ttl_timestamp));
46462306a36Sopenharmony_ci	pos +=
46562306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
46662306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "tx_on_a:",
46762306a36Sopenharmony_ci		      le32_to_cpu(div->tx_on_a), accum_div->tx_on_a,
46862306a36Sopenharmony_ci		      delta_div->tx_on_a, max_div->tx_on_a);
46962306a36Sopenharmony_ci	pos +=
47062306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
47162306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "tx_on_b:",
47262306a36Sopenharmony_ci		      le32_to_cpu(div->tx_on_b), accum_div->tx_on_b,
47362306a36Sopenharmony_ci		      delta_div->tx_on_b, max_div->tx_on_b);
47462306a36Sopenharmony_ci	pos +=
47562306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
47662306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "exec_time:",
47762306a36Sopenharmony_ci		      le32_to_cpu(div->exec_time), accum_div->exec_time,
47862306a36Sopenharmony_ci		      delta_div->exec_time, max_div->exec_time);
47962306a36Sopenharmony_ci	pos +=
48062306a36Sopenharmony_ci	    scnprintf(buf + pos, bufsz - pos,
48162306a36Sopenharmony_ci		      "  %-30s %10u  %10u  %10u  %10u\n", "probe_time:",
48262306a36Sopenharmony_ci		      le32_to_cpu(div->probe_time), accum_div->probe_time,
48362306a36Sopenharmony_ci		      delta_div->probe_time, max_div->probe_time);
48462306a36Sopenharmony_ci	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
48562306a36Sopenharmony_ci	kfree(buf);
48662306a36Sopenharmony_ci	return ret;
48762306a36Sopenharmony_ci}
48862306a36Sopenharmony_ci
48962306a36Sopenharmony_ciconst struct il_debugfs_ops il3945_debugfs_ops = {
49062306a36Sopenharmony_ci	.rx_stats_read = il3945_ucode_rx_stats_read,
49162306a36Sopenharmony_ci	.tx_stats_read = il3945_ucode_tx_stats_read,
49262306a36Sopenharmony_ci	.general_stats_read = il3945_ucode_general_stats_read,
49362306a36Sopenharmony_ci};
494