Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 Atheros Communications Inc. |
| 3 | * |
| 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. |
| 7 | * |
| 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. |
| 15 | */ |
| 16 | |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 17 | #include "ath9k.h" |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 18 | |
| 19 | /* |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 20 | * This function will modify certain transmit queue properties depending on |
| 21 | * the operating mode of the station (AP or AdHoc). Parameters are AIFS |
| 22 | * settings and channel width min/max |
| 23 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 24 | static int ath_beaconq_config(struct ath_softc *sc) |
| 25 | { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 26 | struct ath_hw *ah = sc->sc_ah; |
Sujith | ea9880f | 2008-08-07 10:53:10 +0530 | [diff] [blame] | 27 | struct ath9k_tx_queue_info qi; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 28 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 29 | ath9k_hw_get_txq_props(ah, sc->beacon.beaconq, &qi); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 30 | if (sc->sc_ah->opmode == NL80211_IFTYPE_AP) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 31 | /* Always burst out beacon and CAB traffic. */ |
| 32 | qi.tqi_aifs = 1; |
| 33 | qi.tqi_cwmin = 0; |
| 34 | qi.tqi_cwmax = 0; |
| 35 | } else { |
| 36 | /* Adhoc mode; important thing is to use 2x cwmin. */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 37 | qi.tqi_aifs = sc->beacon.beacon_qi.tqi_aifs; |
| 38 | qi.tqi_cwmin = 2*sc->beacon.beacon_qi.tqi_cwmin; |
| 39 | qi.tqi_cwmax = sc->beacon.beacon_qi.tqi_cwmax; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 42 | if (!ath9k_hw_set_txq_props(ah, sc->beacon.beaconq, &qi)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 43 | DPRINTF(sc, ATH_DBG_FATAL, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 44 | "unable to update h/w beacon queue parameters\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 45 | return 0; |
| 46 | } else { |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 47 | ath9k_hw_resettxqueue(ah, sc->beacon.beaconq); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 48 | return 1; |
| 49 | } |
| 50 | } |
| 51 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 52 | static void ath_bstuck_process(struct ath_softc *sc) |
| 53 | { |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 54 | DPRINTF(sc, ATH_DBG_BEACON, "stuck beacon; resetting (bmiss count %u)\n", |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 55 | sc->beacon.bmisscnt); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 56 | ath_reset(sc, false); |
| 57 | } |
| 58 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 59 | /* |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 60 | * Associates the beacon frame buffer with a transmit descriptor. Will set |
| 61 | * up all required antenna switch parameters, rate codes, and channel flags. |
| 62 | * Beacons are always sent out at the lowest rate, and are not retried. |
| 63 | */ |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 64 | static void ath_beacon_setup(struct ath_softc *sc, struct ath_vif *avp, |
| 65 | struct ath_buf *bf) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 66 | { |
| 67 | struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 68 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 69 | struct ath_desc *ds; |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 70 | struct ath9k_11n_rate_series series[4]; |
Sujith | e63835b | 2008-11-18 09:07:53 +0530 | [diff] [blame] | 71 | struct ath_rate_table *rt; |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 72 | int flags, antenna, ctsrate = 0, ctsduration = 0; |
| 73 | u8 rate; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 74 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 75 | ds = bf->bf_desc; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 76 | flags = ATH9K_TXDESC_NOACK; |
| 77 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 78 | if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC && |
| 79 | (ah->caps.hw_caps & ATH9K_HW_CAP_VEOL)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 80 | ds->ds_link = bf->bf_daddr; /* self-linked */ |
| 81 | flags |= ATH9K_TXDESC_VEOL; |
| 82 | /* Let hardware handle antenna switching. */ |
| 83 | antenna = 0; |
| 84 | } else { |
| 85 | ds->ds_link = 0; |
| 86 | /* |
| 87 | * Switch antenna every beacon. |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 88 | * Should only switch every beacon period, not for every SWBA |
| 89 | * XXX assumes two antennae |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 90 | */ |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 91 | antenna = ((sc->beacon.ast_be_xmit / sc->nbcnvifs) & 1 ? 2 : 1); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | ds->ds_data = bf->bf_buf_addr; |
| 95 | |
Sujith | 3706de6 | 2008-12-07 21:42:10 +0530 | [diff] [blame] | 96 | rt = sc->cur_rate_table; |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 97 | rate = rt->info[0].ratecode; |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 98 | if (sc->sc_flags & SC_OP_PREAMBLE_SHORT) |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 99 | rate |= rt->info[0].short_preamble; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 100 | |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 101 | ath9k_hw_set11n_txdesc(ah, ds, skb->len + FCS_LEN, |
| 102 | ATH9K_PKT_TYPE_BEACON, |
| 103 | MAX_RATE_POWER, |
| 104 | ATH9K_TXKEYIX_INVALID, |
| 105 | ATH9K_KEY_TYPE_CLEAR, |
| 106 | flags); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 107 | |
| 108 | /* NB: beacon's BufLen must be a multiple of 4 bytes */ |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 109 | ath9k_hw_filltxdesc(ah, ds, roundup(skb->len, 4), |
| 110 | true, true, ds); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 111 | |
Luis R. Rodriguez | 0345f37 | 2008-10-03 15:45:25 -0700 | [diff] [blame] | 112 | memset(series, 0, sizeof(struct ath9k_11n_rate_series) * 4); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 113 | series[0].Tries = 1; |
| 114 | series[0].Rate = rate; |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 115 | series[0].ChSel = sc->tx_chainmask; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 116 | series[0].RateFlags = (ctsrate) ? ATH9K_RATESERIES_RTS_CTS : 0; |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 117 | ath9k_hw_set11n_ratescenario(ah, ds, ds, 0, ctsrate, ctsduration, |
| 118 | series, 4, 0); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 121 | static struct ath_buf *ath_beacon_generate(struct ath_softc *sc, int if_id) |
| 122 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 123 | struct ath_buf *bf; |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 124 | struct ath_vif *avp; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 125 | struct sk_buff *skb; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 126 | struct ath_txq *cabq; |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 127 | struct ieee80211_vif *vif; |
Jouni Malinen | 147583c | 2008-08-11 14:01:50 +0300 | [diff] [blame] | 128 | struct ieee80211_tx_info *info; |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 129 | int cabq_depth; |
| 130 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 131 | vif = sc->vifs[if_id]; |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 132 | avp = (void *)vif->drv_priv; |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 133 | cabq = sc->beacon.cabq; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 134 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 135 | if (avp->av_bcbuf == NULL) { |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 136 | DPRINTF(sc, ATH_DBG_BEACON, "avp=%p av_bcbuf=%p\n", |
| 137 | avp, avp->av_bcbuf); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 138 | return NULL; |
| 139 | } |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 140 | |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 141 | /* Release the old beacon first */ |
| 142 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 143 | bf = avp->av_bcbuf; |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 144 | skb = (struct sk_buff *)bf->bf_mpdu; |
Jouni Malinen | a8fff50 | 2008-08-11 14:01:48 +0300 | [diff] [blame] | 145 | if (skb) { |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 146 | dma_unmap_single(sc->dev, bf->bf_dmacontext, |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 147 | skb->len, DMA_TO_DEVICE); |
Jouni Malinen | 3fbb9d9 | 2008-12-05 20:42:45 +0200 | [diff] [blame] | 148 | dev_kfree_skb_any(skb); |
Jouni Malinen | a8fff50 | 2008-08-11 14:01:48 +0300 | [diff] [blame] | 149 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 150 | |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 151 | /* Get a new beacon from mac80211 */ |
| 152 | |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 153 | skb = ieee80211_beacon_get(sc->hw, vif); |
Jouni Malinen | a8fff50 | 2008-08-11 14:01:48 +0300 | [diff] [blame] | 154 | bf->bf_mpdu = skb; |
| 155 | if (skb == NULL) |
| 156 | return NULL; |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 157 | |
Jouni Malinen | 147583c | 2008-08-11 14:01:50 +0300 | [diff] [blame] | 158 | info = IEEE80211_SKB_CB(skb); |
| 159 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
| 160 | /* |
| 161 | * TODO: make sure the seq# gets assigned properly (vs. other |
| 162 | * TX frames) |
| 163 | */ |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 164 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 165 | sc->tx.seq_no += 0x10; |
Jouni Malinen | 147583c | 2008-08-11 14:01:50 +0300 | [diff] [blame] | 166 | hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 167 | hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no); |
Jouni Malinen | 147583c | 2008-08-11 14:01:50 +0300 | [diff] [blame] | 168 | } |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 169 | |
Jouni Malinen | a8fff50 | 2008-08-11 14:01:48 +0300 | [diff] [blame] | 170 | bf->bf_buf_addr = bf->bf_dmacontext = |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 171 | dma_map_single(sc->dev, skb->data, |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 172 | skb->len, DMA_TO_DEVICE); |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 173 | if (unlikely(dma_mapping_error(sc->dev, bf->bf_buf_addr))) { |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 174 | dev_kfree_skb_any(skb); |
| 175 | bf->bf_mpdu = NULL; |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 176 | DPRINTF(sc, ATH_DBG_FATAL, "dma_mapping_error on beaconing\n"); |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 177 | return NULL; |
| 178 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 179 | |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 180 | skb = ieee80211_get_buffered_bc(sc->hw, vif); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 181 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 182 | /* |
| 183 | * if the CABQ traffic from previous DTIM is pending and the current |
| 184 | * beacon is also a DTIM. |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 185 | * 1) if there is only one vif let the cab traffic continue. |
| 186 | * 2) if there are more than one vif and we are using staggered |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 187 | * beacons, then drain the cabq by dropping all the frames in |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 188 | * the cabq so that the current vifs cab traffic can be scheduled. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 189 | */ |
| 190 | spin_lock_bh(&cabq->axq_lock); |
| 191 | cabq_depth = cabq->axq_depth; |
| 192 | spin_unlock_bh(&cabq->axq_lock); |
| 193 | |
Jouni Malinen | e022edb | 2008-08-22 17:31:33 +0300 | [diff] [blame] | 194 | if (skb && cabq_depth) { |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 195 | if (sc->nvifs > 1) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 196 | DPRINTF(sc, ATH_DBG_BEACON, |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 197 | "Flushing previous cabq traffic\n"); |
| 198 | ath_draintxq(sc, cabq, false); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 202 | ath_beacon_setup(sc, avp, bf); |
| 203 | |
Jouni Malinen | e022edb | 2008-08-22 17:31:33 +0300 | [diff] [blame] | 204 | while (skb) { |
| 205 | ath_tx_cabq(sc, skb); |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 206 | skb = ieee80211_get_buffered_bc(sc->hw, vif); |
Jouni Malinen | e022edb | 2008-08-22 17:31:33 +0300 | [diff] [blame] | 207 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 208 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 209 | return bf; |
| 210 | } |
| 211 | |
| 212 | /* |
| 213 | * Startup beacon transmission for adhoc mode when they are sent entirely |
| 214 | * by the hardware using the self-linked descriptor + veol trick. |
| 215 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 216 | static void ath_beacon_start_adhoc(struct ath_softc *sc, int if_id) |
| 217 | { |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 218 | struct ieee80211_vif *vif; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 219 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 220 | struct ath_buf *bf; |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 221 | struct ath_vif *avp; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 222 | struct sk_buff *skb; |
| 223 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 224 | vif = sc->vifs[if_id]; |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 225 | avp = (void *)vif->drv_priv; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 226 | |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 227 | if (avp->av_bcbuf == NULL) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 228 | return; |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 229 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 230 | bf = avp->av_bcbuf; |
| 231 | skb = (struct sk_buff *) bf->bf_mpdu; |
| 232 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 233 | ath_beacon_setup(sc, avp, bf); |
| 234 | |
| 235 | /* NB: caller is known to have already stopped tx dma */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 236 | ath9k_hw_puttxbuf(ah, sc->beacon.beaconq, bf->bf_daddr); |
| 237 | ath9k_hw_txstart(ah, sc->beacon.beaconq); |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 238 | DPRINTF(sc, ATH_DBG_BEACON, "TXDP%u = %llx (%p)\n", |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 239 | sc->beacon.beaconq, ito64(bf->bf_daddr), bf->bf_desc); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 242 | int ath_beaconq_setup(struct ath_hw *ah) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 243 | { |
Sujith | ea9880f | 2008-08-07 10:53:10 +0530 | [diff] [blame] | 244 | struct ath9k_tx_queue_info qi; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 245 | |
Luis R. Rodriguez | 0345f37 | 2008-10-03 15:45:25 -0700 | [diff] [blame] | 246 | memset(&qi, 0, sizeof(qi)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 247 | qi.tqi_aifs = 1; |
| 248 | qi.tqi_cwmin = 0; |
| 249 | qi.tqi_cwmax = 0; |
| 250 | /* NB: don't enable any interrupts */ |
| 251 | return ath9k_hw_setuptxqueue(ah, ATH9K_TX_QUEUE_BEACON, &qi); |
| 252 | } |
| 253 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 254 | int ath_beacon_alloc(struct ath_softc *sc, int if_id) |
| 255 | { |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 256 | struct ieee80211_vif *vif; |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 257 | struct ath_vif *avp; |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 258 | struct ieee80211_hdr *hdr; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 259 | struct ath_buf *bf; |
| 260 | struct sk_buff *skb; |
Sujith | 459f5f9 | 2008-09-17 10:15:36 +0530 | [diff] [blame] | 261 | __le64 tstamp; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 262 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 263 | vif = sc->vifs[if_id]; |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 264 | avp = (void *)vif->drv_priv; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 265 | |
| 266 | /* Allocate a beacon descriptor if we haven't done so. */ |
| 267 | if (!avp->av_bcbuf) { |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 268 | /* Allocate beacon state for hostap/ibss. We know |
| 269 | * a buffer is available. */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 270 | avp->av_bcbuf = list_first_entry(&sc->beacon.bbuf, |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 271 | struct ath_buf, list); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 272 | list_del(&avp->av_bcbuf->list); |
| 273 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 274 | if (sc->sc_ah->opmode == NL80211_IFTYPE_AP || |
| 275 | !(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_VEOL)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 276 | int slot; |
| 277 | /* |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 278 | * Assign the vif to a beacon xmit slot. As |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 279 | * above, this cannot fail to find one. |
| 280 | */ |
| 281 | avp->av_bslot = 0; |
| 282 | for (slot = 0; slot < ATH_BCBUF; slot++) |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 283 | if (sc->beacon.bslot[slot] == ATH_IF_ID_ANY) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 284 | /* |
| 285 | * XXX hack, space out slots to better |
| 286 | * deal with misses |
| 287 | */ |
| 288 | if (slot+1 < ATH_BCBUF && |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 289 | sc->beacon.bslot[slot+1] == |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 290 | ATH_IF_ID_ANY) { |
| 291 | avp->av_bslot = slot+1; |
| 292 | break; |
| 293 | } |
| 294 | avp->av_bslot = slot; |
| 295 | /* NB: keep looking for a double slot */ |
| 296 | } |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 297 | BUG_ON(sc->beacon.bslot[avp->av_bslot] != ATH_IF_ID_ANY); |
| 298 | sc->beacon.bslot[avp->av_bslot] = if_id; |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 299 | sc->nbcnvifs++; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 303 | /* release the previous beacon frame, if it already exists. */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 304 | bf = avp->av_bcbuf; |
| 305 | if (bf->bf_mpdu != NULL) { |
| 306 | skb = (struct sk_buff *)bf->bf_mpdu; |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 307 | dma_unmap_single(sc->dev, bf->bf_dmacontext, |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 308 | skb->len, DMA_TO_DEVICE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 309 | dev_kfree_skb_any(skb); |
| 310 | bf->bf_mpdu = NULL; |
| 311 | } |
| 312 | |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 313 | /* NB: the beacon data buffer must be 32-bit aligned. */ |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 314 | skb = ieee80211_beacon_get(sc->hw, vif); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 315 | if (skb == NULL) { |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 316 | DPRINTF(sc, ATH_DBG_BEACON, "cannot get skb\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 317 | return -ENOMEM; |
| 318 | } |
| 319 | |
Sujith | 459f5f9 | 2008-09-17 10:15:36 +0530 | [diff] [blame] | 320 | tstamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp; |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 321 | sc->beacon.bc_tstamp = le64_to_cpu(tstamp); |
Sujith | 459f5f9 | 2008-09-17 10:15:36 +0530 | [diff] [blame] | 322 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 323 | /* |
| 324 | * Calculate a TSF adjustment factor required for |
| 325 | * staggered beacons. Note that we assume the format |
| 326 | * of the beacon frame leaves the tstamp field immediately |
| 327 | * following the header. |
| 328 | */ |
| 329 | if (avp->av_bslot > 0) { |
| 330 | u64 tsfadjust; |
| 331 | __le64 val; |
| 332 | int intval; |
| 333 | |
Jouni Malinen | a8fff50 | 2008-08-11 14:01:48 +0300 | [diff] [blame] | 334 | intval = sc->hw->conf.beacon_int ? |
| 335 | sc->hw->conf.beacon_int : ATH_DEFAULT_BINTVAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 336 | |
| 337 | /* |
| 338 | * The beacon interval is in TU's; the TSF in usecs. |
| 339 | * We figure out how many TU's to add to align the |
| 340 | * timestamp then convert to TSF units and handle |
| 341 | * byte swapping before writing it in the frame. |
| 342 | * The hardware will then add this each time a beacon |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 343 | * frame is sent. Note that we align vif's 1..N |
| 344 | * and leave vif 0 untouched. This means vap 0 |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 345 | * has a timestamp in one beacon interval while the |
| 346 | * others get a timestamp aligned to the next interval. |
| 347 | */ |
| 348 | tsfadjust = (intval * (ATH_BCBUF - avp->av_bslot)) / ATH_BCBUF; |
| 349 | val = cpu_to_le64(tsfadjust << 10); /* TU->TSF */ |
| 350 | |
| 351 | DPRINTF(sc, ATH_DBG_BEACON, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 352 | "stagger beacons, bslot %d intval %u tsfadjust %llu\n", |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 353 | avp->av_bslot, intval, (unsigned long long)tsfadjust); |
| 354 | |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 355 | hdr = (struct ieee80211_hdr *)skb->data; |
| 356 | memcpy(&hdr[1], &val, sizeof(val)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 359 | bf->bf_mpdu = skb; |
Jouni Malinen | a8fff50 | 2008-08-11 14:01:48 +0300 | [diff] [blame] | 360 | bf->bf_buf_addr = bf->bf_dmacontext = |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 361 | dma_map_single(sc->dev, skb->data, |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 362 | skb->len, DMA_TO_DEVICE); |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 363 | if (unlikely(dma_mapping_error(sc->dev, bf->bf_buf_addr))) { |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 364 | dev_kfree_skb_any(skb); |
| 365 | bf->bf_mpdu = NULL; |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 366 | DPRINTF(sc, ATH_DBG_FATAL, |
| 367 | "dma_mapping_error on beacon alloc\n"); |
Luis R. Rodriguez | f8316df | 2008-12-03 03:35:29 -0800 | [diff] [blame] | 368 | return -ENOMEM; |
| 369 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 370 | |
| 371 | return 0; |
| 372 | } |
| 373 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 374 | void ath_beacon_return(struct ath_softc *sc, struct ath_vif *avp) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 375 | { |
| 376 | if (avp->av_bcbuf != NULL) { |
| 377 | struct ath_buf *bf; |
| 378 | |
| 379 | if (avp->av_bslot != -1) { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 380 | sc->beacon.bslot[avp->av_bslot] = ATH_IF_ID_ANY; |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 381 | sc->nbcnvifs--; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | bf = avp->av_bcbuf; |
| 385 | if (bf->bf_mpdu != NULL) { |
| 386 | struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu; |
Gabor Juhos | 7da3c55 | 2009-01-14 20:17:03 +0100 | [diff] [blame] | 387 | dma_unmap_single(sc->dev, bf->bf_dmacontext, |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 388 | skb->len, DMA_TO_DEVICE); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 389 | dev_kfree_skb_any(skb); |
| 390 | bf->bf_mpdu = NULL; |
| 391 | } |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 392 | list_add_tail(&bf->list, &sc->beacon.bbuf); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 393 | |
| 394 | avp->av_bcbuf = NULL; |
| 395 | } |
| 396 | } |
| 397 | |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 398 | void ath_beacon_tasklet(unsigned long data) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 399 | { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 400 | struct ath_softc *sc = (struct ath_softc *)data; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 401 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 402 | struct ath_buf *bf = NULL; |
| 403 | int slot, if_id; |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 404 | u32 bfaddr, show_cycles = 0, bc = 0, tsftu; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 405 | u32 rx_clear = 0, rx_frame = 0, tx_frame = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 406 | u64 tsf; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 407 | u16 intval; |
| 408 | |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 409 | if (sc->sc_flags & SC_OP_NO_RESET) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 410 | show_cycles = ath9k_hw_GetMibCycleCountsPct(ah, |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 411 | &rx_clear, &rx_frame, &tx_frame); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | /* |
| 415 | * Check if the previous beacon has gone out. If |
| 416 | * not don't try to post another, skip this period |
| 417 | * and wait for the next. Missed beacons indicate |
| 418 | * a problem and should not occur. If we miss too |
| 419 | * many consecutive beacons reset the device. |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 420 | * |
| 421 | * FIXME: Clean up this mess !! |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 422 | */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 423 | if (ath9k_hw_numtxpending(ah, sc->beacon.beaconq) != 0) { |
| 424 | sc->beacon.bmisscnt++; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 425 | /* XXX: doth needs the chanchange IE countdown decremented. |
| 426 | * We should consider adding a mac80211 call to indicate |
| 427 | * a beacon miss so appropriate action could be taken |
| 428 | * (in that layer). |
| 429 | */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 430 | if (sc->beacon.bmisscnt < BSTUCK_THRESH) { |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 431 | if (sc->sc_flags & SC_OP_NO_RESET) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 432 | DPRINTF(sc, ATH_DBG_BEACON, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 433 | "missed %u consecutive beacons\n", |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 434 | sc->beacon.bmisscnt); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 435 | if (show_cycles) { |
| 436 | /* |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 437 | * Display cycle counter stats from HW |
| 438 | * to aide in debug of stickiness. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 439 | */ |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 440 | DPRINTF(sc, ATH_DBG_BEACON, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 441 | "busy times: rx_clear=%d, " |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 442 | "rx_frame=%d, tx_frame=%d\n", |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 443 | rx_clear, rx_frame, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 444 | tx_frame); |
| 445 | } else { |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 446 | DPRINTF(sc, ATH_DBG_BEACON, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 447 | "unable to obtain " |
| 448 | "busy times\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 449 | } |
| 450 | } else { |
| 451 | DPRINTF(sc, ATH_DBG_BEACON, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 452 | "missed %u consecutive beacons\n", |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 453 | sc->beacon.bmisscnt); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 454 | } |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 455 | } else if (sc->beacon.bmisscnt >= BSTUCK_THRESH) { |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 456 | if (sc->sc_flags & SC_OP_NO_RESET) { |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 457 | if (sc->beacon.bmisscnt == BSTUCK_THRESH) { |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 458 | DPRINTF(sc, ATH_DBG_BEACON, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 459 | "beacon is officially " |
| 460 | "stuck\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 461 | } |
| 462 | } else { |
| 463 | DPRINTF(sc, ATH_DBG_BEACON, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 464 | "beacon is officially stuck\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 465 | ath_bstuck_process(sc); |
| 466 | } |
| 467 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 468 | return; |
| 469 | } |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 470 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 471 | if (sc->beacon.bmisscnt != 0) { |
Sujith | 98deeea | 2008-08-11 14:05:46 +0530 | [diff] [blame] | 472 | if (sc->sc_flags & SC_OP_NO_RESET) { |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 473 | DPRINTF(sc, ATH_DBG_BEACON, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 474 | "resume beacon xmit after %u misses\n", |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 475 | sc->beacon.bmisscnt); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 476 | } else { |
| 477 | DPRINTF(sc, ATH_DBG_BEACON, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 478 | "resume beacon xmit after %u misses\n", |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 479 | sc->beacon.bmisscnt); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 480 | } |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 481 | sc->beacon.bmisscnt = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | /* |
| 485 | * Generate beacon frames. we are sending frames |
| 486 | * staggered so calculate the slot for this frame based |
| 487 | * on the tsf to safeguard against missing an swba. |
| 488 | */ |
| 489 | |
Jouni Malinen | a8fff50 | 2008-08-11 14:01:48 +0300 | [diff] [blame] | 490 | intval = sc->hw->conf.beacon_int ? |
| 491 | sc->hw->conf.beacon_int : ATH_DEFAULT_BINTVAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 492 | |
| 493 | tsf = ath9k_hw_gettsf64(ah); |
| 494 | tsftu = TSF_TO_TU(tsf>>32, tsf); |
| 495 | slot = ((tsftu % intval) * ATH_BCBUF) / intval; |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 496 | if_id = sc->beacon.bslot[(slot + 1) % ATH_BCBUF]; |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 497 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 498 | DPRINTF(sc, ATH_DBG_BEACON, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 499 | "slot %d [tsf %llu tsftu %u intval %u] if_id %d\n", |
| 500 | slot, (unsigned long long)tsf, tsftu, |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 501 | intval, if_id); |
| 502 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 503 | bfaddr = 0; |
| 504 | if (if_id != ATH_IF_ID_ANY) { |
| 505 | bf = ath_beacon_generate(sc, if_id); |
| 506 | if (bf != NULL) { |
| 507 | bfaddr = bf->bf_daddr; |
| 508 | bc = 1; |
| 509 | } |
| 510 | } |
| 511 | /* |
| 512 | * Handle slot time change when a non-ERP station joins/leaves |
| 513 | * an 11g network. The 802.11 layer notifies us via callback, |
| 514 | * we mark updateslot, then wait one beacon before effecting |
| 515 | * the change. This gives associated stations at least one |
| 516 | * beacon interval to note the state change. |
| 517 | * |
| 518 | * NB: The slot time change state machine is clocked according |
| 519 | * to whether we are bursting or staggering beacons. We |
| 520 | * recognize the request to update and record the current |
| 521 | * slot then don't transition until that slot is reached |
| 522 | * again. If we miss a beacon for that slot then we'll be |
| 523 | * slow to transition but we'll be sure at least one beacon |
| 524 | * interval has passed. When bursting slot is always left |
| 525 | * set to ATH_BCBUF so this check is a noop. |
| 526 | */ |
| 527 | /* XXX locking */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 528 | if (sc->beacon.updateslot == UPDATE) { |
| 529 | sc->beacon.updateslot = COMMIT; /* commit next beacon */ |
| 530 | sc->beacon.slotupdate = slot; |
| 531 | } else if (sc->beacon.updateslot == COMMIT && sc->beacon.slotupdate == slot) { |
| 532 | ath9k_hw_setslottime(sc->sc_ah, sc->beacon.slottime); |
| 533 | sc->beacon.updateslot = OK; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 534 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 535 | if (bfaddr != 0) { |
| 536 | /* |
| 537 | * Stop any current dma and put the new frame(s) on the queue. |
| 538 | * This should never fail since we check above that no frames |
| 539 | * are still pending on the queue. |
| 540 | */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 541 | if (!ath9k_hw_stoptxdma(ah, sc->beacon.beaconq)) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 542 | DPRINTF(sc, ATH_DBG_FATAL, |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 543 | "beacon queue %u did not stop?\n", sc->beacon.beaconq); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 544 | /* NB: the HAL still stops DMA, so proceed */ |
| 545 | } |
| 546 | |
| 547 | /* NB: cabq traffic should already be queued and primed */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 548 | ath9k_hw_puttxbuf(ah, sc->beacon.beaconq, bfaddr); |
| 549 | ath9k_hw_txstart(ah, sc->beacon.beaconq); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 550 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 551 | sc->beacon.ast_be_xmit += bc; /* XXX per-vif? */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 552 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | /* |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 556 | * Configure the beacon and sleep timers. |
| 557 | * |
| 558 | * When operating as an AP this resets the TSF and sets |
| 559 | * up the hardware to notify us when we need to issue beacons. |
| 560 | * |
| 561 | * When operating in station mode this sets up the beacon |
| 562 | * timers according to the timestamp of the last received |
| 563 | * beacon and the current TSF, configures PCF and DTIM |
| 564 | * handling, programs the sleep registers so the hardware |
| 565 | * will wakeup in time to receive beacons, and configures |
| 566 | * the beacon miss handling so we'll receive a BMISS |
| 567 | * interrupt when we stop seeing beacons from the AP |
| 568 | * we've associated with. |
| 569 | */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 570 | void ath_beacon_config(struct ath_softc *sc, int if_id) |
| 571 | { |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 572 | struct ieee80211_vif *vif; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 573 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 574 | struct ath_beacon_config conf; |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 575 | struct ath_vif *avp; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 576 | enum nl80211_iftype opmode; |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 577 | u32 nexttbtt, intval; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 578 | |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 579 | if (if_id != ATH_IF_ID_ANY) { |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 580 | vif = sc->vifs[if_id]; |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 581 | avp = (void *)vif->drv_priv; |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 582 | opmode = avp->av_opmode; |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 583 | } else { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 584 | opmode = sc->sc_ah->opmode; |
Sujith | 5640b08 | 2008-10-29 10:16:06 +0530 | [diff] [blame] | 585 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 586 | |
Luis R. Rodriguez | 0345f37 | 2008-10-03 15:45:25 -0700 | [diff] [blame] | 587 | memset(&conf, 0, sizeof(struct ath_beacon_config)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 588 | |
Jouni Malinen | a8fff50 | 2008-08-11 14:01:48 +0300 | [diff] [blame] | 589 | conf.beacon_interval = sc->hw->conf.beacon_int ? |
| 590 | sc->hw->conf.beacon_int : ATH_DEFAULT_BINTVAL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 591 | conf.listen_interval = 1; |
| 592 | conf.dtim_period = conf.beacon_interval; |
| 593 | conf.dtim_count = 1; |
| 594 | conf.bmiss_timeout = ATH_DEFAULT_BMISS_LIMIT * conf.beacon_interval; |
| 595 | |
| 596 | /* extract tstamp from last beacon and convert to TU */ |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 597 | nexttbtt = TSF_TO_TU(sc->beacon.bc_tstamp >> 32, sc->beacon.bc_tstamp); |
Sujith | 459f5f9 | 2008-09-17 10:15:36 +0530 | [diff] [blame] | 598 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 599 | /* XXX conditionalize multi-bss support? */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 600 | if (sc->sc_ah->opmode == NL80211_IFTYPE_AP) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 601 | /* |
| 602 | * For multi-bss ap support beacons are either staggered |
| 603 | * evenly over N slots or burst together. For the former |
| 604 | * arrange for the SWBA to be delivered for each slot. |
| 605 | * Slots that are not occupied will generate nothing. |
| 606 | */ |
| 607 | /* NB: the beacon interval is kept internally in TU's */ |
| 608 | intval = conf.beacon_interval & ATH9K_BEACON_PERIOD; |
| 609 | intval /= ATH_BCBUF; /* for staggered beacons */ |
| 610 | } else { |
| 611 | intval = conf.beacon_interval & ATH9K_BEACON_PERIOD; |
| 612 | } |
| 613 | |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 614 | if (nexttbtt == 0) /* e.g. for ap mode */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 615 | nexttbtt = intval; |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 616 | else if (intval) /* NB: can be 0 for monitor mode */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 617 | nexttbtt = roundup(nexttbtt, intval); |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 618 | |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 619 | DPRINTF(sc, ATH_DBG_BEACON, "nexttbtt %u intval %u (%u)\n", |
| 620 | nexttbtt, intval, conf.beacon_interval); |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 621 | |
Colin McCabe | d97809d | 2008-12-01 13:38:55 -0800 | [diff] [blame] | 622 | /* Check for NL80211_IFTYPE_AP and sc_nostabeacons for WDS client */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 623 | if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION) { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 624 | struct ath9k_beacon_state bs; |
| 625 | u64 tsf; |
| 626 | u32 tsftu; |
| 627 | int dtimperiod, dtimcount, sleepduration; |
| 628 | int cfpperiod, cfpcount; |
| 629 | |
| 630 | /* |
| 631 | * Setup dtim and cfp parameters according to |
| 632 | * last beacon we received (which may be none). |
| 633 | */ |
| 634 | dtimperiod = conf.dtim_period; |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 635 | if (dtimperiod <= 0) /* NB: 0 if not known */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 636 | dtimperiod = 1; |
| 637 | dtimcount = conf.dtim_count; |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 638 | if (dtimcount >= dtimperiod) /* NB: sanity check */ |
| 639 | dtimcount = 0; |
| 640 | cfpperiod = 1; /* NB: no PCF support yet */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 641 | cfpcount = 0; |
| 642 | |
| 643 | sleepduration = conf.listen_interval * intval; |
| 644 | if (sleepduration <= 0) |
| 645 | sleepduration = intval; |
| 646 | |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 647 | #define FUDGE 2 |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 648 | /* |
| 649 | * Pull nexttbtt forward to reflect the current |
| 650 | * TSF and calculate dtim+cfp state for the result. |
| 651 | */ |
| 652 | tsf = ath9k_hw_gettsf64(ah); |
| 653 | tsftu = TSF_TO_TU(tsf>>32, tsf) + FUDGE; |
| 654 | do { |
| 655 | nexttbtt += intval; |
| 656 | if (--dtimcount < 0) { |
| 657 | dtimcount = dtimperiod - 1; |
| 658 | if (--cfpcount < 0) |
| 659 | cfpcount = cfpperiod - 1; |
| 660 | } |
| 661 | } while (nexttbtt < tsftu); |
| 662 | #undef FUDGE |
Luis R. Rodriguez | 0345f37 | 2008-10-03 15:45:25 -0700 | [diff] [blame] | 663 | memset(&bs, 0, sizeof(bs)); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 664 | bs.bs_intval = intval; |
| 665 | bs.bs_nexttbtt = nexttbtt; |
| 666 | bs.bs_dtimperiod = dtimperiod*intval; |
| 667 | bs.bs_nextdtim = bs.bs_nexttbtt + dtimcount*intval; |
| 668 | bs.bs_cfpperiod = cfpperiod*bs.bs_dtimperiod; |
| 669 | bs.bs_cfpnext = bs.bs_nextdtim + cfpcount*bs.bs_dtimperiod; |
| 670 | bs.bs_cfpmaxduration = 0; |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 671 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 672 | /* |
| 673 | * Calculate the number of consecutive beacons to miss |
| 674 | * before taking a BMISS interrupt. The configuration |
| 675 | * is specified in TU so we only need calculate based |
| 676 | * on the beacon interval. Note that we clamp the |
| 677 | * result to at most 15 beacons. |
| 678 | */ |
| 679 | if (sleepduration > intval) { |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 680 | bs.bs_bmissthreshold = conf.listen_interval * |
| 681 | ATH_DEFAULT_BMISS_LIMIT / 2; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 682 | } else { |
| 683 | bs.bs_bmissthreshold = |
| 684 | DIV_ROUND_UP(conf.bmiss_timeout, intval); |
| 685 | if (bs.bs_bmissthreshold > 15) |
| 686 | bs.bs_bmissthreshold = 15; |
| 687 | else if (bs.bs_bmissthreshold <= 0) |
| 688 | bs.bs_bmissthreshold = 1; |
| 689 | } |
| 690 | |
| 691 | /* |
| 692 | * Calculate sleep duration. The configuration is |
| 693 | * given in ms. We insure a multiple of the beacon |
| 694 | * period is used. Also, if the sleep duration is |
| 695 | * greater than the DTIM period then it makes senses |
| 696 | * to make it a multiple of that. |
| 697 | * |
| 698 | * XXX fixed at 100ms |
| 699 | */ |
| 700 | |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 701 | bs.bs_sleepduration = roundup(IEEE80211_MS_TO_TU(100), |
| 702 | sleepduration); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 703 | if (bs.bs_sleepduration > bs.bs_dtimperiod) |
| 704 | bs.bs_sleepduration = bs.bs_dtimperiod; |
| 705 | |
Sujith | 4af9cf4 | 2009-02-12 10:06:47 +0530 | [diff] [blame] | 706 | /* TSF out of range threshold fixed at 1 second */ |
| 707 | bs.bs_tsfoor_threshold = ATH9K_TSFOOR_THRESHOLD; |
| 708 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 709 | DPRINTF(sc, ATH_DBG_BEACON, |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 710 | "tsf: %llu tsftu: %u\n", tsf, tsftu); |
| 711 | DPRINTF(sc, ATH_DBG_BEACON, |
| 712 | "bmiss: %u sleep: %u cfp-period: %u maxdur: %u next: %u\n", |
| 713 | bs.bs_bmissthreshold, bs.bs_sleepduration, |
| 714 | bs.bs_cfpperiod, bs.bs_cfpmaxduration, bs.bs_cfpnext); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 715 | |
| 716 | ath9k_hw_set_interrupts(ah, 0); |
| 717 | ath9k_hw_set_sta_beacon_timers(ah, &bs); |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 718 | sc->imask |= ATH9K_INT_BMISS; |
| 719 | ath9k_hw_set_interrupts(ah, sc->imask); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 720 | } else { |
| 721 | u64 tsf; |
| 722 | u32 tsftu; |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 723 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 724 | ath9k_hw_set_interrupts(ah, 0); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 725 | if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) { |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 726 | /* Pull nexttbtt forward to reflect the current TSF */ |
Sujith | 980b24d | 2008-09-17 10:15:09 +0530 | [diff] [blame] | 727 | #define FUDGE 2 |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 728 | if (!(intval & ATH9K_BEACON_RESET_TSF)) { |
| 729 | tsf = ath9k_hw_gettsf64(ah); |
| 730 | tsftu = TSF_TO_TU((u32)(tsf>>32), |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 731 | (u32)tsf) + FUDGE; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 732 | do { |
| 733 | nexttbtt += intval; |
| 734 | } while (nexttbtt < tsftu); |
| 735 | } |
| 736 | #undef FUDGE |
| 737 | DPRINTF(sc, ATH_DBG_BEACON, |
Sujith | 04bd463 | 2008-11-28 22:18:05 +0530 | [diff] [blame] | 738 | "IBSS nexttbtt %u intval %u (%u)\n", |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 739 | nexttbtt, intval & ~ATH9K_BEACON_RESET_TSF, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 740 | conf.beacon_interval); |
| 741 | |
| 742 | /* |
| 743 | * In IBSS mode enable the beacon timers but only |
| 744 | * enable SWBA interrupts if we need to manually |
| 745 | * prepare beacon frames. Otherwise we use a |
| 746 | * self-linked tx descriptor and let the hardware |
| 747 | * deal with things. |
| 748 | */ |
| 749 | intval |= ATH9K_BEACON_ENA; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 750 | if (!(ah->caps.hw_caps & ATH9K_HW_CAP_VEOL)) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 751 | sc->imask |= ATH9K_INT_SWBA; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 752 | ath_beaconq_config(sc); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 753 | } else if (sc->sc_ah->opmode == NL80211_IFTYPE_AP) { |
Alina Friedrichsen | f452a63 | 2009-02-19 23:46:31 +0100 | [diff] [blame] | 754 | if (nexttbtt == intval) |
| 755 | intval |= ATH9K_BEACON_RESET_TSF; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 756 | /* |
| 757 | * In AP mode we enable the beacon timers and |
| 758 | * SWBA interrupts to prepare beacon frames. |
| 759 | */ |
| 760 | intval |= ATH9K_BEACON_ENA; |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 761 | sc->imask |= ATH9K_INT_SWBA; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 762 | ath_beaconq_config(sc); |
| 763 | } |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 764 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 765 | ath9k_hw_beaconinit(ah, nexttbtt, intval); |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 766 | sc->beacon.bmisscnt = 0; |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 767 | ath9k_hw_set_interrupts(ah, sc->imask); |
Sujith | 9fc9ab0 | 2009-03-03 10:16:51 +0530 | [diff] [blame^] | 768 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 769 | /* |
| 770 | * When using a self-linked beacon descriptor in |
| 771 | * ibss mode load it once here. |
| 772 | */ |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 773 | if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC && |
| 774 | (ah->caps.hw_caps & ATH9K_HW_CAP_VEOL)) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 775 | ath_beacon_start_adhoc(sc, 0); |
| 776 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 779 | void ath_beacon_sync(struct ath_softc *sc, int if_id) |
| 780 | { |
| 781 | /* |
| 782 | * Resync beacon timers using the tsf of the |
| 783 | * beacon frame we just received. |
| 784 | */ |
| 785 | ath_beacon_config(sc, if_id); |
Sujith | 672840a | 2008-08-11 14:05:08 +0530 | [diff] [blame] | 786 | sc->sc_flags |= SC_OP_BEACONS; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 787 | } |