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
,
89 return le16_to_cpu(dur
);
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 ath5k_hw_reg_write(ah
, tx_time
, reg
);
270 if (!(rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
))
274 * We're not distinguishing short preamble here,
275 * This is true, all we'll get is a longer value here
276 * which is not necessarilly bad. We could use
277 * export ieee80211_frame_duration() but that needs to be
278 * fixed first to be properly used by mac802111 drivers:
280 * - remove erp stuff and let the routine figure ofdm
282 * - remove passing argument ieee80211_local as
283 * drivers don't have access to it
284 * - move drivers using ieee80211_generic_frame_duration()
287 ath5k_hw_reg_write(ah
, tx_time
,
288 reg
+ (AR5K_SET_SHORT_PREAMBLE
<< 2));
293 * ath5k_hw_set_ack_timeout - Set ACK timeout on PCU
295 * @ah: The &struct ath5k_hw
296 * @timeout: Timeout in usec
298 static int ath5k_hw_set_ack_timeout(struct ath5k_hw
*ah
, unsigned int timeout
)
300 if (ath5k_hw_clocktoh(ah
, AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK
))
304 AR5K_REG_WRITE_BITS(ah
, AR5K_TIME_OUT
, AR5K_TIME_OUT_ACK
,
305 ath5k_hw_htoclock(ah
, timeout
));
311 * ath5k_hw_set_cts_timeout - Set CTS timeout on PCU
313 * @ah: The &struct ath5k_hw
314 * @timeout: Timeout in usec
316 static int ath5k_hw_set_cts_timeout(struct ath5k_hw
*ah
, unsigned int timeout
)
318 if (ath5k_hw_clocktoh(ah
, AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS
))
322 AR5K_REG_WRITE_BITS(ah
, AR5K_TIME_OUT
, AR5K_TIME_OUT_CTS
,
323 ath5k_hw_htoclock(ah
, timeout
));
329 /*******************\
330 * RX filter Control *
331 \*******************/
334 * ath5k_hw_set_lladdr - Set station id
336 * @ah: The &struct ath5k_hw
337 * @mac: The card's mac address
339 * Set station id on hw using the provided mac address
341 int ath5k_hw_set_lladdr(struct ath5k_hw
*ah
, const u8
*mac
)
343 struct ath_common
*common
= ath5k_hw_common(ah
);
347 /* Set new station ID */
348 memcpy(common
->macaddr
, mac
, ETH_ALEN
);
350 pcu_reg
= ath5k_hw_reg_read(ah
, AR5K_STA_ID1
) & 0xffff0000;
352 low_id
= get_unaligned_le32(mac
);
353 high_id
= get_unaligned_le16(mac
+ 4);
355 ath5k_hw_reg_write(ah
, low_id
, AR5K_STA_ID0
);
356 ath5k_hw_reg_write(ah
, pcu_reg
| high_id
, AR5K_STA_ID1
);
362 * ath5k_hw_set_bssid - Set current BSSID on hw
364 * @ah: The &struct ath5k_hw
366 * Sets the current BSSID and BSSID mask we have from the
367 * common struct into the hardware
369 void ath5k_hw_set_bssid(struct ath5k_hw
*ah
)
371 struct ath_common
*common
= ath5k_hw_common(ah
);
375 * Set BSSID mask on 5212
377 if (ah
->ah_version
== AR5K_AR5212
)
378 ath_hw_setbssidmask(common
);
383 ath5k_hw_reg_write(ah
,
384 get_unaligned_le32(common
->curbssid
),
386 ath5k_hw_reg_write(ah
,
387 get_unaligned_le16(common
->curbssid
+ 4) |
388 ((common
->curaid
& 0x3fff) << AR5K_BSS_ID1_AID_S
),
391 if (common
->curaid
== 0) {
392 ath5k_hw_disable_pspoll(ah
);
396 AR5K_REG_WRITE_BITS(ah
, AR5K_BEACON
, AR5K_BEACON_TIM
,
397 tim_offset
? tim_offset
+ 4 : 0);
399 ath5k_hw_enable_pspoll(ah
, NULL
, 0);
402 void ath5k_hw_set_bssid_mask(struct ath5k_hw
*ah
, const u8
*mask
)
404 struct ath_common
*common
= ath5k_hw_common(ah
);
406 /* Cache bssid mask so that we can restore it
408 memcpy(common
->bssidmask
, mask
, ETH_ALEN
);
409 if (ah
->ah_version
== AR5K_AR5212
)
410 ath_hw_setbssidmask(common
);
414 * Set multicast filter
416 void ath5k_hw_set_mcast_filter(struct ath5k_hw
*ah
, u32 filter0
, u32 filter1
)
418 ath5k_hw_reg_write(ah
, filter0
, AR5K_MCAST_FILTER0
);
419 ath5k_hw_reg_write(ah
, filter1
, AR5K_MCAST_FILTER1
);
423 * ath5k_hw_get_rx_filter - Get current rx filter
425 * @ah: The &struct ath5k_hw
427 * Returns the RX filter by reading rx filter and
428 * phy error filter registers. RX filter is used
429 * to set the allowed frame types that PCU will accept
430 * and pass to the driver. For a list of frame types
433 u32
ath5k_hw_get_rx_filter(struct ath5k_hw
*ah
)
435 u32 data
, filter
= 0;
437 filter
= ath5k_hw_reg_read(ah
, AR5K_RX_FILTER
);
439 /*Radar detection for 5212*/
440 if (ah
->ah_version
== AR5K_AR5212
) {
441 data
= ath5k_hw_reg_read(ah
, AR5K_PHY_ERR_FIL
);
443 if (data
& AR5K_PHY_ERR_FIL_RADAR
)
444 filter
|= AR5K_RX_FILTER_RADARERR
;
445 if (data
& (AR5K_PHY_ERR_FIL_OFDM
| AR5K_PHY_ERR_FIL_CCK
))
446 filter
|= AR5K_RX_FILTER_PHYERR
;
453 * ath5k_hw_set_rx_filter - Set rx filter
455 * @ah: The &struct ath5k_hw
456 * @filter: RX filter mask (see reg.h)
458 * Sets RX filter register and also handles PHY error filter
459 * register on 5212 and newer chips so that we have proper PHY
462 void ath5k_hw_set_rx_filter(struct ath5k_hw
*ah
, u32 filter
)
466 /* Set PHY error filter register on 5212*/
467 if (ah
->ah_version
== AR5K_AR5212
) {
468 if (filter
& AR5K_RX_FILTER_RADARERR
)
469 data
|= AR5K_PHY_ERR_FIL_RADAR
;
470 if (filter
& AR5K_RX_FILTER_PHYERR
)
471 data
|= AR5K_PHY_ERR_FIL_OFDM
| AR5K_PHY_ERR_FIL_CCK
;
475 * The AR5210 uses promiscuous mode to detect radar activity
477 if (ah
->ah_version
== AR5K_AR5210
&&
478 (filter
& AR5K_RX_FILTER_RADARERR
)) {
479 filter
&= ~AR5K_RX_FILTER_RADARERR
;
480 filter
|= AR5K_RX_FILTER_PROM
;
483 /*Zero length DMA (phy error reporting) */
485 AR5K_REG_ENABLE_BITS(ah
, AR5K_RXCFG
, AR5K_RXCFG_ZLFDMA
);
487 AR5K_REG_DISABLE_BITS(ah
, AR5K_RXCFG
, AR5K_RXCFG_ZLFDMA
);
489 /*Write RX Filter register*/
490 ath5k_hw_reg_write(ah
, filter
& 0xff, AR5K_RX_FILTER
);
492 /*Write PHY error filter register on 5212*/
493 if (ah
->ah_version
== AR5K_AR5212
)
494 ath5k_hw_reg_write(ah
, data
, AR5K_PHY_ERR_FIL
);
503 #define ATH5K_MAX_TSF_READ 10
506 * ath5k_hw_get_tsf64 - Get the full 64bit TSF
508 * @ah: The &struct ath5k_hw
510 * Returns the current TSF
512 u64
ath5k_hw_get_tsf64(struct ath5k_hw
*ah
)
514 u32 tsf_lower
, tsf_upper1
, tsf_upper2
;
518 /* This code is time critical - we don't want to be interrupted here */
519 local_irq_save(flags
);
522 * While reading TSF upper and then lower part, the clock is still
523 * counting (or jumping in case of IBSS merge) so we might get
524 * inconsistent values. To avoid this, we read the upper part again
525 * and check it has not been changed. We make the hypothesis that a
526 * maximum of 3 changes can happens in a row (we use 10 as a safe
529 * Impact on performance is pretty small, since in most cases, only
530 * 3 register reads are needed.
533 tsf_upper1
= ath5k_hw_reg_read(ah
, AR5K_TSF_U32
);
534 for (i
= 0; i
< ATH5K_MAX_TSF_READ
; i
++) {
535 tsf_lower
= ath5k_hw_reg_read(ah
, AR5K_TSF_L32
);
536 tsf_upper2
= ath5k_hw_reg_read(ah
, AR5K_TSF_U32
);
537 if (tsf_upper2
== tsf_upper1
)
539 tsf_upper1
= tsf_upper2
;
542 local_irq_restore(flags
);
544 WARN_ON( i
== ATH5K_MAX_TSF_READ
);
546 return (((u64
)tsf_upper1
<< 32) | tsf_lower
);
550 * ath5k_hw_set_tsf64 - Set a new 64bit TSF
552 * @ah: The &struct ath5k_hw
553 * @tsf64: The new 64bit TSF
557 void ath5k_hw_set_tsf64(struct ath5k_hw
*ah
, u64 tsf64
)
559 ath5k_hw_reg_write(ah
, tsf64
& 0xffffffff, AR5K_TSF_L32
);
560 ath5k_hw_reg_write(ah
, (tsf64
>> 32) & 0xffffffff, AR5K_TSF_U32
);
564 * ath5k_hw_reset_tsf - Force a TSF reset
566 * @ah: The &struct ath5k_hw
568 * Forces a TSF reset on PCU
570 void ath5k_hw_reset_tsf(struct ath5k_hw
*ah
)
574 val
= ath5k_hw_reg_read(ah
, AR5K_BEACON
) | AR5K_BEACON_RESET_TSF
;
577 * Each write to the RESET_TSF bit toggles a hardware internal
578 * signal to reset TSF, but if left high it will cause a TSF reset
579 * on the next chip reset as well. Thus we always write the value
580 * twice to clear the signal.
582 ath5k_hw_reg_write(ah
, val
, AR5K_BEACON
);
583 ath5k_hw_reg_write(ah
, val
, AR5K_BEACON
);
587 * Initialize beacon timers
589 void ath5k_hw_init_beacon(struct ath5k_hw
*ah
, u32 next_beacon
, u32 interval
)
591 u32 timer1
, timer2
, timer3
;
594 * Set the additional timers by mode
596 switch (ah
->ah_sc
->opmode
) {
597 case NL80211_IFTYPE_MONITOR
:
598 case NL80211_IFTYPE_STATION
:
599 /* In STA mode timer1 is used as next wakeup
600 * timer and timer2 as next CFP duration start
601 * timer. Both in 1/8TUs. */
602 /* TODO: PCF handling */
603 if (ah
->ah_version
== AR5K_AR5210
) {
610 /* Mark associated AP as PCF incapable for now */
611 AR5K_REG_DISABLE_BITS(ah
, AR5K_STA_ID1
, AR5K_STA_ID1_PCF
);
613 case NL80211_IFTYPE_ADHOC
:
614 AR5K_REG_ENABLE_BITS(ah
, AR5K_TXCFG
, AR5K_TXCFG_ADHOC_BCN_ATIM
);
616 /* On non-STA modes timer1 is used as next DMA
617 * beacon alert (DBA) timer and timer2 as next
618 * software beacon alert. Both in 1/8TUs. */
619 timer1
= (next_beacon
- AR5K_TUNE_DMA_BEACON_RESP
) << 3;
620 timer2
= (next_beacon
- AR5K_TUNE_SW_BEACON_RESP
) << 3;
624 /* Timer3 marks the end of our ATIM window
625 * a zero length window is not allowed because
626 * we 'll get no beacons */
627 timer3
= next_beacon
+ 1;
630 * Set the beacon register and enable all timers.
632 /* When in AP or Mesh Point mode zero timer0 to start TSF */
633 if (ah
->ah_sc
->opmode
== NL80211_IFTYPE_AP
||
634 ah
->ah_sc
->opmode
== NL80211_IFTYPE_MESH_POINT
)
635 ath5k_hw_reg_write(ah
, 0, AR5K_TIMER0
);
637 ath5k_hw_reg_write(ah
, next_beacon
, AR5K_TIMER0
);
638 ath5k_hw_reg_write(ah
, timer1
, AR5K_TIMER1
);
639 ath5k_hw_reg_write(ah
, timer2
, AR5K_TIMER2
);
640 ath5k_hw_reg_write(ah
, timer3
, AR5K_TIMER3
);
642 /* Force a TSF reset if requested and enable beacons */
643 if (interval
& AR5K_BEACON_RESET_TSF
)
644 ath5k_hw_reset_tsf(ah
);
646 ath5k_hw_reg_write(ah
, interval
& (AR5K_BEACON_PERIOD
|
650 /* Flush any pending BMISS interrupts on ISR by
651 * performing a clear-on-write operation on PISR
652 * register for the BMISS bit (writing a bit on
653 * ISR togles a reset for that bit and leaves
654 * the rest bits intact) */
655 if (ah
->ah_version
== AR5K_AR5210
)
656 ath5k_hw_reg_write(ah
, AR5K_ISR_BMISS
, AR5K_ISR
);
658 ath5k_hw_reg_write(ah
, AR5K_ISR_BMISS
, AR5K_PISR
);
660 /* TODO: Set enchanced sleep registers on AR5212
661 * based on vif->bss_conf params, until then
662 * disable power save reporting.*/
663 AR5K_REG_DISABLE_BITS(ah
, AR5K_STA_ID1
, AR5K_STA_ID1_PWR_SV
);
668 * ath5k_check_timer_win - Check if timer B is timer A + window
670 * @a: timer a (before b)
671 * @b: timer b (after a)
672 * @window: difference between a and b
673 * @intval: timers are increased by this interval
675 * This helper function checks if timer B is timer A + window and covers
676 * cases where timer A or B might have already been updated or wrapped
677 * around (Timers are 16 bit).
679 * Returns true if O.K.
682 ath5k_check_timer_win(int a
, int b
, int window
, int intval
)
685 * 1.) usually B should be A + window
686 * 2.) A already updated, B not updated yet
687 * 3.) A already updated and has wrapped around
688 * 4.) B has wrapped around
690 if ((b
- a
== window
) || /* 1.) */
691 (a
- b
== intval
- window
) || /* 2.) */
692 ((a
| 0x10000) - b
== intval
- window
) || /* 3.) */
693 ((b
| 0x10000) - a
== window
)) /* 4.) */
694 return true; /* O.K. */
699 * ath5k_hw_check_beacon_timers - Check if the beacon timers are correct
701 * @ah: The &struct ath5k_hw
702 * @intval: beacon interval
704 * This is a workaround for IBSS mode:
706 * The need for this function arises from the fact that we have 4 separate
707 * HW timer registers (TIMER0 - TIMER3), which are closely related to the
708 * next beacon target time (NBTT), and that the HW updates these timers
709 * separately based on the current TSF value. The hardware increments each
710 * timer by the beacon interval, when the local TSF converted to TU is equal
711 * to the value stored in the timer.
713 * The reception of a beacon with the same BSSID can update the local HW TSF
714 * at any time - this is something we can't avoid. If the TSF jumps to a
715 * time which is later than the time stored in a timer, this timer will not
716 * be updated until the TSF in TU wraps around at 16 bit (the size of the
717 * timers) and reaches the time which is stored in the timer.
719 * The problem is that these timers are closely related to TIMER0 (NBTT) and
720 * that they define a time "window". When the TSF jumps between two timers
721 * (e.g. ATIM and NBTT), the one in the past will be left behind (not
722 * updated), while the one in the future will be updated every beacon
723 * interval. This causes the window to get larger, until the TSF wraps
724 * around as described above and the timer which was left behind gets
725 * updated again. But - because the beacon interval is usually not an exact
726 * divisor of the size of the timers (16 bit), an unwanted "window" between
727 * these timers has developed!
729 * This is especially important with the ATIM window, because during
730 * the ATIM window only ATIM frames and no data frames are allowed to be
731 * sent, which creates transmission pauses after each beacon. This symptom
732 * has been described as "ramping ping" because ping times increase linearly
733 * for some time and then drop down again. A wrong window on the DMA beacon
734 * timer has the same effect, so we check for these two conditions.
736 * Returns true if O.K.
739 ath5k_hw_check_beacon_timers(struct ath5k_hw
*ah
, int intval
)
741 unsigned int nbtt
, atim
, dma
;
743 nbtt
= ath5k_hw_reg_read(ah
, AR5K_TIMER0
);
744 atim
= ath5k_hw_reg_read(ah
, AR5K_TIMER3
);
745 dma
= ath5k_hw_reg_read(ah
, AR5K_TIMER1
) >> 3;
747 /* NOTE: SWBA is different. Having a wrong window there does not
748 * stop us from sending data and this condition is catched thru
749 * other means (SWBA interrupt) */
751 if (ath5k_check_timer_win(nbtt
, atim
, 1, intval
) &&
752 ath5k_check_timer_win(dma
, nbtt
, AR5K_TUNE_DMA_BEACON_RESP
,
754 return true; /* O.K. */
759 * ath5k_hw_set_coverage_class - Set IEEE 802.11 coverage class
761 * @ah: The &struct ath5k_hw
762 * @coverage_class: IEEE 802.11 coverage class number
764 * Sets IFS intervals and ACK/CTS timeouts for given coverage class.
766 void ath5k_hw_set_coverage_class(struct ath5k_hw
*ah
, u8 coverage_class
)
768 /* As defined by IEEE 802.11-2007 17.3.8.6 */
769 int slot_time
= ath5k_hw_get_default_slottime(ah
) + 3 * coverage_class
;
770 int ack_timeout
= ath5k_hw_get_default_sifs(ah
) + slot_time
;
771 int cts_timeout
= ack_timeout
;
773 ath5k_hw_set_ifs_intervals(ah
, slot_time
);
774 ath5k_hw_set_ack_timeout(ah
, ack_timeout
);
775 ath5k_hw_set_cts_timeout(ah
, cts_timeout
);
777 ah
->ah_coverage_class
= coverage_class
;
780 /***************************\
781 * Init/Start/Stop functions *
782 \***************************/
785 * ath5k_hw_start_rx_pcu - Start RX engine
787 * @ah: The &struct ath5k_hw
789 * Starts RX engine on PCU so that hw can process RXed frames
792 * NOTE: RX DMA should be already enabled using ath5k_hw_start_rx_dma
794 void ath5k_hw_start_rx_pcu(struct ath5k_hw
*ah
)
796 AR5K_REG_DISABLE_BITS(ah
, AR5K_DIAG_SW
, AR5K_DIAG_SW_DIS_RX
);
800 * at5k_hw_stop_rx_pcu - Stop RX engine
802 * @ah: The &struct ath5k_hw
804 * Stops RX engine on PCU
806 void ath5k_hw_stop_rx_pcu(struct ath5k_hw
*ah
)
808 AR5K_REG_ENABLE_BITS(ah
, AR5K_DIAG_SW
, AR5K_DIAG_SW_DIS_RX
);
812 * ath5k_hw_set_opmode - Set PCU operating mode
814 * @ah: The &struct ath5k_hw
815 * @op_mode: &enum nl80211_iftype operating mode
817 * Configure PCU for the various operating modes (AP/STA etc)
819 int ath5k_hw_set_opmode(struct ath5k_hw
*ah
, enum nl80211_iftype op_mode
)
821 struct ath_common
*common
= ath5k_hw_common(ah
);
822 u32 pcu_reg
, beacon_reg
, low_id
, high_id
;
824 ATH5K_DBG(ah
->ah_sc
, ATH5K_DEBUG_MODE
, "mode %d\n", op_mode
);
826 /* Preserve rest settings */
827 pcu_reg
= ath5k_hw_reg_read(ah
, AR5K_STA_ID1
) & 0xffff0000;
828 pcu_reg
&= ~(AR5K_STA_ID1_ADHOC
| AR5K_STA_ID1_AP
829 | AR5K_STA_ID1_KEYSRCH_MODE
830 | (ah
->ah_version
== AR5K_AR5210
?
831 (AR5K_STA_ID1_PWR_SV
| AR5K_STA_ID1_NO_PSPOLL
) : 0));
836 case NL80211_IFTYPE_ADHOC
:
837 pcu_reg
|= AR5K_STA_ID1_ADHOC
| AR5K_STA_ID1_KEYSRCH_MODE
;
838 beacon_reg
|= AR5K_BCR_ADHOC
;
839 if (ah
->ah_version
== AR5K_AR5210
)
840 pcu_reg
|= AR5K_STA_ID1_NO_PSPOLL
;
842 AR5K_REG_ENABLE_BITS(ah
, AR5K_CFG
, AR5K_CFG_IBSS
);
845 case NL80211_IFTYPE_AP
:
846 case NL80211_IFTYPE_MESH_POINT
:
847 pcu_reg
|= AR5K_STA_ID1_AP
| AR5K_STA_ID1_KEYSRCH_MODE
;
848 beacon_reg
|= AR5K_BCR_AP
;
849 if (ah
->ah_version
== AR5K_AR5210
)
850 pcu_reg
|= AR5K_STA_ID1_NO_PSPOLL
;
852 AR5K_REG_DISABLE_BITS(ah
, AR5K_CFG
, AR5K_CFG_IBSS
);
855 case NL80211_IFTYPE_STATION
:
856 pcu_reg
|= AR5K_STA_ID1_KEYSRCH_MODE
857 | (ah
->ah_version
== AR5K_AR5210
?
858 AR5K_STA_ID1_PWR_SV
: 0);
859 case NL80211_IFTYPE_MONITOR
:
860 pcu_reg
|= AR5K_STA_ID1_KEYSRCH_MODE
861 | (ah
->ah_version
== AR5K_AR5210
?
862 AR5K_STA_ID1_NO_PSPOLL
: 0);
872 low_id
= get_unaligned_le32(common
->macaddr
);
873 high_id
= get_unaligned_le16(common
->macaddr
+ 4);
874 ath5k_hw_reg_write(ah
, low_id
, AR5K_STA_ID0
);
875 ath5k_hw_reg_write(ah
, pcu_reg
| high_id
, AR5K_STA_ID1
);
878 * Set Beacon Control Register on 5210
880 if (ah
->ah_version
== AR5K_AR5210
)
881 ath5k_hw_reg_write(ah
, beacon_reg
, AR5K_BCR
);
886 void ath5k_hw_pcu_init(struct ath5k_hw
*ah
, enum nl80211_iftype op_mode
,
889 /* Set bssid and bssid mask */
890 ath5k_hw_set_bssid(ah
);
893 ath5k_hw_set_opmode(ah
, op_mode
);
895 /* Write rate duration table only on AR5212 and if
896 * virtual interface has already been brought up
897 * XXX: rethink this after new mode changes to
898 * mac80211 are integrated */
899 if (ah
->ah_version
== AR5K_AR5212
&&
901 ath5k_hw_write_rate_duration(ah
);
903 /* Set RSSI/BRSSI thresholds
905 * Note: If we decide to set this value
906 * dynamicaly, have in mind that when AR5K_RSSI_THR
907 * register is read it might return 0x40 if we haven't
908 * wrote anything to it plus BMISS RSSI threshold is zeroed.
909 * So doing a save/restore procedure here isn't the right
910 * choice. Instead store it on ath5k_hw */
911 ath5k_hw_reg_write(ah
, (AR5K_TUNE_RSSI_THRES
|
912 AR5K_TUNE_BMISS_THRES
<<
913 AR5K_RSSI_THR_BMISS_S
),
916 /* MIC QoS support */
917 if (ah
->ah_mac_srev
>= AR5K_SREV_AR2413
) {
918 ath5k_hw_reg_write(ah
, 0x000100aa, AR5K_MIC_QOS_CTL
);
919 ath5k_hw_reg_write(ah
, 0x00003210, AR5K_MIC_QOS_SEL
);
922 /* QoS NOACK Policy */
923 if (ah
->ah_version
== AR5K_AR5212
) {
924 ath5k_hw_reg_write(ah
,
925 AR5K_REG_SM(2, AR5K_QOS_NOACK_2BIT_VALUES
) |
926 AR5K_REG_SM(5, AR5K_QOS_NOACK_BIT_OFFSET
) |
927 AR5K_REG_SM(0, AR5K_QOS_NOACK_BYTE_OFFSET
),
931 /* Restore slot time and ACK timeouts */
932 if (ah
->ah_coverage_class
> 0)
933 ath5k_hw_set_coverage_class(ah
, ah
->ah_coverage_class
);
935 /* Set ACK bitrate mode (see ack_rates_high) */
936 if (ah
->ah_version
== AR5K_AR5212
) {
937 u32 val
= AR5K_STA_ID1_BASE_RATE_11B
| AR5K_STA_ID1_ACKCTS_6MB
;
938 if (ah
->ah_ack_bitrate_high
)
939 AR5K_REG_DISABLE_BITS(ah
, AR5K_STA_ID1
, val
);
941 AR5K_REG_ENABLE_BITS(ah
, AR5K_STA_ID1
, val
);