Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1 | /* |
| 2 | Copyright (C) 2004 - 2008 rt2x00 SourceForge Project |
| 3 | <http://rt2x00.serialmonkey.com> |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the |
| 17 | Free Software Foundation, Inc., |
| 18 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | Module: rt2x00lib |
| 23 | Abstract: rt2x00 queue specific routines. |
| 24 | */ |
| 25 | |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/module.h> |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 28 | #include <linux/dma-mapping.h> |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 29 | |
| 30 | #include "rt2x00.h" |
| 31 | #include "rt2x00lib.h" |
| 32 | |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 33 | struct sk_buff *rt2x00queue_alloc_rxskb(struct rt2x00_dev *rt2x00dev, |
| 34 | struct queue_entry *entry) |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 35 | { |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 36 | struct sk_buff *skb; |
| 37 | struct skb_frame_desc *skbdesc; |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 38 | unsigned int frame_size; |
| 39 | unsigned int head_size = 0; |
| 40 | unsigned int tail_size = 0; |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * The frame size includes descriptor size, because the |
| 44 | * hardware directly receive the frame into the skbuffer. |
| 45 | */ |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 46 | frame_size = entry->queue->data_size + entry->queue->desc_size; |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 47 | |
| 48 | /* |
Ivo van Doorn | ff35239 | 2008-07-04 14:56:07 +0200 | [diff] [blame] | 49 | * The payload should be aligned to a 4-byte boundary, |
| 50 | * this means we need at least 3 bytes for moving the frame |
| 51 | * into the correct offset. |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 52 | */ |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 53 | head_size = 4; |
| 54 | |
| 55 | /* |
| 56 | * For IV/EIV/ICV assembly we must make sure there is |
| 57 | * at least 8 bytes bytes available in headroom for IV/EIV |
| 58 | * and 4 bytes for ICV data as tailroon. |
| 59 | */ |
| 60 | #ifdef CONFIG_RT2X00_LIB_CRYPTO |
| 61 | if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) { |
| 62 | head_size += 8; |
| 63 | tail_size += 4; |
| 64 | } |
| 65 | #endif /* CONFIG_RT2X00_LIB_CRYPTO */ |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * Allocate skbuffer. |
| 69 | */ |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 70 | skb = dev_alloc_skb(frame_size + head_size + tail_size); |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 71 | if (!skb) |
| 72 | return NULL; |
| 73 | |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 74 | /* |
| 75 | * Make sure we not have a frame with the requested bytes |
| 76 | * available in the head and tail. |
| 77 | */ |
| 78 | skb_reserve(skb, head_size); |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 79 | skb_put(skb, frame_size); |
| 80 | |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 81 | /* |
| 82 | * Populate skbdesc. |
| 83 | */ |
| 84 | skbdesc = get_skb_frame_desc(skb); |
| 85 | memset(skbdesc, 0, sizeof(*skbdesc)); |
| 86 | skbdesc->entry = entry; |
| 87 | |
| 88 | if (test_bit(DRIVER_REQUIRE_DMA, &rt2x00dev->flags)) { |
| 89 | skbdesc->skb_dma = dma_map_single(rt2x00dev->dev, |
| 90 | skb->data, |
| 91 | skb->len, |
| 92 | DMA_FROM_DEVICE); |
| 93 | skbdesc->flags |= SKBDESC_DMA_MAPPED_RX; |
| 94 | } |
| 95 | |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 96 | return skb; |
| 97 | } |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 98 | |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 99 | void rt2x00queue_map_txskb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb) |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 100 | { |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 101 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb); |
| 102 | |
| 103 | skbdesc->skb_dma = dma_map_single(rt2x00dev->dev, skb->data, skb->len, |
| 104 | DMA_TO_DEVICE); |
| 105 | skbdesc->flags |= SKBDESC_DMA_MAPPED_TX; |
| 106 | } |
| 107 | EXPORT_SYMBOL_GPL(rt2x00queue_map_txskb); |
| 108 | |
| 109 | void rt2x00queue_unmap_skb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb) |
| 110 | { |
| 111 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb); |
| 112 | |
| 113 | if (skbdesc->flags & SKBDESC_DMA_MAPPED_RX) { |
| 114 | dma_unmap_single(rt2x00dev->dev, skbdesc->skb_dma, skb->len, |
| 115 | DMA_FROM_DEVICE); |
| 116 | skbdesc->flags &= ~SKBDESC_DMA_MAPPED_RX; |
| 117 | } |
| 118 | |
| 119 | if (skbdesc->flags & SKBDESC_DMA_MAPPED_TX) { |
| 120 | dma_unmap_single(rt2x00dev->dev, skbdesc->skb_dma, skb->len, |
| 121 | DMA_TO_DEVICE); |
| 122 | skbdesc->flags &= ~SKBDESC_DMA_MAPPED_TX; |
| 123 | } |
| 124 | } |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 125 | |
| 126 | void rt2x00queue_free_skb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb) |
| 127 | { |
Ivo van Doorn | 9a61319 | 2008-07-05 15:11:57 +0200 | [diff] [blame] | 128 | if (!skb) |
| 129 | return; |
| 130 | |
Ivo van Doorn | 61243d8 | 2008-06-20 22:10:53 +0200 | [diff] [blame] | 131 | rt2x00queue_unmap_skb(rt2x00dev, skb); |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 132 | dev_kfree_skb_any(skb); |
| 133 | } |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 134 | |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 135 | static void rt2x00queue_create_tx_descriptor(struct queue_entry *entry, |
| 136 | struct txentry_desc *txdesc) |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 137 | { |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 138 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 139 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb); |
Ivo van Doorn | 5adf6d6 | 2008-07-20 18:03:38 +0200 | [diff] [blame] | 140 | struct rt2x00_intf *intf = vif_to_intf(tx_info->control.vif); |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 141 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)entry->skb->data; |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 142 | struct ieee80211_rate *rate = |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 143 | ieee80211_get_tx_rate(rt2x00dev->hw, tx_info); |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 144 | const struct rt2x00_rate *hwrate; |
| 145 | unsigned int data_length; |
| 146 | unsigned int duration; |
| 147 | unsigned int residual; |
Ivo van Doorn | d4764b2 | 2008-07-28 10:21:16 +0200 | [diff] [blame] | 148 | unsigned long irqflags; |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 149 | |
| 150 | memset(txdesc, 0, sizeof(*txdesc)); |
| 151 | |
| 152 | /* |
| 153 | * Initialize information from queue |
| 154 | */ |
| 155 | txdesc->queue = entry->queue->qid; |
| 156 | txdesc->cw_min = entry->queue->cw_min; |
| 157 | txdesc->cw_max = entry->queue->cw_max; |
| 158 | txdesc->aifs = entry->queue->aifs; |
| 159 | |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 160 | /* Data length + CRC + IV/EIV/ICV/MMIC (when using encryption) */ |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 161 | data_length = entry->skb->len + 4; |
| 162 | |
| 163 | /* |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 164 | * Check whether this frame is to be acked. |
| 165 | */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 166 | if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK)) |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 167 | __set_bit(ENTRY_TXD_ACK, &txdesc->flags); |
| 168 | |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 169 | #ifdef CONFIG_RT2X00_LIB_CRYPTO |
| 170 | if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags) && |
| 171 | !entry->skb->do_not_encrypt) { |
| 172 | struct ieee80211_key_conf *hw_key = tx_info->control.hw_key; |
| 173 | |
| 174 | __set_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags); |
| 175 | |
| 176 | txdesc->cipher = rt2x00crypto_key_to_cipher(hw_key); |
| 177 | |
| 178 | if (hw_key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 179 | __set_bit(ENTRY_TXD_ENCRYPT_PAIRWISE, &txdesc->flags); |
| 180 | |
| 181 | txdesc->key_idx = hw_key->hw_key_idx; |
| 182 | txdesc->iv_offset = ieee80211_get_hdrlen_from_skb(entry->skb); |
| 183 | |
| 184 | /* |
| 185 | * Extend frame length to include all encryption overhead |
| 186 | * that will be added by the hardware. |
| 187 | */ |
| 188 | data_length += rt2x00crypto_tx_overhead(tx_info); |
| 189 | |
| 190 | if (!(hw_key->flags & IEEE80211_KEY_FLAG_GENERATE_IV)) |
| 191 | __set_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags); |
| 192 | |
| 193 | if (!(hw_key->flags & IEEE80211_KEY_FLAG_GENERATE_MMIC)) |
| 194 | __set_bit(ENTRY_TXD_ENCRYPT_MMIC, &txdesc->flags); |
| 195 | } |
| 196 | #endif /* CONFIG_RT2X00_LIB_CRYPTO */ |
| 197 | |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 198 | /* |
| 199 | * Check if this is a RTS/CTS frame |
| 200 | */ |
Ivo van Doorn | ac10446 | 2008-06-16 19:54:57 +0200 | [diff] [blame] | 201 | if (ieee80211_is_rts(hdr->frame_control) || |
| 202 | ieee80211_is_cts(hdr->frame_control)) { |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 203 | __set_bit(ENTRY_TXD_BURST, &txdesc->flags); |
Ivo van Doorn | ac10446 | 2008-06-16 19:54:57 +0200 | [diff] [blame] | 204 | if (ieee80211_is_rts(hdr->frame_control)) |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 205 | __set_bit(ENTRY_TXD_RTS_FRAME, &txdesc->flags); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 206 | else |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 207 | __set_bit(ENTRY_TXD_CTS_FRAME, &txdesc->flags); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 208 | if (tx_info->control.rts_cts_rate_idx >= 0) |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 209 | rate = |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 210 | ieee80211_get_rts_cts_rate(rt2x00dev->hw, tx_info); |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /* |
| 214 | * Determine retry information. |
| 215 | */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 216 | txdesc->retry_limit = tx_info->control.retry_limit; |
| 217 | if (tx_info->flags & IEEE80211_TX_CTL_LONG_RETRY_LIMIT) |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 218 | __set_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags); |
| 219 | |
| 220 | /* |
| 221 | * Check if more fragments are pending |
| 222 | */ |
Harvey Harrison | 8b7b1e0 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 223 | if (ieee80211_has_morefrags(hdr->frame_control)) { |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 224 | __set_bit(ENTRY_TXD_BURST, &txdesc->flags); |
| 225 | __set_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags); |
| 226 | } |
| 227 | |
| 228 | /* |
| 229 | * Beacons and probe responses require the tsf timestamp |
| 230 | * to be inserted into the frame. |
| 231 | */ |
Ivo van Doorn | ac10446 | 2008-06-16 19:54:57 +0200 | [diff] [blame] | 232 | if (ieee80211_is_beacon(hdr->frame_control) || |
| 233 | ieee80211_is_probe_resp(hdr->frame_control)) |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 234 | __set_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags); |
| 235 | |
| 236 | /* |
| 237 | * Determine with what IFS priority this frame should be send. |
| 238 | * Set ifs to IFS_SIFS when the this is not the first fragment, |
| 239 | * or this fragment came after RTS/CTS. |
| 240 | */ |
| 241 | if (test_bit(ENTRY_TXD_RTS_FRAME, &txdesc->flags)) { |
| 242 | txdesc->ifs = IFS_SIFS; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 243 | } else if (tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) { |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 244 | __set_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags); |
| 245 | txdesc->ifs = IFS_BACKOFF; |
| 246 | } else { |
| 247 | txdesc->ifs = IFS_SIFS; |
| 248 | } |
| 249 | |
| 250 | /* |
Ivo van Doorn | 5adf6d6 | 2008-07-20 18:03:38 +0200 | [diff] [blame] | 251 | * Hardware should insert sequence counter. |
| 252 | * FIXME: We insert a software sequence counter first for |
| 253 | * hardware that doesn't support hardware sequence counting. |
| 254 | * |
| 255 | * This is wrong because beacons are not getting sequence |
| 256 | * numbers assigned properly. |
| 257 | * |
| 258 | * A secondary problem exists for drivers that cannot toggle |
| 259 | * sequence counting per-frame, since those will override the |
| 260 | * sequence counter given by mac80211. |
| 261 | */ |
| 262 | if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
Ivo van Doorn | d4764b2 | 2008-07-28 10:21:16 +0200 | [diff] [blame] | 263 | spin_lock_irqsave(&intf->seqlock, irqflags); |
Ivo van Doorn | 5adf6d6 | 2008-07-20 18:03:38 +0200 | [diff] [blame] | 264 | |
| 265 | if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags)) |
| 266 | intf->seqno += 0x10; |
| 267 | hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); |
| 268 | hdr->seq_ctrl |= cpu_to_le16(intf->seqno); |
| 269 | |
Ivo van Doorn | d4764b2 | 2008-07-28 10:21:16 +0200 | [diff] [blame] | 270 | spin_unlock_irqrestore(&intf->seqlock, irqflags); |
Ivo van Doorn | 5adf6d6 | 2008-07-20 18:03:38 +0200 | [diff] [blame] | 271 | |
| 272 | __set_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags); |
| 273 | } |
| 274 | |
| 275 | /* |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 276 | * PLCP setup |
| 277 | * Length calculation depends on OFDM/CCK rate. |
| 278 | */ |
| 279 | hwrate = rt2x00_get_rate(rate->hw_value); |
| 280 | txdesc->signal = hwrate->plcp; |
| 281 | txdesc->service = 0x04; |
| 282 | |
| 283 | if (hwrate->flags & DEV_RATE_OFDM) { |
| 284 | __set_bit(ENTRY_TXD_OFDM_RATE, &txdesc->flags); |
| 285 | |
| 286 | txdesc->length_high = (data_length >> 6) & 0x3f; |
| 287 | txdesc->length_low = data_length & 0x3f; |
| 288 | } else { |
| 289 | /* |
| 290 | * Convert length to microseconds. |
| 291 | */ |
| 292 | residual = get_duration_res(data_length, hwrate->bitrate); |
| 293 | duration = get_duration(data_length, hwrate->bitrate); |
| 294 | |
| 295 | if (residual != 0) { |
| 296 | duration++; |
| 297 | |
| 298 | /* |
| 299 | * Check if we need to set the Length Extension |
| 300 | */ |
| 301 | if (hwrate->bitrate == 110 && residual <= 30) |
| 302 | txdesc->service |= 0x80; |
| 303 | } |
| 304 | |
| 305 | txdesc->length_high = (duration >> 8) & 0xff; |
| 306 | txdesc->length_low = duration & 0xff; |
| 307 | |
| 308 | /* |
| 309 | * When preamble is enabled we should set the |
| 310 | * preamble bit for the signal. |
| 311 | */ |
| 312 | if (rt2x00_get_rate_preamble(rate->hw_value)) |
| 313 | txdesc->signal |= 0x08; |
| 314 | } |
| 315 | } |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 316 | |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 317 | static void rt2x00queue_write_tx_descriptor(struct queue_entry *entry, |
| 318 | struct txentry_desc *txdesc) |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 319 | { |
Ivo van Doorn | b869767 | 2008-06-06 22:53:14 +0200 | [diff] [blame] | 320 | struct data_queue *queue = entry->queue; |
| 321 | struct rt2x00_dev *rt2x00dev = queue->rt2x00dev; |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 322 | |
| 323 | rt2x00dev->ops->lib->write_tx_desc(rt2x00dev, entry->skb, txdesc); |
| 324 | |
| 325 | /* |
| 326 | * All processing on the frame has been completed, this means |
| 327 | * it is now ready to be dumped to userspace through debugfs. |
| 328 | */ |
| 329 | rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_TX, entry->skb); |
| 330 | |
| 331 | /* |
Ivo van Doorn | b869767 | 2008-06-06 22:53:14 +0200 | [diff] [blame] | 332 | * Check if we need to kick the queue, there are however a few rules |
| 333 | * 1) Don't kick beacon queue |
| 334 | * 2) Don't kick unless this is the last in frame in a burst. |
| 335 | * When the burst flag is set, this frame is always followed |
| 336 | * by another frame which in some way are related to eachother. |
| 337 | * This is true for fragments, RTS or CTS-to-self frames. |
| 338 | * 3) Rule 2 can be broken when the available entries |
| 339 | * in the queue are less then a certain threshold. |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 340 | */ |
Ivo van Doorn | b869767 | 2008-06-06 22:53:14 +0200 | [diff] [blame] | 341 | if (entry->queue->qid == QID_BEACON) |
| 342 | return; |
| 343 | |
| 344 | if (rt2x00queue_threshold(queue) || |
| 345 | !test_bit(ENTRY_TXD_BURST, &txdesc->flags)) |
| 346 | rt2x00dev->ops->lib->kick_tx_queue(rt2x00dev, queue->qid); |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 347 | } |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 348 | |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 349 | int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb) |
| 350 | { |
| 351 | struct queue_entry *entry = rt2x00queue_get_entry(queue, Q_INDEX); |
| 352 | struct txentry_desc txdesc; |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 353 | struct skb_frame_desc *skbdesc; |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 354 | unsigned int iv_len = IEEE80211_SKB_CB(skb)->control.iv_len; |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 355 | |
| 356 | if (unlikely(rt2x00queue_full(queue))) |
| 357 | return -EINVAL; |
| 358 | |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame^] | 359 | if (test_and_set_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags)) { |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 360 | ERROR(queue->rt2x00dev, |
| 361 | "Arrived at non-free entry in the non-full queue %d.\n" |
| 362 | "Please file bug report to %s.\n", |
| 363 | queue->qid, DRV_PROJECT); |
| 364 | return -EINVAL; |
| 365 | } |
| 366 | |
| 367 | /* |
| 368 | * Copy all TX descriptor information into txdesc, |
| 369 | * after that we are free to use the skb->cb array |
| 370 | * for our information. |
| 371 | */ |
| 372 | entry->skb = skb; |
| 373 | rt2x00queue_create_tx_descriptor(entry, &txdesc); |
| 374 | |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 375 | /* |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 376 | * All information is retreived from the skb->cb array, |
| 377 | * now we should claim ownership of the driver part of that |
| 378 | * array. |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 379 | */ |
| 380 | skbdesc = get_skb_frame_desc(entry->skb); |
| 381 | memset(skbdesc, 0, sizeof(*skbdesc)); |
| 382 | skbdesc->entry = entry; |
| 383 | |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 384 | /* |
| 385 | * When hardware encryption is supported, and this frame |
| 386 | * is to be encrypted, we should strip the IV/EIV data from |
| 387 | * the frame so we can provide it to the driver seperately. |
| 388 | */ |
| 389 | if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc.flags) && |
| 390 | !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc.flags)) |
| 391 | rt2x00crypto_tx_remove_iv(skb, iv_len); |
| 392 | |
| 393 | /* |
| 394 | * It could be possible that the queue was corrupted and this |
| 395 | * call failed. Just drop the frame, we cannot rollback and pass |
| 396 | * the frame to mac80211 because the skb->cb has now been tainted. |
| 397 | */ |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 398 | if (unlikely(queue->rt2x00dev->ops->lib->write_tx_data(entry))) { |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame^] | 399 | clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags); |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 400 | dev_kfree_skb_any(entry->skb); |
| 401 | entry->skb = NULL; |
| 402 | return 0; |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 403 | } |
| 404 | |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 405 | if (test_bit(DRIVER_REQUIRE_DMA, &queue->rt2x00dev->flags)) |
| 406 | rt2x00queue_map_txskb(queue->rt2x00dev, skb); |
| 407 | |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame^] | 408 | set_bit(ENTRY_DATA_PENDING, &entry->flags); |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 409 | |
| 410 | rt2x00queue_index_inc(queue, Q_INDEX); |
| 411 | rt2x00queue_write_tx_descriptor(entry, &txdesc); |
| 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 416 | int rt2x00queue_update_beacon(struct rt2x00_dev *rt2x00dev, |
| 417 | struct ieee80211_vif *vif) |
| 418 | { |
| 419 | struct rt2x00_intf *intf = vif_to_intf(vif); |
| 420 | struct skb_frame_desc *skbdesc; |
| 421 | struct txentry_desc txdesc; |
| 422 | __le32 desc[16]; |
| 423 | |
| 424 | if (unlikely(!intf->beacon)) |
| 425 | return -ENOBUFS; |
| 426 | |
| 427 | intf->beacon->skb = ieee80211_beacon_get(rt2x00dev->hw, vif); |
| 428 | if (!intf->beacon->skb) |
| 429 | return -ENOMEM; |
| 430 | |
| 431 | /* |
| 432 | * Copy all TX descriptor information into txdesc, |
| 433 | * after that we are free to use the skb->cb array |
| 434 | * for our information. |
| 435 | */ |
| 436 | rt2x00queue_create_tx_descriptor(intf->beacon, &txdesc); |
| 437 | |
| 438 | /* |
| 439 | * For the descriptor we use a local array from where the |
| 440 | * driver can move it to the correct location required for |
| 441 | * the hardware. |
| 442 | */ |
| 443 | memset(desc, 0, sizeof(desc)); |
| 444 | |
| 445 | /* |
| 446 | * Fill in skb descriptor |
| 447 | */ |
| 448 | skbdesc = get_skb_frame_desc(intf->beacon->skb); |
| 449 | memset(skbdesc, 0, sizeof(*skbdesc)); |
| 450 | skbdesc->desc = desc; |
| 451 | skbdesc->desc_len = intf->beacon->queue->desc_size; |
| 452 | skbdesc->entry = intf->beacon; |
| 453 | |
| 454 | /* |
| 455 | * Write TX descriptor into reserved room in front of the beacon. |
| 456 | */ |
| 457 | rt2x00queue_write_tx_descriptor(intf->beacon, &txdesc); |
| 458 | |
| 459 | /* |
| 460 | * Send beacon to hardware. |
| 461 | * Also enable beacon generation, which might have been disabled |
| 462 | * by the driver during the config_beacon() callback function. |
| 463 | */ |
| 464 | rt2x00dev->ops->lib->write_beacon(intf->beacon); |
| 465 | rt2x00dev->ops->lib->kick_tx_queue(rt2x00dev, QID_BEACON); |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 470 | struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev, |
Ivo van Doorn | e58c6ac | 2008-04-21 19:00:47 +0200 | [diff] [blame] | 471 | const enum data_queue_qid queue) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 472 | { |
| 473 | int atim = test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags); |
| 474 | |
Gertjan van Wingerde | 61448f8 | 2008-05-10 13:43:33 +0200 | [diff] [blame] | 475 | if (queue < rt2x00dev->ops->tx_queues && rt2x00dev->tx) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 476 | return &rt2x00dev->tx[queue]; |
| 477 | |
| 478 | if (!rt2x00dev->bcn) |
| 479 | return NULL; |
| 480 | |
Ivo van Doorn | e58c6ac | 2008-04-21 19:00:47 +0200 | [diff] [blame] | 481 | if (queue == QID_BEACON) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 482 | return &rt2x00dev->bcn[0]; |
Ivo van Doorn | e58c6ac | 2008-04-21 19:00:47 +0200 | [diff] [blame] | 483 | else if (queue == QID_ATIM && atim) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 484 | return &rt2x00dev->bcn[1]; |
| 485 | |
| 486 | return NULL; |
| 487 | } |
| 488 | EXPORT_SYMBOL_GPL(rt2x00queue_get_queue); |
| 489 | |
| 490 | struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue, |
| 491 | enum queue_index index) |
| 492 | { |
| 493 | struct queue_entry *entry; |
Ivo van Doorn | 5f46c4d | 2008-03-09 22:44:30 +0100 | [diff] [blame] | 494 | unsigned long irqflags; |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 495 | |
| 496 | if (unlikely(index >= Q_INDEX_MAX)) { |
| 497 | ERROR(queue->rt2x00dev, |
| 498 | "Entry requested from invalid index type (%d)\n", index); |
| 499 | return NULL; |
| 500 | } |
| 501 | |
Ivo van Doorn | 5f46c4d | 2008-03-09 22:44:30 +0100 | [diff] [blame] | 502 | spin_lock_irqsave(&queue->lock, irqflags); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 503 | |
| 504 | entry = &queue->entries[queue->index[index]]; |
| 505 | |
Ivo van Doorn | 5f46c4d | 2008-03-09 22:44:30 +0100 | [diff] [blame] | 506 | spin_unlock_irqrestore(&queue->lock, irqflags); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 507 | |
| 508 | return entry; |
| 509 | } |
| 510 | EXPORT_SYMBOL_GPL(rt2x00queue_get_entry); |
| 511 | |
| 512 | void rt2x00queue_index_inc(struct data_queue *queue, enum queue_index index) |
| 513 | { |
Ivo van Doorn | 5f46c4d | 2008-03-09 22:44:30 +0100 | [diff] [blame] | 514 | unsigned long irqflags; |
| 515 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 516 | if (unlikely(index >= Q_INDEX_MAX)) { |
| 517 | ERROR(queue->rt2x00dev, |
| 518 | "Index change on invalid index type (%d)\n", index); |
| 519 | return; |
| 520 | } |
| 521 | |
Ivo van Doorn | 5f46c4d | 2008-03-09 22:44:30 +0100 | [diff] [blame] | 522 | spin_lock_irqsave(&queue->lock, irqflags); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 523 | |
| 524 | queue->index[index]++; |
| 525 | if (queue->index[index] >= queue->limit) |
| 526 | queue->index[index] = 0; |
| 527 | |
Ivo van Doorn | 10b6b80 | 2008-02-03 15:55:21 +0100 | [diff] [blame] | 528 | if (index == Q_INDEX) { |
| 529 | queue->length++; |
| 530 | } else if (index == Q_INDEX_DONE) { |
| 531 | queue->length--; |
| 532 | queue->count ++; |
| 533 | } |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 534 | |
Ivo van Doorn | 5f46c4d | 2008-03-09 22:44:30 +0100 | [diff] [blame] | 535 | spin_unlock_irqrestore(&queue->lock, irqflags); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 536 | } |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 537 | |
| 538 | static void rt2x00queue_reset(struct data_queue *queue) |
| 539 | { |
Ivo van Doorn | 5f46c4d | 2008-03-09 22:44:30 +0100 | [diff] [blame] | 540 | unsigned long irqflags; |
| 541 | |
| 542 | spin_lock_irqsave(&queue->lock, irqflags); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 543 | |
| 544 | queue->count = 0; |
| 545 | queue->length = 0; |
| 546 | memset(queue->index, 0, sizeof(queue->index)); |
| 547 | |
Ivo van Doorn | 5f46c4d | 2008-03-09 22:44:30 +0100 | [diff] [blame] | 548 | spin_unlock_irqrestore(&queue->lock, irqflags); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | void rt2x00queue_init_rx(struct rt2x00_dev *rt2x00dev) |
| 552 | { |
| 553 | struct data_queue *queue = rt2x00dev->rx; |
| 554 | unsigned int i; |
| 555 | |
| 556 | rt2x00queue_reset(queue); |
| 557 | |
| 558 | if (!rt2x00dev->ops->lib->init_rxentry) |
| 559 | return; |
| 560 | |
Ivo van Doorn | 9c0ab71 | 2008-07-21 19:06:02 +0200 | [diff] [blame] | 561 | for (i = 0; i < queue->limit; i++) { |
| 562 | queue->entries[i].flags = 0; |
| 563 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 564 | rt2x00dev->ops->lib->init_rxentry(rt2x00dev, |
| 565 | &queue->entries[i]); |
Ivo van Doorn | 9c0ab71 | 2008-07-21 19:06:02 +0200 | [diff] [blame] | 566 | } |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | void rt2x00queue_init_tx(struct rt2x00_dev *rt2x00dev) |
| 570 | { |
| 571 | struct data_queue *queue; |
| 572 | unsigned int i; |
| 573 | |
| 574 | txall_queue_for_each(rt2x00dev, queue) { |
| 575 | rt2x00queue_reset(queue); |
| 576 | |
| 577 | if (!rt2x00dev->ops->lib->init_txentry) |
| 578 | continue; |
| 579 | |
Ivo van Doorn | 9c0ab71 | 2008-07-21 19:06:02 +0200 | [diff] [blame] | 580 | for (i = 0; i < queue->limit; i++) { |
| 581 | queue->entries[i].flags = 0; |
| 582 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 583 | rt2x00dev->ops->lib->init_txentry(rt2x00dev, |
| 584 | &queue->entries[i]); |
Ivo van Doorn | 9c0ab71 | 2008-07-21 19:06:02 +0200 | [diff] [blame] | 585 | } |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | |
| 589 | static int rt2x00queue_alloc_entries(struct data_queue *queue, |
| 590 | const struct data_queue_desc *qdesc) |
| 591 | { |
| 592 | struct queue_entry *entries; |
| 593 | unsigned int entry_size; |
| 594 | unsigned int i; |
| 595 | |
| 596 | rt2x00queue_reset(queue); |
| 597 | |
| 598 | queue->limit = qdesc->entry_num; |
Ivo van Doorn | b869767 | 2008-06-06 22:53:14 +0200 | [diff] [blame] | 599 | queue->threshold = DIV_ROUND_UP(qdesc->entry_num, 10); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 600 | queue->data_size = qdesc->data_size; |
| 601 | queue->desc_size = qdesc->desc_size; |
| 602 | |
| 603 | /* |
| 604 | * Allocate all queue entries. |
| 605 | */ |
| 606 | entry_size = sizeof(*entries) + qdesc->priv_size; |
| 607 | entries = kzalloc(queue->limit * entry_size, GFP_KERNEL); |
| 608 | if (!entries) |
| 609 | return -ENOMEM; |
| 610 | |
| 611 | #define QUEUE_ENTRY_PRIV_OFFSET(__base, __index, __limit, __esize, __psize) \ |
Adam Baker | 231be4e | 2008-02-10 22:48:19 +0100 | [diff] [blame] | 612 | ( ((char *)(__base)) + ((__limit) * (__esize)) + \ |
| 613 | ((__index) * (__psize)) ) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 614 | |
| 615 | for (i = 0; i < queue->limit; i++) { |
| 616 | entries[i].flags = 0; |
| 617 | entries[i].queue = queue; |
| 618 | entries[i].skb = NULL; |
| 619 | entries[i].entry_idx = i; |
| 620 | entries[i].priv_data = |
| 621 | QUEUE_ENTRY_PRIV_OFFSET(entries, i, queue->limit, |
| 622 | sizeof(*entries), qdesc->priv_size); |
| 623 | } |
| 624 | |
| 625 | #undef QUEUE_ENTRY_PRIV_OFFSET |
| 626 | |
| 627 | queue->entries = entries; |
| 628 | |
| 629 | return 0; |
| 630 | } |
| 631 | |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 632 | static void rt2x00queue_free_skbs(struct rt2x00_dev *rt2x00dev, |
| 633 | struct data_queue *queue) |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 634 | { |
| 635 | unsigned int i; |
| 636 | |
| 637 | if (!queue->entries) |
| 638 | return; |
| 639 | |
| 640 | for (i = 0; i < queue->limit; i++) { |
| 641 | if (queue->entries[i].skb) |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 642 | rt2x00queue_free_skb(rt2x00dev, queue->entries[i].skb); |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 646 | static int rt2x00queue_alloc_rxskbs(struct rt2x00_dev *rt2x00dev, |
| 647 | struct data_queue *queue) |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 648 | { |
| 649 | unsigned int i; |
| 650 | struct sk_buff *skb; |
| 651 | |
| 652 | for (i = 0; i < queue->limit; i++) { |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 653 | skb = rt2x00queue_alloc_rxskb(rt2x00dev, &queue->entries[i]); |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 654 | if (!skb) |
Ivo van Doorn | 61243d8 | 2008-06-20 22:10:53 +0200 | [diff] [blame] | 655 | return -ENOMEM; |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 656 | queue->entries[i].skb = skb; |
| 657 | } |
| 658 | |
| 659 | return 0; |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 660 | } |
| 661 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 662 | int rt2x00queue_initialize(struct rt2x00_dev *rt2x00dev) |
| 663 | { |
| 664 | struct data_queue *queue; |
| 665 | int status; |
| 666 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 667 | status = rt2x00queue_alloc_entries(rt2x00dev->rx, rt2x00dev->ops->rx); |
| 668 | if (status) |
| 669 | goto exit; |
| 670 | |
| 671 | tx_queue_for_each(rt2x00dev, queue) { |
| 672 | status = rt2x00queue_alloc_entries(queue, rt2x00dev->ops->tx); |
| 673 | if (status) |
| 674 | goto exit; |
| 675 | } |
| 676 | |
| 677 | status = rt2x00queue_alloc_entries(rt2x00dev->bcn, rt2x00dev->ops->bcn); |
| 678 | if (status) |
| 679 | goto exit; |
| 680 | |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 681 | if (test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags)) { |
| 682 | status = rt2x00queue_alloc_entries(&rt2x00dev->bcn[1], |
| 683 | rt2x00dev->ops->atim); |
| 684 | if (status) |
| 685 | goto exit; |
| 686 | } |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 687 | |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 688 | status = rt2x00queue_alloc_rxskbs(rt2x00dev, rt2x00dev->rx); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 689 | if (status) |
| 690 | goto exit; |
| 691 | |
| 692 | return 0; |
| 693 | |
| 694 | exit: |
| 695 | ERROR(rt2x00dev, "Queue entries allocation failed.\n"); |
| 696 | |
| 697 | rt2x00queue_uninitialize(rt2x00dev); |
| 698 | |
| 699 | return status; |
| 700 | } |
| 701 | |
| 702 | void rt2x00queue_uninitialize(struct rt2x00_dev *rt2x00dev) |
| 703 | { |
| 704 | struct data_queue *queue; |
| 705 | |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 706 | rt2x00queue_free_skbs(rt2x00dev, rt2x00dev->rx); |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 707 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 708 | queue_for_each(rt2x00dev, queue) { |
| 709 | kfree(queue->entries); |
| 710 | queue->entries = NULL; |
| 711 | } |
| 712 | } |
| 713 | |
Ivo van Doorn | 8f53927 | 2008-02-10 22:51:41 +0100 | [diff] [blame] | 714 | static void rt2x00queue_init(struct rt2x00_dev *rt2x00dev, |
| 715 | struct data_queue *queue, enum data_queue_qid qid) |
| 716 | { |
| 717 | spin_lock_init(&queue->lock); |
| 718 | |
| 719 | queue->rt2x00dev = rt2x00dev; |
| 720 | queue->qid = qid; |
| 721 | queue->aifs = 2; |
| 722 | queue->cw_min = 5; |
| 723 | queue->cw_max = 10; |
| 724 | } |
| 725 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 726 | int rt2x00queue_allocate(struct rt2x00_dev *rt2x00dev) |
| 727 | { |
| 728 | struct data_queue *queue; |
| 729 | enum data_queue_qid qid; |
| 730 | unsigned int req_atim = |
| 731 | !!test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags); |
| 732 | |
| 733 | /* |
| 734 | * We need the following queues: |
| 735 | * RX: 1 |
Gertjan van Wingerde | 61448f8 | 2008-05-10 13:43:33 +0200 | [diff] [blame] | 736 | * TX: ops->tx_queues |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 737 | * Beacon: 1 |
| 738 | * Atim: 1 (if required) |
| 739 | */ |
Gertjan van Wingerde | 61448f8 | 2008-05-10 13:43:33 +0200 | [diff] [blame] | 740 | rt2x00dev->data_queues = 2 + rt2x00dev->ops->tx_queues + req_atim; |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 741 | |
| 742 | queue = kzalloc(rt2x00dev->data_queues * sizeof(*queue), GFP_KERNEL); |
| 743 | if (!queue) { |
| 744 | ERROR(rt2x00dev, "Queue allocation failed.\n"); |
| 745 | return -ENOMEM; |
| 746 | } |
| 747 | |
| 748 | /* |
| 749 | * Initialize pointers |
| 750 | */ |
| 751 | rt2x00dev->rx = queue; |
| 752 | rt2x00dev->tx = &queue[1]; |
Gertjan van Wingerde | 61448f8 | 2008-05-10 13:43:33 +0200 | [diff] [blame] | 753 | rt2x00dev->bcn = &queue[1 + rt2x00dev->ops->tx_queues]; |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 754 | |
| 755 | /* |
| 756 | * Initialize queue parameters. |
| 757 | * RX: qid = QID_RX |
| 758 | * TX: qid = QID_AC_BE + index |
| 759 | * TX: cw_min: 2^5 = 32. |
| 760 | * TX: cw_max: 2^10 = 1024. |
Ivo van Doorn | 565a019 | 2008-06-03 20:29:05 +0200 | [diff] [blame] | 761 | * BCN: qid = QID_BEACON |
| 762 | * ATIM: qid = QID_ATIM |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 763 | */ |
Ivo van Doorn | 8f53927 | 2008-02-10 22:51:41 +0100 | [diff] [blame] | 764 | rt2x00queue_init(rt2x00dev, rt2x00dev->rx, QID_RX); |
| 765 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 766 | qid = QID_AC_BE; |
Ivo van Doorn | 8f53927 | 2008-02-10 22:51:41 +0100 | [diff] [blame] | 767 | tx_queue_for_each(rt2x00dev, queue) |
| 768 | rt2x00queue_init(rt2x00dev, queue, qid++); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 769 | |
Ivo van Doorn | 565a019 | 2008-06-03 20:29:05 +0200 | [diff] [blame] | 770 | rt2x00queue_init(rt2x00dev, &rt2x00dev->bcn[0], QID_BEACON); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 771 | if (req_atim) |
Ivo van Doorn | 565a019 | 2008-06-03 20:29:05 +0200 | [diff] [blame] | 772 | rt2x00queue_init(rt2x00dev, &rt2x00dev->bcn[1], QID_ATIM); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 773 | |
| 774 | return 0; |
| 775 | } |
| 776 | |
| 777 | void rt2x00queue_free(struct rt2x00_dev *rt2x00dev) |
| 778 | { |
| 779 | kfree(rt2x00dev->rx); |
| 780 | rt2x00dev->rx = NULL; |
| 781 | rt2x00dev->tx = NULL; |
| 782 | rt2x00dev->bcn = NULL; |
| 783 | } |