blob: f4d383e956a00a9b274ffaa1d02ec1596566308a [file] [log] [blame]
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001 /*
2 * Copyright (c) 2004-2007 Reyk Floeter <reyk@openbsd.org>
3 * Copyright (c) 2006-2007 Nick Kossifidis <mickflemm@gmail.com>
4 * Copyright (c) 2007 Matthew W. S. Bell <mentor@madwifi.org>
5 * Copyright (c) 2007 Luis Rodriguez <mcgrof@winlab.rutgers.edu>
6 * Copyright (c) 2007 Pavel Roskin <proski@gnu.org>
7 * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
8 *
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 *
21 */
22
23/*
24 * HW related functions for Atheros Wireless LAN devices.
25 */
26
27#include <linux/pci.h>
28#include <linux/delay.h>
29
30#include "reg.h"
31#include "base.h"
32#include "debug.h"
33
34/*Rate tables*/
35static const struct ath5k_rate_table ath5k_rt_11a = AR5K_RATES_11A;
36static const struct ath5k_rate_table ath5k_rt_11b = AR5K_RATES_11B;
37static const struct ath5k_rate_table ath5k_rt_11g = AR5K_RATES_11G;
38static const struct ath5k_rate_table ath5k_rt_turbo = AR5K_RATES_TURBO;
39static const struct ath5k_rate_table ath5k_rt_xr = AR5K_RATES_XR;
40
41/*Prototypes*/
42static int ath5k_hw_nic_reset(struct ath5k_hw *, u32);
43static int ath5k_hw_nic_wakeup(struct ath5k_hw *, int, bool);
44static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
45 unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
46 unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
47 unsigned int, unsigned int);
Jiri Slabyb9887632008-02-15 21:58:52 +010048static int ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
Jiri Slabyfa1c1142007-08-12 17:33:16 +020049 unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
50 unsigned int);
51static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *, struct ath5k_desc *);
52static int ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
53 unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
54 unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
55 unsigned int, unsigned int);
56static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *, struct ath5k_desc *);
57static int ath5k_hw_proc_new_rx_status(struct ath5k_hw *, struct ath5k_desc *);
58static int ath5k_hw_proc_old_rx_status(struct ath5k_hw *, struct ath5k_desc *);
59static int ath5k_hw_get_capabilities(struct ath5k_hw *);
60
61static int ath5k_eeprom_init(struct ath5k_hw *);
62static int ath5k_eeprom_read_mac(struct ath5k_hw *, u8 *);
63
64static int ath5k_hw_enable_pspoll(struct ath5k_hw *, u8 *, u16);
65static int ath5k_hw_disable_pspoll(struct ath5k_hw *);
66
67/*
68 * Enable to overwrite the country code (use "00" for debug)
69 */
70#if 0
71#define COUNTRYCODE "00"
72#endif
73
74/*******************\
75 General Functions
76\*******************/
77
78/*
79 * Functions used internaly
80 */
81
82static inline unsigned int ath5k_hw_htoclock(unsigned int usec, bool turbo)
83{
84 return turbo == true ? (usec * 80) : (usec * 40);
85}
86
87static inline unsigned int ath5k_hw_clocktoh(unsigned int clock, bool turbo)
88{
89 return turbo == true ? (clock / 80) : (clock / 40);
90}
91
92/*
93 * Check if a register write has been completed
94 */
95int ath5k_hw_register_timeout(struct ath5k_hw *ah, u32 reg, u32 flag, u32 val,
96 bool is_set)
97{
98 int i;
99 u32 data;
100
101 for (i = AR5K_TUNE_REGISTER_TIMEOUT; i > 0; i--) {
102 data = ath5k_hw_reg_read(ah, reg);
103 if ((is_set == true) && (data & flag))
104 break;
105 else if ((data & flag) == val)
106 break;
107 udelay(15);
108 }
109
110 return (i <= 0) ? -EAGAIN : 0;
111}
112
113
114/***************************************\
115 Attach/Detach Functions
116\***************************************/
117
118/*
119 * Check if the device is supported and initialize the needed structs
120 */
121struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
122{
123 struct ath5k_hw *ah;
124 u8 mac[ETH_ALEN];
125 int ret;
126 u32 srev;
127
128 /*If we passed the test malloc a ath5k_hw struct*/
129 ah = kzalloc(sizeof(struct ath5k_hw), GFP_KERNEL);
130 if (ah == NULL) {
131 ret = -ENOMEM;
132 ATH5K_ERR(sc, "out of memory\n");
133 goto err;
134 }
135
136 ah->ah_sc = sc;
137 ah->ah_iobase = sc->iobase;
138
139 /*
140 * HW information
141 */
142
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200143 ah->ah_op_mode = IEEE80211_IF_TYPE_STA;
144 ah->ah_radar.r_enabled = AR5K_TUNE_RADAR_ALERT;
145 ah->ah_turbo = false;
146 ah->ah_txpower.txp_tpc = AR5K_TUNE_TPC_TXPOWER;
147 ah->ah_imr = 0;
148 ah->ah_atim_window = 0;
149 ah->ah_aifs = AR5K_TUNE_AIFS;
150 ah->ah_cw_min = AR5K_TUNE_CWMIN;
151 ah->ah_limit_tx_retries = AR5K_INIT_TX_RETRY;
152 ah->ah_software_retry = false;
153 ah->ah_ant_diversity = AR5K_TUNE_ANT_DIVERSITY;
154
155 /*
156 * Set the mac revision based on the pci id
157 */
158 ah->ah_version = mac_version;
159
160 /*Fill the ath5k_hw struct with the needed functions*/
161 if (ah->ah_version == AR5K_AR5212)
162 ah->ah_magic = AR5K_EEPROM_MAGIC_5212;
163 else if (ah->ah_version == AR5K_AR5211)
164 ah->ah_magic = AR5K_EEPROM_MAGIC_5211;
165
166 if (ah->ah_version == AR5K_AR5212) {
167 ah->ah_setup_tx_desc = ath5k_hw_setup_4word_tx_desc;
168 ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
169 ah->ah_proc_tx_desc = ath5k_hw_proc_4word_tx_status;
170 } else {
171 ah->ah_setup_tx_desc = ath5k_hw_setup_2word_tx_desc;
172 ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
173 ah->ah_proc_tx_desc = ath5k_hw_proc_2word_tx_status;
174 }
175
176 if (ah->ah_version == AR5K_AR5212)
177 ah->ah_proc_rx_desc = ath5k_hw_proc_new_rx_status;
178 else if (ah->ah_version <= AR5K_AR5211)
179 ah->ah_proc_rx_desc = ath5k_hw_proc_old_rx_status;
180
181 /* Bring device out of sleep and reset it's units */
182 ret = ath5k_hw_nic_wakeup(ah, AR5K_INIT_MODE, true);
183 if (ret)
184 goto err_free;
185
186 /* Get MAC, PHY and RADIO revisions */
187 srev = ath5k_hw_reg_read(ah, AR5K_SREV);
188 ah->ah_mac_srev = srev;
189 ah->ah_mac_version = AR5K_REG_MS(srev, AR5K_SREV_VER);
190 ah->ah_mac_revision = AR5K_REG_MS(srev, AR5K_SREV_REV);
191 ah->ah_phy_revision = ath5k_hw_reg_read(ah, AR5K_PHY_CHIP_ID) &
192 0xffffffff;
193 ah->ah_radio_5ghz_revision = ath5k_hw_radio_revision(ah,
194 CHANNEL_5GHZ);
195
196 if (ah->ah_version == AR5K_AR5210)
197 ah->ah_radio_2ghz_revision = 0;
198 else
199 ah->ah_radio_2ghz_revision = ath5k_hw_radio_revision(ah,
200 CHANNEL_2GHZ);
201
202 /* Return on unsuported chips (unsupported eeprom etc) */
203 if(srev >= AR5K_SREV_VER_AR5416){
204 ATH5K_ERR(sc, "Device not yet supported.\n");
205 ret = -ENODEV;
206 goto err_free;
207 }
208
209 /* Identify single chip solutions */
210 if((srev <= AR5K_SREV_VER_AR5414) &&
Nick Kossifidis0af22562008-02-28 14:49:05 -0500211 (srev >= AR5K_SREV_VER_AR2413)) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200212 ah->ah_single_chip = true;
213 } else {
214 ah->ah_single_chip = false;
215 }
216
217 /* Single chip radio */
218 if (ah->ah_radio_2ghz_revision == ah->ah_radio_5ghz_revision)
219 ah->ah_radio_2ghz_revision = 0;
220
221 /* Identify the radio chip*/
222 if (ah->ah_version == AR5K_AR5210) {
223 ah->ah_radio = AR5K_RF5110;
224 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112) {
225 ah->ah_radio = AR5K_RF5111;
Nick Kossifidis0af22562008-02-28 14:49:05 -0500226 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5111;
227 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC0) {
228
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200229 ah->ah_radio = AR5K_RF5112;
Nick Kossifidis0af22562008-02-28 14:49:05 -0500230
231 if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112A) {
232 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112;
233 } else {
234 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
235 }
236
237 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC1) {
238 ah->ah_radio = AR5K_RF2413;
239 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200240 } else {
Nick Kossifidis0af22562008-02-28 14:49:05 -0500241
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200242 ah->ah_radio = AR5K_RF5413;
Nick Kossifidis0af22562008-02-28 14:49:05 -0500243
244 if (ah->ah_mac_srev <= AR5K_SREV_VER_AR5424 &&
245 ah->ah_mac_srev >= AR5K_SREV_VER_AR2424)
246 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5424;
247 else if (ah->ah_mac_srev >= AR5K_SREV_VER_AR2425)
248 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112;
249 else
250 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
251
252
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200253 }
254
255 ah->ah_phy = AR5K_PHY(0);
256
257 /*
258 * Get card capabilities, values, ...
259 */
260
261 ret = ath5k_eeprom_init(ah);
262 if (ret) {
263 ATH5K_ERR(sc, "unable to init EEPROM\n");
264 goto err_free;
265 }
266
267 /* Get misc capabilities */
268 ret = ath5k_hw_get_capabilities(ah);
269 if (ret) {
270 ATH5K_ERR(sc, "unable to get device capabilities: 0x%04x\n",
271 sc->pdev->device);
272 goto err_free;
273 }
274
275 /* Get MAC address */
276 ret = ath5k_eeprom_read_mac(ah, mac);
277 if (ret) {
278 ATH5K_ERR(sc, "unable to read address from EEPROM: 0x%04x\n",
279 sc->pdev->device);
280 goto err_free;
281 }
282
283 ath5k_hw_set_lladdr(ah, mac);
284 /* Set BSSID to bcast address: ff:ff:ff:ff:ff:ff for now */
285 memset(ah->ah_bssid, 0xff, ETH_ALEN);
286 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
287 ath5k_hw_set_opmode(ah);
288
289 ath5k_hw_set_rfgain_opt(ah);
290
291 return ah;
292err_free:
293 kfree(ah);
294err:
295 return ERR_PTR(ret);
296}
297
298/*
299 * Bring up MAC + PHY Chips
300 */
301static int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
302{
303 u32 turbo, mode, clock;
304 int ret;
305
306 turbo = 0;
307 mode = 0;
308 clock = 0;
309
310 ATH5K_TRACE(ah->ah_sc);
311
312 /* Wakeup the device */
313 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
314 if (ret) {
315 ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
316 return ret;
317 }
318
319 if (ah->ah_version != AR5K_AR5210) {
320 /*
321 * Get channel mode flags
322 */
323
324 if (ah->ah_radio >= AR5K_RF5112) {
325 mode = AR5K_PHY_MODE_RAD_RF5112;
326 clock = AR5K_PHY_PLL_RF5112;
327 } else {
328 mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
329 clock = AR5K_PHY_PLL_RF5111; /*Zero*/
330 }
331
332 if (flags & CHANNEL_2GHZ) {
333 mode |= AR5K_PHY_MODE_FREQ_2GHZ;
334 clock |= AR5K_PHY_PLL_44MHZ;
335
336 if (flags & CHANNEL_CCK) {
337 mode |= AR5K_PHY_MODE_MOD_CCK;
338 } else if (flags & CHANNEL_OFDM) {
339 /* XXX Dynamic OFDM/CCK is not supported by the
340 * AR5211 so we set MOD_OFDM for plain g (no
341 * CCK headers) operation. We need to test
342 * this, 5211 might support ofdm-only g after
343 * all, there are also initial register values
344 * in the code for g mode (see initvals.c). */
345 if (ah->ah_version == AR5K_AR5211)
346 mode |= AR5K_PHY_MODE_MOD_OFDM;
347 else
348 mode |= AR5K_PHY_MODE_MOD_DYN;
349 } else {
350 ATH5K_ERR(ah->ah_sc,
351 "invalid radio modulation mode\n");
352 return -EINVAL;
353 }
354 } else if (flags & CHANNEL_5GHZ) {
355 mode |= AR5K_PHY_MODE_FREQ_5GHZ;
356 clock |= AR5K_PHY_PLL_40MHZ;
357
358 if (flags & CHANNEL_OFDM)
359 mode |= AR5K_PHY_MODE_MOD_OFDM;
360 else {
361 ATH5K_ERR(ah->ah_sc,
362 "invalid radio modulation mode\n");
363 return -EINVAL;
364 }
365 } else {
366 ATH5K_ERR(ah->ah_sc, "invalid radio frequency mode\n");
367 return -EINVAL;
368 }
369
370 if (flags & CHANNEL_TURBO)
371 turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
372 } else { /* Reset the device */
373
374 /* ...enable Atheros turbo mode if requested */
375 if (flags & CHANNEL_TURBO)
376 ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
377 AR5K_PHY_TURBO);
378 }
379
380 /* ...reset chipset and PCI device */
381 if (ah->ah_single_chip == false && ath5k_hw_nic_reset(ah,
382 AR5K_RESET_CTL_CHIP | AR5K_RESET_CTL_PCI)) {
383 ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip + PCI\n");
384 return -EIO;
385 }
386
387 if (ah->ah_version == AR5K_AR5210)
388 udelay(2300);
389
390 /* ...wakeup again!*/
391 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
392 if (ret) {
393 ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
394 return ret;
395 }
396
397 /* ...final warm reset */
398 if (ath5k_hw_nic_reset(ah, 0)) {
399 ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
400 return -EIO;
401 }
402
403 if (ah->ah_version != AR5K_AR5210) {
404 /* ...set the PHY operating mode */
405 ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
406 udelay(300);
407
408 ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
409 ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
410 }
411
412 return 0;
413}
414
415/*
416 * Get the rate table for a specific operation mode
417 */
418const struct ath5k_rate_table *ath5k_hw_get_rate_table(struct ath5k_hw *ah,
419 unsigned int mode)
420{
421 ATH5K_TRACE(ah->ah_sc);
422
423 if (!test_bit(mode, ah->ah_capabilities.cap_mode))
424 return NULL;
425
426 /* Get rate tables */
427 switch (mode) {
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500428 case AR5K_MODE_11A:
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200429 return &ath5k_rt_11a;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500430 case AR5K_MODE_11A_TURBO:
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200431 return &ath5k_rt_turbo;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500432 case AR5K_MODE_11B:
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200433 return &ath5k_rt_11b;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500434 case AR5K_MODE_11G:
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200435 return &ath5k_rt_11g;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500436 case AR5K_MODE_11G_TURBO:
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200437 return &ath5k_rt_xr;
438 }
439
440 return NULL;
441}
442
443/*
444 * Free the ath5k_hw struct
445 */
446void ath5k_hw_detach(struct ath5k_hw *ah)
447{
448 ATH5K_TRACE(ah->ah_sc);
449
450 if (ah->ah_rf_banks != NULL)
451 kfree(ah->ah_rf_banks);
452
453 /* assume interrupts are down */
454 kfree(ah);
455}
456
457/****************************\
458 Reset function and helpers
459\****************************/
460
461/**
462 * ath5k_hw_write_ofdm_timings - set OFDM timings on AR5212
463 *
464 * @ah: the &struct ath5k_hw
465 * @channel: the currently set channel upon reset
466 *
467 * Write the OFDM timings for the AR5212 upon reset. This is a helper for
468 * ath5k_hw_reset(). This seems to tune the PLL a specified frequency
469 * depending on the bandwidth of the channel.
470 *
471 */
472static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
473 struct ieee80211_channel *channel)
474{
475 /* Get exponent and mantissa and set it */
476 u32 coef_scaled, coef_exp, coef_man,
477 ds_coef_exp, ds_coef_man, clock;
478
479 if (!(ah->ah_version == AR5K_AR5212) ||
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500480 !(channel->hw_value & CHANNEL_OFDM))
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200481 BUG();
482
483 /* Seems there are two PLLs, one for baseband sampling and one
484 * for tuning. Tuning basebands are 40 MHz or 80MHz when in
485 * turbo. */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500486 clock = channel->hw_value & CHANNEL_TURBO ? 80 : 40;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200487 coef_scaled = ((5 * (clock << 24)) / 2) /
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500488 channel->center_freq;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200489
490 for (coef_exp = 31; coef_exp > 0; coef_exp--)
491 if ((coef_scaled >> coef_exp) & 0x1)
492 break;
493
494 if (!coef_exp)
495 return -EINVAL;
496
497 coef_exp = 14 - (coef_exp - 24);
498 coef_man = coef_scaled +
499 (1 << (24 - coef_exp - 1));
500 ds_coef_man = coef_man >> (24 - coef_exp);
501 ds_coef_exp = coef_exp - 16;
502
503 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
504 AR5K_PHY_TIMING_3_DSC_MAN, ds_coef_man);
505 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
506 AR5K_PHY_TIMING_3_DSC_EXP, ds_coef_exp);
507
508 return 0;
509}
510
511/**
512 * ath5k_hw_write_rate_duration - set rate duration during hw resets
513 *
514 * @ah: the &struct ath5k_hw
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500515 * @mode: one of enum ath5k_driver_mode
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200516 *
517 * Write the rate duration table for the current mode upon hw reset. This
518 * is a helper for ath5k_hw_reset(). It seems all this is doing is setting
519 * an ACK timeout for the hardware for the current mode for each rate. The
520 * rates which are capable of short preamble (802.11b rates 2Mbps, 5.5Mbps,
521 * and 11Mbps) have another register for the short preamble ACK timeout
522 * calculation.
523 *
524 */
525static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500526 unsigned int mode)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200527{
528 struct ath5k_softc *sc = ah->ah_sc;
529 const struct ath5k_rate_table *rt;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500530 struct ieee80211_rate srate = {};
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200531 unsigned int i;
532
533 /* Get rate table for the current operating mode */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500534 rt = ath5k_hw_get_rate_table(ah, mode);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200535
536 /* Write rate duration table */
537 for (i = 0; i < rt->rate_count; i++) {
538 const struct ath5k_rate *rate, *control_rate;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500539
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200540 u32 reg;
541 u16 tx_time;
542
543 rate = &rt->rates[i];
544 control_rate = &rt->rates[rate->control_rate];
545
546 /* Set ACK timeout */
547 reg = AR5K_RATE_DUR(rate->rate_code);
548
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500549 srate.bitrate = control_rate->rate_kbps/100;
550
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200551 /* An ACK frame consists of 10 bytes. If you add the FCS,
552 * which ieee80211_generic_frame_duration() adds,
553 * its 14 bytes. Note we use the control rate and not the
554 * actual rate for this rate. See mac80211 tx.c
555 * ieee80211_duration() for a brief description of
556 * what rate we should choose to TX ACKs. */
Pavel Roskin38c07b42008-02-26 17:59:14 -0500557 tx_time = le16_to_cpu(ieee80211_generic_frame_duration(sc->hw,
558 sc->vif, 10, &srate));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200559
560 ath5k_hw_reg_write(ah, tx_time, reg);
561
562 if (!HAS_SHPREAMBLE(i))
563 continue;
564
565 /*
566 * We're not distinguishing short preamble here,
567 * This is true, all we'll get is a longer value here
568 * which is not necessarilly bad. We could use
569 * export ieee80211_frame_duration() but that needs to be
570 * fixed first to be properly used by mac802111 drivers:
571 *
572 * - remove erp stuff and let the routine figure ofdm
573 * erp rates
574 * - remove passing argument ieee80211_local as
575 * drivers don't have access to it
576 * - move drivers using ieee80211_generic_frame_duration()
577 * to this
578 */
579 ath5k_hw_reg_write(ah, tx_time,
580 reg + (AR5K_SET_SHORT_PREAMBLE << 2));
581 }
582}
583
584/*
585 * Main reset function
586 */
587int ath5k_hw_reset(struct ath5k_hw *ah, enum ieee80211_if_types op_mode,
588 struct ieee80211_channel *channel, bool change_channel)
589{
590 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
591 u32 data, s_seq, s_ant, s_led[3];
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500592 unsigned int i, mode, freq, ee_mode, ant[2];
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200593 int ret;
594
595 ATH5K_TRACE(ah->ah_sc);
596
597 s_seq = 0;
598 s_ant = 0;
599 ee_mode = 0;
600 freq = 0;
601 mode = 0;
602
603 /*
604 * Save some registers before a reset
605 */
606 /*DCU/Antenna selection not available on 5210*/
607 if (ah->ah_version != AR5K_AR5210) {
608 if (change_channel == true) {
609 /* Seq number for queue 0 -do this for all queues ? */
610 s_seq = ath5k_hw_reg_read(ah,
611 AR5K_QUEUE_DFS_SEQNUM(0));
612 /*Default antenna*/
613 s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
614 }
615 }
616
617 /*GPIOs*/
618 s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) & AR5K_PCICFG_LEDSTATE;
619 s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
620 s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
621
622 if (change_channel == true && ah->ah_rf_banks != NULL)
623 ath5k_hw_get_rf_gain(ah);
624
625
626 /*Wakeup the device*/
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500627 ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, false);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200628 if (ret)
629 return ret;
630
631 /*
632 * Initialize operating mode
633 */
634 ah->ah_op_mode = op_mode;
635
636 /*
637 * 5111/5112 Settings
638 * 5210 only comes with RF5110
639 */
640 if (ah->ah_version != AR5K_AR5210) {
641 if (ah->ah_radio != AR5K_RF5111 &&
642 ah->ah_radio != AR5K_RF5112 &&
643 ah->ah_radio != AR5K_RF5413) {
644 ATH5K_ERR(ah->ah_sc,
645 "invalid phy radio: %u\n", ah->ah_radio);
646 return -EINVAL;
647 }
648
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500649 switch (channel->hw_value & CHANNEL_MODES) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200650 case CHANNEL_A:
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500651 mode = AR5K_MODE_11A;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200652 freq = AR5K_INI_RFGAIN_5GHZ;
653 ee_mode = AR5K_EEPROM_MODE_11A;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200654 break;
655 case CHANNEL_G:
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500656 mode = AR5K_MODE_11G;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200657 freq = AR5K_INI_RFGAIN_2GHZ;
658 ee_mode = AR5K_EEPROM_MODE_11G;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200659 break;
660 case CHANNEL_B:
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500661 mode = AR5K_MODE_11B;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200662 freq = AR5K_INI_RFGAIN_2GHZ;
663 ee_mode = AR5K_EEPROM_MODE_11B;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200664 break;
665 case CHANNEL_T:
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500666 mode = AR5K_MODE_11A_TURBO;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200667 freq = AR5K_INI_RFGAIN_5GHZ;
668 ee_mode = AR5K_EEPROM_MODE_11A;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200669 break;
670 /*Is this ok on 5211 too ?*/
671 case CHANNEL_TG:
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500672 mode = AR5K_MODE_11G_TURBO;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200673 freq = AR5K_INI_RFGAIN_2GHZ;
674 ee_mode = AR5K_EEPROM_MODE_11G;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200675 break;
676 case CHANNEL_XR:
677 if (ah->ah_version == AR5K_AR5211) {
678 ATH5K_ERR(ah->ah_sc,
679 "XR mode not available on 5211");
680 return -EINVAL;
681 }
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500682 mode = AR5K_MODE_XR;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200683 freq = AR5K_INI_RFGAIN_5GHZ;
684 ee_mode = AR5K_EEPROM_MODE_11A;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200685 break;
686 default:
687 ATH5K_ERR(ah->ah_sc,
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500688 "invalid channel: %d\n", channel->center_freq);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200689 return -EINVAL;
690 }
691
692 /* PHY access enable */
693 ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
694
695 }
696
697 ret = ath5k_hw_write_initvals(ah, mode, change_channel);
698 if (ret)
699 return ret;
700
701 /*
702 * 5211/5212 Specific
703 */
704 if (ah->ah_version != AR5K_AR5210) {
705 /*
706 * Write initial RF gain settings
707 * This should work for both 5111/5112
708 */
709 ret = ath5k_hw_rfgain(ah, freq);
710 if (ret)
711 return ret;
712
713 mdelay(1);
714
715 /*
716 * Write some more initial register settings
717 */
718 if (ah->ah_version > AR5K_AR5211){ /* found on 5213+ */
719 ath5k_hw_reg_write(ah, 0x0002a002, AR5K_PHY(11));
720
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500721 if (channel->hw_value == CHANNEL_G)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200722 ath5k_hw_reg_write(ah, 0x00f80d80, AR5K_PHY(83)); /* 0x00fc0ec0 */
723 else
724 ath5k_hw_reg_write(ah, 0x00000000, AR5K_PHY(83));
725
726 ath5k_hw_reg_write(ah, 0x000001b5, 0xa228); /* 0x000009b5 */
727 ath5k_hw_reg_write(ah, 0x000009b5, 0xa228);
728 ath5k_hw_reg_write(ah, 0x0000000f, 0x8060);
729 ath5k_hw_reg_write(ah, 0x00000000, 0xa254);
730 ath5k_hw_reg_write(ah, 0x0000000e, AR5K_PHY_SCAL);
731 }
732
733 /* Fix for first revision of the RF5112 RF chipset */
734 if (ah->ah_radio >= AR5K_RF5112 &&
735 ah->ah_radio_5ghz_revision <
736 AR5K_SREV_RAD_5112A) {
737 ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
738 AR5K_PHY_CCKTXCTL);
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500739 if (channel->hw_value & CHANNEL_5GHZ)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200740 data = 0xffb81020;
741 else
742 data = 0xffb80d20;
743 ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
744 }
745
746 /*
747 * Set TX power (FIXME)
748 */
749 ret = ath5k_hw_txpower(ah, channel, AR5K_TUNE_DEFAULT_TXPOWER);
750 if (ret)
751 return ret;
752
Luis R. Rodriguez132127e2008-01-04 02:21:05 -0500753 /* Write rate duration table only on AR5212 and if
754 * virtual interface has already been brought up
755 * XXX: rethink this after new mode changes to
756 * mac80211 are integrated */
757 if (ah->ah_version == AR5K_AR5212 &&
758 ah->ah_sc->vif != NULL)
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500759 ath5k_hw_write_rate_duration(ah, mode);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200760
761 /*
762 * Write RF registers
763 * TODO:Does this work on 5211 (5111) ?
764 */
765 ret = ath5k_hw_rfregs(ah, channel, mode);
766 if (ret)
767 return ret;
768
769 /*
770 * Configure additional registers
771 */
772
773 /* Write OFDM timings on 5212*/
774 if (ah->ah_version == AR5K_AR5212 &&
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500775 channel->hw_value & CHANNEL_OFDM) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200776 ret = ath5k_hw_write_ofdm_timings(ah, channel);
777 if (ret)
778 return ret;
779 }
780
781 /*Enable/disable 802.11b mode on 5111
782 (enable 2111 frequency converter + CCK)*/
783 if (ah->ah_radio == AR5K_RF5111) {
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500784 if (mode == AR5K_MODE_11B)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200785 AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
786 AR5K_TXCFG_B_MODE);
787 else
788 AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
789 AR5K_TXCFG_B_MODE);
790 }
791
792 /*
793 * Set channel and calibrate the PHY
794 */
795 ret = ath5k_hw_channel(ah, channel);
796 if (ret)
797 return ret;
798
799 /* Set antenna mode */
800 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x44),
801 ah->ah_antenna[ee_mode][0], 0xfffffc06);
802
803 /*
804 * In case a fixed antenna was set as default
805 * write the same settings on both AR5K_PHY_ANT_SWITCH_TABLE
806 * registers.
807 */
808 if (s_ant != 0){
809 if (s_ant == AR5K_ANT_FIXED_A) /* 1 - Main */
810 ant[0] = ant[1] = AR5K_ANT_FIXED_A;
811 else /* 2 - Aux */
812 ant[0] = ant[1] = AR5K_ANT_FIXED_B;
813 } else {
814 ant[0] = AR5K_ANT_FIXED_A;
815 ant[1] = AR5K_ANT_FIXED_B;
816 }
817
818 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[0]],
819 AR5K_PHY_ANT_SWITCH_TABLE_0);
820 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[1]],
821 AR5K_PHY_ANT_SWITCH_TABLE_1);
822
823 /* Commit values from EEPROM */
824 if (ah->ah_radio == AR5K_RF5111)
825 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_FRAME_CTL,
826 AR5K_PHY_FRAME_CTL_TX_CLIP, ee->ee_tx_clip);
827
828 ath5k_hw_reg_write(ah,
829 AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
830 AR5K_PHY(0x5a));
831
832 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x11),
833 (ee->ee_switch_settling[ee_mode] << 7) & 0x3f80,
834 0xffffc07f);
835 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x12),
836 (ee->ee_ant_tx_rx[ee_mode] << 12) & 0x3f000,
837 0xfffc0fff);
838 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x14),
839 (ee->ee_adc_desired_size[ee_mode] & 0x00ff) |
840 ((ee->ee_pga_desired_size[ee_mode] << 8) & 0xff00),
841 0xffff0000);
842
843 ath5k_hw_reg_write(ah,
844 (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
845 (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
846 (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
847 (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY(0x0d));
848
849 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x0a),
850 ee->ee_tx_end2xlna_enable[ee_mode] << 8, 0xffff00ff);
851 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x19),
852 (ee->ee_thr_62[ee_mode] << 12) & 0x7f000, 0xfff80fff);
853 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x49), 4, 0xffffff01);
854
855 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
856 AR5K_PHY_IQ_CORR_ENABLE |
857 (ee->ee_i_cal[ee_mode] << AR5K_PHY_IQ_CORR_Q_I_COFF_S) |
858 ee->ee_q_cal[ee_mode]);
859
860 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
861 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
862 AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
863 ee->ee_margin_tx_rx[ee_mode]);
864
865 } else {
866 mdelay(1);
867 /* Disable phy and wait */
868 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
869 mdelay(1);
870 }
871
872 /*
873 * Restore saved values
874 */
875 /*DCU/Antenna selection not available on 5210*/
876 if (ah->ah_version != AR5K_AR5210) {
877 ath5k_hw_reg_write(ah, s_seq, AR5K_QUEUE_DFS_SEQNUM(0));
878 ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
879 }
880 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
881 ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
882 ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
883
884 /*
885 * Misc
886 */
887 /* XXX: add ah->aid once mac80211 gives this to us */
888 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
889
890 ath5k_hw_set_opmode(ah);
891 /*PISR/SISR Not available on 5210*/
892 if (ah->ah_version != AR5K_AR5210) {
893 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
894 /* If we later allow tuning for this, store into sc structure */
895 data = AR5K_TUNE_RSSI_THRES |
896 AR5K_TUNE_BMISS_THRES << AR5K_RSSI_THR_BMISS_S;
897 ath5k_hw_reg_write(ah, data, AR5K_RSSI_THR);
898 }
899
900 /*
901 * Set Rx/Tx DMA Configuration
902 *(passing dma size not available on 5210)
903 */
904 if (ah->ah_version != AR5K_AR5210) {
905 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG, AR5K_TXCFG_SDMAMR,
906 AR5K_DMASIZE_512B | AR5K_TXCFG_DMASIZE);
907 AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_SDMAMW,
908 AR5K_DMASIZE_512B);
909 }
910
911 /*
912 * Enable the PHY and wait until completion
913 */
914 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
915
916 /*
917 * 5111/5112 Specific
918 */
919 if (ah->ah_version != AR5K_AR5210) {
920 data = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
921 AR5K_PHY_RX_DELAY_M;
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500922 data = (channel->hw_value & CHANNEL_CCK) ?
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200923 ((data << 2) / 22) : (data / 10);
924
925 udelay(100 + data);
926 } else {
927 mdelay(1);
928 }
929
930 /*
931 * Enable calibration and wait until completion
932 */
933 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
934 AR5K_PHY_AGCCTL_CAL);
935
936 if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
937 AR5K_PHY_AGCCTL_CAL, 0, false)) {
938 ATH5K_ERR(ah->ah_sc, "calibration timeout (%uMHz)\n",
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500939 channel->center_freq);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200940 return -EAGAIN;
941 }
942
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500943 ret = ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200944 if (ret)
945 return ret;
946
947 ah->ah_calibration = false;
948
949 /* A and G modes can use QAM modulation which requires enabling
950 * I and Q calibration. Don't bother in B mode. */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -0500951 if (!(mode == AR5K_MODE_11B)) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200952 ah->ah_calibration = true;
953 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
954 AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
955 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
956 AR5K_PHY_IQ_RUN);
957 }
958
959 /*
960 * Reset queues and start beacon timers at the end of the reset routine
961 */
962 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
963 /*No QCU on 5210*/
964 if (ah->ah_version != AR5K_AR5210)
965 AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(i), i);
966
967 ret = ath5k_hw_reset_tx_queue(ah, i);
968 if (ret) {
969 ATH5K_ERR(ah->ah_sc,
970 "failed to reset TX queue #%d\n", i);
971 return ret;
972 }
973 }
974
975 /* Pre-enable interrupts on 5211/5212*/
976 if (ah->ah_version != AR5K_AR5210)
977 ath5k_hw_set_intr(ah, AR5K_INT_RX | AR5K_INT_TX |
978 AR5K_INT_FATAL);
979
980 /*
981 * Set RF kill flags if supported by the device (read from the EEPROM)
982 * Disable gpio_intr for now since it results system hang.
983 * TODO: Handle this in ath5k_intr
984 */
985#if 0
986 if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header)) {
987 ath5k_hw_set_gpio_input(ah, 0);
988 ah->ah_gpio[0] = ath5k_hw_get_gpio(ah, 0);
989 if (ah->ah_gpio[0] == 0)
990 ath5k_hw_set_gpio_intr(ah, 0, 1);
991 else
992 ath5k_hw_set_gpio_intr(ah, 0, 0);
993 }
994#endif
995
996 /*
997 * Set the 32MHz reference clock on 5212 phy clock sleep register
998 */
999 if (ah->ah_version == AR5K_AR5212) {
1000 ath5k_hw_reg_write(ah, AR5K_PHY_SCR_32MHZ, AR5K_PHY_SCR);
1001 ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
1002 ath5k_hw_reg_write(ah, AR5K_PHY_SCAL_32MHZ, AR5K_PHY_SCAL);
1003 ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
1004 ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
1005 ath5k_hw_reg_write(ah, ah->ah_radio == AR5K_RF5111 ?
1006 AR5K_PHY_SPENDING_RF5111 : AR5K_PHY_SPENDING_RF5112,
1007 AR5K_PHY_SPENDING);
1008 }
1009
1010 /*
1011 * Disable beacons and reset the register
1012 */
1013 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
1014 AR5K_BEACON_RESET_TSF);
1015
1016 return 0;
1017}
1018
1019/*
1020 * Reset chipset
1021 */
1022static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
1023{
1024 int ret;
1025 u32 mask = val ? val : ~0U;
1026
1027 ATH5K_TRACE(ah->ah_sc);
1028
1029 /* Read-and-clear RX Descriptor Pointer*/
1030 ath5k_hw_reg_read(ah, AR5K_RXDP);
1031
1032 /*
1033 * Reset the device and wait until success
1034 */
1035 ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
1036
1037 /* Wait at least 128 PCI clocks */
1038 udelay(15);
1039
1040 if (ah->ah_version == AR5K_AR5210) {
1041 val &= AR5K_RESET_CTL_CHIP;
1042 mask &= AR5K_RESET_CTL_CHIP;
1043 } else {
1044 val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1045 mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1046 }
1047
1048 ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, false);
1049
1050 /*
1051 * Reset configuration register (for hw byte-swap). Note that this
1052 * is only set for big endian. We do the necessary magic in
1053 * AR5K_INIT_CFG.
1054 */
1055 if ((val & AR5K_RESET_CTL_PCU) == 0)
1056 ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
1057
1058 return ret;
1059}
1060
1061/*
1062 * Power management functions
1063 */
1064
1065/*
1066 * Sleep control
1067 */
1068int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
1069 bool set_chip, u16 sleep_duration)
1070{
1071 unsigned int i;
1072 u32 staid;
1073
1074 ATH5K_TRACE(ah->ah_sc);
1075 staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
1076
1077 switch (mode) {
1078 case AR5K_PM_AUTO:
1079 staid &= ~AR5K_STA_ID1_DEFAULT_ANTENNA;
1080 /* fallthrough */
1081 case AR5K_PM_NETWORK_SLEEP:
1082 if (set_chip == true)
1083 ath5k_hw_reg_write(ah,
1084 AR5K_SLEEP_CTL_SLE | sleep_duration,
1085 AR5K_SLEEP_CTL);
1086
1087 staid |= AR5K_STA_ID1_PWR_SV;
1088 break;
1089
1090 case AR5K_PM_FULL_SLEEP:
1091 if (set_chip == true)
1092 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_SLP,
1093 AR5K_SLEEP_CTL);
1094
1095 staid |= AR5K_STA_ID1_PWR_SV;
1096 break;
1097
1098 case AR5K_PM_AWAKE:
1099 if (set_chip == false)
1100 goto commit;
1101
1102 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1103 AR5K_SLEEP_CTL);
1104
1105 for (i = 5000; i > 0; i--) {
1106 /* Check if the chip did wake up */
1107 if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
1108 AR5K_PCICFG_SPWR_DN) == 0)
1109 break;
1110
1111 /* Wait a bit and retry */
1112 udelay(200);
1113 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1114 AR5K_SLEEP_CTL);
1115 }
1116
1117 /* Fail if the chip didn't wake up */
1118 if (i <= 0)
1119 return -EIO;
1120
1121 staid &= ~AR5K_STA_ID1_PWR_SV;
1122 break;
1123
1124 default:
1125 return -EINVAL;
1126 }
1127
1128commit:
1129 ah->ah_power_mode = mode;
1130 ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
1131
1132 return 0;
1133}
1134
1135/***********************\
1136 DMA Related Functions
1137\***********************/
1138
1139/*
1140 * Receive functions
1141 */
1142
1143/*
1144 * Start DMA receive
1145 */
1146void ath5k_hw_start_rx(struct ath5k_hw *ah)
1147{
1148 ATH5K_TRACE(ah->ah_sc);
1149 ath5k_hw_reg_write(ah, AR5K_CR_RXE, AR5K_CR);
1150}
1151
1152/*
1153 * Stop DMA receive
1154 */
1155int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
1156{
1157 unsigned int i;
1158
1159 ATH5K_TRACE(ah->ah_sc);
1160 ath5k_hw_reg_write(ah, AR5K_CR_RXD, AR5K_CR);
1161
1162 /*
1163 * It may take some time to disable the DMA receive unit
1164 */
1165 for (i = 2000; i > 0 &&
1166 (ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_CR_RXE) != 0;
1167 i--)
1168 udelay(10);
1169
1170 return i ? 0 : -EBUSY;
1171}
1172
1173/*
1174 * Get the address of the RX Descriptor
1175 */
1176u32 ath5k_hw_get_rx_buf(struct ath5k_hw *ah)
1177{
1178 return ath5k_hw_reg_read(ah, AR5K_RXDP);
1179}
1180
1181/*
1182 * Set the address of the RX Descriptor
1183 */
1184void ath5k_hw_put_rx_buf(struct ath5k_hw *ah, u32 phys_addr)
1185{
1186 ATH5K_TRACE(ah->ah_sc);
1187
1188 /*TODO:Shouldn't we check if RX is enabled first ?*/
1189 ath5k_hw_reg_write(ah, phys_addr, AR5K_RXDP);
1190}
1191
1192/*
1193 * Transmit functions
1194 */
1195
1196/*
1197 * Start DMA transmit for a specific queue
1198 * (see also QCU/DCU functions)
1199 */
1200int ath5k_hw_tx_start(struct ath5k_hw *ah, unsigned int queue)
1201{
1202 u32 tx_queue;
1203
1204 ATH5K_TRACE(ah->ah_sc);
1205 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1206
1207 /* Return if queue is declared inactive */
1208 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1209 return -EIO;
1210
1211 if (ah->ah_version == AR5K_AR5210) {
1212 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1213
1214 /*
1215 * Set the queue by type on 5210
1216 */
1217 switch (ah->ah_txq[queue].tqi_type) {
1218 case AR5K_TX_QUEUE_DATA:
1219 tx_queue |= AR5K_CR_TXE0 & ~AR5K_CR_TXD0;
1220 break;
1221 case AR5K_TX_QUEUE_BEACON:
1222 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1223 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
1224 AR5K_BSR);
1225 break;
1226 case AR5K_TX_QUEUE_CAB:
1227 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1228 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1FV | AR5K_BCR_TQ1V |
1229 AR5K_BCR_BDMAE, AR5K_BSR);
1230 break;
1231 default:
1232 return -EINVAL;
1233 }
1234 /* Start queue */
1235 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1236 } else {
1237 /* Return if queue is disabled */
1238 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXD, queue))
1239 return -EIO;
1240
1241 /* Start queue */
1242 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXE, queue);
1243 }
1244
1245 return 0;
1246}
1247
1248/*
1249 * Stop DMA transmit for a specific queue
1250 * (see also QCU/DCU functions)
1251 */
1252int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue)
1253{
1254 unsigned int i = 100;
1255 u32 tx_queue, pending;
1256
1257 ATH5K_TRACE(ah->ah_sc);
1258 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1259
1260 /* Return if queue is declared inactive */
1261 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1262 return -EIO;
1263
1264 if (ah->ah_version == AR5K_AR5210) {
1265 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1266
1267 /*
1268 * Set by queue type
1269 */
1270 switch (ah->ah_txq[queue].tqi_type) {
1271 case AR5K_TX_QUEUE_DATA:
1272 tx_queue |= AR5K_CR_TXD0 & ~AR5K_CR_TXE0;
1273 break;
1274 case AR5K_TX_QUEUE_BEACON:
1275 case AR5K_TX_QUEUE_CAB:
1276 /* XXX Fix me... */
1277 tx_queue |= AR5K_CR_TXD1 & ~AR5K_CR_TXD1;
1278 ath5k_hw_reg_write(ah, 0, AR5K_BSR);
1279 break;
1280 default:
1281 return -EINVAL;
1282 }
1283
1284 /* Stop queue */
1285 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1286 } else {
1287 /*
1288 * Schedule TX disable and wait until queue is empty
1289 */
1290 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXD, queue);
1291
1292 /*Check for pending frames*/
1293 do {
1294 pending = ath5k_hw_reg_read(ah,
1295 AR5K_QUEUE_STATUS(queue)) &
1296 AR5K_QCU_STS_FRMPENDCNT;
1297 udelay(100);
1298 } while (--i && pending);
1299
1300 /* Clear register */
1301 ath5k_hw_reg_write(ah, 0, AR5K_QCU_TXD);
1302 }
1303
1304 /* TODO: Check for success else return error */
1305 return 0;
1306}
1307
1308/*
1309 * Get the address of the TX Descriptor for a specific queue
1310 * (see also QCU/DCU functions)
1311 */
1312u32 ath5k_hw_get_tx_buf(struct ath5k_hw *ah, unsigned int queue)
1313{
1314 u16 tx_reg;
1315
1316 ATH5K_TRACE(ah->ah_sc);
1317 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1318
1319 /*
1320 * Get the transmit queue descriptor pointer from the selected queue
1321 */
1322 /*5210 doesn't have QCU*/
1323 if (ah->ah_version == AR5K_AR5210) {
1324 switch (ah->ah_txq[queue].tqi_type) {
1325 case AR5K_TX_QUEUE_DATA:
1326 tx_reg = AR5K_NOQCU_TXDP0;
1327 break;
1328 case AR5K_TX_QUEUE_BEACON:
1329 case AR5K_TX_QUEUE_CAB:
1330 tx_reg = AR5K_NOQCU_TXDP1;
1331 break;
1332 default:
1333 return 0xffffffff;
1334 }
1335 } else {
1336 tx_reg = AR5K_QUEUE_TXDP(queue);
1337 }
1338
1339 return ath5k_hw_reg_read(ah, tx_reg);
1340}
1341
1342/*
1343 * Set the address of the TX Descriptor for a specific queue
1344 * (see also QCU/DCU functions)
1345 */
1346int ath5k_hw_put_tx_buf(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
1347{
1348 u16 tx_reg;
1349
1350 ATH5K_TRACE(ah->ah_sc);
1351 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1352
1353 /*
1354 * Set the transmit queue descriptor pointer register by type
1355 * on 5210
1356 */
1357 if (ah->ah_version == AR5K_AR5210) {
1358 switch (ah->ah_txq[queue].tqi_type) {
1359 case AR5K_TX_QUEUE_DATA:
1360 tx_reg = AR5K_NOQCU_TXDP0;
1361 break;
1362 case AR5K_TX_QUEUE_BEACON:
1363 case AR5K_TX_QUEUE_CAB:
1364 tx_reg = AR5K_NOQCU_TXDP1;
1365 break;
1366 default:
1367 return -EINVAL;
1368 }
1369 } else {
1370 /*
1371 * Set the transmit queue descriptor pointer for
1372 * the selected queue on QCU for 5211+
1373 * (this won't work if the queue is still active)
1374 */
1375 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
1376 return -EIO;
1377
1378 tx_reg = AR5K_QUEUE_TXDP(queue);
1379 }
1380
1381 /* Set descriptor pointer */
1382 ath5k_hw_reg_write(ah, phys_addr, tx_reg);
1383
1384 return 0;
1385}
1386
1387/*
1388 * Update tx trigger level
1389 */
1390int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase)
1391{
1392 u32 trigger_level, imr;
1393 int ret = -EIO;
1394
1395 ATH5K_TRACE(ah->ah_sc);
1396
1397 /*
1398 * Disable interrupts by setting the mask
1399 */
1400 imr = ath5k_hw_set_intr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
1401
1402 /*TODO: Boundary check on trigger_level*/
1403 trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
1404 AR5K_TXCFG_TXFULL);
1405
1406 if (increase == false) {
1407 if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
1408 goto done;
1409 } else
1410 trigger_level +=
1411 ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
1412
1413 /*
1414 * Update trigger level on success
1415 */
1416 if (ah->ah_version == AR5K_AR5210)
1417 ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
1418 else
1419 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
1420 AR5K_TXCFG_TXFULL, trigger_level);
1421
1422 ret = 0;
1423
1424done:
1425 /*
1426 * Restore interrupt mask
1427 */
1428 ath5k_hw_set_intr(ah, imr);
1429
1430 return ret;
1431}
1432
1433/*
1434 * Interrupt handling
1435 */
1436
1437/*
1438 * Check if we have pending interrupts
1439 */
1440bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
1441{
1442 ATH5K_TRACE(ah->ah_sc);
1443 return ath5k_hw_reg_read(ah, AR5K_INTPEND);
1444}
1445
1446/*
1447 * Get interrupt mask (ISR)
1448 */
1449int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
1450{
1451 u32 data;
1452
1453 ATH5K_TRACE(ah->ah_sc);
1454
1455 /*
1456 * Read interrupt status from the Interrupt Status register
1457 * on 5210
1458 */
1459 if (ah->ah_version == AR5K_AR5210) {
1460 data = ath5k_hw_reg_read(ah, AR5K_ISR);
1461 if (unlikely(data == AR5K_INT_NOCARD)) {
1462 *interrupt_mask = data;
1463 return -ENODEV;
1464 }
1465 } else {
1466 /*
1467 * Read interrupt status from the Read-And-Clear shadow register
1468 * Note: PISR/SISR Not available on 5210
1469 */
1470 data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
1471 }
1472
1473 /*
1474 * Get abstract interrupt mask (driver-compatible)
1475 */
1476 *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
1477
1478 if (unlikely(data == AR5K_INT_NOCARD))
1479 return -ENODEV;
1480
1481 if (data & (AR5K_ISR_RXOK | AR5K_ISR_RXERR))
1482 *interrupt_mask |= AR5K_INT_RX;
1483
1484 if (data & (AR5K_ISR_TXOK | AR5K_ISR_TXERR
1485 | AR5K_ISR_TXDESC | AR5K_ISR_TXEOL))
1486 *interrupt_mask |= AR5K_INT_TX;
1487
1488 if (ah->ah_version != AR5K_AR5210) {
1489 /*HIU = Host Interface Unit (PCI etc)*/
1490 if (unlikely(data & (AR5K_ISR_HIUERR)))
1491 *interrupt_mask |= AR5K_INT_FATAL;
1492
1493 /*Beacon Not Ready*/
1494 if (unlikely(data & (AR5K_ISR_BNR)))
1495 *interrupt_mask |= AR5K_INT_BNR;
1496 }
1497
1498 /*
1499 * XXX: BMISS interrupts may occur after association.
1500 * I found this on 5210 code but it needs testing. If this is
1501 * true we should disable them before assoc and re-enable them
1502 * after a successfull assoc + some jiffies.
1503 */
1504#if 0
1505 interrupt_mask &= ~AR5K_INT_BMISS;
1506#endif
1507
1508 /*
1509 * In case we didn't handle anything,
1510 * print the register value.
1511 */
1512 if (unlikely(*interrupt_mask == 0 && net_ratelimit()))
1513 ATH5K_PRINTF("0x%08x\n", data);
1514
1515 return 0;
1516}
1517
1518/*
1519 * Set interrupt mask
1520 */
1521enum ath5k_int ath5k_hw_set_intr(struct ath5k_hw *ah, enum ath5k_int new_mask)
1522{
1523 enum ath5k_int old_mask, int_mask;
1524
1525 /*
1526 * Disable card interrupts to prevent any race conditions
1527 * (they will be re-enabled afterwards).
1528 */
1529 ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
1530
1531 old_mask = ah->ah_imr;
1532
1533 /*
1534 * Add additional, chipset-dependent interrupt mask flags
1535 * and write them to the IMR (interrupt mask register).
1536 */
1537 int_mask = new_mask & AR5K_INT_COMMON;
1538
1539 if (new_mask & AR5K_INT_RX)
1540 int_mask |= AR5K_IMR_RXOK | AR5K_IMR_RXERR | AR5K_IMR_RXORN |
1541 AR5K_IMR_RXDESC;
1542
1543 if (new_mask & AR5K_INT_TX)
1544 int_mask |= AR5K_IMR_TXOK | AR5K_IMR_TXERR | AR5K_IMR_TXDESC |
1545 AR5K_IMR_TXURN;
1546
1547 if (ah->ah_version != AR5K_AR5210) {
1548 if (new_mask & AR5K_INT_FATAL) {
1549 int_mask |= AR5K_IMR_HIUERR;
1550 AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_MCABT |
1551 AR5K_SIMR2_SSERR | AR5K_SIMR2_DPERR);
1552 }
1553 }
1554
1555 ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
1556
1557 /* Store new interrupt mask */
1558 ah->ah_imr = new_mask;
1559
1560 /* ..re-enable interrupts */
1561 ath5k_hw_reg_write(ah, AR5K_IER_ENABLE, AR5K_IER);
1562
1563 return old_mask;
1564}
1565
1566
1567/*************************\
1568 EEPROM access functions
1569\*************************/
1570
1571/*
1572 * Read from eeprom
1573 */
1574static int ath5k_hw_eeprom_read(struct ath5k_hw *ah, u32 offset, u16 *data)
1575{
1576 u32 status, timeout;
1577
1578 ATH5K_TRACE(ah->ah_sc);
1579 /*
1580 * Initialize EEPROM access
1581 */
1582 if (ah->ah_version == AR5K_AR5210) {
1583 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1584 (void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset));
1585 } else {
1586 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1587 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1588 AR5K_EEPROM_CMD_READ);
1589 }
1590
1591 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1592 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1593 if (status & AR5K_EEPROM_STAT_RDDONE) {
1594 if (status & AR5K_EEPROM_STAT_RDERR)
1595 return -EIO;
1596 *data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) &
1597 0xffff);
1598 return 0;
1599 }
1600 udelay(15);
1601 }
1602
1603 return -ETIMEDOUT;
1604}
1605
1606/*
1607 * Write to eeprom - currently disabled, use at your own risk
1608 */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001609#if 0
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001610static int ath5k_hw_eeprom_write(struct ath5k_hw *ah, u32 offset, u16 data)
1611{
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001612
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001613 u32 status, timeout;
1614
1615 ATH5K_TRACE(ah->ah_sc);
1616
1617 /*
1618 * Initialize eeprom access
1619 */
1620
1621 if (ah->ah_version == AR5K_AR5210) {
1622 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1623 } else {
1624 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1625 AR5K_EEPROM_CMD_RESET);
1626 }
1627
1628 /*
1629 * Write data to data register
1630 */
1631
1632 if (ah->ah_version == AR5K_AR5210) {
1633 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_BASE + (4 * offset));
1634 } else {
1635 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1636 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_DATA);
1637 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1638 AR5K_EEPROM_CMD_WRITE);
1639 }
1640
1641 /*
1642 * Check status
1643 */
1644
1645 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1646 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1647 if (status & AR5K_EEPROM_STAT_WRDONE) {
1648 if (status & AR5K_EEPROM_STAT_WRERR)
1649 return EIO;
1650 return 0;
1651 }
1652 udelay(15);
1653 }
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001654
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001655 ATH5K_ERR(ah->ah_sc, "EEPROM Write is disabled!");
1656 return -EIO;
1657}
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05001658#endif
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001659
1660/*
1661 * Translate binary channel representation in EEPROM to frequency
1662 */
1663static u16 ath5k_eeprom_bin2freq(struct ath5k_hw *ah, u16 bin, unsigned int mode)
1664{
1665 u16 val;
1666
1667 if (bin == AR5K_EEPROM_CHANNEL_DIS)
1668 return bin;
1669
1670 if (mode == AR5K_EEPROM_MODE_11A) {
1671 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1672 val = (5 * bin) + 4800;
1673 else
1674 val = bin > 62 ? (10 * 62) + (5 * (bin - 62)) + 5100 :
1675 (bin * 10) + 5100;
1676 } else {
1677 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1678 val = bin + 2300;
1679 else
1680 val = bin + 2400;
1681 }
1682
1683 return val;
1684}
1685
1686/*
1687 * Read antenna infos from eeprom
1688 */
1689static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
1690 unsigned int mode)
1691{
1692 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1693 u32 o = *offset;
1694 u16 val;
1695 int ret, i = 0;
1696
1697 AR5K_EEPROM_READ(o++, val);
1698 ee->ee_switch_settling[mode] = (val >> 8) & 0x7f;
1699 ee->ee_ant_tx_rx[mode] = (val >> 2) & 0x3f;
1700 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1701
1702 AR5K_EEPROM_READ(o++, val);
1703 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1704 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1705 ee->ee_ant_control[mode][i++] = val & 0x3f;
1706
1707 AR5K_EEPROM_READ(o++, val);
1708 ee->ee_ant_control[mode][i++] = (val >> 10) & 0x3f;
1709 ee->ee_ant_control[mode][i++] = (val >> 4) & 0x3f;
1710 ee->ee_ant_control[mode][i] = (val << 2) & 0x3f;
1711
1712 AR5K_EEPROM_READ(o++, val);
1713 ee->ee_ant_control[mode][i++] |= (val >> 14) & 0x3;
1714 ee->ee_ant_control[mode][i++] = (val >> 8) & 0x3f;
1715 ee->ee_ant_control[mode][i++] = (val >> 2) & 0x3f;
1716 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1717
1718 AR5K_EEPROM_READ(o++, val);
1719 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1720 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1721 ee->ee_ant_control[mode][i++] = val & 0x3f;
1722
1723 /* Get antenna modes */
1724 ah->ah_antenna[mode][0] =
1725 (ee->ee_ant_control[mode][0] << 4) | 0x1;
1726 ah->ah_antenna[mode][AR5K_ANT_FIXED_A] =
1727 ee->ee_ant_control[mode][1] |
1728 (ee->ee_ant_control[mode][2] << 6) |
1729 (ee->ee_ant_control[mode][3] << 12) |
1730 (ee->ee_ant_control[mode][4] << 18) |
1731 (ee->ee_ant_control[mode][5] << 24);
1732 ah->ah_antenna[mode][AR5K_ANT_FIXED_B] =
1733 ee->ee_ant_control[mode][6] |
1734 (ee->ee_ant_control[mode][7] << 6) |
1735 (ee->ee_ant_control[mode][8] << 12) |
1736 (ee->ee_ant_control[mode][9] << 18) |
1737 (ee->ee_ant_control[mode][10] << 24);
1738
1739 /* return new offset */
1740 *offset = o;
1741
1742 return 0;
1743}
1744
1745/*
1746 * Read supported modes from eeprom
1747 */
1748static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset,
1749 unsigned int mode)
1750{
1751 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1752 u32 o = *offset;
1753 u16 val;
1754 int ret;
1755
1756 AR5K_EEPROM_READ(o++, val);
1757 ee->ee_tx_end2xlna_enable[mode] = (val >> 8) & 0xff;
1758 ee->ee_thr_62[mode] = val & 0xff;
1759
1760 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1761 ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28;
1762
1763 AR5K_EEPROM_READ(o++, val);
1764 ee->ee_tx_end2xpa_disable[mode] = (val >> 8) & 0xff;
1765 ee->ee_tx_frm2xpa_enable[mode] = val & 0xff;
1766
1767 AR5K_EEPROM_READ(o++, val);
1768 ee->ee_pga_desired_size[mode] = (val >> 8) & 0xff;
1769
1770 if ((val & 0xff) & 0x80)
1771 ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1);
1772 else
1773 ee->ee_noise_floor_thr[mode] = val & 0xff;
1774
1775 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1776 ee->ee_noise_floor_thr[mode] =
1777 mode == AR5K_EEPROM_MODE_11A ? -54 : -1;
1778
1779 AR5K_EEPROM_READ(o++, val);
1780 ee->ee_xlna_gain[mode] = (val >> 5) & 0xff;
1781 ee->ee_x_gain[mode] = (val >> 1) & 0xf;
1782 ee->ee_xpd[mode] = val & 0x1;
1783
1784 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0)
1785 ee->ee_fixed_bias[mode] = (val >> 13) & 0x1;
1786
1787 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) {
1788 AR5K_EEPROM_READ(o++, val);
1789 ee->ee_false_detect[mode] = (val >> 6) & 0x7f;
1790
1791 if (mode == AR5K_EEPROM_MODE_11A)
1792 ee->ee_xr_power[mode] = val & 0x3f;
1793 else {
1794 ee->ee_ob[mode][0] = val & 0x7;
1795 ee->ee_db[mode][0] = (val >> 3) & 0x7;
1796 }
1797 }
1798
1799 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) {
1800 ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN;
1801 ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA;
1802 } else {
1803 ee->ee_i_gain[mode] = (val >> 13) & 0x7;
1804
1805 AR5K_EEPROM_READ(o++, val);
1806 ee->ee_i_gain[mode] |= (val << 3) & 0x38;
1807
1808 if (mode == AR5K_EEPROM_MODE_11G)
1809 ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff;
1810 }
1811
1812 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
1813 mode == AR5K_EEPROM_MODE_11A) {
1814 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
1815 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
1816 }
1817
1818 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6 &&
1819 mode == AR5K_EEPROM_MODE_11G)
1820 ee->ee_scaled_cck_delta = (val >> 11) & 0x1f;
1821
1822 /* return new offset */
1823 *offset = o;
1824
1825 return 0;
1826}
1827
1828/*
1829 * Initialize eeprom & capabilities structs
1830 */
1831static int ath5k_eeprom_init(struct ath5k_hw *ah)
1832{
1833 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1834 unsigned int mode, i;
1835 int ret;
1836 u32 offset;
1837 u16 val;
1838
1839 /* Initial TX thermal adjustment values */
1840 ee->ee_tx_clip = 4;
1841 ee->ee_pwd_84 = ee->ee_pwd_90 = 1;
1842 ee->ee_gain_select = 1;
1843
1844 /*
1845 * Read values from EEPROM and store them in the capability structure
1846 */
1847 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC, ee_magic);
1848 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT, ee_protect);
1849 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN, ee_regdomain);
1850 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION, ee_version);
1851 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR, ee_header);
1852
1853 /* Return if we have an old EEPROM */
1854 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_0)
1855 return 0;
1856
1857#ifdef notyet
1858 /*
1859 * Validate the checksum of the EEPROM date. There are some
1860 * devices with invalid EEPROMs.
1861 */
1862 for (cksum = 0, offset = 0; offset < AR5K_EEPROM_INFO_MAX; offset++) {
1863 AR5K_EEPROM_READ(AR5K_EEPROM_INFO(offset), val);
1864 cksum ^= val;
1865 }
1866 if (cksum != AR5K_EEPROM_INFO_CKSUM) {
1867 ATH5K_ERR(ah->ah_sc, "Invalid EEPROM checksum 0x%04x\n", cksum);
1868 return -EIO;
1869 }
1870#endif
1871
1872 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah->ah_ee_version),
1873 ee_ant_gain);
1874
1875 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
1876 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0, ee_misc0);
1877 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1, ee_misc1);
1878 }
1879
1880 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_3) {
1881 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ, val);
1882 ee->ee_ob[AR5K_EEPROM_MODE_11B][0] = val & 0x7;
1883 ee->ee_db[AR5K_EEPROM_MODE_11B][0] = (val >> 3) & 0x7;
1884
1885 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ, val);
1886 ee->ee_ob[AR5K_EEPROM_MODE_11G][0] = val & 0x7;
1887 ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7;
1888 }
1889
1890 /*
1891 * Get conformance test limit values
1892 */
1893 offset = AR5K_EEPROM_CTL(ah->ah_ee_version);
1894 ee->ee_ctls = AR5K_EEPROM_N_CTLS(ah->ah_ee_version);
1895
1896 for (i = 0; i < ee->ee_ctls; i++) {
1897 AR5K_EEPROM_READ(offset++, val);
1898 ee->ee_ctl[i] = (val >> 8) & 0xff;
1899 ee->ee_ctl[i + 1] = val & 0xff;
1900 }
1901
1902 /*
1903 * Get values for 802.11a (5GHz)
1904 */
1905 mode = AR5K_EEPROM_MODE_11A;
1906
1907 ee->ee_turbo_max_power[mode] =
1908 AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header);
1909
1910 offset = AR5K_EEPROM_MODES_11A(ah->ah_ee_version);
1911
1912 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
1913 if (ret)
1914 return ret;
1915
1916 AR5K_EEPROM_READ(offset++, val);
1917 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
1918 ee->ee_ob[mode][3] = (val >> 5) & 0x7;
1919 ee->ee_db[mode][3] = (val >> 2) & 0x7;
1920 ee->ee_ob[mode][2] = (val << 1) & 0x7;
1921
1922 AR5K_EEPROM_READ(offset++, val);
1923 ee->ee_ob[mode][2] |= (val >> 15) & 0x1;
1924 ee->ee_db[mode][2] = (val >> 12) & 0x7;
1925 ee->ee_ob[mode][1] = (val >> 9) & 0x7;
1926 ee->ee_db[mode][1] = (val >> 6) & 0x7;
1927 ee->ee_ob[mode][0] = (val >> 3) & 0x7;
1928 ee->ee_db[mode][0] = val & 0x7;
1929
1930 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
1931 if (ret)
1932 return ret;
1933
1934 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1) {
1935 AR5K_EEPROM_READ(offset++, val);
1936 ee->ee_margin_tx_rx[mode] = val & 0x3f;
1937 }
1938
1939 /*
1940 * Get values for 802.11b (2.4GHz)
1941 */
1942 mode = AR5K_EEPROM_MODE_11B;
1943 offset = AR5K_EEPROM_MODES_11B(ah->ah_ee_version);
1944
1945 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
1946 if (ret)
1947 return ret;
1948
1949 AR5K_EEPROM_READ(offset++, val);
1950 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
1951 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
1952 ee->ee_db[mode][1] = val & 0x7;
1953
1954 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
1955 if (ret)
1956 return ret;
1957
1958 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
1959 AR5K_EEPROM_READ(offset++, val);
1960 ee->ee_cal_pier[mode][0] =
1961 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
1962 ee->ee_cal_pier[mode][1] =
1963 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
1964
1965 AR5K_EEPROM_READ(offset++, val);
1966 ee->ee_cal_pier[mode][2] =
1967 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
1968 }
1969
1970 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
1971 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
1972
1973 /*
1974 * Get values for 802.11g (2.4GHz)
1975 */
1976 mode = AR5K_EEPROM_MODE_11G;
1977 offset = AR5K_EEPROM_MODES_11G(ah->ah_ee_version);
1978
1979 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
1980 if (ret)
1981 return ret;
1982
1983 AR5K_EEPROM_READ(offset++, val);
1984 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
1985 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
1986 ee->ee_db[mode][1] = val & 0x7;
1987
1988 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
1989 if (ret)
1990 return ret;
1991
1992 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
1993 AR5K_EEPROM_READ(offset++, val);
1994 ee->ee_cal_pier[mode][0] =
1995 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
1996 ee->ee_cal_pier[mode][1] =
1997 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
1998
1999 AR5K_EEPROM_READ(offset++, val);
2000 ee->ee_turbo_max_power[mode] = val & 0x7f;
2001 ee->ee_xr_power[mode] = (val >> 7) & 0x3f;
2002
2003 AR5K_EEPROM_READ(offset++, val);
2004 ee->ee_cal_pier[mode][2] =
2005 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2006
2007 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
2008 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
2009
2010 AR5K_EEPROM_READ(offset++, val);
2011 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
2012 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
2013
2014 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) {
2015 AR5K_EEPROM_READ(offset++, val);
2016 ee->ee_cck_ofdm_gain_delta = val & 0xff;
2017 }
2018 }
2019
2020 /*
2021 * Read 5GHz EEPROM channels
2022 */
2023
2024 return 0;
2025}
2026
2027/*
2028 * Read the MAC address from eeprom
2029 */
2030static int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
2031{
2032 u8 mac_d[ETH_ALEN];
2033 u32 total, offset;
2034 u16 data;
2035 int octet, ret;
2036
2037 memset(mac, 0, ETH_ALEN);
2038 memset(mac_d, 0, ETH_ALEN);
2039
2040 ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
2041 if (ret)
2042 return ret;
2043
2044 for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
2045 ret = ath5k_hw_eeprom_read(ah, offset, &data);
2046 if (ret)
2047 return ret;
2048
2049 total += data;
2050 mac_d[octet + 1] = data & 0xff;
2051 mac_d[octet] = data >> 8;
2052 octet += 2;
2053 }
2054
2055 memcpy(mac, mac_d, ETH_ALEN);
2056
2057 if (!total || total == 3 * 0xffff)
2058 return -EINVAL;
2059
2060 return 0;
2061}
2062
2063/*
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002064 * Fill the capabilities struct
2065 */
2066static int ath5k_hw_get_capabilities(struct ath5k_hw *ah)
2067{
2068 u16 ee_header;
2069
2070 ATH5K_TRACE(ah->ah_sc);
2071 /* Capabilities stored in the EEPROM */
2072 ee_header = ah->ah_capabilities.cap_eeprom.ee_header;
2073
2074 if (ah->ah_version == AR5K_AR5210) {
2075 /*
2076 * Set radio capabilities
2077 * (The AR5110 only supports the middle 5GHz band)
2078 */
2079 ah->ah_capabilities.cap_range.range_5ghz_min = 5120;
2080 ah->ah_capabilities.cap_range.range_5ghz_max = 5430;
2081 ah->ah_capabilities.cap_range.range_2ghz_min = 0;
2082 ah->ah_capabilities.cap_range.range_2ghz_max = 0;
2083
2084 /* Set supported modes */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002085 __set_bit(AR5K_MODE_11A, ah->ah_capabilities.cap_mode);
2086 __set_bit(AR5K_MODE_11A_TURBO, ah->ah_capabilities.cap_mode);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002087 } else {
2088 /*
2089 * XXX The tranceiver supports frequencies from 4920 to 6100GHz
2090 * XXX and from 2312 to 2732GHz. There are problems with the
2091 * XXX current ieee80211 implementation because the IEEE
2092 * XXX channel mapping does not support negative channel
2093 * XXX numbers (2312MHz is channel -19). Of course, this
2094 * XXX doesn't matter because these channels are out of range
2095 * XXX but some regulation domains like MKK (Japan) will
2096 * XXX support frequencies somewhere around 4.8GHz.
2097 */
2098
2099 /*
2100 * Set radio capabilities
2101 */
2102
2103 if (AR5K_EEPROM_HDR_11A(ee_header)) {
2104 ah->ah_capabilities.cap_range.range_5ghz_min = 5005; /* 4920 */
2105 ah->ah_capabilities.cap_range.range_5ghz_max = 6100;
2106
2107 /* Set supported modes */
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002108 __set_bit(AR5K_MODE_11A,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002109 ah->ah_capabilities.cap_mode);
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002110 __set_bit(AR5K_MODE_11A_TURBO,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002111 ah->ah_capabilities.cap_mode);
2112 if (ah->ah_version == AR5K_AR5212)
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002113 __set_bit(AR5K_MODE_11G_TURBO,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002114 ah->ah_capabilities.cap_mode);
2115 }
2116
2117 /* Enable 802.11b if a 2GHz capable radio (2111/5112) is
2118 * connected */
2119 if (AR5K_EEPROM_HDR_11B(ee_header) ||
2120 AR5K_EEPROM_HDR_11G(ee_header)) {
2121 ah->ah_capabilities.cap_range.range_2ghz_min = 2412; /* 2312 */
2122 ah->ah_capabilities.cap_range.range_2ghz_max = 2732;
2123
2124 if (AR5K_EEPROM_HDR_11B(ee_header))
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002125 __set_bit(AR5K_MODE_11B,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002126 ah->ah_capabilities.cap_mode);
2127
2128 if (AR5K_EEPROM_HDR_11G(ee_header))
Luis R. Rodriguezd8ee3982008-02-03 21:51:04 -05002129 __set_bit(AR5K_MODE_11G,
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002130 ah->ah_capabilities.cap_mode);
2131 }
2132 }
2133
2134 /* GPIO */
2135 ah->ah_gpio_npins = AR5K_NUM_GPIO;
2136
2137 /* Set number of supported TX queues */
2138 if (ah->ah_version == AR5K_AR5210)
2139 ah->ah_capabilities.cap_queues.q_tx_num =
2140 AR5K_NUM_TX_QUEUES_NOQCU;
2141 else
2142 ah->ah_capabilities.cap_queues.q_tx_num = AR5K_NUM_TX_QUEUES;
2143
2144 return 0;
2145}
2146
2147/*********************************\
2148 Protocol Control Unit Functions
2149\*********************************/
2150
2151/*
2152 * Set Operation mode
2153 */
2154int ath5k_hw_set_opmode(struct ath5k_hw *ah)
2155{
2156 u32 pcu_reg, beacon_reg, low_id, high_id;
2157
2158 pcu_reg = 0;
2159 beacon_reg = 0;
2160
2161 ATH5K_TRACE(ah->ah_sc);
2162
2163 switch (ah->ah_op_mode) {
2164 case IEEE80211_IF_TYPE_IBSS:
2165 pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_DESC_ANTENNA |
2166 (ah->ah_version == AR5K_AR5210 ?
2167 AR5K_STA_ID1_NO_PSPOLL : 0);
2168 beacon_reg |= AR5K_BCR_ADHOC;
2169 break;
2170
2171 case IEEE80211_IF_TYPE_AP:
2172 pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_RTS_DEF_ANTENNA |
2173 (ah->ah_version == AR5K_AR5210 ?
2174 AR5K_STA_ID1_NO_PSPOLL : 0);
2175 beacon_reg |= AR5K_BCR_AP;
2176 break;
2177
2178 case IEEE80211_IF_TYPE_STA:
2179 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2180 (ah->ah_version == AR5K_AR5210 ?
2181 AR5K_STA_ID1_PWR_SV : 0);
2182 case IEEE80211_IF_TYPE_MNTR:
2183 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2184 (ah->ah_version == AR5K_AR5210 ?
2185 AR5K_STA_ID1_NO_PSPOLL : 0);
2186 break;
2187
2188 default:
2189 return -EINVAL;
2190 }
2191
2192 /*
2193 * Set PCU registers
2194 */
2195 low_id = AR5K_LOW_ID(ah->ah_sta_id);
2196 high_id = AR5K_HIGH_ID(ah->ah_sta_id);
2197 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2198 ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
2199
2200 /*
2201 * Set Beacon Control Register on 5210
2202 */
2203 if (ah->ah_version == AR5K_AR5210)
2204 ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR);
2205
2206 return 0;
2207}
2208
2209/*
2210 * BSSID Functions
2211 */
2212
2213/*
2214 * Get station id
2215 */
2216void ath5k_hw_get_lladdr(struct ath5k_hw *ah, u8 *mac)
2217{
2218 ATH5K_TRACE(ah->ah_sc);
2219 memcpy(mac, ah->ah_sta_id, ETH_ALEN);
2220}
2221
2222/*
2223 * Set station id
2224 */
2225int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
2226{
2227 u32 low_id, high_id;
2228
2229 ATH5K_TRACE(ah->ah_sc);
2230 /* Set new station ID */
2231 memcpy(ah->ah_sta_id, mac, ETH_ALEN);
2232
2233 low_id = AR5K_LOW_ID(mac);
2234 high_id = AR5K_HIGH_ID(mac);
2235
2236 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2237 ath5k_hw_reg_write(ah, high_id, AR5K_STA_ID1);
2238
2239 return 0;
2240}
2241
2242/*
2243 * Set BSSID
2244 */
2245void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id)
2246{
2247 u32 low_id, high_id;
2248 u16 tim_offset = 0;
2249
2250 /*
2251 * Set simple BSSID mask on 5212
2252 */
2253 if (ah->ah_version == AR5K_AR5212) {
2254 ath5k_hw_reg_write(ah, 0xfffffff, AR5K_BSS_IDM0);
2255 ath5k_hw_reg_write(ah, 0xfffffff, AR5K_BSS_IDM1);
2256 }
2257
2258 /*
2259 * Set BSSID which triggers the "SME Join" operation
2260 */
2261 low_id = AR5K_LOW_ID(bssid);
2262 high_id = AR5K_HIGH_ID(bssid);
2263 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_ID0);
2264 ath5k_hw_reg_write(ah, high_id | ((assoc_id & 0x3fff) <<
2265 AR5K_BSS_ID1_AID_S), AR5K_BSS_ID1);
2266
2267 if (assoc_id == 0) {
2268 ath5k_hw_disable_pspoll(ah);
2269 return;
2270 }
2271
2272 AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM,
2273 tim_offset ? tim_offset + 4 : 0);
2274
2275 ath5k_hw_enable_pspoll(ah, NULL, 0);
2276}
2277/**
2278 * ath5k_hw_set_bssid_mask - set common bits we should listen to
2279 *
2280 * The bssid_mask is a utility used by AR5212 hardware to inform the hardware
2281 * which bits of the interface's MAC address should be looked at when trying
2282 * to decide which packets to ACK. In station mode every bit matters. In AP
2283 * mode with a single BSS every bit matters as well. In AP mode with
2284 * multiple BSSes not every bit matters.
2285 *
2286 * @ah: the &struct ath5k_hw
2287 * @mask: the bssid_mask, a u8 array of size ETH_ALEN
2288 *
2289 * Note that this is a simple filter and *does* not filter out all
2290 * relevant frames. Some non-relevant frames will get through, probability
2291 * jocks are welcomed to compute.
2292 *
2293 * When handling multiple BSSes (or VAPs) you can get the BSSID mask by
2294 * computing the set of:
2295 *
2296 * ~ ( MAC XOR BSSID )
2297 *
2298 * When you do this you are essentially computing the common bits. Later it
2299 * is assumed the harware will "and" (&) the BSSID mask with the MAC address
2300 * to obtain the relevant bits which should match on the destination frame.
2301 *
2302 * Simple example: on your card you have have two BSSes you have created with
2303 * BSSID-01 and BSSID-02. Lets assume BSSID-01 will not use the MAC address.
2304 * There is another BSSID-03 but you are not part of it. For simplicity's sake,
2305 * assuming only 4 bits for a mac address and for BSSIDs you can then have:
2306 *
2307 * \
2308 * MAC: 0001 |
2309 * BSSID-01: 0100 | --> Belongs to us
2310 * BSSID-02: 1001 |
2311 * /
2312 * -------------------
2313 * BSSID-03: 0110 | --> External
2314 * -------------------
2315 *
2316 * Our bssid_mask would then be:
2317 *
2318 * On loop iteration for BSSID-01:
2319 * ~(0001 ^ 0100) -> ~(0101)
2320 * -> 1010
2321 * bssid_mask = 1010
2322 *
2323 * On loop iteration for BSSID-02:
2324 * bssid_mask &= ~(0001 ^ 1001)
2325 * bssid_mask = (1010) & ~(0001 ^ 1001)
2326 * bssid_mask = (1010) & ~(1001)
2327 * bssid_mask = (1010) & (0110)
2328 * bssid_mask = 0010
2329 *
2330 * A bssid_mask of 0010 means "only pay attention to the second least
2331 * significant bit". This is because its the only bit common
2332 * amongst the MAC and all BSSIDs we support. To findout what the real
2333 * common bit is we can simply "&" the bssid_mask now with any BSSID we have
2334 * or our MAC address (we assume the hardware uses the MAC address).
2335 *
2336 * Now, suppose there's an incoming frame for BSSID-03:
2337 *
2338 * IFRAME-01: 0110
2339 *
2340 * An easy eye-inspeciton of this already should tell you that this frame
2341 * will not pass our check. This is beacuse the bssid_mask tells the
2342 * hardware to only look at the second least significant bit and the
2343 * common bit amongst the MAC and BSSIDs is 0, this frame has the 2nd LSB
2344 * as 1, which does not match 0.
2345 *
2346 * So with IFRAME-01 we *assume* the hardware will do:
2347 *
2348 * allow = (IFRAME-01 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2349 * --> allow = (0110 & 0010) == (0010 & 0001) ? 1 : 0;
2350 * --> allow = (0010) == 0000 ? 1 : 0;
2351 * --> allow = 0
2352 *
2353 * Lets now test a frame that should work:
2354 *
2355 * IFRAME-02: 0001 (we should allow)
2356 *
2357 * allow = (0001 & 1010) == 1010
2358 *
2359 * allow = (IFRAME-02 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2360 * --> allow = (0001 & 0010) == (0010 & 0001) ? 1 :0;
2361 * --> allow = (0010) == (0010)
2362 * --> allow = 1
2363 *
2364 * Other examples:
2365 *
2366 * IFRAME-03: 0100 --> allowed
2367 * IFRAME-04: 1001 --> allowed
2368 * IFRAME-05: 1101 --> allowed but its not for us!!!
2369 *
2370 */
2371int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
2372{
2373 u32 low_id, high_id;
2374 ATH5K_TRACE(ah->ah_sc);
2375
2376 if (ah->ah_version == AR5K_AR5212) {
2377 low_id = AR5K_LOW_ID(mask);
2378 high_id = AR5K_HIGH_ID(mask);
2379
2380 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_IDM0);
2381 ath5k_hw_reg_write(ah, high_id, AR5K_BSS_IDM1);
2382
2383 return 0;
2384 }
2385
2386 return -EIO;
2387}
2388
2389/*
2390 * Receive start/stop functions
2391 */
2392
2393/*
2394 * Start receive on PCU
2395 */
2396void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
2397{
2398 ATH5K_TRACE(ah->ah_sc);
2399 AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
2400}
2401
2402/*
2403 * Stop receive on PCU
2404 */
2405void ath5k_hw_stop_pcu_recv(struct ath5k_hw *ah)
2406{
2407 ATH5K_TRACE(ah->ah_sc);
2408 AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
2409}
2410
2411/*
2412 * RX Filter functions
2413 */
2414
2415/*
2416 * Set multicast filter
2417 */
2418void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
2419{
2420 ATH5K_TRACE(ah->ah_sc);
2421 /* Set the multicat filter */
2422 ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0);
2423 ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1);
2424}
2425
2426/*
2427 * Set multicast filter by index
2428 */
2429int ath5k_hw_set_mcast_filterindex(struct ath5k_hw *ah, u32 index)
2430{
2431
2432 ATH5K_TRACE(ah->ah_sc);
2433 if (index >= 64)
2434 return -EINVAL;
2435 else if (index >= 32)
2436 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER1,
2437 (1 << (index - 32)));
2438 else
2439 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2440
2441 return 0;
2442}
2443
2444/*
2445 * Clear Multicast filter by index
2446 */
2447int ath5k_hw_clear_mcast_filter_idx(struct ath5k_hw *ah, u32 index)
2448{
2449
2450 ATH5K_TRACE(ah->ah_sc);
2451 if (index >= 64)
2452 return -EINVAL;
2453 else if (index >= 32)
2454 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER1,
2455 (1 << (index - 32)));
2456 else
2457 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2458
2459 return 0;
2460}
2461
2462/*
2463 * Get current rx filter
2464 */
2465u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah)
2466{
2467 u32 data, filter = 0;
2468
2469 ATH5K_TRACE(ah->ah_sc);
2470 filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER);
2471
2472 /*Radar detection for 5212*/
2473 if (ah->ah_version == AR5K_AR5212) {
2474 data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL);
2475
2476 if (data & AR5K_PHY_ERR_FIL_RADAR)
2477 filter |= AR5K_RX_FILTER_RADARERR;
2478 if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK))
2479 filter |= AR5K_RX_FILTER_PHYERR;
2480 }
2481
2482 return filter;
2483}
2484
2485/*
2486 * Set rx filter
2487 */
2488void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
2489{
2490 u32 data = 0;
2491
2492 ATH5K_TRACE(ah->ah_sc);
2493
2494 /* Set PHY error filter register on 5212*/
2495 if (ah->ah_version == AR5K_AR5212) {
2496 if (filter & AR5K_RX_FILTER_RADARERR)
2497 data |= AR5K_PHY_ERR_FIL_RADAR;
2498 if (filter & AR5K_RX_FILTER_PHYERR)
2499 data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK;
2500 }
2501
2502 /*
2503 * The AR5210 uses promiscous mode to detect radar activity
2504 */
2505 if (ah->ah_version == AR5K_AR5210 &&
2506 (filter & AR5K_RX_FILTER_RADARERR)) {
2507 filter &= ~AR5K_RX_FILTER_RADARERR;
2508 filter |= AR5K_RX_FILTER_PROM;
2509 }
2510
2511 /*Zero length DMA*/
2512 if (data)
2513 AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2514 else
2515 AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2516
2517 /*Write RX Filter register*/
2518 ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER);
2519
2520 /*Write PHY error filter register on 5212*/
2521 if (ah->ah_version == AR5K_AR5212)
2522 ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
2523
2524}
2525
2526/*
2527 * Beacon related functions
2528 */
2529
2530/*
2531 * Get a 32bit TSF
2532 */
2533u32 ath5k_hw_get_tsf32(struct ath5k_hw *ah)
2534{
2535 ATH5K_TRACE(ah->ah_sc);
2536 return ath5k_hw_reg_read(ah, AR5K_TSF_L32);
2537}
2538
2539/*
2540 * Get the full 64bit TSF
2541 */
2542u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah)
2543{
2544 u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
2545 ATH5K_TRACE(ah->ah_sc);
2546
2547 return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32);
2548}
2549
2550/*
2551 * Force a TSF reset
2552 */
2553void ath5k_hw_reset_tsf(struct ath5k_hw *ah)
2554{
2555 ATH5K_TRACE(ah->ah_sc);
2556 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_RESET_TSF);
2557}
2558
2559/*
2560 * Initialize beacon timers
2561 */
2562void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
2563{
2564 u32 timer1, timer2, timer3;
2565
2566 ATH5K_TRACE(ah->ah_sc);
2567 /*
2568 * Set the additional timers by mode
2569 */
2570 switch (ah->ah_op_mode) {
2571 case IEEE80211_IF_TYPE_STA:
2572 if (ah->ah_version == AR5K_AR5210) {
2573 timer1 = 0xffffffff;
2574 timer2 = 0xffffffff;
2575 } else {
2576 timer1 = 0x0000ffff;
2577 timer2 = 0x0007ffff;
2578 }
2579 break;
2580
2581 default:
Bruno Randolf1008e0f2008-01-18 21:51:19 +09002582 timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3;
2583 timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02002584 }
2585
2586 timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1);
2587
2588 /*
2589 * Set the beacon register and enable all timers.
2590 * (next beacon, DMA beacon, software beacon, ATIM window time)
2591 */
2592 ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
2593 ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
2594 ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
2595 ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
2596
2597 ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD |
2598 AR5K_BEACON_RESET_TSF | AR5K_BEACON_ENABLE),
2599 AR5K_BEACON);
2600}
2601
2602#if 0
2603/*
2604 * Set beacon timers
2605 */
2606int ath5k_hw_set_beacon_timers(struct ath5k_hw *ah,
2607 const struct ath5k_beacon_state *state)
2608{
2609 u32 cfp_period, next_cfp, dtim, interval, next_beacon;
2610
2611 /*
2612 * TODO: should be changed through *state
2613 * review struct ath5k_beacon_state struct
2614 *
2615 * XXX: These are used for cfp period bellow, are they
2616 * ok ? Is it O.K. for tsf here to be 0 or should we use
2617 * get_tsf ?
2618 */
2619 u32 dtim_count = 0; /* XXX */
2620 u32 cfp_count = 0; /* XXX */
2621 u32 tsf = 0; /* XXX */
2622
2623 ATH5K_TRACE(ah->ah_sc);
2624 /* Return on an invalid beacon state */
2625 if (state->bs_interval < 1)
2626 return -EINVAL;
2627
2628 interval = state->bs_interval;
2629 dtim = state->bs_dtim_period;
2630
2631 /*
2632 * PCF support?
2633 */
2634 if (state->bs_cfp_period > 0) {
2635 /*
2636 * Enable PCF mode and set the CFP
2637 * (Contention Free Period) and timer registers
2638 */
2639 cfp_period = state->bs_cfp_period * state->bs_dtim_period *
2640 state->bs_interval;
2641 next_cfp = (cfp_count * state->bs_dtim_period + dtim_count) *
2642 state->bs_interval;
2643
2644 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
2645 AR5K_STA_ID1_DEFAULT_ANTENNA |
2646 AR5K_STA_ID1_PCF);
2647 ath5k_hw_reg_write(ah, cfp_period, AR5K_CFP_PERIOD);
2648 ath5k_hw_reg_write(ah, state->bs_cfp_max_duration,
2649 AR5K_CFP_DUR);
2650 ath5k_hw_reg_write(ah, (tsf + (next_cfp == 0 ? cfp_period :
2651 next_cfp)) << 3, AR5K_TIMER2);
2652 } else {
2653 /* Disable PCF mode */
2654 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2655 AR5K_STA_ID1_DEFAULT_ANTENNA |
2656 AR5K_STA_ID1_PCF);
2657 }
2658
2659 /*
2660 * Enable the beacon timer register
2661 */
2662 ath5k_hw_reg_write(ah, state->bs_next_beacon, AR5K_TIMER0);
2663
2664 /*
2665 * Start the beacon timers
2666 */
2667 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_BEACON) &~
2668 (AR5K_BEACON_PERIOD | AR5K_BEACON_TIM)) |
2669 AR5K_REG_SM(state->bs_tim_offset ? state->bs_tim_offset + 4 : 0,
2670 AR5K_BEACON_TIM) | AR5K_REG_SM(state->bs_interval,
2671 AR5K_BEACON_PERIOD), AR5K_BEACON);
2672
2673 /*
2674 * Write new beacon miss threshold, if it appears to be valid
2675 * XXX: Figure out right values for min <= bs_bmiss_threshold <= max
2676 * and return if its not in range. We can test this by reading value and
2677 * setting value to a largest value and seeing which values register.
2678 */
2679
2680 AR5K_REG_WRITE_BITS(ah, AR5K_RSSI_THR, AR5K_RSSI_THR_BMISS,
2681 state->bs_bmiss_threshold);
2682
2683 /*
2684 * Set sleep control register
2685 * XXX: Didn't find this in 5210 code but since this register
2686 * exists also in ar5k's 5210 headers i leave it as common code.
2687 */
2688 AR5K_REG_WRITE_BITS(ah, AR5K_SLEEP_CTL, AR5K_SLEEP_CTL_SLDUR,
2689 (state->bs_sleep_duration - 3) << 3);
2690
2691 /*
2692 * Set enhanced sleep registers on 5212
2693 */
2694 if (ah->ah_version == AR5K_AR5212) {
2695 if (state->bs_sleep_duration > state->bs_interval &&
2696 roundup(state->bs_sleep_duration, interval) ==
2697 state->bs_sleep_duration)
2698 interval = state->bs_sleep_duration;
2699
2700 if (state->bs_sleep_duration > dtim && (dtim == 0 ||
2701 roundup(state->bs_sleep_duration, dtim) ==
2702 state->bs_sleep_duration))
2703 dtim = state->bs_sleep_duration;
2704
2705 if (interval > dtim)
2706 return -EINVAL;
2707
2708 next_beacon = interval == dtim ? state->bs_next_dtim :
2709 state->bs_next_beacon;
2710
2711 ath5k_hw_reg_write(ah,
2712 AR5K_REG_SM((state->bs_next_dtim - 3) << 3,
2713 AR5K_SLEEP0_NEXT_DTIM) |
2714 AR5K_REG_SM(10, AR5K_SLEEP0_CABTO) |
2715 AR5K_SLEEP0_ENH_SLEEP_EN |
2716 AR5K_SLEEP0_ASSUME_DTIM, AR5K_SLEEP0);
2717
2718 ath5k_hw_reg_write(ah, AR5K_REG_SM((next_beacon - 3) << 3,
2719 AR5K_SLEEP1_NEXT_TIM) |
2720 AR5K_REG_SM(10, AR5K_SLEEP1_BEACON_TO), AR5K_SLEEP1);
2721
2722 ath5k_hw_reg_write(ah,
2723 AR5K_REG_SM(interval, AR5K_SLEEP2_TIM_PER) |
2724 AR5K_REG_SM(dtim, AR5K_SLEEP2_DTIM_PER), AR5K_SLEEP2);
2725 }
2726
2727 return 0;
2728}
2729
2730/*
2731 * Reset beacon timers
2732 */
2733void ath5k_hw_reset_beacon(struct ath5k_hw *ah)
2734{
2735 ATH5K_TRACE(ah->ah_sc);
2736 /*
2737 * Disable beacon timer
2738 */
2739 ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
2740
2741 /*
2742 * Disable some beacon register values
2743 */
2744 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2745 AR5K_STA_ID1_DEFAULT_ANTENNA | AR5K_STA_ID1_PCF);
2746 ath5k_hw_reg_write(ah, AR5K_BEACON_PERIOD, AR5K_BEACON);
2747}
2748
2749/*
2750 * Wait for beacon queue to finish
2751 */
2752int ath5k_hw_beaconq_finish(struct ath5k_hw *ah, unsigned long phys_addr)
2753{
2754 unsigned int i;
2755 int ret;
2756
2757 ATH5K_TRACE(ah->ah_sc);
2758
2759 /* 5210 doesn't have QCU*/
2760 if (ah->ah_version == AR5K_AR5210) {
2761 /*
2762 * Wait for beaconn queue to finish by checking
2763 * Control Register and Beacon Status Register.
2764 */
2765 for (i = AR5K_TUNE_BEACON_INTERVAL / 2; i > 0; i--) {
2766 if (!(ath5k_hw_reg_read(ah, AR5K_BSR) & AR5K_BSR_TXQ1F)
2767 ||
2768 !(ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_BSR_TXQ1F))
2769 break;
2770 udelay(10);
2771 }
2772
2773 /* Timeout... */
2774 if (i <= 0) {
2775 /*
2776 * Re-schedule the beacon queue
2777 */
2778 ath5k_hw_reg_write(ah, phys_addr, AR5K_NOQCU_TXDP1);
2779 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
2780 AR5K_BCR);
2781
2782 return -EIO;
2783 }
2784 ret = 0;
2785 } else {
2786 /*5211/5212*/
2787 ret = ath5k_hw_register_timeout(ah,
2788 AR5K_QUEUE_STATUS(AR5K_TX_QUEUE_ID_BEACON),
2789 AR5K_QCU_STS_FRMPENDCNT, 0, false);
2790
2791 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, AR5K_TX_QUEUE_ID_BEACON))
2792 return -EIO;
2793 }
2794
2795 return ret;
2796}
2797#endif
2798
2799/*
2800 * Update mib counters (statistics)
2801 */
2802void ath5k_hw_update_mib_counters(struct ath5k_hw *ah,
2803 struct ath5k_mib_stats *statistics)
2804{
2805 ATH5K_TRACE(ah->ah_sc);
2806 /* Read-And-Clear */
2807 statistics->ackrcv_bad += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL);
2808 statistics->rts_bad += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL);
2809 statistics->rts_good += ath5k_hw_reg_read(ah, AR5K_RTS_OK);
2810 statistics->fcs_bad += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL);
2811 statistics->beacons += ath5k_hw_reg_read(ah, AR5K_BEACON_CNT);
2812
2813 /* Reset profile count registers on 5212*/
2814 if (ah->ah_version == AR5K_AR5212) {
2815 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_TX);
2816 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RX);
2817 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR);
2818 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE);
2819 }
2820}
2821
2822/** ath5k_hw_set_ack_bitrate - set bitrate for ACKs
2823 *
2824 * @ah: the &struct ath5k_hw
2825 * @high: determines if to use low bit rate or now
2826 */
2827void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high)
2828{
2829 if (ah->ah_version != AR5K_AR5212)
2830 return;
2831 else {
2832 u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB;
2833 if (high)
2834 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val);
2835 else
2836 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val);
2837 }
2838}
2839
2840
2841/*
2842 * ACK/CTS Timeouts
2843 */
2844
2845/*
2846 * Set ACK timeout on PCU
2847 */
2848int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout)
2849{
2850 ATH5K_TRACE(ah->ah_sc);
2851 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK),
2852 ah->ah_turbo) <= timeout)
2853 return -EINVAL;
2854
2855 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK,
2856 ath5k_hw_htoclock(timeout, ah->ah_turbo));
2857
2858 return 0;
2859}
2860
2861/*
2862 * Read the ACK timeout from PCU
2863 */
2864unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah)
2865{
2866 ATH5K_TRACE(ah->ah_sc);
2867
2868 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
2869 AR5K_TIME_OUT), AR5K_TIME_OUT_ACK), ah->ah_turbo);
2870}
2871
2872/*
2873 * Set CTS timeout on PCU
2874 */
2875int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout)
2876{
2877 ATH5K_TRACE(ah->ah_sc);
2878 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS),
2879 ah->ah_turbo) <= timeout)
2880 return -EINVAL;
2881
2882 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS,
2883 ath5k_hw_htoclock(timeout, ah->ah_turbo));
2884
2885 return 0;
2886}
2887
2888/*
2889 * Read CTS timeout from PCU
2890 */
2891unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah)
2892{
2893 ATH5K_TRACE(ah->ah_sc);
2894 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
2895 AR5K_TIME_OUT), AR5K_TIME_OUT_CTS), ah->ah_turbo);
2896}
2897
2898/*
2899 * Key table (WEP) functions
2900 */
2901
2902int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
2903{
2904 unsigned int i;
2905
2906 ATH5K_TRACE(ah->ah_sc);
2907 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
2908
2909 for (i = 0; i < AR5K_KEYCACHE_SIZE; i++)
2910 ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i));
2911
2912 /* Set NULL encryption on non-5210*/
2913 if (ah->ah_version != AR5K_AR5210)
2914 ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
2915 AR5K_KEYTABLE_TYPE(entry));
2916
2917 return 0;
2918}
2919
2920int ath5k_hw_is_key_valid(struct ath5k_hw *ah, u16 entry)
2921{
2922 ATH5K_TRACE(ah->ah_sc);
2923 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
2924
2925 /* Check the validation flag at the end of the entry */
2926 return ath5k_hw_reg_read(ah, AR5K_KEYTABLE_MAC1(entry)) &
2927 AR5K_KEYTABLE_VALID;
2928}
2929
2930int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
2931 const struct ieee80211_key_conf *key, const u8 *mac)
2932{
2933 unsigned int i;
2934 __le32 key_v[5] = {};
2935 u32 keytype;
2936
2937 ATH5K_TRACE(ah->ah_sc);
2938
2939 /* key->keylen comes in from mac80211 in bytes */
2940
2941 if (key->keylen > AR5K_KEYTABLE_SIZE / 8)
2942 return -EOPNOTSUPP;
2943
2944 switch (key->keylen) {
2945 /* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit */
2946 case 40 / 8:
2947 memcpy(&key_v[0], key->key, 5);
2948 keytype = AR5K_KEYTABLE_TYPE_40;
2949 break;
2950
2951 /* WEP 104-bit = 104-bit entered key + 24-bit IV = 128-bit */
2952 case 104 / 8:
2953 memcpy(&key_v[0], &key->key[0], 6);
2954 memcpy(&key_v[2], &key->key[6], 6);
2955 memcpy(&key_v[4], &key->key[12], 1);
2956 keytype = AR5K_KEYTABLE_TYPE_104;
2957 break;
2958 /* WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit */
2959 case 128 / 8:
2960 memcpy(&key_v[0], &key->key[0], 6);
2961 memcpy(&key_v[2], &key->key[6], 6);
2962 memcpy(&key_v[4], &key->key[12], 4);
2963 keytype = AR5K_KEYTABLE_TYPE_128;
2964 break;
2965
2966 default:
2967 return -EINVAL; /* shouldn't happen */
2968 }
2969
2970 for (i = 0; i < ARRAY_SIZE(key_v); i++)
2971 ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
2972 AR5K_KEYTABLE_OFF(entry, i));
2973
2974 ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry));
2975
2976 return ath5k_hw_set_key_lladdr(ah, entry, mac);
2977}
2978
2979int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac)
2980{
2981 u32 low_id, high_id;
2982
2983 ATH5K_TRACE(ah->ah_sc);
2984 /* Invalid entry (key table overflow) */
2985 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
2986
2987 /* MAC may be NULL if it's a broadcast key. In this case no need to
2988 * to compute AR5K_LOW_ID and AR5K_HIGH_ID as we already know it. */
2989 if (unlikely(mac == NULL)) {
2990 low_id = 0xffffffff;
2991 high_id = 0xffff | AR5K_KEYTABLE_VALID;
2992 } else {
2993 low_id = AR5K_LOW_ID(mac);
2994 high_id = AR5K_HIGH_ID(mac) | AR5K_KEYTABLE_VALID;
2995 }
2996
2997 ath5k_hw_reg_write(ah, low_id, AR5K_KEYTABLE_MAC0(entry));
2998 ath5k_hw_reg_write(ah, high_id, AR5K_KEYTABLE_MAC1(entry));
2999
3000 return 0;
3001}
3002
3003
3004/********************************************\
3005Queue Control Unit, DFS Control Unit Functions
3006\********************************************/
3007
3008/*
3009 * Initialize a transmit queue
3010 */
3011int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type,
3012 struct ath5k_txq_info *queue_info)
3013{
3014 unsigned int queue;
3015 int ret;
3016
3017 ATH5K_TRACE(ah->ah_sc);
3018
3019 /*
3020 * Get queue by type
3021 */
3022 /*5210 only has 2 queues*/
3023 if (ah->ah_version == AR5K_AR5210) {
3024 switch (queue_type) {
3025 case AR5K_TX_QUEUE_DATA:
3026 queue = AR5K_TX_QUEUE_ID_NOQCU_DATA;
3027 break;
3028 case AR5K_TX_QUEUE_BEACON:
3029 case AR5K_TX_QUEUE_CAB:
3030 queue = AR5K_TX_QUEUE_ID_NOQCU_BEACON;
3031 break;
3032 default:
3033 return -EINVAL;
3034 }
3035 } else {
3036 switch (queue_type) {
3037 case AR5K_TX_QUEUE_DATA:
3038 for (queue = AR5K_TX_QUEUE_ID_DATA_MIN;
3039 ah->ah_txq[queue].tqi_type !=
3040 AR5K_TX_QUEUE_INACTIVE; queue++) {
3041
3042 if (queue > AR5K_TX_QUEUE_ID_DATA_MAX)
3043 return -EINVAL;
3044 }
3045 break;
3046 case AR5K_TX_QUEUE_UAPSD:
3047 queue = AR5K_TX_QUEUE_ID_UAPSD;
3048 break;
3049 case AR5K_TX_QUEUE_BEACON:
3050 queue = AR5K_TX_QUEUE_ID_BEACON;
3051 break;
3052 case AR5K_TX_QUEUE_CAB:
3053 queue = AR5K_TX_QUEUE_ID_CAB;
3054 break;
3055 case AR5K_TX_QUEUE_XR_DATA:
3056 if (ah->ah_version != AR5K_AR5212)
3057 ATH5K_ERR(ah->ah_sc,
3058 "XR data queues only supported in"
3059 " 5212!\n");
3060 queue = AR5K_TX_QUEUE_ID_XR_DATA;
3061 break;
3062 default:
3063 return -EINVAL;
3064 }
3065 }
3066
3067 /*
3068 * Setup internal queue structure
3069 */
3070 memset(&ah->ah_txq[queue], 0, sizeof(struct ath5k_txq_info));
3071 ah->ah_txq[queue].tqi_type = queue_type;
3072
3073 if (queue_info != NULL) {
3074 queue_info->tqi_type = queue_type;
3075 ret = ath5k_hw_setup_tx_queueprops(ah, queue, queue_info);
3076 if (ret)
3077 return ret;
3078 }
3079 /*
3080 * We use ah_txq_status to hold a temp value for
3081 * the Secondary interrupt mask registers on 5211+
3082 * check out ath5k_hw_reset_tx_queue
3083 */
3084 AR5K_Q_ENABLE_BITS(ah->ah_txq_status, queue);
3085
3086 return queue;
3087}
3088
3089/*
3090 * Setup a transmit queue
3091 */
3092int ath5k_hw_setup_tx_queueprops(struct ath5k_hw *ah, int queue,
3093 const struct ath5k_txq_info *queue_info)
3094{
3095 ATH5K_TRACE(ah->ah_sc);
3096 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3097
3098 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3099 return -EIO;
3100
3101 memcpy(&ah->ah_txq[queue], queue_info, sizeof(struct ath5k_txq_info));
3102
3103 /*XXX: Is this supported on 5210 ?*/
3104 if ((queue_info->tqi_type == AR5K_TX_QUEUE_DATA &&
3105 ((queue_info->tqi_subtype == AR5K_WME_AC_VI) ||
3106 (queue_info->tqi_subtype == AR5K_WME_AC_VO))) ||
3107 queue_info->tqi_type == AR5K_TX_QUEUE_UAPSD)
3108 ah->ah_txq[queue].tqi_flags |= AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
3109
3110 return 0;
3111}
3112
3113/*
3114 * Get properties for a specific transmit queue
3115 */
3116int ath5k_hw_get_tx_queueprops(struct ath5k_hw *ah, int queue,
3117 struct ath5k_txq_info *queue_info)
3118{
3119 ATH5K_TRACE(ah->ah_sc);
3120 memcpy(queue_info, &ah->ah_txq[queue], sizeof(struct ath5k_txq_info));
3121 return 0;
3122}
3123
3124/*
3125 * Set a transmit queue inactive
3126 */
3127void ath5k_hw_release_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3128{
3129 ATH5K_TRACE(ah->ah_sc);
3130 if (WARN_ON(queue >= ah->ah_capabilities.cap_queues.q_tx_num))
3131 return;
3132
3133 /* This queue will be skipped in further operations */
3134 ah->ah_txq[queue].tqi_type = AR5K_TX_QUEUE_INACTIVE;
3135 /*For SIMR setup*/
3136 AR5K_Q_DISABLE_BITS(ah->ah_txq_status, queue);
3137}
3138
3139/*
3140 * Set DFS params for a transmit queue
3141 */
3142int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3143{
3144 u32 cw_min, cw_max, retry_lg, retry_sh;
3145 struct ath5k_txq_info *tq = &ah->ah_txq[queue];
3146
3147 ATH5K_TRACE(ah->ah_sc);
3148 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3149
3150 tq = &ah->ah_txq[queue];
3151
3152 if (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE)
3153 return 0;
3154
3155 if (ah->ah_version == AR5K_AR5210) {
3156 /* Only handle data queues, others will be ignored */
3157 if (tq->tqi_type != AR5K_TX_QUEUE_DATA)
3158 return 0;
3159
3160 /* Set Slot time */
3161 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3162 AR5K_INIT_SLOT_TIME_TURBO : AR5K_INIT_SLOT_TIME,
3163 AR5K_SLOT_TIME);
3164 /* Set ACK_CTS timeout */
3165 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3166 AR5K_INIT_ACK_CTS_TIMEOUT_TURBO :
3167 AR5K_INIT_ACK_CTS_TIMEOUT, AR5K_SLOT_TIME);
3168 /* Set Transmit Latency */
3169 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3170 AR5K_INIT_TRANSMIT_LATENCY_TURBO :
3171 AR5K_INIT_TRANSMIT_LATENCY, AR5K_USEC_5210);
3172 /* Set IFS0 */
3173 if (ah->ah_turbo == true)
3174 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS_TURBO +
3175 (ah->ah_aifs + tq->tqi_aifs) *
3176 AR5K_INIT_SLOT_TIME_TURBO) <<
3177 AR5K_IFS0_DIFS_S) | AR5K_INIT_SIFS_TURBO,
3178 AR5K_IFS0);
3179 else
3180 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS +
3181 (ah->ah_aifs + tq->tqi_aifs) *
3182 AR5K_INIT_SLOT_TIME) << AR5K_IFS0_DIFS_S) |
3183 AR5K_INIT_SIFS, AR5K_IFS0);
3184
3185 /* Set IFS1 */
3186 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3187 AR5K_INIT_PROTO_TIME_CNTRL_TURBO :
3188 AR5K_INIT_PROTO_TIME_CNTRL, AR5K_IFS1);
3189 /* Set PHY register 0x9844 (??) */
3190 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3191 (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x38 :
3192 (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x1C,
3193 AR5K_PHY(17));
3194 /* Set Frame Control Register */
3195 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3196 (AR5K_PHY_FRAME_CTL_INI | AR5K_PHY_TURBO_MODE |
3197 AR5K_PHY_TURBO_SHORT | 0x2020) :
3198 (AR5K_PHY_FRAME_CTL_INI | 0x1020),
3199 AR5K_PHY_FRAME_CTL_5210);
3200 }
3201
3202 /*
3203 * Calculate cwmin/max by channel mode
3204 */
3205 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN;
3206 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX;
3207 ah->ah_aifs = AR5K_TUNE_AIFS;
3208 /*XR is only supported on 5212*/
3209 if (IS_CHAN_XR(ah->ah_current_channel) &&
3210 ah->ah_version == AR5K_AR5212) {
3211 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_XR;
3212 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_XR;
3213 ah->ah_aifs = AR5K_TUNE_AIFS_XR;
3214 /*B mode is not supported on 5210*/
3215 } else if (IS_CHAN_B(ah->ah_current_channel) &&
3216 ah->ah_version != AR5K_AR5210) {
3217 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_11B;
3218 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_11B;
3219 ah->ah_aifs = AR5K_TUNE_AIFS_11B;
3220 }
3221
3222 cw_min = 1;
3223 while (cw_min < ah->ah_cw_min)
3224 cw_min = (cw_min << 1) | 1;
3225
3226 cw_min = tq->tqi_cw_min < 0 ? (cw_min >> (-tq->tqi_cw_min)) :
3227 ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
3228 cw_max = tq->tqi_cw_max < 0 ? (cw_max >> (-tq->tqi_cw_max)) :
3229 ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
3230
3231 /*
3232 * Calculate and set retry limits
3233 */
3234 if (ah->ah_software_retry == true) {
3235 /* XXX Need to test this */
3236 retry_lg = ah->ah_limit_tx_retries;
3237 retry_sh = retry_lg = retry_lg > AR5K_DCU_RETRY_LMT_SH_RETRY ?
3238 AR5K_DCU_RETRY_LMT_SH_RETRY : retry_lg;
3239 } else {
3240 retry_lg = AR5K_INIT_LG_RETRY;
3241 retry_sh = AR5K_INIT_SH_RETRY;
3242 }
3243
3244 /*No QCU/DCU [5210]*/
3245 if (ah->ah_version == AR5K_AR5210) {
3246 ath5k_hw_reg_write(ah,
3247 (cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
3248 | AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3249 AR5K_NODCU_RETRY_LMT_SLG_RETRY)
3250 | AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3251 AR5K_NODCU_RETRY_LMT_SSH_RETRY)
3252 | AR5K_REG_SM(retry_lg, AR5K_NODCU_RETRY_LMT_LG_RETRY)
3253 | AR5K_REG_SM(retry_sh, AR5K_NODCU_RETRY_LMT_SH_RETRY),
3254 AR5K_NODCU_RETRY_LMT);
3255 } else {
3256 /*QCU/DCU [5211+]*/
3257 ath5k_hw_reg_write(ah,
3258 AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3259 AR5K_DCU_RETRY_LMT_SLG_RETRY) |
3260 AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3261 AR5K_DCU_RETRY_LMT_SSH_RETRY) |
3262 AR5K_REG_SM(retry_lg, AR5K_DCU_RETRY_LMT_LG_RETRY) |
3263 AR5K_REG_SM(retry_sh, AR5K_DCU_RETRY_LMT_SH_RETRY),
3264 AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
3265
3266 /*===Rest is also for QCU/DCU only [5211+]===*/
3267
3268 /*
3269 * Set initial content window (cw_min/cw_max)
3270 * and arbitrated interframe space (aifs)...
3271 */
3272 ath5k_hw_reg_write(ah,
3273 AR5K_REG_SM(cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
3274 AR5K_REG_SM(cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
3275 AR5K_REG_SM(ah->ah_aifs + tq->tqi_aifs,
3276 AR5K_DCU_LCL_IFS_AIFS),
3277 AR5K_QUEUE_DFS_LOCAL_IFS(queue));
3278
3279 /*
3280 * Set misc registers
3281 */
3282 ath5k_hw_reg_write(ah, AR5K_QCU_MISC_DCU_EARLY,
3283 AR5K_QUEUE_MISC(queue));
3284
3285 if (tq->tqi_cbr_period) {
3286 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
3287 AR5K_QCU_CBRCFG_INTVAL) |
3288 AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
3289 AR5K_QCU_CBRCFG_ORN_THRES),
3290 AR5K_QUEUE_CBRCFG(queue));
3291 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3292 AR5K_QCU_MISC_FRSHED_CBR);
3293 if (tq->tqi_cbr_overflow_limit)
3294 AR5K_REG_ENABLE_BITS(ah,
3295 AR5K_QUEUE_MISC(queue),
3296 AR5K_QCU_MISC_CBR_THRES_ENABLE);
3297 }
3298
3299 if (tq->tqi_ready_time)
3300 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
3301 AR5K_QCU_RDYTIMECFG_INTVAL) |
3302 AR5K_QCU_RDYTIMECFG_ENABLE,
3303 AR5K_QUEUE_RDYTIMECFG(queue));
3304
3305 if (tq->tqi_burst_time) {
3306 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
3307 AR5K_DCU_CHAN_TIME_DUR) |
3308 AR5K_DCU_CHAN_TIME_ENABLE,
3309 AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
3310
3311 if (tq->tqi_flags & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
3312 AR5K_REG_ENABLE_BITS(ah,
3313 AR5K_QUEUE_MISC(queue),
3314 AR5K_QCU_MISC_TXE);
3315 }
3316
3317 if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
3318 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
3319 AR5K_QUEUE_DFS_MISC(queue));
3320
3321 if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
3322 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
3323 AR5K_QUEUE_DFS_MISC(queue));
3324
3325 /*
3326 * Set registers by queue type
3327 */
3328 switch (tq->tqi_type) {
3329 case AR5K_TX_QUEUE_BEACON:
3330 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3331 AR5K_QCU_MISC_FRSHED_DBA_GT |
3332 AR5K_QCU_MISC_CBREXP_BCN |
3333 AR5K_QCU_MISC_BCN_ENABLE);
3334
3335 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3336 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3337 AR5K_DCU_MISC_ARBLOCK_CTL_S) |
3338 AR5K_DCU_MISC_POST_FR_BKOFF_DIS |
3339 AR5K_DCU_MISC_BCN_ENABLE);
3340
3341 ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL -
3342 (AR5K_TUNE_SW_BEACON_RESP -
3343 AR5K_TUNE_DMA_BEACON_RESP) -
3344 AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF) * 1024) |
3345 AR5K_QCU_RDYTIMECFG_ENABLE,
3346 AR5K_QUEUE_RDYTIMECFG(queue));
3347 break;
3348
3349 case AR5K_TX_QUEUE_CAB:
3350 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3351 AR5K_QCU_MISC_FRSHED_DBA_GT |
3352 AR5K_QCU_MISC_CBREXP |
3353 AR5K_QCU_MISC_CBREXP_BCN);
3354
3355 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3356 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3357 AR5K_DCU_MISC_ARBLOCK_CTL_S));
3358 break;
3359
3360 case AR5K_TX_QUEUE_UAPSD:
3361 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3362 AR5K_QCU_MISC_CBREXP);
3363 break;
3364
3365 case AR5K_TX_QUEUE_DATA:
3366 default:
3367 break;
3368 }
3369
3370 /*
3371 * Enable interrupts for this tx queue
3372 * in the secondary interrupt mask registers
3373 */
3374 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
3375 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
3376
3377 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
3378 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
3379
3380 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
3381 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
3382
3383 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
3384 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
3385
3386 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
3387 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
3388
3389
3390 /* Update secondary interrupt mask registers */
3391 ah->ah_txq_imr_txok &= ah->ah_txq_status;
3392 ah->ah_txq_imr_txerr &= ah->ah_txq_status;
3393 ah->ah_txq_imr_txurn &= ah->ah_txq_status;
3394 ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
3395 ah->ah_txq_imr_txeol &= ah->ah_txq_status;
3396
3397 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
3398 AR5K_SIMR0_QCU_TXOK) |
3399 AR5K_REG_SM(ah->ah_txq_imr_txdesc,
3400 AR5K_SIMR0_QCU_TXDESC), AR5K_SIMR0);
3401 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
3402 AR5K_SIMR1_QCU_TXERR) |
3403 AR5K_REG_SM(ah->ah_txq_imr_txeol,
3404 AR5K_SIMR1_QCU_TXEOL), AR5K_SIMR1);
3405 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txurn,
3406 AR5K_SIMR2_QCU_TXURN), AR5K_SIMR2);
3407 }
3408
3409 return 0;
3410}
3411
3412/*
3413 * Get number of pending frames
3414 * for a specific queue [5211+]
3415 */
3416u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah, unsigned int queue) {
3417 ATH5K_TRACE(ah->ah_sc);
3418 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3419
3420 /* Return if queue is declared inactive */
3421 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3422 return false;
3423
3424 /* XXX: How about AR5K_CFG_TXCNT ? */
3425 if (ah->ah_version == AR5K_AR5210)
3426 return false;
3427
3428 return AR5K_QUEUE_STATUS(queue) & AR5K_QCU_STS_FRMPENDCNT;
3429}
3430
3431/*
3432 * Set slot time
3433 */
3434int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time)
3435{
3436 ATH5K_TRACE(ah->ah_sc);
3437 if (slot_time < AR5K_SLOT_TIME_9 || slot_time > AR5K_SLOT_TIME_MAX)
3438 return -EINVAL;
3439
3440 if (ah->ah_version == AR5K_AR5210)
3441 ath5k_hw_reg_write(ah, ath5k_hw_htoclock(slot_time,
3442 ah->ah_turbo), AR5K_SLOT_TIME);
3443 else
3444 ath5k_hw_reg_write(ah, slot_time, AR5K_DCU_GBL_IFS_SLOT);
3445
3446 return 0;
3447}
3448
3449/*
3450 * Get slot time
3451 */
3452unsigned int ath5k_hw_get_slot_time(struct ath5k_hw *ah)
3453{
3454 ATH5K_TRACE(ah->ah_sc);
3455 if (ah->ah_version == AR5K_AR5210)
3456 return ath5k_hw_clocktoh(ath5k_hw_reg_read(ah,
3457 AR5K_SLOT_TIME) & 0xffff, ah->ah_turbo);
3458 else
3459 return ath5k_hw_reg_read(ah, AR5K_DCU_GBL_IFS_SLOT) & 0xffff;
3460}
3461
3462
3463/******************************\
3464 Hardware Descriptor Functions
3465\******************************/
3466
3467/*
3468 * TX Descriptor
3469 */
3470
3471/*
3472 * Initialize the 2-word tx descriptor on 5210/5211
3473 */
3474static int
3475ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3476 unsigned int pkt_len, unsigned int hdr_len, enum ath5k_pkt_type type,
3477 unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
3478 unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
3479 unsigned int rtscts_rate, unsigned int rtscts_duration)
3480{
3481 u32 frame_type;
3482 struct ath5k_hw_2w_tx_desc *tx_desc;
Bruno Randolf281c56d2008-02-05 18:44:55 +09003483 unsigned int frame_len;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003484
3485 tx_desc = (struct ath5k_hw_2w_tx_desc *)&desc->ds_ctl0;
3486
3487 /*
3488 * Validate input
3489 * - Zero retries don't make sense.
3490 * - A zero rate will put the HW into a mode where it continously sends
3491 * noise on the channel, so it is important to avoid this.
3492 */
3493 if (unlikely(tx_tries0 == 0)) {
3494 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3495 WARN_ON(1);
3496 return -EINVAL;
3497 }
3498 if (unlikely(tx_rate0 == 0)) {
3499 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3500 WARN_ON(1);
3501 return -EINVAL;
3502 }
3503
3504 /* Clear status descriptor */
3505 memset(desc->ds_hw, 0, sizeof(struct ath5k_hw_tx_status));
3506
3507 /* Initialize control descriptor */
3508 tx_desc->tx_control_0 = 0;
3509 tx_desc->tx_control_1 = 0;
3510
3511 /* Setup control descriptor */
3512
3513 /* Verify and set frame length */
Bruno Randolf281c56d2008-02-05 18:44:55 +09003514
3515 /* remove padding we might have added before */
3516 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3517
3518 if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003519 return -EINVAL;
3520
Bruno Randolf281c56d2008-02-05 18:44:55 +09003521 tx_desc->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003522
3523 /* Verify and set buffer length */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003524
3525 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3526 if(type == AR5K_PKT_TYPE_BEACON)
Bruno Randolf281c56d2008-02-05 18:44:55 +09003527 pkt_len = roundup(pkt_len, 4);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003528
Bruno Randolf281c56d2008-02-05 18:44:55 +09003529 if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003530 return -EINVAL;
3531
Bruno Randolf281c56d2008-02-05 18:44:55 +09003532 tx_desc->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003533
3534 /*
3535 * Verify and set header length
3536 * XXX: I only found that on 5210 code, does it work on 5211 ?
3537 */
3538 if (ah->ah_version == AR5K_AR5210) {
3539 if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN)
3540 return -EINVAL;
3541 tx_desc->tx_control_0 |=
3542 AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN);
3543 }
3544
3545 /*Diferences between 5210-5211*/
3546 if (ah->ah_version == AR5K_AR5210) {
3547 switch (type) {
3548 case AR5K_PKT_TYPE_BEACON:
3549 case AR5K_PKT_TYPE_PROBE_RESP:
3550 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
3551 case AR5K_PKT_TYPE_PIFS:
3552 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
3553 default:
3554 frame_type = type /*<< 2 ?*/;
3555 }
3556
3557 tx_desc->tx_control_0 |=
3558 AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE) |
3559 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3560 } else {
3561 tx_desc->tx_control_0 |=
3562 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
3563 AR5K_REG_SM(antenna_mode, AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
3564 tx_desc->tx_control_1 |=
3565 AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE);
3566 }
3567#define _TX_FLAGS(_c, _flag) \
3568 if (flags & AR5K_TXDESC_##_flag) \
3569 tx_desc->tx_control_##_c |= \
3570 AR5K_2W_TX_DESC_CTL##_c##_##_flag
3571
3572 _TX_FLAGS(0, CLRDMASK);
3573 _TX_FLAGS(0, VEOL);
3574 _TX_FLAGS(0, INTREQ);
3575 _TX_FLAGS(0, RTSENA);
3576 _TX_FLAGS(1, NOACK);
3577
3578#undef _TX_FLAGS
3579
3580 /*
3581 * WEP crap
3582 */
3583 if (key_index != AR5K_TXKEYIX_INVALID) {
3584 tx_desc->tx_control_0 |=
3585 AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3586 tx_desc->tx_control_1 |=
3587 AR5K_REG_SM(key_index,
3588 AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3589 }
3590
3591 /*
3592 * RTS/CTS Duration [5210 ?]
3593 */
3594 if ((ah->ah_version == AR5K_AR5210) &&
3595 (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
3596 tx_desc->tx_control_1 |= rtscts_duration &
3597 AR5K_2W_TX_DESC_CTL1_RTS_DURATION;
3598
3599 return 0;
3600}
3601
3602/*
3603 * Initialize the 4-word tx descriptor on 5212
3604 */
3605static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
3606 struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
3607 enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
3608 unsigned int tx_tries0, unsigned int key_index,
3609 unsigned int antenna_mode, unsigned int flags, unsigned int rtscts_rate,
3610 unsigned int rtscts_duration)
3611{
3612 struct ath5k_hw_4w_tx_desc *tx_desc;
3613 struct ath5k_hw_tx_status *tx_status;
Bruno Randolf281c56d2008-02-05 18:44:55 +09003614 unsigned int frame_len;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003615
3616 ATH5K_TRACE(ah->ah_sc);
3617 tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
3618 tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[2];
3619
3620 /*
3621 * Validate input
3622 * - Zero retries don't make sense.
3623 * - A zero rate will put the HW into a mode where it continously sends
3624 * noise on the channel, so it is important to avoid this.
3625 */
3626 if (unlikely(tx_tries0 == 0)) {
3627 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3628 WARN_ON(1);
3629 return -EINVAL;
3630 }
3631 if (unlikely(tx_rate0 == 0)) {
3632 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3633 WARN_ON(1);
3634 return -EINVAL;
3635 }
3636
3637 /* Clear status descriptor */
3638 memset(tx_status, 0, sizeof(struct ath5k_hw_tx_status));
3639
3640 /* Initialize control descriptor */
3641 tx_desc->tx_control_0 = 0;
3642 tx_desc->tx_control_1 = 0;
3643 tx_desc->tx_control_2 = 0;
3644 tx_desc->tx_control_3 = 0;
3645
3646 /* Setup control descriptor */
3647
3648 /* Verify and set frame length */
Bruno Randolf281c56d2008-02-05 18:44:55 +09003649
3650 /* remove padding we might have added before */
3651 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3652
3653 if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003654 return -EINVAL;
3655
Bruno Randolf281c56d2008-02-05 18:44:55 +09003656 tx_desc->tx_control_0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003657
3658 /* Verify and set buffer length */
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003659
3660 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3661 if(type == AR5K_PKT_TYPE_BEACON)
Bruno Randolf281c56d2008-02-05 18:44:55 +09003662 pkt_len = roundup(pkt_len, 4);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003663
Bruno Randolf281c56d2008-02-05 18:44:55 +09003664 if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003665 return -EINVAL;
3666
Bruno Randolf281c56d2008-02-05 18:44:55 +09003667 tx_desc->tx_control_1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003668
3669 tx_desc->tx_control_0 |=
3670 AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
3671 AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
3672 tx_desc->tx_control_1 |= AR5K_REG_SM(type,
3673 AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
3674 tx_desc->tx_control_2 = AR5K_REG_SM(tx_tries0 + AR5K_TUNE_HWTXTRIES,
3675 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
3676 tx_desc->tx_control_3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
3677
3678#define _TX_FLAGS(_c, _flag) \
3679 if (flags & AR5K_TXDESC_##_flag) \
3680 tx_desc->tx_control_##_c |= \
3681 AR5K_4W_TX_DESC_CTL##_c##_##_flag
3682
3683 _TX_FLAGS(0, CLRDMASK);
3684 _TX_FLAGS(0, VEOL);
3685 _TX_FLAGS(0, INTREQ);
3686 _TX_FLAGS(0, RTSENA);
3687 _TX_FLAGS(0, CTSENA);
3688 _TX_FLAGS(1, NOACK);
3689
3690#undef _TX_FLAGS
3691
3692 /*
3693 * WEP crap
3694 */
3695 if (key_index != AR5K_TXKEYIX_INVALID) {
3696 tx_desc->tx_control_0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3697 tx_desc->tx_control_1 |= AR5K_REG_SM(key_index,
3698 AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3699 }
3700
3701 /*
3702 * RTS/CTS
3703 */
3704 if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
3705 if ((flags & AR5K_TXDESC_RTSENA) &&
3706 (flags & AR5K_TXDESC_CTSENA))
3707 return -EINVAL;
3708 tx_desc->tx_control_2 |= rtscts_duration &
3709 AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
3710 tx_desc->tx_control_3 |= AR5K_REG_SM(rtscts_rate,
3711 AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
3712 }
3713
3714 return 0;
3715}
3716
3717/*
3718 * Initialize a 4-word multirate tx descriptor on 5212
3719 */
Jiri Slabyb9887632008-02-15 21:58:52 +01003720static int
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003721ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3722 unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2, u_int tx_tries2,
3723 unsigned int tx_rate3, u_int tx_tries3)
3724{
3725 struct ath5k_hw_4w_tx_desc *tx_desc;
3726
3727 /*
3728 * Rates can be 0 as long as the retry count is 0 too.
3729 * A zero rate and nonzero retry count will put the HW into a mode where
3730 * it continously sends noise on the channel, so it is important to
3731 * avoid this.
3732 */
3733 if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
3734 (tx_rate2 == 0 && tx_tries2 != 0) ||
3735 (tx_rate3 == 0 && tx_tries3 != 0))) {
3736 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3737 WARN_ON(1);
3738 return -EINVAL;
3739 }
3740
3741 if (ah->ah_version == AR5K_AR5212) {
3742 tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
3743
3744#define _XTX_TRIES(_n) \
3745 if (tx_tries##_n) { \
3746 tx_desc->tx_control_2 |= \
3747 AR5K_REG_SM(tx_tries##_n, \
3748 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
3749 tx_desc->tx_control_3 |= \
3750 AR5K_REG_SM(tx_rate##_n, \
3751 AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
3752 }
3753
3754 _XTX_TRIES(1);
3755 _XTX_TRIES(2);
3756 _XTX_TRIES(3);
3757
3758#undef _XTX_TRIES
3759
Jiri Slabyb9887632008-02-15 21:58:52 +01003760 return 1;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003761 }
3762
Jiri Slabyb9887632008-02-15 21:58:52 +01003763 return 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003764}
3765
3766/*
3767 * Proccess the tx status descriptor on 5210/5211
3768 */
3769static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
3770 struct ath5k_desc *desc)
3771{
3772 struct ath5k_hw_tx_status *tx_status;
3773 struct ath5k_hw_2w_tx_desc *tx_desc;
3774
3775 tx_desc = (struct ath5k_hw_2w_tx_desc *)&desc->ds_ctl0;
3776 tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[0];
3777
3778 /* No frame has been send or error */
3779 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
3780 return -EINPROGRESS;
3781
3782 /*
3783 * Get descriptor status
3784 */
3785 desc->ds_us.tx.ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
3786 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
3787 desc->ds_us.tx.ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
3788 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
3789 desc->ds_us.tx.ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
3790 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
3791 /*TODO: desc->ds_us.tx.ts_virtcol + test*/
3792 desc->ds_us.tx.ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
3793 AR5K_DESC_TX_STATUS1_SEQ_NUM);
3794 desc->ds_us.tx.ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
3795 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
3796 desc->ds_us.tx.ts_antenna = 1;
3797 desc->ds_us.tx.ts_status = 0;
3798 desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_0,
3799 AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3800
3801 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
3802 if (tx_status->tx_status_0 &
3803 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
3804 desc->ds_us.tx.ts_status |= AR5K_TXERR_XRETRY;
3805
3806 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
3807 desc->ds_us.tx.ts_status |= AR5K_TXERR_FIFO;
3808
3809 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
3810 desc->ds_us.tx.ts_status |= AR5K_TXERR_FILT;
3811 }
3812
3813 return 0;
3814}
3815
3816/*
3817 * Proccess a tx descriptor on 5212
3818 */
3819static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
3820 struct ath5k_desc *desc)
3821{
3822 struct ath5k_hw_tx_status *tx_status;
3823 struct ath5k_hw_4w_tx_desc *tx_desc;
3824
3825 ATH5K_TRACE(ah->ah_sc);
3826 tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
3827 tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[2];
3828
3829 /* No frame has been send or error */
3830 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
3831 return -EINPROGRESS;
3832
3833 /*
3834 * Get descriptor status
3835 */
3836 desc->ds_us.tx.ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
3837 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
3838 desc->ds_us.tx.ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
3839 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
3840 desc->ds_us.tx.ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
3841 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
3842 desc->ds_us.tx.ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
3843 AR5K_DESC_TX_STATUS1_SEQ_NUM);
3844 desc->ds_us.tx.ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
3845 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
3846 desc->ds_us.tx.ts_antenna = (tx_status->tx_status_1 &
3847 AR5K_DESC_TX_STATUS1_XMIT_ANTENNA) ? 2 : 1;
3848 desc->ds_us.tx.ts_status = 0;
3849
3850 switch (AR5K_REG_MS(tx_status->tx_status_1,
3851 AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX)) {
3852 case 0:
3853 desc->ds_us.tx.ts_rate = tx_desc->tx_control_3 &
3854 AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
3855 break;
3856 case 1:
3857 desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
3858 AR5K_4W_TX_DESC_CTL3_XMIT_RATE1);
3859 desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
3860 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1);
3861 break;
3862 case 2:
3863 desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
3864 AR5K_4W_TX_DESC_CTL3_XMIT_RATE2);
3865 desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
3866 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2);
3867 break;
3868 case 3:
3869 desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
3870 AR5K_4W_TX_DESC_CTL3_XMIT_RATE3);
3871 desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
3872 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES3);
3873 break;
3874 }
3875
3876 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
3877 if (tx_status->tx_status_0 &
3878 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
3879 desc->ds_us.tx.ts_status |= AR5K_TXERR_XRETRY;
3880
3881 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
3882 desc->ds_us.tx.ts_status |= AR5K_TXERR_FIFO;
3883
3884 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
3885 desc->ds_us.tx.ts_status |= AR5K_TXERR_FILT;
3886 }
3887
3888 return 0;
3889}
3890
3891/*
3892 * RX Descriptor
3893 */
3894
3895/*
3896 * Initialize an rx descriptor
3897 */
3898int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3899 u32 size, unsigned int flags)
3900{
3901 struct ath5k_rx_desc *rx_desc;
3902
3903 ATH5K_TRACE(ah->ah_sc);
3904 rx_desc = (struct ath5k_rx_desc *)&desc->ds_ctl0;
3905
3906 /*
3907 *Clear ds_hw
3908 * If we don't clean the status descriptor,
3909 * while scanning we get too many results,
3910 * most of them virtual, after some secs
3911 * of scanning system hangs. M.F.
3912 */
3913 memset(desc->ds_hw, 0, sizeof(desc->ds_hw));
3914
3915 /*Initialize rx descriptor*/
3916 rx_desc->rx_control_0 = 0;
3917 rx_desc->rx_control_1 = 0;
3918
3919 /* Setup descriptor */
3920 rx_desc->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
3921 if (unlikely(rx_desc->rx_control_1 != size))
3922 return -EINVAL;
3923
3924 if (flags & AR5K_RXDESC_INTREQ)
3925 rx_desc->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
3926
3927 return 0;
3928}
3929
3930/*
3931 * Proccess the rx status descriptor on 5210/5211
3932 */
3933static int ath5k_hw_proc_old_rx_status(struct ath5k_hw *ah,
3934 struct ath5k_desc *desc)
3935{
3936 struct ath5k_hw_old_rx_status *rx_status;
3937
3938 rx_status = (struct ath5k_hw_old_rx_status *)&desc->ds_hw[0];
3939
3940 /* No frame received / not ready */
3941 if (unlikely((rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_DONE)
3942 == 0))
3943 return -EINPROGRESS;
3944
3945 /*
3946 * Frame receive status
3947 */
3948 desc->ds_us.rx.rs_datalen = rx_status->rx_status_0 &
3949 AR5K_OLD_RX_DESC_STATUS0_DATA_LEN;
3950 desc->ds_us.rx.rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
3951 AR5K_OLD_RX_DESC_STATUS0_RECEIVE_SIGNAL);
3952 desc->ds_us.rx.rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
3953 AR5K_OLD_RX_DESC_STATUS0_RECEIVE_RATE);
3954 desc->ds_us.rx.rs_antenna = rx_status->rx_status_0 &
3955 AR5K_OLD_RX_DESC_STATUS0_RECEIVE_ANTENNA;
3956 desc->ds_us.rx.rs_more = rx_status->rx_status_0 &
3957 AR5K_OLD_RX_DESC_STATUS0_MORE;
3958 desc->ds_us.rx.rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
3959 AR5K_OLD_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
3960 desc->ds_us.rx.rs_status = 0;
3961
3962 /*
3963 * Key table status
3964 */
3965 if (rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_KEY_INDEX_VALID)
3966 desc->ds_us.rx.rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
3967 AR5K_OLD_RX_DESC_STATUS1_KEY_INDEX);
3968 else
3969 desc->ds_us.rx.rs_keyix = AR5K_RXKEYIX_INVALID;
3970
3971 /*
3972 * Receive/descriptor errors
3973 */
3974 if ((rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_FRAME_RECEIVE_OK)
3975 == 0) {
3976 if (rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_CRC_ERROR)
3977 desc->ds_us.rx.rs_status |= AR5K_RXERR_CRC;
3978
3979 if (rx_status->rx_status_1 &
3980 AR5K_OLD_RX_DESC_STATUS1_FIFO_OVERRUN)
3981 desc->ds_us.rx.rs_status |= AR5K_RXERR_FIFO;
3982
3983 if (rx_status->rx_status_1 &
3984 AR5K_OLD_RX_DESC_STATUS1_PHY_ERROR) {
3985 desc->ds_us.rx.rs_status |= AR5K_RXERR_PHY;
3986 desc->ds_us.rx.rs_phyerr =
3987 AR5K_REG_MS(rx_status->rx_status_1,
3988 AR5K_OLD_RX_DESC_STATUS1_PHY_ERROR);
3989 }
3990
3991 if (rx_status->rx_status_1 &
3992 AR5K_OLD_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
3993 desc->ds_us.rx.rs_status |= AR5K_RXERR_DECRYPT;
3994 }
3995
3996 return 0;
3997}
3998
3999/*
4000 * Proccess the rx status descriptor on 5212
4001 */
4002static int ath5k_hw_proc_new_rx_status(struct ath5k_hw *ah,
4003 struct ath5k_desc *desc)
4004{
4005 struct ath5k_hw_new_rx_status *rx_status;
4006 struct ath5k_hw_rx_error *rx_err;
4007
4008 ATH5K_TRACE(ah->ah_sc);
4009 rx_status = (struct ath5k_hw_new_rx_status *)&desc->ds_hw[0];
4010
4011 /* Overlay on error */
4012 rx_err = (struct ath5k_hw_rx_error *)&desc->ds_hw[0];
4013
4014 /* No frame received / not ready */
4015 if (unlikely((rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_DONE)
4016 == 0))
4017 return -EINPROGRESS;
4018
4019 /*
4020 * Frame receive status
4021 */
4022 desc->ds_us.rx.rs_datalen = rx_status->rx_status_0 &
4023 AR5K_NEW_RX_DESC_STATUS0_DATA_LEN;
4024 desc->ds_us.rx.rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
4025 AR5K_NEW_RX_DESC_STATUS0_RECEIVE_SIGNAL);
4026 desc->ds_us.rx.rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
4027 AR5K_NEW_RX_DESC_STATUS0_RECEIVE_RATE);
4028 desc->ds_us.rx.rs_antenna = rx_status->rx_status_0 &
4029 AR5K_NEW_RX_DESC_STATUS0_RECEIVE_ANTENNA;
4030 desc->ds_us.rx.rs_more = rx_status->rx_status_0 &
4031 AR5K_NEW_RX_DESC_STATUS0_MORE;
4032 desc->ds_us.rx.rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
4033 AR5K_NEW_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
4034 desc->ds_us.rx.rs_status = 0;
4035
4036 /*
4037 * Key table status
4038 */
4039 if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_KEY_INDEX_VALID)
4040 desc->ds_us.rx.rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
4041 AR5K_NEW_RX_DESC_STATUS1_KEY_INDEX);
4042 else
4043 desc->ds_us.rx.rs_keyix = AR5K_RXKEYIX_INVALID;
4044
4045 /*
4046 * Receive/descriptor errors
4047 */
4048 if ((rx_status->rx_status_1 &
4049 AR5K_NEW_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
4050 if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_CRC_ERROR)
4051 desc->ds_us.rx.rs_status |= AR5K_RXERR_CRC;
4052
4053 if (rx_status->rx_status_1 &
4054 AR5K_NEW_RX_DESC_STATUS1_PHY_ERROR) {
4055 desc->ds_us.rx.rs_status |= AR5K_RXERR_PHY;
4056 desc->ds_us.rx.rs_phyerr =
4057 AR5K_REG_MS(rx_err->rx_error_1,
4058 AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE);
4059 }
4060
4061 if (rx_status->rx_status_1 &
4062 AR5K_NEW_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
4063 desc->ds_us.rx.rs_status |= AR5K_RXERR_DECRYPT;
4064
4065 if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_MIC_ERROR)
4066 desc->ds_us.rx.rs_status |= AR5K_RXERR_MIC;
4067 }
4068
4069 return 0;
4070}
4071
4072
4073/****************\
4074 GPIO Functions
4075\****************/
4076
4077/*
4078 * Set led state
4079 */
4080void ath5k_hw_set_ledstate(struct ath5k_hw *ah, unsigned int state)
4081{
4082 u32 led;
4083 /*5210 has different led mode handling*/
4084 u32 led_5210;
4085
4086 ATH5K_TRACE(ah->ah_sc);
4087
4088 /*Reset led status*/
4089 if (ah->ah_version != AR5K_AR5210)
4090 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
4091 AR5K_PCICFG_LEDMODE | AR5K_PCICFG_LED);
4092 else
4093 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_LED);
4094
4095 /*
4096 * Some blinking values, define at your wish
4097 */
4098 switch (state) {
4099 case AR5K_LED_SCAN:
4100 case AR5K_LED_AUTH:
4101 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_PEND;
4102 led_5210 = AR5K_PCICFG_LED_PEND | AR5K_PCICFG_LED_BCTL;
4103 break;
4104
4105 case AR5K_LED_INIT:
4106 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_NONE;
4107 led_5210 = AR5K_PCICFG_LED_PEND;
4108 break;
4109
4110 case AR5K_LED_ASSOC:
4111 case AR5K_LED_RUN:
4112 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_ASSOC;
4113 led_5210 = AR5K_PCICFG_LED_ASSOC;
4114 break;
4115
4116 default:
4117 led = AR5K_PCICFG_LEDMODE_PROM | AR5K_PCICFG_LED_NONE;
4118 led_5210 = AR5K_PCICFG_LED_PEND;
4119 break;
4120 }
4121
4122 /*Write new status to the register*/
4123 if (ah->ah_version != AR5K_AR5210)
4124 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led);
4125 else
4126 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led_5210);
4127}
4128
4129/*
4130 * Set GPIO outputs
4131 */
4132int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
4133{
4134 ATH5K_TRACE(ah->ah_sc);
4135 if (gpio > AR5K_NUM_GPIO)
4136 return -EINVAL;
4137
4138 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4139 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR);
4140
4141 return 0;
4142}
4143
4144/*
4145 * Set GPIO inputs
4146 */
4147int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
4148{
4149 ATH5K_TRACE(ah->ah_sc);
4150 if (gpio > AR5K_NUM_GPIO)
4151 return -EINVAL;
4152
4153 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4154 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR);
4155
4156 return 0;
4157}
4158
4159/*
4160 * Get GPIO state
4161 */
4162u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
4163{
4164 ATH5K_TRACE(ah->ah_sc);
4165 if (gpio > AR5K_NUM_GPIO)
4166 return 0xffffffff;
4167
4168 /* GPIO input magic */
4169 return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) &
4170 0x1;
4171}
4172
4173/*
4174 * Set GPIO state
4175 */
4176int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
4177{
4178 u32 data;
4179 ATH5K_TRACE(ah->ah_sc);
4180
4181 if (gpio > AR5K_NUM_GPIO)
4182 return -EINVAL;
4183
4184 /* GPIO output magic */
4185 data = ath5k_hw_reg_read(ah, AR5K_GPIODO);
4186
4187 data &= ~(1 << gpio);
4188 data |= (val & 1) << gpio;
4189
4190 ath5k_hw_reg_write(ah, data, AR5K_GPIODO);
4191
4192 return 0;
4193}
4194
4195/*
4196 * Initialize the GPIO interrupt (RFKill switch)
4197 */
4198void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
4199 u32 interrupt_level)
4200{
4201 u32 data;
4202
4203 ATH5K_TRACE(ah->ah_sc);
4204 if (gpio > AR5K_NUM_GPIO)
4205 return;
4206
4207 /*
4208 * Set the GPIO interrupt
4209 */
4210 data = (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &
4211 ~(AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_SELH |
4212 AR5K_GPIOCR_INT_ENA | AR5K_GPIOCR_OUT(gpio))) |
4213 (AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_ENA);
4214
4215 ath5k_hw_reg_write(ah, interrupt_level ? data :
4216 (data | AR5K_GPIOCR_INT_SELH), AR5K_GPIOCR);
4217
4218 ah->ah_imr |= AR5K_IMR_GPIO;
4219
4220 /* Enable GPIO interrupts */
4221 AR5K_REG_ENABLE_BITS(ah, AR5K_PIMR, AR5K_IMR_GPIO);
4222}
4223
4224
Jiri Slabyfa1c1142007-08-12 17:33:16 +02004225
4226
4227/****************\
4228 Misc functions
4229\****************/
4230
4231int ath5k_hw_get_capability(struct ath5k_hw *ah,
4232 enum ath5k_capability_type cap_type,
4233 u32 capability, u32 *result)
4234{
4235 ATH5K_TRACE(ah->ah_sc);
4236
4237 switch (cap_type) {
4238 case AR5K_CAP_NUM_TXQUEUES:
4239 if (result) {
4240 if (ah->ah_version == AR5K_AR5210)
4241 *result = AR5K_NUM_TX_QUEUES_NOQCU;
4242 else
4243 *result = AR5K_NUM_TX_QUEUES;
4244 goto yes;
4245 }
4246 case AR5K_CAP_VEOL:
4247 goto yes;
4248 case AR5K_CAP_COMPRESSION:
4249 if (ah->ah_version == AR5K_AR5212)
4250 goto yes;
4251 else
4252 goto no;
4253 case AR5K_CAP_BURST:
4254 goto yes;
4255 case AR5K_CAP_TPC:
4256 goto yes;
4257 case AR5K_CAP_BSSIDMASK:
4258 if (ah->ah_version == AR5K_AR5212)
4259 goto yes;
4260 else
4261 goto no;
4262 case AR5K_CAP_XR:
4263 if (ah->ah_version == AR5K_AR5212)
4264 goto yes;
4265 else
4266 goto no;
4267 default:
4268 goto no;
4269 }
4270
4271no:
4272 return -EINVAL;
4273yes:
4274 return 0;
4275}
4276
4277static int ath5k_hw_enable_pspoll(struct ath5k_hw *ah, u8 *bssid,
4278 u16 assoc_id)
4279{
4280 ATH5K_TRACE(ah->ah_sc);
4281
4282 if (ah->ah_version == AR5K_AR5210) {
4283 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
4284 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
4285 return 0;
4286 }
4287
4288 return -EIO;
4289}
4290
4291static int ath5k_hw_disable_pspoll(struct ath5k_hw *ah)
4292{
4293 ATH5K_TRACE(ah->ah_sc);
4294
4295 if (ah->ah_version == AR5K_AR5210) {
4296 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
4297 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
4298 return 0;
4299 }
4300
4301 return -EIO;
4302}