ath9k_htc: Update to upstream's commit d19607454d656cb14d8c16dfbf161eebb542e8fe dated...
[linux-libre-firmware.git] / ath9k_htc / target_firmware / wlan / ah_internal.h
1 /*
2  * Copyright (c) 2013 Qualcomm Atheros, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted (subject to the limitations in the
7  * disclaimer below) provided that the following conditions are met:
8  *
9  *  * Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  *  * Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the
15  *    distribution.
16  *
17  *  * Neither the name of Qualcomm Atheros nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22  * GRANTED BY THIS LICENSE.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35
36 /*
37  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
38  * Copyright (c) 2002-2005 Atheros Communications, Inc.
39  * All rights reserved.
40  *
41  * $Id: //depot/sw/branches/fusion_usb/target_firmware/wlan/target/hal/main/ah_internal.h#2 $
42  */
43 #ifndef _ATH_AH_INTERAL_H_
44 #define _ATH_AH_INTERAL_H_
45
46 #include <stdarg.h>
47
48 #define IEEE80211_AMPDU_LIMIT_MAX   (64 * 1024 - 1)
49
50 #define AH_NULL 0
51 #define AH_MIN(a,b) ((a)<(b)?(a):(b))
52 #define AH_MAX(a,b) ((a)>(b)?(a):(b))
53
54 /*
55  * Common assertion interface.  Note: it is a bad idea to generate
56  * an assertion failure for any recoverable event.  Instead catch
57  * the violation and, if possible, fix it up or recover from it; either
58  * with an error return value or a diagnostic messages.  System software
59  * does not panic unless the situation is hopeless.
60  */
61 #ifdef AH_ASSERT
62 #define HALASSERT(_x) do {                      \
63                 adf_os_assert(_x)               \
64                 } while (0)
65 #else
66 #define HALASSERT(_x)
67 #endif /* AH_ASSERT */
68
69 #ifndef NBBY
70 #define NBBY    8           /* number of bits/byte */
71 #endif
72
73 #define IEEE80211_ADDR_LEN 6
74
75 /*
76  * Internal form of a HAL_CHANNEL.  Note that the structure
77  * must be defined such that you can cast references to a
78  * HAL_CHANNEL so don't shuffle the first two members.
79  */
80 typedef struct {
81         a_uint16_t   channel;    /* NB: must be first for casting */
82         a_uint32_t   channelFlags;
83         a_uint8_t    privFlags;
84         int8_t       maxRegTxPower;
85         int8_t       maxTxPower;
86         int8_t       minTxPower; /* as above... */
87         a_uint8_t    regClassId; /* Regulatory class id */
88         HAL_BOOL     bssSendHere;
89         a_uint8_t    gainI;
90         HAL_BOOL     iqCalValid;
91         HAL_BOOL     oneTimeCalsDone;
92         int8_t       iCoff;
93         int8_t       qCoff;
94         a_int16_t    rawNoiseFloor;
95         a_int16_t    finalNoiseFloor;
96         int8_t       antennaMax;
97         a_uint32_t   regDmnFlags;    /* Flags for channel use in reg */
98         a_uint32_t   conformanceTestLimit;   /* conformance test limit from reg domain */
99         a_uint16_t   mainSpur;          /* cached spur value for this cahnnel */
100         u_int64_t    ah_tsf_last;    /* tsf @ which time accured is computed */
101         u_int64_t    ah_channel_time;   /* time on the channel  */
102         u_int64_t    dfsTsf; /* Tsf when channel leaves NOL */
103 } HAL_CHANNEL_INTERNAL;
104
105 typedef struct {
106         a_uint32_t   halChanSpreadSupport   : 1,
107                 halSleepAfterBeaconBroken   : 1,
108                 halCompressSupport      : 1,
109                 halBurstSupport         : 1,
110                 halFastFramesSupport    : 1,
111                 halChapTuningSupport    : 1,
112                 halTurboGSupport        : 1,
113                 halTurboPrimeSupport    : 1,
114                 halXrSupport            : 1,
115                 halMicAesCcmSupport     : 1,
116                 halMicCkipSupport       : 1,
117                 halMicTkipSupport       : 1,
118                 halCipherAesCcmSupport  : 1,
119                 halCipherCkipSupport    : 1,
120                 halCipherTkipSupport    : 1,
121                 halPSPollBroken         : 1,
122                 halVEOLSupport          : 1,
123                 halBssIdMaskSupport     : 1,
124                 halMcastKeySrchSupport  : 1,
125                 halTsfAddSupport        : 1,
126                 halChanHalfRate         : 1,
127                 halChanQuarterRate      : 1,
128                 halHTSupport            : 1,
129                 halGTTSupport           : 1,
130                 halFastCCSupport        : 1,
131                 halExtChanDfsSupport    : 1,
132                 halUseCombinedRadarRssi : 1,
133                 halCSTSupport           : 1,
134                 halRifsRxSupport        : 1,
135                 halRifsTxSupport        : 1,
136 #ifdef MAGPIE_MERLIN
137                 halforcePpmSupport      : 1,
138                 halAutoSleepSupport     : 1,
139                 hal4kbSplitTransSupport : 1,
140                 halEnhancedPmSupport    : 1,
141                 halMbssidAggrSupport    : 1,
142                 halTkipWepHtRateSupport : 1,
143 #endif
144                 halRfSilentSupport      : 1;
145         a_uint32_t   halWirelessModes;
146         a_uint16_t   halTotalQueues;
147         a_uint16_t   halKeyCacheSize;
148         a_uint16_t   halLow5GhzChan, halHigh5GhzChan;
149         a_uint16_t   halLow2GhzChan, halHigh2GhzChan;
150         a_uint16_t   halNumMRRetries;
151         a_uint8_t    halTxChainMask;
152         a_uint8_t    halRxChainMask;
153         a_uint16_t   halRtsAggrLimit;
154         a_uint16_t   halJapanRegCap;
155         a_uint8_t    halNumGpioPins;
156 } HAL_CAPABILITIES;
157
158
159 #if !defined(_NET_IF_IEEE80211_H_) && !defined(_NET80211__IEEE80211_H_)
160 /*
161  * Stuff that would naturally come from _ieee80211.h
162  */
163 #define IEEE80211_ADDR_LEN      6
164 #define IEEE80211_WEP_KEYLEN    5   /* 40bit */
165 #define IEEE80211_WEP_IVLEN     3   /* 24bit */
166 #define IEEE80211_WEP_KIDLEN    1   /* 1 octet */
167 #define IEEE80211_WEP_CRCLEN    4   /* CRC-32 */
168 #define IEEE80211_CRC_LEN       4
169 #define IEEE80211_MTU           1500
170 #define IEEE80211_MAX_LEN       (2300 + IEEE80211_CRC_LEN + \
171     (IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN))
172
173 #define WLAN_CTRL_FRAME_SIZE    (2+2+6+4)   /* ACK+FCS */
174
175 enum {
176         IEEE80211_T_DS,         /* direct sequence spread spectrum */
177         IEEE80211_T_FH,         /* frequency hopping */
178         IEEE80211_T_OFDM,       /* frequency division multiplexing */
179         IEEE80211_T_TURBO,      /* high rate DS */
180         IEEE80211_T_HT,         /* HT - full GI */
181         IEEE80211_T_MAX
182 };
183 #define IEEE80211_T_CCK IEEE80211_T_DS  /* more common nomenclatur */
184 #endif /* _NET_IF_IEEE80211_H_ */
185
186 /* NB: these are defined privately until XR support is announced */
187 enum {
188         ATHEROS_T_XR    = IEEE80211_T_MAX,  /* extended range */
189 };
190
191 struct ath_hal_private {
192         struct ath_hal h;
193
194         a_uint32_t ah_macVersion;
195         a_uint16_t ah_macRev;
196         a_uint16_t ah_phyRev;
197
198         HAL_CAPABILITIES ah_caps;       /* device capabilities */
199         HAL_CHANNEL_INTERNAL *ah_curchan;   /* current channel */
200 };
201
202 #define AH_PRIVATE(_ah) ((struct ath_hal_private *)(_ah))
203
204 #define IS_CHAN_A(_c)   ((((_c)->channelFlags & CHANNEL_A) == CHANNEL_A) || \
205              (((_c)->channelFlags & CHANNEL_A_HT20) == CHANNEL_A_HT20))
206 #define IS_CHAN_B(_c)   (((_c)->channelFlags & CHANNEL_B) == CHANNEL_B)
207 #define IS_CHAN_G(_c)   ((((_c)->channelFlags & (CHANNEL_108G|CHANNEL_G)) == CHANNEL_G) || \
208              (((_c)->channelFlags & CHANNEL_G_HT20) == CHANNEL_G_HT20))
209 #define IS_CHAN_108G(_c)(((_c)->channelFlags & CHANNEL_108G) == CHANNEL_108G)
210 #define IS_CHAN_T(_c)   (((_c)->channelFlags & CHANNEL_T) == CHANNEL_T)
211 #define IS_CHAN_X(_c)   (((_c)->channelFlags & CHANNEL_X) == CHANNEL_X)
212 #define IS_CHAN_PUREG(_c) \
213         (((_c)->channelFlags & CHANNEL_PUREG) == CHANNEL_PUREG)
214 #define IS_CHAN_NA(_c)  (((_c)->channelFlags & CHANNEL_A_HT20) == CHANNEL_A_HT20)
215 #define IS_CHAN_NG(_c)  (((_c)->channelFlags & CHANNEL_G_HT20) == CHANNEL_G_HT20)
216
217 #define IS_CHAN_TURBO(_c)   (((_c)->channelFlags & CHANNEL_TURBO) != 0)
218 #define IS_CHAN_CCK(_c)     (((_c)->channelFlags & CHANNEL_CCK) != 0)
219 #define IS_CHAN_OFDM(_c)    (((_c)->channelFlags & CHANNEL_OFDM) != 0)
220 #define IS_CHAN_XR(_c)      (((_c)->channelFlags & CHANNEL_XR) != 0)
221 #define IS_CHAN_5GHZ(_c)    (((_c)->channelFlags & CHANNEL_5GHZ) != 0)
222 #define IS_CHAN_2GHZ(_c)    (((_c)->channelFlags & CHANNEL_2GHZ) != 0)
223 #define IS_CHAN_PASSIVE(_c) (((_c)->channelFlags & CHANNEL_PASSIVE) != 0)
224 #define IS_CHAN_HALF_RATE(_c)   (((_c)->channelFlags & CHANNEL_HALF) != 0)
225 #define IS_CHAN_QUARTER_RATE(_c) (((_c)->channelFlags & CHANNEL_QUARTER) != 0)
226 #define IS_CHAN_HT(_c)      (((_c)->channelFlags & CHANNEL_HT20) != 0)
227 #define IS_CHAN_HT20(_c)    (((_c)->channelFlags & CHANNEL_HT20) != 0)
228 #define IS_CHAN_HT40(_c)    (((_c)->channelFlags & CHANNEL_HT40) != 0)
229
230 #define IS_CHAN_IN_PUBLIC_SAFETY_BAND(_c) ((_c) > 4940 && (_c) < 4990)
231
232 /*
233  * Register manipulation macros that expect bit field defines
234  * to follow the convention that an _S suffix is appended for
235  * a shift count, while the field mask has no suffix.
236  */
237 #define SM(_v, _f)  (((_v) << _f##_S) & _f)
238 #define MS(_v, _f)  (((_v) & _f) >> _f##_S)
239 #define OS_REG_RMW_FIELD(_a, _r, _f, _v)                                \
240         iowrite32_mac(_r,                                               \
241                      (ioread32_mac(_r) & ~_f)           \
242                       | (((_v) << _f##_S) & _f))
243 #define OS_REG_RMW(_a, _r, _set, _clr)                                  \
244         iowrite32_mac(_r,                                               \
245                      (ioread32_mac(_r) & ~(_clr)) | (_set))
246 #define OS_REG_SET_BIT(_a, _r, _f)                      \
247         iowrite32_mac(_r, ioread32_mac(_r) | _f)
248 #define OS_REG_CLR_BIT(_a, _r, _f)                      \
249         iowrite32_mac(_r, ioread32_mac(_r) & ~_f)
250
251
252 /* wait for the register contents to have the specified value */
253 extern HAL_BOOL ath_hal_wait(struct ath_hal *, a_uint32_t reg,
254                              a_uint32_t mask, a_uint32_t val);
255
256 /* allocate and free memory */
257 extern void *ath_hal_malloc(size_t);
258 extern void ath_hal_free(void *);
259
260 /*
261  * Generic get/set capability support.  Each chip overrides
262  * this routine to support chip-specific capabilities.
263  */
264 extern HAL_STATUS ath_hal_getcapability(struct ath_hal *ah,
265                 HAL_CAPABILITY_TYPE type);
266 extern HAL_BOOL ath_hal_setcapability(struct ath_hal *ah,
267               HAL_CAPABILITY_TYPE type, a_uint32_t capability,
268               a_uint32_t setting, HAL_STATUS *status);
269
270 #endif /* _ATH_AH_INTERAL_H_ */