blob: c67340ff83c8204b917cad3f5808f3f402af3b16 [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)) {
Ido Yarivef2e3002011-04-18 16:44:11 +030068 if (unlikely(wl->tx_frames_cnt == ACX_TX_DESCRIPTORS))
69 clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
70
Ido Yariv25eeb9e2010-10-12 16:20:06 +020071 wl->tx_frames[id] = NULL;
72 wl->tx_frames_cnt--;
73 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030074}
75
Ohad Ben-Cohenc5745182011-03-30 16:35:59 +020076static int wl1271_tx_update_filters(struct wl1271 *wl,
77 struct sk_buff *skb)
78{
79 struct ieee80211_hdr *hdr;
80
81 hdr = (struct ieee80211_hdr *)(skb->data +
82 sizeof(struct wl1271_tx_hw_descr));
83
84 /*
85 * stop bssid-based filtering before transmitting authentication
86 * requests. this way the hw will never drop authentication
87 * responses coming from BSSIDs it isn't familiar with (e.g. on
88 * roaming)
89 */
90 if (!ieee80211_is_auth(hdr->frame_control))
91 return 0;
92
93 wl1271_configure_filters(wl, FIF_OTHER_BSS);
94
95 return wl1271_acx_rx_config(wl, wl->rx_config, wl->rx_filter);
96}
97
Arik Nemtsov99a27752011-02-23 00:22:25 +020098static void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl,
99 struct sk_buff *skb)
100{
101 struct ieee80211_hdr *hdr;
102
103 /*
104 * add the station to the known list before transmitting the
105 * authentication response. this way it won't get de-authed by FW
106 * when transmitting too soon.
107 */
108 hdr = (struct ieee80211_hdr *)(skb->data +
109 sizeof(struct wl1271_tx_hw_descr));
110 if (ieee80211_is_auth(hdr->frame_control))
111 wl1271_acx_set_inconnection_sta(wl, hdr->addr1);
112}
113
Arik Nemtsovb622d992011-02-23 00:22:31 +0200114static void wl1271_tx_regulate_link(struct wl1271 *wl, u8 hlid)
115{
116 bool fw_ps;
117 u8 tx_blks;
118
119 /* only regulate station links */
120 if (hlid < WL1271_AP_STA_HLID_START)
121 return;
122
123 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
124 tx_blks = wl->links[hlid].allocated_blks;
125
126 /*
127 * if in FW PS and there is enough data in FW we can put the link
128 * into high-level PS and clean out its TX queues.
129 */
130 if (fw_ps && tx_blks >= WL1271_PS_STA_MAX_BLOCKS)
131 wl1271_ps_link_start(wl, hlid, true);
132}
133
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200134u8 wl1271_tx_get_hlid(struct sk_buff *skb)
135{
136 struct ieee80211_tx_info *control = IEEE80211_SKB_CB(skb);
137
138 if (control->control.sta) {
139 struct wl1271_station *wl_sta;
140
141 wl_sta = (struct wl1271_station *)
142 control->control.sta->drv_priv;
143 return wl_sta->hlid;
144 } else {
145 struct ieee80211_hdr *hdr;
146
147 hdr = (struct ieee80211_hdr *)skb->data;
148 if (ieee80211_is_mgmt(hdr->frame_control))
149 return WL1271_AP_GLOBAL_HLID;
150 else
151 return WL1271_AP_BROADCAST_HLID;
152 }
153}
154
Ido Yariv0da13da2011-03-31 10:06:58 +0200155static unsigned int wl12xx_calc_packet_alignment(struct wl1271 *wl,
156 unsigned int packet_length)
157{
158 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT)
159 return ALIGN(packet_length, WL12XX_BUS_BLOCK_SIZE);
160 else
161 return ALIGN(packet_length, WL1271_TX_ALIGN_TO);
162}
163
Ido Yariva19606b2010-09-30 13:28:28 +0200164static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
Arik Nemtsov09039f42011-02-23 00:22:30 +0200165 u32 buf_offset, u8 hlid)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300166{
167 struct wl1271_tx_hw_descr *desc;
168 u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra;
Shahar Levi48a61472011-03-06 16:32:08 +0200169 u32 len;
Juuso Oikarinen5c9417f2010-02-22 08:38:39 +0200170 u32 total_blocks;
Arik Nemtsov7bb5d6c2011-08-14 13:17:00 +0300171 int id, ret = -EBUSY;
Luciano Coelhoe7ddf542011-03-10 15:24:57 +0200172
Arik Nemtsov29207432011-08-14 13:17:02 +0300173 /* we use 1 spare block */
174 u32 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;
Arik Nemtsov7bb5d6c2011-08-14 13:17:00 +0300206 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 Nemtsovfae2fd72011-06-26 10:36:04 +0300383 wl1271_tx_fill_hdr(wl, skb, extra, info, hlid);
384
Arik Nemtsovb622d992011-02-23 00:22:31 +0200385 if (wl->bss_type == BSS_TYPE_AP_BSS) {
Arik Nemtsov99a27752011-02-23 00:22:25 +0200386 wl1271_tx_ap_update_inconnection_sta(wl, skb);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200387 wl1271_tx_regulate_link(wl, hlid);
Ohad Ben-Cohenc5745182011-03-30 16:35:59 +0200388 } else {
389 wl1271_tx_update_filters(wl, skb);
Arik Nemtsovb622d992011-02-23 00:22:31 +0200390 }
Arik Nemtsov99a27752011-02-23 00:22:25 +0200391
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;
Arik Nemtsov708bb3c2011-06-24 13:03:37 +0300442 int i;
Ido Yariv2fe33e82010-10-12 14:49:12 +0200443
Arik Nemtsov708bb3c2011-06-24 13:03:37 +0300444 for (i = 0; i < NUM_TX_QUEUES; i++) {
445 if (test_bit(i, &wl->stopped_queues_map) &&
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300446 wl->tx_queue_count[i] <= WL1271_TX_QUEUE_LOW_WATERMARK) {
Arik Nemtsov708bb3c2011-06-24 13:03:37 +0300447 /* firmware buffer has space, restart queues */
448 spin_lock_irqsave(&wl->wl_lock, flags);
449 ieee80211_wake_queue(wl->hw,
450 wl1271_tx_get_mac80211_queue(i));
451 clear_bit(i, &wl->stopped_queues_map);
452 spin_unlock_irqrestore(&wl->wl_lock, flags);
453 }
Ido Yariv2fe33e82010-10-12 14:49:12 +0200454 }
455}
456
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200457static struct sk_buff *wl1271_sta_skb_dequeue(struct wl1271 *wl)
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200458{
459 struct sk_buff *skb = NULL;
460 unsigned long flags;
461
Arik Nemtsov7bb5d6c2011-08-14 13:17:00 +0300462 skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_VO]);
463 if (skb)
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200464 goto out;
Arik Nemtsov7bb5d6c2011-08-14 13:17:00 +0300465 skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_VI]);
466 if (skb)
467 goto out;
468 skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_BE]);
469 if (skb)
470 goto out;
471 skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_BK]);
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200472
473out:
474 if (skb) {
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300475 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200476 spin_lock_irqsave(&wl->wl_lock, flags);
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300477 wl->tx_queue_count[q]--;
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200478 spin_unlock_irqrestore(&wl->wl_lock, flags);
479 }
480
481 return skb;
482}
483
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200484static struct sk_buff *wl1271_ap_skb_dequeue(struct wl1271 *wl)
485{
486 struct sk_buff *skb = NULL;
487 unsigned long flags;
488 int i, h, start_hlid;
489
490 /* start from the link after the last one */
491 start_hlid = (wl->last_tx_hlid + 1) % AP_MAX_LINKS;
492
493 /* dequeue according to AC, round robin on each link */
494 for (i = 0; i < AP_MAX_LINKS; i++) {
495 h = (start_hlid + i) % AP_MAX_LINKS;
496
Arik Nemtsov7bb5d6c2011-08-14 13:17:00 +0300497 skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_VO]);
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200498 if (skb)
Arik Nemtsov7bb5d6c2011-08-14 13:17:00 +0300499 goto out;
500 skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_VI]);
501 if (skb)
502 goto out;
503 skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_BE]);
504 if (skb)
505 goto out;
506 skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_BK]);
507 if (skb)
508 goto out;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200509 }
510
Arik Nemtsov7bb5d6c2011-08-14 13:17:00 +0300511out:
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200512 if (skb) {
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300513 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200514 wl->last_tx_hlid = h;
515 spin_lock_irqsave(&wl->wl_lock, flags);
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300516 wl->tx_queue_count[q]--;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200517 spin_unlock_irqrestore(&wl->wl_lock, flags);
518 } else {
519 wl->last_tx_hlid = 0;
520 }
521
522 return skb;
523}
524
525static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl)
526{
Ido Yariv990f5de2011-03-31 10:06:59 +0200527 unsigned long flags;
528 struct sk_buff *skb = NULL;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200529
Ido Yariv990f5de2011-03-31 10:06:59 +0200530 if (wl->bss_type == BSS_TYPE_AP_BSS)
531 skb = wl1271_ap_skb_dequeue(wl);
532 else
533 skb = wl1271_sta_skb_dequeue(wl);
534
535 if (!skb &&
536 test_and_clear_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) {
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300537 int q;
538
Ido Yariv990f5de2011-03-31 10:06:59 +0200539 skb = wl->dummy_packet;
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300540 q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
Ido Yariv990f5de2011-03-31 10:06:59 +0200541 spin_lock_irqsave(&wl->wl_lock, flags);
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300542 wl->tx_queue_count[q]--;
Ido Yariv990f5de2011-03-31 10:06:59 +0200543 spin_unlock_irqrestore(&wl->wl_lock, flags);
544 }
545
546 return skb;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200547}
548
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200549static void wl1271_skb_queue_head(struct wl1271 *wl, struct sk_buff *skb)
550{
551 unsigned long flags;
552 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
553
Ido Yariv990f5de2011-03-31 10:06:59 +0200554 if (wl12xx_is_dummy_packet(wl, skb)) {
555 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
556 } else if (wl->bss_type == BSS_TYPE_AP_BSS) {
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200557 u8 hlid = wl1271_tx_get_hlid(skb);
558 skb_queue_head(&wl->links[hlid].tx_queue[q], skb);
559
560 /* make sure we dequeue the same packet next time */
561 wl->last_tx_hlid = (hlid + AP_MAX_LINKS - 1) % AP_MAX_LINKS;
562 } else {
563 skb_queue_head(&wl->tx_queue[q], skb);
564 }
565
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200566 spin_lock_irqsave(&wl->wl_lock, flags);
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300567 wl->tx_queue_count[q]++;
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200568 spin_unlock_irqrestore(&wl->wl_lock, flags);
569}
570
Eliad Peller77ddaa12011-05-15 11:10:29 +0300571static bool wl1271_tx_is_data_present(struct sk_buff *skb)
572{
573 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
574
575 return ieee80211_is_data_present(hdr->frame_control);
576}
577
Ido Yariva5225502010-10-12 14:49:10 +0200578void wl1271_tx_work_locked(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300579{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300580 struct sk_buff *skb;
Ido Yariv6c6e6692010-10-12 14:49:09 +0200581 u32 buf_offset = 0;
582 bool sent_packets = false;
Eliad Peller77ddaa12011-05-15 11:10:29 +0300583 bool had_data = false;
584 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300585 int ret;
586
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300587 if (unlikely(wl->state == WL1271_STATE_OFF))
Eliad Pellerc1b193e2011-03-23 22:22:15 +0200588 return;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300589
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200590 while ((skb = wl1271_skb_dequeue(wl))) {
Eliad Peller77ddaa12011-05-15 11:10:29 +0300591 if (wl1271_tx_is_data_present(skb))
592 had_data = true;
593
Ido Yariva19606b2010-09-30 13:28:28 +0200594 ret = wl1271_prepare_tx_frame(wl, skb, buf_offset);
Ido Yariv6c6e6692010-10-12 14:49:09 +0200595 if (ret == -EAGAIN) {
Ido Yariva19606b2010-09-30 13:28:28 +0200596 /*
Ido Yariv6c6e6692010-10-12 14:49:09 +0200597 * Aggregation buffer is full.
598 * Flush buffer and try again.
599 */
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200600 wl1271_skb_queue_head(wl, skb);
Ido Yariv6c6e6692010-10-12 14:49:09 +0200601 wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200602 buf_offset, true);
Ido Yariv6c6e6692010-10-12 14:49:09 +0200603 sent_packets = true;
604 buf_offset = 0;
605 continue;
606 } else if (ret == -EBUSY) {
607 /*
608 * Firmware buffer is full.
Ido Yariva19606b2010-09-30 13:28:28 +0200609 * Queue back last skb, and stop aggregating.
610 */
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200611 wl1271_skb_queue_head(wl, skb);
Ido Yariva5225502010-10-12 14:49:10 +0200612 /* No work left, avoid scheduling redundant tx work */
613 set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200614 goto out_ack;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300615 } else if (ret < 0) {
616 dev_kfree_skb(skb);
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200617 goto out_ack;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300618 }
Ido Yariva19606b2010-09-30 13:28:28 +0200619 buf_offset += ret;
620 wl->tx_packets_count++;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300621 }
622
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200623out_ack:
Ido Yariva19606b2010-09-30 13:28:28 +0200624 if (buf_offset) {
625 wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
626 buf_offset, true);
Ido Yariv6c6e6692010-10-12 14:49:09 +0200627 sent_packets = true;
628 }
629 if (sent_packets) {
Ido Yariv606ea9f2011-03-01 15:14:39 +0200630 /*
631 * Interrupt the firmware with the new packets. This is only
632 * required for older hardware revisions
633 */
634 if (wl->quirks & WL12XX_QUIRK_END_OF_TRANSACTION)
635 wl1271_write32(wl, WL1271_HOST_WR_ACCESS,
636 wl->tx_packets_count);
637
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200638 wl1271_handle_tx_low_watermark(wl);
Ido Yariva19606b2010-09-30 13:28:28 +0200639 }
Eliad Peller77ddaa12011-05-15 11:10:29 +0300640 if (!is_ap && wl->conf.rx_streaming.interval && had_data &&
641 (wl->conf.rx_streaming.always ||
642 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) {
643 u32 timeout = wl->conf.rx_streaming.duration;
644
645 /* enable rx streaming */
646 if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags))
647 ieee80211_queue_work(wl->hw,
648 &wl->rx_streaming_enable_work);
649
650 mod_timer(&wl->rx_streaming_timer,
651 jiffies + msecs_to_jiffies(timeout));
652 }
Ido Yariva5225502010-10-12 14:49:10 +0200653}
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300654
Ido Yariva5225502010-10-12 14:49:10 +0200655void wl1271_tx_work(struct work_struct *work)
656{
657 struct wl1271 *wl = container_of(work, struct wl1271, tx_work);
Eliad Pellerc1b193e2011-03-23 22:22:15 +0200658 int ret;
Ido Yariva5225502010-10-12 14:49:10 +0200659
660 mutex_lock(&wl->mutex);
Eliad Pellerc1b193e2011-03-23 22:22:15 +0200661 ret = wl1271_ps_elp_wakeup(wl);
662 if (ret < 0)
663 goto out;
664
Ido Yariva5225502010-10-12 14:49:10 +0200665 wl1271_tx_work_locked(wl);
Eliad Pellerc1b193e2011-03-23 22:22:15 +0200666
Eliad Pellerc75bbcd2011-04-04 10:38:47 +0300667 wl1271_ps_elp_sleep(wl);
Eliad Pellerc1b193e2011-03-23 22:22:15 +0200668out:
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300669 mutex_unlock(&wl->mutex);
670}
671
672static void wl1271_tx_complete_packet(struct wl1271 *wl,
673 struct wl1271_tx_hw_res_descr *result)
674{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300675 struct ieee80211_tx_info *info;
676 struct sk_buff *skb;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300677 int id = result->id;
Juuso Oikarinen31627dc2010-03-26 12:53:12 +0200678 int rate = -1;
679 u8 retries = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300680
681 /* check for id legality */
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200682 if (unlikely(id >= ACX_TX_DESCRIPTORS || wl->tx_frames[id] == NULL)) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300683 wl1271_warning("TX result illegal id: %d", id);
684 return;
685 }
686
687 skb = wl->tx_frames[id];
688 info = IEEE80211_SKB_CB(skb);
689
Ido Yariv990f5de2011-03-31 10:06:59 +0200690 if (wl12xx_is_dummy_packet(wl, skb)) {
Shahar Leviae47c452011-03-06 16:32:14 +0200691 wl1271_free_tx_id(wl, id);
692 return;
693 }
694
Juuso Oikarinen31627dc2010-03-26 12:53:12 +0200695 /* update the TX status info */
696 if (result->status == TX_SUCCESS) {
697 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300698 info->flags |= IEEE80211_TX_STAT_ACK;
Teemu Paasikivi6a2de932010-10-14 11:00:04 +0200699 rate = wl1271_rate_to_idx(result->rate_class_index, wl->band);
Juuso Oikarinen31627dc2010-03-26 12:53:12 +0200700 retries = result->ack_failures;
701 } else if (result->status == TX_RETRY_EXCEEDED) {
702 wl->stats.excessive_retries++;
703 retries = result->ack_failures;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300704 }
705
Juuso Oikarinen31627dc2010-03-26 12:53:12 +0200706 info->status.rates[0].idx = rate;
707 info->status.rates[0].count = retries;
708 info->status.rates[0].flags = 0;
709 info->status.ack_signal = -1;
710
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300711 wl->stats.retry_count += result->ack_failures;
712
Oz Krakowskib992c682011-06-26 10:36:02 +0300713 /*
714 * update sequence number only when relevant, i.e. only in
715 * sessions of TKIP, AES and GEM (not in open or WEP sessions)
716 */
717 if (info->control.hw_key &&
718 (info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP ||
719 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_CCMP ||
720 info->control.hw_key->cipher == WL1271_CIPHER_SUITE_GEM)) {
721 u8 fw_lsb = result->tx_security_sequence_number_lsb;
722 u8 cur_lsb = wl->tx_security_last_seq_lsb;
723
724 /*
725 * update security sequence number, taking care of potential
726 * wrap-around
727 */
728 wl->tx_security_seq += (fw_lsb - cur_lsb + 256) % 256;
729 wl->tx_security_last_seq_lsb = fw_lsb;
730 }
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300731
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +0300732 /* remove private header from packet */
733 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
734
735 /* remove TKIP header space if present */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300736 if (info->control.hw_key &&
Johannes Berg97359d12010-08-10 09:46:38 +0200737 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
Juuso Oikarinen1e2b7972009-10-08 21:56:20 +0300738 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
739 memmove(skb->data + WL1271_TKIP_IV_SPACE, skb->data, hdrlen);
740 skb_pull(skb, WL1271_TKIP_IV_SPACE);
741 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300742
743 wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
744 " status 0x%x",
745 result->id, skb, result->ack_failures,
746 result->rate_class_index, result->status);
747
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300748 /* return the packet to the stack */
Ido Yariva6208652011-03-01 15:14:41 +0200749 skb_queue_tail(&wl->deferred_tx_queue, skb);
Eliad Peller92ef8962011-06-07 12:50:46 +0300750 queue_work(wl->freezable_wq, &wl->netstack_work);
Ido Yariv25eeb9e2010-10-12 16:20:06 +0200751 wl1271_free_tx_id(wl, result->id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300752}
753
754/* Called upon reception of a TX complete interrupt */
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200755void wl1271_tx_complete(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300756{
757 struct wl1271_acx_mem_map *memmap =
758 (struct wl1271_acx_mem_map *)wl->target_mem_map;
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200759 u32 count, fw_counter;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300760 u32 i;
761
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300762 /* read the tx results from the chipset */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200763 wl1271_read(wl, le32_to_cpu(memmap->tx_result),
764 wl->tx_res_if, sizeof(*wl->tx_res_if), false);
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200765 fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter);
766
767 /* write host counter to chipset (to ack) */
768 wl1271_write32(wl, le32_to_cpu(memmap->tx_result) +
769 offsetof(struct wl1271_tx_hw_res_if,
770 tx_result_host_counter), fw_counter);
771
772 count = fw_counter - wl->tx_results_count;
Juuso Oikarinen06f7bc72010-02-22 08:38:33 +0200773 wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300774
775 /* verify that the result buffer is not getting overrun */
Juuso Oikarinenffb591c2010-02-22 08:38:31 +0200776 if (unlikely(count > TX_HW_RESULT_QUEUE_LEN))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300777 wl1271_warning("TX result overflow from chipset: %d", count);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300778
779 /* process the results */
780 for (i = 0; i < count; i++) {
781 struct wl1271_tx_hw_res_descr *result;
782 u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK;
783
784 /* process the packet */
785 result = &(wl->tx_res_if->tx_results_queue[offset]);
786 wl1271_tx_complete_packet(wl, result);
787
788 wl->tx_results_count++;
789 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300790}
791
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200792void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid)
793{
794 struct sk_buff *skb;
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300795 int i;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200796 unsigned long flags;
Arik Nemtsov1d36cd82011-02-23 00:22:27 +0200797 struct ieee80211_tx_info *info;
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300798 int total[NUM_TX_QUEUES];
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200799
800 for (i = 0; i < NUM_TX_QUEUES; i++) {
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300801 total[i] = 0;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200802 while ((skb = skb_dequeue(&wl->links[hlid].tx_queue[i]))) {
803 wl1271_debug(DEBUG_TX, "link freeing skb 0x%p", skb);
Arik Nemtsov1d36cd82011-02-23 00:22:27 +0200804 info = IEEE80211_SKB_CB(skb);
805 info->status.rates[0].idx = -1;
806 info->status.rates[0].count = 0;
Eliad Pellerc27d3ac2011-06-07 10:40:39 +0300807 ieee80211_tx_status_ni(wl->hw, skb);
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300808 total[i]++;
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200809 }
810 }
811
812 spin_lock_irqsave(&wl->wl_lock, flags);
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300813 for (i = 0; i < NUM_TX_QUEUES; i++)
814 wl->tx_queue_count[i] -= total[i];
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200815 spin_unlock_irqrestore(&wl->wl_lock, flags);
816
817 wl1271_handle_tx_low_watermark(wl);
818}
819
Arik Nemtsov7dece1c2011-04-18 14:15:28 +0300820/* caller must hold wl->mutex and TX must be stopped */
821void wl1271_tx_reset(struct wl1271 *wl, bool reset_tx_queues)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300822{
823 int i;
824 struct sk_buff *skb;
Arik Nemtsov1d36cd82011-02-23 00:22:27 +0200825 struct ieee80211_tx_info *info;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300826
827 /* TX failure */
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200828 if (wl->bss_type == BSS_TYPE_AP_BSS) {
Arik Nemtsov09039f42011-02-23 00:22:30 +0200829 for (i = 0; i < AP_MAX_LINKS; i++) {
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200830 wl1271_tx_reset_link_queues(wl, i);
Arik Nemtsov09039f42011-02-23 00:22:30 +0200831 wl->links[i].allocated_blks = 0;
832 wl->links[i].prev_freed_blks = 0;
833 }
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200834
835 wl->last_tx_hlid = 0;
836 } else {
837 for (i = 0; i < NUM_TX_QUEUES; i++) {
838 while ((skb = skb_dequeue(&wl->tx_queue[i]))) {
839 wl1271_debug(DEBUG_TX, "freeing skb 0x%p",
840 skb);
Shahar Leviae47c452011-03-06 16:32:14 +0200841
Ido Yariv990f5de2011-03-31 10:06:59 +0200842 if (!wl12xx_is_dummy_packet(wl, skb)) {
Shahar Leviae47c452011-03-06 16:32:14 +0200843 info = IEEE80211_SKB_CB(skb);
844 info->status.rates[0].idx = -1;
845 info->status.rates[0].count = 0;
Eliad Pellerc27d3ac2011-06-07 10:40:39 +0300846 ieee80211_tx_status_ni(wl->hw, skb);
Shahar Leviae47c452011-03-06 16:32:14 +0200847 }
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200848 }
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300849 wl->tx_queue_count[i] = 0;
Juuso Oikarinen6742f552010-12-13 09:52:37 +0200850 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300851 }
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200852
Arik Nemtsov708bb3c2011-06-24 13:03:37 +0300853 wl->stopped_queues_map = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300854
Ido Yariv2fe33e82010-10-12 14:49:12 +0200855 /*
856 * Make sure the driver is at a consistent state, in case this
857 * function is called from a context other than interface removal.
Arik Nemtsov7dece1c2011-04-18 14:15:28 +0300858 * This call will always wake the TX queues.
Ido Yariv2fe33e82010-10-12 14:49:12 +0200859 */
Arik Nemtsov7dece1c2011-04-18 14:15:28 +0300860 if (reset_tx_queues)
861 wl1271_handle_tx_low_watermark(wl);
Ido Yariv2fe33e82010-10-12 14:49:12 +0200862
Ido Yariv50e9f742011-02-28 00:16:13 +0200863 for (i = 0; i < ACX_TX_DESCRIPTORS; i++) {
864 if (wl->tx_frames[i] == NULL)
865 continue;
866
867 skb = wl->tx_frames[i];
868 wl1271_free_tx_id(wl, i);
869 wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb);
870
Ido Yariv990f5de2011-03-31 10:06:59 +0200871 if (!wl12xx_is_dummy_packet(wl, skb)) {
Shahar Leviae47c452011-03-06 16:32:14 +0200872 /*
873 * Remove private headers before passing the skb to
874 * mac80211
875 */
876 info = IEEE80211_SKB_CB(skb);
877 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
878 if (info->control.hw_key &&
879 info->control.hw_key->cipher ==
880 WLAN_CIPHER_SUITE_TKIP) {
881 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
882 memmove(skb->data + WL1271_TKIP_IV_SPACE,
883 skb->data, hdrlen);
884 skb_pull(skb, WL1271_TKIP_IV_SPACE);
885 }
886
887 info->status.rates[0].idx = -1;
888 info->status.rates[0].count = 0;
889
Eliad Pellerc27d3ac2011-06-07 10:40:39 +0300890 ieee80211_tx_status_ni(wl->hw, skb);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300891 }
Ido Yariv50e9f742011-02-28 00:16:13 +0200892 }
Juuso Oikarinen781608c2010-05-24 11:18:17 +0300893}
894
895#define WL1271_TX_FLUSH_TIMEOUT 500000
896
897/* caller must *NOT* hold wl->mutex */
898void wl1271_tx_flush(struct wl1271 *wl)
899{
900 unsigned long timeout;
901 timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT);
902
903 while (!time_after(jiffies, timeout)) {
904 mutex_lock(&wl->mutex);
Arik Nemtsova8c0ddb2011-02-23 00:22:26 +0200905 wl1271_debug(DEBUG_TX, "flushing tx buffer: %d %d",
Arik Nemtsovf1a46382011-07-07 14:25:23 +0300906 wl->tx_frames_cnt,
907 wl1271_tx_total_queue_count(wl));
908 if ((wl->tx_frames_cnt == 0) &&
909 (wl1271_tx_total_queue_count(wl) == 0)) {
Juuso Oikarinen781608c2010-05-24 11:18:17 +0300910 mutex_unlock(&wl->mutex);
911 return;
912 }
913 mutex_unlock(&wl->mutex);
914 msleep(1);
915 }
916
917 wl1271_warning("Unable to flush all TX buffers, timed out.");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300918}
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200919
920u32 wl1271_tx_min_rate_get(struct wl1271 *wl)
921{
922 int i;
923 u32 rate = 0;
924
925 if (!wl->basic_rate_set) {
926 WARN_ON(1);
927 wl->basic_rate_set = wl->conf.tx.basic_rate;
928 }
929
930 for (i = 0; !rate; i++) {
931 if ((wl->basic_rate_set >> i) & 0x1)
932 rate = 1 << i;
933 }
934
935 return rate;
936}