xref: /titanic_41/usr/src/uts/common/io/arn/arn_rc.h (revision 5e01956f3000408c2a2c5a08c8d0acf2c2a9d8ee)
1 /*
2  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * Copyright (c) 2004 Sam Leffler, Errno Consulting
8  * Copyright (c) 2004 Video54 Technologies, Inc.
9  * Copyright (c) 2008 Atheros Communications Inc.
10  *
11  * Permission to use, copy, modify, and/or distribute this software for any
12  * purpose with or without fee is hereby granted, provided that the above
13  * copyright notice and this permission notice appear in all copies.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
18  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  */
23 
24 #ifndef	_ARN_RC_H
25 #define	_ARN_RC_H
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #include "arn_ath9k.h"
32 
33 struct arn_softc;
34 struct ath_buf;
35 
36 #define	ATH_RATE_MAX		30
37 #define	RATE_TABLE_SIZE		64
38 #define	MAX_TX_RATE_PHY		48
39 
40 /*
41  * VALID_ALL - valid for 20/40/Legacy,
42  * VALID - Legacy only,
43  * VALID_20 - HT 20 only,
44  * VALID_40 - HT 40 only
45  */
46 
47 #define	INVALID		0x0
48 #define	VALID		0x1
49 #define	VALID_20	0x2
50 #define	VALID_40	0x4
51 #define	VALID_2040	(VALID_20|VALID_40)
52 #define	VALID_ALL	(VALID_2040|VALID)
53 
54 enum {
55 	WLAN_RC_PHY_OFDM,
56 	WLAN_RC_PHY_CCK,
57 	WLAN_RC_PHY_HT_20_SS,
58 	WLAN_RC_PHY_HT_20_DS,
59 	WLAN_RC_PHY_HT_40_SS,
60 	WLAN_RC_PHY_HT_40_DS,
61 	WLAN_RC_PHY_HT_20_SS_HGI,
62 	WLAN_RC_PHY_HT_20_DS_HGI,
63 	WLAN_RC_PHY_HT_40_SS_HGI,
64 	WLAN_RC_PHY_HT_40_DS_HGI,
65 	WLAN_RC_PHY_MAX
66 };
67 
68 #define	WLAN_RC_PHY_DS(_phy)	((_phy == WLAN_RC_PHY_HT_20_DS)		|| \
69 				(_phy == WLAN_RC_PHY_HT_40_DS)		|| \
70 				(_phy == WLAN_RC_PHY_HT_20_DS_HGI)	|| \
71 				(_phy == WLAN_RC_PHY_HT_40_DS_HGI))
72 #define	WLAN_RC_PHY_40(_phy)	((_phy == WLAN_RC_PHY_HT_40_SS) 	|| \
73 				(_phy == WLAN_RC_PHY_HT_40_DS)		|| \
74 				(_phy == WLAN_RC_PHY_HT_40_SS_HGI)	|| \
75 				(_phy == WLAN_RC_PHY_HT_40_DS_HGI))
76 #define	WLAN_RC_PHY_SGI(_phy)	((_phy == WLAN_RC_PHY_HT_20_SS_HGI)	|| \
77 				(_phy == WLAN_RC_PHY_HT_20_DS_HGI)	|| \
78 				(_phy == WLAN_RC_PHY_HT_40_SS_HGI)	|| \
79 				(_phy == WLAN_RC_PHY_HT_40_DS_HGI))
80 
81 #define	WLAN_RC_PHY_HT(_phy)	(_phy >= WLAN_RC_PHY_HT_20_SS)
82 
83 #define	WLAN_RC_CAP_MODE(capflag)	(((capflag & WLAN_RC_HT_FLAG) ?	\
84 	(capflag & WLAN_RC_40_FLAG) ? VALID_40 : VALID_20 : VALID))
85 
86 /*
87  * Return TRUE if flag supports HT20 && client supports HT20 or
88  * return TRUE if flag supports HT40 && client supports HT40.
89  * This is used becos some rates overlap between HT20/HT40.
90  */
91 #define	WLAN_RC_PHY_HT_VALID(flag, capflag)			\
92 	(((flag & VALID_20) && !(capflag & WLAN_RC_40_FLAG)) || \
93 	((flag & VALID_40) && (capflag & WLAN_RC_40_FLAG)))
94 
95 #define	WLAN_RC_DS_FLAG		(0x01)
96 #define	WLAN_RC_40_FLAG		(0x02)
97 #define	WLAN_RC_SGI_FLAG	(0x04)
98 #define	WLAN_RC_HT_FLAG		(0x08)
99 
100 /*
101  * struct ath_rate_table - Rate Control table
102  * @valid: valid for use in rate control
103  * @valid_single_stream: valid for use in rate control for
104  * 	single stream operation
105  * @phy: CCK/OFDM
106  * @ratekbps: rate in Kbits per second
107  * @user_ratekbps: user rate in Kbits per second
108  * @ratecode: rate that goes into HW descriptors
109  * @short_preamble: Mask for enabling short preamble in ratecode for CCK
110  * @dot11rate: value that goes into supported
111  * 	rates info element of MLME
112  * @ctrl_rate: Index of next lower basic rate, used for duration computation
113  * @max_4ms_framelen: maximum frame length(bytes) for tx duration
114  * @probe_interval: interval for rate control to probe for other rates
115  * @rssi_reduce_interval: interval for rate control to reduce rssi
116  * @initial_ratemax: initial ratemax value
117  */
118 struct ath_rate_table {
119 	int rate_cnt;
120 	uint8_t rateCodeToIndex[256];
121 	struct {
122 		int valid;
123 		int valid_single_stream;
124 		uint8_t phy;
125 		uint32_t ratekbps;
126 		uint32_t user_ratekbps;
127 		uint8_t ratecode;
128 		uint8_t short_preamble;
129 		uint8_t dot11rate;
130 		uint8_t ctrl_rate;
131 		int8_t rssi_ack_validmin;
132 		int8_t rssi_ack_deltamin;
133 		uint8_t base_index;
134 		uint8_t cw40index;
135 		uint8_t sgi_index;
136 		uint8_t ht_index;
137 		uint32_t max_4ms_framelen;
138 		uint16_t lpAckDuration;
139 		uint16_t spAckDuration;
140 	} info[RATE_TABLE_SIZE];
141 	uint32_t probe_interval;
142 	uint32_t rssi_reduce_interval;
143 	uint8_t initial_ratemax;
144 };
145 
146 struct ath_tx_ratectrl_state {
147 	int8_t rssi_thres; /* required rssi for this rate (dB) */
148 	uint8_t per; /* recent estimate of packet error rate (%) */
149 };
150 
151 struct ath_rateset {
152 	uint8_t rs_nrates;
153 	uint8_t rs_rates[ATH_RATE_MAX];
154 };
155 
156 /*
157  * struct ath_rate_priv - Rate Control priv data
158  * @state: RC state
159  * @rssi_last: last ACK rssi
160  * @rssi_last_lookup: last ACK rssi used for lookup
161  * @rssi_last_prev: previous last ACK rssi
162  * @rssi_last_prev2: 2nd previous last ACK rssi
163  * @rssi_sum_cnt: count of rssi_sum for averaging
164  * @rssi_sum_rate: rate that we are averaging
165  * @rssi_sum: running sum of rssi for averaging
166  * @probe_rate: rate we are probing at
167  * @rssi_time: msec timestamp for last ack rssi
168  * @rssi_down_time: msec timestamp for last down step
169  * @probe_time: msec timestamp for last probe
170  * @hw_maxretry_pktcnt: num of packets since we got HW max retry error
171  * @max_valid_rate: maximum number of valid rate
172  * @per_down_time: msec timestamp for last PER down step
173  * @valid_phy_ratecnt: valid rate count
174  * @rate_max_phy: phy index for the max rate
175  * @probe_interval: interval for ratectrl to probe for other rates
176  * @prev_data_rix: rate idx of last data frame
177  * @ht_cap: HT capabilities
178  * @single_stream: When TRUE, only single TX stream possible
179  * @neg_rates: Negotatied rates
180  * @neg_ht_rates: Negotiated HT rates
181  */
182 struct ath_rate_priv {
183 	int8_t rssi_last;
184 	int8_t rssi_last_lookup;
185 	int8_t rssi_last_prev;
186 	int8_t rssi_last_prev2;
187 	int32_t rssi_sum_cnt;
188 	int32_t rssi_sum_rate;
189 	int32_t rssi_sum;
190 	uint8_t rate_table_size;
191 	uint8_t probe_rate;
192 	uint8_t hw_maxretry_pktcnt;
193 	uint8_t max_valid_rate;
194 	uint8_t valid_rate_index[RATE_TABLE_SIZE];
195 	uint8_t ht_cap;
196 	uint8_t single_stream;
197 	uint8_t valid_phy_ratecnt[WLAN_RC_PHY_MAX];
198 	uint8_t valid_phy_rateidx[WLAN_RC_PHY_MAX][RATE_TABLE_SIZE];
199 	uint8_t rc_phy_mode;
200 	uint8_t rate_max_phy;
201 	uint32_t rssi_time;
202 	uint32_t rssi_down_time;
203 	uint32_t probe_time;
204 	uint32_t per_down_time;
205 	uint32_t probe_interval;
206 	uint32_t prev_data_rix;
207 	uint32_t tx_triglevel_max;
208 	struct ath_tx_ratectrl_state state[RATE_TABLE_SIZE];
209 	struct ath_rateset neg_rates;
210 	struct ath_rateset neg_ht_rates;
211 };
212 
213 enum ath9k_internal_frame_type {
214 	ATH9K_NOT_INTERNAL,
215 	ATH9K_INT_PAUSE,
216 	ATH9K_INT_UNPAUSE
217 };
218 
219 struct ath_tx_info_priv {
220 	struct ath_tx_status tx;
221 	int n_frames;
222 	int n_bad_frames;
223 	boolean_t update_rc;
224 	enum ath9k_internal_frame_type frame_type;
225 };
226 
227 #define	ATH_TX_INFO_PRIV(tx_info)	\
228 	((struct ath_tx_info_priv *)((tx_info)->rate_driver_data[0]))
229 
230 /* Temp private definitions for RC */
231 struct ath9k_tx_rate {
232 	int8_t idx;
233 	uint8_t count;
234 	uint8_t flags;
235 };
236 
237 enum ath9k_rate_control_flags {
238 	ATH9K_TX_RC_USE_RTS_CTS		= BIT(0),
239 	ATH9K_TX_RC_USE_CTS_PROTECT		= BIT(1),
240 	ATH9K_TX_RC_USE_SHORT_PREAMBLE	= BIT(2),
241 	ATH9K_TX_RC_MCS			= BIT(3),
242 	ATH9K_TX_RC_GREEN_FIELD		= BIT(4),
243 	ATH9K_TX_RC_40_MHZ_WIDTH		= BIT(5),
244 	ATH9K_TX_RC_DUP_DATA		= BIT(6),
245 	ATH9K_TX_RC_SHORT_GI		= BIT(7),
246 };
247 
248 /* RATE */
249 void arn_tx_status(struct arn_softc *sc, struct ath_buf *bf, boolean_t is_data);
250 void arn_get_rate(struct arn_softc *sc, struct ath_buf *bf,
251     struct ieee80211_frame *wh);
252 void arn_rate_init(struct arn_softc *sc, struct ieee80211_node *in);
253 
254 
255 void arn_rate_attach(struct arn_softc *sc);
256 void arn_rate_update(struct arn_softc *sc,
257     struct ieee80211_node *in, int32_t rate);
258 void arn_rate_ctl_start(struct arn_softc *sc, struct ieee80211_node *in);
259 void arn_rate_cb(void *arg, struct ieee80211_node *in);
260 void arn_rate_ctl_reset(struct arn_softc *sc, enum ieee80211_state state);
261 void arn_rate_ctl(void *arg, struct ieee80211_node *in);
262 
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 #endif /* _ARN_RC_H */
268