2 * Copyright (c) 2004-2007 Reyk Floeter <reyk@openbsd.org>
3 * Copyright (c) 2006-2007 Nick Kossifidis <mickflemm@gmail.com>
4 * Copyright (c) 2007 Matthew W. S. Bell <mentor@madwifi.org>
5 * Copyright (c) 2007 Luis Rodriguez <mcgrof@winlab.rutgers.edu>
6 * Copyright (c) 2007 Pavel Roskin <proski@gnu.org>
7 * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * HW related functions for Atheros Wireless LAN devices.
27 #include <linux/pci.h>
28 #include <linux/delay.h>
35 static const struct ath5k_rate_table ath5k_rt_11a = AR5K_RATES_11A;
36 static const struct ath5k_rate_table ath5k_rt_11b = AR5K_RATES_11B;
37 static const struct ath5k_rate_table ath5k_rt_11g = AR5K_RATES_11G;
38 static const struct ath5k_rate_table ath5k_rt_turbo = AR5K_RATES_TURBO;
39 static const struct ath5k_rate_table ath5k_rt_xr = AR5K_RATES_XR;
42 static int ath5k_hw_nic_reset(struct ath5k_hw *, u32);
43 static int ath5k_hw_nic_wakeup(struct ath5k_hw *, int, bool);
44 static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
45 unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
46 unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
47 unsigned int, unsigned int);
48 static int ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
49 unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
51 static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *, struct ath5k_desc *,
52 struct ath5k_tx_status *);
53 static int ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
54 unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
55 unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
56 unsigned int, unsigned int);
57 static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *, struct ath5k_desc *,
58 struct ath5k_tx_status *);
59 static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *, struct ath5k_desc *,
60 struct ath5k_rx_status *);
61 static int ath5k_hw_proc_5210_rx_status(struct ath5k_hw *, struct ath5k_desc *,
62 struct ath5k_rx_status *);
63 static int ath5k_hw_get_capabilities(struct ath5k_hw *);
65 static int ath5k_eeprom_init(struct ath5k_hw *);
66 static int ath5k_eeprom_read_mac(struct ath5k_hw *, u8 *);
68 static int ath5k_hw_enable_pspoll(struct ath5k_hw *, u8 *, u16);
69 static int ath5k_hw_disable_pspoll(struct ath5k_hw *);
72 * Enable to overwrite the country code (use "00" for debug)
75 #define COUNTRYCODE "00"
83 * Functions used internaly
86 static inline unsigned int ath5k_hw_htoclock(unsigned int usec, bool turbo)
88 return turbo ? (usec * 80) : (usec * 40);
91 static inline unsigned int ath5k_hw_clocktoh(unsigned int clock, bool turbo)
93 return turbo ? (clock / 80) : (clock / 40);
97 * Check if a register write has been completed
99 int ath5k_hw_register_timeout(struct ath5k_hw *ah, u32 reg, u32 flag, u32 val,
105 for (i = AR5K_TUNE_REGISTER_TIMEOUT; i > 0; i--) {
106 data = ath5k_hw_reg_read(ah, reg);
107 if (is_set && (data & flag))
109 else if ((data & flag) == val)
114 return (i <= 0) ? -EAGAIN : 0;
118 /***************************************\
119 Attach/Detach Functions
120 \***************************************/
123 * Power On Self Test helper function
125 static int ath5k_hw_post(struct ath5k_hw *ah)
130 u16 regs[2] = {AR5K_STA_ID0, AR5K_PHY(8)};
132 u32 static_pattern[4] = {
133 0x55555555, 0xaaaaaaaa,
134 0x66666666, 0x99999999
139 for (c = 0; c < 2; c++) {
143 /* Save previous value */
144 init_val = ath5k_hw_reg_read(ah, cur_reg);
146 for (i = 0; i < 256; i++) {
147 var_pattern = i << 16 | i;
148 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
149 cur_val = ath5k_hw_reg_read(ah, cur_reg);
151 if (cur_val != var_pattern) {
152 ATH5K_ERR(ah->ah_sc, "POST Failed !!!\n");
156 /* Found on ndiswrapper dumps */
157 var_pattern = 0x0039080f;
158 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
161 for (i = 0; i < 4; i++) {
162 var_pattern = static_pattern[i];
163 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
164 cur_val = ath5k_hw_reg_read(ah, cur_reg);
166 if (cur_val != var_pattern) {
167 ATH5K_ERR(ah->ah_sc, "POST Failed !!!\n");
171 /* Found on ndiswrapper dumps */
172 var_pattern = 0x003b080f;
173 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
176 /* Restore previous value */
177 ath5k_hw_reg_write(ah, init_val, cur_reg);
186 * Check if the device is supported and initialize the needed structs
188 struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
191 struct pci_dev *pdev = sc->pdev;
196 /*If we passed the test malloc a ath5k_hw struct*/
197 ah = kzalloc(sizeof(struct ath5k_hw), GFP_KERNEL);
200 ATH5K_ERR(sc, "out of memory\n");
205 ah->ah_iobase = sc->iobase;
211 ah->ah_op_mode = IEEE80211_IF_TYPE_STA;
212 ah->ah_radar.r_enabled = AR5K_TUNE_RADAR_ALERT;
213 ah->ah_turbo = false;
214 ah->ah_txpower.txp_tpc = AR5K_TUNE_TPC_TXPOWER;
216 ah->ah_atim_window = 0;
217 ah->ah_aifs = AR5K_TUNE_AIFS;
218 ah->ah_cw_min = AR5K_TUNE_CWMIN;
219 ah->ah_limit_tx_retries = AR5K_INIT_TX_RETRY;
220 ah->ah_software_retry = false;
221 ah->ah_ant_diversity = AR5K_TUNE_ANT_DIVERSITY;
224 * Set the mac revision based on the pci id
226 ah->ah_version = mac_version;
228 /*Fill the ath5k_hw struct with the needed functions*/
229 if (ah->ah_version == AR5K_AR5212)
230 ah->ah_magic = AR5K_EEPROM_MAGIC_5212;
231 else if (ah->ah_version == AR5K_AR5211)
232 ah->ah_magic = AR5K_EEPROM_MAGIC_5211;
234 if (ah->ah_version == AR5K_AR5212) {
235 ah->ah_setup_tx_desc = ath5k_hw_setup_4word_tx_desc;
236 ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
237 ah->ah_proc_tx_desc = ath5k_hw_proc_4word_tx_status;
239 ah->ah_setup_tx_desc = ath5k_hw_setup_2word_tx_desc;
240 ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
241 ah->ah_proc_tx_desc = ath5k_hw_proc_2word_tx_status;
244 if (ah->ah_version == AR5K_AR5212)
245 ah->ah_proc_rx_desc = ath5k_hw_proc_5212_rx_status;
246 else if (ah->ah_version <= AR5K_AR5211)
247 ah->ah_proc_rx_desc = ath5k_hw_proc_5210_rx_status;
249 /* Bring device out of sleep and reset it's units */
250 ret = ath5k_hw_nic_wakeup(ah, AR5K_INIT_MODE, true);
254 /* Get MAC, PHY and RADIO revisions */
255 srev = ath5k_hw_reg_read(ah, AR5K_SREV);
256 ah->ah_mac_srev = srev;
257 ah->ah_mac_version = AR5K_REG_MS(srev, AR5K_SREV_VER);
258 ah->ah_mac_revision = AR5K_REG_MS(srev, AR5K_SREV_REV);
259 ah->ah_phy_revision = ath5k_hw_reg_read(ah, AR5K_PHY_CHIP_ID) &
261 ah->ah_radio_5ghz_revision = ath5k_hw_radio_revision(ah,
264 if (ah->ah_version == AR5K_AR5210)
265 ah->ah_radio_2ghz_revision = 0;
267 ah->ah_radio_2ghz_revision = ath5k_hw_radio_revision(ah,
270 /* Return on unsuported chips (unsupported eeprom etc) */
271 if ((srev >= AR5K_SREV_VER_AR5416) &&
272 (srev < AR5K_SREV_VER_AR2425)) {
273 ATH5K_ERR(sc, "Device not yet supported.\n");
276 } else if (srev == AR5K_SREV_VER_AR2425) {
277 ATH5K_WARN(sc, "Support for RF2425 is under development.\n");
280 /* Identify single chip solutions */
281 if (((srev <= AR5K_SREV_VER_AR5414) &&
282 (srev >= AR5K_SREV_VER_AR2413)) ||
283 (srev == AR5K_SREV_VER_AR2425)) {
284 ah->ah_single_chip = true;
286 ah->ah_single_chip = false;
289 /* Single chip radio */
290 if (ah->ah_radio_2ghz_revision == ah->ah_radio_5ghz_revision)
291 ah->ah_radio_2ghz_revision = 0;
293 /* Identify the radio chip*/
294 if (ah->ah_version == AR5K_AR5210) {
295 ah->ah_radio = AR5K_RF5110;
297 * Register returns 0x0/0x04 for radio revision
298 * so ath5k_hw_radio_revision doesn't parse the value
299 * correctly. For now we are based on mac's srev to
300 * identify RF2425 radio.
302 } else if (srev == AR5K_SREV_VER_AR2425) {
303 ah->ah_radio = AR5K_RF2425;
304 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF2425;
305 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112) {
306 ah->ah_radio = AR5K_RF5111;
307 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5111;
308 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC0) {
309 ah->ah_radio = AR5K_RF5112;
310 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112;
311 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC1) {
312 ah->ah_radio = AR5K_RF2413;
313 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF2413;
314 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC2) {
315 ah->ah_radio = AR5K_RF5413;
316 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5413;
317 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5133) {
319 if (srev >= AR5K_SREV_VER_AR5424) {
320 ah->ah_radio = AR5K_RF5413;
321 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5413;
324 ah->ah_radio = AR5K_RF2413; /* For testing */
325 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF2413;
328 ah->ah_phy = AR5K_PHY(0);
331 * Write PCI-E power save settings
333 if ((ah->ah_version == AR5K_AR5212) && (pdev->is_pcie)) {
334 ath5k_hw_reg_write(ah, 0x9248fc00, 0x4080);
335 ath5k_hw_reg_write(ah, 0x24924924, 0x4080);
336 ath5k_hw_reg_write(ah, 0x28000039, 0x4080);
337 ath5k_hw_reg_write(ah, 0x53160824, 0x4080);
338 ath5k_hw_reg_write(ah, 0xe5980579, 0x4080);
339 ath5k_hw_reg_write(ah, 0x001defff, 0x4080);
340 ath5k_hw_reg_write(ah, 0x1aaabe40, 0x4080);
341 ath5k_hw_reg_write(ah, 0xbe105554, 0x4080);
342 ath5k_hw_reg_write(ah, 0x000e3007, 0x4080);
343 ath5k_hw_reg_write(ah, 0x00000000, 0x4084);
349 ret = ath5k_hw_post(ah);
353 /* Write AR5K_PCICFG_UNK on 2112B and later chips */
354 if (ah->ah_radio_5ghz_revision > AR5K_SREV_RAD_2112B ||
355 srev > AR5K_SREV_VER_AR2413) {
356 ath5k_hw_reg_write(ah, AR5K_PCICFG_UNK, AR5K_PCICFG);
360 * Get card capabilities, values, ...
362 ret = ath5k_eeprom_init(ah);
364 ATH5K_ERR(sc, "unable to init EEPROM\n");
368 /* Get misc capabilities */
369 ret = ath5k_hw_get_capabilities(ah);
371 ATH5K_ERR(sc, "unable to get device capabilities: 0x%04x\n",
376 /* Get MAC address */
377 ret = ath5k_eeprom_read_mac(ah, mac);
379 ATH5K_ERR(sc, "unable to read address from EEPROM: 0x%04x\n",
384 ath5k_hw_set_lladdr(ah, mac);
385 /* Set BSSID to bcast address: ff:ff:ff:ff:ff:ff for now */
386 memset(ah->ah_bssid, 0xff, ETH_ALEN);
387 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
388 ath5k_hw_set_opmode(ah);
390 ath5k_hw_set_rfgain_opt(ah);
400 * Bring up MAC + PHY Chips
402 static int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
404 struct pci_dev *pdev = ah->ah_sc->pdev;
405 u32 turbo, mode, clock, bus_flags;
412 ATH5K_TRACE(ah->ah_sc);
414 /* Wakeup the device */
415 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
417 ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
421 if (ah->ah_version != AR5K_AR5210) {
423 * Get channel mode flags
426 if (ah->ah_radio >= AR5K_RF5112) {
427 mode = AR5K_PHY_MODE_RAD_RF5112;
428 clock = AR5K_PHY_PLL_RF5112;
430 mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
431 clock = AR5K_PHY_PLL_RF5111; /*Zero*/
434 if (flags & CHANNEL_2GHZ) {
435 mode |= AR5K_PHY_MODE_FREQ_2GHZ;
436 clock |= AR5K_PHY_PLL_44MHZ;
438 if (flags & CHANNEL_CCK) {
439 mode |= AR5K_PHY_MODE_MOD_CCK;
440 } else if (flags & CHANNEL_OFDM) {
441 /* XXX Dynamic OFDM/CCK is not supported by the
442 * AR5211 so we set MOD_OFDM for plain g (no
443 * CCK headers) operation. We need to test
444 * this, 5211 might support ofdm-only g after
445 * all, there are also initial register values
446 * in the code for g mode (see initvals.c). */
447 if (ah->ah_version == AR5K_AR5211)
448 mode |= AR5K_PHY_MODE_MOD_OFDM;
450 mode |= AR5K_PHY_MODE_MOD_DYN;
453 "invalid radio modulation mode\n");
456 } else if (flags & CHANNEL_5GHZ) {
457 mode |= AR5K_PHY_MODE_FREQ_5GHZ;
458 clock |= AR5K_PHY_PLL_40MHZ;
460 if (flags & CHANNEL_OFDM)
461 mode |= AR5K_PHY_MODE_MOD_OFDM;
464 "invalid radio modulation mode\n");
468 ATH5K_ERR(ah->ah_sc, "invalid radio frequency mode\n");
472 if (flags & CHANNEL_TURBO)
473 turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
474 } else { /* Reset the device */
476 /* ...enable Atheros turbo mode if requested */
477 if (flags & CHANNEL_TURBO)
478 ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
482 /* reseting PCI on PCI-E cards results card to hang
483 * and always return 0xffff... so we ingore that flag
485 bus_flags = (pdev->is_pcie) ? 0 : AR5K_RESET_CTL_PCI;
488 ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
489 AR5K_RESET_CTL_BASEBAND | bus_flags);
491 ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip\n");
495 if (ah->ah_version == AR5K_AR5210)
498 /* ...wakeup again!*/
499 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
501 ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
505 /* ...final warm reset */
506 if (ath5k_hw_nic_reset(ah, 0)) {
507 ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
511 if (ah->ah_version != AR5K_AR5210) {
512 /* ...set the PHY operating mode */
513 ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
516 ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
517 ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
524 * Get the rate table for a specific operation mode
526 const struct ath5k_rate_table *ath5k_hw_get_rate_table(struct ath5k_hw *ah,
529 ATH5K_TRACE(ah->ah_sc);
531 if (!test_bit(mode, ah->ah_capabilities.cap_mode))
534 /* Get rate tables */
537 return &ath5k_rt_11a;
538 case AR5K_MODE_11A_TURBO:
539 return &ath5k_rt_turbo;
541 return &ath5k_rt_11b;
543 return &ath5k_rt_11g;
544 case AR5K_MODE_11G_TURBO:
552 * Free the ath5k_hw struct
554 void ath5k_hw_detach(struct ath5k_hw *ah)
556 ATH5K_TRACE(ah->ah_sc);
558 __set_bit(ATH_STAT_INVALID, ah->ah_sc->status);
560 if (ah->ah_rf_banks != NULL)
561 kfree(ah->ah_rf_banks);
563 /* assume interrupts are down */
567 /****************************\
568 Reset function and helpers
569 \****************************/
572 * ath5k_hw_write_ofdm_timings - set OFDM timings on AR5212
574 * @ah: the &struct ath5k_hw
575 * @channel: the currently set channel upon reset
577 * Write the OFDM timings for the AR5212 upon reset. This is a helper for
578 * ath5k_hw_reset(). This seems to tune the PLL a specified frequency
579 * depending on the bandwidth of the channel.
582 static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
583 struct ieee80211_channel *channel)
585 /* Get exponent and mantissa and set it */
586 u32 coef_scaled, coef_exp, coef_man,
587 ds_coef_exp, ds_coef_man, clock;
589 if (!(ah->ah_version == AR5K_AR5212) ||
590 !(channel->hw_value & CHANNEL_OFDM))
593 /* Seems there are two PLLs, one for baseband sampling and one
594 * for tuning. Tuning basebands are 40 MHz or 80MHz when in
596 clock = channel->hw_value & CHANNEL_TURBO ? 80 : 40;
597 coef_scaled = ((5 * (clock << 24)) / 2) /
598 channel->center_freq;
600 for (coef_exp = 31; coef_exp > 0; coef_exp--)
601 if ((coef_scaled >> coef_exp) & 0x1)
607 coef_exp = 14 - (coef_exp - 24);
608 coef_man = coef_scaled +
609 (1 << (24 - coef_exp - 1));
610 ds_coef_man = coef_man >> (24 - coef_exp);
611 ds_coef_exp = coef_exp - 16;
613 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
614 AR5K_PHY_TIMING_3_DSC_MAN, ds_coef_man);
615 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
616 AR5K_PHY_TIMING_3_DSC_EXP, ds_coef_exp);
622 * ath5k_hw_write_rate_duration - set rate duration during hw resets
624 * @ah: the &struct ath5k_hw
625 * @mode: one of enum ath5k_driver_mode
627 * Write the rate duration table for the current mode upon hw reset. This
628 * is a helper for ath5k_hw_reset(). It seems all this is doing is setting
629 * an ACK timeout for the hardware for the current mode for each rate. The
630 * rates which are capable of short preamble (802.11b rates 2Mbps, 5.5Mbps,
631 * and 11Mbps) have another register for the short preamble ACK timeout
635 static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
638 struct ath5k_softc *sc = ah->ah_sc;
639 const struct ath5k_rate_table *rt;
640 struct ieee80211_rate srate = {};
643 /* Get rate table for the current operating mode */
644 rt = ath5k_hw_get_rate_table(ah, mode);
646 /* Write rate duration table */
647 for (i = 0; i < rt->rate_count; i++) {
648 const struct ath5k_rate *rate, *control_rate;
653 rate = &rt->rates[i];
654 control_rate = &rt->rates[rate->control_rate];
656 /* Set ACK timeout */
657 reg = AR5K_RATE_DUR(rate->rate_code);
659 srate.bitrate = control_rate->rate_kbps/100;
661 /* An ACK frame consists of 10 bytes. If you add the FCS,
662 * which ieee80211_generic_frame_duration() adds,
663 * its 14 bytes. Note we use the control rate and not the
664 * actual rate for this rate. See mac80211 tx.c
665 * ieee80211_duration() for a brief description of
666 * what rate we should choose to TX ACKs. */
667 tx_time = le16_to_cpu(ieee80211_generic_frame_duration(sc->hw,
668 sc->vif, 10, &srate));
670 ath5k_hw_reg_write(ah, tx_time, reg);
672 if (!HAS_SHPREAMBLE(i))
676 * We're not distinguishing short preamble here,
677 * This is true, all we'll get is a longer value here
678 * which is not necessarilly bad. We could use
679 * export ieee80211_frame_duration() but that needs to be
680 * fixed first to be properly used by mac802111 drivers:
682 * - remove erp stuff and let the routine figure ofdm
684 * - remove passing argument ieee80211_local as
685 * drivers don't have access to it
686 * - move drivers using ieee80211_generic_frame_duration()
689 ath5k_hw_reg_write(ah, tx_time,
690 reg + (AR5K_SET_SHORT_PREAMBLE << 2));
695 * Main reset function
697 int ath5k_hw_reset(struct ath5k_hw *ah, enum ieee80211_if_types op_mode,
698 struct ieee80211_channel *channel, bool change_channel)
700 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
701 struct pci_dev *pdev = ah->ah_sc->pdev;
702 u32 data, s_seq, s_ant, s_led[3], dma_size;
703 unsigned int i, mode, freq, ee_mode, ant[2];
706 ATH5K_TRACE(ah->ah_sc);
715 * Save some registers before a reset
717 /*DCU/Antenna selection not available on 5210*/
718 if (ah->ah_version != AR5K_AR5210) {
719 if (change_channel) {
720 /* Seq number for queue 0 -do this for all queues ? */
721 s_seq = ath5k_hw_reg_read(ah,
722 AR5K_QUEUE_DFS_SEQNUM(0));
724 s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
729 s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) & AR5K_PCICFG_LEDSTATE;
730 s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
731 s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
733 if (change_channel && ah->ah_rf_banks != NULL)
734 ath5k_hw_get_rf_gain(ah);
737 /*Wakeup the device*/
738 ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, false);
743 * Initialize operating mode
745 ah->ah_op_mode = op_mode;
749 * 5210 only comes with RF5110
751 if (ah->ah_version != AR5K_AR5210) {
752 if (ah->ah_radio != AR5K_RF5111 &&
753 ah->ah_radio != AR5K_RF5112 &&
754 ah->ah_radio != AR5K_RF5413 &&
755 ah->ah_radio != AR5K_RF2413 &&
756 ah->ah_radio != AR5K_RF2425) {
758 "invalid phy radio: %u\n", ah->ah_radio);
762 switch (channel->hw_value & CHANNEL_MODES) {
764 mode = AR5K_MODE_11A;
765 freq = AR5K_INI_RFGAIN_5GHZ;
766 ee_mode = AR5K_EEPROM_MODE_11A;
769 mode = AR5K_MODE_11G;
770 freq = AR5K_INI_RFGAIN_2GHZ;
771 ee_mode = AR5K_EEPROM_MODE_11G;
774 mode = AR5K_MODE_11B;
775 freq = AR5K_INI_RFGAIN_2GHZ;
776 ee_mode = AR5K_EEPROM_MODE_11B;
779 mode = AR5K_MODE_11A_TURBO;
780 freq = AR5K_INI_RFGAIN_5GHZ;
781 ee_mode = AR5K_EEPROM_MODE_11A;
783 /*Is this ok on 5211 too ?*/
785 mode = AR5K_MODE_11G_TURBO;
786 freq = AR5K_INI_RFGAIN_2GHZ;
787 ee_mode = AR5K_EEPROM_MODE_11G;
790 if (ah->ah_version == AR5K_AR5211) {
792 "XR mode not available on 5211");
796 freq = AR5K_INI_RFGAIN_5GHZ;
797 ee_mode = AR5K_EEPROM_MODE_11A;
801 "invalid channel: %d\n", channel->center_freq);
805 /* PHY access enable */
806 ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
810 ret = ath5k_hw_write_initvals(ah, mode, change_channel);
817 if (ah->ah_version != AR5K_AR5210) {
819 * Write initial RF gain settings
820 * This should work for both 5111/5112
822 ret = ath5k_hw_rfgain(ah, freq);
829 * Write some more initial register settings
831 if (ah->ah_version == AR5K_AR5212) {
832 ath5k_hw_reg_write(ah, 0x0002a002, 0x982c);
834 if (channel->hw_value == CHANNEL_G)
835 if (ah->ah_mac_srev < AR5K_SREV_VER_AR2413)
836 ath5k_hw_reg_write(ah, 0x00f80d80,
838 else if (ah->ah_mac_srev < AR5K_SREV_VER_AR2424)
839 ath5k_hw_reg_write(ah, 0x00380140,
841 else if (ah->ah_mac_srev < AR5K_SREV_VER_AR2425)
842 ath5k_hw_reg_write(ah, 0x00fc0ec0,
845 ath5k_hw_reg_write(ah, 0x00fc0fc0,
848 ath5k_hw_reg_write(ah, 0x00000000, 0x994c);
850 /* Some bits are disabled here, we know nothing about
851 * register 0xa228 yet, most of the times this ends up
852 * with a value 0x9b5 -haven't seen any dump with
853 * a different value- */
854 /* Got this from decompiling binary HAL */
855 data = ath5k_hw_reg_read(ah, 0xa228);
857 ath5k_hw_reg_write(ah, data, 0xa228);
859 data = ath5k_hw_reg_read(ah, 0xa228);
861 ath5k_hw_reg_write(ah, data, 0xa228);
864 /* Just write 0x9b5 ? */
865 /* ath5k_hw_reg_write(ah, 0x000009b5, 0xa228); */
866 ath5k_hw_reg_write(ah, 0x0000000f, AR5K_SEQ_MASK);
867 ath5k_hw_reg_write(ah, 0x00000000, 0xa254);
868 ath5k_hw_reg_write(ah, 0x0000000e, AR5K_PHY_SCAL);
871 /* Fix for first revision of the RF5112 RF chipset */
872 if (ah->ah_radio >= AR5K_RF5112 &&
873 ah->ah_radio_5ghz_revision <
874 AR5K_SREV_RAD_5112A) {
875 ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
877 if (channel->hw_value & CHANNEL_5GHZ)
881 ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
886 * Set TX power (FIXME)
888 ret = ath5k_hw_txpower(ah, channel, AR5K_TUNE_DEFAULT_TXPOWER);
892 /* Write rate duration table only on AR5212 and if
893 * virtual interface has already been brought up
894 * XXX: rethink this after new mode changes to
895 * mac80211 are integrated */
896 if (ah->ah_version == AR5K_AR5212 &&
897 ah->ah_sc->vif != NULL)
898 ath5k_hw_write_rate_duration(ah, mode);
903 ret = ath5k_hw_rfregs(ah, channel, mode);
908 * Configure additional registers
911 /* Write OFDM timings on 5212*/
912 if (ah->ah_version == AR5K_AR5212 &&
913 channel->hw_value & CHANNEL_OFDM) {
914 ret = ath5k_hw_write_ofdm_timings(ah, channel);
919 /*Enable/disable 802.11b mode on 5111
920 (enable 2111 frequency converter + CCK)*/
921 if (ah->ah_radio == AR5K_RF5111) {
922 if (mode == AR5K_MODE_11B)
923 AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
926 AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
931 * Set channel and calibrate the PHY
933 ret = ath5k_hw_channel(ah, channel);
937 /* Set antenna mode */
938 AR5K_REG_MASKED_BITS(ah, AR5K_PHY_ANT_CTL,
939 ah->ah_antenna[ee_mode][0], 0xfffffc06);
942 * In case a fixed antenna was set as default
943 * write the same settings on both AR5K_PHY_ANT_SWITCH_TABLE
947 if (s_ant == AR5K_ANT_FIXED_A) /* 1 - Main */
948 ant[0] = ant[1] = AR5K_ANT_FIXED_A;
950 ant[0] = ant[1] = AR5K_ANT_FIXED_B;
952 ant[0] = AR5K_ANT_FIXED_A;
953 ant[1] = AR5K_ANT_FIXED_B;
956 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[0]],
957 AR5K_PHY_ANT_SWITCH_TABLE_0);
958 ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[1]],
959 AR5K_PHY_ANT_SWITCH_TABLE_1);
961 /* Commit values from EEPROM */
962 if (ah->ah_radio == AR5K_RF5111)
963 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_FRAME_CTL,
964 AR5K_PHY_FRAME_CTL_TX_CLIP, ee->ee_tx_clip);
966 ath5k_hw_reg_write(ah,
967 AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
970 AR5K_REG_MASKED_BITS(ah, AR5K_PHY_SETTLING,
971 (ee->ee_switch_settling[ee_mode] << 7) & 0x3f80,
973 AR5K_REG_MASKED_BITS(ah, AR5K_PHY_GAIN,
974 (ee->ee_ant_tx_rx[ee_mode] << 12) & 0x3f000,
976 AR5K_REG_MASKED_BITS(ah, AR5K_PHY_DESIRED_SIZE,
977 (ee->ee_adc_desired_size[ee_mode] & 0x00ff) |
978 ((ee->ee_pga_desired_size[ee_mode] << 8) & 0xff00),
981 ath5k_hw_reg_write(ah,
982 (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
983 (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
984 (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
985 (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY_RF_CTL4);
987 AR5K_REG_MASKED_BITS(ah, AR5K_PHY_RF_CTL3,
988 ee->ee_tx_end2xlna_enable[ee_mode] << 8, 0xffff00ff);
989 AR5K_REG_MASKED_BITS(ah, AR5K_PHY_NF,
990 (ee->ee_thr_62[ee_mode] << 12) & 0x7f000, 0xfff80fff);
991 AR5K_REG_MASKED_BITS(ah, AR5K_PHY_OFDM_SELFCORR, 4, 0xffffff01);
993 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
994 AR5K_PHY_IQ_CORR_ENABLE |
995 (ee->ee_i_cal[ee_mode] << AR5K_PHY_IQ_CORR_Q_I_COFF_S) |
996 ee->ee_q_cal[ee_mode]);
998 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
999 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
1000 AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
1001 ee->ee_margin_tx_rx[ee_mode]);
1005 /* Disable phy and wait */
1006 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
1011 * Restore saved values
1013 /*DCU/Antenna selection not available on 5210*/
1014 if (ah->ah_version != AR5K_AR5210) {
1015 ath5k_hw_reg_write(ah, s_seq, AR5K_QUEUE_DFS_SEQNUM(0));
1016 ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
1018 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
1019 ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
1020 ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
1025 /* XXX: add ah->aid once mac80211 gives this to us */
1026 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
1028 ath5k_hw_set_opmode(ah);
1029 /*PISR/SISR Not available on 5210*/
1030 if (ah->ah_version != AR5K_AR5210) {
1031 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
1032 /* If we later allow tuning for this, store into sc structure */
1033 data = AR5K_TUNE_RSSI_THRES |
1034 AR5K_TUNE_BMISS_THRES << AR5K_RSSI_THR_BMISS_S;
1035 ath5k_hw_reg_write(ah, data, AR5K_RSSI_THR);
1039 * Set Rx/Tx DMA Configuration
1041 * Set maximum DMA size (512) except for PCI-E cards since
1042 * it causes rx overruns and tx errors (tested on 5424 but since
1043 * rx overruns also occur on 5416/5418 with madwifi we set 128
1044 * for all PCI-E cards to be safe).
1046 * In dumps this is 128 for allchips.
1048 * XXX: need to check 5210 for this
1049 * TODO: Check out tx triger level, it's always 64 on dumps but I
1050 * guess we can tweak it and see how it goes ;-)
1052 dma_size = (pdev->is_pcie) ? AR5K_DMASIZE_128B : AR5K_DMASIZE_512B;
1053 if (ah->ah_version != AR5K_AR5210) {
1054 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
1055 AR5K_TXCFG_SDMAMR, dma_size);
1056 AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG,
1057 AR5K_RXCFG_SDMAMW, dma_size);
1061 * Enable the PHY and wait until completion
1063 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
1066 * On 5211+ read activation -> rx delay
1069 if (ah->ah_version != AR5K_AR5210) {
1070 data = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
1071 AR5K_PHY_RX_DELAY_M;
1072 data = (channel->hw_value & CHANNEL_CCK) ?
1073 ((data << 2) / 22) : (data / 10);
1075 udelay(100 + (2 * data));
1082 * Perform ADC test (?)
1084 data = ath5k_hw_reg_read(ah, AR5K_PHY_TST1);
1085 ath5k_hw_reg_write(ah, AR5K_PHY_TST1_TXHOLD, AR5K_PHY_TST1);
1086 for (i = 0; i <= 20; i++) {
1087 if (!(ath5k_hw_reg_read(ah, AR5K_PHY_ADC_TEST) & 0x10))
1091 ath5k_hw_reg_write(ah, data, AR5K_PHY_TST1);
1095 * Start automatic gain calibration
1097 * During AGC calibration RX path is re-routed to
1098 * a signal detector so we don't receive anything.
1100 * This method is used to calibrate some static offsets
1101 * used together with on-the fly I/Q calibration (the
1102 * one performed via ath5k_hw_phy_calibrate), that doesn't
1103 * interrupt rx path.
1105 * If we are in a noisy environment AGC calibration may time
1108 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
1109 AR5K_PHY_AGCCTL_CAL);
1111 /* At the same time start I/Q calibration for QAM constellation
1112 * -no need for CCK- */
1113 ah->ah_calibration = false;
1114 if (!(mode == AR5K_MODE_11B)) {
1115 ah->ah_calibration = true;
1116 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
1117 AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
1118 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
1122 /* Wait for gain calibration to finish (we check for I/Q calibration
1123 * during ath5k_phy_calibrate) */
1124 if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
1125 AR5K_PHY_AGCCTL_CAL, 0, false)) {
1126 ATH5K_ERR(ah->ah_sc, "gain calibration timeout (%uMHz)\n",
1127 channel->center_freq);
1132 * Start noise floor calibration
1134 * If we run NF calibration before AGC, it always times out.
1135 * Binary HAL starts NF and AGC calibration at the same time
1136 * and only waits for AGC to finish. I believe that's wrong because
1137 * during NF calibration, rx path is also routed to a detector, so if
1138 * it doesn't finish we won't have RX.
1140 * XXX: Find an interval that's OK for all cards...
1142 ret = ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
1147 * Reset queues and start beacon timers at the end of the reset routine
1149 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
1151 if (ah->ah_version != AR5K_AR5210)
1152 AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(i), i);
1154 ret = ath5k_hw_reset_tx_queue(ah, i);
1156 ATH5K_ERR(ah->ah_sc,
1157 "failed to reset TX queue #%d\n", i);
1162 /* Pre-enable interrupts on 5211/5212*/
1163 if (ah->ah_version != AR5K_AR5210)
1164 ath5k_hw_set_intr(ah, AR5K_INT_RX | AR5K_INT_TX |
1168 * Set RF kill flags if supported by the device (read from the EEPROM)
1169 * Disable gpio_intr for now since it results system hang.
1170 * TODO: Handle this in ath5k_intr
1173 if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header)) {
1174 ath5k_hw_set_gpio_input(ah, 0);
1175 ah->ah_gpio[0] = ath5k_hw_get_gpio(ah, 0);
1176 if (ah->ah_gpio[0] == 0)
1177 ath5k_hw_set_gpio_intr(ah, 0, 1);
1179 ath5k_hw_set_gpio_intr(ah, 0, 0);
1184 * Set the 32MHz reference clock on 5212 phy clock sleep register
1186 * TODO: Find out how to switch to external 32Khz clock to save power
1188 if (ah->ah_version == AR5K_AR5212) {
1189 ath5k_hw_reg_write(ah, AR5K_PHY_SCR_32MHZ, AR5K_PHY_SCR);
1190 ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
1191 ath5k_hw_reg_write(ah, AR5K_PHY_SCAL_32MHZ, AR5K_PHY_SCAL);
1192 ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
1193 ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
1194 ath5k_hw_reg_write(ah, ah->ah_phy_spending, AR5K_PHY_SPENDING);
1196 data = ath5k_hw_reg_read(ah, AR5K_USEC_5211) & 0xffffc07f ;
1197 data |= (ah->ah_phy_spending == AR5K_PHY_SPENDING_18) ?
1198 0x00000f80 : 0x00001380 ;
1199 ath5k_hw_reg_write(ah, data, AR5K_USEC_5211);
1203 if (ah->ah_version == AR5K_AR5212) {
1204 ath5k_hw_reg_write(ah, 0x000100aa, 0x8118);
1205 ath5k_hw_reg_write(ah, 0x00003210, 0x811c);
1206 ath5k_hw_reg_write(ah, 0x00000052, 0x8108);
1207 if (ah->ah_mac_srev >= AR5K_SREV_VER_AR2413)
1208 ath5k_hw_reg_write(ah, 0x00000004, 0x8120);
1212 * Disable beacons and reset the register
1214 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
1215 AR5K_BEACON_RESET_TSF);
1223 static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
1226 u32 mask = val ? val : ~0U;
1228 ATH5K_TRACE(ah->ah_sc);
1230 /* Read-and-clear RX Descriptor Pointer*/
1231 ath5k_hw_reg_read(ah, AR5K_RXDP);
1234 * Reset the device and wait until success
1236 ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
1238 /* Wait at least 128 PCI clocks */
1241 if (ah->ah_version == AR5K_AR5210) {
1242 val &= AR5K_RESET_CTL_CHIP;
1243 mask &= AR5K_RESET_CTL_CHIP;
1245 val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1246 mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1249 ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, false);
1252 * Reset configuration register (for hw byte-swap). Note that this
1253 * is only set for big endian. We do the necessary magic in
1256 if ((val & AR5K_RESET_CTL_PCU) == 0)
1257 ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
1263 * Power management functions
1269 int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
1270 bool set_chip, u16 sleep_duration)
1275 ATH5K_TRACE(ah->ah_sc);
1276 staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
1280 staid &= ~AR5K_STA_ID1_DEFAULT_ANTENNA;
1282 case AR5K_PM_NETWORK_SLEEP:
1284 ath5k_hw_reg_write(ah,
1285 AR5K_SLEEP_CTL_SLE_ALLOW |
1289 staid |= AR5K_STA_ID1_PWR_SV;
1292 case AR5K_PM_FULL_SLEEP:
1294 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_SLP,
1297 staid |= AR5K_STA_ID1_PWR_SV;
1302 staid &= ~AR5K_STA_ID1_PWR_SV;
1307 /* Preserve sleep duration */
1308 data = ath5k_hw_reg_read(ah, AR5K_SLEEP_CTL);
1309 if( data & 0xffc00000 ){
1312 data = data & 0xfffcffff;
1315 ath5k_hw_reg_write(ah, data, AR5K_SLEEP_CTL);
1318 for (i = 50; i > 0; i--) {
1319 /* Check if the chip did wake up */
1320 if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
1321 AR5K_PCICFG_SPWR_DN) == 0)
1324 /* Wait a bit and retry */
1326 ath5k_hw_reg_write(ah, data, AR5K_SLEEP_CTL);
1329 /* Fail if the chip didn't wake up */
1340 ah->ah_power_mode = mode;
1341 ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
1346 /***********************\
1347 DMA Related Functions
1348 \***********************/
1357 void ath5k_hw_start_rx(struct ath5k_hw *ah)
1359 ATH5K_TRACE(ah->ah_sc);
1360 ath5k_hw_reg_write(ah, AR5K_CR_RXE, AR5K_CR);
1361 ath5k_hw_reg_read(ah, AR5K_CR);
1367 int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
1371 ATH5K_TRACE(ah->ah_sc);
1372 ath5k_hw_reg_write(ah, AR5K_CR_RXD, AR5K_CR);
1375 * It may take some time to disable the DMA receive unit
1377 for (i = 2000; i > 0 &&
1378 (ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_CR_RXE) != 0;
1382 return i ? 0 : -EBUSY;
1386 * Get the address of the RX Descriptor
1388 u32 ath5k_hw_get_rx_buf(struct ath5k_hw *ah)
1390 return ath5k_hw_reg_read(ah, AR5K_RXDP);
1394 * Set the address of the RX Descriptor
1396 void ath5k_hw_put_rx_buf(struct ath5k_hw *ah, u32 phys_addr)
1398 ATH5K_TRACE(ah->ah_sc);
1400 /*TODO:Shouldn't we check if RX is enabled first ?*/
1401 ath5k_hw_reg_write(ah, phys_addr, AR5K_RXDP);
1405 * Transmit functions
1409 * Start DMA transmit for a specific queue
1410 * (see also QCU/DCU functions)
1412 int ath5k_hw_tx_start(struct ath5k_hw *ah, unsigned int queue)
1416 ATH5K_TRACE(ah->ah_sc);
1417 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1419 /* Return if queue is declared inactive */
1420 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1423 if (ah->ah_version == AR5K_AR5210) {
1424 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1427 * Set the queue by type on 5210
1429 switch (ah->ah_txq[queue].tqi_type) {
1430 case AR5K_TX_QUEUE_DATA:
1431 tx_queue |= AR5K_CR_TXE0 & ~AR5K_CR_TXD0;
1433 case AR5K_TX_QUEUE_BEACON:
1434 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1435 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
1438 case AR5K_TX_QUEUE_CAB:
1439 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1440 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1FV | AR5K_BCR_TQ1V |
1441 AR5K_BCR_BDMAE, AR5K_BSR);
1447 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1448 ath5k_hw_reg_read(ah, AR5K_CR);
1450 /* Return if queue is disabled */
1451 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXD, queue))
1455 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXE, queue);
1462 * Stop DMA transmit for a specific queue
1463 * (see also QCU/DCU functions)
1465 int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue)
1467 unsigned int i = 100;
1468 u32 tx_queue, pending;
1470 ATH5K_TRACE(ah->ah_sc);
1471 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1473 /* Return if queue is declared inactive */
1474 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1477 if (ah->ah_version == AR5K_AR5210) {
1478 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1483 switch (ah->ah_txq[queue].tqi_type) {
1484 case AR5K_TX_QUEUE_DATA:
1485 tx_queue |= AR5K_CR_TXD0 & ~AR5K_CR_TXE0;
1487 case AR5K_TX_QUEUE_BEACON:
1488 case AR5K_TX_QUEUE_CAB:
1490 tx_queue |= AR5K_CR_TXD1 & ~AR5K_CR_TXD1;
1491 ath5k_hw_reg_write(ah, 0, AR5K_BSR);
1498 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1499 ath5k_hw_reg_read(ah, AR5K_CR);
1502 * Schedule TX disable and wait until queue is empty
1504 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXD, queue);
1506 /*Check for pending frames*/
1508 pending = ath5k_hw_reg_read(ah,
1509 AR5K_QUEUE_STATUS(queue)) &
1510 AR5K_QCU_STS_FRMPENDCNT;
1512 } while (--i && pending);
1514 /* Clear register */
1515 ath5k_hw_reg_write(ah, 0, AR5K_QCU_TXD);
1520 /* TODO: Check for success else return error */
1525 * Get the address of the TX Descriptor for a specific queue
1526 * (see also QCU/DCU functions)
1528 u32 ath5k_hw_get_tx_buf(struct ath5k_hw *ah, unsigned int queue)
1532 ATH5K_TRACE(ah->ah_sc);
1533 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1536 * Get the transmit queue descriptor pointer from the selected queue
1538 /*5210 doesn't have QCU*/
1539 if (ah->ah_version == AR5K_AR5210) {
1540 switch (ah->ah_txq[queue].tqi_type) {
1541 case AR5K_TX_QUEUE_DATA:
1542 tx_reg = AR5K_NOQCU_TXDP0;
1544 case AR5K_TX_QUEUE_BEACON:
1545 case AR5K_TX_QUEUE_CAB:
1546 tx_reg = AR5K_NOQCU_TXDP1;
1552 tx_reg = AR5K_QUEUE_TXDP(queue);
1555 return ath5k_hw_reg_read(ah, tx_reg);
1559 * Set the address of the TX Descriptor for a specific queue
1560 * (see also QCU/DCU functions)
1562 int ath5k_hw_put_tx_buf(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
1566 ATH5K_TRACE(ah->ah_sc);
1567 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1570 * Set the transmit queue descriptor pointer register by type
1573 if (ah->ah_version == AR5K_AR5210) {
1574 switch (ah->ah_txq[queue].tqi_type) {
1575 case AR5K_TX_QUEUE_DATA:
1576 tx_reg = AR5K_NOQCU_TXDP0;
1578 case AR5K_TX_QUEUE_BEACON:
1579 case AR5K_TX_QUEUE_CAB:
1580 tx_reg = AR5K_NOQCU_TXDP1;
1587 * Set the transmit queue descriptor pointer for
1588 * the selected queue on QCU for 5211+
1589 * (this won't work if the queue is still active)
1591 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
1594 tx_reg = AR5K_QUEUE_TXDP(queue);
1597 /* Set descriptor pointer */
1598 ath5k_hw_reg_write(ah, phys_addr, tx_reg);
1604 * Update tx trigger level
1606 int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase)
1608 u32 trigger_level, imr;
1611 ATH5K_TRACE(ah->ah_sc);
1614 * Disable interrupts by setting the mask
1616 imr = ath5k_hw_set_intr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
1618 /*TODO: Boundary check on trigger_level*/
1619 trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
1623 if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
1627 ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
1630 * Update trigger level on success
1632 if (ah->ah_version == AR5K_AR5210)
1633 ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
1635 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
1636 AR5K_TXCFG_TXFULL, trigger_level);
1642 * Restore interrupt mask
1644 ath5k_hw_set_intr(ah, imr);
1650 * Interrupt handling
1654 * Check if we have pending interrupts
1656 bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
1658 ATH5K_TRACE(ah->ah_sc);
1659 return ath5k_hw_reg_read(ah, AR5K_INTPEND);
1663 * Get interrupt mask (ISR)
1665 int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
1669 ATH5K_TRACE(ah->ah_sc);
1672 * Read interrupt status from the Interrupt Status register
1675 if (ah->ah_version == AR5K_AR5210) {
1676 data = ath5k_hw_reg_read(ah, AR5K_ISR);
1677 if (unlikely(data == AR5K_INT_NOCARD)) {
1678 *interrupt_mask = data;
1683 * Read interrupt status from the Read-And-Clear shadow register
1684 * Note: PISR/SISR Not available on 5210
1686 data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
1690 * Get abstract interrupt mask (driver-compatible)
1692 *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
1694 if (unlikely(data == AR5K_INT_NOCARD))
1697 if (data & (AR5K_ISR_RXOK | AR5K_ISR_RXERR))
1698 *interrupt_mask |= AR5K_INT_RX;
1700 if (data & (AR5K_ISR_TXOK | AR5K_ISR_TXERR
1701 | AR5K_ISR_TXDESC | AR5K_ISR_TXEOL))
1702 *interrupt_mask |= AR5K_INT_TX;
1704 if (ah->ah_version != AR5K_AR5210) {
1705 /*HIU = Host Interface Unit (PCI etc)*/
1706 if (unlikely(data & (AR5K_ISR_HIUERR)))
1707 *interrupt_mask |= AR5K_INT_FATAL;
1709 /*Beacon Not Ready*/
1710 if (unlikely(data & (AR5K_ISR_BNR)))
1711 *interrupt_mask |= AR5K_INT_BNR;
1715 * XXX: BMISS interrupts may occur after association.
1716 * I found this on 5210 code but it needs testing. If this is
1717 * true we should disable them before assoc and re-enable them
1718 * after a successfull assoc + some jiffies.
1721 interrupt_mask &= ~AR5K_INT_BMISS;
1725 * In case we didn't handle anything,
1726 * print the register value.
1728 if (unlikely(*interrupt_mask == 0 && net_ratelimit()))
1729 ATH5K_PRINTF("0x%08x\n", data);
1735 * Set interrupt mask
1737 enum ath5k_int ath5k_hw_set_intr(struct ath5k_hw *ah, enum ath5k_int new_mask)
1739 enum ath5k_int old_mask, int_mask;
1742 * Disable card interrupts to prevent any race conditions
1743 * (they will be re-enabled afterwards).
1745 ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
1746 ath5k_hw_reg_read(ah, AR5K_IER);
1748 old_mask = ah->ah_imr;
1751 * Add additional, chipset-dependent interrupt mask flags
1752 * and write them to the IMR (interrupt mask register).
1754 int_mask = new_mask & AR5K_INT_COMMON;
1756 if (new_mask & AR5K_INT_RX)
1757 int_mask |= AR5K_IMR_RXOK | AR5K_IMR_RXERR | AR5K_IMR_RXORN |
1760 if (new_mask & AR5K_INT_TX)
1761 int_mask |= AR5K_IMR_TXOK | AR5K_IMR_TXERR | AR5K_IMR_TXDESC |
1764 if (ah->ah_version != AR5K_AR5210) {
1765 if (new_mask & AR5K_INT_FATAL) {
1766 int_mask |= AR5K_IMR_HIUERR;
1767 AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_MCABT |
1768 AR5K_SIMR2_SSERR | AR5K_SIMR2_DPERR);
1772 ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
1774 /* Store new interrupt mask */
1775 ah->ah_imr = new_mask;
1777 /* ..re-enable interrupts */
1778 ath5k_hw_reg_write(ah, AR5K_IER_ENABLE, AR5K_IER);
1779 ath5k_hw_reg_read(ah, AR5K_IER);
1785 /*************************\
1786 EEPROM access functions
1787 \*************************/
1792 static int ath5k_hw_eeprom_read(struct ath5k_hw *ah, u32 offset, u16 *data)
1794 u32 status, timeout;
1796 ATH5K_TRACE(ah->ah_sc);
1798 * Initialize EEPROM access
1800 if (ah->ah_version == AR5K_AR5210) {
1801 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1802 (void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset));
1804 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1805 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1806 AR5K_EEPROM_CMD_READ);
1809 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1810 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1811 if (status & AR5K_EEPROM_STAT_RDDONE) {
1812 if (status & AR5K_EEPROM_STAT_RDERR)
1814 *data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) &
1825 * Write to eeprom - currently disabled, use at your own risk
1828 static int ath5k_hw_eeprom_write(struct ath5k_hw *ah, u32 offset, u16 data)
1831 u32 status, timeout;
1833 ATH5K_TRACE(ah->ah_sc);
1836 * Initialize eeprom access
1839 if (ah->ah_version == AR5K_AR5210) {
1840 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1842 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1843 AR5K_EEPROM_CMD_RESET);
1847 * Write data to data register
1850 if (ah->ah_version == AR5K_AR5210) {
1851 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_BASE + (4 * offset));
1853 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1854 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_DATA);
1855 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1856 AR5K_EEPROM_CMD_WRITE);
1863 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1864 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1865 if (status & AR5K_EEPROM_STAT_WRDONE) {
1866 if (status & AR5K_EEPROM_STAT_WRERR)
1873 ATH5K_ERR(ah->ah_sc, "EEPROM Write is disabled!");
1879 * Translate binary channel representation in EEPROM to frequency
1881 static u16 ath5k_eeprom_bin2freq(struct ath5k_hw *ah, u16 bin, unsigned int mode)
1885 if (bin == AR5K_EEPROM_CHANNEL_DIS)
1888 if (mode == AR5K_EEPROM_MODE_11A) {
1889 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1890 val = (5 * bin) + 4800;
1892 val = bin > 62 ? (10 * 62) + (5 * (bin - 62)) + 5100 :
1895 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1905 * Read antenna infos from eeprom
1907 static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
1910 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1915 AR5K_EEPROM_READ(o++, val);
1916 ee->ee_switch_settling[mode] = (val >> 8) & 0x7f;
1917 ee->ee_ant_tx_rx[mode] = (val >> 2) & 0x3f;
1918 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1920 AR5K_EEPROM_READ(o++, val);
1921 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1922 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1923 ee->ee_ant_control[mode][i++] = val & 0x3f;
1925 AR5K_EEPROM_READ(o++, val);
1926 ee->ee_ant_control[mode][i++] = (val >> 10) & 0x3f;
1927 ee->ee_ant_control[mode][i++] = (val >> 4) & 0x3f;
1928 ee->ee_ant_control[mode][i] = (val << 2) & 0x3f;
1930 AR5K_EEPROM_READ(o++, val);
1931 ee->ee_ant_control[mode][i++] |= (val >> 14) & 0x3;
1932 ee->ee_ant_control[mode][i++] = (val >> 8) & 0x3f;
1933 ee->ee_ant_control[mode][i++] = (val >> 2) & 0x3f;
1934 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1936 AR5K_EEPROM_READ(o++, val);
1937 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1938 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1939 ee->ee_ant_control[mode][i++] = val & 0x3f;
1941 /* Get antenna modes */
1942 ah->ah_antenna[mode][0] =
1943 (ee->ee_ant_control[mode][0] << 4) | 0x1;
1944 ah->ah_antenna[mode][AR5K_ANT_FIXED_A] =
1945 ee->ee_ant_control[mode][1] |
1946 (ee->ee_ant_control[mode][2] << 6) |
1947 (ee->ee_ant_control[mode][3] << 12) |
1948 (ee->ee_ant_control[mode][4] << 18) |
1949 (ee->ee_ant_control[mode][5] << 24);
1950 ah->ah_antenna[mode][AR5K_ANT_FIXED_B] =
1951 ee->ee_ant_control[mode][6] |
1952 (ee->ee_ant_control[mode][7] << 6) |
1953 (ee->ee_ant_control[mode][8] << 12) |
1954 (ee->ee_ant_control[mode][9] << 18) |
1955 (ee->ee_ant_control[mode][10] << 24);
1957 /* return new offset */
1964 * Read supported modes from eeprom
1966 static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset,
1969 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1974 AR5K_EEPROM_READ(o++, val);
1975 ee->ee_tx_end2xlna_enable[mode] = (val >> 8) & 0xff;
1976 ee->ee_thr_62[mode] = val & 0xff;
1978 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1979 ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28;
1981 AR5K_EEPROM_READ(o++, val);
1982 ee->ee_tx_end2xpa_disable[mode] = (val >> 8) & 0xff;
1983 ee->ee_tx_frm2xpa_enable[mode] = val & 0xff;
1985 AR5K_EEPROM_READ(o++, val);
1986 ee->ee_pga_desired_size[mode] = (val >> 8) & 0xff;
1988 if ((val & 0xff) & 0x80)
1989 ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1);
1991 ee->ee_noise_floor_thr[mode] = val & 0xff;
1993 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1994 ee->ee_noise_floor_thr[mode] =
1995 mode == AR5K_EEPROM_MODE_11A ? -54 : -1;
1997 AR5K_EEPROM_READ(o++, val);
1998 ee->ee_xlna_gain[mode] = (val >> 5) & 0xff;
1999 ee->ee_x_gain[mode] = (val >> 1) & 0xf;
2000 ee->ee_xpd[mode] = val & 0x1;
2002 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0)
2003 ee->ee_fixed_bias[mode] = (val >> 13) & 0x1;
2005 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) {
2006 AR5K_EEPROM_READ(o++, val);
2007 ee->ee_false_detect[mode] = (val >> 6) & 0x7f;
2009 if (mode == AR5K_EEPROM_MODE_11A)
2010 ee->ee_xr_power[mode] = val & 0x3f;
2012 ee->ee_ob[mode][0] = val & 0x7;
2013 ee->ee_db[mode][0] = (val >> 3) & 0x7;
2017 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) {
2018 ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN;
2019 ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA;
2021 ee->ee_i_gain[mode] = (val >> 13) & 0x7;
2023 AR5K_EEPROM_READ(o++, val);
2024 ee->ee_i_gain[mode] |= (val << 3) & 0x38;
2026 if (mode == AR5K_EEPROM_MODE_11G)
2027 ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff;
2030 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
2031 mode == AR5K_EEPROM_MODE_11A) {
2032 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
2033 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
2036 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6 &&
2037 mode == AR5K_EEPROM_MODE_11G)
2038 ee->ee_scaled_cck_delta = (val >> 11) & 0x1f;
2040 /* return new offset */
2047 * Initialize eeprom & capabilities structs
2049 static int ath5k_eeprom_init(struct ath5k_hw *ah)
2051 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
2052 unsigned int mode, i;
2057 /* Initial TX thermal adjustment values */
2059 ee->ee_pwd_84 = ee->ee_pwd_90 = 1;
2060 ee->ee_gain_select = 1;
2063 * Read values from EEPROM and store them in the capability structure
2065 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC, ee_magic);
2066 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT, ee_protect);
2067 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN, ee_regdomain);
2068 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION, ee_version);
2069 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR, ee_header);
2071 /* Return if we have an old EEPROM */
2072 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_0)
2077 * Validate the checksum of the EEPROM date. There are some
2078 * devices with invalid EEPROMs.
2080 for (cksum = 0, offset = 0; offset < AR5K_EEPROM_INFO_MAX; offset++) {
2081 AR5K_EEPROM_READ(AR5K_EEPROM_INFO(offset), val);
2084 if (cksum != AR5K_EEPROM_INFO_CKSUM) {
2085 ATH5K_ERR(ah->ah_sc, "Invalid EEPROM checksum 0x%04x\n", cksum);
2090 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah->ah_ee_version),
2093 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2094 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0, ee_misc0);
2095 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1, ee_misc1);
2098 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_3) {
2099 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ, val);
2100 ee->ee_ob[AR5K_EEPROM_MODE_11B][0] = val & 0x7;
2101 ee->ee_db[AR5K_EEPROM_MODE_11B][0] = (val >> 3) & 0x7;
2103 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ, val);
2104 ee->ee_ob[AR5K_EEPROM_MODE_11G][0] = val & 0x7;
2105 ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7;
2109 * Get conformance test limit values
2111 offset = AR5K_EEPROM_CTL(ah->ah_ee_version);
2112 ee->ee_ctls = AR5K_EEPROM_N_CTLS(ah->ah_ee_version);
2114 for (i = 0; i < ee->ee_ctls; i++) {
2115 AR5K_EEPROM_READ(offset++, val);
2116 ee->ee_ctl[i] = (val >> 8) & 0xff;
2117 ee->ee_ctl[i + 1] = val & 0xff;
2121 * Get values for 802.11a (5GHz)
2123 mode = AR5K_EEPROM_MODE_11A;
2125 ee->ee_turbo_max_power[mode] =
2126 AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header);
2128 offset = AR5K_EEPROM_MODES_11A(ah->ah_ee_version);
2130 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2134 AR5K_EEPROM_READ(offset++, val);
2135 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2136 ee->ee_ob[mode][3] = (val >> 5) & 0x7;
2137 ee->ee_db[mode][3] = (val >> 2) & 0x7;
2138 ee->ee_ob[mode][2] = (val << 1) & 0x7;
2140 AR5K_EEPROM_READ(offset++, val);
2141 ee->ee_ob[mode][2] |= (val >> 15) & 0x1;
2142 ee->ee_db[mode][2] = (val >> 12) & 0x7;
2143 ee->ee_ob[mode][1] = (val >> 9) & 0x7;
2144 ee->ee_db[mode][1] = (val >> 6) & 0x7;
2145 ee->ee_ob[mode][0] = (val >> 3) & 0x7;
2146 ee->ee_db[mode][0] = val & 0x7;
2148 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2152 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1) {
2153 AR5K_EEPROM_READ(offset++, val);
2154 ee->ee_margin_tx_rx[mode] = val & 0x3f;
2158 * Get values for 802.11b (2.4GHz)
2160 mode = AR5K_EEPROM_MODE_11B;
2161 offset = AR5K_EEPROM_MODES_11B(ah->ah_ee_version);
2163 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2167 AR5K_EEPROM_READ(offset++, val);
2168 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2169 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
2170 ee->ee_db[mode][1] = val & 0x7;
2172 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2176 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2177 AR5K_EEPROM_READ(offset++, val);
2178 ee->ee_cal_pier[mode][0] =
2179 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2180 ee->ee_cal_pier[mode][1] =
2181 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
2183 AR5K_EEPROM_READ(offset++, val);
2184 ee->ee_cal_pier[mode][2] =
2185 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2188 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
2189 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
2192 * Get values for 802.11g (2.4GHz)
2194 mode = AR5K_EEPROM_MODE_11G;
2195 offset = AR5K_EEPROM_MODES_11G(ah->ah_ee_version);
2197 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2201 AR5K_EEPROM_READ(offset++, val);
2202 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2203 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
2204 ee->ee_db[mode][1] = val & 0x7;
2206 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2210 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2211 AR5K_EEPROM_READ(offset++, val);
2212 ee->ee_cal_pier[mode][0] =
2213 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2214 ee->ee_cal_pier[mode][1] =
2215 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
2217 AR5K_EEPROM_READ(offset++, val);
2218 ee->ee_turbo_max_power[mode] = val & 0x7f;
2219 ee->ee_xr_power[mode] = (val >> 7) & 0x3f;
2221 AR5K_EEPROM_READ(offset++, val);
2222 ee->ee_cal_pier[mode][2] =
2223 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2225 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
2226 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
2228 AR5K_EEPROM_READ(offset++, val);
2229 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
2230 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
2232 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) {
2233 AR5K_EEPROM_READ(offset++, val);
2234 ee->ee_cck_ofdm_gain_delta = val & 0xff;
2239 * Read 5GHz EEPROM channels
2246 * Read the MAC address from eeprom
2248 static int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
2255 memset(mac, 0, ETH_ALEN);
2256 memset(mac_d, 0, ETH_ALEN);
2258 ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
2262 for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
2263 ret = ath5k_hw_eeprom_read(ah, offset, &data);
2268 mac_d[octet + 1] = data & 0xff;
2269 mac_d[octet] = data >> 8;
2273 memcpy(mac, mac_d, ETH_ALEN);
2275 if (!total || total == 3 * 0xffff)
2282 * Fill the capabilities struct
2284 static int ath5k_hw_get_capabilities(struct ath5k_hw *ah)
2288 ATH5K_TRACE(ah->ah_sc);
2289 /* Capabilities stored in the EEPROM */
2290 ee_header = ah->ah_capabilities.cap_eeprom.ee_header;
2292 if (ah->ah_version == AR5K_AR5210) {
2294 * Set radio capabilities
2295 * (The AR5110 only supports the middle 5GHz band)
2297 ah->ah_capabilities.cap_range.range_5ghz_min = 5120;
2298 ah->ah_capabilities.cap_range.range_5ghz_max = 5430;
2299 ah->ah_capabilities.cap_range.range_2ghz_min = 0;
2300 ah->ah_capabilities.cap_range.range_2ghz_max = 0;
2302 /* Set supported modes */
2303 __set_bit(AR5K_MODE_11A, ah->ah_capabilities.cap_mode);
2304 __set_bit(AR5K_MODE_11A_TURBO, ah->ah_capabilities.cap_mode);
2307 * XXX The tranceiver supports frequencies from 4920 to 6100GHz
2308 * XXX and from 2312 to 2732GHz. There are problems with the
2309 * XXX current ieee80211 implementation because the IEEE
2310 * XXX channel mapping does not support negative channel
2311 * XXX numbers (2312MHz is channel -19). Of course, this
2312 * XXX doesn't matter because these channels are out of range
2313 * XXX but some regulation domains like MKK (Japan) will
2314 * XXX support frequencies somewhere around 4.8GHz.
2318 * Set radio capabilities
2321 if (AR5K_EEPROM_HDR_11A(ee_header)) {
2322 ah->ah_capabilities.cap_range.range_5ghz_min = 5005; /* 4920 */
2323 ah->ah_capabilities.cap_range.range_5ghz_max = 6100;
2325 /* Set supported modes */
2326 __set_bit(AR5K_MODE_11A,
2327 ah->ah_capabilities.cap_mode);
2328 __set_bit(AR5K_MODE_11A_TURBO,
2329 ah->ah_capabilities.cap_mode);
2330 if (ah->ah_version == AR5K_AR5212)
2331 __set_bit(AR5K_MODE_11G_TURBO,
2332 ah->ah_capabilities.cap_mode);
2335 /* Enable 802.11b if a 2GHz capable radio (2111/5112) is
2337 if (AR5K_EEPROM_HDR_11B(ee_header) ||
2338 AR5K_EEPROM_HDR_11G(ee_header)) {
2339 ah->ah_capabilities.cap_range.range_2ghz_min = 2412; /* 2312 */
2340 ah->ah_capabilities.cap_range.range_2ghz_max = 2732;
2342 if (AR5K_EEPROM_HDR_11B(ee_header))
2343 __set_bit(AR5K_MODE_11B,
2344 ah->ah_capabilities.cap_mode);
2346 if (AR5K_EEPROM_HDR_11G(ee_header))
2347 __set_bit(AR5K_MODE_11G,
2348 ah->ah_capabilities.cap_mode);
2353 ah->ah_gpio_npins = AR5K_NUM_GPIO;
2355 /* Set number of supported TX queues */
2356 if (ah->ah_version == AR5K_AR5210)
2357 ah->ah_capabilities.cap_queues.q_tx_num =
2358 AR5K_NUM_TX_QUEUES_NOQCU;
2360 ah->ah_capabilities.cap_queues.q_tx_num = AR5K_NUM_TX_QUEUES;
2365 /*********************************\
2366 Protocol Control Unit Functions
2367 \*********************************/
2370 * Set Operation mode
2372 int ath5k_hw_set_opmode(struct ath5k_hw *ah)
2374 u32 pcu_reg, beacon_reg, low_id, high_id;
2379 ATH5K_TRACE(ah->ah_sc);
2381 switch (ah->ah_op_mode) {
2382 case IEEE80211_IF_TYPE_IBSS:
2383 pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_DESC_ANTENNA |
2384 (ah->ah_version == AR5K_AR5210 ?
2385 AR5K_STA_ID1_NO_PSPOLL : 0);
2386 beacon_reg |= AR5K_BCR_ADHOC;
2389 case IEEE80211_IF_TYPE_AP:
2390 pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_RTS_DEF_ANTENNA |
2391 (ah->ah_version == AR5K_AR5210 ?
2392 AR5K_STA_ID1_NO_PSPOLL : 0);
2393 beacon_reg |= AR5K_BCR_AP;
2396 case IEEE80211_IF_TYPE_STA:
2397 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2398 (ah->ah_version == AR5K_AR5210 ?
2399 AR5K_STA_ID1_PWR_SV : 0);
2400 case IEEE80211_IF_TYPE_MNTR:
2401 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2402 (ah->ah_version == AR5K_AR5210 ?
2403 AR5K_STA_ID1_NO_PSPOLL : 0);
2413 low_id = AR5K_LOW_ID(ah->ah_sta_id);
2414 high_id = AR5K_HIGH_ID(ah->ah_sta_id);
2415 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2416 ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
2419 * Set Beacon Control Register on 5210
2421 if (ah->ah_version == AR5K_AR5210)
2422 ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR);
2434 void ath5k_hw_get_lladdr(struct ath5k_hw *ah, u8 *mac)
2436 ATH5K_TRACE(ah->ah_sc);
2437 memcpy(mac, ah->ah_sta_id, ETH_ALEN);
2443 int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
2445 u32 low_id, high_id;
2447 ATH5K_TRACE(ah->ah_sc);
2448 /* Set new station ID */
2449 memcpy(ah->ah_sta_id, mac, ETH_ALEN);
2451 low_id = AR5K_LOW_ID(mac);
2452 high_id = AR5K_HIGH_ID(mac);
2454 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2455 ath5k_hw_reg_write(ah, high_id, AR5K_STA_ID1);
2463 void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id)
2465 u32 low_id, high_id;
2469 * Set simple BSSID mask on 5212
2471 if (ah->ah_version == AR5K_AR5212) {
2472 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM0);
2473 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM1);
2477 * Set BSSID which triggers the "SME Join" operation
2479 low_id = AR5K_LOW_ID(bssid);
2480 high_id = AR5K_HIGH_ID(bssid);
2481 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_ID0);
2482 ath5k_hw_reg_write(ah, high_id | ((assoc_id & 0x3fff) <<
2483 AR5K_BSS_ID1_AID_S), AR5K_BSS_ID1);
2485 if (assoc_id == 0) {
2486 ath5k_hw_disable_pspoll(ah);
2490 AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM,
2491 tim_offset ? tim_offset + 4 : 0);
2493 ath5k_hw_enable_pspoll(ah, NULL, 0);
2496 * ath5k_hw_set_bssid_mask - set common bits we should listen to
2498 * The bssid_mask is a utility used by AR5212 hardware to inform the hardware
2499 * which bits of the interface's MAC address should be looked at when trying
2500 * to decide which packets to ACK. In station mode every bit matters. In AP
2501 * mode with a single BSS every bit matters as well. In AP mode with
2502 * multiple BSSes not every bit matters.
2504 * @ah: the &struct ath5k_hw
2505 * @mask: the bssid_mask, a u8 array of size ETH_ALEN
2507 * Note that this is a simple filter and *does* not filter out all
2508 * relevant frames. Some non-relevant frames will get through, probability
2509 * jocks are welcomed to compute.
2511 * When handling multiple BSSes (or VAPs) you can get the BSSID mask by
2512 * computing the set of:
2514 * ~ ( MAC XOR BSSID )
2516 * When you do this you are essentially computing the common bits. Later it
2517 * is assumed the harware will "and" (&) the BSSID mask with the MAC address
2518 * to obtain the relevant bits which should match on the destination frame.
2520 * Simple example: on your card you have have two BSSes you have created with
2521 * BSSID-01 and BSSID-02. Lets assume BSSID-01 will not use the MAC address.
2522 * There is another BSSID-03 but you are not part of it. For simplicity's sake,
2523 * assuming only 4 bits for a mac address and for BSSIDs you can then have:
2527 * BSSID-01: 0100 | --> Belongs to us
2530 * -------------------
2531 * BSSID-03: 0110 | --> External
2532 * -------------------
2534 * Our bssid_mask would then be:
2536 * On loop iteration for BSSID-01:
2537 * ~(0001 ^ 0100) -> ~(0101)
2541 * On loop iteration for BSSID-02:
2542 * bssid_mask &= ~(0001 ^ 1001)
2543 * bssid_mask = (1010) & ~(0001 ^ 1001)
2544 * bssid_mask = (1010) & ~(1001)
2545 * bssid_mask = (1010) & (0110)
2548 * A bssid_mask of 0010 means "only pay attention to the second least
2549 * significant bit". This is because its the only bit common
2550 * amongst the MAC and all BSSIDs we support. To findout what the real
2551 * common bit is we can simply "&" the bssid_mask now with any BSSID we have
2552 * or our MAC address (we assume the hardware uses the MAC address).
2554 * Now, suppose there's an incoming frame for BSSID-03:
2558 * An easy eye-inspeciton of this already should tell you that this frame
2559 * will not pass our check. This is beacuse the bssid_mask tells the
2560 * hardware to only look at the second least significant bit and the
2561 * common bit amongst the MAC and BSSIDs is 0, this frame has the 2nd LSB
2562 * as 1, which does not match 0.
2564 * So with IFRAME-01 we *assume* the hardware will do:
2566 * allow = (IFRAME-01 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2567 * --> allow = (0110 & 0010) == (0010 & 0001) ? 1 : 0;
2568 * --> allow = (0010) == 0000 ? 1 : 0;
2571 * Lets now test a frame that should work:
2573 * IFRAME-02: 0001 (we should allow)
2575 * allow = (0001 & 1010) == 1010
2577 * allow = (IFRAME-02 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2578 * --> allow = (0001 & 0010) == (0010 & 0001) ? 1 :0;
2579 * --> allow = (0010) == (0010)
2584 * IFRAME-03: 0100 --> allowed
2585 * IFRAME-04: 1001 --> allowed
2586 * IFRAME-05: 1101 --> allowed but its not for us!!!
2589 int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
2591 u32 low_id, high_id;
2592 ATH5K_TRACE(ah->ah_sc);
2594 if (ah->ah_version == AR5K_AR5212) {
2595 low_id = AR5K_LOW_ID(mask);
2596 high_id = AR5K_HIGH_ID(mask);
2598 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_IDM0);
2599 ath5k_hw_reg_write(ah, high_id, AR5K_BSS_IDM1);
2608 * Receive start/stop functions
2612 * Start receive on PCU
2614 void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
2616 ATH5K_TRACE(ah->ah_sc);
2617 AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
2619 /* TODO: ANI Support */
2623 * Stop receive on PCU
2625 void ath5k_hw_stop_pcu_recv(struct ath5k_hw *ah)
2627 ATH5K_TRACE(ah->ah_sc);
2628 AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
2630 /* TODO: ANI Support */
2634 * RX Filter functions
2638 * Set multicast filter
2640 void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
2642 ATH5K_TRACE(ah->ah_sc);
2643 /* Set the multicat filter */
2644 ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0);
2645 ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1);
2649 * Set multicast filter by index
2651 int ath5k_hw_set_mcast_filterindex(struct ath5k_hw *ah, u32 index)
2654 ATH5K_TRACE(ah->ah_sc);
2657 else if (index >= 32)
2658 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER1,
2659 (1 << (index - 32)));
2661 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2667 * Clear Multicast filter by index
2669 int ath5k_hw_clear_mcast_filter_idx(struct ath5k_hw *ah, u32 index)
2672 ATH5K_TRACE(ah->ah_sc);
2675 else if (index >= 32)
2676 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER1,
2677 (1 << (index - 32)));
2679 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2685 * Get current rx filter
2687 u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah)
2689 u32 data, filter = 0;
2691 ATH5K_TRACE(ah->ah_sc);
2692 filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER);
2694 /*Radar detection for 5212*/
2695 if (ah->ah_version == AR5K_AR5212) {
2696 data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL);
2698 if (data & AR5K_PHY_ERR_FIL_RADAR)
2699 filter |= AR5K_RX_FILTER_RADARERR;
2700 if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK))
2701 filter |= AR5K_RX_FILTER_PHYERR;
2710 void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
2714 ATH5K_TRACE(ah->ah_sc);
2716 /* Set PHY error filter register on 5212*/
2717 if (ah->ah_version == AR5K_AR5212) {
2718 if (filter & AR5K_RX_FILTER_RADARERR)
2719 data |= AR5K_PHY_ERR_FIL_RADAR;
2720 if (filter & AR5K_RX_FILTER_PHYERR)
2721 data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK;
2725 * The AR5210 uses promiscous mode to detect radar activity
2727 if (ah->ah_version == AR5K_AR5210 &&
2728 (filter & AR5K_RX_FILTER_RADARERR)) {
2729 filter &= ~AR5K_RX_FILTER_RADARERR;
2730 filter |= AR5K_RX_FILTER_PROM;
2735 AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2737 AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2739 /*Write RX Filter register*/
2740 ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER);
2742 /*Write PHY error filter register on 5212*/
2743 if (ah->ah_version == AR5K_AR5212)
2744 ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
2749 * Beacon related functions
2755 u32 ath5k_hw_get_tsf32(struct ath5k_hw *ah)
2757 ATH5K_TRACE(ah->ah_sc);
2758 return ath5k_hw_reg_read(ah, AR5K_TSF_L32);
2762 * Get the full 64bit TSF
2764 u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah)
2766 u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
2767 ATH5K_TRACE(ah->ah_sc);
2769 return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32);
2775 void ath5k_hw_reset_tsf(struct ath5k_hw *ah)
2777 ATH5K_TRACE(ah->ah_sc);
2778 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_RESET_TSF);
2782 * Initialize beacon timers
2784 void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
2786 u32 timer1, timer2, timer3;
2788 ATH5K_TRACE(ah->ah_sc);
2790 * Set the additional timers by mode
2792 switch (ah->ah_op_mode) {
2793 case IEEE80211_IF_TYPE_STA:
2794 if (ah->ah_version == AR5K_AR5210) {
2795 timer1 = 0xffffffff;
2796 timer2 = 0xffffffff;
2798 timer1 = 0x0000ffff;
2799 timer2 = 0x0007ffff;
2804 timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3;
2805 timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3;
2808 timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1);
2811 * Set the beacon register and enable all timers.
2812 * (next beacon, DMA beacon, software beacon, ATIM window time)
2814 ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
2815 ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
2816 ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
2817 ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
2819 ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD |
2820 AR5K_BEACON_RESET_TSF | AR5K_BEACON_ENABLE),
2828 int ath5k_hw_set_beacon_timers(struct ath5k_hw *ah,
2829 const struct ath5k_beacon_state *state)
2831 u32 cfp_period, next_cfp, dtim, interval, next_beacon;
2834 * TODO: should be changed through *state
2835 * review struct ath5k_beacon_state struct
2837 * XXX: These are used for cfp period bellow, are they
2838 * ok ? Is it O.K. for tsf here to be 0 or should we use
2841 u32 dtim_count = 0; /* XXX */
2842 u32 cfp_count = 0; /* XXX */
2843 u32 tsf = 0; /* XXX */
2845 ATH5K_TRACE(ah->ah_sc);
2846 /* Return on an invalid beacon state */
2847 if (state->bs_interval < 1)
2850 interval = state->bs_interval;
2851 dtim = state->bs_dtim_period;
2856 if (state->bs_cfp_period > 0) {
2858 * Enable PCF mode and set the CFP
2859 * (Contention Free Period) and timer registers
2861 cfp_period = state->bs_cfp_period * state->bs_dtim_period *
2863 next_cfp = (cfp_count * state->bs_dtim_period + dtim_count) *
2866 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
2867 AR5K_STA_ID1_DEFAULT_ANTENNA |
2869 ath5k_hw_reg_write(ah, cfp_period, AR5K_CFP_PERIOD);
2870 ath5k_hw_reg_write(ah, state->bs_cfp_max_duration,
2872 ath5k_hw_reg_write(ah, (tsf + (next_cfp == 0 ? cfp_period :
2873 next_cfp)) << 3, AR5K_TIMER2);
2875 /* Disable PCF mode */
2876 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2877 AR5K_STA_ID1_DEFAULT_ANTENNA |
2882 * Enable the beacon timer register
2884 ath5k_hw_reg_write(ah, state->bs_next_beacon, AR5K_TIMER0);
2887 * Start the beacon timers
2889 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_BEACON) &~
2890 (AR5K_BEACON_PERIOD | AR5K_BEACON_TIM)) |
2891 AR5K_REG_SM(state->bs_tim_offset ? state->bs_tim_offset + 4 : 0,
2892 AR5K_BEACON_TIM) | AR5K_REG_SM(state->bs_interval,
2893 AR5K_BEACON_PERIOD), AR5K_BEACON);
2896 * Write new beacon miss threshold, if it appears to be valid
2897 * XXX: Figure out right values for min <= bs_bmiss_threshold <= max
2898 * and return if its not in range. We can test this by reading value and
2899 * setting value to a largest value and seeing which values register.
2902 AR5K_REG_WRITE_BITS(ah, AR5K_RSSI_THR, AR5K_RSSI_THR_BMISS,
2903 state->bs_bmiss_threshold);
2906 * Set sleep control register
2907 * XXX: Didn't find this in 5210 code but since this register
2908 * exists also in ar5k's 5210 headers i leave it as common code.
2910 AR5K_REG_WRITE_BITS(ah, AR5K_SLEEP_CTL, AR5K_SLEEP_CTL_SLDUR,
2911 (state->bs_sleep_duration - 3) << 3);
2914 * Set enhanced sleep registers on 5212
2916 if (ah->ah_version == AR5K_AR5212) {
2917 if (state->bs_sleep_duration > state->bs_interval &&
2918 roundup(state->bs_sleep_duration, interval) ==
2919 state->bs_sleep_duration)
2920 interval = state->bs_sleep_duration;
2922 if (state->bs_sleep_duration > dtim && (dtim == 0 ||
2923 roundup(state->bs_sleep_duration, dtim) ==
2924 state->bs_sleep_duration))
2925 dtim = state->bs_sleep_duration;
2927 if (interval > dtim)
2930 next_beacon = interval == dtim ? state->bs_next_dtim :
2931 state->bs_next_beacon;
2933 ath5k_hw_reg_write(ah,
2934 AR5K_REG_SM((state->bs_next_dtim - 3) << 3,
2935 AR5K_SLEEP0_NEXT_DTIM) |
2936 AR5K_REG_SM(10, AR5K_SLEEP0_CABTO) |
2937 AR5K_SLEEP0_ENH_SLEEP_EN |
2938 AR5K_SLEEP0_ASSUME_DTIM, AR5K_SLEEP0);
2940 ath5k_hw_reg_write(ah, AR5K_REG_SM((next_beacon - 3) << 3,
2941 AR5K_SLEEP1_NEXT_TIM) |
2942 AR5K_REG_SM(10, AR5K_SLEEP1_BEACON_TO), AR5K_SLEEP1);
2944 ath5k_hw_reg_write(ah,
2945 AR5K_REG_SM(interval, AR5K_SLEEP2_TIM_PER) |
2946 AR5K_REG_SM(dtim, AR5K_SLEEP2_DTIM_PER), AR5K_SLEEP2);
2953 * Reset beacon timers
2955 void ath5k_hw_reset_beacon(struct ath5k_hw *ah)
2957 ATH5K_TRACE(ah->ah_sc);
2959 * Disable beacon timer
2961 ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
2964 * Disable some beacon register values
2966 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2967 AR5K_STA_ID1_DEFAULT_ANTENNA | AR5K_STA_ID1_PCF);
2968 ath5k_hw_reg_write(ah, AR5K_BEACON_PERIOD, AR5K_BEACON);
2972 * Wait for beacon queue to finish
2974 int ath5k_hw_beaconq_finish(struct ath5k_hw *ah, unsigned long phys_addr)
2979 ATH5K_TRACE(ah->ah_sc);
2981 /* 5210 doesn't have QCU*/
2982 if (ah->ah_version == AR5K_AR5210) {
2984 * Wait for beaconn queue to finish by checking
2985 * Control Register and Beacon Status Register.
2987 for (i = AR5K_TUNE_BEACON_INTERVAL / 2; i > 0; i--) {
2988 if (!(ath5k_hw_reg_read(ah, AR5K_BSR) & AR5K_BSR_TXQ1F)
2990 !(ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_BSR_TXQ1F))
2998 * Re-schedule the beacon queue
3000 ath5k_hw_reg_write(ah, phys_addr, AR5K_NOQCU_TXDP1);
3001 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
3009 ret = ath5k_hw_register_timeout(ah,
3010 AR5K_QUEUE_STATUS(AR5K_TX_QUEUE_ID_BEACON),
3011 AR5K_QCU_STS_FRMPENDCNT, 0, false);
3013 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, AR5K_TX_QUEUE_ID_BEACON))
3022 * Update mib counters (statistics)
3024 void ath5k_hw_update_mib_counters(struct ath5k_hw *ah,
3025 struct ieee80211_low_level_stats *stats)
3027 ATH5K_TRACE(ah->ah_sc);
3029 /* Read-And-Clear */
3030 stats->dot11ACKFailureCount += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL);
3031 stats->dot11RTSFailureCount += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL);
3032 stats->dot11RTSSuccessCount += ath5k_hw_reg_read(ah, AR5K_RTS_OK);
3033 stats->dot11FCSErrorCount += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL);
3035 /* XXX: Should we use this to track beacon count ?
3036 * -we read it anyway to clear the register */
3037 ath5k_hw_reg_read(ah, AR5K_BEACON_CNT);
3039 /* Reset profile count registers on 5212*/
3040 if (ah->ah_version == AR5K_AR5212) {
3041 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_TX);
3042 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RX);
3043 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR);
3044 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE);
3048 /** ath5k_hw_set_ack_bitrate - set bitrate for ACKs
3050 * @ah: the &struct ath5k_hw
3051 * @high: determines if to use low bit rate or now
3053 void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high)
3055 if (ah->ah_version != AR5K_AR5212)
3058 u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB;
3060 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val);
3062 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val);
3072 * Set ACK timeout on PCU
3074 int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout)
3076 ATH5K_TRACE(ah->ah_sc);
3077 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK),
3078 ah->ah_turbo) <= timeout)
3081 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK,
3082 ath5k_hw_htoclock(timeout, ah->ah_turbo));
3088 * Read the ACK timeout from PCU
3090 unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah)
3092 ATH5K_TRACE(ah->ah_sc);
3094 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
3095 AR5K_TIME_OUT), AR5K_TIME_OUT_ACK), ah->ah_turbo);
3099 * Set CTS timeout on PCU
3101 int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout)
3103 ATH5K_TRACE(ah->ah_sc);
3104 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS),
3105 ah->ah_turbo) <= timeout)
3108 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS,
3109 ath5k_hw_htoclock(timeout, ah->ah_turbo));
3115 * Read CTS timeout from PCU
3117 unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah)
3119 ATH5K_TRACE(ah->ah_sc);
3120 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
3121 AR5K_TIME_OUT), AR5K_TIME_OUT_CTS), ah->ah_turbo);
3125 * Key table (WEP) functions
3128 int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
3132 ATH5K_TRACE(ah->ah_sc);
3133 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3135 for (i = 0; i < AR5K_KEYCACHE_SIZE; i++)
3136 ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i));
3139 * Set NULL encryption on AR5212+
3141 * Note: AR5K_KEYTABLE_TYPE -> AR5K_KEYTABLE_OFF(entry, 5)
3142 * AR5K_KEYTABLE_TYPE_NULL -> 0x00000007
3144 * Note2: Windows driver (ndiswrapper) sets this to
3145 * 0x00000714 instead of 0x00000007
3147 if (ah->ah_version > AR5K_AR5211)
3148 ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
3149 AR5K_KEYTABLE_TYPE(entry));
3154 int ath5k_hw_is_key_valid(struct ath5k_hw *ah, u16 entry)
3156 ATH5K_TRACE(ah->ah_sc);
3157 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3159 /* Check the validation flag at the end of the entry */
3160 return ath5k_hw_reg_read(ah, AR5K_KEYTABLE_MAC1(entry)) &
3161 AR5K_KEYTABLE_VALID;
3164 int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
3165 const struct ieee80211_key_conf *key, const u8 *mac)
3168 __le32 key_v[5] = {};
3171 ATH5K_TRACE(ah->ah_sc);
3173 /* key->keylen comes in from mac80211 in bytes */
3175 if (key->keylen > AR5K_KEYTABLE_SIZE / 8)
3178 switch (key->keylen) {
3179 /* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit */
3181 memcpy(&key_v[0], key->key, 5);
3182 keytype = AR5K_KEYTABLE_TYPE_40;
3185 /* WEP 104-bit = 104-bit entered key + 24-bit IV = 128-bit */
3187 memcpy(&key_v[0], &key->key[0], 6);
3188 memcpy(&key_v[2], &key->key[6], 6);
3189 memcpy(&key_v[4], &key->key[12], 1);
3190 keytype = AR5K_KEYTABLE_TYPE_104;
3192 /* WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit */
3194 memcpy(&key_v[0], &key->key[0], 6);
3195 memcpy(&key_v[2], &key->key[6], 6);
3196 memcpy(&key_v[4], &key->key[12], 4);
3197 keytype = AR5K_KEYTABLE_TYPE_128;
3201 return -EINVAL; /* shouldn't happen */
3204 for (i = 0; i < ARRAY_SIZE(key_v); i++)
3205 ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
3206 AR5K_KEYTABLE_OFF(entry, i));
3208 ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry));
3210 return ath5k_hw_set_key_lladdr(ah, entry, mac);
3213 int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac)
3215 u32 low_id, high_id;
3217 ATH5K_TRACE(ah->ah_sc);
3218 /* Invalid entry (key table overflow) */
3219 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3221 /* MAC may be NULL if it's a broadcast key. In this case no need to
3222 * to compute AR5K_LOW_ID and AR5K_HIGH_ID as we already know it. */
3223 if (unlikely(mac == NULL)) {
3224 low_id = 0xffffffff;
3225 high_id = 0xffff | AR5K_KEYTABLE_VALID;
3227 low_id = AR5K_LOW_ID(mac);
3228 high_id = AR5K_HIGH_ID(mac) | AR5K_KEYTABLE_VALID;
3231 ath5k_hw_reg_write(ah, low_id, AR5K_KEYTABLE_MAC0(entry));
3232 ath5k_hw_reg_write(ah, high_id, AR5K_KEYTABLE_MAC1(entry));
3238 /********************************************\
3239 Queue Control Unit, DFS Control Unit Functions
3240 \********************************************/
3243 * Initialize a transmit queue
3245 int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type,
3246 struct ath5k_txq_info *queue_info)
3251 ATH5K_TRACE(ah->ah_sc);
3256 /*5210 only has 2 queues*/
3257 if (ah->ah_version == AR5K_AR5210) {
3258 switch (queue_type) {
3259 case AR5K_TX_QUEUE_DATA:
3260 queue = AR5K_TX_QUEUE_ID_NOQCU_DATA;
3262 case AR5K_TX_QUEUE_BEACON:
3263 case AR5K_TX_QUEUE_CAB:
3264 queue = AR5K_TX_QUEUE_ID_NOQCU_BEACON;
3270 switch (queue_type) {
3271 case AR5K_TX_QUEUE_DATA:
3272 for (queue = AR5K_TX_QUEUE_ID_DATA_MIN;
3273 ah->ah_txq[queue].tqi_type !=
3274 AR5K_TX_QUEUE_INACTIVE; queue++) {
3276 if (queue > AR5K_TX_QUEUE_ID_DATA_MAX)
3280 case AR5K_TX_QUEUE_UAPSD:
3281 queue = AR5K_TX_QUEUE_ID_UAPSD;
3283 case AR5K_TX_QUEUE_BEACON:
3284 queue = AR5K_TX_QUEUE_ID_BEACON;
3286 case AR5K_TX_QUEUE_CAB:
3287 queue = AR5K_TX_QUEUE_ID_CAB;
3289 case AR5K_TX_QUEUE_XR_DATA:
3290 if (ah->ah_version != AR5K_AR5212)
3291 ATH5K_ERR(ah->ah_sc,
3292 "XR data queues only supported in"
3294 queue = AR5K_TX_QUEUE_ID_XR_DATA;
3302 * Setup internal queue structure
3304 memset(&ah->ah_txq[queue], 0, sizeof(struct ath5k_txq_info));
3305 ah->ah_txq[queue].tqi_type = queue_type;
3307 if (queue_info != NULL) {
3308 queue_info->tqi_type = queue_type;
3309 ret = ath5k_hw_setup_tx_queueprops(ah, queue, queue_info);
3314 * We use ah_txq_status to hold a temp value for
3315 * the Secondary interrupt mask registers on 5211+
3316 * check out ath5k_hw_reset_tx_queue
3318 AR5K_Q_ENABLE_BITS(ah->ah_txq_status, queue);
3324 * Setup a transmit queue
3326 int ath5k_hw_setup_tx_queueprops(struct ath5k_hw *ah, int queue,
3327 const struct ath5k_txq_info *queue_info)
3329 ATH5K_TRACE(ah->ah_sc);
3330 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3332 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3335 memcpy(&ah->ah_txq[queue], queue_info, sizeof(struct ath5k_txq_info));
3337 /*XXX: Is this supported on 5210 ?*/
3338 if ((queue_info->tqi_type == AR5K_TX_QUEUE_DATA &&
3339 ((queue_info->tqi_subtype == AR5K_WME_AC_VI) ||
3340 (queue_info->tqi_subtype == AR5K_WME_AC_VO))) ||
3341 queue_info->tqi_type == AR5K_TX_QUEUE_UAPSD)
3342 ah->ah_txq[queue].tqi_flags |= AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
3348 * Get properties for a specific transmit queue
3350 int ath5k_hw_get_tx_queueprops(struct ath5k_hw *ah, int queue,
3351 struct ath5k_txq_info *queue_info)
3353 ATH5K_TRACE(ah->ah_sc);
3354 memcpy(queue_info, &ah->ah_txq[queue], sizeof(struct ath5k_txq_info));
3359 * Set a transmit queue inactive
3361 void ath5k_hw_release_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3363 ATH5K_TRACE(ah->ah_sc);
3364 if (WARN_ON(queue >= ah->ah_capabilities.cap_queues.q_tx_num))
3367 /* This queue will be skipped in further operations */
3368 ah->ah_txq[queue].tqi_type = AR5K_TX_QUEUE_INACTIVE;
3370 AR5K_Q_DISABLE_BITS(ah->ah_txq_status, queue);
3374 * Set DFS params for a transmit queue
3376 int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3378 u32 cw_min, cw_max, retry_lg, retry_sh;
3379 struct ath5k_txq_info *tq = &ah->ah_txq[queue];
3381 ATH5K_TRACE(ah->ah_sc);
3382 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3384 tq = &ah->ah_txq[queue];
3386 if (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE)
3389 if (ah->ah_version == AR5K_AR5210) {
3390 /* Only handle data queues, others will be ignored */
3391 if (tq->tqi_type != AR5K_TX_QUEUE_DATA)
3395 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3396 AR5K_INIT_SLOT_TIME_TURBO : AR5K_INIT_SLOT_TIME,
3398 /* Set ACK_CTS timeout */
3399 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3400 AR5K_INIT_ACK_CTS_TIMEOUT_TURBO :
3401 AR5K_INIT_ACK_CTS_TIMEOUT, AR5K_SLOT_TIME);
3402 /* Set Transmit Latency */
3403 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3404 AR5K_INIT_TRANSMIT_LATENCY_TURBO :
3405 AR5K_INIT_TRANSMIT_LATENCY, AR5K_USEC_5210);
3408 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS_TURBO +
3409 (ah->ah_aifs + tq->tqi_aifs) *
3410 AR5K_INIT_SLOT_TIME_TURBO) <<
3411 AR5K_IFS0_DIFS_S) | AR5K_INIT_SIFS_TURBO,
3414 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS +
3415 (ah->ah_aifs + tq->tqi_aifs) *
3416 AR5K_INIT_SLOT_TIME) << AR5K_IFS0_DIFS_S) |
3417 AR5K_INIT_SIFS, AR5K_IFS0);
3420 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3421 AR5K_INIT_PROTO_TIME_CNTRL_TURBO :
3422 AR5K_INIT_PROTO_TIME_CNTRL, AR5K_IFS1);
3423 /* Set AR5K_PHY_SETTLING */
3424 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3425 (ath5k_hw_reg_read(ah, AR5K_PHY_SETTLING) & ~0x7F)
3427 (ath5k_hw_reg_read(ah, AR5K_PHY_SETTLING) & ~0x7F)
3430 /* Set Frame Control Register */
3431 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3432 (AR5K_PHY_FRAME_CTL_INI | AR5K_PHY_TURBO_MODE |
3433 AR5K_PHY_TURBO_SHORT | 0x2020) :
3434 (AR5K_PHY_FRAME_CTL_INI | 0x1020),
3435 AR5K_PHY_FRAME_CTL_5210);
3439 * Calculate cwmin/max by channel mode
3441 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN;
3442 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX;
3443 ah->ah_aifs = AR5K_TUNE_AIFS;
3444 /*XR is only supported on 5212*/
3445 if (IS_CHAN_XR(ah->ah_current_channel) &&
3446 ah->ah_version == AR5K_AR5212) {
3447 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_XR;
3448 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_XR;
3449 ah->ah_aifs = AR5K_TUNE_AIFS_XR;
3450 /*B mode is not supported on 5210*/
3451 } else if (IS_CHAN_B(ah->ah_current_channel) &&
3452 ah->ah_version != AR5K_AR5210) {
3453 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_11B;
3454 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_11B;
3455 ah->ah_aifs = AR5K_TUNE_AIFS_11B;
3459 while (cw_min < ah->ah_cw_min)
3460 cw_min = (cw_min << 1) | 1;
3462 cw_min = tq->tqi_cw_min < 0 ? (cw_min >> (-tq->tqi_cw_min)) :
3463 ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
3464 cw_max = tq->tqi_cw_max < 0 ? (cw_max >> (-tq->tqi_cw_max)) :
3465 ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
3468 * Calculate and set retry limits
3470 if (ah->ah_software_retry) {
3471 /* XXX Need to test this */
3472 retry_lg = ah->ah_limit_tx_retries;
3473 retry_sh = retry_lg = retry_lg > AR5K_DCU_RETRY_LMT_SH_RETRY ?
3474 AR5K_DCU_RETRY_LMT_SH_RETRY : retry_lg;
3476 retry_lg = AR5K_INIT_LG_RETRY;
3477 retry_sh = AR5K_INIT_SH_RETRY;
3480 /*No QCU/DCU [5210]*/
3481 if (ah->ah_version == AR5K_AR5210) {
3482 ath5k_hw_reg_write(ah,
3483 (cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
3484 | AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3485 AR5K_NODCU_RETRY_LMT_SLG_RETRY)
3486 | AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3487 AR5K_NODCU_RETRY_LMT_SSH_RETRY)
3488 | AR5K_REG_SM(retry_lg, AR5K_NODCU_RETRY_LMT_LG_RETRY)
3489 | AR5K_REG_SM(retry_sh, AR5K_NODCU_RETRY_LMT_SH_RETRY),
3490 AR5K_NODCU_RETRY_LMT);
3493 ath5k_hw_reg_write(ah,
3494 AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3495 AR5K_DCU_RETRY_LMT_SLG_RETRY) |
3496 AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3497 AR5K_DCU_RETRY_LMT_SSH_RETRY) |
3498 AR5K_REG_SM(retry_lg, AR5K_DCU_RETRY_LMT_LG_RETRY) |
3499 AR5K_REG_SM(retry_sh, AR5K_DCU_RETRY_LMT_SH_RETRY),
3500 AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
3502 /*===Rest is also for QCU/DCU only [5211+]===*/
3505 * Set initial content window (cw_min/cw_max)
3506 * and arbitrated interframe space (aifs)...
3508 ath5k_hw_reg_write(ah,
3509 AR5K_REG_SM(cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
3510 AR5K_REG_SM(cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
3511 AR5K_REG_SM(ah->ah_aifs + tq->tqi_aifs,
3512 AR5K_DCU_LCL_IFS_AIFS),
3513 AR5K_QUEUE_DFS_LOCAL_IFS(queue));
3516 * Set misc registers
3518 ath5k_hw_reg_write(ah, AR5K_QCU_MISC_DCU_EARLY,
3519 AR5K_QUEUE_MISC(queue));
3521 if (tq->tqi_cbr_period) {
3522 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
3523 AR5K_QCU_CBRCFG_INTVAL) |
3524 AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
3525 AR5K_QCU_CBRCFG_ORN_THRES),
3526 AR5K_QUEUE_CBRCFG(queue));
3527 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3528 AR5K_QCU_MISC_FRSHED_CBR);
3529 if (tq->tqi_cbr_overflow_limit)
3530 AR5K_REG_ENABLE_BITS(ah,
3531 AR5K_QUEUE_MISC(queue),
3532 AR5K_QCU_MISC_CBR_THRES_ENABLE);
3535 if (tq->tqi_ready_time)
3536 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
3537 AR5K_QCU_RDYTIMECFG_INTVAL) |
3538 AR5K_QCU_RDYTIMECFG_ENABLE,
3539 AR5K_QUEUE_RDYTIMECFG(queue));
3541 if (tq->tqi_burst_time) {
3542 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
3543 AR5K_DCU_CHAN_TIME_DUR) |
3544 AR5K_DCU_CHAN_TIME_ENABLE,
3545 AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
3547 if (tq->tqi_flags & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
3548 AR5K_REG_ENABLE_BITS(ah,
3549 AR5K_QUEUE_MISC(queue),
3550 AR5K_QCU_MISC_RDY_VEOL_POLICY);
3553 if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
3554 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
3555 AR5K_QUEUE_DFS_MISC(queue));
3557 if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
3558 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
3559 AR5K_QUEUE_DFS_MISC(queue));
3562 * Set registers by queue type
3564 switch (tq->tqi_type) {
3565 case AR5K_TX_QUEUE_BEACON:
3566 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3567 AR5K_QCU_MISC_FRSHED_DBA_GT |
3568 AR5K_QCU_MISC_CBREXP_BCN |
3569 AR5K_QCU_MISC_BCN_ENABLE);
3571 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3572 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3573 AR5K_DCU_MISC_ARBLOCK_CTL_S) |
3574 AR5K_DCU_MISC_POST_FR_BKOFF_DIS |
3575 AR5K_DCU_MISC_BCN_ENABLE);
3577 ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL -
3578 (AR5K_TUNE_SW_BEACON_RESP -
3579 AR5K_TUNE_DMA_BEACON_RESP) -
3580 AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF) * 1024) |
3581 AR5K_QCU_RDYTIMECFG_ENABLE,
3582 AR5K_QUEUE_RDYTIMECFG(queue));
3585 case AR5K_TX_QUEUE_CAB:
3586 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3587 AR5K_QCU_MISC_FRSHED_DBA_GT |
3588 AR5K_QCU_MISC_CBREXP |
3589 AR5K_QCU_MISC_CBREXP_BCN);
3591 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3592 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3593 AR5K_DCU_MISC_ARBLOCK_CTL_S));
3596 case AR5K_TX_QUEUE_UAPSD:
3597 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3598 AR5K_QCU_MISC_CBREXP);
3601 case AR5K_TX_QUEUE_DATA:
3607 * Enable interrupts for this tx queue
3608 * in the secondary interrupt mask registers
3610 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
3611 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
3613 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
3614 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
3616 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
3617 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
3619 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
3620 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
3622 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
3623 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
3626 /* Update secondary interrupt mask registers */
3627 ah->ah_txq_imr_txok &= ah->ah_txq_status;
3628 ah->ah_txq_imr_txerr &= ah->ah_txq_status;
3629 ah->ah_txq_imr_txurn &= ah->ah_txq_status;
3630 ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
3631 ah->ah_txq_imr_txeol &= ah->ah_txq_status;
3633 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
3634 AR5K_SIMR0_QCU_TXOK) |
3635 AR5K_REG_SM(ah->ah_txq_imr_txdesc,
3636 AR5K_SIMR0_QCU_TXDESC), AR5K_SIMR0);
3637 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
3638 AR5K_SIMR1_QCU_TXERR) |
3639 AR5K_REG_SM(ah->ah_txq_imr_txeol,
3640 AR5K_SIMR1_QCU_TXEOL), AR5K_SIMR1);
3641 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txurn,
3642 AR5K_SIMR2_QCU_TXURN), AR5K_SIMR2);
3649 * Get number of pending frames
3650 * for a specific queue [5211+]
3652 u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah, unsigned int queue) {
3653 ATH5K_TRACE(ah->ah_sc);
3654 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3656 /* Return if queue is declared inactive */
3657 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3660 /* XXX: How about AR5K_CFG_TXCNT ? */
3661 if (ah->ah_version == AR5K_AR5210)
3664 return AR5K_QUEUE_STATUS(queue) & AR5K_QCU_STS_FRMPENDCNT;
3670 int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time)
3672 ATH5K_TRACE(ah->ah_sc);
3673 if (slot_time < AR5K_SLOT_TIME_9 || slot_time > AR5K_SLOT_TIME_MAX)
3676 if (ah->ah_version == AR5K_AR5210)
3677 ath5k_hw_reg_write(ah, ath5k_hw_htoclock(slot_time,
3678 ah->ah_turbo), AR5K_SLOT_TIME);
3680 ath5k_hw_reg_write(ah, slot_time, AR5K_DCU_GBL_IFS_SLOT);
3688 unsigned int ath5k_hw_get_slot_time(struct ath5k_hw *ah)
3690 ATH5K_TRACE(ah->ah_sc);
3691 if (ah->ah_version == AR5K_AR5210)
3692 return ath5k_hw_clocktoh(ath5k_hw_reg_read(ah,
3693 AR5K_SLOT_TIME) & 0xffff, ah->ah_turbo);
3695 return ath5k_hw_reg_read(ah, AR5K_DCU_GBL_IFS_SLOT) & 0xffff;
3699 /******************************\
3700 Hardware Descriptor Functions
3701 \******************************/
3708 * Initialize the 2-word tx descriptor on 5210/5211
3711 ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3712 unsigned int pkt_len, unsigned int hdr_len, enum ath5k_pkt_type type,
3713 unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
3714 unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
3715 unsigned int rtscts_rate, unsigned int rtscts_duration)
3718 struct ath5k_hw_2w_tx_ctl *tx_ctl;
3719 unsigned int frame_len;
3721 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
3725 * - Zero retries don't make sense.
3726 * - A zero rate will put the HW into a mode where it continously sends
3727 * noise on the channel, so it is important to avoid this.
3729 if (unlikely(tx_tries0 == 0)) {
3730 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3734 if (unlikely(tx_rate0 == 0)) {
3735 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3740 /* Clear descriptor */
3741 memset(&desc->ud.ds_tx5210, 0, sizeof(struct ath5k_hw_5210_tx_desc));
3743 /* Setup control descriptor */
3745 /* Verify and set frame length */
3747 /* remove padding we might have added before */
3748 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3750 if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
3753 tx_ctl->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
3755 /* Verify and set buffer length */
3757 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3758 if(type == AR5K_PKT_TYPE_BEACON)
3759 pkt_len = roundup(pkt_len, 4);
3761 if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
3764 tx_ctl->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
3767 * Verify and set header length
3768 * XXX: I only found that on 5210 code, does it work on 5211 ?
3770 if (ah->ah_version == AR5K_AR5210) {
3771 if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN)
3773 tx_ctl->tx_control_0 |=
3774 AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN);
3777 /*Diferences between 5210-5211*/
3778 if (ah->ah_version == AR5K_AR5210) {
3780 case AR5K_PKT_TYPE_BEACON:
3781 case AR5K_PKT_TYPE_PROBE_RESP:
3782 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
3783 case AR5K_PKT_TYPE_PIFS:
3784 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
3786 frame_type = type /*<< 2 ?*/;
3789 tx_ctl->tx_control_0 |=
3790 AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE) |
3791 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3793 tx_ctl->tx_control_0 |=
3794 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
3795 AR5K_REG_SM(antenna_mode, AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
3796 tx_ctl->tx_control_1 |=
3797 AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE);
3799 #define _TX_FLAGS(_c, _flag) \
3800 if (flags & AR5K_TXDESC_##_flag) \
3801 tx_ctl->tx_control_##_c |= \
3802 AR5K_2W_TX_DESC_CTL##_c##_##_flag
3804 _TX_FLAGS(0, CLRDMASK);
3806 _TX_FLAGS(0, INTREQ);
3807 _TX_FLAGS(0, RTSENA);
3808 _TX_FLAGS(1, NOACK);
3815 if (key_index != AR5K_TXKEYIX_INVALID) {
3816 tx_ctl->tx_control_0 |=
3817 AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3818 tx_ctl->tx_control_1 |=
3819 AR5K_REG_SM(key_index,
3820 AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3824 * RTS/CTS Duration [5210 ?]
3826 if ((ah->ah_version == AR5K_AR5210) &&
3827 (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
3828 tx_ctl->tx_control_1 |= rtscts_duration &
3829 AR5K_2W_TX_DESC_CTL1_RTS_DURATION;
3835 * Initialize the 4-word tx descriptor on 5212
3837 static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
3838 struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
3839 enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
3840 unsigned int tx_tries0, unsigned int key_index,
3841 unsigned int antenna_mode, unsigned int flags, unsigned int rtscts_rate,
3842 unsigned int rtscts_duration)
3844 struct ath5k_hw_4w_tx_ctl *tx_ctl;
3845 unsigned int frame_len;
3847 ATH5K_TRACE(ah->ah_sc);
3848 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
3852 * - Zero retries don't make sense.
3853 * - A zero rate will put the HW into a mode where it continously sends
3854 * noise on the channel, so it is important to avoid this.
3856 if (unlikely(tx_tries0 == 0)) {
3857 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3861 if (unlikely(tx_rate0 == 0)) {
3862 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3867 /* Clear descriptor */
3868 memset(&desc->ud.ds_tx5212, 0, sizeof(struct ath5k_hw_5212_tx_desc));
3870 /* Setup control descriptor */
3872 /* Verify and set frame length */
3874 /* remove padding we might have added before */
3875 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3877 if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
3880 tx_ctl->tx_control_0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
3882 /* Verify and set buffer length */
3884 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3885 if(type == AR5K_PKT_TYPE_BEACON)
3886 pkt_len = roundup(pkt_len, 4);
3888 if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
3891 tx_ctl->tx_control_1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
3893 tx_ctl->tx_control_0 |=
3894 AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
3895 AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
3896 tx_ctl->tx_control_1 |= AR5K_REG_SM(type,
3897 AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
3898 tx_ctl->tx_control_2 = AR5K_REG_SM(tx_tries0 + AR5K_TUNE_HWTXTRIES,
3899 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
3900 tx_ctl->tx_control_3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
3902 #define _TX_FLAGS(_c, _flag) \
3903 if (flags & AR5K_TXDESC_##_flag) \
3904 tx_ctl->tx_control_##_c |= \
3905 AR5K_4W_TX_DESC_CTL##_c##_##_flag
3907 _TX_FLAGS(0, CLRDMASK);
3909 _TX_FLAGS(0, INTREQ);
3910 _TX_FLAGS(0, RTSENA);
3911 _TX_FLAGS(0, CTSENA);
3912 _TX_FLAGS(1, NOACK);
3919 if (key_index != AR5K_TXKEYIX_INVALID) {
3920 tx_ctl->tx_control_0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3921 tx_ctl->tx_control_1 |= AR5K_REG_SM(key_index,
3922 AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3928 if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
3929 if ((flags & AR5K_TXDESC_RTSENA) &&
3930 (flags & AR5K_TXDESC_CTSENA))
3932 tx_ctl->tx_control_2 |= rtscts_duration &
3933 AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
3934 tx_ctl->tx_control_3 |= AR5K_REG_SM(rtscts_rate,
3935 AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
3942 * Initialize a 4-word multirate tx descriptor on 5212
3945 ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3946 unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2, u_int tx_tries2,
3947 unsigned int tx_rate3, u_int tx_tries3)
3949 struct ath5k_hw_4w_tx_ctl *tx_ctl;
3952 * Rates can be 0 as long as the retry count is 0 too.
3953 * A zero rate and nonzero retry count will put the HW into a mode where
3954 * it continously sends noise on the channel, so it is important to
3957 if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
3958 (tx_rate2 == 0 && tx_tries2 != 0) ||
3959 (tx_rate3 == 0 && tx_tries3 != 0))) {
3960 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3965 if (ah->ah_version == AR5K_AR5212) {
3966 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
3968 #define _XTX_TRIES(_n) \
3969 if (tx_tries##_n) { \
3970 tx_ctl->tx_control_2 |= \
3971 AR5K_REG_SM(tx_tries##_n, \
3972 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
3973 tx_ctl->tx_control_3 |= \
3974 AR5K_REG_SM(tx_rate##_n, \
3975 AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
3991 * Proccess the tx status descriptor on 5210/5211
3993 static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
3994 struct ath5k_desc *desc, struct ath5k_tx_status *ts)
3996 struct ath5k_hw_2w_tx_ctl *tx_ctl;
3997 struct ath5k_hw_tx_status *tx_status;
3999 ATH5K_TRACE(ah->ah_sc);
4001 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
4002 tx_status = &desc->ud.ds_tx5210.tx_stat;
4004 /* No frame has been send or error */
4005 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
4006 return -EINPROGRESS;
4009 * Get descriptor status
4011 ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
4012 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
4013 ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
4014 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
4015 ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
4016 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
4017 /*TODO: ts->ts_virtcol + test*/
4018 ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
4019 AR5K_DESC_TX_STATUS1_SEQ_NUM);
4020 ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
4021 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
4024 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_0,
4025 AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
4027 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
4028 if (tx_status->tx_status_0 &
4029 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
4030 ts->ts_status |= AR5K_TXERR_XRETRY;
4032 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
4033 ts->ts_status |= AR5K_TXERR_FIFO;
4035 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
4036 ts->ts_status |= AR5K_TXERR_FILT;
4043 * Proccess a tx descriptor on 5212
4045 static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
4046 struct ath5k_desc *desc, struct ath5k_tx_status *ts)
4048 struct ath5k_hw_4w_tx_ctl *tx_ctl;
4049 struct ath5k_hw_tx_status *tx_status;
4051 ATH5K_TRACE(ah->ah_sc);
4053 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
4054 tx_status = &desc->ud.ds_tx5212.tx_stat;
4056 /* No frame has been send or error */
4057 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
4058 return -EINPROGRESS;
4061 * Get descriptor status
4063 ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
4064 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
4065 ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
4066 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
4067 ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
4068 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
4069 ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
4070 AR5K_DESC_TX_STATUS1_SEQ_NUM);
4071 ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
4072 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
4073 ts->ts_antenna = (tx_status->tx_status_1 &
4074 AR5K_DESC_TX_STATUS1_XMIT_ANTENNA) ? 2 : 1;
4077 switch (AR5K_REG_MS(tx_status->tx_status_1,
4078 AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX)) {
4080 ts->ts_rate = tx_ctl->tx_control_3 &
4081 AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
4084 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
4085 AR5K_4W_TX_DESC_CTL3_XMIT_RATE1);
4086 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
4087 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1);
4090 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
4091 AR5K_4W_TX_DESC_CTL3_XMIT_RATE2);
4092 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
4093 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2);
4096 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
4097 AR5K_4W_TX_DESC_CTL3_XMIT_RATE3);
4098 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
4099 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES3);
4103 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
4104 if (tx_status->tx_status_0 &
4105 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
4106 ts->ts_status |= AR5K_TXERR_XRETRY;
4108 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
4109 ts->ts_status |= AR5K_TXERR_FIFO;
4111 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
4112 ts->ts_status |= AR5K_TXERR_FILT;
4123 * Initialize an rx descriptor
4125 int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
4126 u32 size, unsigned int flags)
4128 struct ath5k_hw_rx_ctl *rx_ctl;
4130 ATH5K_TRACE(ah->ah_sc);
4131 rx_ctl = &desc->ud.ds_rx.rx_ctl;
4134 * Clear the descriptor
4135 * If we don't clean the status descriptor,
4136 * while scanning we get too many results,
4137 * most of them virtual, after some secs
4138 * of scanning system hangs. M.F.
4140 memset(&desc->ud.ds_rx, 0, sizeof(struct ath5k_hw_all_rx_desc));
4142 /* Setup descriptor */
4143 rx_ctl->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
4144 if (unlikely(rx_ctl->rx_control_1 != size))
4147 if (flags & AR5K_RXDESC_INTREQ)
4148 rx_ctl->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
4154 * Proccess the rx status descriptor on 5210/5211
4156 static int ath5k_hw_proc_5210_rx_status(struct ath5k_hw *ah,
4157 struct ath5k_desc *desc, struct ath5k_rx_status *rs)
4159 struct ath5k_hw_rx_status *rx_status;
4161 rx_status = &desc->ud.ds_rx.u.rx_stat;
4163 /* No frame received / not ready */
4164 if (unlikely((rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_DONE)
4166 return -EINPROGRESS;
4169 * Frame receive status
4171 rs->rs_datalen = rx_status->rx_status_0 &
4172 AR5K_5210_RX_DESC_STATUS0_DATA_LEN;
4173 rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
4174 AR5K_5210_RX_DESC_STATUS0_RECEIVE_SIGNAL);
4175 rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
4176 AR5K_5210_RX_DESC_STATUS0_RECEIVE_RATE);
4177 rs->rs_antenna = rx_status->rx_status_0 &
4178 AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANTENNA;
4179 rs->rs_more = rx_status->rx_status_0 &
4180 AR5K_5210_RX_DESC_STATUS0_MORE;
4181 /* TODO: this timestamp is 13 bit, later on we assume 15 bit */
4182 rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
4183 AR5K_5210_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
4190 if (rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_KEY_INDEX_VALID)
4191 rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
4192 AR5K_5210_RX_DESC_STATUS1_KEY_INDEX);
4194 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
4197 * Receive/descriptor errors
4199 if ((rx_status->rx_status_1 &
4200 AR5K_5210_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
4201 if (rx_status->rx_status_1 &
4202 AR5K_5210_RX_DESC_STATUS1_CRC_ERROR)
4203 rs->rs_status |= AR5K_RXERR_CRC;
4205 if (rx_status->rx_status_1 &
4206 AR5K_5210_RX_DESC_STATUS1_FIFO_OVERRUN)
4207 rs->rs_status |= AR5K_RXERR_FIFO;
4209 if (rx_status->rx_status_1 &
4210 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR) {
4211 rs->rs_status |= AR5K_RXERR_PHY;
4212 rs->rs_phyerr |= AR5K_REG_MS(rx_status->rx_status_1,
4213 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR);
4216 if (rx_status->rx_status_1 &
4217 AR5K_5210_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
4218 rs->rs_status |= AR5K_RXERR_DECRYPT;
4225 * Proccess the rx status descriptor on 5212
4227 static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *ah,
4228 struct ath5k_desc *desc, struct ath5k_rx_status *rs)
4230 struct ath5k_hw_rx_status *rx_status;
4231 struct ath5k_hw_rx_error *rx_err;
4233 ATH5K_TRACE(ah->ah_sc);
4234 rx_status = &desc->ud.ds_rx.u.rx_stat;
4236 /* Overlay on error */
4237 rx_err = &desc->ud.ds_rx.u.rx_err;
4239 /* No frame received / not ready */
4240 if (unlikely((rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_DONE)
4242 return -EINPROGRESS;
4245 * Frame receive status
4247 rs->rs_datalen = rx_status->rx_status_0 &
4248 AR5K_5212_RX_DESC_STATUS0_DATA_LEN;
4249 rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
4250 AR5K_5212_RX_DESC_STATUS0_RECEIVE_SIGNAL);
4251 rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
4252 AR5K_5212_RX_DESC_STATUS0_RECEIVE_RATE);
4253 rs->rs_antenna = rx_status->rx_status_0 &
4254 AR5K_5212_RX_DESC_STATUS0_RECEIVE_ANTENNA;
4255 rs->rs_more = rx_status->rx_status_0 &
4256 AR5K_5212_RX_DESC_STATUS0_MORE;
4257 rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
4258 AR5K_5212_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
4265 if (rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_KEY_INDEX_VALID)
4266 rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
4267 AR5K_5212_RX_DESC_STATUS1_KEY_INDEX);
4269 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
4272 * Receive/descriptor errors
4274 if ((rx_status->rx_status_1 &
4275 AR5K_5212_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
4276 if (rx_status->rx_status_1 &
4277 AR5K_5212_RX_DESC_STATUS1_CRC_ERROR)
4278 rs->rs_status |= AR5K_RXERR_CRC;
4280 if (rx_status->rx_status_1 &
4281 AR5K_5212_RX_DESC_STATUS1_PHY_ERROR) {
4282 rs->rs_status |= AR5K_RXERR_PHY;
4283 rs->rs_phyerr |= AR5K_REG_MS(rx_err->rx_error_1,
4284 AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE);
4287 if (rx_status->rx_status_1 &
4288 AR5K_5212_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
4289 rs->rs_status |= AR5K_RXERR_DECRYPT;
4291 if (rx_status->rx_status_1 &
4292 AR5K_5212_RX_DESC_STATUS1_MIC_ERROR)
4293 rs->rs_status |= AR5K_RXERR_MIC;
4307 void ath5k_hw_set_ledstate(struct ath5k_hw *ah, unsigned int state)
4310 /*5210 has different led mode handling*/
4313 ATH5K_TRACE(ah->ah_sc);
4315 /*Reset led status*/
4316 if (ah->ah_version != AR5K_AR5210)
4317 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
4318 AR5K_PCICFG_LEDMODE | AR5K_PCICFG_LED);
4320 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_LED);
4323 * Some blinking values, define at your wish
4328 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_PEND;
4329 led_5210 = AR5K_PCICFG_LED_PEND | AR5K_PCICFG_LED_BCTL;
4333 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_NONE;
4334 led_5210 = AR5K_PCICFG_LED_PEND;
4337 case AR5K_LED_ASSOC:
4339 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_ASSOC;
4340 led_5210 = AR5K_PCICFG_LED_ASSOC;
4344 led = AR5K_PCICFG_LEDMODE_PROM | AR5K_PCICFG_LED_NONE;
4345 led_5210 = AR5K_PCICFG_LED_PEND;
4349 /*Write new status to the register*/
4350 if (ah->ah_version != AR5K_AR5210)
4351 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led);
4353 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led_5210);
4359 int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
4361 ATH5K_TRACE(ah->ah_sc);
4362 if (gpio > AR5K_NUM_GPIO)
4365 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4366 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR);
4374 int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
4376 ATH5K_TRACE(ah->ah_sc);
4377 if (gpio > AR5K_NUM_GPIO)
4380 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4381 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR);
4389 u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
4391 ATH5K_TRACE(ah->ah_sc);
4392 if (gpio > AR5K_NUM_GPIO)
4395 /* GPIO input magic */
4396 return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) &
4403 int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
4406 ATH5K_TRACE(ah->ah_sc);
4408 if (gpio > AR5K_NUM_GPIO)
4411 /* GPIO output magic */
4412 data = ath5k_hw_reg_read(ah, AR5K_GPIODO);
4414 data &= ~(1 << gpio);
4415 data |= (val & 1) << gpio;
4417 ath5k_hw_reg_write(ah, data, AR5K_GPIODO);
4423 * Initialize the GPIO interrupt (RFKill switch)
4425 void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
4426 u32 interrupt_level)
4430 ATH5K_TRACE(ah->ah_sc);
4431 if (gpio > AR5K_NUM_GPIO)
4435 * Set the GPIO interrupt
4437 data = (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &
4438 ~(AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_SELH |
4439 AR5K_GPIOCR_INT_ENA | AR5K_GPIOCR_OUT(gpio))) |
4440 (AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_ENA);
4442 ath5k_hw_reg_write(ah, interrupt_level ? data :
4443 (data | AR5K_GPIOCR_INT_SELH), AR5K_GPIOCR);
4445 ah->ah_imr |= AR5K_IMR_GPIO;
4447 /* Enable GPIO interrupts */
4448 AR5K_REG_ENABLE_BITS(ah, AR5K_PIMR, AR5K_IMR_GPIO);
4458 int ath5k_hw_get_capability(struct ath5k_hw *ah,
4459 enum ath5k_capability_type cap_type,
4460 u32 capability, u32 *result)
4462 ATH5K_TRACE(ah->ah_sc);
4465 case AR5K_CAP_NUM_TXQUEUES:
4467 if (ah->ah_version == AR5K_AR5210)
4468 *result = AR5K_NUM_TX_QUEUES_NOQCU;
4470 *result = AR5K_NUM_TX_QUEUES;
4475 case AR5K_CAP_COMPRESSION:
4476 if (ah->ah_version == AR5K_AR5212)
4480 case AR5K_CAP_BURST:
4484 case AR5K_CAP_BSSIDMASK:
4485 if (ah->ah_version == AR5K_AR5212)
4490 if (ah->ah_version == AR5K_AR5212)
4504 static int ath5k_hw_enable_pspoll(struct ath5k_hw *ah, u8 *bssid,
4507 ATH5K_TRACE(ah->ah_sc);
4509 if (ah->ah_version == AR5K_AR5210) {
4510 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
4511 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
4518 static int ath5k_hw_disable_pspoll(struct ath5k_hw *ah)
4520 ATH5K_TRACE(ah->ah_sc);
4522 if (ah->ah_version == AR5K_AR5210) {
4523 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
4524 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);