Initial cut of the open ath9k htc firmware.
[open-ath9k-htc-firmware.git] / target_firmware / wlan / ratectrl11n.h
1 /*
2  * Copyright (c) 2000-2002 Atheros Communications, Inc., All Rights Reserved
3  *
4  * Definitions for core driver
5  * This is a common header file for all platforms and operating systems.
6  */
7 #ifndef _RATECTRL11N_H_
8 #define _RATECTRL11N_H_
9
10 /* HT 20/40 rates. If 20 bit is enabled then that rate is
11  * used only in 20 mode. If both 20/40 bits are enabled
12  * then that rate can be used for both 20 and 40 mode */
13
14 #define TRUE_20         0x2     
15 #define TRUE_40         0x4     
16 #define TRUE_2040       (TRUE_20|TRUE_40)
17 #define TRUE_ALL_11N    (TRUE_2040|TRUE)
18
19 enum {
20         WLAN_RC_DS  = 0x01,
21         WLAN_RC_40  = 0x02,
22         WLAN_RC_SGI = 0x04,
23         WLAN_RC_HT  = 0x08,
24 };
25
26 typedef enum {
27         WLAN_RC_LEGACY      = 0,
28         WLAN_RC_HT_LNPHY    = 1,
29         WLAN_RC_HT_PLPHY    = 2,
30         WLAN_RC_MAX         = 3
31 } WLAN_RC_VERS;
32
33 #define WLAN_RC_PHY_DS(_phy)   ((_phy == WLAN_RC_PHY_HT_20_DS)          \
34                                 || (_phy == WLAN_RC_PHY_HT_40_DS)       \
35                                 || (_phy == WLAN_RC_PHY_HT_20_DS_HGI)   \
36                                 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))   
37 #define WLAN_RC_PHY_40(_phy)   ((_phy == WLAN_RC_PHY_HT_40_SS)          \
38                                 || (_phy == WLAN_RC_PHY_HT_40_DS)       \
39                                 || (_phy == WLAN_RC_PHY_HT_40_SS_HGI)   \
40                                 || (_phy == WLAN_RC_PHY_HT_40_DS_HGI))   
41 #define WLAN_RC_PHY_20(_phy)   ((_phy == WLAN_RC_PHY_HT_20_SS)          \
42                                 || (_phy == WLAN_RC_PHY_HT_20_DS)       \
43                                 || (_phy == WLAN_RC_PHY_HT_20_SS_HGI)   \
44                                 || (_phy == WLAN_RC_PHY_HT_20_DS_HGI))   
45 #define WLAN_RC_PHY_SGI(_phy)  ((_phy == WLAN_RC_PHY_HT_20_SS_HGI)      \
46                                 || (_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))   
49
50 #define WLAN_RC_PHY_HT(_phy)    (_phy >= WLAN_RC_PHY_HT_20_SS)
51
52 /* Returns the capflag mode */
53
54 #define WLAN_RC_CAP_MODE(capflag) (((capflag & WLAN_RC_HT_FLAG)?        \
55                                     (capflag & WLAN_RC_40_FLAG)?TRUE_40:TRUE_20: \
56                                     TRUE))
57
58 /* Return TRUE if flag supports HT20 && client supports HT20 or
59  * return TRUE if flag supports HT40 && client supports HT40.
60  * This is used becos some rates overlap between HT20/HT40.
61  */
62
63 #define WLAN_RC_PHY_HT_VALID(flag, capflag) (((flag & TRUE_20) && !(capflag \
64                                 & WLAN_RC_40_FLAG)) || ((flag & TRUE_40) && \
65                                   (capflag & WLAN_RC_40_FLAG)))
66
67 #define WLAN_RC_DS_FLAG         (0x01)
68 #define WLAN_RC_40_FLAG         (0x02)
69 #define WLAN_RC_HT40_SGI_FLAG   (0x04)
70 #define WLAN_RC_HT_FLAG         (0x08)
71 #define WLAN_RC_STBC_FLAG       (0x30)  /* 2 bits */
72 #define WLAN_RC_STBC_FLAG_S     (   4)
73 #define WLAN_RC_WEP_TKIP_FLAG   (0x100)
74
75 /* Index into the rate table */
76 #define INIT_RATE_MAX_20        23              
77 #define INIT_RATE_MAX_40        40
78
79 /*
80  * Rate Table structure for various modes - 'b', 'a', 'g', 'xr';
81  * order of fields in info structure is important because hardcoded
82  * structures are initialized within the hal for these
83  */
84
85 #ifndef MAGPIE_MERLIN // K2
86 #define RATE_TABLE_11N_SIZE             54
87 #else
88 #define RATE_TABLE_11N_SIZE             64
89 #endif
90
91 #define MAX_SUPPORTED_MCS           128
92
93 typedef struct regDataLenTable {
94         A_UINT8     numEntries;
95         A_UINT16    frameLenRateIndex[RATE_TABLE_11N_SIZE];
96 } REG_DATALEN_TABLE;
97
98 typedef struct {
99         A_BOOL    valid;            /* Valid for use in rate control */
100         A_BOOL    validSingleStream;/* Valid for use in rate control for single stream operation */
101 #ifdef MAGPIE_MERLIN
102         A_BOOL    validSTBC;        /* Valid for use in rate control for single stream operation */
103 #endif    
104         WLAN_PHY  phy;              /* CCK/OFDM/TURBO/XR */
105         A_UINT32  rateKbps;         /* Rate in Kbits per second */
106         A_UINT32  userRateKbps;     /* User rate in KBits per second */
107         A_UINT8   rateCode;         /* rate that goes into hw descriptors */
108         A_UINT8   shortPreamble;    /* Mask for enabling short preamble in rate code for CCK */
109         A_UINT8   dot11Rate;        /* Value that goes into supported rates info element of MLME */
110         A_UINT8   controlRate;      /* Index of next lower basic rate, used for duration computation */
111         A_RSSI    rssiAckValidMin;  /* Rate control related information */
112         A_RSSI    rssiAckDeltaMin;  /* Rate control related information */
113         A_UINT8   baseIndex;        /* base rate index */
114         A_UINT8   cw40Index;        /* 40cap rate index */
115         A_UINT8   sgiIndex;         /* shortgi rate index */
116         A_UINT8   htIndex;          /* shortgi rate index */
117         A_UINT8   txChainMask_2ch;  /* transmit chain mask */
118         A_UINT8   txChainMask_3ch;  /* transmit chain mask */
119         A_UINT32  max4msframelen;   /* Maximum frame length(bytes) for 4ms tx duration */
120         A_BOOL    uapsdvalid;       /* Valid for UAPSD nodes */
121 } rc11n_info_t;
122
123 typedef struct {
124         A_UINT8          rateCount;
125         A_UINT8          probeInterval;        /* interval for ratectrl to probe for other rates */
126         A_UINT8          rssiReduceInterval;   /* interval for ratectrl to reduce RSSI */
127         A_UINT8          initialRateMax;   /* the initial rateMax value used in rcSibUpdate() */
128         rc11n_info_t     info[];
129 } RATE_TABLE_11N;
130
131 /*
132  *  Update the SIB's rate control information
133  *
134  *  This should be called when the supported rates change
135  *  (e.g. SME operation, wireless mode change)
136  *
137  *  It will determine which rates are valid for use.
138  */
139 void rcSibUpdate_11n(struct ath_softc_tgt *,
140                      struct ath_node_target *,
141                      A_UINT32 capflag, 
142                      A_BOOL keepState,
143                      struct ieee80211_rate *rs);
144
145 /*
146  * Determines and returns the new Tx rate index.
147  */ 
148 void rcRateFind_11n(struct ath_softc_tgt *sc,
149                     struct ath_node_target *an,
150                     int numTries,
151                     int numRates,
152                     int stepDnInc,
153                     unsigned int rcflag,
154                     struct ath_rc_series series[],
155                     int *isProbe);
156
157 /*
158  * This routine is called by the Tx interrupt service routine to give
159  * the status of previous frames.
160  */
161 void rcUpdate_11n(struct ath_softc_tgt *sc,
162                   struct ath_node_target *an,
163                   A_UINT8 curTxAnt,
164                   int finalTSIdx,
165                   int Xretries,
166                   struct ath_rc_series rcs[],
167                   int nFrames,
168                   int nBad,
169                   int sh_lo_retry);
170
171 void ath_tx_status_update_rate(struct ath_softc_tgt *sc,
172                                struct ath_rc_series rcs[],
173                                int series,
174                                WMI_TXSTATUS_EVENT *txs);
175
176 #endif /* _RATECTRL11N_H_ */