rc80211_minstrel_ht_debugfs.c 8.9 KB

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