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. |
Sujith | cee075a | 2009-03-13 09:07:23 +0530 | [diff] [blame] | 4 | * Copyright (c) 2008-2009 Atheros Communications Inc. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 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 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 22 | struct ath_softc; |
| 23 | |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 24 | #define ATH_RATE_MAX 30 |
| 25 | #define RATE_TABLE_SIZE 64 |
| 26 | #define MAX_TX_RATE_PHY 48 |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 27 | |
Sujith | 2c5a744 | 2008-11-18 09:08:33 +0530 | [diff] [blame] | 28 | /* VALID_ALL - valid for 20/40/Legacy, |
| 29 | * VALID - Legacy only, |
| 30 | * VALID_20 - HT 20 only, |
| 31 | * VALID_40 - HT 40 only */ |
| 32 | |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 33 | #define INVALID 0x0 |
| 34 | #define VALID 0x1 |
| 35 | #define VALID_20 0x2 |
| 36 | #define VALID_40 0x4 |
| 37 | #define VALID_2040 (VALID_20|VALID_40) |
| 38 | #define VALID_ALL (VALID_2040|VALID) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 39 | |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 40 | enum { |
| 41 | WLAN_RC_PHY_OFDM, |
| 42 | WLAN_RC_PHY_CCK, |
| 43 | WLAN_RC_PHY_HT_20_SS, |
| 44 | WLAN_RC_PHY_HT_20_DS, |
| 45 | WLAN_RC_PHY_HT_40_SS, |
| 46 | WLAN_RC_PHY_HT_40_DS, |
| 47 | WLAN_RC_PHY_HT_20_SS_HGI, |
| 48 | WLAN_RC_PHY_HT_20_DS_HGI, |
| 49 | WLAN_RC_PHY_HT_40_SS_HGI, |
| 50 | WLAN_RC_PHY_HT_40_DS_HGI, |
| 51 | WLAN_RC_PHY_MAX |
| 52 | }; |
| 53 | |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 54 | #define WLAN_RC_PHY_DS(_phy) ((_phy == WLAN_RC_PHY_HT_20_DS) \ |
| 55 | || (_phy == WLAN_RC_PHY_HT_40_DS) \ |
| 56 | || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \ |
| 57 | || (_phy == WLAN_RC_PHY_HT_40_DS_HGI)) |
| 58 | #define WLAN_RC_PHY_40(_phy) ((_phy == WLAN_RC_PHY_HT_40_SS) \ |
| 59 | || (_phy == WLAN_RC_PHY_HT_40_DS) \ |
| 60 | || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \ |
| 61 | || (_phy == WLAN_RC_PHY_HT_40_DS_HGI)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 62 | #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] | 63 | || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \ |
| 64 | || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \ |
| 65 | || (_phy == WLAN_RC_PHY_HT_40_DS_HGI)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 66 | |
| 67 | #define WLAN_RC_PHY_HT(_phy) (_phy >= WLAN_RC_PHY_HT_20_SS) |
| 68 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 69 | #define WLAN_RC_CAP_MODE(capflag) (((capflag & WLAN_RC_HT_FLAG) ? \ |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 70 | (capflag & WLAN_RC_40_FLAG) ? VALID_40 : VALID_20 : VALID)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 71 | |
| 72 | /* Return TRUE if flag supports HT20 && client supports HT20 or |
| 73 | * return TRUE if flag supports HT40 && client supports HT40. |
| 74 | * This is used becos some rates overlap between HT20/HT40. |
| 75 | */ |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 76 | #define WLAN_RC_PHY_HT_VALID(flag, capflag) \ |
| 77 | (((flag & VALID_20) && !(capflag & WLAN_RC_40_FLAG)) || \ |
| 78 | ((flag & VALID_40) && (capflag & WLAN_RC_40_FLAG))) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 79 | |
| 80 | #define WLAN_RC_DS_FLAG (0x01) |
| 81 | #define WLAN_RC_40_FLAG (0x02) |
| 82 | #define WLAN_RC_SGI_FLAG (0x04) |
| 83 | #define WLAN_RC_HT_FLAG (0x08) |
| 84 | |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 85 | /** |
| 86 | * struct ath_rate_table - Rate Control table |
| 87 | * @valid: valid for use in rate control |
| 88 | * @valid_single_stream: valid for use in rate control for |
| 89 | * single stream operation |
| 90 | * @phy: CCK/OFDM |
| 91 | * @ratekbps: rate in Kbits per second |
| 92 | * @user_ratekbps: user rate in Kbits per second |
| 93 | * @ratecode: rate that goes into HW descriptors |
| 94 | * @short_preamble: Mask for enabling short preamble in ratecode for CCK |
| 95 | * @dot11rate: value that goes into supported |
| 96 | * rates info element of MLME |
| 97 | * @ctrl_rate: Index of next lower basic rate, used for duration computation |
| 98 | * @max_4ms_framelen: maximum frame length(bytes) for tx duration |
| 99 | * @probe_interval: interval for rate control to probe for other rates |
| 100 | * @rssi_reduce_interval: interval for rate control to reduce rssi |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 101 | * @initial_ratemax: initial ratemax value |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 102 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 103 | struct ath_rate_table { |
| 104 | int rate_cnt; |
| 105 | struct { |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 106 | int valid; |
| 107 | int valid_single_stream; |
| 108 | u8 phy; |
| 109 | u32 ratekbps; |
| 110 | u32 user_ratekbps; |
| 111 | u8 ratecode; |
| 112 | u8 short_preamble; |
| 113 | u8 dot11rate; |
| 114 | u8 ctrl_rate; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 115 | u8 base_index; |
| 116 | u8 cw40index; |
| 117 | u8 sgi_index; |
| 118 | u8 ht_index; |
| 119 | u32 max_4ms_framelen; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 120 | } info[RATE_TABLE_SIZE]; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 121 | u32 probe_interval; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 122 | u8 initial_ratemax; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 125 | struct ath_tx_ratectrl_state { |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 126 | u8 per; /* recent estimate of packet error rate (%) */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 127 | }; |
| 128 | |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 129 | struct ath_rateset { |
| 130 | u8 rs_nrates; |
| 131 | u8 rs_rates[ATH_RATE_MAX]; |
| 132 | }; |
| 133 | |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 134 | /** |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 135 | * struct ath_rate_priv - Rate Control priv data |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 136 | * @state: RC state |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 137 | * @probe_rate: rate we are probing at |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 138 | * @probe_time: msec timestamp for last probe |
| 139 | * @hw_maxretry_pktcnt: num of packets since we got HW max retry error |
| 140 | * @max_valid_rate: maximum number of valid rate |
| 141 | * @per_down_time: msec timestamp for last PER down step |
| 142 | * @valid_phy_ratecnt: valid rate count |
| 143 | * @rate_max_phy: phy index for the max rate |
| 144 | * @probe_interval: interval for ratectrl to probe for other rates |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 145 | * @prev_data_rix: rate idx of last data frame |
| 146 | * @ht_cap: HT capabilities |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 147 | * @neg_rates: Negotatied rates |
| 148 | * @neg_ht_rates: Negotiated HT rates |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 149 | */ |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 150 | struct ath_rate_priv { |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 151 | u8 rate_table_size; |
| 152 | u8 probe_rate; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 153 | u8 hw_maxretry_pktcnt; |
| 154 | u8 max_valid_rate; |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 155 | u8 valid_rate_index[RATE_TABLE_SIZE]; |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 156 | u8 ht_cap; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 157 | u8 valid_phy_ratecnt[WLAN_RC_PHY_MAX]; |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 158 | u8 valid_phy_rateidx[WLAN_RC_PHY_MAX][RATE_TABLE_SIZE]; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 159 | u8 rate_max_phy; |
Sujith | 256b7759 | 2008-11-18 09:03:12 +0530 | [diff] [blame] | 160 | u32 probe_time; |
| 161 | u32 per_down_time; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 162 | u32 probe_interval; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 163 | u32 prev_data_rix; |
Sujith | fe7f4a7 | 2008-11-18 09:07:06 +0530 | [diff] [blame] | 164 | u32 tx_triglevel_max; |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 165 | struct ath_tx_ratectrl_state state[RATE_TABLE_SIZE]; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 166 | struct ath_rateset neg_rates; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 167 | struct ath_rateset neg_ht_rates; |
Sujith | 5701ed8 | 2008-08-26 08:11:26 +0530 | [diff] [blame] | 168 | struct ath_rate_softc *asc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 169 | }; |
| 170 | |
Jouni Malinen | f0ed85c | 2009-03-03 19:23:31 +0200 | [diff] [blame] | 171 | enum ath9k_internal_frame_type { |
| 172 | ATH9K_NOT_INTERNAL, |
| 173 | ATH9K_INT_PAUSE, |
| 174 | ATH9K_INT_UNPAUSE |
| 175 | }; |
| 176 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 177 | struct ath_tx_info_priv { |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 178 | struct ath_wiphy *aphy; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 179 | struct ath_tx_status tx; |
| 180 | int n_frames; |
| 181 | int n_bad_frames; |
Vasanthakumar Thiagarajan | 7ac4701 | 2008-11-20 11:51:18 +0530 | [diff] [blame] | 182 | bool update_rc; |
Jouni Malinen | f0ed85c | 2009-03-03 19:23:31 +0200 | [diff] [blame] | 183 | enum ath9k_internal_frame_type frame_type; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
Sujith | 46d14a5 | 2008-11-18 09:08:13 +0530 | [diff] [blame] | 186 | #define ATH_TX_INFO_PRIV(tx_info) \ |
| 187 | ((struct ath_tx_info_priv *)((tx_info)->rate_driver_data[0])) |
| 188 | |
Sujith | fe7f4a7 | 2008-11-18 09:07:06 +0530 | [diff] [blame] | 189 | void ath_rate_attach(struct ath_softc *sc); |
Sujith | 2b406f1 | 2008-11-18 09:05:35 +0530 | [diff] [blame] | 190 | u8 ath_rate_findrateix(struct ath_softc *sc, u8 dot11_rate); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 191 | int ath_rate_control_register(void); |
| 192 | void ath_rate_control_unregister(void); |
| 193 | |
| 194 | #endif /* RC_H */ |