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> |
| 26 | |
| 27 | #include "wl1271.h" |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 28 | #include "wl1271_io.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 29 | #include "wl1271_reg.h" |
| 30 | #include "wl1271_ps.h" |
| 31 | #include "wl1271_tx.h" |
| 32 | |
| 33 | static int wl1271_tx_id(struct wl1271 *wl, struct sk_buff *skb) |
| 34 | { |
| 35 | int i; |
Juuso Oikarinen | be7078c | 2009-10-08 21:56:26 +0300 | [diff] [blame] | 36 | for (i = 0; i < ACX_TX_DESCRIPTORS; i++) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 37 | if (wl->tx_frames[i] == NULL) { |
| 38 | wl->tx_frames[i] = skb; |
| 39 | return i; |
| 40 | } |
| 41 | |
| 42 | return -EBUSY; |
| 43 | } |
| 44 | |
| 45 | static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra) |
| 46 | { |
| 47 | struct wl1271_tx_hw_descr *desc; |
| 48 | u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra; |
| 49 | u32 total_blocks, excluded; |
| 50 | int id, ret = -EBUSY; |
| 51 | |
| 52 | /* allocate free identifier for the packet */ |
| 53 | id = wl1271_tx_id(wl, skb); |
| 54 | if (id < 0) |
| 55 | return id; |
| 56 | |
| 57 | /* approximate the number of blocks required for this packet |
| 58 | in the firmware */ |
| 59 | /* FIXME: try to figure out what is done here and make it cleaner */ |
Juuso Oikarinen | 207347e | 2009-10-12 15:08:53 +0300 | [diff] [blame] | 60 | total_blocks = (total_len + 20) >> TX_HW_BLOCK_SHIFT_DIV; |
| 61 | excluded = (total_blocks << 2) + ((total_len + 20) & 0xff) + 34; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 62 | total_blocks += (excluded > 252) ? 2 : 1; |
| 63 | total_blocks += TX_HW_BLOCK_SPARE; |
| 64 | |
| 65 | if (total_blocks <= wl->tx_blocks_available) { |
| 66 | desc = (struct wl1271_tx_hw_descr *)skb_push( |
| 67 | skb, total_len - skb->len); |
| 68 | |
| 69 | desc->extra_mem_blocks = TX_HW_BLOCK_SPARE; |
| 70 | desc->total_mem_blocks = total_blocks; |
| 71 | desc->id = id; |
| 72 | |
| 73 | wl->tx_blocks_available -= total_blocks; |
| 74 | |
| 75 | ret = 0; |
| 76 | |
| 77 | wl1271_debug(DEBUG_TX, |
| 78 | "tx_allocate: size: %d, blocks: %d, id: %d", |
| 79 | total_len, total_blocks, id); |
| 80 | } else |
| 81 | wl->tx_frames[id] = NULL; |
| 82 | |
| 83 | return ret; |
| 84 | } |
| 85 | |
| 86 | static int wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb, |
| 87 | u32 extra, struct ieee80211_tx_info *control) |
| 88 | { |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame^] | 89 | struct timespec ts; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 90 | struct wl1271_tx_hw_descr *desc; |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 91 | int pad, ac; |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame^] | 92 | s64 hosttime; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 93 | u16 tx_attr; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 94 | |
| 95 | desc = (struct wl1271_tx_hw_descr *) skb->data; |
| 96 | |
Juuso Oikarinen | 1e2b797 | 2009-10-08 21:56:20 +0300 | [diff] [blame] | 97 | /* relocate space for security header */ |
| 98 | if (extra) { |
| 99 | void *framestart = skb->data + sizeof(*desc); |
| 100 | u16 fc = *(u16 *)(framestart + extra); |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 101 | int hdrlen = ieee80211_hdrlen(cpu_to_le16(fc)); |
Juuso Oikarinen | 1e2b797 | 2009-10-08 21:56:20 +0300 | [diff] [blame] | 102 | memmove(framestart, framestart + extra, hdrlen); |
| 103 | } |
| 104 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 105 | /* configure packet life time */ |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame^] | 106 | getnstimeofday(&ts); |
| 107 | hosttime = (timespec_to_ns(&ts) >> 10); |
| 108 | desc->start_time = cpu_to_le32(hosttime - wl->time_offset); |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 109 | desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 110 | |
| 111 | /* configure the tx attributes */ |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 112 | tx_attr = wl->session_counter << TX_HW_ATTR_OFST_SESSION_COUNTER; |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 113 | |
| 114 | /* queue */ |
| 115 | ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); |
| 116 | desc->tid = wl1271_tx_ac_to_tid(ac); |
| 117 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 118 | desc->aid = TX_HW_DEFAULT_AID; |
| 119 | desc->reserved = 0; |
| 120 | |
| 121 | /* align the length (and store in terms of words) */ |
| 122 | pad = WL1271_TX_ALIGN(skb->len); |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 123 | desc->length = cpu_to_le16(pad >> 2); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 124 | |
| 125 | /* calculate number of padding bytes */ |
| 126 | pad = pad - skb->len; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 127 | tx_attr |= pad << TX_HW_ATTR_OFST_LAST_WORD_PAD; |
| 128 | |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 129 | /* if the packets are destined for AP (have a STA entry) send them |
| 130 | with AP rate policies, otherwise use default basic rates */ |
| 131 | if (control->control.sta) |
| 132 | tx_attr |= ACX_TX_AP_FULL_RATE << TX_HW_ATTR_OFST_RATE_POLICY; |
| 133 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 134 | desc->tx_attr = cpu_to_le16(tx_attr); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 135 | |
| 136 | wl1271_debug(DEBUG_TX, "tx_fill_hdr: pad: %d", pad); |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | static int wl1271_tx_send_packet(struct wl1271 *wl, struct sk_buff *skb, |
| 141 | struct ieee80211_tx_info *control) |
| 142 | { |
| 143 | |
| 144 | struct wl1271_tx_hw_descr *desc; |
| 145 | int len; |
| 146 | |
| 147 | /* FIXME: This is a workaround for getting non-aligned packets. |
| 148 | This happens at least with EAPOL packets from the user space. |
| 149 | Our DMA requires packets to be aligned on a 4-byte boundary. |
| 150 | */ |
| 151 | if (unlikely((long)skb->data & 0x03)) { |
| 152 | int offset = (4 - (long)skb->data) & 0x03; |
| 153 | wl1271_debug(DEBUG_TX, "skb offset %d", offset); |
| 154 | |
| 155 | /* check whether the current skb can be used */ |
| 156 | if (!skb_cloned(skb) && (skb_tailroom(skb) >= offset)) { |
| 157 | unsigned char *src = skb->data; |
| 158 | |
| 159 | /* align the buffer on a 4-byte boundary */ |
| 160 | skb_reserve(skb, offset); |
| 161 | memmove(skb->data, src, skb->len); |
| 162 | } else { |
| 163 | wl1271_info("No handler, fixme!"); |
| 164 | return -EINVAL; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | len = WL1271_TX_ALIGN(skb->len); |
| 169 | |
| 170 | /* perform a fixed address block write with the packet */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 171 | wl1271_write(wl, WL1271_SLV_MEM_DATA, skb->data, len, true); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 172 | |
| 173 | /* write packet new counter into the write access register */ |
| 174 | wl->tx_packets_count++; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 175 | |
| 176 | desc = (struct wl1271_tx_hw_descr *) skb->data; |
| 177 | wl1271_debug(DEBUG_TX, "tx id %u skb 0x%p payload %u (%u words)", |
| 178 | desc->id, skb, len, desc->length); |
| 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | /* caller must hold wl->mutex */ |
| 184 | static int wl1271_tx_frame(struct wl1271 *wl, struct sk_buff *skb) |
| 185 | { |
| 186 | struct ieee80211_tx_info *info; |
| 187 | u32 extra = 0; |
| 188 | int ret = 0; |
| 189 | u8 idx; |
| 190 | |
| 191 | if (!skb) |
| 192 | return -EINVAL; |
| 193 | |
| 194 | info = IEEE80211_SKB_CB(skb); |
| 195 | |
| 196 | if (info->control.hw_key && |
| 197 | info->control.hw_key->alg == ALG_TKIP) |
| 198 | extra = WL1271_TKIP_IV_SPACE; |
| 199 | |
| 200 | if (info->control.hw_key) { |
| 201 | idx = info->control.hw_key->hw_key_idx; |
| 202 | |
| 203 | /* FIXME: do we have to do this if we're not using WEP? */ |
| 204 | if (unlikely(wl->default_key != idx)) { |
| 205 | ret = wl1271_cmd_set_default_wep_key(wl, idx); |
| 206 | if (ret < 0) |
| 207 | return ret; |
Juuso Oikarinen | ee444cf | 2010-02-18 13:25:50 +0200 | [diff] [blame] | 208 | wl->default_key = idx; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
| 212 | ret = wl1271_tx_allocate(wl, skb, extra); |
| 213 | if (ret < 0) |
| 214 | return ret; |
| 215 | |
| 216 | ret = wl1271_tx_fill_hdr(wl, skb, extra, info); |
| 217 | if (ret < 0) |
| 218 | return ret; |
| 219 | |
| 220 | ret = wl1271_tx_send_packet(wl, skb, info); |
| 221 | if (ret < 0) |
| 222 | return ret; |
| 223 | |
| 224 | return ret; |
| 225 | } |
| 226 | |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 227 | static u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set) |
| 228 | { |
| 229 | struct ieee80211_supported_band *band; |
| 230 | u32 enabled_rates = 0; |
| 231 | int bit; |
| 232 | |
| 233 | band = wl->hw->wiphy->bands[wl->band]; |
| 234 | for (bit = 0; bit < band->n_bitrates; bit++) { |
| 235 | if (rate_set & 0x1) |
| 236 | enabled_rates |= band->bitrates[bit].hw_value; |
| 237 | rate_set >>= 1; |
| 238 | } |
| 239 | |
| 240 | return enabled_rates; |
| 241 | } |
| 242 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 243 | void wl1271_tx_work(struct work_struct *work) |
| 244 | { |
| 245 | struct wl1271 *wl = container_of(work, struct wl1271, tx_work); |
| 246 | struct sk_buff *skb; |
| 247 | bool woken_up = false; |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 248 | u32 sta_rates = 0; |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 249 | u32 prev_tx_packets_count; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 250 | int ret; |
| 251 | |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 252 | /* check if the rates supported by the AP have changed */ |
| 253 | if (unlikely(test_and_clear_bit(WL1271_FLAG_STA_RATES_CHANGED, |
| 254 | &wl->flags))) { |
| 255 | unsigned long flags; |
| 256 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 257 | sta_rates = wl->sta_rate_set; |
| 258 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 259 | } |
| 260 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 261 | mutex_lock(&wl->mutex); |
| 262 | |
| 263 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 264 | goto out; |
| 265 | |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 266 | prev_tx_packets_count = wl->tx_packets_count; |
| 267 | |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 268 | /* if rates have changed, re-configure the rate policy */ |
| 269 | if (unlikely(sta_rates)) { |
| 270 | wl->rate_set = wl1271_tx_enabled_rates_get(wl, sta_rates); |
| 271 | wl1271_acx_rate_policies(wl); |
| 272 | } |
| 273 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 274 | while ((skb = skb_dequeue(&wl->tx_queue))) { |
| 275 | if (!woken_up) { |
| 276 | ret = wl1271_ps_elp_wakeup(wl, false); |
| 277 | if (ret < 0) |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 278 | goto out_ack; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 279 | woken_up = true; |
| 280 | } |
| 281 | |
| 282 | ret = wl1271_tx_frame(wl, skb); |
| 283 | if (ret == -EBUSY) { |
Juuso Oikarinen | 06f7bc7 | 2010-02-22 08:38:33 +0200 | [diff] [blame] | 284 | /* firmware buffer is full, lets stop transmitting. */ |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 285 | skb_queue_head(&wl->tx_queue, skb); |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 286 | goto out_ack; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 287 | } else if (ret < 0) { |
| 288 | dev_kfree_skb(skb); |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 289 | goto out_ack; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 293 | out_ack: |
| 294 | /* interrupt the firmware with the new packets */ |
| 295 | if (prev_tx_packets_count != wl->tx_packets_count) |
| 296 | wl1271_write32(wl, WL1271_HOST_WR_ACCESS, wl->tx_packets_count); |
| 297 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 298 | out: |
| 299 | if (woken_up) |
| 300 | wl1271_ps_elp_sleep(wl); |
| 301 | |
| 302 | mutex_unlock(&wl->mutex); |
| 303 | } |
| 304 | |
| 305 | static void wl1271_tx_complete_packet(struct wl1271 *wl, |
| 306 | struct wl1271_tx_hw_res_descr *result) |
| 307 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 308 | struct ieee80211_tx_info *info; |
| 309 | struct sk_buff *skb; |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 310 | u16 seq; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 311 | int id = result->id; |
| 312 | |
| 313 | /* check for id legality */ |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 314 | if (unlikely(id >= ACX_TX_DESCRIPTORS || wl->tx_frames[id] == NULL)) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 315 | wl1271_warning("TX result illegal id: %d", id); |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | skb = wl->tx_frames[id]; |
| 320 | info = IEEE80211_SKB_CB(skb); |
| 321 | |
| 322 | /* update packet status */ |
| 323 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) { |
| 324 | if (result->status == TX_SUCCESS) |
| 325 | info->flags |= IEEE80211_TX_STAT_ACK; |
| 326 | if (result->status & TX_RETRY_EXCEEDED) { |
| 327 | /* FIXME */ |
| 328 | /* info->status.excessive_retries = 1; */ |
| 329 | wl->stats.excessive_retries++; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | /* FIXME */ |
| 334 | /* info->status.retry_count = result->ack_failures; */ |
| 335 | wl->stats.retry_count += result->ack_failures; |
| 336 | |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 337 | /* update security sequence number */ |
| 338 | seq = wl->tx_security_seq_16 + |
| 339 | (result->lsb_security_sequence_number - |
| 340 | wl->tx_security_last_seq); |
| 341 | wl->tx_security_last_seq = result->lsb_security_sequence_number; |
| 342 | |
| 343 | if (seq < wl->tx_security_seq_16) |
| 344 | wl->tx_security_seq_32++; |
| 345 | wl->tx_security_seq_16 = seq; |
| 346 | |
Juuso Oikarinen | 1e2b797 | 2009-10-08 21:56:20 +0300 | [diff] [blame] | 347 | /* remove private header from packet */ |
| 348 | skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); |
| 349 | |
| 350 | /* remove TKIP header space if present */ |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 351 | if (info->control.hw_key && |
Juuso Oikarinen | 1e2b797 | 2009-10-08 21:56:20 +0300 | [diff] [blame] | 352 | info->control.hw_key->alg == ALG_TKIP) { |
| 353 | int hdrlen = ieee80211_get_hdrlen_from_skb(skb); |
| 354 | memmove(skb->data + WL1271_TKIP_IV_SPACE, skb->data, hdrlen); |
| 355 | skb_pull(skb, WL1271_TKIP_IV_SPACE); |
| 356 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 357 | |
| 358 | wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x" |
| 359 | " status 0x%x", |
| 360 | result->id, skb, result->ack_failures, |
| 361 | result->rate_class_index, result->status); |
| 362 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 363 | /* return the packet to the stack */ |
| 364 | ieee80211_tx_status(wl->hw, skb); |
| 365 | wl->tx_frames[result->id] = NULL; |
| 366 | } |
| 367 | |
| 368 | /* Called upon reception of a TX complete interrupt */ |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 369 | void wl1271_tx_complete(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 370 | { |
| 371 | struct wl1271_acx_mem_map *memmap = |
| 372 | (struct wl1271_acx_mem_map *)wl->target_mem_map; |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 373 | u32 count, fw_counter; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 374 | u32 i; |
| 375 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 376 | /* read the tx results from the chipset */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 377 | wl1271_read(wl, le32_to_cpu(memmap->tx_result), |
| 378 | wl->tx_res_if, sizeof(*wl->tx_res_if), false); |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 379 | fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter); |
| 380 | |
| 381 | /* write host counter to chipset (to ack) */ |
| 382 | wl1271_write32(wl, le32_to_cpu(memmap->tx_result) + |
| 383 | offsetof(struct wl1271_tx_hw_res_if, |
| 384 | tx_result_host_counter), fw_counter); |
| 385 | |
| 386 | count = fw_counter - wl->tx_results_count; |
Juuso Oikarinen | 06f7bc7 | 2010-02-22 08:38:33 +0200 | [diff] [blame] | 387 | wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 388 | |
| 389 | /* verify that the result buffer is not getting overrun */ |
Juuso Oikarinen | ffb591c | 2010-02-22 08:38:31 +0200 | [diff] [blame] | 390 | if (unlikely(count > TX_HW_RESULT_QUEUE_LEN)) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 391 | wl1271_warning("TX result overflow from chipset: %d", count); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 392 | |
| 393 | /* process the results */ |
| 394 | for (i = 0; i < count; i++) { |
| 395 | struct wl1271_tx_hw_res_descr *result; |
| 396 | u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK; |
| 397 | |
| 398 | /* process the packet */ |
| 399 | result = &(wl->tx_res_if->tx_results_queue[offset]); |
| 400 | wl1271_tx_complete_packet(wl, result); |
| 401 | |
| 402 | wl->tx_results_count++; |
| 403 | } |
Juuso Oikarinen | 06f7bc7 | 2010-02-22 08:38:33 +0200 | [diff] [blame] | 404 | |
| 405 | if (test_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags) && |
| 406 | skb_queue_len(&wl->tx_queue) <= WL1271_TX_QUEUE_LOW_WATERMARK) { |
| 407 | unsigned long flags; |
| 408 | |
| 409 | /* firmware buffer has space, restart queues */ |
| 410 | wl1271_debug(DEBUG_TX, "tx_complete: waking queues"); |
| 411 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 412 | ieee80211_wake_queues(wl->hw); |
| 413 | clear_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags); |
| 414 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 415 | ieee80211_queue_work(wl->hw, &wl->tx_work); |
| 416 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /* caller must hold wl->mutex */ |
| 420 | void wl1271_tx_flush(struct wl1271 *wl) |
| 421 | { |
| 422 | int i; |
| 423 | struct sk_buff *skb; |
| 424 | struct ieee80211_tx_info *info; |
| 425 | |
| 426 | /* TX failure */ |
| 427 | /* control->flags = 0; FIXME */ |
| 428 | |
| 429 | while ((skb = skb_dequeue(&wl->tx_queue))) { |
| 430 | info = IEEE80211_SKB_CB(skb); |
| 431 | |
| 432 | wl1271_debug(DEBUG_TX, "flushing skb 0x%p", skb); |
| 433 | |
| 434 | if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS)) |
| 435 | continue; |
| 436 | |
| 437 | ieee80211_tx_status(wl->hw, skb); |
| 438 | } |
| 439 | |
Juuso Oikarinen | be7078c | 2009-10-08 21:56:26 +0300 | [diff] [blame] | 440 | for (i = 0; i < ACX_TX_DESCRIPTORS; i++) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 441 | if (wl->tx_frames[i] != NULL) { |
| 442 | skb = wl->tx_frames[i]; |
| 443 | info = IEEE80211_SKB_CB(skb); |
| 444 | |
| 445 | if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS)) |
| 446 | continue; |
| 447 | |
| 448 | ieee80211_tx_status(wl->hw, skb); |
| 449 | wl->tx_frames[i] = NULL; |
| 450 | } |
| 451 | } |