blob: 8d0650a510a26860a7f243c1158daff54dc2285e [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
2 * Copyright (c) 2004 Sam Leffler, Errno Consulting
3 * Copyright (c) 2004 Video54 Technologies, Inc.
4 * Copyright (c) 2008 Atheros Communications Inc.
5 *
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.
9 *
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.
17 */
18
19#ifndef RC_H
20#define RC_H
21
22#include "ath9k.h"
23/*
24 * Interface definitions for transmit rate control modules for the
25 * Atheros driver.
26 *
27 * A rate control module is responsible for choosing the transmit rate
28 * for each data frame. Management+control frames are always sent at
29 * a fixed rate.
30 *
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.
35 *
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.
41 *
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
47 * it's own timer).
48 *
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.
54 */
55
56struct ath_softc;
57
58#define TRUE 1
59#define FALSE 0
60
61#define ATH_RATE_MAX 30
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070062
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070063#define WLAN_PHY_HT_20_SS WLAN_RC_PHY_HT_20_SS
64#define WLAN_PHY_HT_20_DS WLAN_RC_PHY_HT_20_DS
65#define WLAN_PHY_HT_20_DS_HGI WLAN_RC_PHY_HT_20_DS_HGI
66#define WLAN_PHY_HT_40_SS WLAN_RC_PHY_HT_40_SS
67#define WLAN_PHY_HT_40_SS_HGI WLAN_RC_PHY_HT_40_SS_HGI
68#define WLAN_PHY_HT_40_DS WLAN_RC_PHY_HT_40_DS
69#define WLAN_PHY_HT_40_DS_HGI WLAN_RC_PHY_HT_40_DS_HGI
70
71#define WLAN_PHY_OFDM PHY_OFDM
72#define WLAN_PHY_CCK PHY_CCK
73
74#define TRUE_20 0x2
75#define TRUE_40 0x4
76#define TRUE_2040 (TRUE_20|TRUE_40)
77#define TRUE_ALL (TRUE_2040|TRUE)
78
79enum {
80 WLAN_RC_PHY_HT_20_SS = 4,
81 WLAN_RC_PHY_HT_20_DS,
82 WLAN_RC_PHY_HT_40_SS,
83 WLAN_RC_PHY_HT_40_DS,
84 WLAN_RC_PHY_HT_20_SS_HGI,
85 WLAN_RC_PHY_HT_20_DS_HGI,
86 WLAN_RC_PHY_HT_40_SS_HGI,
87 WLAN_RC_PHY_HT_40_DS_HGI,
88 WLAN_RC_PHY_MAX
89};
90
Sujith5701ed82008-08-26 08:11:26 +053091#define WLAN_RC_PHY_DS(_phy) ((_phy == WLAN_RC_PHY_HT_20_DS) \
92 || (_phy == WLAN_RC_PHY_HT_40_DS) \
93 || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
94 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
95#define WLAN_RC_PHY_40(_phy) ((_phy == WLAN_RC_PHY_HT_40_SS) \
96 || (_phy == WLAN_RC_PHY_HT_40_DS) \
97 || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
98 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070099#define WLAN_RC_PHY_SGI(_phy) ((_phy == WLAN_RC_PHY_HT_20_SS_HGI) \
Sujith5701ed82008-08-26 08:11:26 +0530100 || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
101 || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
102 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700103
104#define WLAN_RC_PHY_HT(_phy) (_phy >= WLAN_RC_PHY_HT_20_SS)
105
106/* Returns the capflag mode */
107#define WLAN_RC_CAP_MODE(capflag) (((capflag & WLAN_RC_HT_FLAG) ? \
108 (capflag & WLAN_RC_40_FLAG) ? TRUE_40 : TRUE_20 : TRUE))
109
110/* Return TRUE if flag supports HT20 && client supports HT20 or
111 * return TRUE if flag supports HT40 && client supports HT40.
112 * This is used becos some rates overlap between HT20/HT40.
113 */
114
115#define WLAN_RC_PHY_HT_VALID(flag, capflag) (((flag & TRUE_20) && !(capflag \
116 & WLAN_RC_40_FLAG)) || ((flag & TRUE_40) && \
117 (capflag & WLAN_RC_40_FLAG)))
118
119#define WLAN_RC_DS_FLAG (0x01)
120#define WLAN_RC_40_FLAG (0x02)
121#define WLAN_RC_SGI_FLAG (0x04)
122#define WLAN_RC_HT_FLAG (0x08)
123
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700124#define RATE_TABLE_SIZE 64
125
Sujith5701ed82008-08-26 08:11:26 +0530126/**
127 * struct ath_rate_table - Rate Control table
128 * @valid: valid for use in rate control
129 * @valid_single_stream: valid for use in rate control for
130 * single stream operation
131 * @phy: CCK/OFDM
132 * @ratekbps: rate in Kbits per second
133 * @user_ratekbps: user rate in Kbits per second
134 * @ratecode: rate that goes into HW descriptors
135 * @short_preamble: Mask for enabling short preamble in ratecode for CCK
136 * @dot11rate: value that goes into supported
137 * rates info element of MLME
138 * @ctrl_rate: Index of next lower basic rate, used for duration computation
139 * @max_4ms_framelen: maximum frame length(bytes) for tx duration
140 * @probe_interval: interval for rate control to probe for other rates
141 * @rssi_reduce_interval: interval for rate control to reduce rssi
142 * @initial_ratemax: initial ratemax value used in ath_rc_sib_update()
143 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700144struct ath_rate_table {
145 int rate_cnt;
146 struct {
Sujith5701ed82008-08-26 08:11:26 +0530147 int valid;
148 int valid_single_stream;
149 u8 phy;
150 u32 ratekbps;
151 u32 user_ratekbps;
152 u8 ratecode;
153 u8 short_preamble;
154 u8 dot11rate;
155 u8 ctrl_rate;
156 int8_t rssi_ack_validmin;
157 int8_t rssi_ack_deltamin;
158 u8 base_index;
159 u8 cw40index;
160 u8 sgi_index;
161 u8 ht_index;
162 u32 max_4ms_framelen;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700163 } info[RATE_TABLE_SIZE];
Sujith5701ed82008-08-26 08:11:26 +0530164 u32 probe_interval;
165 u32 rssi_reduce_interval;
166 u8 initial_ratemax;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700167};
168
169#define ATH_RC_PROBE_ALLOWED 0x00000001
170#define ATH_RC_MINRATE_LASTRATE 0x00000002
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700171
172struct ath_rc_series {
Sujith5701ed82008-08-26 08:11:26 +0530173 u8 rix;
174 u8 tries;
175 u8 flags;
176 u32 max_4ms_framelen;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700177};
178
179/* rcs_flags definition */
180#define ATH_RC_DS_FLAG 0x01
181#define ATH_RC_CW40_FLAG 0x02 /* CW 40 */
182#define ATH_RC_SGI_FLAG 0x04 /* Short Guard Interval */
183#define ATH_RC_HT_FLAG 0x08 /* HT */
184#define ATH_RC_RTSCTS_FLAG 0x10 /* RTS-CTS */
185
186/*
187 * State structures for new rate adaptation code
188 */
189#define MAX_TX_RATE_TBL 64
190#define MAX_TX_RATE_PHY 48
191
192struct ath_tx_ratectrl_state {
Sujith5701ed82008-08-26 08:11:26 +0530193 int8_t rssi_thres; /* required rssi for this rate (dB) */
194 u8 per; /* recent estimate of packet error rate (%) */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700195};
196
Sujith256b77592008-11-18 09:03:12 +0530197struct ath_rateset {
198 u8 rs_nrates;
199 u8 rs_rates[ATH_RATE_MAX];
200};
201
202/* per-device state */
203struct ath_rate_softc {
204 /* phy tables that contain rate control data */
205 const void *hw_rate_table[ATH9K_MODE_MAX];
206
207 /* -1 or index of fixed rate */
208 int fixedrix;
209};
210
Sujith5701ed82008-08-26 08:11:26 +0530211/**
Sujith256b77592008-11-18 09:03:12 +0530212 * struct ath_rate_node - Rate Control priv data
Sujith5701ed82008-08-26 08:11:26 +0530213 * @state: RC state
214 * @rssi_last: last ACK rssi
215 * @rssi_last_lookup: last ACK rssi used for lookup
216 * @rssi_last_prev: previous last ACK rssi
217 * @rssi_last_prev2: 2nd previous last ACK rssi
218 * @rssi_sum_cnt: count of rssi_sum for averaging
219 * @rssi_sum_rate: rate that we are averaging
220 * @rssi_sum: running sum of rssi for averaging
221 * @probe_rate: rate we are probing at
222 * @rssi_time: msec timestamp for last ack rssi
223 * @rssi_down_time: msec timestamp for last down step
224 * @probe_time: msec timestamp for last probe
225 * @hw_maxretry_pktcnt: num of packets since we got HW max retry error
226 * @max_valid_rate: maximum number of valid rate
227 * @per_down_time: msec timestamp for last PER down step
228 * @valid_phy_ratecnt: valid rate count
229 * @rate_max_phy: phy index for the max rate
230 * @probe_interval: interval for ratectrl to probe for other rates
Sujith256b77592008-11-18 09:03:12 +0530231 * @prev_data_rix: rate idx of last data frame
232 * @ht_cap: HT capabilities
233 * @single_stream: When TRUE, only single TX stream possible
234 * @neg_rates: Negotatied rates
235 * @neg_ht_rates: Negotiated HT rates
Sujith5701ed82008-08-26 08:11:26 +0530236 */
Sujith256b77592008-11-18 09:03:12 +0530237
238/* per-node state */
239struct ath_rate_node {
Sujith5701ed82008-08-26 08:11:26 +0530240 int8_t rssi_last;
241 int8_t rssi_last_lookup;
242 int8_t rssi_last_prev;
243 int8_t rssi_last_prev2;
244 int32_t rssi_sum_cnt;
245 int32_t rssi_sum_rate;
246 int32_t rssi_sum;
247 u8 rate_table_size;
248 u8 probe_rate;
Sujith5701ed82008-08-26 08:11:26 +0530249 u8 hw_maxretry_pktcnt;
250 u8 max_valid_rate;
251 u8 valid_rate_index[MAX_TX_RATE_TBL];
Sujith256b77592008-11-18 09:03:12 +0530252 u8 ht_cap;
253 u8 single_stream;
Sujith5701ed82008-08-26 08:11:26 +0530254 u8 valid_phy_ratecnt[WLAN_RC_PHY_MAX];
255 u8 valid_phy_rateidx[WLAN_RC_PHY_MAX][MAX_TX_RATE_TBL];
256 u8 rc_phy_mode;
257 u8 rate_max_phy;
Sujith256b77592008-11-18 09:03:12 +0530258 u32 rssi_time;
259 u32 rssi_down_time;
260 u32 probe_time;
261 u32 per_down_time;
Sujith5701ed82008-08-26 08:11:26 +0530262 u32 probe_interval;
Sujith5701ed82008-08-26 08:11:26 +0530263 u32 prev_data_rix;
Sujith256b77592008-11-18 09:03:12 +0530264 struct ath_tx_ratectrl_state state[MAX_TX_RATE_TBL];
Sujith5701ed82008-08-26 08:11:26 +0530265 struct ath_rateset neg_rates;
Sujith5701ed82008-08-26 08:11:26 +0530266 struct ath_rateset neg_ht_rates;
Sujith5701ed82008-08-26 08:11:26 +0530267 struct ath_rate_softc *asc;
268 struct ath_vap *avp;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700269};
270
271/* Driver data of ieee80211_tx_info */
272struct ath_tx_info_priv {
273 struct ath_rc_series rcs[4];
274 struct ath_tx_status tx;
275 int n_frames;
276 int n_bad_frames;
277 u8 min_rate;
278};
279
Sujith46494e62008-11-18 09:05:13 +0530280struct ath_rate_softc *ath_rate_attach(struct ath_softc *sch);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700281void ath_rate_detach(struct ath_rate_softc *asc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700282void ath_rc_node_update(struct ieee80211_hw *hw, struct ath_rate_node *rc_priv);
Sujith2b406f12008-11-18 09:05:35 +0530283u8 ath_rate_findrateix(struct ath_softc *sc, u8 dot11_rate);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700284int ath_rate_control_register(void);
285void ath_rate_control_unregister(void);
286
287#endif /* RC_H */