mac80211: minstrel_ht: set A-MSDU tx limits based on selected max_prob_rate
authorFelix Fietkau <nbd@openwrt.org>
Thu, 3 Mar 2016 21:59:01 +0000 (22:59 +0100)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 6 Apr 2016 11:18:20 +0000 (13:18 +0200)
Prevents excessive A-MSDU aggregation at low data rates or bad
conditions.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/mac80211/rc80211_minstrel_ht.c

index 46ce08ed70b5e1f3b804360a6b07865d5f13f90b..d77a9a8423387937e47e1b1e53f50d10ef1679f9 100644 (file)
@@ -883,6 +883,59 @@ minstrel_ht_set_rate(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
        ratetbl->rate[offset].flags = flags;
 }
 
+static inline int
+minstrel_ht_get_prob_ewma(struct minstrel_ht_sta *mi, int rate)
+{
+       int group = rate / MCS_GROUP_RATES;
+       rate %= MCS_GROUP_RATES;
+       return mi->groups[group].rates[rate].prob_ewma;
+}
+
+static int
+minstrel_ht_get_max_amsdu_len(struct minstrel_ht_sta *mi)
+{
+       int group = mi->max_prob_rate / MCS_GROUP_RATES;
+       const struct mcs_group *g = &minstrel_mcs_groups[group];
+       int rate = mi->max_prob_rate % MCS_GROUP_RATES;
+
+       /* Disable A-MSDU if max_prob_rate is bad */
+       if (mi->groups[group].rates[rate].prob_ewma < MINSTREL_FRAC(50, 100))
+               return 1;
+
+       /* If the rate is slower than single-stream MCS1, make A-MSDU limit small */
+       if (g->duration[rate] > MCS_DURATION(1, 0, 52))
+               return 500;
+
+       /*
+        * If the rate is slower than single-stream MCS4, limit A-MSDU to usual
+        * data packet size
+        */
+       if (g->duration[rate] > MCS_DURATION(1, 0, 104))
+               return 1600;
+
+       /*
+        * If the rate is slower than single-stream MCS7, or if the max throughput
+        * rate success probability is less than 75%, limit A-MSDU to twice the usual
+        * data packet size
+        */
+       if (g->duration[rate] > MCS_DURATION(1, 0, 260) ||
+           (minstrel_ht_get_prob_ewma(mi, mi->max_tp_rate[0]) <
+            MINSTREL_FRAC(75, 100)))
+               return 3200;
+
+       /*
+        * HT A-MPDU limits maximum MPDU size under BA agreement to 4095 bytes.
+        * Since aggregation sessions are started/stopped without txq flush, use
+        * the limit here to avoid the complexity of having to de-aggregate
+        * packets in the queue.
+        */
+       if (!mi->sta->vht_cap.vht_supported)
+               return IEEE80211_MAX_MPDU_LEN_HT_BA;
+
+       /* unlimited */
+       return 0;
+}
+
 static void
 minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
 {
@@ -907,6 +960,7 @@ minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
                minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_prob_rate);
        }
 
+       mi->sta->max_rc_amsdu_len = minstrel_ht_get_max_amsdu_len(mi);
        rates->rate[i].idx = -1;
        rate_control_set_rates(mp->hw, mi->sta, rates);
 }