Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004-2011 Atheros Communications Inc. |
Vasanthakumar Thiagarajan | 1b2df40 | 2012-02-06 20:15:53 +0530 | [diff] [blame] | 3 | * Copyright (c) 2011-2012 Qualcomm Atheros, Inc. |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 4 | * |
| 5 | * Permission to use, copy, modify, and/or distribute this software for any |
| 6 | * purpose with or without fee is hereby granted, provided that the above |
| 7 | * copyright notice and this permission notice appear in all copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | */ |
| 17 | |
Joe Perches | 516304b | 2012-03-18 17:30:52 -0700 | [diff] [blame] | 18 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 19 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 20 | #include "core.h" |
| 21 | #include "debug.h" |
Kalle Valo | e76ac2bf | 2012-03-25 17:15:27 +0300 | [diff] [blame] | 22 | #include "htc-ops.h" |
Kalle Valo | 416cf0b | 2013-03-18 13:42:20 +0200 | [diff] [blame] | 23 | #include "trace.h" |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 24 | |
Vasanthakumar Thiagarajan | 3fdc099 | 2012-01-21 15:22:52 +0530 | [diff] [blame] | 25 | /* |
| 26 | * tid - tid_mux0..tid_mux3 |
| 27 | * aid - tid_mux4..tid_mux7 |
| 28 | */ |
| 29 | #define ATH6KL_TID_MASK 0xf |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 30 | #define ATH6KL_AID_SHIFT 4 |
Vasanthakumar Thiagarajan | 3fdc099 | 2012-01-21 15:22:52 +0530 | [diff] [blame] | 31 | |
| 32 | static inline u8 ath6kl_get_tid(u8 tid_mux) |
| 33 | { |
| 34 | return tid_mux & ATH6KL_TID_MASK; |
| 35 | } |
| 36 | |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 37 | static inline u8 ath6kl_get_aid(u8 tid_mux) |
| 38 | { |
| 39 | return tid_mux >> ATH6KL_AID_SHIFT; |
| 40 | } |
| 41 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 42 | static u8 ath6kl_ibss_map_epid(struct sk_buff *skb, struct net_device *dev, |
| 43 | u32 *map_no) |
| 44 | { |
| 45 | struct ath6kl *ar = ath6kl_priv(dev); |
| 46 | struct ethhdr *eth_hdr; |
| 47 | u32 i, ep_map = -1; |
| 48 | u8 *datap; |
| 49 | |
| 50 | *map_no = 0; |
| 51 | datap = skb->data; |
| 52 | eth_hdr = (struct ethhdr *) (datap + sizeof(struct wmi_data_hdr)); |
| 53 | |
| 54 | if (is_multicast_ether_addr(eth_hdr->h_dest)) |
| 55 | return ENDPOINT_2; |
| 56 | |
| 57 | for (i = 0; i < ar->node_num; i++) { |
| 58 | if (memcmp(eth_hdr->h_dest, ar->node_map[i].mac_addr, |
| 59 | ETH_ALEN) == 0) { |
| 60 | *map_no = i + 1; |
| 61 | ar->node_map[i].tx_pend++; |
| 62 | return ar->node_map[i].ep_id; |
| 63 | } |
| 64 | |
| 65 | if ((ep_map == -1) && !ar->node_map[i].tx_pend) |
| 66 | ep_map = i; |
| 67 | } |
| 68 | |
| 69 | if (ep_map == -1) { |
| 70 | ep_map = ar->node_num; |
| 71 | ar->node_num++; |
| 72 | if (ar->node_num > MAX_NODE_NUM) |
| 73 | return ENDPOINT_UNUSED; |
| 74 | } |
| 75 | |
| 76 | memcpy(ar->node_map[ep_map].mac_addr, eth_hdr->h_dest, ETH_ALEN); |
| 77 | |
| 78 | for (i = ENDPOINT_2; i <= ENDPOINT_5; i++) { |
| 79 | if (!ar->tx_pending[i]) { |
| 80 | ar->node_map[ep_map].ep_id = i; |
| 81 | break; |
| 82 | } |
| 83 | |
| 84 | /* |
| 85 | * No free endpoint is available, start redistribution on |
| 86 | * the inuse endpoints. |
| 87 | */ |
| 88 | if (i == ENDPOINT_5) { |
| 89 | ar->node_map[ep_map].ep_id = ar->next_ep_id; |
| 90 | ar->next_ep_id++; |
| 91 | if (ar->next_ep_id > ENDPOINT_5) |
| 92 | ar->next_ep_id = ENDPOINT_2; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | *map_no = ep_map + 1; |
| 97 | ar->node_map[ep_map].tx_pend++; |
| 98 | |
| 99 | return ar->node_map[ep_map].ep_id; |
| 100 | } |
| 101 | |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 102 | static bool ath6kl_process_uapsdq(struct ath6kl_sta *conn, |
| 103 | struct ath6kl_vif *vif, |
| 104 | struct sk_buff *skb, |
| 105 | u32 *flags) |
| 106 | { |
| 107 | struct ath6kl *ar = vif->ar; |
| 108 | bool is_apsdq_empty = false; |
| 109 | struct ethhdr *datap = (struct ethhdr *) skb->data; |
Kalle Valo | e572602 | 2012-01-17 15:05:46 +0200 | [diff] [blame] | 110 | u8 up = 0, traffic_class, *ip_hdr; |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 111 | u16 ether_type; |
| 112 | struct ath6kl_llc_snap_hdr *llc_hdr; |
| 113 | |
| 114 | if (conn->sta_flags & STA_PS_APSD_TRIGGER) { |
| 115 | /* |
| 116 | * This tx is because of a uAPSD trigger, determine |
| 117 | * more and EOSP bit. Set EOSP if queue is empty |
| 118 | * or sufficient frames are delivered for this trigger. |
| 119 | */ |
| 120 | spin_lock_bh(&conn->psq_lock); |
| 121 | if (!skb_queue_empty(&conn->apsdq)) |
| 122 | *flags |= WMI_DATA_HDR_FLAGS_MORE; |
| 123 | else if (conn->sta_flags & STA_PS_APSD_EOSP) |
| 124 | *flags |= WMI_DATA_HDR_FLAGS_EOSP; |
| 125 | *flags |= WMI_DATA_HDR_FLAGS_UAPSD; |
| 126 | spin_unlock_bh(&conn->psq_lock); |
| 127 | return false; |
Kalle Valo | a5d8f9d | 2014-03-11 12:58:01 +0200 | [diff] [blame] | 128 | } else if (!conn->apsd_info) { |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 129 | return false; |
Kalle Valo | a5d8f9d | 2014-03-11 12:58:01 +0200 | [diff] [blame] | 130 | } |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 131 | |
| 132 | if (test_bit(WMM_ENABLED, &vif->flags)) { |
| 133 | ether_type = be16_to_cpu(datap->h_proto); |
| 134 | if (is_ethertype(ether_type)) { |
| 135 | /* packet is in DIX format */ |
| 136 | ip_hdr = (u8 *)(datap + 1); |
| 137 | } else { |
| 138 | /* packet is in 802.3 format */ |
| 139 | llc_hdr = (struct ath6kl_llc_snap_hdr *) |
| 140 | (datap + 1); |
| 141 | ether_type = be16_to_cpu(llc_hdr->eth_type); |
| 142 | ip_hdr = (u8 *)(llc_hdr + 1); |
| 143 | } |
| 144 | |
| 145 | if (ether_type == IP_ETHERTYPE) |
| 146 | up = ath6kl_wmi_determine_user_priority( |
| 147 | ip_hdr, 0); |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | traffic_class = ath6kl_wmi_get_traffic_class(up); |
| 151 | |
| 152 | if ((conn->apsd_info & (1 << traffic_class)) == 0) |
| 153 | return false; |
| 154 | |
| 155 | /* Queue the frames if the STA is sleeping */ |
| 156 | spin_lock_bh(&conn->psq_lock); |
| 157 | is_apsdq_empty = skb_queue_empty(&conn->apsdq); |
| 158 | skb_queue_tail(&conn->apsdq, skb); |
| 159 | spin_unlock_bh(&conn->psq_lock); |
| 160 | |
| 161 | /* |
| 162 | * If this is the first pkt getting queued |
| 163 | * for this STA, update the PVB for this STA |
| 164 | */ |
| 165 | if (is_apsdq_empty) { |
| 166 | ath6kl_wmi_set_apsd_bfrd_traf(ar->wmi, |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 167 | vif->fw_vif_idx, |
| 168 | conn->aid, 1, 0); |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 169 | } |
| 170 | *flags |= WMI_DATA_HDR_FLAGS_UAPSD; |
| 171 | |
| 172 | return true; |
| 173 | } |
| 174 | |
| 175 | static bool ath6kl_process_psq(struct ath6kl_sta *conn, |
| 176 | struct ath6kl_vif *vif, |
| 177 | struct sk_buff *skb, |
| 178 | u32 *flags) |
| 179 | { |
| 180 | bool is_psq_empty = false; |
| 181 | struct ath6kl *ar = vif->ar; |
| 182 | |
| 183 | if (conn->sta_flags & STA_PS_POLLED) { |
| 184 | spin_lock_bh(&conn->psq_lock); |
| 185 | if (!skb_queue_empty(&conn->psq)) |
| 186 | *flags |= WMI_DATA_HDR_FLAGS_MORE; |
| 187 | spin_unlock_bh(&conn->psq_lock); |
| 188 | return false; |
| 189 | } |
| 190 | |
| 191 | /* Queue the frames if the STA is sleeping */ |
| 192 | spin_lock_bh(&conn->psq_lock); |
| 193 | is_psq_empty = skb_queue_empty(&conn->psq); |
| 194 | skb_queue_tail(&conn->psq, skb); |
| 195 | spin_unlock_bh(&conn->psq_lock); |
| 196 | |
| 197 | /* |
| 198 | * If this is the first pkt getting queued |
| 199 | * for this STA, update the PVB for this |
| 200 | * STA. |
| 201 | */ |
| 202 | if (is_psq_empty) |
| 203 | ath6kl_wmi_set_pvb_cmd(ar->wmi, |
| 204 | vif->fw_vif_idx, |
| 205 | conn->aid, 1); |
| 206 | return true; |
| 207 | } |
| 208 | |
Vasanthakumar Thiagarajan | 6765d0a | 2011-10-25 19:34:17 +0530 | [diff] [blame] | 209 | static bool ath6kl_powersave_ap(struct ath6kl_vif *vif, struct sk_buff *skb, |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 210 | u32 *flags) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 211 | { |
| 212 | struct ethhdr *datap = (struct ethhdr *) skb->data; |
| 213 | struct ath6kl_sta *conn = NULL; |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 214 | bool ps_queued = false; |
Vasanthakumar Thiagarajan | 6765d0a | 2011-10-25 19:34:17 +0530 | [diff] [blame] | 215 | struct ath6kl *ar = vif->ar; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 216 | |
| 217 | if (is_multicast_ether_addr(datap->h_dest)) { |
| 218 | u8 ctr = 0; |
| 219 | bool q_mcast = false; |
| 220 | |
| 221 | for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) { |
| 222 | if (ar->sta_list[ctr].sta_flags & STA_PS_SLEEP) { |
| 223 | q_mcast = true; |
| 224 | break; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | if (q_mcast) { |
| 229 | /* |
| 230 | * If this transmit is not because of a Dtim Expiry |
| 231 | * q it. |
| 232 | */ |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 233 | if (!test_bit(DTIM_EXPIRED, &vif->flags)) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 234 | bool is_mcastq_empty = false; |
| 235 | |
| 236 | spin_lock_bh(&ar->mcastpsq_lock); |
| 237 | is_mcastq_empty = |
| 238 | skb_queue_empty(&ar->mcastpsq); |
| 239 | skb_queue_tail(&ar->mcastpsq, skb); |
| 240 | spin_unlock_bh(&ar->mcastpsq_lock); |
| 241 | |
| 242 | /* |
| 243 | * If this is the first Mcast pkt getting |
| 244 | * queued indicate to the target to set the |
| 245 | * BitmapControl LSB of the TIM IE. |
| 246 | */ |
| 247 | if (is_mcastq_empty) |
| 248 | ath6kl_wmi_set_pvb_cmd(ar->wmi, |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 249 | vif->fw_vif_idx, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 250 | MCAST_AID, 1); |
| 251 | |
| 252 | ps_queued = true; |
| 253 | } else { |
| 254 | /* |
| 255 | * This transmit is because of Dtim expiry. |
| 256 | * Determine if MoreData bit has to be set. |
| 257 | */ |
| 258 | spin_lock_bh(&ar->mcastpsq_lock); |
| 259 | if (!skb_queue_empty(&ar->mcastpsq)) |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 260 | *flags |= WMI_DATA_HDR_FLAGS_MORE; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 261 | spin_unlock_bh(&ar->mcastpsq_lock); |
| 262 | } |
| 263 | } |
| 264 | } else { |
Vasanthakumar Thiagarajan | 6765d0a | 2011-10-25 19:34:17 +0530 | [diff] [blame] | 265 | conn = ath6kl_find_sta(vif, datap->h_dest); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 266 | if (!conn) { |
| 267 | dev_kfree_skb(skb); |
| 268 | |
| 269 | /* Inform the caller that the skb is consumed */ |
| 270 | return true; |
| 271 | } |
| 272 | |
| 273 | if (conn->sta_flags & STA_PS_SLEEP) { |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 274 | ps_queued = ath6kl_process_uapsdq(conn, |
| 275 | vif, skb, flags); |
| 276 | if (!(*flags & WMI_DATA_HDR_FLAGS_UAPSD)) |
| 277 | ps_queued = ath6kl_process_psq(conn, |
| 278 | vif, skb, flags); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 279 | } |
| 280 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 281 | return ps_queued; |
| 282 | } |
| 283 | |
| 284 | /* Tx functions */ |
| 285 | |
| 286 | int ath6kl_control_tx(void *devt, struct sk_buff *skb, |
| 287 | enum htc_endpoint_id eid) |
| 288 | { |
| 289 | struct ath6kl *ar = devt; |
| 290 | int status = 0; |
| 291 | struct ath6kl_cookie *cookie = NULL; |
| 292 | |
Kalle Valo | 416cf0b | 2013-03-18 13:42:20 +0200 | [diff] [blame] | 293 | trace_ath6kl_wmi_cmd(skb->data, skb->len); |
| 294 | |
Vasanthakumar Thiagarajan | 58109df | 2012-09-11 12:07:00 +0530 | [diff] [blame] | 295 | if (WARN_ON_ONCE(ar->state == ATH6KL_STATE_WOW)) { |
Vasanthakumar Thiagarajan | 0616dc1 | 2012-08-14 10:10:33 +0530 | [diff] [blame] | 296 | dev_kfree_skb(skb); |
Raja Mani | 390a8c8 | 2012-03-07 11:35:04 +0530 | [diff] [blame] | 297 | return -EACCES; |
Vasanthakumar Thiagarajan | 0616dc1 | 2012-08-14 10:10:33 +0530 | [diff] [blame] | 298 | } |
Raja Mani | 390a8c8 | 2012-03-07 11:35:04 +0530 | [diff] [blame] | 299 | |
Raja Mani | 363f149 | 2012-09-21 15:08:55 +0530 | [diff] [blame] | 300 | if (WARN_ON_ONCE(eid == ENDPOINT_UNUSED || |
| 301 | eid >= ENDPOINT_MAX)) { |
| 302 | status = -EINVAL; |
| 303 | goto fail_ctrl_tx; |
| 304 | } |
| 305 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 306 | spin_lock_bh(&ar->lock); |
| 307 | |
| 308 | ath6kl_dbg(ATH6KL_DBG_WLAN_TX, |
| 309 | "%s: skb=0x%p, len=0x%x eid =%d\n", __func__, |
| 310 | skb, skb->len, eid); |
| 311 | |
| 312 | if (test_bit(WMI_CTRL_EP_FULL, &ar->flag) && (eid == ar->ctrl_ep)) { |
| 313 | /* |
| 314 | * Control endpoint is full, don't allocate resources, we |
| 315 | * are just going to drop this packet. |
| 316 | */ |
| 317 | cookie = NULL; |
| 318 | ath6kl_err("wmi ctrl ep full, dropping pkt : 0x%p, len:%d\n", |
| 319 | skb, skb->len); |
Kalle Valo | a5d8f9d | 2014-03-11 12:58:01 +0200 | [diff] [blame] | 320 | } else { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 321 | cookie = ath6kl_alloc_cookie(ar); |
Kalle Valo | a5d8f9d | 2014-03-11 12:58:01 +0200 | [diff] [blame] | 322 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 323 | |
| 324 | if (cookie == NULL) { |
| 325 | spin_unlock_bh(&ar->lock); |
| 326 | status = -ENOMEM; |
| 327 | goto fail_ctrl_tx; |
| 328 | } |
| 329 | |
| 330 | ar->tx_pending[eid]++; |
| 331 | |
| 332 | if (eid != ar->ctrl_ep) |
| 333 | ar->total_tx_data_pend++; |
| 334 | |
| 335 | spin_unlock_bh(&ar->lock); |
| 336 | |
| 337 | cookie->skb = skb; |
| 338 | cookie->map_no = 0; |
| 339 | set_htc_pkt_info(&cookie->htc_pkt, cookie, skb->data, skb->len, |
| 340 | eid, ATH6KL_CONTROL_PKT_TAG); |
Kalle Valo | cfc10f2 | 2012-03-25 17:15:24 +0300 | [diff] [blame] | 341 | cookie->htc_pkt.skb = skb; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 342 | |
| 343 | /* |
| 344 | * This interface is asynchronous, if there is an error, cleanup |
| 345 | * will happen in the TX completion callback. |
| 346 | */ |
Kalle Valo | ad226ec | 2011-08-10 09:49:12 +0300 | [diff] [blame] | 347 | ath6kl_htc_tx(ar->htc_target, &cookie->htc_pkt); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 348 | |
| 349 | return 0; |
| 350 | |
| 351 | fail_ctrl_tx: |
| 352 | dev_kfree_skb(skb); |
| 353 | return status; |
| 354 | } |
| 355 | |
| 356 | int ath6kl_data_tx(struct sk_buff *skb, struct net_device *dev) |
| 357 | { |
| 358 | struct ath6kl *ar = ath6kl_priv(dev); |
| 359 | struct ath6kl_cookie *cookie = NULL; |
| 360 | enum htc_endpoint_id eid = ENDPOINT_UNUSED; |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 361 | struct ath6kl_vif *vif = netdev_priv(dev); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 362 | u32 map_no = 0; |
| 363 | u16 htc_tag = ATH6KL_DATA_PKT_TAG; |
Kalle Valo | c28d555 | 2014-03-11 12:58:02 +0200 | [diff] [blame] | 364 | u8 ac = 99; /* initialize to unmapped ac */ |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 365 | bool chk_adhoc_ps_mapping = false; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 366 | int ret; |
Rishi Panjwani | bc48ad3 | 2011-12-27 14:28:00 -0800 | [diff] [blame] | 367 | struct wmi_tx_meta_v2 meta_v2; |
| 368 | void *meta; |
| 369 | u8 csum_start = 0, csum_dest = 0, csum = skb->ip_summed; |
| 370 | u8 meta_ver = 0; |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 371 | u32 flags = 0; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 372 | |
| 373 | ath6kl_dbg(ATH6KL_DBG_WLAN_TX, |
| 374 | "%s: skb=0x%p, data=0x%p, len=0x%x\n", __func__, |
| 375 | skb, skb->data, skb->len); |
| 376 | |
| 377 | /* If target is not associated */ |
Vasanthakumar Thiagarajan | 1881ced | 2012-04-26 20:26:13 +0530 | [diff] [blame] | 378 | if (!test_bit(CONNECTED, &vif->flags)) |
| 379 | goto fail_tx; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 380 | |
Vasanthakumar Thiagarajan | 1881ced | 2012-04-26 20:26:13 +0530 | [diff] [blame] | 381 | if (WARN_ON_ONCE(ar->state != ATH6KL_STATE_ON)) |
| 382 | goto fail_tx; |
Raja Mani | 390a8c8 | 2012-03-07 11:35:04 +0530 | [diff] [blame] | 383 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 384 | if (!test_bit(WMI_READY, &ar->flag)) |
| 385 | goto fail_tx; |
| 386 | |
| 387 | /* AP mode Power saving processing */ |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 388 | if (vif->nw_type == AP_NETWORK) { |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 389 | if (ath6kl_powersave_ap(vif, skb, &flags)) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | if (test_bit(WMI_ENABLED, &ar->flag)) { |
Rishi Panjwani | bc48ad3 | 2011-12-27 14:28:00 -0800 | [diff] [blame] | 394 | if ((dev->features & NETIF_F_IP_CSUM) && |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 395 | (csum == CHECKSUM_PARTIAL)) { |
Rishi Panjwani | bc48ad3 | 2011-12-27 14:28:00 -0800 | [diff] [blame] | 396 | csum_start = skb->csum_start - |
| 397 | (skb_network_header(skb) - skb->head) + |
| 398 | sizeof(struct ath6kl_llc_snap_hdr); |
| 399 | csum_dest = skb->csum_offset + csum_start; |
| 400 | } |
| 401 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 402 | if (skb_headroom(skb) < dev->needed_headroom) { |
Vasanthakumar Thiagarajan | a29517c | 2011-11-04 15:48:51 +0530 | [diff] [blame] | 403 | struct sk_buff *tmp_skb = skb; |
| 404 | |
| 405 | skb = skb_realloc_headroom(skb, dev->needed_headroom); |
| 406 | kfree_skb(tmp_skb); |
| 407 | if (skb == NULL) { |
| 408 | vif->net_stats.tx_dropped++; |
| 409 | return 0; |
| 410 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | if (ath6kl_wmi_dix_2_dot3(ar->wmi, skb)) { |
| 414 | ath6kl_err("ath6kl_wmi_dix_2_dot3 failed\n"); |
| 415 | goto fail_tx; |
| 416 | } |
| 417 | |
Rishi Panjwani | bc48ad3 | 2011-12-27 14:28:00 -0800 | [diff] [blame] | 418 | if ((dev->features & NETIF_F_IP_CSUM) && |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 419 | (csum == CHECKSUM_PARTIAL)) { |
Rishi Panjwani | bc48ad3 | 2011-12-27 14:28:00 -0800 | [diff] [blame] | 420 | meta_v2.csum_start = csum_start; |
| 421 | meta_v2.csum_dest = csum_dest; |
| 422 | |
| 423 | /* instruct target to calculate checksum */ |
| 424 | meta_v2.csum_flags = WMI_META_V2_FLAG_CSUM_OFFLOAD; |
| 425 | meta_ver = WMI_META_VERSION_2; |
| 426 | meta = &meta_v2; |
| 427 | } else { |
| 428 | meta_ver = 0; |
| 429 | meta = NULL; |
| 430 | } |
| 431 | |
| 432 | ret = ath6kl_wmi_data_hdr_add(ar->wmi, skb, |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 433 | DATA_MSGTYPE, flags, 0, |
Rishi Panjwani | bc48ad3 | 2011-12-27 14:28:00 -0800 | [diff] [blame] | 434 | meta_ver, |
| 435 | meta, vif->fw_vif_idx); |
| 436 | |
| 437 | if (ret) { |
| 438 | ath6kl_warn("failed to add wmi data header:%d\n" |
| 439 | , ret); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 440 | goto fail_tx; |
| 441 | } |
| 442 | |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 443 | if ((vif->nw_type == ADHOC_NETWORK) && |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 444 | ar->ibss_ps_enable && test_bit(CONNECTED, &vif->flags)) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 445 | chk_adhoc_ps_mapping = true; |
| 446 | else { |
| 447 | /* get the stream mapping */ |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 448 | ret = ath6kl_wmi_implicit_create_pstream(ar->wmi, |
| 449 | vif->fw_vif_idx, skb, |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 450 | 0, test_bit(WMM_ENABLED, &vif->flags), &ac); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 451 | if (ret) |
| 452 | goto fail_tx; |
| 453 | } |
Kalle Valo | a5d8f9d | 2014-03-11 12:58:01 +0200 | [diff] [blame] | 454 | } else { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 455 | goto fail_tx; |
Kalle Valo | a5d8f9d | 2014-03-11 12:58:01 +0200 | [diff] [blame] | 456 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 457 | |
| 458 | spin_lock_bh(&ar->lock); |
| 459 | |
| 460 | if (chk_adhoc_ps_mapping) |
| 461 | eid = ath6kl_ibss_map_epid(skb, dev, &map_no); |
| 462 | else |
| 463 | eid = ar->ac2ep_map[ac]; |
| 464 | |
| 465 | if (eid == 0 || eid == ENDPOINT_UNUSED) { |
| 466 | ath6kl_err("eid %d is not mapped!\n", eid); |
| 467 | spin_unlock_bh(&ar->lock); |
| 468 | goto fail_tx; |
| 469 | } |
| 470 | |
| 471 | /* allocate resource for this packet */ |
| 472 | cookie = ath6kl_alloc_cookie(ar); |
| 473 | |
| 474 | if (!cookie) { |
| 475 | spin_unlock_bh(&ar->lock); |
| 476 | goto fail_tx; |
| 477 | } |
| 478 | |
| 479 | /* update counts while the lock is held */ |
| 480 | ar->tx_pending[eid]++; |
| 481 | ar->total_tx_data_pend++; |
| 482 | |
| 483 | spin_unlock_bh(&ar->lock); |
| 484 | |
Jouni Malinen | 00b1edf | 2011-09-27 11:00:08 +0300 | [diff] [blame] | 485 | if (!IS_ALIGNED((unsigned long) skb->data - HTC_HDR_LENGTH, 4) && |
| 486 | skb_cloned(skb)) { |
| 487 | /* |
| 488 | * We will touch (move the buffer data to align it. Since the |
| 489 | * skb buffer is cloned and not only the header is changed, we |
| 490 | * have to copy it to allow the changes. Since we are copying |
| 491 | * the data here, we may as well align it by reserving suitable |
| 492 | * headroom to avoid the memmove in ath6kl_htc_tx_buf_align(). |
| 493 | */ |
| 494 | struct sk_buff *nskb; |
| 495 | |
| 496 | nskb = skb_copy_expand(skb, HTC_HDR_LENGTH, 0, GFP_ATOMIC); |
| 497 | if (nskb == NULL) |
| 498 | goto fail_tx; |
| 499 | kfree_skb(skb); |
| 500 | skb = nskb; |
| 501 | } |
| 502 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 503 | cookie->skb = skb; |
| 504 | cookie->map_no = map_no; |
| 505 | set_htc_pkt_info(&cookie->htc_pkt, cookie, skb->data, skb->len, |
| 506 | eid, htc_tag); |
Kalle Valo | cfc10f2 | 2012-03-25 17:15:24 +0300 | [diff] [blame] | 507 | cookie->htc_pkt.skb = skb; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 508 | |
Kalle Valo | ef09410 | 2011-09-27 14:30:45 +0300 | [diff] [blame] | 509 | ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, __func__, "tx ", |
| 510 | skb->data, skb->len); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 511 | |
| 512 | /* |
| 513 | * HTC interface is asynchronous, if this fails, cleanup will |
| 514 | * happen in the ath6kl_tx_complete callback. |
| 515 | */ |
Kalle Valo | ad226ec | 2011-08-10 09:49:12 +0300 | [diff] [blame] | 516 | ath6kl_htc_tx(ar->htc_target, &cookie->htc_pkt); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 517 | |
| 518 | return 0; |
| 519 | |
| 520 | fail_tx: |
| 521 | dev_kfree_skb(skb); |
| 522 | |
Vasanthakumar Thiagarajan | b95907a | 2011-10-25 19:34:11 +0530 | [diff] [blame] | 523 | vif->net_stats.tx_dropped++; |
| 524 | vif->net_stats.tx_aborted_errors++; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 525 | |
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | /* indicate tx activity or inactivity on a WMI stream */ |
| 530 | void ath6kl_indicate_tx_activity(void *devt, u8 traffic_class, bool active) |
| 531 | { |
| 532 | struct ath6kl *ar = devt; |
| 533 | enum htc_endpoint_id eid; |
| 534 | int i; |
| 535 | |
| 536 | eid = ar->ac2ep_map[traffic_class]; |
| 537 | |
| 538 | if (!test_bit(WMI_ENABLED, &ar->flag)) |
| 539 | goto notify_htc; |
| 540 | |
| 541 | spin_lock_bh(&ar->lock); |
| 542 | |
| 543 | ar->ac_stream_active[traffic_class] = active; |
| 544 | |
| 545 | if (active) { |
| 546 | /* |
| 547 | * Keep track of the active stream with the highest |
| 548 | * priority. |
| 549 | */ |
| 550 | if (ar->ac_stream_pri_map[traffic_class] > |
| 551 | ar->hiac_stream_active_pri) |
| 552 | /* set the new highest active priority */ |
| 553 | ar->hiac_stream_active_pri = |
| 554 | ar->ac_stream_pri_map[traffic_class]; |
| 555 | |
| 556 | } else { |
| 557 | /* |
| 558 | * We may have to search for the next active stream |
| 559 | * that is the highest priority. |
| 560 | */ |
| 561 | if (ar->hiac_stream_active_pri == |
| 562 | ar->ac_stream_pri_map[traffic_class]) { |
| 563 | /* |
| 564 | * The highest priority stream just went inactive |
| 565 | * reset and search for the "next" highest "active" |
| 566 | * priority stream. |
| 567 | */ |
| 568 | ar->hiac_stream_active_pri = 0; |
| 569 | |
| 570 | for (i = 0; i < WMM_NUM_AC; i++) { |
| 571 | if (ar->ac_stream_active[i] && |
| 572 | (ar->ac_stream_pri_map[i] > |
| 573 | ar->hiac_stream_active_pri)) |
| 574 | /* |
| 575 | * Set the new highest active |
| 576 | * priority. |
| 577 | */ |
| 578 | ar->hiac_stream_active_pri = |
| 579 | ar->ac_stream_pri_map[i]; |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | spin_unlock_bh(&ar->lock); |
| 585 | |
| 586 | notify_htc: |
| 587 | /* notify HTC, this may cause credit distribution changes */ |
Kalle Valo | e76ac2bf | 2012-03-25 17:15:27 +0300 | [diff] [blame] | 588 | ath6kl_htc_activity_changed(ar->htc_target, eid, active); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | enum htc_send_full_action ath6kl_tx_queue_full(struct htc_target *target, |
| 592 | struct htc_packet *packet) |
| 593 | { |
| 594 | struct ath6kl *ar = target->dev->ar; |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 595 | struct ath6kl_vif *vif; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 596 | enum htc_endpoint_id endpoint = packet->endpoint; |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 597 | enum htc_send_full_action action = HTC_SEND_FULL_KEEP; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 598 | |
| 599 | if (endpoint == ar->ctrl_ep) { |
| 600 | /* |
| 601 | * Under normal WMI if this is getting full, then something |
| 602 | * is running rampant the host should not be exhausting the |
| 603 | * WMI queue with too many commands the only exception to |
| 604 | * this is during testing using endpointping. |
| 605 | */ |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 606 | set_bit(WMI_CTRL_EP_FULL, &ar->flag); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 607 | ath6kl_err("wmi ctrl ep is full\n"); |
Vasanthakumar Thiagarajan | 7756579 | 2012-08-29 19:40:28 +0530 | [diff] [blame] | 608 | ath6kl_recovery_err_notify(ar, ATH6KL_FW_EP_FULL); |
Vasanthakumar Thiagarajan | 901db39 | 2011-11-08 20:01:25 +0530 | [diff] [blame] | 609 | return action; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | if (packet->info.tx.tag == ATH6KL_CONTROL_PKT_TAG) |
Vasanthakumar Thiagarajan | 901db39 | 2011-11-08 20:01:25 +0530 | [diff] [blame] | 613 | return action; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 614 | |
| 615 | /* |
| 616 | * The last MAX_HI_COOKIE_NUM "batch" of cookies are reserved for |
| 617 | * the highest active stream. |
| 618 | */ |
| 619 | if (ar->ac_stream_pri_map[ar->ep2ac_map[endpoint]] < |
| 620 | ar->hiac_stream_active_pri && |
Chilam Ng | 0ea10f2b | 2012-02-09 02:17:01 -0800 | [diff] [blame] | 621 | ar->cookie_count <= |
| 622 | target->endpoint[endpoint].tx_drop_packet_threshold) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 623 | /* |
| 624 | * Give preference to the highest priority stream by |
| 625 | * dropping the packets which overflowed. |
| 626 | */ |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 627 | action = HTC_SEND_FULL_DROP; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 628 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 629 | /* FIXME: Locking */ |
Vasanthakumar Thiagarajan | 11f6e40 | 2011-11-01 16:38:50 +0530 | [diff] [blame] | 630 | spin_lock_bh(&ar->list_lock); |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 631 | list_for_each_entry(vif, &ar->vif_list, list) { |
Vasanthakumar Thiagarajan | 901db39 | 2011-11-08 20:01:25 +0530 | [diff] [blame] | 632 | if (vif->nw_type == ADHOC_NETWORK || |
| 633 | action != HTC_SEND_FULL_DROP) { |
Vasanthakumar Thiagarajan | 11f6e40 | 2011-11-01 16:38:50 +0530 | [diff] [blame] | 634 | spin_unlock_bh(&ar->list_lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 635 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 636 | set_bit(NETQ_STOPPED, &vif->flags); |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 637 | netif_stop_queue(vif->ndev); |
| 638 | |
| 639 | return action; |
| 640 | } |
| 641 | } |
Vasanthakumar Thiagarajan | 11f6e40 | 2011-11-01 16:38:50 +0530 | [diff] [blame] | 642 | spin_unlock_bh(&ar->list_lock); |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 643 | |
| 644 | return action; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | /* TODO this needs to be looked at */ |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 648 | static void ath6kl_tx_clear_node_map(struct ath6kl_vif *vif, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 649 | enum htc_endpoint_id eid, u32 map_no) |
| 650 | { |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 651 | struct ath6kl *ar = vif->ar; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 652 | u32 i; |
| 653 | |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 654 | if (vif->nw_type != ADHOC_NETWORK) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 655 | return; |
| 656 | |
| 657 | if (!ar->ibss_ps_enable) |
| 658 | return; |
| 659 | |
| 660 | if (eid == ar->ctrl_ep) |
| 661 | return; |
| 662 | |
| 663 | if (map_no == 0) |
| 664 | return; |
| 665 | |
| 666 | map_no--; |
| 667 | ar->node_map[map_no].tx_pend--; |
| 668 | |
| 669 | if (ar->node_map[map_no].tx_pend) |
| 670 | return; |
| 671 | |
| 672 | if (map_no != (ar->node_num - 1)) |
| 673 | return; |
| 674 | |
| 675 | for (i = ar->node_num; i > 0; i--) { |
| 676 | if (ar->node_map[i - 1].tx_pend) |
| 677 | break; |
| 678 | |
| 679 | memset(&ar->node_map[i - 1], 0, |
| 680 | sizeof(struct ath6kl_node_mapping)); |
| 681 | ar->node_num--; |
| 682 | } |
| 683 | } |
| 684 | |
Kalle Valo | 63de111 | 2012-03-25 17:15:22 +0300 | [diff] [blame] | 685 | void ath6kl_tx_complete(struct htc_target *target, |
| 686 | struct list_head *packet_queue) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 687 | { |
Kalle Valo | 63de111 | 2012-03-25 17:15:22 +0300 | [diff] [blame] | 688 | struct ath6kl *ar = target->dev->ar; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 689 | struct sk_buff_head skb_queue; |
| 690 | struct htc_packet *packet; |
| 691 | struct sk_buff *skb; |
| 692 | struct ath6kl_cookie *ath6kl_cookie; |
| 693 | u32 map_no = 0; |
| 694 | int status; |
| 695 | enum htc_endpoint_id eid; |
| 696 | bool wake_event = false; |
Kalle Valo | 71f96ee | 2011-11-14 19:31:30 +0200 | [diff] [blame] | 697 | bool flushing[ATH6KL_VIF_MAX] = {false}; |
Vasanthakumar Thiagarajan | 6765d0a | 2011-10-25 19:34:17 +0530 | [diff] [blame] | 698 | u8 if_idx; |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 699 | struct ath6kl_vif *vif; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 700 | |
| 701 | skb_queue_head_init(&skb_queue); |
| 702 | |
| 703 | /* lock the driver as we update internal state */ |
| 704 | spin_lock_bh(&ar->lock); |
| 705 | |
| 706 | /* reap completed packets */ |
| 707 | while (!list_empty(packet_queue)) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 708 | packet = list_first_entry(packet_queue, struct htc_packet, |
| 709 | list); |
| 710 | list_del(&packet->list); |
| 711 | |
Pandiyarajan Pitchaimuthu | 3077494 | 2012-09-21 20:13:09 +0530 | [diff] [blame] | 712 | if (WARN_ON_ONCE(packet->endpoint == ENDPOINT_UNUSED || |
| 713 | packet->endpoint >= ENDPOINT_MAX)) |
| 714 | continue; |
| 715 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 716 | ath6kl_cookie = (struct ath6kl_cookie *)packet->pkt_cntxt; |
Vasanthakumar Thiagarajan | 8114f9b | 2012-08-14 10:10:34 +0530 | [diff] [blame] | 717 | if (WARN_ON_ONCE(!ath6kl_cookie)) |
| 718 | continue; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 719 | |
| 720 | status = packet->status; |
| 721 | skb = ath6kl_cookie->skb; |
| 722 | eid = packet->endpoint; |
| 723 | map_no = ath6kl_cookie->map_no; |
| 724 | |
Vasanthakumar Thiagarajan | 8114f9b | 2012-08-14 10:10:34 +0530 | [diff] [blame] | 725 | if (WARN_ON_ONCE(!skb || !skb->data)) { |
| 726 | dev_kfree_skb(skb); |
| 727 | ath6kl_free_cookie(ar, ath6kl_cookie); |
| 728 | continue; |
| 729 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 730 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 731 | __skb_queue_tail(&skb_queue, skb); |
| 732 | |
Vasanthakumar Thiagarajan | 8114f9b | 2012-08-14 10:10:34 +0530 | [diff] [blame] | 733 | if (WARN_ON_ONCE(!status && (packet->act_len != skb->len))) { |
| 734 | ath6kl_free_cookie(ar, ath6kl_cookie); |
| 735 | continue; |
| 736 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 737 | |
| 738 | ar->tx_pending[eid]--; |
| 739 | |
| 740 | if (eid != ar->ctrl_ep) |
| 741 | ar->total_tx_data_pend--; |
| 742 | |
| 743 | if (eid == ar->ctrl_ep) { |
| 744 | if (test_bit(WMI_CTRL_EP_FULL, &ar->flag)) |
| 745 | clear_bit(WMI_CTRL_EP_FULL, &ar->flag); |
| 746 | |
| 747 | if (ar->tx_pending[eid] == 0) |
| 748 | wake_event = true; |
| 749 | } |
| 750 | |
Vasanthakumar Thiagarajan | 6765d0a | 2011-10-25 19:34:17 +0530 | [diff] [blame] | 751 | if (eid == ar->ctrl_ep) { |
| 752 | if_idx = wmi_cmd_hdr_get_if_idx( |
Vasanthakumar Thiagarajan | f3803eb | 2011-11-07 12:50:17 +0530 | [diff] [blame] | 753 | (struct wmi_cmd_hdr *) packet->buf); |
Vasanthakumar Thiagarajan | 6765d0a | 2011-10-25 19:34:17 +0530 | [diff] [blame] | 754 | } else { |
| 755 | if_idx = wmi_data_hdr_get_if_idx( |
Vasanthakumar Thiagarajan | f3803eb | 2011-11-07 12:50:17 +0530 | [diff] [blame] | 756 | (struct wmi_data_hdr *) packet->buf); |
Vasanthakumar Thiagarajan | 6765d0a | 2011-10-25 19:34:17 +0530 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | vif = ath6kl_get_vif_by_index(ar, if_idx); |
| 760 | if (!vif) { |
| 761 | ath6kl_free_cookie(ar, ath6kl_cookie); |
| 762 | continue; |
| 763 | } |
| 764 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 765 | if (status) { |
| 766 | if (status == -ECANCELED) |
| 767 | /* a packet was flushed */ |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 768 | flushing[if_idx] = true; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 769 | |
Vasanthakumar Thiagarajan | b95907a | 2011-10-25 19:34:11 +0530 | [diff] [blame] | 770 | vif->net_stats.tx_errors++; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 771 | |
Kalle Valo | 778e650 | 2011-10-27 18:49:08 +0300 | [diff] [blame] | 772 | if (status != -ENOSPC && status != -ECANCELED) |
| 773 | ath6kl_warn("tx complete error: %d\n", status); |
| 774 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 775 | ath6kl_dbg(ATH6KL_DBG_WLAN_TX, |
| 776 | "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n", |
| 777 | __func__, skb, packet->buf, packet->act_len, |
| 778 | eid, "error!"); |
| 779 | } else { |
| 780 | ath6kl_dbg(ATH6KL_DBG_WLAN_TX, |
| 781 | "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n", |
| 782 | __func__, skb, packet->buf, packet->act_len, |
| 783 | eid, "OK"); |
| 784 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 785 | flushing[if_idx] = false; |
Vasanthakumar Thiagarajan | b95907a | 2011-10-25 19:34:11 +0530 | [diff] [blame] | 786 | vif->net_stats.tx_packets++; |
| 787 | vif->net_stats.tx_bytes += skb->len; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 788 | } |
| 789 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 790 | ath6kl_tx_clear_node_map(vif, eid, map_no); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 791 | |
| 792 | ath6kl_free_cookie(ar, ath6kl_cookie); |
| 793 | |
Vasanthakumar Thiagarajan | 59c9844 | 2011-10-25 19:34:01 +0530 | [diff] [blame] | 794 | if (test_bit(NETQ_STOPPED, &vif->flags)) |
| 795 | clear_bit(NETQ_STOPPED, &vif->flags); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | spin_unlock_bh(&ar->lock); |
| 799 | |
| 800 | __skb_queue_purge(&skb_queue); |
| 801 | |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 802 | /* FIXME: Locking */ |
Vasanthakumar Thiagarajan | 11f6e40 | 2011-11-01 16:38:50 +0530 | [diff] [blame] | 803 | spin_lock_bh(&ar->list_lock); |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 804 | list_for_each_entry(vif, &ar->vif_list, list) { |
| 805 | if (test_bit(CONNECTED, &vif->flags) && |
| 806 | !flushing[vif->fw_vif_idx]) { |
Vasanthakumar Thiagarajan | 11f6e40 | 2011-11-01 16:38:50 +0530 | [diff] [blame] | 807 | spin_unlock_bh(&ar->list_lock); |
Vasanthakumar Thiagarajan | 28ae58d | 2011-10-25 19:34:14 +0530 | [diff] [blame] | 808 | netif_wake_queue(vif->ndev); |
Vasanthakumar Thiagarajan | 11f6e40 | 2011-11-01 16:38:50 +0530 | [diff] [blame] | 809 | spin_lock_bh(&ar->list_lock); |
Vasanthakumar Thiagarajan | 990bd91 | 2011-10-25 19:34:20 +0530 | [diff] [blame] | 810 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 811 | } |
Vasanthakumar Thiagarajan | 11f6e40 | 2011-11-01 16:38:50 +0530 | [diff] [blame] | 812 | spin_unlock_bh(&ar->list_lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 813 | |
| 814 | if (wake_event) |
| 815 | wake_up(&ar->event_wq); |
| 816 | |
| 817 | return; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | void ath6kl_tx_data_cleanup(struct ath6kl *ar) |
| 821 | { |
| 822 | int i; |
| 823 | |
| 824 | /* flush all the data (non-control) streams */ |
| 825 | for (i = 0; i < WMM_NUM_AC; i++) |
Kalle Valo | ad226ec | 2011-08-10 09:49:12 +0300 | [diff] [blame] | 826 | ath6kl_htc_flush_txep(ar->htc_target, ar->ac2ep_map[i], |
| 827 | ATH6KL_DATA_PKT_TAG); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | /* Rx functions */ |
| 831 | |
| 832 | static void ath6kl_deliver_frames_to_nw_stack(struct net_device *dev, |
| 833 | struct sk_buff *skb) |
| 834 | { |
| 835 | if (!skb) |
| 836 | return; |
| 837 | |
| 838 | skb->dev = dev; |
| 839 | |
| 840 | if (!(skb->dev->flags & IFF_UP)) { |
| 841 | dev_kfree_skb(skb); |
| 842 | return; |
| 843 | } |
| 844 | |
| 845 | skb->protocol = eth_type_trans(skb, skb->dev); |
| 846 | |
| 847 | netif_rx_ni(skb); |
| 848 | } |
| 849 | |
| 850 | static void ath6kl_alloc_netbufs(struct sk_buff_head *q, u16 num) |
| 851 | { |
| 852 | struct sk_buff *skb; |
| 853 | |
| 854 | while (num) { |
| 855 | skb = ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE); |
| 856 | if (!skb) { |
| 857 | ath6kl_err("netbuf allocation failed\n"); |
| 858 | return; |
| 859 | } |
| 860 | skb_queue_tail(q, skb); |
| 861 | num--; |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | static struct sk_buff *aggr_get_free_skb(struct aggr_info *p_aggr) |
| 866 | { |
| 867 | struct sk_buff *skb = NULL; |
| 868 | |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 869 | if (skb_queue_len(&p_aggr->rx_amsdu_freeq) < |
| 870 | (AGGR_NUM_OF_FREE_NETBUFS >> 2)) |
| 871 | ath6kl_alloc_netbufs(&p_aggr->rx_amsdu_freeq, |
| 872 | AGGR_NUM_OF_FREE_NETBUFS); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 873 | |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 874 | skb = skb_dequeue(&p_aggr->rx_amsdu_freeq); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 875 | |
| 876 | return skb; |
| 877 | } |
| 878 | |
| 879 | void ath6kl_rx_refill(struct htc_target *target, enum htc_endpoint_id endpoint) |
| 880 | { |
| 881 | struct ath6kl *ar = target->dev->ar; |
| 882 | struct sk_buff *skb; |
| 883 | int rx_buf; |
| 884 | int n_buf_refill; |
| 885 | struct htc_packet *packet; |
| 886 | struct list_head queue; |
| 887 | |
| 888 | n_buf_refill = ATH6KL_MAX_RX_BUFFERS - |
Kalle Valo | ad226ec | 2011-08-10 09:49:12 +0300 | [diff] [blame] | 889 | ath6kl_htc_get_rxbuf_num(ar->htc_target, endpoint); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 890 | |
| 891 | if (n_buf_refill <= 0) |
| 892 | return; |
| 893 | |
| 894 | INIT_LIST_HEAD(&queue); |
| 895 | |
| 896 | ath6kl_dbg(ATH6KL_DBG_WLAN_RX, |
| 897 | "%s: providing htc with %d buffers at eid=%d\n", |
| 898 | __func__, n_buf_refill, endpoint); |
| 899 | |
| 900 | for (rx_buf = 0; rx_buf < n_buf_refill; rx_buf++) { |
| 901 | skb = ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE); |
| 902 | if (!skb) |
| 903 | break; |
| 904 | |
| 905 | packet = (struct htc_packet *) skb->head; |
Vasanthakumar Thiagarajan | baec5c6 | 2012-09-21 12:45:24 +0530 | [diff] [blame] | 906 | if (!IS_ALIGNED((unsigned long) skb->data, 4)) { |
| 907 | size_t len = skb_headlen(skb); |
Vasanthakumar Thiagarajan | 94e532d | 2011-08-22 20:14:31 +0530 | [diff] [blame] | 908 | skb->data = PTR_ALIGN(skb->data - 4, 4); |
Vasanthakumar Thiagarajan | baec5c6 | 2012-09-21 12:45:24 +0530 | [diff] [blame] | 909 | skb_set_tail_pointer(skb, len); |
| 910 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 911 | set_htc_rxpkt_info(packet, skb, skb->data, |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 912 | ATH6KL_BUFFER_SIZE, endpoint); |
Kalle Valo | cfc10f2 | 2012-03-25 17:15:24 +0300 | [diff] [blame] | 913 | packet->skb = skb; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 914 | list_add_tail(&packet->list, &queue); |
| 915 | } |
| 916 | |
| 917 | if (!list_empty(&queue)) |
Kalle Valo | ad226ec | 2011-08-10 09:49:12 +0300 | [diff] [blame] | 918 | ath6kl_htc_add_rxbuf_multiple(ar->htc_target, &queue); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | void ath6kl_refill_amsdu_rxbufs(struct ath6kl *ar, int count) |
| 922 | { |
| 923 | struct htc_packet *packet; |
| 924 | struct sk_buff *skb; |
| 925 | |
| 926 | while (count) { |
| 927 | skb = ath6kl_buf_alloc(ATH6KL_AMSDU_BUFFER_SIZE); |
| 928 | if (!skb) |
| 929 | return; |
| 930 | |
| 931 | packet = (struct htc_packet *) skb->head; |
Vasanthakumar Thiagarajan | baec5c6 | 2012-09-21 12:45:24 +0530 | [diff] [blame] | 932 | if (!IS_ALIGNED((unsigned long) skb->data, 4)) { |
| 933 | size_t len = skb_headlen(skb); |
Vasanthakumar Thiagarajan | 94e532d | 2011-08-22 20:14:31 +0530 | [diff] [blame] | 934 | skb->data = PTR_ALIGN(skb->data - 4, 4); |
Vasanthakumar Thiagarajan | baec5c6 | 2012-09-21 12:45:24 +0530 | [diff] [blame] | 935 | skb_set_tail_pointer(skb, len); |
| 936 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 937 | set_htc_rxpkt_info(packet, skb, skb->data, |
| 938 | ATH6KL_AMSDU_BUFFER_SIZE, 0); |
Kalle Valo | cfc10f2 | 2012-03-25 17:15:24 +0300 | [diff] [blame] | 939 | packet->skb = skb; |
| 940 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 941 | spin_lock_bh(&ar->lock); |
| 942 | list_add_tail(&packet->list, &ar->amsdu_rx_buffer_queue); |
| 943 | spin_unlock_bh(&ar->lock); |
| 944 | count--; |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | /* |
| 949 | * Callback to allocate a receive buffer for a pending packet. We use a |
| 950 | * pre-allocated list of buffers of maximum AMSDU size (4K). |
| 951 | */ |
| 952 | struct htc_packet *ath6kl_alloc_amsdu_rxbuf(struct htc_target *target, |
| 953 | enum htc_endpoint_id endpoint, |
| 954 | int len) |
| 955 | { |
| 956 | struct ath6kl *ar = target->dev->ar; |
| 957 | struct htc_packet *packet = NULL; |
| 958 | struct list_head *pkt_pos; |
| 959 | int refill_cnt = 0, depth = 0; |
| 960 | |
| 961 | ath6kl_dbg(ATH6KL_DBG_WLAN_RX, "%s: eid=%d, len:%d\n", |
| 962 | __func__, endpoint, len); |
| 963 | |
| 964 | if ((len <= ATH6KL_BUFFER_SIZE) || |
| 965 | (len > ATH6KL_AMSDU_BUFFER_SIZE)) |
| 966 | return NULL; |
| 967 | |
| 968 | spin_lock_bh(&ar->lock); |
| 969 | |
| 970 | if (list_empty(&ar->amsdu_rx_buffer_queue)) { |
| 971 | spin_unlock_bh(&ar->lock); |
| 972 | refill_cnt = ATH6KL_MAX_AMSDU_RX_BUFFERS; |
| 973 | goto refill_buf; |
| 974 | } |
| 975 | |
| 976 | packet = list_first_entry(&ar->amsdu_rx_buffer_queue, |
| 977 | struct htc_packet, list); |
| 978 | list_del(&packet->list); |
| 979 | list_for_each(pkt_pos, &ar->amsdu_rx_buffer_queue) |
| 980 | depth++; |
| 981 | |
| 982 | refill_cnt = ATH6KL_MAX_AMSDU_RX_BUFFERS - depth; |
| 983 | spin_unlock_bh(&ar->lock); |
| 984 | |
| 985 | /* set actual endpoint ID */ |
| 986 | packet->endpoint = endpoint; |
| 987 | |
| 988 | refill_buf: |
| 989 | if (refill_cnt >= ATH6KL_AMSDU_REFILL_THRESHOLD) |
| 990 | ath6kl_refill_amsdu_rxbufs(ar, refill_cnt); |
| 991 | |
| 992 | return packet; |
| 993 | } |
| 994 | |
| 995 | static void aggr_slice_amsdu(struct aggr_info *p_aggr, |
| 996 | struct rxtid *rxtid, struct sk_buff *skb) |
| 997 | { |
| 998 | struct sk_buff *new_skb; |
| 999 | struct ethhdr *hdr; |
| 1000 | u16 frame_8023_len, payload_8023_len, mac_hdr_len, amsdu_len; |
| 1001 | u8 *framep; |
| 1002 | |
| 1003 | mac_hdr_len = sizeof(struct ethhdr); |
| 1004 | framep = skb->data + mac_hdr_len; |
| 1005 | amsdu_len = skb->len - mac_hdr_len; |
| 1006 | |
| 1007 | while (amsdu_len > mac_hdr_len) { |
| 1008 | hdr = (struct ethhdr *) framep; |
| 1009 | payload_8023_len = ntohs(hdr->h_proto); |
| 1010 | |
| 1011 | if (payload_8023_len < MIN_MSDU_SUBFRAME_PAYLOAD_LEN || |
| 1012 | payload_8023_len > MAX_MSDU_SUBFRAME_PAYLOAD_LEN) { |
| 1013 | ath6kl_err("802.3 AMSDU frame bound check failed. len %d\n", |
| 1014 | payload_8023_len); |
| 1015 | break; |
| 1016 | } |
| 1017 | |
| 1018 | frame_8023_len = payload_8023_len + mac_hdr_len; |
| 1019 | new_skb = aggr_get_free_skb(p_aggr); |
| 1020 | if (!new_skb) { |
| 1021 | ath6kl_err("no buffer available\n"); |
| 1022 | break; |
| 1023 | } |
| 1024 | |
| 1025 | memcpy(new_skb->data, framep, frame_8023_len); |
| 1026 | skb_put(new_skb, frame_8023_len); |
| 1027 | if (ath6kl_wmi_dot3_2_dix(new_skb)) { |
| 1028 | ath6kl_err("dot3_2_dix error\n"); |
| 1029 | dev_kfree_skb(new_skb); |
| 1030 | break; |
| 1031 | } |
| 1032 | |
| 1033 | skb_queue_tail(&rxtid->q, new_skb); |
| 1034 | |
| 1035 | /* Is this the last subframe within this aggregate ? */ |
| 1036 | if ((amsdu_len - frame_8023_len) == 0) |
| 1037 | break; |
| 1038 | |
| 1039 | /* Add the length of A-MSDU subframe padding bytes - |
| 1040 | * Round to nearest word. |
| 1041 | */ |
Vasanthakumar Thiagarajan | 13e34ea | 2011-08-16 11:19:38 +0530 | [diff] [blame] | 1042 | frame_8023_len = ALIGN(frame_8023_len, 4); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1043 | |
| 1044 | framep += frame_8023_len; |
| 1045 | amsdu_len -= frame_8023_len; |
| 1046 | } |
| 1047 | |
| 1048 | dev_kfree_skb(skb); |
| 1049 | } |
| 1050 | |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1051 | static void aggr_deque_frms(struct aggr_info_conn *agg_conn, u8 tid, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1052 | u16 seq_no, u8 order) |
| 1053 | { |
| 1054 | struct sk_buff *skb; |
| 1055 | struct rxtid *rxtid; |
| 1056 | struct skb_hold_q *node; |
| 1057 | u16 idx, idx_end, seq_end; |
| 1058 | struct rxtid_stats *stats; |
| 1059 | |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1060 | rxtid = &agg_conn->rx_tid[tid]; |
| 1061 | stats = &agg_conn->stat[tid]; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1062 | |
Vasanthakumar Thiagarajan | 0faf745 | 2012-05-30 12:27:11 +0530 | [diff] [blame] | 1063 | spin_lock_bh(&rxtid->lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1064 | idx = AGGR_WIN_IDX(rxtid->seq_next, rxtid->hold_q_sz); |
| 1065 | |
| 1066 | /* |
| 1067 | * idx_end is typically the last possible frame in the window, |
| 1068 | * but changes to 'the' seq_no, when BAR comes. If seq_no |
| 1069 | * is non-zero, we will go up to that and stop. |
| 1070 | * Note: last seq no in current window will occupy the same |
| 1071 | * index position as index that is just previous to start. |
| 1072 | * An imp point : if win_sz is 7, for seq_no space of 4095, |
| 1073 | * then, there would be holes when sequence wrap around occurs. |
| 1074 | * Target should judiciously choose the win_sz, based on |
| 1075 | * this condition. For 4095, (TID_WINDOW_SZ = 2 x win_sz |
| 1076 | * 2, 4, 8, 16 win_sz works fine). |
| 1077 | * We must deque from "idx" to "idx_end", including both. |
| 1078 | */ |
| 1079 | seq_end = seq_no ? seq_no : rxtid->seq_next; |
| 1080 | idx_end = AGGR_WIN_IDX(seq_end, rxtid->hold_q_sz); |
| 1081 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1082 | do { |
| 1083 | node = &rxtid->hold_q[idx]; |
| 1084 | if ((order == 1) && (!node->skb)) |
| 1085 | break; |
| 1086 | |
| 1087 | if (node->skb) { |
| 1088 | if (node->is_amsdu) |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1089 | aggr_slice_amsdu(agg_conn->aggr_info, rxtid, |
| 1090 | node->skb); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1091 | else |
| 1092 | skb_queue_tail(&rxtid->q, node->skb); |
| 1093 | node->skb = NULL; |
Kalle Valo | a5d8f9d | 2014-03-11 12:58:01 +0200 | [diff] [blame] | 1094 | } else { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1095 | stats->num_hole++; |
Kalle Valo | a5d8f9d | 2014-03-11 12:58:01 +0200 | [diff] [blame] | 1096 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1097 | |
| 1098 | rxtid->seq_next = ATH6KL_NEXT_SEQ_NO(rxtid->seq_next); |
| 1099 | idx = AGGR_WIN_IDX(rxtid->seq_next, rxtid->hold_q_sz); |
| 1100 | } while (idx != idx_end); |
| 1101 | |
| 1102 | spin_unlock_bh(&rxtid->lock); |
| 1103 | |
| 1104 | stats->num_delivered += skb_queue_len(&rxtid->q); |
| 1105 | |
| 1106 | while ((skb = skb_dequeue(&rxtid->q))) |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1107 | ath6kl_deliver_frames_to_nw_stack(agg_conn->dev, skb); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1108 | } |
| 1109 | |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1110 | static bool aggr_process_recv_frm(struct aggr_info_conn *agg_conn, u8 tid, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1111 | u16 seq_no, |
| 1112 | bool is_amsdu, struct sk_buff *frame) |
| 1113 | { |
| 1114 | struct rxtid *rxtid; |
| 1115 | struct rxtid_stats *stats; |
| 1116 | struct sk_buff *skb; |
| 1117 | struct skb_hold_q *node; |
| 1118 | u16 idx, st, cur, end; |
| 1119 | bool is_queued = false; |
| 1120 | u16 extended_end; |
| 1121 | |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1122 | rxtid = &agg_conn->rx_tid[tid]; |
| 1123 | stats = &agg_conn->stat[tid]; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1124 | |
| 1125 | stats->num_into_aggr++; |
| 1126 | |
| 1127 | if (!rxtid->aggr) { |
| 1128 | if (is_amsdu) { |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1129 | aggr_slice_amsdu(agg_conn->aggr_info, rxtid, frame); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1130 | is_queued = true; |
| 1131 | stats->num_amsdu++; |
| 1132 | while ((skb = skb_dequeue(&rxtid->q))) |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1133 | ath6kl_deliver_frames_to_nw_stack(agg_conn->dev, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1134 | skb); |
| 1135 | } |
| 1136 | return is_queued; |
| 1137 | } |
| 1138 | |
| 1139 | /* Check the incoming sequence no, if it's in the window */ |
| 1140 | st = rxtid->seq_next; |
| 1141 | cur = seq_no; |
| 1142 | end = (st + rxtid->hold_q_sz-1) & ATH6KL_MAX_SEQ_NO; |
| 1143 | |
| 1144 | if (((st < end) && (cur < st || cur > end)) || |
| 1145 | ((st > end) && (cur > end) && (cur < st))) { |
| 1146 | extended_end = (end + rxtid->hold_q_sz - 1) & |
| 1147 | ATH6KL_MAX_SEQ_NO; |
| 1148 | |
| 1149 | if (((end < extended_end) && |
| 1150 | (cur < end || cur > extended_end)) || |
| 1151 | ((end > extended_end) && (cur > extended_end) && |
| 1152 | (cur < end))) { |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1153 | aggr_deque_frms(agg_conn, tid, 0, 0); |
Vasanthakumar Thiagarajan | 0faf745 | 2012-05-30 12:27:11 +0530 | [diff] [blame] | 1154 | spin_lock_bh(&rxtid->lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1155 | if (cur >= rxtid->hold_q_sz - 1) |
| 1156 | rxtid->seq_next = cur - (rxtid->hold_q_sz - 1); |
| 1157 | else |
| 1158 | rxtid->seq_next = ATH6KL_MAX_SEQ_NO - |
| 1159 | (rxtid->hold_q_sz - 2 - cur); |
Vasanthakumar Thiagarajan | 0faf745 | 2012-05-30 12:27:11 +0530 | [diff] [blame] | 1160 | spin_unlock_bh(&rxtid->lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1161 | } else { |
| 1162 | /* |
| 1163 | * Dequeue only those frames that are outside the |
| 1164 | * new shifted window. |
| 1165 | */ |
| 1166 | if (cur >= rxtid->hold_q_sz - 1) |
| 1167 | st = cur - (rxtid->hold_q_sz - 1); |
| 1168 | else |
| 1169 | st = ATH6KL_MAX_SEQ_NO - |
| 1170 | (rxtid->hold_q_sz - 2 - cur); |
| 1171 | |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1172 | aggr_deque_frms(agg_conn, tid, st, 0); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | stats->num_oow++; |
| 1176 | } |
| 1177 | |
| 1178 | idx = AGGR_WIN_IDX(seq_no, rxtid->hold_q_sz); |
| 1179 | |
| 1180 | node = &rxtid->hold_q[idx]; |
| 1181 | |
| 1182 | spin_lock_bh(&rxtid->lock); |
| 1183 | |
| 1184 | /* |
| 1185 | * Is the cur frame duplicate or something beyond our window(hold_q |
| 1186 | * -> which is 2x, already)? |
| 1187 | * |
| 1188 | * 1. Duplicate is easy - drop incoming frame. |
| 1189 | * 2. Not falling in current sliding window. |
| 1190 | * 2a. is the frame_seq_no preceding current tid_seq_no? |
| 1191 | * -> drop the frame. perhaps sender did not get our ACK. |
| 1192 | * this is taken care of above. |
| 1193 | * 2b. is the frame_seq_no beyond window(st, TID_WINDOW_SZ); |
| 1194 | * -> Taken care of it above, by moving window forward. |
| 1195 | */ |
| 1196 | dev_kfree_skb(node->skb); |
| 1197 | stats->num_dups++; |
| 1198 | |
| 1199 | node->skb = frame; |
| 1200 | is_queued = true; |
| 1201 | node->is_amsdu = is_amsdu; |
| 1202 | node->seq_no = seq_no; |
| 1203 | |
| 1204 | if (node->is_amsdu) |
| 1205 | stats->num_amsdu++; |
| 1206 | else |
| 1207 | stats->num_mpdu++; |
| 1208 | |
| 1209 | spin_unlock_bh(&rxtid->lock); |
| 1210 | |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1211 | aggr_deque_frms(agg_conn, tid, 0, 1); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1212 | |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1213 | if (agg_conn->timer_scheduled) |
Vasanthakumar Thiagarajan | 7940bad | 2012-05-30 12:27:12 +0530 | [diff] [blame] | 1214 | return is_queued; |
| 1215 | |
| 1216 | spin_lock_bh(&rxtid->lock); |
Kalle Valo | c28d555 | 2014-03-11 12:58:02 +0200 | [diff] [blame] | 1217 | for (idx = 0; idx < rxtid->hold_q_sz; idx++) { |
Vasanthakumar Thiagarajan | 7940bad | 2012-05-30 12:27:12 +0530 | [diff] [blame] | 1218 | if (rxtid->hold_q[idx].skb) { |
| 1219 | /* |
| 1220 | * There is a frame in the queue and no |
| 1221 | * timer so start a timer to ensure that |
| 1222 | * the frame doesn't remain stuck |
| 1223 | * forever. |
| 1224 | */ |
| 1225 | agg_conn->timer_scheduled = true; |
| 1226 | mod_timer(&agg_conn->timer, |
| 1227 | (jiffies + (HZ * AGGR_RX_TIMEOUT) / 1000)); |
| 1228 | rxtid->timer_mon = true; |
| 1229 | break; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1230 | } |
Vasanthakumar Thiagarajan | 0faf745 | 2012-05-30 12:27:11 +0530 | [diff] [blame] | 1231 | } |
Vasanthakumar Thiagarajan | 7940bad | 2012-05-30 12:27:12 +0530 | [diff] [blame] | 1232 | spin_unlock_bh(&rxtid->lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1233 | |
| 1234 | return is_queued; |
| 1235 | } |
| 1236 | |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 1237 | static void ath6kl_uapsd_trigger_frame_rx(struct ath6kl_vif *vif, |
| 1238 | struct ath6kl_sta *conn) |
| 1239 | { |
| 1240 | struct ath6kl *ar = vif->ar; |
| 1241 | bool is_apsdq_empty, is_apsdq_empty_at_start; |
| 1242 | u32 num_frames_to_deliver, flags; |
| 1243 | struct sk_buff *skb = NULL; |
| 1244 | |
| 1245 | /* |
| 1246 | * If the APSD q for this STA is not empty, dequeue and |
| 1247 | * send a pkt from the head of the q. Also update the |
| 1248 | * More data bit in the WMI_DATA_HDR if there are |
| 1249 | * more pkts for this STA in the APSD q. |
| 1250 | * If there are no more pkts for this STA, |
| 1251 | * update the APSD bitmap for this STA. |
| 1252 | */ |
| 1253 | |
| 1254 | num_frames_to_deliver = (conn->apsd_info >> ATH6KL_APSD_NUM_OF_AC) & |
| 1255 | ATH6KL_APSD_FRAME_MASK; |
| 1256 | /* |
| 1257 | * Number of frames to send in a service period is |
| 1258 | * indicated by the station |
| 1259 | * in the QOS_INFO of the association request |
| 1260 | * If it is zero, send all frames |
| 1261 | */ |
| 1262 | if (!num_frames_to_deliver) |
| 1263 | num_frames_to_deliver = ATH6KL_APSD_ALL_FRAME; |
| 1264 | |
| 1265 | spin_lock_bh(&conn->psq_lock); |
| 1266 | is_apsdq_empty = skb_queue_empty(&conn->apsdq); |
| 1267 | spin_unlock_bh(&conn->psq_lock); |
| 1268 | is_apsdq_empty_at_start = is_apsdq_empty; |
| 1269 | |
| 1270 | while ((!is_apsdq_empty) && (num_frames_to_deliver)) { |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 1271 | spin_lock_bh(&conn->psq_lock); |
| 1272 | skb = skb_dequeue(&conn->apsdq); |
| 1273 | is_apsdq_empty = skb_queue_empty(&conn->apsdq); |
| 1274 | spin_unlock_bh(&conn->psq_lock); |
| 1275 | |
| 1276 | /* |
| 1277 | * Set the STA flag to Trigger delivery, |
| 1278 | * so that the frame will go out |
| 1279 | */ |
| 1280 | conn->sta_flags |= STA_PS_APSD_TRIGGER; |
| 1281 | num_frames_to_deliver--; |
| 1282 | |
| 1283 | /* Last frame in the service period, set EOSP or queue empty */ |
| 1284 | if ((is_apsdq_empty) || (!num_frames_to_deliver)) |
| 1285 | conn->sta_flags |= STA_PS_APSD_EOSP; |
| 1286 | |
| 1287 | ath6kl_data_tx(skb, vif->ndev); |
| 1288 | conn->sta_flags &= ~(STA_PS_APSD_TRIGGER); |
| 1289 | conn->sta_flags &= ~(STA_PS_APSD_EOSP); |
| 1290 | } |
| 1291 | |
| 1292 | if (is_apsdq_empty) { |
| 1293 | if (is_apsdq_empty_at_start) |
| 1294 | flags = WMI_AP_APSD_NO_DELIVERY_FRAMES; |
| 1295 | else |
| 1296 | flags = 0; |
| 1297 | |
| 1298 | ath6kl_wmi_set_apsd_bfrd_traf(ar->wmi, |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 1299 | vif->fw_vif_idx, |
| 1300 | conn->aid, 0, flags); |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | return; |
| 1304 | } |
| 1305 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1306 | void ath6kl_rx(struct htc_target *target, struct htc_packet *packet) |
| 1307 | { |
| 1308 | struct ath6kl *ar = target->dev->ar; |
| 1309 | struct sk_buff *skb = packet->pkt_cntxt; |
| 1310 | struct wmi_rx_meta_v2 *meta; |
| 1311 | struct wmi_data_hdr *dhdr; |
| 1312 | int min_hdr_len; |
| 1313 | u8 meta_type, dot11_hdr = 0; |
Kalle Valo | 8bd5bca | 2012-03-25 17:15:25 +0300 | [diff] [blame] | 1314 | u8 pad_before_data_start; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1315 | int status = packet->status; |
| 1316 | enum htc_endpoint_id ept = packet->endpoint; |
| 1317 | bool is_amsdu, prev_ps, ps_state = false; |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 1318 | bool trig_state = false; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1319 | struct ath6kl_sta *conn = NULL; |
| 1320 | struct sk_buff *skb1 = NULL; |
| 1321 | struct ethhdr *datap = NULL; |
Vasanthakumar Thiagarajan | 6765d0a | 2011-10-25 19:34:17 +0530 | [diff] [blame] | 1322 | struct ath6kl_vif *vif; |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1323 | struct aggr_info_conn *aggr_conn; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1324 | u16 seq_no, offset; |
Vasanthakumar Thiagarajan | 6765d0a | 2011-10-25 19:34:17 +0530 | [diff] [blame] | 1325 | u8 tid, if_idx; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1326 | |
| 1327 | ath6kl_dbg(ATH6KL_DBG_WLAN_RX, |
| 1328 | "%s: ar=0x%p eid=%d, skb=0x%p, data=0x%p, len=0x%x status:%d", |
| 1329 | __func__, ar, ept, skb, packet->buf, |
| 1330 | packet->act_len, status); |
| 1331 | |
Kalle Valo | 15ac077 | 2013-03-10 07:51:39 +0200 | [diff] [blame] | 1332 | if (status || packet->act_len < HTC_HDR_LENGTH) { |
Vasanthakumar Thiagarajan | 6765d0a | 2011-10-25 19:34:17 +0530 | [diff] [blame] | 1333 | dev_kfree_skb(skb); |
| 1334 | return; |
| 1335 | } |
| 1336 | |
| 1337 | skb_put(skb, packet->act_len + HTC_HDR_LENGTH); |
| 1338 | skb_pull(skb, HTC_HDR_LENGTH); |
| 1339 | |
Vasanthakumar Thiagarajan | 81db48d | 2012-02-28 20:20:22 +0530 | [diff] [blame] | 1340 | ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, __func__, "rx ", |
| 1341 | skb->data, skb->len); |
| 1342 | |
Vasanthakumar Thiagarajan | 6765d0a | 2011-10-25 19:34:17 +0530 | [diff] [blame] | 1343 | if (ept == ar->ctrl_ep) { |
Vasanthakumar Thiagarajan | 81db48d | 2012-02-28 20:20:22 +0530 | [diff] [blame] | 1344 | if (test_bit(WMI_ENABLED, &ar->flag)) { |
| 1345 | ath6kl_check_wow_status(ar); |
| 1346 | ath6kl_wmi_control_rx(ar->wmi, skb); |
| 1347 | return; |
| 1348 | } |
Vasanthakumar Thiagarajan | 6765d0a | 2011-10-25 19:34:17 +0530 | [diff] [blame] | 1349 | if_idx = |
| 1350 | wmi_cmd_hdr_get_if_idx((struct wmi_cmd_hdr *) skb->data); |
| 1351 | } else { |
| 1352 | if_idx = |
| 1353 | wmi_data_hdr_get_if_idx((struct wmi_data_hdr *) skb->data); |
| 1354 | } |
| 1355 | |
| 1356 | vif = ath6kl_get_vif_by_index(ar, if_idx); |
| 1357 | if (!vif) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1358 | dev_kfree_skb(skb); |
| 1359 | return; |
| 1360 | } |
| 1361 | |
| 1362 | /* |
| 1363 | * Take lock to protect buffer counts and adaptive power throughput |
| 1364 | * state. |
| 1365 | */ |
Vasanthakumar Thiagarajan | 478ac02 | 2011-10-25 19:34:19 +0530 | [diff] [blame] | 1366 | spin_lock_bh(&vif->if_lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1367 | |
Vasanthakumar Thiagarajan | b95907a | 2011-10-25 19:34:11 +0530 | [diff] [blame] | 1368 | vif->net_stats.rx_packets++; |
| 1369 | vif->net_stats.rx_bytes += packet->act_len; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1370 | |
Vasanthakumar Thiagarajan | 478ac02 | 2011-10-25 19:34:19 +0530 | [diff] [blame] | 1371 | spin_unlock_bh(&vif->if_lock); |
Vasanthakumar Thiagarajan | 83dc5f2 | 2011-08-14 17:08:33 +0530 | [diff] [blame] | 1372 | |
Vasanthakumar Thiagarajan | 28ae58d | 2011-10-25 19:34:14 +0530 | [diff] [blame] | 1373 | skb->dev = vif->ndev; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1374 | |
| 1375 | if (!test_bit(WMI_ENABLED, &ar->flag)) { |
| 1376 | if (EPPING_ALIGNMENT_PAD > 0) |
| 1377 | skb_pull(skb, EPPING_ALIGNMENT_PAD); |
Vasanthakumar Thiagarajan | 28ae58d | 2011-10-25 19:34:14 +0530 | [diff] [blame] | 1378 | ath6kl_deliver_frames_to_nw_stack(vif->ndev, skb); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1379 | return; |
| 1380 | } |
| 1381 | |
Raja Mani | a918fb3 | 2011-11-07 22:52:46 +0200 | [diff] [blame] | 1382 | ath6kl_check_wow_status(ar); |
| 1383 | |
Vasanthakumar Thiagarajan | 67f9178 | 2011-08-14 17:08:34 +0530 | [diff] [blame] | 1384 | min_hdr_len = sizeof(struct ethhdr) + sizeof(struct wmi_data_hdr) + |
| 1385 | sizeof(struct ath6kl_llc_snap_hdr); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1386 | |
| 1387 | dhdr = (struct wmi_data_hdr *) skb->data; |
| 1388 | |
| 1389 | /* |
| 1390 | * In the case of AP mode we may receive NULL data frames |
| 1391 | * that do not have LLC hdr. They are 16 bytes in size. |
| 1392 | * Allow these frames in the AP mode. |
| 1393 | */ |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 1394 | if (vif->nw_type != AP_NETWORK && |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1395 | ((packet->act_len < min_hdr_len) || |
| 1396 | (packet->act_len > WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH))) { |
| 1397 | ath6kl_info("frame len is too short or too long\n"); |
Vasanthakumar Thiagarajan | b95907a | 2011-10-25 19:34:11 +0530 | [diff] [blame] | 1398 | vif->net_stats.rx_errors++; |
| 1399 | vif->net_stats.rx_length_errors++; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1400 | dev_kfree_skb(skb); |
| 1401 | return; |
| 1402 | } |
| 1403 | |
Pierre Le Magourou | 270df8f | 2016-07-18 23:22:19 +0300 | [diff] [blame] | 1404 | pad_before_data_start = |
| 1405 | (le16_to_cpu(dhdr->info3) >> WMI_DATA_HDR_PAD_BEFORE_DATA_SHIFT) |
| 1406 | & WMI_DATA_HDR_PAD_BEFORE_DATA_MASK; |
| 1407 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1408 | /* Get the Power save state of the STA */ |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 1409 | if (vif->nw_type == AP_NETWORK) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1410 | meta_type = wmi_data_hdr_get_meta(dhdr); |
| 1411 | |
| 1412 | ps_state = !!((dhdr->info >> WMI_DATA_HDR_PS_SHIFT) & |
| 1413 | WMI_DATA_HDR_PS_MASK); |
| 1414 | |
Pierre Le Magourou | 270df8f | 2016-07-18 23:22:19 +0300 | [diff] [blame] | 1415 | offset = sizeof(struct wmi_data_hdr) + pad_before_data_start; |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 1416 | trig_state = !!(le16_to_cpu(dhdr->info3) & WMI_DATA_HDR_TRIG); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1417 | |
| 1418 | switch (meta_type) { |
| 1419 | case 0: |
| 1420 | break; |
| 1421 | case WMI_META_VERSION_1: |
| 1422 | offset += sizeof(struct wmi_rx_meta_v1); |
| 1423 | break; |
| 1424 | case WMI_META_VERSION_2: |
| 1425 | offset += sizeof(struct wmi_rx_meta_v2); |
| 1426 | break; |
| 1427 | default: |
| 1428 | break; |
| 1429 | } |
| 1430 | |
| 1431 | datap = (struct ethhdr *) (skb->data + offset); |
Vasanthakumar Thiagarajan | 6765d0a | 2011-10-25 19:34:17 +0530 | [diff] [blame] | 1432 | conn = ath6kl_find_sta(vif, datap->h_source); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1433 | |
| 1434 | if (!conn) { |
| 1435 | dev_kfree_skb(skb); |
| 1436 | return; |
| 1437 | } |
| 1438 | |
| 1439 | /* |
| 1440 | * If there is a change in PS state of the STA, |
| 1441 | * take appropriate steps: |
| 1442 | * |
| 1443 | * 1. If Sleep-->Awake, flush the psq for the STA |
| 1444 | * Clear the PVB for the STA. |
| 1445 | * 2. If Awake-->Sleep, Starting queueing frames |
| 1446 | * the STA. |
| 1447 | */ |
| 1448 | prev_ps = !!(conn->sta_flags & STA_PS_SLEEP); |
| 1449 | |
| 1450 | if (ps_state) |
| 1451 | conn->sta_flags |= STA_PS_SLEEP; |
| 1452 | else |
| 1453 | conn->sta_flags &= ~STA_PS_SLEEP; |
| 1454 | |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 1455 | /* Accept trigger only when the station is in sleep */ |
| 1456 | if ((conn->sta_flags & STA_PS_SLEEP) && trig_state) |
| 1457 | ath6kl_uapsd_trigger_frame_rx(vif, conn); |
| 1458 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1459 | if (prev_ps ^ !!(conn->sta_flags & STA_PS_SLEEP)) { |
| 1460 | if (!(conn->sta_flags & STA_PS_SLEEP)) { |
| 1461 | struct sk_buff *skbuff = NULL; |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 1462 | bool is_apsdq_empty; |
Naveen Gangadharan | d0ff738 | 2012-02-08 17:51:36 -0800 | [diff] [blame] | 1463 | struct ath6kl_mgmt_buff *mgmt; |
| 1464 | u8 idx; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1465 | |
| 1466 | spin_lock_bh(&conn->psq_lock); |
Naveen Gangadharan | d0ff738 | 2012-02-08 17:51:36 -0800 | [diff] [blame] | 1467 | while (conn->mgmt_psq_len > 0) { |
| 1468 | mgmt = list_first_entry( |
| 1469 | &conn->mgmt_psq, |
| 1470 | struct ath6kl_mgmt_buff, |
| 1471 | list); |
| 1472 | list_del(&mgmt->list); |
| 1473 | conn->mgmt_psq_len--; |
| 1474 | spin_unlock_bh(&conn->psq_lock); |
| 1475 | idx = vif->fw_vif_idx; |
| 1476 | |
| 1477 | ath6kl_wmi_send_mgmt_cmd(ar->wmi, |
| 1478 | idx, |
| 1479 | mgmt->id, |
| 1480 | mgmt->freq, |
| 1481 | mgmt->wait, |
| 1482 | mgmt->buf, |
| 1483 | mgmt->len, |
| 1484 | mgmt->no_cck); |
| 1485 | |
| 1486 | kfree(mgmt); |
| 1487 | spin_lock_bh(&conn->psq_lock); |
| 1488 | } |
| 1489 | conn->mgmt_psq_len = 0; |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 1490 | while ((skbuff = skb_dequeue(&conn->psq))) { |
| 1491 | spin_unlock_bh(&conn->psq_lock); |
| 1492 | ath6kl_data_tx(skbuff, vif->ndev); |
| 1493 | spin_lock_bh(&conn->psq_lock); |
| 1494 | } |
| 1495 | |
| 1496 | is_apsdq_empty = skb_queue_empty(&conn->apsdq); |
| 1497 | while ((skbuff = skb_dequeue(&conn->apsdq))) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1498 | spin_unlock_bh(&conn->psq_lock); |
Vasanthakumar Thiagarajan | 28ae58d | 2011-10-25 19:34:14 +0530 | [diff] [blame] | 1499 | ath6kl_data_tx(skbuff, vif->ndev); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1500 | spin_lock_bh(&conn->psq_lock); |
| 1501 | } |
| 1502 | spin_unlock_bh(&conn->psq_lock); |
Thirumalai Pachamuthu | c1762a3 | 2012-01-12 18:21:39 +0530 | [diff] [blame] | 1503 | |
| 1504 | if (!is_apsdq_empty) |
| 1505 | ath6kl_wmi_set_apsd_bfrd_traf( |
| 1506 | ar->wmi, |
| 1507 | vif->fw_vif_idx, |
| 1508 | conn->aid, 0, 0); |
| 1509 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1510 | /* Clear the PVB for this STA */ |
Vasanthakumar Thiagarajan | 334234b | 2011-10-25 19:34:12 +0530 | [diff] [blame] | 1511 | ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, |
| 1512 | conn->aid, 0); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | /* drop NULL data frames here */ |
| 1517 | if ((packet->act_len < min_hdr_len) || |
| 1518 | (packet->act_len > |
| 1519 | WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH)) { |
| 1520 | dev_kfree_skb(skb); |
| 1521 | return; |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | is_amsdu = wmi_data_hdr_is_amsdu(dhdr) ? true : false; |
| 1526 | tid = wmi_data_hdr_get_up(dhdr); |
| 1527 | seq_no = wmi_data_hdr_get_seqno(dhdr); |
| 1528 | meta_type = wmi_data_hdr_get_meta(dhdr); |
| 1529 | dot11_hdr = wmi_data_hdr_get_dot11(dhdr); |
Kalle Valo | 8bd5bca | 2012-03-25 17:15:25 +0300 | [diff] [blame] | 1530 | |
Vasanthakumar Thiagarajan | 594a0bc | 2011-08-14 17:08:35 +0530 | [diff] [blame] | 1531 | skb_pull(skb, sizeof(struct wmi_data_hdr)); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1532 | |
| 1533 | switch (meta_type) { |
| 1534 | case WMI_META_VERSION_1: |
| 1535 | skb_pull(skb, sizeof(struct wmi_rx_meta_v1)); |
| 1536 | break; |
| 1537 | case WMI_META_VERSION_2: |
| 1538 | meta = (struct wmi_rx_meta_v2 *) skb->data; |
| 1539 | if (meta->csum_flags & 0x1) { |
| 1540 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 1541 | skb->csum = (__force __wsum) meta->csum; |
| 1542 | } |
| 1543 | skb_pull(skb, sizeof(struct wmi_rx_meta_v2)); |
| 1544 | break; |
| 1545 | default: |
| 1546 | break; |
| 1547 | } |
| 1548 | |
Kalle Valo | 8bd5bca | 2012-03-25 17:15:25 +0300 | [diff] [blame] | 1549 | skb_pull(skb, pad_before_data_start); |
| 1550 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1551 | if (dot11_hdr) |
| 1552 | status = ath6kl_wmi_dot11_hdr_remove(ar->wmi, skb); |
| 1553 | else if (!is_amsdu) |
| 1554 | status = ath6kl_wmi_dot3_2_dix(skb); |
| 1555 | |
| 1556 | if (status) { |
| 1557 | /* |
| 1558 | * Drop frames that could not be processed (lack of |
| 1559 | * memory, etc.) |
| 1560 | */ |
| 1561 | dev_kfree_skb(skb); |
| 1562 | return; |
| 1563 | } |
| 1564 | |
Vasanthakumar Thiagarajan | 28ae58d | 2011-10-25 19:34:14 +0530 | [diff] [blame] | 1565 | if (!(vif->ndev->flags & IFF_UP)) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1566 | dev_kfree_skb(skb); |
| 1567 | return; |
| 1568 | } |
| 1569 | |
Vasanthakumar Thiagarajan | f5938f2 | 2011-10-25 19:34:03 +0530 | [diff] [blame] | 1570 | if (vif->nw_type == AP_NETWORK) { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1571 | datap = (struct ethhdr *) skb->data; |
| 1572 | if (is_multicast_ether_addr(datap->h_dest)) |
| 1573 | /* |
| 1574 | * Bcast/Mcast frames should be sent to the |
| 1575 | * OS stack as well as on the air. |
| 1576 | */ |
| 1577 | skb1 = skb_copy(skb, GFP_ATOMIC); |
| 1578 | else { |
| 1579 | /* |
| 1580 | * Search for a connected STA with dstMac |
| 1581 | * as the Mac address. If found send the |
| 1582 | * frame to it on the air else send the |
| 1583 | * frame up the stack. |
| 1584 | */ |
Vasanthakumar Thiagarajan | 6765d0a | 2011-10-25 19:34:17 +0530 | [diff] [blame] | 1585 | conn = ath6kl_find_sta(vif, datap->h_dest); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1586 | |
| 1587 | if (conn && ar->intra_bss) { |
| 1588 | skb1 = skb; |
| 1589 | skb = NULL; |
| 1590 | } else if (conn && !ar->intra_bss) { |
| 1591 | dev_kfree_skb(skb); |
| 1592 | skb = NULL; |
| 1593 | } |
| 1594 | } |
| 1595 | if (skb1) |
Vasanthakumar Thiagarajan | 28ae58d | 2011-10-25 19:34:14 +0530 | [diff] [blame] | 1596 | ath6kl_data_tx(skb1, vif->ndev); |
Kalle Valo | ad3f78b | 2011-10-06 14:32:32 +0300 | [diff] [blame] | 1597 | |
| 1598 | if (skb == NULL) { |
| 1599 | /* nothing to deliver up the stack */ |
| 1600 | return; |
| 1601 | } |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1602 | } |
| 1603 | |
Kalle Valo | 5694f962 | 2011-09-19 21:38:44 +0300 | [diff] [blame] | 1604 | datap = (struct ethhdr *) skb->data; |
| 1605 | |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1606 | if (is_unicast_ether_addr(datap->h_dest)) { |
| 1607 | if (vif->nw_type == AP_NETWORK) { |
| 1608 | conn = ath6kl_find_sta(vif, datap->h_source); |
| 1609 | if (!conn) |
| 1610 | return; |
| 1611 | aggr_conn = conn->aggr_conn; |
Kalle Valo | a5d8f9d | 2014-03-11 12:58:01 +0200 | [diff] [blame] | 1612 | } else { |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1613 | aggr_conn = vif->aggr_cntxt->aggr_conn; |
Kalle Valo | a5d8f9d | 2014-03-11 12:58:01 +0200 | [diff] [blame] | 1614 | } |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1615 | |
| 1616 | if (aggr_process_recv_frm(aggr_conn, tid, seq_no, |
Kalle Valo | 96f1fad | 2012-03-07 20:03:57 +0200 | [diff] [blame] | 1617 | is_amsdu, skb)) { |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1618 | /* aggregation code will handle the skb */ |
| 1619 | return; |
| 1620 | } |
Kalle Valo | a5d8f9d | 2014-03-11 12:58:01 +0200 | [diff] [blame] | 1621 | } else if (!is_broadcast_ether_addr(datap->h_dest)) { |
Vasanthakumar Thiagarajan | b514fab | 2012-04-03 14:13:46 +0530 | [diff] [blame] | 1622 | vif->net_stats.multicast++; |
Kalle Valo | a5d8f9d | 2014-03-11 12:58:01 +0200 | [diff] [blame] | 1623 | } |
Kalle Valo | 5694f962 | 2011-09-19 21:38:44 +0300 | [diff] [blame] | 1624 | |
Vasanthakumar Thiagarajan | 28ae58d | 2011-10-25 19:34:14 +0530 | [diff] [blame] | 1625 | ath6kl_deliver_frames_to_nw_stack(vif->ndev, skb); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | static void aggr_timeout(unsigned long arg) |
| 1629 | { |
| 1630 | u8 i, j; |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1631 | struct aggr_info_conn *aggr_conn = (struct aggr_info_conn *) arg; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1632 | struct rxtid *rxtid; |
| 1633 | struct rxtid_stats *stats; |
| 1634 | |
| 1635 | for (i = 0; i < NUM_OF_TIDS; i++) { |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1636 | rxtid = &aggr_conn->rx_tid[i]; |
| 1637 | stats = &aggr_conn->stat[i]; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1638 | |
Vasanthakumar Thiagarajan | 7940bad | 2012-05-30 12:27:12 +0530 | [diff] [blame] | 1639 | if (!rxtid->aggr || !rxtid->timer_mon) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1640 | continue; |
| 1641 | |
| 1642 | stats->num_timeouts++; |
Kalle Valo | 37ca633 | 2011-07-21 10:54:26 +0300 | [diff] [blame] | 1643 | ath6kl_dbg(ATH6KL_DBG_AGGR, |
| 1644 | "aggr timeout (st %d end %d)\n", |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1645 | rxtid->seq_next, |
| 1646 | ((rxtid->seq_next + rxtid->hold_q_sz-1) & |
| 1647 | ATH6KL_MAX_SEQ_NO)); |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1648 | aggr_deque_frms(aggr_conn, i, 0, 0); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1649 | } |
| 1650 | |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1651 | aggr_conn->timer_scheduled = false; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1652 | |
| 1653 | for (i = 0; i < NUM_OF_TIDS; i++) { |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1654 | rxtid = &aggr_conn->rx_tid[i]; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1655 | |
| 1656 | if (rxtid->aggr && rxtid->hold_q) { |
Vasanthakumar Thiagarajan | 0faf745 | 2012-05-30 12:27:11 +0530 | [diff] [blame] | 1657 | spin_lock_bh(&rxtid->lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1658 | for (j = 0; j < rxtid->hold_q_sz; j++) { |
| 1659 | if (rxtid->hold_q[j].skb) { |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1660 | aggr_conn->timer_scheduled = true; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1661 | rxtid->timer_mon = true; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1662 | break; |
| 1663 | } |
| 1664 | } |
Vasanthakumar Thiagarajan | 0faf745 | 2012-05-30 12:27:11 +0530 | [diff] [blame] | 1665 | spin_unlock_bh(&rxtid->lock); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1666 | |
| 1667 | if (j >= rxtid->hold_q_sz) |
| 1668 | rxtid->timer_mon = false; |
| 1669 | } |
| 1670 | } |
| 1671 | |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1672 | if (aggr_conn->timer_scheduled) |
| 1673 | mod_timer(&aggr_conn->timer, |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1674 | jiffies + msecs_to_jiffies(AGGR_RX_TIMEOUT)); |
| 1675 | } |
| 1676 | |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1677 | static void aggr_delete_tid_state(struct aggr_info_conn *aggr_conn, u8 tid) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1678 | { |
| 1679 | struct rxtid *rxtid; |
| 1680 | struct rxtid_stats *stats; |
| 1681 | |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1682 | if (!aggr_conn || tid >= NUM_OF_TIDS) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1683 | return; |
| 1684 | |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1685 | rxtid = &aggr_conn->rx_tid[tid]; |
| 1686 | stats = &aggr_conn->stat[tid]; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1687 | |
| 1688 | if (rxtid->aggr) |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1689 | aggr_deque_frms(aggr_conn, tid, 0, 0); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1690 | |
| 1691 | rxtid->aggr = false; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1692 | rxtid->timer_mon = false; |
| 1693 | rxtid->win_sz = 0; |
| 1694 | rxtid->seq_next = 0; |
| 1695 | rxtid->hold_q_sz = 0; |
| 1696 | |
| 1697 | kfree(rxtid->hold_q); |
| 1698 | rxtid->hold_q = NULL; |
| 1699 | |
| 1700 | memset(stats, 0, sizeof(struct rxtid_stats)); |
| 1701 | } |
| 1702 | |
Vasanthakumar Thiagarajan | 3fdc099 | 2012-01-21 15:22:52 +0530 | [diff] [blame] | 1703 | void aggr_recv_addba_req_evt(struct ath6kl_vif *vif, u8 tid_mux, u16 seq_no, |
Vasanthakumar Thiagarajan | 240d279 | 2011-10-25 19:34:13 +0530 | [diff] [blame] | 1704 | u8 win_sz) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1705 | { |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1706 | struct ath6kl_sta *sta; |
| 1707 | struct aggr_info_conn *aggr_conn = NULL; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1708 | struct rxtid *rxtid; |
| 1709 | struct rxtid_stats *stats; |
| 1710 | u16 hold_q_size; |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1711 | u8 tid, aid; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1712 | |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1713 | if (vif->nw_type == AP_NETWORK) { |
| 1714 | aid = ath6kl_get_aid(tid_mux); |
| 1715 | sta = ath6kl_find_sta_by_aid(vif->ar, aid); |
| 1716 | if (sta) |
| 1717 | aggr_conn = sta->aggr_conn; |
Kalle Valo | a5d8f9d | 2014-03-11 12:58:01 +0200 | [diff] [blame] | 1718 | } else { |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1719 | aggr_conn = vif->aggr_cntxt->aggr_conn; |
Kalle Valo | a5d8f9d | 2014-03-11 12:58:01 +0200 | [diff] [blame] | 1720 | } |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1721 | |
| 1722 | if (!aggr_conn) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1723 | return; |
| 1724 | |
Vasanthakumar Thiagarajan | 3fdc099 | 2012-01-21 15:22:52 +0530 | [diff] [blame] | 1725 | tid = ath6kl_get_tid(tid_mux); |
| 1726 | if (tid >= NUM_OF_TIDS) |
| 1727 | return; |
| 1728 | |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1729 | rxtid = &aggr_conn->rx_tid[tid]; |
| 1730 | stats = &aggr_conn->stat[tid]; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1731 | |
| 1732 | if (win_sz < AGGR_WIN_SZ_MIN || win_sz > AGGR_WIN_SZ_MAX) |
| 1733 | ath6kl_dbg(ATH6KL_DBG_WLAN_RX, "%s: win_sz %d, tid %d\n", |
| 1734 | __func__, win_sz, tid); |
| 1735 | |
| 1736 | if (rxtid->aggr) |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1737 | aggr_delete_tid_state(aggr_conn, tid); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1738 | |
| 1739 | rxtid->seq_next = seq_no; |
| 1740 | hold_q_size = TID_WINDOW_SZ(win_sz) * sizeof(struct skb_hold_q); |
| 1741 | rxtid->hold_q = kzalloc(hold_q_size, GFP_KERNEL); |
| 1742 | if (!rxtid->hold_q) |
| 1743 | return; |
| 1744 | |
| 1745 | rxtid->win_sz = win_sz; |
| 1746 | rxtid->hold_q_sz = TID_WINDOW_SZ(win_sz); |
| 1747 | if (!skb_queue_empty(&rxtid->q)) |
| 1748 | return; |
| 1749 | |
| 1750 | rxtid->aggr = true; |
| 1751 | } |
| 1752 | |
Vasanthakumar Thiagarajan | c865154 | 2012-01-26 13:17:18 +0530 | [diff] [blame] | 1753 | void aggr_conn_init(struct ath6kl_vif *vif, struct aggr_info *aggr_info, |
| 1754 | struct aggr_info_conn *aggr_conn) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1755 | { |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1756 | struct rxtid *rxtid; |
| 1757 | u8 i; |
| 1758 | |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1759 | aggr_conn->aggr_sz = AGGR_SZ_DEFAULT; |
| 1760 | aggr_conn->dev = vif->ndev; |
| 1761 | init_timer(&aggr_conn->timer); |
| 1762 | aggr_conn->timer.function = aggr_timeout; |
| 1763 | aggr_conn->timer.data = (unsigned long) aggr_conn; |
Vasanthakumar Thiagarajan | c865154 | 2012-01-26 13:17:18 +0530 | [diff] [blame] | 1764 | aggr_conn->aggr_info = aggr_info; |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1765 | |
| 1766 | aggr_conn->timer_scheduled = false; |
| 1767 | |
| 1768 | for (i = 0; i < NUM_OF_TIDS; i++) { |
| 1769 | rxtid = &aggr_conn->rx_tid[i]; |
| 1770 | rxtid->aggr = false; |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1771 | rxtid->timer_mon = false; |
| 1772 | skb_queue_head_init(&rxtid->q); |
| 1773 | spin_lock_init(&rxtid->lock); |
| 1774 | } |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | struct aggr_info *aggr_init(struct ath6kl_vif *vif) |
| 1778 | { |
| 1779 | struct aggr_info *p_aggr = NULL; |
| 1780 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1781 | p_aggr = kzalloc(sizeof(struct aggr_info), GFP_KERNEL); |
| 1782 | if (!p_aggr) { |
| 1783 | ath6kl_err("failed to alloc memory for aggr_node\n"); |
| 1784 | return NULL; |
| 1785 | } |
| 1786 | |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1787 | p_aggr->aggr_conn = kzalloc(sizeof(struct aggr_info_conn), GFP_KERNEL); |
| 1788 | if (!p_aggr->aggr_conn) { |
| 1789 | ath6kl_err("failed to alloc memory for connection specific aggr info\n"); |
| 1790 | kfree(p_aggr); |
| 1791 | return NULL; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1792 | } |
| 1793 | |
Vasanthakumar Thiagarajan | c865154 | 2012-01-26 13:17:18 +0530 | [diff] [blame] | 1794 | aggr_conn_init(vif, p_aggr, p_aggr->aggr_conn); |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1795 | |
| 1796 | skb_queue_head_init(&p_aggr->rx_amsdu_freeq); |
| 1797 | ath6kl_alloc_netbufs(&p_aggr->rx_amsdu_freeq, AGGR_NUM_OF_FREE_NETBUFS); |
| 1798 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1799 | return p_aggr; |
| 1800 | } |
| 1801 | |
Vasanthakumar Thiagarajan | 3fdc099 | 2012-01-21 15:22:52 +0530 | [diff] [blame] | 1802 | void aggr_recv_delba_req_evt(struct ath6kl_vif *vif, u8 tid_mux) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1803 | { |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1804 | struct ath6kl_sta *sta; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1805 | struct rxtid *rxtid; |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1806 | struct aggr_info_conn *aggr_conn = NULL; |
| 1807 | u8 tid, aid; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1808 | |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1809 | if (vif->nw_type == AP_NETWORK) { |
| 1810 | aid = ath6kl_get_aid(tid_mux); |
| 1811 | sta = ath6kl_find_sta_by_aid(vif->ar, aid); |
| 1812 | if (sta) |
| 1813 | aggr_conn = sta->aggr_conn; |
Kalle Valo | a5d8f9d | 2014-03-11 12:58:01 +0200 | [diff] [blame] | 1814 | } else { |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1815 | aggr_conn = vif->aggr_cntxt->aggr_conn; |
Kalle Valo | a5d8f9d | 2014-03-11 12:58:01 +0200 | [diff] [blame] | 1816 | } |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1817 | |
| 1818 | if (!aggr_conn) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1819 | return; |
| 1820 | |
Vasanthakumar Thiagarajan | 3fdc099 | 2012-01-21 15:22:52 +0530 | [diff] [blame] | 1821 | tid = ath6kl_get_tid(tid_mux); |
| 1822 | if (tid >= NUM_OF_TIDS) |
| 1823 | return; |
| 1824 | |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1825 | rxtid = &aggr_conn->rx_tid[tid]; |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1826 | |
| 1827 | if (rxtid->aggr) |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1828 | aggr_delete_tid_state(aggr_conn, tid); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1829 | } |
| 1830 | |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1831 | void aggr_reset_state(struct aggr_info_conn *aggr_conn) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1832 | { |
| 1833 | u8 tid; |
| 1834 | |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1835 | if (!aggr_conn) |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1836 | return; |
| 1837 | |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1838 | if (aggr_conn->timer_scheduled) { |
| 1839 | del_timer(&aggr_conn->timer); |
| 1840 | aggr_conn->timer_scheduled = false; |
Vasanthakumar Thiagarajan | 7a950ea | 2012-01-21 15:22:48 +0530 | [diff] [blame] | 1841 | } |
| 1842 | |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1843 | for (tid = 0; tid < NUM_OF_TIDS; tid++) |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1844 | aggr_delete_tid_state(aggr_conn, tid); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | /* clean up our amsdu buffer list */ |
| 1848 | void ath6kl_cleanup_amsdu_rxbufs(struct ath6kl *ar) |
| 1849 | { |
| 1850 | struct htc_packet *packet, *tmp_pkt; |
| 1851 | |
| 1852 | spin_lock_bh(&ar->lock); |
| 1853 | if (list_empty(&ar->amsdu_rx_buffer_queue)) { |
| 1854 | spin_unlock_bh(&ar->lock); |
| 1855 | return; |
| 1856 | } |
| 1857 | |
| 1858 | list_for_each_entry_safe(packet, tmp_pkt, &ar->amsdu_rx_buffer_queue, |
| 1859 | list) { |
| 1860 | list_del(&packet->list); |
| 1861 | spin_unlock_bh(&ar->lock); |
| 1862 | dev_kfree_skb(packet->pkt_cntxt); |
| 1863 | spin_lock_bh(&ar->lock); |
| 1864 | } |
| 1865 | |
| 1866 | spin_unlock_bh(&ar->lock); |
| 1867 | } |
| 1868 | |
| 1869 | void aggr_module_destroy(struct aggr_info *aggr_info) |
| 1870 | { |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1871 | if (!aggr_info) |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1872 | return; |
| 1873 | |
Vasanthakumar Thiagarajan | 1d2a445 | 2012-01-21 15:22:53 +0530 | [diff] [blame] | 1874 | aggr_reset_state(aggr_info->aggr_conn); |
Vasanthakumar Thiagarajan | 7baef81 | 2012-01-21 15:22:50 +0530 | [diff] [blame] | 1875 | skb_queue_purge(&aggr_info->rx_amsdu_freeq); |
| 1876 | kfree(aggr_info->aggr_conn); |
Kalle Valo | bdcd817 | 2011-07-18 00:22:30 +0300 | [diff] [blame] | 1877 | kfree(aggr_info); |
| 1878 | } |