rc80211_minstrel_ht_debugfs.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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, eprob, tx_time;
  22. char htmode = '2';
  23. char gimode = 'L';
  24. u32 gflags;
  25. if (!mi->supported[i])
  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. unsigned int prob_ewmsd;
  40. if (!(mi->supported[i] & BIT(j)))
  41. continue;
  42. if (gflags & IEEE80211_TX_RC_MCS) {
  43. p += sprintf(p, "HT%c0 ", htmode);
  44. p += sprintf(p, "%cGI ", gimode);
  45. p += sprintf(p, "%d ", mg->streams);
  46. } else if (gflags & IEEE80211_TX_RC_VHT_MCS) {
  47. p += sprintf(p, "VHT%c0 ", htmode);
  48. p += sprintf(p, "%cGI ", gimode);
  49. p += sprintf(p, "%d ", mg->streams);
  50. } else {
  51. p += sprintf(p, "CCK ");
  52. p += sprintf(p, "%cP ", j < 4 ? 'L' : 'S');
  53. p += sprintf(p, "1 ");
  54. }
  55. *(p++) = (idx == mi->max_tp_rate[0]) ? 'A' : ' ';
  56. *(p++) = (idx == mi->max_tp_rate[1]) ? 'B' : ' ';
  57. *(p++) = (idx == mi->max_tp_rate[2]) ? 'C' : ' ';
  58. *(p++) = (idx == mi->max_tp_rate[3]) ? 'D' : ' ';
  59. *(p++) = (idx == mi->max_prob_rate) ? 'P' : ' ';
  60. if (gflags & IEEE80211_TX_RC_MCS) {
  61. p += sprintf(p, " MCS%-2u", (mg->streams - 1) * 8 + j);
  62. } else if (gflags & IEEE80211_TX_RC_VHT_MCS) {
  63. p += sprintf(p, " MCS%-1u/%1u", j, mg->streams);
  64. } else {
  65. int r = bitrates[j % 4];
  66. p += sprintf(p, " %2u.%1uM", r / 10, r % 10);
  67. }
  68. p += sprintf(p, " %3u ", idx);
  69. /* tx_time[rate(i)] in usec */
  70. tx_time = DIV_ROUND_CLOSEST(mg->duration[j], 1000);
  71. p += sprintf(p, "%6u ", tx_time);
  72. tp_max = minstrel_ht_get_tp_avg(mi, i, j, MINSTREL_FRAC(100, 100));
  73. tp_avg = minstrel_ht_get_tp_avg(mi, i, j, mrs->prob_ewma);
  74. eprob = MINSTREL_TRUNC(mrs->prob_ewma * 1000);
  75. prob_ewmsd = minstrel_get_ewmsd10(mrs);
  76. p += sprintf(p, "%4u.%1u %4u.%1u %3u.%1u %3u.%1u"
  77. " %3u %3u %-3u "
  78. "%9llu %-9llu\n",
  79. tp_max / 10, tp_max % 10,
  80. tp_avg / 10, tp_avg % 10,
  81. eprob / 10, eprob % 10,
  82. prob_ewmsd / 10, prob_ewmsd % 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)] [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, eprob, tx_time;
  144. char htmode = '2';
  145. char gimode = 'L';
  146. u32 gflags;
  147. if (!mi->supported[i])
  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. unsigned int prob_ewmsd;
  162. if (!(mi->supported[i] & BIT(j)))
  163. continue;
  164. if (gflags & IEEE80211_TX_RC_MCS) {
  165. p += sprintf(p, "HT%c0,", htmode);
  166. p += sprintf(p, "%cGI,", gimode);
  167. p += sprintf(p, "%d,", mg->streams);
  168. } else if (gflags & IEEE80211_TX_RC_VHT_MCS) {
  169. p += sprintf(p, "VHT%c0,", htmode);
  170. p += sprintf(p, "%cGI,", gimode);
  171. p += sprintf(p, "%d,", mg->streams);
  172. } else {
  173. p += sprintf(p, "CCK,");
  174. p += sprintf(p, "%cP,", j < 4 ? 'L' : 'S');
  175. p += sprintf(p, "1,");
  176. }
  177. p += sprintf(p, "%s" ,((idx == mi->max_tp_rate[0]) ? "A" : ""));
  178. p += sprintf(p, "%s" ,((idx == mi->max_tp_rate[1]) ? "B" : ""));
  179. p += sprintf(p, "%s" ,((idx == mi->max_tp_rate[2]) ? "C" : ""));
  180. p += sprintf(p, "%s" ,((idx == mi->max_tp_rate[3]) ? "D" : ""));
  181. p += sprintf(p, "%s" ,((idx == mi->max_prob_rate) ? "P" : ""));
  182. if (gflags & IEEE80211_TX_RC_MCS) {
  183. p += sprintf(p, ",MCS%-2u,", (mg->streams - 1) * 8 + j);
  184. } else if (gflags & IEEE80211_TX_RC_VHT_MCS) {
  185. p += sprintf(p, ",MCS%-1u/%1u,", j, mg->streams);
  186. } else {
  187. int r = bitrates[j % 4];
  188. p += sprintf(p, ",%2u.%1uM,", r / 10, r % 10);
  189. }
  190. p += sprintf(p, "%u,", idx);
  191. tx_time = DIV_ROUND_CLOSEST(mg->duration[j], 1000);
  192. p += sprintf(p, "%u,", tx_time);
  193. tp_max = minstrel_ht_get_tp_avg(mi, i, j, MINSTREL_FRAC(100, 100));
  194. tp_avg = minstrel_ht_get_tp_avg(mi, i, j, mrs->prob_ewma);
  195. eprob = MINSTREL_TRUNC(mrs->prob_ewma * 1000);
  196. prob_ewmsd = minstrel_get_ewmsd10(mrs);
  197. p += sprintf(p, "%u.%u,%u.%u,%u.%u,%u.%u,%u,%u,"
  198. "%u,%llu,%llu,",
  199. tp_max / 10, tp_max % 10,
  200. tp_avg / 10, tp_avg % 10,
  201. eprob / 10, eprob % 10,
  202. prob_ewmsd / 10, prob_ewmsd % 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", 0444, dir, msp,
  258. &minstrel_ht_stat_fops);
  259. msp->dbg_stats_csv = debugfs_create_file("rc_stats_csv", 0444, dir, msp,
  260. &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. }