blob: af5bb50a2e8b6ce8cd8bdc5da46a213c01354721 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/io.h>
18#include <asm/unaligned.h>
Vasanthakumar Thiagarajan7b6840a2009-09-07 17:46:49 +053019#include <linux/pci.h>
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070020
Sujith394cf0a2009-02-09 13:26:54 +053021#include "ath9k.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070022#include "initvals.h"
23
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080024#define ATH9K_CLOCK_RATE_CCK 22
25#define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
26#define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070027
Sujithcbe61d82009-02-09 13:27:12 +053028static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
29static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan,
Sujithf1dc5602008-10-29 10:16:30 +053030 enum ath9k_ht_macmode macmode);
Sujithcbe61d82009-02-09 13:27:12 +053031static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +053032 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +053033 u32 reg, u32 value);
Sujithcbe61d82009-02-09 13:27:12 +053034static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
35static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070036
Sujithf1dc5602008-10-29 10:16:30 +053037/********************/
38/* Helper Functions */
39/********************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070040
Sujithcbe61d82009-02-09 13:27:12 +053041static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053042{
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080043 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053044
Sujith2660b812009-02-09 13:27:26 +053045 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080046 return clks / ATH9K_CLOCK_RATE_CCK;
47 if (conf->channel->band == IEEE80211_BAND_2GHZ)
48 return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
Sujithcbe61d82009-02-09 13:27:12 +053049
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080050 return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053051}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070052
Sujithcbe61d82009-02-09 13:27:12 +053053static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks)
Sujithf1dc5602008-10-29 10:16:30 +053054{
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080055 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053056
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080057 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053058 return ath9k_hw_mac_usec(ah, clks) / 2;
59 else
60 return ath9k_hw_mac_usec(ah, clks);
61}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070062
Sujithcbe61d82009-02-09 13:27:12 +053063static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053064{
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080065 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053066
Sujith2660b812009-02-09 13:27:26 +053067 if (!ah->curchan) /* should really check for CCK instead */
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080068 return usecs *ATH9K_CLOCK_RATE_CCK;
69 if (conf->channel->band == IEEE80211_BAND_2GHZ)
70 return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
71 return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
Sujithf1dc5602008-10-29 10:16:30 +053072}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070073
Sujithcbe61d82009-02-09 13:27:12 +053074static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
Sujithf1dc5602008-10-29 10:16:30 +053075{
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080076 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
Sujithcbe61d82009-02-09 13:27:12 +053077
Luis R. Rodriguez4febf7b2008-12-23 15:58:48 -080078 if (conf_is_ht40(conf))
Sujithf1dc5602008-10-29 10:16:30 +053079 return ath9k_hw_mac_clks(ah, usecs) * 2;
80 else
81 return ath9k_hw_mac_clks(ah, usecs);
82}
83
Gabor Juhosfb4a3d32009-04-29 13:01:58 +020084/*
85 * Read and write, they both share the same lock. We do this to serialize
86 * reads and writes on Atheros 802.11n PCI devices only. This is required
87 * as the FIFO on these devices can only accept sanely 2 requests. After
88 * that the device goes bananas. Serializing the reads/writes prevents this
89 * from happening.
90 */
91
92void ath9k_iowrite32(struct ath_hw *ah, u32 reg_offset, u32 val)
93{
94 if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
95 unsigned long flags;
96 spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags);
97 iowrite32(val, ah->ah_sc->mem + reg_offset);
98 spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags);
99 } else
100 iowrite32(val, ah->ah_sc->mem + reg_offset);
101}
102
103unsigned int ath9k_ioread32(struct ath_hw *ah, u32 reg_offset)
104{
105 u32 val;
106 if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
107 unsigned long flags;
108 spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags);
109 val = ioread32(ah->ah_sc->mem + reg_offset);
110 spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags);
111 } else
112 val = ioread32(ah->ah_sc->mem + reg_offset);
113 return val;
114}
115
Sujith0caa7b12009-02-16 13:23:20 +0530116bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700117{
118 int i;
119
Sujith0caa7b12009-02-16 13:23:20 +0530120 BUG_ON(timeout < AH_TIME_QUANTUM);
121
122 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700123 if ((REG_READ(ah, reg) & mask) == val)
124 return true;
125
126 udelay(AH_TIME_QUANTUM);
127 }
Sujith04bd4632008-11-28 22:18:05 +0530128
Sujithd8baa932009-03-30 15:28:25 +0530129 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
Sujith0caa7b12009-02-16 13:23:20 +0530130 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
131 timeout, reg, REG_READ(ah, reg), mask, val);
Sujithf1dc5602008-10-29 10:16:30 +0530132
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700133 return false;
134}
135
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700136u32 ath9k_hw_reverse_bits(u32 val, u32 n)
137{
138 u32 retval;
139 int i;
140
141 for (i = 0, retval = 0; i < n; i++) {
142 retval = (retval << 1) | (val & 1);
143 val >>= 1;
144 }
145 return retval;
146}
147
Sujithcbe61d82009-02-09 13:27:12 +0530148bool ath9k_get_channel_edges(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530149 u16 flags, u16 *low,
150 u16 *high)
151{
Sujith2660b812009-02-09 13:27:26 +0530152 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +0530153
154 if (flags & CHANNEL_5GHZ) {
155 *low = pCap->low_5ghz_chan;
156 *high = pCap->high_5ghz_chan;
157 return true;
158 }
159 if ((flags & CHANNEL_2GHZ)) {
160 *low = pCap->low_2ghz_chan;
161 *high = pCap->high_2ghz_chan;
162 return true;
163 }
164 return false;
165}
166
Sujithcbe61d82009-02-09 13:27:12 +0530167u16 ath9k_hw_computetxtime(struct ath_hw *ah,
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400168 const struct ath_rate_table *rates,
Sujithf1dc5602008-10-29 10:16:30 +0530169 u32 frameLen, u16 rateix,
170 bool shortPreamble)
171{
172 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
173 u32 kbps;
174
Sujithe63835b2008-11-18 09:07:53 +0530175 kbps = rates->info[rateix].ratekbps;
Sujithf1dc5602008-10-29 10:16:30 +0530176
177 if (kbps == 0)
178 return 0;
179
180 switch (rates->info[rateix].phy) {
Sujith46d14a52008-11-18 09:08:13 +0530181 case WLAN_RC_PHY_CCK:
Sujithf1dc5602008-10-29 10:16:30 +0530182 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
Sujithe63835b2008-11-18 09:07:53 +0530183 if (shortPreamble && rates->info[rateix].short_preamble)
Sujithf1dc5602008-10-29 10:16:30 +0530184 phyTime >>= 1;
185 numBits = frameLen << 3;
186 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
187 break;
Sujith46d14a52008-11-18 09:08:13 +0530188 case WLAN_RC_PHY_OFDM:
Sujith2660b812009-02-09 13:27:26 +0530189 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530190 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
191 numBits = OFDM_PLCP_BITS + (frameLen << 3);
192 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
193 txTime = OFDM_SIFS_TIME_QUARTER
194 + OFDM_PREAMBLE_TIME_QUARTER
195 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
Sujith2660b812009-02-09 13:27:26 +0530196 } else if (ah->curchan &&
197 IS_CHAN_HALF_RATE(ah->curchan)) {
Sujithf1dc5602008-10-29 10:16:30 +0530198 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
199 numBits = OFDM_PLCP_BITS + (frameLen << 3);
200 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
201 txTime = OFDM_SIFS_TIME_HALF +
202 OFDM_PREAMBLE_TIME_HALF
203 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
204 } else {
205 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
206 numBits = OFDM_PLCP_BITS + (frameLen << 3);
207 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
208 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
209 + (numSymbols * OFDM_SYMBOL_TIME);
210 }
211 break;
212 default:
Sujithd8baa932009-03-30 15:28:25 +0530213 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +0530214 "Unknown phy %u (rate ix %u)\n",
Sujithf1dc5602008-10-29 10:16:30 +0530215 rates->info[rateix].phy, rateix);
216 txTime = 0;
217 break;
218 }
219
220 return txTime;
221}
222
Sujithcbe61d82009-02-09 13:27:12 +0530223void ath9k_hw_get_channel_centers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530224 struct ath9k_channel *chan,
225 struct chan_centers *centers)
226{
227 int8_t extoff;
Sujithf1dc5602008-10-29 10:16:30 +0530228
229 if (!IS_CHAN_HT40(chan)) {
230 centers->ctl_center = centers->ext_center =
231 centers->synth_center = chan->channel;
232 return;
233 }
234
235 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
236 (chan->chanmode == CHANNEL_G_HT40PLUS)) {
237 centers->synth_center =
238 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
239 extoff = 1;
240 } else {
241 centers->synth_center =
242 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
243 extoff = -1;
244 }
245
246 centers->ctl_center =
247 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
248 centers->ext_center =
249 centers->synth_center + (extoff *
Sujith2660b812009-02-09 13:27:26 +0530250 ((ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_20) ?
Sujithf1dc5602008-10-29 10:16:30 +0530251 HT40_CHANNEL_CENTER_SHIFT : 15));
Sujithf1dc5602008-10-29 10:16:30 +0530252}
253
254/******************/
255/* Chip Revisions */
256/******************/
257
Sujithcbe61d82009-02-09 13:27:12 +0530258static void ath9k_hw_read_revisions(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530259{
260 u32 val;
261
262 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
263
264 if (val == 0xFF) {
265 val = REG_READ(ah, AR_SREV);
Sujithd535a422009-02-09 13:27:06 +0530266 ah->hw_version.macVersion =
267 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
268 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
Sujith2660b812009-02-09 13:27:26 +0530269 ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
Sujithf1dc5602008-10-29 10:16:30 +0530270 } else {
271 if (!AR_SREV_9100(ah))
Sujithd535a422009-02-09 13:27:06 +0530272 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
Sujithf1dc5602008-10-29 10:16:30 +0530273
Sujithd535a422009-02-09 13:27:06 +0530274 ah->hw_version.macRev = val & AR_SREV_REVISION;
Sujithf1dc5602008-10-29 10:16:30 +0530275
Sujithd535a422009-02-09 13:27:06 +0530276 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
Sujith2660b812009-02-09 13:27:26 +0530277 ah->is_pciexpress = true;
Sujithf1dc5602008-10-29 10:16:30 +0530278 }
279}
280
Sujithcbe61d82009-02-09 13:27:12 +0530281static int ath9k_hw_get_radiorev(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530282{
283 u32 val;
284 int i;
285
286 REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
287
288 for (i = 0; i < 8; i++)
289 REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
290 val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
291 val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
292
293 return ath9k_hw_reverse_bits(val, 8);
294}
295
296/************************************/
297/* HW Attach, Detach, Init Routines */
298/************************************/
299
Sujithcbe61d82009-02-09 13:27:12 +0530300static void ath9k_hw_disablepcie(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530301{
Sujithfeed0292009-01-29 11:37:35 +0530302 if (AR_SREV_9100(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530303 return;
304
305 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
306 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
307 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
308 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
309 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
310 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
311 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
312 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
313 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
314
315 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
316}
317
Sujithcbe61d82009-02-09 13:27:12 +0530318static bool ath9k_hw_chip_test(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530319{
320 u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
321 u32 regHold[2];
322 u32 patternData[4] = { 0x55555555,
323 0xaaaaaaaa,
324 0x66666666,
325 0x99999999 };
326 int i, j;
327
328 for (i = 0; i < 2; i++) {
329 u32 addr = regAddr[i];
330 u32 wrData, rdData;
331
332 regHold[i] = REG_READ(ah, addr);
333 for (j = 0; j < 0x100; j++) {
334 wrData = (j << 16) | j;
335 REG_WRITE(ah, addr, wrData);
336 rdData = REG_READ(ah, addr);
337 if (rdData != wrData) {
Sujithd8baa932009-03-30 15:28:25 +0530338 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +0530339 "address test failed "
Sujithf1dc5602008-10-29 10:16:30 +0530340 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
Sujith04bd4632008-11-28 22:18:05 +0530341 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530342 return false;
343 }
344 }
345 for (j = 0; j < 4; j++) {
346 wrData = patternData[j];
347 REG_WRITE(ah, addr, wrData);
348 rdData = REG_READ(ah, addr);
349 if (wrData != rdData) {
Sujithd8baa932009-03-30 15:28:25 +0530350 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +0530351 "address test failed "
Sujithf1dc5602008-10-29 10:16:30 +0530352 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
Sujith04bd4632008-11-28 22:18:05 +0530353 addr, wrData, rdData);
Sujithf1dc5602008-10-29 10:16:30 +0530354 return false;
355 }
356 }
357 REG_WRITE(ah, regAddr[i], regHold[i]);
358 }
359 udelay(100);
Sujithcbe61d82009-02-09 13:27:12 +0530360
Sujithf1dc5602008-10-29 10:16:30 +0530361 return true;
362}
363
364static const char *ath9k_hw_devname(u16 devid)
365{
366 switch (devid) {
367 case AR5416_DEVID_PCI:
Sujithf1dc5602008-10-29 10:16:30 +0530368 return "Atheros 5416";
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +0100369 case AR5416_DEVID_PCIE:
370 return "Atheros 5418";
Sujithf1dc5602008-10-29 10:16:30 +0530371 case AR9160_DEVID_PCI:
372 return "Atheros 9160";
Gabor Juhos0c1aa492009-01-14 20:17:12 +0100373 case AR5416_AR9100_DEVID:
374 return "Atheros 9100";
Sujithf1dc5602008-10-29 10:16:30 +0530375 case AR9280_DEVID_PCI:
376 case AR9280_DEVID_PCIE:
377 return "Atheros 9280";
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530378 case AR9285_DEVID_PCIE:
379 return "Atheros 9285";
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530380 case AR5416_DEVID_AR9287_PCI:
381 case AR5416_DEVID_AR9287_PCIE:
382 return "Atheros 9287";
Sujithf1dc5602008-10-29 10:16:30 +0530383 }
384
385 return NULL;
386}
387
Luis R. Rodriguezb8b0f372009-08-03 12:24:43 -0700388static void ath9k_hw_init_config(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700389{
390 int i;
391
Sujith2660b812009-02-09 13:27:26 +0530392 ah->config.dma_beacon_response_time = 2;
393 ah->config.sw_beacon_response_time = 10;
394 ah->config.additional_swba_backoff = 0;
395 ah->config.ack_6mb = 0x0;
396 ah->config.cwm_ignore_extcca = 0;
397 ah->config.pcie_powersave_enable = 0;
Sujith2660b812009-02-09 13:27:26 +0530398 ah->config.pcie_clock_req = 0;
Sujith2660b812009-02-09 13:27:26 +0530399 ah->config.pcie_waen = 0;
400 ah->config.analog_shiftreg = 1;
401 ah->config.ht_enable = 1;
402 ah->config.ofdm_trig_low = 200;
403 ah->config.ofdm_trig_high = 500;
404 ah->config.cck_trig_high = 200;
405 ah->config.cck_trig_low = 100;
406 ah->config.enable_ani = 1;
Sujith1cf68732009-08-13 09:34:32 +0530407 ah->config.diversity_control = ATH9K_ANT_VARIABLE;
Sujith2660b812009-02-09 13:27:26 +0530408 ah->config.antenna_switch_swap = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700409
410 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujith2660b812009-02-09 13:27:26 +0530411 ah->config.spurchans[i][0] = AR_NO_SPUR;
412 ah->config.spurchans[i][1] = AR_NO_SPUR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700413 }
414
Sujith0ef1f162009-03-30 15:28:35 +0530415 ah->config.intr_mitigation = true;
Luis R. Rodriguez61584252009-03-12 18:18:49 -0400416
417 /*
418 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
419 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
420 * This means we use it for all AR5416 devices, and the few
421 * minor PCI AR9280 devices out there.
422 *
423 * Serialization is required because these devices do not handle
424 * well the case of two concurrent reads/writes due to the latency
425 * involved. During one read/write another read/write can be issued
426 * on another CPU while the previous read/write may still be working
427 * on our hardware, if we hit this case the hardware poops in a loop.
428 * We prevent this by serializing reads and writes.
429 *
430 * This issue is not present on PCI-Express devices or pre-AR5416
431 * devices (legacy, 802.11abg).
432 */
433 if (num_possible_cpus() > 1)
David S. Miller2d6a5e92009-03-17 15:01:30 -0700434 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700435}
436
Luis R. Rodriguez50aca252009-08-03 12:24:42 -0700437static void ath9k_hw_init_defaults(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700438{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700439 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
440
441 regulatory->country_code = CTRY_DEFAULT;
442 regulatory->power_limit = MAX_RATE_POWER;
443 regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
444
Sujithd535a422009-02-09 13:27:06 +0530445 ah->hw_version.magic = AR5416_MAGIC;
Sujithd535a422009-02-09 13:27:06 +0530446 ah->hw_version.subvendorid = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700447
448 ah->ah_flags = 0;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -0700449 if (ah->hw_version.devid == AR5416_AR9100_DEVID)
Sujithd535a422009-02-09 13:27:06 +0530450 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700451 if (!AR_SREV_9100(ah))
452 ah->ah_flags = AH_USE_EEPROM;
453
Sujith2660b812009-02-09 13:27:26 +0530454 ah->atim_window = 0;
Sujith2660b812009-02-09 13:27:26 +0530455 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
456 ah->beacon_interval = 100;
457 ah->enable_32kHz_clock = DONT_USE_32KHZ;
458 ah->slottime = (u32) -1;
459 ah->acktimeout = (u32) -1;
460 ah->ctstimeout = (u32) -1;
461 ah->globaltxtimeout = (u32) -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700462
Sujith2660b812009-02-09 13:27:26 +0530463 ah->gbeacon_rate = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700464
Gabor Juhoscbdec972009-07-24 17:27:22 +0200465 ah->power_mode = ATH9K_PM_UNDEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700466}
467
Sujithcbe61d82009-02-09 13:27:12 +0530468static int ath9k_hw_rfattach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700469{
470 bool rfStatus = false;
471 int ecode = 0;
472
473 rfStatus = ath9k_hw_init_rf(ah, &ecode);
474 if (!rfStatus) {
Sujithd8baa932009-03-30 15:28:25 +0530475 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
476 "RF setup failed, status: %u\n", ecode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700477 return ecode;
478 }
479
480 return 0;
481}
482
Sujithcbe61d82009-02-09 13:27:12 +0530483static int ath9k_hw_rf_claim(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700484{
485 u32 val;
486
487 REG_WRITE(ah, AR_PHY(0), 0x00000007);
488
489 val = ath9k_hw_get_radiorev(ah);
490 switch (val & AR_RADIO_SREV_MAJOR) {
491 case 0:
492 val = AR_RAD5133_SREV_MAJOR;
493 break;
494 case AR_RAD5133_SREV_MAJOR:
495 case AR_RAD5122_SREV_MAJOR:
496 case AR_RAD2133_SREV_MAJOR:
497 case AR_RAD2122_SREV_MAJOR:
498 break;
499 default:
Sujithd8baa932009-03-30 15:28:25 +0530500 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
501 "Radio Chip Rev 0x%02X not supported\n",
502 val & AR_RADIO_SREV_MAJOR);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700503 return -EOPNOTSUPP;
504 }
505
Sujithd535a422009-02-09 13:27:06 +0530506 ah->hw_version.analog5GhzRev = val;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700507
508 return 0;
509}
510
Sujithcbe61d82009-02-09 13:27:12 +0530511static int ath9k_hw_init_macaddr(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700512{
Sujithf1dc5602008-10-29 10:16:30 +0530513 u32 sum;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700514 int i;
Sujithf1dc5602008-10-29 10:16:30 +0530515 u16 eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700516
Sujithf1dc5602008-10-29 10:16:30 +0530517 sum = 0;
518 for (i = 0; i < 3; i++) {
Sujithf74df6f2009-02-09 13:27:24 +0530519 eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
Sujithf1dc5602008-10-29 10:16:30 +0530520 sum += eeval;
Sujithba52da52009-02-09 13:27:10 +0530521 ah->macaddr[2 * i] = eeval >> 8;
522 ah->macaddr[2 * i + 1] = eeval & 0xff;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700523 }
Sujithd8baa932009-03-30 15:28:25 +0530524 if (sum == 0 || sum == 0xffff * 3)
Sujithf1dc5602008-10-29 10:16:30 +0530525 return -EADDRNOTAVAIL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700526
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700527 return 0;
528}
529
Sujithcbe61d82009-02-09 13:27:12 +0530530static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530531{
532 u32 rxgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530533
Sujithf74df6f2009-02-09 13:27:24 +0530534 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
535 rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530536
537 if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530538 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530539 ar9280Modes_backoff_13db_rxgain_9280_2,
540 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
541 else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
Sujith2660b812009-02-09 13:27:26 +0530542 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530543 ar9280Modes_backoff_23db_rxgain_9280_2,
544 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
545 else
Sujith2660b812009-02-09 13:27:26 +0530546 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530547 ar9280Modes_original_rxgain_9280_2,
548 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530549 } else {
Sujith2660b812009-02-09 13:27:26 +0530550 INIT_INI_ARRAY(&ah->iniModesRxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530551 ar9280Modes_original_rxgain_9280_2,
552 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530553 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530554}
555
Sujithcbe61d82009-02-09 13:27:12 +0530556static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530557{
558 u32 txgain_type;
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530559
Sujithf74df6f2009-02-09 13:27:24 +0530560 if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
561 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530562
563 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
Sujith2660b812009-02-09 13:27:26 +0530564 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530565 ar9280Modes_high_power_tx_gain_9280_2,
566 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
567 else
Sujith2660b812009-02-09 13:27:26 +0530568 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530569 ar9280Modes_original_tx_gain_9280_2,
570 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530571 } else {
Sujith2660b812009-02-09 13:27:26 +0530572 INIT_INI_ARRAY(&ah->iniModesTxGain,
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530573 ar9280Modes_original_tx_gain_9280_2,
574 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
Sujithcbe61d82009-02-09 13:27:12 +0530575 }
Senthil Balasubramanian9f804202008-11-13 17:58:41 +0530576}
577
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700578static int ath9k_hw_post_init(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700579{
580 int ecode;
581
Sujithd8baa932009-03-30 15:28:25 +0530582 if (!ath9k_hw_chip_test(ah))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700583 return -ENODEV;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700584
585 ecode = ath9k_hw_rf_claim(ah);
586 if (ecode != 0)
587 return ecode;
588
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700589 ecode = ath9k_hw_eeprom_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700590 if (ecode != 0)
591 return ecode;
Sujith7d01b222009-03-13 08:55:55 +0530592
593 DPRINTF(ah->ah_sc, ATH_DBG_CONFIG, "Eeprom VER: %d, REV: %d\n",
594 ah->eep_ops->get_eeprom_ver(ah), ah->eep_ops->get_eeprom_rev(ah));
595
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700596 ecode = ath9k_hw_rfattach(ah);
597 if (ecode != 0)
598 return ecode;
599
600 if (!AR_SREV_9100(ah)) {
601 ath9k_hw_ani_setup(ah);
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700602 ath9k_hw_ani_init(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700603 }
Sujithf1dc5602008-10-29 10:16:30 +0530604
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700605 return 0;
606}
607
Luis R. Rodriguezee2bb462009-08-03 12:24:39 -0700608static bool ath9k_hw_devid_supported(u16 devid)
609{
610 switch (devid) {
611 case AR5416_DEVID_PCI:
612 case AR5416_DEVID_PCIE:
613 case AR5416_AR9100_DEVID:
614 case AR9160_DEVID_PCI:
615 case AR9280_DEVID_PCI:
616 case AR9280_DEVID_PCIE:
617 case AR9285_DEVID_PCIE:
618 case AR5416_DEVID_AR9287_PCI:
619 case AR5416_DEVID_AR9287_PCIE:
620 return true;
621 default:
622 break;
623 }
624 return false;
625}
626
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700627static bool ath9k_hw_macversion_supported(u32 macversion)
628{
629 switch (macversion) {
630 case AR_SREV_VERSION_5416_PCI:
631 case AR_SREV_VERSION_5416_PCIE:
632 case AR_SREV_VERSION_9160:
633 case AR_SREV_VERSION_9100:
634 case AR_SREV_VERSION_9280:
635 case AR_SREV_VERSION_9285:
636 case AR_SREV_VERSION_9287:
637 return true;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400638 /* Not yet */
639 case AR_SREV_VERSION_9271:
Luis R. Rodriguezf9d4a662009-08-03 12:24:41 -0700640 default:
641 break;
642 }
643 return false;
644}
645
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700646static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700647{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700648 if (AR_SREV_9160_10_OR_LATER(ah)) {
649 if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530650 ah->iq_caldata.calData = &iq_cal_single_sample;
651 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700652 &adc_gain_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530653 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700654 &adc_dc_cal_single_sample;
Sujith2660b812009-02-09 13:27:26 +0530655 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700656 &adc_init_dc_cal;
657 } else {
Sujith2660b812009-02-09 13:27:26 +0530658 ah->iq_caldata.calData = &iq_cal_multi_sample;
659 ah->adcgain_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700660 &adc_gain_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530661 ah->adcdc_caldata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700662 &adc_dc_cal_multi_sample;
Sujith2660b812009-02-09 13:27:26 +0530663 ah->adcdc_calinitdata.calData =
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700664 &adc_init_dc_cal;
665 }
Sujith2660b812009-02-09 13:27:26 +0530666 ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700667 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700668}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700669
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700670static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
671{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400672 if (AR_SREV_9271(ah)) {
673 INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271_1_0,
674 ARRAY_SIZE(ar9271Modes_9271_1_0), 6);
675 INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271_1_0,
676 ARRAY_SIZE(ar9271Common_9271_1_0), 2);
677 return;
678 }
679
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530680 if (AR_SREV_9287_11_OR_LATER(ah)) {
681 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
682 ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
683 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
684 ARRAY_SIZE(ar9287Common_9287_1_1), 2);
685 if (ah->config.pcie_clock_req)
686 INIT_INI_ARRAY(&ah->iniPcieSerdes,
687 ar9287PciePhy_clkreq_off_L1_9287_1_1,
688 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
689 else
690 INIT_INI_ARRAY(&ah->iniPcieSerdes,
691 ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
692 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
693 2);
694 } else if (AR_SREV_9287_10_OR_LATER(ah)) {
695 INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
696 ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
697 INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
698 ARRAY_SIZE(ar9287Common_9287_1_0), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700699
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530700 if (ah->config.pcie_clock_req)
701 INIT_INI_ARRAY(&ah->iniPcieSerdes,
702 ar9287PciePhy_clkreq_off_L1_9287_1_0,
703 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
704 else
705 INIT_INI_ARRAY(&ah->iniPcieSerdes,
706 ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
707 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
708 2);
709 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
710
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530711
Sujith2660b812009-02-09 13:27:26 +0530712 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530713 ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530714 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530715 ARRAY_SIZE(ar9285Common_9285_1_2), 2);
716
Sujith2660b812009-02-09 13:27:26 +0530717 if (ah->config.pcie_clock_req) {
718 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530719 ar9285PciePhy_clkreq_off_L1_9285_1_2,
720 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
721 } else {
Sujith2660b812009-02-09 13:27:26 +0530722 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530723 ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
724 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
725 2);
726 }
727 } else if (AR_SREV_9285_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530728 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530729 ARRAY_SIZE(ar9285Modes_9285), 6);
Sujith2660b812009-02-09 13:27:26 +0530730 INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530731 ARRAY_SIZE(ar9285Common_9285), 2);
732
Sujith2660b812009-02-09 13:27:26 +0530733 if (ah->config.pcie_clock_req) {
734 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530735 ar9285PciePhy_clkreq_off_L1_9285,
736 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
737 } else {
Sujith2660b812009-02-09 13:27:26 +0530738 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530739 ar9285PciePhy_clkreq_always_on_L1_9285,
740 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
741 }
742 } else if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530743 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700744 ARRAY_SIZE(ar9280Modes_9280_2), 6);
Sujith2660b812009-02-09 13:27:26 +0530745 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700746 ARRAY_SIZE(ar9280Common_9280_2), 2);
747
Sujith2660b812009-02-09 13:27:26 +0530748 if (ah->config.pcie_clock_req) {
749 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530750 ar9280PciePhy_clkreq_off_L1_9280,
751 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700752 } else {
Sujith2660b812009-02-09 13:27:26 +0530753 INIT_INI_ARRAY(&ah->iniPcieSerdes,
Sujithf1dc5602008-10-29 10:16:30 +0530754 ar9280PciePhy_clkreq_always_on_L1_9280,
755 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700756 }
Sujith2660b812009-02-09 13:27:26 +0530757 INIT_INI_ARRAY(&ah->iniModesAdditional,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700758 ar9280Modes_fast_clock_9280_2,
Sujithf1dc5602008-10-29 10:16:30 +0530759 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700760 } else if (AR_SREV_9280_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530761 INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700762 ARRAY_SIZE(ar9280Modes_9280), 6);
Sujith2660b812009-02-09 13:27:26 +0530763 INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700764 ARRAY_SIZE(ar9280Common_9280), 2);
765 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530766 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700767 ARRAY_SIZE(ar5416Modes_9160), 6);
Sujith2660b812009-02-09 13:27:26 +0530768 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700769 ARRAY_SIZE(ar5416Common_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530770 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700771 ARRAY_SIZE(ar5416Bank0_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530772 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700773 ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530774 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700775 ARRAY_SIZE(ar5416Bank1_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530776 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777 ARRAY_SIZE(ar5416Bank2_9160), 2);
Sujith2660b812009-02-09 13:27:26 +0530778 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700779 ARRAY_SIZE(ar5416Bank3_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530780 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700781 ARRAY_SIZE(ar5416Bank6_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530782 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700783 ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
Sujith2660b812009-02-09 13:27:26 +0530784 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700785 ARRAY_SIZE(ar5416Bank7_9160), 2);
786 if (AR_SREV_9160_11(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530787 INIT_INI_ARRAY(&ah->iniAddac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700788 ar5416Addac_91601_1,
789 ARRAY_SIZE(ar5416Addac_91601_1), 2);
790 } else {
Sujith2660b812009-02-09 13:27:26 +0530791 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700792 ARRAY_SIZE(ar5416Addac_9160), 2);
793 }
794 } else if (AR_SREV_9100_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +0530795 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700796 ARRAY_SIZE(ar5416Modes_9100), 6);
Sujith2660b812009-02-09 13:27:26 +0530797 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700798 ARRAY_SIZE(ar5416Common_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530799 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700800 ARRAY_SIZE(ar5416Bank0_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530801 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700802 ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530803 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700804 ARRAY_SIZE(ar5416Bank1_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530805 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700806 ARRAY_SIZE(ar5416Bank2_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530807 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700808 ARRAY_SIZE(ar5416Bank3_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530809 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700810 ARRAY_SIZE(ar5416Bank6_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530811 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700812 ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
Sujith2660b812009-02-09 13:27:26 +0530813 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700814 ARRAY_SIZE(ar5416Bank7_9100), 2);
Sujith2660b812009-02-09 13:27:26 +0530815 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700816 ARRAY_SIZE(ar5416Addac_9100), 2);
817 } else {
Sujith2660b812009-02-09 13:27:26 +0530818 INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700819 ARRAY_SIZE(ar5416Modes), 6);
Sujith2660b812009-02-09 13:27:26 +0530820 INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700821 ARRAY_SIZE(ar5416Common), 2);
Sujith2660b812009-02-09 13:27:26 +0530822 INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700823 ARRAY_SIZE(ar5416Bank0), 2);
Sujith2660b812009-02-09 13:27:26 +0530824 INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700825 ARRAY_SIZE(ar5416BB_RfGain), 3);
Sujith2660b812009-02-09 13:27:26 +0530826 INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700827 ARRAY_SIZE(ar5416Bank1), 2);
Sujith2660b812009-02-09 13:27:26 +0530828 INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700829 ARRAY_SIZE(ar5416Bank2), 2);
Sujith2660b812009-02-09 13:27:26 +0530830 INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700831 ARRAY_SIZE(ar5416Bank3), 3);
Sujith2660b812009-02-09 13:27:26 +0530832 INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700833 ARRAY_SIZE(ar5416Bank6), 3);
Sujith2660b812009-02-09 13:27:26 +0530834 INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700835 ARRAY_SIZE(ar5416Bank6TPC), 3);
Sujith2660b812009-02-09 13:27:26 +0530836 INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700837 ARRAY_SIZE(ar5416Bank7), 2);
Sujith2660b812009-02-09 13:27:26 +0530838 INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700839 ARRAY_SIZE(ar5416Addac), 2);
840 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700841}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700842
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700843static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
844{
Vivek Natarajanac88b6e2009-07-23 10:59:57 +0530845 if (AR_SREV_9287_11(ah))
846 INIT_INI_ARRAY(&ah->iniModesRxGain,
847 ar9287Modes_rx_gain_9287_1_1,
848 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
849 else if (AR_SREV_9287_10(ah))
850 INIT_INI_ARRAY(&ah->iniModesRxGain,
851 ar9287Modes_rx_gain_9287_1_0,
852 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
853 else if (AR_SREV_9280_20(ah))
854 ath9k_hw_init_rxgain_ini(ah);
855
856 if (AR_SREV_9287_11(ah)) {
857 INIT_INI_ARRAY(&ah->iniModesTxGain,
858 ar9287Modes_tx_gain_9287_1_1,
859 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
860 } else if (AR_SREV_9287_10(ah)) {
861 INIT_INI_ARRAY(&ah->iniModesTxGain,
862 ar9287Modes_tx_gain_9287_1_0,
863 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
864 } else if (AR_SREV_9280_20(ah)) {
865 ath9k_hw_init_txgain_ini(ah);
866 } else if (AR_SREV_9285_12_OR_LATER(ah)) {
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530867 u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
868
869 /* txgain table */
870 if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
871 INIT_INI_ARRAY(&ah->iniModesTxGain,
872 ar9285Modes_high_power_tx_gain_9285_1_2,
873 ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6);
874 } else {
875 INIT_INI_ARRAY(&ah->iniModesTxGain,
876 ar9285Modes_original_tx_gain_9285_1_2,
877 ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6);
878 }
879
880 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700881}
Senthil Balasubramanian4e845162009-03-06 11:24:10 +0530882
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700883static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah)
884{
885 u32 i, j;
Sujith06d0f062009-02-12 10:06:45 +0530886
887 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
888 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
889
890 /* EEPROM Fixup */
Sujith2660b812009-02-09 13:27:26 +0530891 for (i = 0; i < ah->iniModes.ia_rows; i++) {
892 u32 reg = INI_RA(&ah->iniModes, i, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700893
Sujith2660b812009-02-09 13:27:26 +0530894 for (j = 1; j < ah->iniModes.ia_columns; j++) {
895 u32 val = INI_RA(&ah->iniModes, i, j);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700896
Sujith2660b812009-02-09 13:27:26 +0530897 INI_RA(&ah->iniModes, i, j) =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530898 ath9k_hw_ini_fixup(ah,
Sujith2660b812009-02-09 13:27:26 +0530899 &ah->eeprom.def,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700900 reg, val);
901 }
902 }
903 }
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700904}
905
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700906int ath9k_hw_init(struct ath_hw *ah)
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700907{
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700908 int r = 0;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700909
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700910 if (!ath9k_hw_devid_supported(ah->hw_version.devid))
911 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700912
913 ath9k_hw_init_defaults(ah);
914 ath9k_hw_init_config(ah);
915
916 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
917 DPRINTF(ah->ah_sc, ATH_DBG_FATAL, "Couldn't reset chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700918 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700919 }
920
921 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
922 DPRINTF(ah->ah_sc, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700923 return -EIO;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700924 }
925
926 if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
927 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
928 (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
929 ah->config.serialize_regmode =
930 SER_REG_MODE_ON;
931 } else {
932 ah->config.serialize_regmode =
933 SER_REG_MODE_OFF;
934 }
935 }
936
937 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "serialize_regmode is %d\n",
938 ah->config.serialize_regmode);
939
940 if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) {
941 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
942 "Mac Chip Rev 0x%02x.%x is not supported by "
943 "this driver\n", ah->hw_version.macVersion,
944 ah->hw_version.macRev);
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700945 return -EOPNOTSUPP;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700946 }
947
948 if (AR_SREV_9100(ah)) {
949 ah->iq_caldata.calData = &iq_cal_multi_sample;
950 ah->supp_cals = IQ_MISMATCH_CAL;
951 ah->is_pciexpress = false;
952 }
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400953
954 if (AR_SREV_9271(ah))
955 ah->is_pciexpress = false;
956
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700957 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
958
959 ath9k_hw_init_cal_settings(ah);
960
961 ah->ani_function = ATH9K_ANI_ALL;
962 if (AR_SREV_9280_10_OR_LATER(ah))
963 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
964
965 ath9k_hw_init_mode_regs(ah);
966
967 if (ah->is_pciexpress)
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530968 ath9k_hw_configpcipowersave(ah, 0, 0);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700969 else
970 ath9k_hw_disablepcie(ah);
971
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700972 r = ath9k_hw_post_init(ah);
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700973 if (r)
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700974 return r;
Luis R. Rodriguezaa4058a2009-08-03 12:24:45 -0700975
976 ath9k_hw_init_mode_gain_regs(ah);
977 ath9k_hw_fill_cap_info(ah);
978 ath9k_hw_init_11a_eeprom_fix(ah);
Sujithf6688cd2008-12-07 21:43:10 +0530979
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700980 r = ath9k_hw_init_macaddr(ah);
981 if (r) {
Luis R. Rodriguez07c10c62009-08-03 12:24:40 -0700982 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Sujithd8baa932009-03-30 15:28:25 +0530983 "Failed to initialize MAC address\n");
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -0700984 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700985 }
986
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400987 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
Sujith2660b812009-02-09 13:27:26 +0530988 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700989 else
Sujith2660b812009-02-09 13:27:26 +0530990 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700991
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700992 ath9k_init_nfcal_hist_buffer(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700993
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -0700994 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700995}
996
Sujithcbe61d82009-02-09 13:27:12 +0530997static void ath9k_hw_init_bb(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530998 struct ath9k_channel *chan)
999{
1000 u32 synthDelay;
1001
1002 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301003 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301004 synthDelay = (4 * synthDelay) / 22;
1005 else
1006 synthDelay /= 10;
1007
1008 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
1009
1010 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1011}
1012
Sujithcbe61d82009-02-09 13:27:12 +05301013static void ath9k_hw_init_qos(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301014{
1015 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
1016 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
1017
1018 REG_WRITE(ah, AR_QOS_NO_ACK,
1019 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
1020 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
1021 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
1022
1023 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
1024 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
1025 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
1026 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
1027 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
1028}
1029
Sujithcbe61d82009-02-09 13:27:12 +05301030static void ath9k_hw_init_pll(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301031 struct ath9k_channel *chan)
1032{
1033 u32 pll;
1034
1035 if (AR_SREV_9100(ah)) {
1036 if (chan && IS_CHAN_5GHZ(chan))
1037 pll = 0x1450;
1038 else
1039 pll = 0x1458;
1040 } else {
1041 if (AR_SREV_9280_10_OR_LATER(ah)) {
1042 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1043
1044 if (chan && IS_CHAN_HALF_RATE(chan))
1045 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1046 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1047 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1048
1049 if (chan && IS_CHAN_5GHZ(chan)) {
1050 pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
1051
1052
1053 if (AR_SREV_9280_20(ah)) {
1054 if (((chan->channel % 20) == 0)
1055 || ((chan->channel % 10) == 0))
1056 pll = 0x2850;
1057 else
1058 pll = 0x142c;
1059 }
1060 } else {
1061 pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
1062 }
1063
1064 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1065
1066 pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
1067
1068 if (chan && IS_CHAN_HALF_RATE(chan))
1069 pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
1070 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1071 pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
1072
1073 if (chan && IS_CHAN_5GHZ(chan))
1074 pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
1075 else
1076 pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
1077 } else {
1078 pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
1079
1080 if (chan && IS_CHAN_HALF_RATE(chan))
1081 pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
1082 else if (chan && IS_CHAN_QUARTER_RATE(chan))
1083 pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
1084
1085 if (chan && IS_CHAN_5GHZ(chan))
1086 pll |= SM(0xa, AR_RTC_PLL_DIV);
1087 else
1088 pll |= SM(0xb, AR_RTC_PLL_DIV);
1089 }
1090 }
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001091 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
Sujithf1dc5602008-10-29 10:16:30 +05301092
1093 udelay(RTC_PLL_SETTLE_DELAY);
1094
1095 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
1096}
1097
Sujithcbe61d82009-02-09 13:27:12 +05301098static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301099{
Sujithf1dc5602008-10-29 10:16:30 +05301100 int rx_chainmask, tx_chainmask;
1101
Sujith2660b812009-02-09 13:27:26 +05301102 rx_chainmask = ah->rxchainmask;
1103 tx_chainmask = ah->txchainmask;
Sujithf1dc5602008-10-29 10:16:30 +05301104
1105 switch (rx_chainmask) {
1106 case 0x5:
1107 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1108 AR_PHY_SWAP_ALT_CHAIN);
1109 case 0x3:
Sujithd535a422009-02-09 13:27:06 +05301110 if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
Sujithf1dc5602008-10-29 10:16:30 +05301111 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
1112 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
1113 break;
1114 }
1115 case 0x1:
1116 case 0x2:
Sujithf1dc5602008-10-29 10:16:30 +05301117 case 0x7:
1118 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
1119 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
1120 break;
1121 default:
1122 break;
1123 }
1124
1125 REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
1126 if (tx_chainmask == 0x5) {
1127 REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
1128 AR_PHY_SWAP_ALT_CHAIN);
1129 }
1130 if (AR_SREV_9100(ah))
1131 REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
1132 REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
1133}
1134
Sujithcbe61d82009-02-09 13:27:12 +05301135static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
Colin McCabed97809d2008-12-01 13:38:55 -08001136 enum nl80211_iftype opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301137{
Sujith2660b812009-02-09 13:27:26 +05301138 ah->mask_reg = AR_IMR_TXERR |
Sujithf1dc5602008-10-29 10:16:30 +05301139 AR_IMR_TXURN |
1140 AR_IMR_RXERR |
1141 AR_IMR_RXORN |
1142 AR_IMR_BCNMISC;
1143
Sujith0ef1f162009-03-30 15:28:35 +05301144 if (ah->config.intr_mitigation)
Sujith2660b812009-02-09 13:27:26 +05301145 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
Sujithf1dc5602008-10-29 10:16:30 +05301146 else
Sujith2660b812009-02-09 13:27:26 +05301147 ah->mask_reg |= AR_IMR_RXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301148
Sujith2660b812009-02-09 13:27:26 +05301149 ah->mask_reg |= AR_IMR_TXOK;
Sujithf1dc5602008-10-29 10:16:30 +05301150
Colin McCabed97809d2008-12-01 13:38:55 -08001151 if (opmode == NL80211_IFTYPE_AP)
Sujith2660b812009-02-09 13:27:26 +05301152 ah->mask_reg |= AR_IMR_MIB;
Sujithf1dc5602008-10-29 10:16:30 +05301153
Sujith2660b812009-02-09 13:27:26 +05301154 REG_WRITE(ah, AR_IMR, ah->mask_reg);
Sujithf1dc5602008-10-29 10:16:30 +05301155 REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
1156
1157 if (!AR_SREV_9100(ah)) {
1158 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
1159 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
1160 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
1161 }
1162}
1163
Sujithcbe61d82009-02-09 13:27:12 +05301164static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301165{
Sujithf1dc5602008-10-29 10:16:30 +05301166 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
Sujith04bd4632008-11-28 22:18:05 +05301167 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad ack timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301168 ah->acktimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301169 return false;
1170 } else {
1171 REG_RMW_FIELD(ah, AR_TIME_OUT,
1172 AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301173 ah->acktimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301174 return true;
1175 }
1176}
1177
Sujithcbe61d82009-02-09 13:27:12 +05301178static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
Sujithf1dc5602008-10-29 10:16:30 +05301179{
Sujithf1dc5602008-10-29 10:16:30 +05301180 if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
Sujith04bd4632008-11-28 22:18:05 +05301181 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad cts timeout %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05301182 ah->ctstimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301183 return false;
1184 } else {
1185 REG_RMW_FIELD(ah, AR_TIME_OUT,
1186 AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05301187 ah->ctstimeout = us;
Sujithf1dc5602008-10-29 10:16:30 +05301188 return true;
1189 }
1190}
1191
Sujithcbe61d82009-02-09 13:27:12 +05301192static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
Sujithf1dc5602008-10-29 10:16:30 +05301193{
Sujithf1dc5602008-10-29 10:16:30 +05301194 if (tu > 0xFFFF) {
1195 DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
Sujith04bd4632008-11-28 22:18:05 +05301196 "bad global tx timeout %u\n", tu);
Sujith2660b812009-02-09 13:27:26 +05301197 ah->globaltxtimeout = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05301198 return false;
1199 } else {
1200 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
Sujith2660b812009-02-09 13:27:26 +05301201 ah->globaltxtimeout = tu;
Sujithf1dc5602008-10-29 10:16:30 +05301202 return true;
1203 }
1204}
1205
Sujithcbe61d82009-02-09 13:27:12 +05301206static void ath9k_hw_init_user_settings(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301207{
Sujith2660b812009-02-09 13:27:26 +05301208 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
1209 ah->misc_mode);
Sujithf1dc5602008-10-29 10:16:30 +05301210
Sujith2660b812009-02-09 13:27:26 +05301211 if (ah->misc_mode != 0)
Sujithf1dc5602008-10-29 10:16:30 +05301212 REG_WRITE(ah, AR_PCU_MISC,
Sujith2660b812009-02-09 13:27:26 +05301213 REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
1214 if (ah->slottime != (u32) -1)
1215 ath9k_hw_setslottime(ah, ah->slottime);
1216 if (ah->acktimeout != (u32) -1)
1217 ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
1218 if (ah->ctstimeout != (u32) -1)
1219 ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
1220 if (ah->globaltxtimeout != (u32) -1)
1221 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
Sujithf1dc5602008-10-29 10:16:30 +05301222}
1223
1224const char *ath9k_hw_probe(u16 vendorid, u16 devid)
1225{
1226 return vendorid == ATHEROS_VENDOR_ID ?
1227 ath9k_hw_devname(devid) : NULL;
1228}
1229
Sujithcbe61d82009-02-09 13:27:12 +05301230void ath9k_hw_detach(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001231{
1232 if (!AR_SREV_9100(ah))
Luis R. Rodrigueze70c0cf2009-08-03 12:24:51 -07001233 ath9k_hw_ani_disable(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001234
Luis R. Rodriguez081b35a2009-08-03 12:24:50 -07001235 ath9k_hw_rf_free(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001236 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
1237 kfree(ah);
Luis R. Rodriguez9db6b6a2009-08-03 12:24:52 -07001238 ah = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001239}
1240
Sujithf1dc5602008-10-29 10:16:30 +05301241/*******/
1242/* INI */
1243/*******/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001244
Sujithcbe61d82009-02-09 13:27:12 +05301245static void ath9k_hw_override_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301246 struct ath9k_channel *chan)
1247{
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001248 u32 val;
1249
1250 if (AR_SREV_9271(ah)) {
1251 /*
1252 * Enable spectral scan to solution for issues with stuck
1253 * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
1254 * AR9271 1.1
1255 */
1256 if (AR_SREV_9271_10(ah)) {
1257 val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) | AR_PHY_SPECTRAL_SCAN_ENABLE;
1258 REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
1259 }
1260 else if (AR_SREV_9271_11(ah))
1261 /*
1262 * change AR_PHY_RF_CTL3 setting to fix MAC issue
1263 * present on AR9271 1.1
1264 */
1265 REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001);
1266 return;
1267 }
1268
Senthil Balasubramanian8aa15e12008-12-08 19:43:50 +05301269 /*
1270 * Set the RX_ABORT and RX_DIS and clear if off only after
1271 * RXE is set for MAC. This prevents frames with corrupted
1272 * descriptor status.
1273 */
1274 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
1275
1276
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001277 if (!AR_SREV_5416_20_OR_LATER(ah) ||
Sujithf1dc5602008-10-29 10:16:30 +05301278 AR_SREV_9280_10_OR_LATER(ah))
1279 return;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001280 /*
1281 * Disable BB clock gating
1282 * Necessary to avoid issues on AR5416 2.0
1283 */
Sujithf1dc5602008-10-29 10:16:30 +05301284 REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
1285}
1286
Sujithcbe61d82009-02-09 13:27:12 +05301287static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301288 struct ar5416_eeprom_def *pEepData,
Sujithf1dc5602008-10-29 10:16:30 +05301289 u32 reg, u32 value)
1290{
1291 struct base_eep_header *pBase = &(pEepData->baseEepHeader);
1292
Sujithd535a422009-02-09 13:27:06 +05301293 switch (ah->hw_version.devid) {
Sujithf1dc5602008-10-29 10:16:30 +05301294 case AR9280_DEVID_PCI:
1295 if (reg == 0x7894) {
Sujithd8baa932009-03-30 15:28:25 +05301296 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301297 "ini VAL: %x EEPROM: %x\n", value,
1298 (pBase->version & 0xff));
1299
1300 if ((pBase->version & 0xff) > 0x0a) {
Sujithd8baa932009-03-30 15:28:25 +05301301 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301302 "PWDCLKIND: %d\n",
1303 pBase->pwdclkind);
1304 value &= ~AR_AN_TOP2_PWDCLKIND;
1305 value |= AR_AN_TOP2_PWDCLKIND &
1306 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1307 } else {
Sujithd8baa932009-03-30 15:28:25 +05301308 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301309 "PWDCLKIND Earlier Rev\n");
1310 }
1311
Sujithd8baa932009-03-30 15:28:25 +05301312 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujithf1dc5602008-10-29 10:16:30 +05301313 "final ini VAL: %x\n", value);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001314 }
Sujithf1dc5602008-10-29 10:16:30 +05301315 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001316 }
1317
Sujithf1dc5602008-10-29 10:16:30 +05301318 return value;
1319}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001320
Sujithcbe61d82009-02-09 13:27:12 +05301321static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301322 struct ar5416_eeprom_def *pEepData,
1323 u32 reg, u32 value)
1324{
Sujith2660b812009-02-09 13:27:26 +05301325 if (ah->eep_map == EEP_MAP_4KBITS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301326 return value;
1327 else
1328 return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
1329}
1330
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301331static void ath9k_olc_init(struct ath_hw *ah)
1332{
1333 u32 i;
1334
Vivek Natarajandb91f2e2009-08-14 11:27:16 +05301335 if (OLC_FOR_AR9287_10_LATER) {
1336 REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
1337 AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
1338 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
1339 AR9287_AN_TXPC0_TXPCMODE,
1340 AR9287_AN_TXPC0_TXPCMODE_S,
1341 AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
1342 udelay(100);
1343 } else {
1344 for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
1345 ah->originalGain[i] =
1346 MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
1347 AR_PHY_TX_GAIN);
1348 ah->PDADCdelta = 0;
1349 }
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301350}
1351
Bob Copeland3a702e42009-03-30 22:30:29 -04001352static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
1353 struct ath9k_channel *chan)
1354{
1355 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1356
1357 if (IS_CHAN_B(chan))
1358 ctl |= CTL_11B;
1359 else if (IS_CHAN_G(chan))
1360 ctl |= CTL_11G;
1361 else
1362 ctl |= CTL_11A;
1363
1364 return ctl;
1365}
1366
Sujithcbe61d82009-02-09 13:27:12 +05301367static int ath9k_hw_process_ini(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301368 struct ath9k_channel *chan,
1369 enum ath9k_ht_macmode macmode)
1370{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001371 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301372 int i, regWrites = 0;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001373 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301374 u32 modesIndex, freqIndex;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001375
Sujithf1dc5602008-10-29 10:16:30 +05301376 switch (chan->chanmode) {
1377 case CHANNEL_A:
1378 case CHANNEL_A_HT20:
1379 modesIndex = 1;
1380 freqIndex = 1;
1381 break;
1382 case CHANNEL_A_HT40PLUS:
1383 case CHANNEL_A_HT40MINUS:
1384 modesIndex = 2;
1385 freqIndex = 1;
1386 break;
1387 case CHANNEL_G:
1388 case CHANNEL_G_HT20:
1389 case CHANNEL_B:
1390 modesIndex = 4;
1391 freqIndex = 2;
1392 break;
1393 case CHANNEL_G_HT40PLUS:
1394 case CHANNEL_G_HT40MINUS:
1395 modesIndex = 3;
1396 freqIndex = 2;
1397 break;
1398
1399 default:
1400 return -EINVAL;
1401 }
1402
1403 REG_WRITE(ah, AR_PHY(0), 0x00000007);
Sujithf1dc5602008-10-29 10:16:30 +05301404 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
Sujithf74df6f2009-02-09 13:27:24 +05301405 ah->eep_ops->set_addac(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301406
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001407 if (AR_SREV_5416_22_OR_LATER(ah)) {
Sujith2660b812009-02-09 13:27:26 +05301408 REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
Sujithf1dc5602008-10-29 10:16:30 +05301409 } else {
1410 struct ar5416IniArray temp;
1411 u32 addacSize =
Sujith2660b812009-02-09 13:27:26 +05301412 sizeof(u32) * ah->iniAddac.ia_rows *
1413 ah->iniAddac.ia_columns;
Sujithf1dc5602008-10-29 10:16:30 +05301414
Sujith2660b812009-02-09 13:27:26 +05301415 memcpy(ah->addac5416_21,
1416 ah->iniAddac.ia_array, addacSize);
Sujithf1dc5602008-10-29 10:16:30 +05301417
Sujith2660b812009-02-09 13:27:26 +05301418 (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301419
Sujith2660b812009-02-09 13:27:26 +05301420 temp.ia_array = ah->addac5416_21;
1421 temp.ia_columns = ah->iniAddac.ia_columns;
1422 temp.ia_rows = ah->iniAddac.ia_rows;
Sujithf1dc5602008-10-29 10:16:30 +05301423 REG_WRITE_ARRAY(&temp, 1, regWrites);
1424 }
1425
1426 REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
1427
Sujith2660b812009-02-09 13:27:26 +05301428 for (i = 0; i < ah->iniModes.ia_rows; i++) {
1429 u32 reg = INI_RA(&ah->iniModes, i, 0);
1430 u32 val = INI_RA(&ah->iniModes, i, modesIndex);
Sujithf1dc5602008-10-29 10:16:30 +05301431
Sujithf1dc5602008-10-29 10:16:30 +05301432 REG_WRITE(ah, reg, val);
1433
1434 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301435 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301436 udelay(100);
1437 }
1438
1439 DO_DELAY(regWrites);
1440 }
1441
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301442 if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301443 REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301444
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05301445 if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
1446 AR_SREV_9287_10_OR_LATER(ah))
Sujith2660b812009-02-09 13:27:26 +05301447 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
Senthil Balasubramanian9f804202008-11-13 17:58:41 +05301448
Sujith2660b812009-02-09 13:27:26 +05301449 for (i = 0; i < ah->iniCommon.ia_rows; i++) {
1450 u32 reg = INI_RA(&ah->iniCommon, i, 0);
1451 u32 val = INI_RA(&ah->iniCommon, i, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301452
1453 REG_WRITE(ah, reg, val);
1454
1455 if (reg >= 0x7800 && reg < 0x78a0
Sujith2660b812009-02-09 13:27:26 +05301456 && ah->config.analog_shiftreg) {
Sujithf1dc5602008-10-29 10:16:30 +05301457 udelay(100);
1458 }
1459
1460 DO_DELAY(regWrites);
1461 }
1462
1463 ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
1464
1465 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301466 REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
Sujithf1dc5602008-10-29 10:16:30 +05301467 regWrites);
1468 }
1469
1470 ath9k_hw_override_ini(ah, chan);
1471 ath9k_hw_set_regs(ah, chan, macmode);
1472 ath9k_hw_init_chain_masks(ah);
1473
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301474 if (OLC_FOR_AR9280_20_LATER)
1475 ath9k_olc_init(ah);
1476
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001477 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001478 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001479 channel->max_antenna_gain * 2,
1480 channel->max_power * 2,
1481 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001482 (u32) regulatory->power_limit));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001483
Sujithf1dc5602008-10-29 10:16:30 +05301484 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
Sujithd8baa932009-03-30 15:28:25 +05301485 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301486 "ar5416SetRfRegs failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001487 return -EIO;
1488 }
1489
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001490 return 0;
1491}
1492
Sujithf1dc5602008-10-29 10:16:30 +05301493/****************************************/
1494/* Reset and Channel Switching Routines */
1495/****************************************/
1496
Sujithcbe61d82009-02-09 13:27:12 +05301497static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301498{
1499 u32 rfMode = 0;
1500
1501 if (chan == NULL)
1502 return;
1503
1504 rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
1505 ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
1506
1507 if (!AR_SREV_9280_10_OR_LATER(ah))
1508 rfMode |= (IS_CHAN_5GHZ(chan)) ?
1509 AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
1510
1511 if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
1512 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
1513
1514 REG_WRITE(ah, AR_PHY_MODE, rfMode);
1515}
1516
Sujithcbe61d82009-02-09 13:27:12 +05301517static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301518{
1519 REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
1520}
1521
Sujithcbe61d82009-02-09 13:27:12 +05301522static inline void ath9k_hw_set_dma(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301523{
1524 u32 regval;
1525
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001526 /*
1527 * set AHB_MODE not to do cacheline prefetches
1528 */
Sujithf1dc5602008-10-29 10:16:30 +05301529 regval = REG_READ(ah, AR_AHB_MODE);
1530 REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
1531
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001532 /*
1533 * let mac dma reads be in 128 byte chunks
1534 */
Sujithf1dc5602008-10-29 10:16:30 +05301535 regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
1536 REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
1537
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001538 /*
1539 * Restore TX Trigger Level to its pre-reset value.
1540 * The initial value depends on whether aggregation is enabled, and is
1541 * adjusted whenever underruns are detected.
1542 */
Sujith2660b812009-02-09 13:27:26 +05301543 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
Sujithf1dc5602008-10-29 10:16:30 +05301544
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001545 /*
1546 * let mac dma writes be in 128 byte chunks
1547 */
Sujithf1dc5602008-10-29 10:16:30 +05301548 regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
1549 REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
1550
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001551 /*
1552 * Setup receive FIFO threshold to hold off TX activities
1553 */
Sujithf1dc5602008-10-29 10:16:30 +05301554 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1555
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001556 /*
1557 * reduce the number of usable entries in PCU TXBUF to avoid
1558 * wrap around issues.
1559 */
Sujithf1dc5602008-10-29 10:16:30 +05301560 if (AR_SREV_9285(ah)) {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001561 /* For AR9285 the number of Fifos are reduced to half.
1562 * So set the usable tx buf size also to half to
1563 * avoid data/delimiter underruns
1564 */
Sujithf1dc5602008-10-29 10:16:30 +05301565 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1566 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04001567 } else if (!AR_SREV_9271(ah)) {
Sujithf1dc5602008-10-29 10:16:30 +05301568 REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
1569 AR_PCU_TXBUF_CTRL_USABLE_SIZE);
1570 }
1571}
1572
Sujithcbe61d82009-02-09 13:27:12 +05301573static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
Sujithf1dc5602008-10-29 10:16:30 +05301574{
1575 u32 val;
1576
1577 val = REG_READ(ah, AR_STA_ID1);
1578 val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
1579 switch (opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08001580 case NL80211_IFTYPE_AP:
Sujithf1dc5602008-10-29 10:16:30 +05301581 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
1582 | AR_STA_ID1_KSRCH_MODE);
1583 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1584 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001585 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04001586 case NL80211_IFTYPE_MESH_POINT:
Sujithf1dc5602008-10-29 10:16:30 +05301587 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
1588 | AR_STA_ID1_KSRCH_MODE);
1589 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1590 break;
Colin McCabed97809d2008-12-01 13:38:55 -08001591 case NL80211_IFTYPE_STATION:
1592 case NL80211_IFTYPE_MONITOR:
Sujithf1dc5602008-10-29 10:16:30 +05301593 REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
1594 break;
1595 }
1596}
1597
Sujithcbe61d82009-02-09 13:27:12 +05301598static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001599 u32 coef_scaled,
1600 u32 *coef_mantissa,
1601 u32 *coef_exponent)
1602{
1603 u32 coef_exp, coef_man;
1604
1605 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1606 if ((coef_scaled >> coef_exp) & 0x1)
1607 break;
1608
1609 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1610
1611 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1612
1613 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1614 *coef_exponent = coef_exp - 16;
1615}
1616
Sujithcbe61d82009-02-09 13:27:12 +05301617static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301618 struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001619{
1620 u32 coef_scaled, ds_coef_exp, ds_coef_man;
1621 u32 clockMhzScaled = 0x64000000;
1622 struct chan_centers centers;
1623
1624 if (IS_CHAN_HALF_RATE(chan))
1625 clockMhzScaled = clockMhzScaled >> 1;
1626 else if (IS_CHAN_QUARTER_RATE(chan))
1627 clockMhzScaled = clockMhzScaled >> 2;
1628
1629 ath9k_hw_get_channel_centers(ah, chan, &centers);
1630 coef_scaled = clockMhzScaled / centers.synth_center;
1631
1632 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1633 &ds_coef_exp);
1634
1635 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1636 AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
1637 REG_RMW_FIELD(ah, AR_PHY_TIMING3,
1638 AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
1639
1640 coef_scaled = (9 * coef_scaled) / 10;
1641
1642 ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
1643 &ds_coef_exp);
1644
1645 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1646 AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
1647 REG_RMW_FIELD(ah, AR_PHY_HALFGI,
1648 AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
1649}
1650
Sujithcbe61d82009-02-09 13:27:12 +05301651static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
Sujithf1dc5602008-10-29 10:16:30 +05301652{
1653 u32 rst_flags;
1654 u32 tmpReg;
1655
Sujith70768492009-02-16 13:23:12 +05301656 if (AR_SREV_9100(ah)) {
1657 u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
1658 val &= ~AR_RTC_DERIVED_CLK_PERIOD;
1659 val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
1660 REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
1661 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1662 }
1663
Sujithf1dc5602008-10-29 10:16:30 +05301664 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1665 AR_RTC_FORCE_WAKE_ON_INT);
1666
1667 if (AR_SREV_9100(ah)) {
1668 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1669 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1670 } else {
1671 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1672 if (tmpReg &
1673 (AR_INTR_SYNC_LOCAL_TIMEOUT |
1674 AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
1675 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1676 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1677 } else {
1678 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1679 }
1680
1681 rst_flags = AR_RTC_RC_MAC_WARM;
1682 if (type == ATH9K_RESET_COLD)
1683 rst_flags |= AR_RTC_RC_MAC_COLD;
1684 }
1685
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001686 REG_WRITE(ah, AR_RTC_RC, rst_flags);
Sujithf1dc5602008-10-29 10:16:30 +05301687 udelay(50);
1688
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001689 REG_WRITE(ah, AR_RTC_RC, 0);
Sujith0caa7b12009-02-16 13:23:20 +05301690 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
Sujithf1dc5602008-10-29 10:16:30 +05301691 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05301692 "RTC stuck in MAC reset\n");
Sujithf1dc5602008-10-29 10:16:30 +05301693 return false;
1694 }
1695
1696 if (!AR_SREV_9100(ah))
1697 REG_WRITE(ah, AR_RC, 0);
1698
1699 ath9k_hw_init_pll(ah, NULL);
1700
1701 if (AR_SREV_9100(ah))
1702 udelay(50);
1703
1704 return true;
1705}
1706
Sujithcbe61d82009-02-09 13:27:12 +05301707static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301708{
1709 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1710 AR_RTC_FORCE_WAKE_ON_INT);
1711
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301712 if (!AR_SREV_9100(ah))
1713 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1714
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001715 REG_WRITE(ah, AR_RTC_RESET, 0);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301716 udelay(2);
Vasanthakumar Thiagarajan1c29ce62009-08-31 17:48:36 +05301717
1718 if (!AR_SREV_9100(ah))
1719 REG_WRITE(ah, AR_RC, 0);
1720
Gabor Juhosd03a66c2009-01-14 20:17:09 +01001721 REG_WRITE(ah, AR_RTC_RESET, 1);
Sujithf1dc5602008-10-29 10:16:30 +05301722
1723 if (!ath9k_hw_wait(ah,
1724 AR_RTC_STATUS,
1725 AR_RTC_STATUS_M,
Sujith0caa7b12009-02-16 13:23:20 +05301726 AR_RTC_STATUS_ON,
1727 AH_WAIT_TIMEOUT)) {
Sujith04bd4632008-11-28 22:18:05 +05301728 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "RTC not waking up\n");
Sujithf1dc5602008-10-29 10:16:30 +05301729 return false;
1730 }
1731
1732 ath9k_hw_read_revisions(ah);
1733
1734 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1735}
1736
Sujithcbe61d82009-02-09 13:27:12 +05301737static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
Sujithf1dc5602008-10-29 10:16:30 +05301738{
1739 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1740 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1741
1742 switch (type) {
1743 case ATH9K_RESET_POWER_ON:
1744 return ath9k_hw_set_reset_power_on(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301745 case ATH9K_RESET_WARM:
1746 case ATH9K_RESET_COLD:
1747 return ath9k_hw_set_reset(ah, type);
Sujithf1dc5602008-10-29 10:16:30 +05301748 default:
1749 return false;
1750 }
1751}
1752
Sujithcbe61d82009-02-09 13:27:12 +05301753static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan,
Sujithf1dc5602008-10-29 10:16:30 +05301754 enum ath9k_ht_macmode macmode)
1755{
1756 u32 phymode;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301757 u32 enableDacFifo = 0;
Sujithf1dc5602008-10-29 10:16:30 +05301758
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301759 if (AR_SREV_9285_10_OR_LATER(ah))
1760 enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
1761 AR_PHY_FC_ENABLE_DAC_FIFO);
1762
Sujithf1dc5602008-10-29 10:16:30 +05301763 phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301764 | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
Sujithf1dc5602008-10-29 10:16:30 +05301765
1766 if (IS_CHAN_HT40(chan)) {
1767 phymode |= AR_PHY_FC_DYN2040_EN;
1768
1769 if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
1770 (chan->chanmode == CHANNEL_G_HT40PLUS))
1771 phymode |= AR_PHY_FC_DYN2040_PRI_CH;
1772
Sujith2660b812009-02-09 13:27:26 +05301773 if (ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_25)
Sujithf1dc5602008-10-29 10:16:30 +05301774 phymode |= AR_PHY_FC_DYN2040_EXT_CH;
1775 }
1776 REG_WRITE(ah, AR_PHY_TURBO, phymode);
1777
1778 ath9k_hw_set11nmac2040(ah, macmode);
1779
1780 REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
1781 REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
1782}
1783
Sujithcbe61d82009-02-09 13:27:12 +05301784static bool ath9k_hw_chip_reset(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301785 struct ath9k_channel *chan)
1786{
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301787 if (OLC_FOR_AR9280_20_LATER) {
1788 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
1789 return false;
1790 } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
Sujithf1dc5602008-10-29 10:16:30 +05301791 return false;
1792
1793 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1794 return false;
1795
Sujith2660b812009-02-09 13:27:26 +05301796 ah->chip_fullsleep = false;
Sujithf1dc5602008-10-29 10:16:30 +05301797 ath9k_hw_init_pll(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301798 ath9k_hw_set_rfmode(ah, chan);
1799
1800 return true;
1801}
1802
Sujithcbe61d82009-02-09 13:27:12 +05301803static bool ath9k_hw_channel_change(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301804 struct ath9k_channel *chan,
1805 enum ath9k_ht_macmode macmode)
1806{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001807 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001808 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05301809 u32 synthDelay, qnum;
1810
1811 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1812 if (ath9k_hw_numtxpending(ah, qnum)) {
1813 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
Sujith04bd4632008-11-28 22:18:05 +05301814 "Transmit frames pending on queue %d\n", qnum);
Sujithf1dc5602008-10-29 10:16:30 +05301815 return false;
1816 }
1817 }
1818
1819 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1820 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
Sujith0caa7b12009-02-16 13:23:20 +05301821 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
Sujithd8baa932009-03-30 15:28:25 +05301822 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301823 "Could not kill baseband RX\n");
Sujithf1dc5602008-10-29 10:16:30 +05301824 return false;
1825 }
1826
1827 ath9k_hw_set_regs(ah, chan, macmode);
1828
1829 if (AR_SREV_9280_10_OR_LATER(ah)) {
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001830 ath9k_hw_ar9280_set_channel(ah, chan);
Sujithf1dc5602008-10-29 10:16:30 +05301831 } else {
1832 if (!(ath9k_hw_set_channel(ah, chan))) {
Sujithd8baa932009-03-30 15:28:25 +05301833 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
1834 "Failed to set channel\n");
Sujithf1dc5602008-10-29 10:16:30 +05301835 return false;
1836 }
1837 }
1838
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07001839 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001840 ath9k_regd_get_ctl(regulatory, chan),
Sujithf74df6f2009-02-09 13:27:24 +05301841 channel->max_antenna_gain * 2,
1842 channel->max_power * 2,
1843 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001844 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05301845
1846 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
Sujith788a3d62008-11-18 09:09:54 +05301847 if (IS_CHAN_B(chan))
Sujithf1dc5602008-10-29 10:16:30 +05301848 synthDelay = (4 * synthDelay) / 22;
1849 else
1850 synthDelay /= 10;
1851
1852 udelay(synthDelay + BASE_ACTIVATE_DELAY);
1853
1854 REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
1855
1856 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
1857 ath9k_hw_set_delta_slope(ah, chan);
1858
1859 if (AR_SREV_9280_10_OR_LATER(ah))
1860 ath9k_hw_9280_spur_mitigate(ah, chan);
1861 else
1862 ath9k_hw_spur_mitigate(ah, chan);
1863
1864 if (!chan->oneTimeCalsDone)
1865 chan->oneTimeCalsDone = true;
1866
1867 return true;
1868}
1869
Sujithcbe61d82009-02-09 13:27:12 +05301870static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001871{
1872 int bb_spur = AR_NO_SPUR;
1873 int freq;
1874 int bin, cur_bin;
1875 int bb_spur_off, spur_subchannel_sd;
1876 int spur_freq_sd;
1877 int spur_delta_phase;
1878 int denominator;
1879 int upper, lower, cur_vit_mask;
1880 int tmp, newVal;
1881 int i;
1882 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
1883 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
1884 };
1885 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
1886 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
1887 };
1888 int inc[4] = { 0, 100, 0, 0 };
1889 struct chan_centers centers;
1890
1891 int8_t mask_m[123];
1892 int8_t mask_p[123];
1893 int8_t mask_amt;
1894 int tmp_mask;
1895 int cur_bb_spur;
1896 bool is2GHz = IS_CHAN_2GHZ(chan);
1897
1898 memset(&mask_m, 0, sizeof(int8_t) * 123);
1899 memset(&mask_p, 0, sizeof(int8_t) * 123);
1900
1901 ath9k_hw_get_channel_centers(ah, chan, &centers);
1902 freq = centers.synth_center;
1903
Sujith2660b812009-02-09 13:27:26 +05301904 ah->config.spurmode = SPUR_ENABLE_EEPROM;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001905 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05301906 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001907
1908 if (is2GHz)
1909 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
1910 else
1911 cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
1912
1913 if (AR_NO_SPUR == cur_bb_spur)
1914 break;
1915 cur_bb_spur = cur_bb_spur - freq;
1916
1917 if (IS_CHAN_HT40(chan)) {
1918 if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
1919 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
1920 bb_spur = cur_bb_spur;
1921 break;
1922 }
1923 } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
1924 (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
1925 bb_spur = cur_bb_spur;
1926 break;
1927 }
1928 }
1929
1930 if (AR_NO_SPUR == bb_spur) {
1931 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1932 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1933 return;
1934 } else {
1935 REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
1936 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
1937 }
1938
1939 bin = bb_spur * 320;
1940
1941 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
1942
1943 newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
1944 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
1945 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
1946 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
1947 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
1948
1949 newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
1950 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
1951 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
1952 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
1953 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
1954 REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
1955
1956 if (IS_CHAN_HT40(chan)) {
1957 if (bb_spur < 0) {
1958 spur_subchannel_sd = 1;
1959 bb_spur_off = bb_spur + 10;
1960 } else {
1961 spur_subchannel_sd = 0;
1962 bb_spur_off = bb_spur - 10;
1963 }
1964 } else {
1965 spur_subchannel_sd = 0;
1966 bb_spur_off = bb_spur;
1967 }
1968
1969 if (IS_CHAN_HT40(chan))
1970 spur_delta_phase =
1971 ((bb_spur * 262144) /
1972 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1973 else
1974 spur_delta_phase =
1975 ((bb_spur * 524288) /
1976 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
1977
1978 denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
1979 spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
1980
1981 newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
1982 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
1983 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
1984 REG_WRITE(ah, AR_PHY_TIMING11, newVal);
1985
1986 newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
1987 REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
1988
1989 cur_bin = -6000;
1990 upper = bin + 100;
1991 lower = bin - 100;
1992
1993 for (i = 0; i < 4; i++) {
1994 int pilot_mask = 0;
1995 int chan_mask = 0;
1996 int bp = 0;
1997 for (bp = 0; bp < 30; bp++) {
1998 if ((cur_bin > lower) && (cur_bin < upper)) {
1999 pilot_mask = pilot_mask | 0x1 << bp;
2000 chan_mask = chan_mask | 0x1 << bp;
2001 }
2002 cur_bin += 100;
2003 }
2004 cur_bin += inc[i];
2005 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2006 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2007 }
2008
2009 cur_vit_mask = 6100;
2010 upper = bin + 120;
2011 lower = bin - 120;
2012
2013 for (i = 0; i < 123; i++) {
2014 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002015
2016 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002017 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunkb08cbcd2008-08-05 22:06:51 +03002018
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002019 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002020 mask_amt = 1;
2021 else
2022 mask_amt = 0;
2023 if (cur_vit_mask < 0)
2024 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2025 else
2026 mask_p[cur_vit_mask / 100] = mask_amt;
2027 }
2028 cur_vit_mask -= 100;
2029 }
2030
2031 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2032 | (mask_m[48] << 26) | (mask_m[49] << 24)
2033 | (mask_m[50] << 22) | (mask_m[51] << 20)
2034 | (mask_m[52] << 18) | (mask_m[53] << 16)
2035 | (mask_m[54] << 14) | (mask_m[55] << 12)
2036 | (mask_m[56] << 10) | (mask_m[57] << 8)
2037 | (mask_m[58] << 6) | (mask_m[59] << 4)
2038 | (mask_m[60] << 2) | (mask_m[61] << 0);
2039 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2040 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2041
2042 tmp_mask = (mask_m[31] << 28)
2043 | (mask_m[32] << 26) | (mask_m[33] << 24)
2044 | (mask_m[34] << 22) | (mask_m[35] << 20)
2045 | (mask_m[36] << 18) | (mask_m[37] << 16)
2046 | (mask_m[48] << 14) | (mask_m[39] << 12)
2047 | (mask_m[40] << 10) | (mask_m[41] << 8)
2048 | (mask_m[42] << 6) | (mask_m[43] << 4)
2049 | (mask_m[44] << 2) | (mask_m[45] << 0);
2050 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2051 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2052
2053 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2054 | (mask_m[18] << 26) | (mask_m[18] << 24)
2055 | (mask_m[20] << 22) | (mask_m[20] << 20)
2056 | (mask_m[22] << 18) | (mask_m[22] << 16)
2057 | (mask_m[24] << 14) | (mask_m[24] << 12)
2058 | (mask_m[25] << 10) | (mask_m[26] << 8)
2059 | (mask_m[27] << 6) | (mask_m[28] << 4)
2060 | (mask_m[29] << 2) | (mask_m[30] << 0);
2061 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2062 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2063
2064 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2065 | (mask_m[2] << 26) | (mask_m[3] << 24)
2066 | (mask_m[4] << 22) | (mask_m[5] << 20)
2067 | (mask_m[6] << 18) | (mask_m[7] << 16)
2068 | (mask_m[8] << 14) | (mask_m[9] << 12)
2069 | (mask_m[10] << 10) | (mask_m[11] << 8)
2070 | (mask_m[12] << 6) | (mask_m[13] << 4)
2071 | (mask_m[14] << 2) | (mask_m[15] << 0);
2072 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2073 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2074
2075 tmp_mask = (mask_p[15] << 28)
2076 | (mask_p[14] << 26) | (mask_p[13] << 24)
2077 | (mask_p[12] << 22) | (mask_p[11] << 20)
2078 | (mask_p[10] << 18) | (mask_p[9] << 16)
2079 | (mask_p[8] << 14) | (mask_p[7] << 12)
2080 | (mask_p[6] << 10) | (mask_p[5] << 8)
2081 | (mask_p[4] << 6) | (mask_p[3] << 4)
2082 | (mask_p[2] << 2) | (mask_p[1] << 0);
2083 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2084 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2085
2086 tmp_mask = (mask_p[30] << 28)
2087 | (mask_p[29] << 26) | (mask_p[28] << 24)
2088 | (mask_p[27] << 22) | (mask_p[26] << 20)
2089 | (mask_p[25] << 18) | (mask_p[24] << 16)
2090 | (mask_p[23] << 14) | (mask_p[22] << 12)
2091 | (mask_p[21] << 10) | (mask_p[20] << 8)
2092 | (mask_p[19] << 6) | (mask_p[18] << 4)
2093 | (mask_p[17] << 2) | (mask_p[16] << 0);
2094 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2095 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2096
2097 tmp_mask = (mask_p[45] << 28)
2098 | (mask_p[44] << 26) | (mask_p[43] << 24)
2099 | (mask_p[42] << 22) | (mask_p[41] << 20)
2100 | (mask_p[40] << 18) | (mask_p[39] << 16)
2101 | (mask_p[38] << 14) | (mask_p[37] << 12)
2102 | (mask_p[36] << 10) | (mask_p[35] << 8)
2103 | (mask_p[34] << 6) | (mask_p[33] << 4)
2104 | (mask_p[32] << 2) | (mask_p[31] << 0);
2105 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2106 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2107
2108 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2109 | (mask_p[59] << 26) | (mask_p[58] << 24)
2110 | (mask_p[57] << 22) | (mask_p[56] << 20)
2111 | (mask_p[55] << 18) | (mask_p[54] << 16)
2112 | (mask_p[53] << 14) | (mask_p[52] << 12)
2113 | (mask_p[51] << 10) | (mask_p[50] << 8)
2114 | (mask_p[49] << 6) | (mask_p[48] << 4)
2115 | (mask_p[47] << 2) | (mask_p[46] << 0);
2116 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2117 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2118}
2119
Sujithcbe61d82009-02-09 13:27:12 +05302120static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002121{
2122 int bb_spur = AR_NO_SPUR;
2123 int bin, cur_bin;
2124 int spur_freq_sd;
2125 int spur_delta_phase;
2126 int denominator;
2127 int upper, lower, cur_vit_mask;
2128 int tmp, new;
2129 int i;
2130 int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
2131 AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
2132 };
2133 int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
2134 AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
2135 };
2136 int inc[4] = { 0, 100, 0, 0 };
2137
2138 int8_t mask_m[123];
2139 int8_t mask_p[123];
2140 int8_t mask_amt;
2141 int tmp_mask;
2142 int cur_bb_spur;
2143 bool is2GHz = IS_CHAN_2GHZ(chan);
2144
2145 memset(&mask_m, 0, sizeof(int8_t) * 123);
2146 memset(&mask_p, 0, sizeof(int8_t) * 123);
2147
2148 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithf74df6f2009-02-09 13:27:24 +05302149 cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002150 if (AR_NO_SPUR == cur_bb_spur)
2151 break;
2152 cur_bb_spur = cur_bb_spur - (chan->channel * 10);
2153 if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
2154 bb_spur = cur_bb_spur;
2155 break;
2156 }
2157 }
2158
2159 if (AR_NO_SPUR == bb_spur)
2160 return;
2161
2162 bin = bb_spur * 32;
2163
2164 tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
2165 new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
2166 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
2167 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
2168 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
2169
2170 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
2171
2172 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
2173 AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
2174 AR_PHY_SPUR_REG_MASK_RATE_SELECT |
2175 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
2176 SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
2177 REG_WRITE(ah, AR_PHY_SPUR_REG, new);
2178
2179 spur_delta_phase = ((bb_spur * 524288) / 100) &
2180 AR_PHY_TIMING11_SPUR_DELTA_PHASE;
2181
2182 denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
2183 spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
2184
2185 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
2186 SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
2187 SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
2188 REG_WRITE(ah, AR_PHY_TIMING11, new);
2189
2190 cur_bin = -6000;
2191 upper = bin + 100;
2192 lower = bin - 100;
2193
2194 for (i = 0; i < 4; i++) {
2195 int pilot_mask = 0;
2196 int chan_mask = 0;
2197 int bp = 0;
2198 for (bp = 0; bp < 30; bp++) {
2199 if ((cur_bin > lower) && (cur_bin < upper)) {
2200 pilot_mask = pilot_mask | 0x1 << bp;
2201 chan_mask = chan_mask | 0x1 << bp;
2202 }
2203 cur_bin += 100;
2204 }
2205 cur_bin += inc[i];
2206 REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
2207 REG_WRITE(ah, chan_mask_reg[i], chan_mask);
2208 }
2209
2210 cur_vit_mask = 6100;
2211 upper = bin + 120;
2212 lower = bin - 120;
2213
2214 for (i = 0; i < 123; i++) {
2215 if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002216
2217 /* workaround for gcc bug #37014 */
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002218 volatile int tmp_v = abs(cur_vit_mask - bin);
Adrian Bunk88b9e2b2008-08-05 22:06:51 +03002219
Luis R. Rodrigueza085ff72008-12-23 15:58:51 -08002220 if (tmp_v < 75)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002221 mask_amt = 1;
2222 else
2223 mask_amt = 0;
2224 if (cur_vit_mask < 0)
2225 mask_m[abs(cur_vit_mask / 100)] = mask_amt;
2226 else
2227 mask_p[cur_vit_mask / 100] = mask_amt;
2228 }
2229 cur_vit_mask -= 100;
2230 }
2231
2232 tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
2233 | (mask_m[48] << 26) | (mask_m[49] << 24)
2234 | (mask_m[50] << 22) | (mask_m[51] << 20)
2235 | (mask_m[52] << 18) | (mask_m[53] << 16)
2236 | (mask_m[54] << 14) | (mask_m[55] << 12)
2237 | (mask_m[56] << 10) | (mask_m[57] << 8)
2238 | (mask_m[58] << 6) | (mask_m[59] << 4)
2239 | (mask_m[60] << 2) | (mask_m[61] << 0);
2240 REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
2241 REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
2242
2243 tmp_mask = (mask_m[31] << 28)
2244 | (mask_m[32] << 26) | (mask_m[33] << 24)
2245 | (mask_m[34] << 22) | (mask_m[35] << 20)
2246 | (mask_m[36] << 18) | (mask_m[37] << 16)
2247 | (mask_m[48] << 14) | (mask_m[39] << 12)
2248 | (mask_m[40] << 10) | (mask_m[41] << 8)
2249 | (mask_m[42] << 6) | (mask_m[43] << 4)
2250 | (mask_m[44] << 2) | (mask_m[45] << 0);
2251 REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
2252 REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
2253
2254 tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
2255 | (mask_m[18] << 26) | (mask_m[18] << 24)
2256 | (mask_m[20] << 22) | (mask_m[20] << 20)
2257 | (mask_m[22] << 18) | (mask_m[22] << 16)
2258 | (mask_m[24] << 14) | (mask_m[24] << 12)
2259 | (mask_m[25] << 10) | (mask_m[26] << 8)
2260 | (mask_m[27] << 6) | (mask_m[28] << 4)
2261 | (mask_m[29] << 2) | (mask_m[30] << 0);
2262 REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
2263 REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
2264
2265 tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
2266 | (mask_m[2] << 26) | (mask_m[3] << 24)
2267 | (mask_m[4] << 22) | (mask_m[5] << 20)
2268 | (mask_m[6] << 18) | (mask_m[7] << 16)
2269 | (mask_m[8] << 14) | (mask_m[9] << 12)
2270 | (mask_m[10] << 10) | (mask_m[11] << 8)
2271 | (mask_m[12] << 6) | (mask_m[13] << 4)
2272 | (mask_m[14] << 2) | (mask_m[15] << 0);
2273 REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
2274 REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
2275
2276 tmp_mask = (mask_p[15] << 28)
2277 | (mask_p[14] << 26) | (mask_p[13] << 24)
2278 | (mask_p[12] << 22) | (mask_p[11] << 20)
2279 | (mask_p[10] << 18) | (mask_p[9] << 16)
2280 | (mask_p[8] << 14) | (mask_p[7] << 12)
2281 | (mask_p[6] << 10) | (mask_p[5] << 8)
2282 | (mask_p[4] << 6) | (mask_p[3] << 4)
2283 | (mask_p[2] << 2) | (mask_p[1] << 0);
2284 REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
2285 REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
2286
2287 tmp_mask = (mask_p[30] << 28)
2288 | (mask_p[29] << 26) | (mask_p[28] << 24)
2289 | (mask_p[27] << 22) | (mask_p[26] << 20)
2290 | (mask_p[25] << 18) | (mask_p[24] << 16)
2291 | (mask_p[23] << 14) | (mask_p[22] << 12)
2292 | (mask_p[21] << 10) | (mask_p[20] << 8)
2293 | (mask_p[19] << 6) | (mask_p[18] << 4)
2294 | (mask_p[17] << 2) | (mask_p[16] << 0);
2295 REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
2296 REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
2297
2298 tmp_mask = (mask_p[45] << 28)
2299 | (mask_p[44] << 26) | (mask_p[43] << 24)
2300 | (mask_p[42] << 22) | (mask_p[41] << 20)
2301 | (mask_p[40] << 18) | (mask_p[39] << 16)
2302 | (mask_p[38] << 14) | (mask_p[37] << 12)
2303 | (mask_p[36] << 10) | (mask_p[35] << 8)
2304 | (mask_p[34] << 6) | (mask_p[33] << 4)
2305 | (mask_p[32] << 2) | (mask_p[31] << 0);
2306 REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
2307 REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
2308
2309 tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
2310 | (mask_p[59] << 26) | (mask_p[58] << 24)
2311 | (mask_p[57] << 22) | (mask_p[56] << 20)
2312 | (mask_p[55] << 18) | (mask_p[54] << 16)
2313 | (mask_p[53] << 14) | (mask_p[52] << 12)
2314 | (mask_p[51] << 10) | (mask_p[50] << 8)
2315 | (mask_p[49] << 6) | (mask_p[48] << 4)
2316 | (mask_p[47] << 2) | (mask_p[46] << 0);
2317 REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
2318 REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
2319}
2320
Johannes Berg3b319aa2009-06-13 14:50:26 +05302321static void ath9k_enable_rfkill(struct ath_hw *ah)
2322{
2323 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
2324 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
2325
2326 REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
2327 AR_GPIO_INPUT_MUX2_RFSILENT);
2328
2329 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
2330 REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
2331}
2332
Sujithcbe61d82009-02-09 13:27:12 +05302333int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002334 bool bChannelChange)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002335{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002336 u32 saveLedState;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002337 struct ath_softc *sc = ah->ah_sc;
Sujith2660b812009-02-09 13:27:26 +05302338 struct ath9k_channel *curchan = ah->curchan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002339 u32 saveDefAntenna;
2340 u32 macStaId1;
Sujith46fe7822009-09-17 09:25:25 +05302341 u64 tsf = 0;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002342 int i, rx_chainmask, r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002343
Sujith2660b812009-02-09 13:27:26 +05302344 ah->extprotspacing = sc->ht_extprotspacing;
2345 ah->txchainmask = sc->tx_chainmask;
2346 ah->rxchainmask = sc->rx_chainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002347
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002348 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
2349 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002350
2351 if (curchan)
2352 ath9k_hw_getnf(ah, curchan);
2353
2354 if (bChannelChange &&
Sujith2660b812009-02-09 13:27:26 +05302355 (ah->chip_fullsleep != true) &&
2356 (ah->curchan != NULL) &&
2357 (chan->channel != ah->curchan->channel) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002358 ((chan->channelFlags & CHANNEL_ALL) ==
Sujith2660b812009-02-09 13:27:26 +05302359 (ah->curchan->channelFlags & CHANNEL_ALL)) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002360 (!AR_SREV_9280(ah) || (!IS_CHAN_A_5MHZ_SPACED(chan) &&
Sujith2660b812009-02-09 13:27:26 +05302361 !IS_CHAN_A_5MHZ_SPACED(ah->curchan)))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002362
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002363 if (ath9k_hw_channel_change(ah, chan, sc->tx_chan_width)) {
Sujith2660b812009-02-09 13:27:26 +05302364 ath9k_hw_loadnf(ah, ah->curchan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002365 ath9k_hw_start_nfcal(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002366 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002367 }
2368 }
2369
2370 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
2371 if (saveDefAntenna == 0)
2372 saveDefAntenna = 1;
2373
2374 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
2375
Sujith46fe7822009-09-17 09:25:25 +05302376 /* For chips on which RTC reset is done, save TSF before it gets cleared */
2377 if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2378 tsf = ath9k_hw_gettsf64(ah);
2379
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002380 saveLedState = REG_READ(ah, AR_CFG_LED) &
2381 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
2382 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
2383
2384 ath9k_hw_mark_phy_inactive(ah);
2385
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002386 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2387 REG_WRITE(ah,
2388 AR9271_RESET_POWER_DOWN_CONTROL,
2389 AR9271_RADIO_RF_RST);
2390 udelay(50);
2391 }
2392
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002393 if (!ath9k_hw_chip_reset(ah, chan)) {
Sujithd8baa932009-03-30 15:28:25 +05302394 DPRINTF(ah->ah_sc, ATH_DBG_FATAL, "Chip reset failed\n");
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002395 return -EINVAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002396 }
2397
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002398 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
2399 ah->htc_reset_init = false;
2400 REG_WRITE(ah,
2401 AR9271_RESET_POWER_DOWN_CONTROL,
2402 AR9271_GATE_MAC_CTL);
2403 udelay(50);
2404 }
2405
Sujith46fe7822009-09-17 09:25:25 +05302406 /* Restore TSF */
2407 if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
2408 ath9k_hw_settsf64(ah, tsf);
2409
Vasanthakumar Thiagarajan369391d2009-01-21 19:24:13 +05302410 if (AR_SREV_9280_10_OR_LATER(ah))
2411 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002412
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302413 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302414 /* Enable ASYNC FIFO */
2415 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2416 AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
2417 REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
2418 REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2419 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2420 REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
2421 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
2422 }
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002423 r = ath9k_hw_process_ini(ah, chan, sc->tx_chan_width);
2424 if (r)
2425 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002426
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002427 /* Setup MFP options for CCMP */
2428 if (AR_SREV_9280_20_OR_LATER(ah)) {
2429 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2430 * frames when constructing CCMP AAD. */
2431 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
2432 0xc7ff);
2433 ah->sw_mgmt_crypto = false;
2434 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
2435 /* Disable hardware crypto for management frames */
2436 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
2437 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
2438 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2439 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
2440 ah->sw_mgmt_crypto = true;
2441 } else
2442 ah->sw_mgmt_crypto = true;
2443
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002444 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
2445 ath9k_hw_set_delta_slope(ah, chan);
2446
2447 if (AR_SREV_9280_10_OR_LATER(ah))
2448 ath9k_hw_9280_spur_mitigate(ah, chan);
2449 else
2450 ath9k_hw_spur_mitigate(ah, chan);
2451
Sujithd6509152009-03-13 08:56:05 +05302452 ah->eep_ops->set_board_values(ah, chan);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002453
2454 ath9k_hw_decrease_chain_power(ah, chan);
2455
Sujithba52da52009-02-09 13:27:10 +05302456 REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(ah->macaddr));
2457 REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(ah->macaddr + 4)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002458 | macStaId1
2459 | AR_STA_ID1_RTS_USE_DEF
Sujith2660b812009-02-09 13:27:26 +05302460 | (ah->config.
Sujith60b67f52008-08-07 10:52:38 +05302461 ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
Sujith2660b812009-02-09 13:27:26 +05302462 | ah->sta_id1_defaults);
2463 ath9k_hw_set_operating_mode(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002464
Sujithba52da52009-02-09 13:27:10 +05302465 REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(sc->bssidmask));
2466 REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(sc->bssidmask + 4));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002467
2468 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
2469
Sujithba52da52009-02-09 13:27:10 +05302470 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(sc->curbssid));
2471 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(sc->curbssid + 4) |
2472 ((sc->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002473
2474 REG_WRITE(ah, AR_ISR, ~0);
2475
2476 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
2477
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07002478 if (AR_SREV_9280_10_OR_LATER(ah))
2479 ath9k_hw_ar9280_set_channel(ah, chan);
2480 else
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002481 if (!(ath9k_hw_set_channel(ah, chan)))
2482 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002483
2484 for (i = 0; i < AR_NUM_DCU; i++)
2485 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
2486
Sujith2660b812009-02-09 13:27:26 +05302487 ah->intr_txqs = 0;
2488 for (i = 0; i < ah->caps.total_queues; i++)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002489 ath9k_hw_resettxqueue(ah, i);
2490
Sujith2660b812009-02-09 13:27:26 +05302491 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002492 ath9k_hw_init_qos(ah);
2493
Sujith2660b812009-02-09 13:27:26 +05302494 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302495 ath9k_enable_rfkill(ah);
Johannes Berg3b319aa2009-06-13 14:50:26 +05302496
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002497 ath9k_hw_init_user_settings(ah);
2498
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302499 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302500 REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
2501 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
2502 REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
2503 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
2504 REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
2505 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
2506
2507 REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
2508 REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
2509
2510 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
2511 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
2512 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
2513 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
2514 }
Vivek Natarajan326bebb2009-08-14 11:33:36 +05302515 if (AR_SREV_9287_12_OR_LATER(ah)) {
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302516 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
2517 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
2518 }
2519
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002520 REG_WRITE(ah, AR_STA_ID1,
2521 REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
2522
2523 ath9k_hw_set_dma(ah);
2524
2525 REG_WRITE(ah, AR_OBS, 8);
2526
Sujith0ef1f162009-03-30 15:28:35 +05302527 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002528 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2529 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2530 }
2531
2532 ath9k_hw_init_bb(ah, chan);
2533
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002534 if (!ath9k_hw_init_cal(ah, chan))
Joe Perches6badaaf2009-06-28 09:26:32 -07002535 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002536
Sujith2660b812009-02-09 13:27:26 +05302537 rx_chainmask = ah->rxchainmask;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002538 if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
2539 REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
2540 REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
2541 }
2542
2543 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
2544
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002545 /*
2546 * For big endian systems turn on swapping for descriptors
2547 */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002548 if (AR_SREV_9100(ah)) {
2549 u32 mask;
2550 mask = REG_READ(ah, AR_CFG);
2551 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
2552 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302553 "CFG Byte Swap Set 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002554 } else {
2555 mask =
2556 INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
2557 REG_WRITE(ah, AR_CFG, mask);
2558 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
Sujith04bd4632008-11-28 22:18:05 +05302559 "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002560 }
2561 } else {
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002562 /* Configure AR9271 target WLAN */
2563 if (AR_SREV_9271(ah))
2564 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002565#ifdef __BIG_ENDIAN
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04002566 else
2567 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002568#endif
2569 }
2570
Vasanthakumar Thiagarajan42cc41e2009-08-26 21:08:45 +05302571 if (ah->ah_sc->sc_flags & SC_OP_BTCOEX_ENABLED)
2572 ath9k_hw_btcoex_enable(ah);
2573
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002574 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002575}
2576
Sujithf1dc5602008-10-29 10:16:30 +05302577/************************/
2578/* Key Cache Management */
2579/************************/
2580
Sujithcbe61d82009-02-09 13:27:12 +05302581bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002582{
Sujithf1dc5602008-10-29 10:16:30 +05302583 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002584
Sujith2660b812009-02-09 13:27:26 +05302585 if (entry >= ah->caps.keycache_size) {
Sujithd8baa932009-03-30 15:28:25 +05302586 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
2587 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002588 return false;
2589 }
2590
Sujithf1dc5602008-10-29 10:16:30 +05302591 keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002592
Sujithf1dc5602008-10-29 10:16:30 +05302593 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
2594 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
2595 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
2596 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
2597 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
2598 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
2599 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
2600 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
2601
2602 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2603 u16 micentry = entry + 64;
2604
2605 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
2606 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
2607 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
2608 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
2609
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002610 }
2611
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002612 return true;
2613}
2614
Sujithcbe61d82009-02-09 13:27:12 +05302615bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002616{
Sujithf1dc5602008-10-29 10:16:30 +05302617 u32 macHi, macLo;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002618
Sujith2660b812009-02-09 13:27:26 +05302619 if (entry >= ah->caps.keycache_size) {
Sujithd8baa932009-03-30 15:28:25 +05302620 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
2621 "keychache entry %u out of range\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002622 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002623 }
2624
Sujithf1dc5602008-10-29 10:16:30 +05302625 if (mac != NULL) {
2626 macHi = (mac[5] << 8) | mac[4];
2627 macLo = (mac[3] << 24) |
2628 (mac[2] << 16) |
2629 (mac[1] << 8) |
2630 mac[0];
2631 macLo >>= 1;
2632 macLo |= (macHi & 1) << 31;
2633 macHi >>= 1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002634 } else {
Sujithf1dc5602008-10-29 10:16:30 +05302635 macLo = macHi = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002636 }
Sujithf1dc5602008-10-29 10:16:30 +05302637 REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
2638 REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002639
2640 return true;
2641}
2642
Sujithcbe61d82009-02-09 13:27:12 +05302643bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
Sujithf1dc5602008-10-29 10:16:30 +05302644 const struct ath9k_keyval *k,
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002645 const u8 *mac)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002646{
Sujith2660b812009-02-09 13:27:26 +05302647 const struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujithf1dc5602008-10-29 10:16:30 +05302648 u32 key0, key1, key2, key3, key4;
2649 u32 keyType;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002650
Sujithf1dc5602008-10-29 10:16:30 +05302651 if (entry >= pCap->keycache_size) {
Sujithd8baa932009-03-30 15:28:25 +05302652 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
2653 "keycache entry %u out of range\n", entry);
Sujithf1dc5602008-10-29 10:16:30 +05302654 return false;
2655 }
2656
2657 switch (k->kv_type) {
2658 case ATH9K_CIPHER_AES_OCB:
2659 keyType = AR_KEYTABLE_TYPE_AES;
2660 break;
2661 case ATH9K_CIPHER_AES_CCM:
2662 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
Sujithd8baa932009-03-30 15:28:25 +05302663 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
Sujith04bd4632008-11-28 22:18:05 +05302664 "AES-CCM not supported by mac rev 0x%x\n",
Sujithd535a422009-02-09 13:27:06 +05302665 ah->hw_version.macRev);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002666 return false;
2667 }
Sujithf1dc5602008-10-29 10:16:30 +05302668 keyType = AR_KEYTABLE_TYPE_CCM;
2669 break;
2670 case ATH9K_CIPHER_TKIP:
2671 keyType = AR_KEYTABLE_TYPE_TKIP;
2672 if (ATH9K_IS_MIC_ENABLED(ah)
2673 && entry + 64 >= pCap->keycache_size) {
Sujithd8baa932009-03-30 15:28:25 +05302674 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
Sujith04bd4632008-11-28 22:18:05 +05302675 "entry %u inappropriate for TKIP\n", entry);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002676 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002677 }
Sujithf1dc5602008-10-29 10:16:30 +05302678 break;
2679 case ATH9K_CIPHER_WEP:
Zhu Yie31a16d2009-05-21 21:47:03 +08002680 if (k->kv_len < WLAN_KEY_LEN_WEP40) {
Sujithd8baa932009-03-30 15:28:25 +05302681 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
Sujith04bd4632008-11-28 22:18:05 +05302682 "WEP key length %u too small\n", k->kv_len);
Sujithf1dc5602008-10-29 10:16:30 +05302683 return false;
2684 }
Zhu Yie31a16d2009-05-21 21:47:03 +08002685 if (k->kv_len <= WLAN_KEY_LEN_WEP40)
Sujithf1dc5602008-10-29 10:16:30 +05302686 keyType = AR_KEYTABLE_TYPE_40;
Zhu Yie31a16d2009-05-21 21:47:03 +08002687 else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302688 keyType = AR_KEYTABLE_TYPE_104;
2689 else
2690 keyType = AR_KEYTABLE_TYPE_128;
2691 break;
2692 case ATH9K_CIPHER_CLR:
2693 keyType = AR_KEYTABLE_TYPE_CLR;
2694 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002695 default:
Sujithd8baa932009-03-30 15:28:25 +05302696 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05302697 "cipher %u not supported\n", k->kv_type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002698 return false;
2699 }
Sujithf1dc5602008-10-29 10:16:30 +05302700
Jouni Malinene0caf9e2009-03-02 18:15:53 +02002701 key0 = get_unaligned_le32(k->kv_val + 0);
2702 key1 = get_unaligned_le16(k->kv_val + 4);
2703 key2 = get_unaligned_le32(k->kv_val + 6);
2704 key3 = get_unaligned_le16(k->kv_val + 10);
2705 key4 = get_unaligned_le32(k->kv_val + 12);
Zhu Yie31a16d2009-05-21 21:47:03 +08002706 if (k->kv_len <= WLAN_KEY_LEN_WEP104)
Sujithf1dc5602008-10-29 10:16:30 +05302707 key4 &= 0xff;
2708
Jouni Malinen672903b2009-03-02 15:06:31 +02002709 /*
2710 * Note: Key cache registers access special memory area that requires
2711 * two 32-bit writes to actually update the values in the internal
2712 * memory. Consequently, the exact order and pairs used here must be
2713 * maintained.
2714 */
2715
Sujithf1dc5602008-10-29 10:16:30 +05302716 if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
2717 u16 micentry = entry + 64;
2718
Jouni Malinen672903b2009-03-02 15:06:31 +02002719 /*
2720 * Write inverted key[47:0] first to avoid Michael MIC errors
2721 * on frames that could be sent or received at the same time.
2722 * The correct key will be written in the end once everything
2723 * else is ready.
2724 */
Sujithf1dc5602008-10-29 10:16:30 +05302725 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
2726 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002727
2728 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302729 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2730 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002731
2732 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302733 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2734 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
Jouni Malinen672903b2009-03-02 15:06:31 +02002735
2736 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302737 (void) ath9k_hw_keysetmac(ah, entry, mac);
2738
Sujith2660b812009-02-09 13:27:26 +05302739 if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
Jouni Malinen672903b2009-03-02 15:06:31 +02002740 /*
2741 * TKIP uses two key cache entries:
2742 * Michael MIC TX/RX keys in the same key cache entry
2743 * (idx = main index + 64):
2744 * key0 [31:0] = RX key [31:0]
2745 * key1 [15:0] = TX key [31:16]
2746 * key1 [31:16] = reserved
2747 * key2 [31:0] = RX key [63:32]
2748 * key3 [15:0] = TX key [15:0]
2749 * key3 [31:16] = reserved
2750 * key4 [31:0] = TX key [63:32]
2751 */
Sujithf1dc5602008-10-29 10:16:30 +05302752 u32 mic0, mic1, mic2, mic3, mic4;
2753
2754 mic0 = get_unaligned_le32(k->kv_mic + 0);
2755 mic2 = get_unaligned_le32(k->kv_mic + 4);
2756 mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
2757 mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
2758 mic4 = get_unaligned_le32(k->kv_txmic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002759
2760 /* Write RX[31:0] and TX[31:16] */
Sujithf1dc5602008-10-29 10:16:30 +05302761 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2762 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002763
2764 /* Write RX[63:32] and TX[15:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302765 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2766 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002767
2768 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302769 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
2770 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2771 AR_KEYTABLE_TYPE_CLR);
2772
2773 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002774 /*
2775 * TKIP uses four key cache entries (two for group
2776 * keys):
2777 * Michael MIC TX/RX keys are in different key cache
2778 * entries (idx = main index + 64 for TX and
2779 * main index + 32 + 96 for RX):
2780 * key0 [31:0] = TX/RX MIC key [31:0]
2781 * key1 [31:0] = reserved
2782 * key2 [31:0] = TX/RX MIC key [63:32]
2783 * key3 [31:0] = reserved
2784 * key4 [31:0] = reserved
2785 *
2786 * Upper layer code will call this function separately
2787 * for TX and RX keys when these registers offsets are
2788 * used.
2789 */
Sujithf1dc5602008-10-29 10:16:30 +05302790 u32 mic0, mic2;
2791
2792 mic0 = get_unaligned_le32(k->kv_mic + 0);
2793 mic2 = get_unaligned_le32(k->kv_mic + 4);
Jouni Malinen672903b2009-03-02 15:06:31 +02002794
2795 /* Write MIC key[31:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302796 REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
2797 REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002798
2799 /* Write MIC key[63:32] */
Sujithf1dc5602008-10-29 10:16:30 +05302800 REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
2801 REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002802
2803 /* Write TX[63:32] and keyType(reserved) */
Sujithf1dc5602008-10-29 10:16:30 +05302804 REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
2805 REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
2806 AR_KEYTABLE_TYPE_CLR);
2807 }
Jouni Malinen672903b2009-03-02 15:06:31 +02002808
2809 /* MAC address registers are reserved for the MIC entry */
Sujithf1dc5602008-10-29 10:16:30 +05302810 REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
2811 REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
Jouni Malinen672903b2009-03-02 15:06:31 +02002812
2813 /*
2814 * Write the correct (un-inverted) key[47:0] last to enable
2815 * TKIP now that all other registers are set with correct
2816 * values.
2817 */
Sujithf1dc5602008-10-29 10:16:30 +05302818 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2819 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
2820 } else {
Jouni Malinen672903b2009-03-02 15:06:31 +02002821 /* Write key[47:0] */
Sujithf1dc5602008-10-29 10:16:30 +05302822 REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
2823 REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
Jouni Malinen672903b2009-03-02 15:06:31 +02002824
2825 /* Write key[95:48] */
Sujithf1dc5602008-10-29 10:16:30 +05302826 REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
2827 REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
Jouni Malinen672903b2009-03-02 15:06:31 +02002828
2829 /* Write key[127:96] and key type */
Sujithf1dc5602008-10-29 10:16:30 +05302830 REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
2831 REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
2832
Jouni Malinen672903b2009-03-02 15:06:31 +02002833 /* Write MAC address for the entry */
Sujithf1dc5602008-10-29 10:16:30 +05302834 (void) ath9k_hw_keysetmac(ah, entry, mac);
2835 }
2836
Sujithf1dc5602008-10-29 10:16:30 +05302837 return true;
2838}
2839
Sujithcbe61d82009-02-09 13:27:12 +05302840bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
Sujithf1dc5602008-10-29 10:16:30 +05302841{
Sujith2660b812009-02-09 13:27:26 +05302842 if (entry < ah->caps.keycache_size) {
Sujithf1dc5602008-10-29 10:16:30 +05302843 u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
2844 if (val & AR_KEYTABLE_VALID)
2845 return true;
2846 }
2847 return false;
2848}
2849
2850/******************************/
2851/* Power Management (Chipset) */
2852/******************************/
2853
Sujithcbe61d82009-02-09 13:27:12 +05302854static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302855{
2856 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2857 if (setChip) {
2858 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2859 AR_RTC_FORCE_WAKE_EN);
2860 if (!AR_SREV_9100(ah))
2861 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2862
Gabor Juhosd03a66c2009-01-14 20:17:09 +01002863 REG_CLR_BIT(ah, (AR_RTC_RESET),
Sujithf1dc5602008-10-29 10:16:30 +05302864 AR_RTC_RESET_EN);
2865 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002866}
2867
Sujithcbe61d82009-02-09 13:27:12 +05302868static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002869{
Sujithf1dc5602008-10-29 10:16:30 +05302870 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2871 if (setChip) {
Sujith2660b812009-02-09 13:27:26 +05302872 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002873
Sujithf1dc5602008-10-29 10:16:30 +05302874 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2875 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2876 AR_RTC_FORCE_WAKE_ON_INT);
2877 } else {
2878 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
2879 AR_RTC_FORCE_WAKE_EN);
2880 }
2881 }
2882}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002883
Sujithcbe61d82009-02-09 13:27:12 +05302884static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
Sujithf1dc5602008-10-29 10:16:30 +05302885{
2886 u32 val;
2887 int i;
2888
2889 if (setChip) {
2890 if ((REG_READ(ah, AR_RTC_STATUS) &
2891 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2892 if (ath9k_hw_set_reset_reg(ah,
2893 ATH9K_RESET_POWER_ON) != true) {
2894 return false;
2895 }
2896 }
2897 if (AR_SREV_9100(ah))
2898 REG_SET_BIT(ah, AR_RTC_RESET,
2899 AR_RTC_RESET_EN);
2900
2901 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2902 AR_RTC_FORCE_WAKE_EN);
2903 udelay(50);
2904
2905 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2906 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2907 if (val == AR_RTC_STATUS_ON)
2908 break;
2909 udelay(50);
2910 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2911 AR_RTC_FORCE_WAKE_EN);
2912 }
2913 if (i == 0) {
Sujithd8baa932009-03-30 15:28:25 +05302914 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05302915 "Failed to wakeup in %uus\n", POWER_UP_TIME / 20);
Sujithf1dc5602008-10-29 10:16:30 +05302916 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002917 }
2918 }
2919
Sujithf1dc5602008-10-29 10:16:30 +05302920 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2921
2922 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002923}
2924
Gabor Juhos04717cc2009-07-14 20:17:13 -04002925static bool ath9k_hw_setpower_nolock(struct ath_hw *ah,
2926 enum ath9k_power_mode mode)
Sujithf1dc5602008-10-29 10:16:30 +05302927{
Sujithcbe61d82009-02-09 13:27:12 +05302928 int status = true, setChip = true;
Sujithf1dc5602008-10-29 10:16:30 +05302929 static const char *modes[] = {
2930 "AWAKE",
2931 "FULL-SLEEP",
2932 "NETWORK SLEEP",
2933 "UNDEFINED"
2934 };
Sujithf1dc5602008-10-29 10:16:30 +05302935
Gabor Juhoscbdec972009-07-24 17:27:22 +02002936 if (ah->power_mode == mode)
2937 return status;
2938
Sujithd8baa932009-03-30 15:28:25 +05302939 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s -> %s\n",
2940 modes[ah->power_mode], modes[mode]);
Sujithf1dc5602008-10-29 10:16:30 +05302941
2942 switch (mode) {
2943 case ATH9K_PM_AWAKE:
2944 status = ath9k_hw_set_power_awake(ah, setChip);
2945 break;
2946 case ATH9K_PM_FULL_SLEEP:
2947 ath9k_set_power_sleep(ah, setChip);
Sujith2660b812009-02-09 13:27:26 +05302948 ah->chip_fullsleep = true;
Sujithf1dc5602008-10-29 10:16:30 +05302949 break;
2950 case ATH9K_PM_NETWORK_SLEEP:
2951 ath9k_set_power_network_sleep(ah, setChip);
2952 break;
2953 default:
Sujithd8baa932009-03-30 15:28:25 +05302954 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05302955 "Unknown power mode %u\n", mode);
Sujithf1dc5602008-10-29 10:16:30 +05302956 return false;
2957 }
Sujith2660b812009-02-09 13:27:26 +05302958 ah->power_mode = mode;
Sujithf1dc5602008-10-29 10:16:30 +05302959
2960 return status;
2961}
2962
Gabor Juhos04717cc2009-07-14 20:17:13 -04002963bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
2964{
2965 unsigned long flags;
2966 bool ret;
2967
2968 spin_lock_irqsave(&ah->ah_sc->sc_pm_lock, flags);
2969 ret = ath9k_hw_setpower_nolock(ah, mode);
2970 spin_unlock_irqrestore(&ah->ah_sc->sc_pm_lock, flags);
2971
2972 return ret;
2973}
2974
Gabor Juhos0bc07982009-07-14 20:17:14 -04002975void ath9k_ps_wakeup(struct ath_softc *sc)
2976{
Gabor Juhos709ade92009-07-14 20:17:15 -04002977 unsigned long flags;
2978
2979 spin_lock_irqsave(&sc->sc_pm_lock, flags);
2980 if (++sc->ps_usecount != 1)
2981 goto unlock;
2982
Gabor Juhoscbdec972009-07-24 17:27:22 +02002983 ath9k_hw_setpower_nolock(sc->sc_ah, ATH9K_PM_AWAKE);
Gabor Juhos709ade92009-07-14 20:17:15 -04002984
2985 unlock:
2986 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Gabor Juhos0bc07982009-07-14 20:17:14 -04002987}
2988
2989void ath9k_ps_restore(struct ath_softc *sc)
2990{
Gabor Juhos709ade92009-07-14 20:17:15 -04002991 unsigned long flags;
2992
2993 spin_lock_irqsave(&sc->sc_pm_lock, flags);
2994 if (--sc->ps_usecount != 0)
2995 goto unlock;
2996
Gabor Juhos96148322009-07-24 17:27:21 +02002997 if (sc->ps_enabled &&
2998 !(sc->sc_flags & (SC_OP_WAIT_FOR_BEACON |
2999 SC_OP_WAIT_FOR_CAB |
3000 SC_OP_WAIT_FOR_PSPOLL_DATA |
3001 SC_OP_WAIT_FOR_TX_ACK)))
3002 ath9k_hw_setpower_nolock(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
Gabor Juhos709ade92009-07-14 20:17:15 -04003003
3004 unlock:
3005 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Gabor Juhos0bc07982009-07-14 20:17:14 -04003006}
3007
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003008/*
3009 * Helper for ASPM support.
3010 *
3011 * Disable PLL when in L0s as well as receiver clock when in L1.
3012 * This power saving option must be enabled through the SerDes.
3013 *
3014 * Programming the SerDes must go through the same 288 bit serial shift
3015 * register as the other analog registers. Hence the 9 writes.
3016 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303017void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore, int power_off)
Sujithf1dc5602008-10-29 10:16:30 +05303018{
Sujithf1dc5602008-10-29 10:16:30 +05303019 u8 i;
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303020 u32 val;
Sujithf1dc5602008-10-29 10:16:30 +05303021
Sujith2660b812009-02-09 13:27:26 +05303022 if (ah->is_pciexpress != true)
Sujithf1dc5602008-10-29 10:16:30 +05303023 return;
3024
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003025 /* Do not touch SerDes registers */
Sujith2660b812009-02-09 13:27:26 +05303026 if (ah->config.pcie_powersave_enable == 2)
Sujithf1dc5602008-10-29 10:16:30 +05303027 return;
3028
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003029 /* Nothing to do on restore for 11N */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303030 if (!restore) {
3031 if (AR_SREV_9280_20_OR_LATER(ah)) {
3032 /*
3033 * AR9280 2.0 or later chips use SerDes values from the
3034 * initvals.h initialized depending on chipset during
3035 * ath9k_hw_init()
3036 */
3037 for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
3038 REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
3039 INI_RA(&ah->iniPcieSerdes, i, 1));
3040 }
3041 } else if (AR_SREV_9280(ah) &&
3042 (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
3043 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
3044 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
Sujithf1dc5602008-10-29 10:16:30 +05303045
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303046 /* RX shut off when elecidle is asserted */
3047 REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
3048 REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
3049 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
3050
3051 /* Shut off CLKREQ active in L1 */
3052 if (ah->config.pcie_clock_req)
3053 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
3054 else
3055 REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
3056
3057 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3058 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3059 REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
3060
3061 /* Load the new settings */
3062 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
3063
3064 } else {
3065 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
3066 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
3067
3068 /* RX shut off when elecidle is asserted */
3069 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
3070 REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
3071 REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
3072
3073 /*
3074 * Ignore ah->ah_config.pcie_clock_req setting for
3075 * pre-AR9280 11n
3076 */
3077 REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
3078
3079 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
3080 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
3081 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
3082
3083 /* Load the new settings */
3084 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
Sujithf1dc5602008-10-29 10:16:30 +05303085 }
Sujithf1dc5602008-10-29 10:16:30 +05303086
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303087 udelay(1000);
Sujithf1dc5602008-10-29 10:16:30 +05303088
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303089 /* set bit 19 to allow forcing of pcie core into L1 state */
3090 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
Sujithf1dc5602008-10-29 10:16:30 +05303091
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303092 /* Several PCIe massages to ensure proper behaviour */
3093 if (ah->config.pcie_waen) {
3094 val = ah->config.pcie_waen;
3095 if (!power_off)
3096 val &= (~AR_WA_D3_L1_DISABLE);
3097 } else {
3098 if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3099 AR_SREV_9287(ah)) {
3100 val = AR9285_WA_DEFAULT;
3101 if (!power_off)
3102 val &= (~AR_WA_D3_L1_DISABLE);
3103 } else if (AR_SREV_9280(ah)) {
3104 /*
3105 * On AR9280 chips bit 22 of 0x4004 needs to be
3106 * set otherwise card may disappear.
3107 */
3108 val = AR9280_WA_DEFAULT;
3109 if (!power_off)
3110 val &= (~AR_WA_D3_L1_DISABLE);
3111 } else
3112 val = AR_WA_DEFAULT;
3113 }
Sujithf1dc5602008-10-29 10:16:30 +05303114
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303115 REG_WRITE(ah, AR_WA, val);
Sujithf1dc5602008-10-29 10:16:30 +05303116 }
3117
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303118 if (power_off) {
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003119 /*
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303120 * Set PCIe workaround bits
3121 * bit 14 in WA register (disable L1) should only
3122 * be set when device enters D3 and be cleared
3123 * when device comes back to D0.
Luis R. Rodriguez24c1a282009-02-10 15:35:22 -08003124 */
Vivek Natarajan93b1b372009-09-17 09:24:58 +05303125 if (ah->config.pcie_waen) {
3126 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
3127 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3128 } else {
3129 if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
3130 AR_SREV_9287(ah)) &&
3131 (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
3132 (AR_SREV_9280(ah) &&
3133 (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
3134 REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
3135 }
3136 }
Sujithf1dc5602008-10-29 10:16:30 +05303137 }
3138}
3139
3140/**********************/
3141/* Interrupt Handling */
3142/**********************/
3143
Sujithcbe61d82009-02-09 13:27:12 +05303144bool ath9k_hw_intrpend(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003145{
3146 u32 host_isr;
3147
3148 if (AR_SREV_9100(ah))
3149 return true;
3150
3151 host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
3152 if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
3153 return true;
3154
3155 host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
3156 if ((host_isr & AR_INTR_SYNC_DEFAULT)
3157 && (host_isr != AR_INTR_SPURIOUS))
3158 return true;
3159
3160 return false;
3161}
3162
Sujithcbe61d82009-02-09 13:27:12 +05303163bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003164{
3165 u32 isr = 0;
3166 u32 mask2 = 0;
Sujith2660b812009-02-09 13:27:26 +05303167 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003168 u32 sync_cause = 0;
3169 bool fatal_int = false;
3170
3171 if (!AR_SREV_9100(ah)) {
3172 if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
3173 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
3174 == AR_RTC_STATUS_ON) {
3175 isr = REG_READ(ah, AR_ISR);
3176 }
3177 }
3178
Sujithf1dc5602008-10-29 10:16:30 +05303179 sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
3180 AR_INTR_SYNC_DEFAULT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003181
3182 *masked = 0;
3183
3184 if (!isr && !sync_cause)
3185 return false;
3186 } else {
3187 *masked = 0;
3188 isr = REG_READ(ah, AR_ISR);
3189 }
3190
3191 if (isr) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003192 if (isr & AR_ISR_BCNMISC) {
3193 u32 isr2;
3194 isr2 = REG_READ(ah, AR_ISR_S2);
3195 if (isr2 & AR_ISR_S2_TIM)
3196 mask2 |= ATH9K_INT_TIM;
3197 if (isr2 & AR_ISR_S2_DTIM)
3198 mask2 |= ATH9K_INT_DTIM;
3199 if (isr2 & AR_ISR_S2_DTIMSYNC)
3200 mask2 |= ATH9K_INT_DTIMSYNC;
3201 if (isr2 & (AR_ISR_S2_CABEND))
3202 mask2 |= ATH9K_INT_CABEND;
3203 if (isr2 & AR_ISR_S2_GTT)
3204 mask2 |= ATH9K_INT_GTT;
3205 if (isr2 & AR_ISR_S2_CST)
3206 mask2 |= ATH9K_INT_CST;
Sujith4af9cf42009-02-12 10:06:47 +05303207 if (isr2 & AR_ISR_S2_TSFOOR)
3208 mask2 |= ATH9K_INT_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003209 }
3210
3211 isr = REG_READ(ah, AR_ISR_RAC);
3212 if (isr == 0xffffffff) {
3213 *masked = 0;
3214 return false;
3215 }
3216
3217 *masked = isr & ATH9K_INT_COMMON;
3218
Sujith0ef1f162009-03-30 15:28:35 +05303219 if (ah->config.intr_mitigation) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003220 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
3221 *masked |= ATH9K_INT_RX;
3222 }
3223
3224 if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
3225 *masked |= ATH9K_INT_RX;
3226 if (isr &
3227 (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
3228 AR_ISR_TXEOL)) {
3229 u32 s0_s, s1_s;
3230
3231 *masked |= ATH9K_INT_TX;
3232
3233 s0_s = REG_READ(ah, AR_ISR_S0_S);
Sujith2660b812009-02-09 13:27:26 +05303234 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
3235 ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003236
3237 s1_s = REG_READ(ah, AR_ISR_S1_S);
Sujith2660b812009-02-09 13:27:26 +05303238 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
3239 ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003240 }
3241
3242 if (isr & AR_ISR_RXORN) {
3243 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujith04bd4632008-11-28 22:18:05 +05303244 "receive FIFO overrun interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003245 }
3246
3247 if (!AR_SREV_9100(ah)) {
Sujith60b67f52008-08-07 10:52:38 +05303248 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003249 u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
3250 if (isr5 & AR_ISR_S5_TIM_TIMER)
3251 *masked |= ATH9K_INT_TIM_TIMER;
3252 }
3253 }
3254
3255 *masked |= mask2;
3256 }
Sujithf1dc5602008-10-29 10:16:30 +05303257
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003258 if (AR_SREV_9100(ah))
3259 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303260
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05303261 if (isr & AR_ISR_GENTMR) {
3262 u32 s5_s;
3263
3264 s5_s = REG_READ(ah, AR_ISR_S5_S);
3265 if (isr & AR_ISR_GENTMR) {
3266 ah->intr_gen_timer_trigger =
3267 MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
3268
3269 ah->intr_gen_timer_thresh =
3270 MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
3271
3272 if (ah->intr_gen_timer_trigger)
3273 *masked |= ATH9K_INT_GENTIMER;
3274
3275 }
3276 }
3277
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003278 if (sync_cause) {
3279 fatal_int =
3280 (sync_cause &
3281 (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
3282 ? true : false;
3283
3284 if (fatal_int) {
3285 if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
3286 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
Sujith04bd4632008-11-28 22:18:05 +05303287 "received PCI FATAL interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003288 }
3289 if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
3290 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
Sujith04bd4632008-11-28 22:18:05 +05303291 "received PCI PERR interrupt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003292 }
Steven Luoa89bff92009-04-12 02:57:54 -07003293 *masked |= ATH9K_INT_FATAL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003294 }
3295 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
3296 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujith04bd4632008-11-28 22:18:05 +05303297 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003298 REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
3299 REG_WRITE(ah, AR_RC, 0);
3300 *masked |= ATH9K_INT_FATAL;
3301 }
3302 if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
3303 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
Sujith04bd4632008-11-28 22:18:05 +05303304 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003305 }
3306
3307 REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
3308 (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
3309 }
Sujithf1dc5602008-10-29 10:16:30 +05303310
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003311 return true;
3312}
3313
Sujithcbe61d82009-02-09 13:27:12 +05303314enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003315{
Sujith2660b812009-02-09 13:27:26 +05303316 u32 omask = ah->mask_reg;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003317 u32 mask, mask2;
Sujith2660b812009-02-09 13:27:26 +05303318 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003319
Sujith04bd4632008-11-28 22:18:05 +05303320 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003321
3322 if (omask & ATH9K_INT_GLOBAL) {
Sujith04bd4632008-11-28 22:18:05 +05303323 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "disable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003324 REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
3325 (void) REG_READ(ah, AR_IER);
3326 if (!AR_SREV_9100(ah)) {
3327 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
3328 (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
3329
3330 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
3331 (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
3332 }
3333 }
3334
3335 mask = ints & ATH9K_INT_COMMON;
3336 mask2 = 0;
3337
3338 if (ints & ATH9K_INT_TX) {
Sujith2660b812009-02-09 13:27:26 +05303339 if (ah->txok_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003340 mask |= AR_IMR_TXOK;
Sujith2660b812009-02-09 13:27:26 +05303341 if (ah->txdesc_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003342 mask |= AR_IMR_TXDESC;
Sujith2660b812009-02-09 13:27:26 +05303343 if (ah->txerr_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003344 mask |= AR_IMR_TXERR;
Sujith2660b812009-02-09 13:27:26 +05303345 if (ah->txeol_interrupt_mask)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003346 mask |= AR_IMR_TXEOL;
3347 }
3348 if (ints & ATH9K_INT_RX) {
3349 mask |= AR_IMR_RXERR;
Sujith0ef1f162009-03-30 15:28:35 +05303350 if (ah->config.intr_mitigation)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003351 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
3352 else
3353 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
Sujith60b67f52008-08-07 10:52:38 +05303354 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003355 mask |= AR_IMR_GENTMR;
3356 }
3357
3358 if (ints & (ATH9K_INT_BMISC)) {
3359 mask |= AR_IMR_BCNMISC;
3360 if (ints & ATH9K_INT_TIM)
3361 mask2 |= AR_IMR_S2_TIM;
3362 if (ints & ATH9K_INT_DTIM)
3363 mask2 |= AR_IMR_S2_DTIM;
3364 if (ints & ATH9K_INT_DTIMSYNC)
3365 mask2 |= AR_IMR_S2_DTIMSYNC;
3366 if (ints & ATH9K_INT_CABEND)
Sujith4af9cf42009-02-12 10:06:47 +05303367 mask2 |= AR_IMR_S2_CABEND;
3368 if (ints & ATH9K_INT_TSFOOR)
3369 mask2 |= AR_IMR_S2_TSFOOR;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003370 }
3371
3372 if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
3373 mask |= AR_IMR_BCNMISC;
3374 if (ints & ATH9K_INT_GTT)
3375 mask2 |= AR_IMR_S2_GTT;
3376 if (ints & ATH9K_INT_CST)
3377 mask2 |= AR_IMR_S2_CST;
3378 }
3379
Sujith04bd4632008-11-28 22:18:05 +05303380 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003381 REG_WRITE(ah, AR_IMR, mask);
3382 mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
3383 AR_IMR_S2_DTIM |
3384 AR_IMR_S2_DTIMSYNC |
3385 AR_IMR_S2_CABEND |
3386 AR_IMR_S2_CABTO |
3387 AR_IMR_S2_TSFOOR |
3388 AR_IMR_S2_GTT | AR_IMR_S2_CST);
3389 REG_WRITE(ah, AR_IMR_S2, mask | mask2);
Sujith2660b812009-02-09 13:27:26 +05303390 ah->mask_reg = ints;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003391
Sujith60b67f52008-08-07 10:52:38 +05303392 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003393 if (ints & ATH9K_INT_TIM_TIMER)
3394 REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3395 else
3396 REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
3397 }
3398
3399 if (ints & ATH9K_INT_GLOBAL) {
Sujith04bd4632008-11-28 22:18:05 +05303400 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "enable IER\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003401 REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
3402 if (!AR_SREV_9100(ah)) {
3403 REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
3404 AR_INTR_MAC_IRQ);
3405 REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
3406
3407
3408 REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
3409 AR_INTR_SYNC_DEFAULT);
3410 REG_WRITE(ah, AR_INTR_SYNC_MASK,
3411 AR_INTR_SYNC_DEFAULT);
3412 }
3413 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
3414 REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
3415 }
3416
3417 return omask;
3418}
3419
Sujithf1dc5602008-10-29 10:16:30 +05303420/*******************/
3421/* Beacon Handling */
3422/*******************/
3423
Sujithcbe61d82009-02-09 13:27:12 +05303424void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003425{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003426 int flags = 0;
3427
Sujith2660b812009-02-09 13:27:26 +05303428 ah->beacon_interval = beacon_period;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003429
Sujith2660b812009-02-09 13:27:26 +05303430 switch (ah->opmode) {
Colin McCabed97809d2008-12-01 13:38:55 -08003431 case NL80211_IFTYPE_STATION:
3432 case NL80211_IFTYPE_MONITOR:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003433 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3434 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
3435 REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
3436 flags |= AR_TBTT_TIMER_EN;
3437 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003438 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04003439 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003440 REG_SET_BIT(ah, AR_TXCFG,
3441 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
3442 REG_WRITE(ah, AR_NEXT_NDP_TIMER,
3443 TU_TO_USEC(next_beacon +
Sujith2660b812009-02-09 13:27:26 +05303444 (ah->atim_window ? ah->
3445 atim_window : 1)));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003446 flags |= AR_NDP_TIMER_EN;
Colin McCabed97809d2008-12-01 13:38:55 -08003447 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003448 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
3449 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
3450 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303451 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303452 dma_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003453 REG_WRITE(ah, AR_NEXT_SWBA,
3454 TU_TO_USEC(next_beacon -
Sujith2660b812009-02-09 13:27:26 +05303455 ah->config.
Sujith60b67f52008-08-07 10:52:38 +05303456 sw_beacon_response_time));
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003457 flags |=
3458 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
3459 break;
Colin McCabed97809d2008-12-01 13:38:55 -08003460 default:
3461 DPRINTF(ah->ah_sc, ATH_DBG_BEACON,
3462 "%s: unsupported opmode: %d\n",
Sujith2660b812009-02-09 13:27:26 +05303463 __func__, ah->opmode);
Colin McCabed97809d2008-12-01 13:38:55 -08003464 return;
3465 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003466 }
3467
3468 REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3469 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
3470 REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
3471 REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
3472
3473 beacon_period &= ~ATH9K_BEACON_ENA;
3474 if (beacon_period & ATH9K_BEACON_RESET_TSF) {
3475 beacon_period &= ~ATH9K_BEACON_RESET_TSF;
3476 ath9k_hw_reset_tsf(ah);
3477 }
3478
3479 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
3480}
3481
Sujithcbe61d82009-02-09 13:27:12 +05303482void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303483 const struct ath9k_beacon_state *bs)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003484{
3485 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
Sujith2660b812009-02-09 13:27:26 +05303486 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003487
3488 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
3489
3490 REG_WRITE(ah, AR_BEACON_PERIOD,
3491 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3492 REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
3493 TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
3494
3495 REG_RMW_FIELD(ah, AR_RSSI_THR,
3496 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
3497
3498 beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
3499
3500 if (bs->bs_sleepduration > beaconintval)
3501 beaconintval = bs->bs_sleepduration;
3502
3503 dtimperiod = bs->bs_dtimperiod;
3504 if (bs->bs_sleepduration > dtimperiod)
3505 dtimperiod = bs->bs_sleepduration;
3506
3507 if (beaconintval == dtimperiod)
3508 nextTbtt = bs->bs_nextdtim;
3509 else
3510 nextTbtt = bs->bs_nexttbtt;
3511
Sujith04bd4632008-11-28 22:18:05 +05303512 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
3513 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
3514 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
3515 DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003516
3517 REG_WRITE(ah, AR_NEXT_DTIM,
3518 TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
3519 REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
3520
3521 REG_WRITE(ah, AR_SLEEP1,
3522 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
3523 | AR_SLEEP1_ASSUME_DTIM);
3524
Sujith60b67f52008-08-07 10:52:38 +05303525 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003526 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
3527 else
3528 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
3529
3530 REG_WRITE(ah, AR_SLEEP2,
3531 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
3532
3533 REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
3534 REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
3535
3536 REG_SET_BIT(ah, AR_TIMER_MODE,
3537 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
3538 AR_DTIM_TIMER_EN);
3539
Sujith4af9cf42009-02-12 10:06:47 +05303540 /* TSF Out of Range Threshold */
3541 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003542}
3543
Sujithf1dc5602008-10-29 10:16:30 +05303544/*******************/
3545/* HW Capabilities */
3546/*******************/
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003547
Sujitheef7a572009-03-30 15:28:28 +05303548void ath9k_hw_fill_cap_info(struct ath_hw *ah)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003549{
Sujith2660b812009-02-09 13:27:26 +05303550 struct ath9k_hw_capabilities *pCap = &ah->caps;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003551 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303552 struct ath_btcoex_info *btcoex_info = &ah->ah_sc->btcoex_info;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003553
Sujithf1dc5602008-10-29 10:16:30 +05303554 u16 capField = 0, eeval;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003555
Sujithf74df6f2009-02-09 13:27:24 +05303556 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003557 regulatory->current_rd = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303558
Sujithf74df6f2009-02-09 13:27:24 +05303559 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
Sujithfec0de12009-02-12 10:06:43 +05303560 if (AR_SREV_9285_10_OR_LATER(ah))
3561 eeval |= AR9285_RDEXT_DEFAULT;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003562 regulatory->current_rd_ext = eeval;
Sujithf1dc5602008-10-29 10:16:30 +05303563
Sujithf74df6f2009-02-09 13:27:24 +05303564 capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
Sujithf1dc5602008-10-29 10:16:30 +05303565
Sujith2660b812009-02-09 13:27:26 +05303566 if (ah->opmode != NL80211_IFTYPE_AP &&
Sujithd535a422009-02-09 13:27:06 +05303567 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003568 if (regulatory->current_rd == 0x64 ||
3569 regulatory->current_rd == 0x65)
3570 regulatory->current_rd += 5;
3571 else if (regulatory->current_rd == 0x41)
3572 regulatory->current_rd = 0x43;
Sujithf1dc5602008-10-29 10:16:30 +05303573 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003574 "regdomain mapped to 0x%x\n", regulatory->current_rd);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003575 }
Sujithdc2222a2008-08-14 13:26:55 +05303576
Sujithf74df6f2009-02-09 13:27:24 +05303577 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
Sujithf1dc5602008-10-29 10:16:30 +05303578 bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003579
Sujithf1dc5602008-10-29 10:16:30 +05303580 if (eeval & AR5416_OPFLAGS_11A) {
3581 set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303582 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303583 if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
3584 set_bit(ATH9K_MODE_11NA_HT20,
3585 pCap->wireless_modes);
3586 if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
3587 set_bit(ATH9K_MODE_11NA_HT40PLUS,
3588 pCap->wireless_modes);
3589 set_bit(ATH9K_MODE_11NA_HT40MINUS,
3590 pCap->wireless_modes);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003591 }
3592 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003593 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003594
Sujithf1dc5602008-10-29 10:16:30 +05303595 if (eeval & AR5416_OPFLAGS_11G) {
Sujithf1dc5602008-10-29 10:16:30 +05303596 set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
Sujith2660b812009-02-09 13:27:26 +05303597 if (ah->config.ht_enable) {
Sujithf1dc5602008-10-29 10:16:30 +05303598 if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
3599 set_bit(ATH9K_MODE_11NG_HT20,
3600 pCap->wireless_modes);
3601 if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
3602 set_bit(ATH9K_MODE_11NG_HT40PLUS,
3603 pCap->wireless_modes);
3604 set_bit(ATH9K_MODE_11NG_HT40MINUS,
3605 pCap->wireless_modes);
3606 }
3607 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003608 }
Sujithf1dc5602008-10-29 10:16:30 +05303609
Sujithf74df6f2009-02-09 13:27:24 +05303610 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003611 /*
3612 * For AR9271 we will temporarilly uses the rx chainmax as read from
3613 * the EEPROM.
3614 */
Sujith8147f5d2009-02-20 15:13:23 +05303615 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003616 !(eeval & AR5416_OPFLAGS_11A) &&
3617 !(AR_SREV_9271(ah)))
3618 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
Sujith8147f5d2009-02-20 15:13:23 +05303619 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
3620 else
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -04003621 /* Use rx_chainmask from EEPROM. */
Sujith8147f5d2009-02-20 15:13:23 +05303622 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
Sujithf1dc5602008-10-29 10:16:30 +05303623
Sujithd535a422009-02-09 13:27:06 +05303624 if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
Sujith2660b812009-02-09 13:27:26 +05303625 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
Sujithf1dc5602008-10-29 10:16:30 +05303626
3627 pCap->low_2ghz_chan = 2312;
3628 pCap->high_2ghz_chan = 2732;
3629
3630 pCap->low_5ghz_chan = 4920;
3631 pCap->high_5ghz_chan = 6100;
3632
3633 pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
3634 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
3635 pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
3636
3637 pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
3638 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3639 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3640
Sujith2660b812009-02-09 13:27:26 +05303641 if (ah->config.ht_enable)
Sujithf1dc5602008-10-29 10:16:30 +05303642 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3643 else
3644 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
3645
3646 pCap->hw_caps |= ATH9K_HW_CAP_GTT;
3647 pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
3648 pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
3649 pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
3650
3651 if (capField & AR_EEPROM_EEPCAP_MAXQCU)
3652 pCap->total_queues =
3653 MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
3654 else
3655 pCap->total_queues = ATH9K_NUM_TX_QUEUES;
3656
3657 if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
3658 pCap->keycache_size =
3659 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
3660 else
3661 pCap->keycache_size = AR_KEYTABLE_SIZE;
3662
3663 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
Sujithf1dc5602008-10-29 10:16:30 +05303664 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3665
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303666 if (AR_SREV_9285_10_OR_LATER(ah))
3667 pCap->num_gpio_pins = AR9285_NUM_GPIO;
3668 else if (AR_SREV_9280_10_OR_LATER(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303669 pCap->num_gpio_pins = AR928X_NUM_GPIO;
3670 else
3671 pCap->num_gpio_pins = AR_NUM_GPIO;
3672
Sujithf1dc5602008-10-29 10:16:30 +05303673 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3674 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3675 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
3676 } else {
3677 pCap->rts_aggr_limit = (8 * 1024);
3678 }
3679
3680 pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
3681
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05303682#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05303683 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
3684 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
3685 ah->rfkill_gpio =
3686 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
3687 ah->rfkill_polarity =
3688 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
Sujithf1dc5602008-10-29 10:16:30 +05303689
3690 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
3691 }
3692#endif
3693
Sujithd535a422009-02-09 13:27:06 +05303694 if ((ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI) ||
3695 (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE) ||
3696 (ah->hw_version.macVersion == AR_SREV_VERSION_9160) ||
3697 (ah->hw_version.macVersion == AR_SREV_VERSION_9100) ||
Vivek Natarajan882b7092009-04-14 16:21:01 +05303698 (ah->hw_version.macVersion == AR_SREV_VERSION_9280) ||
3699 (ah->hw_version.macVersion == AR_SREV_VERSION_9285))
Sujithf1dc5602008-10-29 10:16:30 +05303700 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
3701 else
3702 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
3703
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05303704 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
Sujithf1dc5602008-10-29 10:16:30 +05303705 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
3706 else
3707 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
3708
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003709 if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
Sujithf1dc5602008-10-29 10:16:30 +05303710 pCap->reg_cap =
3711 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3712 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
3713 AR_EEPROM_EEREGCAP_EN_KK_U2 |
3714 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
3715 } else {
3716 pCap->reg_cap =
3717 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
3718 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
3719 }
3720
3721 pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
3722
3723 pCap->num_antcfg_5ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303724 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303725 pCap->num_antcfg_2ghz =
Sujithf74df6f2009-02-09 13:27:24 +05303726 ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
Sujithf1dc5602008-10-29 10:16:30 +05303727
Vasanthakumar Thiagarajanfe129462009-09-09 15:25:50 +05303728 if (AR_SREV_9280_10_OR_LATER(ah) &&
3729 ath_btcoex_supported(ah->hw_version.subsysid)) {
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303730 btcoex_info->btactive_gpio = ATH_BTACTIVE_GPIO;
3731 btcoex_info->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
3732
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303733 if (AR_SREV_9285(ah)) {
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303734 btcoex_info->btcoex_scheme = ATH_BTCOEX_CFG_3WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303735 btcoex_info->btpriority_gpio = ATH_BTPRIORITY_GPIO;
3736 } else {
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303737 btcoex_info->btcoex_scheme = ATH_BTCOEX_CFG_2WIRE;
Vasanthakumar Thiagarajan8c8f9ba2009-09-09 15:25:52 +05303738 }
Vasanthakumar Thiagarajan22f25d02009-08-26 21:08:47 +05303739 } else {
3740 btcoex_info->btcoex_scheme = ATH_BTCOEX_CFG_NONE;
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05303741 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003742}
3743
Sujithcbe61d82009-02-09 13:27:12 +05303744bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303745 u32 capability, u32 *result)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003746{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003747 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithf1dc5602008-10-29 10:16:30 +05303748 switch (type) {
3749 case ATH9K_CAP_CIPHER:
3750 switch (capability) {
3751 case ATH9K_CIPHER_AES_CCM:
3752 case ATH9K_CIPHER_AES_OCB:
3753 case ATH9K_CIPHER_TKIP:
3754 case ATH9K_CIPHER_WEP:
3755 case ATH9K_CIPHER_MIC:
3756 case ATH9K_CIPHER_CLR:
3757 return true;
3758 default:
3759 return false;
3760 }
3761 case ATH9K_CAP_TKIP_MIC:
3762 switch (capability) {
3763 case 0:
3764 return true;
3765 case 1:
Sujith2660b812009-02-09 13:27:26 +05303766 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303767 AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
3768 false;
3769 }
3770 case ATH9K_CAP_TKIP_SPLIT:
Sujith2660b812009-02-09 13:27:26 +05303771 return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
Sujithf1dc5602008-10-29 10:16:30 +05303772 false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303773 case ATH9K_CAP_DIVERSITY:
3774 return (REG_READ(ah, AR_PHY_CCK_DETECT) &
3775 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
3776 true : false;
Sujithf1dc5602008-10-29 10:16:30 +05303777 case ATH9K_CAP_MCAST_KEYSRCH:
3778 switch (capability) {
3779 case 0:
3780 return true;
3781 case 1:
3782 if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
3783 return false;
3784 } else {
Sujith2660b812009-02-09 13:27:26 +05303785 return (ah->sta_id1_defaults &
Sujithf1dc5602008-10-29 10:16:30 +05303786 AR_STA_ID1_MCAST_KSRCH) ? true :
3787 false;
3788 }
3789 }
3790 return false;
Sujithf1dc5602008-10-29 10:16:30 +05303791 case ATH9K_CAP_TXPOW:
3792 switch (capability) {
3793 case 0:
3794 return 0;
3795 case 1:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003796 *result = regulatory->power_limit;
Sujithf1dc5602008-10-29 10:16:30 +05303797 return 0;
3798 case 2:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003799 *result = regulatory->max_power_level;
Sujithf1dc5602008-10-29 10:16:30 +05303800 return 0;
3801 case 3:
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07003802 *result = regulatory->tp_scale;
Sujithf1dc5602008-10-29 10:16:30 +05303803 return 0;
3804 }
3805 return false;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05303806 case ATH9K_CAP_DS:
3807 return (AR_SREV_9280_20_OR_LATER(ah) &&
3808 (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
3809 ? false : true;
Sujithf1dc5602008-10-29 10:16:30 +05303810 default:
3811 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003812 }
Sujithf1dc5602008-10-29 10:16:30 +05303813}
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003814
Sujithcbe61d82009-02-09 13:27:12 +05303815bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
Sujithf1dc5602008-10-29 10:16:30 +05303816 u32 capability, u32 setting, int *status)
3817{
Sujithf1dc5602008-10-29 10:16:30 +05303818 u32 v;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07003819
Sujithf1dc5602008-10-29 10:16:30 +05303820 switch (type) {
3821 case ATH9K_CAP_TKIP_MIC:
3822 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303823 ah->sta_id1_defaults |=
Sujithf1dc5602008-10-29 10:16:30 +05303824 AR_STA_ID1_CRPT_MIC_ENABLE;
3825 else
Sujith2660b812009-02-09 13:27:26 +05303826 ah->sta_id1_defaults &=
Sujithf1dc5602008-10-29 10:16:30 +05303827 ~AR_STA_ID1_CRPT_MIC_ENABLE;
3828 return true;
3829 case ATH9K_CAP_DIVERSITY:
3830 v = REG_READ(ah, AR_PHY_CCK_DETECT);
3831 if (setting)
3832 v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3833 else
3834 v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
3835 REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
3836 return true;
3837 case ATH9K_CAP_MCAST_KEYSRCH:
3838 if (setting)
Sujith2660b812009-02-09 13:27:26 +05303839 ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303840 else
Sujith2660b812009-02-09 13:27:26 +05303841 ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
Sujithf1dc5602008-10-29 10:16:30 +05303842 return true;
Sujithf1dc5602008-10-29 10:16:30 +05303843 default:
3844 return false;
3845 }
3846}
3847
3848/****************************/
3849/* GPIO / RFKILL / Antennae */
3850/****************************/
3851
Sujithcbe61d82009-02-09 13:27:12 +05303852static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303853 u32 gpio, u32 type)
3854{
3855 int addr;
3856 u32 gpio_shift, tmp;
3857
3858 if (gpio > 11)
3859 addr = AR_GPIO_OUTPUT_MUX3;
3860 else if (gpio > 5)
3861 addr = AR_GPIO_OUTPUT_MUX2;
3862 else
3863 addr = AR_GPIO_OUTPUT_MUX1;
3864
3865 gpio_shift = (gpio % 6) * 5;
3866
3867 if (AR_SREV_9280_20_OR_LATER(ah)
3868 || (addr != AR_GPIO_OUTPUT_MUX1)) {
3869 REG_RMW(ah, addr, (type << gpio_shift),
3870 (0x1f << gpio_shift));
3871 } else {
3872 tmp = REG_READ(ah, addr);
3873 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
3874 tmp &= ~(0x1f << gpio_shift);
3875 tmp |= (type << gpio_shift);
3876 REG_WRITE(ah, addr, tmp);
3877 }
3878}
3879
Sujithcbe61d82009-02-09 13:27:12 +05303880void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303881{
3882 u32 gpio_shift;
3883
Sujith2660b812009-02-09 13:27:26 +05303884 ASSERT(gpio < ah->caps.num_gpio_pins);
Sujithf1dc5602008-10-29 10:16:30 +05303885
3886 gpio_shift = gpio << 1;
3887
3888 REG_RMW(ah,
3889 AR_GPIO_OE_OUT,
3890 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
3891 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3892}
3893
Sujithcbe61d82009-02-09 13:27:12 +05303894u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
Sujithf1dc5602008-10-29 10:16:30 +05303895{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303896#define MS_REG_READ(x, y) \
3897 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3898
Sujith2660b812009-02-09 13:27:26 +05303899 if (gpio >= ah->caps.num_gpio_pins)
Sujithf1dc5602008-10-29 10:16:30 +05303900 return 0xffffffff;
3901
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303902 if (AR_SREV_9287_10_OR_LATER(ah))
3903 return MS_REG_READ(AR9287, gpio) != 0;
3904 else if (AR_SREV_9285_10_OR_LATER(ah))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05303905 return MS_REG_READ(AR9285, gpio) != 0;
3906 else if (AR_SREV_9280_10_OR_LATER(ah))
3907 return MS_REG_READ(AR928X, gpio) != 0;
3908 else
3909 return MS_REG_READ(AR, gpio) != 0;
Sujithf1dc5602008-10-29 10:16:30 +05303910}
3911
Sujithcbe61d82009-02-09 13:27:12 +05303912void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
Sujithf1dc5602008-10-29 10:16:30 +05303913 u32 ah_signal_type)
3914{
3915 u32 gpio_shift;
3916
3917 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
3918
3919 gpio_shift = 2 * gpio;
3920
3921 REG_RMW(ah,
3922 AR_GPIO_OE_OUT,
3923 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
3924 (AR_GPIO_OE_OUT_DRV << gpio_shift));
3925}
3926
Sujithcbe61d82009-02-09 13:27:12 +05303927void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +05303928{
3929 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
3930 AR_GPIO_BIT(gpio));
3931}
3932
Sujithcbe61d82009-02-09 13:27:12 +05303933u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303934{
3935 return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
3936}
3937
Sujithcbe61d82009-02-09 13:27:12 +05303938void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
Sujithf1dc5602008-10-29 10:16:30 +05303939{
3940 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
3941}
3942
Sujithcbe61d82009-02-09 13:27:12 +05303943bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05303944 enum ath9k_ant_setting settings,
3945 struct ath9k_channel *chan,
3946 u8 *tx_chainmask,
3947 u8 *rx_chainmask,
3948 u8 *antenna_cfgd)
3949{
Sujithf1dc5602008-10-29 10:16:30 +05303950 static u8 tx_chainmask_cfg, rx_chainmask_cfg;
3951
3952 if (AR_SREV_9280(ah)) {
3953 if (!tx_chainmask_cfg) {
3954
3955 tx_chainmask_cfg = *tx_chainmask;
3956 rx_chainmask_cfg = *rx_chainmask;
3957 }
3958
3959 switch (settings) {
3960 case ATH9K_ANT_FIXED_A:
3961 *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3962 *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
3963 *antenna_cfgd = true;
3964 break;
3965 case ATH9K_ANT_FIXED_B:
Sujith2660b812009-02-09 13:27:26 +05303966 if (ah->caps.tx_chainmask >
Sujithf1dc5602008-10-29 10:16:30 +05303967 ATH9K_ANTENNA1_CHAINMASK) {
3968 *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3969 }
3970 *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
3971 *antenna_cfgd = true;
3972 break;
3973 case ATH9K_ANT_VARIABLE:
3974 *tx_chainmask = tx_chainmask_cfg;
3975 *rx_chainmask = rx_chainmask_cfg;
3976 *antenna_cfgd = true;
3977 break;
3978 default:
3979 break;
3980 }
3981 } else {
Sujith1cf68732009-08-13 09:34:32 +05303982 ah->config.diversity_control = settings;
Sujithf1dc5602008-10-29 10:16:30 +05303983 }
3984
3985 return true;
3986}
3987
3988/*********************/
3989/* General Operation */
3990/*********************/
3991
Sujithcbe61d82009-02-09 13:27:12 +05303992u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05303993{
3994 u32 bits = REG_READ(ah, AR_RX_FILTER);
3995 u32 phybits = REG_READ(ah, AR_PHY_ERR);
3996
3997 if (phybits & AR_PHY_ERR_RADAR)
3998 bits |= ATH9K_RX_FILTER_PHYRADAR;
3999 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
4000 bits |= ATH9K_RX_FILTER_PHYERR;
4001
4002 return bits;
4003}
4004
Sujithcbe61d82009-02-09 13:27:12 +05304005void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
Sujithf1dc5602008-10-29 10:16:30 +05304006{
4007 u32 phybits;
4008
Sujith7ea310b2009-09-03 12:08:43 +05304009 REG_WRITE(ah, AR_RX_FILTER, bits);
4010
Sujithf1dc5602008-10-29 10:16:30 +05304011 phybits = 0;
4012 if (bits & ATH9K_RX_FILTER_PHYRADAR)
4013 phybits |= AR_PHY_ERR_RADAR;
4014 if (bits & ATH9K_RX_FILTER_PHYERR)
4015 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
4016 REG_WRITE(ah, AR_PHY_ERR, phybits);
4017
4018 if (phybits)
4019 REG_WRITE(ah, AR_RXCFG,
4020 REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
4021 else
4022 REG_WRITE(ah, AR_RXCFG,
4023 REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
4024}
4025
Sujithcbe61d82009-02-09 13:27:12 +05304026bool ath9k_hw_phy_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304027{
4028 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM);
4029}
4030
Sujithcbe61d82009-02-09 13:27:12 +05304031bool ath9k_hw_disable(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304032{
4033 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
4034 return false;
4035
4036 return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD);
4037}
4038
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004039void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
Sujithf1dc5602008-10-29 10:16:30 +05304040{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004041 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujith2660b812009-02-09 13:27:26 +05304042 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08004043 struct ieee80211_channel *channel = chan->chan;
Sujithf1dc5602008-10-29 10:16:30 +05304044
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004045 regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
Sujithf1dc5602008-10-29 10:16:30 +05304046
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004047 ah->eep_ops->set_txpower(ah, chan,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004048 ath9k_regd_get_ctl(regulatory, chan),
Vasanthakumar Thiagarajan8fbff4b2009-05-08 17:54:51 -07004049 channel->max_antenna_gain * 2,
4050 channel->max_power * 2,
4051 min((u32) MAX_RATE_POWER,
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07004052 (u32) regulatory->power_limit));
Sujithf1dc5602008-10-29 10:16:30 +05304053}
4054
Sujithcbe61d82009-02-09 13:27:12 +05304055void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
Sujithf1dc5602008-10-29 10:16:30 +05304056{
Sujithba52da52009-02-09 13:27:10 +05304057 memcpy(ah->macaddr, mac, ETH_ALEN);
Sujithf1dc5602008-10-29 10:16:30 +05304058}
4059
Sujithcbe61d82009-02-09 13:27:12 +05304060void ath9k_hw_setopmode(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304061{
Sujith2660b812009-02-09 13:27:26 +05304062 ath9k_hw_set_operating_mode(ah, ah->opmode);
Sujithf1dc5602008-10-29 10:16:30 +05304063}
4064
Sujithcbe61d82009-02-09 13:27:12 +05304065void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
Sujithf1dc5602008-10-29 10:16:30 +05304066{
4067 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
4068 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
4069}
4070
Sujithba52da52009-02-09 13:27:10 +05304071void ath9k_hw_setbssidmask(struct ath_softc *sc)
Sujithf1dc5602008-10-29 10:16:30 +05304072{
Sujithba52da52009-02-09 13:27:10 +05304073 REG_WRITE(sc->sc_ah, AR_BSSMSKL, get_unaligned_le32(sc->bssidmask));
4074 REG_WRITE(sc->sc_ah, AR_BSSMSKU, get_unaligned_le16(sc->bssidmask + 4));
Sujithf1dc5602008-10-29 10:16:30 +05304075}
4076
Sujithba52da52009-02-09 13:27:10 +05304077void ath9k_hw_write_associd(struct ath_softc *sc)
Sujithf1dc5602008-10-29 10:16:30 +05304078{
Sujithba52da52009-02-09 13:27:10 +05304079 REG_WRITE(sc->sc_ah, AR_BSS_ID0, get_unaligned_le32(sc->curbssid));
4080 REG_WRITE(sc->sc_ah, AR_BSS_ID1, get_unaligned_le16(sc->curbssid + 4) |
4081 ((sc->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
Sujithf1dc5602008-10-29 10:16:30 +05304082}
4083
Sujithcbe61d82009-02-09 13:27:12 +05304084u64 ath9k_hw_gettsf64(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304085{
4086 u64 tsf;
4087
4088 tsf = REG_READ(ah, AR_TSF_U32);
4089 tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
4090
4091 return tsf;
4092}
4093
Sujithcbe61d82009-02-09 13:27:12 +05304094void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004095{
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004096 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
Alina Friedrichsenb9a16192009-03-02 23:28:38 +01004097 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
Alina Friedrichsen27abe062009-01-23 05:44:21 +01004098}
4099
Sujithcbe61d82009-02-09 13:27:12 +05304100void ath9k_hw_reset_tsf(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05304101{
Gabor Juhos1b7e5282009-06-21 00:02:14 +02004102 ath9k_ps_wakeup(ah->ah_sc);
Gabor Juhosf9b604f2009-06-21 00:02:15 +02004103 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
4104 AH_TSF_WRITE_TIMEOUT))
4105 DPRINTF(ah->ah_sc, ATH_DBG_RESET,
4106 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
4107
Sujithf1dc5602008-10-29 10:16:30 +05304108 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
Gabor Juhos1b7e5282009-06-21 00:02:14 +02004109 ath9k_ps_restore(ah->ah_sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004110}
4111
Sujith54e4cec2009-08-07 09:45:09 +05304112void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004113{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004114 if (setting)
Sujith2660b812009-02-09 13:27:26 +05304115 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004116 else
Sujith2660b812009-02-09 13:27:26 +05304117 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004118}
4119
Sujithcbe61d82009-02-09 13:27:12 +05304120bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004121{
Sujithf1dc5602008-10-29 10:16:30 +05304122 if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
Sujith04bd4632008-11-28 22:18:05 +05304123 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad slot time %u\n", us);
Sujith2660b812009-02-09 13:27:26 +05304124 ah->slottime = (u32) -1;
Sujithf1dc5602008-10-29 10:16:30 +05304125 return false;
4126 } else {
4127 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
Sujith2660b812009-02-09 13:27:26 +05304128 ah->slottime = us;
Sujithf1dc5602008-10-29 10:16:30 +05304129 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004130 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004131}
4132
Sujithcbe61d82009-02-09 13:27:12 +05304133void ath9k_hw_set11nmac2040(struct ath_hw *ah, enum ath9k_ht_macmode mode)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004134{
Sujithf1dc5602008-10-29 10:16:30 +05304135 u32 macmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004136
Sujithf1dc5602008-10-29 10:16:30 +05304137 if (mode == ATH9K_HT_MACMODE_2040 &&
Sujith2660b812009-02-09 13:27:26 +05304138 !ah->config.cwm_ignore_extcca)
Sujithf1dc5602008-10-29 10:16:30 +05304139 macmode = AR_2040_JOINED_RX_CLEAR;
4140 else
4141 macmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004142
Sujithf1dc5602008-10-29 10:16:30 +05304143 REG_WRITE(ah, AR_2040_MODE, macmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07004144}
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304145
4146/* HW Generic timers configuration */
4147
4148static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
4149{
4150 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4151 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4152 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4153 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4154 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4155 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4156 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4157 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
4158 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
4159 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
4160 AR_NDP2_TIMER_MODE, 0x0002},
4161 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
4162 AR_NDP2_TIMER_MODE, 0x0004},
4163 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
4164 AR_NDP2_TIMER_MODE, 0x0008},
4165 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
4166 AR_NDP2_TIMER_MODE, 0x0010},
4167 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
4168 AR_NDP2_TIMER_MODE, 0x0020},
4169 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
4170 AR_NDP2_TIMER_MODE, 0x0040},
4171 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
4172 AR_NDP2_TIMER_MODE, 0x0080}
4173};
4174
4175/* HW generic timer primitives */
4176
4177/* compute and clear index of rightmost 1 */
4178static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
4179{
4180 u32 b;
4181
4182 b = *mask;
4183 b &= (0-b);
4184 *mask &= ~b;
4185 b *= debruijn32;
4186 b >>= 27;
4187
4188 return timer_table->gen_timer_index[b];
4189}
4190
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05304191u32 ath9k_hw_gettsf32(struct ath_hw *ah)
Vasanthakumar Thiagarajanff155a42009-08-26 21:08:49 +05304192{
4193 return REG_READ(ah, AR_TSF_L32);
4194}
4195
4196struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
4197 void (*trigger)(void *),
4198 void (*overflow)(void *),
4199 void *arg,
4200 u8 timer_index)
4201{
4202 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4203 struct ath_gen_timer *timer;
4204
4205 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
4206
4207 if (timer == NULL) {
4208 printk(KERN_DEBUG "Failed to allocate memory"
4209 "for hw timer[%d]\n", timer_index);
4210 return NULL;
4211 }
4212
4213 /* allocate a hardware generic timer slot */
4214 timer_table->timers[timer_index] = timer;
4215 timer->index = timer_index;
4216 timer->trigger = trigger;
4217 timer->overflow = overflow;
4218 timer->arg = arg;
4219
4220 return timer;
4221}
4222
4223void ath_gen_timer_start(struct ath_hw *ah,
4224 struct ath_gen_timer *timer,
4225 u32 timer_next, u32 timer_period)
4226{
4227 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4228 u32 tsf;
4229
4230 BUG_ON(!timer_period);
4231
4232 set_bit(timer->index, &timer_table->timer_mask.timer_bits);
4233
4234 tsf = ath9k_hw_gettsf32(ah);
4235
4236 DPRINTF(ah->ah_sc, ATH_DBG_HWTIMER, "curent tsf %x period %x"
4237 "timer_next %x\n", tsf, timer_period, timer_next);
4238
4239 /*
4240 * Pull timer_next forward if the current TSF already passed it
4241 * because of software latency
4242 */
4243 if (timer_next < tsf)
4244 timer_next = tsf + timer_period;
4245
4246 /*
4247 * Program generic timer registers
4248 */
4249 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
4250 timer_next);
4251 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
4252 timer_period);
4253 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4254 gen_tmr_configuration[timer->index].mode_mask);
4255
4256 /* Enable both trigger and thresh interrupt masks */
4257 REG_SET_BIT(ah, AR_IMR_S5,
4258 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4259 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
4260
4261 if ((ah->ah_sc->imask & ATH9K_INT_GENTIMER) == 0) {
4262 ath9k_hw_set_interrupts(ah, 0);
4263 ah->ah_sc->imask |= ATH9K_INT_GENTIMER;
4264 ath9k_hw_set_interrupts(ah, ah->ah_sc->imask);
4265 }
4266}
4267
4268void ath_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
4269{
4270 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4271
4272 if ((timer->index < AR_FIRST_NDP_TIMER) ||
4273 (timer->index >= ATH_MAX_GEN_TIMER)) {
4274 return;
4275 }
4276
4277 /* Clear generic timer enable bits. */
4278 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
4279 gen_tmr_configuration[timer->index].mode_mask);
4280
4281 /* Disable both trigger and thresh interrupt masks */
4282 REG_CLR_BIT(ah, AR_IMR_S5,
4283 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
4284 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
4285
4286 clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
4287
4288 /* if no timer is enabled, turn off interrupt mask */
4289 if (timer_table->timer_mask.val == 0) {
4290 ath9k_hw_set_interrupts(ah, 0);
4291 ah->ah_sc->imask &= ~ATH9K_INT_GENTIMER;
4292 ath9k_hw_set_interrupts(ah, ah->ah_sc->imask);
4293 }
4294}
4295
4296void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
4297{
4298 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4299
4300 /* free the hardware generic timer slot */
4301 timer_table->timers[timer->index] = NULL;
4302 kfree(timer);
4303}
4304
4305/*
4306 * Generic Timer Interrupts handling
4307 */
4308void ath_gen_timer_isr(struct ath_hw *ah)
4309{
4310 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
4311 struct ath_gen_timer *timer;
4312 u32 trigger_mask, thresh_mask, index;
4313
4314 /* get hardware generic timer interrupt status */
4315 trigger_mask = ah->intr_gen_timer_trigger;
4316 thresh_mask = ah->intr_gen_timer_thresh;
4317 trigger_mask &= timer_table->timer_mask.val;
4318 thresh_mask &= timer_table->timer_mask.val;
4319
4320 trigger_mask &= ~thresh_mask;
4321
4322 while (thresh_mask) {
4323 index = rightmost_index(timer_table, &thresh_mask);
4324 timer = timer_table->timers[index];
4325 BUG_ON(!timer);
4326 DPRINTF(ah->ah_sc, ATH_DBG_HWTIMER,
4327 "TSF overflow for Gen timer %d\n", index);
4328 timer->overflow(timer->arg);
4329 }
4330
4331 while (trigger_mask) {
4332 index = rightmost_index(timer_table, &trigger_mask);
4333 timer = timer_table->timers[index];
4334 BUG_ON(!timer);
4335 DPRINTF(ah->ah_sc, ATH_DBG_HWTIMER,
4336 "Gen timer[%d] trigger\n", index);
4337 timer->trigger(timer->arg);
4338 }
4339}
Vasanthakumar Thiagarajan7b6840a2009-09-07 17:46:49 +05304340
4341/*
4342 * Primitive to disable ASPM
4343 */
4344void ath_pcie_aspm_disable(struct ath_softc *sc)
4345{
4346 struct pci_dev *pdev = to_pci_dev(sc->dev);
4347 u8 aspm;
4348
4349 pci_read_config_byte(pdev, ATH_PCIE_CAP_LINK_CTRL, &aspm);
4350 aspm &= ~(ATH_PCIE_CAP_LINK_L0S | ATH_PCIE_CAP_LINK_L1);
4351 pci_write_config_byte(pdev, ATH_PCIE_CAP_LINK_CTRL, aspm);
4352}