xref: /openbmc/linux/net/mac80211/rc80211_minstrel_ht_debugfs.c (revision d0034a7a4ac7fae708146ac0059b9c47a1543f0d)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2ec8aa669SFelix Fietkau /*
3ec8aa669SFelix Fietkau  * Copyright (C) 2010 Felix Fietkau <nbd@openwrt.org>
4ec8aa669SFelix Fietkau  */
5ec8aa669SFelix Fietkau #include <linux/netdevice.h>
6ec8aa669SFelix Fietkau #include <linux/types.h>
7ec8aa669SFelix Fietkau #include <linux/skbuff.h>
8ec8aa669SFelix Fietkau #include <linux/debugfs.h>
9ec8aa669SFelix Fietkau #include <linux/ieee80211.h>
10bc3b2d7fSPaul Gortmaker #include <linux/export.h>
11ec8aa669SFelix Fietkau #include <net/mac80211.h>
12ec8aa669SFelix Fietkau #include "rc80211_minstrel_ht.h"
13ec8aa669SFelix Fietkau 
14cbda98c7SFelix Fietkau struct minstrel_debugfs_info {
15cbda98c7SFelix Fietkau 	size_t len;
16cbda98c7SFelix Fietkau 	char buf[];
17cbda98c7SFelix Fietkau };
18cbda98c7SFelix Fietkau 
19b1c4f683SFelix Fietkau static ssize_t
minstrel_stats_read(struct file * file,char __user * buf,size_t len,loff_t * ppos)20b1c4f683SFelix Fietkau minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *ppos)
21b1c4f683SFelix Fietkau {
22b1c4f683SFelix Fietkau 	struct minstrel_debugfs_info *ms;
23b1c4f683SFelix Fietkau 
24b1c4f683SFelix Fietkau 	ms = file->private_data;
25b1c4f683SFelix Fietkau 	return simple_read_from_buffer(buf, len, ppos, ms->buf, ms->len);
26b1c4f683SFelix Fietkau }
27b1c4f683SFelix Fietkau 
28b1c4f683SFelix Fietkau static int
minstrel_stats_release(struct inode * inode,struct file * file)29b1c4f683SFelix Fietkau minstrel_stats_release(struct inode *inode, struct file *file)
30b1c4f683SFelix Fietkau {
31b1c4f683SFelix Fietkau 	kfree(file->private_data);
32b1c4f683SFelix Fietkau 	return 0;
33b1c4f683SFelix Fietkau }
34b1c4f683SFelix Fietkau 
35*4a8d0c99SFelix Fietkau static bool
minstrel_ht_is_sample_rate(struct minstrel_ht_sta * mi,int idx)36*4a8d0c99SFelix Fietkau minstrel_ht_is_sample_rate(struct minstrel_ht_sta *mi, int idx)
37*4a8d0c99SFelix Fietkau {
38*4a8d0c99SFelix Fietkau 	int type, i;
39*4a8d0c99SFelix Fietkau 
40*4a8d0c99SFelix Fietkau 	for (type = 0; type < ARRAY_SIZE(mi->sample); type++)
41*4a8d0c99SFelix Fietkau 		for (i = 0; i < MINSTREL_SAMPLE_RATES; i++)
42*4a8d0c99SFelix Fietkau 			if (mi->sample[type].cur_sample_rates[i] == idx)
43*4a8d0c99SFelix Fietkau 				return true;
44*4a8d0c99SFelix Fietkau 	return false;
45*4a8d0c99SFelix Fietkau }
46*4a8d0c99SFelix Fietkau 
47a0497f9fSFelix Fietkau static char *
minstrel_ht_stats_dump(struct minstrel_ht_sta * mi,int i,char * p)48a0497f9fSFelix Fietkau minstrel_ht_stats_dump(struct minstrel_ht_sta *mi, int i, char *p)
49a0497f9fSFelix Fietkau {
50a0497f9fSFelix Fietkau 	const struct mcs_group *mg;
511109dc39SFelix Fietkau 	unsigned int j, tp_max, tp_avg, eprob, tx_time;
52a0497f9fSFelix Fietkau 	char htmode = '2';
53a0497f9fSFelix Fietkau 	char gimode = 'L';
548ec7886bSKarl Beldan 	u32 gflags;
55a0497f9fSFelix Fietkau 
5641d08583SFelix Fietkau 	if (!mi->supported[i])
57a0497f9fSFelix Fietkau 		return p;
58a0497f9fSFelix Fietkau 
59a0497f9fSFelix Fietkau 	mg = &minstrel_mcs_groups[i];
608ec7886bSKarl Beldan 	gflags = mg->flags;
618ec7886bSKarl Beldan 
628ec7886bSKarl Beldan 	if (gflags & IEEE80211_TX_RC_40_MHZ_WIDTH)
63a0497f9fSFelix Fietkau 		htmode = '4';
648ec7886bSKarl Beldan 	else if (gflags & IEEE80211_TX_RC_80_MHZ_WIDTH)
659208247dSKarl Beldan 		htmode = '8';
668ec7886bSKarl Beldan 	if (gflags & IEEE80211_TX_RC_SHORT_GI)
67a0497f9fSFelix Fietkau 		gimode = 'S';
68a0497f9fSFelix Fietkau 
69a0497f9fSFelix Fietkau 	for (j = 0; j < MCS_GROUP_RATES; j++) {
709134073bSThomas Huehn 		struct minstrel_rate_stats *mrs = &mi->groups[i].rates[j];
71a42fa256SFelix Fietkau 		int idx = MI_RATE(i, j);
72202df504SFelix Fietkau 		unsigned int duration;
73a0497f9fSFelix Fietkau 
7441d08583SFelix Fietkau 		if (!(mi->supported[i] & BIT(j)))
75a0497f9fSFelix Fietkau 			continue;
76a0497f9fSFelix Fietkau 
779c00bb72SThomas Huehn 		if (gflags & IEEE80211_TX_RC_MCS) {
789c00bb72SThomas Huehn 			p += sprintf(p, "HT%c0  ", htmode);
799c00bb72SThomas Huehn 			p += sprintf(p, "%cGI  ", gimode);
809c00bb72SThomas Huehn 			p += sprintf(p, "%d  ", mg->streams);
819c00bb72SThomas Huehn 		} else if (gflags & IEEE80211_TX_RC_VHT_MCS) {
829c00bb72SThomas Huehn 			p += sprintf(p, "VHT%c0 ", htmode);
839c00bb72SThomas Huehn 			p += sprintf(p, "%cGI ", gimode);
849c00bb72SThomas Huehn 			p += sprintf(p, "%d  ", mg->streams);
85a7844a53SFelix Fietkau 		} else if (i == MINSTREL_OFDM_GROUP) {
86a7844a53SFelix Fietkau 			p += sprintf(p, "OFDM       ");
87a7844a53SFelix Fietkau 			p += sprintf(p, "1 ");
889c00bb72SThomas Huehn 		} else {
899c00bb72SThomas Huehn 			p += sprintf(p, "CCK    ");
909c00bb72SThomas Huehn 			p += sprintf(p, "%cP  ", j < 4 ? 'L' : 'S');
919c00bb72SThomas Huehn 			p += sprintf(p, "1 ");
929c00bb72SThomas Huehn 		}
93a0497f9fSFelix Fietkau 
945935839aSThomas Huehn 		*(p++) = (idx == mi->max_tp_rate[0]) ? 'A' : ' ';
955935839aSThomas Huehn 		*(p++) = (idx == mi->max_tp_rate[1]) ? 'B' : ' ';
965935839aSThomas Huehn 		*(p++) = (idx == mi->max_tp_rate[2]) ? 'C' : ' ';
975935839aSThomas Huehn 		*(p++) = (idx == mi->max_tp_rate[3]) ? 'D' : ' ';
98a0497f9fSFelix Fietkau 		*(p++) = (idx == mi->max_prob_rate) ? 'P' : ' ';
99*4a8d0c99SFelix Fietkau 		*(p++) = minstrel_ht_is_sample_rate(mi, idx) ? 'S' : ' ';
100a0497f9fSFelix Fietkau 
1018ec7886bSKarl Beldan 		if (gflags & IEEE80211_TX_RC_MCS) {
1028ec7886bSKarl Beldan 			p += sprintf(p, "  MCS%-2u", (mg->streams - 1) * 8 + j);
1038ec7886bSKarl Beldan 		} else if (gflags & IEEE80211_TX_RC_VHT_MCS) {
1049208247dSKarl Beldan 			p += sprintf(p, "  MCS%-1u/%1u", j, mg->streams);
105a0497f9fSFelix Fietkau 		} else {
106a7844a53SFelix Fietkau 			int r;
107a7844a53SFelix Fietkau 
108a7844a53SFelix Fietkau 			if (i == MINSTREL_OFDM_GROUP)
109a7844a53SFelix Fietkau 				r = minstrel_ofdm_bitrates[j % 8];
110a7844a53SFelix Fietkau 			else
111a7844a53SFelix Fietkau 				r = minstrel_cck_bitrates[j % 4];
1128ec7886bSKarl Beldan 
1138ec7886bSKarl Beldan 			p += sprintf(p, "   %2u.%1uM", r / 10, r % 10);
114a0497f9fSFelix Fietkau 		}
115a0497f9fSFelix Fietkau 
1169c00bb72SThomas Huehn 		p += sprintf(p, "  %3u  ", idx);
1179c00bb72SThomas Huehn 
1189c00bb72SThomas Huehn 		/* tx_time[rate(i)] in usec */
119202df504SFelix Fietkau 		duration = mg->duration[j];
120202df504SFelix Fietkau 		duration <<= mg->shift;
121202df504SFelix Fietkau 		tx_time = DIV_ROUND_CLOSEST(duration, 1000);
1229c00bb72SThomas Huehn 		p += sprintf(p, "%6u  ", tx_time);
1239c00bb72SThomas Huehn 
12450e55a8eSThomas Huehn 		tp_max = minstrel_ht_get_tp_avg(mi, i, j, MINSTREL_FRAC(100, 100));
1255f63afe0SFelix Fietkau 		tp_avg = minstrel_ht_get_tp_avg(mi, i, j, mrs->prob_avg);
1265f63afe0SFelix Fietkau 		eprob = MINSTREL_TRUNC(mrs->prob_avg * 1000);
127a0497f9fSFelix Fietkau 
128506dbf90SFelix Fietkau 		p += sprintf(p, "%4u.%1u    %4u.%1u     %3u.%1u"
1291109dc39SFelix Fietkau 				"     %3u   %3u %-3u   "
1305f919abcSThomas Huehn 				"%9llu   %-9llu\n",
13150e55a8eSThomas Huehn 				tp_max / 10, tp_max % 10,
1326a27b2c4SThomas Huehn 				tp_avg / 10, tp_avg % 10,
133a0497f9fSFelix Fietkau 				eprob / 10, eprob % 10,
1349134073bSThomas Huehn 				mrs->retry_count,
1359134073bSThomas Huehn 				mrs->last_success,
1369134073bSThomas Huehn 				mrs->last_attempts,
1379134073bSThomas Huehn 				(unsigned long long)mrs->succ_hist,
1389134073bSThomas Huehn 				(unsigned long long)mrs->att_hist);
139a0497f9fSFelix Fietkau 	}
140a0497f9fSFelix Fietkau 
141a0497f9fSFelix Fietkau 	return p;
142a0497f9fSFelix Fietkau }
143a0497f9fSFelix Fietkau 
144ec8aa669SFelix Fietkau static int
minstrel_ht_stats_open(struct inode * inode,struct file * file)145ec8aa669SFelix Fietkau minstrel_ht_stats_open(struct inode *inode, struct file *file)
146ec8aa669SFelix Fietkau {
147cbda98c7SFelix Fietkau 	struct minstrel_ht_sta *mi = inode->i_private;
148ec8aa669SFelix Fietkau 	struct minstrel_debugfs_info *ms;
149a0497f9fSFelix Fietkau 	unsigned int i;
1502cae0b6aSThomas Huehn 	char *p;
151ec8aa669SFelix Fietkau 
1529208247dSKarl Beldan 	ms = kmalloc(32768, GFP_KERNEL);
153ec8aa669SFelix Fietkau 	if (!ms)
154ec8aa669SFelix Fietkau 		return -ENOMEM;
155ec8aa669SFelix Fietkau 
156ec8aa669SFelix Fietkau 	file->private_data = ms;
157ec8aa669SFelix Fietkau 	p = ms->buf;
1589c00bb72SThomas Huehn 
1599c00bb72SThomas Huehn 	p += sprintf(p, "\n");
160a0c391b1SJohannes Berg 	p += sprintf(p,
161506dbf90SFelix Fietkau 		     "              best    ____________rate__________    ____statistics___    _____last____    ______sum-of________\n");
162a0c391b1SJohannes Berg 	p += sprintf(p,
163506dbf90SFelix Fietkau 		     "mode guard #  rate   [name   idx airtime  max_tp]  [avg(tp) avg(prob)]  [retry|suc|att]  [#success | #attempts]\n");
16411b2357dSKarl Beldan 
1658a0ee4feSKarl Beldan 	p = minstrel_ht_stats_dump(mi, MINSTREL_CCK_GROUP, p);
1668a0ee4feSKarl Beldan 	for (i = 0; i < MINSTREL_CCK_GROUP; i++)
167a0497f9fSFelix Fietkau 		p = minstrel_ht_stats_dump(mi, i, p);
1689208247dSKarl Beldan 	for (i++; i < ARRAY_SIZE(mi->groups); i++)
1699208247dSKarl Beldan 		p = minstrel_ht_stats_dump(mi, i, p);
170ec8aa669SFelix Fietkau 
171ec8aa669SFelix Fietkau 	p += sprintf(p, "\nTotal packet count::    ideal %d      "
172ec8aa669SFelix Fietkau 			"lookaround %d\n",
173ec8aa669SFelix Fietkau 			max(0, (int) mi->total_packets - (int) mi->sample_packets),
174ec8aa669SFelix Fietkau 			mi->sample_packets);
17577f7ffdcSFelix Fietkau 	if (mi->avg_ampdu_len)
1769c00bb72SThomas Huehn 		p += sprintf(p, "Average # of aggregated frames per A-MPDU: %d.%d\n",
177ec8aa669SFelix Fietkau 			MINSTREL_TRUNC(mi->avg_ampdu_len),
178ec8aa669SFelix Fietkau 			MINSTREL_TRUNC(mi->avg_ampdu_len * 10) % 10);
179ec8aa669SFelix Fietkau 	ms->len = p - ms->buf;
1809208247dSKarl Beldan 	WARN_ON(ms->len + sizeof(*ms) > 32768);
18111b2357dSKarl Beldan 
182a0572d93SArnd Bergmann 	return nonseekable_open(inode, file);
183ec8aa669SFelix Fietkau }
184ec8aa669SFelix Fietkau 
185ec8aa669SFelix Fietkau static const struct file_operations minstrel_ht_stat_fops = {
186ec8aa669SFelix Fietkau 	.owner = THIS_MODULE,
187ec8aa669SFelix Fietkau 	.open = minstrel_ht_stats_open,
188ec8aa669SFelix Fietkau 	.read = minstrel_stats_read,
189ec8aa669SFelix Fietkau 	.release = minstrel_stats_release,
190a0572d93SArnd Bergmann 	.llseek = no_llseek,
191ec8aa669SFelix Fietkau };
192ec8aa669SFelix Fietkau 
1932cae0b6aSThomas Huehn static char *
minstrel_ht_stats_csv_dump(struct minstrel_ht_sta * mi,int i,char * p)1942cae0b6aSThomas Huehn minstrel_ht_stats_csv_dump(struct minstrel_ht_sta *mi, int i, char *p)
1952cae0b6aSThomas Huehn {
1962cae0b6aSThomas Huehn 	const struct mcs_group *mg;
1971109dc39SFelix Fietkau 	unsigned int j, tp_max, tp_avg, eprob, tx_time;
1982cae0b6aSThomas Huehn 	char htmode = '2';
1992cae0b6aSThomas Huehn 	char gimode = 'L';
2002cae0b6aSThomas Huehn 	u32 gflags;
2012cae0b6aSThomas Huehn 
20241d08583SFelix Fietkau 	if (!mi->supported[i])
2032cae0b6aSThomas Huehn 		return p;
2042cae0b6aSThomas Huehn 
2052cae0b6aSThomas Huehn 	mg = &minstrel_mcs_groups[i];
2062cae0b6aSThomas Huehn 	gflags = mg->flags;
2072cae0b6aSThomas Huehn 
2082cae0b6aSThomas Huehn 	if (gflags & IEEE80211_TX_RC_40_MHZ_WIDTH)
2092cae0b6aSThomas Huehn 		htmode = '4';
2102cae0b6aSThomas Huehn 	else if (gflags & IEEE80211_TX_RC_80_MHZ_WIDTH)
2112cae0b6aSThomas Huehn 		htmode = '8';
2122cae0b6aSThomas Huehn 	if (gflags & IEEE80211_TX_RC_SHORT_GI)
2132cae0b6aSThomas Huehn 		gimode = 'S';
2142cae0b6aSThomas Huehn 
2152cae0b6aSThomas Huehn 	for (j = 0; j < MCS_GROUP_RATES; j++) {
2169134073bSThomas Huehn 		struct minstrel_rate_stats *mrs = &mi->groups[i].rates[j];
217a42fa256SFelix Fietkau 		int idx = MI_RATE(i, j);
218202df504SFelix Fietkau 		unsigned int duration;
2192cae0b6aSThomas Huehn 
22041d08583SFelix Fietkau 		if (!(mi->supported[i] & BIT(j)))
2212cae0b6aSThomas Huehn 			continue;
2222cae0b6aSThomas Huehn 
2232cae0b6aSThomas Huehn 		if (gflags & IEEE80211_TX_RC_MCS) {
2242cae0b6aSThomas Huehn 			p += sprintf(p, "HT%c0,", htmode);
2252cae0b6aSThomas Huehn 			p += sprintf(p, "%cGI,", gimode);
2262cae0b6aSThomas Huehn 			p += sprintf(p, "%d,", mg->streams);
2272cae0b6aSThomas Huehn 		} else if (gflags & IEEE80211_TX_RC_VHT_MCS) {
2282cae0b6aSThomas Huehn 			p += sprintf(p, "VHT%c0,", htmode);
2292cae0b6aSThomas Huehn 			p += sprintf(p, "%cGI,", gimode);
2302cae0b6aSThomas Huehn 			p += sprintf(p, "%d,", mg->streams);
231a7844a53SFelix Fietkau 		} else if (i == MINSTREL_OFDM_GROUP) {
232a7844a53SFelix Fietkau 			p += sprintf(p, "OFDM,,1,");
2332cae0b6aSThomas Huehn 		} else {
2342cae0b6aSThomas Huehn 			p += sprintf(p, "CCK,");
2352cae0b6aSThomas Huehn 			p += sprintf(p, "%cP,", j < 4 ? 'L' : 'S');
2362cae0b6aSThomas Huehn 			p += sprintf(p, "1,");
2372cae0b6aSThomas Huehn 		}
2382cae0b6aSThomas Huehn 
2392cae0b6aSThomas Huehn 		p += sprintf(p, "%s" ,((idx == mi->max_tp_rate[0]) ? "A" : ""));
2402cae0b6aSThomas Huehn 		p += sprintf(p, "%s" ,((idx == mi->max_tp_rate[1]) ? "B" : ""));
2412cae0b6aSThomas Huehn 		p += sprintf(p, "%s" ,((idx == mi->max_tp_rate[2]) ? "C" : ""));
2422cae0b6aSThomas Huehn 		p += sprintf(p, "%s" ,((idx == mi->max_tp_rate[3]) ? "D" : ""));
2432cae0b6aSThomas Huehn 		p += sprintf(p, "%s" ,((idx == mi->max_prob_rate) ? "P" : ""));
244*4a8d0c99SFelix Fietkau 		p += sprintf(p, "%s", (minstrel_ht_is_sample_rate(mi, idx) ? "S" : ""));
2452cae0b6aSThomas Huehn 
2462cae0b6aSThomas Huehn 		if (gflags & IEEE80211_TX_RC_MCS) {
2472cae0b6aSThomas Huehn 			p += sprintf(p, ",MCS%-2u,", (mg->streams - 1) * 8 + j);
2482cae0b6aSThomas Huehn 		} else if (gflags & IEEE80211_TX_RC_VHT_MCS) {
2492cae0b6aSThomas Huehn 			p += sprintf(p, ",MCS%-1u/%1u,", j, mg->streams);
2502cae0b6aSThomas Huehn 		} else {
251a7844a53SFelix Fietkau 			int r;
252a7844a53SFelix Fietkau 
253a7844a53SFelix Fietkau 			if (i == MINSTREL_OFDM_GROUP)
254a7844a53SFelix Fietkau 				r = minstrel_ofdm_bitrates[j % 8];
255a7844a53SFelix Fietkau 			else
256a7844a53SFelix Fietkau 				r = minstrel_cck_bitrates[j % 4];
257a7844a53SFelix Fietkau 
2582cae0b6aSThomas Huehn 			p += sprintf(p, ",%2u.%1uM,", r / 10, r % 10);
2592cae0b6aSThomas Huehn 		}
2602cae0b6aSThomas Huehn 
2612cae0b6aSThomas Huehn 		p += sprintf(p, "%u,", idx);
262202df504SFelix Fietkau 
263202df504SFelix Fietkau 		duration = mg->duration[j];
264202df504SFelix Fietkau 		duration <<= mg->shift;
265202df504SFelix Fietkau 		tx_time = DIV_ROUND_CLOSEST(duration, 1000);
2662cae0b6aSThomas Huehn 		p += sprintf(p, "%u,", tx_time);
2672cae0b6aSThomas Huehn 
26850e55a8eSThomas Huehn 		tp_max = minstrel_ht_get_tp_avg(mi, i, j, MINSTREL_FRAC(100, 100));
2695f63afe0SFelix Fietkau 		tp_avg = minstrel_ht_get_tp_avg(mi, i, j, mrs->prob_avg);
2705f63afe0SFelix Fietkau 		eprob = MINSTREL_TRUNC(mrs->prob_avg * 1000);
2712cae0b6aSThomas Huehn 
272506dbf90SFelix Fietkau 		p += sprintf(p, "%u.%u,%u.%u,%u.%u,%u,%u,"
2735f919abcSThomas Huehn 				"%u,%llu,%llu,",
27450e55a8eSThomas Huehn 				tp_max / 10, tp_max % 10,
2756a27b2c4SThomas Huehn 				tp_avg / 10, tp_avg % 10,
2762cae0b6aSThomas Huehn 				eprob / 10, eprob % 10,
2779134073bSThomas Huehn 				mrs->retry_count,
2789134073bSThomas Huehn 				mrs->last_success,
2799134073bSThomas Huehn 				mrs->last_attempts,
2809134073bSThomas Huehn 				(unsigned long long)mrs->succ_hist,
2819134073bSThomas Huehn 				(unsigned long long)mrs->att_hist);
2822cae0b6aSThomas Huehn 		p += sprintf(p, "%d,%d,%d.%d\n",
2832cae0b6aSThomas Huehn 				max(0, (int) mi->total_packets -
2842cae0b6aSThomas Huehn 				(int) mi->sample_packets),
2852cae0b6aSThomas Huehn 				mi->sample_packets,
2862cae0b6aSThomas Huehn 				MINSTREL_TRUNC(mi->avg_ampdu_len),
2872cae0b6aSThomas Huehn 				MINSTREL_TRUNC(mi->avg_ampdu_len * 10) % 10);
2882cae0b6aSThomas Huehn 	}
2892cae0b6aSThomas Huehn 
2902cae0b6aSThomas Huehn 	return p;
2912cae0b6aSThomas Huehn }
2922cae0b6aSThomas Huehn 
2932cae0b6aSThomas Huehn static int
minstrel_ht_stats_csv_open(struct inode * inode,struct file * file)2942cae0b6aSThomas Huehn minstrel_ht_stats_csv_open(struct inode *inode, struct file *file)
2952cae0b6aSThomas Huehn {
296cbda98c7SFelix Fietkau 	struct minstrel_ht_sta *mi = inode->i_private;
2972cae0b6aSThomas Huehn 	struct minstrel_debugfs_info *ms;
2982cae0b6aSThomas Huehn 	unsigned int i;
2992cae0b6aSThomas Huehn 	char *p;
3002cae0b6aSThomas Huehn 
3012cae0b6aSThomas Huehn 	ms = kmalloc(32768, GFP_KERNEL);
3022cae0b6aSThomas Huehn 	if (!ms)
3032cae0b6aSThomas Huehn 		return -ENOMEM;
3042cae0b6aSThomas Huehn 
3052cae0b6aSThomas Huehn 	file->private_data = ms;
3062cae0b6aSThomas Huehn 
3072cae0b6aSThomas Huehn 	p = ms->buf;
3082cae0b6aSThomas Huehn 
3092cae0b6aSThomas Huehn 	p = minstrel_ht_stats_csv_dump(mi, MINSTREL_CCK_GROUP, p);
3102cae0b6aSThomas Huehn 	for (i = 0; i < MINSTREL_CCK_GROUP; i++)
3112cae0b6aSThomas Huehn 		p = minstrel_ht_stats_csv_dump(mi, i, p);
3122cae0b6aSThomas Huehn 	for (i++; i < ARRAY_SIZE(mi->groups); i++)
3132cae0b6aSThomas Huehn 		p = minstrel_ht_stats_csv_dump(mi, i, p);
3142cae0b6aSThomas Huehn 
3152cae0b6aSThomas Huehn 	ms->len = p - ms->buf;
3162cae0b6aSThomas Huehn 	WARN_ON(ms->len + sizeof(*ms) > 32768);
3172cae0b6aSThomas Huehn 
3182cae0b6aSThomas Huehn 	return nonseekable_open(inode, file);
3192cae0b6aSThomas Huehn }
3202cae0b6aSThomas Huehn 
3212cae0b6aSThomas Huehn static const struct file_operations minstrel_ht_stat_csv_fops = {
3222cae0b6aSThomas Huehn 	.owner = THIS_MODULE,
3232cae0b6aSThomas Huehn 	.open = minstrel_ht_stats_csv_open,
3242cae0b6aSThomas Huehn 	.read = minstrel_stats_read,
3252cae0b6aSThomas Huehn 	.release = minstrel_stats_release,
3262cae0b6aSThomas Huehn 	.llseek = no_llseek,
3272cae0b6aSThomas Huehn };
3282cae0b6aSThomas Huehn 
329ec8aa669SFelix Fietkau void
minstrel_ht_add_sta_debugfs(void * priv,void * priv_sta,struct dentry * dir)330ec8aa669SFelix Fietkau minstrel_ht_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir)
331ec8aa669SFelix Fietkau {
332cbda98c7SFelix Fietkau 	debugfs_create_file("rc_stats", 0444, dir, priv_sta,
333ec8aa669SFelix Fietkau 			    &minstrel_ht_stat_fops);
334cbda98c7SFelix Fietkau 	debugfs_create_file("rc_stats_csv", 0444, dir, priv_sta,
335d6444062SJoe Perches 			    &minstrel_ht_stat_csv_fops);
336ec8aa669SFelix Fietkau }
337