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