blob: 199a3ce57d64df520541a6ce0bac2df166e7dce8 [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.
Sujithcee075a2009-03-13 09:07:23 +05304 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07005 *
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
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070022struct ath_softc;
23
Sujith46d14a52008-11-18 09:08:13 +053024#define ATH_RATE_MAX 30
25#define RATE_TABLE_SIZE 64
26#define MAX_TX_RATE_PHY 48
Sujith394cf0a2009-02-09 13:26:54 +053027#define WLAN_CTRL_FRAME_SIZE (2+2+6+4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070028
Sujith2c5a7442008-11-18 09:08:33 +053029/* VALID_ALL - valid for 20/40/Legacy,
30 * VALID - Legacy only,
31 * VALID_20 - HT 20 only,
32 * VALID_40 - HT 40 only */
33
Sujith46d14a52008-11-18 09:08:13 +053034#define INVALID 0x0
35#define VALID 0x1
36#define VALID_20 0x2
37#define VALID_40 0x4
38#define VALID_2040 (VALID_20|VALID_40)
39#define VALID_ALL (VALID_2040|VALID)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070040
Sujith394cf0a2009-02-09 13:26:54 +053041enum {
42 WLAN_RC_PHY_OFDM,
43 WLAN_RC_PHY_CCK,
44 WLAN_RC_PHY_HT_20_SS,
45 WLAN_RC_PHY_HT_20_DS,
46 WLAN_RC_PHY_HT_40_SS,
47 WLAN_RC_PHY_HT_40_DS,
48 WLAN_RC_PHY_HT_20_SS_HGI,
49 WLAN_RC_PHY_HT_20_DS_HGI,
50 WLAN_RC_PHY_HT_40_SS_HGI,
51 WLAN_RC_PHY_HT_40_DS_HGI,
52 WLAN_RC_PHY_MAX
53};
54
Sujith5701ed82008-08-26 08:11:26 +053055#define WLAN_RC_PHY_DS(_phy) ((_phy == WLAN_RC_PHY_HT_20_DS) \
56 || (_phy == WLAN_RC_PHY_HT_40_DS) \
57 || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
58 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
59#define WLAN_RC_PHY_40(_phy) ((_phy == WLAN_RC_PHY_HT_40_SS) \
60 || (_phy == WLAN_RC_PHY_HT_40_DS) \
61 || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
62 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070063#define WLAN_RC_PHY_SGI(_phy) ((_phy == WLAN_RC_PHY_HT_20_SS_HGI) \
Sujith5701ed82008-08-26 08:11:26 +053064 || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
65 || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
66 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070067
68#define WLAN_RC_PHY_HT(_phy) (_phy >= WLAN_RC_PHY_HT_20_SS)
69
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070070#define WLAN_RC_CAP_MODE(capflag) (((capflag & WLAN_RC_HT_FLAG) ? \
Sujith46d14a52008-11-18 09:08:13 +053071 (capflag & WLAN_RC_40_FLAG) ? VALID_40 : VALID_20 : VALID))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070072
73/* Return TRUE if flag supports HT20 && client supports HT20 or
74 * return TRUE if flag supports HT40 && client supports HT40.
75 * This is used becos some rates overlap between HT20/HT40.
76 */
Sujith46d14a52008-11-18 09:08:13 +053077#define WLAN_RC_PHY_HT_VALID(flag, capflag) \
78 (((flag & VALID_20) && !(capflag & WLAN_RC_40_FLAG)) || \
79 ((flag & VALID_40) && (capflag & WLAN_RC_40_FLAG)))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070080
81#define WLAN_RC_DS_FLAG (0x01)
82#define WLAN_RC_40_FLAG (0x02)
83#define WLAN_RC_SGI_FLAG (0x04)
84#define WLAN_RC_HT_FLAG (0x08)
85
Sujith5701ed82008-08-26 08:11:26 +053086/**
87 * struct ath_rate_table - Rate Control table
88 * @valid: valid for use in rate control
89 * @valid_single_stream: valid for use in rate control for
90 * single stream operation
91 * @phy: CCK/OFDM
92 * @ratekbps: rate in Kbits per second
93 * @user_ratekbps: user rate in Kbits per second
94 * @ratecode: rate that goes into HW descriptors
95 * @short_preamble: Mask for enabling short preamble in ratecode for CCK
96 * @dot11rate: value that goes into supported
97 * rates info element of MLME
98 * @ctrl_rate: Index of next lower basic rate, used for duration computation
99 * @max_4ms_framelen: maximum frame length(bytes) for tx duration
100 * @probe_interval: interval for rate control to probe for other rates
101 * @rssi_reduce_interval: interval for rate control to reduce rssi
Sujith46d14a52008-11-18 09:08:13 +0530102 * @initial_ratemax: initial ratemax value
Sujith5701ed82008-08-26 08:11:26 +0530103 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700104struct ath_rate_table {
105 int rate_cnt;
106 struct {
Sujith5701ed82008-08-26 08:11:26 +0530107 int valid;
108 int valid_single_stream;
109 u8 phy;
110 u32 ratekbps;
111 u32 user_ratekbps;
112 u8 ratecode;
113 u8 short_preamble;
114 u8 dot11rate;
115 u8 ctrl_rate;
116 int8_t rssi_ack_validmin;
117 int8_t rssi_ack_deltamin;
118 u8 base_index;
119 u8 cw40index;
120 u8 sgi_index;
121 u8 ht_index;
122 u32 max_4ms_framelen;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700123 } info[RATE_TABLE_SIZE];
Sujith5701ed82008-08-26 08:11:26 +0530124 u32 probe_interval;
125 u32 rssi_reduce_interval;
126 u8 initial_ratemax;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700127};
128
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700129struct ath_tx_ratectrl_state {
Sujith5701ed82008-08-26 08:11:26 +0530130 int8_t rssi_thres; /* required rssi for this rate (dB) */
131 u8 per; /* recent estimate of packet error rate (%) */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700132};
133
Sujith256b7752008-11-18 09:03:12 +0530134struct ath_rateset {
135 u8 rs_nrates;
136 u8 rs_rates[ATH_RATE_MAX];
137};
138
Sujith5701ed82008-08-26 08:11:26 +0530139/**
Sujith46d14a52008-11-18 09:08:13 +0530140 * struct ath_rate_priv - Rate Control priv data
Sujith5701ed82008-08-26 08:11:26 +0530141 * @state: RC state
142 * @rssi_last: last ACK rssi
143 * @rssi_last_lookup: last ACK rssi used for lookup
144 * @rssi_last_prev: previous last ACK rssi
145 * @rssi_last_prev2: 2nd previous last ACK rssi
146 * @rssi_sum_cnt: count of rssi_sum for averaging
147 * @rssi_sum_rate: rate that we are averaging
148 * @rssi_sum: running sum of rssi for averaging
149 * @probe_rate: rate we are probing at
150 * @rssi_time: msec timestamp for last ack rssi
151 * @rssi_down_time: msec timestamp for last down step
152 * @probe_time: msec timestamp for last probe
153 * @hw_maxretry_pktcnt: num of packets since we got HW max retry error
154 * @max_valid_rate: maximum number of valid rate
155 * @per_down_time: msec timestamp for last PER down step
156 * @valid_phy_ratecnt: valid rate count
157 * @rate_max_phy: phy index for the max rate
158 * @probe_interval: interval for ratectrl to probe for other rates
Sujith256b7752008-11-18 09:03:12 +0530159 * @prev_data_rix: rate idx of last data frame
160 * @ht_cap: HT capabilities
161 * @single_stream: When TRUE, only single TX stream possible
162 * @neg_rates: Negotatied rates
163 * @neg_ht_rates: Negotiated HT rates
Sujith5701ed82008-08-26 08:11:26 +0530164 */
Sujith46d14a52008-11-18 09:08:13 +0530165struct ath_rate_priv {
Sujith5701ed82008-08-26 08:11:26 +0530166 int8_t rssi_last;
167 int8_t rssi_last_lookup;
168 int8_t rssi_last_prev;
169 int8_t rssi_last_prev2;
170 int32_t rssi_sum_cnt;
171 int32_t rssi_sum_rate;
172 int32_t rssi_sum;
173 u8 rate_table_size;
174 u8 probe_rate;
Sujith5701ed82008-08-26 08:11:26 +0530175 u8 hw_maxretry_pktcnt;
176 u8 max_valid_rate;
Sujith46d14a52008-11-18 09:08:13 +0530177 u8 valid_rate_index[RATE_TABLE_SIZE];
Sujith256b7752008-11-18 09:03:12 +0530178 u8 ht_cap;
179 u8 single_stream;
Sujith5701ed82008-08-26 08:11:26 +0530180 u8 valid_phy_ratecnt[WLAN_RC_PHY_MAX];
Sujith46d14a52008-11-18 09:08:13 +0530181 u8 valid_phy_rateidx[WLAN_RC_PHY_MAX][RATE_TABLE_SIZE];
Sujith5701ed82008-08-26 08:11:26 +0530182 u8 rc_phy_mode;
183 u8 rate_max_phy;
Sujith256b7752008-11-18 09:03:12 +0530184 u32 rssi_time;
185 u32 rssi_down_time;
186 u32 probe_time;
187 u32 per_down_time;
Sujith5701ed82008-08-26 08:11:26 +0530188 u32 probe_interval;
Sujith5701ed82008-08-26 08:11:26 +0530189 u32 prev_data_rix;
Sujithfe7f4a72008-11-18 09:07:06 +0530190 u32 tx_triglevel_max;
Sujith46d14a52008-11-18 09:08:13 +0530191 struct ath_tx_ratectrl_state state[RATE_TABLE_SIZE];
Sujith5701ed82008-08-26 08:11:26 +0530192 struct ath_rateset neg_rates;
Sujith5701ed82008-08-26 08:11:26 +0530193 struct ath_rateset neg_ht_rates;
Sujith5701ed82008-08-26 08:11:26 +0530194 struct ath_rate_softc *asc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700195};
196
Jouni Malinenf0ed85c2009-03-03 19:23:31 +0200197enum ath9k_internal_frame_type {
198 ATH9K_NOT_INTERNAL,
199 ATH9K_INT_PAUSE,
200 ATH9K_INT_UNPAUSE
201};
202
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700203struct ath_tx_info_priv {
Jouni Malinenc52f33d2009-03-03 19:23:29 +0200204 struct ath_wiphy *aphy;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700205 struct ath_tx_status tx;
206 int n_frames;
207 int n_bad_frames;
Vasanthakumar Thiagarajan7ac47012008-11-20 11:51:18 +0530208 bool update_rc;
Jouni Malinenf0ed85c2009-03-03 19:23:31 +0200209 enum ath9k_internal_frame_type frame_type;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700210};
211
Sujith46d14a52008-11-18 09:08:13 +0530212#define ATH_TX_INFO_PRIV(tx_info) \
213 ((struct ath_tx_info_priv *)((tx_info)->rate_driver_data[0]))
214
Sujithfe7f4a72008-11-18 09:07:06 +0530215void ath_rate_attach(struct ath_softc *sc);
Sujith2b406f12008-11-18 09:05:35 +0530216u8 ath_rate_findrateix(struct ath_softc *sc, u8 dot11_rate);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700217int ath_rate_control_register(void);
218void ath_rate_control_unregister(void);
219
220#endif /* RC_H */