311-mac80211-use-rate-provided-via-status-rate-on-ieee80.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. From: Felix Fietkau <[email protected]>
  2. Date: Wed, 12 Aug 2020 17:04:22 +0200
  3. Subject: [PATCH] mac80211: use rate provided via status->rate on
  4. ieee80211_tx_status_ext for AQL
  5. Since ieee80211_tx_info does not have enough room to encode HE rates, HE
  6. drivers use status->rate to provide rate info.
  7. Store it in struct sta_info and use it for AQL.
  8. Signed-off-by: Felix Fietkau <[email protected]>
  9. ---
  10. --- a/net/mac80211/airtime.c
  11. +++ b/net/mac80211/airtime.c
  12. @@ -487,14 +487,61 @@ u32 ieee80211_calc_rx_airtime(struct iee
  13. }
  14. EXPORT_SYMBOL_GPL(ieee80211_calc_rx_airtime);
  15. +static bool ieee80211_fill_rate_info(struct ieee80211_hw *hw,
  16. + struct ieee80211_rx_status *stat, u8 band,
  17. + struct rate_info *ri)
  18. +{
  19. + struct ieee80211_supported_band *sband = hw->wiphy->bands[band];
  20. + int i;
  21. +
  22. + if (!ri || !sband)
  23. + return false;
  24. +
  25. + stat->bw = ri->bw;
  26. + stat->nss = ri->nss;
  27. + stat->rate_idx = ri->mcs;
  28. +
  29. + if (ri->flags & RATE_INFO_FLAGS_HE_MCS)
  30. + stat->encoding = RX_ENC_HE;
  31. + else if (ri->flags & RATE_INFO_FLAGS_VHT_MCS)
  32. + stat->encoding = RX_ENC_VHT;
  33. + else if (ri->flags & RATE_INFO_FLAGS_MCS)
  34. + stat->encoding = RX_ENC_HT;
  35. + else
  36. + stat->encoding = RX_ENC_LEGACY;
  37. +
  38. + if (ri->flags & RATE_INFO_FLAGS_SHORT_GI)
  39. + stat->enc_flags |= RX_ENC_FLAG_SHORT_GI;
  40. +
  41. + stat->he_gi = ri->he_gi;
  42. +
  43. + if (stat->encoding != RX_ENC_LEGACY)
  44. + return true;
  45. +
  46. + stat->rate_idx = 0;
  47. + for (i = 0; i < sband->n_bitrates; i++) {
  48. + if (ri->legacy != sband->bitrates[i].bitrate)
  49. + continue;
  50. +
  51. + stat->rate_idx = i;
  52. + return true;
  53. + }
  54. +
  55. + return false;
  56. +}
  57. +
  58. static u32 ieee80211_calc_tx_airtime_rate(struct ieee80211_hw *hw,
  59. struct ieee80211_tx_rate *rate,
  60. + struct rate_info *ri,
  61. u8 band, int len)
  62. {
  63. struct ieee80211_rx_status stat = {
  64. .band = band,
  65. };
  66. + if (ieee80211_fill_rate_info(hw, &stat, band, ri))
  67. + goto out;
  68. +
  69. if (rate->idx < 0 || !rate->count)
  70. return 0;
  71. @@ -522,6 +569,7 @@ static u32 ieee80211_calc_tx_airtime_rat
  72. stat.encoding = RX_ENC_LEGACY;
  73. }
  74. +out:
  75. return ieee80211_calc_rx_airtime(hw, &stat, len);
  76. }
  77. @@ -536,7 +584,7 @@ u32 ieee80211_calc_tx_airtime(struct iee
  78. struct ieee80211_tx_rate *rate = &info->status.rates[i];
  79. u32 cur_duration;
  80. - cur_duration = ieee80211_calc_tx_airtime_rate(hw, rate,
  81. + cur_duration = ieee80211_calc_tx_airtime_rate(hw, rate, NULL,
  82. info->band, len);
  83. if (!cur_duration)
  84. break;
  85. @@ -573,6 +621,7 @@ u32 ieee80211_calc_expected_tx_airtime(s
  86. struct sta_info *sta = container_of(pubsta, struct sta_info,
  87. sta);
  88. struct ieee80211_tx_rate *rate = &sta->tx_stats.last_rate;
  89. + struct rate_info *ri = &sta->tx_stats.last_rate_info;
  90. u32 airtime;
  91. if (!(rate->flags & (IEEE80211_TX_RC_VHT_MCS |
  92. @@ -586,7 +635,7 @@ u32 ieee80211_calc_expected_tx_airtime(s
  93. * This will not be very accurate, but much better than simply
  94. * assuming un-aggregated tx.
  95. */
  96. - airtime = ieee80211_calc_tx_airtime_rate(hw, rate, band,
  97. + airtime = ieee80211_calc_tx_airtime_rate(hw, rate, ri, band,
  98. ampdu ? len * 16 : len);
  99. if (ampdu)
  100. airtime /= 16;
  101. --- a/net/mac80211/sta_info.h
  102. +++ b/net/mac80211/sta_info.h
  103. @@ -609,6 +609,7 @@ struct sta_info {
  104. u64 packets[IEEE80211_NUM_ACS];
  105. u64 bytes[IEEE80211_NUM_ACS];
  106. struct ieee80211_tx_rate last_rate;
  107. + struct rate_info last_rate_info;
  108. u64 msdu[IEEE80211_NUM_TIDS + 1];
  109. } tx_stats;
  110. u16 tid_seq[IEEE80211_QOS_CTL_TID_MASK + 1];
  111. --- a/net/mac80211/status.c
  112. +++ b/net/mac80211/status.c
  113. @@ -1147,9 +1147,17 @@ void ieee80211_tx_status_ext(struct ieee
  114. struct ieee80211_tx_info *info = status->info;
  115. struct ieee80211_sta *pubsta = status->sta;
  116. struct ieee80211_supported_band *sband;
  117. + struct sta_info *sta;
  118. int retry_count;
  119. bool acked, noack_success;
  120. + if (pubsta) {
  121. + sta = container_of(pubsta, struct sta_info, sta);
  122. +
  123. + if (status->rate)
  124. + sta->tx_stats.last_rate_info = *status->rate;
  125. + }
  126. +
  127. if (status->skb)
  128. return __ieee80211_tx_status(hw, status);
  129. @@ -1164,10 +1172,6 @@ void ieee80211_tx_status_ext(struct ieee
  130. noack_success = !!(info->flags & IEEE80211_TX_STAT_NOACK_TRANSMITTED);
  131. if (pubsta) {
  132. - struct sta_info *sta;
  133. -
  134. - sta = container_of(pubsta, struct sta_info, sta);
  135. -
  136. if (!acked && !noack_success)
  137. sta->status_stats.retry_failed++;
  138. sta->status_stats.retry_count += retry_count;