ath9k: add more fixes for half/quarter rate support
[librecmc/librecmc.git] / package / mac80211 / patches / 545-ath9k_timing_settings.patch
1 --- a/drivers/net/wireless/ath/ath9k/hw.c
2 +++ b/drivers/net/wireless/ath/ath9k/hw.c
3 @@ -951,25 +951,60 @@ static bool ath9k_hw_set_global_txtimeou
4  
5  void ath9k_hw_init_global_settings(struct ath_hw *ah)
6  {
7 -       struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
8 +       struct ath_common *common = ath9k_hw_common(ah);
9 +       struct ieee80211_conf *conf = &common->hw->conf;
10 +       const struct ath9k_channel *chan = ah->curchan;
11         int acktimeout;
12         int slottime;
13         int sifstime;
14 +       int rx_lat = 0, tx_lat = 0, eifs = 0;
15 +       u32 reg;
16  
17         ath_dbg(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
18                 ah->misc_mode);
19  
20 +       if (!chan)
21 +               return;
22 +
23         if (ah->misc_mode != 0)
24                 REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode);
25  
26 -       if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ)
27 -               sifstime = 16;
28 -       else
29 -               sifstime = 10;
30 +       rx_lat = 37;
31 +       tx_lat = 54;
32 +
33 +       if (IS_CHAN_HALF_RATE(chan)) {
34 +               eifs = 175;
35 +               rx_lat *= 2;
36 +               tx_lat *= 2;
37 +               if (IS_CHAN_A_FAST_CLOCK(ah, chan))
38 +                   tx_lat += 11;
39 +
40 +               slottime = 13;
41 +               sifstime = 32;
42 +       } else if (IS_CHAN_QUARTER_RATE(chan)) {
43 +               eifs = 340;
44 +               rx_lat *= 4;
45 +               tx_lat *= 4;
46 +               if (IS_CHAN_A_FAST_CLOCK(ah, chan))
47 +                   tx_lat += 22;
48 +
49 +               slottime = 21;
50 +               sifstime = 64;
51 +       } else {
52 +               eifs = REG_READ(ah, AR_D_GBL_IFS_EIFS);
53 +               reg = REG_READ(ah, AR_USEC);
54 +               rx_lat = MS(reg, AR_USEC_RX_LAT);
55 +               tx_lat = MS(reg, AR_USEC_TX_LAT);
56 +
57 +               slottime = ah->slottime;
58 +               if (IS_CHAN_5GHZ(chan))
59 +                       sifstime = 16;
60 +               else
61 +                       sifstime = 10;
62 +       }
63  
64         /* As defined by IEEE 802.11-2007 17.3.8.6 */
65 -       slottime = ah->slottime + 3 * ah->coverage_class;
66 -       acktimeout = slottime + sifstime;
67 +       acktimeout = slottime + sifstime + 3 * ah->coverage_class;
68  
69         /*
70          * Workaround for early ACK timeouts, add an offset to match the
71 @@ -981,11 +1016,19 @@ void ath9k_hw_init_global_settings(struc
72         if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ)
73                 acktimeout += 64 - sifstime - ah->slottime;
74  
75 -       ath9k_hw_setslottime(ah, ah->slottime);
76 +       ath9k_hw_setslottime(ah, slottime);
77         ath9k_hw_set_ack_timeout(ah, acktimeout);
78         ath9k_hw_set_cts_timeout(ah, acktimeout);
79         if (ah->globaltxtimeout != (u32) -1)
80                 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
81 +
82 +       REG_WRITE(ah, AR_D_GBL_IFS_EIFS, ath9k_hw_mac_to_clks(ah, eifs));
83 +       REG_RMW(ah, AR_USEC,
84 +               (common->clockrate - 1) |
85 +               SM(rx_lat, AR_USEC_RX_LAT) |
86 +               SM(tx_lat, AR_USEC_TX_LAT),
87 +               AR_USEC_TX_LAT | AR_USEC_RX_LAT | AR_USEC_USEC);
88 +
89  }
90  EXPORT_SYMBOL(ath9k_hw_init_global_settings);
91