blob: c8223185efd28129325dc46d52760dba7d5d6732 [file] [log] [blame]
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001/*
Kalle Valo80301cd2009-06-12 14:17:39 +03002 * This file is part of wl1251
Kalle Valo2f01a1f2009-04-29 23:33:31 +03003 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27
Kalle Valo13674112009-06-12 14:17:25 +030028#include "wl1251.h"
Kalle Valo29d904c2009-08-07 13:35:11 +030029#include "wl1251_reg.h"
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +030030#include "wl1251_tx.h"
Kalle Valoef2f8d42009-06-12 14:17:19 +030031#include "wl1251_ps.h"
Bob Copeland0764de62009-08-07 13:32:56 +030032#include "wl1251_io.h"
Kalle Valo2f01a1f2009-04-29 23:33:31 +030033
Kalle Valo80301cd2009-06-12 14:17:39 +030034static bool wl1251_tx_double_buffer_busy(struct wl1251 *wl, u32 data_out_count)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030035{
36 int used, data_in_count;
37
38 data_in_count = wl->data_in_count;
39
40 if (data_in_count < data_out_count)
41 /* data_in_count has wrapped */
42 data_in_count += TX_STATUS_DATA_OUT_COUNT_MASK + 1;
43
44 used = data_in_count - data_out_count;
45
46 WARN_ON(used < 0);
47 WARN_ON(used > DP_TX_PACKET_RING_CHUNK_NUM);
48
49 if (used >= DP_TX_PACKET_RING_CHUNK_NUM)
50 return true;
51 else
52 return false;
53}
54
Kalle Valo80301cd2009-06-12 14:17:39 +030055static int wl1251_tx_path_status(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030056{
57 u32 status, addr, data_out_count;
58 bool busy;
59
60 addr = wl->data_path->tx_control_addr;
Kalle Valo80301cd2009-06-12 14:17:39 +030061 status = wl1251_mem_read32(wl, addr);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030062 data_out_count = status & TX_STATUS_DATA_OUT_COUNT_MASK;
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +030063 busy = wl1251_tx_double_buffer_busy(wl, data_out_count);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030064
65 if (busy)
66 return -EBUSY;
67
68 return 0;
69}
70
Kalle Valo80301cd2009-06-12 14:17:39 +030071static int wl1251_tx_id(struct wl1251 *wl, struct sk_buff *skb)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030072{
73 int i;
74
75 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
76 if (wl->tx_frames[i] == NULL) {
77 wl->tx_frames[i] = skb;
78 return i;
79 }
80
81 return -EBUSY;
82}
83
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +030084static void wl1251_tx_control(struct tx_double_buffer_desc *tx_hdr,
Kalle Valo2f01a1f2009-04-29 23:33:31 +030085 struct ieee80211_tx_info *control, u16 fc)
86{
87 *(u16 *)&tx_hdr->control = 0;
88
89 tx_hdr->control.rate_policy = 0;
90
91 /* 802.11 packets */
92 tx_hdr->control.packet_type = 0;
93
94 if (control->flags & IEEE80211_TX_CTL_NO_ACK)
95 tx_hdr->control.ack_policy = 1;
96
97 tx_hdr->control.tx_complete = 1;
98
99 if ((fc & IEEE80211_FTYPE_DATA) &&
100 ((fc & IEEE80211_STYPE_QOS_DATA) ||
101 (fc & IEEE80211_STYPE_QOS_NULLFUNC)))
102 tx_hdr->control.qos = 1;
103}
104
105/* RSN + MIC = 8 + 8 = 16 bytes (worst case - AES). */
106#define MAX_MSDU_SECURITY_LENGTH 16
107#define MAX_MPDU_SECURITY_LENGTH 16
108#define WLAN_QOS_HDR_LEN 26
109#define MAX_MPDU_HEADER_AND_SECURITY (MAX_MPDU_SECURITY_LENGTH + \
110 WLAN_QOS_HDR_LEN)
111#define HW_BLOCK_SIZE 252
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300112static void wl1251_tx_frag_block_num(struct tx_double_buffer_desc *tx_hdr)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300113{
114 u16 payload_len, frag_threshold, mem_blocks;
115 u16 num_mpdus, mem_blocks_per_frag;
116
117 frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
118 tx_hdr->frag_threshold = cpu_to_le16(frag_threshold);
119
120 payload_len = tx_hdr->length + MAX_MSDU_SECURITY_LENGTH;
121
122 if (payload_len > frag_threshold) {
123 mem_blocks_per_frag =
124 ((frag_threshold + MAX_MPDU_HEADER_AND_SECURITY) /
125 HW_BLOCK_SIZE) + 1;
126 num_mpdus = payload_len / frag_threshold;
127 mem_blocks = num_mpdus * mem_blocks_per_frag;
128 payload_len -= num_mpdus * frag_threshold;
129 num_mpdus++;
130
131 } else {
132 mem_blocks_per_frag = 0;
133 mem_blocks = 0;
134 num_mpdus = 1;
135 }
136
137 mem_blocks += (payload_len / HW_BLOCK_SIZE) + 1;
138
139 if (num_mpdus > 1)
140 mem_blocks += min(num_mpdus, mem_blocks_per_frag);
141
142 tx_hdr->num_mem_blocks = mem_blocks;
143}
144
Kalle Valo80301cd2009-06-12 14:17:39 +0300145static int wl1251_tx_fill_hdr(struct wl1251 *wl, struct sk_buff *skb,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300146 struct ieee80211_tx_info *control)
147{
148 struct tx_double_buffer_desc *tx_hdr;
149 struct ieee80211_rate *rate;
150 int id;
151 u16 fc;
152
153 if (!skb)
154 return -EINVAL;
155
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300156 id = wl1251_tx_id(wl, skb);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300157 if (id < 0)
158 return id;
159
160 fc = *(u16 *)skb->data;
161 tx_hdr = (struct tx_double_buffer_desc *) skb_push(skb,
162 sizeof(*tx_hdr));
163
164 tx_hdr->length = cpu_to_le16(skb->len - sizeof(*tx_hdr));
165 rate = ieee80211_get_tx_rate(wl->hw, control);
166 tx_hdr->rate = cpu_to_le16(rate->hw_value);
167 tx_hdr->expiry_time = cpu_to_le32(1 << 16);
168 tx_hdr->id = id;
169
Kalle Valo49e1b9f2009-11-30 10:18:33 +0200170 tx_hdr->xmit_queue = wl1251_tx_get_queue(skb_get_queue_mapping(skb));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300171
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300172 wl1251_tx_control(tx_hdr, control, fc);
173 wl1251_tx_frag_block_num(tx_hdr);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300174
175 return 0;
176}
177
178/* We copy the packet to the target */
Kalle Valo80301cd2009-06-12 14:17:39 +0300179static int wl1251_tx_send_packet(struct wl1251 *wl, struct sk_buff *skb,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300180 struct ieee80211_tx_info *control)
181{
182 struct tx_double_buffer_desc *tx_hdr;
183 int len;
184 u32 addr;
185
186 if (!skb)
187 return -EINVAL;
188
189 tx_hdr = (struct tx_double_buffer_desc *) skb->data;
190
191 if (control->control.hw_key &&
192 control->control.hw_key->alg == ALG_TKIP) {
193 int hdrlen;
194 u16 fc;
195 u8 *pos;
196
197 fc = *(u16 *)(skb->data + sizeof(*tx_hdr));
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300198 tx_hdr->length += WL1251_TKIP_IV_SPACE;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300199
200 hdrlen = ieee80211_hdrlen(fc);
201
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300202 pos = skb_push(skb, WL1251_TKIP_IV_SPACE);
203 memmove(pos, pos + WL1251_TKIP_IV_SPACE,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300204 sizeof(*tx_hdr) + hdrlen);
205 }
206
207 /* Revisit. This is a workaround for getting non-aligned packets.
208 This happens at least with EAPOL packets from the user space.
209 Our DMA requires packets to be aligned on a 4-byte boundary.
210 */
211 if (unlikely((long)skb->data & 0x03)) {
212 int offset = (4 - (long)skb->data) & 0x03;
Kalle Valo80301cd2009-06-12 14:17:39 +0300213 wl1251_debug(DEBUG_TX, "skb offset %d", offset);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300214
215 /* check whether the current skb can be used */
216 if (!skb_cloned(skb) && (skb_tailroom(skb) >= offset)) {
217 unsigned char *src = skb->data;
218
219 /* align the buffer on a 4-byte boundary */
220 skb_reserve(skb, offset);
221 memmove(skb->data, src, skb->len);
Kalle Valo46cb35f2009-11-30 10:18:40 +0200222 tx_hdr = (struct tx_double_buffer_desc *) skb->data;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300223 } else {
Kalle Valo80301cd2009-06-12 14:17:39 +0300224 wl1251_info("No handler, fixme!");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300225 return -EINVAL;
226 }
227 }
228
229 /* Our skb->data at this point includes the HW header */
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300230 len = WL1251_TX_ALIGN(skb->len);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300231
232 if (wl->data_in_count & 0x1)
233 addr = wl->data_path->tx_packet_ring_addr +
234 wl->data_path->tx_packet_ring_chunk_size;
235 else
236 addr = wl->data_path->tx_packet_ring_addr;
237
Bob Copeland0764de62009-08-07 13:32:56 +0300238 wl1251_mem_write(wl, addr, skb->data, len);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300239
Kalle Valo49e1b9f2009-11-30 10:18:33 +0200240 wl1251_debug(DEBUG_TX, "tx id %u skb 0x%p payload %u rate 0x%x "
241 "queue %d", tx_hdr->id, skb, tx_hdr->length,
242 tx_hdr->rate, tx_hdr->xmit_queue);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300243
244 return 0;
245}
246
Kalle Valo80301cd2009-06-12 14:17:39 +0300247static void wl1251_tx_trigger(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300248{
249 u32 data, addr;
250
251 if (wl->data_in_count & 0x1) {
252 addr = ACX_REG_INTERRUPT_TRIG_H;
253 data = INTR_TRIG_TX_PROC1;
254 } else {
255 addr = ACX_REG_INTERRUPT_TRIG;
256 data = INTR_TRIG_TX_PROC0;
257 }
258
Kalle Valo80301cd2009-06-12 14:17:39 +0300259 wl1251_reg_write32(wl, addr, data);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300260
261 /* Bumping data in */
262 wl->data_in_count = (wl->data_in_count + 1) &
263 TX_STATUS_DATA_OUT_COUNT_MASK;
264}
265
266/* caller must hold wl->mutex */
Kalle Valo80301cd2009-06-12 14:17:39 +0300267static int wl1251_tx_frame(struct wl1251 *wl, struct sk_buff *skb)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300268{
269 struct ieee80211_tx_info *info;
270 int ret = 0;
271 u8 idx;
272
273 info = IEEE80211_SKB_CB(skb);
274
275 if (info->control.hw_key) {
276 idx = info->control.hw_key->hw_key_idx;
277 if (unlikely(wl->default_key != idx)) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300278 ret = wl1251_acx_default_key(wl, idx);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300279 if (ret < 0)
280 return ret;
281 }
282 }
283
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300284 ret = wl1251_tx_path_status(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300285 if (ret < 0)
286 return ret;
287
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300288 ret = wl1251_tx_fill_hdr(wl, skb, info);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300289 if (ret < 0)
290 return ret;
291
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300292 ret = wl1251_tx_send_packet(wl, skb, info);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300293 if (ret < 0)
294 return ret;
295
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300296 wl1251_tx_trigger(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300297
298 return ret;
299}
300
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300301void wl1251_tx_work(struct work_struct *work)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300302{
Kalle Valo80301cd2009-06-12 14:17:39 +0300303 struct wl1251 *wl = container_of(work, struct wl1251, tx_work);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300304 struct sk_buff *skb;
305 bool woken_up = false;
306 int ret;
307
308 mutex_lock(&wl->mutex);
309
Kalle Valo80301cd2009-06-12 14:17:39 +0300310 if (unlikely(wl->state == WL1251_STATE_OFF))
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300311 goto out;
312
313 while ((skb = skb_dequeue(&wl->tx_queue))) {
314 if (!woken_up) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300315 ret = wl1251_ps_elp_wakeup(wl);
Kalle Valoc5483b72009-06-12 14:16:32 +0300316 if (ret < 0)
317 goto out;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300318 woken_up = true;
319 }
320
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300321 ret = wl1251_tx_frame(wl, skb);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300322 if (ret == -EBUSY) {
323 /* firmware buffer is full, stop queues */
Kalle Valo80301cd2009-06-12 14:17:39 +0300324 wl1251_debug(DEBUG_TX, "tx_work: fw buffer full, "
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300325 "stop queues");
326 ieee80211_stop_queues(wl->hw);
327 wl->tx_queue_stopped = true;
328 skb_queue_head(&wl->tx_queue, skb);
329 goto out;
330 } else if (ret < 0) {
331 dev_kfree_skb(skb);
332 goto out;
333 }
334 }
335
336out:
337 if (woken_up)
Kalle Valo80301cd2009-06-12 14:17:39 +0300338 wl1251_ps_elp_sleep(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300339
340 mutex_unlock(&wl->mutex);
341}
342
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300343static const char *wl1251_tx_parse_status(u8 status)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300344{
345 /* 8 bit status field, one character per bit plus null */
346 static char buf[9];
347 int i = 0;
348
349 memset(buf, 0, sizeof(buf));
350
351 if (status & TX_DMA_ERROR)
352 buf[i++] = 'm';
353 if (status & TX_DISABLED)
354 buf[i++] = 'd';
355 if (status & TX_RETRY_EXCEEDED)
356 buf[i++] = 'r';
357 if (status & TX_TIMEOUT)
358 buf[i++] = 't';
359 if (status & TX_KEY_NOT_FOUND)
360 buf[i++] = 'k';
361 if (status & TX_ENCRYPT_FAIL)
362 buf[i++] = 'e';
363 if (status & TX_UNAVAILABLE_PRIORITY)
364 buf[i++] = 'p';
365
366 /* bit 0 is unused apparently */
367
368 return buf;
369}
370
Kalle Valo80301cd2009-06-12 14:17:39 +0300371static void wl1251_tx_packet_cb(struct wl1251 *wl,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300372 struct tx_result *result)
373{
374 struct ieee80211_tx_info *info;
375 struct sk_buff *skb;
376 int hdrlen, ret;
377 u8 *frame;
378
379 skb = wl->tx_frames[result->id];
380 if (skb == NULL) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300381 wl1251_error("SKB for packet %d is NULL", result->id);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300382 return;
383 }
384
385 info = IEEE80211_SKB_CB(skb);
386
387 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) &&
388 (result->status == TX_SUCCESS))
389 info->flags |= IEEE80211_TX_STAT_ACK;
390
391 info->status.rates[0].count = result->ack_failures + 1;
392 wl->stats.retry_count += result->ack_failures;
393
394 /*
395 * We have to remove our private TX header before pushing
396 * the skb back to mac80211.
397 */
398 frame = skb_pull(skb, sizeof(struct tx_double_buffer_desc));
399 if (info->control.hw_key &&
400 info->control.hw_key->alg == ALG_TKIP) {
401 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300402 memmove(frame + WL1251_TKIP_IV_SPACE, frame, hdrlen);
403 skb_pull(skb, WL1251_TKIP_IV_SPACE);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300404 }
405
Kalle Valo80301cd2009-06-12 14:17:39 +0300406 wl1251_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300407 " status 0x%x (%s)",
408 result->id, skb, result->ack_failures, result->rate,
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300409 result->status, wl1251_tx_parse_status(result->status));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300410
411
412 ieee80211_tx_status(wl->hw, skb);
413
414 wl->tx_frames[result->id] = NULL;
415
416 if (wl->tx_queue_stopped) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300417 wl1251_debug(DEBUG_TX, "cb: queue was stopped");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300418
419 skb = skb_dequeue(&wl->tx_queue);
420
421 /* The skb can be NULL because tx_work might have been
422 scheduled before the queue was stopped making the
423 queue empty */
424
425 if (skb) {
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300426 ret = wl1251_tx_frame(wl, skb);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300427 if (ret == -EBUSY) {
428 /* firmware buffer is still full */
Kalle Valo80301cd2009-06-12 14:17:39 +0300429 wl1251_debug(DEBUG_TX, "cb: fw buffer "
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300430 "still full");
431 skb_queue_head(&wl->tx_queue, skb);
432 return;
433 } else if (ret < 0) {
434 dev_kfree_skb(skb);
435 return;
436 }
437 }
438
Kalle Valo80301cd2009-06-12 14:17:39 +0300439 wl1251_debug(DEBUG_TX, "cb: waking queues");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300440 ieee80211_wake_queues(wl->hw);
441 wl->tx_queue_stopped = false;
442 }
443}
444
445/* Called upon reception of a TX complete interrupt */
Kalle Valo80301cd2009-06-12 14:17:39 +0300446void wl1251_tx_complete(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300447{
448 int i, result_index, num_complete = 0;
449 struct tx_result result[FW_TX_CMPLT_BLOCK_SIZE], *result_ptr;
450
Kalle Valo80301cd2009-06-12 14:17:39 +0300451 if (unlikely(wl->state != WL1251_STATE_ON))
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300452 return;
453
454 /* First we read the result */
Bob Copeland0764de62009-08-07 13:32:56 +0300455 wl1251_mem_read(wl, wl->data_path->tx_complete_addr,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300456 result, sizeof(result));
457
458 result_index = wl->next_tx_complete;
459
460 for (i = 0; i < ARRAY_SIZE(result); i++) {
461 result_ptr = &result[result_index];
462
463 if (result_ptr->done_1 == 1 &&
464 result_ptr->done_2 == 1) {
Juuso Oikarinen9f2ad4f2009-06-12 14:15:54 +0300465 wl1251_tx_packet_cb(wl, result_ptr);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300466
467 result_ptr->done_1 = 0;
468 result_ptr->done_2 = 0;
469
470 result_index = (result_index + 1) &
471 (FW_TX_CMPLT_BLOCK_SIZE - 1);
472 num_complete++;
473 } else {
474 break;
475 }
476 }
477
478 /* Every completed frame needs to be acknowledged */
479 if (num_complete) {
480 /*
481 * If we've wrapped, we have to clear
482 * the results in 2 steps.
483 */
484 if (result_index > wl->next_tx_complete) {
485 /* Only 1 write is needed */
Bob Copeland0764de62009-08-07 13:32:56 +0300486 wl1251_mem_write(wl,
487 wl->data_path->tx_complete_addr +
488 (wl->next_tx_complete *
489 sizeof(struct tx_result)),
490 &result[wl->next_tx_complete],
491 num_complete *
492 sizeof(struct tx_result));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300493
494
495 } else if (result_index < wl->next_tx_complete) {
496 /* 2 writes are needed */
Bob Copeland0764de62009-08-07 13:32:56 +0300497 wl1251_mem_write(wl,
498 wl->data_path->tx_complete_addr +
499 (wl->next_tx_complete *
500 sizeof(struct tx_result)),
501 &result[wl->next_tx_complete],
502 (FW_TX_CMPLT_BLOCK_SIZE -
503 wl->next_tx_complete) *
504 sizeof(struct tx_result));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300505
Bob Copeland0764de62009-08-07 13:32:56 +0300506 wl1251_mem_write(wl,
507 wl->data_path->tx_complete_addr,
508 result,
509 (num_complete -
510 FW_TX_CMPLT_BLOCK_SIZE +
511 wl->next_tx_complete) *
512 sizeof(struct tx_result));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300513
514 } else {
515 /* We have to write the whole array */
Bob Copeland0764de62009-08-07 13:32:56 +0300516 wl1251_mem_write(wl,
517 wl->data_path->tx_complete_addr,
518 result,
519 FW_TX_CMPLT_BLOCK_SIZE *
520 sizeof(struct tx_result));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300521 }
522
523 }
524
525 wl->next_tx_complete = result_index;
526}
527
528/* caller must hold wl->mutex */
Kalle Valo80301cd2009-06-12 14:17:39 +0300529void wl1251_tx_flush(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300530{
531 int i;
532 struct sk_buff *skb;
533 struct ieee80211_tx_info *info;
534
535 /* TX failure */
536/* control->flags = 0; FIXME */
537
538 while ((skb = skb_dequeue(&wl->tx_queue))) {
539 info = IEEE80211_SKB_CB(skb);
540
Kalle Valo80301cd2009-06-12 14:17:39 +0300541 wl1251_debug(DEBUG_TX, "flushing skb 0x%p", skb);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300542
543 if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS))
544 continue;
545
546 ieee80211_tx_status(wl->hw, skb);
547 }
548
549 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
550 if (wl->tx_frames[i] != NULL) {
551 skb = wl->tx_frames[i];
552 info = IEEE80211_SKB_CB(skb);
553
554 if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS))
555 continue;
556
557 ieee80211_tx_status(wl->hw, skb);
558 wl->tx_frames[i] = NULL;
559 }
560}