Commit | Line | Data |
---|---|---|
f5fc0f86 LC |
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 | ||
00d20100 SL |
27 | #include "wl12xx.h" |
28 | #include "io.h" | |
29 | #include "reg.h" | |
30 | #include "ps.h" | |
31 | #include "tx.h" | |
f5fc0f86 | 32 | |
25eeb9e3 | 33 | static int wl1271_alloc_tx_id(struct wl1271 *wl, struct sk_buff *skb) |
f5fc0f86 | 34 | { |
25eeb9e3 IY |
35 | int id; |
36 | ||
37 | 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 | } | |
f5fc0f86 | 46 | |
25eeb9e3 IY |
47 | static 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 | } | |
f5fc0f86 LC |
53 | } |
54 | ||
a19606b4 IY |
55 | static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra, |
56 | u32 buf_offset) | |
f5fc0f86 LC |
57 | { |
58 | struct wl1271_tx_hw_descr *desc; | |
59 | u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra; | |
5c9417f1 | 60 | u32 total_blocks; |
f5fc0f86 LC |
61 | int id, ret = -EBUSY; |
62 | ||
a19606b4 | 63 | if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE) |
6c6e669e | 64 | return -EAGAIN; |
a19606b4 | 65 | |
f5fc0f86 | 66 | /* allocate free identifier for the packet */ |
25eeb9e3 | 67 | id = wl1271_alloc_tx_id(wl, skb); |
f5fc0f86 LC |
68 | if (id < 0) |
69 | return id; | |
70 | ||
71 | /* approximate the number of blocks required for this packet | |
72 | in the firmware */ | |
5c9417f1 JO |
73 | total_blocks = total_len + TX_HW_BLOCK_SIZE - 1; |
74 | total_blocks = total_blocks / TX_HW_BLOCK_SIZE + TX_HW_BLOCK_SPARE; | |
f5fc0f86 LC |
75 | 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); | |
781608c4 | 90 | } else { |
25eeb9e3 | 91 | wl1271_free_tx_id(wl, id); |
781608c4 | 92 | } |
f5fc0f86 LC |
93 | |
94 | return ret; | |
95 | } | |
96 | ||
a19606b4 | 97 | static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb, |
f5fc0f86 LC |
98 | u32 extra, struct ieee80211_tx_info *control) |
99 | { | |
ac5e1e39 | 100 | struct timespec ts; |
f5fc0f86 | 101 | struct wl1271_tx_hw_descr *desc; |
c6999d83 | 102 | int pad, ac; |
ac5e1e39 | 103 | s64 hosttime; |
d0f63b20 | 104 | u16 tx_attr; |
f5fc0f86 LC |
105 | |
106 | desc = (struct wl1271_tx_hw_descr *) skb->data; | |
107 | ||
1e2b7976 JO |
108 | /* relocate space for security header */ |
109 | if (extra) { | |
110 | void *framestart = skb->data + sizeof(*desc); | |
111 | u16 fc = *(u16 *)(framestart + extra); | |
d0f63b20 | 112 | int hdrlen = ieee80211_hdrlen(cpu_to_le16(fc)); |
1e2b7976 JO |
113 | memmove(framestart, framestart + extra, hdrlen); |
114 | } | |
115 | ||
f5fc0f86 | 116 | /* configure packet life time */ |
ac5e1e39 JO |
117 | getnstimeofday(&ts); |
118 | hosttime = (timespec_to_ns(&ts) >> 10); | |
119 | desc->start_time = cpu_to_le32(hosttime - wl->time_offset); | |
d0f63b20 | 120 | desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU); |
f5fc0f86 LC |
121 | |
122 | /* configure the tx attributes */ | |
d0f63b20 | 123 | tx_attr = wl->session_counter << TX_HW_ATTR_OFST_SESSION_COUNTER; |
c6999d83 | 124 | |
ed484a16 | 125 | /* queue (we use same identifiers for tid's and ac's */ |
c6999d83 | 126 | ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); |
ed484a16 | 127 | desc->tid = ac; |
f5fc0f86 LC |
128 | desc->aid = TX_HW_DEFAULT_AID; |
129 | desc->reserved = 0; | |
130 | ||
131 | /* align the length (and store in terms of words) */ | |
132 | pad = WL1271_TX_ALIGN(skb->len); | |
d0f63b20 | 133 | desc->length = cpu_to_le16(pad >> 2); |
f5fc0f86 LC |
134 | |
135 | /* calculate number of padding bytes */ | |
136 | pad = pad - skb->len; | |
d0f63b20 LC |
137 | tx_attr |= pad << TX_HW_ATTR_OFST_LAST_WORD_PAD; |
138 | ||
830fb67b JO |
139 | /* if the packets are destined for AP (have a STA entry) send them |
140 | with AP rate policies, otherwise use default basic rates */ | |
141 | if (control->control.sta) | |
142 | tx_attr |= ACX_TX_AP_FULL_RATE << TX_HW_ATTR_OFST_RATE_POLICY; | |
143 | ||
d0f63b20 | 144 | desc->tx_attr = cpu_to_le16(tx_attr); |
f5fc0f86 LC |
145 | |
146 | wl1271_debug(DEBUG_TX, "tx_fill_hdr: pad: %d", pad); | |
f5fc0f86 LC |
147 | } |
148 | ||
149 | /* caller must hold wl->mutex */ | |
a19606b4 IY |
150 | static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct sk_buff *skb, |
151 | u32 buf_offset) | |
f5fc0f86 LC |
152 | { |
153 | struct ieee80211_tx_info *info; | |
154 | u32 extra = 0; | |
155 | int ret = 0; | |
156 | u8 idx; | |
a19606b4 | 157 | u32 total_len; |
f5fc0f86 LC |
158 | |
159 | if (!skb) | |
160 | return -EINVAL; | |
161 | ||
162 | info = IEEE80211_SKB_CB(skb); | |
163 | ||
164 | if (info->control.hw_key && | |
97359d12 | 165 | info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) |
f5fc0f86 LC |
166 | extra = WL1271_TKIP_IV_SPACE; |
167 | ||
168 | if (info->control.hw_key) { | |
169 | idx = info->control.hw_key->hw_key_idx; | |
170 | ||
171 | /* FIXME: do we have to do this if we're not using WEP? */ | |
172 | if (unlikely(wl->default_key != idx)) { | |
98bdaabb | 173 | ret = wl1271_cmd_set_sta_default_wep_key(wl, idx); |
f5fc0f86 LC |
174 | if (ret < 0) |
175 | return ret; | |
ee444cf0 | 176 | wl->default_key = idx; |
f5fc0f86 LC |
177 | } |
178 | } | |
179 | ||
a19606b4 | 180 | ret = wl1271_tx_allocate(wl, skb, extra, buf_offset); |
f5fc0f86 LC |
181 | if (ret < 0) |
182 | return ret; | |
183 | ||
a19606b4 | 184 | wl1271_tx_fill_hdr(wl, skb, extra, info); |
f5fc0f86 | 185 | |
a19606b4 IY |
186 | /* |
187 | * The length of each packet is stored in terms of words. Thus, we must | |
188 | * pad the skb data to make sure its length is aligned. | |
189 | * The number of padding bytes is computed and set in wl1271_tx_fill_hdr | |
190 | */ | |
191 | total_len = WL1271_TX_ALIGN(skb->len); | |
192 | memcpy(wl->aggr_buf + buf_offset, skb->data, skb->len); | |
193 | memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len); | |
f5fc0f86 | 194 | |
a19606b4 | 195 | return total_len; |
f5fc0f86 LC |
196 | } |
197 | ||
ebba60c6 | 198 | u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set) |
830fb67b JO |
199 | { |
200 | struct ieee80211_supported_band *band; | |
201 | u32 enabled_rates = 0; | |
202 | int bit; | |
203 | ||
204 | band = wl->hw->wiphy->bands[wl->band]; | |
205 | for (bit = 0; bit < band->n_bitrates; bit++) { | |
206 | if (rate_set & 0x1) | |
207 | enabled_rates |= band->bitrates[bit].hw_value; | |
208 | rate_set >>= 1; | |
209 | } | |
210 | ||
00d20100 | 211 | #ifdef CONFIG_WL12XX_HT |
18357850 SL |
212 | /* MCS rates indication are on bits 16 - 23 */ |
213 | rate_set >>= HW_HT_RATES_OFFSET - band->n_bitrates; | |
214 | ||
215 | for (bit = 0; bit < 8; bit++) { | |
216 | if (rate_set & 0x1) | |
217 | enabled_rates |= (CONF_HW_BIT_RATE_MCS_0 << bit); | |
218 | rate_set >>= 1; | |
219 | } | |
220 | #endif | |
221 | ||
830fb67b JO |
222 | return enabled_rates; |
223 | } | |
224 | ||
2fe33e8c IY |
225 | static void handle_tx_low_watermark(struct wl1271 *wl) |
226 | { | |
227 | unsigned long flags; | |
228 | ||
229 | if (test_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags) && | |
6742f554 | 230 | wl->tx_queue_count <= WL1271_TX_QUEUE_LOW_WATERMARK) { |
2fe33e8c IY |
231 | /* firmware buffer has space, restart queues */ |
232 | spin_lock_irqsave(&wl->wl_lock, flags); | |
233 | ieee80211_wake_queues(wl->hw); | |
234 | clear_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags); | |
235 | spin_unlock_irqrestore(&wl->wl_lock, flags); | |
236 | } | |
237 | } | |
238 | ||
6742f554 JO |
239 | static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl) |
240 | { | |
241 | struct sk_buff *skb = NULL; | |
242 | unsigned long flags; | |
243 | ||
244 | skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_VO]); | |
245 | if (skb) | |
246 | goto out; | |
247 | skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_VI]); | |
248 | if (skb) | |
249 | goto out; | |
250 | skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_BE]); | |
251 | if (skb) | |
252 | goto out; | |
253 | skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_BK]); | |
254 | ||
255 | out: | |
256 | if (skb) { | |
257 | spin_lock_irqsave(&wl->wl_lock, flags); | |
258 | wl->tx_queue_count--; | |
259 | spin_unlock_irqrestore(&wl->wl_lock, flags); | |
260 | } | |
261 | ||
262 | return skb; | |
263 | } | |
264 | ||
265 | static void wl1271_skb_queue_head(struct wl1271 *wl, struct sk_buff *skb) | |
266 | { | |
267 | unsigned long flags; | |
268 | int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); | |
269 | ||
270 | skb_queue_head(&wl->tx_queue[q], skb); | |
271 | spin_lock_irqsave(&wl->wl_lock, flags); | |
272 | wl->tx_queue_count++; | |
273 | spin_unlock_irqrestore(&wl->wl_lock, flags); | |
274 | } | |
275 | ||
a522550a | 276 | void wl1271_tx_work_locked(struct wl1271 *wl) |
f5fc0f86 | 277 | { |
f5fc0f86 LC |
278 | struct sk_buff *skb; |
279 | bool woken_up = false; | |
830fb67b | 280 | u32 sta_rates = 0; |
6c6e669e IY |
281 | u32 buf_offset = 0; |
282 | bool sent_packets = false; | |
f5fc0f86 LC |
283 | int ret; |
284 | ||
830fb67b JO |
285 | /* check if the rates supported by the AP have changed */ |
286 | if (unlikely(test_and_clear_bit(WL1271_FLAG_STA_RATES_CHANGED, | |
287 | &wl->flags))) { | |
288 | unsigned long flags; | |
2fe33e8c | 289 | |
830fb67b JO |
290 | spin_lock_irqsave(&wl->wl_lock, flags); |
291 | sta_rates = wl->sta_rate_set; | |
292 | spin_unlock_irqrestore(&wl->wl_lock, flags); | |
293 | } | |
294 | ||
f5fc0f86 LC |
295 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
296 | goto out; | |
297 | ||
830fb67b JO |
298 | /* if rates have changed, re-configure the rate policy */ |
299 | if (unlikely(sta_rates)) { | |
54046431 LC |
300 | ret = wl1271_ps_elp_wakeup(wl, false); |
301 | if (ret < 0) | |
302 | goto out; | |
303 | woken_up = true; | |
304 | ||
830fb67b | 305 | wl->rate_set = wl1271_tx_enabled_rates_get(wl, sta_rates); |
79b223f4 | 306 | wl1271_acx_sta_rate_policies(wl); |
830fb67b JO |
307 | } |
308 | ||
6742f554 | 309 | while ((skb = wl1271_skb_dequeue(wl))) { |
f5fc0f86 LC |
310 | if (!woken_up) { |
311 | ret = wl1271_ps_elp_wakeup(wl, false); | |
312 | if (ret < 0) | |
ffb591cd | 313 | goto out_ack; |
f5fc0f86 LC |
314 | woken_up = true; |
315 | } | |
316 | ||
a19606b4 | 317 | ret = wl1271_prepare_tx_frame(wl, skb, buf_offset); |
6c6e669e | 318 | if (ret == -EAGAIN) { |
a19606b4 | 319 | /* |
6c6e669e IY |
320 | * Aggregation buffer is full. |
321 | * Flush buffer and try again. | |
322 | */ | |
6742f554 | 323 | wl1271_skb_queue_head(wl, skb); |
6c6e669e | 324 | wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf, |
6742f554 | 325 | buf_offset, true); |
6c6e669e IY |
326 | sent_packets = true; |
327 | buf_offset = 0; | |
328 | continue; | |
329 | } else if (ret == -EBUSY) { | |
330 | /* | |
331 | * Firmware buffer is full. | |
a19606b4 IY |
332 | * Queue back last skb, and stop aggregating. |
333 | */ | |
6742f554 | 334 | wl1271_skb_queue_head(wl, skb); |
a522550a IY |
335 | /* No work left, avoid scheduling redundant tx work */ |
336 | set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); | |
ffb591cd | 337 | goto out_ack; |
f5fc0f86 LC |
338 | } else if (ret < 0) { |
339 | dev_kfree_skb(skb); | |
ffb591cd | 340 | goto out_ack; |
f5fc0f86 | 341 | } |
a19606b4 IY |
342 | buf_offset += ret; |
343 | wl->tx_packets_count++; | |
f5fc0f86 LC |
344 | } |
345 | ||
ffb591cd | 346 | out_ack: |
a19606b4 IY |
347 | if (buf_offset) { |
348 | wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf, | |
349 | buf_offset, true); | |
6c6e669e IY |
350 | sent_packets = true; |
351 | } | |
352 | if (sent_packets) { | |
a19606b4 | 353 | /* interrupt the firmware with the new packets */ |
ffb591cd | 354 | wl1271_write32(wl, WL1271_HOST_WR_ACCESS, wl->tx_packets_count); |
2fe33e8c | 355 | handle_tx_low_watermark(wl); |
a19606b4 | 356 | } |
ffb591cd | 357 | |
f5fc0f86 LC |
358 | out: |
359 | if (woken_up) | |
360 | wl1271_ps_elp_sleep(wl); | |
a522550a | 361 | } |
f5fc0f86 | 362 | |
a522550a IY |
363 | void wl1271_tx_work(struct work_struct *work) |
364 | { | |
365 | struct wl1271 *wl = container_of(work, struct wl1271, tx_work); | |
366 | ||
367 | mutex_lock(&wl->mutex); | |
368 | wl1271_tx_work_locked(wl); | |
f5fc0f86 LC |
369 | mutex_unlock(&wl->mutex); |
370 | } | |
371 | ||
372 | static void wl1271_tx_complete_packet(struct wl1271 *wl, | |
373 | struct wl1271_tx_hw_res_descr *result) | |
374 | { | |
f5fc0f86 LC |
375 | struct ieee80211_tx_info *info; |
376 | struct sk_buff *skb; | |
f5fc0f86 | 377 | int id = result->id; |
31627dc5 JO |
378 | int rate = -1; |
379 | u8 retries = 0; | |
f5fc0f86 LC |
380 | |
381 | /* check for id legality */ | |
ffb591cd | 382 | if (unlikely(id >= ACX_TX_DESCRIPTORS || wl->tx_frames[id] == NULL)) { |
f5fc0f86 LC |
383 | wl1271_warning("TX result illegal id: %d", id); |
384 | return; | |
385 | } | |
386 | ||
387 | skb = wl->tx_frames[id]; | |
388 | info = IEEE80211_SKB_CB(skb); | |
389 | ||
31627dc5 JO |
390 | /* update the TX status info */ |
391 | if (result->status == TX_SUCCESS) { | |
392 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) | |
f5fc0f86 | 393 | info->flags |= IEEE80211_TX_STAT_ACK; |
6a2de93b | 394 | rate = wl1271_rate_to_idx(result->rate_class_index, wl->band); |
31627dc5 JO |
395 | retries = result->ack_failures; |
396 | } else if (result->status == TX_RETRY_EXCEEDED) { | |
397 | wl->stats.excessive_retries++; | |
398 | retries = result->ack_failures; | |
f5fc0f86 LC |
399 | } |
400 | ||
31627dc5 JO |
401 | info->status.rates[0].idx = rate; |
402 | info->status.rates[0].count = retries; | |
403 | info->status.rates[0].flags = 0; | |
404 | info->status.ack_signal = -1; | |
405 | ||
f5fc0f86 LC |
406 | wl->stats.retry_count += result->ack_failures; |
407 | ||
ac4e4ce5 | 408 | /* update security sequence number */ |
04e36fc5 JO |
409 | wl->tx_security_seq += (result->lsb_security_sequence_number - |
410 | wl->tx_security_last_seq); | |
ac4e4ce5 JO |
411 | wl->tx_security_last_seq = result->lsb_security_sequence_number; |
412 | ||
1e2b7976 JO |
413 | /* remove private header from packet */ |
414 | skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); | |
415 | ||
416 | /* remove TKIP header space if present */ | |
f5fc0f86 | 417 | if (info->control.hw_key && |
97359d12 | 418 | info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) { |
1e2b7976 JO |
419 | int hdrlen = ieee80211_get_hdrlen_from_skb(skb); |
420 | memmove(skb->data + WL1271_TKIP_IV_SPACE, skb->data, hdrlen); | |
421 | skb_pull(skb, WL1271_TKIP_IV_SPACE); | |
422 | } | |
f5fc0f86 LC |
423 | |
424 | wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x" | |
425 | " status 0x%x", | |
426 | result->id, skb, result->ack_failures, | |
427 | result->rate_class_index, result->status); | |
428 | ||
f5fc0f86 LC |
429 | /* return the packet to the stack */ |
430 | ieee80211_tx_status(wl->hw, skb); | |
25eeb9e3 | 431 | wl1271_free_tx_id(wl, result->id); |
f5fc0f86 LC |
432 | } |
433 | ||
434 | /* Called upon reception of a TX complete interrupt */ | |
ffb591cd | 435 | void wl1271_tx_complete(struct wl1271 *wl) |
f5fc0f86 LC |
436 | { |
437 | struct wl1271_acx_mem_map *memmap = | |
438 | (struct wl1271_acx_mem_map *)wl->target_mem_map; | |
ffb591cd | 439 | u32 count, fw_counter; |
f5fc0f86 LC |
440 | u32 i; |
441 | ||
f5fc0f86 | 442 | /* read the tx results from the chipset */ |
7b048c52 TP |
443 | wl1271_read(wl, le32_to_cpu(memmap->tx_result), |
444 | wl->tx_res_if, sizeof(*wl->tx_res_if), false); | |
ffb591cd JO |
445 | fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter); |
446 | ||
447 | /* write host counter to chipset (to ack) */ | |
448 | wl1271_write32(wl, le32_to_cpu(memmap->tx_result) + | |
449 | offsetof(struct wl1271_tx_hw_res_if, | |
450 | tx_result_host_counter), fw_counter); | |
451 | ||
452 | count = fw_counter - wl->tx_results_count; | |
06f7bc7d | 453 | wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count); |
f5fc0f86 LC |
454 | |
455 | /* verify that the result buffer is not getting overrun */ | |
ffb591cd | 456 | if (unlikely(count > TX_HW_RESULT_QUEUE_LEN)) |
f5fc0f86 | 457 | wl1271_warning("TX result overflow from chipset: %d", count); |
f5fc0f86 LC |
458 | |
459 | /* process the results */ | |
460 | for (i = 0; i < count; i++) { | |
461 | struct wl1271_tx_hw_res_descr *result; | |
462 | u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK; | |
463 | ||
464 | /* process the packet */ | |
465 | result = &(wl->tx_res_if->tx_results_queue[offset]); | |
466 | wl1271_tx_complete_packet(wl, result); | |
467 | ||
468 | wl->tx_results_count++; | |
469 | } | |
f5fc0f86 LC |
470 | } |
471 | ||
472 | /* caller must hold wl->mutex */ | |
781608c4 | 473 | void wl1271_tx_reset(struct wl1271 *wl) |
f5fc0f86 LC |
474 | { |
475 | int i; | |
476 | struct sk_buff *skb; | |
f5fc0f86 LC |
477 | |
478 | /* TX failure */ | |
6742f554 JO |
479 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
480 | while ((skb = skb_dequeue(&wl->tx_queue[i]))) { | |
481 | wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb); | |
482 | ieee80211_tx_status(wl->hw, skb); | |
483 | } | |
f5fc0f86 | 484 | } |
6742f554 | 485 | wl->tx_queue_count = 0; |
f5fc0f86 | 486 | |
2fe33e8c IY |
487 | /* |
488 | * Make sure the driver is at a consistent state, in case this | |
489 | * function is called from a context other than interface removal. | |
490 | */ | |
491 | handle_tx_low_watermark(wl); | |
492 | ||
be7078c2 | 493 | for (i = 0; i < ACX_TX_DESCRIPTORS; i++) |
f5fc0f86 LC |
494 | if (wl->tx_frames[i] != NULL) { |
495 | skb = wl->tx_frames[i]; | |
25eeb9e3 | 496 | wl1271_free_tx_id(wl, i); |
781608c4 | 497 | wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb); |
6bbe89de | 498 | ieee80211_tx_status(wl->hw, skb); |
f5fc0f86 | 499 | } |
781608c4 JO |
500 | } |
501 | ||
502 | #define WL1271_TX_FLUSH_TIMEOUT 500000 | |
503 | ||
504 | /* caller must *NOT* hold wl->mutex */ | |
505 | void wl1271_tx_flush(struct wl1271 *wl) | |
506 | { | |
507 | unsigned long timeout; | |
508 | timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT); | |
509 | ||
510 | while (!time_after(jiffies, timeout)) { | |
511 | mutex_lock(&wl->mutex); | |
512 | wl1271_debug(DEBUG_TX, "flushing tx buffer: %d", | |
513 | wl->tx_frames_cnt); | |
6742f554 | 514 | if ((wl->tx_frames_cnt == 0) && (wl->tx_queue_count == 0)) { |
781608c4 JO |
515 | mutex_unlock(&wl->mutex); |
516 | return; | |
517 | } | |
518 | mutex_unlock(&wl->mutex); | |
519 | msleep(1); | |
520 | } | |
521 | ||
522 | wl1271_warning("Unable to flush all TX buffers, timed out."); | |
f5fc0f86 | 523 | } |
e0fe371b AN |
524 | |
525 | u32 wl1271_tx_min_rate_get(struct wl1271 *wl) | |
526 | { | |
527 | int i; | |
528 | u32 rate = 0; | |
529 | ||
530 | if (!wl->basic_rate_set) { | |
531 | WARN_ON(1); | |
532 | wl->basic_rate_set = wl->conf.tx.basic_rate; | |
533 | } | |
534 | ||
535 | for (i = 0; !rate; i++) { | |
536 | if ((wl->basic_rate_set >> i) & 0x1) | |
537 | rate = 1 << i; | |
538 | } | |
539 | ||
540 | return rate; | |
541 | } |