libertas: remove CMD_802_11_PWR_CFG
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / wireless / ath5k / hw.c
blobff579a22362129287c57ee145a9dc5c3c4313b7e
1 /*
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>
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.
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.
24 * HW related functions for Atheros Wireless LAN devices.
27 #include <linux/pci.h>
28 #include <linux/delay.h>
30 #include "reg.h"
31 #include "base.h"
32 #include "debug.h"
34 /*Rate tables*/
35 static const struct ath5k_rate_table ath5k_rt_11a = AR5K_RATES_11A;
36 static const struct ath5k_rate_table ath5k_rt_11b = AR5K_RATES_11B;
37 static const struct ath5k_rate_table ath5k_rt_11g = AR5K_RATES_11G;
38 static const struct ath5k_rate_table ath5k_rt_turbo = AR5K_RATES_TURBO;
39 static const struct ath5k_rate_table ath5k_rt_xr = AR5K_RATES_XR;
41 /*Prototypes*/
42 static int ath5k_hw_nic_reset(struct ath5k_hw *, u32);
43 static int ath5k_hw_nic_wakeup(struct ath5k_hw *, int, bool);
44 static 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);
48 static int ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
49 unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
50 unsigned int);
51 static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *, struct ath5k_desc *,
52 struct ath5k_tx_status *);
53 static int ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
54 unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
55 unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
56 unsigned int, unsigned int);
57 static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *, struct ath5k_desc *,
58 struct ath5k_tx_status *);
59 static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *, struct ath5k_desc *,
60 struct ath5k_rx_status *);
61 static int ath5k_hw_proc_5210_rx_status(struct ath5k_hw *, struct ath5k_desc *,
62 struct ath5k_rx_status *);
63 static int ath5k_hw_get_capabilities(struct ath5k_hw *);
65 static int ath5k_eeprom_init(struct ath5k_hw *);
66 static int ath5k_eeprom_read_mac(struct ath5k_hw *, u8 *);
68 static int ath5k_hw_enable_pspoll(struct ath5k_hw *, u8 *, u16);
69 static int ath5k_hw_disable_pspoll(struct ath5k_hw *);
72 * Enable to overwrite the country code (use "00" for debug)
74 #if 0
75 #define COUNTRYCODE "00"
76 #endif
78 /*******************\
79 General Functions
80 \*******************/
83 * Functions used internaly
86 static inline unsigned int ath5k_hw_htoclock(unsigned int usec, bool turbo)
88 return turbo ? (usec * 80) : (usec * 40);
91 static inline unsigned int ath5k_hw_clocktoh(unsigned int clock, bool turbo)
93 return turbo ? (clock / 80) : (clock / 40);
97 * Check if a register write has been completed
99 int ath5k_hw_register_timeout(struct ath5k_hw *ah, u32 reg, u32 flag, u32 val,
100 bool is_set)
102 int i;
103 u32 data;
105 for (i = AR5K_TUNE_REGISTER_TIMEOUT; i > 0; i--) {
106 data = ath5k_hw_reg_read(ah, reg);
107 if (is_set && (data & flag))
108 break;
109 else if ((data & flag) == val)
110 break;
111 udelay(15);
114 return (i <= 0) ? -EAGAIN : 0;
118 /***************************************\
119 Attach/Detach Functions
120 \***************************************/
123 * Check if the device is supported and initialize the needed structs
125 struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
127 struct ath5k_hw *ah;
128 u8 mac[ETH_ALEN];
129 int ret;
130 u32 srev;
132 /*If we passed the test malloc a ath5k_hw struct*/
133 ah = kzalloc(sizeof(struct ath5k_hw), GFP_KERNEL);
134 if (ah == NULL) {
135 ret = -ENOMEM;
136 ATH5K_ERR(sc, "out of memory\n");
137 goto err;
140 ah->ah_sc = sc;
141 ah->ah_iobase = sc->iobase;
144 * HW information
147 ah->ah_op_mode = IEEE80211_IF_TYPE_STA;
148 ah->ah_radar.r_enabled = AR5K_TUNE_RADAR_ALERT;
149 ah->ah_turbo = false;
150 ah->ah_txpower.txp_tpc = AR5K_TUNE_TPC_TXPOWER;
151 ah->ah_imr = 0;
152 ah->ah_atim_window = 0;
153 ah->ah_aifs = AR5K_TUNE_AIFS;
154 ah->ah_cw_min = AR5K_TUNE_CWMIN;
155 ah->ah_limit_tx_retries = AR5K_INIT_TX_RETRY;
156 ah->ah_software_retry = false;
157 ah->ah_ant_diversity = AR5K_TUNE_ANT_DIVERSITY;
160 * Set the mac revision based on the pci id
162 ah->ah_version = mac_version;
164 /*Fill the ath5k_hw struct with the needed functions*/
165 if (ah->ah_version == AR5K_AR5212)
166 ah->ah_magic = AR5K_EEPROM_MAGIC_5212;
167 else if (ah->ah_version == AR5K_AR5211)
168 ah->ah_magic = AR5K_EEPROM_MAGIC_5211;
170 if (ah->ah_version == AR5K_AR5212) {
171 ah->ah_setup_tx_desc = ath5k_hw_setup_4word_tx_desc;
172 ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
173 ah->ah_proc_tx_desc = ath5k_hw_proc_4word_tx_status;
174 } else {
175 ah->ah_setup_tx_desc = ath5k_hw_setup_2word_tx_desc;
176 ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
177 ah->ah_proc_tx_desc = ath5k_hw_proc_2word_tx_status;
180 if (ah->ah_version == AR5K_AR5212)
181 ah->ah_proc_rx_desc = ath5k_hw_proc_5212_rx_status;
182 else if (ah->ah_version <= AR5K_AR5211)
183 ah->ah_proc_rx_desc = ath5k_hw_proc_5210_rx_status;
185 /* Bring device out of sleep and reset it's units */
186 ret = ath5k_hw_nic_wakeup(ah, AR5K_INIT_MODE, true);
187 if (ret)
188 goto err_free;
190 /* Get MAC, PHY and RADIO revisions */
191 srev = ath5k_hw_reg_read(ah, AR5K_SREV);
192 ah->ah_mac_srev = srev;
193 ah->ah_mac_version = AR5K_REG_MS(srev, AR5K_SREV_VER);
194 ah->ah_mac_revision = AR5K_REG_MS(srev, AR5K_SREV_REV);
195 ah->ah_phy_revision = ath5k_hw_reg_read(ah, AR5K_PHY_CHIP_ID) &
196 0xffffffff;
197 ah->ah_radio_5ghz_revision = ath5k_hw_radio_revision(ah,
198 CHANNEL_5GHZ);
200 if (ah->ah_version == AR5K_AR5210)
201 ah->ah_radio_2ghz_revision = 0;
202 else
203 ah->ah_radio_2ghz_revision = ath5k_hw_radio_revision(ah,
204 CHANNEL_2GHZ);
206 /* Return on unsuported chips (unsupported eeprom etc) */
207 if(srev >= AR5K_SREV_VER_AR5416){
208 ATH5K_ERR(sc, "Device not yet supported.\n");
209 ret = -ENODEV;
210 goto err_free;
213 /* Identify single chip solutions */
214 if((srev <= AR5K_SREV_VER_AR5414) &&
215 (srev >= AR5K_SREV_VER_AR2413)) {
216 ah->ah_single_chip = true;
217 } else {
218 ah->ah_single_chip = false;
221 /* Single chip radio */
222 if (ah->ah_radio_2ghz_revision == ah->ah_radio_5ghz_revision)
223 ah->ah_radio_2ghz_revision = 0;
225 /* Identify the radio chip*/
226 if (ah->ah_version == AR5K_AR5210) {
227 ah->ah_radio = AR5K_RF5110;
228 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112) {
229 ah->ah_radio = AR5K_RF5111;
230 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5111;
231 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC0) {
233 ah->ah_radio = AR5K_RF5112;
235 if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112A) {
236 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112;
237 } else {
238 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
241 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC1) {
242 ah->ah_radio = AR5K_RF2413;
243 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
244 } else {
246 ah->ah_radio = AR5K_RF5413;
248 if (ah->ah_mac_srev <= AR5K_SREV_VER_AR5424 &&
249 ah->ah_mac_srev >= AR5K_SREV_VER_AR2424)
250 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5424;
251 else if (ah->ah_mac_srev >= AR5K_SREV_VER_AR2425)
252 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112;
253 else
254 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
259 ah->ah_phy = AR5K_PHY(0);
262 * Get card capabilities, values, ...
265 ret = ath5k_eeprom_init(ah);
266 if (ret) {
267 ATH5K_ERR(sc, "unable to init EEPROM\n");
268 goto err_free;
271 /* Get misc capabilities */
272 ret = ath5k_hw_get_capabilities(ah);
273 if (ret) {
274 ATH5K_ERR(sc, "unable to get device capabilities: 0x%04x\n",
275 sc->pdev->device);
276 goto err_free;
279 /* Get MAC address */
280 ret = ath5k_eeprom_read_mac(ah, mac);
281 if (ret) {
282 ATH5K_ERR(sc, "unable to read address from EEPROM: 0x%04x\n",
283 sc->pdev->device);
284 goto err_free;
287 ath5k_hw_set_lladdr(ah, mac);
288 /* Set BSSID to bcast address: ff:ff:ff:ff:ff:ff for now */
289 memset(ah->ah_bssid, 0xff, ETH_ALEN);
290 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
291 ath5k_hw_set_opmode(ah);
293 ath5k_hw_set_rfgain_opt(ah);
295 return ah;
296 err_free:
297 kfree(ah);
298 err:
299 return ERR_PTR(ret);
303 * Bring up MAC + PHY Chips
305 static int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
307 struct pci_dev *pdev = ah->ah_sc->pdev;
308 u32 turbo, mode, clock, bus_flags;
309 int ret;
311 turbo = 0;
312 mode = 0;
313 clock = 0;
315 ATH5K_TRACE(ah->ah_sc);
317 /* Wakeup the device */
318 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
319 if (ret) {
320 ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
321 return ret;
324 if (ah->ah_version != AR5K_AR5210) {
326 * Get channel mode flags
329 if (ah->ah_radio >= AR5K_RF5112) {
330 mode = AR5K_PHY_MODE_RAD_RF5112;
331 clock = AR5K_PHY_PLL_RF5112;
332 } else {
333 mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
334 clock = AR5K_PHY_PLL_RF5111; /*Zero*/
337 if (flags & CHANNEL_2GHZ) {
338 mode |= AR5K_PHY_MODE_FREQ_2GHZ;
339 clock |= AR5K_PHY_PLL_44MHZ;
341 if (flags & CHANNEL_CCK) {
342 mode |= AR5K_PHY_MODE_MOD_CCK;
343 } else if (flags & CHANNEL_OFDM) {
344 /* XXX Dynamic OFDM/CCK is not supported by the
345 * AR5211 so we set MOD_OFDM for plain g (no
346 * CCK headers) operation. We need to test
347 * this, 5211 might support ofdm-only g after
348 * all, there are also initial register values
349 * in the code for g mode (see initvals.c). */
350 if (ah->ah_version == AR5K_AR5211)
351 mode |= AR5K_PHY_MODE_MOD_OFDM;
352 else
353 mode |= AR5K_PHY_MODE_MOD_DYN;
354 } else {
355 ATH5K_ERR(ah->ah_sc,
356 "invalid radio modulation mode\n");
357 return -EINVAL;
359 } else if (flags & CHANNEL_5GHZ) {
360 mode |= AR5K_PHY_MODE_FREQ_5GHZ;
361 clock |= AR5K_PHY_PLL_40MHZ;
363 if (flags & CHANNEL_OFDM)
364 mode |= AR5K_PHY_MODE_MOD_OFDM;
365 else {
366 ATH5K_ERR(ah->ah_sc,
367 "invalid radio modulation mode\n");
368 return -EINVAL;
370 } else {
371 ATH5K_ERR(ah->ah_sc, "invalid radio frequency mode\n");
372 return -EINVAL;
375 if (flags & CHANNEL_TURBO)
376 turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
377 } else { /* Reset the device */
379 /* ...enable Atheros turbo mode if requested */
380 if (flags & CHANNEL_TURBO)
381 ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
382 AR5K_PHY_TURBO);
385 /* reseting PCI on PCI-E cards results card to hang
386 * and always return 0xffff... so we ingore that flag
387 * for PCI-E cards */
388 bus_flags = (pdev->is_pcie) ? 0 : AR5K_RESET_CTL_PCI;
390 /* Reset chipset */
391 ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
392 AR5K_RESET_CTL_BASEBAND | bus_flags);
393 if (ret) {
394 ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip + PCI\n");
395 return -EIO;
398 if (ah->ah_version == AR5K_AR5210)
399 udelay(2300);
401 /* ...wakeup again!*/
402 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
403 if (ret) {
404 ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
405 return ret;
408 /* ...final warm reset */
409 if (ath5k_hw_nic_reset(ah, 0)) {
410 ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
411 return -EIO;
414 if (ah->ah_version != AR5K_AR5210) {
415 /* ...set the PHY operating mode */
416 ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
417 udelay(300);
419 ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
420 ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
423 return 0;
427 * Get the rate table for a specific operation mode
429 const struct ath5k_rate_table *ath5k_hw_get_rate_table(struct ath5k_hw *ah,
430 unsigned int mode)
432 ATH5K_TRACE(ah->ah_sc);
434 if (!test_bit(mode, ah->ah_capabilities.cap_mode))
435 return NULL;
437 /* Get rate tables */
438 switch (mode) {
439 case AR5K_MODE_11A:
440 return &ath5k_rt_11a;
441 case AR5K_MODE_11A_TURBO:
442 return &ath5k_rt_turbo;
443 case AR5K_MODE_11B:
444 return &ath5k_rt_11b;
445 case AR5K_MODE_11G:
446 return &ath5k_rt_11g;
447 case AR5K_MODE_11G_TURBO:
448 return &ath5k_rt_xr;
451 return NULL;
455 * Free the ath5k_hw struct
457 void ath5k_hw_detach(struct ath5k_hw *ah)
459 ATH5K_TRACE(ah->ah_sc);
461 __set_bit(ATH_STAT_INVALID, ah->ah_sc->status);
463 if (ah->ah_rf_banks != NULL)
464 kfree(ah->ah_rf_banks);
466 /* assume interrupts are down */
467 kfree(ah);
470 /****************************\
471 Reset function and helpers
472 \****************************/
475 * ath5k_hw_write_ofdm_timings - set OFDM timings on AR5212
477 * @ah: the &struct ath5k_hw
478 * @channel: the currently set channel upon reset
480 * Write the OFDM timings for the AR5212 upon reset. This is a helper for
481 * ath5k_hw_reset(). This seems to tune the PLL a specified frequency
482 * depending on the bandwidth of the channel.
485 static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
486 struct ieee80211_channel *channel)
488 /* Get exponent and mantissa and set it */
489 u32 coef_scaled, coef_exp, coef_man,
490 ds_coef_exp, ds_coef_man, clock;
492 if (!(ah->ah_version == AR5K_AR5212) ||
493 !(channel->hw_value & CHANNEL_OFDM))
494 BUG();
496 /* Seems there are two PLLs, one for baseband sampling and one
497 * for tuning. Tuning basebands are 40 MHz or 80MHz when in
498 * turbo. */
499 clock = channel->hw_value & CHANNEL_TURBO ? 80 : 40;
500 coef_scaled = ((5 * (clock << 24)) / 2) /
501 channel->center_freq;
503 for (coef_exp = 31; coef_exp > 0; coef_exp--)
504 if ((coef_scaled >> coef_exp) & 0x1)
505 break;
507 if (!coef_exp)
508 return -EINVAL;
510 coef_exp = 14 - (coef_exp - 24);
511 coef_man = coef_scaled +
512 (1 << (24 - coef_exp - 1));
513 ds_coef_man = coef_man >> (24 - coef_exp);
514 ds_coef_exp = coef_exp - 16;
516 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
517 AR5K_PHY_TIMING_3_DSC_MAN, ds_coef_man);
518 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
519 AR5K_PHY_TIMING_3_DSC_EXP, ds_coef_exp);
521 return 0;
525 * ath5k_hw_write_rate_duration - set rate duration during hw resets
527 * @ah: the &struct ath5k_hw
528 * @mode: one of enum ath5k_driver_mode
530 * Write the rate duration table for the current mode upon hw reset. This
531 * is a helper for ath5k_hw_reset(). It seems all this is doing is setting
532 * an ACK timeout for the hardware for the current mode for each rate. The
533 * rates which are capable of short preamble (802.11b rates 2Mbps, 5.5Mbps,
534 * and 11Mbps) have another register for the short preamble ACK timeout
535 * calculation.
538 static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
539 unsigned int mode)
541 struct ath5k_softc *sc = ah->ah_sc;
542 const struct ath5k_rate_table *rt;
543 struct ieee80211_rate srate = {};
544 unsigned int i;
546 /* Get rate table for the current operating mode */
547 rt = ath5k_hw_get_rate_table(ah, mode);
549 /* Write rate duration table */
550 for (i = 0; i < rt->rate_count; i++) {
551 const struct ath5k_rate *rate, *control_rate;
553 u32 reg;
554 u16 tx_time;
556 rate = &rt->rates[i];
557 control_rate = &rt->rates[rate->control_rate];
559 /* Set ACK timeout */
560 reg = AR5K_RATE_DUR(rate->rate_code);
562 srate.bitrate = control_rate->rate_kbps/100;
564 /* An ACK frame consists of 10 bytes. If you add the FCS,
565 * which ieee80211_generic_frame_duration() adds,
566 * its 14 bytes. Note we use the control rate and not the
567 * actual rate for this rate. See mac80211 tx.c
568 * ieee80211_duration() for a brief description of
569 * what rate we should choose to TX ACKs. */
570 tx_time = le16_to_cpu(ieee80211_generic_frame_duration(sc->hw,
571 sc->vif, 10, &srate));
573 ath5k_hw_reg_write(ah, tx_time, reg);
575 if (!HAS_SHPREAMBLE(i))
576 continue;
579 * We're not distinguishing short preamble here,
580 * This is true, all we'll get is a longer value here
581 * which is not necessarilly bad. We could use
582 * export ieee80211_frame_duration() but that needs to be
583 * fixed first to be properly used by mac802111 drivers:
585 * - remove erp stuff and let the routine figure ofdm
586 * erp rates
587 * - remove passing argument ieee80211_local as
588 * drivers don't have access to it
589 * - move drivers using ieee80211_generic_frame_duration()
590 * to this
592 ath5k_hw_reg_write(ah, tx_time,
593 reg + (AR5K_SET_SHORT_PREAMBLE << 2));
598 * Main reset function
600 int ath5k_hw_reset(struct ath5k_hw *ah, enum ieee80211_if_types op_mode,
601 struct ieee80211_channel *channel, bool change_channel)
603 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
604 struct pci_dev *pdev = ah->ah_sc->pdev;
605 u32 data, s_seq, s_ant, s_led[3], dma_size;
606 unsigned int i, mode, freq, ee_mode, ant[2];
607 int ret;
609 ATH5K_TRACE(ah->ah_sc);
611 s_seq = 0;
612 s_ant = 0;
613 ee_mode = 0;
614 freq = 0;
615 mode = 0;
618 * Save some registers before a reset
620 /*DCU/Antenna selection not available on 5210*/
621 if (ah->ah_version != AR5K_AR5210) {
622 if (change_channel) {
623 /* Seq number for queue 0 -do this for all queues ? */
624 s_seq = ath5k_hw_reg_read(ah,
625 AR5K_QUEUE_DFS_SEQNUM(0));
626 /*Default antenna*/
627 s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
631 /*GPIOs*/
632 s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) & AR5K_PCICFG_LEDSTATE;
633 s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
634 s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
636 if (change_channel && ah->ah_rf_banks != NULL)
637 ath5k_hw_get_rf_gain(ah);
640 /*Wakeup the device*/
641 ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, false);
642 if (ret)
643 return ret;
646 * Initialize operating mode
648 ah->ah_op_mode = op_mode;
651 * 5111/5112 Settings
652 * 5210 only comes with RF5110
654 if (ah->ah_version != AR5K_AR5210) {
655 if (ah->ah_radio != AR5K_RF5111 &&
656 ah->ah_radio != AR5K_RF5112 &&
657 ah->ah_radio != AR5K_RF5413 &&
658 ah->ah_radio != AR5K_RF2413) {
659 ATH5K_ERR(ah->ah_sc,
660 "invalid phy radio: %u\n", ah->ah_radio);
661 return -EINVAL;
664 switch (channel->hw_value & CHANNEL_MODES) {
665 case CHANNEL_A:
666 mode = AR5K_MODE_11A;
667 freq = AR5K_INI_RFGAIN_5GHZ;
668 ee_mode = AR5K_EEPROM_MODE_11A;
669 break;
670 case CHANNEL_G:
671 mode = AR5K_MODE_11G;
672 freq = AR5K_INI_RFGAIN_2GHZ;
673 ee_mode = AR5K_EEPROM_MODE_11G;
674 break;
675 case CHANNEL_B:
676 mode = AR5K_MODE_11B;
677 freq = AR5K_INI_RFGAIN_2GHZ;
678 ee_mode = AR5K_EEPROM_MODE_11B;
679 break;
680 case CHANNEL_T:
681 mode = AR5K_MODE_11A_TURBO;
682 freq = AR5K_INI_RFGAIN_5GHZ;
683 ee_mode = AR5K_EEPROM_MODE_11A;
684 break;
685 /*Is this ok on 5211 too ?*/
686 case CHANNEL_TG:
687 mode = AR5K_MODE_11G_TURBO;
688 freq = AR5K_INI_RFGAIN_2GHZ;
689 ee_mode = AR5K_EEPROM_MODE_11G;
690 break;
691 case CHANNEL_XR:
692 if (ah->ah_version == AR5K_AR5211) {
693 ATH5K_ERR(ah->ah_sc,
694 "XR mode not available on 5211");
695 return -EINVAL;
697 mode = AR5K_MODE_XR;
698 freq = AR5K_INI_RFGAIN_5GHZ;
699 ee_mode = AR5K_EEPROM_MODE_11A;
700 break;
701 default:
702 ATH5K_ERR(ah->ah_sc,
703 "invalid channel: %d\n", channel->center_freq);
704 return -EINVAL;
707 /* PHY access enable */
708 ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
712 ret = ath5k_hw_write_initvals(ah, mode, change_channel);
713 if (ret)
714 return ret;
717 * 5211/5212 Specific
719 if (ah->ah_version != AR5K_AR5210) {
721 * Write initial RF gain settings
722 * This should work for both 5111/5112
724 ret = ath5k_hw_rfgain(ah, freq);
725 if (ret)
726 return ret;
728 mdelay(1);
731 * Write some more initial register settings
733 if (ah->ah_version == AR5K_AR5212) {
734 ath5k_hw_reg_write(ah, 0x0002a002, AR5K_PHY(11));
736 if (channel->hw_value == CHANNEL_G)
737 if (ah->ah_mac_srev < AR5K_SREV_VER_AR2413)
738 ath5k_hw_reg_write(ah, 0x00f80d80,
739 AR5K_PHY(83));
740 else if (ah->ah_mac_srev < AR5K_SREV_VER_AR2424)
741 ath5k_hw_reg_write(ah, 0x00380140,
742 AR5K_PHY(83));
743 else if (ah->ah_mac_srev < AR5K_SREV_VER_AR2425)
744 ath5k_hw_reg_write(ah, 0x00fc0ec0,
745 AR5K_PHY(83));
746 else /* 2425 */
747 ath5k_hw_reg_write(ah, 0x00fc0fc0,
748 AR5K_PHY(83));
749 else
750 ath5k_hw_reg_write(ah, 0x00000000,
751 AR5K_PHY(83));
753 ath5k_hw_reg_write(ah, 0x000009b5, 0xa228);
754 ath5k_hw_reg_write(ah, 0x0000000f, 0x8060);
755 ath5k_hw_reg_write(ah, 0x00000000, 0xa254);
756 ath5k_hw_reg_write(ah, 0x0000000e, AR5K_PHY_SCAL);
759 /* Fix for first revision of the RF5112 RF chipset */
760 if (ah->ah_radio >= AR5K_RF5112 &&
761 ah->ah_radio_5ghz_revision <
762 AR5K_SREV_RAD_5112A) {
763 ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
764 AR5K_PHY_CCKTXCTL);
765 if (channel->hw_value & CHANNEL_5GHZ)
766 data = 0xffb81020;
767 else
768 data = 0xffb80d20;
769 ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
773 * Set TX power (FIXME)
775 ret = ath5k_hw_txpower(ah, channel, AR5K_TUNE_DEFAULT_TXPOWER);
776 if (ret)
777 return ret;
779 /* Write rate duration table only on AR5212 and if
780 * virtual interface has already been brought up
781 * XXX: rethink this after new mode changes to
782 * mac80211 are integrated */
783 if (ah->ah_version == AR5K_AR5212 &&
784 ah->ah_sc->vif != NULL)
785 ath5k_hw_write_rate_duration(ah, mode);
788 * Write RF registers
789 * TODO:Does this work on 5211 (5111) ?
791 ret = ath5k_hw_rfregs(ah, channel, mode);
792 if (ret)
793 return ret;
796 * Configure additional registers
799 /* Write OFDM timings on 5212*/
800 if (ah->ah_version == AR5K_AR5212 &&
801 channel->hw_value & CHANNEL_OFDM) {
802 ret = ath5k_hw_write_ofdm_timings(ah, channel);
803 if (ret)
804 return ret;
807 /*Enable/disable 802.11b mode on 5111
808 (enable 2111 frequency converter + CCK)*/
809 if (ah->ah_radio == AR5K_RF5111) {
810 if (mode == AR5K_MODE_11B)
811 AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
812 AR5K_TXCFG_B_MODE);
813 else
814 AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
815 AR5K_TXCFG_B_MODE);
819 * Set channel and calibrate the PHY
821 ret = ath5k_hw_channel(ah, channel);
822 if (ret)
823 return ret;
825 /* Set antenna mode */
826 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x44),
827 ah->ah_antenna[ee_mode][0], 0xfffffc06);
830 * In case a fixed antenna was set as default
831 * write the same settings on both AR5K_PHY_ANT_SWITCH_TABLE
832 * registers.
834 if (s_ant != 0){
835 if (s_ant == AR5K_ANT_FIXED_A) /* 1 - Main */
836 ant[0] = ant[1] = AR5K_ANT_FIXED_A;
837 else /* 2 - Aux */
838 ant[0] = ant[1] = AR5K_ANT_FIXED_B;
839 } else {
840 ant[0] = AR5K_ANT_FIXED_A;
841 ant[1] = AR5K_ANT_FIXED_B;
844 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[0]],
845 AR5K_PHY_ANT_SWITCH_TABLE_0);
846 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[1]],
847 AR5K_PHY_ANT_SWITCH_TABLE_1);
849 /* Commit values from EEPROM */
850 if (ah->ah_radio == AR5K_RF5111)
851 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_FRAME_CTL,
852 AR5K_PHY_FRAME_CTL_TX_CLIP, ee->ee_tx_clip);
854 ath5k_hw_reg_write(ah,
855 AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
856 AR5K_PHY(0x5a));
858 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x11),
859 (ee->ee_switch_settling[ee_mode] << 7) & 0x3f80,
860 0xffffc07f);
861 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x12),
862 (ee->ee_ant_tx_rx[ee_mode] << 12) & 0x3f000,
863 0xfffc0fff);
864 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x14),
865 (ee->ee_adc_desired_size[ee_mode] & 0x00ff) |
866 ((ee->ee_pga_desired_size[ee_mode] << 8) & 0xff00),
867 0xffff0000);
869 ath5k_hw_reg_write(ah,
870 (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
871 (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
872 (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
873 (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY(0x0d));
875 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x0a),
876 ee->ee_tx_end2xlna_enable[ee_mode] << 8, 0xffff00ff);
877 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x19),
878 (ee->ee_thr_62[ee_mode] << 12) & 0x7f000, 0xfff80fff);
879 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x49), 4, 0xffffff01);
881 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
882 AR5K_PHY_IQ_CORR_ENABLE |
883 (ee->ee_i_cal[ee_mode] << AR5K_PHY_IQ_CORR_Q_I_COFF_S) |
884 ee->ee_q_cal[ee_mode]);
886 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
887 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
888 AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
889 ee->ee_margin_tx_rx[ee_mode]);
891 } else {
892 mdelay(1);
893 /* Disable phy and wait */
894 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
895 mdelay(1);
899 * Restore saved values
901 /*DCU/Antenna selection not available on 5210*/
902 if (ah->ah_version != AR5K_AR5210) {
903 ath5k_hw_reg_write(ah, s_seq, AR5K_QUEUE_DFS_SEQNUM(0));
904 ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
906 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
907 ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
908 ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
911 * Misc
913 /* XXX: add ah->aid once mac80211 gives this to us */
914 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
916 ath5k_hw_set_opmode(ah);
917 /*PISR/SISR Not available on 5210*/
918 if (ah->ah_version != AR5K_AR5210) {
919 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
920 /* If we later allow tuning for this, store into sc structure */
921 data = AR5K_TUNE_RSSI_THRES |
922 AR5K_TUNE_BMISS_THRES << AR5K_RSSI_THR_BMISS_S;
923 ath5k_hw_reg_write(ah, data, AR5K_RSSI_THR);
927 * Set Rx/Tx DMA Configuration
929 * Set maximum DMA size (512) except for PCI-E cards since
930 * it causes rx overruns and tx errors (tested on 5424 but since
931 * rx overruns also occur on 5416/5418 with madwifi we set 128
932 * for all PCI-E cards to be safe).
934 * In dumps this is 128 for allchips.
936 * XXX: need to check 5210 for this
937 * TODO: Check out tx triger level, it's always 64 on dumps but I
938 * guess we can tweak it and see how it goes ;-)
940 dma_size = (pdev->is_pcie) ? AR5K_DMASIZE_128B : AR5K_DMASIZE_512B;
941 if (ah->ah_version != AR5K_AR5210) {
942 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
943 AR5K_TXCFG_SDMAMR, dma_size);
944 AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG,
945 AR5K_RXCFG_SDMAMW, dma_size);
949 * Enable the PHY and wait until completion
951 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
954 * 5111/5112 Specific
956 if (ah->ah_version != AR5K_AR5210) {
957 data = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
958 AR5K_PHY_RX_DELAY_M;
959 data = (channel->hw_value & CHANNEL_CCK) ?
960 ((data << 2) / 22) : (data / 10);
962 udelay(100 + data);
963 } else {
964 mdelay(1);
968 * Enable calibration and wait until completion
970 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
971 AR5K_PHY_AGCCTL_CAL);
973 if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
974 AR5K_PHY_AGCCTL_CAL, 0, false)) {
975 ATH5K_ERR(ah->ah_sc, "calibration timeout (%uMHz)\n",
976 channel->center_freq);
977 return -EAGAIN;
980 ret = ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
981 if (ret)
982 return ret;
984 ah->ah_calibration = false;
986 /* A and G modes can use QAM modulation which requires enabling
987 * I and Q calibration. Don't bother in B mode. */
988 if (!(mode == AR5K_MODE_11B)) {
989 ah->ah_calibration = true;
990 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
991 AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
992 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
993 AR5K_PHY_IQ_RUN);
997 * Reset queues and start beacon timers at the end of the reset routine
999 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
1000 /*No QCU on 5210*/
1001 if (ah->ah_version != AR5K_AR5210)
1002 AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(i), i);
1004 ret = ath5k_hw_reset_tx_queue(ah, i);
1005 if (ret) {
1006 ATH5K_ERR(ah->ah_sc,
1007 "failed to reset TX queue #%d\n", i);
1008 return ret;
1012 /* Pre-enable interrupts on 5211/5212*/
1013 if (ah->ah_version != AR5K_AR5210)
1014 ath5k_hw_set_intr(ah, AR5K_INT_RX | AR5K_INT_TX |
1015 AR5K_INT_FATAL);
1018 * Set RF kill flags if supported by the device (read from the EEPROM)
1019 * Disable gpio_intr for now since it results system hang.
1020 * TODO: Handle this in ath5k_intr
1022 #if 0
1023 if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header)) {
1024 ath5k_hw_set_gpio_input(ah, 0);
1025 ah->ah_gpio[0] = ath5k_hw_get_gpio(ah, 0);
1026 if (ah->ah_gpio[0] == 0)
1027 ath5k_hw_set_gpio_intr(ah, 0, 1);
1028 else
1029 ath5k_hw_set_gpio_intr(ah, 0, 0);
1031 #endif
1034 * Set the 32MHz reference clock on 5212 phy clock sleep register
1036 * TODO: Find out how to switch to external 32Khz clock to save power
1038 if (ah->ah_version == AR5K_AR5212) {
1039 ath5k_hw_reg_write(ah, AR5K_PHY_SCR_32MHZ, AR5K_PHY_SCR);
1040 ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
1041 ath5k_hw_reg_write(ah, AR5K_PHY_SCAL_32MHZ, AR5K_PHY_SCAL);
1042 ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
1043 ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
1044 ath5k_hw_reg_write(ah, ah->ah_phy_spending, AR5K_PHY_SPENDING);
1047 if (ah->ah_version == AR5K_AR5212) {
1048 ath5k_hw_reg_write(ah, 0x000100aa, 0x8118);
1049 ath5k_hw_reg_write(ah, 0x00003210, 0x811c);
1050 ath5k_hw_reg_write(ah, 0x00000052, 0x8108);
1051 if (ah->ah_mac_srev >= AR5K_SREV_VER_AR2413)
1052 ath5k_hw_reg_write(ah, 0x00000004, 0x8120);
1056 * Disable beacons and reset the register
1058 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
1059 AR5K_BEACON_RESET_TSF);
1061 return 0;
1065 * Reset chipset
1067 static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
1069 int ret;
1070 u32 mask = val ? val : ~0U;
1072 ATH5K_TRACE(ah->ah_sc);
1074 /* Read-and-clear RX Descriptor Pointer*/
1075 ath5k_hw_reg_read(ah, AR5K_RXDP);
1078 * Reset the device and wait until success
1080 ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
1082 /* Wait at least 128 PCI clocks */
1083 udelay(15);
1085 if (ah->ah_version == AR5K_AR5210) {
1086 val &= AR5K_RESET_CTL_CHIP;
1087 mask &= AR5K_RESET_CTL_CHIP;
1088 } else {
1089 val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1090 mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1093 ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, false);
1096 * Reset configuration register (for hw byte-swap). Note that this
1097 * is only set for big endian. We do the necessary magic in
1098 * AR5K_INIT_CFG.
1100 if ((val & AR5K_RESET_CTL_PCU) == 0)
1101 ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
1103 return ret;
1107 * Power management functions
1111 * Sleep control
1113 int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
1114 bool set_chip, u16 sleep_duration)
1116 unsigned int i;
1117 u32 staid;
1119 ATH5K_TRACE(ah->ah_sc);
1120 staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
1122 switch (mode) {
1123 case AR5K_PM_AUTO:
1124 staid &= ~AR5K_STA_ID1_DEFAULT_ANTENNA;
1125 /* fallthrough */
1126 case AR5K_PM_NETWORK_SLEEP:
1127 if (set_chip)
1128 ath5k_hw_reg_write(ah,
1129 AR5K_SLEEP_CTL_SLE | sleep_duration,
1130 AR5K_SLEEP_CTL);
1132 staid |= AR5K_STA_ID1_PWR_SV;
1133 break;
1135 case AR5K_PM_FULL_SLEEP:
1136 if (set_chip)
1137 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_SLP,
1138 AR5K_SLEEP_CTL);
1140 staid |= AR5K_STA_ID1_PWR_SV;
1141 break;
1143 case AR5K_PM_AWAKE:
1144 if (!set_chip)
1145 goto commit;
1147 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1148 AR5K_SLEEP_CTL);
1150 for (i = 5000; i > 0; i--) {
1151 /* Check if the chip did wake up */
1152 if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
1153 AR5K_PCICFG_SPWR_DN) == 0)
1154 break;
1156 /* Wait a bit and retry */
1157 udelay(200);
1158 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1159 AR5K_SLEEP_CTL);
1162 /* Fail if the chip didn't wake up */
1163 if (i <= 0)
1164 return -EIO;
1166 staid &= ~AR5K_STA_ID1_PWR_SV;
1167 break;
1169 default:
1170 return -EINVAL;
1173 commit:
1174 ah->ah_power_mode = mode;
1175 ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
1177 return 0;
1180 /***********************\
1181 DMA Related Functions
1182 \***********************/
1185 * Receive functions
1189 * Start DMA receive
1191 void ath5k_hw_start_rx(struct ath5k_hw *ah)
1193 ATH5K_TRACE(ah->ah_sc);
1194 ath5k_hw_reg_write(ah, AR5K_CR_RXE, AR5K_CR);
1198 * Stop DMA receive
1200 int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
1202 unsigned int i;
1204 ATH5K_TRACE(ah->ah_sc);
1205 ath5k_hw_reg_write(ah, AR5K_CR_RXD, AR5K_CR);
1208 * It may take some time to disable the DMA receive unit
1210 for (i = 2000; i > 0 &&
1211 (ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_CR_RXE) != 0;
1212 i--)
1213 udelay(10);
1215 return i ? 0 : -EBUSY;
1219 * Get the address of the RX Descriptor
1221 u32 ath5k_hw_get_rx_buf(struct ath5k_hw *ah)
1223 return ath5k_hw_reg_read(ah, AR5K_RXDP);
1227 * Set the address of the RX Descriptor
1229 void ath5k_hw_put_rx_buf(struct ath5k_hw *ah, u32 phys_addr)
1231 ATH5K_TRACE(ah->ah_sc);
1233 /*TODO:Shouldn't we check if RX is enabled first ?*/
1234 ath5k_hw_reg_write(ah, phys_addr, AR5K_RXDP);
1238 * Transmit functions
1242 * Start DMA transmit for a specific queue
1243 * (see also QCU/DCU functions)
1245 int ath5k_hw_tx_start(struct ath5k_hw *ah, unsigned int queue)
1247 u32 tx_queue;
1249 ATH5K_TRACE(ah->ah_sc);
1250 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1252 /* Return if queue is declared inactive */
1253 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1254 return -EIO;
1256 if (ah->ah_version == AR5K_AR5210) {
1257 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1260 * Set the queue by type on 5210
1262 switch (ah->ah_txq[queue].tqi_type) {
1263 case AR5K_TX_QUEUE_DATA:
1264 tx_queue |= AR5K_CR_TXE0 & ~AR5K_CR_TXD0;
1265 break;
1266 case AR5K_TX_QUEUE_BEACON:
1267 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1268 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
1269 AR5K_BSR);
1270 break;
1271 case AR5K_TX_QUEUE_CAB:
1272 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1273 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1FV | AR5K_BCR_TQ1V |
1274 AR5K_BCR_BDMAE, AR5K_BSR);
1275 break;
1276 default:
1277 return -EINVAL;
1279 /* Start queue */
1280 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1281 } else {
1282 /* Return if queue is disabled */
1283 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXD, queue))
1284 return -EIO;
1286 /* Start queue */
1287 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXE, queue);
1290 return 0;
1294 * Stop DMA transmit for a specific queue
1295 * (see also QCU/DCU functions)
1297 int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue)
1299 unsigned int i = 100;
1300 u32 tx_queue, pending;
1302 ATH5K_TRACE(ah->ah_sc);
1303 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1305 /* Return if queue is declared inactive */
1306 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1307 return -EIO;
1309 if (ah->ah_version == AR5K_AR5210) {
1310 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1313 * Set by queue type
1315 switch (ah->ah_txq[queue].tqi_type) {
1316 case AR5K_TX_QUEUE_DATA:
1317 tx_queue |= AR5K_CR_TXD0 & ~AR5K_CR_TXE0;
1318 break;
1319 case AR5K_TX_QUEUE_BEACON:
1320 case AR5K_TX_QUEUE_CAB:
1321 /* XXX Fix me... */
1322 tx_queue |= AR5K_CR_TXD1 & ~AR5K_CR_TXD1;
1323 ath5k_hw_reg_write(ah, 0, AR5K_BSR);
1324 break;
1325 default:
1326 return -EINVAL;
1329 /* Stop queue */
1330 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1331 } else {
1333 * Schedule TX disable and wait until queue is empty
1335 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXD, queue);
1337 /*Check for pending frames*/
1338 do {
1339 pending = ath5k_hw_reg_read(ah,
1340 AR5K_QUEUE_STATUS(queue)) &
1341 AR5K_QCU_STS_FRMPENDCNT;
1342 udelay(100);
1343 } while (--i && pending);
1345 /* Clear register */
1346 ath5k_hw_reg_write(ah, 0, AR5K_QCU_TXD);
1349 /* TODO: Check for success else return error */
1350 return 0;
1354 * Get the address of the TX Descriptor for a specific queue
1355 * (see also QCU/DCU functions)
1357 u32 ath5k_hw_get_tx_buf(struct ath5k_hw *ah, unsigned int queue)
1359 u16 tx_reg;
1361 ATH5K_TRACE(ah->ah_sc);
1362 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1365 * Get the transmit queue descriptor pointer from the selected queue
1367 /*5210 doesn't have QCU*/
1368 if (ah->ah_version == AR5K_AR5210) {
1369 switch (ah->ah_txq[queue].tqi_type) {
1370 case AR5K_TX_QUEUE_DATA:
1371 tx_reg = AR5K_NOQCU_TXDP0;
1372 break;
1373 case AR5K_TX_QUEUE_BEACON:
1374 case AR5K_TX_QUEUE_CAB:
1375 tx_reg = AR5K_NOQCU_TXDP1;
1376 break;
1377 default:
1378 return 0xffffffff;
1380 } else {
1381 tx_reg = AR5K_QUEUE_TXDP(queue);
1384 return ath5k_hw_reg_read(ah, tx_reg);
1388 * Set the address of the TX Descriptor for a specific queue
1389 * (see also QCU/DCU functions)
1391 int ath5k_hw_put_tx_buf(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
1393 u16 tx_reg;
1395 ATH5K_TRACE(ah->ah_sc);
1396 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1399 * Set the transmit queue descriptor pointer register by type
1400 * on 5210
1402 if (ah->ah_version == AR5K_AR5210) {
1403 switch (ah->ah_txq[queue].tqi_type) {
1404 case AR5K_TX_QUEUE_DATA:
1405 tx_reg = AR5K_NOQCU_TXDP0;
1406 break;
1407 case AR5K_TX_QUEUE_BEACON:
1408 case AR5K_TX_QUEUE_CAB:
1409 tx_reg = AR5K_NOQCU_TXDP1;
1410 break;
1411 default:
1412 return -EINVAL;
1414 } else {
1416 * Set the transmit queue descriptor pointer for
1417 * the selected queue on QCU for 5211+
1418 * (this won't work if the queue is still active)
1420 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
1421 return -EIO;
1423 tx_reg = AR5K_QUEUE_TXDP(queue);
1426 /* Set descriptor pointer */
1427 ath5k_hw_reg_write(ah, phys_addr, tx_reg);
1429 return 0;
1433 * Update tx trigger level
1435 int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase)
1437 u32 trigger_level, imr;
1438 int ret = -EIO;
1440 ATH5K_TRACE(ah->ah_sc);
1443 * Disable interrupts by setting the mask
1445 imr = ath5k_hw_set_intr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
1447 /*TODO: Boundary check on trigger_level*/
1448 trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
1449 AR5K_TXCFG_TXFULL);
1451 if (!increase) {
1452 if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
1453 goto done;
1454 } else
1455 trigger_level +=
1456 ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
1459 * Update trigger level on success
1461 if (ah->ah_version == AR5K_AR5210)
1462 ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
1463 else
1464 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
1465 AR5K_TXCFG_TXFULL, trigger_level);
1467 ret = 0;
1469 done:
1471 * Restore interrupt mask
1473 ath5k_hw_set_intr(ah, imr);
1475 return ret;
1479 * Interrupt handling
1483 * Check if we have pending interrupts
1485 bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
1487 ATH5K_TRACE(ah->ah_sc);
1488 return ath5k_hw_reg_read(ah, AR5K_INTPEND);
1492 * Get interrupt mask (ISR)
1494 int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
1496 u32 data;
1498 ATH5K_TRACE(ah->ah_sc);
1501 * Read interrupt status from the Interrupt Status register
1502 * on 5210
1504 if (ah->ah_version == AR5K_AR5210) {
1505 data = ath5k_hw_reg_read(ah, AR5K_ISR);
1506 if (unlikely(data == AR5K_INT_NOCARD)) {
1507 *interrupt_mask = data;
1508 return -ENODEV;
1510 } else {
1512 * Read interrupt status from the Read-And-Clear shadow register
1513 * Note: PISR/SISR Not available on 5210
1515 data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
1519 * Get abstract interrupt mask (driver-compatible)
1521 *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
1523 if (unlikely(data == AR5K_INT_NOCARD))
1524 return -ENODEV;
1526 if (data & (AR5K_ISR_RXOK | AR5K_ISR_RXERR))
1527 *interrupt_mask |= AR5K_INT_RX;
1529 if (data & (AR5K_ISR_TXOK | AR5K_ISR_TXERR
1530 | AR5K_ISR_TXDESC | AR5K_ISR_TXEOL))
1531 *interrupt_mask |= AR5K_INT_TX;
1533 if (ah->ah_version != AR5K_AR5210) {
1534 /*HIU = Host Interface Unit (PCI etc)*/
1535 if (unlikely(data & (AR5K_ISR_HIUERR)))
1536 *interrupt_mask |= AR5K_INT_FATAL;
1538 /*Beacon Not Ready*/
1539 if (unlikely(data & (AR5K_ISR_BNR)))
1540 *interrupt_mask |= AR5K_INT_BNR;
1544 * XXX: BMISS interrupts may occur after association.
1545 * I found this on 5210 code but it needs testing. If this is
1546 * true we should disable them before assoc and re-enable them
1547 * after a successfull assoc + some jiffies.
1549 #if 0
1550 interrupt_mask &= ~AR5K_INT_BMISS;
1551 #endif
1554 * In case we didn't handle anything,
1555 * print the register value.
1557 if (unlikely(*interrupt_mask == 0 && net_ratelimit()))
1558 ATH5K_PRINTF("0x%08x\n", data);
1560 return 0;
1564 * Set interrupt mask
1566 enum ath5k_int ath5k_hw_set_intr(struct ath5k_hw *ah, enum ath5k_int new_mask)
1568 enum ath5k_int old_mask, int_mask;
1571 * Disable card interrupts to prevent any race conditions
1572 * (they will be re-enabled afterwards).
1574 ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
1576 old_mask = ah->ah_imr;
1579 * Add additional, chipset-dependent interrupt mask flags
1580 * and write them to the IMR (interrupt mask register).
1582 int_mask = new_mask & AR5K_INT_COMMON;
1584 if (new_mask & AR5K_INT_RX)
1585 int_mask |= AR5K_IMR_RXOK | AR5K_IMR_RXERR | AR5K_IMR_RXORN |
1586 AR5K_IMR_RXDESC;
1588 if (new_mask & AR5K_INT_TX)
1589 int_mask |= AR5K_IMR_TXOK | AR5K_IMR_TXERR | AR5K_IMR_TXDESC |
1590 AR5K_IMR_TXURN;
1592 if (ah->ah_version != AR5K_AR5210) {
1593 if (new_mask & AR5K_INT_FATAL) {
1594 int_mask |= AR5K_IMR_HIUERR;
1595 AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_MCABT |
1596 AR5K_SIMR2_SSERR | AR5K_SIMR2_DPERR);
1600 ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
1602 /* Store new interrupt mask */
1603 ah->ah_imr = new_mask;
1605 /* ..re-enable interrupts */
1606 ath5k_hw_reg_write(ah, AR5K_IER_ENABLE, AR5K_IER);
1608 return old_mask;
1612 /*************************\
1613 EEPROM access functions
1614 \*************************/
1617 * Read from eeprom
1619 static int ath5k_hw_eeprom_read(struct ath5k_hw *ah, u32 offset, u16 *data)
1621 u32 status, timeout;
1623 ATH5K_TRACE(ah->ah_sc);
1625 * Initialize EEPROM access
1627 if (ah->ah_version == AR5K_AR5210) {
1628 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1629 (void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset));
1630 } else {
1631 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1632 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1633 AR5K_EEPROM_CMD_READ);
1636 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1637 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1638 if (status & AR5K_EEPROM_STAT_RDDONE) {
1639 if (status & AR5K_EEPROM_STAT_RDERR)
1640 return -EIO;
1641 *data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) &
1642 0xffff);
1643 return 0;
1645 udelay(15);
1648 return -ETIMEDOUT;
1652 * Write to eeprom - currently disabled, use at your own risk
1654 #if 0
1655 static int ath5k_hw_eeprom_write(struct ath5k_hw *ah, u32 offset, u16 data)
1658 u32 status, timeout;
1660 ATH5K_TRACE(ah->ah_sc);
1663 * Initialize eeprom access
1666 if (ah->ah_version == AR5K_AR5210) {
1667 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1668 } else {
1669 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1670 AR5K_EEPROM_CMD_RESET);
1674 * Write data to data register
1677 if (ah->ah_version == AR5K_AR5210) {
1678 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_BASE + (4 * offset));
1679 } else {
1680 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1681 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_DATA);
1682 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1683 AR5K_EEPROM_CMD_WRITE);
1687 * Check status
1690 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1691 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1692 if (status & AR5K_EEPROM_STAT_WRDONE) {
1693 if (status & AR5K_EEPROM_STAT_WRERR)
1694 return EIO;
1695 return 0;
1697 udelay(15);
1700 ATH5K_ERR(ah->ah_sc, "EEPROM Write is disabled!");
1701 return -EIO;
1703 #endif
1706 * Translate binary channel representation in EEPROM to frequency
1708 static u16 ath5k_eeprom_bin2freq(struct ath5k_hw *ah, u16 bin, unsigned int mode)
1710 u16 val;
1712 if (bin == AR5K_EEPROM_CHANNEL_DIS)
1713 return bin;
1715 if (mode == AR5K_EEPROM_MODE_11A) {
1716 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1717 val = (5 * bin) + 4800;
1718 else
1719 val = bin > 62 ? (10 * 62) + (5 * (bin - 62)) + 5100 :
1720 (bin * 10) + 5100;
1721 } else {
1722 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1723 val = bin + 2300;
1724 else
1725 val = bin + 2400;
1728 return val;
1732 * Read antenna infos from eeprom
1734 static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
1735 unsigned int mode)
1737 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1738 u32 o = *offset;
1739 u16 val;
1740 int ret, i = 0;
1742 AR5K_EEPROM_READ(o++, val);
1743 ee->ee_switch_settling[mode] = (val >> 8) & 0x7f;
1744 ee->ee_ant_tx_rx[mode] = (val >> 2) & 0x3f;
1745 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1747 AR5K_EEPROM_READ(o++, val);
1748 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1749 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1750 ee->ee_ant_control[mode][i++] = val & 0x3f;
1752 AR5K_EEPROM_READ(o++, val);
1753 ee->ee_ant_control[mode][i++] = (val >> 10) & 0x3f;
1754 ee->ee_ant_control[mode][i++] = (val >> 4) & 0x3f;
1755 ee->ee_ant_control[mode][i] = (val << 2) & 0x3f;
1757 AR5K_EEPROM_READ(o++, val);
1758 ee->ee_ant_control[mode][i++] |= (val >> 14) & 0x3;
1759 ee->ee_ant_control[mode][i++] = (val >> 8) & 0x3f;
1760 ee->ee_ant_control[mode][i++] = (val >> 2) & 0x3f;
1761 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1763 AR5K_EEPROM_READ(o++, val);
1764 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1765 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1766 ee->ee_ant_control[mode][i++] = val & 0x3f;
1768 /* Get antenna modes */
1769 ah->ah_antenna[mode][0] =
1770 (ee->ee_ant_control[mode][0] << 4) | 0x1;
1771 ah->ah_antenna[mode][AR5K_ANT_FIXED_A] =
1772 ee->ee_ant_control[mode][1] |
1773 (ee->ee_ant_control[mode][2] << 6) |
1774 (ee->ee_ant_control[mode][3] << 12) |
1775 (ee->ee_ant_control[mode][4] << 18) |
1776 (ee->ee_ant_control[mode][5] << 24);
1777 ah->ah_antenna[mode][AR5K_ANT_FIXED_B] =
1778 ee->ee_ant_control[mode][6] |
1779 (ee->ee_ant_control[mode][7] << 6) |
1780 (ee->ee_ant_control[mode][8] << 12) |
1781 (ee->ee_ant_control[mode][9] << 18) |
1782 (ee->ee_ant_control[mode][10] << 24);
1784 /* return new offset */
1785 *offset = o;
1787 return 0;
1791 * Read supported modes from eeprom
1793 static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset,
1794 unsigned int mode)
1796 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1797 u32 o = *offset;
1798 u16 val;
1799 int ret;
1801 AR5K_EEPROM_READ(o++, val);
1802 ee->ee_tx_end2xlna_enable[mode] = (val >> 8) & 0xff;
1803 ee->ee_thr_62[mode] = val & 0xff;
1805 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1806 ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28;
1808 AR5K_EEPROM_READ(o++, val);
1809 ee->ee_tx_end2xpa_disable[mode] = (val >> 8) & 0xff;
1810 ee->ee_tx_frm2xpa_enable[mode] = val & 0xff;
1812 AR5K_EEPROM_READ(o++, val);
1813 ee->ee_pga_desired_size[mode] = (val >> 8) & 0xff;
1815 if ((val & 0xff) & 0x80)
1816 ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1);
1817 else
1818 ee->ee_noise_floor_thr[mode] = val & 0xff;
1820 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1821 ee->ee_noise_floor_thr[mode] =
1822 mode == AR5K_EEPROM_MODE_11A ? -54 : -1;
1824 AR5K_EEPROM_READ(o++, val);
1825 ee->ee_xlna_gain[mode] = (val >> 5) & 0xff;
1826 ee->ee_x_gain[mode] = (val >> 1) & 0xf;
1827 ee->ee_xpd[mode] = val & 0x1;
1829 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0)
1830 ee->ee_fixed_bias[mode] = (val >> 13) & 0x1;
1832 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) {
1833 AR5K_EEPROM_READ(o++, val);
1834 ee->ee_false_detect[mode] = (val >> 6) & 0x7f;
1836 if (mode == AR5K_EEPROM_MODE_11A)
1837 ee->ee_xr_power[mode] = val & 0x3f;
1838 else {
1839 ee->ee_ob[mode][0] = val & 0x7;
1840 ee->ee_db[mode][0] = (val >> 3) & 0x7;
1844 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) {
1845 ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN;
1846 ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA;
1847 } else {
1848 ee->ee_i_gain[mode] = (val >> 13) & 0x7;
1850 AR5K_EEPROM_READ(o++, val);
1851 ee->ee_i_gain[mode] |= (val << 3) & 0x38;
1853 if (mode == AR5K_EEPROM_MODE_11G)
1854 ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff;
1857 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
1858 mode == AR5K_EEPROM_MODE_11A) {
1859 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
1860 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
1863 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6 &&
1864 mode == AR5K_EEPROM_MODE_11G)
1865 ee->ee_scaled_cck_delta = (val >> 11) & 0x1f;
1867 /* return new offset */
1868 *offset = o;
1870 return 0;
1874 * Initialize eeprom & capabilities structs
1876 static int ath5k_eeprom_init(struct ath5k_hw *ah)
1878 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1879 unsigned int mode, i;
1880 int ret;
1881 u32 offset;
1882 u16 val;
1884 /* Initial TX thermal adjustment values */
1885 ee->ee_tx_clip = 4;
1886 ee->ee_pwd_84 = ee->ee_pwd_90 = 1;
1887 ee->ee_gain_select = 1;
1890 * Read values from EEPROM and store them in the capability structure
1892 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC, ee_magic);
1893 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT, ee_protect);
1894 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN, ee_regdomain);
1895 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION, ee_version);
1896 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR, ee_header);
1898 /* Return if we have an old EEPROM */
1899 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_0)
1900 return 0;
1902 #ifdef notyet
1904 * Validate the checksum of the EEPROM date. There are some
1905 * devices with invalid EEPROMs.
1907 for (cksum = 0, offset = 0; offset < AR5K_EEPROM_INFO_MAX; offset++) {
1908 AR5K_EEPROM_READ(AR5K_EEPROM_INFO(offset), val);
1909 cksum ^= val;
1911 if (cksum != AR5K_EEPROM_INFO_CKSUM) {
1912 ATH5K_ERR(ah->ah_sc, "Invalid EEPROM checksum 0x%04x\n", cksum);
1913 return -EIO;
1915 #endif
1917 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah->ah_ee_version),
1918 ee_ant_gain);
1920 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
1921 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0, ee_misc0);
1922 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1, ee_misc1);
1925 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_3) {
1926 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ, val);
1927 ee->ee_ob[AR5K_EEPROM_MODE_11B][0] = val & 0x7;
1928 ee->ee_db[AR5K_EEPROM_MODE_11B][0] = (val >> 3) & 0x7;
1930 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ, val);
1931 ee->ee_ob[AR5K_EEPROM_MODE_11G][0] = val & 0x7;
1932 ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7;
1936 * Get conformance test limit values
1938 offset = AR5K_EEPROM_CTL(ah->ah_ee_version);
1939 ee->ee_ctls = AR5K_EEPROM_N_CTLS(ah->ah_ee_version);
1941 for (i = 0; i < ee->ee_ctls; i++) {
1942 AR5K_EEPROM_READ(offset++, val);
1943 ee->ee_ctl[i] = (val >> 8) & 0xff;
1944 ee->ee_ctl[i + 1] = val & 0xff;
1948 * Get values for 802.11a (5GHz)
1950 mode = AR5K_EEPROM_MODE_11A;
1952 ee->ee_turbo_max_power[mode] =
1953 AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header);
1955 offset = AR5K_EEPROM_MODES_11A(ah->ah_ee_version);
1957 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
1958 if (ret)
1959 return ret;
1961 AR5K_EEPROM_READ(offset++, val);
1962 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
1963 ee->ee_ob[mode][3] = (val >> 5) & 0x7;
1964 ee->ee_db[mode][3] = (val >> 2) & 0x7;
1965 ee->ee_ob[mode][2] = (val << 1) & 0x7;
1967 AR5K_EEPROM_READ(offset++, val);
1968 ee->ee_ob[mode][2] |= (val >> 15) & 0x1;
1969 ee->ee_db[mode][2] = (val >> 12) & 0x7;
1970 ee->ee_ob[mode][1] = (val >> 9) & 0x7;
1971 ee->ee_db[mode][1] = (val >> 6) & 0x7;
1972 ee->ee_ob[mode][0] = (val >> 3) & 0x7;
1973 ee->ee_db[mode][0] = val & 0x7;
1975 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
1976 if (ret)
1977 return ret;
1979 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1) {
1980 AR5K_EEPROM_READ(offset++, val);
1981 ee->ee_margin_tx_rx[mode] = val & 0x3f;
1985 * Get values for 802.11b (2.4GHz)
1987 mode = AR5K_EEPROM_MODE_11B;
1988 offset = AR5K_EEPROM_MODES_11B(ah->ah_ee_version);
1990 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
1991 if (ret)
1992 return ret;
1994 AR5K_EEPROM_READ(offset++, val);
1995 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
1996 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
1997 ee->ee_db[mode][1] = val & 0x7;
1999 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2000 if (ret)
2001 return ret;
2003 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2004 AR5K_EEPROM_READ(offset++, val);
2005 ee->ee_cal_pier[mode][0] =
2006 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2007 ee->ee_cal_pier[mode][1] =
2008 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
2010 AR5K_EEPROM_READ(offset++, val);
2011 ee->ee_cal_pier[mode][2] =
2012 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2015 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
2016 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
2019 * Get values for 802.11g (2.4GHz)
2021 mode = AR5K_EEPROM_MODE_11G;
2022 offset = AR5K_EEPROM_MODES_11G(ah->ah_ee_version);
2024 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2025 if (ret)
2026 return ret;
2028 AR5K_EEPROM_READ(offset++, val);
2029 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2030 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
2031 ee->ee_db[mode][1] = val & 0x7;
2033 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2034 if (ret)
2035 return ret;
2037 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2038 AR5K_EEPROM_READ(offset++, val);
2039 ee->ee_cal_pier[mode][0] =
2040 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2041 ee->ee_cal_pier[mode][1] =
2042 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
2044 AR5K_EEPROM_READ(offset++, val);
2045 ee->ee_turbo_max_power[mode] = val & 0x7f;
2046 ee->ee_xr_power[mode] = (val >> 7) & 0x3f;
2048 AR5K_EEPROM_READ(offset++, val);
2049 ee->ee_cal_pier[mode][2] =
2050 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2052 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
2053 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
2055 AR5K_EEPROM_READ(offset++, val);
2056 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
2057 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
2059 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) {
2060 AR5K_EEPROM_READ(offset++, val);
2061 ee->ee_cck_ofdm_gain_delta = val & 0xff;
2066 * Read 5GHz EEPROM channels
2069 return 0;
2073 * Read the MAC address from eeprom
2075 static int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
2077 u8 mac_d[ETH_ALEN];
2078 u32 total, offset;
2079 u16 data;
2080 int octet, ret;
2082 memset(mac, 0, ETH_ALEN);
2083 memset(mac_d, 0, ETH_ALEN);
2085 ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
2086 if (ret)
2087 return ret;
2089 for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
2090 ret = ath5k_hw_eeprom_read(ah, offset, &data);
2091 if (ret)
2092 return ret;
2094 total += data;
2095 mac_d[octet + 1] = data & 0xff;
2096 mac_d[octet] = data >> 8;
2097 octet += 2;
2100 memcpy(mac, mac_d, ETH_ALEN);
2102 if (!total || total == 3 * 0xffff)
2103 return -EINVAL;
2105 return 0;
2109 * Fill the capabilities struct
2111 static int ath5k_hw_get_capabilities(struct ath5k_hw *ah)
2113 u16 ee_header;
2115 ATH5K_TRACE(ah->ah_sc);
2116 /* Capabilities stored in the EEPROM */
2117 ee_header = ah->ah_capabilities.cap_eeprom.ee_header;
2119 if (ah->ah_version == AR5K_AR5210) {
2121 * Set radio capabilities
2122 * (The AR5110 only supports the middle 5GHz band)
2124 ah->ah_capabilities.cap_range.range_5ghz_min = 5120;
2125 ah->ah_capabilities.cap_range.range_5ghz_max = 5430;
2126 ah->ah_capabilities.cap_range.range_2ghz_min = 0;
2127 ah->ah_capabilities.cap_range.range_2ghz_max = 0;
2129 /* Set supported modes */
2130 __set_bit(AR5K_MODE_11A, ah->ah_capabilities.cap_mode);
2131 __set_bit(AR5K_MODE_11A_TURBO, ah->ah_capabilities.cap_mode);
2132 } else {
2134 * XXX The tranceiver supports frequencies from 4920 to 6100GHz
2135 * XXX and from 2312 to 2732GHz. There are problems with the
2136 * XXX current ieee80211 implementation because the IEEE
2137 * XXX channel mapping does not support negative channel
2138 * XXX numbers (2312MHz is channel -19). Of course, this
2139 * XXX doesn't matter because these channels are out of range
2140 * XXX but some regulation domains like MKK (Japan) will
2141 * XXX support frequencies somewhere around 4.8GHz.
2145 * Set radio capabilities
2148 if (AR5K_EEPROM_HDR_11A(ee_header)) {
2149 ah->ah_capabilities.cap_range.range_5ghz_min = 5005; /* 4920 */
2150 ah->ah_capabilities.cap_range.range_5ghz_max = 6100;
2152 /* Set supported modes */
2153 __set_bit(AR5K_MODE_11A,
2154 ah->ah_capabilities.cap_mode);
2155 __set_bit(AR5K_MODE_11A_TURBO,
2156 ah->ah_capabilities.cap_mode);
2157 if (ah->ah_version == AR5K_AR5212)
2158 __set_bit(AR5K_MODE_11G_TURBO,
2159 ah->ah_capabilities.cap_mode);
2162 /* Enable 802.11b if a 2GHz capable radio (2111/5112) is
2163 * connected */
2164 if (AR5K_EEPROM_HDR_11B(ee_header) ||
2165 AR5K_EEPROM_HDR_11G(ee_header)) {
2166 ah->ah_capabilities.cap_range.range_2ghz_min = 2412; /* 2312 */
2167 ah->ah_capabilities.cap_range.range_2ghz_max = 2732;
2169 if (AR5K_EEPROM_HDR_11B(ee_header))
2170 __set_bit(AR5K_MODE_11B,
2171 ah->ah_capabilities.cap_mode);
2173 if (AR5K_EEPROM_HDR_11G(ee_header))
2174 __set_bit(AR5K_MODE_11G,
2175 ah->ah_capabilities.cap_mode);
2179 /* GPIO */
2180 ah->ah_gpio_npins = AR5K_NUM_GPIO;
2182 /* Set number of supported TX queues */
2183 if (ah->ah_version == AR5K_AR5210)
2184 ah->ah_capabilities.cap_queues.q_tx_num =
2185 AR5K_NUM_TX_QUEUES_NOQCU;
2186 else
2187 ah->ah_capabilities.cap_queues.q_tx_num = AR5K_NUM_TX_QUEUES;
2189 return 0;
2192 /*********************************\
2193 Protocol Control Unit Functions
2194 \*********************************/
2197 * Set Operation mode
2199 int ath5k_hw_set_opmode(struct ath5k_hw *ah)
2201 u32 pcu_reg, beacon_reg, low_id, high_id;
2203 pcu_reg = 0;
2204 beacon_reg = 0;
2206 ATH5K_TRACE(ah->ah_sc);
2208 switch (ah->ah_op_mode) {
2209 case IEEE80211_IF_TYPE_IBSS:
2210 pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_DESC_ANTENNA |
2211 (ah->ah_version == AR5K_AR5210 ?
2212 AR5K_STA_ID1_NO_PSPOLL : 0);
2213 beacon_reg |= AR5K_BCR_ADHOC;
2214 break;
2216 case IEEE80211_IF_TYPE_AP:
2217 pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_RTS_DEF_ANTENNA |
2218 (ah->ah_version == AR5K_AR5210 ?
2219 AR5K_STA_ID1_NO_PSPOLL : 0);
2220 beacon_reg |= AR5K_BCR_AP;
2221 break;
2223 case IEEE80211_IF_TYPE_STA:
2224 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2225 (ah->ah_version == AR5K_AR5210 ?
2226 AR5K_STA_ID1_PWR_SV : 0);
2227 case IEEE80211_IF_TYPE_MNTR:
2228 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2229 (ah->ah_version == AR5K_AR5210 ?
2230 AR5K_STA_ID1_NO_PSPOLL : 0);
2231 break;
2233 default:
2234 return -EINVAL;
2238 * Set PCU registers
2240 low_id = AR5K_LOW_ID(ah->ah_sta_id);
2241 high_id = AR5K_HIGH_ID(ah->ah_sta_id);
2242 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2243 ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
2246 * Set Beacon Control Register on 5210
2248 if (ah->ah_version == AR5K_AR5210)
2249 ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR);
2251 return 0;
2255 * BSSID Functions
2259 * Get station id
2261 void ath5k_hw_get_lladdr(struct ath5k_hw *ah, u8 *mac)
2263 ATH5K_TRACE(ah->ah_sc);
2264 memcpy(mac, ah->ah_sta_id, ETH_ALEN);
2268 * Set station id
2270 int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
2272 u32 low_id, high_id;
2274 ATH5K_TRACE(ah->ah_sc);
2275 /* Set new station ID */
2276 memcpy(ah->ah_sta_id, mac, ETH_ALEN);
2278 low_id = AR5K_LOW_ID(mac);
2279 high_id = AR5K_HIGH_ID(mac);
2281 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2282 ath5k_hw_reg_write(ah, high_id, AR5K_STA_ID1);
2284 return 0;
2288 * Set BSSID
2290 void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id)
2292 u32 low_id, high_id;
2293 u16 tim_offset = 0;
2296 * Set simple BSSID mask on 5212
2298 if (ah->ah_version == AR5K_AR5212) {
2299 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM0);
2300 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM1);
2304 * Set BSSID which triggers the "SME Join" operation
2306 low_id = AR5K_LOW_ID(bssid);
2307 high_id = AR5K_HIGH_ID(bssid);
2308 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_ID0);
2309 ath5k_hw_reg_write(ah, high_id | ((assoc_id & 0x3fff) <<
2310 AR5K_BSS_ID1_AID_S), AR5K_BSS_ID1);
2312 if (assoc_id == 0) {
2313 ath5k_hw_disable_pspoll(ah);
2314 return;
2317 AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM,
2318 tim_offset ? tim_offset + 4 : 0);
2320 ath5k_hw_enable_pspoll(ah, NULL, 0);
2323 * ath5k_hw_set_bssid_mask - set common bits we should listen to
2325 * The bssid_mask is a utility used by AR5212 hardware to inform the hardware
2326 * which bits of the interface's MAC address should be looked at when trying
2327 * to decide which packets to ACK. In station mode every bit matters. In AP
2328 * mode with a single BSS every bit matters as well. In AP mode with
2329 * multiple BSSes not every bit matters.
2331 * @ah: the &struct ath5k_hw
2332 * @mask: the bssid_mask, a u8 array of size ETH_ALEN
2334 * Note that this is a simple filter and *does* not filter out all
2335 * relevant frames. Some non-relevant frames will get through, probability
2336 * jocks are welcomed to compute.
2338 * When handling multiple BSSes (or VAPs) you can get the BSSID mask by
2339 * computing the set of:
2341 * ~ ( MAC XOR BSSID )
2343 * When you do this you are essentially computing the common bits. Later it
2344 * is assumed the harware will "and" (&) the BSSID mask with the MAC address
2345 * to obtain the relevant bits which should match on the destination frame.
2347 * Simple example: on your card you have have two BSSes you have created with
2348 * BSSID-01 and BSSID-02. Lets assume BSSID-01 will not use the MAC address.
2349 * There is another BSSID-03 but you are not part of it. For simplicity's sake,
2350 * assuming only 4 bits for a mac address and for BSSIDs you can then have:
2353 * MAC: 0001 |
2354 * BSSID-01: 0100 | --> Belongs to us
2355 * BSSID-02: 1001 |
2357 * -------------------
2358 * BSSID-03: 0110 | --> External
2359 * -------------------
2361 * Our bssid_mask would then be:
2363 * On loop iteration for BSSID-01:
2364 * ~(0001 ^ 0100) -> ~(0101)
2365 * -> 1010
2366 * bssid_mask = 1010
2368 * On loop iteration for BSSID-02:
2369 * bssid_mask &= ~(0001 ^ 1001)
2370 * bssid_mask = (1010) & ~(0001 ^ 1001)
2371 * bssid_mask = (1010) & ~(1001)
2372 * bssid_mask = (1010) & (0110)
2373 * bssid_mask = 0010
2375 * A bssid_mask of 0010 means "only pay attention to the second least
2376 * significant bit". This is because its the only bit common
2377 * amongst the MAC and all BSSIDs we support. To findout what the real
2378 * common bit is we can simply "&" the bssid_mask now with any BSSID we have
2379 * or our MAC address (we assume the hardware uses the MAC address).
2381 * Now, suppose there's an incoming frame for BSSID-03:
2383 * IFRAME-01: 0110
2385 * An easy eye-inspeciton of this already should tell you that this frame
2386 * will not pass our check. This is beacuse the bssid_mask tells the
2387 * hardware to only look at the second least significant bit and the
2388 * common bit amongst the MAC and BSSIDs is 0, this frame has the 2nd LSB
2389 * as 1, which does not match 0.
2391 * So with IFRAME-01 we *assume* the hardware will do:
2393 * allow = (IFRAME-01 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2394 * --> allow = (0110 & 0010) == (0010 & 0001) ? 1 : 0;
2395 * --> allow = (0010) == 0000 ? 1 : 0;
2396 * --> allow = 0
2398 * Lets now test a frame that should work:
2400 * IFRAME-02: 0001 (we should allow)
2402 * allow = (0001 & 1010) == 1010
2404 * allow = (IFRAME-02 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2405 * --> allow = (0001 & 0010) == (0010 & 0001) ? 1 :0;
2406 * --> allow = (0010) == (0010)
2407 * --> allow = 1
2409 * Other examples:
2411 * IFRAME-03: 0100 --> allowed
2412 * IFRAME-04: 1001 --> allowed
2413 * IFRAME-05: 1101 --> allowed but its not for us!!!
2416 int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
2418 u32 low_id, high_id;
2419 ATH5K_TRACE(ah->ah_sc);
2421 if (ah->ah_version == AR5K_AR5212) {
2422 low_id = AR5K_LOW_ID(mask);
2423 high_id = AR5K_HIGH_ID(mask);
2425 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_IDM0);
2426 ath5k_hw_reg_write(ah, high_id, AR5K_BSS_IDM1);
2428 return 0;
2431 return -EIO;
2435 * Receive start/stop functions
2439 * Start receive on PCU
2441 void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
2443 ATH5K_TRACE(ah->ah_sc);
2444 AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
2446 /* TODO: ANI Support */
2450 * Stop receive on PCU
2452 void ath5k_hw_stop_pcu_recv(struct ath5k_hw *ah)
2454 ATH5K_TRACE(ah->ah_sc);
2455 AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
2457 /* TODO: ANI Support */
2461 * RX Filter functions
2465 * Set multicast filter
2467 void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
2469 ATH5K_TRACE(ah->ah_sc);
2470 /* Set the multicat filter */
2471 ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0);
2472 ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1);
2476 * Set multicast filter by index
2478 int ath5k_hw_set_mcast_filterindex(struct ath5k_hw *ah, u32 index)
2481 ATH5K_TRACE(ah->ah_sc);
2482 if (index >= 64)
2483 return -EINVAL;
2484 else if (index >= 32)
2485 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER1,
2486 (1 << (index - 32)));
2487 else
2488 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2490 return 0;
2494 * Clear Multicast filter by index
2496 int ath5k_hw_clear_mcast_filter_idx(struct ath5k_hw *ah, u32 index)
2499 ATH5K_TRACE(ah->ah_sc);
2500 if (index >= 64)
2501 return -EINVAL;
2502 else if (index >= 32)
2503 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER1,
2504 (1 << (index - 32)));
2505 else
2506 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2508 return 0;
2512 * Get current rx filter
2514 u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah)
2516 u32 data, filter = 0;
2518 ATH5K_TRACE(ah->ah_sc);
2519 filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER);
2521 /*Radar detection for 5212*/
2522 if (ah->ah_version == AR5K_AR5212) {
2523 data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL);
2525 if (data & AR5K_PHY_ERR_FIL_RADAR)
2526 filter |= AR5K_RX_FILTER_RADARERR;
2527 if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK))
2528 filter |= AR5K_RX_FILTER_PHYERR;
2531 return filter;
2535 * Set rx filter
2537 void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
2539 u32 data = 0;
2541 ATH5K_TRACE(ah->ah_sc);
2543 /* Set PHY error filter register on 5212*/
2544 if (ah->ah_version == AR5K_AR5212) {
2545 if (filter & AR5K_RX_FILTER_RADARERR)
2546 data |= AR5K_PHY_ERR_FIL_RADAR;
2547 if (filter & AR5K_RX_FILTER_PHYERR)
2548 data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK;
2552 * The AR5210 uses promiscous mode to detect radar activity
2554 if (ah->ah_version == AR5K_AR5210 &&
2555 (filter & AR5K_RX_FILTER_RADARERR)) {
2556 filter &= ~AR5K_RX_FILTER_RADARERR;
2557 filter |= AR5K_RX_FILTER_PROM;
2560 /*Zero length DMA*/
2561 if (data)
2562 AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2563 else
2564 AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2566 /*Write RX Filter register*/
2567 ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER);
2569 /*Write PHY error filter register on 5212*/
2570 if (ah->ah_version == AR5K_AR5212)
2571 ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
2576 * Beacon related functions
2580 * Get a 32bit TSF
2582 u32 ath5k_hw_get_tsf32(struct ath5k_hw *ah)
2584 ATH5K_TRACE(ah->ah_sc);
2585 return ath5k_hw_reg_read(ah, AR5K_TSF_L32);
2589 * Get the full 64bit TSF
2591 u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah)
2593 u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
2594 ATH5K_TRACE(ah->ah_sc);
2596 return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32);
2600 * Force a TSF reset
2602 void ath5k_hw_reset_tsf(struct ath5k_hw *ah)
2604 ATH5K_TRACE(ah->ah_sc);
2605 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_RESET_TSF);
2609 * Initialize beacon timers
2611 void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
2613 u32 timer1, timer2, timer3;
2615 ATH5K_TRACE(ah->ah_sc);
2617 * Set the additional timers by mode
2619 switch (ah->ah_op_mode) {
2620 case IEEE80211_IF_TYPE_STA:
2621 if (ah->ah_version == AR5K_AR5210) {
2622 timer1 = 0xffffffff;
2623 timer2 = 0xffffffff;
2624 } else {
2625 timer1 = 0x0000ffff;
2626 timer2 = 0x0007ffff;
2628 break;
2630 default:
2631 timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3;
2632 timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3;
2635 timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1);
2638 * Set the beacon register and enable all timers.
2639 * (next beacon, DMA beacon, software beacon, ATIM window time)
2641 ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
2642 ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
2643 ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
2644 ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
2646 ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD |
2647 AR5K_BEACON_RESET_TSF | AR5K_BEACON_ENABLE),
2648 AR5K_BEACON);
2651 #if 0
2653 * Set beacon timers
2655 int ath5k_hw_set_beacon_timers(struct ath5k_hw *ah,
2656 const struct ath5k_beacon_state *state)
2658 u32 cfp_period, next_cfp, dtim, interval, next_beacon;
2661 * TODO: should be changed through *state
2662 * review struct ath5k_beacon_state struct
2664 * XXX: These are used for cfp period bellow, are they
2665 * ok ? Is it O.K. for tsf here to be 0 or should we use
2666 * get_tsf ?
2668 u32 dtim_count = 0; /* XXX */
2669 u32 cfp_count = 0; /* XXX */
2670 u32 tsf = 0; /* XXX */
2672 ATH5K_TRACE(ah->ah_sc);
2673 /* Return on an invalid beacon state */
2674 if (state->bs_interval < 1)
2675 return -EINVAL;
2677 interval = state->bs_interval;
2678 dtim = state->bs_dtim_period;
2681 * PCF support?
2683 if (state->bs_cfp_period > 0) {
2685 * Enable PCF mode and set the CFP
2686 * (Contention Free Period) and timer registers
2688 cfp_period = state->bs_cfp_period * state->bs_dtim_period *
2689 state->bs_interval;
2690 next_cfp = (cfp_count * state->bs_dtim_period + dtim_count) *
2691 state->bs_interval;
2693 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
2694 AR5K_STA_ID1_DEFAULT_ANTENNA |
2695 AR5K_STA_ID1_PCF);
2696 ath5k_hw_reg_write(ah, cfp_period, AR5K_CFP_PERIOD);
2697 ath5k_hw_reg_write(ah, state->bs_cfp_max_duration,
2698 AR5K_CFP_DUR);
2699 ath5k_hw_reg_write(ah, (tsf + (next_cfp == 0 ? cfp_period :
2700 next_cfp)) << 3, AR5K_TIMER2);
2701 } else {
2702 /* Disable PCF mode */
2703 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2704 AR5K_STA_ID1_DEFAULT_ANTENNA |
2705 AR5K_STA_ID1_PCF);
2709 * Enable the beacon timer register
2711 ath5k_hw_reg_write(ah, state->bs_next_beacon, AR5K_TIMER0);
2714 * Start the beacon timers
2716 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_BEACON) &~
2717 (AR5K_BEACON_PERIOD | AR5K_BEACON_TIM)) |
2718 AR5K_REG_SM(state->bs_tim_offset ? state->bs_tim_offset + 4 : 0,
2719 AR5K_BEACON_TIM) | AR5K_REG_SM(state->bs_interval,
2720 AR5K_BEACON_PERIOD), AR5K_BEACON);
2723 * Write new beacon miss threshold, if it appears to be valid
2724 * XXX: Figure out right values for min <= bs_bmiss_threshold <= max
2725 * and return if its not in range. We can test this by reading value and
2726 * setting value to a largest value and seeing which values register.
2729 AR5K_REG_WRITE_BITS(ah, AR5K_RSSI_THR, AR5K_RSSI_THR_BMISS,
2730 state->bs_bmiss_threshold);
2733 * Set sleep control register
2734 * XXX: Didn't find this in 5210 code but since this register
2735 * exists also in ar5k's 5210 headers i leave it as common code.
2737 AR5K_REG_WRITE_BITS(ah, AR5K_SLEEP_CTL, AR5K_SLEEP_CTL_SLDUR,
2738 (state->bs_sleep_duration - 3) << 3);
2741 * Set enhanced sleep registers on 5212
2743 if (ah->ah_version == AR5K_AR5212) {
2744 if (state->bs_sleep_duration > state->bs_interval &&
2745 roundup(state->bs_sleep_duration, interval) ==
2746 state->bs_sleep_duration)
2747 interval = state->bs_sleep_duration;
2749 if (state->bs_sleep_duration > dtim && (dtim == 0 ||
2750 roundup(state->bs_sleep_duration, dtim) ==
2751 state->bs_sleep_duration))
2752 dtim = state->bs_sleep_duration;
2754 if (interval > dtim)
2755 return -EINVAL;
2757 next_beacon = interval == dtim ? state->bs_next_dtim :
2758 state->bs_next_beacon;
2760 ath5k_hw_reg_write(ah,
2761 AR5K_REG_SM((state->bs_next_dtim - 3) << 3,
2762 AR5K_SLEEP0_NEXT_DTIM) |
2763 AR5K_REG_SM(10, AR5K_SLEEP0_CABTO) |
2764 AR5K_SLEEP0_ENH_SLEEP_EN |
2765 AR5K_SLEEP0_ASSUME_DTIM, AR5K_SLEEP0);
2767 ath5k_hw_reg_write(ah, AR5K_REG_SM((next_beacon - 3) << 3,
2768 AR5K_SLEEP1_NEXT_TIM) |
2769 AR5K_REG_SM(10, AR5K_SLEEP1_BEACON_TO), AR5K_SLEEP1);
2771 ath5k_hw_reg_write(ah,
2772 AR5K_REG_SM(interval, AR5K_SLEEP2_TIM_PER) |
2773 AR5K_REG_SM(dtim, AR5K_SLEEP2_DTIM_PER), AR5K_SLEEP2);
2776 return 0;
2780 * Reset beacon timers
2782 void ath5k_hw_reset_beacon(struct ath5k_hw *ah)
2784 ATH5K_TRACE(ah->ah_sc);
2786 * Disable beacon timer
2788 ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
2791 * Disable some beacon register values
2793 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2794 AR5K_STA_ID1_DEFAULT_ANTENNA | AR5K_STA_ID1_PCF);
2795 ath5k_hw_reg_write(ah, AR5K_BEACON_PERIOD, AR5K_BEACON);
2799 * Wait for beacon queue to finish
2801 int ath5k_hw_beaconq_finish(struct ath5k_hw *ah, unsigned long phys_addr)
2803 unsigned int i;
2804 int ret;
2806 ATH5K_TRACE(ah->ah_sc);
2808 /* 5210 doesn't have QCU*/
2809 if (ah->ah_version == AR5K_AR5210) {
2811 * Wait for beaconn queue to finish by checking
2812 * Control Register and Beacon Status Register.
2814 for (i = AR5K_TUNE_BEACON_INTERVAL / 2; i > 0; i--) {
2815 if (!(ath5k_hw_reg_read(ah, AR5K_BSR) & AR5K_BSR_TXQ1F)
2817 !(ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_BSR_TXQ1F))
2818 break;
2819 udelay(10);
2822 /* Timeout... */
2823 if (i <= 0) {
2825 * Re-schedule the beacon queue
2827 ath5k_hw_reg_write(ah, phys_addr, AR5K_NOQCU_TXDP1);
2828 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
2829 AR5K_BCR);
2831 return -EIO;
2833 ret = 0;
2834 } else {
2835 /*5211/5212*/
2836 ret = ath5k_hw_register_timeout(ah,
2837 AR5K_QUEUE_STATUS(AR5K_TX_QUEUE_ID_BEACON),
2838 AR5K_QCU_STS_FRMPENDCNT, 0, false);
2840 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, AR5K_TX_QUEUE_ID_BEACON))
2841 return -EIO;
2844 return ret;
2846 #endif
2849 * Update mib counters (statistics)
2851 void ath5k_hw_update_mib_counters(struct ath5k_hw *ah,
2852 struct ath5k_mib_stats *statistics)
2854 ATH5K_TRACE(ah->ah_sc);
2855 /* Read-And-Clear */
2856 statistics->ackrcv_bad += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL);
2857 statistics->rts_bad += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL);
2858 statistics->rts_good += ath5k_hw_reg_read(ah, AR5K_RTS_OK);
2859 statistics->fcs_bad += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL);
2860 statistics->beacons += ath5k_hw_reg_read(ah, AR5K_BEACON_CNT);
2862 /* Reset profile count registers on 5212*/
2863 if (ah->ah_version == AR5K_AR5212) {
2864 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_TX);
2865 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RX);
2866 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR);
2867 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE);
2871 /** ath5k_hw_set_ack_bitrate - set bitrate for ACKs
2873 * @ah: the &struct ath5k_hw
2874 * @high: determines if to use low bit rate or now
2876 void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high)
2878 if (ah->ah_version != AR5K_AR5212)
2879 return;
2880 else {
2881 u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB;
2882 if (high)
2883 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val);
2884 else
2885 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val);
2891 * ACK/CTS Timeouts
2895 * Set ACK timeout on PCU
2897 int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout)
2899 ATH5K_TRACE(ah->ah_sc);
2900 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK),
2901 ah->ah_turbo) <= timeout)
2902 return -EINVAL;
2904 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK,
2905 ath5k_hw_htoclock(timeout, ah->ah_turbo));
2907 return 0;
2911 * Read the ACK timeout from PCU
2913 unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah)
2915 ATH5K_TRACE(ah->ah_sc);
2917 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
2918 AR5K_TIME_OUT), AR5K_TIME_OUT_ACK), ah->ah_turbo);
2922 * Set CTS timeout on PCU
2924 int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout)
2926 ATH5K_TRACE(ah->ah_sc);
2927 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS),
2928 ah->ah_turbo) <= timeout)
2929 return -EINVAL;
2931 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS,
2932 ath5k_hw_htoclock(timeout, ah->ah_turbo));
2934 return 0;
2938 * Read CTS timeout from PCU
2940 unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah)
2942 ATH5K_TRACE(ah->ah_sc);
2943 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
2944 AR5K_TIME_OUT), AR5K_TIME_OUT_CTS), ah->ah_turbo);
2948 * Key table (WEP) functions
2951 int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
2953 unsigned int i;
2955 ATH5K_TRACE(ah->ah_sc);
2956 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
2958 for (i = 0; i < AR5K_KEYCACHE_SIZE; i++)
2959 ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i));
2961 /* Set NULL encryption on non-5210*/
2962 if (ah->ah_version != AR5K_AR5210)
2963 ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
2964 AR5K_KEYTABLE_TYPE(entry));
2966 return 0;
2969 int ath5k_hw_is_key_valid(struct ath5k_hw *ah, u16 entry)
2971 ATH5K_TRACE(ah->ah_sc);
2972 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
2974 /* Check the validation flag at the end of the entry */
2975 return ath5k_hw_reg_read(ah, AR5K_KEYTABLE_MAC1(entry)) &
2976 AR5K_KEYTABLE_VALID;
2979 int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
2980 const struct ieee80211_key_conf *key, const u8 *mac)
2982 unsigned int i;
2983 __le32 key_v[5] = {};
2984 u32 keytype;
2986 ATH5K_TRACE(ah->ah_sc);
2988 /* key->keylen comes in from mac80211 in bytes */
2990 if (key->keylen > AR5K_KEYTABLE_SIZE / 8)
2991 return -EOPNOTSUPP;
2993 switch (key->keylen) {
2994 /* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit */
2995 case 40 / 8:
2996 memcpy(&key_v[0], key->key, 5);
2997 keytype = AR5K_KEYTABLE_TYPE_40;
2998 break;
3000 /* WEP 104-bit = 104-bit entered key + 24-bit IV = 128-bit */
3001 case 104 / 8:
3002 memcpy(&key_v[0], &key->key[0], 6);
3003 memcpy(&key_v[2], &key->key[6], 6);
3004 memcpy(&key_v[4], &key->key[12], 1);
3005 keytype = AR5K_KEYTABLE_TYPE_104;
3006 break;
3007 /* WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit */
3008 case 128 / 8:
3009 memcpy(&key_v[0], &key->key[0], 6);
3010 memcpy(&key_v[2], &key->key[6], 6);
3011 memcpy(&key_v[4], &key->key[12], 4);
3012 keytype = AR5K_KEYTABLE_TYPE_128;
3013 break;
3015 default:
3016 return -EINVAL; /* shouldn't happen */
3019 for (i = 0; i < ARRAY_SIZE(key_v); i++)
3020 ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
3021 AR5K_KEYTABLE_OFF(entry, i));
3023 ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry));
3025 return ath5k_hw_set_key_lladdr(ah, entry, mac);
3028 int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac)
3030 u32 low_id, high_id;
3032 ATH5K_TRACE(ah->ah_sc);
3033 /* Invalid entry (key table overflow) */
3034 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3036 /* MAC may be NULL if it's a broadcast key. In this case no need to
3037 * to compute AR5K_LOW_ID and AR5K_HIGH_ID as we already know it. */
3038 if (unlikely(mac == NULL)) {
3039 low_id = 0xffffffff;
3040 high_id = 0xffff | AR5K_KEYTABLE_VALID;
3041 } else {
3042 low_id = AR5K_LOW_ID(mac);
3043 high_id = AR5K_HIGH_ID(mac) | AR5K_KEYTABLE_VALID;
3046 ath5k_hw_reg_write(ah, low_id, AR5K_KEYTABLE_MAC0(entry));
3047 ath5k_hw_reg_write(ah, high_id, AR5K_KEYTABLE_MAC1(entry));
3049 return 0;
3053 /********************************************\
3054 Queue Control Unit, DFS Control Unit Functions
3055 \********************************************/
3058 * Initialize a transmit queue
3060 int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type,
3061 struct ath5k_txq_info *queue_info)
3063 unsigned int queue;
3064 int ret;
3066 ATH5K_TRACE(ah->ah_sc);
3069 * Get queue by type
3071 /*5210 only has 2 queues*/
3072 if (ah->ah_version == AR5K_AR5210) {
3073 switch (queue_type) {
3074 case AR5K_TX_QUEUE_DATA:
3075 queue = AR5K_TX_QUEUE_ID_NOQCU_DATA;
3076 break;
3077 case AR5K_TX_QUEUE_BEACON:
3078 case AR5K_TX_QUEUE_CAB:
3079 queue = AR5K_TX_QUEUE_ID_NOQCU_BEACON;
3080 break;
3081 default:
3082 return -EINVAL;
3084 } else {
3085 switch (queue_type) {
3086 case AR5K_TX_QUEUE_DATA:
3087 for (queue = AR5K_TX_QUEUE_ID_DATA_MIN;
3088 ah->ah_txq[queue].tqi_type !=
3089 AR5K_TX_QUEUE_INACTIVE; queue++) {
3091 if (queue > AR5K_TX_QUEUE_ID_DATA_MAX)
3092 return -EINVAL;
3094 break;
3095 case AR5K_TX_QUEUE_UAPSD:
3096 queue = AR5K_TX_QUEUE_ID_UAPSD;
3097 break;
3098 case AR5K_TX_QUEUE_BEACON:
3099 queue = AR5K_TX_QUEUE_ID_BEACON;
3100 break;
3101 case AR5K_TX_QUEUE_CAB:
3102 queue = AR5K_TX_QUEUE_ID_CAB;
3103 break;
3104 case AR5K_TX_QUEUE_XR_DATA:
3105 if (ah->ah_version != AR5K_AR5212)
3106 ATH5K_ERR(ah->ah_sc,
3107 "XR data queues only supported in"
3108 " 5212!\n");
3109 queue = AR5K_TX_QUEUE_ID_XR_DATA;
3110 break;
3111 default:
3112 return -EINVAL;
3117 * Setup internal queue structure
3119 memset(&ah->ah_txq[queue], 0, sizeof(struct ath5k_txq_info));
3120 ah->ah_txq[queue].tqi_type = queue_type;
3122 if (queue_info != NULL) {
3123 queue_info->tqi_type = queue_type;
3124 ret = ath5k_hw_setup_tx_queueprops(ah, queue, queue_info);
3125 if (ret)
3126 return ret;
3129 * We use ah_txq_status to hold a temp value for
3130 * the Secondary interrupt mask registers on 5211+
3131 * check out ath5k_hw_reset_tx_queue
3133 AR5K_Q_ENABLE_BITS(ah->ah_txq_status, queue);
3135 return queue;
3139 * Setup a transmit queue
3141 int ath5k_hw_setup_tx_queueprops(struct ath5k_hw *ah, int queue,
3142 const struct ath5k_txq_info *queue_info)
3144 ATH5K_TRACE(ah->ah_sc);
3145 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3147 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3148 return -EIO;
3150 memcpy(&ah->ah_txq[queue], queue_info, sizeof(struct ath5k_txq_info));
3152 /*XXX: Is this supported on 5210 ?*/
3153 if ((queue_info->tqi_type == AR5K_TX_QUEUE_DATA &&
3154 ((queue_info->tqi_subtype == AR5K_WME_AC_VI) ||
3155 (queue_info->tqi_subtype == AR5K_WME_AC_VO))) ||
3156 queue_info->tqi_type == AR5K_TX_QUEUE_UAPSD)
3157 ah->ah_txq[queue].tqi_flags |= AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
3159 return 0;
3163 * Get properties for a specific transmit queue
3165 int ath5k_hw_get_tx_queueprops(struct ath5k_hw *ah, int queue,
3166 struct ath5k_txq_info *queue_info)
3168 ATH5K_TRACE(ah->ah_sc);
3169 memcpy(queue_info, &ah->ah_txq[queue], sizeof(struct ath5k_txq_info));
3170 return 0;
3174 * Set a transmit queue inactive
3176 void ath5k_hw_release_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3178 ATH5K_TRACE(ah->ah_sc);
3179 if (WARN_ON(queue >= ah->ah_capabilities.cap_queues.q_tx_num))
3180 return;
3182 /* This queue will be skipped in further operations */
3183 ah->ah_txq[queue].tqi_type = AR5K_TX_QUEUE_INACTIVE;
3184 /*For SIMR setup*/
3185 AR5K_Q_DISABLE_BITS(ah->ah_txq_status, queue);
3189 * Set DFS params for a transmit queue
3191 int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3193 u32 cw_min, cw_max, retry_lg, retry_sh;
3194 struct ath5k_txq_info *tq = &ah->ah_txq[queue];
3196 ATH5K_TRACE(ah->ah_sc);
3197 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3199 tq = &ah->ah_txq[queue];
3201 if (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE)
3202 return 0;
3204 if (ah->ah_version == AR5K_AR5210) {
3205 /* Only handle data queues, others will be ignored */
3206 if (tq->tqi_type != AR5K_TX_QUEUE_DATA)
3207 return 0;
3209 /* Set Slot time */
3210 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3211 AR5K_INIT_SLOT_TIME_TURBO : AR5K_INIT_SLOT_TIME,
3212 AR5K_SLOT_TIME);
3213 /* Set ACK_CTS timeout */
3214 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3215 AR5K_INIT_ACK_CTS_TIMEOUT_TURBO :
3216 AR5K_INIT_ACK_CTS_TIMEOUT, AR5K_SLOT_TIME);
3217 /* Set Transmit Latency */
3218 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3219 AR5K_INIT_TRANSMIT_LATENCY_TURBO :
3220 AR5K_INIT_TRANSMIT_LATENCY, AR5K_USEC_5210);
3221 /* Set IFS0 */
3222 if (ah->ah_turbo)
3223 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS_TURBO +
3224 (ah->ah_aifs + tq->tqi_aifs) *
3225 AR5K_INIT_SLOT_TIME_TURBO) <<
3226 AR5K_IFS0_DIFS_S) | AR5K_INIT_SIFS_TURBO,
3227 AR5K_IFS0);
3228 else
3229 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS +
3230 (ah->ah_aifs + tq->tqi_aifs) *
3231 AR5K_INIT_SLOT_TIME) << AR5K_IFS0_DIFS_S) |
3232 AR5K_INIT_SIFS, AR5K_IFS0);
3234 /* Set IFS1 */
3235 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3236 AR5K_INIT_PROTO_TIME_CNTRL_TURBO :
3237 AR5K_INIT_PROTO_TIME_CNTRL, AR5K_IFS1);
3238 /* Set PHY register 0x9844 (??) */
3239 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3240 (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x38 :
3241 (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x1C,
3242 AR5K_PHY(17));
3243 /* Set Frame Control Register */
3244 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3245 (AR5K_PHY_FRAME_CTL_INI | AR5K_PHY_TURBO_MODE |
3246 AR5K_PHY_TURBO_SHORT | 0x2020) :
3247 (AR5K_PHY_FRAME_CTL_INI | 0x1020),
3248 AR5K_PHY_FRAME_CTL_5210);
3252 * Calculate cwmin/max by channel mode
3254 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN;
3255 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX;
3256 ah->ah_aifs = AR5K_TUNE_AIFS;
3257 /*XR is only supported on 5212*/
3258 if (IS_CHAN_XR(ah->ah_current_channel) &&
3259 ah->ah_version == AR5K_AR5212) {
3260 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_XR;
3261 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_XR;
3262 ah->ah_aifs = AR5K_TUNE_AIFS_XR;
3263 /*B mode is not supported on 5210*/
3264 } else if (IS_CHAN_B(ah->ah_current_channel) &&
3265 ah->ah_version != AR5K_AR5210) {
3266 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_11B;
3267 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_11B;
3268 ah->ah_aifs = AR5K_TUNE_AIFS_11B;
3271 cw_min = 1;
3272 while (cw_min < ah->ah_cw_min)
3273 cw_min = (cw_min << 1) | 1;
3275 cw_min = tq->tqi_cw_min < 0 ? (cw_min >> (-tq->tqi_cw_min)) :
3276 ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
3277 cw_max = tq->tqi_cw_max < 0 ? (cw_max >> (-tq->tqi_cw_max)) :
3278 ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
3281 * Calculate and set retry limits
3283 if (ah->ah_software_retry) {
3284 /* XXX Need to test this */
3285 retry_lg = ah->ah_limit_tx_retries;
3286 retry_sh = retry_lg = retry_lg > AR5K_DCU_RETRY_LMT_SH_RETRY ?
3287 AR5K_DCU_RETRY_LMT_SH_RETRY : retry_lg;
3288 } else {
3289 retry_lg = AR5K_INIT_LG_RETRY;
3290 retry_sh = AR5K_INIT_SH_RETRY;
3293 /*No QCU/DCU [5210]*/
3294 if (ah->ah_version == AR5K_AR5210) {
3295 ath5k_hw_reg_write(ah,
3296 (cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
3297 | AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3298 AR5K_NODCU_RETRY_LMT_SLG_RETRY)
3299 | AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3300 AR5K_NODCU_RETRY_LMT_SSH_RETRY)
3301 | AR5K_REG_SM(retry_lg, AR5K_NODCU_RETRY_LMT_LG_RETRY)
3302 | AR5K_REG_SM(retry_sh, AR5K_NODCU_RETRY_LMT_SH_RETRY),
3303 AR5K_NODCU_RETRY_LMT);
3304 } else {
3305 /*QCU/DCU [5211+]*/
3306 ath5k_hw_reg_write(ah,
3307 AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3308 AR5K_DCU_RETRY_LMT_SLG_RETRY) |
3309 AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3310 AR5K_DCU_RETRY_LMT_SSH_RETRY) |
3311 AR5K_REG_SM(retry_lg, AR5K_DCU_RETRY_LMT_LG_RETRY) |
3312 AR5K_REG_SM(retry_sh, AR5K_DCU_RETRY_LMT_SH_RETRY),
3313 AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
3315 /*===Rest is also for QCU/DCU only [5211+]===*/
3318 * Set initial content window (cw_min/cw_max)
3319 * and arbitrated interframe space (aifs)...
3321 ath5k_hw_reg_write(ah,
3322 AR5K_REG_SM(cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
3323 AR5K_REG_SM(cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
3324 AR5K_REG_SM(ah->ah_aifs + tq->tqi_aifs,
3325 AR5K_DCU_LCL_IFS_AIFS),
3326 AR5K_QUEUE_DFS_LOCAL_IFS(queue));
3329 * Set misc registers
3331 ath5k_hw_reg_write(ah, AR5K_QCU_MISC_DCU_EARLY,
3332 AR5K_QUEUE_MISC(queue));
3334 if (tq->tqi_cbr_period) {
3335 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
3336 AR5K_QCU_CBRCFG_INTVAL) |
3337 AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
3338 AR5K_QCU_CBRCFG_ORN_THRES),
3339 AR5K_QUEUE_CBRCFG(queue));
3340 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3341 AR5K_QCU_MISC_FRSHED_CBR);
3342 if (tq->tqi_cbr_overflow_limit)
3343 AR5K_REG_ENABLE_BITS(ah,
3344 AR5K_QUEUE_MISC(queue),
3345 AR5K_QCU_MISC_CBR_THRES_ENABLE);
3348 if (tq->tqi_ready_time)
3349 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
3350 AR5K_QCU_RDYTIMECFG_INTVAL) |
3351 AR5K_QCU_RDYTIMECFG_ENABLE,
3352 AR5K_QUEUE_RDYTIMECFG(queue));
3354 if (tq->tqi_burst_time) {
3355 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
3356 AR5K_DCU_CHAN_TIME_DUR) |
3357 AR5K_DCU_CHAN_TIME_ENABLE,
3358 AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
3360 if (tq->tqi_flags & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
3361 AR5K_REG_ENABLE_BITS(ah,
3362 AR5K_QUEUE_MISC(queue),
3363 AR5K_QCU_MISC_TXE);
3366 if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
3367 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
3368 AR5K_QUEUE_DFS_MISC(queue));
3370 if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
3371 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
3372 AR5K_QUEUE_DFS_MISC(queue));
3375 * Set registers by queue type
3377 switch (tq->tqi_type) {
3378 case AR5K_TX_QUEUE_BEACON:
3379 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3380 AR5K_QCU_MISC_FRSHED_DBA_GT |
3381 AR5K_QCU_MISC_CBREXP_BCN |
3382 AR5K_QCU_MISC_BCN_ENABLE);
3384 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3385 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3386 AR5K_DCU_MISC_ARBLOCK_CTL_S) |
3387 AR5K_DCU_MISC_POST_FR_BKOFF_DIS |
3388 AR5K_DCU_MISC_BCN_ENABLE);
3390 ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL -
3391 (AR5K_TUNE_SW_BEACON_RESP -
3392 AR5K_TUNE_DMA_BEACON_RESP) -
3393 AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF) * 1024) |
3394 AR5K_QCU_RDYTIMECFG_ENABLE,
3395 AR5K_QUEUE_RDYTIMECFG(queue));
3396 break;
3398 case AR5K_TX_QUEUE_CAB:
3399 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3400 AR5K_QCU_MISC_FRSHED_DBA_GT |
3401 AR5K_QCU_MISC_CBREXP |
3402 AR5K_QCU_MISC_CBREXP_BCN);
3404 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3405 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3406 AR5K_DCU_MISC_ARBLOCK_CTL_S));
3407 break;
3409 case AR5K_TX_QUEUE_UAPSD:
3410 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3411 AR5K_QCU_MISC_CBREXP);
3412 break;
3414 case AR5K_TX_QUEUE_DATA:
3415 default:
3416 break;
3420 * Enable interrupts for this tx queue
3421 * in the secondary interrupt mask registers
3423 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
3424 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
3426 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
3427 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
3429 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
3430 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
3432 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
3433 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
3435 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
3436 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
3439 /* Update secondary interrupt mask registers */
3440 ah->ah_txq_imr_txok &= ah->ah_txq_status;
3441 ah->ah_txq_imr_txerr &= ah->ah_txq_status;
3442 ah->ah_txq_imr_txurn &= ah->ah_txq_status;
3443 ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
3444 ah->ah_txq_imr_txeol &= ah->ah_txq_status;
3446 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
3447 AR5K_SIMR0_QCU_TXOK) |
3448 AR5K_REG_SM(ah->ah_txq_imr_txdesc,
3449 AR5K_SIMR0_QCU_TXDESC), AR5K_SIMR0);
3450 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
3451 AR5K_SIMR1_QCU_TXERR) |
3452 AR5K_REG_SM(ah->ah_txq_imr_txeol,
3453 AR5K_SIMR1_QCU_TXEOL), AR5K_SIMR1);
3454 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txurn,
3455 AR5K_SIMR2_QCU_TXURN), AR5K_SIMR2);
3458 return 0;
3462 * Get number of pending frames
3463 * for a specific queue [5211+]
3465 u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah, unsigned int queue) {
3466 ATH5K_TRACE(ah->ah_sc);
3467 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3469 /* Return if queue is declared inactive */
3470 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3471 return false;
3473 /* XXX: How about AR5K_CFG_TXCNT ? */
3474 if (ah->ah_version == AR5K_AR5210)
3475 return false;
3477 return AR5K_QUEUE_STATUS(queue) & AR5K_QCU_STS_FRMPENDCNT;
3481 * Set slot time
3483 int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time)
3485 ATH5K_TRACE(ah->ah_sc);
3486 if (slot_time < AR5K_SLOT_TIME_9 || slot_time > AR5K_SLOT_TIME_MAX)
3487 return -EINVAL;
3489 if (ah->ah_version == AR5K_AR5210)
3490 ath5k_hw_reg_write(ah, ath5k_hw_htoclock(slot_time,
3491 ah->ah_turbo), AR5K_SLOT_TIME);
3492 else
3493 ath5k_hw_reg_write(ah, slot_time, AR5K_DCU_GBL_IFS_SLOT);
3495 return 0;
3499 * Get slot time
3501 unsigned int ath5k_hw_get_slot_time(struct ath5k_hw *ah)
3503 ATH5K_TRACE(ah->ah_sc);
3504 if (ah->ah_version == AR5K_AR5210)
3505 return ath5k_hw_clocktoh(ath5k_hw_reg_read(ah,
3506 AR5K_SLOT_TIME) & 0xffff, ah->ah_turbo);
3507 else
3508 return ath5k_hw_reg_read(ah, AR5K_DCU_GBL_IFS_SLOT) & 0xffff;
3512 /******************************\
3513 Hardware Descriptor Functions
3514 \******************************/
3517 * TX Descriptor
3521 * Initialize the 2-word tx descriptor on 5210/5211
3523 static int
3524 ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3525 unsigned int pkt_len, unsigned int hdr_len, enum ath5k_pkt_type type,
3526 unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
3527 unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
3528 unsigned int rtscts_rate, unsigned int rtscts_duration)
3530 u32 frame_type;
3531 struct ath5k_hw_2w_tx_ctl *tx_ctl;
3532 unsigned int frame_len;
3534 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
3537 * Validate input
3538 * - Zero retries don't make sense.
3539 * - A zero rate will put the HW into a mode where it continously sends
3540 * noise on the channel, so it is important to avoid this.
3542 if (unlikely(tx_tries0 == 0)) {
3543 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3544 WARN_ON(1);
3545 return -EINVAL;
3547 if (unlikely(tx_rate0 == 0)) {
3548 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3549 WARN_ON(1);
3550 return -EINVAL;
3553 /* Clear descriptor */
3554 memset(&desc->ud.ds_tx5210, 0, sizeof(struct ath5k_hw_5210_tx_desc));
3556 /* Setup control descriptor */
3558 /* Verify and set frame length */
3560 /* remove padding we might have added before */
3561 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3563 if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
3564 return -EINVAL;
3566 tx_ctl->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
3568 /* Verify and set buffer length */
3570 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3571 if(type == AR5K_PKT_TYPE_BEACON)
3572 pkt_len = roundup(pkt_len, 4);
3574 if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
3575 return -EINVAL;
3577 tx_ctl->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
3580 * Verify and set header length
3581 * XXX: I only found that on 5210 code, does it work on 5211 ?
3583 if (ah->ah_version == AR5K_AR5210) {
3584 if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN)
3585 return -EINVAL;
3586 tx_ctl->tx_control_0 |=
3587 AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN);
3590 /*Diferences between 5210-5211*/
3591 if (ah->ah_version == AR5K_AR5210) {
3592 switch (type) {
3593 case AR5K_PKT_TYPE_BEACON:
3594 case AR5K_PKT_TYPE_PROBE_RESP:
3595 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
3596 case AR5K_PKT_TYPE_PIFS:
3597 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
3598 default:
3599 frame_type = type /*<< 2 ?*/;
3602 tx_ctl->tx_control_0 |=
3603 AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE) |
3604 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3605 } else {
3606 tx_ctl->tx_control_0 |=
3607 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
3608 AR5K_REG_SM(antenna_mode, AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
3609 tx_ctl->tx_control_1 |=
3610 AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE);
3612 #define _TX_FLAGS(_c, _flag) \
3613 if (flags & AR5K_TXDESC_##_flag) \
3614 tx_ctl->tx_control_##_c |= \
3615 AR5K_2W_TX_DESC_CTL##_c##_##_flag
3617 _TX_FLAGS(0, CLRDMASK);
3618 _TX_FLAGS(0, VEOL);
3619 _TX_FLAGS(0, INTREQ);
3620 _TX_FLAGS(0, RTSENA);
3621 _TX_FLAGS(1, NOACK);
3623 #undef _TX_FLAGS
3626 * WEP crap
3628 if (key_index != AR5K_TXKEYIX_INVALID) {
3629 tx_ctl->tx_control_0 |=
3630 AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3631 tx_ctl->tx_control_1 |=
3632 AR5K_REG_SM(key_index,
3633 AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3637 * RTS/CTS Duration [5210 ?]
3639 if ((ah->ah_version == AR5K_AR5210) &&
3640 (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
3641 tx_ctl->tx_control_1 |= rtscts_duration &
3642 AR5K_2W_TX_DESC_CTL1_RTS_DURATION;
3644 return 0;
3648 * Initialize the 4-word tx descriptor on 5212
3650 static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
3651 struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
3652 enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
3653 unsigned int tx_tries0, unsigned int key_index,
3654 unsigned int antenna_mode, unsigned int flags, unsigned int rtscts_rate,
3655 unsigned int rtscts_duration)
3657 struct ath5k_hw_4w_tx_ctl *tx_ctl;
3658 unsigned int frame_len;
3660 ATH5K_TRACE(ah->ah_sc);
3661 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
3664 * Validate input
3665 * - Zero retries don't make sense.
3666 * - A zero rate will put the HW into a mode where it continously sends
3667 * noise on the channel, so it is important to avoid this.
3669 if (unlikely(tx_tries0 == 0)) {
3670 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3671 WARN_ON(1);
3672 return -EINVAL;
3674 if (unlikely(tx_rate0 == 0)) {
3675 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3676 WARN_ON(1);
3677 return -EINVAL;
3680 /* Clear descriptor */
3681 memset(&desc->ud.ds_tx5212, 0, sizeof(struct ath5k_hw_5212_tx_desc));
3683 /* Setup control descriptor */
3685 /* Verify and set frame length */
3687 /* remove padding we might have added before */
3688 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3690 if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
3691 return -EINVAL;
3693 tx_ctl->tx_control_0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
3695 /* Verify and set buffer length */
3697 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3698 if(type == AR5K_PKT_TYPE_BEACON)
3699 pkt_len = roundup(pkt_len, 4);
3701 if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
3702 return -EINVAL;
3704 tx_ctl->tx_control_1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
3706 tx_ctl->tx_control_0 |=
3707 AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
3708 AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
3709 tx_ctl->tx_control_1 |= AR5K_REG_SM(type,
3710 AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
3711 tx_ctl->tx_control_2 = AR5K_REG_SM(tx_tries0 + AR5K_TUNE_HWTXTRIES,
3712 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
3713 tx_ctl->tx_control_3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
3715 #define _TX_FLAGS(_c, _flag) \
3716 if (flags & AR5K_TXDESC_##_flag) \
3717 tx_ctl->tx_control_##_c |= \
3718 AR5K_4W_TX_DESC_CTL##_c##_##_flag
3720 _TX_FLAGS(0, CLRDMASK);
3721 _TX_FLAGS(0, VEOL);
3722 _TX_FLAGS(0, INTREQ);
3723 _TX_FLAGS(0, RTSENA);
3724 _TX_FLAGS(0, CTSENA);
3725 _TX_FLAGS(1, NOACK);
3727 #undef _TX_FLAGS
3730 * WEP crap
3732 if (key_index != AR5K_TXKEYIX_INVALID) {
3733 tx_ctl->tx_control_0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3734 tx_ctl->tx_control_1 |= AR5K_REG_SM(key_index,
3735 AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3739 * RTS/CTS
3741 if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
3742 if ((flags & AR5K_TXDESC_RTSENA) &&
3743 (flags & AR5K_TXDESC_CTSENA))
3744 return -EINVAL;
3745 tx_ctl->tx_control_2 |= rtscts_duration &
3746 AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
3747 tx_ctl->tx_control_3 |= AR5K_REG_SM(rtscts_rate,
3748 AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
3751 return 0;
3755 * Initialize a 4-word multirate tx descriptor on 5212
3757 static int
3758 ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3759 unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2, u_int tx_tries2,
3760 unsigned int tx_rate3, u_int tx_tries3)
3762 struct ath5k_hw_4w_tx_ctl *tx_ctl;
3765 * Rates can be 0 as long as the retry count is 0 too.
3766 * A zero rate and nonzero retry count will put the HW into a mode where
3767 * it continously sends noise on the channel, so it is important to
3768 * avoid this.
3770 if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
3771 (tx_rate2 == 0 && tx_tries2 != 0) ||
3772 (tx_rate3 == 0 && tx_tries3 != 0))) {
3773 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3774 WARN_ON(1);
3775 return -EINVAL;
3778 if (ah->ah_version == AR5K_AR5212) {
3779 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
3781 #define _XTX_TRIES(_n) \
3782 if (tx_tries##_n) { \
3783 tx_ctl->tx_control_2 |= \
3784 AR5K_REG_SM(tx_tries##_n, \
3785 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
3786 tx_ctl->tx_control_3 |= \
3787 AR5K_REG_SM(tx_rate##_n, \
3788 AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
3791 _XTX_TRIES(1);
3792 _XTX_TRIES(2);
3793 _XTX_TRIES(3);
3795 #undef _XTX_TRIES
3797 return 1;
3800 return 0;
3804 * Proccess the tx status descriptor on 5210/5211
3806 static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
3807 struct ath5k_desc *desc, struct ath5k_tx_status *ts)
3809 struct ath5k_hw_2w_tx_ctl *tx_ctl;
3810 struct ath5k_hw_tx_status *tx_status;
3812 ATH5K_TRACE(ah->ah_sc);
3814 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
3815 tx_status = &desc->ud.ds_tx5210.tx_stat;
3817 /* No frame has been send or error */
3818 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
3819 return -EINPROGRESS;
3822 * Get descriptor status
3824 ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
3825 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
3826 ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
3827 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
3828 ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
3829 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
3830 /*TODO: ts->ts_virtcol + test*/
3831 ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
3832 AR5K_DESC_TX_STATUS1_SEQ_NUM);
3833 ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
3834 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
3835 ts->ts_antenna = 1;
3836 ts->ts_status = 0;
3837 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_0,
3838 AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3840 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
3841 if (tx_status->tx_status_0 &
3842 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
3843 ts->ts_status |= AR5K_TXERR_XRETRY;
3845 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
3846 ts->ts_status |= AR5K_TXERR_FIFO;
3848 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
3849 ts->ts_status |= AR5K_TXERR_FILT;
3852 return 0;
3856 * Proccess a tx descriptor on 5212
3858 static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
3859 struct ath5k_desc *desc, struct ath5k_tx_status *ts)
3861 struct ath5k_hw_4w_tx_ctl *tx_ctl;
3862 struct ath5k_hw_tx_status *tx_status;
3864 ATH5K_TRACE(ah->ah_sc);
3866 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
3867 tx_status = &desc->ud.ds_tx5212.tx_stat;
3869 /* No frame has been send or error */
3870 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
3871 return -EINPROGRESS;
3874 * Get descriptor status
3876 ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
3877 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
3878 ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
3879 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
3880 ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
3881 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
3882 ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
3883 AR5K_DESC_TX_STATUS1_SEQ_NUM);
3884 ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
3885 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
3886 ts->ts_antenna = (tx_status->tx_status_1 &
3887 AR5K_DESC_TX_STATUS1_XMIT_ANTENNA) ? 2 : 1;
3888 ts->ts_status = 0;
3890 switch (AR5K_REG_MS(tx_status->tx_status_1,
3891 AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX)) {
3892 case 0:
3893 ts->ts_rate = tx_ctl->tx_control_3 &
3894 AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
3895 break;
3896 case 1:
3897 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
3898 AR5K_4W_TX_DESC_CTL3_XMIT_RATE1);
3899 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
3900 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1);
3901 break;
3902 case 2:
3903 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
3904 AR5K_4W_TX_DESC_CTL3_XMIT_RATE2);
3905 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
3906 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2);
3907 break;
3908 case 3:
3909 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
3910 AR5K_4W_TX_DESC_CTL3_XMIT_RATE3);
3911 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
3912 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES3);
3913 break;
3916 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
3917 if (tx_status->tx_status_0 &
3918 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
3919 ts->ts_status |= AR5K_TXERR_XRETRY;
3921 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
3922 ts->ts_status |= AR5K_TXERR_FIFO;
3924 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
3925 ts->ts_status |= AR5K_TXERR_FILT;
3928 return 0;
3932 * RX Descriptor
3936 * Initialize an rx descriptor
3938 int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3939 u32 size, unsigned int flags)
3941 struct ath5k_hw_rx_ctl *rx_ctl;
3943 ATH5K_TRACE(ah->ah_sc);
3944 rx_ctl = &desc->ud.ds_rx.rx_ctl;
3947 * Clear the descriptor
3948 * If we don't clean the status descriptor,
3949 * while scanning we get too many results,
3950 * most of them virtual, after some secs
3951 * of scanning system hangs. M.F.
3953 memset(&desc->ud.ds_rx, 0, sizeof(struct ath5k_hw_all_rx_desc));
3955 /* Setup descriptor */
3956 rx_ctl->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
3957 if (unlikely(rx_ctl->rx_control_1 != size))
3958 return -EINVAL;
3960 if (flags & AR5K_RXDESC_INTREQ)
3961 rx_ctl->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
3963 return 0;
3967 * Proccess the rx status descriptor on 5210/5211
3969 static int ath5k_hw_proc_5210_rx_status(struct ath5k_hw *ah,
3970 struct ath5k_desc *desc, struct ath5k_rx_status *rs)
3972 struct ath5k_hw_rx_status *rx_status;
3974 rx_status = &desc->ud.ds_rx.u.rx_stat;
3976 /* No frame received / not ready */
3977 if (unlikely((rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_DONE)
3978 == 0))
3979 return -EINPROGRESS;
3982 * Frame receive status
3984 rs->rs_datalen = rx_status->rx_status_0 &
3985 AR5K_5210_RX_DESC_STATUS0_DATA_LEN;
3986 rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
3987 AR5K_5210_RX_DESC_STATUS0_RECEIVE_SIGNAL);
3988 rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
3989 AR5K_5210_RX_DESC_STATUS0_RECEIVE_RATE);
3990 rs->rs_antenna = rx_status->rx_status_0 &
3991 AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANTENNA;
3992 rs->rs_more = rx_status->rx_status_0 &
3993 AR5K_5210_RX_DESC_STATUS0_MORE;
3994 /* TODO: this timestamp is 13 bit, later on we assume 15 bit */
3995 rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
3996 AR5K_5210_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
3997 rs->rs_status = 0;
4000 * Key table status
4002 if (rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_KEY_INDEX_VALID)
4003 rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
4004 AR5K_5210_RX_DESC_STATUS1_KEY_INDEX);
4005 else
4006 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
4009 * Receive/descriptor errors
4011 if ((rx_status->rx_status_1 &
4012 AR5K_5210_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
4013 if (rx_status->rx_status_1 &
4014 AR5K_5210_RX_DESC_STATUS1_CRC_ERROR)
4015 rs->rs_status |= AR5K_RXERR_CRC;
4017 if (rx_status->rx_status_1 &
4018 AR5K_5210_RX_DESC_STATUS1_FIFO_OVERRUN)
4019 rs->rs_status |= AR5K_RXERR_FIFO;
4021 if (rx_status->rx_status_1 &
4022 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR) {
4023 rs->rs_status |= AR5K_RXERR_PHY;
4024 rs->rs_phyerr = AR5K_REG_MS(rx_status->rx_status_1,
4025 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR);
4028 if (rx_status->rx_status_1 &
4029 AR5K_5210_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
4030 rs->rs_status |= AR5K_RXERR_DECRYPT;
4033 return 0;
4037 * Proccess the rx status descriptor on 5212
4039 static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *ah,
4040 struct ath5k_desc *desc, struct ath5k_rx_status *rs)
4042 struct ath5k_hw_rx_status *rx_status;
4043 struct ath5k_hw_rx_error *rx_err;
4045 ATH5K_TRACE(ah->ah_sc);
4046 rx_status = &desc->ud.ds_rx.u.rx_stat;
4048 /* Overlay on error */
4049 rx_err = &desc->ud.ds_rx.u.rx_err;
4051 /* No frame received / not ready */
4052 if (unlikely((rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_DONE)
4053 == 0))
4054 return -EINPROGRESS;
4057 * Frame receive status
4059 rs->rs_datalen = rx_status->rx_status_0 &
4060 AR5K_5212_RX_DESC_STATUS0_DATA_LEN;
4061 rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
4062 AR5K_5212_RX_DESC_STATUS0_RECEIVE_SIGNAL);
4063 rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
4064 AR5K_5212_RX_DESC_STATUS0_RECEIVE_RATE);
4065 rs->rs_antenna = rx_status->rx_status_0 &
4066 AR5K_5212_RX_DESC_STATUS0_RECEIVE_ANTENNA;
4067 rs->rs_more = rx_status->rx_status_0 &
4068 AR5K_5212_RX_DESC_STATUS0_MORE;
4069 rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
4070 AR5K_5212_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
4071 rs->rs_status = 0;
4074 * Key table status
4076 if (rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_KEY_INDEX_VALID)
4077 rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
4078 AR5K_5212_RX_DESC_STATUS1_KEY_INDEX);
4079 else
4080 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
4083 * Receive/descriptor errors
4085 if ((rx_status->rx_status_1 &
4086 AR5K_5212_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
4087 if (rx_status->rx_status_1 &
4088 AR5K_5212_RX_DESC_STATUS1_CRC_ERROR)
4089 rs->rs_status |= AR5K_RXERR_CRC;
4091 if (rx_status->rx_status_1 &
4092 AR5K_5212_RX_DESC_STATUS1_PHY_ERROR) {
4093 rs->rs_status |= AR5K_RXERR_PHY;
4094 rs->rs_phyerr = AR5K_REG_MS(rx_err->rx_error_1,
4095 AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE);
4098 if (rx_status->rx_status_1 &
4099 AR5K_5212_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
4100 rs->rs_status |= AR5K_RXERR_DECRYPT;
4102 if (rx_status->rx_status_1 &
4103 AR5K_5212_RX_DESC_STATUS1_MIC_ERROR)
4104 rs->rs_status |= AR5K_RXERR_MIC;
4107 return 0;
4111 /****************\
4112 GPIO Functions
4113 \****************/
4116 * Set led state
4118 void ath5k_hw_set_ledstate(struct ath5k_hw *ah, unsigned int state)
4120 u32 led;
4121 /*5210 has different led mode handling*/
4122 u32 led_5210;
4124 ATH5K_TRACE(ah->ah_sc);
4126 /*Reset led status*/
4127 if (ah->ah_version != AR5K_AR5210)
4128 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
4129 AR5K_PCICFG_LEDMODE | AR5K_PCICFG_LED);
4130 else
4131 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_LED);
4134 * Some blinking values, define at your wish
4136 switch (state) {
4137 case AR5K_LED_SCAN:
4138 case AR5K_LED_AUTH:
4139 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_PEND;
4140 led_5210 = AR5K_PCICFG_LED_PEND | AR5K_PCICFG_LED_BCTL;
4141 break;
4143 case AR5K_LED_INIT:
4144 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_NONE;
4145 led_5210 = AR5K_PCICFG_LED_PEND;
4146 break;
4148 case AR5K_LED_ASSOC:
4149 case AR5K_LED_RUN:
4150 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_ASSOC;
4151 led_5210 = AR5K_PCICFG_LED_ASSOC;
4152 break;
4154 default:
4155 led = AR5K_PCICFG_LEDMODE_PROM | AR5K_PCICFG_LED_NONE;
4156 led_5210 = AR5K_PCICFG_LED_PEND;
4157 break;
4160 /*Write new status to the register*/
4161 if (ah->ah_version != AR5K_AR5210)
4162 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led);
4163 else
4164 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led_5210);
4168 * Set GPIO outputs
4170 int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
4172 ATH5K_TRACE(ah->ah_sc);
4173 if (gpio > AR5K_NUM_GPIO)
4174 return -EINVAL;
4176 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4177 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR);
4179 return 0;
4183 * Set GPIO inputs
4185 int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
4187 ATH5K_TRACE(ah->ah_sc);
4188 if (gpio > AR5K_NUM_GPIO)
4189 return -EINVAL;
4191 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4192 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR);
4194 return 0;
4198 * Get GPIO state
4200 u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
4202 ATH5K_TRACE(ah->ah_sc);
4203 if (gpio > AR5K_NUM_GPIO)
4204 return 0xffffffff;
4206 /* GPIO input magic */
4207 return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) &
4208 0x1;
4212 * Set GPIO state
4214 int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
4216 u32 data;
4217 ATH5K_TRACE(ah->ah_sc);
4219 if (gpio > AR5K_NUM_GPIO)
4220 return -EINVAL;
4222 /* GPIO output magic */
4223 data = ath5k_hw_reg_read(ah, AR5K_GPIODO);
4225 data &= ~(1 << gpio);
4226 data |= (val & 1) << gpio;
4228 ath5k_hw_reg_write(ah, data, AR5K_GPIODO);
4230 return 0;
4234 * Initialize the GPIO interrupt (RFKill switch)
4236 void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
4237 u32 interrupt_level)
4239 u32 data;
4241 ATH5K_TRACE(ah->ah_sc);
4242 if (gpio > AR5K_NUM_GPIO)
4243 return;
4246 * Set the GPIO interrupt
4248 data = (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &
4249 ~(AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_SELH |
4250 AR5K_GPIOCR_INT_ENA | AR5K_GPIOCR_OUT(gpio))) |
4251 (AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_ENA);
4253 ath5k_hw_reg_write(ah, interrupt_level ? data :
4254 (data | AR5K_GPIOCR_INT_SELH), AR5K_GPIOCR);
4256 ah->ah_imr |= AR5K_IMR_GPIO;
4258 /* Enable GPIO interrupts */
4259 AR5K_REG_ENABLE_BITS(ah, AR5K_PIMR, AR5K_IMR_GPIO);
4265 /****************\
4266 Misc functions
4267 \****************/
4269 int ath5k_hw_get_capability(struct ath5k_hw *ah,
4270 enum ath5k_capability_type cap_type,
4271 u32 capability, u32 *result)
4273 ATH5K_TRACE(ah->ah_sc);
4275 switch (cap_type) {
4276 case AR5K_CAP_NUM_TXQUEUES:
4277 if (result) {
4278 if (ah->ah_version == AR5K_AR5210)
4279 *result = AR5K_NUM_TX_QUEUES_NOQCU;
4280 else
4281 *result = AR5K_NUM_TX_QUEUES;
4282 goto yes;
4284 case AR5K_CAP_VEOL:
4285 goto yes;
4286 case AR5K_CAP_COMPRESSION:
4287 if (ah->ah_version == AR5K_AR5212)
4288 goto yes;
4289 else
4290 goto no;
4291 case AR5K_CAP_BURST:
4292 goto yes;
4293 case AR5K_CAP_TPC:
4294 goto yes;
4295 case AR5K_CAP_BSSIDMASK:
4296 if (ah->ah_version == AR5K_AR5212)
4297 goto yes;
4298 else
4299 goto no;
4300 case AR5K_CAP_XR:
4301 if (ah->ah_version == AR5K_AR5212)
4302 goto yes;
4303 else
4304 goto no;
4305 default:
4306 goto no;
4310 return -EINVAL;
4311 yes:
4312 return 0;
4315 static int ath5k_hw_enable_pspoll(struct ath5k_hw *ah, u8 *bssid,
4316 u16 assoc_id)
4318 ATH5K_TRACE(ah->ah_sc);
4320 if (ah->ah_version == AR5K_AR5210) {
4321 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
4322 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
4323 return 0;
4326 return -EIO;
4329 static int ath5k_hw_disable_pspoll(struct ath5k_hw *ah)
4331 ATH5K_TRACE(ah->ah_sc);
4333 if (ah->ah_version == AR5K_AR5210) {
4334 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
4335 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
4336 return 0;
4339 return -EIO;