2 * Copyright (c) 2008, Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 static u32 ath_chainmask_sel_up_rssi_thres
=
21 ATH_CHAINMASK_SEL_UP_RSSI_THRES
;
22 static u32 ath_chainmask_sel_down_rssi_thres
=
23 ATH_CHAINMASK_SEL_DOWN_RSSI_THRES
;
24 static u32 ath_chainmask_sel_period
=
25 ATH_CHAINMASK_SEL_TIMEOUT
;
27 /* return bus cachesize in 4B word units */
29 static void bus_read_cachesize(struct ath_softc
*sc
, int *csz
)
33 pci_read_config_byte(sc
->pdev
, PCI_CACHE_LINE_SIZE
, (u8
*)&u8tmp
);
37 * This check was put in to avoid "unplesant" consequences if
38 * the bootrom has not fully initialized all PCI devices.
39 * Sometimes the cache line size register is not set
43 *csz
= DEFAULT_CACHELINE
>> 2; /* Use the default size */
46 static u8
parse_mpdudensity(u8 mpdudensity
)
49 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
50 * 0 for no restriction
59 switch (mpdudensity
) {
65 /* Our lower layer calculations limit our precision to
82 * Set current operating mode
84 * This function initializes and fills the rate table in the ATH object based
85 * on the operating mode.
87 static void ath_setcurmode(struct ath_softc
*sc
, enum wireless_mode mode
)
89 const struct ath9k_rate_table
*rt
;
92 rt
= ath9k_hw_getratetable(sc
->sc_ah
, mode
);
95 memset(sc
->sc_hwmap
, 0, sizeof(sc
->sc_hwmap
));
96 for (i
= 0; i
< 256; i
++) {
97 u8 ix
= rt
->rateCodeToIndex
[i
];
102 sc
->sc_hwmap
[i
].ieeerate
=
103 rt
->info
[ix
].dot11Rate
& IEEE80211_RATE_VAL
;
104 sc
->sc_hwmap
[i
].rateKbps
= rt
->info
[ix
].rateKbps
;
106 if (rt
->info
[ix
].shortPreamble
||
107 rt
->info
[ix
].phy
== PHY_OFDM
) {
108 /* XXX: Handle this */
111 /* NB: this uses the last entry if the rate isn't found */
112 /* XXX beware of overlow */
114 sc
->sc_currates
= rt
;
115 sc
->sc_curmode
= mode
;
117 * All protection frames are transmited at 2Mb/s for
118 * 11g, otherwise at 1Mb/s.
119 * XXX select protection rate index from rate table.
121 sc
->sc_protrix
= (mode
== ATH9K_MODE_11G
? 1 : 0);
125 * Set up rate table (legacy rates)
127 static void ath_setup_rates(struct ath_softc
*sc
, enum ieee80211_band band
)
129 struct ath_hal
*ah
= sc
->sc_ah
;
130 const struct ath9k_rate_table
*rt
= NULL
;
131 struct ieee80211_supported_band
*sband
;
132 struct ieee80211_rate
*rate
;
136 case IEEE80211_BAND_2GHZ
:
137 rt
= ath9k_hw_getratetable(ah
, ATH9K_MODE_11G
);
139 case IEEE80211_BAND_5GHZ
:
140 rt
= ath9k_hw_getratetable(ah
, ATH9K_MODE_11A
);
149 sband
= &sc
->sbands
[band
];
150 rate
= sc
->rates
[band
];
152 if (rt
->rateCount
> ATH_RATE_MAX
)
153 maxrates
= ATH_RATE_MAX
;
155 maxrates
= rt
->rateCount
;
157 for (i
= 0; i
< maxrates
; i
++) {
158 rate
[i
].bitrate
= rt
->info
[i
].rateKbps
/ 100;
159 rate
[i
].hw_value
= rt
->info
[i
].rateCode
;
161 DPRINTF(sc
, ATH_DBG_CONFIG
,
162 "%s: Rate: %2dMbps, ratecode: %2d\n",
164 rate
[i
].bitrate
/ 10,
170 * Set up channel list
172 static int ath_setup_channels(struct ath_softc
*sc
)
174 struct ath_hal
*ah
= sc
->sc_ah
;
175 int nchan
, i
, a
= 0, b
= 0;
176 u8 regclassids
[ATH_REGCLASSIDS_MAX
];
178 struct ieee80211_supported_band
*band_2ghz
;
179 struct ieee80211_supported_band
*band_5ghz
;
180 struct ieee80211_channel
*chan_2ghz
;
181 struct ieee80211_channel
*chan_5ghz
;
182 struct ath9k_channel
*c
;
184 /* Fill in ah->ah_channels */
185 if (!ath9k_regd_init_channels(ah
, ATH_CHAN_MAX
, (u32
*)&nchan
,
186 regclassids
, ATH_REGCLASSIDS_MAX
,
187 &nregclass
, CTRY_DEFAULT
, false, 1)) {
188 u32 rd
= ah
->ah_currentRD
;
189 DPRINTF(sc
, ATH_DBG_FATAL
,
190 "%s: unable to collect channel list; "
191 "regdomain likely %u country code %u\n",
192 __func__
, rd
, CTRY_DEFAULT
);
196 band_2ghz
= &sc
->sbands
[IEEE80211_BAND_2GHZ
];
197 band_5ghz
= &sc
->sbands
[IEEE80211_BAND_5GHZ
];
198 chan_2ghz
= sc
->channels
[IEEE80211_BAND_2GHZ
];
199 chan_5ghz
= sc
->channels
[IEEE80211_BAND_5GHZ
];
201 for (i
= 0; i
< nchan
; i
++) {
202 c
= &ah
->ah_channels
[i
];
203 if (IS_CHAN_2GHZ(c
)) {
204 chan_2ghz
[a
].band
= IEEE80211_BAND_2GHZ
;
205 chan_2ghz
[a
].center_freq
= c
->channel
;
206 chan_2ghz
[a
].max_power
= c
->maxTxPower
;
208 if (c
->privFlags
& CHANNEL_DISALLOW_ADHOC
)
209 chan_2ghz
[a
].flags
|= IEEE80211_CHAN_NO_IBSS
;
210 if (c
->channelFlags
& CHANNEL_PASSIVE
)
211 chan_2ghz
[a
].flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
213 band_2ghz
->n_channels
= ++a
;
215 DPRINTF(sc
, ATH_DBG_CONFIG
,
216 "%s: 2MHz channel: %d, "
217 "channelFlags: 0x%x\n",
218 __func__
, c
->channel
, c
->channelFlags
);
219 } else if (IS_CHAN_5GHZ(c
)) {
220 chan_5ghz
[b
].band
= IEEE80211_BAND_5GHZ
;
221 chan_5ghz
[b
].center_freq
= c
->channel
;
222 chan_5ghz
[b
].max_power
= c
->maxTxPower
;
224 if (c
->privFlags
& CHANNEL_DISALLOW_ADHOC
)
225 chan_5ghz
[b
].flags
|= IEEE80211_CHAN_NO_IBSS
;
226 if (c
->channelFlags
& CHANNEL_PASSIVE
)
227 chan_5ghz
[b
].flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
229 band_5ghz
->n_channels
= ++b
;
231 DPRINTF(sc
, ATH_DBG_CONFIG
,
232 "%s: 5MHz channel: %d, "
233 "channelFlags: 0x%x\n",
234 __func__
, c
->channel
, c
->channelFlags
);
242 * Determine mode from channel flags
244 * This routine will provide the enumerated WIRELESSS_MODE value based
245 * on the settings of the channel flags. If no valid set of flags
246 * exist, the lowest mode (11b) is selected.
249 static enum wireless_mode
ath_chan2mode(struct ath9k_channel
*chan
)
251 if (chan
->chanmode
== CHANNEL_A
)
252 return ATH9K_MODE_11A
;
253 else if (chan
->chanmode
== CHANNEL_G
)
254 return ATH9K_MODE_11G
;
255 else if (chan
->chanmode
== CHANNEL_B
)
256 return ATH9K_MODE_11B
;
257 else if (chan
->chanmode
== CHANNEL_A_HT20
)
258 return ATH9K_MODE_11NA_HT20
;
259 else if (chan
->chanmode
== CHANNEL_G_HT20
)
260 return ATH9K_MODE_11NG_HT20
;
261 else if (chan
->chanmode
== CHANNEL_A_HT40PLUS
)
262 return ATH9K_MODE_11NA_HT40PLUS
;
263 else if (chan
->chanmode
== CHANNEL_A_HT40MINUS
)
264 return ATH9K_MODE_11NA_HT40MINUS
;
265 else if (chan
->chanmode
== CHANNEL_G_HT40PLUS
)
266 return ATH9K_MODE_11NG_HT40PLUS
;
267 else if (chan
->chanmode
== CHANNEL_G_HT40MINUS
)
268 return ATH9K_MODE_11NG_HT40MINUS
;
270 WARN_ON(1); /* should not get here */
272 return ATH9K_MODE_11B
;
276 * Set the current channel
278 * Set/change channels. If the channel is really being changed, it's done
279 * by reseting the chip. To accomplish this we must first cleanup any pending
280 * DMA, then restart stuff after a la ath_init.
282 int ath_set_channel(struct ath_softc
*sc
, struct ath9k_channel
*hchan
)
284 struct ath_hal
*ah
= sc
->sc_ah
;
285 bool fastcc
= true, stopped
;
287 if (sc
->sc_flags
& SC_OP_INVALID
) /* the device is invalid or removed */
290 DPRINTF(sc
, ATH_DBG_CONFIG
,
291 "%s: %u (%u MHz) -> %u (%u MHz), cflags:%x\n",
293 ath9k_hw_mhz2ieee(ah
, sc
->sc_ah
->ah_curchan
->channel
,
294 sc
->sc_ah
->ah_curchan
->channelFlags
),
295 sc
->sc_ah
->ah_curchan
->channel
,
296 ath9k_hw_mhz2ieee(ah
, hchan
->channel
, hchan
->channelFlags
),
297 hchan
->channel
, hchan
->channelFlags
);
299 if (hchan
->channel
!= sc
->sc_ah
->ah_curchan
->channel
||
300 hchan
->channelFlags
!= sc
->sc_ah
->ah_curchan
->channelFlags
||
301 (sc
->sc_flags
& SC_OP_CHAINMASK_UPDATE
) ||
302 (sc
->sc_flags
& SC_OP_FULL_RESET
)) {
305 * This is only performed if the channel settings have
308 * To switch channels clear any pending DMA operations;
309 * wait long enough for the RX fifo to drain, reset the
310 * hardware at the new frequency, and then re-enable
311 * the relevant bits of the h/w.
313 ath9k_hw_set_interrupts(ah
, 0); /* disable interrupts */
314 ath_draintxq(sc
, false); /* clear pending tx frames */
315 stopped
= ath_stoprecv(sc
); /* turn off frame recv */
317 /* XXX: do not flush receive queue here. We don't want
318 * to flush data frames already in queue because of
319 * changing channel. */
321 if (!stopped
|| (sc
->sc_flags
& SC_OP_FULL_RESET
))
324 spin_lock_bh(&sc
->sc_resetlock
);
325 if (!ath9k_hw_reset(ah
, hchan
,
326 sc
->sc_ht_info
.tx_chan_width
,
329 sc
->sc_ht_extprotspacing
,
331 DPRINTF(sc
, ATH_DBG_FATAL
,
332 "%s: unable to reset channel %u (%uMhz) "
333 "flags 0x%x hal status %u\n", __func__
,
334 ath9k_hw_mhz2ieee(ah
, hchan
->channel
,
335 hchan
->channelFlags
),
336 hchan
->channel
, hchan
->channelFlags
, status
);
337 spin_unlock_bh(&sc
->sc_resetlock
);
340 spin_unlock_bh(&sc
->sc_resetlock
);
342 sc
->sc_flags
&= ~SC_OP_CHAINMASK_UPDATE
;
343 sc
->sc_flags
&= ~SC_OP_FULL_RESET
;
345 /* Re-enable rx framework */
346 if (ath_startrecv(sc
) != 0) {
347 DPRINTF(sc
, ATH_DBG_FATAL
,
348 "%s: unable to restart recv logic\n", __func__
);
352 * Change channels and update the h/w rate map
353 * if we're switching; e.g. 11a to 11b/g.
355 ath_setcurmode(sc
, ath_chan2mode(hchan
));
357 ath_update_txpow(sc
); /* update tx power state */
359 * Re-enable interrupts.
361 ath9k_hw_set_interrupts(ah
, sc
->sc_imask
);
366 /**********************/
367 /* Chainmask Handling */
368 /**********************/
370 static void ath_chainmask_sel_timertimeout(unsigned long data
)
372 struct ath_chainmask_sel
*cm
= (struct ath_chainmask_sel
*)data
;
373 cm
->switch_allowed
= 1;
376 /* Start chainmask select timer */
377 static void ath_chainmask_sel_timerstart(struct ath_chainmask_sel
*cm
)
379 cm
->switch_allowed
= 0;
380 mod_timer(&cm
->timer
, ath_chainmask_sel_period
);
383 /* Stop chainmask select timer */
384 static void ath_chainmask_sel_timerstop(struct ath_chainmask_sel
*cm
)
386 cm
->switch_allowed
= 0;
387 del_timer_sync(&cm
->timer
);
390 static void ath_chainmask_sel_init(struct ath_softc
*sc
, struct ath_node
*an
)
392 struct ath_chainmask_sel
*cm
= &an
->an_chainmask_sel
;
394 memset(cm
, 0, sizeof(struct ath_chainmask_sel
));
396 cm
->cur_tx_mask
= sc
->sc_tx_chainmask
;
397 cm
->cur_rx_mask
= sc
->sc_rx_chainmask
;
398 cm
->tx_avgrssi
= ATH_RSSI_DUMMY_MARKER
;
399 setup_timer(&cm
->timer
,
400 ath_chainmask_sel_timertimeout
, (unsigned long) cm
);
403 int ath_chainmask_sel_logic(struct ath_softc
*sc
, struct ath_node
*an
)
405 struct ath_chainmask_sel
*cm
= &an
->an_chainmask_sel
;
408 * Disable auto-swtiching in one of the following if conditions.
409 * sc_chainmask_auto_sel is used for internal global auto-switching
410 * enabled/disabled setting
412 if (sc
->sc_ah
->ah_caps
.tx_chainmask
!= ATH_CHAINMASK_SEL_3X3
) {
413 cm
->cur_tx_mask
= sc
->sc_tx_chainmask
;
414 return cm
->cur_tx_mask
;
417 if (cm
->tx_avgrssi
== ATH_RSSI_DUMMY_MARKER
)
418 return cm
->cur_tx_mask
;
420 if (cm
->switch_allowed
) {
421 /* Switch down from tx 3 to tx 2. */
422 if (cm
->cur_tx_mask
== ATH_CHAINMASK_SEL_3X3
&&
423 ATH_RSSI_OUT(cm
->tx_avgrssi
) >=
424 ath_chainmask_sel_down_rssi_thres
) {
425 cm
->cur_tx_mask
= sc
->sc_tx_chainmask
;
427 /* Don't let another switch happen until
428 * this timer expires */
429 ath_chainmask_sel_timerstart(cm
);
431 /* Switch up from tx 2 to 3. */
432 else if (cm
->cur_tx_mask
== sc
->sc_tx_chainmask
&&
433 ATH_RSSI_OUT(cm
->tx_avgrssi
) <=
434 ath_chainmask_sel_up_rssi_thres
) {
435 cm
->cur_tx_mask
= ATH_CHAINMASK_SEL_3X3
;
437 /* Don't let another switch happen
438 * until this timer expires */
439 ath_chainmask_sel_timerstart(cm
);
443 return cm
->cur_tx_mask
;
447 * Update tx/rx chainmask. For legacy association,
448 * hard code chainmask to 1x1, for 11n association, use
449 * the chainmask configuration.
452 void ath_update_chainmask(struct ath_softc
*sc
, int is_ht
)
454 sc
->sc_flags
|= SC_OP_CHAINMASK_UPDATE
;
456 sc
->sc_tx_chainmask
= sc
->sc_ah
->ah_caps
.tx_chainmask
;
457 sc
->sc_rx_chainmask
= sc
->sc_ah
->ah_caps
.rx_chainmask
;
459 sc
->sc_tx_chainmask
= 1;
460 sc
->sc_rx_chainmask
= 1;
463 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: tx chmask: %d, rx chmask: %d\n",
464 __func__
, sc
->sc_tx_chainmask
, sc
->sc_rx_chainmask
);
472 * This routine performs the periodic noise floor calibration function
473 * that is used to adjust and optimize the chip performance. This
474 * takes environmental changes (location, temperature) into account.
475 * When the task is complete, it reschedules itself depending on the
476 * appropriate interval that was calculated.
479 static void ath_ani_calibrate(unsigned long data
)
481 struct ath_softc
*sc
;
483 bool longcal
= false;
484 bool shortcal
= false;
485 bool aniflag
= false;
486 unsigned int timestamp
= jiffies_to_msecs(jiffies
);
489 sc
= (struct ath_softc
*)data
;
493 * don't calibrate when we're scanning.
494 * we are most likely not on our home channel.
496 if (sc
->rx_filter
& FIF_BCN_PRBRESP_PROMISC
)
499 /* Long calibration runs independently of short calibration. */
500 if ((timestamp
- sc
->sc_ani
.sc_longcal_timer
) >= ATH_LONG_CALINTERVAL
) {
502 DPRINTF(sc
, ATH_DBG_ANI
, "%s: longcal @%lu\n",
504 sc
->sc_ani
.sc_longcal_timer
= timestamp
;
507 /* Short calibration applies only while sc_caldone is false */
508 if (!sc
->sc_ani
.sc_caldone
) {
509 if ((timestamp
- sc
->sc_ani
.sc_shortcal_timer
) >=
510 ATH_SHORT_CALINTERVAL
) {
512 DPRINTF(sc
, ATH_DBG_ANI
, "%s: shortcal @%lu\n",
514 sc
->sc_ani
.sc_shortcal_timer
= timestamp
;
515 sc
->sc_ani
.sc_resetcal_timer
= timestamp
;
518 if ((timestamp
- sc
->sc_ani
.sc_resetcal_timer
) >=
519 ATH_RESTART_CALINTERVAL
) {
520 ath9k_hw_reset_calvalid(ah
, ah
->ah_curchan
,
521 &sc
->sc_ani
.sc_caldone
);
522 if (sc
->sc_ani
.sc_caldone
)
523 sc
->sc_ani
.sc_resetcal_timer
= timestamp
;
527 /* Verify whether we must check ANI */
528 if ((timestamp
- sc
->sc_ani
.sc_checkani_timer
) >=
529 ATH_ANI_POLLINTERVAL
) {
531 sc
->sc_ani
.sc_checkani_timer
= timestamp
;
534 /* Skip all processing if there's nothing to do. */
535 if (longcal
|| shortcal
|| aniflag
) {
536 /* Call ANI routine if necessary */
538 ath9k_hw_ani_monitor(ah
, &sc
->sc_halstats
,
541 /* Perform calibration if necessary */
542 if (longcal
|| shortcal
) {
543 bool iscaldone
= false;
545 if (ath9k_hw_calibrate(ah
, ah
->ah_curchan
,
546 sc
->sc_rx_chainmask
, longcal
,
549 sc
->sc_ani
.sc_noise_floor
=
550 ath9k_hw_getchan_noise(ah
,
553 DPRINTF(sc
, ATH_DBG_ANI
,
554 "%s: calibrate chan %u/%x nf: %d\n",
556 ah
->ah_curchan
->channel
,
557 ah
->ah_curchan
->channelFlags
,
558 sc
->sc_ani
.sc_noise_floor
);
560 DPRINTF(sc
, ATH_DBG_ANY
,
561 "%s: calibrate chan %u/%x failed\n",
563 ah
->ah_curchan
->channel
,
564 ah
->ah_curchan
->channelFlags
);
566 sc
->sc_ani
.sc_caldone
= iscaldone
;
571 * Set timer interval based on previous results.
572 * The interval must be the shortest necessary to satisfy ANI,
573 * short calibration and long calibration.
576 cal_interval
= ATH_ANI_POLLINTERVAL
;
577 if (!sc
->sc_ani
.sc_caldone
)
578 cal_interval
= min(cal_interval
, (u32
)ATH_SHORT_CALINTERVAL
);
580 mod_timer(&sc
->sc_ani
.timer
, jiffies
+ msecs_to_jiffies(cal_interval
));
587 int ath_open(struct ath_softc
*sc
, struct ath9k_channel
*initial_chan
)
589 struct ath_hal
*ah
= sc
->sc_ah
;
593 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: mode %d\n",
594 __func__
, sc
->sc_ah
->ah_opmode
);
596 /* Reset SERDES registers */
597 ath9k_hw_configpcipowersave(ah
, 0);
600 * The basic interface to setting the hardware in a good
601 * state is ``reset''. On return the hardware is known to
602 * be powered up and with interrupts disabled. This must
603 * be followed by initialization of the appropriate bits
604 * and then setup of the interrupt mask.
607 spin_lock_bh(&sc
->sc_resetlock
);
608 if (!ath9k_hw_reset(ah
, initial_chan
,
609 sc
->sc_ht_info
.tx_chan_width
,
610 sc
->sc_tx_chainmask
, sc
->sc_rx_chainmask
,
611 sc
->sc_ht_extprotspacing
, false, &status
)) {
612 DPRINTF(sc
, ATH_DBG_FATAL
,
613 "%s: unable to reset hardware; hal status %u "
614 "(freq %u flags 0x%x)\n", __func__
, status
,
615 initial_chan
->channel
, initial_chan
->channelFlags
);
617 spin_unlock_bh(&sc
->sc_resetlock
);
620 spin_unlock_bh(&sc
->sc_resetlock
);
623 * This is needed only to setup initial state
624 * but it's best done after a reset.
626 ath_update_txpow(sc
);
629 * Setup the hardware after reset:
630 * The receive engine is set going.
631 * Frame transmit is handled entirely
632 * in the frame output path; there's nothing to do
633 * here except setup the interrupt mask.
635 if (ath_startrecv(sc
) != 0) {
636 DPRINTF(sc
, ATH_DBG_FATAL
,
637 "%s: unable to start recv logic\n", __func__
);
642 /* Setup our intr mask. */
643 sc
->sc_imask
= ATH9K_INT_RX
| ATH9K_INT_TX
644 | ATH9K_INT_RXEOL
| ATH9K_INT_RXORN
645 | ATH9K_INT_FATAL
| ATH9K_INT_GLOBAL
;
647 if (ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_GTT
)
648 sc
->sc_imask
|= ATH9K_INT_GTT
;
650 if (ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_HT
)
651 sc
->sc_imask
|= ATH9K_INT_CST
;
654 * Enable MIB interrupts when there are hardware phy counters.
655 * Note we only do this (at the moment) for station mode.
657 if (ath9k_hw_phycounters(ah
) &&
658 ((sc
->sc_ah
->ah_opmode
== ATH9K_M_STA
) ||
659 (sc
->sc_ah
->ah_opmode
== ATH9K_M_IBSS
)))
660 sc
->sc_imask
|= ATH9K_INT_MIB
;
662 * Some hardware processes the TIM IE and fires an
663 * interrupt when the TIM bit is set. For hardware
664 * that does, if not overridden by configuration,
665 * enable the TIM interrupt when operating as station.
667 if ((ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_ENHANCEDPM
) &&
668 (sc
->sc_ah
->ah_opmode
== ATH9K_M_STA
) &&
669 !sc
->sc_config
.swBeaconProcess
)
670 sc
->sc_imask
|= ATH9K_INT_TIM
;
672 ath_setcurmode(sc
, ath_chan2mode(initial_chan
));
674 sc
->sc_flags
&= ~SC_OP_INVALID
;
676 /* Disable BMISS interrupt when we're not associated */
677 sc
->sc_imask
&= ~(ATH9K_INT_SWBA
| ATH9K_INT_BMISS
);
678 ath9k_hw_set_interrupts(sc
->sc_ah
,sc
->sc_imask
);
680 ieee80211_wake_queues(sc
->hw
);
685 void ath_stop(struct ath_softc
*sc
)
687 struct ath_hal
*ah
= sc
->sc_ah
;
689 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: Cleaning up\n", __func__
);
691 ieee80211_stop_queues(sc
->hw
);
693 /* make sure h/w will not generate any interrupt
694 * before setting the invalid flag. */
695 ath9k_hw_set_interrupts(ah
, 0);
697 if (!(sc
->sc_flags
& SC_OP_INVALID
)) {
698 ath_draintxq(sc
, false);
700 ath9k_hw_phy_disable(ah
);
702 sc
->sc_rxlink
= NULL
;
704 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
705 if (sc
->sc_ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_RFSILENT
)
706 cancel_delayed_work_sync(&sc
->rf_kill
.rfkill_poll
);
708 /* disable HAL and put h/w to sleep */
709 ath9k_hw_disable(sc
->sc_ah
);
710 ath9k_hw_configpcipowersave(sc
->sc_ah
, 1);
712 sc
->sc_flags
|= SC_OP_INVALID
;
715 int ath_reset(struct ath_softc
*sc
, bool retry_tx
)
717 struct ath_hal
*ah
= sc
->sc_ah
;
721 ath9k_hw_set_interrupts(ah
, 0);
722 ath_draintxq(sc
, retry_tx
);
727 spin_lock_bh(&sc
->sc_resetlock
);
728 if (!ath9k_hw_reset(ah
, sc
->sc_ah
->ah_curchan
,
729 sc
->sc_ht_info
.tx_chan_width
,
730 sc
->sc_tx_chainmask
, sc
->sc_rx_chainmask
,
731 sc
->sc_ht_extprotspacing
, false, &status
)) {
732 DPRINTF(sc
, ATH_DBG_FATAL
,
733 "%s: unable to reset hardware; hal status %u\n",
737 spin_unlock_bh(&sc
->sc_resetlock
);
739 if (ath_startrecv(sc
) != 0)
740 DPRINTF(sc
, ATH_DBG_FATAL
,
741 "%s: unable to start recv logic\n", __func__
);
744 * We may be doing a reset in response to a request
745 * that changes the channel so update any state that
746 * might change as a result.
748 ath_setcurmode(sc
, ath_chan2mode(sc
->sc_ah
->ah_curchan
));
750 ath_update_txpow(sc
);
752 if (sc
->sc_flags
& SC_OP_BEACONS
)
753 ath_beacon_config(sc
, ATH_IF_ID_ANY
); /* restart beacons */
755 ath9k_hw_set_interrupts(ah
, sc
->sc_imask
);
757 /* Restart the txq */
760 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++) {
761 if (ATH_TXQ_SETUP(sc
, i
)) {
762 spin_lock_bh(&sc
->sc_txq
[i
].axq_lock
);
763 ath_txq_schedule(sc
, &sc
->sc_txq
[i
]);
764 spin_unlock_bh(&sc
->sc_txq
[i
].axq_lock
);
772 /* Interrupt handler. Most of the actual processing is deferred.
773 * It's the caller's responsibility to ensure the chip is awake. */
775 irqreturn_t
ath_isr(int irq
, void *dev
)
777 struct ath_softc
*sc
= dev
;
778 struct ath_hal
*ah
= sc
->sc_ah
;
779 enum ath9k_int status
;
783 if (sc
->sc_flags
& SC_OP_INVALID
) {
785 * The hardware is not ready/present, don't
786 * touch anything. Note this can happen early
787 * on if the IRQ is shared.
791 if (!ath9k_hw_intrpend(ah
)) { /* shared irq, not for us */
796 * Figure out the reason(s) for the interrupt. Note
797 * that the hal returns a pseudo-ISR that may include
798 * bits we haven't explicitly enabled so we mask the
799 * value to insure we only process bits we requested.
801 ath9k_hw_getisr(ah
, &status
); /* NB: clears ISR too */
803 status
&= sc
->sc_imask
; /* discard unasked-for bits */
806 * If there are no status bits set, then this interrupt was not
807 * for me (should have been caught above).
813 sc
->sc_intrstatus
= status
;
815 if (status
& ATH9K_INT_FATAL
) {
816 /* need a chip reset */
818 } else if (status
& ATH9K_INT_RXORN
) {
819 /* need a chip reset */
822 if (status
& ATH9K_INT_SWBA
) {
823 /* schedule a tasklet for beacon handling */
824 tasklet_schedule(&sc
->bcon_tasklet
);
826 if (status
& ATH9K_INT_RXEOL
) {
828 * NB: the hardware should re-read the link when
829 * RXE bit is written, but it doesn't work
830 * at least on older hardware revs.
835 if (status
& ATH9K_INT_TXURN
)
836 /* bump tx trigger level */
837 ath9k_hw_updatetxtriglevel(ah
, true);
838 /* XXX: optimize this */
839 if (status
& ATH9K_INT_RX
)
841 if (status
& ATH9K_INT_TX
)
843 if (status
& ATH9K_INT_BMISS
)
845 /* carrier sense timeout */
846 if (status
& ATH9K_INT_CST
)
848 if (status
& ATH9K_INT_MIB
) {
850 * Disable interrupts until we service the MIB
851 * interrupt; otherwise it will continue to
854 ath9k_hw_set_interrupts(ah
, 0);
856 * Let the hal handle the event. We assume
857 * it will clear whatever condition caused
860 ath9k_hw_procmibevent(ah
, &sc
->sc_halstats
);
861 ath9k_hw_set_interrupts(ah
, sc
->sc_imask
);
863 if (status
& ATH9K_INT_TIM_TIMER
) {
864 if (!(ah
->ah_caps
.hw_caps
&
865 ATH9K_HW_CAP_AUTOSLEEP
)) {
866 /* Clear RxAbort bit so that we can
868 ath9k_hw_setrxabort(ah
, 0);
876 /* turn off every interrupt except SWBA */
877 ath9k_hw_set_interrupts(ah
, (sc
->sc_imask
& ATH9K_INT_SWBA
));
878 tasklet_schedule(&sc
->intr_tq
);
884 /* Deferred interrupt processing */
886 static void ath9k_tasklet(unsigned long data
)
888 struct ath_softc
*sc
= (struct ath_softc
*)data
;
889 u32 status
= sc
->sc_intrstatus
;
891 if (status
& ATH9K_INT_FATAL
) {
892 /* need a chip reset */
893 ath_reset(sc
, false);
898 (ATH9K_INT_RX
| ATH9K_INT_RXEOL
| ATH9K_INT_RXORN
)) {
899 /* XXX: fill me in */
901 if (status & ATH9K_INT_RXORN) {
903 if (status & ATH9K_INT_RXEOL) {
906 spin_lock_bh(&sc
->sc_rxflushlock
);
907 ath_rx_tasklet(sc
, 0);
908 spin_unlock_bh(&sc
->sc_rxflushlock
);
910 /* XXX: optimize this */
911 if (status
& ATH9K_INT_TX
)
913 /* XXX: fill me in */
915 if (status & ATH9K_INT_BMISS) {
917 if (status & (ATH9K_INT_TIM | ATH9K_INT_DTIMSYNC)) {
918 if (status & ATH9K_INT_TIM) {
920 if (status & ATH9K_INT_DTIMSYNC) {
926 /* re-enable hardware interrupt */
927 ath9k_hw_set_interrupts(sc
->sc_ah
, sc
->sc_imask
);
930 int ath_init(u16 devid
, struct ath_softc
*sc
)
932 struct ath_hal
*ah
= NULL
;
937 /* XXX: hardware will not be ready until ath_open() being called */
938 sc
->sc_flags
|= SC_OP_INVALID
;
939 sc
->sc_debug
= DBG_DEFAULT
;
941 spin_lock_init(&sc
->sc_resetlock
);
942 tasklet_init(&sc
->intr_tq
, ath9k_tasklet
, (unsigned long)sc
);
943 tasklet_init(&sc
->bcon_tasklet
, ath9k_beacon_tasklet
,
947 * Cache line size is used to size and align various
948 * structures used to communicate with the hardware.
950 bus_read_cachesize(sc
, &csz
);
951 /* XXX assert csz is non-zero */
952 sc
->sc_cachelsz
= csz
<< 2; /* convert to bytes */
954 ah
= ath9k_hw_attach(devid
, sc
, sc
->mem
, &status
);
956 DPRINTF(sc
, ATH_DBG_FATAL
,
957 "%s: unable to attach hardware; HAL status %u\n",
964 /* Get the hardware key cache size. */
965 sc
->sc_keymax
= ah
->ah_caps
.keycache_size
;
966 if (sc
->sc_keymax
> ATH_KEYMAX
) {
967 DPRINTF(sc
, ATH_DBG_KEYCACHE
,
968 "%s: Warning, using only %u entries in %u key cache\n",
969 __func__
, ATH_KEYMAX
, sc
->sc_keymax
);
970 sc
->sc_keymax
= ATH_KEYMAX
;
974 * Reset the key cache since some parts do not
975 * reset the contents on initial power up.
977 for (i
= 0; i
< sc
->sc_keymax
; i
++)
978 ath9k_hw_keyreset(ah
, (u16
) i
);
980 * Mark key cache slots associated with global keys
981 * as in use. If we knew TKIP was not to be used we
982 * could leave the +32, +64, and +32+64 slots free.
983 * XXX only for splitmic.
985 for (i
= 0; i
< IEEE80211_WEP_NKID
; i
++) {
986 set_bit(i
, sc
->sc_keymap
);
987 set_bit(i
+ 32, sc
->sc_keymap
);
988 set_bit(i
+ 64, sc
->sc_keymap
);
989 set_bit(i
+ 32 + 64, sc
->sc_keymap
);
992 /* Collect the channel list using the default country code */
994 error
= ath_setup_channels(sc
);
998 /* default to MONITOR mode */
999 sc
->sc_ah
->ah_opmode
= ATH9K_M_MONITOR
;
1001 /* Setup rate tables */
1003 ath_setup_rates(sc
, IEEE80211_BAND_2GHZ
);
1004 ath_setup_rates(sc
, IEEE80211_BAND_5GHZ
);
1006 /* NB: setup here so ath_rate_update is happy */
1007 ath_setcurmode(sc
, ATH9K_MODE_11A
);
1010 * Allocate hardware transmit queues: one queue for
1011 * beacon frames and one data queue for each QoS
1012 * priority. Note that the hal handles reseting
1013 * these queues at the needed time.
1015 sc
->sc_bhalq
= ath_beaconq_setup(ah
);
1016 if (sc
->sc_bhalq
== -1) {
1017 DPRINTF(sc
, ATH_DBG_FATAL
,
1018 "%s: unable to setup a beacon xmit queue\n", __func__
);
1022 sc
->sc_cabq
= ath_txq_setup(sc
, ATH9K_TX_QUEUE_CAB
, 0);
1023 if (sc
->sc_cabq
== NULL
) {
1024 DPRINTF(sc
, ATH_DBG_FATAL
,
1025 "%s: unable to setup CAB xmit queue\n", __func__
);
1030 sc
->sc_config
.cabqReadytime
= ATH_CABQ_READY_TIME
;
1031 ath_cabq_update(sc
);
1033 for (i
= 0; i
< ARRAY_SIZE(sc
->sc_haltype2q
); i
++)
1034 sc
->sc_haltype2q
[i
] = -1;
1036 /* Setup data queues */
1037 /* NB: ensure BK queue is the lowest priority h/w queue */
1038 if (!ath_tx_setup(sc
, ATH9K_WME_AC_BK
)) {
1039 DPRINTF(sc
, ATH_DBG_FATAL
,
1040 "%s: unable to setup xmit queue for BK traffic\n",
1046 if (!ath_tx_setup(sc
, ATH9K_WME_AC_BE
)) {
1047 DPRINTF(sc
, ATH_DBG_FATAL
,
1048 "%s: unable to setup xmit queue for BE traffic\n",
1053 if (!ath_tx_setup(sc
, ATH9K_WME_AC_VI
)) {
1054 DPRINTF(sc
, ATH_DBG_FATAL
,
1055 "%s: unable to setup xmit queue for VI traffic\n",
1060 if (!ath_tx_setup(sc
, ATH9K_WME_AC_VO
)) {
1061 DPRINTF(sc
, ATH_DBG_FATAL
,
1062 "%s: unable to setup xmit queue for VO traffic\n",
1068 /* Initializes the noise floor to a reasonable default value.
1069 * Later on this will be updated during ANI processing. */
1071 sc
->sc_ani
.sc_noise_floor
= ATH_DEFAULT_NOISE_FLOOR
;
1072 setup_timer(&sc
->sc_ani
.timer
, ath_ani_calibrate
, (unsigned long)sc
);
1074 ath_rate_attach(sc
);
1076 if (ath9k_hw_getcapability(ah
, ATH9K_CAP_CIPHER
,
1077 ATH9K_CIPHER_TKIP
, NULL
)) {
1079 * Whether we should enable h/w TKIP MIC.
1080 * XXX: if we don't support WME TKIP MIC, then we wouldn't
1081 * report WMM capable, so it's always safe to turn on
1082 * TKIP MIC in this case.
1084 ath9k_hw_setcapability(sc
->sc_ah
, ATH9K_CAP_TKIP_MIC
,
1089 * Check whether the separate key cache entries
1090 * are required to handle both tx+rx MIC keys.
1091 * With split mic keys the number of stations is limited
1092 * to 27 otherwise 59.
1094 if (ath9k_hw_getcapability(ah
, ATH9K_CAP_CIPHER
,
1095 ATH9K_CIPHER_TKIP
, NULL
)
1096 && ath9k_hw_getcapability(ah
, ATH9K_CAP_CIPHER
,
1097 ATH9K_CIPHER_MIC
, NULL
)
1098 && ath9k_hw_getcapability(ah
, ATH9K_CAP_TKIP_SPLIT
,
1100 sc
->sc_splitmic
= 1;
1102 /* turn on mcast key search if possible */
1103 if (!ath9k_hw_getcapability(ah
, ATH9K_CAP_MCAST_KEYSRCH
, 0, NULL
))
1104 (void)ath9k_hw_setcapability(ah
, ATH9K_CAP_MCAST_KEYSRCH
, 1,
1107 sc
->sc_config
.txpowlimit
= ATH_TXPOWER_MAX
;
1108 sc
->sc_config
.txpowlimit_override
= 0;
1110 /* 11n Capabilities */
1111 if (ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_HT
) {
1112 sc
->sc_flags
|= SC_OP_TXAGGR
;
1113 sc
->sc_flags
|= SC_OP_RXAGGR
;
1116 sc
->sc_tx_chainmask
= ah
->ah_caps
.tx_chainmask
;
1117 sc
->sc_rx_chainmask
= ah
->ah_caps
.rx_chainmask
;
1119 ath9k_hw_setcapability(ah
, ATH9K_CAP_DIVERSITY
, 1, true, NULL
);
1120 sc
->sc_defant
= ath9k_hw_getdefantenna(ah
);
1122 ath9k_hw_getmac(ah
, sc
->sc_myaddr
);
1123 if (ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_BSSIDMASK
) {
1124 ath9k_hw_getbssidmask(ah
, sc
->sc_bssidmask
);
1125 ATH_SET_VAP_BSSID_MASK(sc
->sc_bssidmask
);
1126 ath9k_hw_setbssidmask(ah
, sc
->sc_bssidmask
);
1129 sc
->sc_slottime
= ATH9K_SLOT_TIME_9
; /* default to short slot time */
1131 /* initialize beacon slots */
1132 for (i
= 0; i
< ARRAY_SIZE(sc
->sc_bslot
); i
++)
1133 sc
->sc_bslot
[i
] = ATH_IF_ID_ANY
;
1135 /* save MISC configurations */
1136 sc
->sc_config
.swBeaconProcess
= 1;
1138 #ifdef CONFIG_SLOW_ANT_DIV
1139 /* range is 40 - 255, we use something in the middle */
1140 ath_slow_ant_div_init(&sc
->sc_antdiv
, sc
, 0x127);
1143 /* setup channels and rates */
1145 sc
->sbands
[IEEE80211_BAND_2GHZ
].channels
=
1146 sc
->channels
[IEEE80211_BAND_2GHZ
];
1147 sc
->sbands
[IEEE80211_BAND_2GHZ
].bitrates
=
1148 sc
->rates
[IEEE80211_BAND_2GHZ
];
1149 sc
->sbands
[IEEE80211_BAND_2GHZ
].band
= IEEE80211_BAND_2GHZ
;
1151 if (test_bit(ATH9K_MODE_11A
, sc
->sc_ah
->ah_caps
.wireless_modes
)) {
1152 sc
->sbands
[IEEE80211_BAND_5GHZ
].channels
=
1153 sc
->channels
[IEEE80211_BAND_5GHZ
];
1154 sc
->sbands
[IEEE80211_BAND_5GHZ
].bitrates
=
1155 sc
->rates
[IEEE80211_BAND_5GHZ
];
1156 sc
->sbands
[IEEE80211_BAND_5GHZ
].band
= IEEE80211_BAND_5GHZ
;
1161 /* cleanup tx queues */
1162 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++)
1163 if (ATH_TXQ_SETUP(sc
, i
))
1164 ath_tx_cleanupq(sc
, &sc
->sc_txq
[i
]);
1167 ath9k_hw_detach(ah
);
1172 /*******************/
1173 /* Node Management */
1174 /*******************/
1176 void ath_node_attach(struct ath_softc
*sc
, struct ieee80211_sta
*sta
)
1178 struct ath_node
*an
;
1180 an
= (struct ath_node
*)sta
->drv_priv
;
1182 if (sc
->sc_flags
& SC_OP_TXAGGR
)
1183 ath_tx_node_init(sc
, an
);
1185 an
->maxampdu
= 1 << (IEEE80211_HTCAP_MAXRXAMPDU_FACTOR
+
1186 sta
->ht_cap
.ampdu_factor
);
1187 an
->mpdudensity
= parse_mpdudensity(sta
->ht_cap
.ampdu_density
);
1189 ath_chainmask_sel_init(sc
, an
);
1190 ath_chainmask_sel_timerstart(&an
->an_chainmask_sel
);
1193 void ath_node_detach(struct ath_softc
*sc
, struct ieee80211_sta
*sta
)
1195 struct ath_node
*an
= (struct ath_node
*)sta
->drv_priv
;
1197 ath_chainmask_sel_timerstop(&an
->an_chainmask_sel
);
1199 if (sc
->sc_flags
& SC_OP_TXAGGR
)
1200 ath_tx_node_cleanup(sc
, an
);
1206 * Setup driver-specific state for a newly associated node. This routine
1207 * really only applies if compression or XR are enabled, there is no code
1208 * covering any other cases.
1211 void ath_newassoc(struct ath_softc
*sc
,
1212 struct ath_node
*an
, int isnew
, int isuapsd
)
1216 /* if station reassociates, tear down the aggregation state. */
1218 for (tidno
= 0; tidno
< WME_NUM_TID
; tidno
++) {
1219 if (sc
->sc_flags
& SC_OP_TXAGGR
)
1220 ath_tx_aggr_teardown(sc
, an
, tidno
);
1229 void ath_key_reset(struct ath_softc
*sc
, u16 keyix
, int freeslot
)
1231 ath9k_hw_keyreset(sc
->sc_ah
, keyix
);
1233 clear_bit(keyix
, sc
->sc_keymap
);
1236 int ath_keyset(struct ath_softc
*sc
,
1238 struct ath9k_keyval
*hk
,
1239 const u8 mac
[ETH_ALEN
])
1243 status
= ath9k_hw_set_keycache_entry(sc
->sc_ah
,
1244 keyix
, hk
, mac
, false);
1246 return status
!= false;
1249 /***********************/
1250 /* TX Power/Regulatory */
1251 /***********************/
1254 * Set Transmit power in HAL
1256 * This routine makes the actual HAL calls to set the new transmit power
1260 void ath_update_txpow(struct ath_softc
*sc
)
1262 struct ath_hal
*ah
= sc
->sc_ah
;
1265 if (sc
->sc_curtxpow
!= sc
->sc_config
.txpowlimit
) {
1266 ath9k_hw_set_txpowerlimit(ah
, sc
->sc_config
.txpowlimit
);
1267 /* read back in case value is clamped */
1268 ath9k_hw_getcapability(ah
, ATH9K_CAP_TXPOW
, 1, &txpow
);
1269 sc
->sc_curtxpow
= txpow
;
1273 /**************************/
1274 /* Slow Antenna Diversity */
1275 /**************************/
1277 void ath_slow_ant_div_init(struct ath_antdiv
*antdiv
,
1278 struct ath_softc
*sc
,
1283 /* antdivf_rssitrig can range from 40 - 0xff */
1284 trig
= (rssitrig
> 0xff) ? 0xff : rssitrig
;
1285 trig
= (rssitrig
< 40) ? 40 : rssitrig
;
1287 antdiv
->antdiv_sc
= sc
;
1288 antdiv
->antdivf_rssitrig
= trig
;
1291 void ath_slow_ant_div_start(struct ath_antdiv
*antdiv
,
1295 antdiv
->antdiv_num_antcfg
=
1296 num_antcfg
< ATH_ANT_DIV_MAX_CFG
?
1297 num_antcfg
: ATH_ANT_DIV_MAX_CFG
;
1298 antdiv
->antdiv_state
= ATH_ANT_DIV_IDLE
;
1299 antdiv
->antdiv_curcfg
= 0;
1300 antdiv
->antdiv_bestcfg
= 0;
1301 antdiv
->antdiv_laststatetsf
= 0;
1303 memcpy(antdiv
->antdiv_bssid
, bssid
, sizeof(antdiv
->antdiv_bssid
));
1305 antdiv
->antdiv_start
= 1;
1308 void ath_slow_ant_div_stop(struct ath_antdiv
*antdiv
)
1310 antdiv
->antdiv_start
= 0;
1313 static int32_t ath_find_max_val(int32_t *val
,
1314 u8 num_val
, u8
*max_index
)
1316 u32 MaxVal
= *val
++;
1320 while (++cur_index
< num_val
) {
1321 if (*val
> MaxVal
) {
1323 *max_index
= cur_index
;
1332 void ath_slow_ant_div(struct ath_antdiv
*antdiv
,
1333 struct ieee80211_hdr
*hdr
,
1334 struct ath_rx_status
*rx_stats
)
1336 struct ath_softc
*sc
= antdiv
->antdiv_sc
;
1337 struct ath_hal
*ah
= sc
->sc_ah
;
1339 u8 bestcfg
, curcfg
= antdiv
->antdiv_curcfg
;
1340 __le16 fc
= hdr
->frame_control
;
1342 if (antdiv
->antdiv_start
&& ieee80211_is_beacon(fc
)
1343 && !compare_ether_addr(hdr
->addr3
, antdiv
->antdiv_bssid
)) {
1344 antdiv
->antdiv_lastbrssi
[curcfg
] = rx_stats
->rs_rssi
;
1345 antdiv
->antdiv_lastbtsf
[curcfg
] = ath9k_hw_gettsf64(sc
->sc_ah
);
1346 curtsf
= antdiv
->antdiv_lastbtsf
[curcfg
];
1351 switch (antdiv
->antdiv_state
) {
1352 case ATH_ANT_DIV_IDLE
:
1353 if ((antdiv
->antdiv_lastbrssi
[curcfg
] <
1354 antdiv
->antdivf_rssitrig
)
1355 && ((curtsf
- antdiv
->antdiv_laststatetsf
) >
1356 ATH_ANT_DIV_MIN_IDLE_US
)) {
1359 if (curcfg
== antdiv
->antdiv_num_antcfg
)
1362 if (!ath9k_hw_select_antconfig(ah
, curcfg
)) {
1363 antdiv
->antdiv_bestcfg
= antdiv
->antdiv_curcfg
;
1364 antdiv
->antdiv_curcfg
= curcfg
;
1365 antdiv
->antdiv_laststatetsf
= curtsf
;
1366 antdiv
->antdiv_state
= ATH_ANT_DIV_SCAN
;
1371 case ATH_ANT_DIV_SCAN
:
1372 if ((curtsf
- antdiv
->antdiv_laststatetsf
) <
1373 ATH_ANT_DIV_MIN_SCAN_US
)
1377 if (curcfg
== antdiv
->antdiv_num_antcfg
)
1380 if (curcfg
== antdiv
->antdiv_bestcfg
) {
1381 ath_find_max_val(antdiv
->antdiv_lastbrssi
,
1382 antdiv
->antdiv_num_antcfg
, &bestcfg
);
1383 if (!ath9k_hw_select_antconfig(ah
, bestcfg
)) {
1384 antdiv
->antdiv_bestcfg
= bestcfg
;
1385 antdiv
->antdiv_curcfg
= bestcfg
;
1386 antdiv
->antdiv_laststatetsf
= curtsf
;
1387 antdiv
->antdiv_state
= ATH_ANT_DIV_IDLE
;
1390 if (!ath9k_hw_select_antconfig(ah
, curcfg
)) {
1391 antdiv
->antdiv_curcfg
= curcfg
;
1392 antdiv
->antdiv_laststatetsf
= curtsf
;
1393 antdiv
->antdiv_state
= ATH_ANT_DIV_SCAN
;
1401 /***********************/
1402 /* Descriptor Handling */
1403 /***********************/
1406 * Set up DMA descriptors
1408 * This function will allocate both the DMA descriptor structure, and the
1409 * buffers it contains. These are used to contain the descriptors used
1413 int ath_descdma_setup(struct ath_softc
*sc
,
1414 struct ath_descdma
*dd
,
1415 struct list_head
*head
,
1420 #define DS2PHYS(_dd, _ds) \
1421 ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
1422 #define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
1423 #define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
1425 struct ath_desc
*ds
;
1427 int i
, bsize
, error
;
1429 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: %s DMA: %u buffers %u desc/buf\n",
1430 __func__
, name
, nbuf
, ndesc
);
1432 /* ath_desc must be a multiple of DWORDs */
1433 if ((sizeof(struct ath_desc
) % 4) != 0) {
1434 DPRINTF(sc
, ATH_DBG_FATAL
, "%s: ath_desc not DWORD aligned\n",
1436 ASSERT((sizeof(struct ath_desc
) % 4) == 0);
1442 dd
->dd_desc_len
= sizeof(struct ath_desc
) * nbuf
* ndesc
;
1445 * Need additional DMA memory because we can't use
1446 * descriptors that cross the 4K page boundary. Assume
1447 * one skipped descriptor per 4K page.
1449 if (!(sc
->sc_ah
->ah_caps
.hw_caps
& ATH9K_HW_CAP_4KB_SPLITTRANS
)) {
1451 ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd
->dd_desc_len
);
1454 while (ndesc_skipped
) {
1455 dma_len
= ndesc_skipped
* sizeof(struct ath_desc
);
1456 dd
->dd_desc_len
+= dma_len
;
1458 ndesc_skipped
= ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len
);
1462 /* allocate descriptors */
1463 dd
->dd_desc
= pci_alloc_consistent(sc
->pdev
,
1465 &dd
->dd_desc_paddr
);
1466 if (dd
->dd_desc
== NULL
) {
1471 DPRINTF(sc
, ATH_DBG_CONFIG
, "%s: %s DMA map: %p (%u) -> %llx (%u)\n",
1472 __func__
, dd
->dd_name
, ds
, (u32
) dd
->dd_desc_len
,
1473 ito64(dd
->dd_desc_paddr
), /*XXX*/(u32
) dd
->dd_desc_len
);
1475 /* allocate buffers */
1476 bsize
= sizeof(struct ath_buf
) * nbuf
;
1477 bf
= kmalloc(bsize
, GFP_KERNEL
);
1482 memset(bf
, 0, bsize
);
1485 INIT_LIST_HEAD(head
);
1486 for (i
= 0; i
< nbuf
; i
++, bf
++, ds
+= ndesc
) {
1488 bf
->bf_daddr
= DS2PHYS(dd
, ds
);
1490 if (!(sc
->sc_ah
->ah_caps
.hw_caps
&
1491 ATH9K_HW_CAP_4KB_SPLITTRANS
)) {
1493 * Skip descriptor addresses which can cause 4KB
1494 * boundary crossing (addr + length) with a 32 dword
1497 while (ATH_DESC_4KB_BOUND_CHECK(bf
->bf_daddr
)) {
1498 ASSERT((caddr_t
) bf
->bf_desc
<
1499 ((caddr_t
) dd
->dd_desc
+
1504 bf
->bf_daddr
= DS2PHYS(dd
, ds
);
1507 list_add_tail(&bf
->list
, head
);
1511 pci_free_consistent(sc
->pdev
,
1512 dd
->dd_desc_len
, dd
->dd_desc
, dd
->dd_desc_paddr
);
1514 memset(dd
, 0, sizeof(*dd
));
1516 #undef ATH_DESC_4KB_BOUND_CHECK
1517 #undef ATH_DESC_4KB_BOUND_NUM_SKIPPED
1522 * Cleanup DMA descriptors
1524 * This function will free the DMA block that was allocated for the descriptor
1525 * pool. Since this was allocated as one "chunk", it is freed in the same
1529 void ath_descdma_cleanup(struct ath_softc
*sc
,
1530 struct ath_descdma
*dd
,
1531 struct list_head
*head
)
1533 /* Free memory associated with descriptors */
1534 pci_free_consistent(sc
->pdev
,
1535 dd
->dd_desc_len
, dd
->dd_desc
, dd
->dd_desc_paddr
);
1537 INIT_LIST_HEAD(head
);
1538 kfree(dd
->dd_bufptr
);
1539 memset(dd
, 0, sizeof(*dd
));
1546 int ath_get_hal_qnum(u16 queue
, struct ath_softc
*sc
)
1552 qnum
= sc
->sc_haltype2q
[ATH9K_WME_AC_VO
];
1555 qnum
= sc
->sc_haltype2q
[ATH9K_WME_AC_VI
];
1558 qnum
= sc
->sc_haltype2q
[ATH9K_WME_AC_BE
];
1561 qnum
= sc
->sc_haltype2q
[ATH9K_WME_AC_BK
];
1564 qnum
= sc
->sc_haltype2q
[ATH9K_WME_AC_BE
];
1571 int ath_get_mac80211_qnum(u32 queue
, struct ath_softc
*sc
)
1576 case ATH9K_WME_AC_VO
:
1579 case ATH9K_WME_AC_VI
:
1582 case ATH9K_WME_AC_BE
:
1585 case ATH9K_WME_AC_BK
:
1598 * Expand time stamp to TSF
1600 * Extend 15-bit time stamp from rx descriptor to
1601 * a full 64-bit TSF using the current h/w TSF.
1604 u64
ath_extend_tsf(struct ath_softc
*sc
, u32 rstamp
)
1608 tsf
= ath9k_hw_gettsf64(sc
->sc_ah
);
1609 if ((tsf
& 0x7fff) < rstamp
)
1611 return (tsf
& ~0x7fff) | rstamp
;
1615 * Set Default Antenna
1617 * Call into the HAL to set the default antenna to use. Not really valid for
1621 void ath_setdefantenna(void *context
, u32 antenna
)
1623 struct ath_softc
*sc
= (struct ath_softc
*)context
;
1624 struct ath_hal
*ah
= sc
->sc_ah
;
1626 /* XXX block beacon interrupts */
1627 ath9k_hw_setantenna(ah
, antenna
);
1628 sc
->sc_defant
= antenna
;
1629 sc
->sc_rxotherant
= 0;
1635 * This will wake up the chip if required, and set the slot time for the
1636 * frame (maximum transmit time). Slot time is assumed to be already set
1637 * in the ATH object member sc_slottime
1640 void ath_setslottime(struct ath_softc
*sc
)
1642 ath9k_hw_setslottime(sc
->sc_ah
, sc
->sc_slottime
);
1643 sc
->sc_updateslot
= OK
;