2 * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
3 * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
4 * Copyright (c) 2007-2008 Matthew W. S. Bell <mentor@madwifi.org>
5 * Copyright (c) 2007-2008 Luis Rodriguez <mcgrof@winlab.rutgers.edu>
6 * Copyright (c) 2007-2008 Pavel Roskin <proski@gnu.org>
7 * Copyright (c) 2007-2008 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.
23 /*********************************\
24 * Protocol Control Unit Functions *
25 \*********************************/
27 #include <asm/unaligned.h>
39 * ath5k_hw_get_default_slottime - Get the default slot time for current mode
41 * @ah: The &struct ath5k_hw
43 static unsigned int ath5k_hw_get_default_slottime(struct ath5k_hw *ah)
45 struct ieee80211_channel *channel = ah->ah_current_channel;
47 if (channel->hw_value & CHANNEL_TURBO)
48 return 6; /* both turbo modes */
50 if (channel->hw_value & CHANNEL_CCK)
51 return 20; /* 802.11b */
53 return 9; /* 802.11 a/g */
57 * ath5k_hw_get_default_sifs - Get the default SIFS for current mode
59 * @ah: The &struct ath5k_hw
61 static unsigned int ath5k_hw_get_default_sifs(struct ath5k_hw *ah)
63 struct ieee80211_channel *channel = ah->ah_current_channel;
65 if (channel->hw_value & CHANNEL_TURBO)
66 return 8; /* both turbo modes */
68 if (channel->hw_value & CHANNEL_5GHZ)
69 return 16; /* 802.11a */
71 return 10; /* 802.11 b/g */
75 * ath5k_hw_update_mib_counters - Update MIB counters (mac layer statistics)
77 * @ah: The &struct ath5k_hw
79 * Reads MIB counters from PCU and updates sw statistics. Is called after a
80 * MIB interrupt, because one of these counters might have reached their maximum
81 * and triggered the MIB interrupt, to let us read and clear the counter.
83 * Is called in interrupt context!
85 void ath5k_hw_update_mib_counters(struct ath5k_hw *ah)
87 struct ath5k_statistics *stats = &ah->ah_sc->stats;
90 stats->ack_fail += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL);
91 stats->rts_fail += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL);
92 stats->rts_ok += ath5k_hw_reg_read(ah, AR5K_RTS_OK);
93 stats->fcs_error += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL);
94 stats->beacons += ath5k_hw_reg_read(ah, AR5K_BEACON_CNT);
98 * ath5k_hw_set_ack_bitrate - set bitrate for ACKs
100 * @ah: The &struct ath5k_hw
101 * @high: Flag to determine if we want to use high transmission rate
104 * If high flag is set, we tell hw to use a set of control rates based on
105 * the current transmission rate (check out control_rates array inside reset.c).
106 * If not hw just uses the lowest rate available for the current modulation
107 * scheme being used (1Mbit for CCK and 6Mbits for OFDM).
109 void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high)
111 if (ah->ah_version != AR5K_AR5212)
114 u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB;
116 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val);
118 AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val);
128 * index into rates for control rates, we can set it up like this because
129 * this is only used for AR5212 and we know it supports G mode
131 static const unsigned int control_rates[] =
132 { 0, 1, 1, 1, 4, 4, 6, 6, 8, 8, 8, 8 };
135 * ath5k_hw_write_rate_duration - fill rate code to duration table
137 * @ah: the &struct ath5k_hw
138 * @mode: one of enum ath5k_driver_mode
140 * Write the rate code to duration table upon hw reset. This is a helper for
141 * ath5k_hw_reset(). It seems all this is doing is setting an ACK timeout on
142 * the hardware, based on current mode, for each rate. The rates which are
143 * capable of short preamble (802.11b rates 2Mbps, 5.5Mbps, and 11Mbps) have
144 * different rate code so we write their value twice (one for long preamble
145 * and one for short).
147 * Note: Band doesn't matter here, if we set the values for OFDM it works
148 * on both a and g modes. So all we have to do is set values for all g rates
149 * that include all OFDM and CCK rates. If we operate in turbo or xr/half/
150 * quarter rate mode, we need to use another set of bitrates (that's why we
151 * need the mode parameter) but we don't handle these proprietary modes yet.
153 static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
156 struct ath5k_softc *sc = ah->ah_sc;
157 struct ieee80211_rate *rate;
160 /* Write rate duration table */
161 for (i = 0; i < sc->sbands[IEEE80211_BAND_2GHZ].n_bitrates; i++) {
165 rate = &sc->sbands[IEEE80211_BAND_2GHZ].bitrates[control_rates[i]];
167 /* Set ACK timeout */
168 reg = AR5K_RATE_DUR(rate->hw_value);
170 /* An ACK frame consists of 10 bytes. If you add the FCS,
171 * which ieee80211_generic_frame_duration() adds,
172 * its 14 bytes. Note we use the control rate and not the
173 * actual rate for this rate. See mac80211 tx.c
174 * ieee80211_duration() for a brief description of
175 * what rate we should choose to TX ACKs. */
176 tx_time = le16_to_cpu(ieee80211_generic_frame_duration(sc->hw,
179 ath5k_hw_reg_write(ah, tx_time, reg);
181 if (!(rate->flags & IEEE80211_RATE_SHORT_PREAMBLE))
185 * We're not distinguishing short preamble here,
186 * This is true, all we'll get is a longer value here
187 * which is not necessarilly bad. We could use
188 * export ieee80211_frame_duration() but that needs to be
189 * fixed first to be properly used by mac802111 drivers:
191 * - remove erp stuff and let the routine figure ofdm
193 * - remove passing argument ieee80211_local as
194 * drivers don't have access to it
195 * - move drivers using ieee80211_generic_frame_duration()
198 ath5k_hw_reg_write(ah, tx_time,
199 reg + (AR5K_SET_SHORT_PREAMBLE << 2));
204 * ath5k_hw_set_ack_timeout - Set ACK timeout on PCU
206 * @ah: The &struct ath5k_hw
207 * @timeout: Timeout in usec
209 static int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout)
211 if (ath5k_hw_clocktoh(ah, AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK))
215 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK,
216 ath5k_hw_htoclock(ah, timeout));
222 * ath5k_hw_set_cts_timeout - Set CTS timeout on PCU
224 * @ah: The &struct ath5k_hw
225 * @timeout: Timeout in usec
227 static int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout)
229 if (ath5k_hw_clocktoh(ah, AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS))
233 AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS,
234 ath5k_hw_htoclock(ah, timeout));
240 /*******************\
241 * RX filter Control *
242 \*******************/
245 * ath5k_hw_set_lladdr - Set station id
247 * @ah: The &struct ath5k_hw
248 * @mac: The card's mac address
250 * Set station id on hw using the provided mac address
252 int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
254 struct ath_common *common = ath5k_hw_common(ah);
258 /* Set new station ID */
259 memcpy(common->macaddr, mac, ETH_ALEN);
261 pcu_reg = ath5k_hw_reg_read(ah, AR5K_STA_ID1) & 0xffff0000;
263 low_id = get_unaligned_le32(mac);
264 high_id = get_unaligned_le16(mac + 4);
266 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
267 ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
273 * ath5k_hw_set_bssid - Set current BSSID on hw
275 * @ah: The &struct ath5k_hw
277 * Sets the current BSSID and BSSID mask we have from the
278 * common struct into the hardware
280 void ath5k_hw_set_bssid(struct ath5k_hw *ah)
282 struct ath_common *common = ath5k_hw_common(ah);
286 * Set BSSID mask on 5212
288 if (ah->ah_version == AR5K_AR5212)
289 ath_hw_setbssidmask(common);
294 ath5k_hw_reg_write(ah,
295 get_unaligned_le32(common->curbssid),
297 ath5k_hw_reg_write(ah,
298 get_unaligned_le16(common->curbssid + 4) |
299 ((common->curaid & 0x3fff) << AR5K_BSS_ID1_AID_S),
302 if (common->curaid == 0) {
303 ath5k_hw_disable_pspoll(ah);
307 AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM,
308 tim_offset ? tim_offset + 4 : 0);
310 ath5k_hw_enable_pspoll(ah, NULL, 0);
313 void ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
315 struct ath_common *common = ath5k_hw_common(ah);
317 /* Cache bssid mask so that we can restore it
319 memcpy(common->bssidmask, mask, ETH_ALEN);
320 if (ah->ah_version == AR5K_AR5212)
321 ath_hw_setbssidmask(common);
325 * Set multicast filter
327 void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
329 ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0);
330 ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1);
334 * ath5k_hw_get_rx_filter - Get current rx filter
336 * @ah: The &struct ath5k_hw
338 * Returns the RX filter by reading rx filter and
339 * phy error filter registers. RX filter is used
340 * to set the allowed frame types that PCU will accept
341 * and pass to the driver. For a list of frame types
344 u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah)
346 u32 data, filter = 0;
348 filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER);
350 /*Radar detection for 5212*/
351 if (ah->ah_version == AR5K_AR5212) {
352 data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL);
354 if (data & AR5K_PHY_ERR_FIL_RADAR)
355 filter |= AR5K_RX_FILTER_RADARERR;
356 if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK))
357 filter |= AR5K_RX_FILTER_PHYERR;
364 * ath5k_hw_set_rx_filter - Set rx filter
366 * @ah: The &struct ath5k_hw
367 * @filter: RX filter mask (see reg.h)
369 * Sets RX filter register and also handles PHY error filter
370 * register on 5212 and newer chips so that we have proper PHY
373 void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
377 /* Set PHY error filter register on 5212*/
378 if (ah->ah_version == AR5K_AR5212) {
379 if (filter & AR5K_RX_FILTER_RADARERR)
380 data |= AR5K_PHY_ERR_FIL_RADAR;
381 if (filter & AR5K_RX_FILTER_PHYERR)
382 data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK;
386 * The AR5210 uses promiscous mode to detect radar activity
388 if (ah->ah_version == AR5K_AR5210 &&
389 (filter & AR5K_RX_FILTER_RADARERR)) {
390 filter &= ~AR5K_RX_FILTER_RADARERR;
391 filter |= AR5K_RX_FILTER_PROM;
394 /*Zero length DMA (phy error reporting) */
396 AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
398 AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
400 /*Write RX Filter register*/
401 ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER);
403 /*Write PHY error filter register on 5212*/
404 if (ah->ah_version == AR5K_AR5212)
405 ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
414 #define ATH5K_MAX_TSF_READ 10
417 * ath5k_hw_get_tsf64 - Get the full 64bit TSF
419 * @ah: The &struct ath5k_hw
421 * Returns the current TSF
423 u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah)
425 u32 tsf_lower, tsf_upper1, tsf_upper2;
429 /* This code is time critical - we don't want to be interrupted here */
430 local_irq_save(flags);
433 * While reading TSF upper and then lower part, the clock is still
434 * counting (or jumping in case of IBSS merge) so we might get
435 * inconsistent values. To avoid this, we read the upper part again
436 * and check it has not been changed. We make the hypothesis that a
437 * maximum of 3 changes can happens in a row (we use 10 as a safe
440 * Impact on performance is pretty small, since in most cases, only
441 * 3 register reads are needed.
444 tsf_upper1 = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
445 for (i = 0; i < ATH5K_MAX_TSF_READ; i++) {
446 tsf_lower = ath5k_hw_reg_read(ah, AR5K_TSF_L32);
447 tsf_upper2 = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
448 if (tsf_upper2 == tsf_upper1)
450 tsf_upper1 = tsf_upper2;
453 local_irq_restore(flags);
455 WARN_ON( i == ATH5K_MAX_TSF_READ );
457 return (((u64)tsf_upper1 << 32) | tsf_lower);
461 * ath5k_hw_set_tsf64 - Set a new 64bit TSF
463 * @ah: The &struct ath5k_hw
464 * @tsf64: The new 64bit TSF
468 void ath5k_hw_set_tsf64(struct ath5k_hw *ah, u64 tsf64)
470 ath5k_hw_reg_write(ah, tsf64 & 0xffffffff, AR5K_TSF_L32);
471 ath5k_hw_reg_write(ah, (tsf64 >> 32) & 0xffffffff, AR5K_TSF_U32);
475 * ath5k_hw_reset_tsf - Force a TSF reset
477 * @ah: The &struct ath5k_hw
479 * Forces a TSF reset on PCU
481 void ath5k_hw_reset_tsf(struct ath5k_hw *ah)
485 val = ath5k_hw_reg_read(ah, AR5K_BEACON) | AR5K_BEACON_RESET_TSF;
488 * Each write to the RESET_TSF bit toggles a hardware internal
489 * signal to reset TSF, but if left high it will cause a TSF reset
490 * on the next chip reset as well. Thus we always write the value
491 * twice to clear the signal.
493 ath5k_hw_reg_write(ah, val, AR5K_BEACON);
494 ath5k_hw_reg_write(ah, val, AR5K_BEACON);
498 * Initialize beacon timers
500 void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
502 u32 timer1, timer2, timer3;
505 * Set the additional timers by mode
507 switch (ah->ah_sc->opmode) {
508 case NL80211_IFTYPE_MONITOR:
509 case NL80211_IFTYPE_STATION:
510 /* In STA mode timer1 is used as next wakeup
511 * timer and timer2 as next CFP duration start
512 * timer. Both in 1/8TUs. */
513 /* TODO: PCF handling */
514 if (ah->ah_version == AR5K_AR5210) {
521 /* Mark associated AP as PCF incapable for now */
522 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, AR5K_STA_ID1_PCF);
524 case NL80211_IFTYPE_ADHOC:
525 AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG, AR5K_TXCFG_ADHOC_BCN_ATIM);
527 /* On non-STA modes timer1 is used as next DMA
528 * beacon alert (DBA) timer and timer2 as next
529 * software beacon alert. Both in 1/8TUs. */
530 timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3;
531 timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3;
535 /* Timer3 marks the end of our ATIM window
536 * a zero length window is not allowed because
537 * we 'll get no beacons */
538 timer3 = next_beacon + 1;
541 * Set the beacon register and enable all timers.
543 /* When in AP or Mesh Point mode zero timer0 to start TSF */
544 if (ah->ah_sc->opmode == NL80211_IFTYPE_AP ||
545 ah->ah_sc->opmode == NL80211_IFTYPE_MESH_POINT)
546 ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
548 ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
549 ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
550 ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
551 ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
553 /* Force a TSF reset if requested and enable beacons */
554 if (interval & AR5K_BEACON_RESET_TSF)
555 ath5k_hw_reset_tsf(ah);
557 ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD |
561 /* Flush any pending BMISS interrupts on ISR by
562 * performing a clear-on-write operation on PISR
563 * register for the BMISS bit (writing a bit on
564 * ISR togles a reset for that bit and leaves
565 * the rest bits intact) */
566 if (ah->ah_version == AR5K_AR5210)
567 ath5k_hw_reg_write(ah, AR5K_ISR_BMISS, AR5K_ISR);
569 ath5k_hw_reg_write(ah, AR5K_ISR_BMISS, AR5K_PISR);
571 /* TODO: Set enchanced sleep registers on AR5212
572 * based on vif->bss_conf params, until then
573 * disable power save reporting.*/
574 AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, AR5K_STA_ID1_PWR_SV);
579 * ath5k_check_timer_win - Check if timer B is timer A + window
581 * @a: timer a (before b)
582 * @b: timer b (after a)
583 * @window: difference between a and b
584 * @intval: timers are increased by this interval
586 * This helper function checks if timer B is timer A + window and covers
587 * cases where timer A or B might have already been updated or wrapped
588 * around (Timers are 16 bit).
590 * Returns true if O.K.
593 ath5k_check_timer_win(int a, int b, int window, int intval)
596 * 1.) usually B should be A + window
597 * 2.) A already updated, B not updated yet
598 * 3.) A already updated and has wrapped around
599 * 4.) B has wrapped around
601 if ((b - a == window) || /* 1.) */
602 (a - b == intval - window) || /* 2.) */
603 ((a | 0x10000) - b == intval - window) || /* 3.) */
604 ((b | 0x10000) - a == window)) /* 4.) */
605 return true; /* O.K. */
610 * ath5k_hw_check_beacon_timers - Check if the beacon timers are correct
612 * @ah: The &struct ath5k_hw
613 * @intval: beacon interval
615 * This is a workaround for IBSS mode:
617 * The need for this function arises from the fact that we have 4 separate
618 * HW timer registers (TIMER0 - TIMER3), which are closely related to the
619 * next beacon target time (NBTT), and that the HW updates these timers
620 * seperately based on the current TSF value. The hardware increments each
621 * timer by the beacon interval, when the local TSF coverted to TU is equal
622 * to the value stored in the timer.
624 * The reception of a beacon with the same BSSID can update the local HW TSF
625 * at any time - this is something we can't avoid. If the TSF jumps to a
626 * time which is later than the time stored in a timer, this timer will not
627 * be updated until the TSF in TU wraps around at 16 bit (the size of the
628 * timers) and reaches the time which is stored in the timer.
630 * The problem is that these timers are closely related to TIMER0 (NBTT) and
631 * that they define a time "window". When the TSF jumps between two timers
632 * (e.g. ATIM and NBTT), the one in the past will be left behind (not
633 * updated), while the one in the future will be updated every beacon
634 * interval. This causes the window to get larger, until the TSF wraps
635 * around as described above and the timer which was left behind gets
636 * updated again. But - because the beacon interval is usually not an exact
637 * divisor of the size of the timers (16 bit), an unwanted "window" between
638 * these timers has developed!
640 * This is especially important with the ATIM window, because during
641 * the ATIM window only ATIM frames and no data frames are allowed to be
642 * sent, which creates transmission pauses after each beacon. This symptom
643 * has been described as "ramping ping" because ping times increase linearly
644 * for some time and then drop down again. A wrong window on the DMA beacon
645 * timer has the same effect, so we check for these two conditions.
647 * Returns true if O.K.
650 ath5k_hw_check_beacon_timers(struct ath5k_hw *ah, int intval)
652 unsigned int nbtt, atim, dma;
654 nbtt = ath5k_hw_reg_read(ah, AR5K_TIMER0);
655 atim = ath5k_hw_reg_read(ah, AR5K_TIMER3);
656 dma = ath5k_hw_reg_read(ah, AR5K_TIMER1) >> 3;
658 /* NOTE: SWBA is different. Having a wrong window there does not
659 * stop us from sending data and this condition is catched thru
660 * other means (SWBA interrupt) */
662 if (ath5k_check_timer_win(nbtt, atim, 1, intval) &&
663 ath5k_check_timer_win(dma, nbtt, AR5K_TUNE_DMA_BEACON_RESP,
665 return true; /* O.K. */
670 * ath5k_hw_set_coverage_class - Set IEEE 802.11 coverage class
672 * @ah: The &struct ath5k_hw
673 * @coverage_class: IEEE 802.11 coverage class number
675 * Sets slot time, ACK timeout and CTS timeout for given coverage class.
677 void ath5k_hw_set_coverage_class(struct ath5k_hw *ah, u8 coverage_class)
679 /* As defined by IEEE 802.11-2007 17.3.8.6 */
680 int slot_time = ath5k_hw_get_default_slottime(ah) + 3 * coverage_class;
681 int ack_timeout = ath5k_hw_get_default_sifs(ah) + slot_time;
682 int cts_timeout = ack_timeout;
684 ath5k_hw_set_slot_time(ah, slot_time);
685 ath5k_hw_set_ack_timeout(ah, ack_timeout);
686 ath5k_hw_set_cts_timeout(ah, cts_timeout);
688 ah->ah_coverage_class = coverage_class;
691 /***************************\
692 * Init/Start/Stop functions *
693 \***************************/
696 * ath5k_hw_start_rx_pcu - Start RX engine
698 * @ah: The &struct ath5k_hw
700 * Starts RX engine on PCU so that hw can process RXed frames
703 * NOTE: RX DMA should be already enabled using ath5k_hw_start_rx_dma
705 void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
707 AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
711 * at5k_hw_stop_rx_pcu - Stop RX engine
713 * @ah: The &struct ath5k_hw
715 * Stops RX engine on PCU
717 void ath5k_hw_stop_rx_pcu(struct ath5k_hw *ah)
719 AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
723 * ath5k_hw_set_opmode - Set PCU operating mode
725 * @ah: The &struct ath5k_hw
726 * @op_mode: &enum nl80211_iftype operating mode
728 * Configure PCU for the various operating modes (AP/STA etc)
730 int ath5k_hw_set_opmode(struct ath5k_hw *ah, enum nl80211_iftype op_mode)
732 struct ath_common *common = ath5k_hw_common(ah);
733 u32 pcu_reg, beacon_reg, low_id, high_id;
735 ATH5K_DBG(ah->ah_sc, ATH5K_DEBUG_MODE, "mode %d\n", op_mode);
737 /* Preserve rest settings */
738 pcu_reg = ath5k_hw_reg_read(ah, AR5K_STA_ID1) & 0xffff0000;
739 pcu_reg &= ~(AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_AP
740 | AR5K_STA_ID1_KEYSRCH_MODE
741 | (ah->ah_version == AR5K_AR5210 ?
742 (AR5K_STA_ID1_PWR_SV | AR5K_STA_ID1_NO_PSPOLL) : 0));
747 case NL80211_IFTYPE_ADHOC:
748 pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_KEYSRCH_MODE;
749 beacon_reg |= AR5K_BCR_ADHOC;
750 if (ah->ah_version == AR5K_AR5210)
751 pcu_reg |= AR5K_STA_ID1_NO_PSPOLL;
753 AR5K_REG_ENABLE_BITS(ah, AR5K_CFG, AR5K_CFG_IBSS);
756 case NL80211_IFTYPE_AP:
757 case NL80211_IFTYPE_MESH_POINT:
758 pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_KEYSRCH_MODE;
759 beacon_reg |= AR5K_BCR_AP;
760 if (ah->ah_version == AR5K_AR5210)
761 pcu_reg |= AR5K_STA_ID1_NO_PSPOLL;
763 AR5K_REG_DISABLE_BITS(ah, AR5K_CFG, AR5K_CFG_IBSS);
766 case NL80211_IFTYPE_STATION:
767 pcu_reg |= AR5K_STA_ID1_KEYSRCH_MODE
768 | (ah->ah_version == AR5K_AR5210 ?
769 AR5K_STA_ID1_PWR_SV : 0);
770 case NL80211_IFTYPE_MONITOR:
771 pcu_reg |= AR5K_STA_ID1_KEYSRCH_MODE
772 | (ah->ah_version == AR5K_AR5210 ?
773 AR5K_STA_ID1_NO_PSPOLL : 0);
783 low_id = get_unaligned_le32(common->macaddr);
784 high_id = get_unaligned_le16(common->macaddr + 4);
785 ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
786 ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
789 * Set Beacon Control Register on 5210
791 if (ah->ah_version == AR5K_AR5210)
792 ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR);
797 void ath5k_hw_pcu_init(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
800 /* Set bssid and bssid mask */
801 ath5k_hw_set_bssid(ah);
804 ath5k_hw_set_opmode(ah, op_mode);
806 /* Write rate duration table only on AR5212 and if
807 * virtual interface has already been brought up
808 * XXX: rethink this after new mode changes to
809 * mac80211 are integrated */
810 if (ah->ah_version == AR5K_AR5212 &&
812 ath5k_hw_write_rate_duration(ah, mode);
814 /* Set RSSI/BRSSI thresholds
816 * Note: If we decide to set this value
817 * dynamicaly, have in mind that when AR5K_RSSI_THR
818 * register is read it might return 0x40 if we haven't
819 * wrote anything to it plus BMISS RSSI threshold is zeroed.
820 * So doing a save/restore procedure here isn't the right
821 * choice. Instead store it on ath5k_hw */
822 ath5k_hw_reg_write(ah, (AR5K_TUNE_RSSI_THRES |
823 AR5K_TUNE_BMISS_THRES <<
824 AR5K_RSSI_THR_BMISS_S),
827 /* MIC QoS support */
828 if (ah->ah_mac_srev >= AR5K_SREV_AR2413) {
829 ath5k_hw_reg_write(ah, 0x000100aa, AR5K_MIC_QOS_CTL);
830 ath5k_hw_reg_write(ah, 0x00003210, AR5K_MIC_QOS_SEL);
833 /* QoS NOACK Policy */
834 if (ah->ah_version == AR5K_AR5212) {
835 ath5k_hw_reg_write(ah,
836 AR5K_REG_SM(2, AR5K_QOS_NOACK_2BIT_VALUES) |
837 AR5K_REG_SM(5, AR5K_QOS_NOACK_BIT_OFFSET) |
838 AR5K_REG_SM(0, AR5K_QOS_NOACK_BYTE_OFFSET),
842 /* Restore slot time and ACK timeouts */
843 if (ah->ah_coverage_class > 0)
844 ath5k_hw_set_coverage_class(ah, ah->ah_coverage_class);