blob: f667d2c94e5c88192eed67032f6c3e0b476c6383 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From: Felix Fietkau <nbd@nbd.name>
2Date: Fri, 25 Dec 2020 16:22:52 +0100
3Subject: [PATCH] mac80211: minstrel_ht: clean up CCK code
4
5- move ack overhead out of rate duration table
6- remove cck_supported, cck_supported_short
7
8Preparation for adding OFDM legacy rates support
9
10Signed-off-by: Felix Fietkau <nbd@nbd.name>
11---
12
13--- a/net/mac80211/rc80211_minstrel_ht.c
14+++ b/net/mac80211/rc80211_minstrel_ht.c
15@@ -136,20 +136,16 @@
16 __VHT_GROUP(_streams, _sgi, _bw, \
17 VHT_GROUP_SHIFT(_streams, _sgi, _bw))
18
19-#define CCK_DURATION(_bitrate, _short, _len) \
20+#define CCK_DURATION(_bitrate, _short) \
21 (1000 * (10 /* SIFS */ + \
22 (_short ? 72 + 24 : 144 + 48) + \
23- (8 * (_len + 4) * 10) / (_bitrate)))
24-
25-#define CCK_ACK_DURATION(_bitrate, _short) \
26- (CCK_DURATION((_bitrate > 10 ? 20 : 10), false, 60) + \
27- CCK_DURATION(_bitrate, _short, AVG_PKT_SIZE))
28+ (8 * (AVG_PKT_SIZE + 4) * 10) / (_bitrate)))
29
30 #define CCK_DURATION_LIST(_short, _s) \
31- CCK_ACK_DURATION(10, _short) >> _s, \
32- CCK_ACK_DURATION(20, _short) >> _s, \
33- CCK_ACK_DURATION(55, _short) >> _s, \
34- CCK_ACK_DURATION(110, _short) >> _s
35+ CCK_DURATION(10, _short) >> _s, \
36+ CCK_DURATION(20, _short) >> _s, \
37+ CCK_DURATION(55, _short) >> _s, \
38+ CCK_DURATION(110, _short) >> _s
39
40 #define __CCK_GROUP(_s) \
41 [MINSTREL_CCK_GROUP] = { \
42@@ -163,7 +159,7 @@
43 }
44
45 #define CCK_GROUP_SHIFT \
46- GROUP_SHIFT(CCK_ACK_DURATION(10, false))
47+ GROUP_SHIFT(CCK_DURATION(10, false))
48
49 #define CCK_GROUP __CCK_GROUP(CCK_GROUP_SHIFT)
50
51@@ -349,15 +345,19 @@ int
52 minstrel_ht_get_tp_avg(struct minstrel_ht_sta *mi, int group, int rate,
53 int prob_avg)
54 {
55- unsigned int nsecs = 0;
56+ unsigned int nsecs = 0, overhead = mi->overhead;
57+ unsigned int ampdu_len = 1;
58
59 /* do not account throughput if sucess prob is below 10% */
60 if (prob_avg < MINSTREL_FRAC(10, 100))
61 return 0;
62
63- if (group != MINSTREL_CCK_GROUP)
64- nsecs = 1000 * mi->overhead / minstrel_ht_avg_ampdu_len(mi);
65+ if (group == MINSTREL_CCK_GROUP)
66+ overhead = mi->overhead_legacy;
67+ else
68+ ampdu_len = minstrel_ht_avg_ampdu_len(mi);
69
70+ nsecs = 1000 * overhead / ampdu_len;
71 nsecs += minstrel_mcs_groups[group].duration[rate] <<
72 minstrel_mcs_groups[group].shift;
73
74@@ -1031,7 +1031,10 @@ minstrel_calc_retransmit(struct minstrel
75 ctime += (t_slot * cw) >> 1;
76 cw = min((cw << 1) | 1, mp->cw_max);
77
78- if (index / MCS_GROUP_RATES != MINSTREL_CCK_GROUP) {
79+ if (index / MCS_GROUP_RATES == MINSTREL_CCK_GROUP) {
80+ overhead = mi->overhead_legacy;
81+ overhead_rtscts = mi->overhead_legacy_rtscts;
82+ } else {
83 overhead = mi->overhead;
84 overhead_rtscts = mi->overhead_rtscts;
85 }
86@@ -1369,18 +1372,14 @@ minstrel_ht_update_cck(struct minstrel_p
87 if (!ieee80211_hw_check(mp->hw, SUPPORTS_HT_CCK_RATES))
88 return;
89
90- mi->cck_supported = 0;
91- mi->cck_supported_short = 0;
92 for (i = 0; i < 4; i++) {
93 if (!rate_supported(sta, sband->band, mp->cck_rates[i]))
94 continue;
95
96- mi->cck_supported |= BIT(i);
97+ mi->supported[MINSTREL_CCK_GROUP] |= BIT(i);
98 if (sband->bitrates[i].flags & IEEE80211_RATE_SHORT_PREAMBLE)
99- mi->cck_supported_short |= BIT(i);
100+ mi->supported[MINSTREL_CCK_GROUP] |= BIT(i + 4);
101 }
102-
103- mi->supported[MINSTREL_CCK_GROUP] = mi->cck_supported;
104 }
105
106 static void
107@@ -1394,12 +1393,13 @@ minstrel_ht_update_caps(void *priv, stru
108 struct ieee80211_mcs_info *mcs = &sta->ht_cap.mcs;
109 u16 ht_cap = sta->ht_cap.cap;
110 struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
111+ const struct ieee80211_rate *ctl_rate;
112+ bool ldpc, erp;
113 int use_vht;
114 int n_supported = 0;
115 int ack_dur;
116 int stbc;
117 int i;
118- bool ldpc;
119
120 /* fall back to the old minstrel for legacy stations */
121 if (!sta->ht_cap.ht_supported)
122@@ -1423,6 +1423,14 @@ minstrel_ht_update_caps(void *priv, stru
123 mi->overhead += ack_dur;
124 mi->overhead_rtscts = mi->overhead + 2 * ack_dur;
125
126+ ctl_rate = &sband->bitrates[rate_lowest_index(sband, sta)];
127+ erp = ctl_rate->flags & IEEE80211_RATE_ERP_G;
128+ ack_dur = ieee80211_frame_duration(sband->band, 10,
129+ ctl_rate->bitrate, erp, 1,
130+ ieee80211_chandef_get_shift(chandef));
131+ mi->overhead_legacy = ack_dur;
132+ mi->overhead_legacy_rtscts = mi->overhead_legacy + 2 * ack_dur;
133+
134 mi->avg_ampdu_len = MINSTREL_FRAC(1, 1);
135
136 /* When using MRR, sample more on the first attempt, without delay */
137@@ -1523,8 +1531,6 @@ minstrel_ht_update_caps(void *priv, stru
138 if (!n_supported)
139 goto use_legacy;
140
141- mi->supported[MINSTREL_CCK_GROUP] |= mi->cck_supported_short << 4;
142-
143 /* create an initial rate table with the lowest supported rates */
144 minstrel_ht_update_stats(mp, mi, true);
145 minstrel_ht_update_rates(mp, mi);
146--- a/net/mac80211/rc80211_minstrel_ht.h
147+++ b/net/mac80211/rc80211_minstrel_ht.h
148@@ -77,6 +77,8 @@ struct minstrel_ht_sta {
149 /* overhead time in usec for each frame */
150 unsigned int overhead;
151 unsigned int overhead_rtscts;
152+ unsigned int overhead_legacy;
153+ unsigned int overhead_legacy_rtscts;
154
155 unsigned int total_packets_last;
156 unsigned int total_packets_cur;
157@@ -97,9 +99,6 @@ struct minstrel_ht_sta {
158 /* current MCS group to be sampled */
159 u8 sample_group;
160
161- u8 cck_supported;
162- u8 cck_supported_short;
163-
164 /* Bitfield of supported MCS rates of all groups */
165 u16 supported[MINSTREL_GROUPS_NB];
166