Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 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" |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 23 | |
| 24 | struct ath_softc; |
| 25 | |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 26 | #define ATH_RATE_MAX 30 |
| 27 | #define RATE_TABLE_SIZE 64 |
| 28 | #define MAX_TX_RATE_PHY 48 |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 29 | |
Sujith | 2c5a744 | 2008-11-18 09:08:33 +0530 | [diff] [blame] | 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 | |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 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) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 41 | |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 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)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 50 | #define WLAN_RC_PHY_SGI(_phy) ((_phy == WLAN_RC_PHY_HT_20_SS_HGI) \ |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 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)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 54 | |
| 55 | #define WLAN_RC_PHY_HT(_phy) (_phy >= WLAN_RC_PHY_HT_20_SS) |
| 56 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 57 | #define WLAN_RC_CAP_MODE(capflag) (((capflag & WLAN_RC_HT_FLAG) ? \ |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 58 | (capflag & WLAN_RC_40_FLAG) ? VALID_40 : VALID_20 : VALID)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 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 | */ |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 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))) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 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 | |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 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 |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 89 | * @initial_ratemax: initial ratemax value |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 90 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 91 | struct ath_rate_table { |
| 92 | int rate_cnt; |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 93 | u8 rateCodeToIndex[256]; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 94 | struct { |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 95 | int valid; |
| 96 | int valid_single_stream; |
| 97 | u8 phy; |
| 98 | u32 ratekbps; |
| 99 | u32 user_ratekbps; |
| 100 | u8 ratecode; |
| 101 | u8 short_preamble; |
| 102 | u8 dot11rate; |
| 103 | u8 ctrl_rate; |
| 104 | int8_t rssi_ack_validmin; |
| 105 | int8_t rssi_ack_deltamin; |
| 106 | u8 base_index; |
| 107 | u8 cw40index; |
| 108 | u8 sgi_index; |
| 109 | u8 ht_index; |
| 110 | u32 max_4ms_framelen; |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 111 | u16 lpAckDuration; |
| 112 | u16 spAckDuration; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 113 | } info[RATE_TABLE_SIZE]; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 114 | u32 probe_interval; |
| 115 | u32 rssi_reduce_interval; |
| 116 | u8 initial_ratemax; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 119 | struct ath_tx_ratectrl_state { |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 120 | int8_t rssi_thres; /* required rssi for this rate (dB) */ |
| 121 | u8 per; /* recent estimate of packet error rate (%) */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
Sujith | 256b775 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 124 | struct ath_rateset { |
| 125 | u8 rs_nrates; |
| 126 | u8 rs_rates[ATH_RATE_MAX]; |
| 127 | }; |
| 128 | |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 129 | /** |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 130 | * struct ath_rate_priv - Rate Control priv data |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 131 | * @state: RC state |
| 132 | * @rssi_last: last ACK rssi |
| 133 | * @rssi_last_lookup: last ACK rssi used for lookup |
| 134 | * @rssi_last_prev: previous last ACK rssi |
| 135 | * @rssi_last_prev2: 2nd previous last ACK rssi |
| 136 | * @rssi_sum_cnt: count of rssi_sum for averaging |
| 137 | * @rssi_sum_rate: rate that we are averaging |
| 138 | * @rssi_sum: running sum of rssi for averaging |
| 139 | * @probe_rate: rate we are probing at |
| 140 | * @rssi_time: msec timestamp for last ack rssi |
| 141 | * @rssi_down_time: msec timestamp for last down step |
| 142 | * @probe_time: msec timestamp for last probe |
| 143 | * @hw_maxretry_pktcnt: num of packets since we got HW max retry error |
| 144 | * @max_valid_rate: maximum number of valid rate |
| 145 | * @per_down_time: msec timestamp for last PER down step |
| 146 | * @valid_phy_ratecnt: valid rate count |
| 147 | * @rate_max_phy: phy index for the max rate |
| 148 | * @probe_interval: interval for ratectrl to probe for other rates |
Sujith | 256b775 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 149 | * @prev_data_rix: rate idx of last data frame |
| 150 | * @ht_cap: HT capabilities |
| 151 | * @single_stream: When TRUE, only single TX stream possible |
| 152 | * @neg_rates: Negotatied rates |
| 153 | * @neg_ht_rates: Negotiated HT rates |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 154 | */ |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 155 | struct ath_rate_priv { |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 156 | int8_t rssi_last; |
| 157 | int8_t rssi_last_lookup; |
| 158 | int8_t rssi_last_prev; |
| 159 | int8_t rssi_last_prev2; |
| 160 | int32_t rssi_sum_cnt; |
| 161 | int32_t rssi_sum_rate; |
| 162 | int32_t rssi_sum; |
| 163 | u8 rate_table_size; |
| 164 | u8 probe_rate; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 165 | u8 hw_maxretry_pktcnt; |
| 166 | u8 max_valid_rate; |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 167 | u8 valid_rate_index[RATE_TABLE_SIZE]; |
Sujith | 256b775 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 168 | u8 ht_cap; |
| 169 | u8 single_stream; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 170 | u8 valid_phy_ratecnt[WLAN_RC_PHY_MAX]; |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 171 | u8 valid_phy_rateidx[WLAN_RC_PHY_MAX][RATE_TABLE_SIZE]; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 172 | u8 rc_phy_mode; |
| 173 | u8 rate_max_phy; |
Sujith | 256b775 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 174 | u32 rssi_time; |
| 175 | u32 rssi_down_time; |
| 176 | u32 probe_time; |
| 177 | u32 per_down_time; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 178 | u32 probe_interval; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 179 | u32 prev_data_rix; |
Sujith | fe7f4a7 | 2008-11-18 09:07:06 +0530 | [diff] [blame] | 180 | u32 tx_triglevel_max; |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 181 | struct ath_tx_ratectrl_state state[RATE_TABLE_SIZE]; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 182 | struct ath_rateset neg_rates; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 183 | struct ath_rateset neg_ht_rates; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 184 | struct ath_rate_softc *asc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 185 | }; |
| 186 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 187 | struct ath_tx_info_priv { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 188 | struct ath_tx_status tx; |
| 189 | int n_frames; |
| 190 | int n_bad_frames; |
Vasanthakumar Thiagarajan | 7ac4701 | 2008-11-20 11:51:18 +0530 | [diff] [blame] | 191 | bool update_rc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 192 | }; |
| 193 | |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 194 | #define ATH_TX_INFO_PRIV(tx_info) \ |
| 195 | ((struct ath_tx_info_priv *)((tx_info)->rate_driver_data[0])) |
| 196 | |
Sujith | fe7f4a7 | 2008-11-18 09:07:06 +0530 | [diff] [blame] | 197 | void ath_rate_attach(struct ath_softc *sc); |
Sujith | 2b406f1 | 2008-11-18 09:05:35 +0530 | [diff] [blame] | 198 | u8 ath_rate_findrateix(struct ath_softc *sc, u8 dot11_rate); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 199 | int ath_rate_control_register(void); |
| 200 | void ath_rate_control_unregister(void); |
| 201 | |
| 202 | #endif /* RC_H */ |