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