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 static int ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
53 unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
54 unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
55 unsigned int, unsigned int);
56 static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *, struct ath5k_desc *);
57 static int ath5k_hw_proc_new_rx_status(struct ath5k_hw *, struct ath5k_desc *);
58 static int ath5k_hw_proc_old_rx_status(struct ath5k_hw *, struct ath5k_desc *);
59 static int ath5k_hw_get_capabilities(struct ath5k_hw *);
61 static int ath5k_eeprom_init(struct ath5k_hw *);
62 static int ath5k_eeprom_read_mac(struct ath5k_hw *, u8 *);
64 static int ath5k_hw_enable_pspoll(struct ath5k_hw *, u8 *, u16);
65 static int ath5k_hw_disable_pspoll(struct ath5k_hw *);
68 * Enable to overwrite the country code (use "00" for debug)
71 #define COUNTRYCODE "00"
79 * Functions used internaly
82 static inline unsigned int ath5k_hw_htoclock(unsigned int usec, bool turbo)
84 return turbo == true ? (usec * 80) : (usec * 40);
87 static inline unsigned int ath5k_hw_clocktoh(unsigned int clock, bool turbo)
89 return turbo == true ? (clock / 80) : (clock / 40);
93 * Check if a register write has been completed
95 int ath5k_hw_register_timeout(struct ath5k_hw *ah, u32 reg, u32 flag, u32 val,
101 for (i = AR5K_TUNE_REGISTER_TIMEOUT; i > 0; i--) {
102 data = ath5k_hw_reg_read(ah, reg);
103 if ((is_set == true) && (data & flag))
105 else if ((data & flag) == val)
110 return (i <= 0) ? -EAGAIN : 0;
114 /***************************************\
115 Attach/Detach Functions
116 \***************************************/
119 * Check if the device is supported and initialize the needed structs
121 struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
128 /*If we passed the test malloc a ath5k_hw struct*/
129 ah = kzalloc(sizeof(struct ath5k_hw), GFP_KERNEL);
132 ATH5K_ERR(sc, "out of memory\n");
137 ah->ah_iobase = sc->iobase;
143 ah->ah_op_mode = IEEE80211_IF_TYPE_STA;
144 ah->ah_radar.r_enabled = AR5K_TUNE_RADAR_ALERT;
145 ah->ah_turbo = false;
146 ah->ah_txpower.txp_tpc = AR5K_TUNE_TPC_TXPOWER;
148 ah->ah_atim_window = 0;
149 ah->ah_aifs = AR5K_TUNE_AIFS;
150 ah->ah_cw_min = AR5K_TUNE_CWMIN;
151 ah->ah_limit_tx_retries = AR5K_INIT_TX_RETRY;
152 ah->ah_software_retry = false;
153 ah->ah_ant_diversity = AR5K_TUNE_ANT_DIVERSITY;
156 * Set the mac revision based on the pci id
158 ah->ah_version = mac_version;
160 /*Fill the ath5k_hw struct with the needed functions*/
161 if (ah->ah_version == AR5K_AR5212)
162 ah->ah_magic = AR5K_EEPROM_MAGIC_5212;
163 else if (ah->ah_version == AR5K_AR5211)
164 ah->ah_magic = AR5K_EEPROM_MAGIC_5211;
166 if (ah->ah_version == AR5K_AR5212) {
167 ah->ah_setup_tx_desc = ath5k_hw_setup_4word_tx_desc;
168 ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
169 ah->ah_proc_tx_desc = ath5k_hw_proc_4word_tx_status;
171 ah->ah_setup_tx_desc = ath5k_hw_setup_2word_tx_desc;
172 ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
173 ah->ah_proc_tx_desc = ath5k_hw_proc_2word_tx_status;
176 if (ah->ah_version == AR5K_AR5212)
177 ah->ah_proc_rx_desc = ath5k_hw_proc_new_rx_status;
178 else if (ah->ah_version <= AR5K_AR5211)
179 ah->ah_proc_rx_desc = ath5k_hw_proc_old_rx_status;
181 /* Bring device out of sleep and reset it's units */
182 ret = ath5k_hw_nic_wakeup(ah, AR5K_INIT_MODE, true);
186 /* Get MAC, PHY and RADIO revisions */
187 srev = ath5k_hw_reg_read(ah, AR5K_SREV);
188 ah->ah_mac_srev = srev;
189 ah->ah_mac_version = AR5K_REG_MS(srev, AR5K_SREV_VER);
190 ah->ah_mac_revision = AR5K_REG_MS(srev, AR5K_SREV_REV);
191 ah->ah_phy_revision = ath5k_hw_reg_read(ah, AR5K_PHY_CHIP_ID) &
193 ah->ah_radio_5ghz_revision = ath5k_hw_radio_revision(ah,
196 if (ah->ah_version == AR5K_AR5210)
197 ah->ah_radio_2ghz_revision = 0;
199 ah->ah_radio_2ghz_revision = ath5k_hw_radio_revision(ah,
202 /* Return on unsuported chips (unsupported eeprom etc) */
203 if(srev >= AR5K_SREV_VER_AR5416){
204 ATH5K_ERR(sc, "Device not yet supported.\n");
209 /* Identify single chip solutions */
210 if((srev <= AR5K_SREV_VER_AR5414) &&
211 (srev >= AR5K_SREV_VER_AR2424)) {
212 ah->ah_single_chip = true;
214 ah->ah_single_chip = false;
217 /* Single chip radio */
218 if (ah->ah_radio_2ghz_revision == ah->ah_radio_5ghz_revision)
219 ah->ah_radio_2ghz_revision = 0;
221 /* Identify the radio chip*/
222 if (ah->ah_version == AR5K_AR5210) {
223 ah->ah_radio = AR5K_RF5110;
224 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112) {
225 ah->ah_radio = AR5K_RF5111;
226 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC1) {
227 ah->ah_radio = AR5K_RF5112;
229 ah->ah_radio = AR5K_RF5413;
232 ah->ah_phy = AR5K_PHY(0);
235 * Get card capabilities, values, ...
238 ret = ath5k_eeprom_init(ah);
240 ATH5K_ERR(sc, "unable to init EEPROM\n");
244 /* Get misc capabilities */
245 ret = ath5k_hw_get_capabilities(ah);
247 ATH5K_ERR(sc, "unable to get device capabilities: 0x%04x\n",
252 /* Get MAC address */
253 ret = ath5k_eeprom_read_mac(ah, mac);
255 ATH5K_ERR(sc, "unable to read address from EEPROM: 0x%04x\n",
260 ath5k_hw_set_lladdr(ah, mac);
261 /* Set BSSID to bcast address: ff:ff:ff:ff:ff:ff for now */
262 memset(ah->ah_bssid, 0xff, ETH_ALEN);
263 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
264 ath5k_hw_set_opmode(ah);
266 ath5k_hw_set_rfgain_opt(ah);
276 * Bring up MAC + PHY Chips
278 static int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
280 u32 turbo, mode, clock;
287 ATH5K_TRACE(ah->ah_sc);
289 /* Wakeup the device */
290 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
292 ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
296 if (ah->ah_version != AR5K_AR5210) {
298 * Get channel mode flags
301 if (ah->ah_radio >= AR5K_RF5112) {
302 mode = AR5K_PHY_MODE_RAD_RF5112;
303 clock = AR5K_PHY_PLL_RF5112;
305 mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
306 clock = AR5K_PHY_PLL_RF5111; /*Zero*/
309 if (flags & CHANNEL_2GHZ) {
310 mode |= AR5K_PHY_MODE_FREQ_2GHZ;
311 clock |= AR5K_PHY_PLL_44MHZ;
313 if (flags & CHANNEL_CCK) {
314 mode |= AR5K_PHY_MODE_MOD_CCK;
315 } else if (flags & CHANNEL_OFDM) {
316 /* XXX Dynamic OFDM/CCK is not supported by the
317 * AR5211 so we set MOD_OFDM for plain g (no
318 * CCK headers) operation. We need to test
319 * this, 5211 might support ofdm-only g after
320 * all, there are also initial register values
321 * in the code for g mode (see initvals.c). */
322 if (ah->ah_version == AR5K_AR5211)
323 mode |= AR5K_PHY_MODE_MOD_OFDM;
325 mode |= AR5K_PHY_MODE_MOD_DYN;
328 "invalid radio modulation mode\n");
331 } else if (flags & CHANNEL_5GHZ) {
332 mode |= AR5K_PHY_MODE_FREQ_5GHZ;
333 clock |= AR5K_PHY_PLL_40MHZ;
335 if (flags & CHANNEL_OFDM)
336 mode |= AR5K_PHY_MODE_MOD_OFDM;
339 "invalid radio modulation mode\n");
343 ATH5K_ERR(ah->ah_sc, "invalid radio frequency mode\n");
347 if (flags & CHANNEL_TURBO)
348 turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
349 } else { /* Reset the device */
351 /* ...enable Atheros turbo mode if requested */
352 if (flags & CHANNEL_TURBO)
353 ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
357 /* ...reset chipset and PCI device */
358 if (ah->ah_single_chip == false && ath5k_hw_nic_reset(ah,
359 AR5K_RESET_CTL_CHIP | AR5K_RESET_CTL_PCI)) {
360 ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip + PCI\n");
364 if (ah->ah_version == AR5K_AR5210)
367 /* ...wakeup again!*/
368 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
370 ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
374 /* ...final warm reset */
375 if (ath5k_hw_nic_reset(ah, 0)) {
376 ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
380 if (ah->ah_version != AR5K_AR5210) {
381 /* ...set the PHY operating mode */
382 ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
385 ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
386 ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
393 * Get the rate table for a specific operation mode
395 const struct ath5k_rate_table *ath5k_hw_get_rate_table(struct ath5k_hw *ah,
398 ATH5K_TRACE(ah->ah_sc);
400 if (!test_bit(mode, ah->ah_capabilities.cap_mode))
403 /* Get rate tables */
406 return &ath5k_rt_11a;
407 case AR5K_MODE_11A_TURBO:
408 return &ath5k_rt_turbo;
410 return &ath5k_rt_11b;
412 return &ath5k_rt_11g;
413 case AR5K_MODE_11G_TURBO:
421 * Free the ath5k_hw struct
423 void ath5k_hw_detach(struct ath5k_hw *ah)
425 ATH5K_TRACE(ah->ah_sc);
427 if (ah->ah_rf_banks != NULL)
428 kfree(ah->ah_rf_banks);
430 /* assume interrupts are down */
434 /****************************\
435 Reset function and helpers
436 \****************************/
439 * ath5k_hw_write_ofdm_timings - set OFDM timings on AR5212
441 * @ah: the &struct ath5k_hw
442 * @channel: the currently set channel upon reset
444 * Write the OFDM timings for the AR5212 upon reset. This is a helper for
445 * ath5k_hw_reset(). This seems to tune the PLL a specified frequency
446 * depending on the bandwidth of the channel.
449 static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
450 struct ieee80211_channel *channel)
452 /* Get exponent and mantissa and set it */
453 u32 coef_scaled, coef_exp, coef_man,
454 ds_coef_exp, ds_coef_man, clock;
456 if (!(ah->ah_version == AR5K_AR5212) ||
457 !(channel->hw_value & CHANNEL_OFDM))
460 /* Seems there are two PLLs, one for baseband sampling and one
461 * for tuning. Tuning basebands are 40 MHz or 80MHz when in
463 clock = channel->hw_value & CHANNEL_TURBO ? 80 : 40;
464 coef_scaled = ((5 * (clock << 24)) / 2) /
465 channel->center_freq;
467 for (coef_exp = 31; coef_exp > 0; coef_exp--)
468 if ((coef_scaled >> coef_exp) & 0x1)
474 coef_exp = 14 - (coef_exp - 24);
475 coef_man = coef_scaled +
476 (1 << (24 - coef_exp - 1));
477 ds_coef_man = coef_man >> (24 - coef_exp);
478 ds_coef_exp = coef_exp - 16;
480 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
481 AR5K_PHY_TIMING_3_DSC_MAN, ds_coef_man);
482 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
483 AR5K_PHY_TIMING_3_DSC_EXP, ds_coef_exp);
489 * ath5k_hw_write_rate_duration - set rate duration during hw resets
491 * @ah: the &struct ath5k_hw
492 * @mode: one of enum ath5k_driver_mode
494 * Write the rate duration table for the current mode upon hw reset. This
495 * is a helper for ath5k_hw_reset(). It seems all this is doing is setting
496 * an ACK timeout for the hardware for the current mode for each rate. The
497 * rates which are capable of short preamble (802.11b rates 2Mbps, 5.5Mbps,
498 * and 11Mbps) have another register for the short preamble ACK timeout
502 static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
505 struct ath5k_softc *sc = ah->ah_sc;
506 const struct ath5k_rate_table *rt;
507 struct ieee80211_rate srate = {};
510 /* Get rate table for the current operating mode */
511 rt = ath5k_hw_get_rate_table(ah, mode);
513 /* Write rate duration table */
514 for (i = 0; i < rt->rate_count; i++) {
515 const struct ath5k_rate *rate, *control_rate;
520 rate = &rt->rates[i];
521 control_rate = &rt->rates[rate->control_rate];
523 /* Set ACK timeout */
524 reg = AR5K_RATE_DUR(rate->rate_code);
526 srate.bitrate = control_rate->rate_kbps/100;
528 /* An ACK frame consists of 10 bytes. If you add the FCS,
529 * which ieee80211_generic_frame_duration() adds,
530 * its 14 bytes. Note we use the control rate and not the
531 * actual rate for this rate. See mac80211 tx.c
532 * ieee80211_duration() for a brief description of
533 * what rate we should choose to TX ACKs. */
534 tx_time = le16_to_cpu(ieee80211_generic_frame_duration(sc->hw,
535 sc->vif, 10, &srate));
537 ath5k_hw_reg_write(ah, tx_time, reg);
539 if (!HAS_SHPREAMBLE(i))
543 * We're not distinguishing short preamble here,
544 * This is true, all we'll get is a longer value here
545 * which is not necessarilly bad. We could use
546 * export ieee80211_frame_duration() but that needs to be
547 * fixed first to be properly used by mac802111 drivers:
549 * - remove erp stuff and let the routine figure ofdm
551 * - remove passing argument ieee80211_local as
552 * drivers don't have access to it
553 * - move drivers using ieee80211_generic_frame_duration()
556 ath5k_hw_reg_write(ah, tx_time,
557 reg + (AR5K_SET_SHORT_PREAMBLE << 2));
562 * Main reset function
564 int ath5k_hw_reset(struct ath5k_hw *ah, enum ieee80211_if_types op_mode,
565 struct ieee80211_channel *channel, bool change_channel)
567 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
568 u32 data, s_seq, s_ant, s_led[3];
569 unsigned int i, mode, freq, ee_mode, ant[2];
572 ATH5K_TRACE(ah->ah_sc);
581 * Save some registers before a reset
583 /*DCU/Antenna selection not available on 5210*/
584 if (ah->ah_version != AR5K_AR5210) {
585 if (change_channel == true) {
586 /* Seq number for queue 0 -do this for all queues ? */
587 s_seq = ath5k_hw_reg_read(ah,
588 AR5K_QUEUE_DFS_SEQNUM(0));
590 s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
595 s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) & AR5K_PCICFG_LEDSTATE;
596 s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
597 s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
599 if (change_channel == true && ah->ah_rf_banks != NULL)
600 ath5k_hw_get_rf_gain(ah);
603 /*Wakeup the device*/
604 ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, false);
609 * Initialize operating mode
611 ah->ah_op_mode = op_mode;
615 * 5210 only comes with RF5110
617 if (ah->ah_version != AR5K_AR5210) {
618 if (ah->ah_radio != AR5K_RF5111 &&
619 ah->ah_radio != AR5K_RF5112 &&
620 ah->ah_radio != AR5K_RF5413) {
622 "invalid phy radio: %u\n", ah->ah_radio);
626 switch (channel->hw_value & CHANNEL_MODES) {
628 mode = AR5K_MODE_11A;
629 freq = AR5K_INI_RFGAIN_5GHZ;
630 ee_mode = AR5K_EEPROM_MODE_11A;
633 mode = AR5K_MODE_11G;
634 freq = AR5K_INI_RFGAIN_2GHZ;
635 ee_mode = AR5K_EEPROM_MODE_11G;
638 mode = AR5K_MODE_11B;
639 freq = AR5K_INI_RFGAIN_2GHZ;
640 ee_mode = AR5K_EEPROM_MODE_11B;
643 mode = AR5K_MODE_11A_TURBO;
644 freq = AR5K_INI_RFGAIN_5GHZ;
645 ee_mode = AR5K_EEPROM_MODE_11A;
647 /*Is this ok on 5211 too ?*/
649 mode = AR5K_MODE_11G_TURBO;
650 freq = AR5K_INI_RFGAIN_2GHZ;
651 ee_mode = AR5K_EEPROM_MODE_11G;
654 if (ah->ah_version == AR5K_AR5211) {
656 "XR mode not available on 5211");
660 freq = AR5K_INI_RFGAIN_5GHZ;
661 ee_mode = AR5K_EEPROM_MODE_11A;
665 "invalid channel: %d\n", channel->center_freq);
669 /* PHY access enable */
670 ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
674 ret = ath5k_hw_write_initvals(ah, mode, change_channel);
681 if (ah->ah_version != AR5K_AR5210) {
683 * Write initial RF gain settings
684 * This should work for both 5111/5112
686 ret = ath5k_hw_rfgain(ah, freq);
693 * Write some more initial register settings
695 if (ah->ah_version > AR5K_AR5211){ /* found on 5213+ */
696 ath5k_hw_reg_write(ah, 0x0002a002, AR5K_PHY(11));
698 if (channel->hw_value == CHANNEL_G)
699 ath5k_hw_reg_write(ah, 0x00f80d80, AR5K_PHY(83)); /* 0x00fc0ec0 */
701 ath5k_hw_reg_write(ah, 0x00000000, AR5K_PHY(83));
703 ath5k_hw_reg_write(ah, 0x000001b5, 0xa228); /* 0x000009b5 */
704 ath5k_hw_reg_write(ah, 0x000009b5, 0xa228);
705 ath5k_hw_reg_write(ah, 0x0000000f, 0x8060);
706 ath5k_hw_reg_write(ah, 0x00000000, 0xa254);
707 ath5k_hw_reg_write(ah, 0x0000000e, AR5K_PHY_SCAL);
710 /* Fix for first revision of the RF5112 RF chipset */
711 if (ah->ah_radio >= AR5K_RF5112 &&
712 ah->ah_radio_5ghz_revision <
713 AR5K_SREV_RAD_5112A) {
714 ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
716 if (channel->hw_value & CHANNEL_5GHZ)
720 ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
724 * Set TX power (FIXME)
726 ret = ath5k_hw_txpower(ah, channel, AR5K_TUNE_DEFAULT_TXPOWER);
730 /* Write rate duration table only on AR5212 and if
731 * virtual interface has already been brought up
732 * XXX: rethink this after new mode changes to
733 * mac80211 are integrated */
734 if (ah->ah_version == AR5K_AR5212 &&
735 ah->ah_sc->vif != NULL)
736 ath5k_hw_write_rate_duration(ah, mode);
740 * TODO:Does this work on 5211 (5111) ?
742 ret = ath5k_hw_rfregs(ah, channel, mode);
747 * Configure additional registers
750 /* Write OFDM timings on 5212*/
751 if (ah->ah_version == AR5K_AR5212 &&
752 channel->hw_value & CHANNEL_OFDM) {
753 ret = ath5k_hw_write_ofdm_timings(ah, channel);
758 /*Enable/disable 802.11b mode on 5111
759 (enable 2111 frequency converter + CCK)*/
760 if (ah->ah_radio == AR5K_RF5111) {
761 if (mode == AR5K_MODE_11B)
762 AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
765 AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
770 * Set channel and calibrate the PHY
772 ret = ath5k_hw_channel(ah, channel);
776 /* Set antenna mode */
777 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x44),
778 ah->ah_antenna[ee_mode][0], 0xfffffc06);
781 * In case a fixed antenna was set as default
782 * write the same settings on both AR5K_PHY_ANT_SWITCH_TABLE
786 if (s_ant == AR5K_ANT_FIXED_A) /* 1 - Main */
787 ant[0] = ant[1] = AR5K_ANT_FIXED_A;
789 ant[0] = ant[1] = AR5K_ANT_FIXED_B;
791 ant[0] = AR5K_ANT_FIXED_A;
792 ant[1] = AR5K_ANT_FIXED_B;
795 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[0]],
796 AR5K_PHY_ANT_SWITCH_TABLE_0);
797 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[1]],
798 AR5K_PHY_ANT_SWITCH_TABLE_1);
800 /* Commit values from EEPROM */
801 if (ah->ah_radio == AR5K_RF5111)
802 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_FRAME_CTL,
803 AR5K_PHY_FRAME_CTL_TX_CLIP, ee->ee_tx_clip);
805 ath5k_hw_reg_write(ah,
806 AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
809 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x11),
810 (ee->ee_switch_settling[ee_mode] << 7) & 0x3f80,
812 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x12),
813 (ee->ee_ant_tx_rx[ee_mode] << 12) & 0x3f000,
815 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x14),
816 (ee->ee_adc_desired_size[ee_mode] & 0x00ff) |
817 ((ee->ee_pga_desired_size[ee_mode] << 8) & 0xff00),
820 ath5k_hw_reg_write(ah,
821 (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
822 (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
823 (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
824 (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY(0x0d));
826 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x0a),
827 ee->ee_tx_end2xlna_enable[ee_mode] << 8, 0xffff00ff);
828 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x19),
829 (ee->ee_thr_62[ee_mode] << 12) & 0x7f000, 0xfff80fff);
830 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x49), 4, 0xffffff01);
832 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
833 AR5K_PHY_IQ_CORR_ENABLE |
834 (ee->ee_i_cal[ee_mode] << AR5K_PHY_IQ_CORR_Q_I_COFF_S) |
835 ee->ee_q_cal[ee_mode]);
837 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
838 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
839 AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
840 ee->ee_margin_tx_rx[ee_mode]);
844 /* Disable phy and wait */
845 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
850 * Restore saved values
852 /*DCU/Antenna selection not available on 5210*/
853 if (ah->ah_version != AR5K_AR5210) {
854 ath5k_hw_reg_write(ah, s_seq, AR5K_QUEUE_DFS_SEQNUM(0));
855 ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
857 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
858 ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
859 ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
864 /* XXX: add ah->aid once mac80211 gives this to us */
865 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
867 ath5k_hw_set_opmode(ah);
868 /*PISR/SISR Not available on 5210*/
869 if (ah->ah_version != AR5K_AR5210) {
870 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
871 /* If we later allow tuning for this, store into sc structure */
872 data = AR5K_TUNE_RSSI_THRES |
873 AR5K_TUNE_BMISS_THRES << AR5K_RSSI_THR_BMISS_S;
874 ath5k_hw_reg_write(ah, data, AR5K_RSSI_THR);
878 * Set Rx/Tx DMA Configuration
879 *(passing dma size not available on 5210)
881 if (ah->ah_version != AR5K_AR5210) {
882 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG, AR5K_TXCFG_SDMAMR,
883 AR5K_DMASIZE_512B | AR5K_TXCFG_DMASIZE);
884 AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_SDMAMW,
889 * Enable the PHY and wait until completion
891 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
896 if (ah->ah_version != AR5K_AR5210) {
897 data = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
899 data = (channel->hw_value & CHANNEL_CCK) ?
900 ((data << 2) / 22) : (data / 10);
908 * Enable calibration and wait until completion
910 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
911 AR5K_PHY_AGCCTL_CAL);
913 if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
914 AR5K_PHY_AGCCTL_CAL, 0, false)) {
915 ATH5K_ERR(ah->ah_sc, "calibration timeout (%uMHz)\n",
916 channel->center_freq);
920 ret = ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
924 ah->ah_calibration = false;
926 /* A and G modes can use QAM modulation which requires enabling
927 * I and Q calibration. Don't bother in B mode. */
928 if (!(mode == AR5K_MODE_11B)) {
929 ah->ah_calibration = true;
930 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
931 AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
932 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
937 * Reset queues and start beacon timers at the end of the reset routine
939 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
941 if (ah->ah_version != AR5K_AR5210)
942 AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(i), i);
944 ret = ath5k_hw_reset_tx_queue(ah, i);
947 "failed to reset TX queue #%d\n", i);
952 /* Pre-enable interrupts on 5211/5212*/
953 if (ah->ah_version != AR5K_AR5210)
954 ath5k_hw_set_intr(ah, AR5K_INT_RX | AR5K_INT_TX |
958 * Set RF kill flags if supported by the device (read from the EEPROM)
959 * Disable gpio_intr for now since it results system hang.
960 * TODO: Handle this in ath5k_intr
963 if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header)) {
964 ath5k_hw_set_gpio_input(ah, 0);
965 ah->ah_gpio[0] = ath5k_hw_get_gpio(ah, 0);
966 if (ah->ah_gpio[0] == 0)
967 ath5k_hw_set_gpio_intr(ah, 0, 1);
969 ath5k_hw_set_gpio_intr(ah, 0, 0);
974 * Set the 32MHz reference clock on 5212 phy clock sleep register
976 if (ah->ah_version == AR5K_AR5212) {
977 ath5k_hw_reg_write(ah, AR5K_PHY_SCR_32MHZ, AR5K_PHY_SCR);
978 ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
979 ath5k_hw_reg_write(ah, AR5K_PHY_SCAL_32MHZ, AR5K_PHY_SCAL);
980 ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
981 ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
982 ath5k_hw_reg_write(ah, ah->ah_radio == AR5K_RF5111 ?
983 AR5K_PHY_SPENDING_RF5111 : AR5K_PHY_SPENDING_RF5112,
988 * Disable beacons and reset the register
990 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
991 AR5K_BEACON_RESET_TSF);
999 static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
1002 u32 mask = val ? val : ~0U;
1004 ATH5K_TRACE(ah->ah_sc);
1006 /* Read-and-clear RX Descriptor Pointer*/
1007 ath5k_hw_reg_read(ah, AR5K_RXDP);
1010 * Reset the device and wait until success
1012 ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
1014 /* Wait at least 128 PCI clocks */
1017 if (ah->ah_version == AR5K_AR5210) {
1018 val &= AR5K_RESET_CTL_CHIP;
1019 mask &= AR5K_RESET_CTL_CHIP;
1021 val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1022 mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1025 ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, false);
1028 * Reset configuration register (for hw byte-swap). Note that this
1029 * is only set for big endian. We do the necessary magic in
1032 if ((val & AR5K_RESET_CTL_PCU) == 0)
1033 ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
1039 * Power management functions
1045 int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
1046 bool set_chip, u16 sleep_duration)
1051 ATH5K_TRACE(ah->ah_sc);
1052 staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
1056 staid &= ~AR5K_STA_ID1_DEFAULT_ANTENNA;
1058 case AR5K_PM_NETWORK_SLEEP:
1059 if (set_chip == true)
1060 ath5k_hw_reg_write(ah,
1061 AR5K_SLEEP_CTL_SLE | sleep_duration,
1064 staid |= AR5K_STA_ID1_PWR_SV;
1067 case AR5K_PM_FULL_SLEEP:
1068 if (set_chip == true)
1069 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_SLP,
1072 staid |= AR5K_STA_ID1_PWR_SV;
1076 if (set_chip == false)
1079 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1082 for (i = 5000; i > 0; i--) {
1083 /* Check if the chip did wake up */
1084 if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
1085 AR5K_PCICFG_SPWR_DN) == 0)
1088 /* Wait a bit and retry */
1090 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1094 /* Fail if the chip didn't wake up */
1098 staid &= ~AR5K_STA_ID1_PWR_SV;
1106 ah->ah_power_mode = mode;
1107 ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
1112 /***********************\
1113 DMA Related Functions
1114 \***********************/
1123 void ath5k_hw_start_rx(struct ath5k_hw *ah)
1125 ATH5K_TRACE(ah->ah_sc);
1126 ath5k_hw_reg_write(ah, AR5K_CR_RXE, AR5K_CR);
1132 int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
1136 ATH5K_TRACE(ah->ah_sc);
1137 ath5k_hw_reg_write(ah, AR5K_CR_RXD, AR5K_CR);
1140 * It may take some time to disable the DMA receive unit
1142 for (i = 2000; i > 0 &&
1143 (ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_CR_RXE) != 0;
1147 return i ? 0 : -EBUSY;
1151 * Get the address of the RX Descriptor
1153 u32 ath5k_hw_get_rx_buf(struct ath5k_hw *ah)
1155 return ath5k_hw_reg_read(ah, AR5K_RXDP);
1159 * Set the address of the RX Descriptor
1161 void ath5k_hw_put_rx_buf(struct ath5k_hw *ah, u32 phys_addr)
1163 ATH5K_TRACE(ah->ah_sc);
1165 /*TODO:Shouldn't we check if RX is enabled first ?*/
1166 ath5k_hw_reg_write(ah, phys_addr, AR5K_RXDP);
1170 * Transmit functions
1174 * Start DMA transmit for a specific queue
1175 * (see also QCU/DCU functions)
1177 int ath5k_hw_tx_start(struct ath5k_hw *ah, unsigned int queue)
1181 ATH5K_TRACE(ah->ah_sc);
1182 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1184 /* Return if queue is declared inactive */
1185 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1188 if (ah->ah_version == AR5K_AR5210) {
1189 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1192 * Set the queue by type on 5210
1194 switch (ah->ah_txq[queue].tqi_type) {
1195 case AR5K_TX_QUEUE_DATA:
1196 tx_queue |= AR5K_CR_TXE0 & ~AR5K_CR_TXD0;
1198 case AR5K_TX_QUEUE_BEACON:
1199 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1200 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
1203 case AR5K_TX_QUEUE_CAB:
1204 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1205 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1FV | AR5K_BCR_TQ1V |
1206 AR5K_BCR_BDMAE, AR5K_BSR);
1212 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1214 /* Return if queue is disabled */
1215 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXD, queue))
1219 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXE, queue);
1226 * Stop DMA transmit for a specific queue
1227 * (see also QCU/DCU functions)
1229 int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue)
1231 unsigned int i = 100;
1232 u32 tx_queue, pending;
1234 ATH5K_TRACE(ah->ah_sc);
1235 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1237 /* Return if queue is declared inactive */
1238 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1241 if (ah->ah_version == AR5K_AR5210) {
1242 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1247 switch (ah->ah_txq[queue].tqi_type) {
1248 case AR5K_TX_QUEUE_DATA:
1249 tx_queue |= AR5K_CR_TXD0 & ~AR5K_CR_TXE0;
1251 case AR5K_TX_QUEUE_BEACON:
1252 case AR5K_TX_QUEUE_CAB:
1254 tx_queue |= AR5K_CR_TXD1 & ~AR5K_CR_TXD1;
1255 ath5k_hw_reg_write(ah, 0, AR5K_BSR);
1262 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1265 * Schedule TX disable and wait until queue is empty
1267 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXD, queue);
1269 /*Check for pending frames*/
1271 pending = ath5k_hw_reg_read(ah,
1272 AR5K_QUEUE_STATUS(queue)) &
1273 AR5K_QCU_STS_FRMPENDCNT;
1275 } while (--i && pending);
1277 /* Clear register */
1278 ath5k_hw_reg_write(ah, 0, AR5K_QCU_TXD);
1281 /* TODO: Check for success else return error */
1286 * Get the address of the TX Descriptor for a specific queue
1287 * (see also QCU/DCU functions)
1289 u32 ath5k_hw_get_tx_buf(struct ath5k_hw *ah, unsigned int queue)
1293 ATH5K_TRACE(ah->ah_sc);
1294 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1297 * Get the transmit queue descriptor pointer from the selected queue
1299 /*5210 doesn't have QCU*/
1300 if (ah->ah_version == AR5K_AR5210) {
1301 switch (ah->ah_txq[queue].tqi_type) {
1302 case AR5K_TX_QUEUE_DATA:
1303 tx_reg = AR5K_NOQCU_TXDP0;
1305 case AR5K_TX_QUEUE_BEACON:
1306 case AR5K_TX_QUEUE_CAB:
1307 tx_reg = AR5K_NOQCU_TXDP1;
1313 tx_reg = AR5K_QUEUE_TXDP(queue);
1316 return ath5k_hw_reg_read(ah, tx_reg);
1320 * Set the address of the TX Descriptor for a specific queue
1321 * (see also QCU/DCU functions)
1323 int ath5k_hw_put_tx_buf(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
1327 ATH5K_TRACE(ah->ah_sc);
1328 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1331 * Set the transmit queue descriptor pointer register by type
1334 if (ah->ah_version == AR5K_AR5210) {
1335 switch (ah->ah_txq[queue].tqi_type) {
1336 case AR5K_TX_QUEUE_DATA:
1337 tx_reg = AR5K_NOQCU_TXDP0;
1339 case AR5K_TX_QUEUE_BEACON:
1340 case AR5K_TX_QUEUE_CAB:
1341 tx_reg = AR5K_NOQCU_TXDP1;
1348 * Set the transmit queue descriptor pointer for
1349 * the selected queue on QCU for 5211+
1350 * (this won't work if the queue is still active)
1352 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
1355 tx_reg = AR5K_QUEUE_TXDP(queue);
1358 /* Set descriptor pointer */
1359 ath5k_hw_reg_write(ah, phys_addr, tx_reg);
1365 * Update tx trigger level
1367 int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase)
1369 u32 trigger_level, imr;
1372 ATH5K_TRACE(ah->ah_sc);
1375 * Disable interrupts by setting the mask
1377 imr = ath5k_hw_set_intr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
1379 /*TODO: Boundary check on trigger_level*/
1380 trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
1383 if (increase == false) {
1384 if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
1388 ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
1391 * Update trigger level on success
1393 if (ah->ah_version == AR5K_AR5210)
1394 ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
1396 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
1397 AR5K_TXCFG_TXFULL, trigger_level);
1403 * Restore interrupt mask
1405 ath5k_hw_set_intr(ah, imr);
1411 * Interrupt handling
1415 * Check if we have pending interrupts
1417 bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
1419 ATH5K_TRACE(ah->ah_sc);
1420 return ath5k_hw_reg_read(ah, AR5K_INTPEND);
1424 * Get interrupt mask (ISR)
1426 int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
1430 ATH5K_TRACE(ah->ah_sc);
1433 * Read interrupt status from the Interrupt Status register
1436 if (ah->ah_version == AR5K_AR5210) {
1437 data = ath5k_hw_reg_read(ah, AR5K_ISR);
1438 if (unlikely(data == AR5K_INT_NOCARD)) {
1439 *interrupt_mask = data;
1444 * Read interrupt status from the Read-And-Clear shadow register
1445 * Note: PISR/SISR Not available on 5210
1447 data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
1451 * Get abstract interrupt mask (driver-compatible)
1453 *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
1455 if (unlikely(data == AR5K_INT_NOCARD))
1458 if (data & (AR5K_ISR_RXOK | AR5K_ISR_RXERR))
1459 *interrupt_mask |= AR5K_INT_RX;
1461 if (data & (AR5K_ISR_TXOK | AR5K_ISR_TXERR
1462 | AR5K_ISR_TXDESC | AR5K_ISR_TXEOL))
1463 *interrupt_mask |= AR5K_INT_TX;
1465 if (ah->ah_version != AR5K_AR5210) {
1466 /*HIU = Host Interface Unit (PCI etc)*/
1467 if (unlikely(data & (AR5K_ISR_HIUERR)))
1468 *interrupt_mask |= AR5K_INT_FATAL;
1470 /*Beacon Not Ready*/
1471 if (unlikely(data & (AR5K_ISR_BNR)))
1472 *interrupt_mask |= AR5K_INT_BNR;
1476 * XXX: BMISS interrupts may occur after association.
1477 * I found this on 5210 code but it needs testing. If this is
1478 * true we should disable them before assoc and re-enable them
1479 * after a successfull assoc + some jiffies.
1482 interrupt_mask &= ~AR5K_INT_BMISS;
1486 * In case we didn't handle anything,
1487 * print the register value.
1489 if (unlikely(*interrupt_mask == 0 && net_ratelimit()))
1490 ATH5K_PRINTF("0x%08x\n", data);
1496 * Set interrupt mask
1498 enum ath5k_int ath5k_hw_set_intr(struct ath5k_hw *ah, enum ath5k_int new_mask)
1500 enum ath5k_int old_mask, int_mask;
1503 * Disable card interrupts to prevent any race conditions
1504 * (they will be re-enabled afterwards).
1506 ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
1508 old_mask = ah->ah_imr;
1511 * Add additional, chipset-dependent interrupt mask flags
1512 * and write them to the IMR (interrupt mask register).
1514 int_mask = new_mask & AR5K_INT_COMMON;
1516 if (new_mask & AR5K_INT_RX)
1517 int_mask |= AR5K_IMR_RXOK | AR5K_IMR_RXERR | AR5K_IMR_RXORN |
1520 if (new_mask & AR5K_INT_TX)
1521 int_mask |= AR5K_IMR_TXOK | AR5K_IMR_TXERR | AR5K_IMR_TXDESC |
1524 if (ah->ah_version != AR5K_AR5210) {
1525 if (new_mask & AR5K_INT_FATAL) {
1526 int_mask |= AR5K_IMR_HIUERR;
1527 AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_MCABT |
1528 AR5K_SIMR2_SSERR | AR5K_SIMR2_DPERR);
1532 ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
1534 /* Store new interrupt mask */
1535 ah->ah_imr = new_mask;
1537 /* ..re-enable interrupts */
1538 ath5k_hw_reg_write(ah, AR5K_IER_ENABLE, AR5K_IER);
1544 /*************************\
1545 EEPROM access functions
1546 \*************************/
1551 static int ath5k_hw_eeprom_read(struct ath5k_hw *ah, u32 offset, u16 *data)
1553 u32 status, timeout;
1555 ATH5K_TRACE(ah->ah_sc);
1557 * Initialize EEPROM access
1559 if (ah->ah_version == AR5K_AR5210) {
1560 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1561 (void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset));
1563 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1564 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1565 AR5K_EEPROM_CMD_READ);
1568 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1569 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1570 if (status & AR5K_EEPROM_STAT_RDDONE) {
1571 if (status & AR5K_EEPROM_STAT_RDERR)
1573 *data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) &
1584 * Write to eeprom - currently disabled, use at your own risk
1587 static int ath5k_hw_eeprom_write(struct ath5k_hw *ah, u32 offset, u16 data)
1590 u32 status, timeout;
1592 ATH5K_TRACE(ah->ah_sc);
1595 * Initialize eeprom access
1598 if (ah->ah_version == AR5K_AR5210) {
1599 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1601 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1602 AR5K_EEPROM_CMD_RESET);
1606 * Write data to data register
1609 if (ah->ah_version == AR5K_AR5210) {
1610 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_BASE + (4 * offset));
1612 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1613 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_DATA);
1614 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1615 AR5K_EEPROM_CMD_WRITE);
1622 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1623 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1624 if (status & AR5K_EEPROM_STAT_WRDONE) {
1625 if (status & AR5K_EEPROM_STAT_WRERR)
1632 ATH5K_ERR(ah->ah_sc, "EEPROM Write is disabled!");
1638 * Translate binary channel representation in EEPROM to frequency
1640 static u16 ath5k_eeprom_bin2freq(struct ath5k_hw *ah, u16 bin, unsigned int mode)
1644 if (bin == AR5K_EEPROM_CHANNEL_DIS)
1647 if (mode == AR5K_EEPROM_MODE_11A) {
1648 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1649 val = (5 * bin) + 4800;
1651 val = bin > 62 ? (10 * 62) + (5 * (bin - 62)) + 5100 :
1654 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1664 * Read antenna infos from eeprom
1666 static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
1669 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1674 AR5K_EEPROM_READ(o++, val);
1675 ee->ee_switch_settling[mode] = (val >> 8) & 0x7f;
1676 ee->ee_ant_tx_rx[mode] = (val >> 2) & 0x3f;
1677 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1679 AR5K_EEPROM_READ(o++, val);
1680 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1681 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1682 ee->ee_ant_control[mode][i++] = val & 0x3f;
1684 AR5K_EEPROM_READ(o++, val);
1685 ee->ee_ant_control[mode][i++] = (val >> 10) & 0x3f;
1686 ee->ee_ant_control[mode][i++] = (val >> 4) & 0x3f;
1687 ee->ee_ant_control[mode][i] = (val << 2) & 0x3f;
1689 AR5K_EEPROM_READ(o++, val);
1690 ee->ee_ant_control[mode][i++] |= (val >> 14) & 0x3;
1691 ee->ee_ant_control[mode][i++] = (val >> 8) & 0x3f;
1692 ee->ee_ant_control[mode][i++] = (val >> 2) & 0x3f;
1693 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1695 AR5K_EEPROM_READ(o++, val);
1696 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1697 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1698 ee->ee_ant_control[mode][i++] = val & 0x3f;
1700 /* Get antenna modes */
1701 ah->ah_antenna[mode][0] =
1702 (ee->ee_ant_control[mode][0] << 4) | 0x1;
1703 ah->ah_antenna[mode][AR5K_ANT_FIXED_A] =
1704 ee->ee_ant_control[mode][1] |
1705 (ee->ee_ant_control[mode][2] << 6) |
1706 (ee->ee_ant_control[mode][3] << 12) |
1707 (ee->ee_ant_control[mode][4] << 18) |
1708 (ee->ee_ant_control[mode][5] << 24);
1709 ah->ah_antenna[mode][AR5K_ANT_FIXED_B] =
1710 ee->ee_ant_control[mode][6] |
1711 (ee->ee_ant_control[mode][7] << 6) |
1712 (ee->ee_ant_control[mode][8] << 12) |
1713 (ee->ee_ant_control[mode][9] << 18) |
1714 (ee->ee_ant_control[mode][10] << 24);
1716 /* return new offset */
1723 * Read supported modes from eeprom
1725 static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset,
1728 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1733 AR5K_EEPROM_READ(o++, val);
1734 ee->ee_tx_end2xlna_enable[mode] = (val >> 8) & 0xff;
1735 ee->ee_thr_62[mode] = val & 0xff;
1737 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1738 ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28;
1740 AR5K_EEPROM_READ(o++, val);
1741 ee->ee_tx_end2xpa_disable[mode] = (val >> 8) & 0xff;
1742 ee->ee_tx_frm2xpa_enable[mode] = val & 0xff;
1744 AR5K_EEPROM_READ(o++, val);
1745 ee->ee_pga_desired_size[mode] = (val >> 8) & 0xff;
1747 if ((val & 0xff) & 0x80)
1748 ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1);
1750 ee->ee_noise_floor_thr[mode] = val & 0xff;
1752 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1753 ee->ee_noise_floor_thr[mode] =
1754 mode == AR5K_EEPROM_MODE_11A ? -54 : -1;
1756 AR5K_EEPROM_READ(o++, val);
1757 ee->ee_xlna_gain[mode] = (val >> 5) & 0xff;
1758 ee->ee_x_gain[mode] = (val >> 1) & 0xf;
1759 ee->ee_xpd[mode] = val & 0x1;
1761 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0)
1762 ee->ee_fixed_bias[mode] = (val >> 13) & 0x1;
1764 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) {
1765 AR5K_EEPROM_READ(o++, val);
1766 ee->ee_false_detect[mode] = (val >> 6) & 0x7f;
1768 if (mode == AR5K_EEPROM_MODE_11A)
1769 ee->ee_xr_power[mode] = val & 0x3f;
1771 ee->ee_ob[mode][0] = val & 0x7;
1772 ee->ee_db[mode][0] = (val >> 3) & 0x7;
1776 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) {
1777 ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN;
1778 ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA;
1780 ee->ee_i_gain[mode] = (val >> 13) & 0x7;
1782 AR5K_EEPROM_READ(o++, val);
1783 ee->ee_i_gain[mode] |= (val << 3) & 0x38;
1785 if (mode == AR5K_EEPROM_MODE_11G)
1786 ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff;
1789 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
1790 mode == AR5K_EEPROM_MODE_11A) {
1791 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
1792 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
1795 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6 &&
1796 mode == AR5K_EEPROM_MODE_11G)
1797 ee->ee_scaled_cck_delta = (val >> 11) & 0x1f;
1799 /* return new offset */
1806 * Initialize eeprom & capabilities structs
1808 static int ath5k_eeprom_init(struct ath5k_hw *ah)
1810 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1811 unsigned int mode, i;
1816 /* Initial TX thermal adjustment values */
1818 ee->ee_pwd_84 = ee->ee_pwd_90 = 1;
1819 ee->ee_gain_select = 1;
1822 * Read values from EEPROM and store them in the capability structure
1824 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC, ee_magic);
1825 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT, ee_protect);
1826 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN, ee_regdomain);
1827 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION, ee_version);
1828 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR, ee_header);
1830 /* Return if we have an old EEPROM */
1831 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_0)
1836 * Validate the checksum of the EEPROM date. There are some
1837 * devices with invalid EEPROMs.
1839 for (cksum = 0, offset = 0; offset < AR5K_EEPROM_INFO_MAX; offset++) {
1840 AR5K_EEPROM_READ(AR5K_EEPROM_INFO(offset), val);
1843 if (cksum != AR5K_EEPROM_INFO_CKSUM) {
1844 ATH5K_ERR(ah->ah_sc, "Invalid EEPROM checksum 0x%04x\n", cksum);
1849 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah->ah_ee_version),
1852 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
1853 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0, ee_misc0);
1854 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1, ee_misc1);
1857 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_3) {
1858 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ, val);
1859 ee->ee_ob[AR5K_EEPROM_MODE_11B][0] = val & 0x7;
1860 ee->ee_db[AR5K_EEPROM_MODE_11B][0] = (val >> 3) & 0x7;
1862 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ, val);
1863 ee->ee_ob[AR5K_EEPROM_MODE_11G][0] = val & 0x7;
1864 ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7;
1868 * Get conformance test limit values
1870 offset = AR5K_EEPROM_CTL(ah->ah_ee_version);
1871 ee->ee_ctls = AR5K_EEPROM_N_CTLS(ah->ah_ee_version);
1873 for (i = 0; i < ee->ee_ctls; i++) {
1874 AR5K_EEPROM_READ(offset++, val);
1875 ee->ee_ctl[i] = (val >> 8) & 0xff;
1876 ee->ee_ctl[i + 1] = val & 0xff;
1880 * Get values for 802.11a (5GHz)
1882 mode = AR5K_EEPROM_MODE_11A;
1884 ee->ee_turbo_max_power[mode] =
1885 AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header);
1887 offset = AR5K_EEPROM_MODES_11A(ah->ah_ee_version);
1889 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
1893 AR5K_EEPROM_READ(offset++, val);
1894 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
1895 ee->ee_ob[mode][3] = (val >> 5) & 0x7;
1896 ee->ee_db[mode][3] = (val >> 2) & 0x7;
1897 ee->ee_ob[mode][2] = (val << 1) & 0x7;
1899 AR5K_EEPROM_READ(offset++, val);
1900 ee->ee_ob[mode][2] |= (val >> 15) & 0x1;
1901 ee->ee_db[mode][2] = (val >> 12) & 0x7;
1902 ee->ee_ob[mode][1] = (val >> 9) & 0x7;
1903 ee->ee_db[mode][1] = (val >> 6) & 0x7;
1904 ee->ee_ob[mode][0] = (val >> 3) & 0x7;
1905 ee->ee_db[mode][0] = val & 0x7;
1907 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
1911 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1) {
1912 AR5K_EEPROM_READ(offset++, val);
1913 ee->ee_margin_tx_rx[mode] = val & 0x3f;
1917 * Get values for 802.11b (2.4GHz)
1919 mode = AR5K_EEPROM_MODE_11B;
1920 offset = AR5K_EEPROM_MODES_11B(ah->ah_ee_version);
1922 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
1926 AR5K_EEPROM_READ(offset++, val);
1927 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
1928 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
1929 ee->ee_db[mode][1] = val & 0x7;
1931 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
1935 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
1936 AR5K_EEPROM_READ(offset++, val);
1937 ee->ee_cal_pier[mode][0] =
1938 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
1939 ee->ee_cal_pier[mode][1] =
1940 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
1942 AR5K_EEPROM_READ(offset++, val);
1943 ee->ee_cal_pier[mode][2] =
1944 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
1947 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
1948 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
1951 * Get values for 802.11g (2.4GHz)
1953 mode = AR5K_EEPROM_MODE_11G;
1954 offset = AR5K_EEPROM_MODES_11G(ah->ah_ee_version);
1956 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
1960 AR5K_EEPROM_READ(offset++, val);
1961 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
1962 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
1963 ee->ee_db[mode][1] = val & 0x7;
1965 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
1969 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
1970 AR5K_EEPROM_READ(offset++, val);
1971 ee->ee_cal_pier[mode][0] =
1972 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
1973 ee->ee_cal_pier[mode][1] =
1974 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
1976 AR5K_EEPROM_READ(offset++, val);
1977 ee->ee_turbo_max_power[mode] = val & 0x7f;
1978 ee->ee_xr_power[mode] = (val >> 7) & 0x3f;
1980 AR5K_EEPROM_READ(offset++, val);
1981 ee->ee_cal_pier[mode][2] =
1982 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
1984 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
1985 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
1987 AR5K_EEPROM_READ(offset++, val);
1988 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
1989 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
1991 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) {
1992 AR5K_EEPROM_READ(offset++, val);
1993 ee->ee_cck_ofdm_gain_delta = val & 0xff;
1998 * Read 5GHz EEPROM channels
2005 * Read the MAC address from eeprom
2007 static int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
2014 memset(mac, 0, ETH_ALEN);
2015 memset(mac_d, 0, ETH_ALEN);
2017 ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
2021 for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
2022 ret = ath5k_hw_eeprom_read(ah, offset, &data);
2027 mac_d[octet + 1] = data & 0xff;
2028 mac_d[octet] = data >> 8;
2032 memcpy(mac, mac_d, ETH_ALEN);
2034 if (!total || total == 3 * 0xffff)
2041 * Fill the capabilities struct
2043 static int ath5k_hw_get_capabilities(struct ath5k_hw *ah)
2047 ATH5K_TRACE(ah->ah_sc);
2048 /* Capabilities stored in the EEPROM */
2049 ee_header = ah->ah_capabilities.cap_eeprom.ee_header;
2051 if (ah->ah_version == AR5K_AR5210) {
2053 * Set radio capabilities
2054 * (The AR5110 only supports the middle 5GHz band)
2056 ah->ah_capabilities.cap_range.range_5ghz_min = 5120;
2057 ah->ah_capabilities.cap_range.range_5ghz_max = 5430;
2058 ah->ah_capabilities.cap_range.range_2ghz_min = 0;
2059 ah->ah_capabilities.cap_range.range_2ghz_max = 0;
2061 /* Set supported modes */
2062 __set_bit(AR5K_MODE_11A, ah->ah_capabilities.cap_mode);
2063 __set_bit(AR5K_MODE_11A_TURBO, ah->ah_capabilities.cap_mode);
2066 * XXX The tranceiver supports frequencies from 4920 to 6100GHz
2067 * XXX and from 2312 to 2732GHz. There are problems with the
2068 * XXX current ieee80211 implementation because the IEEE
2069 * XXX channel mapping does not support negative channel
2070 * XXX numbers (2312MHz is channel -19). Of course, this
2071 * XXX doesn't matter because these channels are out of range
2072 * XXX but some regulation domains like MKK (Japan) will
2073 * XXX support frequencies somewhere around 4.8GHz.
2077 * Set radio capabilities
2080 if (AR5K_EEPROM_HDR_11A(ee_header)) {
2081 ah->ah_capabilities.cap_range.range_5ghz_min = 5005; /* 4920 */
2082 ah->ah_capabilities.cap_range.range_5ghz_max = 6100;
2084 /* Set supported modes */
2085 __set_bit(AR5K_MODE_11A,
2086 ah->ah_capabilities.cap_mode);
2087 __set_bit(AR5K_MODE_11A_TURBO,
2088 ah->ah_capabilities.cap_mode);
2089 if (ah->ah_version == AR5K_AR5212)
2090 __set_bit(AR5K_MODE_11G_TURBO,
2091 ah->ah_capabilities.cap_mode);
2094 /* Enable 802.11b if a 2GHz capable radio (2111/5112) is
2096 if (AR5K_EEPROM_HDR_11B(ee_header) ||
2097 AR5K_EEPROM_HDR_11G(ee_header)) {
2098 ah->ah_capabilities.cap_range.range_2ghz_min = 2412; /* 2312 */
2099 ah->ah_capabilities.cap_range.range_2ghz_max = 2732;
2101 if (AR5K_EEPROM_HDR_11B(ee_header))
2102 __set_bit(AR5K_MODE_11B,
2103 ah->ah_capabilities.cap_mode);
2105 if (AR5K_EEPROM_HDR_11G(ee_header))
2106 __set_bit(AR5K_MODE_11G,
2107 ah->ah_capabilities.cap_mode);
2112 ah->ah_gpio_npins = AR5K_NUM_GPIO;
2114 /* Set number of supported TX queues */
2115 if (ah->ah_version == AR5K_AR5210)
2116 ah->ah_capabilities.cap_queues.q_tx_num =
2117 AR5K_NUM_TX_QUEUES_NOQCU;
2119 ah->ah_capabilities.cap_queues.q_tx_num = AR5K_NUM_TX_QUEUES;
2124 /*********************************\
2125 Protocol Control Unit Functions
2126 \*********************************/
2129 * Set Operation mode
2131 int ath5k_hw_set_opmode(struct ath5k_hw *ah)
2133 u32 pcu_reg, beacon_reg, low_id, high_id;
2138 ATH5K_TRACE(ah->ah_sc);
2140 switch (ah->ah_op_mode) {
2141 case IEEE80211_IF_TYPE_IBSS:
2142 pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_DESC_ANTENNA |
2143 (ah->ah_version == AR5K_AR5210 ?
2144 AR5K_STA_ID1_NO_PSPOLL : 0);
2145 beacon_reg |= AR5K_BCR_ADHOC;
2148 case IEEE80211_IF_TYPE_AP:
2149 pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_RTS_DEF_ANTENNA |
2150 (ah->ah_version == AR5K_AR5210 ?
2151 AR5K_STA_ID1_NO_PSPOLL : 0);
2152 beacon_reg |= AR5K_BCR_AP;
2155 case IEEE80211_IF_TYPE_STA:
2156 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2157 (ah->ah_version == AR5K_AR5210 ?
2158 AR5K_STA_ID1_PWR_SV : 0);
2159 case IEEE80211_IF_TYPE_MNTR:
2160 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2161 (ah->ah_version == AR5K_AR5210 ?
2162 AR5K_STA_ID1_NO_PSPOLL : 0);
2172 low_id = AR5K_LOW_ID(ah->ah_sta_id);
2173 high_id = AR5K_HIGH_ID(ah->ah_sta_id);
2174 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2175 ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
2178 * Set Beacon Control Register on 5210
2180 if (ah->ah_version == AR5K_AR5210)
2181 ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR);
2193 void ath5k_hw_get_lladdr(struct ath5k_hw *ah, u8 *mac)
2195 ATH5K_TRACE(ah->ah_sc);
2196 memcpy(mac, ah->ah_sta_id, ETH_ALEN);
2202 int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
2204 u32 low_id, high_id;
2206 ATH5K_TRACE(ah->ah_sc);
2207 /* Set new station ID */
2208 memcpy(ah->ah_sta_id, mac, ETH_ALEN);
2210 low_id = AR5K_LOW_ID(mac);
2211 high_id = AR5K_HIGH_ID(mac);
2213 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2214 ath5k_hw_reg_write(ah, high_id, AR5K_STA_ID1);
2222 void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id)
2224 u32 low_id, high_id;
2228 * Set simple BSSID mask on 5212
2230 if (ah->ah_version == AR5K_AR5212) {
2231 ath5k_hw_reg_write(ah, 0xfffffff, AR5K_BSS_IDM0);
2232 ath5k_hw_reg_write(ah, 0xfffffff, AR5K_BSS_IDM1);
2236 * Set BSSID which triggers the "SME Join" operation
2238 low_id = AR5K_LOW_ID(bssid);
2239 high_id = AR5K_HIGH_ID(bssid);
2240 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_ID0);
2241 ath5k_hw_reg_write(ah, high_id | ((assoc_id & 0x3fff) <<
2242 AR5K_BSS_ID1_AID_S), AR5K_BSS_ID1);
2244 if (assoc_id == 0) {
2245 ath5k_hw_disable_pspoll(ah);
2249 AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM,
2250 tim_offset ? tim_offset + 4 : 0);
2252 ath5k_hw_enable_pspoll(ah, NULL, 0);
2255 * ath5k_hw_set_bssid_mask - set common bits we should listen to
2257 * The bssid_mask is a utility used by AR5212 hardware to inform the hardware
2258 * which bits of the interface's MAC address should be looked at when trying
2259 * to decide which packets to ACK. In station mode every bit matters. In AP
2260 * mode with a single BSS every bit matters as well. In AP mode with
2261 * multiple BSSes not every bit matters.
2263 * @ah: the &struct ath5k_hw
2264 * @mask: the bssid_mask, a u8 array of size ETH_ALEN
2266 * Note that this is a simple filter and *does* not filter out all
2267 * relevant frames. Some non-relevant frames will get through, probability
2268 * jocks are welcomed to compute.
2270 * When handling multiple BSSes (or VAPs) you can get the BSSID mask by
2271 * computing the set of:
2273 * ~ ( MAC XOR BSSID )
2275 * When you do this you are essentially computing the common bits. Later it
2276 * is assumed the harware will "and" (&) the BSSID mask with the MAC address
2277 * to obtain the relevant bits which should match on the destination frame.
2279 * Simple example: on your card you have have two BSSes you have created with
2280 * BSSID-01 and BSSID-02. Lets assume BSSID-01 will not use the MAC address.
2281 * There is another BSSID-03 but you are not part of it. For simplicity's sake,
2282 * assuming only 4 bits for a mac address and for BSSIDs you can then have:
2286 * BSSID-01: 0100 | --> Belongs to us
2289 * -------------------
2290 * BSSID-03: 0110 | --> External
2291 * -------------------
2293 * Our bssid_mask would then be:
2295 * On loop iteration for BSSID-01:
2296 * ~(0001 ^ 0100) -> ~(0101)
2300 * On loop iteration for BSSID-02:
2301 * bssid_mask &= ~(0001 ^ 1001)
2302 * bssid_mask = (1010) & ~(0001 ^ 1001)
2303 * bssid_mask = (1010) & ~(1001)
2304 * bssid_mask = (1010) & (0110)
2307 * A bssid_mask of 0010 means "only pay attention to the second least
2308 * significant bit". This is because its the only bit common
2309 * amongst the MAC and all BSSIDs we support. To findout what the real
2310 * common bit is we can simply "&" the bssid_mask now with any BSSID we have
2311 * or our MAC address (we assume the hardware uses the MAC address).
2313 * Now, suppose there's an incoming frame for BSSID-03:
2317 * An easy eye-inspeciton of this already should tell you that this frame
2318 * will not pass our check. This is beacuse the bssid_mask tells the
2319 * hardware to only look at the second least significant bit and the
2320 * common bit amongst the MAC and BSSIDs is 0, this frame has the 2nd LSB
2321 * as 1, which does not match 0.
2323 * So with IFRAME-01 we *assume* the hardware will do:
2325 * allow = (IFRAME-01 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2326 * --> allow = (0110 & 0010) == (0010 & 0001) ? 1 : 0;
2327 * --> allow = (0010) == 0000 ? 1 : 0;
2330 * Lets now test a frame that should work:
2332 * IFRAME-02: 0001 (we should allow)
2334 * allow = (0001 & 1010) == 1010
2336 * allow = (IFRAME-02 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2337 * --> allow = (0001 & 0010) == (0010 & 0001) ? 1 :0;
2338 * --> allow = (0010) == (0010)
2343 * IFRAME-03: 0100 --> allowed
2344 * IFRAME-04: 1001 --> allowed
2345 * IFRAME-05: 1101 --> allowed but its not for us!!!
2348 int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
2350 u32 low_id, high_id;
2351 ATH5K_TRACE(ah->ah_sc);
2353 if (ah->ah_version == AR5K_AR5212) {
2354 low_id = AR5K_LOW_ID(mask);
2355 high_id = AR5K_HIGH_ID(mask);
2357 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_IDM0);
2358 ath5k_hw_reg_write(ah, high_id, AR5K_BSS_IDM1);
2367 * Receive start/stop functions
2371 * Start receive on PCU
2373 void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
2375 ATH5K_TRACE(ah->ah_sc);
2376 AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
2380 * Stop receive on PCU
2382 void ath5k_hw_stop_pcu_recv(struct ath5k_hw *ah)
2384 ATH5K_TRACE(ah->ah_sc);
2385 AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
2389 * RX Filter functions
2393 * Set multicast filter
2395 void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
2397 ATH5K_TRACE(ah->ah_sc);
2398 /* Set the multicat filter */
2399 ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0);
2400 ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1);
2404 * Set multicast filter by index
2406 int ath5k_hw_set_mcast_filterindex(struct ath5k_hw *ah, u32 index)
2409 ATH5K_TRACE(ah->ah_sc);
2412 else if (index >= 32)
2413 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER1,
2414 (1 << (index - 32)));
2416 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2422 * Clear Multicast filter by index
2424 int ath5k_hw_clear_mcast_filter_idx(struct ath5k_hw *ah, u32 index)
2427 ATH5K_TRACE(ah->ah_sc);
2430 else if (index >= 32)
2431 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER1,
2432 (1 << (index - 32)));
2434 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2440 * Get current rx filter
2442 u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah)
2444 u32 data, filter = 0;
2446 ATH5K_TRACE(ah->ah_sc);
2447 filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER);
2449 /*Radar detection for 5212*/
2450 if (ah->ah_version == AR5K_AR5212) {
2451 data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL);
2453 if (data & AR5K_PHY_ERR_FIL_RADAR)
2454 filter |= AR5K_RX_FILTER_RADARERR;
2455 if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK))
2456 filter |= AR5K_RX_FILTER_PHYERR;
2465 void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
2469 ATH5K_TRACE(ah->ah_sc);
2471 /* Set PHY error filter register on 5212*/
2472 if (ah->ah_version == AR5K_AR5212) {
2473 if (filter & AR5K_RX_FILTER_RADARERR)
2474 data |= AR5K_PHY_ERR_FIL_RADAR;
2475 if (filter & AR5K_RX_FILTER_PHYERR)
2476 data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK;
2480 * The AR5210 uses promiscous mode to detect radar activity
2482 if (ah->ah_version == AR5K_AR5210 &&
2483 (filter & AR5K_RX_FILTER_RADARERR)) {
2484 filter &= ~AR5K_RX_FILTER_RADARERR;
2485 filter |= AR5K_RX_FILTER_PROM;
2490 AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2492 AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2494 /*Write RX Filter register*/
2495 ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER);
2497 /*Write PHY error filter register on 5212*/
2498 if (ah->ah_version == AR5K_AR5212)
2499 ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
2504 * Beacon related functions
2510 u32 ath5k_hw_get_tsf32(struct ath5k_hw *ah)
2512 ATH5K_TRACE(ah->ah_sc);
2513 return ath5k_hw_reg_read(ah, AR5K_TSF_L32);
2517 * Get the full 64bit TSF
2519 u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah)
2521 u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
2522 ATH5K_TRACE(ah->ah_sc);
2524 return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32);
2530 void ath5k_hw_reset_tsf(struct ath5k_hw *ah)
2532 ATH5K_TRACE(ah->ah_sc);
2533 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_RESET_TSF);
2537 * Initialize beacon timers
2539 void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
2541 u32 timer1, timer2, timer3;
2543 ATH5K_TRACE(ah->ah_sc);
2545 * Set the additional timers by mode
2547 switch (ah->ah_op_mode) {
2548 case IEEE80211_IF_TYPE_STA:
2549 if (ah->ah_version == AR5K_AR5210) {
2550 timer1 = 0xffffffff;
2551 timer2 = 0xffffffff;
2553 timer1 = 0x0000ffff;
2554 timer2 = 0x0007ffff;
2559 timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3;
2560 timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3;
2563 timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1);
2566 * Set the beacon register and enable all timers.
2567 * (next beacon, DMA beacon, software beacon, ATIM window time)
2569 ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
2570 ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
2571 ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
2572 ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
2574 ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD |
2575 AR5K_BEACON_RESET_TSF | AR5K_BEACON_ENABLE),
2583 int ath5k_hw_set_beacon_timers(struct ath5k_hw *ah,
2584 const struct ath5k_beacon_state *state)
2586 u32 cfp_period, next_cfp, dtim, interval, next_beacon;
2589 * TODO: should be changed through *state
2590 * review struct ath5k_beacon_state struct
2592 * XXX: These are used for cfp period bellow, are they
2593 * ok ? Is it O.K. for tsf here to be 0 or should we use
2596 u32 dtim_count = 0; /* XXX */
2597 u32 cfp_count = 0; /* XXX */
2598 u32 tsf = 0; /* XXX */
2600 ATH5K_TRACE(ah->ah_sc);
2601 /* Return on an invalid beacon state */
2602 if (state->bs_interval < 1)
2605 interval = state->bs_interval;
2606 dtim = state->bs_dtim_period;
2611 if (state->bs_cfp_period > 0) {
2613 * Enable PCF mode and set the CFP
2614 * (Contention Free Period) and timer registers
2616 cfp_period = state->bs_cfp_period * state->bs_dtim_period *
2618 next_cfp = (cfp_count * state->bs_dtim_period + dtim_count) *
2621 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
2622 AR5K_STA_ID1_DEFAULT_ANTENNA |
2624 ath5k_hw_reg_write(ah, cfp_period, AR5K_CFP_PERIOD);
2625 ath5k_hw_reg_write(ah, state->bs_cfp_max_duration,
2627 ath5k_hw_reg_write(ah, (tsf + (next_cfp == 0 ? cfp_period :
2628 next_cfp)) << 3, AR5K_TIMER2);
2630 /* Disable PCF mode */
2631 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2632 AR5K_STA_ID1_DEFAULT_ANTENNA |
2637 * Enable the beacon timer register
2639 ath5k_hw_reg_write(ah, state->bs_next_beacon, AR5K_TIMER0);
2642 * Start the beacon timers
2644 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_BEACON) &~
2645 (AR5K_BEACON_PERIOD | AR5K_BEACON_TIM)) |
2646 AR5K_REG_SM(state->bs_tim_offset ? state->bs_tim_offset + 4 : 0,
2647 AR5K_BEACON_TIM) | AR5K_REG_SM(state->bs_interval,
2648 AR5K_BEACON_PERIOD), AR5K_BEACON);
2651 * Write new beacon miss threshold, if it appears to be valid
2652 * XXX: Figure out right values for min <= bs_bmiss_threshold <= max
2653 * and return if its not in range. We can test this by reading value and
2654 * setting value to a largest value and seeing which values register.
2657 AR5K_REG_WRITE_BITS(ah, AR5K_RSSI_THR, AR5K_RSSI_THR_BMISS,
2658 state->bs_bmiss_threshold);
2661 * Set sleep control register
2662 * XXX: Didn't find this in 5210 code but since this register
2663 * exists also in ar5k's 5210 headers i leave it as common code.
2665 AR5K_REG_WRITE_BITS(ah, AR5K_SLEEP_CTL, AR5K_SLEEP_CTL_SLDUR,
2666 (state->bs_sleep_duration - 3) << 3);
2669 * Set enhanced sleep registers on 5212
2671 if (ah->ah_version == AR5K_AR5212) {
2672 if (state->bs_sleep_duration > state->bs_interval &&
2673 roundup(state->bs_sleep_duration, interval) ==
2674 state->bs_sleep_duration)
2675 interval = state->bs_sleep_duration;
2677 if (state->bs_sleep_duration > dtim && (dtim == 0 ||
2678 roundup(state->bs_sleep_duration, dtim) ==
2679 state->bs_sleep_duration))
2680 dtim = state->bs_sleep_duration;
2682 if (interval > dtim)
2685 next_beacon = interval == dtim ? state->bs_next_dtim :
2686 state->bs_next_beacon;
2688 ath5k_hw_reg_write(ah,
2689 AR5K_REG_SM((state->bs_next_dtim - 3) << 3,
2690 AR5K_SLEEP0_NEXT_DTIM) |
2691 AR5K_REG_SM(10, AR5K_SLEEP0_CABTO) |
2692 AR5K_SLEEP0_ENH_SLEEP_EN |
2693 AR5K_SLEEP0_ASSUME_DTIM, AR5K_SLEEP0);
2695 ath5k_hw_reg_write(ah, AR5K_REG_SM((next_beacon - 3) << 3,
2696 AR5K_SLEEP1_NEXT_TIM) |
2697 AR5K_REG_SM(10, AR5K_SLEEP1_BEACON_TO), AR5K_SLEEP1);
2699 ath5k_hw_reg_write(ah,
2700 AR5K_REG_SM(interval, AR5K_SLEEP2_TIM_PER) |
2701 AR5K_REG_SM(dtim, AR5K_SLEEP2_DTIM_PER), AR5K_SLEEP2);
2708 * Reset beacon timers
2710 void ath5k_hw_reset_beacon(struct ath5k_hw *ah)
2712 ATH5K_TRACE(ah->ah_sc);
2714 * Disable beacon timer
2716 ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
2719 * Disable some beacon register values
2721 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2722 AR5K_STA_ID1_DEFAULT_ANTENNA | AR5K_STA_ID1_PCF);
2723 ath5k_hw_reg_write(ah, AR5K_BEACON_PERIOD, AR5K_BEACON);
2727 * Wait for beacon queue to finish
2729 int ath5k_hw_beaconq_finish(struct ath5k_hw *ah, unsigned long phys_addr)
2734 ATH5K_TRACE(ah->ah_sc);
2736 /* 5210 doesn't have QCU*/
2737 if (ah->ah_version == AR5K_AR5210) {
2739 * Wait for beaconn queue to finish by checking
2740 * Control Register and Beacon Status Register.
2742 for (i = AR5K_TUNE_BEACON_INTERVAL / 2; i > 0; i--) {
2743 if (!(ath5k_hw_reg_read(ah, AR5K_BSR) & AR5K_BSR_TXQ1F)
2745 !(ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_BSR_TXQ1F))
2753 * Re-schedule the beacon queue
2755 ath5k_hw_reg_write(ah, phys_addr, AR5K_NOQCU_TXDP1);
2756 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
2764 ret = ath5k_hw_register_timeout(ah,
2765 AR5K_QUEUE_STATUS(AR5K_TX_QUEUE_ID_BEACON),
2766 AR5K_QCU_STS_FRMPENDCNT, 0, false);
2768 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, AR5K_TX_QUEUE_ID_BEACON))
2777 * Update mib counters (statistics)
2779 void ath5k_hw_update_mib_counters(struct ath5k_hw *ah,
2780 struct ath5k_mib_stats *statistics)
2782 ATH5K_TRACE(ah->ah_sc);
2783 /* Read-And-Clear */
2784 statistics->ackrcv_bad += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL);
2785 statistics->rts_bad += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL);
2786 statistics->rts_good += ath5k_hw_reg_read(ah, AR5K_RTS_OK);
2787 statistics->fcs_bad += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL);
2788 statistics->beacons += ath5k_hw_reg_read(ah, AR5K_BEACON_CNT);
2790 /* Reset profile count registers on 5212*/
2791 if (ah->ah_version == AR5K_AR5212) {
2792 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_TX);
2793 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RX);
2794 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR);
2795 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE);
2799 /** ath5k_hw_set_ack_bitrate - set bitrate for ACKs
2801 * @ah: the &struct ath5k_hw
2802 * @high: determines if to use low bit rate or now
2804 void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high)
2806 if (ah->ah_version != AR5K_AR5212)
2809 u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB;
2811 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val);
2813 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val);
2823 * Set ACK timeout on PCU
2825 int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout)
2827 ATH5K_TRACE(ah->ah_sc);
2828 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK),
2829 ah->ah_turbo) <= timeout)
2832 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK,
2833 ath5k_hw_htoclock(timeout, ah->ah_turbo));
2839 * Read the ACK timeout from PCU
2841 unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah)
2843 ATH5K_TRACE(ah->ah_sc);
2845 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
2846 AR5K_TIME_OUT), AR5K_TIME_OUT_ACK), ah->ah_turbo);
2850 * Set CTS timeout on PCU
2852 int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout)
2854 ATH5K_TRACE(ah->ah_sc);
2855 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS),
2856 ah->ah_turbo) <= timeout)
2859 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS,
2860 ath5k_hw_htoclock(timeout, ah->ah_turbo));
2866 * Read CTS timeout from PCU
2868 unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah)
2870 ATH5K_TRACE(ah->ah_sc);
2871 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
2872 AR5K_TIME_OUT), AR5K_TIME_OUT_CTS), ah->ah_turbo);
2876 * Key table (WEP) functions
2879 int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
2883 ATH5K_TRACE(ah->ah_sc);
2884 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
2886 for (i = 0; i < AR5K_KEYCACHE_SIZE; i++)
2887 ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i));
2889 /* Set NULL encryption on non-5210*/
2890 if (ah->ah_version != AR5K_AR5210)
2891 ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
2892 AR5K_KEYTABLE_TYPE(entry));
2897 int ath5k_hw_is_key_valid(struct ath5k_hw *ah, u16 entry)
2899 ATH5K_TRACE(ah->ah_sc);
2900 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
2902 /* Check the validation flag at the end of the entry */
2903 return ath5k_hw_reg_read(ah, AR5K_KEYTABLE_MAC1(entry)) &
2904 AR5K_KEYTABLE_VALID;
2907 int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
2908 const struct ieee80211_key_conf *key, const u8 *mac)
2911 __le32 key_v[5] = {};
2914 ATH5K_TRACE(ah->ah_sc);
2916 /* key->keylen comes in from mac80211 in bytes */
2918 if (key->keylen > AR5K_KEYTABLE_SIZE / 8)
2921 switch (key->keylen) {
2922 /* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit */
2924 memcpy(&key_v[0], key->key, 5);
2925 keytype = AR5K_KEYTABLE_TYPE_40;
2928 /* WEP 104-bit = 104-bit entered key + 24-bit IV = 128-bit */
2930 memcpy(&key_v[0], &key->key[0], 6);
2931 memcpy(&key_v[2], &key->key[6], 6);
2932 memcpy(&key_v[4], &key->key[12], 1);
2933 keytype = AR5K_KEYTABLE_TYPE_104;
2935 /* WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit */
2937 memcpy(&key_v[0], &key->key[0], 6);
2938 memcpy(&key_v[2], &key->key[6], 6);
2939 memcpy(&key_v[4], &key->key[12], 4);
2940 keytype = AR5K_KEYTABLE_TYPE_128;
2944 return -EINVAL; /* shouldn't happen */
2947 for (i = 0; i < ARRAY_SIZE(key_v); i++)
2948 ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
2949 AR5K_KEYTABLE_OFF(entry, i));
2951 ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry));
2953 return ath5k_hw_set_key_lladdr(ah, entry, mac);
2956 int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac)
2958 u32 low_id, high_id;
2960 ATH5K_TRACE(ah->ah_sc);
2961 /* Invalid entry (key table overflow) */
2962 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
2964 /* MAC may be NULL if it's a broadcast key. In this case no need to
2965 * to compute AR5K_LOW_ID and AR5K_HIGH_ID as we already know it. */
2966 if (unlikely(mac == NULL)) {
2967 low_id = 0xffffffff;
2968 high_id = 0xffff | AR5K_KEYTABLE_VALID;
2970 low_id = AR5K_LOW_ID(mac);
2971 high_id = AR5K_HIGH_ID(mac) | AR5K_KEYTABLE_VALID;
2974 ath5k_hw_reg_write(ah, low_id, AR5K_KEYTABLE_MAC0(entry));
2975 ath5k_hw_reg_write(ah, high_id, AR5K_KEYTABLE_MAC1(entry));
2981 /********************************************\
2982 Queue Control Unit, DFS Control Unit Functions
2983 \********************************************/
2986 * Initialize a transmit queue
2988 int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type,
2989 struct ath5k_txq_info *queue_info)
2994 ATH5K_TRACE(ah->ah_sc);
2999 /*5210 only has 2 queues*/
3000 if (ah->ah_version == AR5K_AR5210) {
3001 switch (queue_type) {
3002 case AR5K_TX_QUEUE_DATA:
3003 queue = AR5K_TX_QUEUE_ID_NOQCU_DATA;
3005 case AR5K_TX_QUEUE_BEACON:
3006 case AR5K_TX_QUEUE_CAB:
3007 queue = AR5K_TX_QUEUE_ID_NOQCU_BEACON;
3013 switch (queue_type) {
3014 case AR5K_TX_QUEUE_DATA:
3015 for (queue = AR5K_TX_QUEUE_ID_DATA_MIN;
3016 ah->ah_txq[queue].tqi_type !=
3017 AR5K_TX_QUEUE_INACTIVE; queue++) {
3019 if (queue > AR5K_TX_QUEUE_ID_DATA_MAX)
3023 case AR5K_TX_QUEUE_UAPSD:
3024 queue = AR5K_TX_QUEUE_ID_UAPSD;
3026 case AR5K_TX_QUEUE_BEACON:
3027 queue = AR5K_TX_QUEUE_ID_BEACON;
3029 case AR5K_TX_QUEUE_CAB:
3030 queue = AR5K_TX_QUEUE_ID_CAB;
3032 case AR5K_TX_QUEUE_XR_DATA:
3033 if (ah->ah_version != AR5K_AR5212)
3034 ATH5K_ERR(ah->ah_sc,
3035 "XR data queues only supported in"
3037 queue = AR5K_TX_QUEUE_ID_XR_DATA;
3045 * Setup internal queue structure
3047 memset(&ah->ah_txq[queue], 0, sizeof(struct ath5k_txq_info));
3048 ah->ah_txq[queue].tqi_type = queue_type;
3050 if (queue_info != NULL) {
3051 queue_info->tqi_type = queue_type;
3052 ret = ath5k_hw_setup_tx_queueprops(ah, queue, queue_info);
3057 * We use ah_txq_status to hold a temp value for
3058 * the Secondary interrupt mask registers on 5211+
3059 * check out ath5k_hw_reset_tx_queue
3061 AR5K_Q_ENABLE_BITS(ah->ah_txq_status, queue);
3067 * Setup a transmit queue
3069 int ath5k_hw_setup_tx_queueprops(struct ath5k_hw *ah, int queue,
3070 const struct ath5k_txq_info *queue_info)
3072 ATH5K_TRACE(ah->ah_sc);
3073 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3075 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3078 memcpy(&ah->ah_txq[queue], queue_info, sizeof(struct ath5k_txq_info));
3080 /*XXX: Is this supported on 5210 ?*/
3081 if ((queue_info->tqi_type == AR5K_TX_QUEUE_DATA &&
3082 ((queue_info->tqi_subtype == AR5K_WME_AC_VI) ||
3083 (queue_info->tqi_subtype == AR5K_WME_AC_VO))) ||
3084 queue_info->tqi_type == AR5K_TX_QUEUE_UAPSD)
3085 ah->ah_txq[queue].tqi_flags |= AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
3091 * Get properties for a specific transmit queue
3093 int ath5k_hw_get_tx_queueprops(struct ath5k_hw *ah, int queue,
3094 struct ath5k_txq_info *queue_info)
3096 ATH5K_TRACE(ah->ah_sc);
3097 memcpy(queue_info, &ah->ah_txq[queue], sizeof(struct ath5k_txq_info));
3102 * Set a transmit queue inactive
3104 void ath5k_hw_release_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3106 ATH5K_TRACE(ah->ah_sc);
3107 if (WARN_ON(queue >= ah->ah_capabilities.cap_queues.q_tx_num))
3110 /* This queue will be skipped in further operations */
3111 ah->ah_txq[queue].tqi_type = AR5K_TX_QUEUE_INACTIVE;
3113 AR5K_Q_DISABLE_BITS(ah->ah_txq_status, queue);
3117 * Set DFS params for a transmit queue
3119 int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3121 u32 cw_min, cw_max, retry_lg, retry_sh;
3122 struct ath5k_txq_info *tq = &ah->ah_txq[queue];
3124 ATH5K_TRACE(ah->ah_sc);
3125 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3127 tq = &ah->ah_txq[queue];
3129 if (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE)
3132 if (ah->ah_version == AR5K_AR5210) {
3133 /* Only handle data queues, others will be ignored */
3134 if (tq->tqi_type != AR5K_TX_QUEUE_DATA)
3138 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3139 AR5K_INIT_SLOT_TIME_TURBO : AR5K_INIT_SLOT_TIME,
3141 /* Set ACK_CTS timeout */
3142 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3143 AR5K_INIT_ACK_CTS_TIMEOUT_TURBO :
3144 AR5K_INIT_ACK_CTS_TIMEOUT, AR5K_SLOT_TIME);
3145 /* Set Transmit Latency */
3146 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3147 AR5K_INIT_TRANSMIT_LATENCY_TURBO :
3148 AR5K_INIT_TRANSMIT_LATENCY, AR5K_USEC_5210);
3150 if (ah->ah_turbo == true)
3151 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS_TURBO +
3152 (ah->ah_aifs + tq->tqi_aifs) *
3153 AR5K_INIT_SLOT_TIME_TURBO) <<
3154 AR5K_IFS0_DIFS_S) | AR5K_INIT_SIFS_TURBO,
3157 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS +
3158 (ah->ah_aifs + tq->tqi_aifs) *
3159 AR5K_INIT_SLOT_TIME) << AR5K_IFS0_DIFS_S) |
3160 AR5K_INIT_SIFS, AR5K_IFS0);
3163 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3164 AR5K_INIT_PROTO_TIME_CNTRL_TURBO :
3165 AR5K_INIT_PROTO_TIME_CNTRL, AR5K_IFS1);
3166 /* Set PHY register 0x9844 (??) */
3167 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3168 (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x38 :
3169 (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x1C,
3171 /* Set Frame Control Register */
3172 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3173 (AR5K_PHY_FRAME_CTL_INI | AR5K_PHY_TURBO_MODE |
3174 AR5K_PHY_TURBO_SHORT | 0x2020) :
3175 (AR5K_PHY_FRAME_CTL_INI | 0x1020),
3176 AR5K_PHY_FRAME_CTL_5210);
3180 * Calculate cwmin/max by channel mode
3182 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN;
3183 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX;
3184 ah->ah_aifs = AR5K_TUNE_AIFS;
3185 /*XR is only supported on 5212*/
3186 if (IS_CHAN_XR(ah->ah_current_channel) &&
3187 ah->ah_version == AR5K_AR5212) {
3188 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_XR;
3189 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_XR;
3190 ah->ah_aifs = AR5K_TUNE_AIFS_XR;
3191 /*B mode is not supported on 5210*/
3192 } else if (IS_CHAN_B(ah->ah_current_channel) &&
3193 ah->ah_version != AR5K_AR5210) {
3194 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_11B;
3195 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_11B;
3196 ah->ah_aifs = AR5K_TUNE_AIFS_11B;
3200 while (cw_min < ah->ah_cw_min)
3201 cw_min = (cw_min << 1) | 1;
3203 cw_min = tq->tqi_cw_min < 0 ? (cw_min >> (-tq->tqi_cw_min)) :
3204 ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
3205 cw_max = tq->tqi_cw_max < 0 ? (cw_max >> (-tq->tqi_cw_max)) :
3206 ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
3209 * Calculate and set retry limits
3211 if (ah->ah_software_retry == true) {
3212 /* XXX Need to test this */
3213 retry_lg = ah->ah_limit_tx_retries;
3214 retry_sh = retry_lg = retry_lg > AR5K_DCU_RETRY_LMT_SH_RETRY ?
3215 AR5K_DCU_RETRY_LMT_SH_RETRY : retry_lg;
3217 retry_lg = AR5K_INIT_LG_RETRY;
3218 retry_sh = AR5K_INIT_SH_RETRY;
3221 /*No QCU/DCU [5210]*/
3222 if (ah->ah_version == AR5K_AR5210) {
3223 ath5k_hw_reg_write(ah,
3224 (cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
3225 | AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3226 AR5K_NODCU_RETRY_LMT_SLG_RETRY)
3227 | AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3228 AR5K_NODCU_RETRY_LMT_SSH_RETRY)
3229 | AR5K_REG_SM(retry_lg, AR5K_NODCU_RETRY_LMT_LG_RETRY)
3230 | AR5K_REG_SM(retry_sh, AR5K_NODCU_RETRY_LMT_SH_RETRY),
3231 AR5K_NODCU_RETRY_LMT);
3234 ath5k_hw_reg_write(ah,
3235 AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3236 AR5K_DCU_RETRY_LMT_SLG_RETRY) |
3237 AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3238 AR5K_DCU_RETRY_LMT_SSH_RETRY) |
3239 AR5K_REG_SM(retry_lg, AR5K_DCU_RETRY_LMT_LG_RETRY) |
3240 AR5K_REG_SM(retry_sh, AR5K_DCU_RETRY_LMT_SH_RETRY),
3241 AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
3243 /*===Rest is also for QCU/DCU only [5211+]===*/
3246 * Set initial content window (cw_min/cw_max)
3247 * and arbitrated interframe space (aifs)...
3249 ath5k_hw_reg_write(ah,
3250 AR5K_REG_SM(cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
3251 AR5K_REG_SM(cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
3252 AR5K_REG_SM(ah->ah_aifs + tq->tqi_aifs,
3253 AR5K_DCU_LCL_IFS_AIFS),
3254 AR5K_QUEUE_DFS_LOCAL_IFS(queue));
3257 * Set misc registers
3259 ath5k_hw_reg_write(ah, AR5K_QCU_MISC_DCU_EARLY,
3260 AR5K_QUEUE_MISC(queue));
3262 if (tq->tqi_cbr_period) {
3263 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
3264 AR5K_QCU_CBRCFG_INTVAL) |
3265 AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
3266 AR5K_QCU_CBRCFG_ORN_THRES),
3267 AR5K_QUEUE_CBRCFG(queue));
3268 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3269 AR5K_QCU_MISC_FRSHED_CBR);
3270 if (tq->tqi_cbr_overflow_limit)
3271 AR5K_REG_ENABLE_BITS(ah,
3272 AR5K_QUEUE_MISC(queue),
3273 AR5K_QCU_MISC_CBR_THRES_ENABLE);
3276 if (tq->tqi_ready_time)
3277 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
3278 AR5K_QCU_RDYTIMECFG_INTVAL) |
3279 AR5K_QCU_RDYTIMECFG_ENABLE,
3280 AR5K_QUEUE_RDYTIMECFG(queue));
3282 if (tq->tqi_burst_time) {
3283 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
3284 AR5K_DCU_CHAN_TIME_DUR) |
3285 AR5K_DCU_CHAN_TIME_ENABLE,
3286 AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
3288 if (tq->tqi_flags & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
3289 AR5K_REG_ENABLE_BITS(ah,
3290 AR5K_QUEUE_MISC(queue),
3294 if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
3295 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
3296 AR5K_QUEUE_DFS_MISC(queue));
3298 if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
3299 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
3300 AR5K_QUEUE_DFS_MISC(queue));
3303 * Set registers by queue type
3305 switch (tq->tqi_type) {
3306 case AR5K_TX_QUEUE_BEACON:
3307 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3308 AR5K_QCU_MISC_FRSHED_DBA_GT |
3309 AR5K_QCU_MISC_CBREXP_BCN |
3310 AR5K_QCU_MISC_BCN_ENABLE);
3312 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3313 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3314 AR5K_DCU_MISC_ARBLOCK_CTL_S) |
3315 AR5K_DCU_MISC_POST_FR_BKOFF_DIS |
3316 AR5K_DCU_MISC_BCN_ENABLE);
3318 ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL -
3319 (AR5K_TUNE_SW_BEACON_RESP -
3320 AR5K_TUNE_DMA_BEACON_RESP) -
3321 AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF) * 1024) |
3322 AR5K_QCU_RDYTIMECFG_ENABLE,
3323 AR5K_QUEUE_RDYTIMECFG(queue));
3326 case AR5K_TX_QUEUE_CAB:
3327 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3328 AR5K_QCU_MISC_FRSHED_DBA_GT |
3329 AR5K_QCU_MISC_CBREXP |
3330 AR5K_QCU_MISC_CBREXP_BCN);
3332 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3333 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3334 AR5K_DCU_MISC_ARBLOCK_CTL_S));
3337 case AR5K_TX_QUEUE_UAPSD:
3338 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3339 AR5K_QCU_MISC_CBREXP);
3342 case AR5K_TX_QUEUE_DATA:
3348 * Enable interrupts for this tx queue
3349 * in the secondary interrupt mask registers
3351 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
3352 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
3354 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
3355 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
3357 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
3358 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
3360 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
3361 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
3363 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
3364 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
3367 /* Update secondary interrupt mask registers */
3368 ah->ah_txq_imr_txok &= ah->ah_txq_status;
3369 ah->ah_txq_imr_txerr &= ah->ah_txq_status;
3370 ah->ah_txq_imr_txurn &= ah->ah_txq_status;
3371 ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
3372 ah->ah_txq_imr_txeol &= ah->ah_txq_status;
3374 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
3375 AR5K_SIMR0_QCU_TXOK) |
3376 AR5K_REG_SM(ah->ah_txq_imr_txdesc,
3377 AR5K_SIMR0_QCU_TXDESC), AR5K_SIMR0);
3378 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
3379 AR5K_SIMR1_QCU_TXERR) |
3380 AR5K_REG_SM(ah->ah_txq_imr_txeol,
3381 AR5K_SIMR1_QCU_TXEOL), AR5K_SIMR1);
3382 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txurn,
3383 AR5K_SIMR2_QCU_TXURN), AR5K_SIMR2);
3390 * Get number of pending frames
3391 * for a specific queue [5211+]
3393 u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah, unsigned int queue) {
3394 ATH5K_TRACE(ah->ah_sc);
3395 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3397 /* Return if queue is declared inactive */
3398 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3401 /* XXX: How about AR5K_CFG_TXCNT ? */
3402 if (ah->ah_version == AR5K_AR5210)
3405 return AR5K_QUEUE_STATUS(queue) & AR5K_QCU_STS_FRMPENDCNT;
3411 int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time)
3413 ATH5K_TRACE(ah->ah_sc);
3414 if (slot_time < AR5K_SLOT_TIME_9 || slot_time > AR5K_SLOT_TIME_MAX)
3417 if (ah->ah_version == AR5K_AR5210)
3418 ath5k_hw_reg_write(ah, ath5k_hw_htoclock(slot_time,
3419 ah->ah_turbo), AR5K_SLOT_TIME);
3421 ath5k_hw_reg_write(ah, slot_time, AR5K_DCU_GBL_IFS_SLOT);
3429 unsigned int ath5k_hw_get_slot_time(struct ath5k_hw *ah)
3431 ATH5K_TRACE(ah->ah_sc);
3432 if (ah->ah_version == AR5K_AR5210)
3433 return ath5k_hw_clocktoh(ath5k_hw_reg_read(ah,
3434 AR5K_SLOT_TIME) & 0xffff, ah->ah_turbo);
3436 return ath5k_hw_reg_read(ah, AR5K_DCU_GBL_IFS_SLOT) & 0xffff;
3440 /******************************\
3441 Hardware Descriptor Functions
3442 \******************************/
3449 * Initialize the 2-word tx descriptor on 5210/5211
3452 ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3453 unsigned int pkt_len, unsigned int hdr_len, enum ath5k_pkt_type type,
3454 unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
3455 unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
3456 unsigned int rtscts_rate, unsigned int rtscts_duration)
3459 struct ath5k_hw_2w_tx_desc *tx_desc;
3460 unsigned int frame_len;
3462 tx_desc = (struct ath5k_hw_2w_tx_desc *)&desc->ds_ctl0;
3466 * - Zero retries don't make sense.
3467 * - A zero rate will put the HW into a mode where it continously sends
3468 * noise on the channel, so it is important to avoid this.
3470 if (unlikely(tx_tries0 == 0)) {
3471 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3475 if (unlikely(tx_rate0 == 0)) {
3476 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3481 /* Clear status descriptor */
3482 memset(desc->ds_hw, 0, sizeof(struct ath5k_hw_tx_status));
3484 /* Initialize control descriptor */
3485 tx_desc->tx_control_0 = 0;
3486 tx_desc->tx_control_1 = 0;
3488 /* Setup control descriptor */
3490 /* Verify and set frame length */
3492 /* remove padding we might have added before */
3493 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3495 if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
3498 tx_desc->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
3500 /* Verify and set buffer length */
3502 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3503 if(type == AR5K_PKT_TYPE_BEACON)
3504 pkt_len = roundup(pkt_len, 4);
3506 if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
3509 tx_desc->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
3512 * Verify and set header length
3513 * XXX: I only found that on 5210 code, does it work on 5211 ?
3515 if (ah->ah_version == AR5K_AR5210) {
3516 if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN)
3518 tx_desc->tx_control_0 |=
3519 AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN);
3522 /*Diferences between 5210-5211*/
3523 if (ah->ah_version == AR5K_AR5210) {
3525 case AR5K_PKT_TYPE_BEACON:
3526 case AR5K_PKT_TYPE_PROBE_RESP:
3527 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
3528 case AR5K_PKT_TYPE_PIFS:
3529 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
3531 frame_type = type /*<< 2 ?*/;
3534 tx_desc->tx_control_0 |=
3535 AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE) |
3536 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3538 tx_desc->tx_control_0 |=
3539 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
3540 AR5K_REG_SM(antenna_mode, AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
3541 tx_desc->tx_control_1 |=
3542 AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE);
3544 #define _TX_FLAGS(_c, _flag) \
3545 if (flags & AR5K_TXDESC_##_flag) \
3546 tx_desc->tx_control_##_c |= \
3547 AR5K_2W_TX_DESC_CTL##_c##_##_flag
3549 _TX_FLAGS(0, CLRDMASK);
3551 _TX_FLAGS(0, INTREQ);
3552 _TX_FLAGS(0, RTSENA);
3553 _TX_FLAGS(1, NOACK);
3560 if (key_index != AR5K_TXKEYIX_INVALID) {
3561 tx_desc->tx_control_0 |=
3562 AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3563 tx_desc->tx_control_1 |=
3564 AR5K_REG_SM(key_index,
3565 AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3569 * RTS/CTS Duration [5210 ?]
3571 if ((ah->ah_version == AR5K_AR5210) &&
3572 (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
3573 tx_desc->tx_control_1 |= rtscts_duration &
3574 AR5K_2W_TX_DESC_CTL1_RTS_DURATION;
3580 * Initialize the 4-word tx descriptor on 5212
3582 static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
3583 struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
3584 enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
3585 unsigned int tx_tries0, unsigned int key_index,
3586 unsigned int antenna_mode, unsigned int flags, unsigned int rtscts_rate,
3587 unsigned int rtscts_duration)
3589 struct ath5k_hw_4w_tx_desc *tx_desc;
3590 struct ath5k_hw_tx_status *tx_status;
3591 unsigned int frame_len;
3593 ATH5K_TRACE(ah->ah_sc);
3594 tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
3595 tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[2];
3599 * - Zero retries don't make sense.
3600 * - A zero rate will put the HW into a mode where it continously sends
3601 * noise on the channel, so it is important to avoid this.
3603 if (unlikely(tx_tries0 == 0)) {
3604 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3608 if (unlikely(tx_rate0 == 0)) {
3609 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3614 /* Clear status descriptor */
3615 memset(tx_status, 0, sizeof(struct ath5k_hw_tx_status));
3617 /* Initialize control descriptor */
3618 tx_desc->tx_control_0 = 0;
3619 tx_desc->tx_control_1 = 0;
3620 tx_desc->tx_control_2 = 0;
3621 tx_desc->tx_control_3 = 0;
3623 /* Setup control descriptor */
3625 /* Verify and set frame length */
3627 /* remove padding we might have added before */
3628 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3630 if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
3633 tx_desc->tx_control_0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
3635 /* Verify and set buffer length */
3637 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3638 if(type == AR5K_PKT_TYPE_BEACON)
3639 pkt_len = roundup(pkt_len, 4);
3641 if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
3644 tx_desc->tx_control_1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
3646 tx_desc->tx_control_0 |=
3647 AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
3648 AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
3649 tx_desc->tx_control_1 |= AR5K_REG_SM(type,
3650 AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
3651 tx_desc->tx_control_2 = AR5K_REG_SM(tx_tries0 + AR5K_TUNE_HWTXTRIES,
3652 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
3653 tx_desc->tx_control_3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
3655 #define _TX_FLAGS(_c, _flag) \
3656 if (flags & AR5K_TXDESC_##_flag) \
3657 tx_desc->tx_control_##_c |= \
3658 AR5K_4W_TX_DESC_CTL##_c##_##_flag
3660 _TX_FLAGS(0, CLRDMASK);
3662 _TX_FLAGS(0, INTREQ);
3663 _TX_FLAGS(0, RTSENA);
3664 _TX_FLAGS(0, CTSENA);
3665 _TX_FLAGS(1, NOACK);
3672 if (key_index != AR5K_TXKEYIX_INVALID) {
3673 tx_desc->tx_control_0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3674 tx_desc->tx_control_1 |= AR5K_REG_SM(key_index,
3675 AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3681 if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
3682 if ((flags & AR5K_TXDESC_RTSENA) &&
3683 (flags & AR5K_TXDESC_CTSENA))
3685 tx_desc->tx_control_2 |= rtscts_duration &
3686 AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
3687 tx_desc->tx_control_3 |= AR5K_REG_SM(rtscts_rate,
3688 AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
3695 * Initialize a 4-word multirate tx descriptor on 5212
3698 ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3699 unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2, u_int tx_tries2,
3700 unsigned int tx_rate3, u_int tx_tries3)
3702 struct ath5k_hw_4w_tx_desc *tx_desc;
3705 * Rates can be 0 as long as the retry count is 0 too.
3706 * A zero rate and nonzero retry count will put the HW into a mode where
3707 * it continously sends noise on the channel, so it is important to
3710 if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
3711 (tx_rate2 == 0 && tx_tries2 != 0) ||
3712 (tx_rate3 == 0 && tx_tries3 != 0))) {
3713 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3718 if (ah->ah_version == AR5K_AR5212) {
3719 tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
3721 #define _XTX_TRIES(_n) \
3722 if (tx_tries##_n) { \
3723 tx_desc->tx_control_2 |= \
3724 AR5K_REG_SM(tx_tries##_n, \
3725 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
3726 tx_desc->tx_control_3 |= \
3727 AR5K_REG_SM(tx_rate##_n, \
3728 AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
3744 * Proccess the tx status descriptor on 5210/5211
3746 static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
3747 struct ath5k_desc *desc)
3749 struct ath5k_hw_tx_status *tx_status;
3750 struct ath5k_hw_2w_tx_desc *tx_desc;
3752 tx_desc = (struct ath5k_hw_2w_tx_desc *)&desc->ds_ctl0;
3753 tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[0];
3755 /* No frame has been send or error */
3756 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
3757 return -EINPROGRESS;
3760 * Get descriptor status
3762 desc->ds_us.tx.ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
3763 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
3764 desc->ds_us.tx.ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
3765 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
3766 desc->ds_us.tx.ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
3767 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
3768 /*TODO: desc->ds_us.tx.ts_virtcol + test*/
3769 desc->ds_us.tx.ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
3770 AR5K_DESC_TX_STATUS1_SEQ_NUM);
3771 desc->ds_us.tx.ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
3772 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
3773 desc->ds_us.tx.ts_antenna = 1;
3774 desc->ds_us.tx.ts_status = 0;
3775 desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_0,
3776 AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3778 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
3779 if (tx_status->tx_status_0 &
3780 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
3781 desc->ds_us.tx.ts_status |= AR5K_TXERR_XRETRY;
3783 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
3784 desc->ds_us.tx.ts_status |= AR5K_TXERR_FIFO;
3786 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
3787 desc->ds_us.tx.ts_status |= AR5K_TXERR_FILT;
3794 * Proccess a tx descriptor on 5212
3796 static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
3797 struct ath5k_desc *desc)
3799 struct ath5k_hw_tx_status *tx_status;
3800 struct ath5k_hw_4w_tx_desc *tx_desc;
3802 ATH5K_TRACE(ah->ah_sc);
3803 tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
3804 tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[2];
3806 /* No frame has been send or error */
3807 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
3808 return -EINPROGRESS;
3811 * Get descriptor status
3813 desc->ds_us.tx.ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
3814 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
3815 desc->ds_us.tx.ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
3816 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
3817 desc->ds_us.tx.ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
3818 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
3819 desc->ds_us.tx.ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
3820 AR5K_DESC_TX_STATUS1_SEQ_NUM);
3821 desc->ds_us.tx.ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
3822 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
3823 desc->ds_us.tx.ts_antenna = (tx_status->tx_status_1 &
3824 AR5K_DESC_TX_STATUS1_XMIT_ANTENNA) ? 2 : 1;
3825 desc->ds_us.tx.ts_status = 0;
3827 switch (AR5K_REG_MS(tx_status->tx_status_1,
3828 AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX)) {
3830 desc->ds_us.tx.ts_rate = tx_desc->tx_control_3 &
3831 AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
3834 desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
3835 AR5K_4W_TX_DESC_CTL3_XMIT_RATE1);
3836 desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
3837 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1);
3840 desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
3841 AR5K_4W_TX_DESC_CTL3_XMIT_RATE2);
3842 desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
3843 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2);
3846 desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
3847 AR5K_4W_TX_DESC_CTL3_XMIT_RATE3);
3848 desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
3849 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES3);
3853 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
3854 if (tx_status->tx_status_0 &
3855 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
3856 desc->ds_us.tx.ts_status |= AR5K_TXERR_XRETRY;
3858 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
3859 desc->ds_us.tx.ts_status |= AR5K_TXERR_FIFO;
3861 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
3862 desc->ds_us.tx.ts_status |= AR5K_TXERR_FILT;
3873 * Initialize an rx descriptor
3875 int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3876 u32 size, unsigned int flags)
3878 struct ath5k_rx_desc *rx_desc;
3880 ATH5K_TRACE(ah->ah_sc);
3881 rx_desc = (struct ath5k_rx_desc *)&desc->ds_ctl0;
3885 * If we don't clean the status descriptor,
3886 * while scanning we get too many results,
3887 * most of them virtual, after some secs
3888 * of scanning system hangs. M.F.
3890 memset(desc->ds_hw, 0, sizeof(desc->ds_hw));
3892 /*Initialize rx descriptor*/
3893 rx_desc->rx_control_0 = 0;
3894 rx_desc->rx_control_1 = 0;
3896 /* Setup descriptor */
3897 rx_desc->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
3898 if (unlikely(rx_desc->rx_control_1 != size))
3901 if (flags & AR5K_RXDESC_INTREQ)
3902 rx_desc->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
3908 * Proccess the rx status descriptor on 5210/5211
3910 static int ath5k_hw_proc_old_rx_status(struct ath5k_hw *ah,
3911 struct ath5k_desc *desc)
3913 struct ath5k_hw_old_rx_status *rx_status;
3915 rx_status = (struct ath5k_hw_old_rx_status *)&desc->ds_hw[0];
3917 /* No frame received / not ready */
3918 if (unlikely((rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_DONE)
3920 return -EINPROGRESS;
3923 * Frame receive status
3925 desc->ds_us.rx.rs_datalen = rx_status->rx_status_0 &
3926 AR5K_OLD_RX_DESC_STATUS0_DATA_LEN;
3927 desc->ds_us.rx.rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
3928 AR5K_OLD_RX_DESC_STATUS0_RECEIVE_SIGNAL);
3929 desc->ds_us.rx.rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
3930 AR5K_OLD_RX_DESC_STATUS0_RECEIVE_RATE);
3931 desc->ds_us.rx.rs_antenna = rx_status->rx_status_0 &
3932 AR5K_OLD_RX_DESC_STATUS0_RECEIVE_ANTENNA;
3933 desc->ds_us.rx.rs_more = rx_status->rx_status_0 &
3934 AR5K_OLD_RX_DESC_STATUS0_MORE;
3935 desc->ds_us.rx.rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
3936 AR5K_OLD_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
3937 desc->ds_us.rx.rs_status = 0;
3942 if (rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_KEY_INDEX_VALID)
3943 desc->ds_us.rx.rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
3944 AR5K_OLD_RX_DESC_STATUS1_KEY_INDEX);
3946 desc->ds_us.rx.rs_keyix = AR5K_RXKEYIX_INVALID;
3949 * Receive/descriptor errors
3951 if ((rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_FRAME_RECEIVE_OK)
3953 if (rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_CRC_ERROR)
3954 desc->ds_us.rx.rs_status |= AR5K_RXERR_CRC;
3956 if (rx_status->rx_status_1 &
3957 AR5K_OLD_RX_DESC_STATUS1_FIFO_OVERRUN)
3958 desc->ds_us.rx.rs_status |= AR5K_RXERR_FIFO;
3960 if (rx_status->rx_status_1 &
3961 AR5K_OLD_RX_DESC_STATUS1_PHY_ERROR) {
3962 desc->ds_us.rx.rs_status |= AR5K_RXERR_PHY;
3963 desc->ds_us.rx.rs_phyerr =
3964 AR5K_REG_MS(rx_status->rx_status_1,
3965 AR5K_OLD_RX_DESC_STATUS1_PHY_ERROR);
3968 if (rx_status->rx_status_1 &
3969 AR5K_OLD_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
3970 desc->ds_us.rx.rs_status |= AR5K_RXERR_DECRYPT;
3977 * Proccess the rx status descriptor on 5212
3979 static int ath5k_hw_proc_new_rx_status(struct ath5k_hw *ah,
3980 struct ath5k_desc *desc)
3982 struct ath5k_hw_new_rx_status *rx_status;
3983 struct ath5k_hw_rx_error *rx_err;
3985 ATH5K_TRACE(ah->ah_sc);
3986 rx_status = (struct ath5k_hw_new_rx_status *)&desc->ds_hw[0];
3988 /* Overlay on error */
3989 rx_err = (struct ath5k_hw_rx_error *)&desc->ds_hw[0];
3991 /* No frame received / not ready */
3992 if (unlikely((rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_DONE)
3994 return -EINPROGRESS;
3997 * Frame receive status
3999 desc->ds_us.rx.rs_datalen = rx_status->rx_status_0 &
4000 AR5K_NEW_RX_DESC_STATUS0_DATA_LEN;
4001 desc->ds_us.rx.rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
4002 AR5K_NEW_RX_DESC_STATUS0_RECEIVE_SIGNAL);
4003 desc->ds_us.rx.rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
4004 AR5K_NEW_RX_DESC_STATUS0_RECEIVE_RATE);
4005 desc->ds_us.rx.rs_antenna = rx_status->rx_status_0 &
4006 AR5K_NEW_RX_DESC_STATUS0_RECEIVE_ANTENNA;
4007 desc->ds_us.rx.rs_more = rx_status->rx_status_0 &
4008 AR5K_NEW_RX_DESC_STATUS0_MORE;
4009 desc->ds_us.rx.rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
4010 AR5K_NEW_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
4011 desc->ds_us.rx.rs_status = 0;
4016 if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_KEY_INDEX_VALID)
4017 desc->ds_us.rx.rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
4018 AR5K_NEW_RX_DESC_STATUS1_KEY_INDEX);
4020 desc->ds_us.rx.rs_keyix = AR5K_RXKEYIX_INVALID;
4023 * Receive/descriptor errors
4025 if ((rx_status->rx_status_1 &
4026 AR5K_NEW_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
4027 if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_CRC_ERROR)
4028 desc->ds_us.rx.rs_status |= AR5K_RXERR_CRC;
4030 if (rx_status->rx_status_1 &
4031 AR5K_NEW_RX_DESC_STATUS1_PHY_ERROR) {
4032 desc->ds_us.rx.rs_status |= AR5K_RXERR_PHY;
4033 desc->ds_us.rx.rs_phyerr =
4034 AR5K_REG_MS(rx_err->rx_error_1,
4035 AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE);
4038 if (rx_status->rx_status_1 &
4039 AR5K_NEW_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
4040 desc->ds_us.rx.rs_status |= AR5K_RXERR_DECRYPT;
4042 if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_MIC_ERROR)
4043 desc->ds_us.rx.rs_status |= AR5K_RXERR_MIC;
4057 void ath5k_hw_set_ledstate(struct ath5k_hw *ah, unsigned int state)
4060 /*5210 has different led mode handling*/
4063 ATH5K_TRACE(ah->ah_sc);
4065 /*Reset led status*/
4066 if (ah->ah_version != AR5K_AR5210)
4067 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
4068 AR5K_PCICFG_LEDMODE | AR5K_PCICFG_LED);
4070 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_LED);
4073 * Some blinking values, define at your wish
4078 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_PEND;
4079 led_5210 = AR5K_PCICFG_LED_PEND | AR5K_PCICFG_LED_BCTL;
4083 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_NONE;
4084 led_5210 = AR5K_PCICFG_LED_PEND;
4087 case AR5K_LED_ASSOC:
4089 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_ASSOC;
4090 led_5210 = AR5K_PCICFG_LED_ASSOC;
4094 led = AR5K_PCICFG_LEDMODE_PROM | AR5K_PCICFG_LED_NONE;
4095 led_5210 = AR5K_PCICFG_LED_PEND;
4099 /*Write new status to the register*/
4100 if (ah->ah_version != AR5K_AR5210)
4101 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led);
4103 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led_5210);
4109 int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
4111 ATH5K_TRACE(ah->ah_sc);
4112 if (gpio > AR5K_NUM_GPIO)
4115 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4116 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR);
4124 int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
4126 ATH5K_TRACE(ah->ah_sc);
4127 if (gpio > AR5K_NUM_GPIO)
4130 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4131 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR);
4139 u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
4141 ATH5K_TRACE(ah->ah_sc);
4142 if (gpio > AR5K_NUM_GPIO)
4145 /* GPIO input magic */
4146 return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) &
4153 int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
4156 ATH5K_TRACE(ah->ah_sc);
4158 if (gpio > AR5K_NUM_GPIO)
4161 /* GPIO output magic */
4162 data = ath5k_hw_reg_read(ah, AR5K_GPIODO);
4164 data &= ~(1 << gpio);
4165 data |= (val & 1) << gpio;
4167 ath5k_hw_reg_write(ah, data, AR5K_GPIODO);
4173 * Initialize the GPIO interrupt (RFKill switch)
4175 void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
4176 u32 interrupt_level)
4180 ATH5K_TRACE(ah->ah_sc);
4181 if (gpio > AR5K_NUM_GPIO)
4185 * Set the GPIO interrupt
4187 data = (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &
4188 ~(AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_SELH |
4189 AR5K_GPIOCR_INT_ENA | AR5K_GPIOCR_OUT(gpio))) |
4190 (AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_ENA);
4192 ath5k_hw_reg_write(ah, interrupt_level ? data :
4193 (data | AR5K_GPIOCR_INT_SELH), AR5K_GPIOCR);
4195 ah->ah_imr |= AR5K_IMR_GPIO;
4197 /* Enable GPIO interrupts */
4198 AR5K_REG_ENABLE_BITS(ah, AR5K_PIMR, AR5K_IMR_GPIO);
4208 int ath5k_hw_get_capability(struct ath5k_hw *ah,
4209 enum ath5k_capability_type cap_type,
4210 u32 capability, u32 *result)
4212 ATH5K_TRACE(ah->ah_sc);
4215 case AR5K_CAP_NUM_TXQUEUES:
4217 if (ah->ah_version == AR5K_AR5210)
4218 *result = AR5K_NUM_TX_QUEUES_NOQCU;
4220 *result = AR5K_NUM_TX_QUEUES;
4225 case AR5K_CAP_COMPRESSION:
4226 if (ah->ah_version == AR5K_AR5212)
4230 case AR5K_CAP_BURST:
4234 case AR5K_CAP_BSSIDMASK:
4235 if (ah->ah_version == AR5K_AR5212)
4240 if (ah->ah_version == AR5K_AR5212)
4254 static int ath5k_hw_enable_pspoll(struct ath5k_hw *ah, u8 *bssid,
4257 ATH5K_TRACE(ah->ah_sc);
4259 if (ah->ah_version == AR5K_AR5210) {
4260 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
4261 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
4268 static int ath5k_hw_disable_pspoll(struct ath5k_hw *ah)
4270 ATH5K_TRACE(ah->ah_sc);
4272 if (ah->ah_version == AR5K_AR5210) {
4273 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
4274 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);