Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 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> |
Arik Nemtsov | c6c8a65 | 2010-10-16 20:27:53 +0200 | [diff] [blame] | 26 | #include <linux/etherdevice.h> |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 27 | |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 28 | #include "wl12xx.h" |
| 29 | #include "io.h" |
| 30 | #include "reg.h" |
| 31 | #include "ps.h" |
| 32 | #include "tx.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 33 | |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 34 | static 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 Yariv | 25eeb9e | 2010-10-12 16:20:06 +0200 | [diff] [blame] | 51 | static int wl1271_alloc_tx_id(struct wl1271 *wl, struct sk_buff *skb) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 52 | { |
Ido Yariv | 25eeb9e | 2010-10-12 16:20:06 +0200 | [diff] [blame] | 53 | int id; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 54 | |
Ido Yariv | 25eeb9e | 2010-10-12 16:20:06 +0200 | [diff] [blame] | 55 | 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 | |
| 65 | static 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 Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 71 | } |
| 72 | |
Arik Nemtsov | 99a2775 | 2011-02-23 00:22:25 +0200 | [diff] [blame] | 73 | static void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl, |
| 74 | struct sk_buff *skb) |
| 75 | { |
| 76 | struct ieee80211_hdr *hdr; |
| 77 | |
| 78 | /* |
| 79 | * add the station to the known list before transmitting the |
| 80 | * authentication response. this way it won't get de-authed by FW |
| 81 | * when transmitting too soon. |
| 82 | */ |
| 83 | hdr = (struct ieee80211_hdr *)(skb->data + |
| 84 | sizeof(struct wl1271_tx_hw_descr)); |
| 85 | if (ieee80211_is_auth(hdr->frame_control)) |
| 86 | wl1271_acx_set_inconnection_sta(wl, hdr->addr1); |
| 87 | } |
| 88 | |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame^] | 89 | u8 wl1271_tx_get_hlid(struct sk_buff *skb) |
| 90 | { |
| 91 | struct ieee80211_tx_info *control = IEEE80211_SKB_CB(skb); |
| 92 | |
| 93 | if (control->control.sta) { |
| 94 | struct wl1271_station *wl_sta; |
| 95 | |
| 96 | wl_sta = (struct wl1271_station *) |
| 97 | control->control.sta->drv_priv; |
| 98 | return wl_sta->hlid; |
| 99 | } else { |
| 100 | struct ieee80211_hdr *hdr; |
| 101 | |
| 102 | hdr = (struct ieee80211_hdr *)skb->data; |
| 103 | if (ieee80211_is_mgmt(hdr->frame_control)) |
| 104 | return WL1271_AP_GLOBAL_HLID; |
| 105 | else |
| 106 | return WL1271_AP_BROADCAST_HLID; |
| 107 | } |
| 108 | } |
| 109 | |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 110 | static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra, |
| 111 | u32 buf_offset) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 112 | { |
| 113 | struct wl1271_tx_hw_descr *desc; |
| 114 | u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra; |
Juuso Oikarinen | 5c9417f | 2010-02-22 08:38:39 +0200 | [diff] [blame] | 115 | u32 total_blocks; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 116 | int id, ret = -EBUSY; |
| 117 | |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 118 | if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE) |
Ido Yariv | 6c6e669 | 2010-10-12 14:49:09 +0200 | [diff] [blame] | 119 | return -EAGAIN; |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 120 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 121 | /* allocate free identifier for the packet */ |
Ido Yariv | 25eeb9e | 2010-10-12 16:20:06 +0200 | [diff] [blame] | 122 | id = wl1271_alloc_tx_id(wl, skb); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 123 | if (id < 0) |
| 124 | return id; |
| 125 | |
| 126 | /* approximate the number of blocks required for this packet |
| 127 | in the firmware */ |
Juuso Oikarinen | 5c9417f | 2010-02-22 08:38:39 +0200 | [diff] [blame] | 128 | total_blocks = total_len + TX_HW_BLOCK_SIZE - 1; |
| 129 | total_blocks = total_blocks / TX_HW_BLOCK_SIZE + TX_HW_BLOCK_SPARE; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 130 | if (total_blocks <= wl->tx_blocks_available) { |
| 131 | desc = (struct wl1271_tx_hw_descr *)skb_push( |
| 132 | skb, total_len - skb->len); |
| 133 | |
| 134 | desc->extra_mem_blocks = TX_HW_BLOCK_SPARE; |
| 135 | desc->total_mem_blocks = total_blocks; |
| 136 | desc->id = id; |
| 137 | |
| 138 | wl->tx_blocks_available -= total_blocks; |
| 139 | |
| 140 | ret = 0; |
| 141 | |
| 142 | wl1271_debug(DEBUG_TX, |
| 143 | "tx_allocate: size: %d, blocks: %d, id: %d", |
| 144 | total_len, total_blocks, id); |
Juuso Oikarinen | 781608c | 2010-05-24 11:18:17 +0300 | [diff] [blame] | 145 | } else { |
Ido Yariv | 25eeb9e | 2010-10-12 16:20:06 +0200 | [diff] [blame] | 146 | wl1271_free_tx_id(wl, id); |
Juuso Oikarinen | 781608c | 2010-05-24 11:18:17 +0300 | [diff] [blame] | 147 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 148 | |
| 149 | return ret; |
| 150 | } |
| 151 | |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 152 | static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 153 | u32 extra, struct ieee80211_tx_info *control) |
| 154 | { |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame] | 155 | struct timespec ts; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 156 | struct wl1271_tx_hw_descr *desc; |
Arik Nemtsov | c6c8a65 | 2010-10-16 20:27:53 +0200 | [diff] [blame] | 157 | int pad, ac, rate_idx; |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame] | 158 | s64 hosttime; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 159 | u16 tx_attr; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 160 | |
| 161 | desc = (struct wl1271_tx_hw_descr *) skb->data; |
| 162 | |
Juuso Oikarinen | 1e2b797 | 2009-10-08 21:56:20 +0300 | [diff] [blame] | 163 | /* relocate space for security header */ |
| 164 | if (extra) { |
| 165 | void *framestart = skb->data + sizeof(*desc); |
| 166 | u16 fc = *(u16 *)(framestart + extra); |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 167 | int hdrlen = ieee80211_hdrlen(cpu_to_le16(fc)); |
Juuso Oikarinen | 1e2b797 | 2009-10-08 21:56:20 +0300 | [diff] [blame] | 168 | memmove(framestart, framestart + extra, hdrlen); |
| 169 | } |
| 170 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 171 | /* configure packet life time */ |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame] | 172 | getnstimeofday(&ts); |
| 173 | hosttime = (timespec_to_ns(&ts) >> 10); |
| 174 | desc->start_time = cpu_to_le32(hosttime - wl->time_offset); |
Arik Nemtsov | c6c8a65 | 2010-10-16 20:27:53 +0200 | [diff] [blame] | 175 | |
| 176 | if (wl->bss_type != BSS_TYPE_AP_BSS) |
| 177 | desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU); |
| 178 | else |
| 179 | desc->life_time = cpu_to_le16(TX_HW_AP_MODE_PKT_LIFETIME_TU); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 180 | |
| 181 | /* configure the tx attributes */ |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 182 | tx_attr = wl->session_counter << TX_HW_ATTR_OFST_SESSION_COUNTER; |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 183 | |
Juuso Oikarinen | ed484a1 | 2010-09-01 11:31:11 +0200 | [diff] [blame] | 184 | /* queue (we use same identifiers for tid's and ac's */ |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 185 | ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); |
Juuso Oikarinen | ed484a1 | 2010-09-01 11:31:11 +0200 | [diff] [blame] | 186 | desc->tid = ac; |
Arik Nemtsov | c6c8a65 | 2010-10-16 20:27:53 +0200 | [diff] [blame] | 187 | |
| 188 | if (wl->bss_type != BSS_TYPE_AP_BSS) { |
| 189 | desc->aid = TX_HW_DEFAULT_AID; |
| 190 | |
| 191 | /* if the packets are destined for AP (have a STA entry) |
| 192 | send them with AP rate policies, otherwise use default |
| 193 | basic rates */ |
| 194 | if (control->control.sta) |
| 195 | rate_idx = ACX_TX_AP_FULL_RATE; |
| 196 | else |
| 197 | rate_idx = ACX_TX_BASIC_RATE; |
| 198 | } else { |
| 199 | if (control->control.sta) { |
| 200 | struct wl1271_station *wl_sta; |
| 201 | |
| 202 | wl_sta = (struct wl1271_station *) |
| 203 | control->control.sta->drv_priv; |
| 204 | desc->hlid = wl_sta->hlid; |
| 205 | rate_idx = ac; |
| 206 | } else { |
| 207 | struct ieee80211_hdr *hdr; |
| 208 | |
| 209 | hdr = (struct ieee80211_hdr *) |
| 210 | (skb->data + sizeof(*desc)); |
| 211 | if (ieee80211_is_mgmt(hdr->frame_control)) { |
| 212 | desc->hlid = WL1271_AP_GLOBAL_HLID; |
| 213 | rate_idx = ACX_TX_AP_MODE_MGMT_RATE; |
| 214 | } else { |
| 215 | desc->hlid = WL1271_AP_BROADCAST_HLID; |
| 216 | rate_idx = ACX_TX_AP_MODE_BCST_RATE; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | tx_attr |= rate_idx << TX_HW_ATTR_OFST_RATE_POLICY; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 222 | desc->reserved = 0; |
| 223 | |
| 224 | /* align the length (and store in terms of words) */ |
Eliad Peller | 02ad2d9 | 2011-02-23 00:27:06 +0200 | [diff] [blame] | 225 | pad = ALIGN(skb->len, WL1271_TX_ALIGN_TO); |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 226 | desc->length = cpu_to_le16(pad >> 2); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 227 | |
| 228 | /* calculate number of padding bytes */ |
| 229 | pad = pad - skb->len; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 230 | tx_attr |= pad << TX_HW_ATTR_OFST_LAST_WORD_PAD; |
| 231 | |
| 232 | desc->tx_attr = cpu_to_le16(tx_attr); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 233 | |
Arik Nemtsov | c6c8a65 | 2010-10-16 20:27:53 +0200 | [diff] [blame] | 234 | wl1271_debug(DEBUG_TX, "tx_fill_hdr: pad: %d hlid: %d " |
Eliad Peller | 1d4801f | 2011-01-16 10:07:10 +0100 | [diff] [blame] | 235 | "tx_attr: 0x%x len: %d life: %d mem: %d", pad, desc->hlid, |
| 236 | le16_to_cpu(desc->tx_attr), le16_to_cpu(desc->length), |
| 237 | le16_to_cpu(desc->life_time), desc->total_mem_blocks); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /* caller must hold wl->mutex */ |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 241 | static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct sk_buff *skb, |
| 242 | u32 buf_offset) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 243 | { |
| 244 | struct ieee80211_tx_info *info; |
| 245 | u32 extra = 0; |
| 246 | int ret = 0; |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 247 | u32 total_len; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 248 | |
| 249 | if (!skb) |
| 250 | return -EINVAL; |
| 251 | |
| 252 | info = IEEE80211_SKB_CB(skb); |
| 253 | |
| 254 | if (info->control.hw_key && |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 255 | info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 256 | extra = WL1271_TKIP_IV_SPACE; |
| 257 | |
| 258 | if (info->control.hw_key) { |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 259 | bool is_wep; |
| 260 | u8 idx = info->control.hw_key->hw_key_idx; |
| 261 | u32 cipher = info->control.hw_key->cipher; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 262 | |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 263 | is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) || |
| 264 | (cipher == WLAN_CIPHER_SUITE_WEP104); |
| 265 | |
| 266 | if (unlikely(is_wep && wl->default_key != idx)) { |
| 267 | ret = wl1271_set_default_wep_key(wl, idx); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 268 | if (ret < 0) |
| 269 | return ret; |
Juuso Oikarinen | ee444cf | 2010-02-18 13:25:50 +0200 | [diff] [blame] | 270 | wl->default_key = idx; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 274 | ret = wl1271_tx_allocate(wl, skb, extra, buf_offset); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 275 | if (ret < 0) |
| 276 | return ret; |
| 277 | |
Arik Nemtsov | 99a2775 | 2011-02-23 00:22:25 +0200 | [diff] [blame] | 278 | if (wl->bss_type == BSS_TYPE_AP_BSS) |
| 279 | wl1271_tx_ap_update_inconnection_sta(wl, skb); |
| 280 | |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 281 | wl1271_tx_fill_hdr(wl, skb, extra, info); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 282 | |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 283 | /* |
| 284 | * The length of each packet is stored in terms of words. Thus, we must |
| 285 | * pad the skb data to make sure its length is aligned. |
| 286 | * The number of padding bytes is computed and set in wl1271_tx_fill_hdr |
| 287 | */ |
Eliad Peller | 02ad2d9 | 2011-02-23 00:27:06 +0200 | [diff] [blame] | 288 | total_len = ALIGN(skb->len, WL1271_TX_ALIGN_TO); |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 289 | memcpy(wl->aggr_buf + buf_offset, skb->data, skb->len); |
| 290 | memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 291 | |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 292 | return total_len; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 293 | } |
| 294 | |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 295 | u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set) |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 296 | { |
| 297 | struct ieee80211_supported_band *band; |
| 298 | u32 enabled_rates = 0; |
| 299 | int bit; |
| 300 | |
| 301 | band = wl->hw->wiphy->bands[wl->band]; |
| 302 | for (bit = 0; bit < band->n_bitrates; bit++) { |
| 303 | if (rate_set & 0x1) |
| 304 | enabled_rates |= band->bitrates[bit].hw_value; |
| 305 | rate_set >>= 1; |
| 306 | } |
| 307 | |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 308 | #ifdef CONFIG_WL12XX_HT |
Shahar Levi | 1835785 | 2010-10-13 16:09:41 +0200 | [diff] [blame] | 309 | /* MCS rates indication are on bits 16 - 23 */ |
| 310 | rate_set >>= HW_HT_RATES_OFFSET - band->n_bitrates; |
| 311 | |
| 312 | for (bit = 0; bit < 8; bit++) { |
| 313 | if (rate_set & 0x1) |
| 314 | enabled_rates |= (CONF_HW_BIT_RATE_MCS_0 << bit); |
| 315 | rate_set >>= 1; |
| 316 | } |
| 317 | #endif |
| 318 | |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 319 | return enabled_rates; |
| 320 | } |
| 321 | |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame^] | 322 | void wl1271_handle_tx_low_watermark(struct wl1271 *wl) |
Ido Yariv | 2fe33e8 | 2010-10-12 14:49:12 +0200 | [diff] [blame] | 323 | { |
| 324 | unsigned long flags; |
| 325 | |
| 326 | if (test_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags) && |
Juuso Oikarinen | 6742f55 | 2010-12-13 09:52:37 +0200 | [diff] [blame] | 327 | wl->tx_queue_count <= WL1271_TX_QUEUE_LOW_WATERMARK) { |
Ido Yariv | 2fe33e8 | 2010-10-12 14:49:12 +0200 | [diff] [blame] | 328 | /* firmware buffer has space, restart queues */ |
| 329 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 330 | ieee80211_wake_queues(wl->hw); |
| 331 | clear_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags); |
| 332 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 333 | } |
| 334 | } |
| 335 | |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame^] | 336 | static struct sk_buff *wl1271_sta_skb_dequeue(struct wl1271 *wl) |
Juuso Oikarinen | 6742f55 | 2010-12-13 09:52:37 +0200 | [diff] [blame] | 337 | { |
| 338 | struct sk_buff *skb = NULL; |
| 339 | unsigned long flags; |
| 340 | |
| 341 | skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_VO]); |
| 342 | if (skb) |
| 343 | goto out; |
| 344 | skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_VI]); |
| 345 | if (skb) |
| 346 | goto out; |
| 347 | skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_BE]); |
| 348 | if (skb) |
| 349 | goto out; |
| 350 | skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_BK]); |
| 351 | |
| 352 | out: |
| 353 | if (skb) { |
| 354 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 355 | wl->tx_queue_count--; |
| 356 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 357 | } |
| 358 | |
| 359 | return skb; |
| 360 | } |
| 361 | |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame^] | 362 | static struct sk_buff *wl1271_ap_skb_dequeue(struct wl1271 *wl) |
| 363 | { |
| 364 | struct sk_buff *skb = NULL; |
| 365 | unsigned long flags; |
| 366 | int i, h, start_hlid; |
| 367 | |
| 368 | /* start from the link after the last one */ |
| 369 | start_hlid = (wl->last_tx_hlid + 1) % AP_MAX_LINKS; |
| 370 | |
| 371 | /* dequeue according to AC, round robin on each link */ |
| 372 | for (i = 0; i < AP_MAX_LINKS; i++) { |
| 373 | h = (start_hlid + i) % AP_MAX_LINKS; |
| 374 | |
| 375 | skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_VO]); |
| 376 | if (skb) |
| 377 | goto out; |
| 378 | skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_VI]); |
| 379 | if (skb) |
| 380 | goto out; |
| 381 | skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_BE]); |
| 382 | if (skb) |
| 383 | goto out; |
| 384 | skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_BK]); |
| 385 | if (skb) |
| 386 | goto out; |
| 387 | } |
| 388 | |
| 389 | out: |
| 390 | if (skb) { |
| 391 | wl->last_tx_hlid = h; |
| 392 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 393 | wl->tx_queue_count--; |
| 394 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 395 | } else { |
| 396 | wl->last_tx_hlid = 0; |
| 397 | } |
| 398 | |
| 399 | return skb; |
| 400 | } |
| 401 | |
| 402 | static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl) |
| 403 | { |
| 404 | if (wl->bss_type == BSS_TYPE_AP_BSS) |
| 405 | return wl1271_ap_skb_dequeue(wl); |
| 406 | |
| 407 | return wl1271_sta_skb_dequeue(wl); |
| 408 | } |
| 409 | |
Juuso Oikarinen | 6742f55 | 2010-12-13 09:52:37 +0200 | [diff] [blame] | 410 | static void wl1271_skb_queue_head(struct wl1271 *wl, struct sk_buff *skb) |
| 411 | { |
| 412 | unsigned long flags; |
| 413 | int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); |
| 414 | |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame^] | 415 | if (wl->bss_type == BSS_TYPE_AP_BSS) { |
| 416 | u8 hlid = wl1271_tx_get_hlid(skb); |
| 417 | skb_queue_head(&wl->links[hlid].tx_queue[q], skb); |
| 418 | |
| 419 | /* make sure we dequeue the same packet next time */ |
| 420 | wl->last_tx_hlid = (hlid + AP_MAX_LINKS - 1) % AP_MAX_LINKS; |
| 421 | } else { |
| 422 | skb_queue_head(&wl->tx_queue[q], skb); |
| 423 | } |
| 424 | |
Juuso Oikarinen | 6742f55 | 2010-12-13 09:52:37 +0200 | [diff] [blame] | 425 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 426 | wl->tx_queue_count++; |
| 427 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 428 | } |
| 429 | |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 430 | void wl1271_tx_work_locked(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 431 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 432 | struct sk_buff *skb; |
| 433 | bool woken_up = false; |
Ido Yariv | 6c6e669 | 2010-10-12 14:49:09 +0200 | [diff] [blame] | 434 | u32 buf_offset = 0; |
| 435 | bool sent_packets = false; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 436 | int ret; |
| 437 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 438 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 439 | goto out; |
| 440 | |
Juuso Oikarinen | 6742f55 | 2010-12-13 09:52:37 +0200 | [diff] [blame] | 441 | while ((skb = wl1271_skb_dequeue(wl))) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 442 | if (!woken_up) { |
| 443 | ret = wl1271_ps_elp_wakeup(wl, false); |
| 444 | if (ret < 0) |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 445 | goto out_ack; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 446 | woken_up = true; |
| 447 | } |
| 448 | |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 449 | ret = wl1271_prepare_tx_frame(wl, skb, buf_offset); |
Ido Yariv | 6c6e669 | 2010-10-12 14:49:09 +0200 | [diff] [blame] | 450 | if (ret == -EAGAIN) { |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 451 | /* |
Ido Yariv | 6c6e669 | 2010-10-12 14:49:09 +0200 | [diff] [blame] | 452 | * Aggregation buffer is full. |
| 453 | * Flush buffer and try again. |
| 454 | */ |
Juuso Oikarinen | 6742f55 | 2010-12-13 09:52:37 +0200 | [diff] [blame] | 455 | wl1271_skb_queue_head(wl, skb); |
Ido Yariv | 6c6e669 | 2010-10-12 14:49:09 +0200 | [diff] [blame] | 456 | wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf, |
Juuso Oikarinen | 6742f55 | 2010-12-13 09:52:37 +0200 | [diff] [blame] | 457 | buf_offset, true); |
Ido Yariv | 6c6e669 | 2010-10-12 14:49:09 +0200 | [diff] [blame] | 458 | sent_packets = true; |
| 459 | buf_offset = 0; |
| 460 | continue; |
| 461 | } else if (ret == -EBUSY) { |
| 462 | /* |
| 463 | * Firmware buffer is full. |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 464 | * Queue back last skb, and stop aggregating. |
| 465 | */ |
Juuso Oikarinen | 6742f55 | 2010-12-13 09:52:37 +0200 | [diff] [blame] | 466 | wl1271_skb_queue_head(wl, skb); |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 467 | /* No work left, avoid scheduling redundant tx work */ |
| 468 | set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 469 | goto out_ack; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 470 | } else if (ret < 0) { |
| 471 | dev_kfree_skb(skb); |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 472 | goto out_ack; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 473 | } |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 474 | buf_offset += ret; |
| 475 | wl->tx_packets_count++; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 476 | } |
| 477 | |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 478 | out_ack: |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 479 | if (buf_offset) { |
| 480 | wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf, |
| 481 | buf_offset, true); |
Ido Yariv | 6c6e669 | 2010-10-12 14:49:09 +0200 | [diff] [blame] | 482 | sent_packets = true; |
| 483 | } |
| 484 | if (sent_packets) { |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 485 | /* interrupt the firmware with the new packets */ |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 486 | wl1271_write32(wl, WL1271_HOST_WR_ACCESS, wl->tx_packets_count); |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame^] | 487 | wl1271_handle_tx_low_watermark(wl); |
Ido Yariv | a19606b | 2010-09-30 13:28:28 +0200 | [diff] [blame] | 488 | } |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 489 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 490 | out: |
| 491 | if (woken_up) |
| 492 | wl1271_ps_elp_sleep(wl); |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 493 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 494 | |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 495 | void wl1271_tx_work(struct work_struct *work) |
| 496 | { |
| 497 | struct wl1271 *wl = container_of(work, struct wl1271, tx_work); |
| 498 | |
| 499 | mutex_lock(&wl->mutex); |
| 500 | wl1271_tx_work_locked(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 501 | mutex_unlock(&wl->mutex); |
| 502 | } |
| 503 | |
| 504 | static void wl1271_tx_complete_packet(struct wl1271 *wl, |
| 505 | struct wl1271_tx_hw_res_descr *result) |
| 506 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 507 | struct ieee80211_tx_info *info; |
| 508 | struct sk_buff *skb; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 509 | int id = result->id; |
Juuso Oikarinen | 31627dc | 2010-03-26 12:53:12 +0200 | [diff] [blame] | 510 | int rate = -1; |
| 511 | u8 retries = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 512 | |
| 513 | /* check for id legality */ |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 514 | if (unlikely(id >= ACX_TX_DESCRIPTORS || wl->tx_frames[id] == NULL)) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 515 | wl1271_warning("TX result illegal id: %d", id); |
| 516 | return; |
| 517 | } |
| 518 | |
| 519 | skb = wl->tx_frames[id]; |
| 520 | info = IEEE80211_SKB_CB(skb); |
| 521 | |
Juuso Oikarinen | 31627dc | 2010-03-26 12:53:12 +0200 | [diff] [blame] | 522 | /* update the TX status info */ |
| 523 | if (result->status == TX_SUCCESS) { |
| 524 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 525 | info->flags |= IEEE80211_TX_STAT_ACK; |
Teemu Paasikivi | 6a2de93 | 2010-10-14 11:00:04 +0200 | [diff] [blame] | 526 | rate = wl1271_rate_to_idx(result->rate_class_index, wl->band); |
Juuso Oikarinen | 31627dc | 2010-03-26 12:53:12 +0200 | [diff] [blame] | 527 | retries = result->ack_failures; |
| 528 | } else if (result->status == TX_RETRY_EXCEEDED) { |
| 529 | wl->stats.excessive_retries++; |
| 530 | retries = result->ack_failures; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 531 | } |
| 532 | |
Juuso Oikarinen | 31627dc | 2010-03-26 12:53:12 +0200 | [diff] [blame] | 533 | info->status.rates[0].idx = rate; |
| 534 | info->status.rates[0].count = retries; |
| 535 | info->status.rates[0].flags = 0; |
| 536 | info->status.ack_signal = -1; |
| 537 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 538 | wl->stats.retry_count += result->ack_failures; |
| 539 | |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 540 | /* update security sequence number */ |
Juuso Oikarinen | 04e36fc | 2010-02-22 08:38:40 +0200 | [diff] [blame] | 541 | wl->tx_security_seq += (result->lsb_security_sequence_number - |
| 542 | wl->tx_security_last_seq); |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 543 | wl->tx_security_last_seq = result->lsb_security_sequence_number; |
| 544 | |
Juuso Oikarinen | 1e2b797 | 2009-10-08 21:56:20 +0300 | [diff] [blame] | 545 | /* remove private header from packet */ |
| 546 | skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); |
| 547 | |
| 548 | /* remove TKIP header space if present */ |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 549 | if (info->control.hw_key && |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 550 | info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) { |
Juuso Oikarinen | 1e2b797 | 2009-10-08 21:56:20 +0300 | [diff] [blame] | 551 | int hdrlen = ieee80211_get_hdrlen_from_skb(skb); |
| 552 | memmove(skb->data + WL1271_TKIP_IV_SPACE, skb->data, hdrlen); |
| 553 | skb_pull(skb, WL1271_TKIP_IV_SPACE); |
| 554 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 555 | |
| 556 | wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x" |
| 557 | " status 0x%x", |
| 558 | result->id, skb, result->ack_failures, |
| 559 | result->rate_class_index, result->status); |
| 560 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 561 | /* return the packet to the stack */ |
| 562 | ieee80211_tx_status(wl->hw, skb); |
Ido Yariv | 25eeb9e | 2010-10-12 16:20:06 +0200 | [diff] [blame] | 563 | wl1271_free_tx_id(wl, result->id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /* Called upon reception of a TX complete interrupt */ |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 567 | void wl1271_tx_complete(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 568 | { |
| 569 | struct wl1271_acx_mem_map *memmap = |
| 570 | (struct wl1271_acx_mem_map *)wl->target_mem_map; |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 571 | u32 count, fw_counter; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 572 | u32 i; |
| 573 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 574 | /* read the tx results from the chipset */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 575 | wl1271_read(wl, le32_to_cpu(memmap->tx_result), |
| 576 | wl->tx_res_if, sizeof(*wl->tx_res_if), false); |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 577 | fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter); |
| 578 | |
| 579 | /* write host counter to chipset (to ack) */ |
| 580 | wl1271_write32(wl, le32_to_cpu(memmap->tx_result) + |
| 581 | offsetof(struct wl1271_tx_hw_res_if, |
| 582 | tx_result_host_counter), fw_counter); |
| 583 | |
| 584 | count = fw_counter - wl->tx_results_count; |
Juuso Oikarinen | 06f7bc7 | 2010-02-22 08:38:33 +0200 | [diff] [blame] | 585 | wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 586 | |
| 587 | /* verify that the result buffer is not getting overrun */ |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 588 | if (unlikely(count > TX_HW_RESULT_QUEUE_LEN)) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 589 | wl1271_warning("TX result overflow from chipset: %d", count); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 590 | |
| 591 | /* process the results */ |
| 592 | for (i = 0; i < count; i++) { |
| 593 | struct wl1271_tx_hw_res_descr *result; |
| 594 | u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK; |
| 595 | |
| 596 | /* process the packet */ |
| 597 | result = &(wl->tx_res_if->tx_results_queue[offset]); |
| 598 | wl1271_tx_complete_packet(wl, result); |
| 599 | |
| 600 | wl->tx_results_count++; |
| 601 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 602 | } |
| 603 | |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame^] | 604 | void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid) |
| 605 | { |
| 606 | struct sk_buff *skb; |
| 607 | int i, total = 0; |
| 608 | unsigned long flags; |
| 609 | |
| 610 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
| 611 | while ((skb = skb_dequeue(&wl->links[hlid].tx_queue[i]))) { |
| 612 | wl1271_debug(DEBUG_TX, "link freeing skb 0x%p", skb); |
| 613 | ieee80211_tx_status(wl->hw, skb); |
| 614 | total++; |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 619 | wl->tx_queue_count -= total; |
| 620 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 621 | |
| 622 | wl1271_handle_tx_low_watermark(wl); |
| 623 | } |
| 624 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 625 | /* caller must hold wl->mutex */ |
Juuso Oikarinen | 781608c | 2010-05-24 11:18:17 +0300 | [diff] [blame] | 626 | void wl1271_tx_reset(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 627 | { |
| 628 | int i; |
| 629 | struct sk_buff *skb; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 630 | |
| 631 | /* TX failure */ |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame^] | 632 | if (wl->bss_type == BSS_TYPE_AP_BSS) { |
| 633 | for (i = 0; i < AP_MAX_LINKS; i++) |
| 634 | wl1271_tx_reset_link_queues(wl, i); |
| 635 | |
| 636 | wl->last_tx_hlid = 0; |
| 637 | } else { |
| 638 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
| 639 | while ((skb = skb_dequeue(&wl->tx_queue[i]))) { |
| 640 | wl1271_debug(DEBUG_TX, "freeing skb 0x%p", |
| 641 | skb); |
| 642 | ieee80211_tx_status(wl->hw, skb); |
| 643 | } |
Juuso Oikarinen | 6742f55 | 2010-12-13 09:52:37 +0200 | [diff] [blame] | 644 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 645 | } |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame^] | 646 | |
Juuso Oikarinen | 6742f55 | 2010-12-13 09:52:37 +0200 | [diff] [blame] | 647 | wl->tx_queue_count = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 648 | |
Ido Yariv | 2fe33e8 | 2010-10-12 14:49:12 +0200 | [diff] [blame] | 649 | /* |
| 650 | * Make sure the driver is at a consistent state, in case this |
| 651 | * function is called from a context other than interface removal. |
| 652 | */ |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame^] | 653 | wl1271_handle_tx_low_watermark(wl); |
Ido Yariv | 2fe33e8 | 2010-10-12 14:49:12 +0200 | [diff] [blame] | 654 | |
Juuso Oikarinen | be7078c | 2009-10-08 21:56:26 +0300 | [diff] [blame] | 655 | for (i = 0; i < ACX_TX_DESCRIPTORS; i++) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 656 | if (wl->tx_frames[i] != NULL) { |
| 657 | skb = wl->tx_frames[i]; |
Ido Yariv | 25eeb9e | 2010-10-12 16:20:06 +0200 | [diff] [blame] | 658 | wl1271_free_tx_id(wl, i); |
Juuso Oikarinen | 781608c | 2010-05-24 11:18:17 +0300 | [diff] [blame] | 659 | wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb); |
Juuso Oikarinen | 6bbe89d | 2010-04-01 11:38:24 +0300 | [diff] [blame] | 660 | ieee80211_tx_status(wl->hw, skb); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 661 | } |
Juuso Oikarinen | 781608c | 2010-05-24 11:18:17 +0300 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | #define WL1271_TX_FLUSH_TIMEOUT 500000 |
| 665 | |
| 666 | /* caller must *NOT* hold wl->mutex */ |
| 667 | void wl1271_tx_flush(struct wl1271 *wl) |
| 668 | { |
| 669 | unsigned long timeout; |
| 670 | timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT); |
| 671 | |
| 672 | while (!time_after(jiffies, timeout)) { |
| 673 | mutex_lock(&wl->mutex); |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame^] | 674 | wl1271_debug(DEBUG_TX, "flushing tx buffer: %d %d", |
| 675 | wl->tx_frames_cnt, wl->tx_queue_count); |
Juuso Oikarinen | 6742f55 | 2010-12-13 09:52:37 +0200 | [diff] [blame] | 676 | if ((wl->tx_frames_cnt == 0) && (wl->tx_queue_count == 0)) { |
Juuso Oikarinen | 781608c | 2010-05-24 11:18:17 +0300 | [diff] [blame] | 677 | mutex_unlock(&wl->mutex); |
| 678 | return; |
| 679 | } |
| 680 | mutex_unlock(&wl->mutex); |
| 681 | msleep(1); |
| 682 | } |
| 683 | |
| 684 | wl1271_warning("Unable to flush all TX buffers, timed out."); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 685 | } |
Arik Nemtsov | e0fe371 | 2010-10-16 18:19:53 +0200 | [diff] [blame] | 686 | |
| 687 | u32 wl1271_tx_min_rate_get(struct wl1271 *wl) |
| 688 | { |
| 689 | int i; |
| 690 | u32 rate = 0; |
| 691 | |
| 692 | if (!wl->basic_rate_set) { |
| 693 | WARN_ON(1); |
| 694 | wl->basic_rate_set = wl->conf.tx.basic_rate; |
| 695 | } |
| 696 | |
| 697 | for (i = 0; !rate; i++) { |
| 698 | if ((wl->basic_rate_set >> i) & 0x1) |
| 699 | rate = 1 << i; |
| 700 | } |
| 701 | |
| 702 | return rate; |
| 703 | } |