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_AR2413)) {
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 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5111;
227 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC0) {
229 ah->ah_radio = AR5K_RF5112;
231 if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112A) {
232 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112;
234 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
237 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC1) {
238 ah->ah_radio = AR5K_RF2413;
239 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
242 ah->ah_radio = AR5K_RF5413;
244 if (ah->ah_mac_srev <= AR5K_SREV_VER_AR5424 &&
245 ah->ah_mac_srev >= AR5K_SREV_VER_AR2424)
246 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5424;
247 else if (ah->ah_mac_srev >= AR5K_SREV_VER_AR2425)
248 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112;
250 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
255 ah->ah_phy = AR5K_PHY(0);
258 * Get card capabilities, values, ...
261 ret = ath5k_eeprom_init(ah);
263 ATH5K_ERR(sc, "unable to init EEPROM\n");
267 /* Get misc capabilities */
268 ret = ath5k_hw_get_capabilities(ah);
270 ATH5K_ERR(sc, "unable to get device capabilities: 0x%04x\n",
275 /* Get MAC address */
276 ret = ath5k_eeprom_read_mac(ah, mac);
278 ATH5K_ERR(sc, "unable to read address from EEPROM: 0x%04x\n",
283 ath5k_hw_set_lladdr(ah, mac);
284 /* Set BSSID to bcast address: ff:ff:ff:ff:ff:ff for now */
285 memset(ah->ah_bssid, 0xff, ETH_ALEN);
286 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
287 ath5k_hw_set_opmode(ah);
289 ath5k_hw_set_rfgain_opt(ah);
299 * Bring up MAC + PHY Chips
301 static int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
303 struct pci_dev *pdev = ah->ah_sc->pdev;
304 u32 turbo, mode, clock, bus_flags;
311 ATH5K_TRACE(ah->ah_sc);
313 /* Wakeup the device */
314 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
316 ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
320 if (ah->ah_version != AR5K_AR5210) {
322 * Get channel mode flags
325 if (ah->ah_radio >= AR5K_RF5112) {
326 mode = AR5K_PHY_MODE_RAD_RF5112;
327 clock = AR5K_PHY_PLL_RF5112;
329 mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
330 clock = AR5K_PHY_PLL_RF5111; /*Zero*/
333 if (flags & CHANNEL_2GHZ) {
334 mode |= AR5K_PHY_MODE_FREQ_2GHZ;
335 clock |= AR5K_PHY_PLL_44MHZ;
337 if (flags & CHANNEL_CCK) {
338 mode |= AR5K_PHY_MODE_MOD_CCK;
339 } else if (flags & CHANNEL_OFDM) {
340 /* XXX Dynamic OFDM/CCK is not supported by the
341 * AR5211 so we set MOD_OFDM for plain g (no
342 * CCK headers) operation. We need to test
343 * this, 5211 might support ofdm-only g after
344 * all, there are also initial register values
345 * in the code for g mode (see initvals.c). */
346 if (ah->ah_version == AR5K_AR5211)
347 mode |= AR5K_PHY_MODE_MOD_OFDM;
349 mode |= AR5K_PHY_MODE_MOD_DYN;
352 "invalid radio modulation mode\n");
355 } else if (flags & CHANNEL_5GHZ) {
356 mode |= AR5K_PHY_MODE_FREQ_5GHZ;
357 clock |= AR5K_PHY_PLL_40MHZ;
359 if (flags & CHANNEL_OFDM)
360 mode |= AR5K_PHY_MODE_MOD_OFDM;
363 "invalid radio modulation mode\n");
367 ATH5K_ERR(ah->ah_sc, "invalid radio frequency mode\n");
371 if (flags & CHANNEL_TURBO)
372 turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
373 } else { /* Reset the device */
375 /* ...enable Atheros turbo mode if requested */
376 if (flags & CHANNEL_TURBO)
377 ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
381 /* reseting PCI on PCI-E cards results card to hang
382 * and always return 0xffff... so we ingore that flag
384 bus_flags = (pdev->is_pcie) ? 0 : AR5K_RESET_CTL_PCI;
387 ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
388 AR5K_RESET_CTL_BASEBAND | bus_flags);
390 ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip + PCI\n");
394 if (ah->ah_version == AR5K_AR5210)
397 /* ...wakeup again!*/
398 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
400 ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
404 /* ...final warm reset */
405 if (ath5k_hw_nic_reset(ah, 0)) {
406 ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
410 if (ah->ah_version != AR5K_AR5210) {
411 /* ...set the PHY operating mode */
412 ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
415 ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
416 ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
423 * Get the rate table for a specific operation mode
425 const struct ath5k_rate_table *ath5k_hw_get_rate_table(struct ath5k_hw *ah,
428 ATH5K_TRACE(ah->ah_sc);
430 if (!test_bit(mode, ah->ah_capabilities.cap_mode))
433 /* Get rate tables */
436 return &ath5k_rt_11a;
437 case AR5K_MODE_11A_TURBO:
438 return &ath5k_rt_turbo;
440 return &ath5k_rt_11b;
442 return &ath5k_rt_11g;
443 case AR5K_MODE_11G_TURBO:
451 * Free the ath5k_hw struct
453 void ath5k_hw_detach(struct ath5k_hw *ah)
455 ATH5K_TRACE(ah->ah_sc);
457 if (ah->ah_rf_banks != NULL)
458 kfree(ah->ah_rf_banks);
460 /* assume interrupts are down */
464 /****************************\
465 Reset function and helpers
466 \****************************/
469 * ath5k_hw_write_ofdm_timings - set OFDM timings on AR5212
471 * @ah: the &struct ath5k_hw
472 * @channel: the currently set channel upon reset
474 * Write the OFDM timings for the AR5212 upon reset. This is a helper for
475 * ath5k_hw_reset(). This seems to tune the PLL a specified frequency
476 * depending on the bandwidth of the channel.
479 static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
480 struct ieee80211_channel *channel)
482 /* Get exponent and mantissa and set it */
483 u32 coef_scaled, coef_exp, coef_man,
484 ds_coef_exp, ds_coef_man, clock;
486 if (!(ah->ah_version == AR5K_AR5212) ||
487 !(channel->hw_value & CHANNEL_OFDM))
490 /* Seems there are two PLLs, one for baseband sampling and one
491 * for tuning. Tuning basebands are 40 MHz or 80MHz when in
493 clock = channel->hw_value & CHANNEL_TURBO ? 80 : 40;
494 coef_scaled = ((5 * (clock << 24)) / 2) /
495 channel->center_freq;
497 for (coef_exp = 31; coef_exp > 0; coef_exp--)
498 if ((coef_scaled >> coef_exp) & 0x1)
504 coef_exp = 14 - (coef_exp - 24);
505 coef_man = coef_scaled +
506 (1 << (24 - coef_exp - 1));
507 ds_coef_man = coef_man >> (24 - coef_exp);
508 ds_coef_exp = coef_exp - 16;
510 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
511 AR5K_PHY_TIMING_3_DSC_MAN, ds_coef_man);
512 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
513 AR5K_PHY_TIMING_3_DSC_EXP, ds_coef_exp);
519 * ath5k_hw_write_rate_duration - set rate duration during hw resets
521 * @ah: the &struct ath5k_hw
522 * @mode: one of enum ath5k_driver_mode
524 * Write the rate duration table for the current mode upon hw reset. This
525 * is a helper for ath5k_hw_reset(). It seems all this is doing is setting
526 * an ACK timeout for the hardware for the current mode for each rate. The
527 * rates which are capable of short preamble (802.11b rates 2Mbps, 5.5Mbps,
528 * and 11Mbps) have another register for the short preamble ACK timeout
532 static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
535 struct ath5k_softc *sc = ah->ah_sc;
536 const struct ath5k_rate_table *rt;
537 struct ieee80211_rate srate = {};
540 /* Get rate table for the current operating mode */
541 rt = ath5k_hw_get_rate_table(ah, mode);
543 /* Write rate duration table */
544 for (i = 0; i < rt->rate_count; i++) {
545 const struct ath5k_rate *rate, *control_rate;
550 rate = &rt->rates[i];
551 control_rate = &rt->rates[rate->control_rate];
553 /* Set ACK timeout */
554 reg = AR5K_RATE_DUR(rate->rate_code);
556 srate.bitrate = control_rate->rate_kbps/100;
558 /* An ACK frame consists of 10 bytes. If you add the FCS,
559 * which ieee80211_generic_frame_duration() adds,
560 * its 14 bytes. Note we use the control rate and not the
561 * actual rate for this rate. See mac80211 tx.c
562 * ieee80211_duration() for a brief description of
563 * what rate we should choose to TX ACKs. */
564 tx_time = le16_to_cpu(ieee80211_generic_frame_duration(sc->hw,
565 sc->vif, 10, &srate));
567 ath5k_hw_reg_write(ah, tx_time, reg);
569 if (!HAS_SHPREAMBLE(i))
573 * We're not distinguishing short preamble here,
574 * This is true, all we'll get is a longer value here
575 * which is not necessarilly bad. We could use
576 * export ieee80211_frame_duration() but that needs to be
577 * fixed first to be properly used by mac802111 drivers:
579 * - remove erp stuff and let the routine figure ofdm
581 * - remove passing argument ieee80211_local as
582 * drivers don't have access to it
583 * - move drivers using ieee80211_generic_frame_duration()
586 ath5k_hw_reg_write(ah, tx_time,
587 reg + (AR5K_SET_SHORT_PREAMBLE << 2));
592 * Main reset function
594 int ath5k_hw_reset(struct ath5k_hw *ah, enum ieee80211_if_types op_mode,
595 struct ieee80211_channel *channel, bool change_channel)
597 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
598 struct pci_dev *pdev = ah->ah_sc->pdev;
599 u32 data, s_seq, s_ant, s_led[3], dma_size;
600 unsigned int i, mode, freq, ee_mode, ant[2];
603 ATH5K_TRACE(ah->ah_sc);
612 * Save some registers before a reset
614 /*DCU/Antenna selection not available on 5210*/
615 if (ah->ah_version != AR5K_AR5210) {
616 if (change_channel == true) {
617 /* Seq number for queue 0 -do this for all queues ? */
618 s_seq = ath5k_hw_reg_read(ah,
619 AR5K_QUEUE_DFS_SEQNUM(0));
621 s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
626 s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) & AR5K_PCICFG_LEDSTATE;
627 s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
628 s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
630 if (change_channel == true && ah->ah_rf_banks != NULL)
631 ath5k_hw_get_rf_gain(ah);
634 /*Wakeup the device*/
635 ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, false);
640 * Initialize operating mode
642 ah->ah_op_mode = op_mode;
646 * 5210 only comes with RF5110
648 if (ah->ah_version != AR5K_AR5210) {
649 if (ah->ah_radio != AR5K_RF5111 &&
650 ah->ah_radio != AR5K_RF5112 &&
651 ah->ah_radio != AR5K_RF5413 &&
652 ah->ah_radio != AR5K_RF2413) {
654 "invalid phy radio: %u\n", ah->ah_radio);
658 switch (channel->hw_value & CHANNEL_MODES) {
660 mode = AR5K_MODE_11A;
661 freq = AR5K_INI_RFGAIN_5GHZ;
662 ee_mode = AR5K_EEPROM_MODE_11A;
665 mode = AR5K_MODE_11G;
666 freq = AR5K_INI_RFGAIN_2GHZ;
667 ee_mode = AR5K_EEPROM_MODE_11G;
670 mode = AR5K_MODE_11B;
671 freq = AR5K_INI_RFGAIN_2GHZ;
672 ee_mode = AR5K_EEPROM_MODE_11B;
675 mode = AR5K_MODE_11A_TURBO;
676 freq = AR5K_INI_RFGAIN_5GHZ;
677 ee_mode = AR5K_EEPROM_MODE_11A;
679 /*Is this ok on 5211 too ?*/
681 mode = AR5K_MODE_11G_TURBO;
682 freq = AR5K_INI_RFGAIN_2GHZ;
683 ee_mode = AR5K_EEPROM_MODE_11G;
686 if (ah->ah_version == AR5K_AR5211) {
688 "XR mode not available on 5211");
692 freq = AR5K_INI_RFGAIN_5GHZ;
693 ee_mode = AR5K_EEPROM_MODE_11A;
697 "invalid channel: %d\n", channel->center_freq);
701 /* PHY access enable */
702 ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
706 ret = ath5k_hw_write_initvals(ah, mode, change_channel);
713 if (ah->ah_version != AR5K_AR5210) {
715 * Write initial RF gain settings
716 * This should work for both 5111/5112
718 ret = ath5k_hw_rfgain(ah, freq);
725 * Write some more initial register settings
727 if (ah->ah_version == AR5K_AR5212) {
728 ath5k_hw_reg_write(ah, 0x0002a002, AR5K_PHY(11));
730 if (channel->hw_value == CHANNEL_G)
731 if (ah->ah_mac_srev < AR5K_SREV_VER_AR2413)
732 ath5k_hw_reg_write(ah, 0x00f80d80,
734 else if (ah->ah_mac_srev < AR5K_SREV_VER_AR2424)
735 ath5k_hw_reg_write(ah, 0x00380140,
737 else if (ah->ah_mac_srev < AR5K_SREV_VER_AR2425)
738 ath5k_hw_reg_write(ah, 0x00fc0ec0,
741 ath5k_hw_reg_write(ah, 0x00fc0fc0,
744 ath5k_hw_reg_write(ah, 0x00000000,
747 ath5k_hw_reg_write(ah, 0x000009b5, 0xa228);
748 ath5k_hw_reg_write(ah, 0x0000000f, 0x8060);
749 ath5k_hw_reg_write(ah, 0x00000000, 0xa254);
750 ath5k_hw_reg_write(ah, 0x0000000e, AR5K_PHY_SCAL);
753 /* Fix for first revision of the RF5112 RF chipset */
754 if (ah->ah_radio >= AR5K_RF5112 &&
755 ah->ah_radio_5ghz_revision <
756 AR5K_SREV_RAD_5112A) {
757 ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
759 if (channel->hw_value & CHANNEL_5GHZ)
763 ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
767 * Set TX power (FIXME)
769 ret = ath5k_hw_txpower(ah, channel, AR5K_TUNE_DEFAULT_TXPOWER);
773 /* Write rate duration table only on AR5212 and if
774 * virtual interface has already been brought up
775 * XXX: rethink this after new mode changes to
776 * mac80211 are integrated */
777 if (ah->ah_version == AR5K_AR5212 &&
778 ah->ah_sc->vif != NULL)
779 ath5k_hw_write_rate_duration(ah, mode);
783 * TODO:Does this work on 5211 (5111) ?
785 ret = ath5k_hw_rfregs(ah, channel, mode);
790 * Configure additional registers
793 /* Write OFDM timings on 5212*/
794 if (ah->ah_version == AR5K_AR5212 &&
795 channel->hw_value & CHANNEL_OFDM) {
796 ret = ath5k_hw_write_ofdm_timings(ah, channel);
801 /*Enable/disable 802.11b mode on 5111
802 (enable 2111 frequency converter + CCK)*/
803 if (ah->ah_radio == AR5K_RF5111) {
804 if (mode == AR5K_MODE_11B)
805 AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
808 AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
813 * Set channel and calibrate the PHY
815 ret = ath5k_hw_channel(ah, channel);
819 /* Set antenna mode */
820 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x44),
821 ah->ah_antenna[ee_mode][0], 0xfffffc06);
824 * In case a fixed antenna was set as default
825 * write the same settings on both AR5K_PHY_ANT_SWITCH_TABLE
829 if (s_ant == AR5K_ANT_FIXED_A) /* 1 - Main */
830 ant[0] = ant[1] = AR5K_ANT_FIXED_A;
832 ant[0] = ant[1] = AR5K_ANT_FIXED_B;
834 ant[0] = AR5K_ANT_FIXED_A;
835 ant[1] = AR5K_ANT_FIXED_B;
838 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[0]],
839 AR5K_PHY_ANT_SWITCH_TABLE_0);
840 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[1]],
841 AR5K_PHY_ANT_SWITCH_TABLE_1);
843 /* Commit values from EEPROM */
844 if (ah->ah_radio == AR5K_RF5111)
845 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_FRAME_CTL,
846 AR5K_PHY_FRAME_CTL_TX_CLIP, ee->ee_tx_clip);
848 ath5k_hw_reg_write(ah,
849 AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
852 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x11),
853 (ee->ee_switch_settling[ee_mode] << 7) & 0x3f80,
855 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x12),
856 (ee->ee_ant_tx_rx[ee_mode] << 12) & 0x3f000,
858 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x14),
859 (ee->ee_adc_desired_size[ee_mode] & 0x00ff) |
860 ((ee->ee_pga_desired_size[ee_mode] << 8) & 0xff00),
863 ath5k_hw_reg_write(ah,
864 (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
865 (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
866 (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
867 (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY(0x0d));
869 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x0a),
870 ee->ee_tx_end2xlna_enable[ee_mode] << 8, 0xffff00ff);
871 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x19),
872 (ee->ee_thr_62[ee_mode] << 12) & 0x7f000, 0xfff80fff);
873 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x49), 4, 0xffffff01);
875 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
876 AR5K_PHY_IQ_CORR_ENABLE |
877 (ee->ee_i_cal[ee_mode] << AR5K_PHY_IQ_CORR_Q_I_COFF_S) |
878 ee->ee_q_cal[ee_mode]);
880 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
881 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
882 AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
883 ee->ee_margin_tx_rx[ee_mode]);
887 /* Disable phy and wait */
888 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
893 * Restore saved values
895 /*DCU/Antenna selection not available on 5210*/
896 if (ah->ah_version != AR5K_AR5210) {
897 ath5k_hw_reg_write(ah, s_seq, AR5K_QUEUE_DFS_SEQNUM(0));
898 ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
900 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
901 ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
902 ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
907 /* XXX: add ah->aid once mac80211 gives this to us */
908 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
910 ath5k_hw_set_opmode(ah);
911 /*PISR/SISR Not available on 5210*/
912 if (ah->ah_version != AR5K_AR5210) {
913 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
914 /* If we later allow tuning for this, store into sc structure */
915 data = AR5K_TUNE_RSSI_THRES |
916 AR5K_TUNE_BMISS_THRES << AR5K_RSSI_THR_BMISS_S;
917 ath5k_hw_reg_write(ah, data, AR5K_RSSI_THR);
921 * Set Rx/Tx DMA Configuration
923 * Set maximum DMA size (512) except for PCI-E cards since
924 * it causes rx overruns and tx errors (tested on 5424 but since
925 * rx overruns also occur on 5416/5418 with madwifi we set 128
926 * for all PCI-E cards to be safe).
928 * In dumps this is 128 for allchips.
930 * XXX: need to check 5210 for this
931 * TODO: Check out tx triger level, it's always 64 on dumps but I
932 * guess we can tweak it and see how it goes ;-)
934 dma_size = (pdev->is_pcie) ? AR5K_DMASIZE_128B : AR5K_DMASIZE_512B;
935 if (ah->ah_version != AR5K_AR5210) {
936 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
937 AR5K_TXCFG_SDMAMR, dma_size);
938 AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG,
939 AR5K_RXCFG_SDMAMW, dma_size);
943 * Enable the PHY and wait until completion
945 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
950 if (ah->ah_version != AR5K_AR5210) {
951 data = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
953 data = (channel->hw_value & CHANNEL_CCK) ?
954 ((data << 2) / 22) : (data / 10);
962 * Enable calibration and wait until completion
964 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
965 AR5K_PHY_AGCCTL_CAL);
967 if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
968 AR5K_PHY_AGCCTL_CAL, 0, false)) {
969 ATH5K_ERR(ah->ah_sc, "calibration timeout (%uMHz)\n",
970 channel->center_freq);
974 ret = ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
978 ah->ah_calibration = false;
980 /* A and G modes can use QAM modulation which requires enabling
981 * I and Q calibration. Don't bother in B mode. */
982 if (!(mode == AR5K_MODE_11B)) {
983 ah->ah_calibration = true;
984 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
985 AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
986 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
991 * Reset queues and start beacon timers at the end of the reset routine
993 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
995 if (ah->ah_version != AR5K_AR5210)
996 AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(i), i);
998 ret = ath5k_hw_reset_tx_queue(ah, i);
1000 ATH5K_ERR(ah->ah_sc,
1001 "failed to reset TX queue #%d\n", i);
1006 /* Pre-enable interrupts on 5211/5212*/
1007 if (ah->ah_version != AR5K_AR5210)
1008 ath5k_hw_set_intr(ah, AR5K_INT_RX | AR5K_INT_TX |
1012 * Set RF kill flags if supported by the device (read from the EEPROM)
1013 * Disable gpio_intr for now since it results system hang.
1014 * TODO: Handle this in ath5k_intr
1017 if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header)) {
1018 ath5k_hw_set_gpio_input(ah, 0);
1019 ah->ah_gpio[0] = ath5k_hw_get_gpio(ah, 0);
1020 if (ah->ah_gpio[0] == 0)
1021 ath5k_hw_set_gpio_intr(ah, 0, 1);
1023 ath5k_hw_set_gpio_intr(ah, 0, 0);
1028 * Set the 32MHz reference clock on 5212 phy clock sleep register
1030 * TODO: Find out how to switch to external 32Khz clock to save power
1032 if (ah->ah_version == AR5K_AR5212) {
1033 ath5k_hw_reg_write(ah, AR5K_PHY_SCR_32MHZ, AR5K_PHY_SCR);
1034 ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
1035 ath5k_hw_reg_write(ah, AR5K_PHY_SCAL_32MHZ, AR5K_PHY_SCAL);
1036 ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
1037 ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
1038 ath5k_hw_reg_write(ah, ah->ah_phy_spending, AR5K_PHY_SPENDING);
1041 if (ah->ah_version == AR5K_AR5212) {
1042 ath5k_hw_reg_write(ah, 0x000100aa, 0x8118);
1043 ath5k_hw_reg_write(ah, 0x00003210, 0x811c);
1044 ath5k_hw_reg_write(ah, 0x00000052, 0x8108);
1045 if (ah->ah_mac_srev >= AR5K_SREV_VER_AR2413)
1046 ath5k_hw_reg_write(ah, 0x00000004, 0x8120);
1050 * Disable beacons and reset the register
1052 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
1053 AR5K_BEACON_RESET_TSF);
1061 static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
1064 u32 mask = val ? val : ~0U;
1066 ATH5K_TRACE(ah->ah_sc);
1068 /* Read-and-clear RX Descriptor Pointer*/
1069 ath5k_hw_reg_read(ah, AR5K_RXDP);
1072 * Reset the device and wait until success
1074 ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
1076 /* Wait at least 128 PCI clocks */
1079 if (ah->ah_version == AR5K_AR5210) {
1080 val &= AR5K_RESET_CTL_CHIP;
1081 mask &= AR5K_RESET_CTL_CHIP;
1083 val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1084 mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1087 ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, false);
1090 * Reset configuration register (for hw byte-swap). Note that this
1091 * is only set for big endian. We do the necessary magic in
1094 if ((val & AR5K_RESET_CTL_PCU) == 0)
1095 ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
1101 * Power management functions
1107 int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
1108 bool set_chip, u16 sleep_duration)
1113 ATH5K_TRACE(ah->ah_sc);
1114 staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
1118 staid &= ~AR5K_STA_ID1_DEFAULT_ANTENNA;
1120 case AR5K_PM_NETWORK_SLEEP:
1121 if (set_chip == true)
1122 ath5k_hw_reg_write(ah,
1123 AR5K_SLEEP_CTL_SLE | sleep_duration,
1126 staid |= AR5K_STA_ID1_PWR_SV;
1129 case AR5K_PM_FULL_SLEEP:
1130 if (set_chip == true)
1131 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_SLP,
1134 staid |= AR5K_STA_ID1_PWR_SV;
1138 if (set_chip == false)
1141 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1144 for (i = 5000; i > 0; i--) {
1145 /* Check if the chip did wake up */
1146 if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
1147 AR5K_PCICFG_SPWR_DN) == 0)
1150 /* Wait a bit and retry */
1152 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1156 /* Fail if the chip didn't wake up */
1160 staid &= ~AR5K_STA_ID1_PWR_SV;
1168 ah->ah_power_mode = mode;
1169 ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
1174 /***********************\
1175 DMA Related Functions
1176 \***********************/
1185 void ath5k_hw_start_rx(struct ath5k_hw *ah)
1187 ATH5K_TRACE(ah->ah_sc);
1188 ath5k_hw_reg_write(ah, AR5K_CR_RXE, AR5K_CR);
1194 int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
1198 ATH5K_TRACE(ah->ah_sc);
1199 ath5k_hw_reg_write(ah, AR5K_CR_RXD, AR5K_CR);
1202 * It may take some time to disable the DMA receive unit
1204 for (i = 2000; i > 0 &&
1205 (ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_CR_RXE) != 0;
1209 return i ? 0 : -EBUSY;
1213 * Get the address of the RX Descriptor
1215 u32 ath5k_hw_get_rx_buf(struct ath5k_hw *ah)
1217 return ath5k_hw_reg_read(ah, AR5K_RXDP);
1221 * Set the address of the RX Descriptor
1223 void ath5k_hw_put_rx_buf(struct ath5k_hw *ah, u32 phys_addr)
1225 ATH5K_TRACE(ah->ah_sc);
1227 /*TODO:Shouldn't we check if RX is enabled first ?*/
1228 ath5k_hw_reg_write(ah, phys_addr, AR5K_RXDP);
1232 * Transmit functions
1236 * Start DMA transmit for a specific queue
1237 * (see also QCU/DCU functions)
1239 int ath5k_hw_tx_start(struct ath5k_hw *ah, unsigned int queue)
1243 ATH5K_TRACE(ah->ah_sc);
1244 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1246 /* Return if queue is declared inactive */
1247 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1250 if (ah->ah_version == AR5K_AR5210) {
1251 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1254 * Set the queue by type on 5210
1256 switch (ah->ah_txq[queue].tqi_type) {
1257 case AR5K_TX_QUEUE_DATA:
1258 tx_queue |= AR5K_CR_TXE0 & ~AR5K_CR_TXD0;
1260 case AR5K_TX_QUEUE_BEACON:
1261 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1262 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
1265 case AR5K_TX_QUEUE_CAB:
1266 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1267 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1FV | AR5K_BCR_TQ1V |
1268 AR5K_BCR_BDMAE, AR5K_BSR);
1274 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1276 /* Return if queue is disabled */
1277 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXD, queue))
1281 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXE, queue);
1288 * Stop DMA transmit for a specific queue
1289 * (see also QCU/DCU functions)
1291 int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue)
1293 unsigned int i = 100;
1294 u32 tx_queue, pending;
1296 ATH5K_TRACE(ah->ah_sc);
1297 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1299 /* Return if queue is declared inactive */
1300 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1303 if (ah->ah_version == AR5K_AR5210) {
1304 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1309 switch (ah->ah_txq[queue].tqi_type) {
1310 case AR5K_TX_QUEUE_DATA:
1311 tx_queue |= AR5K_CR_TXD0 & ~AR5K_CR_TXE0;
1313 case AR5K_TX_QUEUE_BEACON:
1314 case AR5K_TX_QUEUE_CAB:
1316 tx_queue |= AR5K_CR_TXD1 & ~AR5K_CR_TXD1;
1317 ath5k_hw_reg_write(ah, 0, AR5K_BSR);
1324 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1327 * Schedule TX disable and wait until queue is empty
1329 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXD, queue);
1331 /*Check for pending frames*/
1333 pending = ath5k_hw_reg_read(ah,
1334 AR5K_QUEUE_STATUS(queue)) &
1335 AR5K_QCU_STS_FRMPENDCNT;
1337 } while (--i && pending);
1339 /* Clear register */
1340 ath5k_hw_reg_write(ah, 0, AR5K_QCU_TXD);
1343 /* TODO: Check for success else return error */
1348 * Get the address of the TX Descriptor for a specific queue
1349 * (see also QCU/DCU functions)
1351 u32 ath5k_hw_get_tx_buf(struct ath5k_hw *ah, unsigned int queue)
1355 ATH5K_TRACE(ah->ah_sc);
1356 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1359 * Get the transmit queue descriptor pointer from the selected queue
1361 /*5210 doesn't have QCU*/
1362 if (ah->ah_version == AR5K_AR5210) {
1363 switch (ah->ah_txq[queue].tqi_type) {
1364 case AR5K_TX_QUEUE_DATA:
1365 tx_reg = AR5K_NOQCU_TXDP0;
1367 case AR5K_TX_QUEUE_BEACON:
1368 case AR5K_TX_QUEUE_CAB:
1369 tx_reg = AR5K_NOQCU_TXDP1;
1375 tx_reg = AR5K_QUEUE_TXDP(queue);
1378 return ath5k_hw_reg_read(ah, tx_reg);
1382 * Set the address of the TX Descriptor for a specific queue
1383 * (see also QCU/DCU functions)
1385 int ath5k_hw_put_tx_buf(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
1389 ATH5K_TRACE(ah->ah_sc);
1390 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1393 * Set the transmit queue descriptor pointer register by type
1396 if (ah->ah_version == AR5K_AR5210) {
1397 switch (ah->ah_txq[queue].tqi_type) {
1398 case AR5K_TX_QUEUE_DATA:
1399 tx_reg = AR5K_NOQCU_TXDP0;
1401 case AR5K_TX_QUEUE_BEACON:
1402 case AR5K_TX_QUEUE_CAB:
1403 tx_reg = AR5K_NOQCU_TXDP1;
1410 * Set the transmit queue descriptor pointer for
1411 * the selected queue on QCU for 5211+
1412 * (this won't work if the queue is still active)
1414 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
1417 tx_reg = AR5K_QUEUE_TXDP(queue);
1420 /* Set descriptor pointer */
1421 ath5k_hw_reg_write(ah, phys_addr, tx_reg);
1427 * Update tx trigger level
1429 int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase)
1431 u32 trigger_level, imr;
1434 ATH5K_TRACE(ah->ah_sc);
1437 * Disable interrupts by setting the mask
1439 imr = ath5k_hw_set_intr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
1441 /*TODO: Boundary check on trigger_level*/
1442 trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
1445 if (increase == false) {
1446 if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
1450 ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
1453 * Update trigger level on success
1455 if (ah->ah_version == AR5K_AR5210)
1456 ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
1458 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
1459 AR5K_TXCFG_TXFULL, trigger_level);
1465 * Restore interrupt mask
1467 ath5k_hw_set_intr(ah, imr);
1473 * Interrupt handling
1477 * Check if we have pending interrupts
1479 bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
1481 ATH5K_TRACE(ah->ah_sc);
1482 return ath5k_hw_reg_read(ah, AR5K_INTPEND);
1486 * Get interrupt mask (ISR)
1488 int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
1492 ATH5K_TRACE(ah->ah_sc);
1495 * Read interrupt status from the Interrupt Status register
1498 if (ah->ah_version == AR5K_AR5210) {
1499 data = ath5k_hw_reg_read(ah, AR5K_ISR);
1500 if (unlikely(data == AR5K_INT_NOCARD)) {
1501 *interrupt_mask = data;
1506 * Read interrupt status from the Read-And-Clear shadow register
1507 * Note: PISR/SISR Not available on 5210
1509 data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
1513 * Get abstract interrupt mask (driver-compatible)
1515 *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
1517 if (unlikely(data == AR5K_INT_NOCARD))
1520 if (data & (AR5K_ISR_RXOK | AR5K_ISR_RXERR))
1521 *interrupt_mask |= AR5K_INT_RX;
1523 if (data & (AR5K_ISR_TXOK | AR5K_ISR_TXERR
1524 | AR5K_ISR_TXDESC | AR5K_ISR_TXEOL))
1525 *interrupt_mask |= AR5K_INT_TX;
1527 if (ah->ah_version != AR5K_AR5210) {
1528 /*HIU = Host Interface Unit (PCI etc)*/
1529 if (unlikely(data & (AR5K_ISR_HIUERR)))
1530 *interrupt_mask |= AR5K_INT_FATAL;
1532 /*Beacon Not Ready*/
1533 if (unlikely(data & (AR5K_ISR_BNR)))
1534 *interrupt_mask |= AR5K_INT_BNR;
1538 * XXX: BMISS interrupts may occur after association.
1539 * I found this on 5210 code but it needs testing. If this is
1540 * true we should disable them before assoc and re-enable them
1541 * after a successfull assoc + some jiffies.
1544 interrupt_mask &= ~AR5K_INT_BMISS;
1548 * In case we didn't handle anything,
1549 * print the register value.
1551 if (unlikely(*interrupt_mask == 0 && net_ratelimit()))
1552 ATH5K_PRINTF("0x%08x\n", data);
1558 * Set interrupt mask
1560 enum ath5k_int ath5k_hw_set_intr(struct ath5k_hw *ah, enum ath5k_int new_mask)
1562 enum ath5k_int old_mask, int_mask;
1565 * Disable card interrupts to prevent any race conditions
1566 * (they will be re-enabled afterwards).
1568 ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
1570 old_mask = ah->ah_imr;
1573 * Add additional, chipset-dependent interrupt mask flags
1574 * and write them to the IMR (interrupt mask register).
1576 int_mask = new_mask & AR5K_INT_COMMON;
1578 if (new_mask & AR5K_INT_RX)
1579 int_mask |= AR5K_IMR_RXOK | AR5K_IMR_RXERR | AR5K_IMR_RXORN |
1582 if (new_mask & AR5K_INT_TX)
1583 int_mask |= AR5K_IMR_TXOK | AR5K_IMR_TXERR | AR5K_IMR_TXDESC |
1586 if (ah->ah_version != AR5K_AR5210) {
1587 if (new_mask & AR5K_INT_FATAL) {
1588 int_mask |= AR5K_IMR_HIUERR;
1589 AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_MCABT |
1590 AR5K_SIMR2_SSERR | AR5K_SIMR2_DPERR);
1594 ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
1596 /* Store new interrupt mask */
1597 ah->ah_imr = new_mask;
1599 /* ..re-enable interrupts */
1600 ath5k_hw_reg_write(ah, AR5K_IER_ENABLE, AR5K_IER);
1606 /*************************\
1607 EEPROM access functions
1608 \*************************/
1613 static int ath5k_hw_eeprom_read(struct ath5k_hw *ah, u32 offset, u16 *data)
1615 u32 status, timeout;
1617 ATH5K_TRACE(ah->ah_sc);
1619 * Initialize EEPROM access
1621 if (ah->ah_version == AR5K_AR5210) {
1622 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1623 (void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset));
1625 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1626 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1627 AR5K_EEPROM_CMD_READ);
1630 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1631 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1632 if (status & AR5K_EEPROM_STAT_RDDONE) {
1633 if (status & AR5K_EEPROM_STAT_RDERR)
1635 *data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) &
1646 * Write to eeprom - currently disabled, use at your own risk
1649 static int ath5k_hw_eeprom_write(struct ath5k_hw *ah, u32 offset, u16 data)
1652 u32 status, timeout;
1654 ATH5K_TRACE(ah->ah_sc);
1657 * Initialize eeprom access
1660 if (ah->ah_version == AR5K_AR5210) {
1661 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1663 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1664 AR5K_EEPROM_CMD_RESET);
1668 * Write data to data register
1671 if (ah->ah_version == AR5K_AR5210) {
1672 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_BASE + (4 * offset));
1674 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1675 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_DATA);
1676 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1677 AR5K_EEPROM_CMD_WRITE);
1684 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1685 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1686 if (status & AR5K_EEPROM_STAT_WRDONE) {
1687 if (status & AR5K_EEPROM_STAT_WRERR)
1694 ATH5K_ERR(ah->ah_sc, "EEPROM Write is disabled!");
1700 * Translate binary channel representation in EEPROM to frequency
1702 static u16 ath5k_eeprom_bin2freq(struct ath5k_hw *ah, u16 bin, unsigned int mode)
1706 if (bin == AR5K_EEPROM_CHANNEL_DIS)
1709 if (mode == AR5K_EEPROM_MODE_11A) {
1710 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1711 val = (5 * bin) + 4800;
1713 val = bin > 62 ? (10 * 62) + (5 * (bin - 62)) + 5100 :
1716 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1726 * Read antenna infos from eeprom
1728 static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
1731 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1736 AR5K_EEPROM_READ(o++, val);
1737 ee->ee_switch_settling[mode] = (val >> 8) & 0x7f;
1738 ee->ee_ant_tx_rx[mode] = (val >> 2) & 0x3f;
1739 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1741 AR5K_EEPROM_READ(o++, val);
1742 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1743 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1744 ee->ee_ant_control[mode][i++] = val & 0x3f;
1746 AR5K_EEPROM_READ(o++, val);
1747 ee->ee_ant_control[mode][i++] = (val >> 10) & 0x3f;
1748 ee->ee_ant_control[mode][i++] = (val >> 4) & 0x3f;
1749 ee->ee_ant_control[mode][i] = (val << 2) & 0x3f;
1751 AR5K_EEPROM_READ(o++, val);
1752 ee->ee_ant_control[mode][i++] |= (val >> 14) & 0x3;
1753 ee->ee_ant_control[mode][i++] = (val >> 8) & 0x3f;
1754 ee->ee_ant_control[mode][i++] = (val >> 2) & 0x3f;
1755 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1757 AR5K_EEPROM_READ(o++, val);
1758 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1759 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1760 ee->ee_ant_control[mode][i++] = val & 0x3f;
1762 /* Get antenna modes */
1763 ah->ah_antenna[mode][0] =
1764 (ee->ee_ant_control[mode][0] << 4) | 0x1;
1765 ah->ah_antenna[mode][AR5K_ANT_FIXED_A] =
1766 ee->ee_ant_control[mode][1] |
1767 (ee->ee_ant_control[mode][2] << 6) |
1768 (ee->ee_ant_control[mode][3] << 12) |
1769 (ee->ee_ant_control[mode][4] << 18) |
1770 (ee->ee_ant_control[mode][5] << 24);
1771 ah->ah_antenna[mode][AR5K_ANT_FIXED_B] =
1772 ee->ee_ant_control[mode][6] |
1773 (ee->ee_ant_control[mode][7] << 6) |
1774 (ee->ee_ant_control[mode][8] << 12) |
1775 (ee->ee_ant_control[mode][9] << 18) |
1776 (ee->ee_ant_control[mode][10] << 24);
1778 /* return new offset */
1785 * Read supported modes from eeprom
1787 static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset,
1790 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1795 AR5K_EEPROM_READ(o++, val);
1796 ee->ee_tx_end2xlna_enable[mode] = (val >> 8) & 0xff;
1797 ee->ee_thr_62[mode] = val & 0xff;
1799 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1800 ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28;
1802 AR5K_EEPROM_READ(o++, val);
1803 ee->ee_tx_end2xpa_disable[mode] = (val >> 8) & 0xff;
1804 ee->ee_tx_frm2xpa_enable[mode] = val & 0xff;
1806 AR5K_EEPROM_READ(o++, val);
1807 ee->ee_pga_desired_size[mode] = (val >> 8) & 0xff;
1809 if ((val & 0xff) & 0x80)
1810 ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1);
1812 ee->ee_noise_floor_thr[mode] = val & 0xff;
1814 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1815 ee->ee_noise_floor_thr[mode] =
1816 mode == AR5K_EEPROM_MODE_11A ? -54 : -1;
1818 AR5K_EEPROM_READ(o++, val);
1819 ee->ee_xlna_gain[mode] = (val >> 5) & 0xff;
1820 ee->ee_x_gain[mode] = (val >> 1) & 0xf;
1821 ee->ee_xpd[mode] = val & 0x1;
1823 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0)
1824 ee->ee_fixed_bias[mode] = (val >> 13) & 0x1;
1826 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) {
1827 AR5K_EEPROM_READ(o++, val);
1828 ee->ee_false_detect[mode] = (val >> 6) & 0x7f;
1830 if (mode == AR5K_EEPROM_MODE_11A)
1831 ee->ee_xr_power[mode] = val & 0x3f;
1833 ee->ee_ob[mode][0] = val & 0x7;
1834 ee->ee_db[mode][0] = (val >> 3) & 0x7;
1838 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) {
1839 ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN;
1840 ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA;
1842 ee->ee_i_gain[mode] = (val >> 13) & 0x7;
1844 AR5K_EEPROM_READ(o++, val);
1845 ee->ee_i_gain[mode] |= (val << 3) & 0x38;
1847 if (mode == AR5K_EEPROM_MODE_11G)
1848 ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff;
1851 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
1852 mode == AR5K_EEPROM_MODE_11A) {
1853 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
1854 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
1857 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6 &&
1858 mode == AR5K_EEPROM_MODE_11G)
1859 ee->ee_scaled_cck_delta = (val >> 11) & 0x1f;
1861 /* return new offset */
1868 * Initialize eeprom & capabilities structs
1870 static int ath5k_eeprom_init(struct ath5k_hw *ah)
1872 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1873 unsigned int mode, i;
1878 /* Initial TX thermal adjustment values */
1880 ee->ee_pwd_84 = ee->ee_pwd_90 = 1;
1881 ee->ee_gain_select = 1;
1884 * Read values from EEPROM and store them in the capability structure
1886 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC, ee_magic);
1887 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT, ee_protect);
1888 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN, ee_regdomain);
1889 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION, ee_version);
1890 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR, ee_header);
1892 /* Return if we have an old EEPROM */
1893 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_0)
1898 * Validate the checksum of the EEPROM date. There are some
1899 * devices with invalid EEPROMs.
1901 for (cksum = 0, offset = 0; offset < AR5K_EEPROM_INFO_MAX; offset++) {
1902 AR5K_EEPROM_READ(AR5K_EEPROM_INFO(offset), val);
1905 if (cksum != AR5K_EEPROM_INFO_CKSUM) {
1906 ATH5K_ERR(ah->ah_sc, "Invalid EEPROM checksum 0x%04x\n", cksum);
1911 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah->ah_ee_version),
1914 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
1915 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0, ee_misc0);
1916 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1, ee_misc1);
1919 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_3) {
1920 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ, val);
1921 ee->ee_ob[AR5K_EEPROM_MODE_11B][0] = val & 0x7;
1922 ee->ee_db[AR5K_EEPROM_MODE_11B][0] = (val >> 3) & 0x7;
1924 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ, val);
1925 ee->ee_ob[AR5K_EEPROM_MODE_11G][0] = val & 0x7;
1926 ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7;
1930 * Get conformance test limit values
1932 offset = AR5K_EEPROM_CTL(ah->ah_ee_version);
1933 ee->ee_ctls = AR5K_EEPROM_N_CTLS(ah->ah_ee_version);
1935 for (i = 0; i < ee->ee_ctls; i++) {
1936 AR5K_EEPROM_READ(offset++, val);
1937 ee->ee_ctl[i] = (val >> 8) & 0xff;
1938 ee->ee_ctl[i + 1] = val & 0xff;
1942 * Get values for 802.11a (5GHz)
1944 mode = AR5K_EEPROM_MODE_11A;
1946 ee->ee_turbo_max_power[mode] =
1947 AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header);
1949 offset = AR5K_EEPROM_MODES_11A(ah->ah_ee_version);
1951 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
1955 AR5K_EEPROM_READ(offset++, val);
1956 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
1957 ee->ee_ob[mode][3] = (val >> 5) & 0x7;
1958 ee->ee_db[mode][3] = (val >> 2) & 0x7;
1959 ee->ee_ob[mode][2] = (val << 1) & 0x7;
1961 AR5K_EEPROM_READ(offset++, val);
1962 ee->ee_ob[mode][2] |= (val >> 15) & 0x1;
1963 ee->ee_db[mode][2] = (val >> 12) & 0x7;
1964 ee->ee_ob[mode][1] = (val >> 9) & 0x7;
1965 ee->ee_db[mode][1] = (val >> 6) & 0x7;
1966 ee->ee_ob[mode][0] = (val >> 3) & 0x7;
1967 ee->ee_db[mode][0] = val & 0x7;
1969 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
1973 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1) {
1974 AR5K_EEPROM_READ(offset++, val);
1975 ee->ee_margin_tx_rx[mode] = val & 0x3f;
1979 * Get values for 802.11b (2.4GHz)
1981 mode = AR5K_EEPROM_MODE_11B;
1982 offset = AR5K_EEPROM_MODES_11B(ah->ah_ee_version);
1984 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
1988 AR5K_EEPROM_READ(offset++, val);
1989 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
1990 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
1991 ee->ee_db[mode][1] = val & 0x7;
1993 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
1997 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
1998 AR5K_EEPROM_READ(offset++, val);
1999 ee->ee_cal_pier[mode][0] =
2000 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2001 ee->ee_cal_pier[mode][1] =
2002 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
2004 AR5K_EEPROM_READ(offset++, val);
2005 ee->ee_cal_pier[mode][2] =
2006 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2009 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
2010 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
2013 * Get values for 802.11g (2.4GHz)
2015 mode = AR5K_EEPROM_MODE_11G;
2016 offset = AR5K_EEPROM_MODES_11G(ah->ah_ee_version);
2018 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2022 AR5K_EEPROM_READ(offset++, val);
2023 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2024 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
2025 ee->ee_db[mode][1] = val & 0x7;
2027 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2031 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2032 AR5K_EEPROM_READ(offset++, val);
2033 ee->ee_cal_pier[mode][0] =
2034 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2035 ee->ee_cal_pier[mode][1] =
2036 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
2038 AR5K_EEPROM_READ(offset++, val);
2039 ee->ee_turbo_max_power[mode] = val & 0x7f;
2040 ee->ee_xr_power[mode] = (val >> 7) & 0x3f;
2042 AR5K_EEPROM_READ(offset++, val);
2043 ee->ee_cal_pier[mode][2] =
2044 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2046 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
2047 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
2049 AR5K_EEPROM_READ(offset++, val);
2050 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
2051 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
2053 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) {
2054 AR5K_EEPROM_READ(offset++, val);
2055 ee->ee_cck_ofdm_gain_delta = val & 0xff;
2060 * Read 5GHz EEPROM channels
2067 * Read the MAC address from eeprom
2069 static int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
2076 memset(mac, 0, ETH_ALEN);
2077 memset(mac_d, 0, ETH_ALEN);
2079 ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
2083 for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
2084 ret = ath5k_hw_eeprom_read(ah, offset, &data);
2089 mac_d[octet + 1] = data & 0xff;
2090 mac_d[octet] = data >> 8;
2094 memcpy(mac, mac_d, ETH_ALEN);
2096 if (!total || total == 3 * 0xffff)
2103 * Fill the capabilities struct
2105 static int ath5k_hw_get_capabilities(struct ath5k_hw *ah)
2109 ATH5K_TRACE(ah->ah_sc);
2110 /* Capabilities stored in the EEPROM */
2111 ee_header = ah->ah_capabilities.cap_eeprom.ee_header;
2113 if (ah->ah_version == AR5K_AR5210) {
2115 * Set radio capabilities
2116 * (The AR5110 only supports the middle 5GHz band)
2118 ah->ah_capabilities.cap_range.range_5ghz_min = 5120;
2119 ah->ah_capabilities.cap_range.range_5ghz_max = 5430;
2120 ah->ah_capabilities.cap_range.range_2ghz_min = 0;
2121 ah->ah_capabilities.cap_range.range_2ghz_max = 0;
2123 /* Set supported modes */
2124 __set_bit(AR5K_MODE_11A, ah->ah_capabilities.cap_mode);
2125 __set_bit(AR5K_MODE_11A_TURBO, ah->ah_capabilities.cap_mode);
2128 * XXX The tranceiver supports frequencies from 4920 to 6100GHz
2129 * XXX and from 2312 to 2732GHz. There are problems with the
2130 * XXX current ieee80211 implementation because the IEEE
2131 * XXX channel mapping does not support negative channel
2132 * XXX numbers (2312MHz is channel -19). Of course, this
2133 * XXX doesn't matter because these channels are out of range
2134 * XXX but some regulation domains like MKK (Japan) will
2135 * XXX support frequencies somewhere around 4.8GHz.
2139 * Set radio capabilities
2142 if (AR5K_EEPROM_HDR_11A(ee_header)) {
2143 ah->ah_capabilities.cap_range.range_5ghz_min = 5005; /* 4920 */
2144 ah->ah_capabilities.cap_range.range_5ghz_max = 6100;
2146 /* Set supported modes */
2147 __set_bit(AR5K_MODE_11A,
2148 ah->ah_capabilities.cap_mode);
2149 __set_bit(AR5K_MODE_11A_TURBO,
2150 ah->ah_capabilities.cap_mode);
2151 if (ah->ah_version == AR5K_AR5212)
2152 __set_bit(AR5K_MODE_11G_TURBO,
2153 ah->ah_capabilities.cap_mode);
2156 /* Enable 802.11b if a 2GHz capable radio (2111/5112) is
2158 if (AR5K_EEPROM_HDR_11B(ee_header) ||
2159 AR5K_EEPROM_HDR_11G(ee_header)) {
2160 ah->ah_capabilities.cap_range.range_2ghz_min = 2412; /* 2312 */
2161 ah->ah_capabilities.cap_range.range_2ghz_max = 2732;
2163 if (AR5K_EEPROM_HDR_11B(ee_header))
2164 __set_bit(AR5K_MODE_11B,
2165 ah->ah_capabilities.cap_mode);
2167 if (AR5K_EEPROM_HDR_11G(ee_header))
2168 __set_bit(AR5K_MODE_11G,
2169 ah->ah_capabilities.cap_mode);
2174 ah->ah_gpio_npins = AR5K_NUM_GPIO;
2176 /* Set number of supported TX queues */
2177 if (ah->ah_version == AR5K_AR5210)
2178 ah->ah_capabilities.cap_queues.q_tx_num =
2179 AR5K_NUM_TX_QUEUES_NOQCU;
2181 ah->ah_capabilities.cap_queues.q_tx_num = AR5K_NUM_TX_QUEUES;
2186 /*********************************\
2187 Protocol Control Unit Functions
2188 \*********************************/
2191 * Set Operation mode
2193 int ath5k_hw_set_opmode(struct ath5k_hw *ah)
2195 u32 pcu_reg, beacon_reg, low_id, high_id;
2200 ATH5K_TRACE(ah->ah_sc);
2202 switch (ah->ah_op_mode) {
2203 case IEEE80211_IF_TYPE_IBSS:
2204 pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_DESC_ANTENNA |
2205 (ah->ah_version == AR5K_AR5210 ?
2206 AR5K_STA_ID1_NO_PSPOLL : 0);
2207 beacon_reg |= AR5K_BCR_ADHOC;
2210 case IEEE80211_IF_TYPE_AP:
2211 pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_RTS_DEF_ANTENNA |
2212 (ah->ah_version == AR5K_AR5210 ?
2213 AR5K_STA_ID1_NO_PSPOLL : 0);
2214 beacon_reg |= AR5K_BCR_AP;
2217 case IEEE80211_IF_TYPE_STA:
2218 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2219 (ah->ah_version == AR5K_AR5210 ?
2220 AR5K_STA_ID1_PWR_SV : 0);
2221 case IEEE80211_IF_TYPE_MNTR:
2222 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2223 (ah->ah_version == AR5K_AR5210 ?
2224 AR5K_STA_ID1_NO_PSPOLL : 0);
2234 low_id = AR5K_LOW_ID(ah->ah_sta_id);
2235 high_id = AR5K_HIGH_ID(ah->ah_sta_id);
2236 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2237 ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
2240 * Set Beacon Control Register on 5210
2242 if (ah->ah_version == AR5K_AR5210)
2243 ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR);
2255 void ath5k_hw_get_lladdr(struct ath5k_hw *ah, u8 *mac)
2257 ATH5K_TRACE(ah->ah_sc);
2258 memcpy(mac, ah->ah_sta_id, ETH_ALEN);
2264 int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
2266 u32 low_id, high_id;
2268 ATH5K_TRACE(ah->ah_sc);
2269 /* Set new station ID */
2270 memcpy(ah->ah_sta_id, mac, ETH_ALEN);
2272 low_id = AR5K_LOW_ID(mac);
2273 high_id = AR5K_HIGH_ID(mac);
2275 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2276 ath5k_hw_reg_write(ah, high_id, AR5K_STA_ID1);
2284 void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id)
2286 u32 low_id, high_id;
2290 * Set simple BSSID mask on 5212
2292 if (ah->ah_version == AR5K_AR5212) {
2293 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM0);
2294 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM1);
2298 * Set BSSID which triggers the "SME Join" operation
2300 low_id = AR5K_LOW_ID(bssid);
2301 high_id = AR5K_HIGH_ID(bssid);
2302 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_ID0);
2303 ath5k_hw_reg_write(ah, high_id | ((assoc_id & 0x3fff) <<
2304 AR5K_BSS_ID1_AID_S), AR5K_BSS_ID1);
2306 if (assoc_id == 0) {
2307 ath5k_hw_disable_pspoll(ah);
2311 AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM,
2312 tim_offset ? tim_offset + 4 : 0);
2314 ath5k_hw_enable_pspoll(ah, NULL, 0);
2317 * ath5k_hw_set_bssid_mask - set common bits we should listen to
2319 * The bssid_mask is a utility used by AR5212 hardware to inform the hardware
2320 * which bits of the interface's MAC address should be looked at when trying
2321 * to decide which packets to ACK. In station mode every bit matters. In AP
2322 * mode with a single BSS every bit matters as well. In AP mode with
2323 * multiple BSSes not every bit matters.
2325 * @ah: the &struct ath5k_hw
2326 * @mask: the bssid_mask, a u8 array of size ETH_ALEN
2328 * Note that this is a simple filter and *does* not filter out all
2329 * relevant frames. Some non-relevant frames will get through, probability
2330 * jocks are welcomed to compute.
2332 * When handling multiple BSSes (or VAPs) you can get the BSSID mask by
2333 * computing the set of:
2335 * ~ ( MAC XOR BSSID )
2337 * When you do this you are essentially computing the common bits. Later it
2338 * is assumed the harware will "and" (&) the BSSID mask with the MAC address
2339 * to obtain the relevant bits which should match on the destination frame.
2341 * Simple example: on your card you have have two BSSes you have created with
2342 * BSSID-01 and BSSID-02. Lets assume BSSID-01 will not use the MAC address.
2343 * There is another BSSID-03 but you are not part of it. For simplicity's sake,
2344 * assuming only 4 bits for a mac address and for BSSIDs you can then have:
2348 * BSSID-01: 0100 | --> Belongs to us
2351 * -------------------
2352 * BSSID-03: 0110 | --> External
2353 * -------------------
2355 * Our bssid_mask would then be:
2357 * On loop iteration for BSSID-01:
2358 * ~(0001 ^ 0100) -> ~(0101)
2362 * On loop iteration for BSSID-02:
2363 * bssid_mask &= ~(0001 ^ 1001)
2364 * bssid_mask = (1010) & ~(0001 ^ 1001)
2365 * bssid_mask = (1010) & ~(1001)
2366 * bssid_mask = (1010) & (0110)
2369 * A bssid_mask of 0010 means "only pay attention to the second least
2370 * significant bit". This is because its the only bit common
2371 * amongst the MAC and all BSSIDs we support. To findout what the real
2372 * common bit is we can simply "&" the bssid_mask now with any BSSID we have
2373 * or our MAC address (we assume the hardware uses the MAC address).
2375 * Now, suppose there's an incoming frame for BSSID-03:
2379 * An easy eye-inspeciton of this already should tell you that this frame
2380 * will not pass our check. This is beacuse the bssid_mask tells the
2381 * hardware to only look at the second least significant bit and the
2382 * common bit amongst the MAC and BSSIDs is 0, this frame has the 2nd LSB
2383 * as 1, which does not match 0.
2385 * So with IFRAME-01 we *assume* the hardware will do:
2387 * allow = (IFRAME-01 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2388 * --> allow = (0110 & 0010) == (0010 & 0001) ? 1 : 0;
2389 * --> allow = (0010) == 0000 ? 1 : 0;
2392 * Lets now test a frame that should work:
2394 * IFRAME-02: 0001 (we should allow)
2396 * allow = (0001 & 1010) == 1010
2398 * allow = (IFRAME-02 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2399 * --> allow = (0001 & 0010) == (0010 & 0001) ? 1 :0;
2400 * --> allow = (0010) == (0010)
2405 * IFRAME-03: 0100 --> allowed
2406 * IFRAME-04: 1001 --> allowed
2407 * IFRAME-05: 1101 --> allowed but its not for us!!!
2410 int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
2412 u32 low_id, high_id;
2413 ATH5K_TRACE(ah->ah_sc);
2415 if (ah->ah_version == AR5K_AR5212) {
2416 low_id = AR5K_LOW_ID(mask);
2417 high_id = AR5K_HIGH_ID(mask);
2419 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_IDM0);
2420 ath5k_hw_reg_write(ah, high_id, AR5K_BSS_IDM1);
2429 * Receive start/stop functions
2433 * Start receive on PCU
2435 void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
2437 ATH5K_TRACE(ah->ah_sc);
2438 AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
2440 /* TODO: ANI Support */
2444 * Stop receive on PCU
2446 void ath5k_hw_stop_pcu_recv(struct ath5k_hw *ah)
2448 ATH5K_TRACE(ah->ah_sc);
2449 AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
2451 /* TODO: ANI Support */
2455 * RX Filter functions
2459 * Set multicast filter
2461 void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
2463 ATH5K_TRACE(ah->ah_sc);
2464 /* Set the multicat filter */
2465 ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0);
2466 ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1);
2470 * Set multicast filter by index
2472 int ath5k_hw_set_mcast_filterindex(struct ath5k_hw *ah, u32 index)
2475 ATH5K_TRACE(ah->ah_sc);
2478 else if (index >= 32)
2479 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER1,
2480 (1 << (index - 32)));
2482 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2488 * Clear Multicast filter by index
2490 int ath5k_hw_clear_mcast_filter_idx(struct ath5k_hw *ah, u32 index)
2493 ATH5K_TRACE(ah->ah_sc);
2496 else if (index >= 32)
2497 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER1,
2498 (1 << (index - 32)));
2500 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2506 * Get current rx filter
2508 u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah)
2510 u32 data, filter = 0;
2512 ATH5K_TRACE(ah->ah_sc);
2513 filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER);
2515 /*Radar detection for 5212*/
2516 if (ah->ah_version == AR5K_AR5212) {
2517 data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL);
2519 if (data & AR5K_PHY_ERR_FIL_RADAR)
2520 filter |= AR5K_RX_FILTER_RADARERR;
2521 if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK))
2522 filter |= AR5K_RX_FILTER_PHYERR;
2531 void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
2535 ATH5K_TRACE(ah->ah_sc);
2537 /* Set PHY error filter register on 5212*/
2538 if (ah->ah_version == AR5K_AR5212) {
2539 if (filter & AR5K_RX_FILTER_RADARERR)
2540 data |= AR5K_PHY_ERR_FIL_RADAR;
2541 if (filter & AR5K_RX_FILTER_PHYERR)
2542 data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK;
2546 * The AR5210 uses promiscous mode to detect radar activity
2548 if (ah->ah_version == AR5K_AR5210 &&
2549 (filter & AR5K_RX_FILTER_RADARERR)) {
2550 filter &= ~AR5K_RX_FILTER_RADARERR;
2551 filter |= AR5K_RX_FILTER_PROM;
2556 AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2558 AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2560 /*Write RX Filter register*/
2561 ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER);
2563 /*Write PHY error filter register on 5212*/
2564 if (ah->ah_version == AR5K_AR5212)
2565 ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
2570 * Beacon related functions
2576 u32 ath5k_hw_get_tsf32(struct ath5k_hw *ah)
2578 ATH5K_TRACE(ah->ah_sc);
2579 return ath5k_hw_reg_read(ah, AR5K_TSF_L32);
2583 * Get the full 64bit TSF
2585 u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah)
2587 u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
2588 ATH5K_TRACE(ah->ah_sc);
2590 return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32);
2596 void ath5k_hw_reset_tsf(struct ath5k_hw *ah)
2598 ATH5K_TRACE(ah->ah_sc);
2599 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_RESET_TSF);
2603 * Initialize beacon timers
2605 void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
2607 u32 timer1, timer2, timer3;
2609 ATH5K_TRACE(ah->ah_sc);
2611 * Set the additional timers by mode
2613 switch (ah->ah_op_mode) {
2614 case IEEE80211_IF_TYPE_STA:
2615 if (ah->ah_version == AR5K_AR5210) {
2616 timer1 = 0xffffffff;
2617 timer2 = 0xffffffff;
2619 timer1 = 0x0000ffff;
2620 timer2 = 0x0007ffff;
2625 timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3;
2626 timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3;
2629 timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1);
2632 * Set the beacon register and enable all timers.
2633 * (next beacon, DMA beacon, software beacon, ATIM window time)
2635 ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
2636 ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
2637 ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
2638 ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
2640 ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD |
2641 AR5K_BEACON_RESET_TSF | AR5K_BEACON_ENABLE),
2649 int ath5k_hw_set_beacon_timers(struct ath5k_hw *ah,
2650 const struct ath5k_beacon_state *state)
2652 u32 cfp_period, next_cfp, dtim, interval, next_beacon;
2655 * TODO: should be changed through *state
2656 * review struct ath5k_beacon_state struct
2658 * XXX: These are used for cfp period bellow, are they
2659 * ok ? Is it O.K. for tsf here to be 0 or should we use
2662 u32 dtim_count = 0; /* XXX */
2663 u32 cfp_count = 0; /* XXX */
2664 u32 tsf = 0; /* XXX */
2666 ATH5K_TRACE(ah->ah_sc);
2667 /* Return on an invalid beacon state */
2668 if (state->bs_interval < 1)
2671 interval = state->bs_interval;
2672 dtim = state->bs_dtim_period;
2677 if (state->bs_cfp_period > 0) {
2679 * Enable PCF mode and set the CFP
2680 * (Contention Free Period) and timer registers
2682 cfp_period = state->bs_cfp_period * state->bs_dtim_period *
2684 next_cfp = (cfp_count * state->bs_dtim_period + dtim_count) *
2687 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
2688 AR5K_STA_ID1_DEFAULT_ANTENNA |
2690 ath5k_hw_reg_write(ah, cfp_period, AR5K_CFP_PERIOD);
2691 ath5k_hw_reg_write(ah, state->bs_cfp_max_duration,
2693 ath5k_hw_reg_write(ah, (tsf + (next_cfp == 0 ? cfp_period :
2694 next_cfp)) << 3, AR5K_TIMER2);
2696 /* Disable PCF mode */
2697 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2698 AR5K_STA_ID1_DEFAULT_ANTENNA |
2703 * Enable the beacon timer register
2705 ath5k_hw_reg_write(ah, state->bs_next_beacon, AR5K_TIMER0);
2708 * Start the beacon timers
2710 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_BEACON) &~
2711 (AR5K_BEACON_PERIOD | AR5K_BEACON_TIM)) |
2712 AR5K_REG_SM(state->bs_tim_offset ? state->bs_tim_offset + 4 : 0,
2713 AR5K_BEACON_TIM) | AR5K_REG_SM(state->bs_interval,
2714 AR5K_BEACON_PERIOD), AR5K_BEACON);
2717 * Write new beacon miss threshold, if it appears to be valid
2718 * XXX: Figure out right values for min <= bs_bmiss_threshold <= max
2719 * and return if its not in range. We can test this by reading value and
2720 * setting value to a largest value and seeing which values register.
2723 AR5K_REG_WRITE_BITS(ah, AR5K_RSSI_THR, AR5K_RSSI_THR_BMISS,
2724 state->bs_bmiss_threshold);
2727 * Set sleep control register
2728 * XXX: Didn't find this in 5210 code but since this register
2729 * exists also in ar5k's 5210 headers i leave it as common code.
2731 AR5K_REG_WRITE_BITS(ah, AR5K_SLEEP_CTL, AR5K_SLEEP_CTL_SLDUR,
2732 (state->bs_sleep_duration - 3) << 3);
2735 * Set enhanced sleep registers on 5212
2737 if (ah->ah_version == AR5K_AR5212) {
2738 if (state->bs_sleep_duration > state->bs_interval &&
2739 roundup(state->bs_sleep_duration, interval) ==
2740 state->bs_sleep_duration)
2741 interval = state->bs_sleep_duration;
2743 if (state->bs_sleep_duration > dtim && (dtim == 0 ||
2744 roundup(state->bs_sleep_duration, dtim) ==
2745 state->bs_sleep_duration))
2746 dtim = state->bs_sleep_duration;
2748 if (interval > dtim)
2751 next_beacon = interval == dtim ? state->bs_next_dtim :
2752 state->bs_next_beacon;
2754 ath5k_hw_reg_write(ah,
2755 AR5K_REG_SM((state->bs_next_dtim - 3) << 3,
2756 AR5K_SLEEP0_NEXT_DTIM) |
2757 AR5K_REG_SM(10, AR5K_SLEEP0_CABTO) |
2758 AR5K_SLEEP0_ENH_SLEEP_EN |
2759 AR5K_SLEEP0_ASSUME_DTIM, AR5K_SLEEP0);
2761 ath5k_hw_reg_write(ah, AR5K_REG_SM((next_beacon - 3) << 3,
2762 AR5K_SLEEP1_NEXT_TIM) |
2763 AR5K_REG_SM(10, AR5K_SLEEP1_BEACON_TO), AR5K_SLEEP1);
2765 ath5k_hw_reg_write(ah,
2766 AR5K_REG_SM(interval, AR5K_SLEEP2_TIM_PER) |
2767 AR5K_REG_SM(dtim, AR5K_SLEEP2_DTIM_PER), AR5K_SLEEP2);
2774 * Reset beacon timers
2776 void ath5k_hw_reset_beacon(struct ath5k_hw *ah)
2778 ATH5K_TRACE(ah->ah_sc);
2780 * Disable beacon timer
2782 ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
2785 * Disable some beacon register values
2787 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2788 AR5K_STA_ID1_DEFAULT_ANTENNA | AR5K_STA_ID1_PCF);
2789 ath5k_hw_reg_write(ah, AR5K_BEACON_PERIOD, AR5K_BEACON);
2793 * Wait for beacon queue to finish
2795 int ath5k_hw_beaconq_finish(struct ath5k_hw *ah, unsigned long phys_addr)
2800 ATH5K_TRACE(ah->ah_sc);
2802 /* 5210 doesn't have QCU*/
2803 if (ah->ah_version == AR5K_AR5210) {
2805 * Wait for beaconn queue to finish by checking
2806 * Control Register and Beacon Status Register.
2808 for (i = AR5K_TUNE_BEACON_INTERVAL / 2; i > 0; i--) {
2809 if (!(ath5k_hw_reg_read(ah, AR5K_BSR) & AR5K_BSR_TXQ1F)
2811 !(ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_BSR_TXQ1F))
2819 * Re-schedule the beacon queue
2821 ath5k_hw_reg_write(ah, phys_addr, AR5K_NOQCU_TXDP1);
2822 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
2830 ret = ath5k_hw_register_timeout(ah,
2831 AR5K_QUEUE_STATUS(AR5K_TX_QUEUE_ID_BEACON),
2832 AR5K_QCU_STS_FRMPENDCNT, 0, false);
2834 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, AR5K_TX_QUEUE_ID_BEACON))
2843 * Update mib counters (statistics)
2845 void ath5k_hw_update_mib_counters(struct ath5k_hw *ah,
2846 struct ath5k_mib_stats *statistics)
2848 ATH5K_TRACE(ah->ah_sc);
2849 /* Read-And-Clear */
2850 statistics->ackrcv_bad += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL);
2851 statistics->rts_bad += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL);
2852 statistics->rts_good += ath5k_hw_reg_read(ah, AR5K_RTS_OK);
2853 statistics->fcs_bad += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL);
2854 statistics->beacons += ath5k_hw_reg_read(ah, AR5K_BEACON_CNT);
2856 /* Reset profile count registers on 5212*/
2857 if (ah->ah_version == AR5K_AR5212) {
2858 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_TX);
2859 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RX);
2860 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR);
2861 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE);
2865 /** ath5k_hw_set_ack_bitrate - set bitrate for ACKs
2867 * @ah: the &struct ath5k_hw
2868 * @high: determines if to use low bit rate or now
2870 void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high)
2872 if (ah->ah_version != AR5K_AR5212)
2875 u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB;
2877 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val);
2879 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val);
2889 * Set ACK timeout on PCU
2891 int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout)
2893 ATH5K_TRACE(ah->ah_sc);
2894 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK),
2895 ah->ah_turbo) <= timeout)
2898 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK,
2899 ath5k_hw_htoclock(timeout, ah->ah_turbo));
2905 * Read the ACK timeout from PCU
2907 unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah)
2909 ATH5K_TRACE(ah->ah_sc);
2911 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
2912 AR5K_TIME_OUT), AR5K_TIME_OUT_ACK), ah->ah_turbo);
2916 * Set CTS timeout on PCU
2918 int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout)
2920 ATH5K_TRACE(ah->ah_sc);
2921 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS),
2922 ah->ah_turbo) <= timeout)
2925 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS,
2926 ath5k_hw_htoclock(timeout, ah->ah_turbo));
2932 * Read CTS timeout from PCU
2934 unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah)
2936 ATH5K_TRACE(ah->ah_sc);
2937 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
2938 AR5K_TIME_OUT), AR5K_TIME_OUT_CTS), ah->ah_turbo);
2942 * Key table (WEP) functions
2945 int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
2949 ATH5K_TRACE(ah->ah_sc);
2950 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
2952 for (i = 0; i < AR5K_KEYCACHE_SIZE; i++)
2953 ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i));
2955 /* Set NULL encryption on non-5210*/
2956 if (ah->ah_version != AR5K_AR5210)
2957 ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
2958 AR5K_KEYTABLE_TYPE(entry));
2963 int ath5k_hw_is_key_valid(struct ath5k_hw *ah, u16 entry)
2965 ATH5K_TRACE(ah->ah_sc);
2966 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
2968 /* Check the validation flag at the end of the entry */
2969 return ath5k_hw_reg_read(ah, AR5K_KEYTABLE_MAC1(entry)) &
2970 AR5K_KEYTABLE_VALID;
2973 int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
2974 const struct ieee80211_key_conf *key, const u8 *mac)
2977 __le32 key_v[5] = {};
2980 ATH5K_TRACE(ah->ah_sc);
2982 /* key->keylen comes in from mac80211 in bytes */
2984 if (key->keylen > AR5K_KEYTABLE_SIZE / 8)
2987 switch (key->keylen) {
2988 /* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit */
2990 memcpy(&key_v[0], key->key, 5);
2991 keytype = AR5K_KEYTABLE_TYPE_40;
2994 /* WEP 104-bit = 104-bit entered key + 24-bit IV = 128-bit */
2996 memcpy(&key_v[0], &key->key[0], 6);
2997 memcpy(&key_v[2], &key->key[6], 6);
2998 memcpy(&key_v[4], &key->key[12], 1);
2999 keytype = AR5K_KEYTABLE_TYPE_104;
3001 /* WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit */
3003 memcpy(&key_v[0], &key->key[0], 6);
3004 memcpy(&key_v[2], &key->key[6], 6);
3005 memcpy(&key_v[4], &key->key[12], 4);
3006 keytype = AR5K_KEYTABLE_TYPE_128;
3010 return -EINVAL; /* shouldn't happen */
3013 for (i = 0; i < ARRAY_SIZE(key_v); i++)
3014 ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
3015 AR5K_KEYTABLE_OFF(entry, i));
3017 ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry));
3019 return ath5k_hw_set_key_lladdr(ah, entry, mac);
3022 int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac)
3024 u32 low_id, high_id;
3026 ATH5K_TRACE(ah->ah_sc);
3027 /* Invalid entry (key table overflow) */
3028 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3030 /* MAC may be NULL if it's a broadcast key. In this case no need to
3031 * to compute AR5K_LOW_ID and AR5K_HIGH_ID as we already know it. */
3032 if (unlikely(mac == NULL)) {
3033 low_id = 0xffffffff;
3034 high_id = 0xffff | AR5K_KEYTABLE_VALID;
3036 low_id = AR5K_LOW_ID(mac);
3037 high_id = AR5K_HIGH_ID(mac) | AR5K_KEYTABLE_VALID;
3040 ath5k_hw_reg_write(ah, low_id, AR5K_KEYTABLE_MAC0(entry));
3041 ath5k_hw_reg_write(ah, high_id, AR5K_KEYTABLE_MAC1(entry));
3047 /********************************************\
3048 Queue Control Unit, DFS Control Unit Functions
3049 \********************************************/
3052 * Initialize a transmit queue
3054 int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type,
3055 struct ath5k_txq_info *queue_info)
3060 ATH5K_TRACE(ah->ah_sc);
3065 /*5210 only has 2 queues*/
3066 if (ah->ah_version == AR5K_AR5210) {
3067 switch (queue_type) {
3068 case AR5K_TX_QUEUE_DATA:
3069 queue = AR5K_TX_QUEUE_ID_NOQCU_DATA;
3071 case AR5K_TX_QUEUE_BEACON:
3072 case AR5K_TX_QUEUE_CAB:
3073 queue = AR5K_TX_QUEUE_ID_NOQCU_BEACON;
3079 switch (queue_type) {
3080 case AR5K_TX_QUEUE_DATA:
3081 for (queue = AR5K_TX_QUEUE_ID_DATA_MIN;
3082 ah->ah_txq[queue].tqi_type !=
3083 AR5K_TX_QUEUE_INACTIVE; queue++) {
3085 if (queue > AR5K_TX_QUEUE_ID_DATA_MAX)
3089 case AR5K_TX_QUEUE_UAPSD:
3090 queue = AR5K_TX_QUEUE_ID_UAPSD;
3092 case AR5K_TX_QUEUE_BEACON:
3093 queue = AR5K_TX_QUEUE_ID_BEACON;
3095 case AR5K_TX_QUEUE_CAB:
3096 queue = AR5K_TX_QUEUE_ID_CAB;
3098 case AR5K_TX_QUEUE_XR_DATA:
3099 if (ah->ah_version != AR5K_AR5212)
3100 ATH5K_ERR(ah->ah_sc,
3101 "XR data queues only supported in"
3103 queue = AR5K_TX_QUEUE_ID_XR_DATA;
3111 * Setup internal queue structure
3113 memset(&ah->ah_txq[queue], 0, sizeof(struct ath5k_txq_info));
3114 ah->ah_txq[queue].tqi_type = queue_type;
3116 if (queue_info != NULL) {
3117 queue_info->tqi_type = queue_type;
3118 ret = ath5k_hw_setup_tx_queueprops(ah, queue, queue_info);
3123 * We use ah_txq_status to hold a temp value for
3124 * the Secondary interrupt mask registers on 5211+
3125 * check out ath5k_hw_reset_tx_queue
3127 AR5K_Q_ENABLE_BITS(ah->ah_txq_status, queue);
3133 * Setup a transmit queue
3135 int ath5k_hw_setup_tx_queueprops(struct ath5k_hw *ah, int queue,
3136 const struct ath5k_txq_info *queue_info)
3138 ATH5K_TRACE(ah->ah_sc);
3139 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3141 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3144 memcpy(&ah->ah_txq[queue], queue_info, sizeof(struct ath5k_txq_info));
3146 /*XXX: Is this supported on 5210 ?*/
3147 if ((queue_info->tqi_type == AR5K_TX_QUEUE_DATA &&
3148 ((queue_info->tqi_subtype == AR5K_WME_AC_VI) ||
3149 (queue_info->tqi_subtype == AR5K_WME_AC_VO))) ||
3150 queue_info->tqi_type == AR5K_TX_QUEUE_UAPSD)
3151 ah->ah_txq[queue].tqi_flags |= AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
3157 * Get properties for a specific transmit queue
3159 int ath5k_hw_get_tx_queueprops(struct ath5k_hw *ah, int queue,
3160 struct ath5k_txq_info *queue_info)
3162 ATH5K_TRACE(ah->ah_sc);
3163 memcpy(queue_info, &ah->ah_txq[queue], sizeof(struct ath5k_txq_info));
3168 * Set a transmit queue inactive
3170 void ath5k_hw_release_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3172 ATH5K_TRACE(ah->ah_sc);
3173 if (WARN_ON(queue >= ah->ah_capabilities.cap_queues.q_tx_num))
3176 /* This queue will be skipped in further operations */
3177 ah->ah_txq[queue].tqi_type = AR5K_TX_QUEUE_INACTIVE;
3179 AR5K_Q_DISABLE_BITS(ah->ah_txq_status, queue);
3183 * Set DFS params for a transmit queue
3185 int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3187 u32 cw_min, cw_max, retry_lg, retry_sh;
3188 struct ath5k_txq_info *tq = &ah->ah_txq[queue];
3190 ATH5K_TRACE(ah->ah_sc);
3191 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3193 tq = &ah->ah_txq[queue];
3195 if (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE)
3198 if (ah->ah_version == AR5K_AR5210) {
3199 /* Only handle data queues, others will be ignored */
3200 if (tq->tqi_type != AR5K_TX_QUEUE_DATA)
3204 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3205 AR5K_INIT_SLOT_TIME_TURBO : AR5K_INIT_SLOT_TIME,
3207 /* Set ACK_CTS timeout */
3208 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3209 AR5K_INIT_ACK_CTS_TIMEOUT_TURBO :
3210 AR5K_INIT_ACK_CTS_TIMEOUT, AR5K_SLOT_TIME);
3211 /* Set Transmit Latency */
3212 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3213 AR5K_INIT_TRANSMIT_LATENCY_TURBO :
3214 AR5K_INIT_TRANSMIT_LATENCY, AR5K_USEC_5210);
3216 if (ah->ah_turbo == true)
3217 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS_TURBO +
3218 (ah->ah_aifs + tq->tqi_aifs) *
3219 AR5K_INIT_SLOT_TIME_TURBO) <<
3220 AR5K_IFS0_DIFS_S) | AR5K_INIT_SIFS_TURBO,
3223 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS +
3224 (ah->ah_aifs + tq->tqi_aifs) *
3225 AR5K_INIT_SLOT_TIME) << AR5K_IFS0_DIFS_S) |
3226 AR5K_INIT_SIFS, AR5K_IFS0);
3229 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3230 AR5K_INIT_PROTO_TIME_CNTRL_TURBO :
3231 AR5K_INIT_PROTO_TIME_CNTRL, AR5K_IFS1);
3232 /* Set PHY register 0x9844 (??) */
3233 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3234 (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x38 :
3235 (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x1C,
3237 /* Set Frame Control Register */
3238 ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
3239 (AR5K_PHY_FRAME_CTL_INI | AR5K_PHY_TURBO_MODE |
3240 AR5K_PHY_TURBO_SHORT | 0x2020) :
3241 (AR5K_PHY_FRAME_CTL_INI | 0x1020),
3242 AR5K_PHY_FRAME_CTL_5210);
3246 * Calculate cwmin/max by channel mode
3248 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN;
3249 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX;
3250 ah->ah_aifs = AR5K_TUNE_AIFS;
3251 /*XR is only supported on 5212*/
3252 if (IS_CHAN_XR(ah->ah_current_channel) &&
3253 ah->ah_version == AR5K_AR5212) {
3254 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_XR;
3255 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_XR;
3256 ah->ah_aifs = AR5K_TUNE_AIFS_XR;
3257 /*B mode is not supported on 5210*/
3258 } else if (IS_CHAN_B(ah->ah_current_channel) &&
3259 ah->ah_version != AR5K_AR5210) {
3260 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_11B;
3261 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_11B;
3262 ah->ah_aifs = AR5K_TUNE_AIFS_11B;
3266 while (cw_min < ah->ah_cw_min)
3267 cw_min = (cw_min << 1) | 1;
3269 cw_min = tq->tqi_cw_min < 0 ? (cw_min >> (-tq->tqi_cw_min)) :
3270 ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
3271 cw_max = tq->tqi_cw_max < 0 ? (cw_max >> (-tq->tqi_cw_max)) :
3272 ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
3275 * Calculate and set retry limits
3277 if (ah->ah_software_retry == true) {
3278 /* XXX Need to test this */
3279 retry_lg = ah->ah_limit_tx_retries;
3280 retry_sh = retry_lg = retry_lg > AR5K_DCU_RETRY_LMT_SH_RETRY ?
3281 AR5K_DCU_RETRY_LMT_SH_RETRY : retry_lg;
3283 retry_lg = AR5K_INIT_LG_RETRY;
3284 retry_sh = AR5K_INIT_SH_RETRY;
3287 /*No QCU/DCU [5210]*/
3288 if (ah->ah_version == AR5K_AR5210) {
3289 ath5k_hw_reg_write(ah,
3290 (cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
3291 | AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3292 AR5K_NODCU_RETRY_LMT_SLG_RETRY)
3293 | AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3294 AR5K_NODCU_RETRY_LMT_SSH_RETRY)
3295 | AR5K_REG_SM(retry_lg, AR5K_NODCU_RETRY_LMT_LG_RETRY)
3296 | AR5K_REG_SM(retry_sh, AR5K_NODCU_RETRY_LMT_SH_RETRY),
3297 AR5K_NODCU_RETRY_LMT);
3300 ath5k_hw_reg_write(ah,
3301 AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3302 AR5K_DCU_RETRY_LMT_SLG_RETRY) |
3303 AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3304 AR5K_DCU_RETRY_LMT_SSH_RETRY) |
3305 AR5K_REG_SM(retry_lg, AR5K_DCU_RETRY_LMT_LG_RETRY) |
3306 AR5K_REG_SM(retry_sh, AR5K_DCU_RETRY_LMT_SH_RETRY),
3307 AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
3309 /*===Rest is also for QCU/DCU only [5211+]===*/
3312 * Set initial content window (cw_min/cw_max)
3313 * and arbitrated interframe space (aifs)...
3315 ath5k_hw_reg_write(ah,
3316 AR5K_REG_SM(cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
3317 AR5K_REG_SM(cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
3318 AR5K_REG_SM(ah->ah_aifs + tq->tqi_aifs,
3319 AR5K_DCU_LCL_IFS_AIFS),
3320 AR5K_QUEUE_DFS_LOCAL_IFS(queue));
3323 * Set misc registers
3325 ath5k_hw_reg_write(ah, AR5K_QCU_MISC_DCU_EARLY,
3326 AR5K_QUEUE_MISC(queue));
3328 if (tq->tqi_cbr_period) {
3329 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
3330 AR5K_QCU_CBRCFG_INTVAL) |
3331 AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
3332 AR5K_QCU_CBRCFG_ORN_THRES),
3333 AR5K_QUEUE_CBRCFG(queue));
3334 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3335 AR5K_QCU_MISC_FRSHED_CBR);
3336 if (tq->tqi_cbr_overflow_limit)
3337 AR5K_REG_ENABLE_BITS(ah,
3338 AR5K_QUEUE_MISC(queue),
3339 AR5K_QCU_MISC_CBR_THRES_ENABLE);
3342 if (tq->tqi_ready_time)
3343 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
3344 AR5K_QCU_RDYTIMECFG_INTVAL) |
3345 AR5K_QCU_RDYTIMECFG_ENABLE,
3346 AR5K_QUEUE_RDYTIMECFG(queue));
3348 if (tq->tqi_burst_time) {
3349 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
3350 AR5K_DCU_CHAN_TIME_DUR) |
3351 AR5K_DCU_CHAN_TIME_ENABLE,
3352 AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
3354 if (tq->tqi_flags & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
3355 AR5K_REG_ENABLE_BITS(ah,
3356 AR5K_QUEUE_MISC(queue),
3360 if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
3361 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
3362 AR5K_QUEUE_DFS_MISC(queue));
3364 if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
3365 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
3366 AR5K_QUEUE_DFS_MISC(queue));
3369 * Set registers by queue type
3371 switch (tq->tqi_type) {
3372 case AR5K_TX_QUEUE_BEACON:
3373 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3374 AR5K_QCU_MISC_FRSHED_DBA_GT |
3375 AR5K_QCU_MISC_CBREXP_BCN |
3376 AR5K_QCU_MISC_BCN_ENABLE);
3378 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3379 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3380 AR5K_DCU_MISC_ARBLOCK_CTL_S) |
3381 AR5K_DCU_MISC_POST_FR_BKOFF_DIS |
3382 AR5K_DCU_MISC_BCN_ENABLE);
3384 ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL -
3385 (AR5K_TUNE_SW_BEACON_RESP -
3386 AR5K_TUNE_DMA_BEACON_RESP) -
3387 AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF) * 1024) |
3388 AR5K_QCU_RDYTIMECFG_ENABLE,
3389 AR5K_QUEUE_RDYTIMECFG(queue));
3392 case AR5K_TX_QUEUE_CAB:
3393 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3394 AR5K_QCU_MISC_FRSHED_DBA_GT |
3395 AR5K_QCU_MISC_CBREXP |
3396 AR5K_QCU_MISC_CBREXP_BCN);
3398 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3399 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3400 AR5K_DCU_MISC_ARBLOCK_CTL_S));
3403 case AR5K_TX_QUEUE_UAPSD:
3404 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3405 AR5K_QCU_MISC_CBREXP);
3408 case AR5K_TX_QUEUE_DATA:
3414 * Enable interrupts for this tx queue
3415 * in the secondary interrupt mask registers
3417 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
3418 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
3420 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
3421 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
3423 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
3424 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
3426 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
3427 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
3429 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
3430 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
3433 /* Update secondary interrupt mask registers */
3434 ah->ah_txq_imr_txok &= ah->ah_txq_status;
3435 ah->ah_txq_imr_txerr &= ah->ah_txq_status;
3436 ah->ah_txq_imr_txurn &= ah->ah_txq_status;
3437 ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
3438 ah->ah_txq_imr_txeol &= ah->ah_txq_status;
3440 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
3441 AR5K_SIMR0_QCU_TXOK) |
3442 AR5K_REG_SM(ah->ah_txq_imr_txdesc,
3443 AR5K_SIMR0_QCU_TXDESC), AR5K_SIMR0);
3444 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
3445 AR5K_SIMR1_QCU_TXERR) |
3446 AR5K_REG_SM(ah->ah_txq_imr_txeol,
3447 AR5K_SIMR1_QCU_TXEOL), AR5K_SIMR1);
3448 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txurn,
3449 AR5K_SIMR2_QCU_TXURN), AR5K_SIMR2);
3456 * Get number of pending frames
3457 * for a specific queue [5211+]
3459 u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah, unsigned int queue) {
3460 ATH5K_TRACE(ah->ah_sc);
3461 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3463 /* Return if queue is declared inactive */
3464 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3467 /* XXX: How about AR5K_CFG_TXCNT ? */
3468 if (ah->ah_version == AR5K_AR5210)
3471 return AR5K_QUEUE_STATUS(queue) & AR5K_QCU_STS_FRMPENDCNT;
3477 int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time)
3479 ATH5K_TRACE(ah->ah_sc);
3480 if (slot_time < AR5K_SLOT_TIME_9 || slot_time > AR5K_SLOT_TIME_MAX)
3483 if (ah->ah_version == AR5K_AR5210)
3484 ath5k_hw_reg_write(ah, ath5k_hw_htoclock(slot_time,
3485 ah->ah_turbo), AR5K_SLOT_TIME);
3487 ath5k_hw_reg_write(ah, slot_time, AR5K_DCU_GBL_IFS_SLOT);
3495 unsigned int ath5k_hw_get_slot_time(struct ath5k_hw *ah)
3497 ATH5K_TRACE(ah->ah_sc);
3498 if (ah->ah_version == AR5K_AR5210)
3499 return ath5k_hw_clocktoh(ath5k_hw_reg_read(ah,
3500 AR5K_SLOT_TIME) & 0xffff, ah->ah_turbo);
3502 return ath5k_hw_reg_read(ah, AR5K_DCU_GBL_IFS_SLOT) & 0xffff;
3506 /******************************\
3507 Hardware Descriptor Functions
3508 \******************************/
3515 * Initialize the 2-word tx descriptor on 5210/5211
3518 ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3519 unsigned int pkt_len, unsigned int hdr_len, enum ath5k_pkt_type type,
3520 unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
3521 unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
3522 unsigned int rtscts_rate, unsigned int rtscts_duration)
3525 struct ath5k_hw_2w_tx_desc *tx_desc;
3526 unsigned int frame_len;
3528 tx_desc = (struct ath5k_hw_2w_tx_desc *)&desc->ds_ctl0;
3532 * - Zero retries don't make sense.
3533 * - A zero rate will put the HW into a mode where it continously sends
3534 * noise on the channel, so it is important to avoid this.
3536 if (unlikely(tx_tries0 == 0)) {
3537 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3541 if (unlikely(tx_rate0 == 0)) {
3542 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3547 /* Clear status descriptor */
3548 memset(desc->ds_hw, 0, sizeof(struct ath5k_hw_tx_status));
3550 /* Initialize control descriptor */
3551 tx_desc->tx_control_0 = 0;
3552 tx_desc->tx_control_1 = 0;
3554 /* Setup control descriptor */
3556 /* Verify and set frame length */
3558 /* remove padding we might have added before */
3559 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3561 if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
3564 tx_desc->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
3566 /* Verify and set buffer length */
3568 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3569 if(type == AR5K_PKT_TYPE_BEACON)
3570 pkt_len = roundup(pkt_len, 4);
3572 if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
3575 tx_desc->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
3578 * Verify and set header length
3579 * XXX: I only found that on 5210 code, does it work on 5211 ?
3581 if (ah->ah_version == AR5K_AR5210) {
3582 if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN)
3584 tx_desc->tx_control_0 |=
3585 AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN);
3588 /*Diferences between 5210-5211*/
3589 if (ah->ah_version == AR5K_AR5210) {
3591 case AR5K_PKT_TYPE_BEACON:
3592 case AR5K_PKT_TYPE_PROBE_RESP:
3593 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
3594 case AR5K_PKT_TYPE_PIFS:
3595 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
3597 frame_type = type /*<< 2 ?*/;
3600 tx_desc->tx_control_0 |=
3601 AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE) |
3602 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3604 tx_desc->tx_control_0 |=
3605 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
3606 AR5K_REG_SM(antenna_mode, AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
3607 tx_desc->tx_control_1 |=
3608 AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE);
3610 #define _TX_FLAGS(_c, _flag) \
3611 if (flags & AR5K_TXDESC_##_flag) \
3612 tx_desc->tx_control_##_c |= \
3613 AR5K_2W_TX_DESC_CTL##_c##_##_flag
3615 _TX_FLAGS(0, CLRDMASK);
3617 _TX_FLAGS(0, INTREQ);
3618 _TX_FLAGS(0, RTSENA);
3619 _TX_FLAGS(1, NOACK);
3626 if (key_index != AR5K_TXKEYIX_INVALID) {
3627 tx_desc->tx_control_0 |=
3628 AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3629 tx_desc->tx_control_1 |=
3630 AR5K_REG_SM(key_index,
3631 AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3635 * RTS/CTS Duration [5210 ?]
3637 if ((ah->ah_version == AR5K_AR5210) &&
3638 (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
3639 tx_desc->tx_control_1 |= rtscts_duration &
3640 AR5K_2W_TX_DESC_CTL1_RTS_DURATION;
3646 * Initialize the 4-word tx descriptor on 5212
3648 static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
3649 struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
3650 enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
3651 unsigned int tx_tries0, unsigned int key_index,
3652 unsigned int antenna_mode, unsigned int flags, unsigned int rtscts_rate,
3653 unsigned int rtscts_duration)
3655 struct ath5k_hw_4w_tx_desc *tx_desc;
3656 struct ath5k_hw_tx_status *tx_status;
3657 unsigned int frame_len;
3659 ATH5K_TRACE(ah->ah_sc);
3660 tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
3661 tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[2];
3665 * - Zero retries don't make sense.
3666 * - A zero rate will put the HW into a mode where it continously sends
3667 * noise on the channel, so it is important to avoid this.
3669 if (unlikely(tx_tries0 == 0)) {
3670 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3674 if (unlikely(tx_rate0 == 0)) {
3675 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3680 /* Clear status descriptor */
3681 memset(tx_status, 0, sizeof(struct ath5k_hw_tx_status));
3683 /* Initialize control descriptor */
3684 tx_desc->tx_control_0 = 0;
3685 tx_desc->tx_control_1 = 0;
3686 tx_desc->tx_control_2 = 0;
3687 tx_desc->tx_control_3 = 0;
3689 /* Setup control descriptor */
3691 /* Verify and set frame length */
3693 /* remove padding we might have added before */
3694 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3696 if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
3699 tx_desc->tx_control_0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
3701 /* Verify and set buffer length */
3703 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3704 if(type == AR5K_PKT_TYPE_BEACON)
3705 pkt_len = roundup(pkt_len, 4);
3707 if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
3710 tx_desc->tx_control_1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
3712 tx_desc->tx_control_0 |=
3713 AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
3714 AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
3715 tx_desc->tx_control_1 |= AR5K_REG_SM(type,
3716 AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
3717 tx_desc->tx_control_2 = AR5K_REG_SM(tx_tries0 + AR5K_TUNE_HWTXTRIES,
3718 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
3719 tx_desc->tx_control_3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
3721 #define _TX_FLAGS(_c, _flag) \
3722 if (flags & AR5K_TXDESC_##_flag) \
3723 tx_desc->tx_control_##_c |= \
3724 AR5K_4W_TX_DESC_CTL##_c##_##_flag
3726 _TX_FLAGS(0, CLRDMASK);
3728 _TX_FLAGS(0, INTREQ);
3729 _TX_FLAGS(0, RTSENA);
3730 _TX_FLAGS(0, CTSENA);
3731 _TX_FLAGS(1, NOACK);
3738 if (key_index != AR5K_TXKEYIX_INVALID) {
3739 tx_desc->tx_control_0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3740 tx_desc->tx_control_1 |= AR5K_REG_SM(key_index,
3741 AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3747 if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
3748 if ((flags & AR5K_TXDESC_RTSENA) &&
3749 (flags & AR5K_TXDESC_CTSENA))
3751 tx_desc->tx_control_2 |= rtscts_duration &
3752 AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
3753 tx_desc->tx_control_3 |= AR5K_REG_SM(rtscts_rate,
3754 AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
3761 * Initialize a 4-word multirate tx descriptor on 5212
3764 ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3765 unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2, u_int tx_tries2,
3766 unsigned int tx_rate3, u_int tx_tries3)
3768 struct ath5k_hw_4w_tx_desc *tx_desc;
3771 * Rates can be 0 as long as the retry count is 0 too.
3772 * A zero rate and nonzero retry count will put the HW into a mode where
3773 * it continously sends noise on the channel, so it is important to
3776 if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
3777 (tx_rate2 == 0 && tx_tries2 != 0) ||
3778 (tx_rate3 == 0 && tx_tries3 != 0))) {
3779 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3784 if (ah->ah_version == AR5K_AR5212) {
3785 tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
3787 #define _XTX_TRIES(_n) \
3788 if (tx_tries##_n) { \
3789 tx_desc->tx_control_2 |= \
3790 AR5K_REG_SM(tx_tries##_n, \
3791 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
3792 tx_desc->tx_control_3 |= \
3793 AR5K_REG_SM(tx_rate##_n, \
3794 AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
3810 * Proccess the tx status descriptor on 5210/5211
3812 static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
3813 struct ath5k_desc *desc)
3815 struct ath5k_hw_tx_status *tx_status;
3816 struct ath5k_hw_2w_tx_desc *tx_desc;
3818 tx_desc = (struct ath5k_hw_2w_tx_desc *)&desc->ds_ctl0;
3819 tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[0];
3821 /* No frame has been send or error */
3822 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
3823 return -EINPROGRESS;
3826 * Get descriptor status
3828 desc->ds_us.tx.ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
3829 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
3830 desc->ds_us.tx.ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
3831 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
3832 desc->ds_us.tx.ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
3833 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
3834 /*TODO: desc->ds_us.tx.ts_virtcol + test*/
3835 desc->ds_us.tx.ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
3836 AR5K_DESC_TX_STATUS1_SEQ_NUM);
3837 desc->ds_us.tx.ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
3838 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
3839 desc->ds_us.tx.ts_antenna = 1;
3840 desc->ds_us.tx.ts_status = 0;
3841 desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_0,
3842 AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3844 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
3845 if (tx_status->tx_status_0 &
3846 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
3847 desc->ds_us.tx.ts_status |= AR5K_TXERR_XRETRY;
3849 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
3850 desc->ds_us.tx.ts_status |= AR5K_TXERR_FIFO;
3852 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
3853 desc->ds_us.tx.ts_status |= AR5K_TXERR_FILT;
3860 * Proccess a tx descriptor on 5212
3862 static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
3863 struct ath5k_desc *desc)
3865 struct ath5k_hw_tx_status *tx_status;
3866 struct ath5k_hw_4w_tx_desc *tx_desc;
3868 ATH5K_TRACE(ah->ah_sc);
3869 tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
3870 tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[2];
3872 /* No frame has been send or error */
3873 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
3874 return -EINPROGRESS;
3877 * Get descriptor status
3879 desc->ds_us.tx.ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
3880 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
3881 desc->ds_us.tx.ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
3882 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
3883 desc->ds_us.tx.ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
3884 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
3885 desc->ds_us.tx.ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
3886 AR5K_DESC_TX_STATUS1_SEQ_NUM);
3887 desc->ds_us.tx.ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
3888 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
3889 desc->ds_us.tx.ts_antenna = (tx_status->tx_status_1 &
3890 AR5K_DESC_TX_STATUS1_XMIT_ANTENNA) ? 2 : 1;
3891 desc->ds_us.tx.ts_status = 0;
3893 switch (AR5K_REG_MS(tx_status->tx_status_1,
3894 AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX)) {
3896 desc->ds_us.tx.ts_rate = tx_desc->tx_control_3 &
3897 AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
3900 desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
3901 AR5K_4W_TX_DESC_CTL3_XMIT_RATE1);
3902 desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
3903 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1);
3906 desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
3907 AR5K_4W_TX_DESC_CTL3_XMIT_RATE2);
3908 desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
3909 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2);
3912 desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
3913 AR5K_4W_TX_DESC_CTL3_XMIT_RATE3);
3914 desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
3915 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES3);
3919 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
3920 if (tx_status->tx_status_0 &
3921 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
3922 desc->ds_us.tx.ts_status |= AR5K_TXERR_XRETRY;
3924 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
3925 desc->ds_us.tx.ts_status |= AR5K_TXERR_FIFO;
3927 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
3928 desc->ds_us.tx.ts_status |= AR5K_TXERR_FILT;
3939 * Initialize an rx descriptor
3941 int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3942 u32 size, unsigned int flags)
3944 struct ath5k_rx_desc *rx_desc;
3946 ATH5K_TRACE(ah->ah_sc);
3947 rx_desc = (struct ath5k_rx_desc *)&desc->ds_ctl0;
3951 * If we don't clean the status descriptor,
3952 * while scanning we get too many results,
3953 * most of them virtual, after some secs
3954 * of scanning system hangs. M.F.
3956 memset(desc->ds_hw, 0, sizeof(desc->ds_hw));
3958 /*Initialize rx descriptor*/
3959 rx_desc->rx_control_0 = 0;
3960 rx_desc->rx_control_1 = 0;
3962 /* Setup descriptor */
3963 rx_desc->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
3964 if (unlikely(rx_desc->rx_control_1 != size))
3967 if (flags & AR5K_RXDESC_INTREQ)
3968 rx_desc->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
3974 * Proccess the rx status descriptor on 5210/5211
3976 static int ath5k_hw_proc_old_rx_status(struct ath5k_hw *ah,
3977 struct ath5k_desc *desc)
3979 struct ath5k_hw_old_rx_status *rx_status;
3981 rx_status = (struct ath5k_hw_old_rx_status *)&desc->ds_hw[0];
3983 /* No frame received / not ready */
3984 if (unlikely((rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_DONE)
3986 return -EINPROGRESS;
3989 * Frame receive status
3991 desc->ds_us.rx.rs_datalen = rx_status->rx_status_0 &
3992 AR5K_OLD_RX_DESC_STATUS0_DATA_LEN;
3993 desc->ds_us.rx.rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
3994 AR5K_OLD_RX_DESC_STATUS0_RECEIVE_SIGNAL);
3995 desc->ds_us.rx.rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
3996 AR5K_OLD_RX_DESC_STATUS0_RECEIVE_RATE);
3997 desc->ds_us.rx.rs_antenna = rx_status->rx_status_0 &
3998 AR5K_OLD_RX_DESC_STATUS0_RECEIVE_ANTENNA;
3999 desc->ds_us.rx.rs_more = rx_status->rx_status_0 &
4000 AR5K_OLD_RX_DESC_STATUS0_MORE;
4001 desc->ds_us.rx.rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
4002 AR5K_OLD_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
4003 desc->ds_us.rx.rs_status = 0;
4008 if (rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_KEY_INDEX_VALID)
4009 desc->ds_us.rx.rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
4010 AR5K_OLD_RX_DESC_STATUS1_KEY_INDEX);
4012 desc->ds_us.rx.rs_keyix = AR5K_RXKEYIX_INVALID;
4015 * Receive/descriptor errors
4017 if ((rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_FRAME_RECEIVE_OK)
4019 if (rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_CRC_ERROR)
4020 desc->ds_us.rx.rs_status |= AR5K_RXERR_CRC;
4022 if (rx_status->rx_status_1 &
4023 AR5K_OLD_RX_DESC_STATUS1_FIFO_OVERRUN)
4024 desc->ds_us.rx.rs_status |= AR5K_RXERR_FIFO;
4026 if (rx_status->rx_status_1 &
4027 AR5K_OLD_RX_DESC_STATUS1_PHY_ERROR) {
4028 desc->ds_us.rx.rs_status |= AR5K_RXERR_PHY;
4029 desc->ds_us.rx.rs_phyerr =
4030 AR5K_REG_MS(rx_status->rx_status_1,
4031 AR5K_OLD_RX_DESC_STATUS1_PHY_ERROR);
4034 if (rx_status->rx_status_1 &
4035 AR5K_OLD_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
4036 desc->ds_us.rx.rs_status |= AR5K_RXERR_DECRYPT;
4043 * Proccess the rx status descriptor on 5212
4045 static int ath5k_hw_proc_new_rx_status(struct ath5k_hw *ah,
4046 struct ath5k_desc *desc)
4048 struct ath5k_hw_new_rx_status *rx_status;
4049 struct ath5k_hw_rx_error *rx_err;
4051 ATH5K_TRACE(ah->ah_sc);
4052 rx_status = (struct ath5k_hw_new_rx_status *)&desc->ds_hw[0];
4054 /* Overlay on error */
4055 rx_err = (struct ath5k_hw_rx_error *)&desc->ds_hw[0];
4057 /* No frame received / not ready */
4058 if (unlikely((rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_DONE)
4060 return -EINPROGRESS;
4063 * Frame receive status
4065 desc->ds_us.rx.rs_datalen = rx_status->rx_status_0 &
4066 AR5K_NEW_RX_DESC_STATUS0_DATA_LEN;
4067 desc->ds_us.rx.rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
4068 AR5K_NEW_RX_DESC_STATUS0_RECEIVE_SIGNAL);
4069 desc->ds_us.rx.rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
4070 AR5K_NEW_RX_DESC_STATUS0_RECEIVE_RATE);
4071 desc->ds_us.rx.rs_antenna = rx_status->rx_status_0 &
4072 AR5K_NEW_RX_DESC_STATUS0_RECEIVE_ANTENNA;
4073 desc->ds_us.rx.rs_more = rx_status->rx_status_0 &
4074 AR5K_NEW_RX_DESC_STATUS0_MORE;
4075 desc->ds_us.rx.rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
4076 AR5K_NEW_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
4077 desc->ds_us.rx.rs_status = 0;
4082 if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_KEY_INDEX_VALID)
4083 desc->ds_us.rx.rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
4084 AR5K_NEW_RX_DESC_STATUS1_KEY_INDEX);
4086 desc->ds_us.rx.rs_keyix = AR5K_RXKEYIX_INVALID;
4089 * Receive/descriptor errors
4091 if ((rx_status->rx_status_1 &
4092 AR5K_NEW_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
4093 if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_CRC_ERROR)
4094 desc->ds_us.rx.rs_status |= AR5K_RXERR_CRC;
4096 if (rx_status->rx_status_1 &
4097 AR5K_NEW_RX_DESC_STATUS1_PHY_ERROR) {
4098 desc->ds_us.rx.rs_status |= AR5K_RXERR_PHY;
4099 desc->ds_us.rx.rs_phyerr =
4100 AR5K_REG_MS(rx_err->rx_error_1,
4101 AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE);
4104 if (rx_status->rx_status_1 &
4105 AR5K_NEW_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
4106 desc->ds_us.rx.rs_status |= AR5K_RXERR_DECRYPT;
4108 if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_MIC_ERROR)
4109 desc->ds_us.rx.rs_status |= AR5K_RXERR_MIC;
4123 void ath5k_hw_set_ledstate(struct ath5k_hw *ah, unsigned int state)
4126 /*5210 has different led mode handling*/
4129 ATH5K_TRACE(ah->ah_sc);
4131 /*Reset led status*/
4132 if (ah->ah_version != AR5K_AR5210)
4133 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
4134 AR5K_PCICFG_LEDMODE | AR5K_PCICFG_LED);
4136 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_LED);
4139 * Some blinking values, define at your wish
4144 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_PEND;
4145 led_5210 = AR5K_PCICFG_LED_PEND | AR5K_PCICFG_LED_BCTL;
4149 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_NONE;
4150 led_5210 = AR5K_PCICFG_LED_PEND;
4153 case AR5K_LED_ASSOC:
4155 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_ASSOC;
4156 led_5210 = AR5K_PCICFG_LED_ASSOC;
4160 led = AR5K_PCICFG_LEDMODE_PROM | AR5K_PCICFG_LED_NONE;
4161 led_5210 = AR5K_PCICFG_LED_PEND;
4165 /*Write new status to the register*/
4166 if (ah->ah_version != AR5K_AR5210)
4167 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led);
4169 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led_5210);
4175 int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
4177 ATH5K_TRACE(ah->ah_sc);
4178 if (gpio > AR5K_NUM_GPIO)
4181 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4182 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR);
4190 int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
4192 ATH5K_TRACE(ah->ah_sc);
4193 if (gpio > AR5K_NUM_GPIO)
4196 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4197 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR);
4205 u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
4207 ATH5K_TRACE(ah->ah_sc);
4208 if (gpio > AR5K_NUM_GPIO)
4211 /* GPIO input magic */
4212 return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) &
4219 int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
4222 ATH5K_TRACE(ah->ah_sc);
4224 if (gpio > AR5K_NUM_GPIO)
4227 /* GPIO output magic */
4228 data = ath5k_hw_reg_read(ah, AR5K_GPIODO);
4230 data &= ~(1 << gpio);
4231 data |= (val & 1) << gpio;
4233 ath5k_hw_reg_write(ah, data, AR5K_GPIODO);
4239 * Initialize the GPIO interrupt (RFKill switch)
4241 void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
4242 u32 interrupt_level)
4246 ATH5K_TRACE(ah->ah_sc);
4247 if (gpio > AR5K_NUM_GPIO)
4251 * Set the GPIO interrupt
4253 data = (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &
4254 ~(AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_SELH |
4255 AR5K_GPIOCR_INT_ENA | AR5K_GPIOCR_OUT(gpio))) |
4256 (AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_ENA);
4258 ath5k_hw_reg_write(ah, interrupt_level ? data :
4259 (data | AR5K_GPIOCR_INT_SELH), AR5K_GPIOCR);
4261 ah->ah_imr |= AR5K_IMR_GPIO;
4263 /* Enable GPIO interrupts */
4264 AR5K_REG_ENABLE_BITS(ah, AR5K_PIMR, AR5K_IMR_GPIO);
4274 int ath5k_hw_get_capability(struct ath5k_hw *ah,
4275 enum ath5k_capability_type cap_type,
4276 u32 capability, u32 *result)
4278 ATH5K_TRACE(ah->ah_sc);
4281 case AR5K_CAP_NUM_TXQUEUES:
4283 if (ah->ah_version == AR5K_AR5210)
4284 *result = AR5K_NUM_TX_QUEUES_NOQCU;
4286 *result = AR5K_NUM_TX_QUEUES;
4291 case AR5K_CAP_COMPRESSION:
4292 if (ah->ah_version == AR5K_AR5212)
4296 case AR5K_CAP_BURST:
4300 case AR5K_CAP_BSSIDMASK:
4301 if (ah->ah_version == AR5K_AR5212)
4306 if (ah->ah_version == AR5K_AR5212)
4320 static int ath5k_hw_enable_pspoll(struct ath5k_hw *ah, u8 *bssid,
4323 ATH5K_TRACE(ah->ah_sc);
4325 if (ah->ah_version == AR5K_AR5210) {
4326 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
4327 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
4334 static int ath5k_hw_disable_pspoll(struct ath5k_hw *ah)
4336 ATH5K_TRACE(ah->ah_sc);
4338 if (ah->ah_version == AR5K_AR5210) {
4339 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
4340 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);