312-mac80211-factor-out-code-to-look-up-the-average-pack.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. From: Felix Fietkau <[email protected]>
  2. Date: Wed, 12 Aug 2020 17:06:12 +0200
  3. Subject: [PATCH] mac80211: factor out code to look up the average packet
  4. length duration for a rate
  5. This will be used to enhance AQL estimated aggregation length
  6. Signed-off-by: Felix Fietkau <[email protected]>
  7. ---
  8. --- a/net/mac80211/airtime.c
  9. +++ b/net/mac80211/airtime.c
  10. @@ -405,18 +405,14 @@ ieee80211_calc_legacy_rate_duration(u16
  11. return duration;
  12. }
  13. -u32 ieee80211_calc_rx_airtime(struct ieee80211_hw *hw,
  14. - struct ieee80211_rx_status *status,
  15. - int len)
  16. +static u32 ieee80211_get_rate_duration(struct ieee80211_hw *hw,
  17. + struct ieee80211_rx_status *status,
  18. + u32 *overhead)
  19. {
  20. - struct ieee80211_supported_band *sband;
  21. - const struct ieee80211_rate *rate;
  22. bool sgi = status->enc_flags & RX_ENC_FLAG_SHORT_GI;
  23. - bool sp = status->enc_flags & RX_ENC_FLAG_SHORTPRE;
  24. int bw, streams;
  25. int group, idx;
  26. u32 duration;
  27. - bool cck;
  28. switch (status->bw) {
  29. case RATE_INFO_BW_20:
  30. @@ -437,20 +433,6 @@ u32 ieee80211_calc_rx_airtime(struct iee
  31. }
  32. switch (status->encoding) {
  33. - case RX_ENC_LEGACY:
  34. - if (WARN_ON_ONCE(status->band > NL80211_BAND_5GHZ))
  35. - return 0;
  36. -
  37. - sband = hw->wiphy->bands[status->band];
  38. - if (!sband || status->rate_idx >= sband->n_bitrates)
  39. - return 0;
  40. -
  41. - rate = &sband->bitrates[status->rate_idx];
  42. - cck = rate->flags & IEEE80211_RATE_MANDATORY_B;
  43. -
  44. - return ieee80211_calc_legacy_rate_duration(rate->bitrate, sp,
  45. - cck, len);
  46. -
  47. case RX_ENC_VHT:
  48. streams = status->nss;
  49. idx = status->rate_idx;
  50. @@ -477,13 +459,47 @@ u32 ieee80211_calc_rx_airtime(struct iee
  51. duration = airtime_mcs_groups[group].duration[idx];
  52. duration <<= airtime_mcs_groups[group].shift;
  53. + *overhead = 36 + (streams << 2);
  54. +
  55. + return duration;
  56. +}
  57. +
  58. +
  59. +u32 ieee80211_calc_rx_airtime(struct ieee80211_hw *hw,
  60. + struct ieee80211_rx_status *status,
  61. + int len)
  62. +{
  63. + struct ieee80211_supported_band *sband;
  64. + u32 duration, overhead = 0;
  65. +
  66. + if (status->encoding == RX_ENC_LEGACY) {
  67. + const struct ieee80211_rate *rate;
  68. + bool sp = status->enc_flags & RX_ENC_FLAG_SHORTPRE;
  69. + bool cck;
  70. +
  71. + if (WARN_ON_ONCE(status->band > NL80211_BAND_5GHZ))
  72. + return 0;
  73. +
  74. + sband = hw->wiphy->bands[status->band];
  75. + if (!sband || status->rate_idx >= sband->n_bitrates)
  76. + return 0;
  77. +
  78. + rate = &sband->bitrates[status->rate_idx];
  79. + cck = rate->flags & IEEE80211_RATE_MANDATORY_B;
  80. +
  81. + return ieee80211_calc_legacy_rate_duration(rate->bitrate, sp,
  82. + cck, len);
  83. + }
  84. +
  85. + duration = ieee80211_get_rate_duration(hw, status, &overhead);
  86. + if (!duration)
  87. + return 0;
  88. +
  89. duration *= len;
  90. duration /= AVG_PKT_SIZE;
  91. duration /= 1024;
  92. - duration += 36 + (streams << 2);
  93. -
  94. - return duration;
  95. + return duration + overhead;
  96. }
  97. EXPORT_SYMBOL_GPL(ieee80211_calc_rx_airtime);
  98. @@ -530,46 +546,57 @@ static bool ieee80211_fill_rate_info(str
  99. return false;
  100. }
  101. -static u32 ieee80211_calc_tx_airtime_rate(struct ieee80211_hw *hw,
  102. - struct ieee80211_tx_rate *rate,
  103. - struct rate_info *ri,
  104. - u8 band, int len)
  105. +static int ieee80211_fill_rx_status(struct ieee80211_rx_status *stat,
  106. + struct ieee80211_hw *hw,
  107. + struct ieee80211_tx_rate *rate,
  108. + struct rate_info *ri, u8 band, int len)
  109. {
  110. - struct ieee80211_rx_status stat = {
  111. - .band = band,
  112. - };
  113. + memset(stat, 0, sizeof(*stat));
  114. + stat->band = band;
  115. - if (ieee80211_fill_rate_info(hw, &stat, band, ri))
  116. - goto out;
  117. + if (ieee80211_fill_rate_info(hw, stat, band, ri))
  118. + return 0;
  119. if (rate->idx < 0 || !rate->count)
  120. - return 0;
  121. + return -1;
  122. if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
  123. - stat.bw = RATE_INFO_BW_80;
  124. + stat->bw = RATE_INFO_BW_80;
  125. else if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  126. - stat.bw = RATE_INFO_BW_40;
  127. + stat->bw = RATE_INFO_BW_40;
  128. else
  129. - stat.bw = RATE_INFO_BW_20;
  130. + stat->bw = RATE_INFO_BW_20;
  131. - stat.enc_flags = 0;
  132. + stat->enc_flags = 0;
  133. if (rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  134. - stat.enc_flags |= RX_ENC_FLAG_SHORTPRE;
  135. + stat->enc_flags |= RX_ENC_FLAG_SHORTPRE;
  136. if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
  137. - stat.enc_flags |= RX_ENC_FLAG_SHORT_GI;
  138. + stat->enc_flags |= RX_ENC_FLAG_SHORT_GI;
  139. - stat.rate_idx = rate->idx;
  140. + stat->rate_idx = rate->idx;
  141. if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
  142. - stat.encoding = RX_ENC_VHT;
  143. - stat.rate_idx = ieee80211_rate_get_vht_mcs(rate);
  144. - stat.nss = ieee80211_rate_get_vht_nss(rate);
  145. + stat->encoding = RX_ENC_VHT;
  146. + stat->rate_idx = ieee80211_rate_get_vht_mcs(rate);
  147. + stat->nss = ieee80211_rate_get_vht_nss(rate);
  148. } else if (rate->flags & IEEE80211_TX_RC_MCS) {
  149. - stat.encoding = RX_ENC_HT;
  150. + stat->encoding = RX_ENC_HT;
  151. } else {
  152. - stat.encoding = RX_ENC_LEGACY;
  153. + stat->encoding = RX_ENC_LEGACY;
  154. }
  155. -out:
  156. + return 0;
  157. +}
  158. +
  159. +static u32 ieee80211_calc_tx_airtime_rate(struct ieee80211_hw *hw,
  160. + struct ieee80211_tx_rate *rate,
  161. + struct rate_info *ri,
  162. + u8 band, int len)
  163. +{
  164. + struct ieee80211_rx_status stat;
  165. +
  166. + if (ieee80211_fill_rx_status(&stat, hw, rate, ri, band, len))
  167. + return 0;
  168. +
  169. return ieee80211_calc_rx_airtime(hw, &stat, len);
  170. }