2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
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:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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
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.
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.
38 #include "ah_internal.h"
39 #include <asf_bitmap.h>
41 extern struct ath_hal *ar5416Attach(a_uint32_t devid,HAL_SOFTC sc, adf_os_device_t dev,
42 a_uint32_t flags, HAL_STATUS *status);
45 ath_hal_attach_tgt(a_uint32_t devid,HAL_SOFTC sc,
47 a_uint32_t flags, HAL_STATUS *error)
49 struct ath_hal *ah = AH_NULL;
51 devid = AR5416_DEVID_PCIE;
52 ah = ar5416Attach(devid, sc, dev, flags, error);
58 ath_hal_getcapability(struct ath_hal *ah, HAL_CAPABILITY_TYPE type,
59 a_uint32_t capability, a_uint32_t *result)
62 const HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
64 case HAL_CAP_TSF_ADJUST:
66 case HAL_CAP_BSSIDMASK:
67 return pCap->halBssIdMaskSupport ? HAL_OK : HAL_ENOTSUPP;
69 return pCap->halVEOLSupport ? HAL_OK : HAL_ENOTSUPP;
76 ath_hal_setupratetable(struct ath_hal *ah, HAL_RATE_TABLE *rt)
80 if (rt->rateCodeToIndex[0] != 0)
83 for (i = 0; i < 32; i++)
84 rt->rateCodeToIndex[i] = (a_uint8_t) -1;
85 for (i = 0; i < rt->rateCount; i++) {
86 a_uint8_t code = rt->info[i].rateCode;
87 a_uint8_t cix = rt->info[i].controlRate;
89 rt->rateCodeToIndex[code] = i;
90 rt->rateCodeToIndex[code | rt->info[i].shortPreamble] = i;
91 rt->info[i].lpAckDuration = ath_hal_computetxtime(ah, rt,
92 WLAN_CTRL_FRAME_SIZE, cix, AH_FALSE);
93 rt->info[i].spAckDuration = ath_hal_computetxtime(ah, rt,
94 WLAN_CTRL_FRAME_SIZE, cix, AH_TRUE);
98 #define CCK_SIFS_TIME 10
99 #define CCK_PREAMBLE_BITS 144
100 #define CCK_PLCP_BITS 48
102 #define OFDM_SIFS_TIME 16
103 #define OFDM_PREAMBLE_TIME 20
104 #define OFDM_PLCP_BITS 22
105 #define OFDM_SYMBOL_TIME 4
107 #define OFDM_SIFS_TIME_HALF 32
108 #define OFDM_PREAMBLE_TIME_HALF 40
109 #define OFDM_PLCP_BITS_HALF 22
110 #define OFDM_SYMBOL_TIME_HALF 8
112 #define OFDM_SIFS_TIME_QUARTER 64
113 #define OFDM_PREAMBLE_TIME_QUARTER 80
114 #define OFDM_PLCP_BITS_QUARTER 22
115 #define OFDM_SYMBOL_TIME_QUARTER 16
118 ath_hal_computetxtime(struct ath_hal *ah,
119 const HAL_RATE_TABLE *rates, a_uint32_t frameLen, a_uint16_t rateix,
120 HAL_BOOL shortPreamble)
122 a_uint32_t bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
125 kbps = rates->info[rateix].rateKbps;
128 * index can be invalid duting dynamic Turbo transitions.
130 if(kbps == 0) return 0;
131 switch (rates->info[rateix].phy) {
133 case IEEE80211_T_CCK:
134 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
135 if (shortPreamble && rates->info[rateix].shortPreamble)
137 numBits = frameLen << 3;
138 txTime = phyTime + ((numBits * 1000)/kbps);
139 /* TODO: make sure the same value of txTime can use in all device */
140 if (ath_hal_getcapability(ah, HAL_CAP_HT, 0, AH_NULL) != HAL_OK)
141 txTime = txTime + CCK_SIFS_TIME;
143 case IEEE80211_T_OFDM:
144 /* full rate channel */
145 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
146 HALASSERT(bitsPerSymbol != 0);
148 numBits = OFDM_PLCP_BITS + (frameLen << 3);
149 numSymbols = asf_howmany(numBits, bitsPerSymbol);
150 txTime = OFDM_PREAMBLE_TIME + (numSymbols * OFDM_SYMBOL_TIME);
151 /* TODO: make sure the same value of txTime can use in all device */
152 if (ath_hal_getcapability(ah, HAL_CAP_HT, 0, AH_NULL) != HAL_OK)
153 txTime = txTime + OFDM_SIFS_TIME;
163 #undef CCK_PREAMBLE_BITS
166 #undef OFDM_SIFS_TIME
167 #undef OFDM_PREAMBLE_TIME
168 #undef OFDM_PLCP_BITS
169 #undef OFDM_SYMBOL_TIME
173 ath_hal_get_curmode(struct ath_hal *ah, HAL_CHANNEL_INTERNAL *chan)
176 return HAL_MODE_11NG;
178 if (IS_CHAN_NA(chan))
179 return HAL_MODE_11NA;
184 if (IS_CHAN_NG(chan))
185 return HAL_MODE_11NG;
194 return HAL_MODE_11NG;
200 ath_hal_wait(struct ath_hal *ah, a_uint32_t reg, a_uint32_t mask, a_uint32_t val)
202 #define AH_TIMEOUT_11N 100000
203 #define AH_TIMEOUT_11G 1000
207 if (ath_hal_getcapability(ah, HAL_CAP_HT, 0, AH_NULL) == HAL_OK) {
208 for (i = 0; i < AH_TIMEOUT_11N; i++) {
209 if ((OS_REG_READ(ah, reg) & mask) == val)
214 for (i = 0; i < AH_TIMEOUT_11G; i++) {
215 if ((OS_REG_READ(ah, reg) & mask) == val)
222 #undef AH_TIMEOUT_11N
223 #undef AH_TIMEOUT_11G