Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of wl1271 |
| 3 | * |
| 4 | * Copyright (C) 2009 Nokia Corporation |
| 5 | * |
| 6 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 | * 02110-1301 USA |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/module.h> |
| 26 | |
| 27 | #include "wl1271.h" |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 28 | #include "wl1271_io.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 29 | #include "wl1271_reg.h" |
| 30 | #include "wl1271_ps.h" |
| 31 | #include "wl1271_tx.h" |
| 32 | |
| 33 | static int wl1271_tx_id(struct wl1271 *wl, struct sk_buff *skb) |
| 34 | { |
| 35 | int i; |
Juuso Oikarinen | be7078c | 2009-10-08 21:56:26 +0300 | [diff] [blame] | 36 | for (i = 0; i < ACX_TX_DESCRIPTORS; i++) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 37 | if (wl->tx_frames[i] == NULL) { |
| 38 | wl->tx_frames[i] = skb; |
Juuso Oikarinen | 781608c | 2010-05-24 11:18:17 +0300 | [diff] [blame] | 39 | wl->tx_frames_cnt++; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 40 | return i; |
| 41 | } |
| 42 | |
| 43 | return -EBUSY; |
| 44 | } |
| 45 | |
| 46 | static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra) |
| 47 | { |
| 48 | struct wl1271_tx_hw_descr *desc; |
| 49 | u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra; |
Juuso Oikarinen | 5c9417f | 2010-02-22 08:38:39 +0200 | [diff] [blame] | 50 | u32 total_blocks; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 51 | int id, ret = -EBUSY; |
| 52 | |
| 53 | /* allocate free identifier for the packet */ |
| 54 | id = wl1271_tx_id(wl, skb); |
| 55 | if (id < 0) |
| 56 | return id; |
| 57 | |
| 58 | /* approximate the number of blocks required for this packet |
| 59 | in the firmware */ |
Juuso Oikarinen | 5c9417f | 2010-02-22 08:38:39 +0200 | [diff] [blame] | 60 | total_blocks = total_len + TX_HW_BLOCK_SIZE - 1; |
| 61 | total_blocks = total_blocks / TX_HW_BLOCK_SIZE + TX_HW_BLOCK_SPARE; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 62 | if (total_blocks <= wl->tx_blocks_available) { |
| 63 | desc = (struct wl1271_tx_hw_descr *)skb_push( |
| 64 | skb, total_len - skb->len); |
| 65 | |
| 66 | desc->extra_mem_blocks = TX_HW_BLOCK_SPARE; |
| 67 | desc->total_mem_blocks = total_blocks; |
| 68 | desc->id = id; |
| 69 | |
| 70 | wl->tx_blocks_available -= total_blocks; |
| 71 | |
| 72 | ret = 0; |
| 73 | |
| 74 | wl1271_debug(DEBUG_TX, |
| 75 | "tx_allocate: size: %d, blocks: %d, id: %d", |
| 76 | total_len, total_blocks, id); |
Juuso Oikarinen | 781608c | 2010-05-24 11:18:17 +0300 | [diff] [blame] | 77 | } else { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 78 | wl->tx_frames[id] = NULL; |
Juuso Oikarinen | 781608c | 2010-05-24 11:18:17 +0300 | [diff] [blame] | 79 | wl->tx_frames_cnt--; |
| 80 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 81 | |
| 82 | return ret; |
| 83 | } |
| 84 | |
| 85 | static int wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb, |
| 86 | u32 extra, struct ieee80211_tx_info *control) |
| 87 | { |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame] | 88 | struct timespec ts; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 89 | struct wl1271_tx_hw_descr *desc; |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 90 | int pad, ac; |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame] | 91 | s64 hosttime; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 92 | u16 tx_attr; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 93 | |
| 94 | desc = (struct wl1271_tx_hw_descr *) skb->data; |
| 95 | |
Juuso Oikarinen | 1e2b797 | 2009-10-08 21:56:20 +0300 | [diff] [blame] | 96 | /* relocate space for security header */ |
| 97 | if (extra) { |
| 98 | void *framestart = skb->data + sizeof(*desc); |
| 99 | u16 fc = *(u16 *)(framestart + extra); |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 100 | int hdrlen = ieee80211_hdrlen(cpu_to_le16(fc)); |
Juuso Oikarinen | 1e2b797 | 2009-10-08 21:56:20 +0300 | [diff] [blame] | 101 | memmove(framestart, framestart + extra, hdrlen); |
| 102 | } |
| 103 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 104 | /* configure packet life time */ |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame] | 105 | getnstimeofday(&ts); |
| 106 | hosttime = (timespec_to_ns(&ts) >> 10); |
| 107 | desc->start_time = cpu_to_le32(hosttime - wl->time_offset); |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 108 | desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 109 | |
| 110 | /* configure the tx attributes */ |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 111 | tx_attr = wl->session_counter << TX_HW_ATTR_OFST_SESSION_COUNTER; |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 112 | |
| 113 | /* queue */ |
| 114 | ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); |
| 115 | desc->tid = wl1271_tx_ac_to_tid(ac); |
| 116 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 117 | desc->aid = TX_HW_DEFAULT_AID; |
| 118 | desc->reserved = 0; |
| 119 | |
| 120 | /* align the length (and store in terms of words) */ |
| 121 | pad = WL1271_TX_ALIGN(skb->len); |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 122 | desc->length = cpu_to_le16(pad >> 2); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 123 | |
| 124 | /* calculate number of padding bytes */ |
| 125 | pad = pad - skb->len; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 126 | tx_attr |= pad << TX_HW_ATTR_OFST_LAST_WORD_PAD; |
| 127 | |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 128 | /* if the packets are destined for AP (have a STA entry) send them |
| 129 | with AP rate policies, otherwise use default basic rates */ |
| 130 | if (control->control.sta) |
| 131 | tx_attr |= ACX_TX_AP_FULL_RATE << TX_HW_ATTR_OFST_RATE_POLICY; |
| 132 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 133 | desc->tx_attr = cpu_to_le16(tx_attr); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 134 | |
| 135 | wl1271_debug(DEBUG_TX, "tx_fill_hdr: pad: %d", pad); |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | static int wl1271_tx_send_packet(struct wl1271 *wl, struct sk_buff *skb, |
| 140 | struct ieee80211_tx_info *control) |
| 141 | { |
| 142 | |
| 143 | struct wl1271_tx_hw_descr *desc; |
| 144 | int len; |
| 145 | |
| 146 | /* FIXME: This is a workaround for getting non-aligned packets. |
| 147 | This happens at least with EAPOL packets from the user space. |
| 148 | Our DMA requires packets to be aligned on a 4-byte boundary. |
| 149 | */ |
| 150 | if (unlikely((long)skb->data & 0x03)) { |
| 151 | int offset = (4 - (long)skb->data) & 0x03; |
| 152 | wl1271_debug(DEBUG_TX, "skb offset %d", offset); |
| 153 | |
| 154 | /* check whether the current skb can be used */ |
| 155 | if (!skb_cloned(skb) && (skb_tailroom(skb) >= offset)) { |
| 156 | unsigned char *src = skb->data; |
| 157 | |
| 158 | /* align the buffer on a 4-byte boundary */ |
| 159 | skb_reserve(skb, offset); |
| 160 | memmove(skb->data, src, skb->len); |
| 161 | } else { |
| 162 | wl1271_info("No handler, fixme!"); |
| 163 | return -EINVAL; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | len = WL1271_TX_ALIGN(skb->len); |
| 168 | |
| 169 | /* perform a fixed address block write with the packet */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 170 | wl1271_write(wl, WL1271_SLV_MEM_DATA, skb->data, len, true); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 171 | |
| 172 | /* write packet new counter into the write access register */ |
| 173 | wl->tx_packets_count++; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 174 | |
| 175 | desc = (struct wl1271_tx_hw_descr *) skb->data; |
| 176 | wl1271_debug(DEBUG_TX, "tx id %u skb 0x%p payload %u (%u words)", |
| 177 | desc->id, skb, len, desc->length); |
| 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | /* caller must hold wl->mutex */ |
| 183 | static int wl1271_tx_frame(struct wl1271 *wl, struct sk_buff *skb) |
| 184 | { |
| 185 | struct ieee80211_tx_info *info; |
| 186 | u32 extra = 0; |
| 187 | int ret = 0; |
| 188 | u8 idx; |
| 189 | |
| 190 | if (!skb) |
| 191 | return -EINVAL; |
| 192 | |
| 193 | info = IEEE80211_SKB_CB(skb); |
| 194 | |
| 195 | if (info->control.hw_key && |
| 196 | info->control.hw_key->alg == ALG_TKIP) |
| 197 | extra = WL1271_TKIP_IV_SPACE; |
| 198 | |
| 199 | if (info->control.hw_key) { |
| 200 | idx = info->control.hw_key->hw_key_idx; |
| 201 | |
| 202 | /* FIXME: do we have to do this if we're not using WEP? */ |
| 203 | if (unlikely(wl->default_key != idx)) { |
| 204 | ret = wl1271_cmd_set_default_wep_key(wl, idx); |
| 205 | if (ret < 0) |
| 206 | return ret; |
Juuso Oikarinen | ee444cf | 2010-02-18 13:25:50 +0200 | [diff] [blame] | 207 | wl->default_key = idx; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
| 211 | ret = wl1271_tx_allocate(wl, skb, extra); |
| 212 | if (ret < 0) |
| 213 | return ret; |
| 214 | |
| 215 | ret = wl1271_tx_fill_hdr(wl, skb, extra, info); |
| 216 | if (ret < 0) |
| 217 | return ret; |
| 218 | |
| 219 | ret = wl1271_tx_send_packet(wl, skb, info); |
| 220 | if (ret < 0) |
| 221 | return ret; |
| 222 | |
| 223 | return ret; |
| 224 | } |
| 225 | |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 226 | u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set) |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 227 | { |
| 228 | struct ieee80211_supported_band *band; |
| 229 | u32 enabled_rates = 0; |
| 230 | int bit; |
| 231 | |
| 232 | band = wl->hw->wiphy->bands[wl->band]; |
| 233 | for (bit = 0; bit < band->n_bitrates; bit++) { |
| 234 | if (rate_set & 0x1) |
| 235 | enabled_rates |= band->bitrates[bit].hw_value; |
| 236 | rate_set >>= 1; |
| 237 | } |
| 238 | |
| 239 | return enabled_rates; |
| 240 | } |
| 241 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 242 | void wl1271_tx_work(struct work_struct *work) |
| 243 | { |
| 244 | struct wl1271 *wl = container_of(work, struct wl1271, tx_work); |
| 245 | struct sk_buff *skb; |
| 246 | bool woken_up = false; |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 247 | u32 sta_rates = 0; |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 248 | u32 prev_tx_packets_count; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 249 | int ret; |
| 250 | |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 251 | /* check if the rates supported by the AP have changed */ |
| 252 | if (unlikely(test_and_clear_bit(WL1271_FLAG_STA_RATES_CHANGED, |
| 253 | &wl->flags))) { |
| 254 | unsigned long flags; |
| 255 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 256 | sta_rates = wl->sta_rate_set; |
| 257 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 258 | } |
| 259 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 260 | mutex_lock(&wl->mutex); |
| 261 | |
| 262 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 263 | goto out; |
| 264 | |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 265 | prev_tx_packets_count = wl->tx_packets_count; |
| 266 | |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 267 | /* if rates have changed, re-configure the rate policy */ |
| 268 | if (unlikely(sta_rates)) { |
| 269 | wl->rate_set = wl1271_tx_enabled_rates_get(wl, sta_rates); |
| 270 | wl1271_acx_rate_policies(wl); |
| 271 | } |
| 272 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 273 | while ((skb = skb_dequeue(&wl->tx_queue))) { |
| 274 | if (!woken_up) { |
| 275 | ret = wl1271_ps_elp_wakeup(wl, false); |
| 276 | if (ret < 0) |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 277 | goto out_ack; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 278 | woken_up = true; |
| 279 | } |
| 280 | |
| 281 | ret = wl1271_tx_frame(wl, skb); |
| 282 | if (ret == -EBUSY) { |
Juuso Oikarinen | 06f7bc7 | 2010-02-22 08:38:33 +0200 | [diff] [blame] | 283 | /* firmware buffer is full, lets stop transmitting. */ |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 284 | skb_queue_head(&wl->tx_queue, skb); |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 285 | goto out_ack; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 286 | } else if (ret < 0) { |
| 287 | dev_kfree_skb(skb); |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 288 | goto out_ack; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 292 | out_ack: |
| 293 | /* interrupt the firmware with the new packets */ |
| 294 | if (prev_tx_packets_count != wl->tx_packets_count) |
| 295 | wl1271_write32(wl, WL1271_HOST_WR_ACCESS, wl->tx_packets_count); |
| 296 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 297 | out: |
| 298 | if (woken_up) |
| 299 | wl1271_ps_elp_sleep(wl); |
| 300 | |
| 301 | mutex_unlock(&wl->mutex); |
| 302 | } |
| 303 | |
| 304 | static void wl1271_tx_complete_packet(struct wl1271 *wl, |
| 305 | struct wl1271_tx_hw_res_descr *result) |
| 306 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 307 | struct ieee80211_tx_info *info; |
| 308 | struct sk_buff *skb; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 309 | int id = result->id; |
Juuso Oikarinen | 31627dc | 2010-03-26 12:53:12 +0200 | [diff] [blame] | 310 | int rate = -1; |
| 311 | u8 retries = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 312 | |
| 313 | /* check for id legality */ |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 314 | if (unlikely(id >= ACX_TX_DESCRIPTORS || wl->tx_frames[id] == NULL)) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 315 | wl1271_warning("TX result illegal id: %d", id); |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | skb = wl->tx_frames[id]; |
| 320 | info = IEEE80211_SKB_CB(skb); |
| 321 | |
Juuso Oikarinen | 31627dc | 2010-03-26 12:53:12 +0200 | [diff] [blame] | 322 | /* update the TX status info */ |
| 323 | if (result->status == TX_SUCCESS) { |
| 324 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 325 | info->flags |= IEEE80211_TX_STAT_ACK; |
Juuso Oikarinen | 31627dc | 2010-03-26 12:53:12 +0200 | [diff] [blame] | 326 | rate = wl1271_rate_to_idx(wl, result->rate_class_index); |
| 327 | retries = result->ack_failures; |
| 328 | } else if (result->status == TX_RETRY_EXCEEDED) { |
| 329 | wl->stats.excessive_retries++; |
| 330 | retries = result->ack_failures; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 331 | } |
| 332 | |
Juuso Oikarinen | 31627dc | 2010-03-26 12:53:12 +0200 | [diff] [blame] | 333 | info->status.rates[0].idx = rate; |
| 334 | info->status.rates[0].count = retries; |
| 335 | info->status.rates[0].flags = 0; |
| 336 | info->status.ack_signal = -1; |
| 337 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 338 | wl->stats.retry_count += result->ack_failures; |
| 339 | |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 340 | /* update security sequence number */ |
Juuso Oikarinen | 04e36fc | 2010-02-22 08:38:40 +0200 | [diff] [blame] | 341 | wl->tx_security_seq += (result->lsb_security_sequence_number - |
| 342 | wl->tx_security_last_seq); |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 343 | wl->tx_security_last_seq = result->lsb_security_sequence_number; |
| 344 | |
Juuso Oikarinen | 1e2b797 | 2009-10-08 21:56:20 +0300 | [diff] [blame] | 345 | /* remove private header from packet */ |
| 346 | skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); |
| 347 | |
| 348 | /* remove TKIP header space if present */ |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 349 | if (info->control.hw_key && |
Juuso Oikarinen | 1e2b797 | 2009-10-08 21:56:20 +0300 | [diff] [blame] | 350 | info->control.hw_key->alg == ALG_TKIP) { |
| 351 | int hdrlen = ieee80211_get_hdrlen_from_skb(skb); |
| 352 | memmove(skb->data + WL1271_TKIP_IV_SPACE, skb->data, hdrlen); |
| 353 | skb_pull(skb, WL1271_TKIP_IV_SPACE); |
| 354 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 355 | |
| 356 | wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x" |
| 357 | " status 0x%x", |
| 358 | result->id, skb, result->ack_failures, |
| 359 | result->rate_class_index, result->status); |
| 360 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 361 | /* return the packet to the stack */ |
| 362 | ieee80211_tx_status(wl->hw, skb); |
| 363 | wl->tx_frames[result->id] = NULL; |
Juuso Oikarinen | 781608c | 2010-05-24 11:18:17 +0300 | [diff] [blame] | 364 | wl->tx_frames_cnt--; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /* Called upon reception of a TX complete interrupt */ |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 368 | void wl1271_tx_complete(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 369 | { |
| 370 | struct wl1271_acx_mem_map *memmap = |
| 371 | (struct wl1271_acx_mem_map *)wl->target_mem_map; |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 372 | u32 count, fw_counter; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 373 | u32 i; |
| 374 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 375 | /* read the tx results from the chipset */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 376 | wl1271_read(wl, le32_to_cpu(memmap->tx_result), |
| 377 | wl->tx_res_if, sizeof(*wl->tx_res_if), false); |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 378 | fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter); |
| 379 | |
| 380 | /* write host counter to chipset (to ack) */ |
| 381 | wl1271_write32(wl, le32_to_cpu(memmap->tx_result) + |
| 382 | offsetof(struct wl1271_tx_hw_res_if, |
| 383 | tx_result_host_counter), fw_counter); |
| 384 | |
| 385 | count = fw_counter - wl->tx_results_count; |
Juuso Oikarinen | 06f7bc7 | 2010-02-22 08:38:33 +0200 | [diff] [blame] | 386 | wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 387 | |
| 388 | /* verify that the result buffer is not getting overrun */ |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 389 | if (unlikely(count > TX_HW_RESULT_QUEUE_LEN)) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 390 | wl1271_warning("TX result overflow from chipset: %d", count); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 391 | |
| 392 | /* process the results */ |
| 393 | for (i = 0; i < count; i++) { |
| 394 | struct wl1271_tx_hw_res_descr *result; |
| 395 | u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK; |
| 396 | |
| 397 | /* process the packet */ |
| 398 | result = &(wl->tx_res_if->tx_results_queue[offset]); |
| 399 | wl1271_tx_complete_packet(wl, result); |
| 400 | |
| 401 | wl->tx_results_count++; |
| 402 | } |
Juuso Oikarinen | 06f7bc7 | 2010-02-22 08:38:33 +0200 | [diff] [blame] | 403 | |
| 404 | if (test_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags) && |
| 405 | skb_queue_len(&wl->tx_queue) <= WL1271_TX_QUEUE_LOW_WATERMARK) { |
| 406 | unsigned long flags; |
| 407 | |
| 408 | /* firmware buffer has space, restart queues */ |
| 409 | wl1271_debug(DEBUG_TX, "tx_complete: waking queues"); |
| 410 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 411 | ieee80211_wake_queues(wl->hw); |
| 412 | clear_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags); |
| 413 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 414 | ieee80211_queue_work(wl->hw, &wl->tx_work); |
| 415 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | /* caller must hold wl->mutex */ |
Juuso Oikarinen | 781608c | 2010-05-24 11:18:17 +0300 | [diff] [blame] | 419 | void wl1271_tx_reset(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 420 | { |
| 421 | int i; |
| 422 | struct sk_buff *skb; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 423 | |
| 424 | /* TX failure */ |
| 425 | /* control->flags = 0; FIXME */ |
| 426 | |
| 427 | while ((skb = skb_dequeue(&wl->tx_queue))) { |
Juuso Oikarinen | 781608c | 2010-05-24 11:18:17 +0300 | [diff] [blame] | 428 | wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 429 | ieee80211_tx_status(wl->hw, skb); |
| 430 | } |
| 431 | |
Juuso Oikarinen | be7078c | 2009-10-08 21:56:26 +0300 | [diff] [blame] | 432 | for (i = 0; i < ACX_TX_DESCRIPTORS; i++) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 433 | if (wl->tx_frames[i] != NULL) { |
| 434 | skb = wl->tx_frames[i]; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 435 | wl->tx_frames[i] = NULL; |
Juuso Oikarinen | 781608c | 2010-05-24 11:18:17 +0300 | [diff] [blame] | 436 | wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb); |
Juuso Oikarinen | 6bbe89d | 2010-04-01 11:38:24 +0300 | [diff] [blame] | 437 | ieee80211_tx_status(wl->hw, skb); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 438 | } |
Juuso Oikarinen | 781608c | 2010-05-24 11:18:17 +0300 | [diff] [blame] | 439 | wl->tx_frames_cnt = 0; |
| 440 | } |
| 441 | |
| 442 | #define WL1271_TX_FLUSH_TIMEOUT 500000 |
| 443 | |
| 444 | /* caller must *NOT* hold wl->mutex */ |
| 445 | void wl1271_tx_flush(struct wl1271 *wl) |
| 446 | { |
| 447 | unsigned long timeout; |
| 448 | timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT); |
| 449 | |
| 450 | while (!time_after(jiffies, timeout)) { |
| 451 | mutex_lock(&wl->mutex); |
| 452 | wl1271_debug(DEBUG_TX, "flushing tx buffer: %d", |
| 453 | wl->tx_frames_cnt); |
| 454 | if ((wl->tx_frames_cnt == 0) && |
| 455 | skb_queue_empty(&wl->tx_queue)) { |
| 456 | mutex_unlock(&wl->mutex); |
| 457 | return; |
| 458 | } |
| 459 | mutex_unlock(&wl->mutex); |
| 460 | msleep(1); |
| 461 | } |
| 462 | |
| 463 | wl1271_warning("Unable to flush all TX buffers, timed out."); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 464 | } |