blob: dff4b7ade3df35df17a131d240db61ef97d1ab2c [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"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070023
24struct ath_softc;
25
Sujith46d14a52008-11-18 09:08:13 +053026#define ATH_RATE_MAX 30
27#define RATE_TABLE_SIZE 64
28#define MAX_TX_RATE_PHY 48
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070029
Sujith46d14a52008-11-18 09:08:13 +053030#define INVALID 0x0
31#define VALID 0x1
32#define VALID_20 0x2
33#define VALID_40 0x4
34#define VALID_2040 (VALID_20|VALID_40)
35#define VALID_ALL (VALID_2040|VALID)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070036
Sujith5701ed82008-08-26 08:11:26 +053037#define WLAN_RC_PHY_DS(_phy) ((_phy == WLAN_RC_PHY_HT_20_DS) \
38 || (_phy == WLAN_RC_PHY_HT_40_DS) \
39 || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
40 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
41#define WLAN_RC_PHY_40(_phy) ((_phy == WLAN_RC_PHY_HT_40_SS) \
42 || (_phy == WLAN_RC_PHY_HT_40_DS) \
43 || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
44 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070045#define WLAN_RC_PHY_SGI(_phy) ((_phy == WLAN_RC_PHY_HT_20_SS_HGI) \
Sujith5701ed82008-08-26 08:11:26 +053046 || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
47 || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
48 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070049
50#define WLAN_RC_PHY_HT(_phy) (_phy >= WLAN_RC_PHY_HT_20_SS)
51
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070052#define WLAN_RC_CAP_MODE(capflag) (((capflag & WLAN_RC_HT_FLAG) ? \
Sujith46d14a52008-11-18 09:08:13 +053053 (capflag & WLAN_RC_40_FLAG) ? VALID_40 : VALID_20 : VALID))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070054
55/* Return TRUE if flag supports HT20 && client supports HT20 or
56 * return TRUE if flag supports HT40 && client supports HT40.
57 * This is used becos some rates overlap between HT20/HT40.
58 */
Sujith46d14a52008-11-18 09:08:13 +053059#define WLAN_RC_PHY_HT_VALID(flag, capflag) \
60 (((flag & VALID_20) && !(capflag & WLAN_RC_40_FLAG)) || \
61 ((flag & VALID_40) && (capflag & WLAN_RC_40_FLAG)))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070062
63#define WLAN_RC_DS_FLAG (0x01)
64#define WLAN_RC_40_FLAG (0x02)
65#define WLAN_RC_SGI_FLAG (0x04)
66#define WLAN_RC_HT_FLAG (0x08)
67
Sujith5701ed82008-08-26 08:11:26 +053068/**
69 * struct ath_rate_table - Rate Control table
70 * @valid: valid for use in rate control
71 * @valid_single_stream: valid for use in rate control for
72 * single stream operation
73 * @phy: CCK/OFDM
74 * @ratekbps: rate in Kbits per second
75 * @user_ratekbps: user rate in Kbits per second
76 * @ratecode: rate that goes into HW descriptors
77 * @short_preamble: Mask for enabling short preamble in ratecode for CCK
78 * @dot11rate: value that goes into supported
79 * rates info element of MLME
80 * @ctrl_rate: Index of next lower basic rate, used for duration computation
81 * @max_4ms_framelen: maximum frame length(bytes) for tx duration
82 * @probe_interval: interval for rate control to probe for other rates
83 * @rssi_reduce_interval: interval for rate control to reduce rssi
Sujith46d14a52008-11-18 09:08:13 +053084 * @initial_ratemax: initial ratemax value
Sujith5701ed82008-08-26 08:11:26 +053085 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070086struct ath_rate_table {
87 int rate_cnt;
Sujithe63835b2008-11-18 09:07:53 +053088 u8 rateCodeToIndex[256];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070089 struct {
Sujith5701ed82008-08-26 08:11:26 +053090 int valid;
91 int valid_single_stream;
92 u8 phy;
93 u32 ratekbps;
94 u32 user_ratekbps;
95 u8 ratecode;
96 u8 short_preamble;
97 u8 dot11rate;
98 u8 ctrl_rate;
99 int8_t rssi_ack_validmin;
100 int8_t rssi_ack_deltamin;
101 u8 base_index;
102 u8 cw40index;
103 u8 sgi_index;
104 u8 ht_index;
105 u32 max_4ms_framelen;
Sujithe63835b2008-11-18 09:07:53 +0530106 u16 lpAckDuration;
107 u16 spAckDuration;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700108 } info[RATE_TABLE_SIZE];
Sujith5701ed82008-08-26 08:11:26 +0530109 u32 probe_interval;
110 u32 rssi_reduce_interval;
111 u8 initial_ratemax;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700112};
113
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700114struct ath_tx_ratectrl_state {
Sujith5701ed82008-08-26 08:11:26 +0530115 int8_t rssi_thres; /* required rssi for this rate (dB) */
116 u8 per; /* recent estimate of packet error rate (%) */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700117};
118
Sujith256b7752008-11-18 09:03:12 +0530119struct ath_rateset {
120 u8 rs_nrates;
121 u8 rs_rates[ATH_RATE_MAX];
122};
123
Sujith5701ed82008-08-26 08:11:26 +0530124/**
Sujith46d14a52008-11-18 09:08:13 +0530125 * struct ath_rate_priv - Rate Control priv data
Sujith5701ed82008-08-26 08:11:26 +0530126 * @state: RC state
127 * @rssi_last: last ACK rssi
128 * @rssi_last_lookup: last ACK rssi used for lookup
129 * @rssi_last_prev: previous last ACK rssi
130 * @rssi_last_prev2: 2nd previous last ACK rssi
131 * @rssi_sum_cnt: count of rssi_sum for averaging
132 * @rssi_sum_rate: rate that we are averaging
133 * @rssi_sum: running sum of rssi for averaging
134 * @probe_rate: rate we are probing at
135 * @rssi_time: msec timestamp for last ack rssi
136 * @rssi_down_time: msec timestamp for last down step
137 * @probe_time: msec timestamp for last probe
138 * @hw_maxretry_pktcnt: num of packets since we got HW max retry error
139 * @max_valid_rate: maximum number of valid rate
140 * @per_down_time: msec timestamp for last PER down step
141 * @valid_phy_ratecnt: valid rate count
142 * @rate_max_phy: phy index for the max rate
143 * @probe_interval: interval for ratectrl to probe for other rates
Sujith256b7752008-11-18 09:03:12 +0530144 * @prev_data_rix: rate idx of last data frame
145 * @ht_cap: HT capabilities
146 * @single_stream: When TRUE, only single TX stream possible
147 * @neg_rates: Negotatied rates
148 * @neg_ht_rates: Negotiated HT rates
Sujith5701ed82008-08-26 08:11:26 +0530149 */
Sujith46d14a52008-11-18 09:08:13 +0530150struct ath_rate_priv {
Sujith5701ed82008-08-26 08:11:26 +0530151 int8_t rssi_last;
152 int8_t rssi_last_lookup;
153 int8_t rssi_last_prev;
154 int8_t rssi_last_prev2;
155 int32_t rssi_sum_cnt;
156 int32_t rssi_sum_rate;
157 int32_t rssi_sum;
158 u8 rate_table_size;
159 u8 probe_rate;
Sujith5701ed82008-08-26 08:11:26 +0530160 u8 hw_maxretry_pktcnt;
161 u8 max_valid_rate;
Sujith46d14a52008-11-18 09:08:13 +0530162 u8 valid_rate_index[RATE_TABLE_SIZE];
Sujith256b7752008-11-18 09:03:12 +0530163 u8 ht_cap;
164 u8 single_stream;
Sujith5701ed82008-08-26 08:11:26 +0530165 u8 valid_phy_ratecnt[WLAN_RC_PHY_MAX];
Sujith46d14a52008-11-18 09:08:13 +0530166 u8 valid_phy_rateidx[WLAN_RC_PHY_MAX][RATE_TABLE_SIZE];
Sujith5701ed82008-08-26 08:11:26 +0530167 u8 rc_phy_mode;
168 u8 rate_max_phy;
Sujith256b7752008-11-18 09:03:12 +0530169 u32 rssi_time;
170 u32 rssi_down_time;
171 u32 probe_time;
172 u32 per_down_time;
Sujith5701ed82008-08-26 08:11:26 +0530173 u32 probe_interval;
Sujith5701ed82008-08-26 08:11:26 +0530174 u32 prev_data_rix;
Sujithfe7f4a72008-11-18 09:07:06 +0530175 u32 tx_triglevel_max;
Sujith46d14a52008-11-18 09:08:13 +0530176 struct ath_tx_ratectrl_state state[RATE_TABLE_SIZE];
Sujith5701ed82008-08-26 08:11:26 +0530177 struct ath_rateset neg_rates;
Sujith5701ed82008-08-26 08:11:26 +0530178 struct ath_rateset neg_ht_rates;
Sujith5701ed82008-08-26 08:11:26 +0530179 struct ath_rate_softc *asc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700180};
181
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700182struct ath_tx_info_priv {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700183 struct ath_tx_status tx;
184 int n_frames;
185 int n_bad_frames;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700186};
187
Sujith46d14a52008-11-18 09:08:13 +0530188#define ATH_TX_INFO_PRIV(tx_info) \
189 ((struct ath_tx_info_priv *)((tx_info)->rate_driver_data[0]))
190
Sujithfe7f4a72008-11-18 09:07:06 +0530191void ath_rate_attach(struct ath_softc *sc);
Sujith2b406f12008-11-18 09:05:35 +0530192u8 ath_rate_findrateix(struct ath_softc *sc, u8 dot11_rate);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700193int ath_rate_control_register(void);
194void ath_rate_control_unregister(void);
195
196#endif /* RC_H */