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