blob: 85878e5e75260a52852c6a47272bec42d7a69217 [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
Ido Yariv25eeb9e2010-10-12 16:20:06 +020033static int wl1271_alloc_tx_id(struct wl1271 *wl, struct sk_buff *skb)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030034{
Ido Yariv25eeb9e2010-10-12 16:20:06 +020035 int id;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030036
Ido Yariv25eeb9e2010-10-12 16:20:06 +020037 id = find_first_zero_bit(wl->tx_frames_map, ACX_TX_DESCRIPTORS);
38 if (id >= ACX_TX_DESCRIPTORS)
39 return -EBUSY;
40
41 __set_bit(id, wl->tx_frames_map);
42 wl->tx_frames[id] = skb;
43 wl->tx_frames_cnt++;
44 return id;
45}
46
47static void wl1271_free_tx_id(struct wl1271 *wl, int id)
48{
49 if (__test_and_clear_bit(id, wl->tx_frames_map)) {
50 wl->tx_frames[id] = NULL;
51 wl->tx_frames_cnt--;
52 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030053}
54
Ido Yariva19606b2010-09-30 13:28:28 +020055static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
56 u32 buf_offset)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030057{
58 struct wl1271_tx_hw_descr *desc;
59 u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra;
Juuso Oikarinen5c9417f2010-02-22 08:38:39 +020060 u32 total_blocks;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030061 int id, ret = -EBUSY;
62
Ido Yariva19606b2010-09-30 13:28:28 +020063 if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE)
Ido Yariv6c6e6692010-10-12 14:49:09 +020064 return -EAGAIN;
Ido Yariva19606b2010-09-30 13:28:28 +020065
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030066 /* allocate free identifier for the packet */
Ido Yariv25eeb9e2010-10-12 16:20:06 +020067 id = wl1271_alloc_tx_id(wl, skb);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030068 if (id < 0)
69 return id;
70
71 /* approximate the number of blocks required for this packet
72 in the firmware */
Juuso Oikarinen5c9417f2010-02-22 08:38:39 +020073 total_blocks = total_len + TX_HW_BLOCK_SIZE - 1;
74 total_blocks = total_blocks / TX_HW_BLOCK_SIZE + TX_HW_BLOCK_SPARE;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030075 if (total_blocks <= wl->tx_blocks_available) {
76 desc = (struct wl1271_tx_hw_descr *)skb_push(
77 skb, total_len - skb->len);
78
79 desc->extra_mem_blocks = TX_HW_BLOCK_SPARE;
80 desc->total_mem_blocks = total_blocks;
81 desc->id = id;
82
83 wl->tx_blocks_available -= total_blocks;
84
85 ret = 0;
86
87 wl1271_debug(DEBUG_TX,
88 "tx_allocate: size: %d, blocks: %d, id: %d",
89 total_len, total_blocks, id);
Juuso Oikarinen781608c2010-05-24 11:18:17 +030090 } else {
Ido Yariv25eeb9e2010-10-12 16:20:06 +020091 wl1271_free_tx_id(wl, id);
Juuso Oikarinen781608c2010-05-24 11:18:17 +030092 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030093
94 return ret;
95}
96
Ido Yariva19606b2010-09-30 13:28:28 +020097static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030098 u32 extra, struct ieee80211_tx_info *control)
99{
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200100 struct timespec ts;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300101 struct wl1271_tx_hw_descr *desc;
Kalle Valoc6999d82010-02-18 13:25:41 +0200102 int pad, ac;
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200103 s64 hosttime;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300104 u16 tx_attr;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300105
106 desc = (struct wl1271_tx_hw_descr *) skb->data;
107
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +0300108 /* relocate space for security header */
109 if (extra) {
110 void *framestart = skb->data + sizeof(*desc);
111 u16 fc = *(u16 *)(framestart + extra);
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300112 int hdrlen = ieee80211_hdrlen(cpu_to_le16(fc));
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +0300113 memmove(framestart, framestart + extra, hdrlen);
114 }
115
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300116 /* configure packet life time */
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200117 getnstimeofday(&ts);
118 hosttime = (timespec_to_ns(&ts) >> 10);
119 desc->start_time = cpu_to_le32(hosttime - wl->time_offset);
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300120 desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300121
122 /* configure the tx attributes */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300123 tx_attr = wl->session_counter << TX_HW_ATTR_OFST_SESSION_COUNTER;
Kalle Valoc6999d82010-02-18 13:25:41 +0200124
Juuso Oikarinened484a12010-09-01 11:31:11 +0200125 /* queue (we use same identifiers for tid's and ac's */
Kalle Valoc6999d82010-02-18 13:25:41 +0200126 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
Juuso Oikarinened484a12010-09-01 11:31:11 +0200127 desc->tid = ac;
Kalle Valoc6999d82010-02-18 13:25:41 +0200128
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300129 desc->aid = TX_HW_DEFAULT_AID;
130 desc->reserved = 0;
131
132 /* align the length (and store in terms of words) */
133 pad = WL1271_TX_ALIGN(skb->len);
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300134 desc->length = cpu_to_le16(pad >> 2);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300135
136 /* calculate number of padding bytes */
137 pad = pad - skb->len;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300138 tx_attr |= pad << TX_HW_ATTR_OFST_LAST_WORD_PAD;
139
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200140 /* if the packets are destined for AP (have a STA entry) send them
141 with AP rate policies, otherwise use default basic rates */
142 if (control->control.sta)
143 tx_attr |= ACX_TX_AP_FULL_RATE << TX_HW_ATTR_OFST_RATE_POLICY;
144
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300145 desc->tx_attr = cpu_to_le16(tx_attr);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300146
147 wl1271_debug(DEBUG_TX, "tx_fill_hdr: pad: %d", pad);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300148}
149
150/* caller must hold wl->mutex */
Ido Yariva19606b2010-09-30 13:28:28 +0200151static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct sk_buff *skb,
152 u32 buf_offset)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300153{
154 struct ieee80211_tx_info *info;
155 u32 extra = 0;
156 int ret = 0;
157 u8 idx;
Ido Yariva19606b2010-09-30 13:28:28 +0200158 u32 total_len;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300159
160 if (!skb)
161 return -EINVAL;
162
163 info = IEEE80211_SKB_CB(skb);
164
165 if (info->control.hw_key &&
Johannes Berg97359d12010-08-10 09:46:38 +0200166 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300167 extra = WL1271_TKIP_IV_SPACE;
168
169 if (info->control.hw_key) {
170 idx = info->control.hw_key->hw_key_idx;
171
172 /* FIXME: do we have to do this if we're not using WEP? */
173 if (unlikely(wl->default_key != idx)) {
174 ret = wl1271_cmd_set_default_wep_key(wl, idx);
175 if (ret < 0)
176 return ret;
Juuso Oikarinenee444cf2010-02-18 13:25:50 +0200177 wl->default_key = idx;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300178 }
179 }
180
Ido Yariva19606b2010-09-30 13:28:28 +0200181 ret = wl1271_tx_allocate(wl, skb, extra, buf_offset);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300182 if (ret < 0)
183 return ret;
184
Ido Yariva19606b2010-09-30 13:28:28 +0200185 wl1271_tx_fill_hdr(wl, skb, extra, info);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300186
Ido Yariva19606b2010-09-30 13:28:28 +0200187 /*
188 * The length of each packet is stored in terms of words. Thus, we must
189 * pad the skb data to make sure its length is aligned.
190 * The number of padding bytes is computed and set in wl1271_tx_fill_hdr
191 */
192 total_len = WL1271_TX_ALIGN(skb->len);
193 memcpy(wl->aggr_buf + buf_offset, skb->data, skb->len);
194 memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300195
Ido Yariva19606b2010-09-30 13:28:28 +0200196 return total_len;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300197}
198
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300199u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set)
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200200{
201 struct ieee80211_supported_band *band;
202 u32 enabled_rates = 0;
203 int bit;
204
205 band = wl->hw->wiphy->bands[wl->band];
206 for (bit = 0; bit < band->n_bitrates; bit++) {
207 if (rate_set & 0x1)
208 enabled_rates |= band->bitrates[bit].hw_value;
209 rate_set >>= 1;
210 }
211
212 return enabled_rates;
213}
214
Ido Yariva5225502010-10-12 14:49:10 +0200215void wl1271_tx_work_locked(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300216{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300217 struct sk_buff *skb;
218 bool woken_up = false;
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200219 u32 sta_rates = 0;
Ido Yariv6c6e6692010-10-12 14:49:09 +0200220 u32 buf_offset = 0;
221 bool sent_packets = false;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300222 int ret;
223
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200224 /* check if the rates supported by the AP have changed */
225 if (unlikely(test_and_clear_bit(WL1271_FLAG_STA_RATES_CHANGED,
226 &wl->flags))) {
227 unsigned long flags;
228 spin_lock_irqsave(&wl->wl_lock, flags);
229 sta_rates = wl->sta_rate_set;
230 spin_unlock_irqrestore(&wl->wl_lock, flags);
231 }
232
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300233 if (unlikely(wl->state == WL1271_STATE_OFF))
234 goto out;
235
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200236 /* if rates have changed, re-configure the rate policy */
237 if (unlikely(sta_rates)) {
238 wl->rate_set = wl1271_tx_enabled_rates_get(wl, sta_rates);
239 wl1271_acx_rate_policies(wl);
240 }
241
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300242 while ((skb = skb_dequeue(&wl->tx_queue))) {
243 if (!woken_up) {
244 ret = wl1271_ps_elp_wakeup(wl, false);
245 if (ret < 0)
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200246 goto out_ack;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300247 woken_up = true;
248 }
249
Ido Yariva19606b2010-09-30 13:28:28 +0200250 ret = wl1271_prepare_tx_frame(wl, skb, buf_offset);
Ido Yariv6c6e6692010-10-12 14:49:09 +0200251 if (ret == -EAGAIN) {
Ido Yariva19606b2010-09-30 13:28:28 +0200252 /*
Ido Yariv6c6e6692010-10-12 14:49:09 +0200253 * Aggregation buffer is full.
254 * Flush buffer and try again.
255 */
256 skb_queue_head(&wl->tx_queue, skb);
257 wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
258 buf_offset, true);
259 sent_packets = true;
260 buf_offset = 0;
261 continue;
262 } else if (ret == -EBUSY) {
263 /*
264 * Firmware buffer is full.
Ido Yariva19606b2010-09-30 13:28:28 +0200265 * Queue back last skb, and stop aggregating.
266 */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300267 skb_queue_head(&wl->tx_queue, skb);
Ido Yariva5225502010-10-12 14:49:10 +0200268 /* No work left, avoid scheduling redundant tx work */
269 set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200270 goto out_ack;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300271 } else if (ret < 0) {
272 dev_kfree_skb(skb);
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200273 goto out_ack;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300274 }
Ido Yariva19606b2010-09-30 13:28:28 +0200275 buf_offset += ret;
276 wl->tx_packets_count++;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300277 }
278
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200279out_ack:
Ido Yariva19606b2010-09-30 13:28:28 +0200280 if (buf_offset) {
281 wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
282 buf_offset, true);
Ido Yariv6c6e6692010-10-12 14:49:09 +0200283 sent_packets = true;
284 }
285 if (sent_packets) {
Ido Yariva19606b2010-09-30 13:28:28 +0200286 /* interrupt the firmware with the new packets */
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200287 wl1271_write32(wl, WL1271_HOST_WR_ACCESS, wl->tx_packets_count);
Ido Yariva19606b2010-09-30 13:28:28 +0200288 }
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200289
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300290out:
291 if (woken_up)
292 wl1271_ps_elp_sleep(wl);
Ido Yariva5225502010-10-12 14:49:10 +0200293}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300294
Ido Yariva5225502010-10-12 14:49:10 +0200295void wl1271_tx_work(struct work_struct *work)
296{
297 struct wl1271 *wl = container_of(work, struct wl1271, tx_work);
298
299 mutex_lock(&wl->mutex);
300 wl1271_tx_work_locked(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300301 mutex_unlock(&wl->mutex);
302}
303
304static void wl1271_tx_complete_packet(struct wl1271 *wl,
305 struct wl1271_tx_hw_res_descr *result)
306{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300307 struct ieee80211_tx_info *info;
308 struct sk_buff *skb;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300309 int id = result->id;
Juuso Oikarinen31627dc2010-03-26 12:53:12 +0200310 int rate = -1;
311 u8 retries = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300312
313 /* check for id legality */
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200314 if (unlikely(id >= ACX_TX_DESCRIPTORS || wl->tx_frames[id] == NULL)) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300315 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 Oikarinen31627dc2010-03-26 12:53:12 +0200322 /* update the TX status info */
323 if (result->status == TX_SUCCESS) {
324 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300325 info->flags |= IEEE80211_TX_STAT_ACK;
Juuso Oikarinen31627dc2010-03-26 12:53:12 +0200326 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 Coelhof5fc0f82009-08-06 16:25:28 +0300331 }
332
Juuso Oikarinen31627dc2010-03-26 12:53:12 +0200333 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 Coelhof5fc0f82009-08-06 16:25:28 +0300338 wl->stats.retry_count += result->ack_failures;
339
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300340 /* update security sequence number */
Juuso Oikarinen04e36fc2010-02-22 08:38:40 +0200341 wl->tx_security_seq += (result->lsb_security_sequence_number -
342 wl->tx_security_last_seq);
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300343 wl->tx_security_last_seq = result->lsb_security_sequence_number;
344
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +0300345 /* remove private header from packet */
346 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
347
348 /* remove TKIP header space if present */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300349 if (info->control.hw_key &&
Johannes Berg97359d12010-08-10 09:46:38 +0200350 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +0300351 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 Coelhof5fc0f82009-08-06 16:25:28 +0300355
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 Coelhof5fc0f82009-08-06 16:25:28 +0300361 /* return the packet to the stack */
362 ieee80211_tx_status(wl->hw, skb);
Ido Yariv25eeb9e2010-10-12 16:20:06 +0200363 wl1271_free_tx_id(wl, result->id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300364}
365
366/* Called upon reception of a TX complete interrupt */
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200367void wl1271_tx_complete(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300368{
369 struct wl1271_acx_mem_map *memmap =
370 (struct wl1271_acx_mem_map *)wl->target_mem_map;
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200371 u32 count, fw_counter;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300372 u32 i;
373
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300374 /* read the tx results from the chipset */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200375 wl1271_read(wl, le32_to_cpu(memmap->tx_result),
376 wl->tx_res_if, sizeof(*wl->tx_res_if), false);
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200377 fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter);
378
379 /* write host counter to chipset (to ack) */
380 wl1271_write32(wl, le32_to_cpu(memmap->tx_result) +
381 offsetof(struct wl1271_tx_hw_res_if,
382 tx_result_host_counter), fw_counter);
383
384 count = fw_counter - wl->tx_results_count;
Juuso Oikarinen06f7bc72010-02-22 08:38:33 +0200385 wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300386
387 /* verify that the result buffer is not getting overrun */
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200388 if (unlikely(count > TX_HW_RESULT_QUEUE_LEN))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300389 wl1271_warning("TX result overflow from chipset: %d", count);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300390
391 /* process the results */
392 for (i = 0; i < count; i++) {
393 struct wl1271_tx_hw_res_descr *result;
394 u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK;
395
396 /* process the packet */
397 result = &(wl->tx_res_if->tx_results_queue[offset]);
398 wl1271_tx_complete_packet(wl, result);
399
400 wl->tx_results_count++;
401 }
Juuso Oikarinen06f7bc72010-02-22 08:38:33 +0200402
403 if (test_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags) &&
404 skb_queue_len(&wl->tx_queue) <= WL1271_TX_QUEUE_LOW_WATERMARK) {
405 unsigned long flags;
406
407 /* firmware buffer has space, restart queues */
408 wl1271_debug(DEBUG_TX, "tx_complete: waking queues");
409 spin_lock_irqsave(&wl->wl_lock, flags);
410 ieee80211_wake_queues(wl->hw);
411 clear_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
412 spin_unlock_irqrestore(&wl->wl_lock, flags);
413 ieee80211_queue_work(wl->hw, &wl->tx_work);
414 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300415}
416
417/* caller must hold wl->mutex */
Juuso Oikarinen781608c2010-05-24 11:18:17 +0300418void wl1271_tx_reset(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300419{
420 int i;
421 struct sk_buff *skb;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300422
423 /* TX failure */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300424 while ((skb = skb_dequeue(&wl->tx_queue))) {
Juuso Oikarinen781608c2010-05-24 11:18:17 +0300425 wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300426 ieee80211_tx_status(wl->hw, skb);
427 }
428
Juuso Oikarinenbe7078c2009-10-08 21:56:26 +0300429 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300430 if (wl->tx_frames[i] != NULL) {
431 skb = wl->tx_frames[i];
Ido Yariv25eeb9e2010-10-12 16:20:06 +0200432 wl1271_free_tx_id(wl, i);
Juuso Oikarinen781608c2010-05-24 11:18:17 +0300433 wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb);
Juuso Oikarinen6bbe89d2010-04-01 11:38:24 +0300434 ieee80211_tx_status(wl->hw, skb);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300435 }
Juuso Oikarinen781608c2010-05-24 11:18:17 +0300436}
437
438#define WL1271_TX_FLUSH_TIMEOUT 500000
439
440/* caller must *NOT* hold wl->mutex */
441void wl1271_tx_flush(struct wl1271 *wl)
442{
443 unsigned long timeout;
444 timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT);
445
446 while (!time_after(jiffies, timeout)) {
447 mutex_lock(&wl->mutex);
448 wl1271_debug(DEBUG_TX, "flushing tx buffer: %d",
449 wl->tx_frames_cnt);
450 if ((wl->tx_frames_cnt == 0) &&
451 skb_queue_empty(&wl->tx_queue)) {
452 mutex_unlock(&wl->mutex);
453 return;
454 }
455 mutex_unlock(&wl->mutex);
456 msleep(1);
457 }
458
459 wl1271_warning("Unable to flush all TX buffers, timed out.");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300460}