2 * Copyright (c) 2004-2007 Reyk Floeter <reyk@openbsd.org>
3 * Copyright (c) 2006-2007 Nick Kossifidis <mickflemm@gmail.com>
4 * Copyright (c) 2007 Matthew W. S. Bell <mentor@madwifi.org>
5 * Copyright (c) 2007 Luis Rodriguez <mcgrof@winlab.rutgers.edu>
6 * Copyright (c) 2007 Pavel Roskin <proski@gnu.org>
7 * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * HW related functions for Atheros Wireless LAN devices.
27 #include <linux/pci.h>
28 #include <linux/delay.h>
35 static const struct ath5k_rate_table ath5k_rt_11a = AR5K_RATES_11A;
36 static const struct ath5k_rate_table ath5k_rt_11b = AR5K_RATES_11B;
37 static const struct ath5k_rate_table ath5k_rt_11g = AR5K_RATES_11G;
38 static const struct ath5k_rate_table ath5k_rt_turbo = AR5K_RATES_TURBO;
39 static const struct ath5k_rate_table ath5k_rt_xr = AR5K_RATES_XR;
42 static int ath5k_hw_nic_reset(struct ath5k_hw *, u32);
43 static int ath5k_hw_nic_wakeup(struct ath5k_hw *, int, bool);
44 static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
45 unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
46 unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
47 unsigned int, unsigned int);
48 static int ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
49 unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
51 static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *, struct ath5k_desc *,
52 struct ath5k_tx_status *);
53 static int ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
54 unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
55 unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
56 unsigned int, unsigned int);
57 static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *, struct ath5k_desc *,
58 struct ath5k_tx_status *);
59 static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *, struct ath5k_desc *,
60 struct ath5k_rx_status *);
61 static int ath5k_hw_proc_5210_rx_status(struct ath5k_hw *, struct ath5k_desc *,
62 struct ath5k_rx_status *);
63 static int ath5k_hw_get_capabilities(struct ath5k_hw *);
65 static int ath5k_eeprom_init(struct ath5k_hw *);
66 static int ath5k_eeprom_read_mac(struct ath5k_hw *, u8 *);
68 static int ath5k_hw_enable_pspoll(struct ath5k_hw *, u8 *, u16);
69 static int ath5k_hw_disable_pspoll(struct ath5k_hw *);
72 * Enable to overwrite the country code (use "00" for debug)
75 #define COUNTRYCODE "00"
83 * Functions used internaly
86 static inline unsigned int ath5k_hw_htoclock(unsigned int usec, bool turbo)
88 return turbo ? (usec * 80) : (usec * 40);
91 static inline unsigned int ath5k_hw_clocktoh(unsigned int clock, bool turbo)
93 return turbo ? (clock / 80) : (clock / 40);
97 * Check if a register write has been completed
99 int ath5k_hw_register_timeout(struct ath5k_hw *ah, u32 reg, u32 flag, u32 val,
105 for (i = AR5K_TUNE_REGISTER_TIMEOUT; i > 0; i--) {
106 data = ath5k_hw_reg_read(ah, reg);
107 if (is_set && (data & flag))
109 else if ((data & flag) == val)
114 return (i <= 0) ? -EAGAIN : 0;
118 /***************************************\
119 Attach/Detach Functions
120 \***************************************/
123 * Power On Self Test helper function
125 static int ath5k_hw_post(struct ath5k_hw *ah)
130 u16 regs[2] = {AR5K_STA_ID0, AR5K_PHY(8)};
132 u32 static_pattern[4] = {
133 0x55555555, 0xaaaaaaaa,
134 0x66666666, 0x99999999
139 for (c = 0; c < 2; c++) {
142 init_val = ath5k_hw_reg_read(ah, cur_reg);
144 for (i = 0; i < 256; i++) {
145 var_pattern = i << 16 | i;
146 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
147 cur_val = ath5k_hw_reg_read(ah, cur_reg);
149 if (cur_val != var_pattern) {
150 ATH5K_ERR(ah->ah_sc, "POST Failed !!!\n");
154 /* Found on ndiswrapper dumps */
155 var_pattern = 0x0039080f;
156 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
159 for (i = 0; i < 4; i++) {
160 var_pattern = static_pattern[i];
161 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
162 cur_val = ath5k_hw_reg_read(ah, cur_reg);
164 if (cur_val != var_pattern) {
165 ATH5K_ERR(ah->ah_sc, "POST Failed !!!\n");
169 /* Found on ndiswrapper dumps */
170 var_pattern = 0x003b080f;
171 ath5k_hw_reg_write(ah, var_pattern, cur_reg);
180 * Check if the device is supported and initialize the needed structs
182 struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
185 struct pci_dev *pdev = sc->pdev;
190 /*If we passed the test malloc a ath5k_hw struct*/
191 ah = kzalloc(sizeof(struct ath5k_hw), GFP_KERNEL);
194 ATH5K_ERR(sc, "out of memory\n");
199 ah->ah_iobase = sc->iobase;
205 ah->ah_op_mode = IEEE80211_IF_TYPE_STA;
206 ah->ah_radar.r_enabled = AR5K_TUNE_RADAR_ALERT;
207 ah->ah_turbo = false;
208 ah->ah_txpower.txp_tpc = AR5K_TUNE_TPC_TXPOWER;
210 ah->ah_atim_window = 0;
211 ah->ah_aifs = AR5K_TUNE_AIFS;
212 ah->ah_cw_min = AR5K_TUNE_CWMIN;
213 ah->ah_limit_tx_retries = AR5K_INIT_TX_RETRY;
214 ah->ah_software_retry = false;
215 ah->ah_ant_diversity = AR5K_TUNE_ANT_DIVERSITY;
218 * Set the mac revision based on the pci id
220 ah->ah_version = mac_version;
222 /*Fill the ath5k_hw struct with the needed functions*/
223 if (ah->ah_version == AR5K_AR5212)
224 ah->ah_magic = AR5K_EEPROM_MAGIC_5212;
225 else if (ah->ah_version == AR5K_AR5211)
226 ah->ah_magic = AR5K_EEPROM_MAGIC_5211;
228 if (ah->ah_version == AR5K_AR5212) {
229 ah->ah_setup_tx_desc = ath5k_hw_setup_4word_tx_desc;
230 ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
231 ah->ah_proc_tx_desc = ath5k_hw_proc_4word_tx_status;
233 ah->ah_setup_tx_desc = ath5k_hw_setup_2word_tx_desc;
234 ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
235 ah->ah_proc_tx_desc = ath5k_hw_proc_2word_tx_status;
238 if (ah->ah_version == AR5K_AR5212)
239 ah->ah_proc_rx_desc = ath5k_hw_proc_5212_rx_status;
240 else if (ah->ah_version <= AR5K_AR5211)
241 ah->ah_proc_rx_desc = ath5k_hw_proc_5210_rx_status;
243 /* Bring device out of sleep and reset it's units */
244 ret = ath5k_hw_nic_wakeup(ah, AR5K_INIT_MODE, true);
248 /* Get MAC, PHY and RADIO revisions */
249 srev = ath5k_hw_reg_read(ah, AR5K_SREV);
250 ah->ah_mac_srev = srev;
251 ah->ah_mac_version = AR5K_REG_MS(srev, AR5K_SREV_VER);
252 ah->ah_mac_revision = AR5K_REG_MS(srev, AR5K_SREV_REV);
253 ah->ah_phy_revision = ath5k_hw_reg_read(ah, AR5K_PHY_CHIP_ID) &
255 ah->ah_radio_5ghz_revision = ath5k_hw_radio_revision(ah,
258 if (ah->ah_version == AR5K_AR5210)
259 ah->ah_radio_2ghz_revision = 0;
261 ah->ah_radio_2ghz_revision = ath5k_hw_radio_revision(ah,
264 /* Return on unsuported chips (unsupported eeprom etc) */
265 if ((srev >= AR5K_SREV_VER_AR5416) &&
266 (srev < AR5K_SREV_VER_AR2425)) {
267 ATH5K_ERR(sc, "Device not yet supported.\n");
270 } else if (srev == AR5K_SREV_VER_AR2425) {
271 ATH5K_WARN(sc, "Support for RF2425 is under development.\n");
274 /* Identify single chip solutions */
275 if (((srev <= AR5K_SREV_VER_AR5414) &&
276 (srev >= AR5K_SREV_VER_AR2413)) ||
277 (srev == AR5K_SREV_VER_AR2425)) {
278 ah->ah_single_chip = true;
280 ah->ah_single_chip = false;
283 /* Single chip radio */
284 if (ah->ah_radio_2ghz_revision == ah->ah_radio_5ghz_revision)
285 ah->ah_radio_2ghz_revision = 0;
287 /* Identify the radio chip*/
288 if (ah->ah_version == AR5K_AR5210) {
289 ah->ah_radio = AR5K_RF5110;
290 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112) {
291 ah->ah_radio = AR5K_RF5111;
292 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5111;
293 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC0) {
295 ah->ah_radio = AR5K_RF5112;
297 if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112A) {
298 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112;
300 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
303 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC1) {
304 ah->ah_radio = AR5K_RF2413;
305 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
306 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC2) {
307 ah->ah_radio = AR5K_RF5413;
308 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
309 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5133) {
312 if (srev >= AR5K_SREV_VER_AR5424) {
313 ah->ah_radio = AR5K_RF5413;
314 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5424;
317 ah->ah_radio = AR5K_RF2413; /* For testing */
318 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
322 * Register returns 0x4 for radio revision
323 * so ath5k_hw_radio_revision doesn't parse the value
324 * correctly. For now we are based on mac's srev to
325 * identify RF2425 radio.
327 } else if (srev == AR5K_SREV_VER_AR2425) {
328 ah->ah_radio = AR5K_RF2425;
329 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112;
332 ah->ah_phy = AR5K_PHY(0);
335 * Identify AR5212-based PCI-E cards
336 * And write some initial settings.
338 * (doing a "strings" on ndis driver
339 * -ar5211.sys- reveals the following
340 * pci-e related functions:
346 * pcieDisableAspmOnRfWake
347 * pciePowerSaveEnable
349 * I guess these point to ClockReq but
352 if ((ah->ah_version == AR5K_AR5212) && (pdev->is_pcie)) {
353 ath5k_hw_reg_write(ah, 0x9248fc00, 0x4080);
354 ath5k_hw_reg_write(ah, 0x24924924, 0x4080);
355 ath5k_hw_reg_write(ah, 0x28000039, 0x4080);
356 ath5k_hw_reg_write(ah, 0x53160824, 0x4080);
357 ath5k_hw_reg_write(ah, 0xe5980579, 0x4080);
358 ath5k_hw_reg_write(ah, 0x001defff, 0x4080);
359 ath5k_hw_reg_write(ah, 0x1aaabe40, 0x4080);
360 ath5k_hw_reg_write(ah, 0xbe105554, 0x4080);
361 ath5k_hw_reg_write(ah, 0x000e3007, 0x4080);
362 ath5k_hw_reg_write(ah, 0x00000000, 0x4084);
368 ret = ath5k_hw_post(ah);
373 * Get card capabilities, values, ...
376 ret = ath5k_eeprom_init(ah);
378 ATH5K_ERR(sc, "unable to init EEPROM\n");
382 /* Get misc capabilities */
383 ret = ath5k_hw_get_capabilities(ah);
385 ATH5K_ERR(sc, "unable to get device capabilities: 0x%04x\n",
390 /* Get MAC address */
391 ret = ath5k_eeprom_read_mac(ah, mac);
393 ATH5K_ERR(sc, "unable to read address from EEPROM: 0x%04x\n",
398 ath5k_hw_set_lladdr(ah, mac);
399 /* Set BSSID to bcast address: ff:ff:ff:ff:ff:ff for now */
400 memset(ah->ah_bssid, 0xff, ETH_ALEN);
401 ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
402 ath5k_hw_set_opmode(ah);
404 ath5k_hw_set_rfgain_opt(ah);
414 * Bring up MAC + PHY Chips
416 static int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
418 struct pci_dev *pdev = ah->ah_sc->pdev;
419 u32 turbo, mode, clock, bus_flags;
426 ATH5K_TRACE(ah->ah_sc);
428 /* Wakeup the device */
429 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
431 ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
435 if (ah->ah_version != AR5K_AR5210) {
437 * Get channel mode flags
440 if (ah->ah_radio >= AR5K_RF5112) {
441 mode = AR5K_PHY_MODE_RAD_RF5112;
442 clock = AR5K_PHY_PLL_RF5112;
444 mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
445 clock = AR5K_PHY_PLL_RF5111; /*Zero*/
448 if (flags & CHANNEL_2GHZ) {
449 mode |= AR5K_PHY_MODE_FREQ_2GHZ;
450 clock |= AR5K_PHY_PLL_44MHZ;
452 if (flags & CHANNEL_CCK) {
453 mode |= AR5K_PHY_MODE_MOD_CCK;
454 } else if (flags & CHANNEL_OFDM) {
455 /* XXX Dynamic OFDM/CCK is not supported by the
456 * AR5211 so we set MOD_OFDM for plain g (no
457 * CCK headers) operation. We need to test
458 * this, 5211 might support ofdm-only g after
459 * all, there are also initial register values
460 * in the code for g mode (see initvals.c). */
461 if (ah->ah_version == AR5K_AR5211)
462 mode |= AR5K_PHY_MODE_MOD_OFDM;
464 mode |= AR5K_PHY_MODE_MOD_DYN;
467 "invalid radio modulation mode\n");
470 } else if (flags & CHANNEL_5GHZ) {
471 mode |= AR5K_PHY_MODE_FREQ_5GHZ;
472 clock |= AR5K_PHY_PLL_40MHZ;
474 if (flags & CHANNEL_OFDM)
475 mode |= AR5K_PHY_MODE_MOD_OFDM;
478 "invalid radio modulation mode\n");
482 ATH5K_ERR(ah->ah_sc, "invalid radio frequency mode\n");
486 if (flags & CHANNEL_TURBO)
487 turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
488 } else { /* Reset the device */
490 /* ...enable Atheros turbo mode if requested */
491 if (flags & CHANNEL_TURBO)
492 ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
496 /* reseting PCI on PCI-E cards results card to hang
497 * and always return 0xffff... so we ingore that flag
499 bus_flags = (pdev->is_pcie) ? 0 : AR5K_RESET_CTL_PCI;
502 ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
503 AR5K_RESET_CTL_BASEBAND | bus_flags);
505 ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip\n");
509 if (ah->ah_version == AR5K_AR5210)
512 /* ...wakeup again!*/
513 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
515 ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
519 /* ...final warm reset */
520 if (ath5k_hw_nic_reset(ah, 0)) {
521 ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
525 if (ah->ah_version != AR5K_AR5210) {
526 /* ...set the PHY operating mode */
527 ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
530 ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
531 ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
538 * Get the rate table for a specific operation mode
540 const struct ath5k_rate_table *ath5k_hw_get_rate_table(struct ath5k_hw *ah,
543 ATH5K_TRACE(ah->ah_sc);
545 if (!test_bit(mode, ah->ah_capabilities.cap_mode))
548 /* Get rate tables */
551 return &ath5k_rt_11a;
552 case AR5K_MODE_11A_TURBO:
553 return &ath5k_rt_turbo;
555 return &ath5k_rt_11b;
557 return &ath5k_rt_11g;
558 case AR5K_MODE_11G_TURBO:
566 * Free the ath5k_hw struct
568 void ath5k_hw_detach(struct ath5k_hw *ah)
570 ATH5K_TRACE(ah->ah_sc);
572 __set_bit(ATH_STAT_INVALID, ah->ah_sc->status);
574 if (ah->ah_rf_banks != NULL)
575 kfree(ah->ah_rf_banks);
577 /* assume interrupts are down */
581 /****************************\
582 Reset function and helpers
583 \****************************/
586 * ath5k_hw_write_ofdm_timings - set OFDM timings on AR5212
588 * @ah: the &struct ath5k_hw
589 * @channel: the currently set channel upon reset
591 * Write the OFDM timings for the AR5212 upon reset. This is a helper for
592 * ath5k_hw_reset(). This seems to tune the PLL a specified frequency
593 * depending on the bandwidth of the channel.
596 static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
597 struct ieee80211_channel *channel)
599 /* Get exponent and mantissa and set it */
600 u32 coef_scaled, coef_exp, coef_man,
601 ds_coef_exp, ds_coef_man, clock;
603 if (!(ah->ah_version == AR5K_AR5212) ||
604 !(channel->hw_value & CHANNEL_OFDM))
607 /* Seems there are two PLLs, one for baseband sampling and one
608 * for tuning. Tuning basebands are 40 MHz or 80MHz when in
610 clock = channel->hw_value & CHANNEL_TURBO ? 80 : 40;
611 coef_scaled = ((5 * (clock << 24)) / 2) /
612 channel->center_freq;
614 for (coef_exp = 31; coef_exp > 0; coef_exp--)
615 if ((coef_scaled >> coef_exp) & 0x1)
621 coef_exp = 14 - (coef_exp - 24);
622 coef_man = coef_scaled +
623 (1 << (24 - coef_exp - 1));
624 ds_coef_man = coef_man >> (24 - coef_exp);
625 ds_coef_exp = coef_exp - 16;
627 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
628 AR5K_PHY_TIMING_3_DSC_MAN, ds_coef_man);
629 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
630 AR5K_PHY_TIMING_3_DSC_EXP, ds_coef_exp);
636 * ath5k_hw_write_rate_duration - set rate duration during hw resets
638 * @ah: the &struct ath5k_hw
639 * @mode: one of enum ath5k_driver_mode
641 * Write the rate duration table for the current mode upon hw reset. This
642 * is a helper for ath5k_hw_reset(). It seems all this is doing is setting
643 * an ACK timeout for the hardware for the current mode for each rate. The
644 * rates which are capable of short preamble (802.11b rates 2Mbps, 5.5Mbps,
645 * and 11Mbps) have another register for the short preamble ACK timeout
649 static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
652 struct ath5k_softc *sc = ah->ah_sc;
653 const struct ath5k_rate_table *rt;
654 struct ieee80211_rate srate = {};
657 /* Get rate table for the current operating mode */
658 rt = ath5k_hw_get_rate_table(ah, mode);
660 /* Write rate duration table */
661 for (i = 0; i < rt->rate_count; i++) {
662 const struct ath5k_rate *rate, *control_rate;
667 rate = &rt->rates[i];
668 control_rate = &rt->rates[rate->control_rate];
670 /* Set ACK timeout */
671 reg = AR5K_RATE_DUR(rate->rate_code);
673 srate.bitrate = control_rate->rate_kbps/100;
675 /* An ACK frame consists of 10 bytes. If you add the FCS,
676 * which ieee80211_generic_frame_duration() adds,
677 * its 14 bytes. Note we use the control rate and not the
678 * actual rate for this rate. See mac80211 tx.c
679 * ieee80211_duration() for a brief description of
680 * what rate we should choose to TX ACKs. */
681 tx_time = le16_to_cpu(ieee80211_generic_frame_duration(sc->hw,
682 sc->vif, 10, &srate));
684 ath5k_hw_reg_write(ah, tx_time, reg);
686 if (!HAS_SHPREAMBLE(i))
690 * We're not distinguishing short preamble here,
691 * This is true, all we'll get is a longer value here
692 * which is not necessarilly bad. We could use
693 * export ieee80211_frame_duration() but that needs to be
694 * fixed first to be properly used by mac802111 drivers:
696 * - remove erp stuff and let the routine figure ofdm
698 * - remove passing argument ieee80211_local as
699 * drivers don't have access to it
700 * - move drivers using ieee80211_generic_frame_duration()
703 ath5k_hw_reg_write(ah, tx_time,
704 reg + (AR5K_SET_SHORT_PREAMBLE << 2));
709 * Main reset function
711 int ath5k_hw_reset(struct ath5k_hw *ah, enum ieee80211_if_types op_mode,
712 struct ieee80211_channel *channel, bool change_channel)
714 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
715 struct pci_dev *pdev = ah->ah_sc->pdev;
716 u32 data, s_seq, s_ant, s_led[3], dma_size;
717 unsigned int i, mode, freq, ee_mode, ant[2];
720 ATH5K_TRACE(ah->ah_sc);
729 * Save some registers before a reset
731 /*DCU/Antenna selection not available on 5210*/
732 if (ah->ah_version != AR5K_AR5210) {
733 if (change_channel) {
734 /* Seq number for queue 0 -do this for all queues ? */
735 s_seq = ath5k_hw_reg_read(ah,
736 AR5K_QUEUE_DFS_SEQNUM(0));
738 s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
743 s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) & AR5K_PCICFG_LEDSTATE;
744 s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
745 s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
747 if (change_channel && ah->ah_rf_banks != NULL)
748 ath5k_hw_get_rf_gain(ah);
751 /*Wakeup the device*/
752 ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, false);
757 * Initialize operating mode
759 ah->ah_op_mode = op_mode;
763 * 5210 only comes with RF5110
765 if (ah->ah_version != AR5K_AR5210) {
766 if (ah->ah_radio != AR5K_RF5111 &&
767 ah->ah_radio != AR5K_RF5112 &&
768 ah->ah_radio != AR5K_RF5413 &&
769 ah->ah_radio != AR5K_RF2413 &&
770 ah->ah_radio != AR5K_RF2425) {
772 "invalid phy radio: %u\n", ah->ah_radio);
776 switch (channel->hw_value & CHANNEL_MODES) {
778 mode = AR5K_MODE_11A;
779 freq = AR5K_INI_RFGAIN_5GHZ;
780 ee_mode = AR5K_EEPROM_MODE_11A;
783 mode = AR5K_MODE_11G;
784 freq = AR5K_INI_RFGAIN_2GHZ;
785 ee_mode = AR5K_EEPROM_MODE_11G;
788 mode = AR5K_MODE_11B;
789 freq = AR5K_INI_RFGAIN_2GHZ;
790 ee_mode = AR5K_EEPROM_MODE_11B;
793 mode = AR5K_MODE_11A_TURBO;
794 freq = AR5K_INI_RFGAIN_5GHZ;
795 ee_mode = AR5K_EEPROM_MODE_11A;
797 /*Is this ok on 5211 too ?*/
799 mode = AR5K_MODE_11G_TURBO;
800 freq = AR5K_INI_RFGAIN_2GHZ;
801 ee_mode = AR5K_EEPROM_MODE_11G;
804 if (ah->ah_version == AR5K_AR5211) {
806 "XR mode not available on 5211");
810 freq = AR5K_INI_RFGAIN_5GHZ;
811 ee_mode = AR5K_EEPROM_MODE_11A;
815 "invalid channel: %d\n", channel->center_freq);
819 /* PHY access enable */
820 ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
824 ret = ath5k_hw_write_initvals(ah, mode, change_channel);
831 if (ah->ah_version != AR5K_AR5210) {
833 * Write initial RF gain settings
834 * This should work for both 5111/5112
836 ret = ath5k_hw_rfgain(ah, freq);
843 * Write some more initial register settings
845 if (ah->ah_version == AR5K_AR5212) {
846 ath5k_hw_reg_write(ah, 0x0002a002, AR5K_PHY(11));
848 if (channel->hw_value == CHANNEL_G)
849 if (ah->ah_mac_srev < AR5K_SREV_VER_AR2413)
850 ath5k_hw_reg_write(ah, 0x00f80d80,
852 else if (ah->ah_mac_srev < AR5K_SREV_VER_AR2424)
853 ath5k_hw_reg_write(ah, 0x00380140,
855 else if (ah->ah_mac_srev < AR5K_SREV_VER_AR2425)
856 ath5k_hw_reg_write(ah, 0x00fc0ec0,
859 ath5k_hw_reg_write(ah, 0x00fc0fc0,
862 ath5k_hw_reg_write(ah, 0x00000000,
865 ath5k_hw_reg_write(ah, 0x000009b5, 0xa228);
866 ath5k_hw_reg_write(ah, 0x0000000f, 0x8060);
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);
885 * Set TX power (FIXME)
887 ret = ath5k_hw_txpower(ah, channel, AR5K_TUNE_DEFAULT_TXPOWER);
891 /* Write rate duration table only on AR5212 and if
892 * virtual interface has already been brought up
893 * XXX: rethink this after new mode changes to
894 * mac80211 are integrated */
895 if (ah->ah_version == AR5K_AR5212 &&
896 ah->ah_sc->vif != NULL)
897 ath5k_hw_write_rate_duration(ah, mode);
901 * TODO:Does this work on 5211 (5111) ?
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(0x44),
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(0x11),
971 (ee->ee_switch_settling[ee_mode] << 7) & 0x3f80,
973 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x12),
974 (ee->ee_ant_tx_rx[ee_mode] << 12) & 0x3f000,
976 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x14),
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(0x0d));
987 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x0a),
988 ee->ee_tx_end2xlna_enable[ee_mode] << 8, 0xffff00ff);
989 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x19),
990 (ee->ee_thr_62[ee_mode] << 12) & 0x7f000, 0xfff80fff);
991 AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x49), 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 * 5111/5112 Specific
1068 if (ah->ah_version != AR5K_AR5210) {
1069 data = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
1070 AR5K_PHY_RX_DELAY_M;
1071 data = (channel->hw_value & CHANNEL_CCK) ?
1072 ((data << 2) / 22) : (data / 10);
1080 * Enable calibration and wait until completion
1082 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
1083 AR5K_PHY_AGCCTL_CAL);
1085 if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
1086 AR5K_PHY_AGCCTL_CAL, 0, false)) {
1087 ATH5K_ERR(ah->ah_sc, "calibration timeout (%uMHz)\n",
1088 channel->center_freq);
1092 ret = ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
1096 ah->ah_calibration = false;
1098 /* A and G modes can use QAM modulation which requires enabling
1099 * I and Q calibration. Don't bother in B mode. */
1100 if (!(mode == AR5K_MODE_11B)) {
1101 ah->ah_calibration = true;
1102 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
1103 AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
1104 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
1109 * Reset queues and start beacon timers at the end of the reset routine
1111 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
1113 if (ah->ah_version != AR5K_AR5210)
1114 AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(i), i);
1116 ret = ath5k_hw_reset_tx_queue(ah, i);
1118 ATH5K_ERR(ah->ah_sc,
1119 "failed to reset TX queue #%d\n", i);
1124 /* Pre-enable interrupts on 5211/5212*/
1125 if (ah->ah_version != AR5K_AR5210)
1126 ath5k_hw_set_intr(ah, AR5K_INT_RX | AR5K_INT_TX |
1130 * Set RF kill flags if supported by the device (read from the EEPROM)
1131 * Disable gpio_intr for now since it results system hang.
1132 * TODO: Handle this in ath5k_intr
1135 if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header)) {
1136 ath5k_hw_set_gpio_input(ah, 0);
1137 ah->ah_gpio[0] = ath5k_hw_get_gpio(ah, 0);
1138 if (ah->ah_gpio[0] == 0)
1139 ath5k_hw_set_gpio_intr(ah, 0, 1);
1141 ath5k_hw_set_gpio_intr(ah, 0, 0);
1146 * Set the 32MHz reference clock on 5212 phy clock sleep register
1148 * TODO: Find out how to switch to external 32Khz clock to save power
1150 if (ah->ah_version == AR5K_AR5212) {
1151 ath5k_hw_reg_write(ah, AR5K_PHY_SCR_32MHZ, AR5K_PHY_SCR);
1152 ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
1153 ath5k_hw_reg_write(ah, AR5K_PHY_SCAL_32MHZ, AR5K_PHY_SCAL);
1154 ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
1155 ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
1156 ath5k_hw_reg_write(ah, ah->ah_phy_spending, AR5K_PHY_SPENDING);
1159 if (ah->ah_version == AR5K_AR5212) {
1160 ath5k_hw_reg_write(ah, 0x000100aa, 0x8118);
1161 ath5k_hw_reg_write(ah, 0x00003210, 0x811c);
1162 ath5k_hw_reg_write(ah, 0x00000052, 0x8108);
1163 if (ah->ah_mac_srev >= AR5K_SREV_VER_AR2413)
1164 ath5k_hw_reg_write(ah, 0x00000004, 0x8120);
1168 * Disable beacons and reset the register
1170 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
1171 AR5K_BEACON_RESET_TSF);
1179 static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
1182 u32 mask = val ? val : ~0U;
1184 ATH5K_TRACE(ah->ah_sc);
1186 /* Read-and-clear RX Descriptor Pointer*/
1187 ath5k_hw_reg_read(ah, AR5K_RXDP);
1190 * Reset the device and wait until success
1192 ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
1194 /* Wait at least 128 PCI clocks */
1197 if (ah->ah_version == AR5K_AR5210) {
1198 val &= AR5K_RESET_CTL_CHIP;
1199 mask &= AR5K_RESET_CTL_CHIP;
1201 val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1202 mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
1205 ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, false);
1208 * Reset configuration register (for hw byte-swap). Note that this
1209 * is only set for big endian. We do the necessary magic in
1212 if ((val & AR5K_RESET_CTL_PCU) == 0)
1213 ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
1219 * Power management functions
1225 int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
1226 bool set_chip, u16 sleep_duration)
1231 ATH5K_TRACE(ah->ah_sc);
1232 staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
1236 staid &= ~AR5K_STA_ID1_DEFAULT_ANTENNA;
1238 case AR5K_PM_NETWORK_SLEEP:
1240 ath5k_hw_reg_write(ah,
1241 AR5K_SLEEP_CTL_SLE | sleep_duration,
1244 staid |= AR5K_STA_ID1_PWR_SV;
1247 case AR5K_PM_FULL_SLEEP:
1249 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_SLP,
1252 staid |= AR5K_STA_ID1_PWR_SV;
1259 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1262 for (i = 5000; i > 0; i--) {
1263 /* Check if the chip did wake up */
1264 if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
1265 AR5K_PCICFG_SPWR_DN) == 0)
1268 /* Wait a bit and retry */
1270 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
1274 /* Fail if the chip didn't wake up */
1278 staid &= ~AR5K_STA_ID1_PWR_SV;
1286 ah->ah_power_mode = mode;
1287 ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
1292 /***********************\
1293 DMA Related Functions
1294 \***********************/
1303 void ath5k_hw_start_rx(struct ath5k_hw *ah)
1305 ATH5K_TRACE(ah->ah_sc);
1306 ath5k_hw_reg_write(ah, AR5K_CR_RXE, AR5K_CR);
1312 int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
1316 ATH5K_TRACE(ah->ah_sc);
1317 ath5k_hw_reg_write(ah, AR5K_CR_RXD, AR5K_CR);
1320 * It may take some time to disable the DMA receive unit
1322 for (i = 2000; i > 0 &&
1323 (ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_CR_RXE) != 0;
1327 return i ? 0 : -EBUSY;
1331 * Get the address of the RX Descriptor
1333 u32 ath5k_hw_get_rx_buf(struct ath5k_hw *ah)
1335 return ath5k_hw_reg_read(ah, AR5K_RXDP);
1339 * Set the address of the RX Descriptor
1341 void ath5k_hw_put_rx_buf(struct ath5k_hw *ah, u32 phys_addr)
1343 ATH5K_TRACE(ah->ah_sc);
1345 /*TODO:Shouldn't we check if RX is enabled first ?*/
1346 ath5k_hw_reg_write(ah, phys_addr, AR5K_RXDP);
1350 * Transmit functions
1354 * Start DMA transmit for a specific queue
1355 * (see also QCU/DCU functions)
1357 int ath5k_hw_tx_start(struct ath5k_hw *ah, unsigned int queue)
1361 ATH5K_TRACE(ah->ah_sc);
1362 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1364 /* Return if queue is declared inactive */
1365 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1368 if (ah->ah_version == AR5K_AR5210) {
1369 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1372 * Set the queue by type on 5210
1374 switch (ah->ah_txq[queue].tqi_type) {
1375 case AR5K_TX_QUEUE_DATA:
1376 tx_queue |= AR5K_CR_TXE0 & ~AR5K_CR_TXD0;
1378 case AR5K_TX_QUEUE_BEACON:
1379 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1380 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
1383 case AR5K_TX_QUEUE_CAB:
1384 tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
1385 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1FV | AR5K_BCR_TQ1V |
1386 AR5K_BCR_BDMAE, AR5K_BSR);
1392 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1394 /* Return if queue is disabled */
1395 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXD, queue))
1399 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXE, queue);
1406 * Stop DMA transmit for a specific queue
1407 * (see also QCU/DCU functions)
1409 int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue)
1411 unsigned int i = 100;
1412 u32 tx_queue, pending;
1414 ATH5K_TRACE(ah->ah_sc);
1415 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1417 /* Return if queue is declared inactive */
1418 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
1421 if (ah->ah_version == AR5K_AR5210) {
1422 tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
1427 switch (ah->ah_txq[queue].tqi_type) {
1428 case AR5K_TX_QUEUE_DATA:
1429 tx_queue |= AR5K_CR_TXD0 & ~AR5K_CR_TXE0;
1431 case AR5K_TX_QUEUE_BEACON:
1432 case AR5K_TX_QUEUE_CAB:
1434 tx_queue |= AR5K_CR_TXD1 & ~AR5K_CR_TXD1;
1435 ath5k_hw_reg_write(ah, 0, AR5K_BSR);
1442 ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
1443 ath5k_hw_reg_read(ah, AR5K_CR);
1446 * Schedule TX disable and wait until queue is empty
1448 AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXD, queue);
1450 /*Check for pending frames*/
1452 pending = ath5k_hw_reg_read(ah,
1453 AR5K_QUEUE_STATUS(queue)) &
1454 AR5K_QCU_STS_FRMPENDCNT;
1456 } while (--i && pending);
1458 /* Clear register */
1459 ath5k_hw_reg_write(ah, 0, AR5K_QCU_TXD);
1464 /* TODO: Check for success else return error */
1469 * Get the address of the TX Descriptor for a specific queue
1470 * (see also QCU/DCU functions)
1472 u32 ath5k_hw_get_tx_buf(struct ath5k_hw *ah, unsigned int queue)
1476 ATH5K_TRACE(ah->ah_sc);
1477 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1480 * Get the transmit queue descriptor pointer from the selected queue
1482 /*5210 doesn't have QCU*/
1483 if (ah->ah_version == AR5K_AR5210) {
1484 switch (ah->ah_txq[queue].tqi_type) {
1485 case AR5K_TX_QUEUE_DATA:
1486 tx_reg = AR5K_NOQCU_TXDP0;
1488 case AR5K_TX_QUEUE_BEACON:
1489 case AR5K_TX_QUEUE_CAB:
1490 tx_reg = AR5K_NOQCU_TXDP1;
1496 tx_reg = AR5K_QUEUE_TXDP(queue);
1499 return ath5k_hw_reg_read(ah, tx_reg);
1503 * Set the address of the TX Descriptor for a specific queue
1504 * (see also QCU/DCU functions)
1506 int ath5k_hw_put_tx_buf(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
1510 ATH5K_TRACE(ah->ah_sc);
1511 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
1514 * Set the transmit queue descriptor pointer register by type
1517 if (ah->ah_version == AR5K_AR5210) {
1518 switch (ah->ah_txq[queue].tqi_type) {
1519 case AR5K_TX_QUEUE_DATA:
1520 tx_reg = AR5K_NOQCU_TXDP0;
1522 case AR5K_TX_QUEUE_BEACON:
1523 case AR5K_TX_QUEUE_CAB:
1524 tx_reg = AR5K_NOQCU_TXDP1;
1531 * Set the transmit queue descriptor pointer for
1532 * the selected queue on QCU for 5211+
1533 * (this won't work if the queue is still active)
1535 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
1538 tx_reg = AR5K_QUEUE_TXDP(queue);
1541 /* Set descriptor pointer */
1542 ath5k_hw_reg_write(ah, phys_addr, tx_reg);
1548 * Update tx trigger level
1550 int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase)
1552 u32 trigger_level, imr;
1555 ATH5K_TRACE(ah->ah_sc);
1558 * Disable interrupts by setting the mask
1560 imr = ath5k_hw_set_intr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
1562 /*TODO: Boundary check on trigger_level*/
1563 trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
1567 if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
1571 ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
1574 * Update trigger level on success
1576 if (ah->ah_version == AR5K_AR5210)
1577 ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
1579 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
1580 AR5K_TXCFG_TXFULL, trigger_level);
1586 * Restore interrupt mask
1588 ath5k_hw_set_intr(ah, imr);
1594 * Interrupt handling
1598 * Check if we have pending interrupts
1600 bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
1602 ATH5K_TRACE(ah->ah_sc);
1603 return ath5k_hw_reg_read(ah, AR5K_INTPEND);
1607 * Get interrupt mask (ISR)
1609 int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
1613 ATH5K_TRACE(ah->ah_sc);
1616 * Read interrupt status from the Interrupt Status register
1619 if (ah->ah_version == AR5K_AR5210) {
1620 data = ath5k_hw_reg_read(ah, AR5K_ISR);
1621 if (unlikely(data == AR5K_INT_NOCARD)) {
1622 *interrupt_mask = data;
1627 * Read interrupt status from the Read-And-Clear shadow register
1628 * Note: PISR/SISR Not available on 5210
1630 data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
1634 * Get abstract interrupt mask (driver-compatible)
1636 *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
1638 if (unlikely(data == AR5K_INT_NOCARD))
1641 if (data & (AR5K_ISR_RXOK | AR5K_ISR_RXERR))
1642 *interrupt_mask |= AR5K_INT_RX;
1644 if (data & (AR5K_ISR_TXOK | AR5K_ISR_TXERR
1645 | AR5K_ISR_TXDESC | AR5K_ISR_TXEOL))
1646 *interrupt_mask |= AR5K_INT_TX;
1648 if (ah->ah_version != AR5K_AR5210) {
1649 /*HIU = Host Interface Unit (PCI etc)*/
1650 if (unlikely(data & (AR5K_ISR_HIUERR)))
1651 *interrupt_mask |= AR5K_INT_FATAL;
1653 /*Beacon Not Ready*/
1654 if (unlikely(data & (AR5K_ISR_BNR)))
1655 *interrupt_mask |= AR5K_INT_BNR;
1659 * XXX: BMISS interrupts may occur after association.
1660 * I found this on 5210 code but it needs testing. If this is
1661 * true we should disable them before assoc and re-enable them
1662 * after a successfull assoc + some jiffies.
1665 interrupt_mask &= ~AR5K_INT_BMISS;
1669 * In case we didn't handle anything,
1670 * print the register value.
1672 if (unlikely(*interrupt_mask == 0 && net_ratelimit()))
1673 ATH5K_PRINTF("0x%08x\n", data);
1679 * Set interrupt mask
1681 enum ath5k_int ath5k_hw_set_intr(struct ath5k_hw *ah, enum ath5k_int new_mask)
1683 enum ath5k_int old_mask, int_mask;
1686 * Disable card interrupts to prevent any race conditions
1687 * (they will be re-enabled afterwards).
1689 ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
1691 old_mask = ah->ah_imr;
1694 * Add additional, chipset-dependent interrupt mask flags
1695 * and write them to the IMR (interrupt mask register).
1697 int_mask = new_mask & AR5K_INT_COMMON;
1699 if (new_mask & AR5K_INT_RX)
1700 int_mask |= AR5K_IMR_RXOK | AR5K_IMR_RXERR | AR5K_IMR_RXORN |
1703 if (new_mask & AR5K_INT_TX)
1704 int_mask |= AR5K_IMR_TXOK | AR5K_IMR_TXERR | AR5K_IMR_TXDESC |
1707 if (ah->ah_version != AR5K_AR5210) {
1708 if (new_mask & AR5K_INT_FATAL) {
1709 int_mask |= AR5K_IMR_HIUERR;
1710 AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_MCABT |
1711 AR5K_SIMR2_SSERR | AR5K_SIMR2_DPERR);
1715 ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
1717 /* Store new interrupt mask */
1718 ah->ah_imr = new_mask;
1720 /* ..re-enable interrupts */
1721 ath5k_hw_reg_write(ah, AR5K_IER_ENABLE, AR5K_IER);
1722 ath5k_hw_reg_read(ah, AR5K_IER);
1728 /*************************\
1729 EEPROM access functions
1730 \*************************/
1735 static int ath5k_hw_eeprom_read(struct ath5k_hw *ah, u32 offset, u16 *data)
1737 u32 status, timeout;
1739 ATH5K_TRACE(ah->ah_sc);
1741 * Initialize EEPROM access
1743 if (ah->ah_version == AR5K_AR5210) {
1744 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1745 (void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset));
1747 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1748 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1749 AR5K_EEPROM_CMD_READ);
1752 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1753 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1754 if (status & AR5K_EEPROM_STAT_RDDONE) {
1755 if (status & AR5K_EEPROM_STAT_RDERR)
1757 *data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) &
1768 * Write to eeprom - currently disabled, use at your own risk
1771 static int ath5k_hw_eeprom_write(struct ath5k_hw *ah, u32 offset, u16 data)
1774 u32 status, timeout;
1776 ATH5K_TRACE(ah->ah_sc);
1779 * Initialize eeprom access
1782 if (ah->ah_version == AR5K_AR5210) {
1783 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
1785 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1786 AR5K_EEPROM_CMD_RESET);
1790 * Write data to data register
1793 if (ah->ah_version == AR5K_AR5210) {
1794 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_BASE + (4 * offset));
1796 ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
1797 ath5k_hw_reg_write(ah, data, AR5K_EEPROM_DATA);
1798 AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
1799 AR5K_EEPROM_CMD_WRITE);
1806 for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
1807 status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
1808 if (status & AR5K_EEPROM_STAT_WRDONE) {
1809 if (status & AR5K_EEPROM_STAT_WRERR)
1816 ATH5K_ERR(ah->ah_sc, "EEPROM Write is disabled!");
1822 * Translate binary channel representation in EEPROM to frequency
1824 static u16 ath5k_eeprom_bin2freq(struct ath5k_hw *ah, u16 bin, unsigned int mode)
1828 if (bin == AR5K_EEPROM_CHANNEL_DIS)
1831 if (mode == AR5K_EEPROM_MODE_11A) {
1832 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1833 val = (5 * bin) + 4800;
1835 val = bin > 62 ? (10 * 62) + (5 * (bin - 62)) + 5100 :
1838 if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
1848 * Read antenna infos from eeprom
1850 static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
1853 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1858 AR5K_EEPROM_READ(o++, val);
1859 ee->ee_switch_settling[mode] = (val >> 8) & 0x7f;
1860 ee->ee_ant_tx_rx[mode] = (val >> 2) & 0x3f;
1861 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1863 AR5K_EEPROM_READ(o++, val);
1864 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1865 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1866 ee->ee_ant_control[mode][i++] = val & 0x3f;
1868 AR5K_EEPROM_READ(o++, val);
1869 ee->ee_ant_control[mode][i++] = (val >> 10) & 0x3f;
1870 ee->ee_ant_control[mode][i++] = (val >> 4) & 0x3f;
1871 ee->ee_ant_control[mode][i] = (val << 2) & 0x3f;
1873 AR5K_EEPROM_READ(o++, val);
1874 ee->ee_ant_control[mode][i++] |= (val >> 14) & 0x3;
1875 ee->ee_ant_control[mode][i++] = (val >> 8) & 0x3f;
1876 ee->ee_ant_control[mode][i++] = (val >> 2) & 0x3f;
1877 ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
1879 AR5K_EEPROM_READ(o++, val);
1880 ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
1881 ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
1882 ee->ee_ant_control[mode][i++] = val & 0x3f;
1884 /* Get antenna modes */
1885 ah->ah_antenna[mode][0] =
1886 (ee->ee_ant_control[mode][0] << 4) | 0x1;
1887 ah->ah_antenna[mode][AR5K_ANT_FIXED_A] =
1888 ee->ee_ant_control[mode][1] |
1889 (ee->ee_ant_control[mode][2] << 6) |
1890 (ee->ee_ant_control[mode][3] << 12) |
1891 (ee->ee_ant_control[mode][4] << 18) |
1892 (ee->ee_ant_control[mode][5] << 24);
1893 ah->ah_antenna[mode][AR5K_ANT_FIXED_B] =
1894 ee->ee_ant_control[mode][6] |
1895 (ee->ee_ant_control[mode][7] << 6) |
1896 (ee->ee_ant_control[mode][8] << 12) |
1897 (ee->ee_ant_control[mode][9] << 18) |
1898 (ee->ee_ant_control[mode][10] << 24);
1900 /* return new offset */
1907 * Read supported modes from eeprom
1909 static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset,
1912 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1917 AR5K_EEPROM_READ(o++, val);
1918 ee->ee_tx_end2xlna_enable[mode] = (val >> 8) & 0xff;
1919 ee->ee_thr_62[mode] = val & 0xff;
1921 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1922 ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28;
1924 AR5K_EEPROM_READ(o++, val);
1925 ee->ee_tx_end2xpa_disable[mode] = (val >> 8) & 0xff;
1926 ee->ee_tx_frm2xpa_enable[mode] = val & 0xff;
1928 AR5K_EEPROM_READ(o++, val);
1929 ee->ee_pga_desired_size[mode] = (val >> 8) & 0xff;
1931 if ((val & 0xff) & 0x80)
1932 ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1);
1934 ee->ee_noise_floor_thr[mode] = val & 0xff;
1936 if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
1937 ee->ee_noise_floor_thr[mode] =
1938 mode == AR5K_EEPROM_MODE_11A ? -54 : -1;
1940 AR5K_EEPROM_READ(o++, val);
1941 ee->ee_xlna_gain[mode] = (val >> 5) & 0xff;
1942 ee->ee_x_gain[mode] = (val >> 1) & 0xf;
1943 ee->ee_xpd[mode] = val & 0x1;
1945 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0)
1946 ee->ee_fixed_bias[mode] = (val >> 13) & 0x1;
1948 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) {
1949 AR5K_EEPROM_READ(o++, val);
1950 ee->ee_false_detect[mode] = (val >> 6) & 0x7f;
1952 if (mode == AR5K_EEPROM_MODE_11A)
1953 ee->ee_xr_power[mode] = val & 0x3f;
1955 ee->ee_ob[mode][0] = val & 0x7;
1956 ee->ee_db[mode][0] = (val >> 3) & 0x7;
1960 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) {
1961 ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN;
1962 ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA;
1964 ee->ee_i_gain[mode] = (val >> 13) & 0x7;
1966 AR5K_EEPROM_READ(o++, val);
1967 ee->ee_i_gain[mode] |= (val << 3) & 0x38;
1969 if (mode == AR5K_EEPROM_MODE_11G)
1970 ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff;
1973 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
1974 mode == AR5K_EEPROM_MODE_11A) {
1975 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
1976 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
1979 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6 &&
1980 mode == AR5K_EEPROM_MODE_11G)
1981 ee->ee_scaled_cck_delta = (val >> 11) & 0x1f;
1983 /* return new offset */
1990 * Initialize eeprom & capabilities structs
1992 static int ath5k_eeprom_init(struct ath5k_hw *ah)
1994 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1995 unsigned int mode, i;
2000 /* Initial TX thermal adjustment values */
2002 ee->ee_pwd_84 = ee->ee_pwd_90 = 1;
2003 ee->ee_gain_select = 1;
2006 * Read values from EEPROM and store them in the capability structure
2008 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC, ee_magic);
2009 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT, ee_protect);
2010 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN, ee_regdomain);
2011 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION, ee_version);
2012 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR, ee_header);
2014 /* Return if we have an old EEPROM */
2015 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_0)
2020 * Validate the checksum of the EEPROM date. There are some
2021 * devices with invalid EEPROMs.
2023 for (cksum = 0, offset = 0; offset < AR5K_EEPROM_INFO_MAX; offset++) {
2024 AR5K_EEPROM_READ(AR5K_EEPROM_INFO(offset), val);
2027 if (cksum != AR5K_EEPROM_INFO_CKSUM) {
2028 ATH5K_ERR(ah->ah_sc, "Invalid EEPROM checksum 0x%04x\n", cksum);
2033 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah->ah_ee_version),
2036 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2037 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0, ee_misc0);
2038 AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1, ee_misc1);
2041 if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_3) {
2042 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ, val);
2043 ee->ee_ob[AR5K_EEPROM_MODE_11B][0] = val & 0x7;
2044 ee->ee_db[AR5K_EEPROM_MODE_11B][0] = (val >> 3) & 0x7;
2046 AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ, val);
2047 ee->ee_ob[AR5K_EEPROM_MODE_11G][0] = val & 0x7;
2048 ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7;
2052 * Get conformance test limit values
2054 offset = AR5K_EEPROM_CTL(ah->ah_ee_version);
2055 ee->ee_ctls = AR5K_EEPROM_N_CTLS(ah->ah_ee_version);
2057 for (i = 0; i < ee->ee_ctls; i++) {
2058 AR5K_EEPROM_READ(offset++, val);
2059 ee->ee_ctl[i] = (val >> 8) & 0xff;
2060 ee->ee_ctl[i + 1] = val & 0xff;
2064 * Get values for 802.11a (5GHz)
2066 mode = AR5K_EEPROM_MODE_11A;
2068 ee->ee_turbo_max_power[mode] =
2069 AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header);
2071 offset = AR5K_EEPROM_MODES_11A(ah->ah_ee_version);
2073 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2077 AR5K_EEPROM_READ(offset++, val);
2078 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2079 ee->ee_ob[mode][3] = (val >> 5) & 0x7;
2080 ee->ee_db[mode][3] = (val >> 2) & 0x7;
2081 ee->ee_ob[mode][2] = (val << 1) & 0x7;
2083 AR5K_EEPROM_READ(offset++, val);
2084 ee->ee_ob[mode][2] |= (val >> 15) & 0x1;
2085 ee->ee_db[mode][2] = (val >> 12) & 0x7;
2086 ee->ee_ob[mode][1] = (val >> 9) & 0x7;
2087 ee->ee_db[mode][1] = (val >> 6) & 0x7;
2088 ee->ee_ob[mode][0] = (val >> 3) & 0x7;
2089 ee->ee_db[mode][0] = val & 0x7;
2091 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2095 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1) {
2096 AR5K_EEPROM_READ(offset++, val);
2097 ee->ee_margin_tx_rx[mode] = val & 0x3f;
2101 * Get values for 802.11b (2.4GHz)
2103 mode = AR5K_EEPROM_MODE_11B;
2104 offset = AR5K_EEPROM_MODES_11B(ah->ah_ee_version);
2106 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2110 AR5K_EEPROM_READ(offset++, val);
2111 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2112 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
2113 ee->ee_db[mode][1] = val & 0x7;
2115 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2119 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2120 AR5K_EEPROM_READ(offset++, val);
2121 ee->ee_cal_pier[mode][0] =
2122 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2123 ee->ee_cal_pier[mode][1] =
2124 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
2126 AR5K_EEPROM_READ(offset++, val);
2127 ee->ee_cal_pier[mode][2] =
2128 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2131 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
2132 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
2135 * Get values for 802.11g (2.4GHz)
2137 mode = AR5K_EEPROM_MODE_11G;
2138 offset = AR5K_EEPROM_MODES_11G(ah->ah_ee_version);
2140 ret = ath5k_eeprom_read_ants(ah, &offset, mode);
2144 AR5K_EEPROM_READ(offset++, val);
2145 ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
2146 ee->ee_ob[mode][1] = (val >> 4) & 0x7;
2147 ee->ee_db[mode][1] = val & 0x7;
2149 ret = ath5k_eeprom_read_modes(ah, &offset, mode);
2153 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
2154 AR5K_EEPROM_READ(offset++, val);
2155 ee->ee_cal_pier[mode][0] =
2156 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2157 ee->ee_cal_pier[mode][1] =
2158 ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
2160 AR5K_EEPROM_READ(offset++, val);
2161 ee->ee_turbo_max_power[mode] = val & 0x7f;
2162 ee->ee_xr_power[mode] = (val >> 7) & 0x3f;
2164 AR5K_EEPROM_READ(offset++, val);
2165 ee->ee_cal_pier[mode][2] =
2166 ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
2168 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
2169 ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
2171 AR5K_EEPROM_READ(offset++, val);
2172 ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
2173 ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
2175 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) {
2176 AR5K_EEPROM_READ(offset++, val);
2177 ee->ee_cck_ofdm_gain_delta = val & 0xff;
2182 * Read 5GHz EEPROM channels
2189 * Read the MAC address from eeprom
2191 static int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
2198 memset(mac, 0, ETH_ALEN);
2199 memset(mac_d, 0, ETH_ALEN);
2201 ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
2205 for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
2206 ret = ath5k_hw_eeprom_read(ah, offset, &data);
2211 mac_d[octet + 1] = data & 0xff;
2212 mac_d[octet] = data >> 8;
2216 memcpy(mac, mac_d, ETH_ALEN);
2218 if (!total || total == 3 * 0xffff)
2225 * Fill the capabilities struct
2227 static int ath5k_hw_get_capabilities(struct ath5k_hw *ah)
2231 ATH5K_TRACE(ah->ah_sc);
2232 /* Capabilities stored in the EEPROM */
2233 ee_header = ah->ah_capabilities.cap_eeprom.ee_header;
2235 if (ah->ah_version == AR5K_AR5210) {
2237 * Set radio capabilities
2238 * (The AR5110 only supports the middle 5GHz band)
2240 ah->ah_capabilities.cap_range.range_5ghz_min = 5120;
2241 ah->ah_capabilities.cap_range.range_5ghz_max = 5430;
2242 ah->ah_capabilities.cap_range.range_2ghz_min = 0;
2243 ah->ah_capabilities.cap_range.range_2ghz_max = 0;
2245 /* Set supported modes */
2246 __set_bit(AR5K_MODE_11A, ah->ah_capabilities.cap_mode);
2247 __set_bit(AR5K_MODE_11A_TURBO, ah->ah_capabilities.cap_mode);
2250 * XXX The tranceiver supports frequencies from 4920 to 6100GHz
2251 * XXX and from 2312 to 2732GHz. There are problems with the
2252 * XXX current ieee80211 implementation because the IEEE
2253 * XXX channel mapping does not support negative channel
2254 * XXX numbers (2312MHz is channel -19). Of course, this
2255 * XXX doesn't matter because these channels are out of range
2256 * XXX but some regulation domains like MKK (Japan) will
2257 * XXX support frequencies somewhere around 4.8GHz.
2261 * Set radio capabilities
2264 if (AR5K_EEPROM_HDR_11A(ee_header)) {
2265 ah->ah_capabilities.cap_range.range_5ghz_min = 5005; /* 4920 */
2266 ah->ah_capabilities.cap_range.range_5ghz_max = 6100;
2268 /* Set supported modes */
2269 __set_bit(AR5K_MODE_11A,
2270 ah->ah_capabilities.cap_mode);
2271 __set_bit(AR5K_MODE_11A_TURBO,
2272 ah->ah_capabilities.cap_mode);
2273 if (ah->ah_version == AR5K_AR5212)
2274 __set_bit(AR5K_MODE_11G_TURBO,
2275 ah->ah_capabilities.cap_mode);
2278 /* Enable 802.11b if a 2GHz capable radio (2111/5112) is
2280 if (AR5K_EEPROM_HDR_11B(ee_header) ||
2281 AR5K_EEPROM_HDR_11G(ee_header)) {
2282 ah->ah_capabilities.cap_range.range_2ghz_min = 2412; /* 2312 */
2283 ah->ah_capabilities.cap_range.range_2ghz_max = 2732;
2285 if (AR5K_EEPROM_HDR_11B(ee_header))
2286 __set_bit(AR5K_MODE_11B,
2287 ah->ah_capabilities.cap_mode);
2289 if (AR5K_EEPROM_HDR_11G(ee_header))
2290 __set_bit(AR5K_MODE_11G,
2291 ah->ah_capabilities.cap_mode);
2296 ah->ah_gpio_npins = AR5K_NUM_GPIO;
2298 /* Set number of supported TX queues */
2299 if (ah->ah_version == AR5K_AR5210)
2300 ah->ah_capabilities.cap_queues.q_tx_num =
2301 AR5K_NUM_TX_QUEUES_NOQCU;
2303 ah->ah_capabilities.cap_queues.q_tx_num = AR5K_NUM_TX_QUEUES;
2308 /*********************************\
2309 Protocol Control Unit Functions
2310 \*********************************/
2313 * Set Operation mode
2315 int ath5k_hw_set_opmode(struct ath5k_hw *ah)
2317 u32 pcu_reg, beacon_reg, low_id, high_id;
2322 ATH5K_TRACE(ah->ah_sc);
2324 switch (ah->ah_op_mode) {
2325 case IEEE80211_IF_TYPE_IBSS:
2326 pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_DESC_ANTENNA |
2327 (ah->ah_version == AR5K_AR5210 ?
2328 AR5K_STA_ID1_NO_PSPOLL : 0);
2329 beacon_reg |= AR5K_BCR_ADHOC;
2332 case IEEE80211_IF_TYPE_AP:
2333 pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_RTS_DEF_ANTENNA |
2334 (ah->ah_version == AR5K_AR5210 ?
2335 AR5K_STA_ID1_NO_PSPOLL : 0);
2336 beacon_reg |= AR5K_BCR_AP;
2339 case IEEE80211_IF_TYPE_STA:
2340 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2341 (ah->ah_version == AR5K_AR5210 ?
2342 AR5K_STA_ID1_PWR_SV : 0);
2343 case IEEE80211_IF_TYPE_MNTR:
2344 pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
2345 (ah->ah_version == AR5K_AR5210 ?
2346 AR5K_STA_ID1_NO_PSPOLL : 0);
2356 low_id = AR5K_LOW_ID(ah->ah_sta_id);
2357 high_id = AR5K_HIGH_ID(ah->ah_sta_id);
2358 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2359 ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
2362 * Set Beacon Control Register on 5210
2364 if (ah->ah_version == AR5K_AR5210)
2365 ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR);
2377 void ath5k_hw_get_lladdr(struct ath5k_hw *ah, u8 *mac)
2379 ATH5K_TRACE(ah->ah_sc);
2380 memcpy(mac, ah->ah_sta_id, ETH_ALEN);
2386 int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
2388 u32 low_id, high_id;
2390 ATH5K_TRACE(ah->ah_sc);
2391 /* Set new station ID */
2392 memcpy(ah->ah_sta_id, mac, ETH_ALEN);
2394 low_id = AR5K_LOW_ID(mac);
2395 high_id = AR5K_HIGH_ID(mac);
2397 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
2398 ath5k_hw_reg_write(ah, high_id, AR5K_STA_ID1);
2406 void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id)
2408 u32 low_id, high_id;
2412 * Set simple BSSID mask on 5212
2414 if (ah->ah_version == AR5K_AR5212) {
2415 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM0);
2416 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM1);
2420 * Set BSSID which triggers the "SME Join" operation
2422 low_id = AR5K_LOW_ID(bssid);
2423 high_id = AR5K_HIGH_ID(bssid);
2424 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_ID0);
2425 ath5k_hw_reg_write(ah, high_id | ((assoc_id & 0x3fff) <<
2426 AR5K_BSS_ID1_AID_S), AR5K_BSS_ID1);
2428 if (assoc_id == 0) {
2429 ath5k_hw_disable_pspoll(ah);
2433 AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM,
2434 tim_offset ? tim_offset + 4 : 0);
2436 ath5k_hw_enable_pspoll(ah, NULL, 0);
2439 * ath5k_hw_set_bssid_mask - set common bits we should listen to
2441 * The bssid_mask is a utility used by AR5212 hardware to inform the hardware
2442 * which bits of the interface's MAC address should be looked at when trying
2443 * to decide which packets to ACK. In station mode every bit matters. In AP
2444 * mode with a single BSS every bit matters as well. In AP mode with
2445 * multiple BSSes not every bit matters.
2447 * @ah: the &struct ath5k_hw
2448 * @mask: the bssid_mask, a u8 array of size ETH_ALEN
2450 * Note that this is a simple filter and *does* not filter out all
2451 * relevant frames. Some non-relevant frames will get through, probability
2452 * jocks are welcomed to compute.
2454 * When handling multiple BSSes (or VAPs) you can get the BSSID mask by
2455 * computing the set of:
2457 * ~ ( MAC XOR BSSID )
2459 * When you do this you are essentially computing the common bits. Later it
2460 * is assumed the harware will "and" (&) the BSSID mask with the MAC address
2461 * to obtain the relevant bits which should match on the destination frame.
2463 * Simple example: on your card you have have two BSSes you have created with
2464 * BSSID-01 and BSSID-02. Lets assume BSSID-01 will not use the MAC address.
2465 * There is another BSSID-03 but you are not part of it. For simplicity's sake,
2466 * assuming only 4 bits for a mac address and for BSSIDs you can then have:
2470 * BSSID-01: 0100 | --> Belongs to us
2473 * -------------------
2474 * BSSID-03: 0110 | --> External
2475 * -------------------
2477 * Our bssid_mask would then be:
2479 * On loop iteration for BSSID-01:
2480 * ~(0001 ^ 0100) -> ~(0101)
2484 * On loop iteration for BSSID-02:
2485 * bssid_mask &= ~(0001 ^ 1001)
2486 * bssid_mask = (1010) & ~(0001 ^ 1001)
2487 * bssid_mask = (1010) & ~(1001)
2488 * bssid_mask = (1010) & (0110)
2491 * A bssid_mask of 0010 means "only pay attention to the second least
2492 * significant bit". This is because its the only bit common
2493 * amongst the MAC and all BSSIDs we support. To findout what the real
2494 * common bit is we can simply "&" the bssid_mask now with any BSSID we have
2495 * or our MAC address (we assume the hardware uses the MAC address).
2497 * Now, suppose there's an incoming frame for BSSID-03:
2501 * An easy eye-inspeciton of this already should tell you that this frame
2502 * will not pass our check. This is beacuse the bssid_mask tells the
2503 * hardware to only look at the second least significant bit and the
2504 * common bit amongst the MAC and BSSIDs is 0, this frame has the 2nd LSB
2505 * as 1, which does not match 0.
2507 * So with IFRAME-01 we *assume* the hardware will do:
2509 * allow = (IFRAME-01 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2510 * --> allow = (0110 & 0010) == (0010 & 0001) ? 1 : 0;
2511 * --> allow = (0010) == 0000 ? 1 : 0;
2514 * Lets now test a frame that should work:
2516 * IFRAME-02: 0001 (we should allow)
2518 * allow = (0001 & 1010) == 1010
2520 * allow = (IFRAME-02 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
2521 * --> allow = (0001 & 0010) == (0010 & 0001) ? 1 :0;
2522 * --> allow = (0010) == (0010)
2527 * IFRAME-03: 0100 --> allowed
2528 * IFRAME-04: 1001 --> allowed
2529 * IFRAME-05: 1101 --> allowed but its not for us!!!
2532 int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
2534 u32 low_id, high_id;
2535 ATH5K_TRACE(ah->ah_sc);
2537 if (ah->ah_version == AR5K_AR5212) {
2538 low_id = AR5K_LOW_ID(mask);
2539 high_id = AR5K_HIGH_ID(mask);
2541 ath5k_hw_reg_write(ah, low_id, AR5K_BSS_IDM0);
2542 ath5k_hw_reg_write(ah, high_id, AR5K_BSS_IDM1);
2551 * Receive start/stop functions
2555 * Start receive on PCU
2557 void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
2559 ATH5K_TRACE(ah->ah_sc);
2560 AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
2562 /* TODO: ANI Support */
2566 * Stop receive on PCU
2568 void ath5k_hw_stop_pcu_recv(struct ath5k_hw *ah)
2570 ATH5K_TRACE(ah->ah_sc);
2571 AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
2573 /* TODO: ANI Support */
2577 * RX Filter functions
2581 * Set multicast filter
2583 void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
2585 ATH5K_TRACE(ah->ah_sc);
2586 /* Set the multicat filter */
2587 ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0);
2588 ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1);
2592 * Set multicast filter by index
2594 int ath5k_hw_set_mcast_filterindex(struct ath5k_hw *ah, u32 index)
2597 ATH5K_TRACE(ah->ah_sc);
2600 else if (index >= 32)
2601 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER1,
2602 (1 << (index - 32)));
2604 AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2610 * Clear Multicast filter by index
2612 int ath5k_hw_clear_mcast_filter_idx(struct ath5k_hw *ah, u32 index)
2615 ATH5K_TRACE(ah->ah_sc);
2618 else if (index >= 32)
2619 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER1,
2620 (1 << (index - 32)));
2622 AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
2628 * Get current rx filter
2630 u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah)
2632 u32 data, filter = 0;
2634 ATH5K_TRACE(ah->ah_sc);
2635 filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER);
2637 /*Radar detection for 5212*/
2638 if (ah->ah_version == AR5K_AR5212) {
2639 data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL);
2641 if (data & AR5K_PHY_ERR_FIL_RADAR)
2642 filter |= AR5K_RX_FILTER_RADARERR;
2643 if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK))
2644 filter |= AR5K_RX_FILTER_PHYERR;
2653 void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
2657 ATH5K_TRACE(ah->ah_sc);
2659 /* Set PHY error filter register on 5212*/
2660 if (ah->ah_version == AR5K_AR5212) {
2661 if (filter & AR5K_RX_FILTER_RADARERR)
2662 data |= AR5K_PHY_ERR_FIL_RADAR;
2663 if (filter & AR5K_RX_FILTER_PHYERR)
2664 data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK;
2668 * The AR5210 uses promiscous mode to detect radar activity
2670 if (ah->ah_version == AR5K_AR5210 &&
2671 (filter & AR5K_RX_FILTER_RADARERR)) {
2672 filter &= ~AR5K_RX_FILTER_RADARERR;
2673 filter |= AR5K_RX_FILTER_PROM;
2678 AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2680 AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
2682 /*Write RX Filter register*/
2683 ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER);
2685 /*Write PHY error filter register on 5212*/
2686 if (ah->ah_version == AR5K_AR5212)
2687 ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
2692 * Beacon related functions
2698 u32 ath5k_hw_get_tsf32(struct ath5k_hw *ah)
2700 ATH5K_TRACE(ah->ah_sc);
2701 return ath5k_hw_reg_read(ah, AR5K_TSF_L32);
2705 * Get the full 64bit TSF
2707 u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah)
2709 u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
2710 ATH5K_TRACE(ah->ah_sc);
2712 return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32);
2718 void ath5k_hw_reset_tsf(struct ath5k_hw *ah)
2720 ATH5K_TRACE(ah->ah_sc);
2721 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_RESET_TSF);
2725 * Initialize beacon timers
2727 void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
2729 u32 timer1, timer2, timer3;
2731 ATH5K_TRACE(ah->ah_sc);
2733 * Set the additional timers by mode
2735 switch (ah->ah_op_mode) {
2736 case IEEE80211_IF_TYPE_STA:
2737 if (ah->ah_version == AR5K_AR5210) {
2738 timer1 = 0xffffffff;
2739 timer2 = 0xffffffff;
2741 timer1 = 0x0000ffff;
2742 timer2 = 0x0007ffff;
2747 timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3;
2748 timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3;
2751 timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1);
2754 * Set the beacon register and enable all timers.
2755 * (next beacon, DMA beacon, software beacon, ATIM window time)
2757 ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
2758 ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
2759 ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
2760 ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
2762 ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD |
2763 AR5K_BEACON_RESET_TSF | AR5K_BEACON_ENABLE),
2771 int ath5k_hw_set_beacon_timers(struct ath5k_hw *ah,
2772 const struct ath5k_beacon_state *state)
2774 u32 cfp_period, next_cfp, dtim, interval, next_beacon;
2777 * TODO: should be changed through *state
2778 * review struct ath5k_beacon_state struct
2780 * XXX: These are used for cfp period bellow, are they
2781 * ok ? Is it O.K. for tsf here to be 0 or should we use
2784 u32 dtim_count = 0; /* XXX */
2785 u32 cfp_count = 0; /* XXX */
2786 u32 tsf = 0; /* XXX */
2788 ATH5K_TRACE(ah->ah_sc);
2789 /* Return on an invalid beacon state */
2790 if (state->bs_interval < 1)
2793 interval = state->bs_interval;
2794 dtim = state->bs_dtim_period;
2799 if (state->bs_cfp_period > 0) {
2801 * Enable PCF mode and set the CFP
2802 * (Contention Free Period) and timer registers
2804 cfp_period = state->bs_cfp_period * state->bs_dtim_period *
2806 next_cfp = (cfp_count * state->bs_dtim_period + dtim_count) *
2809 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
2810 AR5K_STA_ID1_DEFAULT_ANTENNA |
2812 ath5k_hw_reg_write(ah, cfp_period, AR5K_CFP_PERIOD);
2813 ath5k_hw_reg_write(ah, state->bs_cfp_max_duration,
2815 ath5k_hw_reg_write(ah, (tsf + (next_cfp == 0 ? cfp_period :
2816 next_cfp)) << 3, AR5K_TIMER2);
2818 /* Disable PCF mode */
2819 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2820 AR5K_STA_ID1_DEFAULT_ANTENNA |
2825 * Enable the beacon timer register
2827 ath5k_hw_reg_write(ah, state->bs_next_beacon, AR5K_TIMER0);
2830 * Start the beacon timers
2832 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_BEACON) &~
2833 (AR5K_BEACON_PERIOD | AR5K_BEACON_TIM)) |
2834 AR5K_REG_SM(state->bs_tim_offset ? state->bs_tim_offset + 4 : 0,
2835 AR5K_BEACON_TIM) | AR5K_REG_SM(state->bs_interval,
2836 AR5K_BEACON_PERIOD), AR5K_BEACON);
2839 * Write new beacon miss threshold, if it appears to be valid
2840 * XXX: Figure out right values for min <= bs_bmiss_threshold <= max
2841 * and return if its not in range. We can test this by reading value and
2842 * setting value to a largest value and seeing which values register.
2845 AR5K_REG_WRITE_BITS(ah, AR5K_RSSI_THR, AR5K_RSSI_THR_BMISS,
2846 state->bs_bmiss_threshold);
2849 * Set sleep control register
2850 * XXX: Didn't find this in 5210 code but since this register
2851 * exists also in ar5k's 5210 headers i leave it as common code.
2853 AR5K_REG_WRITE_BITS(ah, AR5K_SLEEP_CTL, AR5K_SLEEP_CTL_SLDUR,
2854 (state->bs_sleep_duration - 3) << 3);
2857 * Set enhanced sleep registers on 5212
2859 if (ah->ah_version == AR5K_AR5212) {
2860 if (state->bs_sleep_duration > state->bs_interval &&
2861 roundup(state->bs_sleep_duration, interval) ==
2862 state->bs_sleep_duration)
2863 interval = state->bs_sleep_duration;
2865 if (state->bs_sleep_duration > dtim && (dtim == 0 ||
2866 roundup(state->bs_sleep_duration, dtim) ==
2867 state->bs_sleep_duration))
2868 dtim = state->bs_sleep_duration;
2870 if (interval > dtim)
2873 next_beacon = interval == dtim ? state->bs_next_dtim :
2874 state->bs_next_beacon;
2876 ath5k_hw_reg_write(ah,
2877 AR5K_REG_SM((state->bs_next_dtim - 3) << 3,
2878 AR5K_SLEEP0_NEXT_DTIM) |
2879 AR5K_REG_SM(10, AR5K_SLEEP0_CABTO) |
2880 AR5K_SLEEP0_ENH_SLEEP_EN |
2881 AR5K_SLEEP0_ASSUME_DTIM, AR5K_SLEEP0);
2883 ath5k_hw_reg_write(ah, AR5K_REG_SM((next_beacon - 3) << 3,
2884 AR5K_SLEEP1_NEXT_TIM) |
2885 AR5K_REG_SM(10, AR5K_SLEEP1_BEACON_TO), AR5K_SLEEP1);
2887 ath5k_hw_reg_write(ah,
2888 AR5K_REG_SM(interval, AR5K_SLEEP2_TIM_PER) |
2889 AR5K_REG_SM(dtim, AR5K_SLEEP2_DTIM_PER), AR5K_SLEEP2);
2896 * Reset beacon timers
2898 void ath5k_hw_reset_beacon(struct ath5k_hw *ah)
2900 ATH5K_TRACE(ah->ah_sc);
2902 * Disable beacon timer
2904 ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
2907 * Disable some beacon register values
2909 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
2910 AR5K_STA_ID1_DEFAULT_ANTENNA | AR5K_STA_ID1_PCF);
2911 ath5k_hw_reg_write(ah, AR5K_BEACON_PERIOD, AR5K_BEACON);
2915 * Wait for beacon queue to finish
2917 int ath5k_hw_beaconq_finish(struct ath5k_hw *ah, unsigned long phys_addr)
2922 ATH5K_TRACE(ah->ah_sc);
2924 /* 5210 doesn't have QCU*/
2925 if (ah->ah_version == AR5K_AR5210) {
2927 * Wait for beaconn queue to finish by checking
2928 * Control Register and Beacon Status Register.
2930 for (i = AR5K_TUNE_BEACON_INTERVAL / 2; i > 0; i--) {
2931 if (!(ath5k_hw_reg_read(ah, AR5K_BSR) & AR5K_BSR_TXQ1F)
2933 !(ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_BSR_TXQ1F))
2941 * Re-schedule the beacon queue
2943 ath5k_hw_reg_write(ah, phys_addr, AR5K_NOQCU_TXDP1);
2944 ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
2952 ret = ath5k_hw_register_timeout(ah,
2953 AR5K_QUEUE_STATUS(AR5K_TX_QUEUE_ID_BEACON),
2954 AR5K_QCU_STS_FRMPENDCNT, 0, false);
2956 if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, AR5K_TX_QUEUE_ID_BEACON))
2965 * Update mib counters (statistics)
2967 void ath5k_hw_update_mib_counters(struct ath5k_hw *ah,
2968 struct ieee80211_low_level_stats *stats)
2970 ATH5K_TRACE(ah->ah_sc);
2972 /* Read-And-Clear */
2973 stats->dot11ACKFailureCount += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL);
2974 stats->dot11RTSFailureCount += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL);
2975 stats->dot11RTSSuccessCount += ath5k_hw_reg_read(ah, AR5K_RTS_OK);
2976 stats->dot11FCSErrorCount += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL);
2978 /* XXX: Should we use this to track beacon count ?
2979 * -we read it anyway to clear the register */
2980 ath5k_hw_reg_read(ah, AR5K_BEACON_CNT);
2982 /* Reset profile count registers on 5212*/
2983 if (ah->ah_version == AR5K_AR5212) {
2984 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_TX);
2985 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RX);
2986 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR);
2987 ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE);
2991 /** ath5k_hw_set_ack_bitrate - set bitrate for ACKs
2993 * @ah: the &struct ath5k_hw
2994 * @high: determines if to use low bit rate or now
2996 void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high)
2998 if (ah->ah_version != AR5K_AR5212)
3001 u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB;
3003 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val);
3005 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val);
3015 * Set ACK timeout on PCU
3017 int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout)
3019 ATH5K_TRACE(ah->ah_sc);
3020 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK),
3021 ah->ah_turbo) <= timeout)
3024 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK,
3025 ath5k_hw_htoclock(timeout, ah->ah_turbo));
3031 * Read the ACK timeout from PCU
3033 unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah)
3035 ATH5K_TRACE(ah->ah_sc);
3037 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
3038 AR5K_TIME_OUT), AR5K_TIME_OUT_ACK), ah->ah_turbo);
3042 * Set CTS timeout on PCU
3044 int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout)
3046 ATH5K_TRACE(ah->ah_sc);
3047 if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS),
3048 ah->ah_turbo) <= timeout)
3051 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS,
3052 ath5k_hw_htoclock(timeout, ah->ah_turbo));
3058 * Read CTS timeout from PCU
3060 unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah)
3062 ATH5K_TRACE(ah->ah_sc);
3063 return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
3064 AR5K_TIME_OUT), AR5K_TIME_OUT_CTS), ah->ah_turbo);
3068 * Key table (WEP) functions
3071 int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
3075 ATH5K_TRACE(ah->ah_sc);
3076 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3078 for (i = 0; i < AR5K_KEYCACHE_SIZE; i++)
3079 ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i));
3082 * Set NULL encryption on AR5212+
3084 * Note: AR5K_KEYTABLE_TYPE -> AR5K_KEYTABLE_OFF(entry, 5)
3085 * AR5K_KEYTABLE_TYPE_NULL -> 0x00000007
3087 * Note2: Windows driver (ndiswrapper) sets this to
3088 * 0x00000714 instead of 0x00000007
3090 if (ah->ah_version > AR5K_AR5211)
3091 ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
3092 AR5K_KEYTABLE_TYPE(entry));
3097 int ath5k_hw_is_key_valid(struct ath5k_hw *ah, u16 entry)
3099 ATH5K_TRACE(ah->ah_sc);
3100 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3102 /* Check the validation flag at the end of the entry */
3103 return ath5k_hw_reg_read(ah, AR5K_KEYTABLE_MAC1(entry)) &
3104 AR5K_KEYTABLE_VALID;
3107 int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
3108 const struct ieee80211_key_conf *key, const u8 *mac)
3111 __le32 key_v[5] = {};
3114 ATH5K_TRACE(ah->ah_sc);
3116 /* key->keylen comes in from mac80211 in bytes */
3118 if (key->keylen > AR5K_KEYTABLE_SIZE / 8)
3121 switch (key->keylen) {
3122 /* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit */
3124 memcpy(&key_v[0], key->key, 5);
3125 keytype = AR5K_KEYTABLE_TYPE_40;
3128 /* WEP 104-bit = 104-bit entered key + 24-bit IV = 128-bit */
3130 memcpy(&key_v[0], &key->key[0], 6);
3131 memcpy(&key_v[2], &key->key[6], 6);
3132 memcpy(&key_v[4], &key->key[12], 1);
3133 keytype = AR5K_KEYTABLE_TYPE_104;
3135 /* WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit */
3137 memcpy(&key_v[0], &key->key[0], 6);
3138 memcpy(&key_v[2], &key->key[6], 6);
3139 memcpy(&key_v[4], &key->key[12], 4);
3140 keytype = AR5K_KEYTABLE_TYPE_128;
3144 return -EINVAL; /* shouldn't happen */
3147 for (i = 0; i < ARRAY_SIZE(key_v); i++)
3148 ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
3149 AR5K_KEYTABLE_OFF(entry, i));
3151 ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry));
3153 return ath5k_hw_set_key_lladdr(ah, entry, mac);
3156 int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac)
3158 u32 low_id, high_id;
3160 ATH5K_TRACE(ah->ah_sc);
3161 /* Invalid entry (key table overflow) */
3162 AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
3164 /* MAC may be NULL if it's a broadcast key. In this case no need to
3165 * to compute AR5K_LOW_ID and AR5K_HIGH_ID as we already know it. */
3166 if (unlikely(mac == NULL)) {
3167 low_id = 0xffffffff;
3168 high_id = 0xffff | AR5K_KEYTABLE_VALID;
3170 low_id = AR5K_LOW_ID(mac);
3171 high_id = AR5K_HIGH_ID(mac) | AR5K_KEYTABLE_VALID;
3174 ath5k_hw_reg_write(ah, low_id, AR5K_KEYTABLE_MAC0(entry));
3175 ath5k_hw_reg_write(ah, high_id, AR5K_KEYTABLE_MAC1(entry));
3181 /********************************************\
3182 Queue Control Unit, DFS Control Unit Functions
3183 \********************************************/
3186 * Initialize a transmit queue
3188 int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type,
3189 struct ath5k_txq_info *queue_info)
3194 ATH5K_TRACE(ah->ah_sc);
3199 /*5210 only has 2 queues*/
3200 if (ah->ah_version == AR5K_AR5210) {
3201 switch (queue_type) {
3202 case AR5K_TX_QUEUE_DATA:
3203 queue = AR5K_TX_QUEUE_ID_NOQCU_DATA;
3205 case AR5K_TX_QUEUE_BEACON:
3206 case AR5K_TX_QUEUE_CAB:
3207 queue = AR5K_TX_QUEUE_ID_NOQCU_BEACON;
3213 switch (queue_type) {
3214 case AR5K_TX_QUEUE_DATA:
3215 for (queue = AR5K_TX_QUEUE_ID_DATA_MIN;
3216 ah->ah_txq[queue].tqi_type !=
3217 AR5K_TX_QUEUE_INACTIVE; queue++) {
3219 if (queue > AR5K_TX_QUEUE_ID_DATA_MAX)
3223 case AR5K_TX_QUEUE_UAPSD:
3224 queue = AR5K_TX_QUEUE_ID_UAPSD;
3226 case AR5K_TX_QUEUE_BEACON:
3227 queue = AR5K_TX_QUEUE_ID_BEACON;
3229 case AR5K_TX_QUEUE_CAB:
3230 queue = AR5K_TX_QUEUE_ID_CAB;
3232 case AR5K_TX_QUEUE_XR_DATA:
3233 if (ah->ah_version != AR5K_AR5212)
3234 ATH5K_ERR(ah->ah_sc,
3235 "XR data queues only supported in"
3237 queue = AR5K_TX_QUEUE_ID_XR_DATA;
3245 * Setup internal queue structure
3247 memset(&ah->ah_txq[queue], 0, sizeof(struct ath5k_txq_info));
3248 ah->ah_txq[queue].tqi_type = queue_type;
3250 if (queue_info != NULL) {
3251 queue_info->tqi_type = queue_type;
3252 ret = ath5k_hw_setup_tx_queueprops(ah, queue, queue_info);
3257 * We use ah_txq_status to hold a temp value for
3258 * the Secondary interrupt mask registers on 5211+
3259 * check out ath5k_hw_reset_tx_queue
3261 AR5K_Q_ENABLE_BITS(ah->ah_txq_status, queue);
3267 * Setup a transmit queue
3269 int ath5k_hw_setup_tx_queueprops(struct ath5k_hw *ah, int queue,
3270 const struct ath5k_txq_info *queue_info)
3272 ATH5K_TRACE(ah->ah_sc);
3273 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3275 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3278 memcpy(&ah->ah_txq[queue], queue_info, sizeof(struct ath5k_txq_info));
3280 /*XXX: Is this supported on 5210 ?*/
3281 if ((queue_info->tqi_type == AR5K_TX_QUEUE_DATA &&
3282 ((queue_info->tqi_subtype == AR5K_WME_AC_VI) ||
3283 (queue_info->tqi_subtype == AR5K_WME_AC_VO))) ||
3284 queue_info->tqi_type == AR5K_TX_QUEUE_UAPSD)
3285 ah->ah_txq[queue].tqi_flags |= AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
3291 * Get properties for a specific transmit queue
3293 int ath5k_hw_get_tx_queueprops(struct ath5k_hw *ah, int queue,
3294 struct ath5k_txq_info *queue_info)
3296 ATH5K_TRACE(ah->ah_sc);
3297 memcpy(queue_info, &ah->ah_txq[queue], sizeof(struct ath5k_txq_info));
3302 * Set a transmit queue inactive
3304 void ath5k_hw_release_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3306 ATH5K_TRACE(ah->ah_sc);
3307 if (WARN_ON(queue >= ah->ah_capabilities.cap_queues.q_tx_num))
3310 /* This queue will be skipped in further operations */
3311 ah->ah_txq[queue].tqi_type = AR5K_TX_QUEUE_INACTIVE;
3313 AR5K_Q_DISABLE_BITS(ah->ah_txq_status, queue);
3317 * Set DFS params for a transmit queue
3319 int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
3321 u32 cw_min, cw_max, retry_lg, retry_sh;
3322 struct ath5k_txq_info *tq = &ah->ah_txq[queue];
3324 ATH5K_TRACE(ah->ah_sc);
3325 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3327 tq = &ah->ah_txq[queue];
3329 if (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE)
3332 if (ah->ah_version == AR5K_AR5210) {
3333 /* Only handle data queues, others will be ignored */
3334 if (tq->tqi_type != AR5K_TX_QUEUE_DATA)
3338 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3339 AR5K_INIT_SLOT_TIME_TURBO : AR5K_INIT_SLOT_TIME,
3341 /* Set ACK_CTS timeout */
3342 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3343 AR5K_INIT_ACK_CTS_TIMEOUT_TURBO :
3344 AR5K_INIT_ACK_CTS_TIMEOUT, AR5K_SLOT_TIME);
3345 /* Set Transmit Latency */
3346 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3347 AR5K_INIT_TRANSMIT_LATENCY_TURBO :
3348 AR5K_INIT_TRANSMIT_LATENCY, AR5K_USEC_5210);
3351 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS_TURBO +
3352 (ah->ah_aifs + tq->tqi_aifs) *
3353 AR5K_INIT_SLOT_TIME_TURBO) <<
3354 AR5K_IFS0_DIFS_S) | AR5K_INIT_SIFS_TURBO,
3357 ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS +
3358 (ah->ah_aifs + tq->tqi_aifs) *
3359 AR5K_INIT_SLOT_TIME) << AR5K_IFS0_DIFS_S) |
3360 AR5K_INIT_SIFS, AR5K_IFS0);
3363 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3364 AR5K_INIT_PROTO_TIME_CNTRL_TURBO :
3365 AR5K_INIT_PROTO_TIME_CNTRL, AR5K_IFS1);
3366 /* Set PHY register 0x9844 (??) */
3367 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3368 (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x38 :
3369 (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x1C,
3371 /* Set Frame Control Register */
3372 ath5k_hw_reg_write(ah, ah->ah_turbo ?
3373 (AR5K_PHY_FRAME_CTL_INI | AR5K_PHY_TURBO_MODE |
3374 AR5K_PHY_TURBO_SHORT | 0x2020) :
3375 (AR5K_PHY_FRAME_CTL_INI | 0x1020),
3376 AR5K_PHY_FRAME_CTL_5210);
3380 * Calculate cwmin/max by channel mode
3382 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN;
3383 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX;
3384 ah->ah_aifs = AR5K_TUNE_AIFS;
3385 /*XR is only supported on 5212*/
3386 if (IS_CHAN_XR(ah->ah_current_channel) &&
3387 ah->ah_version == AR5K_AR5212) {
3388 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_XR;
3389 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_XR;
3390 ah->ah_aifs = AR5K_TUNE_AIFS_XR;
3391 /*B mode is not supported on 5210*/
3392 } else if (IS_CHAN_B(ah->ah_current_channel) &&
3393 ah->ah_version != AR5K_AR5210) {
3394 cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_11B;
3395 cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_11B;
3396 ah->ah_aifs = AR5K_TUNE_AIFS_11B;
3400 while (cw_min < ah->ah_cw_min)
3401 cw_min = (cw_min << 1) | 1;
3403 cw_min = tq->tqi_cw_min < 0 ? (cw_min >> (-tq->tqi_cw_min)) :
3404 ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
3405 cw_max = tq->tqi_cw_max < 0 ? (cw_max >> (-tq->tqi_cw_max)) :
3406 ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
3409 * Calculate and set retry limits
3411 if (ah->ah_software_retry) {
3412 /* XXX Need to test this */
3413 retry_lg = ah->ah_limit_tx_retries;
3414 retry_sh = retry_lg = retry_lg > AR5K_DCU_RETRY_LMT_SH_RETRY ?
3415 AR5K_DCU_RETRY_LMT_SH_RETRY : retry_lg;
3417 retry_lg = AR5K_INIT_LG_RETRY;
3418 retry_sh = AR5K_INIT_SH_RETRY;
3421 /*No QCU/DCU [5210]*/
3422 if (ah->ah_version == AR5K_AR5210) {
3423 ath5k_hw_reg_write(ah,
3424 (cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
3425 | AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3426 AR5K_NODCU_RETRY_LMT_SLG_RETRY)
3427 | AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3428 AR5K_NODCU_RETRY_LMT_SSH_RETRY)
3429 | AR5K_REG_SM(retry_lg, AR5K_NODCU_RETRY_LMT_LG_RETRY)
3430 | AR5K_REG_SM(retry_sh, AR5K_NODCU_RETRY_LMT_SH_RETRY),
3431 AR5K_NODCU_RETRY_LMT);
3434 ath5k_hw_reg_write(ah,
3435 AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
3436 AR5K_DCU_RETRY_LMT_SLG_RETRY) |
3437 AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
3438 AR5K_DCU_RETRY_LMT_SSH_RETRY) |
3439 AR5K_REG_SM(retry_lg, AR5K_DCU_RETRY_LMT_LG_RETRY) |
3440 AR5K_REG_SM(retry_sh, AR5K_DCU_RETRY_LMT_SH_RETRY),
3441 AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
3443 /*===Rest is also for QCU/DCU only [5211+]===*/
3446 * Set initial content window (cw_min/cw_max)
3447 * and arbitrated interframe space (aifs)...
3449 ath5k_hw_reg_write(ah,
3450 AR5K_REG_SM(cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
3451 AR5K_REG_SM(cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
3452 AR5K_REG_SM(ah->ah_aifs + tq->tqi_aifs,
3453 AR5K_DCU_LCL_IFS_AIFS),
3454 AR5K_QUEUE_DFS_LOCAL_IFS(queue));
3457 * Set misc registers
3459 ath5k_hw_reg_write(ah, AR5K_QCU_MISC_DCU_EARLY,
3460 AR5K_QUEUE_MISC(queue));
3462 if (tq->tqi_cbr_period) {
3463 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
3464 AR5K_QCU_CBRCFG_INTVAL) |
3465 AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
3466 AR5K_QCU_CBRCFG_ORN_THRES),
3467 AR5K_QUEUE_CBRCFG(queue));
3468 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3469 AR5K_QCU_MISC_FRSHED_CBR);
3470 if (tq->tqi_cbr_overflow_limit)
3471 AR5K_REG_ENABLE_BITS(ah,
3472 AR5K_QUEUE_MISC(queue),
3473 AR5K_QCU_MISC_CBR_THRES_ENABLE);
3476 if (tq->tqi_ready_time)
3477 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
3478 AR5K_QCU_RDYTIMECFG_INTVAL) |
3479 AR5K_QCU_RDYTIMECFG_ENABLE,
3480 AR5K_QUEUE_RDYTIMECFG(queue));
3482 if (tq->tqi_burst_time) {
3483 ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
3484 AR5K_DCU_CHAN_TIME_DUR) |
3485 AR5K_DCU_CHAN_TIME_ENABLE,
3486 AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
3488 if (tq->tqi_flags & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
3489 AR5K_REG_ENABLE_BITS(ah,
3490 AR5K_QUEUE_MISC(queue),
3494 if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
3495 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
3496 AR5K_QUEUE_DFS_MISC(queue));
3498 if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
3499 ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
3500 AR5K_QUEUE_DFS_MISC(queue));
3503 * Set registers by queue type
3505 switch (tq->tqi_type) {
3506 case AR5K_TX_QUEUE_BEACON:
3507 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3508 AR5K_QCU_MISC_FRSHED_DBA_GT |
3509 AR5K_QCU_MISC_CBREXP_BCN |
3510 AR5K_QCU_MISC_BCN_ENABLE);
3512 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3513 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3514 AR5K_DCU_MISC_ARBLOCK_CTL_S) |
3515 AR5K_DCU_MISC_POST_FR_BKOFF_DIS |
3516 AR5K_DCU_MISC_BCN_ENABLE);
3518 ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL -
3519 (AR5K_TUNE_SW_BEACON_RESP -
3520 AR5K_TUNE_DMA_BEACON_RESP) -
3521 AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF) * 1024) |
3522 AR5K_QCU_RDYTIMECFG_ENABLE,
3523 AR5K_QUEUE_RDYTIMECFG(queue));
3526 case AR5K_TX_QUEUE_CAB:
3527 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3528 AR5K_QCU_MISC_FRSHED_DBA_GT |
3529 AR5K_QCU_MISC_CBREXP |
3530 AR5K_QCU_MISC_CBREXP_BCN);
3532 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
3533 (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
3534 AR5K_DCU_MISC_ARBLOCK_CTL_S));
3537 case AR5K_TX_QUEUE_UAPSD:
3538 AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
3539 AR5K_QCU_MISC_CBREXP);
3542 case AR5K_TX_QUEUE_DATA:
3548 * Enable interrupts for this tx queue
3549 * in the secondary interrupt mask registers
3551 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
3552 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
3554 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
3555 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
3557 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
3558 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
3560 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
3561 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
3563 if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
3564 AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
3567 /* Update secondary interrupt mask registers */
3568 ah->ah_txq_imr_txok &= ah->ah_txq_status;
3569 ah->ah_txq_imr_txerr &= ah->ah_txq_status;
3570 ah->ah_txq_imr_txurn &= ah->ah_txq_status;
3571 ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
3572 ah->ah_txq_imr_txeol &= ah->ah_txq_status;
3574 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
3575 AR5K_SIMR0_QCU_TXOK) |
3576 AR5K_REG_SM(ah->ah_txq_imr_txdesc,
3577 AR5K_SIMR0_QCU_TXDESC), AR5K_SIMR0);
3578 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
3579 AR5K_SIMR1_QCU_TXERR) |
3580 AR5K_REG_SM(ah->ah_txq_imr_txeol,
3581 AR5K_SIMR1_QCU_TXEOL), AR5K_SIMR1);
3582 ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txurn,
3583 AR5K_SIMR2_QCU_TXURN), AR5K_SIMR2);
3590 * Get number of pending frames
3591 * for a specific queue [5211+]
3593 u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah, unsigned int queue) {
3594 ATH5K_TRACE(ah->ah_sc);
3595 AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
3597 /* Return if queue is declared inactive */
3598 if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
3601 /* XXX: How about AR5K_CFG_TXCNT ? */
3602 if (ah->ah_version == AR5K_AR5210)
3605 return AR5K_QUEUE_STATUS(queue) & AR5K_QCU_STS_FRMPENDCNT;
3611 int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time)
3613 ATH5K_TRACE(ah->ah_sc);
3614 if (slot_time < AR5K_SLOT_TIME_9 || slot_time > AR5K_SLOT_TIME_MAX)
3617 if (ah->ah_version == AR5K_AR5210)
3618 ath5k_hw_reg_write(ah, ath5k_hw_htoclock(slot_time,
3619 ah->ah_turbo), AR5K_SLOT_TIME);
3621 ath5k_hw_reg_write(ah, slot_time, AR5K_DCU_GBL_IFS_SLOT);
3629 unsigned int ath5k_hw_get_slot_time(struct ath5k_hw *ah)
3631 ATH5K_TRACE(ah->ah_sc);
3632 if (ah->ah_version == AR5K_AR5210)
3633 return ath5k_hw_clocktoh(ath5k_hw_reg_read(ah,
3634 AR5K_SLOT_TIME) & 0xffff, ah->ah_turbo);
3636 return ath5k_hw_reg_read(ah, AR5K_DCU_GBL_IFS_SLOT) & 0xffff;
3640 /******************************\
3641 Hardware Descriptor Functions
3642 \******************************/
3649 * Initialize the 2-word tx descriptor on 5210/5211
3652 ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3653 unsigned int pkt_len, unsigned int hdr_len, enum ath5k_pkt_type type,
3654 unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
3655 unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
3656 unsigned int rtscts_rate, unsigned int rtscts_duration)
3659 struct ath5k_hw_2w_tx_ctl *tx_ctl;
3660 unsigned int frame_len;
3662 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
3666 * - Zero retries don't make sense.
3667 * - A zero rate will put the HW into a mode where it continously sends
3668 * noise on the channel, so it is important to avoid this.
3670 if (unlikely(tx_tries0 == 0)) {
3671 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3675 if (unlikely(tx_rate0 == 0)) {
3676 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3681 /* Clear descriptor */
3682 memset(&desc->ud.ds_tx5210, 0, sizeof(struct ath5k_hw_5210_tx_desc));
3684 /* Setup control descriptor */
3686 /* Verify and set frame length */
3688 /* remove padding we might have added before */
3689 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3691 if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
3694 tx_ctl->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
3696 /* Verify and set buffer length */
3698 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3699 if(type == AR5K_PKT_TYPE_BEACON)
3700 pkt_len = roundup(pkt_len, 4);
3702 if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
3705 tx_ctl->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
3708 * Verify and set header length
3709 * XXX: I only found that on 5210 code, does it work on 5211 ?
3711 if (ah->ah_version == AR5K_AR5210) {
3712 if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN)
3714 tx_ctl->tx_control_0 |=
3715 AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN);
3718 /*Diferences between 5210-5211*/
3719 if (ah->ah_version == AR5K_AR5210) {
3721 case AR5K_PKT_TYPE_BEACON:
3722 case AR5K_PKT_TYPE_PROBE_RESP:
3723 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
3724 case AR5K_PKT_TYPE_PIFS:
3725 frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
3727 frame_type = type /*<< 2 ?*/;
3730 tx_ctl->tx_control_0 |=
3731 AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE) |
3732 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3734 tx_ctl->tx_control_0 |=
3735 AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
3736 AR5K_REG_SM(antenna_mode, AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
3737 tx_ctl->tx_control_1 |=
3738 AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE);
3740 #define _TX_FLAGS(_c, _flag) \
3741 if (flags & AR5K_TXDESC_##_flag) \
3742 tx_ctl->tx_control_##_c |= \
3743 AR5K_2W_TX_DESC_CTL##_c##_##_flag
3745 _TX_FLAGS(0, CLRDMASK);
3747 _TX_FLAGS(0, INTREQ);
3748 _TX_FLAGS(0, RTSENA);
3749 _TX_FLAGS(1, NOACK);
3756 if (key_index != AR5K_TXKEYIX_INVALID) {
3757 tx_ctl->tx_control_0 |=
3758 AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3759 tx_ctl->tx_control_1 |=
3760 AR5K_REG_SM(key_index,
3761 AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3765 * RTS/CTS Duration [5210 ?]
3767 if ((ah->ah_version == AR5K_AR5210) &&
3768 (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
3769 tx_ctl->tx_control_1 |= rtscts_duration &
3770 AR5K_2W_TX_DESC_CTL1_RTS_DURATION;
3776 * Initialize the 4-word tx descriptor on 5212
3778 static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
3779 struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
3780 enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
3781 unsigned int tx_tries0, unsigned int key_index,
3782 unsigned int antenna_mode, unsigned int flags, unsigned int rtscts_rate,
3783 unsigned int rtscts_duration)
3785 struct ath5k_hw_4w_tx_ctl *tx_ctl;
3786 unsigned int frame_len;
3788 ATH5K_TRACE(ah->ah_sc);
3789 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
3793 * - Zero retries don't make sense.
3794 * - A zero rate will put the HW into a mode where it continously sends
3795 * noise on the channel, so it is important to avoid this.
3797 if (unlikely(tx_tries0 == 0)) {
3798 ATH5K_ERR(ah->ah_sc, "zero retries\n");
3802 if (unlikely(tx_rate0 == 0)) {
3803 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3808 /* Clear descriptor */
3809 memset(&desc->ud.ds_tx5212, 0, sizeof(struct ath5k_hw_5212_tx_desc));
3811 /* Setup control descriptor */
3813 /* Verify and set frame length */
3815 /* remove padding we might have added before */
3816 frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
3818 if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
3821 tx_ctl->tx_control_0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
3823 /* Verify and set buffer length */
3825 /* NB: beacon's BufLen must be a multiple of 4 bytes */
3826 if(type == AR5K_PKT_TYPE_BEACON)
3827 pkt_len = roundup(pkt_len, 4);
3829 if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
3832 tx_ctl->tx_control_1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
3834 tx_ctl->tx_control_0 |=
3835 AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
3836 AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
3837 tx_ctl->tx_control_1 |= AR5K_REG_SM(type,
3838 AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
3839 tx_ctl->tx_control_2 = AR5K_REG_SM(tx_tries0 + AR5K_TUNE_HWTXTRIES,
3840 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
3841 tx_ctl->tx_control_3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
3843 #define _TX_FLAGS(_c, _flag) \
3844 if (flags & AR5K_TXDESC_##_flag) \
3845 tx_ctl->tx_control_##_c |= \
3846 AR5K_4W_TX_DESC_CTL##_c##_##_flag
3848 _TX_FLAGS(0, CLRDMASK);
3850 _TX_FLAGS(0, INTREQ);
3851 _TX_FLAGS(0, RTSENA);
3852 _TX_FLAGS(0, CTSENA);
3853 _TX_FLAGS(1, NOACK);
3860 if (key_index != AR5K_TXKEYIX_INVALID) {
3861 tx_ctl->tx_control_0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
3862 tx_ctl->tx_control_1 |= AR5K_REG_SM(key_index,
3863 AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
3869 if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
3870 if ((flags & AR5K_TXDESC_RTSENA) &&
3871 (flags & AR5K_TXDESC_CTSENA))
3873 tx_ctl->tx_control_2 |= rtscts_duration &
3874 AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
3875 tx_ctl->tx_control_3 |= AR5K_REG_SM(rtscts_rate,
3876 AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
3883 * Initialize a 4-word multirate tx descriptor on 5212
3886 ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
3887 unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2, u_int tx_tries2,
3888 unsigned int tx_rate3, u_int tx_tries3)
3890 struct ath5k_hw_4w_tx_ctl *tx_ctl;
3893 * Rates can be 0 as long as the retry count is 0 too.
3894 * A zero rate and nonzero retry count will put the HW into a mode where
3895 * it continously sends noise on the channel, so it is important to
3898 if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
3899 (tx_rate2 == 0 && tx_tries2 != 0) ||
3900 (tx_rate3 == 0 && tx_tries3 != 0))) {
3901 ATH5K_ERR(ah->ah_sc, "zero rate\n");
3906 if (ah->ah_version == AR5K_AR5212) {
3907 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
3909 #define _XTX_TRIES(_n) \
3910 if (tx_tries##_n) { \
3911 tx_ctl->tx_control_2 |= \
3912 AR5K_REG_SM(tx_tries##_n, \
3913 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
3914 tx_ctl->tx_control_3 |= \
3915 AR5K_REG_SM(tx_rate##_n, \
3916 AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
3932 * Proccess the tx status descriptor on 5210/5211
3934 static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
3935 struct ath5k_desc *desc, struct ath5k_tx_status *ts)
3937 struct ath5k_hw_2w_tx_ctl *tx_ctl;
3938 struct ath5k_hw_tx_status *tx_status;
3940 ATH5K_TRACE(ah->ah_sc);
3942 tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
3943 tx_status = &desc->ud.ds_tx5210.tx_stat;
3945 /* No frame has been send or error */
3946 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
3947 return -EINPROGRESS;
3950 * Get descriptor status
3952 ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
3953 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
3954 ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
3955 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
3956 ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
3957 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
3958 /*TODO: ts->ts_virtcol + test*/
3959 ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
3960 AR5K_DESC_TX_STATUS1_SEQ_NUM);
3961 ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
3962 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
3965 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_0,
3966 AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
3968 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
3969 if (tx_status->tx_status_0 &
3970 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
3971 ts->ts_status |= AR5K_TXERR_XRETRY;
3973 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
3974 ts->ts_status |= AR5K_TXERR_FIFO;
3976 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
3977 ts->ts_status |= AR5K_TXERR_FILT;
3984 * Proccess a tx descriptor on 5212
3986 static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
3987 struct ath5k_desc *desc, struct ath5k_tx_status *ts)
3989 struct ath5k_hw_4w_tx_ctl *tx_ctl;
3990 struct ath5k_hw_tx_status *tx_status;
3992 ATH5K_TRACE(ah->ah_sc);
3994 tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
3995 tx_status = &desc->ud.ds_tx5212.tx_stat;
3997 /* No frame has been send or error */
3998 if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
3999 return -EINPROGRESS;
4002 * Get descriptor status
4004 ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
4005 AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
4006 ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
4007 AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
4008 ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
4009 AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
4010 ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
4011 AR5K_DESC_TX_STATUS1_SEQ_NUM);
4012 ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
4013 AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
4014 ts->ts_antenna = (tx_status->tx_status_1 &
4015 AR5K_DESC_TX_STATUS1_XMIT_ANTENNA) ? 2 : 1;
4018 switch (AR5K_REG_MS(tx_status->tx_status_1,
4019 AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX)) {
4021 ts->ts_rate = tx_ctl->tx_control_3 &
4022 AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
4025 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
4026 AR5K_4W_TX_DESC_CTL3_XMIT_RATE1);
4027 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
4028 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1);
4031 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
4032 AR5K_4W_TX_DESC_CTL3_XMIT_RATE2);
4033 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
4034 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2);
4037 ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
4038 AR5K_4W_TX_DESC_CTL3_XMIT_RATE3);
4039 ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
4040 AR5K_4W_TX_DESC_CTL2_XMIT_TRIES3);
4044 if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
4045 if (tx_status->tx_status_0 &
4046 AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
4047 ts->ts_status |= AR5K_TXERR_XRETRY;
4049 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
4050 ts->ts_status |= AR5K_TXERR_FIFO;
4052 if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
4053 ts->ts_status |= AR5K_TXERR_FILT;
4064 * Initialize an rx descriptor
4066 int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
4067 u32 size, unsigned int flags)
4069 struct ath5k_hw_rx_ctl *rx_ctl;
4071 ATH5K_TRACE(ah->ah_sc);
4072 rx_ctl = &desc->ud.ds_rx.rx_ctl;
4075 * Clear the descriptor
4076 * If we don't clean the status descriptor,
4077 * while scanning we get too many results,
4078 * most of them virtual, after some secs
4079 * of scanning system hangs. M.F.
4081 memset(&desc->ud.ds_rx, 0, sizeof(struct ath5k_hw_all_rx_desc));
4083 /* Setup descriptor */
4084 rx_ctl->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
4085 if (unlikely(rx_ctl->rx_control_1 != size))
4088 if (flags & AR5K_RXDESC_INTREQ)
4089 rx_ctl->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
4095 * Proccess the rx status descriptor on 5210/5211
4097 static int ath5k_hw_proc_5210_rx_status(struct ath5k_hw *ah,
4098 struct ath5k_desc *desc, struct ath5k_rx_status *rs)
4100 struct ath5k_hw_rx_status *rx_status;
4102 rx_status = &desc->ud.ds_rx.u.rx_stat;
4104 /* No frame received / not ready */
4105 if (unlikely((rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_DONE)
4107 return -EINPROGRESS;
4110 * Frame receive status
4112 rs->rs_datalen = rx_status->rx_status_0 &
4113 AR5K_5210_RX_DESC_STATUS0_DATA_LEN;
4114 rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
4115 AR5K_5210_RX_DESC_STATUS0_RECEIVE_SIGNAL);
4116 rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
4117 AR5K_5210_RX_DESC_STATUS0_RECEIVE_RATE);
4118 rs->rs_antenna = rx_status->rx_status_0 &
4119 AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANTENNA;
4120 rs->rs_more = rx_status->rx_status_0 &
4121 AR5K_5210_RX_DESC_STATUS0_MORE;
4122 /* TODO: this timestamp is 13 bit, later on we assume 15 bit */
4123 rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
4124 AR5K_5210_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
4131 if (rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_KEY_INDEX_VALID)
4132 rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
4133 AR5K_5210_RX_DESC_STATUS1_KEY_INDEX);
4135 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
4138 * Receive/descriptor errors
4140 if ((rx_status->rx_status_1 &
4141 AR5K_5210_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
4142 if (rx_status->rx_status_1 &
4143 AR5K_5210_RX_DESC_STATUS1_CRC_ERROR)
4144 rs->rs_status |= AR5K_RXERR_CRC;
4146 if (rx_status->rx_status_1 &
4147 AR5K_5210_RX_DESC_STATUS1_FIFO_OVERRUN)
4148 rs->rs_status |= AR5K_RXERR_FIFO;
4150 if (rx_status->rx_status_1 &
4151 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR) {
4152 rs->rs_status |= AR5K_RXERR_PHY;
4153 rs->rs_phyerr |= AR5K_REG_MS(rx_status->rx_status_1,
4154 AR5K_5210_RX_DESC_STATUS1_PHY_ERROR);
4157 if (rx_status->rx_status_1 &
4158 AR5K_5210_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
4159 rs->rs_status |= AR5K_RXERR_DECRYPT;
4166 * Proccess the rx status descriptor on 5212
4168 static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *ah,
4169 struct ath5k_desc *desc, struct ath5k_rx_status *rs)
4171 struct ath5k_hw_rx_status *rx_status;
4172 struct ath5k_hw_rx_error *rx_err;
4174 ATH5K_TRACE(ah->ah_sc);
4175 rx_status = &desc->ud.ds_rx.u.rx_stat;
4177 /* Overlay on error */
4178 rx_err = &desc->ud.ds_rx.u.rx_err;
4180 /* No frame received / not ready */
4181 if (unlikely((rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_DONE)
4183 return -EINPROGRESS;
4186 * Frame receive status
4188 rs->rs_datalen = rx_status->rx_status_0 &
4189 AR5K_5212_RX_DESC_STATUS0_DATA_LEN;
4190 rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
4191 AR5K_5212_RX_DESC_STATUS0_RECEIVE_SIGNAL);
4192 rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
4193 AR5K_5212_RX_DESC_STATUS0_RECEIVE_RATE);
4194 rs->rs_antenna = rx_status->rx_status_0 &
4195 AR5K_5212_RX_DESC_STATUS0_RECEIVE_ANTENNA;
4196 rs->rs_more = rx_status->rx_status_0 &
4197 AR5K_5212_RX_DESC_STATUS0_MORE;
4198 rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
4199 AR5K_5212_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
4206 if (rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_KEY_INDEX_VALID)
4207 rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
4208 AR5K_5212_RX_DESC_STATUS1_KEY_INDEX);
4210 rs->rs_keyix = AR5K_RXKEYIX_INVALID;
4213 * Receive/descriptor errors
4215 if ((rx_status->rx_status_1 &
4216 AR5K_5212_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
4217 if (rx_status->rx_status_1 &
4218 AR5K_5212_RX_DESC_STATUS1_CRC_ERROR)
4219 rs->rs_status |= AR5K_RXERR_CRC;
4221 if (rx_status->rx_status_1 &
4222 AR5K_5212_RX_DESC_STATUS1_PHY_ERROR) {
4223 rs->rs_status |= AR5K_RXERR_PHY;
4224 rs->rs_phyerr |= AR5K_REG_MS(rx_err->rx_error_1,
4225 AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE);
4228 if (rx_status->rx_status_1 &
4229 AR5K_5212_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
4230 rs->rs_status |= AR5K_RXERR_DECRYPT;
4232 if (rx_status->rx_status_1 &
4233 AR5K_5212_RX_DESC_STATUS1_MIC_ERROR)
4234 rs->rs_status |= AR5K_RXERR_MIC;
4248 void ath5k_hw_set_ledstate(struct ath5k_hw *ah, unsigned int state)
4251 /*5210 has different led mode handling*/
4254 ATH5K_TRACE(ah->ah_sc);
4256 /*Reset led status*/
4257 if (ah->ah_version != AR5K_AR5210)
4258 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
4259 AR5K_PCICFG_LEDMODE | AR5K_PCICFG_LED);
4261 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_LED);
4264 * Some blinking values, define at your wish
4269 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_PEND;
4270 led_5210 = AR5K_PCICFG_LED_PEND | AR5K_PCICFG_LED_BCTL;
4274 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_NONE;
4275 led_5210 = AR5K_PCICFG_LED_PEND;
4278 case AR5K_LED_ASSOC:
4280 led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_ASSOC;
4281 led_5210 = AR5K_PCICFG_LED_ASSOC;
4285 led = AR5K_PCICFG_LEDMODE_PROM | AR5K_PCICFG_LED_NONE;
4286 led_5210 = AR5K_PCICFG_LED_PEND;
4290 /*Write new status to the register*/
4291 if (ah->ah_version != AR5K_AR5210)
4292 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led);
4294 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led_5210);
4300 int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
4302 ATH5K_TRACE(ah->ah_sc);
4303 if (gpio > AR5K_NUM_GPIO)
4306 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4307 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR);
4315 int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
4317 ATH5K_TRACE(ah->ah_sc);
4318 if (gpio > AR5K_NUM_GPIO)
4321 ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
4322 AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR);
4330 u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
4332 ATH5K_TRACE(ah->ah_sc);
4333 if (gpio > AR5K_NUM_GPIO)
4336 /* GPIO input magic */
4337 return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) &
4344 int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
4347 ATH5K_TRACE(ah->ah_sc);
4349 if (gpio > AR5K_NUM_GPIO)
4352 /* GPIO output magic */
4353 data = ath5k_hw_reg_read(ah, AR5K_GPIODO);
4355 data &= ~(1 << gpio);
4356 data |= (val & 1) << gpio;
4358 ath5k_hw_reg_write(ah, data, AR5K_GPIODO);
4364 * Initialize the GPIO interrupt (RFKill switch)
4366 void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
4367 u32 interrupt_level)
4371 ATH5K_TRACE(ah->ah_sc);
4372 if (gpio > AR5K_NUM_GPIO)
4376 * Set the GPIO interrupt
4378 data = (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &
4379 ~(AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_SELH |
4380 AR5K_GPIOCR_INT_ENA | AR5K_GPIOCR_OUT(gpio))) |
4381 (AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_ENA);
4383 ath5k_hw_reg_write(ah, interrupt_level ? data :
4384 (data | AR5K_GPIOCR_INT_SELH), AR5K_GPIOCR);
4386 ah->ah_imr |= AR5K_IMR_GPIO;
4388 /* Enable GPIO interrupts */
4389 AR5K_REG_ENABLE_BITS(ah, AR5K_PIMR, AR5K_IMR_GPIO);
4399 int ath5k_hw_get_capability(struct ath5k_hw *ah,
4400 enum ath5k_capability_type cap_type,
4401 u32 capability, u32 *result)
4403 ATH5K_TRACE(ah->ah_sc);
4406 case AR5K_CAP_NUM_TXQUEUES:
4408 if (ah->ah_version == AR5K_AR5210)
4409 *result = AR5K_NUM_TX_QUEUES_NOQCU;
4411 *result = AR5K_NUM_TX_QUEUES;
4416 case AR5K_CAP_COMPRESSION:
4417 if (ah->ah_version == AR5K_AR5212)
4421 case AR5K_CAP_BURST:
4425 case AR5K_CAP_BSSIDMASK:
4426 if (ah->ah_version == AR5K_AR5212)
4431 if (ah->ah_version == AR5K_AR5212)
4445 static int ath5k_hw_enable_pspoll(struct ath5k_hw *ah, u8 *bssid,
4448 ATH5K_TRACE(ah->ah_sc);
4450 if (ah->ah_version == AR5K_AR5210) {
4451 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
4452 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
4459 static int ath5k_hw_disable_pspoll(struct ath5k_hw *ah)
4461 ATH5K_TRACE(ah->ah_sc);
4463 if (ah->ah_version == AR5K_AR5210) {
4464 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
4465 AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);