Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * HT handling |
| 3 | * |
| 4 | * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi> |
| 5 | * Copyright 2002-2005, Instant802 Networks, Inc. |
| 6 | * Copyright 2005-2006, Devicescape Software, Inc. |
| 7 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
| 8 | * Copyright 2007, Michael Wu <flamingice@sourmilk.net> |
| 9 | * Copyright 2007-2009, Intel Corporation |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/ieee80211.h> |
| 17 | #include <net/mac80211.h> |
| 18 | #include "ieee80211_i.h" |
| 19 | #include "wme.h" |
| 20 | |
Johannes Berg | 86ab6c5 | 2009-02-10 21:25:49 +0100 | [diff] [blame] | 21 | /** |
| 22 | * DOC: TX aggregation |
| 23 | * |
| 24 | * Aggregation on the TX side requires setting the hardware flag |
| 25 | * %IEEE80211_HW_AMPDU_AGGREGATION as well as, if present, the @ampdu_queues |
| 26 | * hardware parameter to the number of hardware AMPDU queues. If there are no |
| 27 | * hardware queues then the driver will (currently) have to do all frame |
| 28 | * buffering. |
| 29 | * |
| 30 | * When TX aggregation is started by some subsystem (usually the rate control |
| 31 | * algorithm would be appropriate) by calling the |
| 32 | * ieee80211_start_tx_ba_session() function, the driver will be notified via |
| 33 | * its @ampdu_action function, with the %IEEE80211_AMPDU_TX_START action. |
| 34 | * |
| 35 | * In response to that, the driver is later required to call the |
| 36 | * ieee80211_start_tx_ba_cb() (or ieee80211_start_tx_ba_cb_irqsafe()) |
| 37 | * function, which will start the aggregation session. |
| 38 | * |
| 39 | * Similarly, when the aggregation session is stopped by |
| 40 | * ieee80211_stop_tx_ba_session(), the driver's @ampdu_action function will |
| 41 | * be called with the action %IEEE80211_AMPDU_TX_STOP. In this case, the |
| 42 | * call must not fail, and the driver must later call ieee80211_stop_tx_ba_cb() |
| 43 | * (or ieee80211_stop_tx_ba_cb_irqsafe()). |
| 44 | */ |
| 45 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 46 | static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata, |
| 47 | const u8 *da, u16 tid, |
| 48 | u8 dialog_token, u16 start_seq_num, |
| 49 | u16 agg_size, u16 timeout) |
| 50 | { |
| 51 | struct ieee80211_local *local = sdata->local; |
| 52 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 53 | struct sk_buff *skb; |
| 54 | struct ieee80211_mgmt *mgmt; |
| 55 | u16 capab; |
| 56 | |
| 57 | skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom); |
| 58 | |
| 59 | if (!skb) { |
| 60 | printk(KERN_ERR "%s: failed to allocate buffer " |
| 61 | "for addba request frame\n", sdata->dev->name); |
| 62 | return; |
| 63 | } |
| 64 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 65 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 66 | memset(mgmt, 0, 24); |
| 67 | memcpy(mgmt->da, da, ETH_ALEN); |
| 68 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Johannes Berg | 8abd3f9 | 2009-02-10 21:25:47 +0100 | [diff] [blame] | 69 | if (sdata->vif.type == NL80211_IFTYPE_AP || |
| 70 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 71 | memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); |
| 72 | else |
| 73 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 74 | |
| 75 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 76 | IEEE80211_STYPE_ACTION); |
| 77 | |
| 78 | skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req)); |
| 79 | |
| 80 | mgmt->u.action.category = WLAN_CATEGORY_BACK; |
| 81 | mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ; |
| 82 | |
| 83 | mgmt->u.action.u.addba_req.dialog_token = dialog_token; |
| 84 | capab = (u16)(1 << 1); /* bit 1 aggregation policy */ |
| 85 | capab |= (u16)(tid << 2); /* bit 5:2 TID number */ |
| 86 | capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */ |
| 87 | |
| 88 | mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab); |
| 89 | |
| 90 | mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout); |
| 91 | mgmt->u.action.u.addba_req.start_seq_num = |
| 92 | cpu_to_le16(start_seq_num << 4); |
| 93 | |
| 94 | ieee80211_tx_skb(sdata, skb, 1); |
| 95 | } |
| 96 | |
| 97 | void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn) |
| 98 | { |
| 99 | struct ieee80211_local *local = sdata->local; |
| 100 | struct sk_buff *skb; |
| 101 | struct ieee80211_bar *bar; |
| 102 | u16 bar_control = 0; |
| 103 | |
| 104 | skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom); |
| 105 | if (!skb) { |
| 106 | printk(KERN_ERR "%s: failed to allocate buffer for " |
| 107 | "bar frame\n", sdata->dev->name); |
| 108 | return; |
| 109 | } |
| 110 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 111 | bar = (struct ieee80211_bar *)skb_put(skb, sizeof(*bar)); |
| 112 | memset(bar, 0, sizeof(*bar)); |
| 113 | bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | |
| 114 | IEEE80211_STYPE_BACK_REQ); |
| 115 | memcpy(bar->ra, ra, ETH_ALEN); |
| 116 | memcpy(bar->ta, sdata->dev->dev_addr, ETH_ALEN); |
| 117 | bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL; |
| 118 | bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA; |
| 119 | bar_control |= (u16)(tid << 12); |
| 120 | bar->control = cpu_to_le16(bar_control); |
| 121 | bar->start_seq_num = cpu_to_le16(ssn); |
| 122 | |
| 123 | ieee80211_tx_skb(sdata, skb, 0); |
| 124 | } |
| 125 | |
Johannes Berg | 849b796 | 2009-02-10 21:25:54 +0100 | [diff] [blame] | 126 | static int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid, |
| 127 | enum ieee80211_back_parties initiator) |
Johannes Berg | 23e6a7e | 2009-02-10 21:25:50 +0100 | [diff] [blame] | 128 | { |
Johannes Berg | 849b796 | 2009-02-10 21:25:54 +0100 | [diff] [blame] | 129 | struct ieee80211_local *local = sta->local; |
Johannes Berg | 23e6a7e | 2009-02-10 21:25:50 +0100 | [diff] [blame] | 130 | int ret; |
| 131 | u8 *state; |
| 132 | |
| 133 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
| 134 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 135 | if (local->hw.ampdu_queues) { |
| 136 | if (initiator) { |
| 137 | /* |
| 138 | * Stop the AC queue to avoid issues where we send |
| 139 | * unaggregated frames already before the delba. |
| 140 | */ |
| 141 | ieee80211_stop_queue_by_reason(&local->hw, |
| 142 | local->hw.queues + sta->tid_to_tx_q[tid], |
| 143 | IEEE80211_QUEUE_STOP_REASON_AGGREGATION); |
| 144 | } |
Johannes Berg | 23e6a7e | 2009-02-10 21:25:50 +0100 | [diff] [blame] | 145 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 146 | /* |
| 147 | * Pretend the driver woke the queue, just in case |
| 148 | * it disabled it before the session was stopped. |
| 149 | */ |
| 150 | ieee80211_wake_queue( |
| 151 | &local->hw, local->hw.queues + sta->tid_to_tx_q[tid]); |
| 152 | } |
Johannes Berg | 23e6a7e | 2009-02-10 21:25:50 +0100 | [diff] [blame] | 153 | *state = HT_AGG_STATE_REQ_STOP_BA_MSK | |
| 154 | (initiator << HT_AGG_STATE_INITIATOR_SHIFT); |
| 155 | |
| 156 | ret = local->ops->ampdu_action(&local->hw, IEEE80211_AMPDU_TX_STOP, |
| 157 | &sta->sta, tid, NULL); |
| 158 | |
| 159 | /* HW shall not deny going back to legacy */ |
| 160 | if (WARN_ON(ret)) { |
| 161 | *state = HT_AGG_STATE_OPERATIONAL; |
Johannes Berg | 23e6a7e | 2009-02-10 21:25:50 +0100 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | return ret; |
| 165 | } |
| 166 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 167 | /* |
| 168 | * After sending add Block Ack request we activated a timer until |
| 169 | * add Block Ack response will arrive from the recipient. |
| 170 | * If this timer expires sta_addba_resp_timer_expired will be executed. |
| 171 | */ |
| 172 | static void sta_addba_resp_timer_expired(unsigned long data) |
| 173 | { |
| 174 | /* not an elegant detour, but there is no choice as the timer passes |
| 175 | * only one argument, and both sta_info and TID are needed, so init |
| 176 | * flow in sta_info_create gives the TID as data, while the timer_to_id |
| 177 | * array gives the sta through container_of */ |
| 178 | u16 tid = *(u8 *)data; |
Johannes Berg | 23e6a7e | 2009-02-10 21:25:50 +0100 | [diff] [blame] | 179 | struct sta_info *sta = container_of((void *)data, |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 180 | struct sta_info, timer_to_tid[tid]); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 181 | u8 *state; |
| 182 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 183 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
Johannes Berg | 23e6a7e | 2009-02-10 21:25:50 +0100 | [diff] [blame] | 184 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 185 | /* check if the TID waits for addBA response */ |
| 186 | spin_lock_bh(&sta->lock); |
| 187 | if (!(*state & HT_ADDBA_REQUESTED_MSK)) { |
| 188 | spin_unlock_bh(&sta->lock); |
| 189 | *state = HT_AGG_STATE_IDLE; |
| 190 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 191 | printk(KERN_DEBUG "timer expired on tid %d but we are not " |
| 192 | "expecting addBA response there", tid); |
| 193 | #endif |
Johannes Berg | 23e6a7e | 2009-02-10 21:25:50 +0100 | [diff] [blame] | 194 | return; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 198 | printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid); |
| 199 | #endif |
| 200 | |
Johannes Berg | 849b796 | 2009-02-10 21:25:54 +0100 | [diff] [blame] | 201 | ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 202 | spin_unlock_bh(&sta->lock); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 203 | } |
| 204 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 205 | static inline int ieee80211_ac_from_tid(int tid) |
| 206 | { |
| 207 | return ieee802_1d_to_ac[tid & 7]; |
| 208 | } |
| 209 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 210 | int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid) |
| 211 | { |
| 212 | struct ieee80211_local *local = hw_to_local(hw); |
| 213 | struct sta_info *sta; |
| 214 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 215 | u8 *state; |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 216 | int i, qn = -1, ret = 0; |
| 217 | u16 start_seq_num; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 218 | |
Johannes Berg | 23e6a7e | 2009-02-10 21:25:50 +0100 | [diff] [blame] | 219 | if (WARN_ON(!local->ops->ampdu_action)) |
| 220 | return -EINVAL; |
| 221 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 222 | if ((tid >= STA_TID_NUM) || !(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION)) |
| 223 | return -EINVAL; |
| 224 | |
| 225 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 226 | printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n", |
| 227 | ra, tid); |
| 228 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 229 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 230 | if (hw->ampdu_queues && ieee80211_ac_from_tid(tid) == 0) { |
| 231 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 232 | printk(KERN_DEBUG "rejecting on voice AC\n"); |
| 233 | #endif |
| 234 | return -EINVAL; |
| 235 | } |
| 236 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 237 | rcu_read_lock(); |
| 238 | |
| 239 | sta = sta_info_get(local, ra); |
| 240 | if (!sta) { |
| 241 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 242 | printk(KERN_DEBUG "Could not find the station\n"); |
| 243 | #endif |
| 244 | ret = -ENOENT; |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 245 | goto unlock; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 246 | } |
| 247 | |
Johannes Berg | 8abd3f9 | 2009-02-10 21:25:47 +0100 | [diff] [blame] | 248 | /* |
| 249 | * The aggregation code is not prepared to handle |
| 250 | * anything but STA/AP due to the BSSID handling. |
| 251 | * IBSS could work in the code but isn't supported |
| 252 | * by drivers or the standard. |
| 253 | */ |
| 254 | if (sta->sdata->vif.type != NL80211_IFTYPE_STATION && |
| 255 | sta->sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
| 256 | sta->sdata->vif.type != NL80211_IFTYPE_AP) { |
| 257 | ret = -EINVAL; |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 258 | goto unlock; |
Johannes Berg | 8abd3f9 | 2009-02-10 21:25:47 +0100 | [diff] [blame] | 259 | } |
| 260 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 261 | spin_lock_bh(&sta->lock); |
| 262 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 263 | sdata = sta->sdata; |
| 264 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 265 | /* we have tried too many times, receiver does not want A-MPDU */ |
| 266 | if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) { |
| 267 | ret = -EBUSY; |
| 268 | goto err_unlock_sta; |
| 269 | } |
| 270 | |
| 271 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
| 272 | /* check if the TID is not in aggregation flow already */ |
| 273 | if (*state != HT_AGG_STATE_IDLE) { |
| 274 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 275 | printk(KERN_DEBUG "BA request denied - session is not " |
| 276 | "idle on tid %u\n", tid); |
| 277 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 278 | ret = -EAGAIN; |
| 279 | goto err_unlock_sta; |
| 280 | } |
| 281 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 282 | if (hw->ampdu_queues) { |
| 283 | spin_lock(&local->queue_stop_reason_lock); |
| 284 | /* reserve a new queue for this session */ |
| 285 | for (i = 0; i < local->hw.ampdu_queues; i++) { |
| 286 | if (local->ampdu_ac_queue[i] < 0) { |
| 287 | qn = i; |
| 288 | local->ampdu_ac_queue[qn] = |
| 289 | ieee80211_ac_from_tid(tid); |
| 290 | break; |
| 291 | } |
| 292 | } |
| 293 | spin_unlock(&local->queue_stop_reason_lock); |
| 294 | |
| 295 | if (qn < 0) { |
| 296 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 297 | printk(KERN_DEBUG "BA request denied - " |
| 298 | "queue unavailable for tid %d\n", tid); |
| 299 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 300 | ret = -ENOSPC; |
| 301 | goto err_unlock_sta; |
| 302 | } |
| 303 | |
| 304 | /* |
| 305 | * If we successfully allocate the session, we can't have |
| 306 | * anything going on on the queue this TID maps into, so |
| 307 | * stop it for now. This is a "virtual" stop using the same |
| 308 | * mechanism that drivers will use. |
| 309 | * |
| 310 | * XXX: queue up frames for this session in the sta_info |
| 311 | * struct instead to avoid hitting all other STAs. |
| 312 | */ |
| 313 | ieee80211_stop_queue_by_reason( |
| 314 | &local->hw, hw->queues + qn, |
| 315 | IEEE80211_QUEUE_STOP_REASON_AGGREGATION); |
| 316 | } |
| 317 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 318 | /* prepare A-MPDU MLME for Tx aggregation */ |
| 319 | sta->ampdu_mlme.tid_tx[tid] = |
| 320 | kmalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC); |
| 321 | if (!sta->ampdu_mlme.tid_tx[tid]) { |
| 322 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 323 | if (net_ratelimit()) |
| 324 | printk(KERN_ERR "allocate tx mlme to tid %d failed\n", |
| 325 | tid); |
| 326 | #endif |
| 327 | ret = -ENOMEM; |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 328 | goto err_return_queue; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 329 | } |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 330 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 331 | /* Tx timer */ |
| 332 | sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.function = |
| 333 | sta_addba_resp_timer_expired; |
| 334 | sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.data = |
| 335 | (unsigned long)&sta->timer_to_tid[tid]; |
| 336 | init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer); |
| 337 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 338 | /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the |
| 339 | * call back right away, it must see that the flow has begun */ |
| 340 | *state |= HT_ADDBA_REQUESTED_MSK; |
| 341 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 342 | start_seq_num = sta->tid_seq[tid]; |
| 343 | |
Johannes Berg | 23e6a7e | 2009-02-10 21:25:50 +0100 | [diff] [blame] | 344 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START, |
| 345 | &sta->sta, tid, &start_seq_num); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 346 | |
| 347 | if (ret) { |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 348 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 349 | printk(KERN_DEBUG "BA request denied - HW unavailable for" |
| 350 | " tid %d\n", tid); |
| 351 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 352 | *state = HT_AGG_STATE_IDLE; |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 353 | goto err_free; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 354 | } |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 355 | sta->tid_to_tx_q[tid] = qn; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 356 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 357 | spin_unlock_bh(&sta->lock); |
| 358 | |
| 359 | /* send an addBA request */ |
| 360 | sta->ampdu_mlme.dialog_token_allocator++; |
| 361 | sta->ampdu_mlme.tid_tx[tid]->dialog_token = |
| 362 | sta->ampdu_mlme.dialog_token_allocator; |
| 363 | sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num; |
| 364 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 365 | ieee80211_send_addba_request(sta->sdata, ra, tid, |
| 366 | sta->ampdu_mlme.tid_tx[tid]->dialog_token, |
| 367 | sta->ampdu_mlme.tid_tx[tid]->ssn, |
| 368 | 0x40, 5000); |
| 369 | /* activate the timer for the recipient's addBA response */ |
| 370 | sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires = |
| 371 | jiffies + ADDBA_RESP_INTERVAL; |
| 372 | add_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer); |
| 373 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 374 | printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid); |
| 375 | #endif |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 376 | goto unlock; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 377 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 378 | err_free: |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 379 | kfree(sta->ampdu_mlme.tid_tx[tid]); |
| 380 | sta->ampdu_mlme.tid_tx[tid] = NULL; |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 381 | err_return_queue: |
| 382 | if (qn >= 0) { |
| 383 | /* We failed, so start queue again right away. */ |
| 384 | ieee80211_wake_queue_by_reason(hw, hw->queues + qn, |
| 385 | IEEE80211_QUEUE_STOP_REASON_AGGREGATION); |
| 386 | /* give queue back to pool */ |
| 387 | spin_lock(&local->queue_stop_reason_lock); |
| 388 | local->ampdu_ac_queue[qn] = -1; |
| 389 | spin_unlock(&local->queue_stop_reason_lock); |
| 390 | } |
| 391 | err_unlock_sta: |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 392 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 393 | unlock: |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 394 | rcu_read_unlock(); |
| 395 | return ret; |
| 396 | } |
| 397 | EXPORT_SYMBOL(ieee80211_start_tx_ba_session); |
| 398 | |
| 399 | void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid) |
| 400 | { |
| 401 | struct ieee80211_local *local = hw_to_local(hw); |
| 402 | struct sta_info *sta; |
| 403 | u8 *state; |
| 404 | |
| 405 | if (tid >= STA_TID_NUM) { |
| 406 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 407 | printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n", |
| 408 | tid, STA_TID_NUM); |
| 409 | #endif |
| 410 | return; |
| 411 | } |
| 412 | |
| 413 | rcu_read_lock(); |
| 414 | sta = sta_info_get(local, ra); |
| 415 | if (!sta) { |
| 416 | rcu_read_unlock(); |
| 417 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 418 | printk(KERN_DEBUG "Could not find station: %pM\n", ra); |
| 419 | #endif |
| 420 | return; |
| 421 | } |
| 422 | |
| 423 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
| 424 | spin_lock_bh(&sta->lock); |
| 425 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 426 | if (WARN_ON(!(*state & HT_ADDBA_REQUESTED_MSK))) { |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 427 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 428 | printk(KERN_DEBUG "addBA was not requested yet, state is %d\n", |
| 429 | *state); |
| 430 | #endif |
| 431 | spin_unlock_bh(&sta->lock); |
| 432 | rcu_read_unlock(); |
| 433 | return; |
| 434 | } |
| 435 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 436 | if (WARN_ON(*state & HT_ADDBA_DRV_READY_MSK)) |
| 437 | goto out; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 438 | |
| 439 | *state |= HT_ADDBA_DRV_READY_MSK; |
| 440 | |
| 441 | if (*state == HT_AGG_STATE_OPERATIONAL) { |
| 442 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 443 | printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid); |
| 444 | #endif |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 445 | if (hw->ampdu_queues) { |
| 446 | /* |
| 447 | * Wake up this queue, we stopped it earlier, |
| 448 | * this will in turn wake the entire AC. |
| 449 | */ |
| 450 | ieee80211_wake_queue_by_reason(hw, |
| 451 | hw->queues + sta->tid_to_tx_q[tid], |
| 452 | IEEE80211_QUEUE_STOP_REASON_AGGREGATION); |
| 453 | } |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 454 | } |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 455 | |
| 456 | out: |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 457 | spin_unlock_bh(&sta->lock); |
| 458 | rcu_read_unlock(); |
| 459 | } |
| 460 | EXPORT_SYMBOL(ieee80211_start_tx_ba_cb); |
| 461 | |
Johannes Berg | 86ab6c5 | 2009-02-10 21:25:49 +0100 | [diff] [blame] | 462 | void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, |
| 463 | const u8 *ra, u16 tid) |
| 464 | { |
| 465 | struct ieee80211_local *local = hw_to_local(hw); |
| 466 | struct ieee80211_ra_tid *ra_tid; |
| 467 | struct sk_buff *skb = dev_alloc_skb(0); |
| 468 | |
| 469 | if (unlikely(!skb)) { |
| 470 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 471 | if (net_ratelimit()) |
| 472 | printk(KERN_WARNING "%s: Not enough memory, " |
| 473 | "dropping start BA session", skb->dev->name); |
| 474 | #endif |
| 475 | return; |
| 476 | } |
| 477 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; |
| 478 | memcpy(&ra_tid->ra, ra, ETH_ALEN); |
| 479 | ra_tid->tid = tid; |
| 480 | |
| 481 | skb->pkt_type = IEEE80211_ADDBA_MSG; |
| 482 | skb_queue_tail(&local->skb_queue, skb); |
| 483 | tasklet_schedule(&local->tasklet); |
| 484 | } |
| 485 | EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe); |
| 486 | |
Johannes Berg | 849b796 | 2009-02-10 21:25:54 +0100 | [diff] [blame] | 487 | int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid, |
| 488 | enum ieee80211_back_parties initiator) |
| 489 | { |
| 490 | u8 *state; |
| 491 | int ret; |
| 492 | |
| 493 | /* check if the TID is in aggregation */ |
| 494 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
| 495 | spin_lock_bh(&sta->lock); |
| 496 | |
| 497 | if (*state != HT_AGG_STATE_OPERATIONAL) { |
| 498 | ret = -ENOENT; |
| 499 | goto unlock; |
| 500 | } |
| 501 | |
| 502 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 503 | printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n", |
| 504 | sta->sta.addr, tid); |
| 505 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 506 | |
| 507 | ret = ___ieee80211_stop_tx_ba_session(sta, tid, initiator); |
| 508 | |
| 509 | unlock: |
| 510 | spin_unlock_bh(&sta->lock); |
| 511 | return ret; |
| 512 | } |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 513 | |
| 514 | int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw, |
| 515 | u8 *ra, u16 tid, |
| 516 | enum ieee80211_back_parties initiator) |
| 517 | { |
| 518 | struct ieee80211_local *local = hw_to_local(hw); |
| 519 | struct sta_info *sta; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 520 | int ret = 0; |
| 521 | |
Johannes Berg | 23e6a7e | 2009-02-10 21:25:50 +0100 | [diff] [blame] | 522 | if (WARN_ON(!local->ops->ampdu_action)) |
| 523 | return -EINVAL; |
| 524 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 525 | if (tid >= STA_TID_NUM) |
| 526 | return -EINVAL; |
| 527 | |
| 528 | rcu_read_lock(); |
| 529 | sta = sta_info_get(local, ra); |
| 530 | if (!sta) { |
| 531 | rcu_read_unlock(); |
| 532 | return -ENOENT; |
| 533 | } |
| 534 | |
Johannes Berg | 849b796 | 2009-02-10 21:25:54 +0100 | [diff] [blame] | 535 | ret = __ieee80211_stop_tx_ba_session(sta, tid, initiator); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 536 | rcu_read_unlock(); |
| 537 | return ret; |
| 538 | } |
| 539 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_session); |
| 540 | |
| 541 | void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid) |
| 542 | { |
| 543 | struct ieee80211_local *local = hw_to_local(hw); |
| 544 | struct sta_info *sta; |
| 545 | u8 *state; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 546 | |
| 547 | if (tid >= STA_TID_NUM) { |
| 548 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 549 | printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n", |
| 550 | tid, STA_TID_NUM); |
| 551 | #endif |
| 552 | return; |
| 553 | } |
| 554 | |
| 555 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 556 | printk(KERN_DEBUG "Stopping Tx BA session for %pM tid %d\n", |
| 557 | ra, tid); |
| 558 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 559 | |
| 560 | rcu_read_lock(); |
| 561 | sta = sta_info_get(local, ra); |
| 562 | if (!sta) { |
| 563 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 564 | printk(KERN_DEBUG "Could not find station: %pM\n", ra); |
| 565 | #endif |
| 566 | rcu_read_unlock(); |
| 567 | return; |
| 568 | } |
| 569 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
| 570 | |
| 571 | /* NOTE: no need to use sta->lock in this state check, as |
| 572 | * ieee80211_stop_tx_ba_session will let only one stop call to |
| 573 | * pass through per sta/tid |
| 574 | */ |
| 575 | if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) { |
| 576 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 577 | printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n"); |
| 578 | #endif |
| 579 | rcu_read_unlock(); |
| 580 | return; |
| 581 | } |
| 582 | |
| 583 | if (*state & HT_AGG_STATE_INITIATOR_MSK) |
| 584 | ieee80211_send_delba(sta->sdata, ra, tid, |
| 585 | WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE); |
| 586 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 587 | spin_lock_bh(&sta->lock); |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 588 | |
| 589 | if (*state & HT_AGG_STATE_INITIATOR_MSK && |
| 590 | hw->ampdu_queues) { |
| 591 | /* |
| 592 | * Wake up this queue, we stopped it earlier, |
| 593 | * this will in turn wake the entire AC. |
| 594 | */ |
| 595 | ieee80211_wake_queue_by_reason(hw, |
| 596 | hw->queues + sta->tid_to_tx_q[tid], |
| 597 | IEEE80211_QUEUE_STOP_REASON_AGGREGATION); |
| 598 | } |
| 599 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 600 | *state = HT_AGG_STATE_IDLE; |
| 601 | sta->ampdu_mlme.addba_req_num[tid] = 0; |
| 602 | kfree(sta->ampdu_mlme.tid_tx[tid]); |
| 603 | sta->ampdu_mlme.tid_tx[tid] = NULL; |
| 604 | spin_unlock_bh(&sta->lock); |
| 605 | |
| 606 | rcu_read_unlock(); |
| 607 | } |
| 608 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb); |
| 609 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 610 | void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, |
| 611 | const u8 *ra, u16 tid) |
| 612 | { |
| 613 | struct ieee80211_local *local = hw_to_local(hw); |
| 614 | struct ieee80211_ra_tid *ra_tid; |
| 615 | struct sk_buff *skb = dev_alloc_skb(0); |
| 616 | |
| 617 | if (unlikely(!skb)) { |
| 618 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 619 | if (net_ratelimit()) |
| 620 | printk(KERN_WARNING "%s: Not enough memory, " |
| 621 | "dropping stop BA session", skb->dev->name); |
| 622 | #endif |
| 623 | return; |
| 624 | } |
| 625 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; |
| 626 | memcpy(&ra_tid->ra, ra, ETH_ALEN); |
| 627 | ra_tid->tid = tid; |
| 628 | |
| 629 | skb->pkt_type = IEEE80211_DELBA_MSG; |
| 630 | skb_queue_tail(&local->skb_queue, skb); |
| 631 | tasklet_schedule(&local->tasklet); |
| 632 | } |
| 633 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe); |
| 634 | |
Johannes Berg | 86ab6c5 | 2009-02-10 21:25:49 +0100 | [diff] [blame] | 635 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 636 | void ieee80211_process_addba_resp(struct ieee80211_local *local, |
| 637 | struct sta_info *sta, |
| 638 | struct ieee80211_mgmt *mgmt, |
| 639 | size_t len) |
| 640 | { |
| 641 | struct ieee80211_hw *hw = &local->hw; |
| 642 | u16 capab; |
| 643 | u16 tid, start_seq_num; |
| 644 | u8 *state; |
| 645 | |
| 646 | capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab); |
| 647 | tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; |
| 648 | |
| 649 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
| 650 | |
| 651 | spin_lock_bh(&sta->lock); |
| 652 | |
| 653 | if (!(*state & HT_ADDBA_REQUESTED_MSK)) { |
| 654 | spin_unlock_bh(&sta->lock); |
| 655 | return; |
| 656 | } |
| 657 | |
| 658 | if (mgmt->u.action.u.addba_resp.dialog_token != |
| 659 | sta->ampdu_mlme.tid_tx[tid]->dialog_token) { |
| 660 | spin_unlock_bh(&sta->lock); |
| 661 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 662 | printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid); |
| 663 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 664 | return; |
| 665 | } |
| 666 | |
| 667 | del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer); |
| 668 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 669 | printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid); |
| 670 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 671 | if (le16_to_cpu(mgmt->u.action.u.addba_resp.status) |
| 672 | == WLAN_STATUS_SUCCESS) { |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 673 | u8 curstate = *state; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 674 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 675 | *state |= HT_ADDBA_RECEIVED_MSK; |
| 676 | |
| 677 | if (hw->ampdu_queues && *state != curstate && |
| 678 | *state == HT_AGG_STATE_OPERATIONAL) { |
| 679 | /* |
| 680 | * Wake up this queue, we stopped it earlier, |
| 681 | * this will in turn wake the entire AC. |
| 682 | */ |
| 683 | ieee80211_wake_queue_by_reason(hw, |
| 684 | hw->queues + sta->tid_to_tx_q[tid], |
| 685 | IEEE80211_QUEUE_STOP_REASON_AGGREGATION); |
| 686 | } |
| 687 | sta->ampdu_mlme.addba_req_num[tid] = 0; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 688 | |
| 689 | if (local->ops->ampdu_action) { |
| 690 | (void)local->ops->ampdu_action(hw, |
| 691 | IEEE80211_AMPDU_TX_RESUME, |
| 692 | &sta->sta, tid, &start_seq_num); |
| 693 | } |
| 694 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 695 | printk(KERN_DEBUG "Resuming TX aggregation for tid %d\n", tid); |
| 696 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 697 | } else { |
| 698 | sta->ampdu_mlme.addba_req_num[tid]++; |
Johannes Berg | 849b796 | 2009-02-10 21:25:54 +0100 | [diff] [blame] | 699 | ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 700 | } |
Johannes Berg | 849b796 | 2009-02-10 21:25:54 +0100 | [diff] [blame] | 701 | spin_unlock_bh(&sta->lock); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 702 | } |