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