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>
35 * AR5212+ can use higher rates for ack transmition
36 * based on current tx rate instead of the base rate.
37 * It does this to better utilize channel usage.
38 * This is a mapping between G rates (that cover both
39 * CCK and OFDM) and ack rates that we use when setting
40 * rate -> duration table. This mapping is hw-based so
41 * don't change anything.
43 * To enable this functionality we must set
44 * ah->ah_ack_bitrate_high to true else base rate is
45 * used (1Mb for CCK, 6Mb for OFDM).
47 static const unsigned int ack_rates_high
[] =
60 /* 54Mb -> 24Mb */ 8 };
67 * ath5k_hw_get_frame_duration - Get tx time of a frame
69 * @ah: The &struct ath5k_hw
70 * @len: Frame's length in bytes
71 * @rate: The @struct ieee80211_rate
73 * Calculate tx duration of a frame given it's rate and length
74 * It extends ieee80211_generic_frame_duration for non standard
77 int ath5k_hw_get_frame_duration(struct ath5k_hw
*ah
,
78 int len
, struct ieee80211_rate
*rate
)
80 struct ath5k_softc
*sc
= ah
->ah_sc
;
81 int sifs
, preamble
, plcp_bits
, sym_time
;
82 int bitrate
, bits
, symbols
, symbol_bits
;
87 dur
= ieee80211_generic_frame_duration(sc
->hw
,
92 bitrate
= rate
->bitrate
;
93 preamble
= AR5K_INIT_OFDM_PREAMPLE_TIME
;
94 plcp_bits
= AR5K_INIT_OFDM_PLCP_BITS
;
95 sym_time
= AR5K_INIT_OFDM_SYMBOL_TIME
;
97 switch (ah
->ah_bwmode
) {
98 case AR5K_BWMODE_40MHZ
:
99 sifs
= AR5K_INIT_SIFS_TURBO
;
100 preamble
= AR5K_INIT_OFDM_PREAMBLE_TIME_MIN
;
102 case AR5K_BWMODE_10MHZ
:
103 sifs
= AR5K_INIT_SIFS_HALF_RATE
;
107 case AR5K_BWMODE_5MHZ
:
108 sifs
= AR5K_INIT_SIFS_QUARTER_RATE
;
113 sifs
= AR5K_INIT_SIFS_DEFAULT_BG
;
117 bits
= plcp_bits
+ (len
<< 3);
118 /* Bit rate is in 100Kbits */
119 symbol_bits
= bitrate
* sym_time
;
120 symbols
= DIV_ROUND_UP(bits
* 10, symbol_bits
);
122 dur
= sifs
+ preamble
+ (sym_time
* symbols
);
128 * ath5k_hw_get_default_slottime - Get the default slot time for current mode
130 * @ah: The &struct ath5k_hw
132 unsigned int ath5k_hw_get_default_slottime(struct ath5k_hw
*ah
)
134 struct ieee80211_channel
*channel
= ah
->ah_current_channel
;
135 unsigned int slot_time
;
137 switch (ah
->ah_bwmode
) {
138 case AR5K_BWMODE_40MHZ
:
139 slot_time
= AR5K_INIT_SLOT_TIME_TURBO
;
141 case AR5K_BWMODE_10MHZ
:
142 slot_time
= AR5K_INIT_SLOT_TIME_HALF_RATE
;
144 case AR5K_BWMODE_5MHZ
:
145 slot_time
= AR5K_INIT_SLOT_TIME_QUARTER_RATE
;
147 case AR5K_BWMODE_DEFAULT
:
148 slot_time
= AR5K_INIT_SLOT_TIME_DEFAULT
;
150 if (channel
->hw_value
& CHANNEL_CCK
)
151 slot_time
= AR5K_INIT_SLOT_TIME_B
;
159 * ath5k_hw_get_default_sifs - Get the default SIFS for current mode
161 * @ah: The &struct ath5k_hw
163 unsigned int ath5k_hw_get_default_sifs(struct ath5k_hw
*ah
)
165 struct ieee80211_channel
*channel
= ah
->ah_current_channel
;
168 switch (ah
->ah_bwmode
) {
169 case AR5K_BWMODE_40MHZ
:
170 sifs
= AR5K_INIT_SIFS_TURBO
;
172 case AR5K_BWMODE_10MHZ
:
173 sifs
= AR5K_INIT_SIFS_HALF_RATE
;
175 case AR5K_BWMODE_5MHZ
:
176 sifs
= AR5K_INIT_SIFS_QUARTER_RATE
;
178 case AR5K_BWMODE_DEFAULT
:
179 sifs
= AR5K_INIT_SIFS_DEFAULT_BG
;
181 if (channel
->hw_value
& CHANNEL_5GHZ
)
182 sifs
= AR5K_INIT_SIFS_DEFAULT_A
;
190 * ath5k_hw_update_mib_counters - Update MIB counters (mac layer statistics)
192 * @ah: The &struct ath5k_hw
194 * Reads MIB counters from PCU and updates sw statistics. Is called after a
195 * MIB interrupt, because one of these counters might have reached their maximum
196 * and triggered the MIB interrupt, to let us read and clear the counter.
198 * Is called in interrupt context!
200 void ath5k_hw_update_mib_counters(struct ath5k_hw
*ah
)
202 struct ath5k_statistics
*stats
= &ah
->ah_sc
->stats
;
205 stats
->ack_fail
+= ath5k_hw_reg_read(ah
, AR5K_ACK_FAIL
);
206 stats
->rts_fail
+= ath5k_hw_reg_read(ah
, AR5K_RTS_FAIL
);
207 stats
->rts_ok
+= ath5k_hw_reg_read(ah
, AR5K_RTS_OK
);
208 stats
->fcs_error
+= ath5k_hw_reg_read(ah
, AR5K_FCS_FAIL
);
209 stats
->beacons
+= ath5k_hw_reg_read(ah
, AR5K_BEACON_CNT
);
218 * ath5k_hw_write_rate_duration - fill rate code to duration table
220 * @ah: the &struct ath5k_hw
221 * @mode: one of enum ath5k_driver_mode
223 * Write the rate code to duration table upon hw reset. This is a helper for
224 * ath5k_hw_pcu_init(). It seems all this is doing is setting an ACK timeout on
225 * the hardware, based on current mode, for each rate. The rates which are
226 * capable of short preamble (802.11b rates 2Mbps, 5.5Mbps, and 11Mbps) have
227 * different rate code so we write their value twice (one for long preamble
228 * and one for short).
230 * Note: Band doesn't matter here, if we set the values for OFDM it works
231 * on both a and g modes. So all we have to do is set values for all g rates
232 * that include all OFDM and CCK rates.
235 static inline void ath5k_hw_write_rate_duration(struct ath5k_hw
*ah
)
237 struct ath5k_softc
*sc
= ah
->ah_sc
;
238 struct ieee80211_rate
*rate
;
240 /* 802.11g covers both OFDM and CCK */
241 u8 band
= IEEE80211_BAND_2GHZ
;
243 /* Write rate duration table */
244 for (i
= 0; i
< sc
->sbands
[band
].n_bitrates
; i
++) {
248 if (ah
->ah_ack_bitrate_high
)
249 rate
= &sc
->sbands
[band
].bitrates
[ack_rates_high
[i
]];
252 rate
= &sc
->sbands
[band
].bitrates
[0];
255 rate
= &sc
->sbands
[band
].bitrates
[4];
257 /* Set ACK timeout */
258 reg
= AR5K_RATE_DUR(rate
->hw_value
);
260 /* An ACK frame consists of 10 bytes. If you add the FCS,
261 * which ieee80211_generic_frame_duration() adds,
262 * its 14 bytes. Note we use the control rate and not the
263 * actual rate for this rate. See mac80211 tx.c
264 * ieee80211_duration() for a brief description of
265 * what rate we should choose to TX ACKs. */
266 tx_time
= ath5k_hw_get_frame_duration(ah
, 10, rate
);
268 tx_time
= le16_to_cpu(tx_time
);
270 ath5k_hw_reg_write(ah
, tx_time
, reg
);
272 if (!(rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
))
276 * We're not distinguishing short preamble here,
277 * This is true, all we'll get is a longer value here
278 * which is not necessarilly bad. We could use
279 * export ieee80211_frame_duration() but that needs to be
280 * fixed first to be properly used by mac802111 drivers:
282 * - remove erp stuff and let the routine figure ofdm
284 * - remove passing argument ieee80211_local as
285 * drivers don't have access to it
286 * - move drivers using ieee80211_generic_frame_duration()
289 ath5k_hw_reg_write(ah
, tx_time
,
290 reg
+ (AR5K_SET_SHORT_PREAMBLE
<< 2));
295 * ath5k_hw_set_ack_timeout - Set ACK timeout on PCU
297 * @ah: The &struct ath5k_hw
298 * @timeout: Timeout in usec
300 static int ath5k_hw_set_ack_timeout(struct ath5k_hw
*ah
, unsigned int timeout
)
302 if (ath5k_hw_clocktoh(ah
, AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK
))
306 AR5K_REG_WRITE_BITS(ah
, AR5K_TIME_OUT
, AR5K_TIME_OUT_ACK
,
307 ath5k_hw_htoclock(ah
, timeout
));
313 * ath5k_hw_set_cts_timeout - Set CTS timeout on PCU
315 * @ah: The &struct ath5k_hw
316 * @timeout: Timeout in usec
318 static int ath5k_hw_set_cts_timeout(struct ath5k_hw
*ah
, unsigned int timeout
)
320 if (ath5k_hw_clocktoh(ah
, AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS
))
324 AR5K_REG_WRITE_BITS(ah
, AR5K_TIME_OUT
, AR5K_TIME_OUT_CTS
,
325 ath5k_hw_htoclock(ah
, timeout
));
331 /*******************\
332 * RX filter Control *
333 \*******************/
336 * ath5k_hw_set_lladdr - Set station id
338 * @ah: The &struct ath5k_hw
339 * @mac: The card's mac address
341 * Set station id on hw using the provided mac address
343 int ath5k_hw_set_lladdr(struct ath5k_hw
*ah
, const u8
*mac
)
345 struct ath_common
*common
= ath5k_hw_common(ah
);
349 /* Set new station ID */
350 memcpy(common
->macaddr
, mac
, ETH_ALEN
);
352 pcu_reg
= ath5k_hw_reg_read(ah
, AR5K_STA_ID1
) & 0xffff0000;
354 low_id
= get_unaligned_le32(mac
);
355 high_id
= get_unaligned_le16(mac
+ 4);
357 ath5k_hw_reg_write(ah
, low_id
, AR5K_STA_ID0
);
358 ath5k_hw_reg_write(ah
, pcu_reg
| high_id
, AR5K_STA_ID1
);
364 * ath5k_hw_set_bssid - Set current BSSID on hw
366 * @ah: The &struct ath5k_hw
368 * Sets the current BSSID and BSSID mask we have from the
369 * common struct into the hardware
371 void ath5k_hw_set_bssid(struct ath5k_hw
*ah
)
373 struct ath_common
*common
= ath5k_hw_common(ah
);
377 * Set BSSID mask on 5212
379 if (ah
->ah_version
== AR5K_AR5212
)
380 ath_hw_setbssidmask(common
);
385 ath5k_hw_reg_write(ah
,
386 get_unaligned_le32(common
->curbssid
),
388 ath5k_hw_reg_write(ah
,
389 get_unaligned_le16(common
->curbssid
+ 4) |
390 ((common
->curaid
& 0x3fff) << AR5K_BSS_ID1_AID_S
),
393 if (common
->curaid
== 0) {
394 ath5k_hw_disable_pspoll(ah
);
398 AR5K_REG_WRITE_BITS(ah
, AR5K_BEACON
, AR5K_BEACON_TIM
,
399 tim_offset
? tim_offset
+ 4 : 0);
401 ath5k_hw_enable_pspoll(ah
, NULL
, 0);
404 void ath5k_hw_set_bssid_mask(struct ath5k_hw
*ah
, const u8
*mask
)
406 struct ath_common
*common
= ath5k_hw_common(ah
);
408 /* Cache bssid mask so that we can restore it
410 memcpy(common
->bssidmask
, mask
, ETH_ALEN
);
411 if (ah
->ah_version
== AR5K_AR5212
)
412 ath_hw_setbssidmask(common
);
416 * Set multicast filter
418 void ath5k_hw_set_mcast_filter(struct ath5k_hw
*ah
, u32 filter0
, u32 filter1
)
420 ath5k_hw_reg_write(ah
, filter0
, AR5K_MCAST_FILTER0
);
421 ath5k_hw_reg_write(ah
, filter1
, AR5K_MCAST_FILTER1
);
425 * ath5k_hw_get_rx_filter - Get current rx filter
427 * @ah: The &struct ath5k_hw
429 * Returns the RX filter by reading rx filter and
430 * phy error filter registers. RX filter is used
431 * to set the allowed frame types that PCU will accept
432 * and pass to the driver. For a list of frame types
435 u32
ath5k_hw_get_rx_filter(struct ath5k_hw
*ah
)
437 u32 data
, filter
= 0;
439 filter
= ath5k_hw_reg_read(ah
, AR5K_RX_FILTER
);
441 /*Radar detection for 5212*/
442 if (ah
->ah_version
== AR5K_AR5212
) {
443 data
= ath5k_hw_reg_read(ah
, AR5K_PHY_ERR_FIL
);
445 if (data
& AR5K_PHY_ERR_FIL_RADAR
)
446 filter
|= AR5K_RX_FILTER_RADARERR
;
447 if (data
& (AR5K_PHY_ERR_FIL_OFDM
| AR5K_PHY_ERR_FIL_CCK
))
448 filter
|= AR5K_RX_FILTER_PHYERR
;
455 * ath5k_hw_set_rx_filter - Set rx filter
457 * @ah: The &struct ath5k_hw
458 * @filter: RX filter mask (see reg.h)
460 * Sets RX filter register and also handles PHY error filter
461 * register on 5212 and newer chips so that we have proper PHY
464 void ath5k_hw_set_rx_filter(struct ath5k_hw
*ah
, u32 filter
)
468 /* Set PHY error filter register on 5212*/
469 if (ah
->ah_version
== AR5K_AR5212
) {
470 if (filter
& AR5K_RX_FILTER_RADARERR
)
471 data
|= AR5K_PHY_ERR_FIL_RADAR
;
472 if (filter
& AR5K_RX_FILTER_PHYERR
)
473 data
|= AR5K_PHY_ERR_FIL_OFDM
| AR5K_PHY_ERR_FIL_CCK
;
477 * The AR5210 uses promiscous mode to detect radar activity
479 if (ah
->ah_version
== AR5K_AR5210
&&
480 (filter
& AR5K_RX_FILTER_RADARERR
)) {
481 filter
&= ~AR5K_RX_FILTER_RADARERR
;
482 filter
|= AR5K_RX_FILTER_PROM
;
485 /*Zero length DMA (phy error reporting) */
487 AR5K_REG_ENABLE_BITS(ah
, AR5K_RXCFG
, AR5K_RXCFG_ZLFDMA
);
489 AR5K_REG_DISABLE_BITS(ah
, AR5K_RXCFG
, AR5K_RXCFG_ZLFDMA
);
491 /*Write RX Filter register*/
492 ath5k_hw_reg_write(ah
, filter
& 0xff, AR5K_RX_FILTER
);
494 /*Write PHY error filter register on 5212*/
495 if (ah
->ah_version
== AR5K_AR5212
)
496 ath5k_hw_reg_write(ah
, data
, AR5K_PHY_ERR_FIL
);
505 #define ATH5K_MAX_TSF_READ 10
508 * ath5k_hw_get_tsf64 - Get the full 64bit TSF
510 * @ah: The &struct ath5k_hw
512 * Returns the current TSF
514 u64
ath5k_hw_get_tsf64(struct ath5k_hw
*ah
)
516 u32 tsf_lower
, tsf_upper1
, tsf_upper2
;
520 /* This code is time critical - we don't want to be interrupted here */
521 local_irq_save(flags
);
524 * While reading TSF upper and then lower part, the clock is still
525 * counting (or jumping in case of IBSS merge) so we might get
526 * inconsistent values. To avoid this, we read the upper part again
527 * and check it has not been changed. We make the hypothesis that a
528 * maximum of 3 changes can happens in a row (we use 10 as a safe
531 * Impact on performance is pretty small, since in most cases, only
532 * 3 register reads are needed.
535 tsf_upper1
= ath5k_hw_reg_read(ah
, AR5K_TSF_U32
);
536 for (i
= 0; i
< ATH5K_MAX_TSF_READ
; i
++) {
537 tsf_lower
= ath5k_hw_reg_read(ah
, AR5K_TSF_L32
);
538 tsf_upper2
= ath5k_hw_reg_read(ah
, AR5K_TSF_U32
);
539 if (tsf_upper2
== tsf_upper1
)
541 tsf_upper1
= tsf_upper2
;
544 local_irq_restore(flags
);
546 WARN_ON( i
== ATH5K_MAX_TSF_READ
);
548 return (((u64
)tsf_upper1
<< 32) | tsf_lower
);
552 * ath5k_hw_set_tsf64 - Set a new 64bit TSF
554 * @ah: The &struct ath5k_hw
555 * @tsf64: The new 64bit TSF
559 void ath5k_hw_set_tsf64(struct ath5k_hw
*ah
, u64 tsf64
)
561 ath5k_hw_reg_write(ah
, tsf64
& 0xffffffff, AR5K_TSF_L32
);
562 ath5k_hw_reg_write(ah
, (tsf64
>> 32) & 0xffffffff, AR5K_TSF_U32
);
566 * ath5k_hw_reset_tsf - Force a TSF reset
568 * @ah: The &struct ath5k_hw
570 * Forces a TSF reset on PCU
572 void ath5k_hw_reset_tsf(struct ath5k_hw
*ah
)
576 val
= ath5k_hw_reg_read(ah
, AR5K_BEACON
) | AR5K_BEACON_RESET_TSF
;
579 * Each write to the RESET_TSF bit toggles a hardware internal
580 * signal to reset TSF, but if left high it will cause a TSF reset
581 * on the next chip reset as well. Thus we always write the value
582 * twice to clear the signal.
584 ath5k_hw_reg_write(ah
, val
, AR5K_BEACON
);
585 ath5k_hw_reg_write(ah
, val
, AR5K_BEACON
);
589 * Initialize beacon timers
591 void ath5k_hw_init_beacon(struct ath5k_hw
*ah
, u32 next_beacon
, u32 interval
)
593 u32 timer1
, timer2
, timer3
;
596 * Set the additional timers by mode
598 switch (ah
->ah_sc
->opmode
) {
599 case NL80211_IFTYPE_MONITOR
:
600 case NL80211_IFTYPE_STATION
:
601 /* In STA mode timer1 is used as next wakeup
602 * timer and timer2 as next CFP duration start
603 * timer. Both in 1/8TUs. */
604 /* TODO: PCF handling */
605 if (ah
->ah_version
== AR5K_AR5210
) {
612 /* Mark associated AP as PCF incapable for now */
613 AR5K_REG_DISABLE_BITS(ah
, AR5K_STA_ID1
, AR5K_STA_ID1_PCF
);
615 case NL80211_IFTYPE_ADHOC
:
616 AR5K_REG_ENABLE_BITS(ah
, AR5K_TXCFG
, AR5K_TXCFG_ADHOC_BCN_ATIM
);
618 /* On non-STA modes timer1 is used as next DMA
619 * beacon alert (DBA) timer and timer2 as next
620 * software beacon alert. Both in 1/8TUs. */
621 timer1
= (next_beacon
- AR5K_TUNE_DMA_BEACON_RESP
) << 3;
622 timer2
= (next_beacon
- AR5K_TUNE_SW_BEACON_RESP
) << 3;
626 /* Timer3 marks the end of our ATIM window
627 * a zero length window is not allowed because
628 * we 'll get no beacons */
629 timer3
= next_beacon
+ 1;
632 * Set the beacon register and enable all timers.
634 /* When in AP or Mesh Point mode zero timer0 to start TSF */
635 if (ah
->ah_sc
->opmode
== NL80211_IFTYPE_AP
||
636 ah
->ah_sc
->opmode
== NL80211_IFTYPE_MESH_POINT
)
637 ath5k_hw_reg_write(ah
, 0, AR5K_TIMER0
);
639 ath5k_hw_reg_write(ah
, next_beacon
, AR5K_TIMER0
);
640 ath5k_hw_reg_write(ah
, timer1
, AR5K_TIMER1
);
641 ath5k_hw_reg_write(ah
, timer2
, AR5K_TIMER2
);
642 ath5k_hw_reg_write(ah
, timer3
, AR5K_TIMER3
);
644 /* Force a TSF reset if requested and enable beacons */
645 if (interval
& AR5K_BEACON_RESET_TSF
)
646 ath5k_hw_reset_tsf(ah
);
648 ath5k_hw_reg_write(ah
, interval
& (AR5K_BEACON_PERIOD
|
652 /* Flush any pending BMISS interrupts on ISR by
653 * performing a clear-on-write operation on PISR
654 * register for the BMISS bit (writing a bit on
655 * ISR togles a reset for that bit and leaves
656 * the rest bits intact) */
657 if (ah
->ah_version
== AR5K_AR5210
)
658 ath5k_hw_reg_write(ah
, AR5K_ISR_BMISS
, AR5K_ISR
);
660 ath5k_hw_reg_write(ah
, AR5K_ISR_BMISS
, AR5K_PISR
);
662 /* TODO: Set enchanced sleep registers on AR5212
663 * based on vif->bss_conf params, until then
664 * disable power save reporting.*/
665 AR5K_REG_DISABLE_BITS(ah
, AR5K_STA_ID1
, AR5K_STA_ID1_PWR_SV
);
670 * ath5k_check_timer_win - Check if timer B is timer A + window
672 * @a: timer a (before b)
673 * @b: timer b (after a)
674 * @window: difference between a and b
675 * @intval: timers are increased by this interval
677 * This helper function checks if timer B is timer A + window and covers
678 * cases where timer A or B might have already been updated or wrapped
679 * around (Timers are 16 bit).
681 * Returns true if O.K.
684 ath5k_check_timer_win(int a
, int b
, int window
, int intval
)
687 * 1.) usually B should be A + window
688 * 2.) A already updated, B not updated yet
689 * 3.) A already updated and has wrapped around
690 * 4.) B has wrapped around
692 if ((b
- a
== window
) || /* 1.) */
693 (a
- b
== intval
- window
) || /* 2.) */
694 ((a
| 0x10000) - b
== intval
- window
) || /* 3.) */
695 ((b
| 0x10000) - a
== window
)) /* 4.) */
696 return true; /* O.K. */
701 * ath5k_hw_check_beacon_timers - Check if the beacon timers are correct
703 * @ah: The &struct ath5k_hw
704 * @intval: beacon interval
706 * This is a workaround for IBSS mode:
708 * The need for this function arises from the fact that we have 4 separate
709 * HW timer registers (TIMER0 - TIMER3), which are closely related to the
710 * next beacon target time (NBTT), and that the HW updates these timers
711 * seperately based on the current TSF value. The hardware increments each
712 * timer by the beacon interval, when the local TSF coverted to TU is equal
713 * to the value stored in the timer.
715 * The reception of a beacon with the same BSSID can update the local HW TSF
716 * at any time - this is something we can't avoid. If the TSF jumps to a
717 * time which is later than the time stored in a timer, this timer will not
718 * be updated until the TSF in TU wraps around at 16 bit (the size of the
719 * timers) and reaches the time which is stored in the timer.
721 * The problem is that these timers are closely related to TIMER0 (NBTT) and
722 * that they define a time "window". When the TSF jumps between two timers
723 * (e.g. ATIM and NBTT), the one in the past will be left behind (not
724 * updated), while the one in the future will be updated every beacon
725 * interval. This causes the window to get larger, until the TSF wraps
726 * around as described above and the timer which was left behind gets
727 * updated again. But - because the beacon interval is usually not an exact
728 * divisor of the size of the timers (16 bit), an unwanted "window" between
729 * these timers has developed!
731 * This is especially important with the ATIM window, because during
732 * the ATIM window only ATIM frames and no data frames are allowed to be
733 * sent, which creates transmission pauses after each beacon. This symptom
734 * has been described as "ramping ping" because ping times increase linearly
735 * for some time and then drop down again. A wrong window on the DMA beacon
736 * timer has the same effect, so we check for these two conditions.
738 * Returns true if O.K.
741 ath5k_hw_check_beacon_timers(struct ath5k_hw
*ah
, int intval
)
743 unsigned int nbtt
, atim
, dma
;
745 nbtt
= ath5k_hw_reg_read(ah
, AR5K_TIMER0
);
746 atim
= ath5k_hw_reg_read(ah
, AR5K_TIMER3
);
747 dma
= ath5k_hw_reg_read(ah
, AR5K_TIMER1
) >> 3;
749 /* NOTE: SWBA is different. Having a wrong window there does not
750 * stop us from sending data and this condition is catched thru
751 * other means (SWBA interrupt) */
753 if (ath5k_check_timer_win(nbtt
, atim
, 1, intval
) &&
754 ath5k_check_timer_win(dma
, nbtt
, AR5K_TUNE_DMA_BEACON_RESP
,
756 return true; /* O.K. */
761 * ath5k_hw_set_coverage_class - Set IEEE 802.11 coverage class
763 * @ah: The &struct ath5k_hw
764 * @coverage_class: IEEE 802.11 coverage class number
766 * Sets IFS intervals and ACK/CTS timeouts for given coverage class.
768 void ath5k_hw_set_coverage_class(struct ath5k_hw
*ah
, u8 coverage_class
)
770 /* As defined by IEEE 802.11-2007 17.3.8.6 */
771 int slot_time
= ath5k_hw_get_default_slottime(ah
) + 3 * coverage_class
;
772 int ack_timeout
= ath5k_hw_get_default_sifs(ah
) + slot_time
;
773 int cts_timeout
= ack_timeout
;
775 ath5k_hw_set_ifs_intervals(ah
, slot_time
);
776 ath5k_hw_set_ack_timeout(ah
, ack_timeout
);
777 ath5k_hw_set_cts_timeout(ah
, cts_timeout
);
779 ah
->ah_coverage_class
= coverage_class
;
782 /***************************\
783 * Init/Start/Stop functions *
784 \***************************/
787 * ath5k_hw_start_rx_pcu - Start RX engine
789 * @ah: The &struct ath5k_hw
791 * Starts RX engine on PCU so that hw can process RXed frames
794 * NOTE: RX DMA should be already enabled using ath5k_hw_start_rx_dma
796 void ath5k_hw_start_rx_pcu(struct ath5k_hw
*ah
)
798 AR5K_REG_DISABLE_BITS(ah
, AR5K_DIAG_SW
, AR5K_DIAG_SW_DIS_RX
);
802 * at5k_hw_stop_rx_pcu - Stop RX engine
804 * @ah: The &struct ath5k_hw
806 * Stops RX engine on PCU
808 void ath5k_hw_stop_rx_pcu(struct ath5k_hw
*ah
)
810 AR5K_REG_ENABLE_BITS(ah
, AR5K_DIAG_SW
, AR5K_DIAG_SW_DIS_RX
);
814 * ath5k_hw_set_opmode - Set PCU operating mode
816 * @ah: The &struct ath5k_hw
817 * @op_mode: &enum nl80211_iftype operating mode
819 * Configure PCU for the various operating modes (AP/STA etc)
821 int ath5k_hw_set_opmode(struct ath5k_hw
*ah
, enum nl80211_iftype op_mode
)
823 struct ath_common
*common
= ath5k_hw_common(ah
);
824 u32 pcu_reg
, beacon_reg
, low_id
, high_id
;
826 ATH5K_DBG(ah
->ah_sc
, ATH5K_DEBUG_MODE
, "mode %d\n", op_mode
);
828 /* Preserve rest settings */
829 pcu_reg
= ath5k_hw_reg_read(ah
, AR5K_STA_ID1
) & 0xffff0000;
830 pcu_reg
&= ~(AR5K_STA_ID1_ADHOC
| AR5K_STA_ID1_AP
831 | AR5K_STA_ID1_KEYSRCH_MODE
832 | (ah
->ah_version
== AR5K_AR5210
?
833 (AR5K_STA_ID1_PWR_SV
| AR5K_STA_ID1_NO_PSPOLL
) : 0));
838 case NL80211_IFTYPE_ADHOC
:
839 pcu_reg
|= AR5K_STA_ID1_ADHOC
| AR5K_STA_ID1_KEYSRCH_MODE
;
840 beacon_reg
|= AR5K_BCR_ADHOC
;
841 if (ah
->ah_version
== AR5K_AR5210
)
842 pcu_reg
|= AR5K_STA_ID1_NO_PSPOLL
;
844 AR5K_REG_ENABLE_BITS(ah
, AR5K_CFG
, AR5K_CFG_IBSS
);
847 case NL80211_IFTYPE_AP
:
848 case NL80211_IFTYPE_MESH_POINT
:
849 pcu_reg
|= AR5K_STA_ID1_AP
| AR5K_STA_ID1_KEYSRCH_MODE
;
850 beacon_reg
|= AR5K_BCR_AP
;
851 if (ah
->ah_version
== AR5K_AR5210
)
852 pcu_reg
|= AR5K_STA_ID1_NO_PSPOLL
;
854 AR5K_REG_DISABLE_BITS(ah
, AR5K_CFG
, AR5K_CFG_IBSS
);
857 case NL80211_IFTYPE_STATION
:
858 pcu_reg
|= AR5K_STA_ID1_KEYSRCH_MODE
859 | (ah
->ah_version
== AR5K_AR5210
?
860 AR5K_STA_ID1_PWR_SV
: 0);
861 case NL80211_IFTYPE_MONITOR
:
862 pcu_reg
|= AR5K_STA_ID1_KEYSRCH_MODE
863 | (ah
->ah_version
== AR5K_AR5210
?
864 AR5K_STA_ID1_NO_PSPOLL
: 0);
874 low_id
= get_unaligned_le32(common
->macaddr
);
875 high_id
= get_unaligned_le16(common
->macaddr
+ 4);
876 ath5k_hw_reg_write(ah
, low_id
, AR5K_STA_ID0
);
877 ath5k_hw_reg_write(ah
, pcu_reg
| high_id
, AR5K_STA_ID1
);
880 * Set Beacon Control Register on 5210
882 if (ah
->ah_version
== AR5K_AR5210
)
883 ath5k_hw_reg_write(ah
, beacon_reg
, AR5K_BCR
);
888 void ath5k_hw_pcu_init(struct ath5k_hw
*ah
, enum nl80211_iftype op_mode
,
891 /* Set bssid and bssid mask */
892 ath5k_hw_set_bssid(ah
);
895 ath5k_hw_set_opmode(ah
, op_mode
);
897 /* Write rate duration table only on AR5212 and if
898 * virtual interface has already been brought up
899 * XXX: rethink this after new mode changes to
900 * mac80211 are integrated */
901 if (ah
->ah_version
== AR5K_AR5212
&&
903 ath5k_hw_write_rate_duration(ah
);
905 /* Set RSSI/BRSSI thresholds
907 * Note: If we decide to set this value
908 * dynamicaly, have in mind that when AR5K_RSSI_THR
909 * register is read it might return 0x40 if we haven't
910 * wrote anything to it plus BMISS RSSI threshold is zeroed.
911 * So doing a save/restore procedure here isn't the right
912 * choice. Instead store it on ath5k_hw */
913 ath5k_hw_reg_write(ah
, (AR5K_TUNE_RSSI_THRES
|
914 AR5K_TUNE_BMISS_THRES
<<
915 AR5K_RSSI_THR_BMISS_S
),
918 /* MIC QoS support */
919 if (ah
->ah_mac_srev
>= AR5K_SREV_AR2413
) {
920 ath5k_hw_reg_write(ah
, 0x000100aa, AR5K_MIC_QOS_CTL
);
921 ath5k_hw_reg_write(ah
, 0x00003210, AR5K_MIC_QOS_SEL
);
924 /* QoS NOACK Policy */
925 if (ah
->ah_version
== AR5K_AR5212
) {
926 ath5k_hw_reg_write(ah
,
927 AR5K_REG_SM(2, AR5K_QOS_NOACK_2BIT_VALUES
) |
928 AR5K_REG_SM(5, AR5K_QOS_NOACK_BIT_OFFSET
) |
929 AR5K_REG_SM(0, AR5K_QOS_NOACK_BYTE_OFFSET
),
933 /* Restore slot time and ACK timeouts */
934 if (ah
->ah_coverage_class
> 0)
935 ath5k_hw_set_coverage_class(ah
, ah
->ah_coverage_class
);
937 /* Set ACK bitrate mode (see ack_rates_high) */
938 if (ah
->ah_version
== AR5K_AR5212
) {
939 u32 val
= AR5K_STA_ID1_BASE_RATE_11B
| AR5K_STA_ID1_ACKCTS_6MB
;
940 if (ah
->ah_ack_bitrate_high
)
941 AR5K_REG_DISABLE_BITS(ah
, AR5K_STA_ID1
, val
);
943 AR5K_REG_ENABLE_BITS(ah
, AR5K_STA_ID1
, val
);