blob: 94cb9f8d2446f8f21935c8118ca9c573aeab6e86 [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.
Sujithcee075a2009-03-13 09:07:23 +05304 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07005 *
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. Rodriguezdb86f072009-11-05 08:44:39 -080022#include "hw.h"
23
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070024struct 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
Sujith2c5a7442008-11-18 09:08:33 +053030/* VALID_ALL - valid for 20/40/Legacy,
31 * VALID - Legacy only,
32 * VALID_20 - HT 20 only,
33 * VALID_40 - HT 40 only */
34
Sujith46d14a52008-11-18 09:08:13 +053035#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. Rodriguezf078f202008-08-04 00:16:41 -070041
Sujith394cf0a2009-02-09 13:26:54 +053042enum {
43 WLAN_RC_PHY_OFDM,
44 WLAN_RC_PHY_CCK,
45 WLAN_RC_PHY_HT_20_SS,
46 WLAN_RC_PHY_HT_20_DS,
47 WLAN_RC_PHY_HT_40_SS,
48 WLAN_RC_PHY_HT_40_DS,
49 WLAN_RC_PHY_HT_20_SS_HGI,
50 WLAN_RC_PHY_HT_20_DS_HGI,
51 WLAN_RC_PHY_HT_40_SS_HGI,
52 WLAN_RC_PHY_HT_40_DS_HGI,
53 WLAN_RC_PHY_MAX
54};
55
Sujith5701ed82008-08-26 08:11:26 +053056#define WLAN_RC_PHY_DS(_phy) ((_phy == WLAN_RC_PHY_HT_20_DS) \
57 || (_phy == WLAN_RC_PHY_HT_40_DS) \
58 || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
59 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
60#define WLAN_RC_PHY_40(_phy) ((_phy == WLAN_RC_PHY_HT_40_SS) \
61 || (_phy == WLAN_RC_PHY_HT_40_DS) \
62 || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
63 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070064#define WLAN_RC_PHY_SGI(_phy) ((_phy == WLAN_RC_PHY_HT_20_SS_HGI) \
Sujith5701ed82008-08-26 08:11:26 +053065 || (_phy == WLAN_RC_PHY_HT_20_DS_HGI) \
66 || (_phy == WLAN_RC_PHY_HT_40_SS_HGI) \
67 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070068
69#define WLAN_RC_PHY_HT(_phy) (_phy >= WLAN_RC_PHY_HT_20_SS)
70
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070071#define WLAN_RC_CAP_MODE(capflag) (((capflag & WLAN_RC_HT_FLAG) ? \
Sujith46d14a52008-11-18 09:08:13 +053072 (capflag & WLAN_RC_40_FLAG) ? VALID_40 : VALID_20 : VALID))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070073
74/* Return TRUE if flag supports HT20 && client supports HT20 or
75 * return TRUE if flag supports HT40 && client supports HT40.
76 * This is used becos some rates overlap between HT20/HT40.
77 */
Sujith46d14a52008-11-18 09:08:13 +053078#define WLAN_RC_PHY_HT_VALID(flag, capflag) \
79 (((flag & VALID_20) && !(capflag & WLAN_RC_40_FLAG)) || \
80 ((flag & VALID_40) && (capflag & WLAN_RC_40_FLAG)))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070081
82#define WLAN_RC_DS_FLAG (0x01)
83#define WLAN_RC_40_FLAG (0x02)
84#define WLAN_RC_SGI_FLAG (0x04)
85#define WLAN_RC_HT_FLAG (0x08)
86
Sujith5701ed82008-08-26 08:11:26 +053087/**
88 * struct ath_rate_table - Rate Control table
89 * @valid: valid for use in rate control
90 * @valid_single_stream: valid for use in rate control for
91 * single stream operation
92 * @phy: CCK/OFDM
93 * @ratekbps: rate in Kbits per second
94 * @user_ratekbps: user rate in Kbits per second
95 * @ratecode: rate that goes into HW descriptors
96 * @short_preamble: Mask for enabling short preamble in ratecode for CCK
97 * @dot11rate: value that goes into supported
98 * rates info element of MLME
99 * @ctrl_rate: Index of next lower basic rate, used for duration computation
100 * @max_4ms_framelen: maximum frame length(bytes) for tx duration
101 * @probe_interval: interval for rate control to probe for other rates
102 * @rssi_reduce_interval: interval for rate control to reduce rssi
Sujith46d14a52008-11-18 09:08:13 +0530103 * @initial_ratemax: initial ratemax value
Sujith5701ed82008-08-26 08:11:26 +0530104 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700105struct ath_rate_table {
106 int rate_cnt;
107 struct {
Sujith5701ed82008-08-26 08:11:26 +0530108 int valid;
109 int valid_single_stream;
110 u8 phy;
111 u32 ratekbps;
112 u32 user_ratekbps;
113 u8 ratecode;
114 u8 short_preamble;
115 u8 dot11rate;
116 u8 ctrl_rate;
Sujith5701ed82008-08-26 08:11:26 +0530117 u8 base_index;
118 u8 cw40index;
119 u8 sgi_index;
120 u8 ht_index;
121 u32 max_4ms_framelen;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700122 } info[RATE_TABLE_SIZE];
Sujith5701ed82008-08-26 08:11:26 +0530123 u32 probe_interval;
Sujith5701ed82008-08-26 08:11:26 +0530124 u8 initial_ratemax;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700125};
126
Sujith256b77592008-11-18 09:03:12 +0530127struct ath_rateset {
128 u8 rs_nrates;
129 u8 rs_rates[ATH_RATE_MAX];
130};
131
Sujith5701ed82008-08-26 08:11:26 +0530132/**
Sujith46d14a52008-11-18 09:08:13 +0530133 * struct ath_rate_priv - Rate Control priv data
Sujith5701ed82008-08-26 08:11:26 +0530134 * @state: RC state
Sujith5701ed82008-08-26 08:11:26 +0530135 * @probe_rate: rate we are probing at
Sujith5701ed82008-08-26 08:11:26 +0530136 * @probe_time: msec timestamp for last probe
137 * @hw_maxretry_pktcnt: num of packets since we got HW max retry error
138 * @max_valid_rate: maximum number of valid rate
139 * @per_down_time: msec timestamp for last PER down step
140 * @valid_phy_ratecnt: valid rate count
141 * @rate_max_phy: phy index for the max rate
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400142 * @per: PER for every valid rate in %
Sujith5701ed82008-08-26 08:11:26 +0530143 * @probe_interval: interval for ratectrl to probe for other rates
Sujith256b77592008-11-18 09:03:12 +0530144 * @prev_data_rix: rate idx of last data frame
145 * @ht_cap: HT capabilities
Sujith256b77592008-11-18 09:03:12 +0530146 * @neg_rates: Negotatied rates
147 * @neg_ht_rates: Negotiated HT rates
Sujith5701ed82008-08-26 08:11:26 +0530148 */
Sujith46d14a52008-11-18 09:08:13 +0530149struct ath_rate_priv {
Sujith5701ed82008-08-26 08:11:26 +0530150 u8 rate_table_size;
151 u8 probe_rate;
Sujith5701ed82008-08-26 08:11:26 +0530152 u8 hw_maxretry_pktcnt;
153 u8 max_valid_rate;
Sujith46d14a52008-11-18 09:08:13 +0530154 u8 valid_rate_index[RATE_TABLE_SIZE];
Sujith256b77592008-11-18 09:03:12 +0530155 u8 ht_cap;
Sujith5701ed82008-08-26 08:11:26 +0530156 u8 valid_phy_ratecnt[WLAN_RC_PHY_MAX];
Sujith46d14a52008-11-18 09:08:13 +0530157 u8 valid_phy_rateidx[WLAN_RC_PHY_MAX][RATE_TABLE_SIZE];
Sujith5701ed82008-08-26 08:11:26 +0530158 u8 rate_max_phy;
Vasanthakumar Thiagarajan922bac62009-07-14 20:14:13 -0400159 u8 per[RATE_TABLE_SIZE];
Sujith256b77592008-11-18 09:03:12 +0530160 u32 probe_time;
161 u32 per_down_time;
Sujith5701ed82008-08-26 08:11:26 +0530162 u32 probe_interval;
Sujith5701ed82008-08-26 08:11:26 +0530163 u32 prev_data_rix;
Sujithfe7f4a72008-11-18 09:07:06 +0530164 u32 tx_triglevel_max;
Sujith5701ed82008-08-26 08:11:26 +0530165 struct ath_rateset neg_rates;
Sujith5701ed82008-08-26 08:11:26 +0530166 struct ath_rateset neg_ht_rates;
Sujith5701ed82008-08-26 08:11:26 +0530167 struct ath_rate_softc *asc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700168};
169
Jouni Malinenf0ed85c2009-03-03 19:23:31 +0200170enum ath9k_internal_frame_type {
171 ATH9K_NOT_INTERNAL,
172 ATH9K_INT_PAUSE,
173 ATH9K_INT_UNPAUSE
174};
175
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700176struct ath_tx_info_priv {
Jouni Malinenc52f33d2009-03-03 19:23:29 +0200177 struct ath_wiphy *aphy;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700178 struct ath_tx_status tx;
179 int n_frames;
180 int n_bad_frames;
Vasanthakumar Thiagarajan7ac47012008-11-20 11:51:18 +0530181 bool update_rc;
Jouni Malinenf0ed85c2009-03-03 19:23:31 +0200182 enum ath9k_internal_frame_type frame_type;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700183};
184
Sujith46d14a52008-11-18 09:08:13 +0530185#define ATH_TX_INFO_PRIV(tx_info) \
186 ((struct ath_tx_info_priv *)((tx_info)->rate_driver_data[0]))
187
Sujithfe7f4a72008-11-18 09:07:06 +0530188void ath_rate_attach(struct ath_softc *sc);
Sujith2b406f12008-11-18 09:05:35 +0530189u8 ath_rate_findrateix(struct ath_softc *sc, u8 dot11_rate);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700190int ath_rate_control_register(void);
191void ath_rate_control_unregister(void);
192
193#endif /* RC_H */