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.
17 /* Implementation of the main "ATH" layer. */
22 static int ath_outdoor; /* enable outdoor use */
24 static u32 ath_chainmask_sel_up_rssi_thres =
25 ATH_CHAINMASK_SEL_UP_RSSI_THRES;
26 static u32 ath_chainmask_sel_down_rssi_thres =
27 ATH_CHAINMASK_SEL_DOWN_RSSI_THRES;
28 static u32 ath_chainmask_sel_period =
29 ATH_CHAINMASK_SEL_TIMEOUT;
31 /* return bus cachesize in 4B word units */
33 static void bus_read_cachesize(struct ath_softc *sc, int *csz)
37 pci_read_config_byte(sc->pdev, PCI_CACHE_LINE_SIZE, (u8 *)&u8tmp);
41 * This check was put in to avoid "unplesant" consequences if
42 * the bootrom has not fully initialized all PCI devices.
43 * Sometimes the cache line size register is not set
47 *csz = DEFAULT_CACHELINE >> 2; /* Use the default size */
51 * Set current operating mode
53 * This function initializes and fills the rate table in the ATH object based
54 * on the operating mode.
56 static void ath_setcurmode(struct ath_softc *sc, enum wireless_mode mode)
58 const struct ath9k_rate_table *rt;
61 memset(sc->sc_rixmap, 0xff, sizeof(sc->sc_rixmap));
62 rt = ath9k_hw_getratetable(sc->sc_ah, mode);
65 for (i = 0; i < rt->rateCount; i++)
66 sc->sc_rixmap[rt->info[i].rateCode] = (u8) i;
68 memzero(sc->sc_hwmap, sizeof(sc->sc_hwmap));
69 for (i = 0; i < 256; i++) {
70 u8 ix = rt->rateCodeToIndex[i];
75 sc->sc_hwmap[i].ieeerate =
76 rt->info[ix].dot11Rate & IEEE80211_RATE_VAL;
77 sc->sc_hwmap[i].rateKbps = rt->info[ix].rateKbps;
79 if (rt->info[ix].shortPreamble ||
80 rt->info[ix].phy == PHY_OFDM) {
81 /* XXX: Handle this */
84 /* NB: this uses the last entry if the rate isn't found */
85 /* XXX beware of overlow */
88 sc->sc_curmode = mode;
90 * All protection frames are transmited at 2Mb/s for
91 * 11g, otherwise at 1Mb/s.
92 * XXX select protection rate index from rate table.
94 sc->sc_protrix = (mode == ATH9K_MODE_11G ? 1 : 0);
98 * Set up rate table (legacy rates)
100 static void ath_setup_rates(struct ath_softc *sc, enum ieee80211_band band)
102 struct ath_hal *ah = sc->sc_ah;
103 const struct ath9k_rate_table *rt = NULL;
104 struct ieee80211_supported_band *sband;
105 struct ieee80211_rate *rate;
109 case IEEE80211_BAND_2GHZ:
110 rt = ath9k_hw_getratetable(ah, ATH9K_MODE_11G);
112 case IEEE80211_BAND_5GHZ:
113 rt = ath9k_hw_getratetable(ah, ATH9K_MODE_11A);
122 sband = &sc->sbands[band];
123 rate = sc->rates[band];
125 if (rt->rateCount > ATH_RATE_MAX)
126 maxrates = ATH_RATE_MAX;
128 maxrates = rt->rateCount;
130 for (i = 0; i < maxrates; i++) {
131 rate[i].bitrate = rt->info[i].rateKbps / 100;
132 rate[i].hw_value = rt->info[i].rateCode;
134 DPRINTF(sc, ATH_DBG_CONFIG,
135 "%s: Rate: %2dMbps, ratecode: %2d\n",
137 rate[i].bitrate / 10,
143 * Set up channel list
145 static int ath_setup_channels(struct ath_softc *sc)
147 struct ath_hal *ah = sc->sc_ah;
148 int nchan, i, a = 0, b = 0;
149 u8 regclassids[ATH_REGCLASSIDS_MAX];
151 struct ieee80211_supported_band *band_2ghz;
152 struct ieee80211_supported_band *band_5ghz;
153 struct ieee80211_channel *chan_2ghz;
154 struct ieee80211_channel *chan_5ghz;
155 struct ath9k_channel *c;
157 /* Fill in ah->ah_channels */
158 if (!ath9k_regd_init_channels(ah,
167 u32 rd = ah->ah_currentRD;
169 DPRINTF(sc, ATH_DBG_FATAL,
170 "%s: unable to collect channel list; "
171 "regdomain likely %u country code %u\n",
172 __func__, rd, CTRY_DEFAULT);
176 band_2ghz = &sc->sbands[IEEE80211_BAND_2GHZ];
177 band_5ghz = &sc->sbands[IEEE80211_BAND_5GHZ];
178 chan_2ghz = sc->channels[IEEE80211_BAND_2GHZ];
179 chan_5ghz = sc->channels[IEEE80211_BAND_5GHZ];
181 for (i = 0; i < nchan; i++) {
182 c = &ah->ah_channels[i];
183 if (IS_CHAN_2GHZ(c)) {
184 chan_2ghz[a].band = IEEE80211_BAND_2GHZ;
185 chan_2ghz[a].center_freq = c->channel;
186 chan_2ghz[a].max_power = c->maxTxPower;
188 if (c->privFlags & CHANNEL_DISALLOW_ADHOC)
189 chan_2ghz[a].flags |=
190 IEEE80211_CHAN_NO_IBSS;
191 if (c->channelFlags & CHANNEL_PASSIVE)
192 chan_2ghz[a].flags |=
193 IEEE80211_CHAN_PASSIVE_SCAN;
195 band_2ghz->n_channels = ++a;
197 DPRINTF(sc, ATH_DBG_CONFIG,
198 "%s: 2MHz channel: %d, "
199 "channelFlags: 0x%x\n",
203 } else if (IS_CHAN_5GHZ(c)) {
204 chan_5ghz[b].band = IEEE80211_BAND_5GHZ;
205 chan_5ghz[b].center_freq = c->channel;
206 chan_5ghz[b].max_power = c->maxTxPower;
208 if (c->privFlags & CHANNEL_DISALLOW_ADHOC)
209 chan_5ghz[b].flags |=
210 IEEE80211_CHAN_NO_IBSS;
211 if (c->channelFlags & CHANNEL_PASSIVE)
212 chan_5ghz[b].flags |=
213 IEEE80211_CHAN_PASSIVE_SCAN;
215 band_5ghz->n_channels = ++b;
217 DPRINTF(sc, ATH_DBG_CONFIG,
218 "%s: 5MHz channel: %d, "
219 "channelFlags: 0x%x\n",
230 * Determine mode from channel flags
232 * This routine will provide the enumerated WIRELESSS_MODE value based
233 * on the settings of the channel flags. If no valid set of flags
234 * exist, the lowest mode (11b) is selected.
237 static enum wireless_mode ath_chan2mode(struct ath9k_channel *chan)
239 if (chan->chanmode == CHANNEL_A)
240 return ATH9K_MODE_11A;
241 else if (chan->chanmode == CHANNEL_G)
242 return ATH9K_MODE_11G;
243 else if (chan->chanmode == CHANNEL_B)
244 return ATH9K_MODE_11B;
245 else if (chan->chanmode == CHANNEL_A_HT20)
246 return ATH9K_MODE_11NA_HT20;
247 else if (chan->chanmode == CHANNEL_G_HT20)
248 return ATH9K_MODE_11NG_HT20;
249 else if (chan->chanmode == CHANNEL_A_HT40PLUS)
250 return ATH9K_MODE_11NA_HT40PLUS;
251 else if (chan->chanmode == CHANNEL_A_HT40MINUS)
252 return ATH9K_MODE_11NA_HT40MINUS;
253 else if (chan->chanmode == CHANNEL_G_HT40PLUS)
254 return ATH9K_MODE_11NG_HT40PLUS;
255 else if (chan->chanmode == CHANNEL_G_HT40MINUS)
256 return ATH9K_MODE_11NG_HT40MINUS;
258 WARN_ON(1); /* should not get here */
260 return ATH9K_MODE_11B;
264 * Stop the device, grabbing the top-level lock to protect
265 * against concurrent entry through ath_init (which can happen
266 * if another thread does a system call and the thread doing the
267 * stop is preempted).
270 static int ath_stop(struct ath_softc *sc)
272 struct ath_hal *ah = sc->sc_ah;
274 DPRINTF(sc, ATH_DBG_CONFIG, "%s: invalid %ld\n",
275 __func__, sc->sc_flags & SC_OP_INVALID);
278 * Shutdown the hardware and driver:
279 * stop output from above
282 * clear transmit machinery
283 * clear receive machinery
285 * reclaim beacon resources
287 * Note that some of this work is not possible if the
288 * hardware is gone (invalid).
291 if (!(sc->sc_flags & SC_OP_INVALID))
292 ath9k_hw_set_interrupts(ah, 0);
293 ath_draintxq(sc, false);
294 if (!(sc->sc_flags & SC_OP_INVALID)) {
296 ath9k_hw_phy_disable(ah);
298 sc->sc_rxlink = NULL;
304 * Set the current channel
306 * Set/change channels. If the channel is really being changed, it's done
307 * by reseting the chip. To accomplish this we must first cleanup any pending
308 * DMA, then restart stuff after a la ath_init.
310 int ath_set_channel(struct ath_softc *sc, struct ath9k_channel *hchan)
312 struct ath_hal *ah = sc->sc_ah;
313 bool fastcc = true, stopped;
315 if (sc->sc_flags & SC_OP_INVALID) /* the device is invalid or removed */
318 DPRINTF(sc, ATH_DBG_CONFIG,
319 "%s: %u (%u MHz) -> %u (%u MHz), cflags:%x\n",
321 ath9k_hw_mhz2ieee(ah, sc->sc_ah->ah_curchan->channel,
322 sc->sc_ah->ah_curchan->channelFlags),
323 sc->sc_ah->ah_curchan->channel,
324 ath9k_hw_mhz2ieee(ah, hchan->channel, hchan->channelFlags),
325 hchan->channel, hchan->channelFlags);
327 if (hchan->channel != sc->sc_ah->ah_curchan->channel ||
328 hchan->channelFlags != sc->sc_ah->ah_curchan->channelFlags ||
329 (sc->sc_flags & SC_OP_CHAINMASK_UPDATE) ||
330 (sc->sc_flags & SC_OP_FULL_RESET)) {
333 * This is only performed if the channel settings have
336 * To switch channels clear any pending DMA operations;
337 * wait long enough for the RX fifo to drain, reset the
338 * hardware at the new frequency, and then re-enable
339 * the relevant bits of the h/w.
341 ath9k_hw_set_interrupts(ah, 0); /* disable interrupts */
342 ath_draintxq(sc, false); /* clear pending tx frames */
343 stopped = ath_stoprecv(sc); /* turn off frame recv */
345 /* XXX: do not flush receive queue here. We don't want
346 * to flush data frames already in queue because of
347 * changing channel. */
349 if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET))
352 spin_lock_bh(&sc->sc_resetlock);
353 if (!ath9k_hw_reset(ah, hchan,
354 sc->sc_ht_info.tx_chan_width,
357 sc->sc_ht_extprotspacing,
359 DPRINTF(sc, ATH_DBG_FATAL,
360 "%s: unable to reset channel %u (%uMhz) "
361 "flags 0x%x hal status %u\n", __func__,
362 ath9k_hw_mhz2ieee(ah, hchan->channel,
363 hchan->channelFlags),
364 hchan->channel, hchan->channelFlags, status);
365 spin_unlock_bh(&sc->sc_resetlock);
368 spin_unlock_bh(&sc->sc_resetlock);
370 sc->sc_flags &= ~SC_OP_CHAINMASK_UPDATE;
371 sc->sc_flags &= ~SC_OP_FULL_RESET;
373 /* Re-enable rx framework */
374 if (ath_startrecv(sc) != 0) {
375 DPRINTF(sc, ATH_DBG_FATAL,
376 "%s: unable to restart recv logic\n", __func__);
380 * Change channels and update the h/w rate map
381 * if we're switching; e.g. 11a to 11b/g.
383 ath_setcurmode(sc, ath_chan2mode(hchan));
385 ath_update_txpow(sc); /* update tx power state */
387 * Re-enable interrupts.
389 ath9k_hw_set_interrupts(ah, sc->sc_imask);
394 /**********************/
395 /* Chainmask Handling */
396 /**********************/
398 static void ath_chainmask_sel_timertimeout(unsigned long data)
400 struct ath_chainmask_sel *cm = (struct ath_chainmask_sel *)data;
401 cm->switch_allowed = 1;
404 /* Start chainmask select timer */
405 static void ath_chainmask_sel_timerstart(struct ath_chainmask_sel *cm)
407 cm->switch_allowed = 0;
408 mod_timer(&cm->timer, ath_chainmask_sel_period);
411 /* Stop chainmask select timer */
412 static void ath_chainmask_sel_timerstop(struct ath_chainmask_sel *cm)
414 cm->switch_allowed = 0;
415 del_timer_sync(&cm->timer);
418 static void ath_chainmask_sel_init(struct ath_softc *sc, struct ath_node *an)
420 struct ath_chainmask_sel *cm = &an->an_chainmask_sel;
422 memzero(cm, sizeof(struct ath_chainmask_sel));
424 cm->cur_tx_mask = sc->sc_tx_chainmask;
425 cm->cur_rx_mask = sc->sc_rx_chainmask;
426 cm->tx_avgrssi = ATH_RSSI_DUMMY_MARKER;
427 setup_timer(&cm->timer,
428 ath_chainmask_sel_timertimeout, (unsigned long) cm);
431 int ath_chainmask_sel_logic(struct ath_softc *sc, struct ath_node *an)
433 struct ath_chainmask_sel *cm = &an->an_chainmask_sel;
436 * Disable auto-swtiching in one of the following if conditions.
437 * sc_chainmask_auto_sel is used for internal global auto-switching
438 * enabled/disabled setting
440 if (sc->sc_ah->ah_caps.tx_chainmask != ATH_CHAINMASK_SEL_3X3) {
441 cm->cur_tx_mask = sc->sc_tx_chainmask;
442 return cm->cur_tx_mask;
445 if (cm->tx_avgrssi == ATH_RSSI_DUMMY_MARKER)
446 return cm->cur_tx_mask;
448 if (cm->switch_allowed) {
449 /* Switch down from tx 3 to tx 2. */
450 if (cm->cur_tx_mask == ATH_CHAINMASK_SEL_3X3 &&
451 ATH_RSSI_OUT(cm->tx_avgrssi) >=
452 ath_chainmask_sel_down_rssi_thres) {
453 cm->cur_tx_mask = sc->sc_tx_chainmask;
455 /* Don't let another switch happen until
456 * this timer expires */
457 ath_chainmask_sel_timerstart(cm);
459 /* Switch up from tx 2 to 3. */
460 else if (cm->cur_tx_mask == sc->sc_tx_chainmask &&
461 ATH_RSSI_OUT(cm->tx_avgrssi) <=
462 ath_chainmask_sel_up_rssi_thres) {
463 cm->cur_tx_mask = ATH_CHAINMASK_SEL_3X3;
465 /* Don't let another switch happen
466 * until this timer expires */
467 ath_chainmask_sel_timerstart(cm);
471 return cm->cur_tx_mask;
475 * Update tx/rx chainmask. For legacy association,
476 * hard code chainmask to 1x1, for 11n association, use
477 * the chainmask configuration.
480 void ath_update_chainmask(struct ath_softc *sc, int is_ht)
482 sc->sc_flags |= SC_OP_CHAINMASK_UPDATE;
484 sc->sc_tx_chainmask = sc->sc_ah->ah_caps.tx_chainmask;
485 sc->sc_rx_chainmask = sc->sc_ah->ah_caps.rx_chainmask;
487 sc->sc_tx_chainmask = 1;
488 sc->sc_rx_chainmask = 1;
491 DPRINTF(sc, ATH_DBG_CONFIG, "%s: tx chmask: %d, rx chmask: %d\n",
492 __func__, sc->sc_tx_chainmask, sc->sc_rx_chainmask);
499 int ath_vap_attach(struct ath_softc *sc,
501 struct ieee80211_vif *if_data,
502 enum ath9k_opmode opmode)
506 if (if_id >= ATH_BCBUF || sc->sc_vaps[if_id] != NULL) {
507 DPRINTF(sc, ATH_DBG_FATAL,
508 "%s: Invalid interface id = %u\n", __func__, if_id);
515 case ATH9K_M_MONITOR:
518 /* XXX not right, beacon buffer is allocated on RUN trans */
519 if (list_empty(&sc->sc_bbuf))
527 avp = kmalloc(sizeof(struct ath_vap), GFP_KERNEL);
531 memzero(avp, sizeof(struct ath_vap));
532 avp->av_if_data = if_data;
533 /* Set the VAP opmode */
534 avp->av_opmode = opmode;
536 INIT_LIST_HEAD(&avp->av_mcastq.axq_q);
537 INIT_LIST_HEAD(&avp->av_mcastq.axq_acq);
538 spin_lock_init(&avp->av_mcastq.axq_lock);
540 ath9k_hw_set_tsfadjust(sc->sc_ah, 1);
542 sc->sc_vaps[if_id] = avp;
544 /* Set the device opmode */
545 sc->sc_ah->ah_opmode = opmode;
547 /* default VAP configuration */
548 avp->av_config.av_fixed_rateset = IEEE80211_FIXED_RATE_NONE;
549 avp->av_config.av_fixed_retryset = 0x03030303;
554 int ath_vap_detach(struct ath_softc *sc, int if_id)
556 struct ath_hal *ah = sc->sc_ah;
559 avp = sc->sc_vaps[if_id];
561 DPRINTF(sc, ATH_DBG_FATAL, "%s: invalid interface id %u\n",
567 * Quiesce the hardware while we remove the vap. In
568 * particular we need to reclaim all references to the
569 * vap state by any frames pending on the tx queues.
571 * XXX can we do this w/o affecting other vap's?
573 ath9k_hw_set_interrupts(ah, 0); /* disable interrupts */
574 ath_draintxq(sc, false); /* stop xmit side */
575 ath_stoprecv(sc); /* stop recv side */
576 ath_flushrecv(sc); /* flush recv queue */
578 /* Reclaim any pending mcast bufs on the vap. */
579 ath_tx_draintxq(sc, &avp->av_mcastq, false);
582 sc->sc_vaps[if_id] = NULL;
588 int ath_vap_config(struct ath_softc *sc,
589 int if_id, struct ath_vap_config *if_config)
593 if (if_id >= ATH_BCBUF) {
594 DPRINTF(sc, ATH_DBG_FATAL,
595 "%s: Invalid interface id = %u\n", __func__, if_id);
599 avp = sc->sc_vaps[if_id];
603 memcpy(&avp->av_config, if_config, sizeof(avp->av_config));
612 int ath_open(struct ath_softc *sc, struct ath9k_channel *initial_chan)
614 struct ath_hal *ah = sc->sc_ah;
618 DPRINTF(sc, ATH_DBG_CONFIG, "%s: mode %d\n",
619 __func__, sc->sc_ah->ah_opmode);
622 * Stop anything previously setup. This is safe
623 * whether this is the first time through or not.
627 /* Initialize chanmask selection */
628 sc->sc_tx_chainmask = ah->ah_caps.tx_chainmask;
629 sc->sc_rx_chainmask = ah->ah_caps.rx_chainmask;
631 /* Reset SERDES registers */
632 ath9k_hw_configpcipowersave(ah, 0);
635 * The basic interface to setting the hardware in a good
636 * state is ``reset''. On return the hardware is known to
637 * be powered up and with interrupts disabled. This must
638 * be followed by initialization of the appropriate bits
639 * and then setup of the interrupt mask.
642 spin_lock_bh(&sc->sc_resetlock);
643 if (!ath9k_hw_reset(ah, initial_chan,
644 sc->sc_ht_info.tx_chan_width,
645 sc->sc_tx_chainmask, sc->sc_rx_chainmask,
646 sc->sc_ht_extprotspacing, false, &status)) {
647 DPRINTF(sc, ATH_DBG_FATAL,
648 "%s: unable to reset hardware; hal status %u "
649 "(freq %u flags 0x%x)\n", __func__, status,
650 initial_chan->channel, initial_chan->channelFlags);
652 spin_unlock_bh(&sc->sc_resetlock);
655 spin_unlock_bh(&sc->sc_resetlock);
657 * This is needed only to setup initial state
658 * but it's best done after a reset.
660 ath_update_txpow(sc);
663 * Setup the hardware after reset:
664 * The receive engine is set going.
665 * Frame transmit is handled entirely
666 * in the frame output path; there's nothing to do
667 * here except setup the interrupt mask.
669 if (ath_startrecv(sc) != 0) {
670 DPRINTF(sc, ATH_DBG_FATAL,
671 "%s: unable to start recv logic\n", __func__);
675 /* Setup our intr mask. */
676 sc->sc_imask = ATH9K_INT_RX | ATH9K_INT_TX
677 | ATH9K_INT_RXEOL | ATH9K_INT_RXORN
678 | ATH9K_INT_FATAL | ATH9K_INT_GLOBAL;
680 if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_GTT)
681 sc->sc_imask |= ATH9K_INT_GTT;
683 if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT)
684 sc->sc_imask |= ATH9K_INT_CST;
687 * Enable MIB interrupts when there are hardware phy counters.
688 * Note we only do this (at the moment) for station mode.
690 if (ath9k_hw_phycounters(ah) &&
691 ((sc->sc_ah->ah_opmode == ATH9K_M_STA) ||
692 (sc->sc_ah->ah_opmode == ATH9K_M_IBSS)))
693 sc->sc_imask |= ATH9K_INT_MIB;
695 * Some hardware processes the TIM IE and fires an
696 * interrupt when the TIM bit is set. For hardware
697 * that does, if not overridden by configuration,
698 * enable the TIM interrupt when operating as station.
700 if ((ah->ah_caps.hw_caps & ATH9K_HW_CAP_ENHANCEDPM) &&
701 (sc->sc_ah->ah_opmode == ATH9K_M_STA) &&
702 !sc->sc_config.swBeaconProcess)
703 sc->sc_imask |= ATH9K_INT_TIM;
705 * Don't enable interrupts here as we've not yet built our
706 * vap and node data structures, which will be needed as soon
707 * as we start receiving.
709 ath_setcurmode(sc, ath_chan2mode(initial_chan));
711 /* XXX: we must make sure h/w is ready and clear invalid flag
712 * before turning on interrupt. */
713 sc->sc_flags &= ~SC_OP_INVALID;
718 int ath_reset(struct ath_softc *sc, bool retry_tx)
720 struct ath_hal *ah = sc->sc_ah;
724 ath9k_hw_set_interrupts(ah, 0); /* disable interrupts */
725 ath_draintxq(sc, retry_tx); /* stop xmit */
726 ath_stoprecv(sc); /* stop recv */
727 ath_flushrecv(sc); /* flush recv queue */
730 spin_lock_bh(&sc->sc_resetlock);
731 if (!ath9k_hw_reset(ah, sc->sc_ah->ah_curchan,
732 sc->sc_ht_info.tx_chan_width,
733 sc->sc_tx_chainmask, sc->sc_rx_chainmask,
734 sc->sc_ht_extprotspacing, false, &status)) {
735 DPRINTF(sc, ATH_DBG_FATAL,
736 "%s: unable to reset hardware; hal status %u\n",
740 spin_unlock_bh(&sc->sc_resetlock);
742 if (ath_startrecv(sc) != 0) /* restart recv */
743 DPRINTF(sc, ATH_DBG_FATAL,
744 "%s: unable to start recv logic\n", __func__);
747 * We may be doing a reset in response to a request
748 * that changes the channel so update any state that
749 * might change as a result.
751 ath_setcurmode(sc, ath_chan2mode(sc->sc_ah->ah_curchan));
753 ath_update_txpow(sc);
755 if (sc->sc_flags & SC_OP_BEACONS)
756 ath_beacon_config(sc, ATH_IF_ID_ANY); /* restart beacons */
758 ath9k_hw_set_interrupts(ah, sc->sc_imask);
760 /* Restart the txq */
763 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
764 if (ATH_TXQ_SETUP(sc, i)) {
765 spin_lock_bh(&sc->sc_txq[i].axq_lock);
766 ath_txq_schedule(sc, &sc->sc_txq[i]);
767 spin_unlock_bh(&sc->sc_txq[i].axq_lock);
775 int ath_suspend(struct ath_softc *sc)
777 struct ath_hal *ah = sc->sc_ah;
779 /* No I/O if device has been surprise removed */
780 if (sc->sc_flags & SC_OP_INVALID)
783 /* Shut off the interrupt before setting sc->sc_invalid to '1' */
784 ath9k_hw_set_interrupts(ah, 0);
786 /* XXX: we must make sure h/w will not generate any interrupt
787 * before setting the invalid flag. */
788 sc->sc_flags |= SC_OP_INVALID;
790 /* disable HAL and put h/w to sleep */
791 ath9k_hw_disable(sc->sc_ah);
793 ath9k_hw_configpcipowersave(sc->sc_ah, 1);
798 /* Interrupt handler. Most of the actual processing is deferred.
799 * It's the caller's responsibility to ensure the chip is awake. */
801 irqreturn_t ath_isr(int irq, void *dev)
803 struct ath_softc *sc = dev;
804 struct ath_hal *ah = sc->sc_ah;
805 enum ath9k_int status;
809 if (sc->sc_flags & SC_OP_INVALID) {
811 * The hardware is not ready/present, don't
812 * touch anything. Note this can happen early
813 * on if the IRQ is shared.
817 if (!ath9k_hw_intrpend(ah)) { /* shared irq, not for us */
822 * Figure out the reason(s) for the interrupt. Note
823 * that the hal returns a pseudo-ISR that may include
824 * bits we haven't explicitly enabled so we mask the
825 * value to insure we only process bits we requested.
827 ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
829 status &= sc->sc_imask; /* discard unasked-for bits */
832 * If there are no status bits set, then this interrupt was not
833 * for me (should have been caught above).
839 sc->sc_intrstatus = status;
841 if (status & ATH9K_INT_FATAL) {
842 /* need a chip reset */
844 } else if (status & ATH9K_INT_RXORN) {
845 /* need a chip reset */
848 if (status & ATH9K_INT_SWBA) {
849 /* schedule a tasklet for beacon handling */
850 tasklet_schedule(&sc->bcon_tasklet);
852 if (status & ATH9K_INT_RXEOL) {
854 * NB: the hardware should re-read the link when
855 * RXE bit is written, but it doesn't work
856 * at least on older hardware revs.
861 if (status & ATH9K_INT_TXURN)
862 /* bump tx trigger level */
863 ath9k_hw_updatetxtriglevel(ah, true);
864 /* XXX: optimize this */
865 if (status & ATH9K_INT_RX)
867 if (status & ATH9K_INT_TX)
869 if (status & ATH9K_INT_BMISS)
871 /* carrier sense timeout */
872 if (status & ATH9K_INT_CST)
874 if (status & ATH9K_INT_MIB) {
876 * Disable interrupts until we service the MIB
877 * interrupt; otherwise it will continue to
880 ath9k_hw_set_interrupts(ah, 0);
882 * Let the hal handle the event. We assume
883 * it will clear whatever condition caused
886 ath9k_hw_procmibevent(ah, &sc->sc_halstats);
887 ath9k_hw_set_interrupts(ah, sc->sc_imask);
889 if (status & ATH9K_INT_TIM_TIMER) {
890 if (!(ah->ah_caps.hw_caps &
891 ATH9K_HW_CAP_AUTOSLEEP)) {
892 /* Clear RxAbort bit so that we can
894 ath9k_hw_setrxabort(ah, 0);
902 /* turn off every interrupt except SWBA */
903 ath9k_hw_set_interrupts(ah, (sc->sc_imask & ATH9K_INT_SWBA));
904 tasklet_schedule(&sc->intr_tq);
910 /* Deferred interrupt processing */
912 static void ath9k_tasklet(unsigned long data)
914 struct ath_softc *sc = (struct ath_softc *)data;
915 u32 status = sc->sc_intrstatus;
917 if (status & ATH9K_INT_FATAL) {
918 /* need a chip reset */
919 ath_reset(sc, false);
924 (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN)) {
925 /* XXX: fill me in */
927 if (status & ATH9K_INT_RXORN) {
929 if (status & ATH9K_INT_RXEOL) {
932 spin_lock_bh(&sc->sc_rxflushlock);
933 ath_rx_tasklet(sc, 0);
934 spin_unlock_bh(&sc->sc_rxflushlock);
936 /* XXX: optimize this */
937 if (status & ATH9K_INT_TX)
939 /* XXX: fill me in */
941 if (status & ATH9K_INT_BMISS) {
943 if (status & (ATH9K_INT_TIM | ATH9K_INT_DTIMSYNC)) {
944 if (status & ATH9K_INT_TIM) {
946 if (status & ATH9K_INT_DTIMSYNC) {
952 /* re-enable hardware interrupt */
953 ath9k_hw_set_interrupts(sc->sc_ah, sc->sc_imask);
956 int ath_init(u16 devid, struct ath_softc *sc)
958 struct ath_hal *ah = NULL;
963 /* XXX: hardware will not be ready until ath_open() being called */
964 sc->sc_flags |= SC_OP_INVALID;
966 sc->sc_debug = DBG_DEFAULT;
967 DPRINTF(sc, ATH_DBG_CONFIG, "%s: devid 0x%x\n", __func__, devid);
969 /* Initialize tasklet */
970 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
971 tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
975 * Cache line size is used to size and align various
976 * structures used to communicate with the hardware.
978 bus_read_cachesize(sc, &csz);
979 /* XXX assert csz is non-zero */
980 sc->sc_cachelsz = csz << 2; /* convert to bytes */
982 spin_lock_init(&sc->sc_resetlock);
984 ah = ath9k_hw_attach(devid, sc, sc->mem, &status);
986 DPRINTF(sc, ATH_DBG_FATAL,
987 "%s: unable to attach hardware; HAL status %u\n",
994 /* Get the hardware key cache size. */
995 sc->sc_keymax = ah->ah_caps.keycache_size;
996 if (sc->sc_keymax > ATH_KEYMAX) {
997 DPRINTF(sc, ATH_DBG_KEYCACHE,
998 "%s: Warning, using only %u entries in %u key cache\n",
999 __func__, ATH_KEYMAX, sc->sc_keymax);
1000 sc->sc_keymax = ATH_KEYMAX;
1004 * Reset the key cache since some parts do not
1005 * reset the contents on initial power up.
1007 for (i = 0; i < sc->sc_keymax; i++)
1008 ath9k_hw_keyreset(ah, (u16) i);
1010 * Mark key cache slots associated with global keys
1011 * as in use. If we knew TKIP was not to be used we
1012 * could leave the +32, +64, and +32+64 slots free.
1013 * XXX only for splitmic.
1015 for (i = 0; i < IEEE80211_WEP_NKID; i++) {
1016 set_bit(i, sc->sc_keymap);
1017 set_bit(i + 32, sc->sc_keymap);
1018 set_bit(i + 64, sc->sc_keymap);
1019 set_bit(i + 32 + 64, sc->sc_keymap);
1022 * Collect the channel list using the default country
1023 * code and including outdoor channels. The 802.11 layer
1024 * is resposible for filtering this list based on settings
1025 * like the phy mode.
1027 error = ath_setup_channels(sc);
1031 /* default to STA mode */
1032 sc->sc_ah->ah_opmode = ATH9K_M_MONITOR;
1034 /* Setup rate tables */
1036 ath_setup_rates(sc, IEEE80211_BAND_2GHZ);
1037 ath_setup_rates(sc, IEEE80211_BAND_5GHZ);
1039 /* NB: setup here so ath_rate_update is happy */
1040 ath_setcurmode(sc, ATH9K_MODE_11A);
1043 * Allocate hardware transmit queues: one queue for
1044 * beacon frames and one data queue for each QoS
1045 * priority. Note that the hal handles reseting
1046 * these queues at the needed time.
1048 sc->sc_bhalq = ath_beaconq_setup(ah);
1049 if (sc->sc_bhalq == -1) {
1050 DPRINTF(sc, ATH_DBG_FATAL,
1051 "%s: unable to setup a beacon xmit queue\n", __func__);
1055 sc->sc_cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
1056 if (sc->sc_cabq == NULL) {
1057 DPRINTF(sc, ATH_DBG_FATAL,
1058 "%s: unable to setup CAB xmit queue\n", __func__);
1063 sc->sc_config.cabqReadytime = ATH_CABQ_READY_TIME;
1064 ath_cabq_update(sc);
1066 for (i = 0; i < ARRAY_SIZE(sc->sc_haltype2q); i++)
1067 sc->sc_haltype2q[i] = -1;
1069 /* Setup data queues */
1070 /* NB: ensure BK queue is the lowest priority h/w queue */
1071 if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) {
1072 DPRINTF(sc, ATH_DBG_FATAL,
1073 "%s: unable to setup xmit queue for BK traffic\n",
1079 if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) {
1080 DPRINTF(sc, ATH_DBG_FATAL,
1081 "%s: unable to setup xmit queue for BE traffic\n",
1086 if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) {
1087 DPRINTF(sc, ATH_DBG_FATAL,
1088 "%s: unable to setup xmit queue for VI traffic\n",
1093 if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) {
1094 DPRINTF(sc, ATH_DBG_FATAL,
1095 "%s: unable to setup xmit queue for VO traffic\n",
1101 sc->sc_rc = ath_rate_attach(ah);
1102 if (sc->sc_rc == NULL) {
1107 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1108 ATH9K_CIPHER_TKIP, NULL)) {
1110 * Whether we should enable h/w TKIP MIC.
1111 * XXX: if we don't support WME TKIP MIC, then we wouldn't
1112 * report WMM capable, so it's always safe to turn on
1113 * TKIP MIC in this case.
1115 ath9k_hw_setcapability(sc->sc_ah, ATH9K_CAP_TKIP_MIC,
1120 * Check whether the separate key cache entries
1121 * are required to handle both tx+rx MIC keys.
1122 * With split mic keys the number of stations is limited
1123 * to 27 otherwise 59.
1125 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1126 ATH9K_CIPHER_TKIP, NULL)
1127 && ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1128 ATH9K_CIPHER_MIC, NULL)
1129 && ath9k_hw_getcapability(ah, ATH9K_CAP_TKIP_SPLIT,
1131 sc->sc_splitmic = 1;
1133 /* turn on mcast key search if possible */
1134 if (!ath9k_hw_getcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL))
1135 (void)ath9k_hw_setcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 1,
1138 sc->sc_config.txpowlimit = ATH_TXPOWER_MAX;
1139 sc->sc_config.txpowlimit_override = 0;
1141 /* 11n Capabilities */
1142 if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) {
1143 sc->sc_flags |= SC_OP_TXAGGR;
1144 sc->sc_flags |= SC_OP_RXAGGR;
1147 sc->sc_tx_chainmask = ah->ah_caps.tx_chainmask;
1148 sc->sc_rx_chainmask = ah->ah_caps.rx_chainmask;
1150 ath9k_hw_setcapability(ah, ATH9K_CAP_DIVERSITY, 1, true, NULL);
1151 sc->sc_defant = ath9k_hw_getdefantenna(ah);
1153 ath9k_hw_getmac(ah, sc->sc_myaddr);
1154 if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) {
1155 ath9k_hw_getbssidmask(ah, sc->sc_bssidmask);
1156 ATH_SET_VAP_BSSID_MASK(sc->sc_bssidmask);
1157 ath9k_hw_setbssidmask(ah, sc->sc_bssidmask);
1159 sc->sc_slottime = ATH9K_SLOT_TIME_9; /* default to short slot time */
1161 /* initialize beacon slots */
1162 for (i = 0; i < ARRAY_SIZE(sc->sc_bslot); i++)
1163 sc->sc_bslot[i] = ATH_IF_ID_ANY;
1165 /* save MISC configurations */
1166 sc->sc_config.swBeaconProcess = 1;
1168 #ifdef CONFIG_SLOW_ANT_DIV
1169 /* range is 40 - 255, we use something in the middle */
1170 ath_slow_ant_div_init(&sc->sc_antdiv, sc, 0x127);
1175 /* cleanup tx queues */
1176 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1177 if (ATH_TXQ_SETUP(sc, i))
1178 ath_tx_cleanupq(sc, &sc->sc_txq[i]);
1181 ath9k_hw_detach(ah);
1185 void ath_deinit(struct ath_softc *sc)
1187 struct ath_hal *ah = sc->sc_ah;
1190 DPRINTF(sc, ATH_DBG_CONFIG, "%s\n", __func__);
1193 if (!(sc->sc_flags & SC_OP_INVALID))
1194 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
1195 ath_rate_detach(sc->sc_rc);
1196 /* cleanup tx queues */
1197 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1198 if (ATH_TXQ_SETUP(sc, i))
1199 ath_tx_cleanupq(sc, &sc->sc_txq[i]);
1200 ath9k_hw_detach(ah);
1203 /*******************/
1204 /* Node Management */
1205 /*******************/
1207 struct ath_node *ath_node_attach(struct ath_softc *sc, u8 *addr, int if_id)
1209 struct ath_vap *avp;
1210 struct ath_node *an;
1211 DECLARE_MAC_BUF(mac);
1213 avp = sc->sc_vaps[if_id];
1214 ASSERT(avp != NULL);
1216 /* mac80211 sta_notify callback is from an IRQ context, so no sleep */
1217 an = kmalloc(sizeof(struct ath_node), GFP_ATOMIC);
1220 memzero(an, sizeof(*an));
1223 memcpy(an->an_addr, addr, ETH_ALEN);
1224 atomic_set(&an->an_refcnt, 1);
1226 /* set up per-node tx/rx state */
1227 ath_tx_node_init(sc, an);
1228 ath_rx_node_init(sc, an);
1230 ath_chainmask_sel_init(sc, an);
1231 ath_chainmask_sel_timerstart(&an->an_chainmask_sel);
1232 list_add(&an->list, &sc->node_list);
1237 void ath_node_detach(struct ath_softc *sc, struct ath_node *an, bool bh_flag)
1239 unsigned long flags;
1241 DECLARE_MAC_BUF(mac);
1243 ath_chainmask_sel_timerstop(&an->an_chainmask_sel);
1244 an->an_flags |= ATH_NODE_CLEAN;
1245 ath_tx_node_cleanup(sc, an, bh_flag);
1246 ath_rx_node_cleanup(sc, an);
1248 ath_tx_node_free(sc, an);
1249 ath_rx_node_free(sc, an);
1251 spin_lock_irqsave(&sc->node_lock, flags);
1253 list_del(&an->list);
1255 spin_unlock_irqrestore(&sc->node_lock, flags);
1260 /* Finds a node and increases the refcnt if found */
1262 struct ath_node *ath_node_get(struct ath_softc *sc, u8 *addr)
1264 struct ath_node *an = NULL, *an_found = NULL;
1266 if (list_empty(&sc->node_list)) /* FIXME */
1268 list_for_each_entry(an, &sc->node_list, list) {
1269 if (!compare_ether_addr(an->an_addr, addr)) {
1270 atomic_inc(&an->an_refcnt);
1279 /* Decrements the refcnt and if it drops to zero, detach the node */
1281 void ath_node_put(struct ath_softc *sc, struct ath_node *an, bool bh_flag)
1283 if (atomic_dec_and_test(&an->an_refcnt))
1284 ath_node_detach(sc, an, bh_flag);
1287 /* Finds a node, doesn't increment refcnt. Caller must hold sc->node_lock */
1288 struct ath_node *ath_node_find(struct ath_softc *sc, u8 *addr)
1290 struct ath_node *an = NULL, *an_found = NULL;
1292 if (list_empty(&sc->node_list))
1295 list_for_each_entry(an, &sc->node_list, list)
1296 if (!compare_ether_addr(an->an_addr, addr)) {
1307 * Setup driver-specific state for a newly associated node. This routine
1308 * really only applies if compression or XR are enabled, there is no code
1309 * covering any other cases.
1312 void ath_newassoc(struct ath_softc *sc,
1313 struct ath_node *an, int isnew, int isuapsd)
1317 /* if station reassociates, tear down the aggregation state. */
1319 for (tidno = 0; tidno < WME_NUM_TID; tidno++) {
1320 if (sc->sc_flags & SC_OP_TXAGGR)
1321 ath_tx_aggr_teardown(sc, an, tidno);
1322 if (sc->sc_flags & SC_OP_RXAGGR)
1323 ath_rx_aggr_teardown(sc, an, tidno);
1333 void ath_key_reset(struct ath_softc *sc, u16 keyix, int freeslot)
1335 ath9k_hw_keyreset(sc->sc_ah, keyix);
1337 clear_bit(keyix, sc->sc_keymap);
1340 int ath_keyset(struct ath_softc *sc,
1342 struct ath9k_keyval *hk,
1343 const u8 mac[ETH_ALEN])
1347 status = ath9k_hw_set_keycache_entry(sc->sc_ah,
1348 keyix, hk, mac, false);
1350 return status != false;
1353 /***********************/
1354 /* TX Power/Regulatory */
1355 /***********************/
1358 * Set Transmit power in HAL
1360 * This routine makes the actual HAL calls to set the new transmit power
1364 void ath_update_txpow(struct ath_softc *sc)
1366 struct ath_hal *ah = sc->sc_ah;
1369 if (sc->sc_curtxpow != sc->sc_config.txpowlimit) {
1370 ath9k_hw_set_txpowerlimit(ah, sc->sc_config.txpowlimit);
1371 /* read back in case value is clamped */
1372 ath9k_hw_getcapability(ah, ATH9K_CAP_TXPOW, 1, &txpow);
1373 sc->sc_curtxpow = txpow;
1377 /* Return the current country and domain information */
1378 void ath_get_currentCountry(struct ath_softc *sc,
1379 struct ath9k_country_entry *ctry)
1381 ath9k_regd_get_current_country(sc->sc_ah, ctry);
1383 /* If HAL not specific yet, since it is band dependent,
1384 * use the one we passed in. */
1385 if (ctry->countryCode == CTRY_DEFAULT) {
1388 } else if (ctry->iso[0] && ctry->iso[1]) {
1389 if (!ctry->iso[2]) {
1398 /**************************/
1399 /* Slow Antenna Diversity */
1400 /**************************/
1402 void ath_slow_ant_div_init(struct ath_antdiv *antdiv,
1403 struct ath_softc *sc,
1408 /* antdivf_rssitrig can range from 40 - 0xff */
1409 trig = (rssitrig > 0xff) ? 0xff : rssitrig;
1410 trig = (rssitrig < 40) ? 40 : rssitrig;
1412 antdiv->antdiv_sc = sc;
1413 antdiv->antdivf_rssitrig = trig;
1416 void ath_slow_ant_div_start(struct ath_antdiv *antdiv,
1420 antdiv->antdiv_num_antcfg =
1421 num_antcfg < ATH_ANT_DIV_MAX_CFG ?
1422 num_antcfg : ATH_ANT_DIV_MAX_CFG;
1423 antdiv->antdiv_state = ATH_ANT_DIV_IDLE;
1424 antdiv->antdiv_curcfg = 0;
1425 antdiv->antdiv_bestcfg = 0;
1426 antdiv->antdiv_laststatetsf = 0;
1428 memcpy(antdiv->antdiv_bssid, bssid, sizeof(antdiv->antdiv_bssid));
1430 antdiv->antdiv_start = 1;
1433 void ath_slow_ant_div_stop(struct ath_antdiv *antdiv)
1435 antdiv->antdiv_start = 0;
1438 static int32_t ath_find_max_val(int32_t *val,
1439 u8 num_val, u8 *max_index)
1441 u32 MaxVal = *val++;
1445 while (++cur_index < num_val) {
1446 if (*val > MaxVal) {
1448 *max_index = cur_index;
1457 void ath_slow_ant_div(struct ath_antdiv *antdiv,
1458 struct ieee80211_hdr *hdr,
1459 struct ath_rx_status *rx_stats)
1461 struct ath_softc *sc = antdiv->antdiv_sc;
1462 struct ath_hal *ah = sc->sc_ah;
1464 u8 bestcfg, curcfg = antdiv->antdiv_curcfg;
1465 __le16 fc = hdr->frame_control;
1467 if (antdiv->antdiv_start && ieee80211_is_beacon(fc)
1468 && !compare_ether_addr(hdr->addr3, antdiv->antdiv_bssid)) {
1469 antdiv->antdiv_lastbrssi[curcfg] = rx_stats->rs_rssi;
1470 antdiv->antdiv_lastbtsf[curcfg] = ath9k_hw_gettsf64(sc->sc_ah);
1471 curtsf = antdiv->antdiv_lastbtsf[curcfg];
1476 switch (antdiv->antdiv_state) {
1477 case ATH_ANT_DIV_IDLE:
1478 if ((antdiv->antdiv_lastbrssi[curcfg] <
1479 antdiv->antdivf_rssitrig)
1480 && ((curtsf - antdiv->antdiv_laststatetsf) >
1481 ATH_ANT_DIV_MIN_IDLE_US)) {
1484 if (curcfg == antdiv->antdiv_num_antcfg)
1487 if (!ath9k_hw_select_antconfig(ah, curcfg)) {
1488 antdiv->antdiv_bestcfg = antdiv->antdiv_curcfg;
1489 antdiv->antdiv_curcfg = curcfg;
1490 antdiv->antdiv_laststatetsf = curtsf;
1491 antdiv->antdiv_state = ATH_ANT_DIV_SCAN;
1496 case ATH_ANT_DIV_SCAN:
1497 if ((curtsf - antdiv->antdiv_laststatetsf) <
1498 ATH_ANT_DIV_MIN_SCAN_US)
1502 if (curcfg == antdiv->antdiv_num_antcfg)
1505 if (curcfg == antdiv->antdiv_bestcfg) {
1506 ath_find_max_val(antdiv->antdiv_lastbrssi,
1507 antdiv->antdiv_num_antcfg, &bestcfg);
1508 if (!ath9k_hw_select_antconfig(ah, bestcfg)) {
1509 antdiv->antdiv_bestcfg = bestcfg;
1510 antdiv->antdiv_curcfg = bestcfg;
1511 antdiv->antdiv_laststatetsf = curtsf;
1512 antdiv->antdiv_state = ATH_ANT_DIV_IDLE;
1515 if (!ath9k_hw_select_antconfig(ah, curcfg)) {
1516 antdiv->antdiv_curcfg = curcfg;
1517 antdiv->antdiv_laststatetsf = curtsf;
1518 antdiv->antdiv_state = ATH_ANT_DIV_SCAN;
1526 /***********************/
1527 /* Descriptor Handling */
1528 /***********************/
1531 * Set up DMA descriptors
1533 * This function will allocate both the DMA descriptor structure, and the
1534 * buffers it contains. These are used to contain the descriptors used
1538 int ath_descdma_setup(struct ath_softc *sc,
1539 struct ath_descdma *dd,
1540 struct list_head *head,
1545 #define DS2PHYS(_dd, _ds) \
1546 ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
1547 #define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
1548 #define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
1550 struct ath_desc *ds;
1552 int i, bsize, error;
1554 DPRINTF(sc, ATH_DBG_CONFIG, "%s: %s DMA: %u buffers %u desc/buf\n",
1555 __func__, name, nbuf, ndesc);
1557 /* ath_desc must be a multiple of DWORDs */
1558 if ((sizeof(struct ath_desc) % 4) != 0) {
1559 DPRINTF(sc, ATH_DBG_FATAL, "%s: ath_desc not DWORD aligned\n",
1561 ASSERT((sizeof(struct ath_desc) % 4) == 0);
1567 dd->dd_desc_len = sizeof(struct ath_desc) * nbuf * ndesc;
1570 * Need additional DMA memory because we can't use
1571 * descriptors that cross the 4K page boundary. Assume
1572 * one skipped descriptor per 4K page.
1574 if (!(sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
1576 ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
1579 while (ndesc_skipped) {
1580 dma_len = ndesc_skipped * sizeof(struct ath_desc);
1581 dd->dd_desc_len += dma_len;
1583 ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
1587 /* allocate descriptors */
1588 dd->dd_desc = pci_alloc_consistent(sc->pdev,
1590 &dd->dd_desc_paddr);
1591 if (dd->dd_desc == NULL) {
1596 DPRINTF(sc, ATH_DBG_CONFIG, "%s: %s DMA map: %p (%u) -> %llx (%u)\n",
1597 __func__, dd->dd_name, ds, (u32) dd->dd_desc_len,
1598 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
1600 /* allocate buffers */
1601 bsize = sizeof(struct ath_buf) * nbuf;
1602 bf = kmalloc(bsize, GFP_KERNEL);
1610 INIT_LIST_HEAD(head);
1611 for (i = 0; i < nbuf; i++, bf++, ds += ndesc) {
1613 bf->bf_daddr = DS2PHYS(dd, ds);
1615 if (!(sc->sc_ah->ah_caps.hw_caps &
1616 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
1618 * Skip descriptor addresses which can cause 4KB
1619 * boundary crossing (addr + length) with a 32 dword
1622 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
1623 ASSERT((caddr_t) bf->bf_desc <
1624 ((caddr_t) dd->dd_desc +
1629 bf->bf_daddr = DS2PHYS(dd, ds);
1632 list_add_tail(&bf->list, head);
1636 pci_free_consistent(sc->pdev,
1637 dd->dd_desc_len, dd->dd_desc, dd->dd_desc_paddr);
1639 memzero(dd, sizeof(*dd));
1641 #undef ATH_DESC_4KB_BOUND_CHECK
1642 #undef ATH_DESC_4KB_BOUND_NUM_SKIPPED
1647 * Cleanup DMA descriptors
1649 * This function will free the DMA block that was allocated for the descriptor
1650 * pool. Since this was allocated as one "chunk", it is freed in the same
1654 void ath_descdma_cleanup(struct ath_softc *sc,
1655 struct ath_descdma *dd,
1656 struct list_head *head)
1658 /* Free memory associated with descriptors */
1659 pci_free_consistent(sc->pdev,
1660 dd->dd_desc_len, dd->dd_desc, dd->dd_desc_paddr);
1662 INIT_LIST_HEAD(head);
1663 kfree(dd->dd_bufptr);
1664 memzero(dd, sizeof(*dd));
1671 int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
1677 qnum = sc->sc_haltype2q[ATH9K_WME_AC_VO];
1680 qnum = sc->sc_haltype2q[ATH9K_WME_AC_VI];
1683 qnum = sc->sc_haltype2q[ATH9K_WME_AC_BE];
1686 qnum = sc->sc_haltype2q[ATH9K_WME_AC_BK];
1689 qnum = sc->sc_haltype2q[ATH9K_WME_AC_BE];
1696 int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
1701 case ATH9K_WME_AC_VO:
1704 case ATH9K_WME_AC_VI:
1707 case ATH9K_WME_AC_BE:
1710 case ATH9K_WME_AC_BK:
1723 * Expand time stamp to TSF
1725 * Extend 15-bit time stamp from rx descriptor to
1726 * a full 64-bit TSF using the current h/w TSF.
1729 u64 ath_extend_tsf(struct ath_softc *sc, u32 rstamp)
1733 tsf = ath9k_hw_gettsf64(sc->sc_ah);
1734 if ((tsf & 0x7fff) < rstamp)
1736 return (tsf & ~0x7fff) | rstamp;
1740 * Set Default Antenna
1742 * Call into the HAL to set the default antenna to use. Not really valid for
1746 void ath_setdefantenna(void *context, u32 antenna)
1748 struct ath_softc *sc = (struct ath_softc *)context;
1749 struct ath_hal *ah = sc->sc_ah;
1751 /* XXX block beacon interrupts */
1752 ath9k_hw_setantenna(ah, antenna);
1753 sc->sc_defant = antenna;
1754 sc->sc_rxotherant = 0;
1760 * This will wake up the chip if required, and set the slot time for the
1761 * frame (maximum transmit time). Slot time is assumed to be already set
1762 * in the ATH object member sc_slottime
1765 void ath_setslottime(struct ath_softc *sc)
1767 ath9k_hw_setslottime(sc->sc_ah, sc->sc_slottime);
1768 sc->sc_updateslot = OK;