blob: 7a3339fd34158a8ebad55906ba9a03ff43ead2b1 [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>
Arik Nemtsovc6c8a652010-10-16 20:27:53 +020026#include <linux/etherdevice.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030027
Shahar Levi00d20102010-11-08 11:20:10 +000028#include "wl12xx.h"
29#include "io.h"
30#include "reg.h"
31#include "ps.h"
32#include "tx.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030033
Arik Nemtsov7f179b42010-10-16 21:39:06 +020034static int wl1271_set_default_wep_key(struct wl1271 *wl, u8 id)
35{
36 int ret;
37 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
38
39 if (is_ap)
40 ret = wl1271_cmd_set_ap_default_wep_key(wl, id);
41 else
42 ret = wl1271_cmd_set_sta_default_wep_key(wl, id);
43
44 if (ret < 0)
45 return ret;
46
47 wl1271_debug(DEBUG_CRYPT, "default wep key idx: %d", (int)id);
48 return 0;
49}
50
Ido Yariv25eeb9e2010-10-12 16:20:06 +020051static int wl1271_alloc_tx_id(struct wl1271 *wl, struct sk_buff *skb)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030052{
Ido Yariv25eeb9e2010-10-12 16:20:06 +020053 int id;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030054
Ido Yariv25eeb9e2010-10-12 16:20:06 +020055 id = find_first_zero_bit(wl->tx_frames_map, ACX_TX_DESCRIPTORS);
56 if (id >= ACX_TX_DESCRIPTORS)
57 return -EBUSY;
58
59 __set_bit(id, wl->tx_frames_map);
60 wl->tx_frames[id] = skb;
61 wl->tx_frames_cnt++;
62 return id;
63}
64
65static void wl1271_free_tx_id(struct wl1271 *wl, int id)
66{
67 if (__test_and_clear_bit(id, wl->tx_frames_map)) {
68 wl->tx_frames[id] = NULL;
69 wl->tx_frames_cnt--;
70 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030071}
72
Ohad Ben-Cohenc5745182011-03-30 16:35:59 +020073static int wl1271_tx_update_filters(struct wl1271 *wl,
74 struct sk_buff *skb)
75{
76 struct ieee80211_hdr *hdr;
77
78 hdr = (struct ieee80211_hdr *)(skb->data +
79 sizeof(struct wl1271_tx_hw_descr));
80
81 /*
82 * stop bssid-based filtering before transmitting authentication
83 * requests. this way the hw will never drop authentication
84 * responses coming from BSSIDs it isn't familiar with (e.g. on
85 * roaming)
86 */
87 if (!ieee80211_is_auth(hdr->frame_control))
88 return 0;
89
90 wl1271_configure_filters(wl, FIF_OTHER_BSS);
91
92 return wl1271_acx_rx_config(wl, wl->rx_config, wl->rx_filter);
93}
94
Arik Nemtsov99a27752011-02-23 00:22:25 +020095static void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl,
96 struct sk_buff *skb)
97{
98 struct ieee80211_hdr *hdr;
99
100 /*
101 * add the station to the known list before transmitting the
102 * authentication response. this way it won't get de-authed by FW
103 * when transmitting too soon.
104 */
105 hdr = (struct ieee80211_hdr *)(skb->data +
106 sizeof(struct wl1271_tx_hw_descr));
107 if (ieee80211_is_auth(hdr->frame_control))
108 wl1271_acx_set_inconnection_sta(wl, hdr->addr1);
109}
110
Arik Nemtsovb622d992011-02-23 00:22:31 +0200111static void wl1271_tx_regulate_link(struct wl1271 *wl, u8 hlid)
112{
113 bool fw_ps;
114 u8 tx_blks;
115
116 /* only regulate station links */
117 if (hlid < WL1271_AP_STA_HLID_START)
118 return;
119
120 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
121 tx_blks = wl->links[hlid].allocated_blks;
122
123 /*
124 * if in FW PS and there is enough data in FW we can put the link
125 * into high-level PS and clean out its TX queues.
126 */
127 if (fw_ps && tx_blks >= WL1271_PS_STA_MAX_BLOCKS)
128 wl1271_ps_link_start(wl, hlid, true);
129}
130
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200131u8 wl1271_tx_get_hlid(struct sk_buff *skb)
132{
133 struct ieee80211_tx_info *control = IEEE80211_SKB_CB(skb);
134
135 if (control->control.sta) {
136 struct wl1271_station *wl_sta;
137
138 wl_sta = (struct wl1271_station *)
139 control->control.sta->drv_priv;
140 return wl_sta->hlid;
141 } else {
142 struct ieee80211_hdr *hdr;
143
144 hdr = (struct ieee80211_hdr *)skb->data;
145 if (ieee80211_is_mgmt(hdr->frame_control))
146 return WL1271_AP_GLOBAL_HLID;
147 else
148 return WL1271_AP_BROADCAST_HLID;
149 }
150}
151
Ido Yariv0da13da2011-03-31 10:06:58 +0200152static unsigned int wl12xx_calc_packet_alignment(struct wl1271 *wl,
153 unsigned int packet_length)
154{
155 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT)
156 return ALIGN(packet_length, WL12XX_BUS_BLOCK_SIZE);
157 else
158 return ALIGN(packet_length, WL1271_TX_ALIGN_TO);
159}
160
Ido Yariva19606b2010-09-30 13:28:28 +0200161static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
Arik Nemtsov09039f42011-02-23 00:22:30 +0200162 u32 buf_offset, u8 hlid)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300163{
164 struct wl1271_tx_hw_descr *desc;
165 u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra;
Shahar Levi48a61472011-03-06 16:32:08 +0200166 u32 len;
Juuso Oikarinen5c9417f2010-02-22 08:38:39 +0200167 u32 total_blocks;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300168 int id, ret = -EBUSY;
Luciano Coelhoe7ddf542011-03-10 15:24:57 +0200169 u32 spare_blocks;
170
171 if (unlikely(wl->quirks & WL12XX_QUIRK_USE_2_SPARE_BLOCKS))
172 spare_blocks = 2;
173 else
174 spare_blocks = 1;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300175
Ido Yariva19606b2010-09-30 13:28:28 +0200176 if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE)
Ido Yariv6c6e6692010-10-12 14:49:09 +0200177 return -EAGAIN;
Ido Yariva19606b2010-09-30 13:28:28 +0200178
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300179 /* allocate free identifier for the packet */
Ido Yariv25eeb9e2010-10-12 16:20:06 +0200180 id = wl1271_alloc_tx_id(wl, skb);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300181 if (id < 0)
182 return id;
183
184 /* approximate the number of blocks required for this packet
185 in the firmware */
Ido Yariv0da13da2011-03-31 10:06:58 +0200186 len = wl12xx_calc_packet_alignment(wl, total_len);
Shahar Levi48a61472011-03-06 16:32:08 +0200187
188 total_blocks = (len + TX_HW_BLOCK_SIZE - 1) / TX_HW_BLOCK_SIZE +
Luciano Coelhoe7ddf542011-03-10 15:24:57 +0200189 spare_blocks;
Shahar Levi48a61472011-03-06 16:32:08 +0200190
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300191 if (total_blocks <= wl->tx_blocks_available) {
192 desc = (struct wl1271_tx_hw_descr *)skb_push(
193 skb, total_len - skb->len);
194
Shahar Leviae77ecc2011-03-06 16:32:13 +0200195 /* HW descriptor fields change between wl127x and wl128x */
196 if (wl->chip.id == CHIP_ID_1283_PG20) {
197 desc->wl128x_mem.total_mem_blocks = total_blocks;
198 } else {
Luciano Coelhoe7ddf542011-03-10 15:24:57 +0200199 desc->wl127x_mem.extra_blocks = spare_blocks;
Shahar Leviae77ecc2011-03-06 16:32:13 +0200200 desc->wl127x_mem.total_mem_blocks = total_blocks;
201 }
202
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300203 desc->id = id;
204
205 wl->tx_blocks_available -= total_blocks;
Ido Yarivd2f4d472011-03-31 10:07:00 +0200206 wl->tx_allocated_blocks += total_blocks;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300207
Arik Nemtsov09039f42011-02-23 00:22:30 +0200208 if (wl->bss_type == BSS_TYPE_AP_BSS)
209 wl->links[hlid].allocated_blks += total_blocks;
210
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300211 ret = 0;
212
213 wl1271_debug(DEBUG_TX,
214 "tx_allocate: size: %d, blocks: %d, id: %d",
215 total_len, total_blocks, id);
Juuso Oikarinen781608c2010-05-24 11:18:17 +0300216 } else {
Ido Yariv25eeb9e2010-10-12 16:20:06 +0200217 wl1271_free_tx_id(wl, id);
Juuso Oikarinen781608c2010-05-24 11:18:17 +0300218 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300219
220 return ret;
221}
222
Ido Yariv990f5de2011-03-31 10:06:59 +0200223static bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb)
224{
225 return wl->dummy_packet == skb;
226}
227
Ido Yariva19606b2010-09-30 13:28:28 +0200228static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb,
Arik Nemtsov09039f42011-02-23 00:22:30 +0200229 u32 extra, struct ieee80211_tx_info *control,
230 u8 hlid)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300231{
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200232 struct timespec ts;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300233 struct wl1271_tx_hw_descr *desc;
Shahar Levi48a61472011-03-06 16:32:08 +0200234 int aligned_len, ac, rate_idx;
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200235 s64 hosttime;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300236 u16 tx_attr;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300237
238 desc = (struct wl1271_tx_hw_descr *) skb->data;
239
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +0300240 /* relocate space for security header */
241 if (extra) {
242 void *framestart = skb->data + sizeof(*desc);
243 u16 fc = *(u16 *)(framestart + extra);
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300244 int hdrlen = ieee80211_hdrlen(cpu_to_le16(fc));
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +0300245 memmove(framestart, framestart + extra, hdrlen);
246 }
247
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300248 /* configure packet life time */
Juuso Oikarinenac5e1e32010-02-22 08:38:38 +0200249 getnstimeofday(&ts);
250 hosttime = (timespec_to_ns(&ts) >> 10);
251 desc->start_time = cpu_to_le32(hosttime - wl->time_offset);
Arik Nemtsovc6c8a652010-10-16 20:27:53 +0200252
253 if (wl->bss_type != BSS_TYPE_AP_BSS)
254 desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU);
255 else
256 desc->life_time = cpu_to_le16(TX_HW_AP_MODE_PKT_LIFETIME_TU);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300257
Eliad Pellerdb674d22011-03-16 23:03:54 +0200258 /* queue */
Kalle Valoc6999d82010-02-18 13:25:41 +0200259 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
Eliad Pellerdb674d22011-03-16 23:03:54 +0200260 desc->tid = skb->priority;
Arik Nemtsovc6c8a652010-10-16 20:27:53 +0200261
Ido Yariv990f5de2011-03-31 10:06:59 +0200262 if (wl12xx_is_dummy_packet(wl, skb)) {
Shahar Leviae47c452011-03-06 16:32:14 +0200263 /*
264 * FW expects the dummy packet to have an invalid session id -
265 * any session id that is different than the one set in the join
266 */
267 tx_attr = ((~wl->session_counter) <<
268 TX_HW_ATTR_OFST_SESSION_COUNTER) &
269 TX_HW_ATTR_SESSION_COUNTER;
270
271 tx_attr |= TX_HW_ATTR_TX_DUMMY_REQ;
Shahar Leviae47c452011-03-06 16:32:14 +0200272 } else {
273 /* configure the tx attributes */
274 tx_attr =
275 wl->session_counter << TX_HW_ATTR_OFST_SESSION_COUNTER;
276 }
277
Arik Nemtsovc6c8a652010-10-16 20:27:53 +0200278 if (wl->bss_type != BSS_TYPE_AP_BSS) {
Arik Nemtsov09039f42011-02-23 00:22:30 +0200279 desc->aid = hlid;
Arik Nemtsovc6c8a652010-10-16 20:27:53 +0200280
281 /* if the packets are destined for AP (have a STA entry)
282 send them with AP rate policies, otherwise use default
283 basic rates */
284 if (control->control.sta)
285 rate_idx = ACX_TX_AP_FULL_RATE;
286 else
287 rate_idx = ACX_TX_BASIC_RATE;
288 } else {
Arik Nemtsov09039f42011-02-23 00:22:30 +0200289 desc->hlid = hlid;
290 switch (hlid) {
291 case WL1271_AP_GLOBAL_HLID:
292 rate_idx = ACX_TX_AP_MODE_MGMT_RATE;
293 break;
294 case WL1271_AP_BROADCAST_HLID:
295 rate_idx = ACX_TX_AP_MODE_BCST_RATE;
296 break;
297 default:
Arik Nemtsovc6c8a652010-10-16 20:27:53 +0200298 rate_idx = ac;
Arik Nemtsov09039f42011-02-23 00:22:30 +0200299 break;
Arik Nemtsovc6c8a652010-10-16 20:27:53 +0200300 }
301 }
302
303 tx_attr |= rate_idx << TX_HW_ATTR_OFST_RATE_POLICY;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300304 desc->reserved = 0;
305
Ido Yariv0da13da2011-03-31 10:06:58 +0200306 aligned_len = wl12xx_calc_packet_alignment(wl, skb->len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300307
Ido Yariv0da13da2011-03-31 10:06:58 +0200308 if (wl->chip.id == CHIP_ID_1283_PG20) {
Shahar Levi48a61472011-03-06 16:32:08 +0200309 desc->wl128x_mem.extra_bytes = aligned_len - skb->len;
310 desc->length = cpu_to_le16(aligned_len >> 2);
Shahar Leviae77ecc2011-03-06 16:32:13 +0200311
312 wl1271_debug(DEBUG_TX, "tx_fill_hdr: hlid: %d "
313 "tx_attr: 0x%x len: %d life: %d mem: %d",
314 desc->hlid, tx_attr,
315 le16_to_cpu(desc->length),
316 le16_to_cpu(desc->life_time),
317 desc->wl128x_mem.total_mem_blocks);
Shahar Levi48a61472011-03-06 16:32:08 +0200318 } else {
319 int pad;
320
Ido Yariv0da13da2011-03-31 10:06:58 +0200321 /* Store the aligned length in terms of words */
Shahar Levi48a61472011-03-06 16:32:08 +0200322 desc->length = cpu_to_le16(aligned_len >> 2);
323
324 /* calculate number of padding bytes */
325 pad = aligned_len - skb->len;
326 tx_attr |= pad << TX_HW_ATTR_OFST_LAST_WORD_PAD;
327
Shahar Leviae77ecc2011-03-06 16:32:13 +0200328 wl1271_debug(DEBUG_TX, "tx_fill_hdr: pad: %d hlid: %d "
329 "tx_attr: 0x%x len: %d life: %d mem: %d", pad,
330 desc->hlid, tx_attr,
331 le16_to_cpu(desc->length),
332 le16_to_cpu(desc->life_time),
333 desc->wl127x_mem.total_mem_blocks);
Shahar Levi48a61472011-03-06 16:32:08 +0200334 }
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300335
336 desc->tx_attr = cpu_to_le16(tx_attr);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300337}
338
339/* caller must hold wl->mutex */
Ido Yariva19606b2010-09-30 13:28:28 +0200340static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct sk_buff *skb,
341 u32 buf_offset)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300342{
343 struct ieee80211_tx_info *info;
344 u32 extra = 0;
345 int ret = 0;
Ido Yariva19606b2010-09-30 13:28:28 +0200346 u32 total_len;
Arik Nemtsov09039f42011-02-23 00:22:30 +0200347 u8 hlid;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300348
349 if (!skb)
350 return -EINVAL;
351
352 info = IEEE80211_SKB_CB(skb);
353
354 if (info->control.hw_key &&
Johannes Berg97359d12010-08-10 09:46:38 +0200355 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300356 extra = WL1271_TKIP_IV_SPACE;
357
358 if (info->control.hw_key) {
Arik Nemtsov7f179b42010-10-16 21:39:06 +0200359 bool is_wep;
360 u8 idx = info->control.hw_key->hw_key_idx;
361 u32 cipher = info->control.hw_key->cipher;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300362
Arik Nemtsov7f179b42010-10-16 21:39:06 +0200363 is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) ||
364 (cipher == WLAN_CIPHER_SUITE_WEP104);
365
366 if (unlikely(is_wep && wl->default_key != idx)) {
367 ret = wl1271_set_default_wep_key(wl, idx);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300368 if (ret < 0)
369 return ret;
Juuso Oikarinenee444cf2010-02-18 13:25:50 +0200370 wl->default_key = idx;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300371 }
372 }
373
Arik Nemtsov09039f42011-02-23 00:22:30 +0200374 if (wl->bss_type == BSS_TYPE_AP_BSS)
375 hlid = wl1271_tx_get_hlid(skb);
376 else
377 hlid = TX_HW_DEFAULT_AID;
378
379 ret = wl1271_tx_allocate(wl, skb, extra, buf_offset, hlid);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300380 if (ret < 0)
381 return ret;
382
Arik Nemtsovb622d992011-02-23 00:22:31 +0200383 if (wl->bss_type == BSS_TYPE_AP_BSS) {
Arik Nemtsov99a27752011-02-23 00:22:25 +0200384 wl1271_tx_ap_update_inconnection_sta(wl, skb);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200385 wl1271_tx_regulate_link(wl, hlid);
Ohad Ben-Cohenc5745182011-03-30 16:35:59 +0200386 } else {
387 wl1271_tx_update_filters(wl, skb);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200388 }
Arik Nemtsov99a27752011-02-23 00:22:25 +0200389
Arik Nemtsov09039f42011-02-23 00:22:30 +0200390 wl1271_tx_fill_hdr(wl, skb, extra, info, hlid);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300391
Ido Yariva19606b2010-09-30 13:28:28 +0200392 /*
Shahar Levi48a61472011-03-06 16:32:08 +0200393 * The length of each packet is stored in terms of
394 * words. Thus, we must pad the skb data to make sure its
395 * length is aligned. The number of padding bytes is computed
396 * and set in wl1271_tx_fill_hdr.
397 * In special cases, we want to align to a specific block size
398 * (eg. for wl128x with SDIO we align to 256).
Ido Yariva19606b2010-09-30 13:28:28 +0200399 */
Ido Yariv0da13da2011-03-31 10:06:58 +0200400 total_len = wl12xx_calc_packet_alignment(wl, skb->len);
Shahar Levi48a61472011-03-06 16:32:08 +0200401
Ido Yariva19606b2010-09-30 13:28:28 +0200402 memcpy(wl->aggr_buf + buf_offset, skb->data, skb->len);
403 memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300404
Ido Yariv990f5de2011-03-31 10:06:59 +0200405 /* Revert side effects in the dummy packet skb, so it can be reused */
406 if (wl12xx_is_dummy_packet(wl, skb))
407 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
408
Ido Yariva19606b2010-09-30 13:28:28 +0200409 return total_len;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300410}
411
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300412u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set)
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200413{
414 struct ieee80211_supported_band *band;
415 u32 enabled_rates = 0;
416 int bit;
417
418 band = wl->hw->wiphy->bands[wl->band];
419 for (bit = 0; bit < band->n_bitrates; bit++) {
420 if (rate_set & 0x1)
421 enabled_rates |= band->bitrates[bit].hw_value;
422 rate_set >>= 1;
423 }
424
Shahar Levi00d20102010-11-08 11:20:10 +0000425#ifdef CONFIG_WL12XX_HT
Shahar Levi18357852010-10-13 16:09:41 +0200426 /* MCS rates indication are on bits 16 - 23 */
427 rate_set >>= HW_HT_RATES_OFFSET - band->n_bitrates;
428
429 for (bit = 0; bit < 8; bit++) {
430 if (rate_set & 0x1)
431 enabled_rates |= (CONF_HW_BIT_RATE_MCS_0 << bit);
432 rate_set >>= 1;
433 }
434#endif
435
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200436 return enabled_rates;
437}
438
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200439void wl1271_handle_tx_low_watermark(struct wl1271 *wl)
Ido Yariv2fe33e82010-10-12 14:49:12 +0200440{
441 unsigned long flags;
442
443 if (test_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags) &&
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200444 wl->tx_queue_count <= WL1271_TX_QUEUE_LOW_WATERMARK) {
Ido Yariv2fe33e82010-10-12 14:49:12 +0200445 /* firmware buffer has space, restart queues */
446 spin_lock_irqsave(&wl->wl_lock, flags);
447 ieee80211_wake_queues(wl->hw);
448 clear_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
449 spin_unlock_irqrestore(&wl->wl_lock, flags);
450 }
451}
452
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200453static struct sk_buff *wl1271_sta_skb_dequeue(struct wl1271 *wl)
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200454{
455 struct sk_buff *skb = NULL;
456 unsigned long flags;
457
458 skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_VO]);
459 if (skb)
460 goto out;
461 skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_VI]);
462 if (skb)
463 goto out;
464 skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_BE]);
465 if (skb)
466 goto out;
467 skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_BK]);
468
469out:
470 if (skb) {
471 spin_lock_irqsave(&wl->wl_lock, flags);
472 wl->tx_queue_count--;
473 spin_unlock_irqrestore(&wl->wl_lock, flags);
474 }
475
476 return skb;
477}
478
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200479static struct sk_buff *wl1271_ap_skb_dequeue(struct wl1271 *wl)
480{
481 struct sk_buff *skb = NULL;
482 unsigned long flags;
483 int i, h, start_hlid;
484
485 /* start from the link after the last one */
486 start_hlid = (wl->last_tx_hlid + 1) % AP_MAX_LINKS;
487
488 /* dequeue according to AC, round robin on each link */
489 for (i = 0; i < AP_MAX_LINKS; i++) {
490 h = (start_hlid + i) % AP_MAX_LINKS;
491
492 skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_VO]);
493 if (skb)
494 goto out;
495 skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_VI]);
496 if (skb)
497 goto out;
498 skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_BE]);
499 if (skb)
500 goto out;
501 skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_BK]);
502 if (skb)
503 goto out;
504 }
505
506out:
507 if (skb) {
508 wl->last_tx_hlid = h;
509 spin_lock_irqsave(&wl->wl_lock, flags);
510 wl->tx_queue_count--;
511 spin_unlock_irqrestore(&wl->wl_lock, flags);
512 } else {
513 wl->last_tx_hlid = 0;
514 }
515
516 return skb;
517}
518
519static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl)
520{
Ido Yariv990f5de2011-03-31 10:06:59 +0200521 unsigned long flags;
522 struct sk_buff *skb = NULL;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200523
Ido Yariv990f5de2011-03-31 10:06:59 +0200524 if (wl->bss_type == BSS_TYPE_AP_BSS)
525 skb = wl1271_ap_skb_dequeue(wl);
526 else
527 skb = wl1271_sta_skb_dequeue(wl);
528
529 if (!skb &&
530 test_and_clear_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) {
531 skb = wl->dummy_packet;
532 spin_lock_irqsave(&wl->wl_lock, flags);
533 wl->tx_queue_count--;
534 spin_unlock_irqrestore(&wl->wl_lock, flags);
535 }
536
537 return skb;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200538}
539
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200540static void wl1271_skb_queue_head(struct wl1271 *wl, struct sk_buff *skb)
541{
542 unsigned long flags;
543 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
544
Ido Yariv990f5de2011-03-31 10:06:59 +0200545 if (wl12xx_is_dummy_packet(wl, skb)) {
546 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
547 } else if (wl->bss_type == BSS_TYPE_AP_BSS) {
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200548 u8 hlid = wl1271_tx_get_hlid(skb);
549 skb_queue_head(&wl->links[hlid].tx_queue[q], skb);
550
551 /* make sure we dequeue the same packet next time */
552 wl->last_tx_hlid = (hlid + AP_MAX_LINKS - 1) % AP_MAX_LINKS;
553 } else {
554 skb_queue_head(&wl->tx_queue[q], skb);
555 }
556
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200557 spin_lock_irqsave(&wl->wl_lock, flags);
558 wl->tx_queue_count++;
559 spin_unlock_irqrestore(&wl->wl_lock, flags);
560}
561
Ido Yariva5225502010-10-12 14:49:10 +0200562void wl1271_tx_work_locked(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300563{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300564 struct sk_buff *skb;
Ido Yariv6c6e6692010-10-12 14:49:09 +0200565 u32 buf_offset = 0;
566 bool sent_packets = false;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300567 int ret;
568
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300569 if (unlikely(wl->state == WL1271_STATE_OFF))
Eliad Pellerc1b193e2011-03-23 22:22:15 +0200570 return;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300571
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200572 while ((skb = wl1271_skb_dequeue(wl))) {
Ido Yariva19606b2010-09-30 13:28:28 +0200573 ret = wl1271_prepare_tx_frame(wl, skb, buf_offset);
Ido Yariv6c6e6692010-10-12 14:49:09 +0200574 if (ret == -EAGAIN) {
Ido Yariva19606b2010-09-30 13:28:28 +0200575 /*
Ido Yariv6c6e6692010-10-12 14:49:09 +0200576 * Aggregation buffer is full.
577 * Flush buffer and try again.
578 */
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200579 wl1271_skb_queue_head(wl, skb);
Ido Yariv6c6e6692010-10-12 14:49:09 +0200580 wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200581 buf_offset, true);
Ido Yariv6c6e6692010-10-12 14:49:09 +0200582 sent_packets = true;
583 buf_offset = 0;
584 continue;
585 } else if (ret == -EBUSY) {
586 /*
587 * Firmware buffer is full.
Ido Yariva19606b2010-09-30 13:28:28 +0200588 * Queue back last skb, and stop aggregating.
589 */
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200590 wl1271_skb_queue_head(wl, skb);
Ido Yariva5225502010-10-12 14:49:10 +0200591 /* No work left, avoid scheduling redundant tx work */
592 set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200593 goto out_ack;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300594 } else if (ret < 0) {
595 dev_kfree_skb(skb);
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200596 goto out_ack;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300597 }
Ido Yariva19606b2010-09-30 13:28:28 +0200598 buf_offset += ret;
599 wl->tx_packets_count++;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300600 }
601
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200602out_ack:
Ido Yariva19606b2010-09-30 13:28:28 +0200603 if (buf_offset) {
604 wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
605 buf_offset, true);
Ido Yariv6c6e6692010-10-12 14:49:09 +0200606 sent_packets = true;
607 }
608 if (sent_packets) {
Ido Yariv606ea9f2011-03-01 15:14:39 +0200609 /*
610 * Interrupt the firmware with the new packets. This is only
611 * required for older hardware revisions
612 */
613 if (wl->quirks & WL12XX_QUIRK_END_OF_TRANSACTION)
614 wl1271_write32(wl, WL1271_HOST_WR_ACCESS,
615 wl->tx_packets_count);
616
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200617 wl1271_handle_tx_low_watermark(wl);
Ido Yariva19606b2010-09-30 13:28:28 +0200618 }
Ido Yariva5225502010-10-12 14:49:10 +0200619}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300620
Ido Yariva5225502010-10-12 14:49:10 +0200621void wl1271_tx_work(struct work_struct *work)
622{
623 struct wl1271 *wl = container_of(work, struct wl1271, tx_work);
Eliad Pellerc1b193e2011-03-23 22:22:15 +0200624 int ret;
Ido Yariva5225502010-10-12 14:49:10 +0200625
626 mutex_lock(&wl->mutex);
Eliad Pellerc1b193e2011-03-23 22:22:15 +0200627 ret = wl1271_ps_elp_wakeup(wl);
628 if (ret < 0)
629 goto out;
630
Ido Yariva5225502010-10-12 14:49:10 +0200631 wl1271_tx_work_locked(wl);
Eliad Pellerc1b193e2011-03-23 22:22:15 +0200632
633 wl1271_ps_elp_wakeup(wl);
634out:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300635 mutex_unlock(&wl->mutex);
636}
637
638static void wl1271_tx_complete_packet(struct wl1271 *wl,
639 struct wl1271_tx_hw_res_descr *result)
640{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300641 struct ieee80211_tx_info *info;
642 struct sk_buff *skb;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300643 int id = result->id;
Juuso Oikarinen31627dc2010-03-26 12:53:12 +0200644 int rate = -1;
645 u8 retries = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300646
647 /* check for id legality */
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200648 if (unlikely(id >= ACX_TX_DESCRIPTORS || wl->tx_frames[id] == NULL)) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300649 wl1271_warning("TX result illegal id: %d", id);
650 return;
651 }
652
653 skb = wl->tx_frames[id];
654 info = IEEE80211_SKB_CB(skb);
655
Ido Yariv990f5de2011-03-31 10:06:59 +0200656 if (wl12xx_is_dummy_packet(wl, skb)) {
Shahar Leviae47c452011-03-06 16:32:14 +0200657 wl1271_free_tx_id(wl, id);
658 return;
659 }
660
Juuso Oikarinen31627dc2010-03-26 12:53:12 +0200661 /* update the TX status info */
662 if (result->status == TX_SUCCESS) {
663 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300664 info->flags |= IEEE80211_TX_STAT_ACK;
Teemu Paasikivi6a2de932010-10-14 11:00:04 +0200665 rate = wl1271_rate_to_idx(result->rate_class_index, wl->band);
Juuso Oikarinen31627dc2010-03-26 12:53:12 +0200666 retries = result->ack_failures;
667 } else if (result->status == TX_RETRY_EXCEEDED) {
668 wl->stats.excessive_retries++;
669 retries = result->ack_failures;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300670 }
671
Juuso Oikarinen31627dc2010-03-26 12:53:12 +0200672 info->status.rates[0].idx = rate;
673 info->status.rates[0].count = retries;
674 info->status.rates[0].flags = 0;
675 info->status.ack_signal = -1;
676
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300677 wl->stats.retry_count += result->ack_failures;
678
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300679 /* update security sequence number */
Juuso Oikarinen04e36fc2010-02-22 08:38:40 +0200680 wl->tx_security_seq += (result->lsb_security_sequence_number -
681 wl->tx_security_last_seq);
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300682 wl->tx_security_last_seq = result->lsb_security_sequence_number;
683
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +0300684 /* remove private header from packet */
685 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
686
687 /* remove TKIP header space if present */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300688 if (info->control.hw_key &&
Johannes Berg97359d12010-08-10 09:46:38 +0200689 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +0300690 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
691 memmove(skb->data + WL1271_TKIP_IV_SPACE, skb->data, hdrlen);
692 skb_pull(skb, WL1271_TKIP_IV_SPACE);
693 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300694
695 wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
696 " status 0x%x",
697 result->id, skb, result->ack_failures,
698 result->rate_class_index, result->status);
699
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300700 /* return the packet to the stack */
Ido Yariva6208652011-03-01 15:14:41 +0200701 skb_queue_tail(&wl->deferred_tx_queue, skb);
702 ieee80211_queue_work(wl->hw, &wl->netstack_work);
Ido Yariv25eeb9e2010-10-12 16:20:06 +0200703 wl1271_free_tx_id(wl, result->id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300704}
705
706/* Called upon reception of a TX complete interrupt */
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200707void wl1271_tx_complete(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300708{
709 struct wl1271_acx_mem_map *memmap =
710 (struct wl1271_acx_mem_map *)wl->target_mem_map;
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200711 u32 count, fw_counter;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300712 u32 i;
713
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300714 /* read the tx results from the chipset */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200715 wl1271_read(wl, le32_to_cpu(memmap->tx_result),
716 wl->tx_res_if, sizeof(*wl->tx_res_if), false);
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200717 fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter);
718
719 /* write host counter to chipset (to ack) */
720 wl1271_write32(wl, le32_to_cpu(memmap->tx_result) +
721 offsetof(struct wl1271_tx_hw_res_if,
722 tx_result_host_counter), fw_counter);
723
724 count = fw_counter - wl->tx_results_count;
Juuso Oikarinen06f7bc72010-02-22 08:38:33 +0200725 wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300726
727 /* verify that the result buffer is not getting overrun */
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200728 if (unlikely(count > TX_HW_RESULT_QUEUE_LEN))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300729 wl1271_warning("TX result overflow from chipset: %d", count);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300730
731 /* process the results */
732 for (i = 0; i < count; i++) {
733 struct wl1271_tx_hw_res_descr *result;
734 u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK;
735
736 /* process the packet */
737 result = &(wl->tx_res_if->tx_results_queue[offset]);
738 wl1271_tx_complete_packet(wl, result);
739
740 wl->tx_results_count++;
741 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300742}
743
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200744void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid)
745{
746 struct sk_buff *skb;
747 int i, total = 0;
748 unsigned long flags;
Arik Nemtsov1d36cd82011-02-23 00:22:27 +0200749 struct ieee80211_tx_info *info;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200750
751 for (i = 0; i < NUM_TX_QUEUES; i++) {
752 while ((skb = skb_dequeue(&wl->links[hlid].tx_queue[i]))) {
753 wl1271_debug(DEBUG_TX, "link freeing skb 0x%p", skb);
Arik Nemtsov1d36cd82011-02-23 00:22:27 +0200754 info = IEEE80211_SKB_CB(skb);
755 info->status.rates[0].idx = -1;
756 info->status.rates[0].count = 0;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200757 ieee80211_tx_status(wl->hw, skb);
758 total++;
759 }
760 }
761
762 spin_lock_irqsave(&wl->wl_lock, flags);
763 wl->tx_queue_count -= total;
764 spin_unlock_irqrestore(&wl->wl_lock, flags);
765
766 wl1271_handle_tx_low_watermark(wl);
767}
768
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300769/* caller must hold wl->mutex */
Juuso Oikarinen781608c2010-05-24 11:18:17 +0300770void wl1271_tx_reset(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300771{
772 int i;
773 struct sk_buff *skb;
Arik Nemtsov1d36cd82011-02-23 00:22:27 +0200774 struct ieee80211_tx_info *info;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300775
776 /* TX failure */
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200777 if (wl->bss_type == BSS_TYPE_AP_BSS) {
Arik Nemtsov09039f42011-02-23 00:22:30 +0200778 for (i = 0; i < AP_MAX_LINKS; i++) {
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200779 wl1271_tx_reset_link_queues(wl, i);
Arik Nemtsov09039f42011-02-23 00:22:30 +0200780 wl->links[i].allocated_blks = 0;
781 wl->links[i].prev_freed_blks = 0;
782 }
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200783
784 wl->last_tx_hlid = 0;
785 } else {
786 for (i = 0; i < NUM_TX_QUEUES; i++) {
787 while ((skb = skb_dequeue(&wl->tx_queue[i]))) {
788 wl1271_debug(DEBUG_TX, "freeing skb 0x%p",
789 skb);
Shahar Leviae47c452011-03-06 16:32:14 +0200790
Ido Yariv990f5de2011-03-31 10:06:59 +0200791 if (!wl12xx_is_dummy_packet(wl, skb)) {
Shahar Leviae47c452011-03-06 16:32:14 +0200792 info = IEEE80211_SKB_CB(skb);
793 info->status.rates[0].idx = -1;
794 info->status.rates[0].count = 0;
795 ieee80211_tx_status(wl->hw, skb);
796 }
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200797 }
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200798 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300799 }
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200800
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200801 wl->tx_queue_count = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300802
Ido Yariv2fe33e82010-10-12 14:49:12 +0200803 /*
804 * Make sure the driver is at a consistent state, in case this
805 * function is called from a context other than interface removal.
806 */
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200807 wl1271_handle_tx_low_watermark(wl);
Ido Yariv2fe33e82010-10-12 14:49:12 +0200808
Ido Yariv50e9f742011-02-28 00:16:13 +0200809 for (i = 0; i < ACX_TX_DESCRIPTORS; i++) {
810 if (wl->tx_frames[i] == NULL)
811 continue;
812
813 skb = wl->tx_frames[i];
814 wl1271_free_tx_id(wl, i);
815 wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb);
816
Ido Yariv990f5de2011-03-31 10:06:59 +0200817 if (!wl12xx_is_dummy_packet(wl, skb)) {
Shahar Leviae47c452011-03-06 16:32:14 +0200818 /*
819 * Remove private headers before passing the skb to
820 * mac80211
821 */
822 info = IEEE80211_SKB_CB(skb);
823 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
824 if (info->control.hw_key &&
825 info->control.hw_key->cipher ==
826 WLAN_CIPHER_SUITE_TKIP) {
827 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
828 memmove(skb->data + WL1271_TKIP_IV_SPACE,
829 skb->data, hdrlen);
830 skb_pull(skb, WL1271_TKIP_IV_SPACE);
831 }
832
833 info->status.rates[0].idx = -1;
834 info->status.rates[0].count = 0;
835
836 ieee80211_tx_status(wl->hw, skb);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300837 }
Ido Yariv50e9f742011-02-28 00:16:13 +0200838 }
Juuso Oikarinen781608c2010-05-24 11:18:17 +0300839}
840
841#define WL1271_TX_FLUSH_TIMEOUT 500000
842
843/* caller must *NOT* hold wl->mutex */
844void wl1271_tx_flush(struct wl1271 *wl)
845{
846 unsigned long timeout;
847 timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT);
848
849 while (!time_after(jiffies, timeout)) {
850 mutex_lock(&wl->mutex);
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200851 wl1271_debug(DEBUG_TX, "flushing tx buffer: %d %d",
852 wl->tx_frames_cnt, wl->tx_queue_count);
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200853 if ((wl->tx_frames_cnt == 0) && (wl->tx_queue_count == 0)) {
Juuso Oikarinen781608c2010-05-24 11:18:17 +0300854 mutex_unlock(&wl->mutex);
855 return;
856 }
857 mutex_unlock(&wl->mutex);
858 msleep(1);
859 }
860
861 wl1271_warning("Unable to flush all TX buffers, timed out.");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300862}
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200863
864u32 wl1271_tx_min_rate_get(struct wl1271 *wl)
865{
866 int i;
867 u32 rate = 0;
868
869 if (!wl->basic_rate_set) {
870 WARN_ON(1);
871 wl->basic_rate_set = wl->conf.tx.basic_rate;
872 }
873
874 for (i = 0; !rate; i++) {
875 if ((wl->basic_rate_set >> i) & 0x1)
876 rate = 1 << i;
877 }
878
879 return rate;
880}