rc80211_minstrel_ht_debugfs.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. * Copyright (C) 2010 Felix Fietkau <nbd@openwrt.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/netdevice.h>
  9. #include <linux/types.h>
  10. #include <linux/skbuff.h>
  11. #include <linux/debugfs.h>
  12. #include <linux/ieee80211.h>
  13. #include <linux/export.h>
  14. #include <net/mac80211.h>
  15. #include "rc80211_minstrel.h"
  16. #include "rc80211_minstrel_ht.h"
  17. static char *
  18. minstrel_ht_stats_dump(struct minstrel_ht_sta *mi, int i, char *p)
  19. {
  20. const struct mcs_group *mg;
  21. unsigned int j, tp_max, tp_avg, prob, eprob, tx_time;
  22. char htmode = '2';
  23. char gimode = 'L';
  24. u32 gflags;
  25. if (!mi->groups[i].supported)
  26. return p;
  27. mg = &minstrel_mcs_groups[i];
  28. gflags = mg->flags;
  29. if (gflags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  30. htmode = '4';
  31. else if (gflags & IEEE80211_TX_RC_80_MHZ_WIDTH)
  32. htmode = '8';
  33. if (gflags & IEEE80211_TX_RC_SHORT_GI)
  34. gimode = 'S';
  35. for (j = 0; j < MCS_GROUP_RATES; j++) {
  36. struct minstrel_rate_stats *mrs = &mi->groups[i].rates[j];
  37. static const int bitrates[4] = { 10, 20, 55, 110 };
  38. int idx = i * MCS_GROUP_RATES + j;
  39. if (!(mi->groups[i].supported & BIT(j)))
  40. continue;
  41. if (gflags & IEEE80211_TX_RC_MCS) {
  42. p += sprintf(p, "HT%c0 ", htmode);
  43. p += sprintf(p, "%cGI ", gimode);
  44. p += sprintf(p, "%d ", mg->streams);
  45. } else if (gflags & IEEE80211_TX_RC_VHT_MCS) {
  46. p += sprintf(p, "VHT%c0 ", htmode);
  47. p += sprintf(p, "%cGI ", gimode);
  48. p += sprintf(p, "%d ", mg->streams);
  49. } else {
  50. p += sprintf(p, "CCK ");
  51. p += sprintf(p, "%cP ", j < 4 ? 'L' : 'S');
  52. p += sprintf(p, "1 ");
  53. }
  54. *(p++) = (idx == mi->max_tp_rate[0]) ? 'A' : ' ';
  55. *(p++) = (idx == mi->max_tp_rate[1]) ? 'B' : ' ';
  56. *(p++) = (idx == mi->max_tp_rate[2]) ? 'C' : ' ';
  57. *(p++) = (idx == mi->max_tp_rate[3]) ? 'D' : ' ';
  58. *(p++) = (idx == mi->max_prob_rate) ? 'P' : ' ';
  59. if (gflags & IEEE80211_TX_RC_MCS) {
  60. p += sprintf(p, " MCS%-2u", (mg->streams - 1) * 8 + j);
  61. } else if (gflags & IEEE80211_TX_RC_VHT_MCS) {
  62. p += sprintf(p, " MCS%-1u/%1u", j, mg->streams);
  63. } else {
  64. int r = bitrates[j % 4];
  65. p += sprintf(p, " %2u.%1uM", r / 10, r % 10);
  66. }
  67. p += sprintf(p, " %3u ", idx);
  68. /* tx_time[rate(i)] in usec */
  69. tx_time = DIV_ROUND_CLOSEST(mg->duration[j], 1000);
  70. p += sprintf(p, "%6u ", tx_time);
  71. tp_max = minstrel_ht_get_tp_avg(mi, i, j, MINSTREL_FRAC(100, 100));
  72. tp_avg = minstrel_ht_get_tp_avg(mi, i, j, mrs->prob_ewma);
  73. prob = MINSTREL_TRUNC(mrs->cur_prob * 1000);
  74. eprob = MINSTREL_TRUNC(mrs->prob_ewma * 1000);
  75. p += sprintf(p, "%4u.%1u %4u.%1u %3u.%1u %3u.%1u"
  76. " %3u.%1u %3u %3u %-3u "
  77. "%9llu %-9llu\n",
  78. tp_max / 10, tp_max % 10,
  79. tp_avg / 10, tp_avg % 10,
  80. eprob / 10, eprob % 10,
  81. mrs->prob_ewmsd / 10, mrs->prob_ewmsd % 10,
  82. prob / 10, prob % 10,
  83. mrs->retry_count,
  84. mrs->last_success,
  85. mrs->last_attempts,
  86. (unsigned long long)mrs->succ_hist,
  87. (unsigned long long)mrs->att_hist);
  88. }
  89. return p;
  90. }
  91. static int
  92. minstrel_ht_stats_open(struct inode *inode, struct file *file)
  93. {
  94. struct minstrel_ht_sta_priv *msp = inode->i_private;
  95. struct minstrel_ht_sta *mi = &msp->ht;
  96. struct minstrel_debugfs_info *ms;
  97. unsigned int i;
  98. int ret;
  99. char *p;
  100. if (!msp->is_ht) {
  101. inode->i_private = &msp->legacy;
  102. ret = minstrel_stats_open(inode, file);
  103. inode->i_private = msp;
  104. return ret;
  105. }
  106. ms = kmalloc(32768, GFP_KERNEL);
  107. if (!ms)
  108. return -ENOMEM;
  109. file->private_data = ms;
  110. p = ms->buf;
  111. p += sprintf(p, "\n");
  112. p += sprintf(p,
  113. " best ____________rate__________ ________statistics________ ________last_______ ______sum-of________\n");
  114. p += sprintf(p,
  115. "mode guard # rate [name idx airtime max_tp] [avg(tp) avg(prob) sd(prob)] [prob.|retry|suc|att] [#success | #attempts]\n");
  116. p = minstrel_ht_stats_dump(mi, MINSTREL_CCK_GROUP, p);
  117. for (i = 0; i < MINSTREL_CCK_GROUP; i++)
  118. p = minstrel_ht_stats_dump(mi, i, p);
  119. for (i++; i < ARRAY_SIZE(mi->groups); i++)
  120. p = minstrel_ht_stats_dump(mi, i, p);
  121. p += sprintf(p, "\nTotal packet count:: ideal %d "
  122. "lookaround %d\n",
  123. max(0, (int) mi->total_packets - (int) mi->sample_packets),
  124. mi->sample_packets);
  125. p += sprintf(p, "Average # of aggregated frames per A-MPDU: %d.%d\n",
  126. MINSTREL_TRUNC(mi->avg_ampdu_len),
  127. MINSTREL_TRUNC(mi->avg_ampdu_len * 10) % 10);
  128. ms->len = p - ms->buf;
  129. WARN_ON(ms->len + sizeof(*ms) > 32768);
  130. return nonseekable_open(inode, file);
  131. }
  132. static const struct file_operations minstrel_ht_stat_fops = {
  133. .owner = THIS_MODULE,
  134. .open = minstrel_ht_stats_open,
  135. .read = minstrel_stats_read,
  136. .release = minstrel_stats_release,
  137. .llseek = no_llseek,
  138. };
  139. static char *
  140. minstrel_ht_stats_csv_dump(struct minstrel_ht_sta *mi, int i, char *p)
  141. {
  142. const struct mcs_group *mg;
  143. unsigned int j, tp_max, tp_avg, prob, eprob, tx_time;
  144. char htmode = '2';
  145. char gimode = 'L';
  146. u32 gflags;
  147. if (!mi->groups[i].supported)
  148. return p;
  149. mg = &minstrel_mcs_groups[i];
  150. gflags = mg->flags;
  151. if (gflags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  152. htmode = '4';
  153. else if (gflags & IEEE80211_TX_RC_80_MHZ_WIDTH)
  154. htmode = '8';
  155. if (gflags & IEEE80211_TX_RC_SHORT_GI)
  156. gimode = 'S';
  157. for (j = 0; j < MCS_GROUP_RATES; j++) {
  158. struct minstrel_rate_stats *mrs = &mi->groups[i].rates[j];
  159. static const int bitrates[4] = { 10, 20, 55, 110 };
  160. int idx = i * MCS_GROUP_RATES + j;
  161. if (!(mi->groups[i].supported & BIT(j)))
  162. continue;
  163. if (gflags & IEEE80211_TX_RC_MCS) {
  164. p += sprintf(p, "HT%c0,", htmode);
  165. p += sprintf(p, "%cGI,", gimode);
  166. p += sprintf(p, "%d,", mg->streams);
  167. } else if (gflags & IEEE80211_TX_RC_VHT_MCS) {
  168. p += sprintf(p, "VHT%c0,", htmode);
  169. p += sprintf(p, "%cGI,", gimode);
  170. p += sprintf(p, "%d,", mg->streams);
  171. } else {
  172. p += sprintf(p, "CCK,");
  173. p += sprintf(p, "%cP,", j < 4 ? 'L' : 'S');
  174. p += sprintf(p, "1,");
  175. }
  176. p += sprintf(p, "%s" ,((idx == mi->max_tp_rate[0]) ? "A" : ""));
  177. p += sprintf(p, "%s" ,((idx == mi->max_tp_rate[1]) ? "B" : ""));
  178. p += sprintf(p, "%s" ,((idx == mi->max_tp_rate[2]) ? "C" : ""));
  179. p += sprintf(p, "%s" ,((idx == mi->max_tp_rate[3]) ? "D" : ""));
  180. p += sprintf(p, "%s" ,((idx == mi->max_prob_rate) ? "P" : ""));
  181. if (gflags & IEEE80211_TX_RC_MCS) {
  182. p += sprintf(p, ",MCS%-2u,", (mg->streams - 1) * 8 + j);
  183. } else if (gflags & IEEE80211_TX_RC_VHT_MCS) {
  184. p += sprintf(p, ",MCS%-1u/%1u,", j, mg->streams);
  185. } else {
  186. int r = bitrates[j % 4];
  187. p += sprintf(p, ",%2u.%1uM,", r / 10, r % 10);
  188. }
  189. p += sprintf(p, "%u,", idx);
  190. tx_time = DIV_ROUND_CLOSEST(mg->duration[j], 1000);
  191. p += sprintf(p, "%u,", tx_time);
  192. tp_max = minstrel_ht_get_tp_avg(mi, i, j, MINSTREL_FRAC(100, 100));
  193. tp_avg = minstrel_ht_get_tp_avg(mi, i, j, mrs->prob_ewma);
  194. prob = MINSTREL_TRUNC(mrs->cur_prob * 1000);
  195. eprob = MINSTREL_TRUNC(mrs->prob_ewma * 1000);
  196. p += sprintf(p, "%u.%u,%u.%u,%u.%u,%u.%u,%u.%u,%u,%u,"
  197. "%u,%llu,%llu,",
  198. tp_max / 10, tp_max % 10,
  199. tp_avg / 10, tp_avg % 10,
  200. eprob / 10, eprob % 10,
  201. mrs->prob_ewmsd / 10, mrs->prob_ewmsd % 10,
  202. prob / 10, prob % 10,
  203. mrs->retry_count,
  204. mrs->last_success,
  205. mrs->last_attempts,
  206. (unsigned long long)mrs->succ_hist,
  207. (unsigned long long)mrs->att_hist);
  208. p += sprintf(p, "%d,%d,%d.%d\n",
  209. max(0, (int) mi->total_packets -
  210. (int) mi->sample_packets),
  211. mi->sample_packets,
  212. MINSTREL_TRUNC(mi->avg_ampdu_len),
  213. MINSTREL_TRUNC(mi->avg_ampdu_len * 10) % 10);
  214. }
  215. return p;
  216. }
  217. static int
  218. minstrel_ht_stats_csv_open(struct inode *inode, struct file *file)
  219. {
  220. struct minstrel_ht_sta_priv *msp = inode->i_private;
  221. struct minstrel_ht_sta *mi = &msp->ht;
  222. struct minstrel_debugfs_info *ms;
  223. unsigned int i;
  224. int ret;
  225. char *p;
  226. if (!msp->is_ht) {
  227. inode->i_private = &msp->legacy;
  228. ret = minstrel_stats_csv_open(inode, file);
  229. inode->i_private = msp;
  230. return ret;
  231. }
  232. ms = kmalloc(32768, GFP_KERNEL);
  233. if (!ms)
  234. return -ENOMEM;
  235. file->private_data = ms;
  236. p = ms->buf;
  237. p = minstrel_ht_stats_csv_dump(mi, MINSTREL_CCK_GROUP, p);
  238. for (i = 0; i < MINSTREL_CCK_GROUP; i++)
  239. p = minstrel_ht_stats_csv_dump(mi, i, p);
  240. for (i++; i < ARRAY_SIZE(mi->groups); i++)
  241. p = minstrel_ht_stats_csv_dump(mi, i, p);
  242. ms->len = p - ms->buf;
  243. WARN_ON(ms->len + sizeof(*ms) > 32768);
  244. return nonseekable_open(inode, file);
  245. }
  246. static const struct file_operations minstrel_ht_stat_csv_fops = {
  247. .owner = THIS_MODULE,
  248. .open = minstrel_ht_stats_csv_open,
  249. .read = minstrel_stats_read,
  250. .release = minstrel_stats_release,
  251. .llseek = no_llseek,
  252. };
  253. void
  254. minstrel_ht_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir)
  255. {
  256. struct minstrel_ht_sta_priv *msp = priv_sta;
  257. msp->dbg_stats = debugfs_create_file("rc_stats", S_IRUGO, dir, msp,
  258. &minstrel_ht_stat_fops);
  259. msp->dbg_stats_csv = debugfs_create_file("rc_stats_csv", S_IRUGO,
  260. dir, msp, &minstrel_ht_stat_csv_fops);
  261. }
  262. void
  263. minstrel_ht_remove_sta_debugfs(void *priv, void *priv_sta)
  264. {
  265. struct minstrel_ht_sta_priv *msp = priv_sta;
  266. debugfs_remove(msp->dbg_stats);
  267. debugfs_remove(msp->dbg_stats_csv);
  268. }