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