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>
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;
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,
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)
75 #define COUNTRYCODE "00"
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,
105 for (i = AR5K_TUNE_REGISTER_TIMEOUT; i > 0; i--) {
106 data = ath5k_hw_reg_read(ah, reg);
107 if (is_set && (data & flag))
109 else if ((data & flag) == val)
114 return (i <= 0) ? -EAGAIN : 0;
118 /***************************************\
119 Attach/Detach Functions
120 \***************************************/
123 * Power On Self Test helper function
125 static int ath5k_hw_post(struct ath5k_hw *ah)
130 u16 regs[2] = {AR5K_STA_ID0, AR5K_PHY(8)};
132 u32 static_pattern[4] = {
133 0x55555555, 0xaaaaaaaa,
134 0x66666666, 0x99999999
139 for (c = 0; c < 2; c++) {
142 init_val = ath5k_hw_reg_read(ah, cur_reg);
144 for (i = 0; i < 256; i++) {
145 var_pattern = i << 16 | i;
146 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
147 cur_val = ath5k_hw_reg_read(ah, cur_reg);
149 if (cur_val != var_pattern) {
150 ATH5K_ERR(ah->ah_sc, "POST Failed !!!\n");
154 /* Found on ndiswrapper dumps */
155 var_pattern = 0x0039080f;
156 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
159 for (i = 0; i < 4; i++) {
160 var_pattern = static_pattern[i];
161 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
162 cur_val = ath5k_hw_reg_read(ah, cur_reg);
164 if (cur_val != var_pattern) {
165 ATH5K_ERR(ah->ah_sc, "POST Failed !!!\n");
169 /* Found on ndiswrapper dumps */
170 var_pattern = 0x003b080f;
171 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
180 * Check if the device is supported and initialize the needed structs
182 struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
185 struct pci_dev *pdev = sc->pdev;
190 /*If we passed the test malloc a ath5k_hw struct*/
191 ah = kzalloc(sizeof(struct ath5k_hw), GFP_KERNEL);
194 ATH5K_ERR(sc, "out of memory\n");
199 ah->ah_iobase = sc->iobase;
205 ah->ah_op_mode = IEEE80211_IF_TYPE_STA;
206 ah->ah_radar.r_enabled = AR5K_TUNE_RADAR_ALERT;
207 ah->ah_turbo = false;
208 ah->ah_txpower.txp_tpc = AR5K_TUNE_TPC_TXPOWER;
210 ah->ah_atim_window = 0;
211 ah->ah_aifs = AR5K_TUNE_AIFS;
212 ah->ah_cw_min = AR5K_TUNE_CWMIN;
213 ah->ah_limit_tx_retries = AR5K_INIT_TX_RETRY;
214 ah->ah_software_retry = false;
215 ah->ah_ant_diversity = AR5K_TUNE_ANT_DIVERSITY;
218 * Set the mac revision based on the pci id
220 ah->ah_version = mac_version;
222 /*Fill the ath5k_hw struct with the needed functions*/
223 if (ah->ah_version == AR5K_AR5212)
224 ah->ah_magic = AR5K_EEPROM_MAGIC_5212;
225 else if (ah->ah_version == AR5K_AR5211)
226 ah->ah_magic = AR5K_EEPROM_MAGIC_5211;
228 if (ah->ah_version == AR5K_AR5212) {
229 ah->ah_setup_tx_desc = ath5k_hw_setup_4word_tx_desc;
230 ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
231 ah->ah_proc_tx_desc = ath5k_hw_proc_4word_tx_status;
233 ah->ah_setup_tx_desc = ath5k_hw_setup_2word_tx_desc;
234 ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
235 ah->ah_proc_tx_desc = ath5k_hw_proc_2word_tx_status;
238 if (ah->ah_version == AR5K_AR5212)
239 ah->ah_proc_rx_desc = ath5k_hw_proc_5212_rx_status;
240 else if (ah->ah_version <= AR5K_AR5211)
241 ah->ah_proc_rx_desc = ath5k_hw_proc_5210_rx_status;
243 /* Bring device out of sleep and reset it's units */
244 ret = ath5k_hw_nic_wakeup(ah, AR5K_INIT_MODE, true);
248 /* Get MAC, PHY and RADIO revisions */
249 srev = ath5k_hw_reg_read(ah, AR5K_SREV);
250 ah->ah_mac_srev = srev;
251 ah->ah_mac_version = AR5K_REG_MS(srev, AR5K_SREV_VER);
252 ah->ah_mac_revision = AR5K_REG_MS(srev, AR5K_SREV_REV);
253 ah->ah_phy_revision = ath5k_hw_reg_read(ah, AR5K_PHY_CHIP_ID) &
255 ah->ah_radio_5ghz_revision = ath5k_hw_radio_revision(ah,
258 if (ah->ah_version == AR5K_AR5210)
259 ah->ah_radio_2ghz_revision = 0;
261 ah->ah_radio_2ghz_revision = ath5k_hw_radio_revision(ah,
264 /* Return on unsuported chips (unsupported eeprom etc) */
265 if ((srev >= AR5K_SREV_VER_AR5416) &&
266 (srev < AR5K_SREV_VER_AR2425)) {
267 ATH5K_ERR(sc, "Device not yet supported.\n");
270 } else if (srev == AR5K_SREV_VER_AR2425) {
271 ATH5K_WARN(sc, "Support for RF2425 is under development.\n");
274 /* Identify single chip solutions */
275 if (((srev <= AR5K_SREV_VER_AR5414) &&
276 (srev >= AR5K_SREV_VER_AR2413)) ||
277 (srev == AR5K_SREV_VER_AR2425)) {
278 ah->ah_single_chip = true;
280 ah->ah_single_chip = false;
283 /* Single chip radio */
284 if (ah->ah_radio_2ghz_revision == ah->ah_radio_5ghz_revision)
285 ah->ah_radio_2ghz_revision = 0;
287 /* Identify the radio chip*/
288 if (ah->ah_version == AR5K_AR5210) {
289 ah->ah_radio = AR5K_RF5110;
290 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112) {
291 ah->ah_radio = AR5K_RF5111;
292 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5111;
293 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC0) {
295 ah->ah_radio = AR5K_RF5112;
297 if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112A) {
298 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112;
300 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
303 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC1) {
304 ah->ah_radio = AR5K_RF2413;
305 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
306 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC2) {
308 ah->ah_radio = AR5K_RF5413;
310 if (ah->ah_mac_srev <= AR5K_SREV_VER_AR5424 &&
311 ah->ah_mac_srev >= AR5K_SREV_VER_AR2424)
312 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5424;
314 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
316 * Register returns 0x4 for radio revision
317 * so ath5k_hw_radio_revision doesn't parse the value
318 * correctly. For now we are based on mac's srev to
319 * identify RF2425 radio.
321 } else if (srev == AR5K_SREV_VER_AR2425) {
322 ah->ah_radio = AR5K_RF2425;
323 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112;
326 ah->ah_phy = AR5K_PHY(0);
329 * Identify AR5212-based PCI-E cards
330 * And write some initial settings.
332 * (doing a "strings" on ndis driver
333 * -ar5211.sys- reveals the following
334 * pci-e related functions:
340 * pcieDisableAspmOnRfWake
341 * pciePowerSaveEnable
343 * I guess these point to ClockReq but
346 if ((ah->ah_version == AR5K_AR5212) && (pdev->is_pcie)) {
347 ath5k_hw_reg_write(ah, 0x9248fc00, 0x4080);
348 ath5k_hw_reg_write(ah, 0x24924924, 0x4080);
349 ath5k_hw_reg_write(ah, 0x28000039, 0x4080);
350 ath5k_hw_reg_write(ah, 0x53160824, 0x4080);
351 ath5k_hw_reg_write(ah, 0xe5980579, 0x4080);
352 ath5k_hw_reg_write(ah, 0x001defff, 0x4080);
353 ath5k_hw_reg_write(ah, 0x1aaabe40, 0x4080);
354 ath5k_hw_reg_write(ah, 0xbe105554, 0x4080);
355 ath5k_hw_reg_write(ah, 0x000e3007, 0x4080);
356 ath5k_hw_reg_write(ah, 0x00000000, 0x4084);
362 ret = ath5k_hw_post(ah);
367 * Get card capabilities, values, ...
370 ret = ath5k_eeprom_init(ah);
372 ATH5K_ERR(sc, "unable to init EEPROM\n");
376 /* Get misc capabilities */
377 ret = ath5k_hw_get_capabilities(ah);
379 ATH5K_ERR(sc, "unable to get device capabilities: 0x%04x\n",
384 /* Get MAC address */
385 ret = ath5k_eeprom_read_mac(ah, mac);
387 ATH5K_ERR(sc, "unable to read address from EEPROM: 0x%04x\n",
392 ath5k_hw_set_lladdr(ah, mac);
393 /* Set BSSID to bcast address: ff:ff:ff:ff:ff:ff for now */
394 memset(ah->ah_bssid, 0xff, ETH_ALEN);
395 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
396 ath5k_hw_set_opmode(ah);
398 ath5k_hw_set_rfgain_opt(ah);
408 * Bring up MAC + PHY Chips
410 static int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
412 struct pci_dev *pdev = ah->ah_sc->pdev;
413 u32 turbo, mode, clock, bus_flags;
420 ATH5K_TRACE(ah->ah_sc);
422 /* Wakeup the device */
423 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
425 ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
429 if (ah->ah_version != AR5K_AR5210) {
431 * Get channel mode flags
434 if (ah->ah_radio >= AR5K_RF5112) {
435 mode = AR5K_PHY_MODE_RAD_RF5112;
436 clock = AR5K_PHY_PLL_RF5112;
438 mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
439 clock = AR5K_PHY_PLL_RF5111; /*Zero*/
442 if (flags & CHANNEL_2GHZ) {
443 mode |= AR5K_PHY_MODE_FREQ_2GHZ;
444 clock |= AR5K_PHY_PLL_44MHZ;
446 if (flags & CHANNEL_CCK) {
447 mode |= AR5K_PHY_MODE_MOD_CCK;
448 } else if (flags & CHANNEL_OFDM) {
449 /* XXX Dynamic OFDM/CCK is not supported by the
450 * AR5211 so we set MOD_OFDM for plain g (no
451 * CCK headers) operation. We need to test
452 * this, 5211 might support ofdm-only g after
453 * all, there are also initial register values
454 * in the code for g mode (see initvals.c). */
455 if (ah->ah_version == AR5K_AR5211)
456 mode |= AR5K_PHY_MODE_MOD_OFDM;
458 mode |= AR5K_PHY_MODE_MOD_DYN;
461 "invalid radio modulation mode\n");
464 } else if (flags & CHANNEL_5GHZ) {
465 mode |= AR5K_PHY_MODE_FREQ_5GHZ;
466 clock |= AR5K_PHY_PLL_40MHZ;
468 if (flags & CHANNEL_OFDM)
469 mode |= AR5K_PHY_MODE_MOD_OFDM;
472 "invalid radio modulation mode\n");
476 ATH5K_ERR(ah->ah_sc, "invalid radio frequency mode\n");
480 if (flags & CHANNEL_TURBO)
481 turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
482 } else { /* Reset the device */
484 /* ...enable Atheros turbo mode if requested */
485 if (flags & CHANNEL_TURBO)
486 ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
490 /* reseting PCI on PCI-E cards results card to hang
491 * and always return 0xffff... so we ingore that flag
493 bus_flags = (pdev->is_pcie) ? 0 : AR5K_RESET_CTL_PCI;
496 ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
497 AR5K_RESET_CTL_BASEBAND | bus_flags);
499 ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip\n");
503 if (ah->ah_version == AR5K_AR5210)
506 /* ...wakeup again!*/
507 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
509 ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
513 /* ...final warm reset */
514 if (ath5k_hw_nic_reset(ah, 0)) {
515 ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
519 if (ah->ah_version != AR5K_AR5210) {
520 /* ...set the PHY operating mode */
521 ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
524 ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
525 ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
532 * Get the rate table for a specific operation mode
534 const struct ath5k_rate_table *ath5k_hw_get_rate_table(struct ath5k_hw *ah,
537 ATH5K_TRACE(ah->ah_sc);
539 if (!test_bit(mode, ah->ah_capabilities.cap_mode))
542 /* Get rate tables */
545 return &ath5k_rt_11a;
546 case AR5K_MODE_11A_TURBO:
547 return &ath5k_rt_turbo;
549 return &ath5k_rt_11b;
551 return &ath5k_rt_11g;
552 case AR5K_MODE_11G_TURBO:
560 * Free the ath5k_hw struct
562 void ath5k_hw_detach(struct ath5k_hw *ah)
564 ATH5K_TRACE(ah->ah_sc);
566 __set_bit(ATH_STAT_INVALID, ah->ah_sc->status);
568 if (ah->ah_rf_banks != NULL)
569 kfree(ah->ah_rf_banks);
571 /* assume interrupts are down */
575 /****************************\
576 Reset function and helpers
577 \****************************/
580 * ath5k_hw_write_ofdm_timings - set OFDM timings on AR5212
582 * @ah: the &struct ath5k_hw
583 * @channel: the currently set channel upon reset
585 * Write the OFDM timings for the AR5212 upon reset. This is a helper for
586 * ath5k_hw_reset(). This seems to tune the PLL a specified frequency
587 * depending on the bandwidth of the channel.
590 static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
591 struct ieee80211_channel *channel)
593 /* Get exponent and mantissa and set it */
594 u32 coef_scaled, coef_exp, coef_man,
595 ds_coef_exp, ds_coef_man, clock;
597 if (!(ah->ah_version == AR5K_AR5212) ||
598 !(channel->hw_value & CHANNEL_OFDM))
601 /* Seems there are two PLLs, one for baseband sampling and one
602 * for tuning. Tuning basebands are 40 MHz or 80MHz when in
604 clock = channel->hw_value & CHANNEL_TURBO ? 80 : 40;
605 coef_scaled = ((5 * (clock << 24)) / 2) /
606 channel->center_freq;
608 for (coef_exp = 31; coef_exp > 0; coef_exp--)
609 if ((coef_scaled >> coef_exp) & 0x1)
615 coef_exp = 14 - (coef_exp - 24);
616 coef_man = coef_scaled +
617 (1 << (24 - coef_exp - 1));
618 ds_coef_man = coef_man >> (24 - coef_exp);
619 ds_coef_exp = coef_exp - 16;
621 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
622 AR5K_PHY_TIMING_3_DSC_MAN, ds_coef_man);
623 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
624 AR5K_PHY_TIMING_3_DSC_EXP, ds_coef_exp);
630 * ath5k_hw_write_rate_duration - set rate duration during hw resets
632 * @ah: the &struct ath5k_hw
633 * @mode: one of enum ath5k_driver_mode
635 * Write the rate duration table for the current mode upon hw reset. This
636 * is a helper for ath5k_hw_reset(). It seems all this is doing is setting
637 * an ACK timeout for the hardware for the current mode for each rate. The
638 * rates which are capable of short preamble (802.11b rates 2Mbps, 5.5Mbps,
639 * and 11Mbps) have another register for the short preamble ACK timeout
643 static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
646 struct ath5k_softc *sc = ah->ah_sc;
647 const struct ath5k_rate_table *rt;
648 struct ieee80211_rate srate = {};
651 /* Get rate table for the current operating mode */
652 rt = ath5k_hw_get_rate_table(ah, mode);
654 /* Write rate duration table */
655 for (i = 0; i < rt->rate_count; i++) {
656 const struct ath5k_rate *rate, *control_rate;
661 rate = &rt->rates[i];
662 control_rate = &rt->rates[rate->control_rate];
664 /* Set ACK timeout */
665 reg = AR5K_RATE_DUR(rate->rate_code);
667 srate.bitrate = control_rate->rate_kbps/100;
669 /* An ACK frame consists of 10 bytes. If you add the FCS,
670 * which ieee80211_generic_frame_duration() adds,
671 * its 14 bytes. Note we use the control rate and not the
672 * actual rate for this rate. See mac80211 tx.c
673 * ieee80211_duration() for a brief description of
674 * what rate we should choose to TX ACKs. */
675 tx_time = le16_to_cpu(ieee80211_generic_frame_duration(sc->hw,
676 sc->vif, 10, &srate));
678 ath5k_hw_reg_write(ah, tx_time, reg);
680 if (!HAS_SHPREAMBLE(i))
684 * We're not distinguishing short preamble here,
685 * This is true, all we'll get is a longer value here
686 * which is not necessarilly bad. We could use
687 * export ieee80211_frame_duration() but that needs to be
688 * fixed first to be properly used by mac802111 drivers:
690 * - remove erp stuff and let the routine figure ofdm
692 * - remove passing argument ieee80211_local as
693 * drivers don't have access to it
694 * - move drivers using ieee80211_generic_frame_duration()
697 ath5k_hw_reg_write(ah, tx_time,
698 reg + (AR5K_SET_SHORT_PREAMBLE << 2));
703 * Main reset function
705 int ath5k_hw_reset(struct ath5k_hw *ah, enum ieee80211_if_types op_mode,
706 struct ieee80211_channel *channel, bool change_channel)
708 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
709 struct pci_dev *pdev = ah->ah_sc->pdev;
710 u32 data, s_seq, s_ant, s_led[3], dma_size;
711 unsigned int i, mode, freq, ee_mode, ant[2];
714 ATH5K_TRACE(ah->ah_sc);
723 * Save some registers before a reset
725 /*DCU/Antenna selection not available on 5210*/
726 if (ah->ah_version != AR5K_AR5210) {
727 if (change_channel) {
728 /* Seq number for queue 0 -do this for all queues ? */
729 s_seq = ath5k_hw_reg_read(ah,
730 AR5K_QUEUE_DFS_SEQNUM(0));
732 s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
737 s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) & AR5K_PCICFG_LEDSTATE;
738 s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
739 s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
741 if (change_channel && ah->ah_rf_banks != NULL)
742 ath5k_hw_get_rf_gain(ah);
745 /*Wakeup the device*/
746 ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, false);
751 * Initialize operating mode
753 ah->ah_op_mode = op_mode;
757 * 5210 only comes with RF5110
759 if (ah->ah_version != AR5K_AR5210) {
760 if (ah->ah_radio != AR5K_RF5111 &&
761 ah->ah_radio != AR5K_RF5112 &&
762 ah->ah_radio != AR5K_RF5413 &&
763 ah->ah_radio != AR5K_RF2413 &&
764 ah->ah_radio != AR5K_RF2425) {
766 "invalid phy radio: %u\n", ah->ah_radio);
770 switch (channel->hw_value & CHANNEL_MODES) {
772 mode = AR5K_MODE_11A;
773 freq = AR5K_INI_RFGAIN_5GHZ;
774 ee_mode = AR5K_EEPROM_MODE_11A;
777 mode = AR5K_MODE_11G;
778 freq = AR5K_INI_RFGAIN_2GHZ;
779 ee_mode = AR5K_EEPROM_MODE_11G;
782 mode = AR5K_MODE_11B;
783 freq = AR5K_INI_RFGAIN_2GHZ;
784 ee_mode = AR5K_EEPROM_MODE_11B;
787 mode = AR5K_MODE_11A_TURBO;
788 freq = AR5K_INI_RFGAIN_5GHZ;
789 ee_mode = AR5K_EEPROM_MODE_11A;
791 /*Is this ok on 5211 too ?*/
793 mode = AR5K_MODE_11G_TURBO;
794 freq = AR5K_INI_RFGAIN_2GHZ;
795 ee_mode = AR5K_EEPROM_MODE_11G;
798 if (ah->ah_version == AR5K_AR5211) {
800 "XR mode not available on 5211");
804 freq = AR5K_INI_RFGAIN_5GHZ;
805 ee_mode = AR5K_EEPROM_MODE_11A;
809 "invalid channel: %d\n", channel->center_freq);
813 /* PHY access enable */
814 ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
818 ret = ath5k_hw_write_initvals(ah, mode, change_channel);
825 if (ah->ah_version != AR5K_AR5210) {
827 * Write initial RF gain settings
828 * This should work for both 5111/5112
830 ret = ath5k_hw_rfgain(ah, freq);
837 * Write some more initial register settings
839 if (ah->ah_version == AR5K_AR5212) {
840 ath5k_hw_reg_write(ah, 0x0002a002, AR5K_PHY(11));
842 if (channel->hw_value == CHANNEL_G)
843 if (ah->ah_mac_srev < AR5K_SREV_VER_AR2413)
844 ath5k_hw_reg_write(ah, 0x00f80d80,
846 else if (ah->ah_mac_srev < AR5K_SREV_VER_AR2424)
847 ath5k_hw_reg_write(ah, 0x00380140,
849 else if (ah->ah_mac_srev < AR5K_SREV_VER_AR2425)
850 ath5k_hw_reg_write(ah, 0x00fc0ec0,
853 ath5k_hw_reg_write(ah, 0x00fc0fc0,
856 ath5k_hw_reg_write(ah, 0x00000000,
859 ath5k_hw_reg_write(ah, 0x000009b5, 0xa228);
860 ath5k_hw_reg_write(ah, 0x0000000f, 0x8060);
861 ath5k_hw_reg_write(ah, 0x00000000, 0xa254);
862 ath5k_hw_reg_write(ah, 0x0000000e, AR5K_PHY_SCAL);
865 /* Fix for first revision of the RF5112 RF chipset */
866 if (ah->ah_radio >= AR5K_RF5112 &&
867 ah->ah_radio_5ghz_revision <
868 AR5K_SREV_RAD_5112A) {
869 ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
871 if (channel->hw_value & CHANNEL_5GHZ)
875 ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
879 * Set TX power (FIXME)
881 ret = ath5k_hw_txpower(ah, channel, AR5K_TUNE_DEFAULT_TXPOWER);
885 /* Write rate duration table only on AR5212 and if
886 * virtual interface has already been brought up
887 * XXX: rethink this after new mode changes to
888 * mac80211 are integrated */
889 if (ah->ah_version == AR5K_AR5212 &&
890 ah->ah_sc->vif != NULL)
891 ath5k_hw_write_rate_duration(ah, mode);
895 * TODO:Does this work on 5211 (5111) ?
897 ret = ath5k_hw_rfregs(ah, channel, mode);
902 * Configure additional registers
905 /* Write OFDM timings on 5212*/
906 if (ah->ah_version == AR5K_AR5212 &&
907 channel->hw_value & CHANNEL_OFDM) {
908 ret = ath5k_hw_write_ofdm_timings(ah, channel);
913 /*Enable/disable 802.11b mode on 5111
914 (enable 2111 frequency converter + CCK)*/
915 if (ah->ah_radio == AR5K_RF5111) {
916 if (mode == AR5K_MODE_11B)
917 AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
920 AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
925 * Set channel and calibrate the PHY
927 ret = ath5k_hw_channel(ah, channel);
931 /* Set antenna mode */
932 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x44),
933 ah->ah_antenna[ee_mode][0], 0xfffffc06);
936 * In case a fixed antenna was set as default
937 * write the same settings on both AR5K_PHY_ANT_SWITCH_TABLE
941 if (s_ant == AR5K_ANT_FIXED_A) /* 1 - Main */
942 ant[0] = ant[1] = AR5K_ANT_FIXED_A;
944 ant[0] = ant[1] = AR5K_ANT_FIXED_B;
946 ant[0] = AR5K_ANT_FIXED_A;
947 ant[1] = AR5K_ANT_FIXED_B;
950 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[0]],
951 AR5K_PHY_ANT_SWITCH_TABLE_0);
952 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[1]],
953 AR5K_PHY_ANT_SWITCH_TABLE_1);
955 /* Commit values from EEPROM */
956 if (ah->ah_radio == AR5K_RF5111)
957 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_FRAME_CTL,
958 AR5K_PHY_FRAME_CTL_TX_CLIP, ee->ee_tx_clip);
960 ath5k_hw_reg_write(ah,
961 AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
964 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x11),
965 (ee->ee_switch_settling[ee_mode] << 7) & 0x3f80,
967 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x12),
968 (ee->ee_ant_tx_rx[ee_mode] << 12) & 0x3f000,
970 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x14),
971 (ee->ee_adc_desired_size[ee_mode] & 0x00ff) |
972 ((ee->ee_pga_desired_size[ee_mode] << 8) & 0xff00),
975 ath5k_hw_reg_write(ah,
976 (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
977 (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
978 (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
979 (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY(0x0d));
981 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x0a),
982 ee->ee_tx_end2xlna_enable[ee_mode] << 8, 0xffff00ff);
983 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x19),
984 (ee->ee_thr_62[ee_mode] << 12) & 0x7f000, 0xfff80fff);
985 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x49), 4, 0xffffff01);
987 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
988 AR5K_PHY_IQ_CORR_ENABLE |
989 (ee->ee_i_cal[ee_mode] << AR5K_PHY_IQ_CORR_Q_I_COFF_S) |
990 ee->ee_q_cal[ee_mode]);
992 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
993 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
994 AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
995 ee->ee_margin_tx_rx[ee_mode]);
999 /* Disable phy and wait */
1000 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
1005 * Restore saved values
1007 /*DCU/Antenna selection not available on 5210*/
1008 if (ah->ah_version != AR5K_AR5210) {
1009 ath5k_hw_reg_write(ah, s_seq, AR5K_QUEUE_DFS_SEQNUM(0));
1010 ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
1012 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
1013 ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
1014 ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
1019 /* XXX: add ah->aid once mac80211 gives this to us */
1020 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
1022 ath5k_hw_set_opmode(ah);
1023 /*PISR/SISR Not available on 5210*/
1024 if (ah->ah_version != AR5K_AR5210) {
1025 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
1026 /* If we later allow tuning for this, store into sc structure */
1027 data = AR5K_TUNE_RSSI_THRES |
1028 AR5K_TUNE_BMISS_THRES << AR5K_RSSI_THR_BMISS_S;
1029 ath5k_hw_reg_write(ah, data, AR5K_RSSI_THR);
1033 * Set Rx/Tx DMA Configuration
1035 * Set maximum DMA size (512) except for PCI-E cards since
1036 * it causes rx overruns and tx errors (tested on 5424 but since
1037 * rx overruns also occur on 5416/5418 with madwifi we set 128
1038 * for all PCI-E cards to be safe).
1040 * In dumps this is 128 for allchips.
1042 * XXX: need to check 5210 for this
1043 * TODO: Check out tx triger level, it's always 64 on dumps but I
1044 * guess we can tweak it and see how it goes ;-)
1046 dma_size = (pdev->is_pcie) ? AR5K_DMASIZE_128B : AR5K_DMASIZE_512B;
1047 if (ah->ah_version != AR5K_AR5210) {
1048 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
1049 AR5K_TXCFG_SDMAMR, dma_size);
1050 AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG,
1051 AR5K_RXCFG_SDMAMW, dma_size);
1055 * Enable the PHY and wait until completion
1057 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
1060 * 5111/5112 Specific
1062 if (ah->ah_version != AR5K_AR5210) {
1063 data = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
1064 AR5K_PHY_RX_DELAY_M;
1065 data = (channel->hw_value & CHANNEL_CCK) ?
1066 ((data << 2) / 22) : (data / 10);
1074 * Enable calibration and wait until completion
1076 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
1077 AR5K_PHY_AGCCTL_CAL);
1079 if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
1080 AR5K_PHY_AGCCTL_CAL, 0, false)) {
1081 ATH5K_ERR(ah->ah_sc, "calibration timeout (%uMHz)\n",
1082 channel->center_freq);
1086 ret = ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
1090 ah->ah_calibration = false;
1092 /* A and G modes can use QAM modulation which requires enabling
1093 * I and Q calibration. Don't bother in B mode. */
1094 if (!(mode == AR5K_MODE_11B)) {
1095 ah->ah_calibration = true;
1096 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
1097 AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
1098 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
1103 * Reset queues and start beacon timers at the end of the reset routine
1105 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
1107 if (ah->ah_version != AR5K_AR5210)
1108 AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(i), i);
1110 ret = ath5k_hw_reset_tx_queue(ah, i);
1112 ATH5K_ERR(ah->ah_sc,
1113 "failed to reset TX queue #%d\n", i);
1118 /* Pre-enable interrupts on 5211/5212*/
1119 if (ah->ah_version != AR5K_AR5210)
1120 ath5k_hw_set_intr(ah, AR5K_INT_RX | AR5K_INT_TX |
1124 * Set RF kill flags if supported by the device (read from the EEPROM)
1125 * Disable gpio_intr for now since it results system hang.
1126 * TODO: Handle this in ath5k_intr
1129 if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header)) {
1130 ath5k_hw_set_gpio_input(ah, 0);
1131 ah->ah_gpio[0] = ath5k_hw_get_gpio(ah, 0);
1132 if (ah->ah_gpio[0] == 0)
1133 ath5k_hw_set_gpio_intr(ah, 0, 1);
1135 ath5k_hw_set_gpio_intr(ah, 0, 0);
1140 * Set the 32MHz reference clock on 5212 phy clock sleep register
1142 * TODO: Find out how to switch to external 32Khz clock to save power
1144 if (ah->ah_version == AR5K_AR5212) {
1145 ath5k_hw_reg_write(ah, AR5K_PHY_SCR_32MHZ, AR5K_PHY_SCR);
1146 ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
1147 ath5k_hw_reg_write(ah, AR5K_PHY_SCAL_32MHZ, AR5K_PHY_SCAL);
1148 ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
1149 ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
1150 ath5k_hw_reg_write(ah, ah->ah_phy_spending, AR5K_PHY_SPENDING);
1153 if (ah->ah_version == AR5K_AR5212) {
1154 ath5k_hw_reg_write(ah, 0x000100aa, 0x8118);
1155 ath5k_hw_reg_write(ah, 0x00003210, 0x811c);
1156 ath5k_hw_reg_write(ah, 0x00000052, 0x8108);
1157 if (ah->ah_mac_srev >= AR5K_SREV_VER_AR2413)
1158 ath5k_hw_reg_write(ah, 0x00000004, 0x8120);
1162 * Disable beacons and reset the register
1164 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
1165 AR5K_BEACON_RESET_TSF);
1173 static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
1176 u32 mask = val ? val : ~0U;
1178 ATH5K_TRACE(ah->ah_sc);
1180 /* Read-and-clear RX Descriptor Pointer*/
1181 ath5k_hw_reg_read(ah, AR5K_RXDP);
1184 * Reset the device and wait until success
1186 ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
1188 /* Wait at least 128 PCI clocks */
1191 if (ah->ah_version == AR5K_AR5210) {
1192 val &= AR5K_RESET_CTL_CHIP;
1193 mask &= AR5K_RESET_CTL_CHIP;
1195 val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1196 mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1199 ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, false);
1202 * Reset configuration register (for hw byte-swap). Note that this
1203 * is only set for big endian. We do the necessary magic in
1206 if ((val & AR5K_RESET_CTL_PCU) == 0)
1207 ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
1213 * Power management functions
1219 int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
1220 bool set_chip, u16 sleep_duration)
1225 ATH5K_TRACE(ah->ah_sc);
1226 staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
1230 staid &= ~AR5K_STA_ID1_DEFAULT_ANTENNA;
1232 case AR5K_PM_NETWORK_SLEEP:
1234 ath5k_hw_reg_write(ah,
1235 AR5K_SLEEP_CTL_SLE | sleep_duration,
1238 staid |= AR5K_STA_ID1_PWR_SV;
1241 case AR5K_PM_FULL_SLEEP:
1243 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_SLP,
1246 staid |= AR5K_STA_ID1_PWR_SV;
1253 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1256 for (i = 5000; i > 0; i--) {
1257 /* Check if the chip did wake up */
1258 if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
1259 AR5K_PCICFG_SPWR_DN) == 0)
1262 /* Wait a bit and retry */
1264 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1268 /* Fail if the chip didn't wake up */
1272 staid &= ~AR5K_STA_ID1_PWR_SV;
1280 ah->ah_power_mode = mode;
1281 ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
1286 /***********************\
1287 DMA Related Functions
1288 \***********************/
1297 void ath5k_hw_start_rx(struct ath5k_hw *ah)
1299 ATH5K_TRACE(ah->ah_sc);
1300 ath5k_hw_reg_write(ah, AR5K_CR_RXE, AR5K_CR);
1306 int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
1310 ATH5K_TRACE(ah->ah_sc);
1311 ath5k_hw_reg_write(ah, AR5K_CR_RXD, AR5K_CR);
1314 * It may take some time to disable the DMA receive unit
1316 for (i = 2000; i > 0 &&
1317 (ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_CR_RXE) != 0;
1321 return i ? 0 : -EBUSY;
1325 * Get the address of the RX Descriptor
1327 u32 ath5k_hw_get_rx_buf(struct ath5k_hw *ah)
1329 return ath5k_hw_reg_read(ah, AR5K_RXDP);
1333 * Set the address of the RX Descriptor
1335 void ath5k_hw_put_rx_buf(struct ath5k_hw *ah, u32 phys_addr)
1337 ATH5K_TRACE(ah->ah_sc);
1339 /*TODO:Shouldn't we check if RX is enabled first ?*/
1340 ath5k_hw_reg_write(ah, phys_addr, AR5K_RXDP);
1344 * Transmit functions
1348 * Start DMA transmit for a specific queue
1349 * (see also QCU/DCU functions)
1351 int ath5k_hw_tx_start(struct ath5k_hw *ah, unsigned int queue)
1355 ATH5K_TRACE(ah->ah_sc);
1356 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1358 /* Return if queue is declared inactive */
1359 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1362 if (ah->ah_version == AR5K_AR5210) {
1363 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1366 * Set the queue by type on 5210
1368 switch (ah->ah_txq[queue].tqi_type) {
1369 case AR5K_TX_QUEUE_DATA:
1370 tx_queue |= AR5K_CR_TXE0 & ~AR5K_CR_TXD0;
1372 case AR5K_TX_QUEUE_BEACON:
1373 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1374 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
1377 case AR5K_TX_QUEUE_CAB:
1378 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1379 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1FV | AR5K_BCR_TQ1V |
1380 AR5K_BCR_BDMAE, AR5K_BSR);
1386 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1388 /* Return if queue is disabled */
1389 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXD, queue))
1393 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXE, queue);
1400 * Stop DMA transmit for a specific queue
1401 * (see also QCU/DCU functions)
1403 int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue)
1405 unsigned int i = 100;
1406 u32 tx_queue, pending;
1408 ATH5K_TRACE(ah->ah_sc);
1409 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1411 /* Return if queue is declared inactive */
1412 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1415 if (ah->ah_version == AR5K_AR5210) {
1416 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1421 switch (ah->ah_txq[queue].tqi_type) {
1422 case AR5K_TX_QUEUE_DATA:
1423 tx_queue |= AR5K_CR_TXD0 & ~AR5K_CR_TXE0;
1425 case AR5K_TX_QUEUE_BEACON:
1426 case AR5K_TX_QUEUE_CAB:
1428 tx_queue |= AR5K_CR_TXD1 & ~AR5K_CR_TXD1;
1429 ath5k_hw_reg_write(ah, 0, AR5K_BSR);
1436 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1439 * Schedule TX disable and wait until queue is empty
1441 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXD, queue);
1443 /*Check for pending frames*/
1445 pending = ath5k_hw_reg_read(ah,
1446 AR5K_QUEUE_STATUS(queue)) &
1447 AR5K_QCU_STS_FRMPENDCNT;
1449 } while (--i && pending);
1451 /* Clear register */
1452 ath5k_hw_reg_write(ah, 0, AR5K_QCU_TXD);
1455 /* TODO: Check for success else return error */
1460 * Get the address of the TX Descriptor for a specific queue
1461 * (see also QCU/DCU functions)
1463 u32 ath5k_hw_get_tx_buf(struct ath5k_hw *ah, unsigned int queue)
1467 ATH5K_TRACE(ah->ah_sc);
1468 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1471 * Get the transmit queue descriptor pointer from the selected queue
1473 /*5210 doesn't have QCU*/
1474 if (ah->ah_version == AR5K_AR5210) {
1475 switch (ah->ah_txq[queue].tqi_type) {
1476 case AR5K_TX_QUEUE_DATA:
1477 tx_reg = AR5K_NOQCU_TXDP0;
1479 case AR5K_TX_QUEUE_BEACON:
1480 case AR5K_TX_QUEUE_CAB:
1481 tx_reg = AR5K_NOQCU_TXDP1;
1487 tx_reg = AR5K_QUEUE_TXDP(queue);
1490 return ath5k_hw_reg_read(ah, tx_reg);
1494 * Set the address of the TX Descriptor for a specific queue
1495 * (see also QCU/DCU functions)
1497 int ath5k_hw_put_tx_buf(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
1501 ATH5K_TRACE(ah->ah_sc);
1502 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1505 * Set the transmit queue descriptor pointer register by type
1508 if (ah->ah_version == AR5K_AR5210) {
1509 switch (ah->ah_txq[queue].tqi_type) {
1510 case AR5K_TX_QUEUE_DATA:
1511 tx_reg = AR5K_NOQCU_TXDP0;
1513 case AR5K_TX_QUEUE_BEACON:
1514 case AR5K_TX_QUEUE_CAB:
1515 tx_reg = AR5K_NOQCU_TXDP1;
1522 * Set the transmit queue descriptor pointer for
1523 * the selected queue on QCU for 5211+
1524 * (this won't work if the queue is still active)
1526 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
1529 tx_reg = AR5K_QUEUE_TXDP(queue);
1532 /* Set descriptor pointer */
1533 ath5k_hw_reg_write(ah, phys_addr, tx_reg);
1539 * Update tx trigger level
1541 int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase)
1543 u32 trigger_level, imr;
1546 ATH5K_TRACE(ah->ah_sc);
1549 * Disable interrupts by setting the mask
1551 imr = ath5k_hw_set_intr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
1553 /*TODO: Boundary check on trigger_level*/
1554 trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
1558 if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
1562 ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
1565 * Update trigger level on success
1567 if (ah->ah_version == AR5K_AR5210)
1568 ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
1570 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
1571 AR5K_TXCFG_TXFULL, trigger_level);
1577 * Restore interrupt mask
1579 ath5k_hw_set_intr(ah, imr);
1585 * Interrupt handling
1589 * Check if we have pending interrupts
1591 bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
1593 ATH5K_TRACE(ah->ah_sc);
1594 return ath5k_hw_reg_read(ah, AR5K_INTPEND);
1598 * Get interrupt mask (ISR)
1600 int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
1604 ATH5K_TRACE(ah->ah_sc);
1607 * Read interrupt status from the Interrupt Status register
1610 if (ah->ah_version == AR5K_AR5210) {
1611 data = ath5k_hw_reg_read(ah, AR5K_ISR);
1612 if (unlikely(data == AR5K_INT_NOCARD)) {
1613 *interrupt_mask = data;
1618 * Read interrupt status from the Read-And-Clear shadow register
1619 * Note: PISR/SISR Not available on 5210
1621 data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
1625 * Get abstract interrupt mask (driver-compatible)
1627 *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
1629 if (unlikely(data == AR5K_INT_NOCARD))
1632 if (data & (AR5K_ISR_RXOK | AR5K_ISR_RXERR))
1633 *interrupt_mask |= AR5K_INT_RX;
1635 if (data & (AR5K_ISR_TXOK | AR5K_ISR_TXERR
1636 | AR5K_ISR_TXDESC | AR5K_ISR_TXEOL))
1637 *interrupt_mask |= AR5K_INT_TX;
1639 if (ah->ah_version != AR5K_AR5210) {
1640 /*HIU = Host Interface Unit (PCI etc)*/
1641 if (unlikely(data & (AR5K_ISR_HIUERR)))
1642 *interrupt_mask |= AR5K_INT_FATAL;
1644 /*Beacon Not Ready*/
1645 if (unlikely(data & (AR5K_ISR_BNR)))
1646 *interrupt_mask |= AR5K_INT_BNR;
1650 * XXX: BMISS interrupts may occur after association.
1651 * I found this on 5210 code but it needs testing. If this is
1652 * true we should disable them before assoc and re-enable them
1653 * after a successfull assoc + some jiffies.
1656 interrupt_mask &= ~AR5K_INT_BMISS;
1660 * In case we didn't handle anything,
1661 * print the register value.
1663 if (unlikely(*interrupt_mask == 0 && net_ratelimit()))
1664 ATH5K_PRINTF("0x%08x\n", data);
1670 * Set interrupt mask
1672 enum ath5k_int ath5k_hw_set_intr(struct ath5k_hw *ah, enum ath5k_int new_mask)
1674 enum ath5k_int old_mask, int_mask;
1677 * Disable card interrupts to prevent any race conditions
1678 * (they will be re-enabled afterwards).
1680 ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
1682 old_mask = ah->ah_imr;
1685 * Add additional, chipset-dependent interrupt mask flags
1686 * and write them to the IMR (interrupt mask register).
1688 int_mask = new_mask & AR5K_INT_COMMON;
1690 if (new_mask & AR5K_INT_RX)
1691 int_mask |= AR5K_IMR_RXOK | AR5K_IMR_RXERR | AR5K_IMR_RXORN |
1694 if (new_mask & AR5K_INT_TX)
1695 int_mask |= AR5K_IMR_TXOK | AR5K_IMR_TXERR | AR5K_IMR_TXDESC |
1698 if (ah->ah_version != AR5K_AR5210) {
1699 if (new_mask & AR5K_INT_FATAL) {
1700 int_mask |= AR5K_IMR_HIUERR;
1701 AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_MCABT |
1702 AR5K_SIMR2_SSERR | AR5K_SIMR2_DPERR);
1706 ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
1708 /* Store new interrupt mask */
1709 ah->ah_imr = new_mask;
1711 /* ..re-enable interrupts */
1712 ath5k_hw_reg_write(ah, AR5K_IER_ENABLE, AR5K_IER);
1718 /*************************\
1719 EEPROM access functions
1720 \*************************/
1725 static int ath5k_hw_eeprom_read(struct ath5k_hw *ah, u32 offset, u16 *data)
1727 u32 status, timeout;
1729 ATH5K_TRACE(ah->ah_sc);
1731 * Initialize EEPROM access
1733 if (ah->ah_version == AR5K_AR5210) {
1734 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1735 (void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset));
1737 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1738 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1739 AR5K_EEPROM_CMD_READ);
1742 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1743 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1744 if (status & AR5K_EEPROM_STAT_RDDONE) {
1745 if (status & AR5K_EEPROM_STAT_RDERR)
1747 *data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) &
1758 * Write to eeprom - currently disabled, use at your own risk
1761 static int ath5k_hw_eeprom_write(struct ath5k_hw *ah, u32 offset, u16 data)
1764 u32 status, timeout;
1766 ATH5K_TRACE(ah->ah_sc);
1769 * Initialize eeprom access
1772 if (ah->ah_version == AR5K_AR5210) {
1773 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1775 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1776 AR5K_EEPROM_CMD_RESET);
1780 * Write data to data register
1783 if (ah->ah_version == AR5K_AR5210) {
1784 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_BASE + (4 * offset));
1786 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1787 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_DATA);
1788 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1789 AR5K_EEPROM_CMD_WRITE);
1796 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1797 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1798 if (status & AR5K_EEPROM_STAT_WRDONE) {
1799 if (status & AR5K_EEPROM_STAT_WRERR)
1806 ATH5K_ERR(ah->ah_sc, "EEPROM Write is disabled!");
1812 * Translate binary channel representation in EEPROM to frequency
1814 static u16 ath5k_eeprom_bin2freq(struct ath5k_hw *ah, u16 bin, unsigned int mode)
1818 if (bin == AR5K_EEPROM_CHANNEL_DIS)
1821 if (mode == AR5K_EEPROM_MODE_11A) {
1822 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1823 val = (5 * bin) + 4800;
1825 val = bin > 62 ? (10 * 62) + (5 * (bin - 62)) + 5100 :
1828 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1838 * Read antenna infos from eeprom
1840 static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
1843 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1848 AR5K_EEPROM_READ(o++, val);
1849 ee->ee_switch_settling[mode] = (val >> 8) & 0x7f;
1850 ee->ee_ant_tx_rx[mode] = (val >> 2) & 0x3f;
1851 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1853 AR5K_EEPROM_READ(o++, val);
1854 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1855 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1856 ee->ee_ant_control[mode][i++] = val & 0x3f;
1858 AR5K_EEPROM_READ(o++, val);
1859 ee->ee_ant_control[mode][i++] = (val >> 10) & 0x3f;
1860 ee->ee_ant_control[mode][i++] = (val >> 4) & 0x3f;
1861 ee->ee_ant_control[mode][i] = (val << 2) & 0x3f;
1863 AR5K_EEPROM_READ(o++, val);
1864 ee->ee_ant_control[mode][i++] |= (val >> 14) & 0x3;
1865 ee->ee_ant_control[mode][i++] = (val >> 8) & 0x3f;
1866 ee->ee_ant_control[mode][i++] = (val >> 2) & 0x3f;
1867 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1869 AR5K_EEPROM_READ(o++, val);
1870 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1871 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1872 ee->ee_ant_control[mode][i++] = val & 0x3f;
1874 /* Get antenna modes */
1875 ah->ah_antenna[mode][0] =
1876 (ee->ee_ant_control[mode][0] << 4) | 0x1;
1877 ah->ah_antenna[mode][AR5K_ANT_FIXED_A] =
1878 ee->ee_ant_control[mode][1] |
1879 (ee->ee_ant_control[mode][2] << 6) |
1880 (ee->ee_ant_control[mode][3] << 12) |
1881 (ee->ee_ant_control[mode][4] << 18) |
1882 (ee->ee_ant_control[mode][5] << 24);
1883 ah->ah_antenna[mode][AR5K_ANT_FIXED_B] =
1884 ee->ee_ant_control[mode][6] |
1885 (ee->ee_ant_control[mode][7] << 6) |
1886 (ee->ee_ant_control[mode][8] << 12) |
1887 (ee->ee_ant_control[mode][9] << 18) |
1888 (ee->ee_ant_control[mode][10] << 24);
1890 /* return new offset */
1897 * Read supported modes from eeprom
1899 static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset,
1902 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1907 AR5K_EEPROM_READ(o++, val);
1908 ee->ee_tx_end2xlna_enable[mode] = (val >> 8) & 0xff;
1909 ee->ee_thr_62[mode] = val & 0xff;
1911 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1912 ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28;
1914 AR5K_EEPROM_READ(o++, val);
1915 ee->ee_tx_end2xpa_disable[mode] = (val >> 8) & 0xff;
1916 ee->ee_tx_frm2xpa_enable[mode] = val & 0xff;
1918 AR5K_EEPROM_READ(o++, val);
1919 ee->ee_pga_desired_size[mode] = (val >> 8) & 0xff;
1921 if ((val & 0xff) & 0x80)
1922 ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1);
1924 ee->ee_noise_floor_thr[mode] = val & 0xff;
1926 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1927 ee->ee_noise_floor_thr[mode] =
1928 mode == AR5K_EEPROM_MODE_11A ? -54 : -1;
1930 AR5K_EEPROM_READ(o++, val);
1931 ee->ee_xlna_gain[mode] = (val >> 5) & 0xff;
1932 ee->ee_x_gain[mode] = (val >> 1) & 0xf;
1933 ee->ee_xpd[mode] = val & 0x1;
1935 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0)
1936 ee->ee_fixed_bias[mode] = (val >> 13) & 0x1;
1938 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) {
1939 AR5K_EEPROM_READ(o++, val);
1940 ee->ee_false_detect[mode] = (val >> 6) & 0x7f;
1942 if (mode == AR5K_EEPROM_MODE_11A)
1943 ee->ee_xr_power[mode] = val & 0x3f;
1945 ee->ee_ob[mode][0] = val & 0x7;
1946 ee->ee_db[mode][0] = (val >> 3) & 0x7;
1950 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) {
1951 ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN;
1952 ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA;
1954 ee->ee_i_gain[mode] = (val >> 13) & 0x7;
1956 AR5K_EEPROM_READ(o++, val);
1957 ee->ee_i_gain[mode] |= (val << 3) & 0x38;
1959 if (mode == AR5K_EEPROM_MODE_11G)
1960 ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff;
1963 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
1964 mode == AR5K_EEPROM_MODE_11A) {
1965 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
1966 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
1969 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6 &&
1970 mode == AR5K_EEPROM_MODE_11G)
1971 ee->ee_scaled_cck_delta = (val >> 11) & 0x1f;
1973 /* return new offset */
1980 * Initialize eeprom & capabilities structs
1982 static int ath5k_eeprom_init(struct ath5k_hw *ah)
1984 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1985 unsigned int mode, i;
1990 /* Initial TX thermal adjustment values */
1992 ee->ee_pwd_84 = ee->ee_pwd_90 = 1;
1993 ee->ee_gain_select = 1;
1996 * Read values from EEPROM and store them in the capability structure
1998 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC, ee_magic);
1999 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT, ee_protect);
2000 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN, ee_regdomain);
2001 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION, ee_version);
2002 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR, ee_header);
2004 /* Return if we have an old EEPROM */
2005 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_0)
2010 * Validate the checksum of the EEPROM date. There are some
2011 * devices with invalid EEPROMs.
2013 for (cksum = 0, offset = 0; offset < AR5K_EEPROM_INFO_MAX; offset++) {
2014 AR5K_EEPROM_READ(AR5K_EEPROM_INFO(offset), val);
2017 if (cksum != AR5K_EEPROM_INFO_CKSUM) {
2018 ATH5K_ERR(ah->ah_sc, "Invalid EEPROM checksum 0x%04x\n", cksum);
2023 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah->ah_ee_version),
2026 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2027 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0, ee_misc0);
2028 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1, ee_misc1);
2031 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_3) {
2032 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ, val);
2033 ee->ee_ob[AR5K_EEPROM_MODE_11B][0] = val & 0x7;
2034 ee->ee_db[AR5K_EEPROM_MODE_11B][0] = (val >> 3) & 0x7;
2036 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ, val);
2037 ee->ee_ob[AR5K_EEPROM_MODE_11G][0] = val & 0x7;
2038 ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7;
2042 * Get conformance test limit values
2044 offset = AR5K_EEPROM_CTL(ah->ah_ee_version);
2045 ee->ee_ctls = AR5K_EEPROM_N_CTLS(ah->ah_ee_version);
2047 for (i = 0; i < ee->ee_ctls; i++) {
2048 AR5K_EEPROM_READ(offset++, val);
2049 ee->ee_ctl[i] = (val >> 8) & 0xff;
2050 ee->ee_ctl[i + 1] = val & 0xff;
2054 * Get values for 802.11a (5GHz)
2056 mode = AR5K_EEPROM_MODE_11A;
2058 ee->ee_turbo_max_power[mode] =
2059 AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header);
2061 offset = AR5K_EEPROM_MODES_11A(ah->ah_ee_version);
2063 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2067 AR5K_EEPROM_READ(offset++, val);
2068 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2069 ee->ee_ob[mode][3] = (val >> 5) & 0x7;
2070 ee->ee_db[mode][3] = (val >> 2) & 0x7;
2071 ee->ee_ob[mode][2] = (val << 1) & 0x7;
2073 AR5K_EEPROM_READ(offset++, val);
2074 ee->ee_ob[mode][2] |= (val >> 15) & 0x1;
2075 ee->ee_db[mode][2] = (val >> 12) & 0x7;
2076 ee->ee_ob[mode][1] = (val >> 9) & 0x7;
2077 ee->ee_db[mode][1] = (val >> 6) & 0x7;
2078 ee->ee_ob[mode][0] = (val >> 3) & 0x7;
2079 ee->ee_db[mode][0] = val & 0x7;
2081 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2085 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1) {
2086 AR5K_EEPROM_READ(offset++, val);
2087 ee->ee_margin_tx_rx[mode] = val & 0x3f;
2091 * Get values for 802.11b (2.4GHz)
2093 mode = AR5K_EEPROM_MODE_11B;
2094 offset = AR5K_EEPROM_MODES_11B(ah->ah_ee_version);
2096 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2100 AR5K_EEPROM_READ(offset++, val);
2101 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2102 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
2103 ee->ee_db[mode][1] = val & 0x7;
2105 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2109 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2110 AR5K_EEPROM_READ(offset++, val);
2111 ee->ee_cal_pier[mode][0] =
2112 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2113 ee->ee_cal_pier[mode][1] =
2114 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
2116 AR5K_EEPROM_READ(offset++, val);
2117 ee->ee_cal_pier[mode][2] =
2118 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2121 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
2122 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
2125 * Get values for 802.11g (2.4GHz)
2127 mode = AR5K_EEPROM_MODE_11G;
2128 offset = AR5K_EEPROM_MODES_11G(ah->ah_ee_version);
2130 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2134 AR5K_EEPROM_READ(offset++, val);
2135 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2136 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
2137 ee->ee_db[mode][1] = val & 0x7;
2139 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2143 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2144 AR5K_EEPROM_READ(offset++, val);
2145 ee->ee_cal_pier[mode][0] =
2146 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2147 ee->ee_cal_pier[mode][1] =
2148 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
2150 AR5K_EEPROM_READ(offset++, val);
2151 ee->ee_turbo_max_power[mode] = val & 0x7f;
2152 ee->ee_xr_power[mode] = (val >> 7) & 0x3f;
2154 AR5K_EEPROM_READ(offset++, val);
2155 ee->ee_cal_pier[mode][2] =
2156 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2158 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
2159 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
2161 AR5K_EEPROM_READ(offset++, val);
2162 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
2163 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
2165 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) {
2166 AR5K_EEPROM_READ(offset++, val);
2167 ee->ee_cck_ofdm_gain_delta = val & 0xff;
2172 * Read 5GHz EEPROM channels
2179 * Read the MAC address from eeprom
2181 static int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
2188 memset(mac, 0, ETH_ALEN);
2189 memset(mac_d, 0, ETH_ALEN);
2191 ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
2195 for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
2196 ret = ath5k_hw_eeprom_read(ah, offset, &data);
2201 mac_d[octet + 1] = data & 0xff;
2202 mac_d[octet] = data >> 8;
2206 memcpy(mac, mac_d, ETH_ALEN);
2208 if (!total || total == 3 * 0xffff)
2215 * Fill the capabilities struct
2217 static int ath5k_hw_get_capabilities(struct ath5k_hw *ah)
2221 ATH5K_TRACE(ah->ah_sc);
2222 /* Capabilities stored in the EEPROM */
2223 ee_header = ah->ah_capabilities.cap_eeprom.ee_header;
2225 if (ah->ah_version == AR5K_AR5210) {
2227 * Set radio capabilities
2228 * (The AR5110 only supports the middle 5GHz band)
2230 ah->ah_capabilities.cap_range.range_5ghz_min = 5120;
2231 ah->ah_capabilities.cap_range.range_5ghz_max = 5430;
2232 ah->ah_capabilities.cap_range.range_2ghz_min = 0;
2233 ah->ah_capabilities.cap_range.range_2ghz_max = 0;
2235 /* Set supported modes */
2236 __set_bit(AR5K_MODE_11A, ah->ah_capabilities.cap_mode);
2237 __set_bit(AR5K_MODE_11A_TURBO, ah->ah_capabilities.cap_mode);
2240 * XXX The tranceiver supports frequencies from 4920 to 6100GHz
2241 * XXX and from 2312 to 2732GHz. There are problems with the
2242 * XXX current ieee80211 implementation because the IEEE
2243 * XXX channel mapping does not support negative channel
2244 * XXX numbers (2312MHz is channel -19). Of course, this
2245 * XXX doesn't matter because these channels are out of range
2246 * XXX but some regulation domains like MKK (Japan) will
2247 * XXX support frequencies somewhere around 4.8GHz.
2251 * Set radio capabilities
2254 if (AR5K_EEPROM_HDR_11A(ee_header)) {
2255 ah->ah_capabilities.cap_range.range_5ghz_min = 5005; /* 4920 */
2256 ah->ah_capabilities.cap_range.range_5ghz_max = 6100;
2258 /* Set supported modes */
2259 __set_bit(AR5K_MODE_11A,
2260 ah->ah_capabilities.cap_mode);
2261 __set_bit(AR5K_MODE_11A_TURBO,
2262 ah->ah_capabilities.cap_mode);
2263 if (ah->ah_version == AR5K_AR5212)
2264 __set_bit(AR5K_MODE_11G_TURBO,
2265 ah->ah_capabilities.cap_mode);
2268 /* Enable 802.11b if a 2GHz capable radio (2111/5112) is
2270 if (AR5K_EEPROM_HDR_11B(ee_header) ||
2271 AR5K_EEPROM_HDR_11G(ee_header)) {
2272 ah->ah_capabilities.cap_range.range_2ghz_min = 2412; /* 2312 */
2273 ah->ah_capabilities.cap_range.range_2ghz_max = 2732;
2275 if (AR5K_EEPROM_HDR_11B(ee_header))
2276 __set_bit(AR5K_MODE_11B,
2277 ah->ah_capabilities.cap_mode);
2279 if (AR5K_EEPROM_HDR_11G(ee_header))
2280 __set_bit(AR5K_MODE_11G,
2281 ah->ah_capabilities.cap_mode);
2286 ah->ah_gpio_npins = AR5K_NUM_GPIO;
2288 /* Set number of supported TX queues */
2289 if (ah->ah_version == AR5K_AR5210)
2290 ah->ah_capabilities.cap_queues.q_tx_num =
2291 AR5K_NUM_TX_QUEUES_NOQCU;
2293 ah->ah_capabilities.cap_queues.q_tx_num = AR5K_NUM_TX_QUEUES;
2298 /*********************************\
2299 Protocol Control Unit Functions
2300 \*********************************/
2303 * Set Operation mode
2305 int ath5k_hw_set_opmode(struct ath5k_hw *ah)
2307 u32 pcu_reg, beacon_reg, low_id, high_id;
2312 ATH5K_TRACE(ah->ah_sc);
2314 switch (ah->ah_op_mode) {
2315 case IEEE80211_IF_TYPE_IBSS:
2316 pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_DESC_ANTENNA |
2317 (ah->ah_version == AR5K_AR5210 ?
2318 AR5K_STA_ID1_NO_PSPOLL : 0);
2319 beacon_reg |= AR5K_BCR_ADHOC;
2322 case IEEE80211_IF_TYPE_AP:
2323 pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_RTS_DEF_ANTENNA |
2324 (ah->ah_version == AR5K_AR5210 ?
2325 AR5K_STA_ID1_NO_PSPOLL : 0);
2326 beacon_reg |= AR5K_BCR_AP;
2329 case IEEE80211_IF_TYPE_STA:
2330 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2331 (ah->ah_version == AR5K_AR5210 ?
2332 AR5K_STA_ID1_PWR_SV : 0);
2333 case IEEE80211_IF_TYPE_MNTR:
2334 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2335 (ah->ah_version == AR5K_AR5210 ?
2336 AR5K_STA_ID1_NO_PSPOLL : 0);
2346 low_id = AR5K_LOW_ID(ah->ah_sta_id);
2347 high_id = AR5K_HIGH_ID(ah->ah_sta_id);
2348 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2349 ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
2352 * Set Beacon Control Register on 5210
2354 if (ah->ah_version == AR5K_AR5210)
2355 ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR);
2367 void ath5k_hw_get_lladdr(struct ath5k_hw *ah, u8 *mac)
2369 ATH5K_TRACE(ah->ah_sc);
2370 memcpy(mac, ah->ah_sta_id, ETH_ALEN);
2376 int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
2378 u32 low_id, high_id;
2380 ATH5K_TRACE(ah->ah_sc);
2381 /* Set new station ID */
2382 memcpy(ah->ah_sta_id, mac, ETH_ALEN);
2384 low_id = AR5K_LOW_ID(mac);
2385 high_id = AR5K_HIGH_ID(mac);
2387 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2388 ath5k_hw_reg_write(ah, high_id, AR5K_STA_ID1);
2396 void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id)
2398 u32 low_id, high_id;
2402 * Set simple BSSID mask on 5212
2404 if (ah->ah_version == AR5K_AR5212) {
2405 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM0);
2406 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM1);
2410 * Set BSSID which triggers the "SME Join" operation
2412 low_id = AR5K_LOW_ID(bssid);
2413 high_id = AR5K_HIGH_ID(bssid);
2414 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_ID0);
2415 ath5k_hw_reg_write(ah, high_id | ((assoc_id & 0x3fff) <<
2416 AR5K_BSS_ID1_AID_S), AR5K_BSS_ID1);
2418 if (assoc_id == 0) {
2419 ath5k_hw_disable_pspoll(ah);
2423 AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM,
2424 tim_offset ? tim_offset + 4 : 0);
2426 ath5k_hw_enable_pspoll(ah, NULL, 0);
2429 * ath5k_hw_set_bssid_mask - set common bits we should listen to
2431 * The bssid_mask is a utility used by AR5212 hardware to inform the hardware
2432 * which bits of the interface's MAC address should be looked at when trying
2433 * to decide which packets to ACK. In station mode every bit matters. In AP
2434 * mode with a single BSS every bit matters as well. In AP mode with
2435 * multiple BSSes not every bit matters.
2437 * @ah: the &struct ath5k_hw
2438 * @mask: the bssid_mask, a u8 array of size ETH_ALEN
2440 * Note that this is a simple filter and *does* not filter out all
2441 * relevant frames. Some non-relevant frames will get through, probability
2442 * jocks are welcomed to compute.
2444 * When handling multiple BSSes (or VAPs) you can get the BSSID mask by
2445 * computing the set of:
2447 * ~ ( MAC XOR BSSID )
2449 * When you do this you are essentially computing the common bits. Later it
2450 * is assumed the harware will "and" (&) the BSSID mask with the MAC address
2451 * to obtain the relevant bits which should match on the destination frame.
2453 * Simple example: on your card you have have two BSSes you have created with
2454 * BSSID-01 and BSSID-02. Lets assume BSSID-01 will not use the MAC address.
2455 * There is another BSSID-03 but you are not part of it. For simplicity's sake,
2456 * assuming only 4 bits for a mac address and for BSSIDs you can then have:
2460 * BSSID-01: 0100 | --> Belongs to us
2463 * -------------------
2464 * BSSID-03: 0110 | --> External
2465 * -------------------
2467 * Our bssid_mask would then be:
2469 * On loop iteration for BSSID-01:
2470 * ~(0001 ^ 0100) -> ~(0101)
2474 * On loop iteration for BSSID-02:
2475 * bssid_mask &= ~(0001 ^ 1001)
2476 * bssid_mask = (1010) & ~(0001 ^ 1001)
2477 * bssid_mask = (1010) & ~(1001)
2478 * bssid_mask = (1010) & (0110)
2481 * A bssid_mask of 0010 means "only pay attention to the second least
2482 * significant bit". This is because its the only bit common
2483 * amongst the MAC and all BSSIDs we support. To findout what the real
2484 * common bit is we can simply "&" the bssid_mask now with any BSSID we have
2485 * or our MAC address (we assume the hardware uses the MAC address).
2487 * Now, suppose there's an incoming frame for BSSID-03:
2491 * An easy eye-inspeciton of this already should tell you that this frame
2492 * will not pass our check. This is beacuse the bssid_mask tells the
2493 * hardware to only look at the second least significant bit and the
2494 * common bit amongst the MAC and BSSIDs is 0, this frame has the 2nd LSB
2495 * as 1, which does not match 0.
2497 * So with IFRAME-01 we *assume* the hardware will do:
2499 * allow = (IFRAME-01 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2500 * --> allow = (0110 & 0010) == (0010 & 0001) ? 1 : 0;
2501 * --> allow = (0010) == 0000 ? 1 : 0;
2504 * Lets now test a frame that should work:
2506 * IFRAME-02: 0001 (we should allow)
2508 * allow = (0001 & 1010) == 1010
2510 * allow = (IFRAME-02 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2511 * --> allow = (0001 & 0010) == (0010 & 0001) ? 1 :0;
2512 * --> allow = (0010) == (0010)
2517 * IFRAME-03: 0100 --> allowed
2518 * IFRAME-04: 1001 --> allowed
2519 * IFRAME-05: 1101 --> allowed but its not for us!!!
2522 int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
2524 u32 low_id, high_id;
2525 ATH5K_TRACE(ah->ah_sc);
2527 if (ah->ah_version == AR5K_AR5212) {
2528 low_id = AR5K_LOW_ID(mask);
2529 high_id = AR5K_HIGH_ID(mask);
2531 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_IDM0);
2532 ath5k_hw_reg_write(ah, high_id, AR5K_BSS_IDM1);
2541 * Receive start/stop functions
2545 * Start receive on PCU
2547 void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
2549 ATH5K_TRACE(ah->ah_sc);
2550 AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
2552 /* TODO: ANI Support */
2556 * Stop receive on PCU
2558 void ath5k_hw_stop_pcu_recv(struct ath5k_hw *ah)
2560 ATH5K_TRACE(ah->ah_sc);
2561 AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
2563 /* TODO: ANI Support */
2567 * RX Filter functions
2571 * Set multicast filter
2573 void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
2575 ATH5K_TRACE(ah->ah_sc);
2576 /* Set the multicat filter */
2577 ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0);
2578 ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1);
2582 * Set multicast filter by index
2584 int ath5k_hw_set_mcast_filterindex(struct ath5k_hw *ah, u32 index)
2587 ATH5K_TRACE(ah->ah_sc);
2590 else if (index >= 32)
2591 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER1,
2592 (1 << (index - 32)));
2594 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2600 * Clear Multicast filter by index
2602 int ath5k_hw_clear_mcast_filter_idx(struct ath5k_hw *ah, u32 index)
2605 ATH5K_TRACE(ah->ah_sc);
2608 else if (index >= 32)
2609 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER1,
2610 (1 << (index - 32)));
2612 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2618 * Get current rx filter
2620 u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah)
2622 u32 data, filter = 0;
2624 ATH5K_TRACE(ah->ah_sc);
2625 filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER);
2627 /*Radar detection for 5212*/
2628 if (ah->ah_version == AR5K_AR5212) {
2629 data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL);
2631 if (data & AR5K_PHY_ERR_FIL_RADAR)
2632 filter |= AR5K_RX_FILTER_RADARERR;
2633 if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK))
2634 filter |= AR5K_RX_FILTER_PHYERR;
2643 void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
2647 ATH5K_TRACE(ah->ah_sc);
2649 /* Set PHY error filter register on 5212*/
2650 if (ah->ah_version == AR5K_AR5212) {
2651 if (filter & AR5K_RX_FILTER_RADARERR)
2652 data |= AR5K_PHY_ERR_FIL_RADAR;
2653 if (filter & AR5K_RX_FILTER_PHYERR)
2654 data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK;
2658 * The AR5210 uses promiscous mode to detect radar activity
2660 if (ah->ah_version == AR5K_AR5210 &&
2661 (filter & AR5K_RX_FILTER_RADARERR)) {
2662 filter &= ~AR5K_RX_FILTER_RADARERR;
2663 filter |= AR5K_RX_FILTER_PROM;
2668 AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2670 AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2672 /*Write RX Filter register*/
2673 ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER);
2675 /*Write PHY error filter register on 5212*/
2676 if (ah->ah_version == AR5K_AR5212)
2677 ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
2682 * Beacon related functions
2688 u32 ath5k_hw_get_tsf32(struct ath5k_hw *ah)
2690 ATH5K_TRACE(ah->ah_sc);
2691 return ath5k_hw_reg_read(ah, AR5K_TSF_L32);
2695 * Get the full 64bit TSF
2697 u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah)
2699 u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
2700 ATH5K_TRACE(ah->ah_sc);
2702 return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32);
2708 void ath5k_hw_reset_tsf(struct ath5k_hw *ah)
2710 ATH5K_TRACE(ah->ah_sc);
2711 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_RESET_TSF);
2715 * Initialize beacon timers
2717 void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
2719 u32 timer1, timer2, timer3;
2721 ATH5K_TRACE(ah->ah_sc);
2723 * Set the additional timers by mode
2725 switch (ah->ah_op_mode) {
2726 case IEEE80211_IF_TYPE_STA:
2727 if (ah->ah_version == AR5K_AR5210) {
2728 timer1 = 0xffffffff;
2729 timer2 = 0xffffffff;
2731 timer1 = 0x0000ffff;
2732 timer2 = 0x0007ffff;
2737 timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3;
2738 timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3;
2741 timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1);
2744 * Set the beacon register and enable all timers.
2745 * (next beacon, DMA beacon, software beacon, ATIM window time)
2747 ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
2748 ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
2749 ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
2750 ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
2752 ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD |
2753 AR5K_BEACON_RESET_TSF | AR5K_BEACON_ENABLE),
2761 int ath5k_hw_set_beacon_timers(struct ath5k_hw *ah,
2762 const struct ath5k_beacon_state *state)
2764 u32 cfp_period, next_cfp, dtim, interval, next_beacon;
2767 * TODO: should be changed through *state
2768 * review struct ath5k_beacon_state struct
2770 * XXX: These are used for cfp period bellow, are they
2771 * ok ? Is it O.K. for tsf here to be 0 or should we use
2774 u32 dtim_count = 0; /* XXX */
2775 u32 cfp_count = 0; /* XXX */
2776 u32 tsf = 0; /* XXX */
2778 ATH5K_TRACE(ah->ah_sc);
2779 /* Return on an invalid beacon state */
2780 if (state->bs_interval < 1)
2783 interval = state->bs_interval;
2784 dtim = state->bs_dtim_period;
2789 if (state->bs_cfp_period > 0) {
2791 * Enable PCF mode and set the CFP
2792 * (Contention Free Period) and timer registers
2794 cfp_period = state->bs_cfp_period * state->bs_dtim_period *
2796 next_cfp = (cfp_count * state->bs_dtim_period + dtim_count) *
2799 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
2800 AR5K_STA_ID1_DEFAULT_ANTENNA |
2802 ath5k_hw_reg_write(ah, cfp_period, AR5K_CFP_PERIOD);
2803 ath5k_hw_reg_write(ah, state->bs_cfp_max_duration,
2805 ath5k_hw_reg_write(ah, (tsf + (next_cfp == 0 ? cfp_period :
2806 next_cfp)) << 3, AR5K_TIMER2);
2808 /* Disable PCF mode */
2809 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2810 AR5K_STA_ID1_DEFAULT_ANTENNA |
2815 * Enable the beacon timer register
2817 ath5k_hw_reg_write(ah, state->bs_next_beacon, AR5K_TIMER0);
2820 * Start the beacon timers
2822 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_BEACON) &~
2823 (AR5K_BEACON_PERIOD | AR5K_BEACON_TIM)) |
2824 AR5K_REG_SM(state->bs_tim_offset ? state->bs_tim_offset + 4 : 0,
2825 AR5K_BEACON_TIM) | AR5K_REG_SM(state->bs_interval,
2826 AR5K_BEACON_PERIOD), AR5K_BEACON);
2829 * Write new beacon miss threshold, if it appears to be valid
2830 * XXX: Figure out right values for min <= bs_bmiss_threshold <= max
2831 * and return if its not in range. We can test this by reading value and
2832 * setting value to a largest value and seeing which values register.
2835 AR5K_REG_WRITE_BITS(ah, AR5K_RSSI_THR, AR5K_RSSI_THR_BMISS,
2836 state->bs_bmiss_threshold);
2839 * Set sleep control register
2840 * XXX: Didn't find this in 5210 code but since this register
2841 * exists also in ar5k's 5210 headers i leave it as common code.
2843 AR5K_REG_WRITE_BITS(ah, AR5K_SLEEP_CTL, AR5K_SLEEP_CTL_SLDUR,
2844 (state->bs_sleep_duration - 3) << 3);
2847 * Set enhanced sleep registers on 5212
2849 if (ah->ah_version == AR5K_AR5212) {
2850 if (state->bs_sleep_duration > state->bs_interval &&
2851 roundup(state->bs_sleep_duration, interval) ==
2852 state->bs_sleep_duration)
2853 interval = state->bs_sleep_duration;
2855 if (state->bs_sleep_duration > dtim && (dtim == 0 ||
2856 roundup(state->bs_sleep_duration, dtim) ==
2857 state->bs_sleep_duration))
2858 dtim = state->bs_sleep_duration;
2860 if (interval > dtim)
2863 next_beacon = interval == dtim ? state->bs_next_dtim :
2864 state->bs_next_beacon;
2866 ath5k_hw_reg_write(ah,
2867 AR5K_REG_SM((state->bs_next_dtim - 3) << 3,
2868 AR5K_SLEEP0_NEXT_DTIM) |
2869 AR5K_REG_SM(10, AR5K_SLEEP0_CABTO) |
2870 AR5K_SLEEP0_ENH_SLEEP_EN |
2871 AR5K_SLEEP0_ASSUME_DTIM, AR5K_SLEEP0);
2873 ath5k_hw_reg_write(ah, AR5K_REG_SM((next_beacon - 3) << 3,
2874 AR5K_SLEEP1_NEXT_TIM) |
2875 AR5K_REG_SM(10, AR5K_SLEEP1_BEACON_TO), AR5K_SLEEP1);
2877 ath5k_hw_reg_write(ah,
2878 AR5K_REG_SM(interval, AR5K_SLEEP2_TIM_PER) |
2879 AR5K_REG_SM(dtim, AR5K_SLEEP2_DTIM_PER), AR5K_SLEEP2);
2886 * Reset beacon timers
2888 void ath5k_hw_reset_beacon(struct ath5k_hw *ah)
2890 ATH5K_TRACE(ah->ah_sc);
2892 * Disable beacon timer
2894 ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
2897 * Disable some beacon register values
2899 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2900 AR5K_STA_ID1_DEFAULT_ANTENNA | AR5K_STA_ID1_PCF);
2901 ath5k_hw_reg_write(ah, AR5K_BEACON_PERIOD, AR5K_BEACON);
2905 * Wait for beacon queue to finish
2907 int ath5k_hw_beaconq_finish(struct ath5k_hw *ah, unsigned long phys_addr)
2912 ATH5K_TRACE(ah->ah_sc);
2914 /* 5210 doesn't have QCU*/
2915 if (ah->ah_version == AR5K_AR5210) {
2917 * Wait for beaconn queue to finish by checking
2918 * Control Register and Beacon Status Register.
2920 for (i = AR5K_TUNE_BEACON_INTERVAL / 2; i > 0; i--) {
2921 if (!(ath5k_hw_reg_read(ah, AR5K_BSR) & AR5K_BSR_TXQ1F)
2923 !(ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_BSR_TXQ1F))
2931 * Re-schedule the beacon queue
2933 ath5k_hw_reg_write(ah, phys_addr, AR5K_NOQCU_TXDP1);
2934 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
2942 ret = ath5k_hw_register_timeout(ah,
2943 AR5K_QUEUE_STATUS(AR5K_TX_QUEUE_ID_BEACON),
2944 AR5K_QCU_STS_FRMPENDCNT, 0, false);
2946 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, AR5K_TX_QUEUE_ID_BEACON))
2955 * Update mib counters (statistics)
2957 void ath5k_hw_update_mib_counters(struct ath5k_hw *ah,
2958 struct ieee80211_low_level_stats *stats)
2960 ATH5K_TRACE(ah->ah_sc);
2962 /* Read-And-Clear */
2963 stats->dot11ACKFailureCount += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL);
2964 stats->dot11RTSFailureCount += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL);
2965 stats->dot11RTSSuccessCount += ath5k_hw_reg_read(ah, AR5K_RTS_OK);
2966 stats->dot11FCSErrorCount += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL);
2968 /* XXX: Should we use this to track beacon count ?
2969 * -we read it anyway to clear the register */
2970 ath5k_hw_reg_read(ah, AR5K_BEACON_CNT);
2972 /* Reset profile count registers on 5212*/
2973 if (ah->ah_version == AR5K_AR5212) {
2974 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_TX);
2975 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RX);
2976 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR);
2977 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE);
2981 /** ath5k_hw_set_ack_bitrate - set bitrate for ACKs
2983 * @ah: the &struct ath5k_hw
2984 * @high: determines if to use low bit rate or now
2986 void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high)
2988 if (ah->ah_version != AR5K_AR5212)
2991 u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB;
2993 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val);
2995 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val);
3005 * Set ACK timeout on PCU
3007 int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout)
3009 ATH5K_TRACE(ah->ah_sc);
3010 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK),
3011 ah->ah_turbo) <= timeout)
3014 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK,
3015 ath5k_hw_htoclock(timeout, ah->ah_turbo));
3021 * Read the ACK timeout from PCU
3023 unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah)
3025 ATH5K_TRACE(ah->ah_sc);
3027 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
3028 AR5K_TIME_OUT), AR5K_TIME_OUT_ACK), ah->ah_turbo);
3032 * Set CTS timeout on PCU
3034 int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout)
3036 ATH5K_TRACE(ah->ah_sc);
3037 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS),
3038 ah->ah_turbo) <= timeout)
3041 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS,
3042 ath5k_hw_htoclock(timeout, ah->ah_turbo));
3048 * Read CTS timeout from PCU
3050 unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah)
3052 ATH5K_TRACE(ah->ah_sc);
3053 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
3054 AR5K_TIME_OUT), AR5K_TIME_OUT_CTS), ah->ah_turbo);
3058 * Key table (WEP) functions
3061 int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
3065 ATH5K_TRACE(ah->ah_sc);
3066 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3068 for (i = 0; i < AR5K_KEYCACHE_SIZE; i++)
3069 ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i));
3072 * Set NULL encryption on AR5212+
3074 * Note: AR5K_KEYTABLE_TYPE -> AR5K_KEYTABLE_OFF(entry, 5)
3075 * AR5K_KEYTABLE_TYPE_NULL -> 0x00000007
3077 * Note2: Windows driver (ndiswrapper) sets this to
3078 * 0x00000714 instead of 0x00000007
3080 if (ah->ah_version > AR5K_AR5211)
3081 ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
3082 AR5K_KEYTABLE_TYPE(entry));
3087 int ath5k_hw_is_key_valid(struct ath5k_hw *ah, u16 entry)
3089 ATH5K_TRACE(ah->ah_sc);
3090 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3092 /* Check the validation flag at the end of the entry */
3093 return ath5k_hw_reg_read(ah, AR5K_KEYTABLE_MAC1(entry)) &
3094 AR5K_KEYTABLE_VALID;
3097 int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
3098 const struct ieee80211_key_conf *key, const u8 *mac)
3101 __le32 key_v[5] = {};
3104 ATH5K_TRACE(ah->ah_sc);
3106 /* key->keylen comes in from mac80211 in bytes */
3108 if (key->keylen > AR5K_KEYTABLE_SIZE / 8)
3111 switch (key->keylen) {
3112 /* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit */
3114 memcpy(&key_v[0], key->key, 5);
3115 keytype = AR5K_KEYTABLE_TYPE_40;
3118 /* WEP 104-bit = 104-bit entered key + 24-bit IV = 128-bit */
3120 memcpy(&key_v[0], &key->key[0], 6);
3121 memcpy(&key_v[2], &key->key[6], 6);
3122 memcpy(&key_v[4], &key->key[12], 1);
3123 keytype = AR5K_KEYTABLE_TYPE_104;
3125 /* WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit */
3127 memcpy(&key_v[0], &key->key[0], 6);
3128 memcpy(&key_v[2], &key->key[6], 6);
3129 memcpy(&key_v[4], &key->key[12], 4);
3130 keytype = AR5K_KEYTABLE_TYPE_128;
3134 return -EINVAL; /* shouldn't happen */
3137 for (i = 0; i < ARRAY_SIZE(key_v); i++)
3138 ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
3139 AR5K_KEYTABLE_OFF(entry, i));
3141 ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry));
3143 return ath5k_hw_set_key_lladdr(ah, entry, mac);
3146 int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac)
3148 u32 low_id, high_id;
3150 ATH5K_TRACE(ah->ah_sc);
3151 /* Invalid entry (key table overflow) */
3152 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3154 /* MAC may be NULL if it's a broadcast key. In this case no need to
3155 * to compute AR5K_LOW_ID and AR5K_HIGH_ID as we already know it. */
3156 if (unlikely(mac == NULL)) {
3157 low_id = 0xffffffff;
3158 high_id = 0xffff | AR5K_KEYTABLE_VALID;
3160 low_id = AR5K_LOW_ID(mac);
3161 high_id = AR5K_HIGH_ID(mac) | AR5K_KEYTABLE_VALID;
3164 ath5k_hw_reg_write(ah, low_id, AR5K_KEYTABLE_MAC0(entry));
3165 ath5k_hw_reg_write(ah, high_id, AR5K_KEYTABLE_MAC1(entry));
3171 /********************************************\
3172 Queue Control Unit, DFS Control Unit Functions
3173 \********************************************/
3176 * Initialize a transmit queue
3178 int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type,
3179 struct ath5k_txq_info *queue_info)
3184 ATH5K_TRACE(ah->ah_sc);
3189 /*5210 only has 2 queues*/
3190 if (ah->ah_version == AR5K_AR5210) {
3191 switch (queue_type) {
3192 case AR5K_TX_QUEUE_DATA:
3193 queue = AR5K_TX_QUEUE_ID_NOQCU_DATA;
3195 case AR5K_TX_QUEUE_BEACON:
3196 case AR5K_TX_QUEUE_CAB:
3197 queue = AR5K_TX_QUEUE_ID_NOQCU_BEACON;
3203 switch (queue_type) {
3204 case AR5K_TX_QUEUE_DATA:
3205 for (queue = AR5K_TX_QUEUE_ID_DATA_MIN;
3206 ah->ah_txq[queue].tqi_type !=
3207 AR5K_TX_QUEUE_INACTIVE; queue++) {
3209 if (queue > AR5K_TX_QUEUE_ID_DATA_MAX)
3213 case AR5K_TX_QUEUE_UAPSD:
3214 queue = AR5K_TX_QUEUE_ID_UAPSD;
3216 case AR5K_TX_QUEUE_BEACON:
3217 queue = AR5K_TX_QUEUE_ID_BEACON;
3219 case AR5K_TX_QUEUE_CAB:
3220 queue = AR5K_TX_QUEUE_ID_CAB;
3222 case AR5K_TX_QUEUE_XR_DATA:
3223 if (ah->ah_version != AR5K_AR5212)
3224 ATH5K_ERR(ah->ah_sc,
3225 "XR data queues only supported in"
3227 queue = AR5K_TX_QUEUE_ID_XR_DATA;
3235 * Setup internal queue structure
3237 memset(&ah->ah_txq[queue], 0, sizeof(struct ath5k_txq_info));
3238 ah->ah_txq[queue].tqi_type = queue_type;
3240 if (queue_info != NULL) {
3241 queue_info->tqi_type = queue_type;
3242 ret = ath5k_hw_setup_tx_queueprops(ah, queue, queue_info);
3247 * We use ah_txq_status to hold a temp value for
3248 * the Secondary interrupt mask registers on 5211+
3249 * check out ath5k_hw_reset_tx_queue
3251 AR5K_Q_ENABLE_BITS(ah->ah_txq_status, queue);
3257 * Setup a transmit queue
3259 int ath5k_hw_setup_tx_queueprops(struct ath5k_hw *ah, int queue,
3260 const struct ath5k_txq_info *queue_info)
3262 ATH5K_TRACE(ah->ah_sc);
3263 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3265 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3268 memcpy(&ah->ah_txq[queue], queue_info, sizeof(struct ath5k_txq_info));
3270 /*XXX: Is this supported on 5210 ?*/
3271 if ((queue_info->tqi_type == AR5K_TX_QUEUE_DATA &&
3272 ((queue_info->tqi_subtype == AR5K_WME_AC_VI) ||
3273 (queue_info->tqi_subtype == AR5K_WME_AC_VO))) ||
3274 queue_info->tqi_type == AR5K_TX_QUEUE_UAPSD)
3275 ah->ah_txq[queue].tqi_flags |= AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
3281 * Get properties for a specific transmit queue
3283 int ath5k_hw_get_tx_queueprops(struct ath5k_hw *ah, int queue,
3284 struct ath5k_txq_info *queue_info)
3286 ATH5K_TRACE(ah->ah_sc);
3287 memcpy(queue_info, &ah->ah_txq[queue], sizeof(struct ath5k_txq_info));
3292 * Set a transmit queue inactive
3294 void ath5k_hw_release_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3296 ATH5K_TRACE(ah->ah_sc);
3297 if (WARN_ON(queue >= ah->ah_capabilities.cap_queues.q_tx_num))
3300 /* This queue will be skipped in further operations */
3301 ah->ah_txq[queue].tqi_type = AR5K_TX_QUEUE_INACTIVE;
3303 AR5K_Q_DISABLE_BITS(ah->ah_txq_status, queue);
3307 * Set DFS params for a transmit queue
3309 int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3311 u32 cw_min, cw_max, retry_lg, retry_sh;
3312 struct ath5k_txq_info *tq = &ah->ah_txq[queue];
3314 ATH5K_TRACE(ah->ah_sc);
3315 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3317 tq = &ah->ah_txq[queue];
3319 if (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE)
3322 if (ah->ah_version == AR5K_AR5210) {
3323 /* Only handle data queues, others will be ignored */
3324 if (tq->tqi_type != AR5K_TX_QUEUE_DATA)
3328 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3329 AR5K_INIT_SLOT_TIME_TURBO : AR5K_INIT_SLOT_TIME,
3331 /* Set ACK_CTS timeout */
3332 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3333 AR5K_INIT_ACK_CTS_TIMEOUT_TURBO :
3334 AR5K_INIT_ACK_CTS_TIMEOUT, AR5K_SLOT_TIME);
3335 /* Set Transmit Latency */
3336 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3337 AR5K_INIT_TRANSMIT_LATENCY_TURBO :
3338 AR5K_INIT_TRANSMIT_LATENCY, AR5K_USEC_5210);
3341 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS_TURBO +
3342 (ah->ah_aifs + tq->tqi_aifs) *
3343 AR5K_INIT_SLOT_TIME_TURBO) <<
3344 AR5K_IFS0_DIFS_S) | AR5K_INIT_SIFS_TURBO,
3347 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS +
3348 (ah->ah_aifs + tq->tqi_aifs) *
3349 AR5K_INIT_SLOT_TIME) << AR5K_IFS0_DIFS_S) |
3350 AR5K_INIT_SIFS, AR5K_IFS0);
3353 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3354 AR5K_INIT_PROTO_TIME_CNTRL_TURBO :
3355 AR5K_INIT_PROTO_TIME_CNTRL, AR5K_IFS1);
3356 /* Set PHY register 0x9844 (??) */
3357 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3358 (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x38 :
3359 (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x1C,
3361 /* Set Frame Control Register */
3362 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3363 (AR5K_PHY_FRAME_CTL_INI | AR5K_PHY_TURBO_MODE |
3364 AR5K_PHY_TURBO_SHORT | 0x2020) :
3365 (AR5K_PHY_FRAME_CTL_INI | 0x1020),
3366 AR5K_PHY_FRAME_CTL_5210);
3370 * Calculate cwmin/max by channel mode
3372 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN;
3373 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX;
3374 ah->ah_aifs = AR5K_TUNE_AIFS;
3375 /*XR is only supported on 5212*/
3376 if (IS_CHAN_XR(ah->ah_current_channel) &&
3377 ah->ah_version == AR5K_AR5212) {
3378 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_XR;
3379 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_XR;
3380 ah->ah_aifs = AR5K_TUNE_AIFS_XR;
3381 /*B mode is not supported on 5210*/
3382 } else if (IS_CHAN_B(ah->ah_current_channel) &&
3383 ah->ah_version != AR5K_AR5210) {
3384 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_11B;
3385 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_11B;
3386 ah->ah_aifs = AR5K_TUNE_AIFS_11B;
3390 while (cw_min < ah->ah_cw_min)
3391 cw_min = (cw_min << 1) | 1;
3393 cw_min = tq->tqi_cw_min < 0 ? (cw_min >> (-tq->tqi_cw_min)) :
3394 ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
3395 cw_max = tq->tqi_cw_max < 0 ? (cw_max >> (-tq->tqi_cw_max)) :
3396 ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
3399 * Calculate and set retry limits
3401 if (ah->ah_software_retry) {
3402 /* XXX Need to test this */
3403 retry_lg = ah->ah_limit_tx_retries;
3404 retry_sh = retry_lg = retry_lg > AR5K_DCU_RETRY_LMT_SH_RETRY ?
3405 AR5K_DCU_RETRY_LMT_SH_RETRY : retry_lg;
3407 retry_lg = AR5K_INIT_LG_RETRY;
3408 retry_sh = AR5K_INIT_SH_RETRY;
3411 /*No QCU/DCU [5210]*/
3412 if (ah->ah_version == AR5K_AR5210) {
3413 ath5k_hw_reg_write(ah,
3414 (cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
3415 | AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3416 AR5K_NODCU_RETRY_LMT_SLG_RETRY)
3417 | AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3418 AR5K_NODCU_RETRY_LMT_SSH_RETRY)
3419 | AR5K_REG_SM(retry_lg, AR5K_NODCU_RETRY_LMT_LG_RETRY)
3420 | AR5K_REG_SM(retry_sh, AR5K_NODCU_RETRY_LMT_SH_RETRY),
3421 AR5K_NODCU_RETRY_LMT);
3424 ath5k_hw_reg_write(ah,
3425 AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3426 AR5K_DCU_RETRY_LMT_SLG_RETRY) |
3427 AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3428 AR5K_DCU_RETRY_LMT_SSH_RETRY) |
3429 AR5K_REG_SM(retry_lg, AR5K_DCU_RETRY_LMT_LG_RETRY) |
3430 AR5K_REG_SM(retry_sh, AR5K_DCU_RETRY_LMT_SH_RETRY),
3431 AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
3433 /*===Rest is also for QCU/DCU only [5211+]===*/
3436 * Set initial content window (cw_min/cw_max)
3437 * and arbitrated interframe space (aifs)...
3439 ath5k_hw_reg_write(ah,
3440 AR5K_REG_SM(cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
3441 AR5K_REG_SM(cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
3442 AR5K_REG_SM(ah->ah_aifs + tq->tqi_aifs,
3443 AR5K_DCU_LCL_IFS_AIFS),
3444 AR5K_QUEUE_DFS_LOCAL_IFS(queue));
3447 * Set misc registers
3449 ath5k_hw_reg_write(ah, AR5K_QCU_MISC_DCU_EARLY,
3450 AR5K_QUEUE_MISC(queue));
3452 if (tq->tqi_cbr_period) {
3453 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
3454 AR5K_QCU_CBRCFG_INTVAL) |
3455 AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
3456 AR5K_QCU_CBRCFG_ORN_THRES),
3457 AR5K_QUEUE_CBRCFG(queue));
3458 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3459 AR5K_QCU_MISC_FRSHED_CBR);
3460 if (tq->tqi_cbr_overflow_limit)
3461 AR5K_REG_ENABLE_BITS(ah,
3462 AR5K_QUEUE_MISC(queue),
3463 AR5K_QCU_MISC_CBR_THRES_ENABLE);
3466 if (tq->tqi_ready_time)
3467 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
3468 AR5K_QCU_RDYTIMECFG_INTVAL) |
3469 AR5K_QCU_RDYTIMECFG_ENABLE,
3470 AR5K_QUEUE_RDYTIMECFG(queue));
3472 if (tq->tqi_burst_time) {
3473 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
3474 AR5K_DCU_CHAN_TIME_DUR) |
3475 AR5K_DCU_CHAN_TIME_ENABLE,
3476 AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
3478 if (tq->tqi_flags & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
3479 AR5K_REG_ENABLE_BITS(ah,
3480 AR5K_QUEUE_MISC(queue),
3484 if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
3485 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
3486 AR5K_QUEUE_DFS_MISC(queue));
3488 if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
3489 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
3490 AR5K_QUEUE_DFS_MISC(queue));
3493 * Set registers by queue type
3495 switch (tq->tqi_type) {
3496 case AR5K_TX_QUEUE_BEACON:
3497 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3498 AR5K_QCU_MISC_FRSHED_DBA_GT |
3499 AR5K_QCU_MISC_CBREXP_BCN |
3500 AR5K_QCU_MISC_BCN_ENABLE);
3502 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3503 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3504 AR5K_DCU_MISC_ARBLOCK_CTL_S) |
3505 AR5K_DCU_MISC_POST_FR_BKOFF_DIS |
3506 AR5K_DCU_MISC_BCN_ENABLE);
3508 ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL -
3509 (AR5K_TUNE_SW_BEACON_RESP -
3510 AR5K_TUNE_DMA_BEACON_RESP) -
3511 AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF) * 1024) |
3512 AR5K_QCU_RDYTIMECFG_ENABLE,
3513 AR5K_QUEUE_RDYTIMECFG(queue));
3516 case AR5K_TX_QUEUE_CAB:
3517 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3518 AR5K_QCU_MISC_FRSHED_DBA_GT |
3519 AR5K_QCU_MISC_CBREXP |
3520 AR5K_QCU_MISC_CBREXP_BCN);
3522 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3523 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3524 AR5K_DCU_MISC_ARBLOCK_CTL_S));
3527 case AR5K_TX_QUEUE_UAPSD:
3528 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3529 AR5K_QCU_MISC_CBREXP);
3532 case AR5K_TX_QUEUE_DATA:
3538 * Enable interrupts for this tx queue
3539 * in the secondary interrupt mask registers
3541 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
3542 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
3544 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
3545 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
3547 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
3548 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
3550 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
3551 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
3553 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
3554 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
3557 /* Update secondary interrupt mask registers */
3558 ah->ah_txq_imr_txok &= ah->ah_txq_status;
3559 ah->ah_txq_imr_txerr &= ah->ah_txq_status;
3560 ah->ah_txq_imr_txurn &= ah->ah_txq_status;
3561 ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
3562 ah->ah_txq_imr_txeol &= ah->ah_txq_status;
3564 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
3565 AR5K_SIMR0_QCU_TXOK) |
3566 AR5K_REG_SM(ah->ah_txq_imr_txdesc,
3567 AR5K_SIMR0_QCU_TXDESC), AR5K_SIMR0);
3568 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
3569 AR5K_SIMR1_QCU_TXERR) |
3570 AR5K_REG_SM(ah->ah_txq_imr_txeol,
3571 AR5K_SIMR1_QCU_TXEOL), AR5K_SIMR1);
3572 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txurn,
3573 AR5K_SIMR2_QCU_TXURN), AR5K_SIMR2);
3580 * Get number of pending frames
3581 * for a specific queue [5211+]
3583 u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah, unsigned int queue) {
3584 ATH5K_TRACE(ah->ah_sc);
3585 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3587 /* Return if queue is declared inactive */
3588 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3591 /* XXX: How about AR5K_CFG_TXCNT ? */
3592 if (ah->ah_version == AR5K_AR5210)
3595 return AR5K_QUEUE_STATUS(queue) & AR5K_QCU_STS_FRMPENDCNT;
3601 int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time)
3603 ATH5K_TRACE(ah->ah_sc);
3604 if (slot_time < AR5K_SLOT_TIME_9 || slot_time > AR5K_SLOT_TIME_MAX)
3607 if (ah->ah_version == AR5K_AR5210)
3608 ath5k_hw_reg_write(ah, ath5k_hw_htoclock(slot_time,
3609 ah->ah_turbo), AR5K_SLOT_TIME);
3611 ath5k_hw_reg_write(ah, slot_time, AR5K_DCU_GBL_IFS_SLOT);
3619 unsigned int ath5k_hw_get_slot_time(struct ath5k_hw *ah)
3621 ATH5K_TRACE(ah->ah_sc);
3622 if (ah->ah_version == AR5K_AR5210)
3623 return ath5k_hw_clocktoh(ath5k_hw_reg_read(ah,
3624 AR5K_SLOT_TIME) & 0xffff, ah->ah_turbo);
3626 return ath5k_hw_reg_read(ah, AR5K_DCU_GBL_IFS_SLOT) & 0xffff;
3630 /******************************\
3631 Hardware Descriptor Functions
3632 \******************************/
3639 * Initialize the 2-word tx descriptor on 5210/5211
3642 ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3643 unsigned int pkt_len, unsigned int hdr_len, enum ath5k_pkt_type type,
3644 unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
3645 unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
3646 unsigned int rtscts_rate, unsigned int rtscts_duration)
3649 struct ath5k_hw_2w_tx_ctl *tx_ctl;
3650 unsigned int frame_len;
3652 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
3656 * - Zero retries don't make sense.
3657 * - A zero rate will put the HW into a mode where it continously sends
3658 * noise on the channel, so it is important to avoid this.
3660 if (unlikely(tx_tries0 == 0)) {
3661 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3665 if (unlikely(tx_rate0 == 0)) {
3666 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3671 /* Clear descriptor */
3672 memset(&desc->ud.ds_tx5210, 0, sizeof(struct ath5k_hw_5210_tx_desc));
3674 /* Setup control descriptor */
3676 /* Verify and set frame length */
3678 /* remove padding we might have added before */
3679 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3681 if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
3684 tx_ctl->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
3686 /* Verify and set buffer length */
3688 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3689 if(type == AR5K_PKT_TYPE_BEACON)
3690 pkt_len = roundup(pkt_len, 4);
3692 if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
3695 tx_ctl->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
3698 * Verify and set header length
3699 * XXX: I only found that on 5210 code, does it work on 5211 ?
3701 if (ah->ah_version == AR5K_AR5210) {
3702 if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN)
3704 tx_ctl->tx_control_0 |=
3705 AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN);
3708 /*Diferences between 5210-5211*/
3709 if (ah->ah_version == AR5K_AR5210) {
3711 case AR5K_PKT_TYPE_BEACON:
3712 case AR5K_PKT_TYPE_PROBE_RESP:
3713 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
3714 case AR5K_PKT_TYPE_PIFS:
3715 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
3717 frame_type = type /*<< 2 ?*/;
3720 tx_ctl->tx_control_0 |=
3721 AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE) |
3722 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3724 tx_ctl->tx_control_0 |=
3725 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
3726 AR5K_REG_SM(antenna_mode, AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
3727 tx_ctl->tx_control_1 |=
3728 AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE);
3730 #define _TX_FLAGS(_c, _flag) \
3731 if (flags & AR5K_TXDESC_##_flag) \
3732 tx_ctl->tx_control_##_c |= \
3733 AR5K_2W_TX_DESC_CTL##_c##_##_flag
3735 _TX_FLAGS(0, CLRDMASK);
3737 _TX_FLAGS(0, INTREQ);
3738 _TX_FLAGS(0, RTSENA);
3739 _TX_FLAGS(1, NOACK);
3746 if (key_index != AR5K_TXKEYIX_INVALID) {
3747 tx_ctl->tx_control_0 |=
3748 AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3749 tx_ctl->tx_control_1 |=
3750 AR5K_REG_SM(key_index,
3751 AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3755 * RTS/CTS Duration [5210 ?]
3757 if ((ah->ah_version == AR5K_AR5210) &&
3758 (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
3759 tx_ctl->tx_control_1 |= rtscts_duration &
3760 AR5K_2W_TX_DESC_CTL1_RTS_DURATION;
3766 * Initialize the 4-word tx descriptor on 5212
3768 static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
3769 struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
3770 enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
3771 unsigned int tx_tries0, unsigned int key_index,
3772 unsigned int antenna_mode, unsigned int flags, unsigned int rtscts_rate,
3773 unsigned int rtscts_duration)
3775 struct ath5k_hw_4w_tx_ctl *tx_ctl;
3776 unsigned int frame_len;
3778 ATH5K_TRACE(ah->ah_sc);
3779 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
3783 * - Zero retries don't make sense.
3784 * - A zero rate will put the HW into a mode where it continously sends
3785 * noise on the channel, so it is important to avoid this.
3787 if (unlikely(tx_tries0 == 0)) {
3788 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3792 if (unlikely(tx_rate0 == 0)) {
3793 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3798 /* Clear descriptor */
3799 memset(&desc->ud.ds_tx5212, 0, sizeof(struct ath5k_hw_5212_tx_desc));
3801 /* Setup control descriptor */
3803 /* Verify and set frame length */
3805 /* remove padding we might have added before */
3806 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3808 if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
3811 tx_ctl->tx_control_0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
3813 /* Verify and set buffer length */
3815 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3816 if(type == AR5K_PKT_TYPE_BEACON)
3817 pkt_len = roundup(pkt_len, 4);
3819 if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
3822 tx_ctl->tx_control_1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
3824 tx_ctl->tx_control_0 |=
3825 AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
3826 AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
3827 tx_ctl->tx_control_1 |= AR5K_REG_SM(type,
3828 AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
3829 tx_ctl->tx_control_2 = AR5K_REG_SM(tx_tries0 + AR5K_TUNE_HWTXTRIES,
3830 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
3831 tx_ctl->tx_control_3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
3833 #define _TX_FLAGS(_c, _flag) \
3834 if (flags & AR5K_TXDESC_##_flag) \
3835 tx_ctl->tx_control_##_c |= \
3836 AR5K_4W_TX_DESC_CTL##_c##_##_flag
3838 _TX_FLAGS(0, CLRDMASK);
3840 _TX_FLAGS(0, INTREQ);
3841 _TX_FLAGS(0, RTSENA);
3842 _TX_FLAGS(0, CTSENA);
3843 _TX_FLAGS(1, NOACK);
3850 if (key_index != AR5K_TXKEYIX_INVALID) {
3851 tx_ctl->tx_control_0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3852 tx_ctl->tx_control_1 |= AR5K_REG_SM(key_index,
3853 AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3859 if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
3860 if ((flags & AR5K_TXDESC_RTSENA) &&
3861 (flags & AR5K_TXDESC_CTSENA))
3863 tx_ctl->tx_control_2 |= rtscts_duration &
3864 AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
3865 tx_ctl->tx_control_3 |= AR5K_REG_SM(rtscts_rate,
3866 AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
3873 * Initialize a 4-word multirate tx descriptor on 5212
3876 ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3877 unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2, u_int tx_tries2,
3878 unsigned int tx_rate3, u_int tx_tries3)
3880 struct ath5k_hw_4w_tx_ctl *tx_ctl;
3883 * Rates can be 0 as long as the retry count is 0 too.
3884 * A zero rate and nonzero retry count will put the HW into a mode where
3885 * it continously sends noise on the channel, so it is important to
3888 if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
3889 (tx_rate2 == 0 && tx_tries2 != 0) ||
3890 (tx_rate3 == 0 && tx_tries3 != 0))) {
3891 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3896 if (ah->ah_version == AR5K_AR5212) {
3897 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
3899 #define _XTX_TRIES(_n) \
3900 if (tx_tries##_n) { \
3901 tx_ctl->tx_control_2 |= \
3902 AR5K_REG_SM(tx_tries##_n, \
3903 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
3904 tx_ctl->tx_control_3 |= \
3905 AR5K_REG_SM(tx_rate##_n, \
3906 AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
3922 * Proccess the tx status descriptor on 5210/5211
3924 static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
3925 struct ath5k_desc *desc, struct ath5k_tx_status *ts)
3927 struct ath5k_hw_2w_tx_ctl *tx_ctl;
3928 struct ath5k_hw_tx_status *tx_status;
3930 ATH5K_TRACE(ah->ah_sc);
3932 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
3933 tx_status = &desc->ud.ds_tx5210.tx_stat;
3935 /* No frame has been send or error */
3936 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
3937 return -EINPROGRESS;
3940 * Get descriptor status
3942 ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
3943 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
3944 ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
3945 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
3946 ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
3947 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
3948 /*TODO: ts->ts_virtcol + test*/
3949 ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
3950 AR5K_DESC_TX_STATUS1_SEQ_NUM);
3951 ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
3952 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
3955 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_0,
3956 AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3958 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
3959 if (tx_status->tx_status_0 &
3960 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
3961 ts->ts_status |= AR5K_TXERR_XRETRY;
3963 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
3964 ts->ts_status |= AR5K_TXERR_FIFO;
3966 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
3967 ts->ts_status |= AR5K_TXERR_FILT;
3974 * Proccess a tx descriptor on 5212
3976 static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
3977 struct ath5k_desc *desc, struct ath5k_tx_status *ts)
3979 struct ath5k_hw_4w_tx_ctl *tx_ctl;
3980 struct ath5k_hw_tx_status *tx_status;
3982 ATH5K_TRACE(ah->ah_sc);
3984 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
3985 tx_status = &desc->ud.ds_tx5212.tx_stat;
3987 /* No frame has been send or error */
3988 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
3989 return -EINPROGRESS;
3992 * Get descriptor status
3994 ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
3995 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
3996 ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
3997 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
3998 ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
3999 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
4000 ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
4001 AR5K_DESC_TX_STATUS1_SEQ_NUM);
4002 ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
4003 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
4004 ts->ts_antenna = (tx_status->tx_status_1 &
4005 AR5K_DESC_TX_STATUS1_XMIT_ANTENNA) ? 2 : 1;
4008 switch (AR5K_REG_MS(tx_status->tx_status_1,
4009 AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX)) {
4011 ts->ts_rate = tx_ctl->tx_control_3 &
4012 AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
4015 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
4016 AR5K_4W_TX_DESC_CTL3_XMIT_RATE1);
4017 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
4018 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1);
4021 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
4022 AR5K_4W_TX_DESC_CTL3_XMIT_RATE2);
4023 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
4024 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2);
4027 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
4028 AR5K_4W_TX_DESC_CTL3_XMIT_RATE3);
4029 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
4030 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES3);
4034 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
4035 if (tx_status->tx_status_0 &
4036 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
4037 ts->ts_status |= AR5K_TXERR_XRETRY;
4039 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
4040 ts->ts_status |= AR5K_TXERR_FIFO;
4042 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
4043 ts->ts_status |= AR5K_TXERR_FILT;
4054 * Initialize an rx descriptor
4056 int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
4057 u32 size, unsigned int flags)
4059 struct ath5k_hw_rx_ctl *rx_ctl;
4061 ATH5K_TRACE(ah->ah_sc);
4062 rx_ctl = &desc->ud.ds_rx.rx_ctl;
4065 * Clear the descriptor
4066 * If we don't clean the status descriptor,
4067 * while scanning we get too many results,
4068 * most of them virtual, after some secs
4069 * of scanning system hangs. M.F.
4071 memset(&desc->ud.ds_rx, 0, sizeof(struct ath5k_hw_all_rx_desc));
4073 /* Setup descriptor */
4074 rx_ctl->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
4075 if (unlikely(rx_ctl->rx_control_1 != size))
4078 if (flags & AR5K_RXDESC_INTREQ)
4079 rx_ctl->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
4085 * Proccess the rx status descriptor on 5210/5211
4087 static int ath5k_hw_proc_5210_rx_status(struct ath5k_hw *ah,
4088 struct ath5k_desc *desc, struct ath5k_rx_status *rs)
4090 struct ath5k_hw_rx_status *rx_status;
4092 rx_status = &desc->ud.ds_rx.u.rx_stat;
4094 /* No frame received / not ready */
4095 if (unlikely((rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_DONE)
4097 return -EINPROGRESS;
4100 * Frame receive status
4102 rs->rs_datalen = rx_status->rx_status_0 &
4103 AR5K_5210_RX_DESC_STATUS0_DATA_LEN;
4104 rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
4105 AR5K_5210_RX_DESC_STATUS0_RECEIVE_SIGNAL);
4106 rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
4107 AR5K_5210_RX_DESC_STATUS0_RECEIVE_RATE);
4108 rs->rs_antenna = rx_status->rx_status_0 &
4109 AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANTENNA;
4110 rs->rs_more = rx_status->rx_status_0 &
4111 AR5K_5210_RX_DESC_STATUS0_MORE;
4112 /* TODO: this timestamp is 13 bit, later on we assume 15 bit */
4113 rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
4114 AR5K_5210_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
4120 if (rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_KEY_INDEX_VALID)
4121 rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
4122 AR5K_5210_RX_DESC_STATUS1_KEY_INDEX);
4124 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
4127 * Receive/descriptor errors
4129 if ((rx_status->rx_status_1 &
4130 AR5K_5210_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
4131 if (rx_status->rx_status_1 &
4132 AR5K_5210_RX_DESC_STATUS1_CRC_ERROR)
4133 rs->rs_status |= AR5K_RXERR_CRC;
4135 if (rx_status->rx_status_1 &
4136 AR5K_5210_RX_DESC_STATUS1_FIFO_OVERRUN)
4137 rs->rs_status |= AR5K_RXERR_FIFO;
4139 if (rx_status->rx_status_1 &
4140 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR) {
4141 rs->rs_status |= AR5K_RXERR_PHY;
4142 rs->rs_phyerr = AR5K_REG_MS(rx_status->rx_status_1,
4143 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR);
4146 if (rx_status->rx_status_1 &
4147 AR5K_5210_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
4148 rs->rs_status |= AR5K_RXERR_DECRYPT;
4155 * Proccess the rx status descriptor on 5212
4157 static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *ah,
4158 struct ath5k_desc *desc, struct ath5k_rx_status *rs)
4160 struct ath5k_hw_rx_status *rx_status;
4161 struct ath5k_hw_rx_error *rx_err;
4163 ATH5K_TRACE(ah->ah_sc);
4164 rx_status = &desc->ud.ds_rx.u.rx_stat;
4166 /* Overlay on error */
4167 rx_err = &desc->ud.ds_rx.u.rx_err;
4169 /* No frame received / not ready */
4170 if (unlikely((rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_DONE)
4172 return -EINPROGRESS;
4175 * Frame receive status
4177 rs->rs_datalen = rx_status->rx_status_0 &
4178 AR5K_5212_RX_DESC_STATUS0_DATA_LEN;
4179 rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
4180 AR5K_5212_RX_DESC_STATUS0_RECEIVE_SIGNAL);
4181 rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
4182 AR5K_5212_RX_DESC_STATUS0_RECEIVE_RATE);
4183 rs->rs_antenna = rx_status->rx_status_0 &
4184 AR5K_5212_RX_DESC_STATUS0_RECEIVE_ANTENNA;
4185 rs->rs_more = rx_status->rx_status_0 &
4186 AR5K_5212_RX_DESC_STATUS0_MORE;
4187 rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
4188 AR5K_5212_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
4194 if (rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_KEY_INDEX_VALID)
4195 rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
4196 AR5K_5212_RX_DESC_STATUS1_KEY_INDEX);
4198 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
4201 * Receive/descriptor errors
4203 if ((rx_status->rx_status_1 &
4204 AR5K_5212_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
4205 if (rx_status->rx_status_1 &
4206 AR5K_5212_RX_DESC_STATUS1_CRC_ERROR)
4207 rs->rs_status |= AR5K_RXERR_CRC;
4209 if (rx_status->rx_status_1 &
4210 AR5K_5212_RX_DESC_STATUS1_PHY_ERROR) {
4211 rs->rs_status |= AR5K_RXERR_PHY;
4212 rs->rs_phyerr = AR5K_REG_MS(rx_err->rx_error_1,
4213 AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE);
4216 if (rx_status->rx_status_1 &
4217 AR5K_5212_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
4218 rs->rs_status |= AR5K_RXERR_DECRYPT;
4220 if (rx_status->rx_status_1 &
4221 AR5K_5212_RX_DESC_STATUS1_MIC_ERROR)
4222 rs->rs_status |= AR5K_RXERR_MIC;
4236 void ath5k_hw_set_ledstate(struct ath5k_hw *ah, unsigned int state)
4239 /*5210 has different led mode handling*/
4242 ATH5K_TRACE(ah->ah_sc);
4244 /*Reset led status*/
4245 if (ah->ah_version != AR5K_AR5210)
4246 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
4247 AR5K_PCICFG_LEDMODE | AR5K_PCICFG_LED);
4249 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_LED);
4252 * Some blinking values, define at your wish
4257 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_PEND;
4258 led_5210 = AR5K_PCICFG_LED_PEND | AR5K_PCICFG_LED_BCTL;
4262 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_NONE;
4263 led_5210 = AR5K_PCICFG_LED_PEND;
4266 case AR5K_LED_ASSOC:
4268 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_ASSOC;
4269 led_5210 = AR5K_PCICFG_LED_ASSOC;
4273 led = AR5K_PCICFG_LEDMODE_PROM | AR5K_PCICFG_LED_NONE;
4274 led_5210 = AR5K_PCICFG_LED_PEND;
4278 /*Write new status to the register*/
4279 if (ah->ah_version != AR5K_AR5210)
4280 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led);
4282 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led_5210);
4288 int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
4290 ATH5K_TRACE(ah->ah_sc);
4291 if (gpio > AR5K_NUM_GPIO)
4294 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4295 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR);
4303 int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
4305 ATH5K_TRACE(ah->ah_sc);
4306 if (gpio > AR5K_NUM_GPIO)
4309 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4310 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR);
4318 u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
4320 ATH5K_TRACE(ah->ah_sc);
4321 if (gpio > AR5K_NUM_GPIO)
4324 /* GPIO input magic */
4325 return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) &
4332 int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
4335 ATH5K_TRACE(ah->ah_sc);
4337 if (gpio > AR5K_NUM_GPIO)
4340 /* GPIO output magic */
4341 data = ath5k_hw_reg_read(ah, AR5K_GPIODO);
4343 data &= ~(1 << gpio);
4344 data |= (val & 1) << gpio;
4346 ath5k_hw_reg_write(ah, data, AR5K_GPIODO);
4352 * Initialize the GPIO interrupt (RFKill switch)
4354 void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
4355 u32 interrupt_level)
4359 ATH5K_TRACE(ah->ah_sc);
4360 if (gpio > AR5K_NUM_GPIO)
4364 * Set the GPIO interrupt
4366 data = (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &
4367 ~(AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_SELH |
4368 AR5K_GPIOCR_INT_ENA | AR5K_GPIOCR_OUT(gpio))) |
4369 (AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_ENA);
4371 ath5k_hw_reg_write(ah, interrupt_level ? data :
4372 (data | AR5K_GPIOCR_INT_SELH), AR5K_GPIOCR);
4374 ah->ah_imr |= AR5K_IMR_GPIO;
4376 /* Enable GPIO interrupts */
4377 AR5K_REG_ENABLE_BITS(ah, AR5K_PIMR, AR5K_IMR_GPIO);
4387 int ath5k_hw_get_capability(struct ath5k_hw *ah,
4388 enum ath5k_capability_type cap_type,
4389 u32 capability, u32 *result)
4391 ATH5K_TRACE(ah->ah_sc);
4394 case AR5K_CAP_NUM_TXQUEUES:
4396 if (ah->ah_version == AR5K_AR5210)
4397 *result = AR5K_NUM_TX_QUEUES_NOQCU;
4399 *result = AR5K_NUM_TX_QUEUES;
4404 case AR5K_CAP_COMPRESSION:
4405 if (ah->ah_version == AR5K_AR5212)
4409 case AR5K_CAP_BURST:
4413 case AR5K_CAP_BSSIDMASK:
4414 if (ah->ah_version == AR5K_AR5212)
4419 if (ah->ah_version == AR5K_AR5212)
4433 static int ath5k_hw_enable_pspoll(struct ath5k_hw *ah, u8 *bssid,
4436 ATH5K_TRACE(ah->ah_sc);
4438 if (ah->ah_version == AR5K_AR5210) {
4439 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
4440 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
4447 static int ath5k_hw_disable_pspoll(struct ath5k_hw *ah)
4449 ATH5K_TRACE(ah->ah_sc);
4451 if (ah->ah_version == AR5K_AR5210) {
4452 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
4453 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);