ath9k: split up and adjust rc cleanup patch according to upstream feedback, also...
[10.03/openwrt.git] / package / mac80211 / patches / 560-ath9k_rate_control_api.patch
1 --- a/drivers/net/wireless/ath/ath9k/rc.c
2 +++ b/drivers/net/wireless/ath/ath9k/rc.c
3 @@ -19,6 +19,7 @@
4  
5  static const struct ath_rate_table ar5416_11na_ratetable = {
6         42,
7 +       8, /* MCS start */
8         {
9                 { VALID, VALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
10                         5400, 0x0b, 0x00, 12,
11 @@ -156,6 +157,7 @@ static const struct ath_rate_table ar541
12  
13  static const struct ath_rate_table ar5416_11ng_ratetable = {
14         46,
15 +       12, /* MCS start */
16         {
17                 { VALID_ALL, VALID_ALL, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
18                         900, 0x1b, 0x00, 2,
19 @@ -302,6 +304,7 @@ static const struct ath_rate_table ar541
20  
21  static const struct ath_rate_table ar5416_11a_ratetable = {
22         8,
23 +       0,
24         {
25                 { VALID, VALID, WLAN_RC_PHY_OFDM, 6000, /* 6 Mb */
26                         5400, 0x0b, 0x00, (0x80|12),
27 @@ -334,6 +337,7 @@ static const struct ath_rate_table ar541
28  
29  static const struct ath_rate_table ar5416_11g_ratetable = {
30         12,
31 +       0,
32         {
33                 { VALID, VALID, WLAN_RC_PHY_CCK, 1000, /* 1 Mb */
34                         900, 0x1b, 0x00, 2,
35 @@ -376,6 +380,20 @@ static const struct ath_rate_table ar541
36         0,   /* Phy rates allowed initially */
37  };
38  
39 +static const struct ath_rate_table *hw_rate_table[ATH9K_MODE_MAX] = {
40 +       [ATH9K_MODE_11A] = &ar5416_11a_ratetable,
41 +       [ATH9K_MODE_11G] = &ar5416_11g_ratetable,
42 +       [ATH9K_MODE_11NA_HT20] = &ar5416_11na_ratetable,
43 +       [ATH9K_MODE_11NG_HT20] = &ar5416_11ng_ratetable,
44 +       [ATH9K_MODE_11NA_HT40PLUS] = &ar5416_11na_ratetable,
45 +       [ATH9K_MODE_11NA_HT40MINUS] = &ar5416_11na_ratetable,
46 +       [ATH9K_MODE_11NG_HT40PLUS] = &ar5416_11ng_ratetable,
47 +       [ATH9K_MODE_11NG_HT40MINUS] = &ar5416_11ng_ratetable,
48 +};
49 +
50 +static int ath_rc_get_rateindex(const struct ath_rate_table *rate_table,
51 +                               struct ieee80211_tx_rate *rate);
52 +
53  static inline int8_t median(int8_t a, int8_t b, int8_t c)
54  {
55         if (a >= b) {
56 @@ -534,7 +552,7 @@ static u8 ath_rc_setvalid_rates(struct a
57                          * capflag matches one of the validity
58                          * (VALID/VALID_20/VALID_40) flags */
59  
60 -                       if (((rate & 0x7F) == (dot11rate & 0x7F)) &&
61 +                       if ((rate == dot11rate) &&
62                             ((valid & WLAN_RC_CAP_MODE(capflag)) ==
63                              WLAN_RC_CAP_MODE(capflag)) &&
64                             !WLAN_RC_PHY_HT(phy)) {
65 @@ -576,8 +594,7 @@ static u8 ath_rc_setvalid_htrates(struct
66                         u8 rate = rateset->rs_rates[i];
67                         u8 dot11rate = rate_table->info[j].dot11rate;
68  
69 -                       if (((rate & 0x7F) != (dot11rate & 0x7F)) ||
70 -                           !WLAN_RC_PHY_HT(phy) ||
71 +                       if ((rate != dot11rate) || !WLAN_RC_PHY_HT(phy) ||
72                             !WLAN_RC_PHY_HT_VALID(valid, capflag))
73                                 continue;
74  
75 @@ -696,18 +713,20 @@ static void ath_rc_rate_set_series(const
76                                    u8 tries, u8 rix, int rtsctsenable)
77  {
78         rate->count = tries;
79 -       rate->idx = rix;
80 +       rate->idx = rate_table->info[rix].ratecode;
81  
82         if (txrc->short_preamble)
83                 rate->flags |= IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
84         if (txrc->rts || rtsctsenable)
85                 rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
86 -       if (WLAN_RC_PHY_40(rate_table->info[rix].phy))
87 -               rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
88 -       if (WLAN_RC_PHY_SGI(rate_table->info[rix].phy))
89 -               rate->flags |= IEEE80211_TX_RC_SHORT_GI;
90 -       if (WLAN_RC_PHY_HT(rate_table->info[rix].phy))
91 +
92 +       if (WLAN_RC_PHY_HT(rate_table->info[rix].phy)) {
93                 rate->flags |= IEEE80211_TX_RC_MCS;
94 +               if (WLAN_RC_PHY_40(rate_table->info[rix].phy))
95 +                       rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
96 +               if (WLAN_RC_PHY_SGI(rate_table->info[rix].phy))
97 +                       rate->flags |= IEEE80211_TX_RC_SHORT_GI;
98 +       }
99  }
100  
101  static void ath_rc_rate_set_rtscts(struct ath_softc *sc,
102 @@ -720,7 +739,7 @@ static void ath_rc_rate_set_rtscts(struc
103         /* get the cix for the lowest valid rix */
104         for (i = 3; i >= 0; i--) {
105                 if (rates[i].count && (rates[i].idx >= 0)) {
106 -                       rix = rates[i].idx;
107 +                       rix = ath_rc_get_rateindex(rate_table, &rates[i]);
108                         break;
109                 }
110         }
111 @@ -1080,15 +1099,19 @@ static int ath_rc_get_rateindex(const st
112  {
113         int rix;
114  
115 +       if (!(rate->flags & IEEE80211_TX_RC_MCS))
116 +               return rate->idx;
117 +
118 +       rix = rate->idx + rate_table->mcs_start;
119         if ((rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
120             (rate->flags & IEEE80211_TX_RC_SHORT_GI))
121 -               rix = rate_table->info[rate->idx].ht_index;
122 +               rix = rate_table->info[rix].ht_index;
123         else if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
124 -               rix = rate_table->info[rate->idx].sgi_index;
125 +               rix = rate_table->info[rix].sgi_index;
126         else if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
127 -               rix = rate_table->info[rate->idx].cw40index;
128 +               rix = rate_table->info[rix].cw40index;
129         else
130 -               rix = rate_table->info[rate->idx].base_index;
131 +               rix = rate_table->info[rix].base_index;
132  
133         return rix;
134  }
135 @@ -1183,7 +1206,9 @@ struct ath_rate_table *ath_choose_rate_t
136  
137         ath_print(common, ATH_DBG_CONFIG,
138                   "Choosing rate table for mode: %d\n", mode);
139 -       return sc->hw_rate_table[mode];
140 +
141 +       sc->cur_rate_mode = mode;
142 +       return hw_rate_table[mode];
143  }
144  
145  static void ath_rc_init(struct ath_softc *sc,
146 @@ -1197,12 +1222,6 @@ static void ath_rc_init(struct ath_softc
147         u8 *ht_mcs = (u8 *)&ath_rc_priv->neg_ht_rates;
148         u8 i, j, k, hi = 0, hthi = 0;
149  
150 -       if (!rate_table) {
151 -               ath_print(common, ATH_DBG_FATAL,
152 -                         "Rate table not initialized\n");
153 -               return;
154 -       }
155 -
156         /* Initial rate table size. Will change depending
157          * on the working rate set */
158         ath_rc_priv->rate_table_size = RATE_TABLE_SIZE;
159 @@ -1357,7 +1376,8 @@ static void ath_tx_status(void *priv, st
160                 }
161         }
162  
163 -       ath_debug_stat_rc(sc, skb);
164 +       ath_debug_stat_rc(sc, ath_rc_get_rateindex(sc->cur_rate_table,
165 +               &tx_info->status.rates[final_ts_idx]));
166  }
167  
168  static void ath_rate_init(void *priv, struct ieee80211_supported_band *sband,
169 @@ -1365,7 +1385,7 @@ static void ath_rate_init(void *priv, st
170  {
171         struct ath_softc *sc = priv;
172         struct ath_rate_priv *ath_rc_priv = priv_sta;
173 -       const struct ath_rate_table *rate_table = NULL;
174 +       const struct ath_rate_table *rate_table;
175         bool is_cw40, is_sgi40;
176         int i, j = 0;
177  
178 @@ -1397,11 +1417,9 @@ static void ath_rate_init(void *priv, st
179             (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT) ||
180             (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)) {
181                 rate_table = ath_choose_rate_table(sc, sband->band,
182 -                                                  sta->ht_cap.ht_supported,
183 -                                                  is_cw40);
184 -       } else if (sc->sc_ah->opmode == NL80211_IFTYPE_AP) {
185 -               /* cur_rate_table would be set on init through config() */
186 -               rate_table = sc->cur_rate_table;
187 +                                     sta->ht_cap.ht_supported, is_cw40);
188 +       } else {
189 +               rate_table = hw_rate_table[sc->cur_rate_mode];
190         }
191  
192         ath_rc_priv->ht_cap = ath_rc_build_ht_caps(sc, sta, is_cw40, is_sgi40);
193 @@ -1445,6 +1463,7 @@ static void ath_rate_update(void *priv, 
194                         ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
195                                   "Operating HT Bandwidth changed to: %d\n",
196                                   sc->hw->conf.channel_type);
197 +                       sc->cur_rate_table = hw_rate_table[sc->cur_rate_mode];
198                 }
199         }
200  }
201 @@ -1497,26 +1516,6 @@ static struct rate_control_ops ath_rate_
202         .free_sta = ath_rate_free_sta,
203  };
204  
205 -void ath_rate_attach(struct ath_softc *sc)
206 -{
207 -       sc->hw_rate_table[ATH9K_MODE_11A] =
208 -               &ar5416_11a_ratetable;
209 -       sc->hw_rate_table[ATH9K_MODE_11G] =
210 -               &ar5416_11g_ratetable;
211 -       sc->hw_rate_table[ATH9K_MODE_11NA_HT20] =
212 -               &ar5416_11na_ratetable;
213 -       sc->hw_rate_table[ATH9K_MODE_11NG_HT20] =
214 -               &ar5416_11ng_ratetable;
215 -       sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS] =
216 -               &ar5416_11na_ratetable;
217 -       sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS] =
218 -               &ar5416_11na_ratetable;
219 -       sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS] =
220 -               &ar5416_11ng_ratetable;
221 -       sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS] =
222 -               &ar5416_11ng_ratetable;
223 -}
224 -
225  int ath_rate_control_register(void)
226  {
227         return ieee80211_rate_control_register(&ath_rate_ops);
228 --- a/drivers/net/wireless/ath/ath9k/xmit.c
229 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
230 @@ -70,6 +70,29 @@ static int ath_tx_num_badfrms(struct ath
231  static void ath_tx_rc_status(struct ath_buf *bf, struct ath_desc *ds,
232                              int nbad, int txok, bool update_rc);
233  
234 +enum {
235 +       MCS_DEFAULT,
236 +       MCS_HT40,
237 +       MCS_HT40_SGI,
238 +};
239 +
240 +static int ath_max_4ms_framelen[3][16] = {
241 +       [MCS_DEFAULT] = {
242 +               3216,  6434,  9650,  12868, 19304, 25740,  28956,  32180,
243 +               6430,  12860, 19300, 25736, 38600, 51472,  57890,  64320,
244 +       },
245 +       [MCS_HT40] = {
246 +               6684,  13368, 20052, 26738, 40104, 53476,  60156,  66840,
247 +               13360, 26720, 40080, 53440, 80160, 106880, 120240, 133600,
248 +       },
249 +       [MCS_HT40_SGI] = {
250 +               /* TODO: Only MCS 7 and 15 updated, recalculate the rest */
251 +               6684,  13368, 20052, 26738, 40104, 53476,  60156,  74200,
252 +               13360, 26720, 40080, 53440, 80160, 106880, 120240, 148400,
253 +       }
254 +};
255 +
256 +
257  /*********************/
258  /* Aggregation logic */
259  /*********************/
260 @@ -459,7 +482,6 @@ static void ath_tx_complete_aggr(struct 
261  static u32 ath_lookup_rate(struct ath_softc *sc, struct ath_buf *bf,
262                            struct ath_atx_tid *tid)
263  {
264 -       const struct ath_rate_table *rate_table = sc->cur_rate_table;
265         struct sk_buff *skb;
266         struct ieee80211_tx_info *tx_info;
267         struct ieee80211_tx_rate *rates;
268 @@ -480,12 +502,20 @@ static u32 ath_lookup_rate(struct ath_so
269  
270         for (i = 0; i < 4; i++) {
271                 if (rates[i].count) {
272 -                       if (!WLAN_RC_PHY_HT(rate_table->info[rates[i].idx].phy)) {
273 +                       int modeidx;
274 +                       if (!(rates[i].flags & IEEE80211_TX_RC_MCS)) {
275                                 legacy = 1;
276                                 break;
277                         }
278  
279 -                       frmlen = rate_table->info[rates[i].idx].max_4ms_framelen;
280 +                       if (rates[i].flags & IEEE80211_TX_RC_SHORT_GI)
281 +                               modeidx = MCS_HT40_SGI;
282 +                       else if (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
283 +                               modeidx = MCS_HT40;
284 +                       else
285 +                               modeidx = MCS_DEFAULT;
286 +
287 +                       frmlen = ath_max_4ms_framelen[modeidx][rates[i].idx];
288                         max_4ms_framelen = min(max_4ms_framelen, frmlen);
289                 }
290         }
291 @@ -523,12 +553,11 @@ static u32 ath_lookup_rate(struct ath_so
292  static int ath_compute_num_delims(struct ath_softc *sc, struct ath_atx_tid *tid,
293                                   struct ath_buf *bf, u16 frmlen)
294  {
295 -       const struct ath_rate_table *rt = sc->cur_rate_table;
296         struct sk_buff *skb = bf->bf_mpdu;
297         struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
298         u32 nsymbits, nsymbols;
299         u16 minlen;
300 -       u8 rc, flags, rix;
301 +       u8 flags, rix;
302         int width, half_gi, ndelim, mindelim;
303  
304         /* Select standard number of delimiters based on frame length alone */
305 @@ -558,7 +587,6 @@ static int ath_compute_num_delims(struct
306  
307         rix = tx_info->control.rates[0].idx;
308         flags = tx_info->control.rates[0].flags;
309 -       rc = rt->info[rix].ratecode;
310         width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0;
311         half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0;
312  
313 @@ -570,7 +598,7 @@ static int ath_compute_num_delims(struct
314         if (nsymbols == 0)
315                 nsymbols = 1;
316  
317 -       nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
318 +       nsymbits = bits_per_symbol[rix][width];
319         minlen = (nsymbols * nsymbits) / BITS_PER_BYTE;
320  
321         if (frmlen < minlen) {
322 @@ -1430,22 +1458,14 @@ static int setup_tx_flags(struct ath_sof
323  static u32 ath_pkt_duration(struct ath_softc *sc, u8 rix, struct ath_buf *bf,
324                             int width, int half_gi, bool shortPreamble)
325  {
326 -       const struct ath_rate_table *rate_table = sc->cur_rate_table;
327         u32 nbits, nsymbits, duration, nsymbols;
328 -       u8 rc;
329         int streams, pktlen;
330  
331         pktlen = bf_isaggr(bf) ? bf->bf_al : bf->bf_frmlen;
332 -       rc = rate_table->info[rix].ratecode;
333 -
334 -       /* for legacy rates, use old function to compute packet duration */
335 -       if (!IS_HT_RATE(rc))
336 -               return ath9k_hw_computetxtime(sc->sc_ah, rate_table, pktlen,
337 -                                             rix, shortPreamble);
338  
339         /* find number of symbols: PLCP + data */
340         nbits = (pktlen << 3) + OFDM_PLCP_BITS;
341 -       nsymbits = bits_per_symbol[HT_RC_2_MCS(rc)][width];
342 +       nsymbits = bits_per_symbol[rix][width];
343         nsymbols = (nbits + nsymbits - 1) / nsymbits;
344  
345         if (!half_gi)
346 @@ -1454,7 +1474,7 @@ static u32 ath_pkt_duration(struct ath_s
347                 duration = SYMBOL_TIME_HALFGI(nsymbols);
348  
349         /* addup duration for legacy/ht training and signal fields */
350 -       streams = HT_RC_2_STREAMS(rc);
351 +       streams = HT_RC_2_STREAMS(rix);
352         duration += L_STF + L_LTF + L_SIG + HT_SIG + HT_STF + HT_LTF(streams);
353  
354         return duration;
355 @@ -1463,11 +1483,11 @@ static u32 ath_pkt_duration(struct ath_s
356  static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf)
357  {
358         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
359 -       const struct ath_rate_table *rt = sc->cur_rate_table;
360         struct ath9k_11n_rate_series series[4];
361         struct sk_buff *skb;
362         struct ieee80211_tx_info *tx_info;
363         struct ieee80211_tx_rate *rates;
364 +       const struct ieee80211_rate *rate;
365         struct ieee80211_hdr *hdr;
366         int i, flags = 0;
367         u8 rix = 0, ctsrate = 0;
368 @@ -1486,11 +1506,10 @@ static void ath_buf_set_rate(struct ath_
369          * checking the BSS's global flag.
370          * But for the rate series, IEEE80211_TX_RC_USE_SHORT_PREAMBLE is used.
371          */
372 +       rate = ieee80211_get_rts_cts_rate(sc->hw, tx_info);
373 +       ctsrate = rate->hw_value;
374         if (sc->sc_flags & SC_OP_PREAMBLE_SHORT)
375 -               ctsrate = rt->info[tx_info->control.rts_cts_rate_idx].ratecode |
376 -                       rt->info[tx_info->control.rts_cts_rate_idx].short_preamble;
377 -       else
378 -               ctsrate = rt->info[tx_info->control.rts_cts_rate_idx].ratecode;
379 +               ctsrate |= rate->hw_value_short;
380  
381         /*
382          * ATH9K_TXDESC_RTSENA and ATH9K_TXDESC_CTSENA are mutually exclusive.
383 @@ -1513,6 +1532,9 @@ static void ath_buf_set_rate(struct ath_
384                 flags &= ~(ATH9K_TXDESC_RTSENA);
385  
386         for (i = 0; i < 4; i++) {
387 +               bool is_40, is_sgi, is_sp;
388 +               int phy;
389 +
390                 if (!rates[i].count || (rates[i].idx < 0))
391                         continue;
392  
393 @@ -1520,12 +1542,6 @@ static void ath_buf_set_rate(struct ath_
394                 series[i].Tries = rates[i].count;
395                 series[i].ChSel = common->tx_chainmask;
396  
397 -               if (rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
398 -                       series[i].Rate = rt->info[rix].ratecode |
399 -                               rt->info[rix].short_preamble;
400 -               else
401 -                       series[i].Rate = rt->info[rix].ratecode;
402 -
403                 if (rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS)
404                         series[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
405                 if (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
406 @@ -1533,10 +1549,36 @@ static void ath_buf_set_rate(struct ath_
407                 if (rates[i].flags & IEEE80211_TX_RC_SHORT_GI)
408                         series[i].RateFlags |= ATH9K_RATESERIES_HALFGI;
409  
410 -               series[i].PktDuration = ath_pkt_duration(sc, rix, bf,
411 -                        (rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) != 0,
412 -                        (rates[i].flags & IEEE80211_TX_RC_SHORT_GI),
413 -                        (rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE));
414 +               is_sgi = !!(rates[i].flags & IEEE80211_TX_RC_SHORT_GI);
415 +               is_40 = !!(rates[i].flags & IEEE80211_TX_RC_40_MHZ_WIDTH);
416 +               is_sp = !!(rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE);
417 +
418 +               if (rates[i].flags & IEEE80211_TX_RC_MCS) {
419 +                       /* MCS rates */
420 +                       series[i].Rate = rix | 0x80;
421 +                       series[i].PktDuration = ath_pkt_duration(sc, rix, bf,
422 +                                is_40, is_sgi, is_sp);
423 +                       continue;
424 +               }
425 +
426 +               /* legcay rates */
427 +               if ((tx_info->band == IEEE80211_BAND_2GHZ) &&
428 +                   !(rate->flags & IEEE80211_RATE_ERP_G))
429 +                       phy = WLAN_RC_PHY_CCK;
430 +               else
431 +                       phy = WLAN_RC_PHY_OFDM;
432 +
433 +               rate = &sc->sbands[tx_info->band].bitrates[rates[i].idx];
434 +               series[i].Rate = rate->hw_value;
435 +               if (rate->hw_value_short) {
436 +                       if (rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
437 +                               series[i].Rate |= rate->hw_value_short;
438 +               } else {
439 +                       is_sp = false;
440 +               }
441 +
442 +               series[i].PktDuration = ath9k_hw_computetxtime(sc->sc_ah,
443 +                       phy, rate->bitrate * 100, bf->bf_frmlen, rix, is_sp);
444         }
445  
446         /* set dur_update_en for l-sig computation except for PS-Poll frames */
447 @@ -1925,8 +1967,10 @@ static void ath_tx_rc_status(struct ath_
448                 }
449         }
450  
451 -       for (i = tx_rateindex + 1; i < hw->max_rates; i++)
452 +       for (i = tx_rateindex + 1; i < hw->max_rates; i++) {
453                 tx_info->status.rates[i].count = 0;
454 +               tx_info->status.rates[i].idx = -1;
455 +       }
456  
457         tx_info->status.rates[tx_rateindex].count = bf->bf_retries + 1;
458  }
459 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
460 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
461 @@ -21,7 +21,6 @@
462  #include <linux/device.h>
463  #include <linux/leds.h>
464  
465 -#include "rc.h"
466  #include "debug.h"
467  #include "common.h"
468  
469 @@ -433,6 +432,7 @@ struct ath_led {
470  #define SC_OP_BT_PRIORITY_DETECTED BIT(21)
471  
472  struct ath_wiphy;
473 +struct ath_rate_table;
474  
475  struct ath_softc {
476         struct ieee80211_hw *hw;
477 @@ -477,9 +477,8 @@ struct ath_softc {
478         struct ath_rx rx;
479         struct ath_tx tx;
480         struct ath_beacon beacon;
481 -       struct ieee80211_rate rates[IEEE80211_NUM_BANDS][ATH_RATE_MAX];
482 -       const struct ath_rate_table *hw_rate_table[ATH9K_MODE_MAX];
483         const struct ath_rate_table *cur_rate_table;
484 +       enum wireless_mode cur_rate_mode;
485         struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
486  
487         struct ath_led radio_led;
488 --- a/drivers/net/wireless/ath/ath9k/main.c
489 +++ b/drivers/net/wireless/ath/ath9k/main.c
490 @@ -105,37 +105,55 @@ static struct ieee80211_channel ath9k_5g
491         CHAN5G(5825, 37), /* Channel 165 */
492  };
493  
494 +/* Atheros hardware rate code addition for short premble */
495 +#define SHPCHECK(__hw_rate, __flags) \
496 +       ((__flags & IEEE80211_RATE_SHORT_PREAMBLE) ? (__hw_rate | 0x04 ) : 0)
497 +
498 +#define RATE(_bitrate, _hw_rate, _flags) {              \
499 +       .bitrate        = (_bitrate),                   \
500 +       .flags          = (_flags),                     \
501 +       .hw_value       = (_hw_rate),                   \
502 +       .hw_value_short = (SHPCHECK(_hw_rate, _flags))  \
503 +}
504 +
505 +static struct ieee80211_rate ath9k_legacy_rates[] = {
506 +       RATE(10, 0x1b, 0),
507 +       RATE(20, 0x1a, IEEE80211_RATE_SHORT_PREAMBLE),
508 +       RATE(55, 0x19, IEEE80211_RATE_SHORT_PREAMBLE),
509 +       RATE(110, 0x18, IEEE80211_RATE_SHORT_PREAMBLE),
510 +       RATE(60, 0x0b, 0),
511 +       RATE(90, 0x0f, 0),
512 +       RATE(120, 0x0a, 0),
513 +       RATE(180, 0x0e, 0),
514 +       RATE(240, 0x09, 0),
515 +       RATE(360, 0x0d, 0),
516 +       RATE(480, 0x08, 0),
517 +       RATE(540, 0x0c, 0),
518 +};
519 +
520  static void ath_cache_conf_rate(struct ath_softc *sc,
521                                 struct ieee80211_conf *conf)
522  {
523         switch (conf->channel->band) {
524         case IEEE80211_BAND_2GHZ:
525                 if (conf_is_ht20(conf))
526 -                       sc->cur_rate_table =
527 -                         sc->hw_rate_table[ATH9K_MODE_11NG_HT20];
528 +                       sc->cur_rate_mode = ATH9K_MODE_11NG_HT20;
529                 else if (conf_is_ht40_minus(conf))
530 -                       sc->cur_rate_table =
531 -                         sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS];
532 +                       sc->cur_rate_mode = ATH9K_MODE_11NG_HT40MINUS;
533                 else if (conf_is_ht40_plus(conf))
534 -                       sc->cur_rate_table =
535 -                         sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS];
536 +                       sc->cur_rate_mode = ATH9K_MODE_11NG_HT40PLUS;
537                 else
538 -                       sc->cur_rate_table =
539 -                         sc->hw_rate_table[ATH9K_MODE_11G];
540 +                       sc->cur_rate_mode = ATH9K_MODE_11G;
541                 break;
542         case IEEE80211_BAND_5GHZ:
543                 if (conf_is_ht20(conf))
544 -                       sc->cur_rate_table =
545 -                         sc->hw_rate_table[ATH9K_MODE_11NA_HT20];
546 +                       sc->cur_rate_mode = ATH9K_MODE_11NA_HT20;
547                 else if (conf_is_ht40_minus(conf))
548 -                       sc->cur_rate_table =
549 -                         sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS];
550 +                       sc->cur_rate_mode = ATH9K_MODE_11NA_HT40MINUS;
551                 else if (conf_is_ht40_plus(conf))
552 -                       sc->cur_rate_table =
553 -                         sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS];
554 +                       sc->cur_rate_mode = ATH9K_MODE_11NA_HT40PLUS;
555                 else
556 -                       sc->cur_rate_table =
557 -                         sc->hw_rate_table[ATH9K_MODE_11A];
558 +                       sc->cur_rate_mode = ATH9K_MODE_11A;
559                 break;
560         default:
561                 BUG_ON(1);
562 @@ -191,51 +209,6 @@ static u8 parse_mpdudensity(u8 mpdudensi
563         }
564  }
565  
566 -static void ath_setup_rates(struct ath_softc *sc, enum ieee80211_band band)
567 -{
568 -       const struct ath_rate_table *rate_table = NULL;
569 -       struct ieee80211_supported_band *sband;
570 -       struct ieee80211_rate *rate;
571 -       int i, maxrates;
572 -
573 -       switch (band) {
574 -       case IEEE80211_BAND_2GHZ:
575 -               rate_table = sc->hw_rate_table[ATH9K_MODE_11G];
576 -               break;
577 -       case IEEE80211_BAND_5GHZ:
578 -               rate_table = sc->hw_rate_table[ATH9K_MODE_11A];
579 -               break;
580 -       default:
581 -               break;
582 -       }
583 -
584 -       if (rate_table == NULL)
585 -               return;
586 -
587 -       sband = &sc->sbands[band];
588 -       rate = sc->rates[band];
589 -
590 -       if (rate_table->rate_cnt > ATH_RATE_MAX)
591 -               maxrates = ATH_RATE_MAX;
592 -       else
593 -               maxrates = rate_table->rate_cnt;
594 -
595 -       for (i = 0; i < maxrates; i++) {
596 -               rate[i].bitrate = rate_table->info[i].ratekbps / 100;
597 -               rate[i].hw_value = rate_table->info[i].ratecode;
598 -               if (rate_table->info[i].short_preamble) {
599 -                       rate[i].hw_value_short = rate_table->info[i].ratecode |
600 -                               rate_table->info[i].short_preamble;
601 -                       rate[i].flags = IEEE80211_RATE_SHORT_PREAMBLE;
602 -               }
603 -               sband->n_bitrates++;
604 -
605 -               ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
606 -                         "Rate: %2dMbps, ratecode: %2d\n",
607 -                         rate[i].bitrate / 10, rate[i].hw_value);
608 -       }
609 -}
610 -
611  static struct ath9k_channel *ath_get_curchannel(struct ath_softc *sc,
612                                                 struct ieee80211_hw *hw)
613  {
614 @@ -1713,12 +1686,6 @@ static int ath_init_softc(u16 devid, str
615         /* default to MONITOR mode */
616         sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR;
617  
618 -       /* Setup rate tables */
619 -
620 -       ath_rate_attach(sc);
621 -       ath_setup_rates(sc, IEEE80211_BAND_2GHZ);
622 -       ath_setup_rates(sc, IEEE80211_BAND_5GHZ);
623 -
624         /*
625          * Allocate hardware transmit queues: one queue for
626          * beacon frames and one data queue for each QoS
627 @@ -1839,19 +1806,22 @@ static int ath_init_softc(u16 devid, str
628         /* setup channels and rates */
629  
630         sc->sbands[IEEE80211_BAND_2GHZ].channels = ath9k_2ghz_chantable;
631 -       sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
632 -               sc->rates[IEEE80211_BAND_2GHZ];
633         sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
634         sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
635                 ARRAY_SIZE(ath9k_2ghz_chantable);
636 +       sc->sbands[IEEE80211_BAND_2GHZ].bitrates = ath9k_legacy_rates;
637 +       sc->sbands[IEEE80211_BAND_2GHZ].n_bitrates =
638 +               ARRAY_SIZE(ath9k_legacy_rates);
639  
640         if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes)) {
641                 sc->sbands[IEEE80211_BAND_5GHZ].channels = ath9k_5ghz_chantable;
642 -               sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
643 -                       sc->rates[IEEE80211_BAND_5GHZ];
644                 sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
645                 sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
646                         ARRAY_SIZE(ath9k_5ghz_chantable);
647 +               sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
648 +                       ath9k_legacy_rates + 4;
649 +               sc->sbands[IEEE80211_BAND_5GHZ].n_bitrates =
650 +                       ARRAY_SIZE(ath9k_legacy_rates) - 4;
651         }
652  
653         switch (ah->btcoex_hw.scheme) {
654 --- a/drivers/net/wireless/ath/ath9k/rc.h
655 +++ b/drivers/net/wireless/ath/ath9k/rc.h
656 @@ -104,6 +104,7 @@ enum {
657   */
658  struct ath_rate_table {
659         int rate_cnt;
660 +       int mcs_start;
661         struct {
662                 int valid;
663                 int valid_single_stream;
664 @@ -179,8 +180,6 @@ enum ath9k_internal_frame_type {
665         ATH9K_INT_UNPAUSE
666  };
667  
668 -void ath_rate_attach(struct ath_softc *sc);
669 -u8 ath_rate_findrateix(struct ath_softc *sc, u8 dot11_rate);
670  int ath_rate_control_register(void);
671  void ath_rate_control_unregister(void);
672  
673 --- a/drivers/net/wireless/ath/ath9k/beacon.c
674 +++ b/drivers/net/wireless/ath/ath9k/beacon.c
675 @@ -65,9 +65,9 @@ static void ath_beacon_setup(struct ath_
676         struct ath_common *common = ath9k_hw_common(ah);
677         struct ath_desc *ds;
678         struct ath9k_11n_rate_series series[4];
679 -       const struct ath_rate_table *rt;
680         int flags, antenna, ctsrate = 0, ctsduration = 0;
681 -       u8 rate;
682 +       struct ieee80211_supported_band *sband;
683 +       u8 rate = 0;
684  
685         ds = bf->bf_desc;
686         flags = ATH9K_TXDESC_NOACK;
687 @@ -91,10 +91,10 @@ static void ath_beacon_setup(struct ath_
688  
689         ds->ds_data = bf->bf_buf_addr;
690  
691 -       rt = sc->cur_rate_table;
692 -       rate = rt->info[0].ratecode;
693 +       sband = &sc->sbands[common->hw->conf.channel->band];
694 +       rate = sband->bitrates[0].hw_value;
695         if (sc->sc_flags & SC_OP_PREAMBLE_SHORT)
696 -               rate |= rt->info[0].short_preamble;
697 +               rate |= sband->bitrates[0].hw_value_short;
698  
699         ath9k_hw_set11n_txdesc(ah, ds, skb->len + FCS_LEN,
700                                ATH9K_PKT_TYPE_BEACON,
701 --- a/drivers/net/wireless/ath/ath9k/debug.h
702 +++ b/drivers/net/wireless/ath/ath9k/debug.h
703 @@ -18,6 +18,7 @@
704  #define DEBUG_H
705  
706  #include "hw.h"
707 +#include "rc.h"
708  
709  struct ath_txq;
710  struct ath_buf;
711 @@ -138,7 +139,7 @@ void ath9k_exit_debug(struct ath_hw *ah)
712  int ath9k_debug_create_root(void);
713  void ath9k_debug_remove_root(void);
714  void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status);
715 -void ath_debug_stat_rc(struct ath_softc *sc, struct sk_buff *skb);
716 +void ath_debug_stat_rc(struct ath_softc *sc, int final_rate);
717  void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
718                        struct ath_buf *bf);
719  void ath_debug_stat_retries(struct ath_softc *sc, int rix,
720 --- a/drivers/net/wireless/ath/ath9k/debug.c
721 +++ b/drivers/net/wireless/ath/ath9k/debug.c
722 @@ -255,21 +255,11 @@ static const struct file_operations fops
723         .owner = THIS_MODULE
724  };
725  
726 -void ath_debug_stat_rc(struct ath_softc *sc, struct sk_buff *skb)
727 +void ath_debug_stat_rc(struct ath_softc *sc, int final_rate)
728  {
729 -       struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
730 -       struct ieee80211_tx_rate *rates = tx_info->status.rates;
731 -       int final_ts_idx = 0, idx, i;
732         struct ath_rc_stats *stats;
733  
734 -       for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
735 -               if (!rates[i].count)
736 -                       break;
737 -
738 -               final_ts_idx = i;
739 -       }
740 -       idx = rates[final_ts_idx].idx;
741 -       stats = &sc->debug.stats.rcstats[idx];
742 +       stats = &sc->debug.stats.rcstats[final_rate];
743         stats->success++;
744  }
745  
746 --- a/drivers/net/wireless/ath/ath9k/hw.c
747 +++ b/drivers/net/wireless/ath/ath9k/hw.c
748 @@ -149,22 +149,19 @@ bool ath9k_get_channel_edges(struct ath_
749  }
750  
751  u16 ath9k_hw_computetxtime(struct ath_hw *ah,
752 -                          const struct ath_rate_table *rates,
753 +                          u8 phy, int kbps,
754                            u32 frameLen, u16 rateix,
755                            bool shortPreamble)
756  {
757         u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
758 -       u32 kbps;
759 -
760 -       kbps = rates->info[rateix].ratekbps;
761  
762         if (kbps == 0)
763                 return 0;
764  
765 -       switch (rates->info[rateix].phy) {
766 +       switch (phy) {
767         case WLAN_RC_PHY_CCK:
768                 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
769 -               if (shortPreamble && rates->info[rateix].short_preamble)
770 +               if (shortPreamble)
771                         phyTime >>= 1;
772                 numBits = frameLen << 3;
773                 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
774 @@ -195,8 +192,7 @@ u16 ath9k_hw_computetxtime(struct ath_hw
775                 break;
776         default:
777                 ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
778 -                         "Unknown phy %u (rate ix %u)\n",
779 -                         rates->info[rateix].phy, rateix);
780 +                         "Unknown phy %u (rate ix %u)\n", phy, rateix);
781                 txTime = 0;
782                 break;
783         }
784 --- a/drivers/net/wireless/ath/ath9k/hw.h
785 +++ b/drivers/net/wireless/ath/ath9k/hw.h
786 @@ -670,7 +670,7 @@ bool ath9k_hw_wait(struct ath_hw *ah, u3
787  u32 ath9k_hw_reverse_bits(u32 val, u32 n);
788  bool ath9k_get_channel_edges(struct ath_hw *ah, u16 flags, u16 *low, u16 *high);
789  u16 ath9k_hw_computetxtime(struct ath_hw *ah,
790 -                          const struct ath_rate_table *rates,
791 +                          u8 phy, int kbps,
792                            u32 frameLen, u16 rateix, bool shortPreamble);
793  void ath9k_hw_get_channel_centers(struct ath_hw *ah,
794                                   struct ath9k_channel *chan,
795 --- a/drivers/net/wireless/ath/ath9k/mac.h
796 +++ b/drivers/net/wireless/ath/ath9k/mac.h
797 @@ -616,7 +616,6 @@ enum ath9k_cipher {
798  
799  struct ath_hw;
800  struct ath9k_channel;
801 -struct ath_rate_table;
802  
803  u32 ath9k_hw_gettxbuf(struct ath_hw *ah, u32 q);
804  void ath9k_hw_puttxbuf(struct ath_hw *ah, u32 q, u32 txdp);