rc80211_minstrel_ht_debugfs.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 int
  18. minstrel_ht_stats_open(struct inode *inode, struct file *file)
  19. {
  20. struct minstrel_ht_sta_priv *msp = inode->i_private;
  21. struct minstrel_ht_sta *mi = &msp->ht;
  22. struct minstrel_debugfs_info *ms;
  23. unsigned int i, j, tp, prob, eprob;
  24. char *p;
  25. int ret;
  26. if (!msp->is_ht) {
  27. inode->i_private = &msp->legacy;
  28. ret = minstrel_stats_open(inode, file);
  29. inode->i_private = msp;
  30. return ret;
  31. }
  32. ms = kmalloc(sizeof(*ms) + 8192, GFP_KERNEL);
  33. if (!ms)
  34. return -ENOMEM;
  35. file->private_data = ms;
  36. p = ms->buf;
  37. p += sprintf(p, "type rate throughput ewma prob this prob "
  38. "this succ/attempt success attempts\n");
  39. for (i = 0; i < MINSTREL_MAX_STREAMS * MINSTREL_STREAM_GROUPS; i++) {
  40. char htmode = '2';
  41. char gimode = 'L';
  42. if (!mi->groups[i].supported)
  43. continue;
  44. if (minstrel_mcs_groups[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  45. htmode = '4';
  46. if (minstrel_mcs_groups[i].flags & IEEE80211_TX_RC_SHORT_GI)
  47. gimode = 'S';
  48. for (j = 0; j < MCS_GROUP_RATES; j++) {
  49. struct minstrel_rate_stats *mr = &mi->groups[i].rates[j];
  50. int idx = i * MCS_GROUP_RATES + j;
  51. if (!(mi->groups[i].supported & BIT(j)))
  52. continue;
  53. p += sprintf(p, "HT%c0/%cGI ", htmode, gimode);
  54. *(p++) = (idx == mi->max_tp_rate) ? 'T' : ' ';
  55. *(p++) = (idx == mi->max_tp_rate2) ? 't' : ' ';
  56. *(p++) = (idx == mi->max_prob_rate) ? 'P' : ' ';
  57. p += sprintf(p, "MCS%-2u", (minstrel_mcs_groups[i].streams - 1) *
  58. MCS_GROUP_RATES + j);
  59. tp = mr->cur_tp / 10;
  60. prob = MINSTREL_TRUNC(mr->cur_prob * 1000);
  61. eprob = MINSTREL_TRUNC(mr->probability * 1000);
  62. p += sprintf(p, " %6u.%1u %6u.%1u %6u.%1u "
  63. "%3u(%3u) %8llu %8llu\n",
  64. tp / 10, tp % 10,
  65. eprob / 10, eprob % 10,
  66. prob / 10, prob % 10,
  67. mr->last_success,
  68. mr->last_attempts,
  69. (unsigned long long)mr->succ_hist,
  70. (unsigned long long)mr->att_hist);
  71. }
  72. }
  73. p += sprintf(p, "\nTotal packet count:: ideal %d "
  74. "lookaround %d\n",
  75. max(0, (int) mi->total_packets - (int) mi->sample_packets),
  76. mi->sample_packets);
  77. p += sprintf(p, "Average A-MPDU length: %d.%d\n",
  78. MINSTREL_TRUNC(mi->avg_ampdu_len),
  79. MINSTREL_TRUNC(mi->avg_ampdu_len * 10) % 10);
  80. ms->len = p - ms->buf;
  81. return nonseekable_open(inode, file);
  82. }
  83. static const struct file_operations minstrel_ht_stat_fops = {
  84. .owner = THIS_MODULE,
  85. .open = minstrel_ht_stats_open,
  86. .read = minstrel_stats_read,
  87. .release = minstrel_stats_release,
  88. .llseek = no_llseek,
  89. };
  90. void
  91. minstrel_ht_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir)
  92. {
  93. struct minstrel_ht_sta_priv *msp = priv_sta;
  94. msp->dbg_stats = debugfs_create_file("rc_stats", S_IRUGO, dir, msp,
  95. &minstrel_ht_stat_fops);
  96. }
  97. void
  98. minstrel_ht_remove_sta_debugfs(void *priv, void *priv_sta)
  99. {
  100. struct minstrel_ht_sta_priv *msp = priv_sta;
  101. debugfs_remove(msp->dbg_stats);
  102. }