blob: e3dc13c4d01ad0b572267526efae5f666b5bf757 [file] [log] [blame]
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001/*
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 Paasikivi7b048c52010-02-18 13:25:55 +020028#include "wl1271_io.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030029#include "wl1271_reg.h"
30#include "wl1271_ps.h"
31#include "wl1271_tx.h"
32
33static int wl1271_tx_id(struct wl1271 *wl, struct sk_buff *skb)
34{
35 int i;
Juuso Oikarinenbe7078c2009-10-08 21:56:26 +030036 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030037 if (wl->tx_frames[i] == NULL) {
38 wl->tx_frames[i] = skb;
Juuso Oikarinen781608c2010-05-24 11:18:17 +030039 wl->tx_frames_cnt++;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030040 return i;
41 }
42
43 return -EBUSY;
44}
45
Ido Yariva19606b2010-09-30 13:28:28 +020046static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
47 u32 buf_offset)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030048{
49 struct wl1271_tx_hw_descr *desc;
50 u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra;
Juuso Oikarinen5c9417f2010-02-22 08:38:39 +020051 u32 total_blocks;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030052 int id, ret = -EBUSY;
53
Ido Yariva19606b2010-09-30 13:28:28 +020054 if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE)
55 return -EBUSY;
56
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030057 /* allocate free identifier for the packet */
58 id = wl1271_tx_id(wl, skb);
59 if (id < 0)
60 return id;
61
62 /* approximate the number of blocks required for this packet
63 in the firmware */
Juuso Oikarinen5c9417f2010-02-22 08:38:39 +020064 total_blocks = total_len + TX_HW_BLOCK_SIZE - 1;
65 total_blocks = total_blocks / TX_HW_BLOCK_SIZE + TX_HW_BLOCK_SPARE;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030066 if (total_blocks <= wl->tx_blocks_available) {
67 desc = (struct wl1271_tx_hw_descr *)skb_push(
68 skb, total_len - skb->len);
69
70 desc->extra_mem_blocks = TX_HW_BLOCK_SPARE;
71 desc->total_mem_blocks = total_blocks;
72 desc->id = id;
73
74 wl->tx_blocks_available -= total_blocks;
75
76 ret = 0;
77
78 wl1271_debug(DEBUG_TX,
79 "tx_allocate: size: %d, blocks: %d, id: %d",
80 total_len, total_blocks, id);
Juuso Oikarinen781608c2010-05-24 11:18:17 +030081 } else {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030082 wl->tx_frames[id] = NULL;
Juuso Oikarinen781608c2010-05-24 11:18:17 +030083 wl->tx_frames_cnt--;
84 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030085
86 return ret;
87}
88
Ido Yariva19606b2010-09-30 13:28:28 +020089static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030090 u32 extra, struct ieee80211_tx_info *control)
91{
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +020092 struct timespec ts;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030093 struct wl1271_tx_hw_descr *desc;
Kalle Valoc6999d82010-02-18 13:25:41 +020094 int pad, ac;
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +020095 s64 hosttime;
Luciano Coelhod0f63b22009-10-15 10:33:29 +030096 u16 tx_attr;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030097
98 desc = (struct wl1271_tx_hw_descr *) skb->data;
99
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +0300100 /* relocate space for security header */
101 if (extra) {
102 void *framestart = skb->data + sizeof(*desc);
103 u16 fc = *(u16 *)(framestart + extra);
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300104 int hdrlen = ieee80211_hdrlen(cpu_to_le16(fc));
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +0300105 memmove(framestart, framestart + extra, hdrlen);
106 }
107
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300108 /* configure packet life time */
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200109 getnstimeofday(&ts);
110 hosttime = (timespec_to_ns(&ts) >> 10);
111 desc->start_time = cpu_to_le32(hosttime - wl->time_offset);
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300112 desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300113
114 /* configure the tx attributes */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300115 tx_attr = wl->session_counter << TX_HW_ATTR_OFST_SESSION_COUNTER;
Kalle Valoc6999d82010-02-18 13:25:41 +0200116
Juuso Oikarinened484a12010-09-01 11:31:11 +0200117 /* queue (we use same identifiers for tid's and ac's */
Kalle Valoc6999d82010-02-18 13:25:41 +0200118 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
Juuso Oikarinened484a12010-09-01 11:31:11 +0200119 desc->tid = ac;
Kalle Valoc6999d82010-02-18 13:25:41 +0200120
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300121 desc->aid = TX_HW_DEFAULT_AID;
122 desc->reserved = 0;
123
124 /* align the length (and store in terms of words) */
125 pad = WL1271_TX_ALIGN(skb->len);
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300126 desc->length = cpu_to_le16(pad >> 2);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300127
128 /* calculate number of padding bytes */
129 pad = pad - skb->len;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300130 tx_attr |= pad << TX_HW_ATTR_OFST_LAST_WORD_PAD;
131
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200132 /* if the packets are destined for AP (have a STA entry) send them
133 with AP rate policies, otherwise use default basic rates */
134 if (control->control.sta)
135 tx_attr |= ACX_TX_AP_FULL_RATE << TX_HW_ATTR_OFST_RATE_POLICY;
136
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300137 desc->tx_attr = cpu_to_le16(tx_attr);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300138
139 wl1271_debug(DEBUG_TX, "tx_fill_hdr: pad: %d", pad);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300140}
141
142/* caller must hold wl->mutex */
Ido Yariva19606b2010-09-30 13:28:28 +0200143static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct sk_buff *skb,
144 u32 buf_offset)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300145{
146 struct ieee80211_tx_info *info;
147 u32 extra = 0;
148 int ret = 0;
149 u8 idx;
Ido Yariva19606b2010-09-30 13:28:28 +0200150 u32 total_len;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300151
152 if (!skb)
153 return -EINVAL;
154
155 info = IEEE80211_SKB_CB(skb);
156
157 if (info->control.hw_key &&
Johannes Berg97359d12010-08-10 09:46:38 +0200158 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300159 extra = WL1271_TKIP_IV_SPACE;
160
161 if (info->control.hw_key) {
162 idx = info->control.hw_key->hw_key_idx;
163
164 /* FIXME: do we have to do this if we're not using WEP? */
165 if (unlikely(wl->default_key != idx)) {
166 ret = wl1271_cmd_set_default_wep_key(wl, idx);
167 if (ret < 0)
168 return ret;
Juuso Oikarinenee444cf2010-02-18 13:25:50 +0200169 wl->default_key = idx;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300170 }
171 }
172
Ido Yariva19606b2010-09-30 13:28:28 +0200173 ret = wl1271_tx_allocate(wl, skb, extra, buf_offset);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300174 if (ret < 0)
175 return ret;
176
Ido Yariva19606b2010-09-30 13:28:28 +0200177 wl1271_tx_fill_hdr(wl, skb, extra, info);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300178
Ido Yariva19606b2010-09-30 13:28:28 +0200179 /*
180 * The length of each packet is stored in terms of words. Thus, we must
181 * pad the skb data to make sure its length is aligned.
182 * The number of padding bytes is computed and set in wl1271_tx_fill_hdr
183 */
184 total_len = WL1271_TX_ALIGN(skb->len);
185 memcpy(wl->aggr_buf + buf_offset, skb->data, skb->len);
186 memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300187
Ido Yariva19606b2010-09-30 13:28:28 +0200188 return total_len;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300189}
190
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300191u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set)
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200192{
193 struct ieee80211_supported_band *band;
194 u32 enabled_rates = 0;
195 int bit;
196
197 band = wl->hw->wiphy->bands[wl->band];
198 for (bit = 0; bit < band->n_bitrates; bit++) {
199 if (rate_set & 0x1)
200 enabled_rates |= band->bitrates[bit].hw_value;
201 rate_set >>= 1;
202 }
203
204 return enabled_rates;
205}
206
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300207void wl1271_tx_work(struct work_struct *work)
208{
209 struct wl1271 *wl = container_of(work, struct wl1271, tx_work);
210 struct sk_buff *skb;
211 bool woken_up = false;
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200212 u32 sta_rates = 0;
Ido Yariva19606b2010-09-30 13:28:28 +0200213 u32 buf_offset;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300214 int ret;
215
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200216 /* check if the rates supported by the AP have changed */
217 if (unlikely(test_and_clear_bit(WL1271_FLAG_STA_RATES_CHANGED,
218 &wl->flags))) {
219 unsigned long flags;
220 spin_lock_irqsave(&wl->wl_lock, flags);
221 sta_rates = wl->sta_rate_set;
222 spin_unlock_irqrestore(&wl->wl_lock, flags);
223 }
224
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300225 mutex_lock(&wl->mutex);
226
227 if (unlikely(wl->state == WL1271_STATE_OFF))
228 goto out;
229
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200230 /* if rates have changed, re-configure the rate policy */
231 if (unlikely(sta_rates)) {
232 wl->rate_set = wl1271_tx_enabled_rates_get(wl, sta_rates);
233 wl1271_acx_rate_policies(wl);
234 }
235
Ido Yariva19606b2010-09-30 13:28:28 +0200236 /* Prepare the transfer buffer, by aggregating all
237 * available packets */
238 buf_offset = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300239 while ((skb = skb_dequeue(&wl->tx_queue))) {
240 if (!woken_up) {
241 ret = wl1271_ps_elp_wakeup(wl, false);
242 if (ret < 0)
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200243 goto out_ack;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300244 woken_up = true;
245 }
246
Ido Yariva19606b2010-09-30 13:28:28 +0200247 ret = wl1271_prepare_tx_frame(wl, skb, buf_offset);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300248 if (ret == -EBUSY) {
Ido Yariva19606b2010-09-30 13:28:28 +0200249 /*
250 * Either the firmware buffer is full, or the
251 * aggregation buffer is.
252 * Queue back last skb, and stop aggregating.
253 */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300254 skb_queue_head(&wl->tx_queue, skb);
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200255 goto out_ack;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300256 } else if (ret < 0) {
257 dev_kfree_skb(skb);
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200258 goto out_ack;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300259 }
Ido Yariva19606b2010-09-30 13:28:28 +0200260 buf_offset += ret;
261 wl->tx_packets_count++;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300262 }
263
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200264out_ack:
Ido Yariva19606b2010-09-30 13:28:28 +0200265 if (buf_offset) {
266 wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
267 buf_offset, true);
268 /* interrupt the firmware with the new packets */
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200269 wl1271_write32(wl, WL1271_HOST_WR_ACCESS, wl->tx_packets_count);
Ido Yariva19606b2010-09-30 13:28:28 +0200270 }
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200271
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300272out:
273 if (woken_up)
274 wl1271_ps_elp_sleep(wl);
275
276 mutex_unlock(&wl->mutex);
277}
278
279static void wl1271_tx_complete_packet(struct wl1271 *wl,
280 struct wl1271_tx_hw_res_descr *result)
281{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300282 struct ieee80211_tx_info *info;
283 struct sk_buff *skb;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300284 int id = result->id;
Juuso Oikarinen31627dc2010-03-26 12:53:12 +0200285 int rate = -1;
286 u8 retries = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300287
288 /* check for id legality */
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200289 if (unlikely(id >= ACX_TX_DESCRIPTORS || wl->tx_frames[id] == NULL)) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300290 wl1271_warning("TX result illegal id: %d", id);
291 return;
292 }
293
294 skb = wl->tx_frames[id];
295 info = IEEE80211_SKB_CB(skb);
296
Juuso Oikarinen31627dc2010-03-26 12:53:12 +0200297 /* update the TX status info */
298 if (result->status == TX_SUCCESS) {
299 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300300 info->flags |= IEEE80211_TX_STAT_ACK;
Juuso Oikarinen31627dc2010-03-26 12:53:12 +0200301 rate = wl1271_rate_to_idx(wl, result->rate_class_index);
302 retries = result->ack_failures;
303 } else if (result->status == TX_RETRY_EXCEEDED) {
304 wl->stats.excessive_retries++;
305 retries = result->ack_failures;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300306 }
307
Juuso Oikarinen31627dc2010-03-26 12:53:12 +0200308 info->status.rates[0].idx = rate;
309 info->status.rates[0].count = retries;
310 info->status.rates[0].flags = 0;
311 info->status.ack_signal = -1;
312
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300313 wl->stats.retry_count += result->ack_failures;
314
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300315 /* update security sequence number */
Juuso Oikarinen04e36fc2010-02-22 08:38:40 +0200316 wl->tx_security_seq += (result->lsb_security_sequence_number -
317 wl->tx_security_last_seq);
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300318 wl->tx_security_last_seq = result->lsb_security_sequence_number;
319
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +0300320 /* remove private header from packet */
321 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
322
323 /* remove TKIP header space if present */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300324 if (info->control.hw_key &&
Johannes Berg97359d12010-08-10 09:46:38 +0200325 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +0300326 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
327 memmove(skb->data + WL1271_TKIP_IV_SPACE, skb->data, hdrlen);
328 skb_pull(skb, WL1271_TKIP_IV_SPACE);
329 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300330
331 wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
332 " status 0x%x",
333 result->id, skb, result->ack_failures,
334 result->rate_class_index, result->status);
335
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300336 /* return the packet to the stack */
337 ieee80211_tx_status(wl->hw, skb);
338 wl->tx_frames[result->id] = NULL;
Juuso Oikarinen781608c2010-05-24 11:18:17 +0300339 wl->tx_frames_cnt--;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300340}
341
342/* Called upon reception of a TX complete interrupt */
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200343void wl1271_tx_complete(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300344{
345 struct wl1271_acx_mem_map *memmap =
346 (struct wl1271_acx_mem_map *)wl->target_mem_map;
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200347 u32 count, fw_counter;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300348 u32 i;
349
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300350 /* read the tx results from the chipset */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200351 wl1271_read(wl, le32_to_cpu(memmap->tx_result),
352 wl->tx_res_if, sizeof(*wl->tx_res_if), false);
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200353 fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter);
354
355 /* write host counter to chipset (to ack) */
356 wl1271_write32(wl, le32_to_cpu(memmap->tx_result) +
357 offsetof(struct wl1271_tx_hw_res_if,
358 tx_result_host_counter), fw_counter);
359
360 count = fw_counter - wl->tx_results_count;
Juuso Oikarinen06f7bc72010-02-22 08:38:33 +0200361 wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300362
363 /* verify that the result buffer is not getting overrun */
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200364 if (unlikely(count > TX_HW_RESULT_QUEUE_LEN))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300365 wl1271_warning("TX result overflow from chipset: %d", count);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300366
367 /* process the results */
368 for (i = 0; i < count; i++) {
369 struct wl1271_tx_hw_res_descr *result;
370 u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK;
371
372 /* process the packet */
373 result = &(wl->tx_res_if->tx_results_queue[offset]);
374 wl1271_tx_complete_packet(wl, result);
375
376 wl->tx_results_count++;
377 }
Juuso Oikarinen06f7bc72010-02-22 08:38:33 +0200378
379 if (test_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags) &&
380 skb_queue_len(&wl->tx_queue) <= WL1271_TX_QUEUE_LOW_WATERMARK) {
381 unsigned long flags;
382
383 /* firmware buffer has space, restart queues */
384 wl1271_debug(DEBUG_TX, "tx_complete: waking queues");
385 spin_lock_irqsave(&wl->wl_lock, flags);
386 ieee80211_wake_queues(wl->hw);
387 clear_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
388 spin_unlock_irqrestore(&wl->wl_lock, flags);
389 ieee80211_queue_work(wl->hw, &wl->tx_work);
390 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300391}
392
393/* caller must hold wl->mutex */
Juuso Oikarinen781608c2010-05-24 11:18:17 +0300394void wl1271_tx_reset(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300395{
396 int i;
397 struct sk_buff *skb;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300398
399 /* TX failure */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300400 while ((skb = skb_dequeue(&wl->tx_queue))) {
Juuso Oikarinen781608c2010-05-24 11:18:17 +0300401 wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300402 ieee80211_tx_status(wl->hw, skb);
403 }
404
Juuso Oikarinenbe7078c2009-10-08 21:56:26 +0300405 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300406 if (wl->tx_frames[i] != NULL) {
407 skb = wl->tx_frames[i];
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300408 wl->tx_frames[i] = NULL;
Juuso Oikarinen781608c2010-05-24 11:18:17 +0300409 wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb);
Juuso Oikarinen6bbe89d2010-04-01 11:38:24 +0300410 ieee80211_tx_status(wl->hw, skb);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300411 }
Juuso Oikarinen781608c2010-05-24 11:18:17 +0300412 wl->tx_frames_cnt = 0;
413}
414
415#define WL1271_TX_FLUSH_TIMEOUT 500000
416
417/* caller must *NOT* hold wl->mutex */
418void wl1271_tx_flush(struct wl1271 *wl)
419{
420 unsigned long timeout;
421 timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT);
422
423 while (!time_after(jiffies, timeout)) {
424 mutex_lock(&wl->mutex);
425 wl1271_debug(DEBUG_TX, "flushing tx buffer: %d",
426 wl->tx_frames_cnt);
427 if ((wl->tx_frames_cnt == 0) &&
428 skb_queue_empty(&wl->tx_queue)) {
429 mutex_unlock(&wl->mutex);
430 return;
431 }
432 mutex_unlock(&wl->mutex);
433 msleep(1);
434 }
435
436 wl1271_warning("Unable to flush all TX buffers, timed out.");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300437}