xref: /titanic_41/usr/src/uts/common/io/arn/arn_rc.h (revision c0b6434526a837cec6e2665caf2f98240fe517c9)
1 /*
2  * Copyright 2009 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 
35 #define	ATH_RATE_MAX		30
36 #define	RATE_TABLE_SIZE		64
37 #define	MAX_TX_RATE_PHY		48
38 
39 /*
40  * VALID_ALL - valid for 20/40/Legacy,
41  * VALID - Legacy only,
42  * VALID_20 - HT 20 only,
43  * VALID_40 - HT 40 only
44  */
45 
46 #define	INVALID		0x0
47 #define	VALID		0x1
48 #define	VALID_20	0x2
49 #define	VALID_40	0x4
50 #define	VALID_2040	(VALID_20|VALID_40)
51 #define	VALID_ALL	(VALID_2040|VALID)
52 
53 #define	WLAN_RC_PHY_DS(_phy)	((_phy == WLAN_RC_PHY_HT_20_DS)		|| \
54 				(_phy == WLAN_RC_PHY_HT_40_DS)		|| \
55 				(_phy == WLAN_RC_PHY_HT_20_DS_HGI)	|| \
56 				(_phy == WLAN_RC_PHY_HT_40_DS_HGI))
57 #define	WLAN_RC_PHY_40(_phy)	((_phy == WLAN_RC_PHY_HT_40_SS) 	|| \
58 				(_phy == WLAN_RC_PHY_HT_40_DS)		|| \
59 				(_phy == WLAN_RC_PHY_HT_40_SS_HGI)	|| \
60 				(_phy == WLAN_RC_PHY_HT_40_DS_HGI))
61 #define	WLAN_RC_PHY_SGI(_phy)	((_phy == WLAN_RC_PHY_HT_20_SS_HGI)	|| \
62 				(_phy == WLAN_RC_PHY_HT_20_DS_HGI)	|| \
63 				(_phy == WLAN_RC_PHY_HT_40_SS_HGI)	|| \
64 				(_phy == WLAN_RC_PHY_HT_40_DS_HGI))
65 
66 #define	WLAN_RC_PHY_HT(_phy)	(_phy >= WLAN_RC_PHY_HT_20_SS)
67 
68 #define	WLAN_RC_CAP_MODE(capflag)	(((capflag & WLAN_RC_HT_FLAG) ?	\
69 	(capflag & WLAN_RC_40_FLAG) ? VALID_40 : VALID_20 : VALID))
70 
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  */
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)))
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 
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
101  * @initial_ratemax: initial ratemax value
102  */
103 struct ath_rate_table {
104 	int rate_cnt;
105 	uint8_t rateCodeToIndex[256];
106 	struct {
107 		int valid;
108 		int valid_single_stream;
109 		uint8_t phy;
110 		uint32_t ratekbps;
111 		uint32_t user_ratekbps;
112 		uint8_t ratecode;
113 		uint8_t short_preamble;
114 		uint8_t dot11rate;
115 		uint8_t ctrl_rate;
116 		int8_t rssi_ack_validmin;
117 		int8_t rssi_ack_deltamin;
118 		uint8_t base_index;
119 		uint8_t cw40index;
120 		uint8_t sgi_index;
121 		uint8_t ht_index;
122 		uint32_t max_4ms_framelen;
123 		uint16_t lpAckDuration;
124 		uint16_t spAckDuration;
125 	} info[RATE_TABLE_SIZE];
126 	uint32_t probe_interval;
127 	uint32_t rssi_reduce_interval;
128 	uint8_t initial_ratemax;
129 };
130 
131 struct ath_tx_ratectrl_state {
132 	int8_t rssi_thres; /* required rssi for this rate (dB) */
133 	uint8_t per; /* recent estimate of packet error rate (%) */
134 };
135 
136 struct ath_rateset {
137 	uint8_t rs_nrates;
138 	uint8_t rs_rates[ATH_RATE_MAX];
139 };
140 
141 /*
142  * struct ath_rate_priv - Rate Control priv data
143  * @state: RC state
144  * @rssi_last: last ACK rssi
145  * @rssi_last_lookup: last ACK rssi used for lookup
146  * @rssi_last_prev: previous last ACK rssi
147  * @rssi_last_prev2: 2nd previous last ACK rssi
148  * @rssi_sum_cnt: count of rssi_sum for averaging
149  * @rssi_sum_rate: rate that we are averaging
150  * @rssi_sum: running sum of rssi for averaging
151  * @probe_rate: rate we are probing at
152  * @rssi_time: msec timestamp for last ack rssi
153  * @rssi_down_time: msec timestamp for last down step
154  * @probe_time: msec timestamp for last probe
155  * @hw_maxretry_pktcnt: num of packets since we got HW max retry error
156  * @max_valid_rate: maximum number of valid rate
157  * @per_down_time: msec timestamp for last PER down step
158  * @valid_phy_ratecnt: valid rate count
159  * @rate_max_phy: phy index for the max rate
160  * @probe_interval: interval for ratectrl to probe for other rates
161  * @prev_data_rix: rate idx of last data frame
162  * @ht_cap: HT capabilities
163  * @single_stream: When TRUE, only single TX stream possible
164  * @neg_rates: Negotatied rates
165  * @neg_ht_rates: Negotiated HT rates
166  */
167 struct ath_rate_priv {
168 	int8_t rssi_last;
169 	int8_t rssi_last_lookup;
170 	int8_t rssi_last_prev;
171 	int8_t rssi_last_prev2;
172 	int32_t rssi_sum_cnt;
173 	int32_t rssi_sum_rate;
174 	int32_t rssi_sum;
175 	uint8_t rate_table_size;
176 	uint8_t probe_rate;
177 	uint8_t hw_maxretry_pktcnt;
178 	uint8_t max_valid_rate;
179 	uint8_t valid_rate_index[RATE_TABLE_SIZE];
180 	uint8_t ht_cap;
181 	uint8_t single_stream;
182 	uint8_t valid_phy_ratecnt[WLAN_RC_PHY_MAX];
183 	uint8_t valid_phy_rateidx[WLAN_RC_PHY_MAX][RATE_TABLE_SIZE];
184 	uint8_t rc_phy_mode;
185 	uint8_t rate_max_phy;
186 	uint32_t rssi_time;
187 	uint32_t rssi_down_time;
188 	uint32_t probe_time;
189 	uint32_t per_down_time;
190 	uint32_t probe_interval;
191 	uint32_t prev_data_rix;
192 	uint32_t tx_triglevel_max;
193 	struct ath_tx_ratectrl_state state[RATE_TABLE_SIZE];
194 	struct ath_rateset neg_rates;
195 	struct ath_rateset neg_ht_rates;
196 };
197 
198 struct ath_tx_info_priv {
199 	struct ath_tx_status tx;
200 	int n_frames;
201 	int n_bad_frames;
202 	boolean_t update_rc;
203 };
204 
205 #define	ATH_TX_INFO_PRIV(tx_info)	\
206 	((struct ath_tx_info_priv *)((tx_info)->rate_driver_data[0]))
207 
208 /* RATE */
209 void arn_rate_attach(struct arn_softc *sc);
210 void arn_rate_update(struct arn_softc *sc, struct ieee80211_node *in,
211     int32_t rate);
212 void arn_rate_ctl_start(struct arn_softc *sc, struct ieee80211_node *in);
213 void arn_rate_cb(void *arg, struct ieee80211_node *in);
214 void arn_rate_ctl_reset(struct arn_softc *sc, enum ieee80211_state state);
215 void arn_rate_ctl(void *arg, struct ieee80211_node *in);
216 
217 #ifdef __cplusplus
218 }
219 #endif
220 
221 #endif /* _ARN_RC_H */
222