Commit | Line | Data |
---|---|---|
f078f209 LR |
1 | /* |
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" | |
f078f209 LR |
23 | |
24 | struct ath_softc; | |
25 | ||
46d14a58 S |
26 | #define ATH_RATE_MAX 30 |
27 | #define RATE_TABLE_SIZE 64 | |
28 | #define MAX_TX_RATE_PHY 48 | |
f078f209 | 29 | |
2c5a744d S |
30 | /* VALID_ALL - valid for 20/40/Legacy, |
31 | * VALID - Legacy only, | |
32 | * VALID_20 - HT 20 only, | |
33 | * VALID_40 - HT 40 only */ | |
34 | ||
46d14a58 S |
35 | #define INVALID 0x0 |
36 | #define VALID 0x1 | |
37 | #define VALID_20 0x2 | |
38 | #define VALID_40 0x4 | |
39 | #define VALID_2040 (VALID_20|VALID_40) | |
40 | #define VALID_ALL (VALID_2040|VALID) | |
f078f209 | 41 | |
5701ed84 S |
42 | #define WLAN_RC_PHY_DS(_phy) ((_phy == WLAN_RC_PHY_HT_20_DS) \ |
43 | || (_phy == WLAN_RC_PHY_HT_40_DS) \ | |
44 | || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \ | |
45 | || (_phy == WLAN_RC_PHY_HT_40_DS_HGI)) | |
46 | #define WLAN_RC_PHY_40(_phy) ((_phy == WLAN_RC_PHY_HT_40_SS) \ | |
47 | || (_phy == WLAN_RC_PHY_HT_40_DS) \ | |
48 | || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \ | |
49 | || (_phy == WLAN_RC_PHY_HT_40_DS_HGI)) | |
f078f209 | 50 | #define WLAN_RC_PHY_SGI(_phy) ((_phy == WLAN_RC_PHY_HT_20_SS_HGI) \ |
5701ed84 S |
51 | || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \ |
52 | || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \ | |
53 | || (_phy == WLAN_RC_PHY_HT_40_DS_HGI)) | |
f078f209 LR |
54 | |
55 | #define WLAN_RC_PHY_HT(_phy) (_phy >= WLAN_RC_PHY_HT_20_SS) | |
56 | ||
f078f209 | 57 | #define WLAN_RC_CAP_MODE(capflag) (((capflag & WLAN_RC_HT_FLAG) ? \ |
46d14a58 | 58 | (capflag & WLAN_RC_40_FLAG) ? VALID_40 : VALID_20 : VALID)) |
f078f209 LR |
59 | |
60 | /* Return TRUE if flag supports HT20 && client supports HT20 or | |
61 | * return TRUE if flag supports HT40 && client supports HT40. | |
62 | * This is used becos some rates overlap between HT20/HT40. | |
63 | */ | |
46d14a58 S |
64 | #define WLAN_RC_PHY_HT_VALID(flag, capflag) \ |
65 | (((flag & VALID_20) && !(capflag & WLAN_RC_40_FLAG)) || \ | |
66 | ((flag & VALID_40) && (capflag & WLAN_RC_40_FLAG))) | |
f078f209 LR |
67 | |
68 | #define WLAN_RC_DS_FLAG (0x01) | |
69 | #define WLAN_RC_40_FLAG (0x02) | |
70 | #define WLAN_RC_SGI_FLAG (0x04) | |
71 | #define WLAN_RC_HT_FLAG (0x08) | |
72 | ||
5701ed84 S |
73 | /** |
74 | * struct ath_rate_table - Rate Control table | |
75 | * @valid: valid for use in rate control | |
76 | * @valid_single_stream: valid for use in rate control for | |
77 | * single stream operation | |
78 | * @phy: CCK/OFDM | |
79 | * @ratekbps: rate in Kbits per second | |
80 | * @user_ratekbps: user rate in Kbits per second | |
81 | * @ratecode: rate that goes into HW descriptors | |
82 | * @short_preamble: Mask for enabling short preamble in ratecode for CCK | |
83 | * @dot11rate: value that goes into supported | |
84 | * rates info element of MLME | |
85 | * @ctrl_rate: Index of next lower basic rate, used for duration computation | |
86 | * @max_4ms_framelen: maximum frame length(bytes) for tx duration | |
87 | * @probe_interval: interval for rate control to probe for other rates | |
88 | * @rssi_reduce_interval: interval for rate control to reduce rssi | |
46d14a58 | 89 | * @initial_ratemax: initial ratemax value |
5701ed84 | 90 | */ |
f078f209 LR |
91 | struct ath_rate_table { |
92 | int rate_cnt; | |
93 | struct { | |
5701ed84 S |
94 | int valid; |
95 | int valid_single_stream; | |
96 | u8 phy; | |
97 | u32 ratekbps; | |
98 | u32 user_ratekbps; | |
99 | u8 ratecode; | |
100 | u8 short_preamble; | |
101 | u8 dot11rate; | |
102 | u8 ctrl_rate; | |
103 | int8_t rssi_ack_validmin; | |
104 | int8_t rssi_ack_deltamin; | |
105 | u8 base_index; | |
106 | u8 cw40index; | |
107 | u8 sgi_index; | |
108 | u8 ht_index; | |
109 | u32 max_4ms_framelen; | |
e63835b0 S |
110 | u16 lpAckDuration; |
111 | u16 spAckDuration; | |
f078f209 | 112 | } info[RATE_TABLE_SIZE]; |
5701ed84 S |
113 | u32 probe_interval; |
114 | u32 rssi_reduce_interval; | |
115 | u8 initial_ratemax; | |
f078f209 LR |
116 | }; |
117 | ||
f078f209 | 118 | struct ath_tx_ratectrl_state { |
5701ed84 S |
119 | int8_t rssi_thres; /* required rssi for this rate (dB) */ |
120 | u8 per; /* recent estimate of packet error rate (%) */ | |
f078f209 LR |
121 | }; |
122 | ||
256b7759 S |
123 | struct ath_rateset { |
124 | u8 rs_nrates; | |
125 | u8 rs_rates[ATH_RATE_MAX]; | |
126 | }; | |
127 | ||
5701ed84 | 128 | /** |
46d14a58 | 129 | * struct ath_rate_priv - Rate Control priv data |
5701ed84 S |
130 | * @state: RC state |
131 | * @rssi_last: last ACK rssi | |
132 | * @rssi_last_lookup: last ACK rssi used for lookup | |
133 | * @rssi_last_prev: previous last ACK rssi | |
134 | * @rssi_last_prev2: 2nd previous last ACK rssi | |
135 | * @rssi_sum_cnt: count of rssi_sum for averaging | |
136 | * @rssi_sum_rate: rate that we are averaging | |
137 | * @rssi_sum: running sum of rssi for averaging | |
138 | * @probe_rate: rate we are probing at | |
139 | * @rssi_time: msec timestamp for last ack rssi | |
140 | * @rssi_down_time: msec timestamp for last down step | |
141 | * @probe_time: msec timestamp for last probe | |
142 | * @hw_maxretry_pktcnt: num of packets since we got HW max retry error | |
143 | * @max_valid_rate: maximum number of valid rate | |
144 | * @per_down_time: msec timestamp for last PER down step | |
145 | * @valid_phy_ratecnt: valid rate count | |
146 | * @rate_max_phy: phy index for the max rate | |
147 | * @probe_interval: interval for ratectrl to probe for other rates | |
256b7759 S |
148 | * @prev_data_rix: rate idx of last data frame |
149 | * @ht_cap: HT capabilities | |
150 | * @single_stream: When TRUE, only single TX stream possible | |
151 | * @neg_rates: Negotatied rates | |
152 | * @neg_ht_rates: Negotiated HT rates | |
5701ed84 | 153 | */ |
46d14a58 | 154 | struct ath_rate_priv { |
5701ed84 S |
155 | int8_t rssi_last; |
156 | int8_t rssi_last_lookup; | |
157 | int8_t rssi_last_prev; | |
158 | int8_t rssi_last_prev2; | |
159 | int32_t rssi_sum_cnt; | |
160 | int32_t rssi_sum_rate; | |
161 | int32_t rssi_sum; | |
162 | u8 rate_table_size; | |
163 | u8 probe_rate; | |
5701ed84 S |
164 | u8 hw_maxretry_pktcnt; |
165 | u8 max_valid_rate; | |
46d14a58 | 166 | u8 valid_rate_index[RATE_TABLE_SIZE]; |
256b7759 S |
167 | u8 ht_cap; |
168 | u8 single_stream; | |
5701ed84 | 169 | u8 valid_phy_ratecnt[WLAN_RC_PHY_MAX]; |
46d14a58 | 170 | u8 valid_phy_rateidx[WLAN_RC_PHY_MAX][RATE_TABLE_SIZE]; |
5701ed84 S |
171 | u8 rc_phy_mode; |
172 | u8 rate_max_phy; | |
256b7759 S |
173 | u32 rssi_time; |
174 | u32 rssi_down_time; | |
175 | u32 probe_time; | |
176 | u32 per_down_time; | |
5701ed84 | 177 | u32 probe_interval; |
5701ed84 | 178 | u32 prev_data_rix; |
fe7f4a77 | 179 | u32 tx_triglevel_max; |
46d14a58 | 180 | struct ath_tx_ratectrl_state state[RATE_TABLE_SIZE]; |
5701ed84 | 181 | struct ath_rateset neg_rates; |
5701ed84 | 182 | struct ath_rateset neg_ht_rates; |
5701ed84 | 183 | struct ath_rate_softc *asc; |
f078f209 LR |
184 | }; |
185 | ||
f078f209 | 186 | struct ath_tx_info_priv { |
f078f209 LR |
187 | struct ath_tx_status tx; |
188 | int n_frames; | |
189 | int n_bad_frames; | |
7ac47010 | 190 | bool update_rc; |
f078f209 LR |
191 | }; |
192 | ||
46d14a58 S |
193 | #define ATH_TX_INFO_PRIV(tx_info) \ |
194 | ((struct ath_tx_info_priv *)((tx_info)->rate_driver_data[0])) | |
195 | ||
fe7f4a77 | 196 | void ath_rate_attach(struct ath_softc *sc); |
2b406f1e | 197 | u8 ath_rate_findrateix(struct ath_softc *sc, u8 dot11_rate); |
f078f209 LR |
198 | int ath_rate_control_register(void); |
199 | void ath_rate_control_unregister(void); | |
200 | ||
201 | #endif /* RC_H */ |