2 * Copyright (c) 2004 Sam Leffler, Errno Consulting
3 * Copyright (c) 2004 Video54 Technologies, Inc.
4 * Copyright (c) 2008 Atheros Communications Inc.
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Interface definitions for transmit rate control modules for the
27 * A rate control module is responsible for choosing the transmit rate
28 * for each data frame. Management+control frames are always sent at
31 * Only one module may be present at a time; the driver references
32 * rate control interfaces by symbol name. If multiple modules are
33 * to be supported we'll need to switch to a registration-based scheme
34 * as is currently done, for example, for authentication modules.
36 * An instance of the rate control module is attached to each device
37 * at attach time and detached when the device is destroyed. The module
38 * may associate data with each device and each node (station). Both
39 * sets of storage are opaque except for the size of the per-node storage
40 * which must be provided when the module is attached.
42 * The rate control module is notified for each state transition and
43 * station association/reassociation. Otherwise it is queried for a
44 * rate for each outgoing frame and provided status from each transmitted
45 * frame. Any ancillary processing is the responsibility of the module
46 * (e.g. if periodic processing is required then the module should setup
49 * In addition to the transmit rate for each frame the module must also
50 * indicate the number of attempts to make at the specified rate. If this
51 * number is != ATH_TXMAXTRY then an additional callback is made to setup
52 * additional transmit state. The rate control code is assumed to write
53 * this additional data directly to the transmit descriptor.
61 #define ATH_RATE_MAX 30
63 enum ieee80211_fixed_rate_mode {
64 IEEE80211_FIXED_RATE_NONE = 0,
65 IEEE80211_FIXED_RATE_MCS = 1 /* HT rates */
69 * Use the hal os glue code to get ms time
71 #define IEEE80211_RATE_IDX_ENTRY(val, idx) (((val&(0xff<<(idx*8)))>>(idx*8)))
73 #define WLAN_PHY_HT_20_SS WLAN_RC_PHY_HT_20_SS
74 #define WLAN_PHY_HT_20_DS WLAN_RC_PHY_HT_20_DS
75 #define WLAN_PHY_HT_20_DS_HGI WLAN_RC_PHY_HT_20_DS_HGI
76 #define WLAN_PHY_HT_40_SS WLAN_RC_PHY_HT_40_SS
77 #define WLAN_PHY_HT_40_SS_HGI WLAN_RC_PHY_HT_40_SS_HGI
78 #define WLAN_PHY_HT_40_DS WLAN_RC_PHY_HT_40_DS
79 #define WLAN_PHY_HT_40_DS_HGI WLAN_RC_PHY_HT_40_DS_HGI
81 #define WLAN_PHY_OFDM PHY_OFDM
82 #define WLAN_PHY_CCK PHY_CCK
86 #define TRUE_2040 (TRUE_20|TRUE_40)
87 #define TRUE_ALL (TRUE_2040|TRUE)
90 WLAN_RC_PHY_HT_20_SS = 4,
94 WLAN_RC_PHY_HT_20_SS_HGI,
95 WLAN_RC_PHY_HT_20_DS_HGI,
96 WLAN_RC_PHY_HT_40_SS_HGI,
97 WLAN_RC_PHY_HT_40_DS_HGI,
101 #define WLAN_RC_PHY_DS(_phy) ((_phy == WLAN_RC_PHY_HT_20_DS) \
102 || (_phy == WLAN_RC_PHY_HT_40_DS) \
103 || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
104 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
105 #define WLAN_RC_PHY_40(_phy) ((_phy == WLAN_RC_PHY_HT_40_SS) \
106 || (_phy == WLAN_RC_PHY_HT_40_DS) \
107 || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
108 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
109 #define WLAN_RC_PHY_SGI(_phy) ((_phy == WLAN_RC_PHY_HT_20_SS_HGI) \
110 || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
111 || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
112 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
114 #define WLAN_RC_PHY_HT(_phy) (_phy >= WLAN_RC_PHY_HT_20_SS)
116 /* Returns the capflag mode */
117 #define WLAN_RC_CAP_MODE(capflag) (((capflag & WLAN_RC_HT_FLAG) ? \
118 (capflag & WLAN_RC_40_FLAG) ? TRUE_40 : TRUE_20 : TRUE))
120 /* Return TRUE if flag supports HT20 && client supports HT20 or
121 * return TRUE if flag supports HT40 && client supports HT40.
122 * This is used becos some rates overlap between HT20/HT40.
125 #define WLAN_RC_PHY_HT_VALID(flag, capflag) (((flag & TRUE_20) && !(capflag \
126 & WLAN_RC_40_FLAG)) || ((flag & TRUE_40) && \
127 (capflag & WLAN_RC_40_FLAG)))
129 #define WLAN_RC_DS_FLAG (0x01)
130 #define WLAN_RC_40_FLAG (0x02)
131 #define WLAN_RC_SGI_FLAG (0x04)
132 #define WLAN_RC_HT_FLAG (0x08)
134 #define RATE_TABLE_SIZE 64
137 * struct ath_rate_table - Rate Control table
138 * @valid: valid for use in rate control
139 * @valid_single_stream: valid for use in rate control for
140 * single stream operation
142 * @ratekbps: rate in Kbits per second
143 * @user_ratekbps: user rate in Kbits per second
144 * @ratecode: rate that goes into HW descriptors
145 * @short_preamble: Mask for enabling short preamble in ratecode for CCK
146 * @dot11rate: value that goes into supported
147 * rates info element of MLME
148 * @ctrl_rate: Index of next lower basic rate, used for duration computation
149 * @max_4ms_framelen: maximum frame length(bytes) for tx duration
150 * @probe_interval: interval for rate control to probe for other rates
151 * @rssi_reduce_interval: interval for rate control to reduce rssi
152 * @initial_ratemax: initial ratemax value used in ath_rc_sib_update()
154 struct ath_rate_table {
158 int valid_single_stream;
166 int8_t rssi_ack_validmin;
167 int8_t rssi_ack_deltamin;
172 u32 max_4ms_framelen;
173 } info[RATE_TABLE_SIZE];
175 u32 rssi_reduce_interval;
179 #define ATH_RC_PROBE_ALLOWED 0x00000001
180 #define ATH_RC_MINRATE_LASTRATE 0x00000002
182 struct ath_rc_series {
186 u32 max_4ms_framelen;
189 /* rcs_flags definition */
190 #define ATH_RC_DS_FLAG 0x01
191 #define ATH_RC_CW40_FLAG 0x02 /* CW 40 */
192 #define ATH_RC_SGI_FLAG 0x04 /* Short Guard Interval */
193 #define ATH_RC_HT_FLAG 0x08 /* HT */
194 #define ATH_RC_RTSCTS_FLAG 0x10 /* RTS-CTS */
197 * State structures for new rate adaptation code
199 #define MAX_TX_RATE_TBL 64
200 #define MAX_TX_RATE_PHY 48
202 struct ath_tx_ratectrl_state {
203 int8_t rssi_thres; /* required rssi for this rate (dB) */
204 u8 per; /* recent estimate of packet error rate (%) */
208 * struct ath_tx_ratectrl - TX Rate control Information
210 * @rssi_last: last ACK rssi
211 * @rssi_last_lookup: last ACK rssi used for lookup
212 * @rssi_last_prev: previous last ACK rssi
213 * @rssi_last_prev2: 2nd previous last ACK rssi
214 * @rssi_sum_cnt: count of rssi_sum for averaging
215 * @rssi_sum_rate: rate that we are averaging
216 * @rssi_sum: running sum of rssi for averaging
217 * @probe_rate: rate we are probing at
218 * @rssi_time: msec timestamp for last ack rssi
219 * @rssi_down_time: msec timestamp for last down step
220 * @probe_time: msec timestamp for last probe
221 * @hw_maxretry_pktcnt: num of packets since we got HW max retry error
222 * @max_valid_rate: maximum number of valid rate
223 * @per_down_time: msec timestamp for last PER down step
224 * @valid_phy_ratecnt: valid rate count
225 * @rate_max_phy: phy index for the max rate
226 * @probe_interval: interval for ratectrl to probe for other rates
228 struct ath_tx_ratectrl {
229 struct ath_tx_ratectrl_state state[MAX_TX_RATE_TBL];
231 int8_t rssi_last_lookup;
232 int8_t rssi_last_prev;
233 int8_t rssi_last_prev2;
234 int32_t rssi_sum_cnt;
235 int32_t rssi_sum_rate;
242 u8 hw_maxretry_pktcnt;
244 u8 valid_rate_index[MAX_TX_RATE_TBL];
248 u8 valid_phy_ratecnt[WLAN_RC_PHY_MAX];
249 u8 valid_phy_rateidx[WLAN_RC_PHY_MAX][MAX_TX_RATE_TBL];
257 u8 rs_rates[ATH_RATE_MAX];
260 /* per-device state */
261 struct ath_rate_softc {
262 /* phy tables that contain rate control data */
263 const void *hw_rate_table[ATH9K_MODE_MAX];
265 /* -1 or index of fixed rate */
270 struct ath_rate_node {
271 struct ath_tx_ratectrl tx_ratectrl;
273 /* rate idx of last data frame */
276 /* ht capabilities */
279 /* When TRUE, only single stream Tx possible */
282 /* Negotiated rates */
283 struct ath_rateset neg_rates;
285 /* Negotiated HT rates */
286 struct ath_rateset neg_ht_rates;
288 struct ath_rate_softc *asc;
292 /* Driver data of ieee80211_tx_info */
293 struct ath_tx_info_priv {
294 struct ath_rc_series rcs[4];
295 struct ath_tx_status tx;
302 * Attach/detach a rate control module.
304 struct ath_rate_softc *ath_rate_attach(struct ath_hal *ah);
305 void ath_rate_detach(struct ath_rate_softc *asc);
308 * Update/reset rate control state for 802.11 state transitions.
309 * Important mostly as the analog to ath_rate_newassoc when operating
312 void ath_rc_node_update(struct ieee80211_hw *hw, struct ath_rate_node *rc_priv);
313 void ath_rate_newstate(struct ath_softc *sc, struct ath_vap *avp);
316 * Return rate index for given Dot11 Rate.
318 u8 ath_rate_findrateix(struct ath_softc *sc,
321 /* Routines to register/unregister rate control algorithm */
322 int ath_rate_control_register(void);
323 void ath_rate_control_unregister(void);