Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1 | /* |
Ivo van Doorn | 7e613e1 | 2010-08-06 20:45:38 +0200 | [diff] [blame] | 2 | Copyright (C) 2010 Willow Garage <http://www.willowgarage.com> |
| 3 | Copyright (C) 2004 - 2010 Ivo van Doorn <IvDoorn@gmail.com> |
Gertjan van Wingerde | 9c9a0d1 | 2009-11-08 16:39:55 +0100 | [diff] [blame] | 4 | Copyright (C) 2004 - 2009 Gertjan van Wingerde <gwingerde@gmail.com> |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 5 | <http://rt2x00.serialmonkey.com> |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
Jeff Kirsher | a05b8c5 | 2013-12-06 03:32:11 -0800 | [diff] [blame] | 18 | along with this program; if not, see <http://www.gnu.org/licenses/>. |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | /* |
| 22 | Module: rt2x00lib |
| 23 | Abstract: rt2x00 queue specific routines. |
| 24 | */ |
| 25 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 27 | #include <linux/kernel.h> |
| 28 | #include <linux/module.h> |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 29 | #include <linux/dma-mapping.h> |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 30 | |
| 31 | #include "rt2x00.h" |
| 32 | #include "rt2x00lib.h" |
| 33 | |
Helmut Schaa | 8821102 | 2012-04-19 13:24:10 +0200 | [diff] [blame] | 34 | struct sk_buff *rt2x00queue_alloc_rxskb(struct queue_entry *entry, gfp_t gfp) |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 35 | { |
Stanislaw Gruszka | f0bda57 | 2013-04-17 14:30:47 +0200 | [diff] [blame] | 36 | struct data_queue *queue = entry->queue; |
| 37 | struct rt2x00_dev *rt2x00dev = queue->rt2x00dev; |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 38 | struct sk_buff *skb; |
| 39 | struct skb_frame_desc *skbdesc; |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 40 | unsigned int frame_size; |
| 41 | unsigned int head_size = 0; |
| 42 | unsigned int tail_size = 0; |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * The frame size includes descriptor size, because the |
| 46 | * hardware directly receive the frame into the skbuffer. |
| 47 | */ |
Stanislaw Gruszka | f0bda57 | 2013-04-17 14:30:47 +0200 | [diff] [blame] | 48 | frame_size = queue->data_size + queue->desc_size + queue->winfo_size; |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 49 | |
| 50 | /* |
Ivo van Doorn | ff35239 | 2008-07-04 14:56:07 +0200 | [diff] [blame] | 51 | * The payload should be aligned to a 4-byte boundary, |
| 52 | * this means we need at least 3 bytes for moving the frame |
| 53 | * into the correct offset. |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 54 | */ |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 55 | head_size = 4; |
| 56 | |
| 57 | /* |
| 58 | * For IV/EIV/ICV assembly we must make sure there is |
| 59 | * at least 8 bytes bytes available in headroom for IV/EIV |
Ivo van Doorn | 9c3444d | 2008-12-03 17:29:48 +0100 | [diff] [blame] | 60 | * and 8 bytes for ICV data as tailroon. |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 61 | */ |
Gabor Juhos | 7b8a00d | 2013-10-11 13:18:41 +0200 | [diff] [blame] | 62 | if (rt2x00_has_cap_hw_crypto(rt2x00dev)) { |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 63 | head_size += 8; |
Ivo van Doorn | 9c3444d | 2008-12-03 17:29:48 +0100 | [diff] [blame] | 64 | tail_size += 8; |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 65 | } |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * Allocate skbuffer. |
| 69 | */ |
Helmut Schaa | 8821102 | 2012-04-19 13:24:10 +0200 | [diff] [blame] | 70 | skb = __dev_alloc_skb(frame_size + head_size + tail_size, gfp); |
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)); |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 86 | |
Fred Chou | b9d305c | 2014-12-26 16:19:18 +0800 | [diff] [blame] | 87 | if (rt2x00_has_cap_flag(rt2x00dev, REQUIRE_DMA)) { |
Stanislaw Gruszka | 4ea545d | 2013-02-13 14:27:05 +0100 | [diff] [blame] | 88 | dma_addr_t skb_dma; |
| 89 | |
| 90 | skb_dma = dma_map_single(rt2x00dev->dev, skb->data, skb->len, |
| 91 | DMA_FROM_DEVICE); |
| 92 | if (unlikely(dma_mapping_error(rt2x00dev->dev, skb_dma))) { |
| 93 | dev_kfree_skb_any(skb); |
| 94 | return NULL; |
| 95 | } |
| 96 | |
| 97 | skbdesc->skb_dma = skb_dma; |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 98 | skbdesc->flags |= SKBDESC_DMA_MAPPED_RX; |
| 99 | } |
| 100 | |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 101 | return skb; |
| 102 | } |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 103 | |
Stanislaw Gruszka | 4ea545d | 2013-02-13 14:27:05 +0100 | [diff] [blame] | 104 | int rt2x00queue_map_txskb(struct queue_entry *entry) |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 105 | { |
Ivo van Doorn | fa69560 | 2010-10-11 15:37:25 +0200 | [diff] [blame] | 106 | struct device *dev = entry->queue->rt2x00dev->dev; |
| 107 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 108 | |
Ivo van Doorn | 3ee54a0 | 2008-08-29 21:04:50 +0200 | [diff] [blame] | 109 | skbdesc->skb_dma = |
Ivo van Doorn | fa69560 | 2010-10-11 15:37:25 +0200 | [diff] [blame] | 110 | dma_map_single(dev, entry->skb->data, entry->skb->len, DMA_TO_DEVICE); |
Stanislaw Gruszka | 4ea545d | 2013-02-13 14:27:05 +0100 | [diff] [blame] | 111 | |
| 112 | if (unlikely(dma_mapping_error(dev, skbdesc->skb_dma))) |
| 113 | return -ENOMEM; |
| 114 | |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 115 | skbdesc->flags |= SKBDESC_DMA_MAPPED_TX; |
Stanislaw Gruszka | 4ea545d | 2013-02-13 14:27:05 +0100 | [diff] [blame] | 116 | return 0; |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 117 | } |
| 118 | EXPORT_SYMBOL_GPL(rt2x00queue_map_txskb); |
| 119 | |
Ivo van Doorn | fa69560 | 2010-10-11 15:37:25 +0200 | [diff] [blame] | 120 | void rt2x00queue_unmap_skb(struct queue_entry *entry) |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 121 | { |
Ivo van Doorn | fa69560 | 2010-10-11 15:37:25 +0200 | [diff] [blame] | 122 | struct device *dev = entry->queue->rt2x00dev->dev; |
| 123 | struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb); |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 124 | |
| 125 | if (skbdesc->flags & SKBDESC_DMA_MAPPED_RX) { |
Ivo van Doorn | fa69560 | 2010-10-11 15:37:25 +0200 | [diff] [blame] | 126 | dma_unmap_single(dev, skbdesc->skb_dma, entry->skb->len, |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 127 | DMA_FROM_DEVICE); |
| 128 | skbdesc->flags &= ~SKBDESC_DMA_MAPPED_RX; |
Helmut Schaa | 546adf2 | 2010-10-09 13:33:43 +0200 | [diff] [blame] | 129 | } else if (skbdesc->flags & SKBDESC_DMA_MAPPED_TX) { |
Ivo van Doorn | fa69560 | 2010-10-11 15:37:25 +0200 | [diff] [blame] | 130 | dma_unmap_single(dev, skbdesc->skb_dma, entry->skb->len, |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 131 | DMA_TO_DEVICE); |
| 132 | skbdesc->flags &= ~SKBDESC_DMA_MAPPED_TX; |
| 133 | } |
| 134 | } |
Gertjan van Wingerde | 0b8004a | 2010-06-03 10:51:45 +0200 | [diff] [blame] | 135 | EXPORT_SYMBOL_GPL(rt2x00queue_unmap_skb); |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 136 | |
Ivo van Doorn | fa69560 | 2010-10-11 15:37:25 +0200 | [diff] [blame] | 137 | void rt2x00queue_free_skb(struct queue_entry *entry) |
Gertjan van Wingerde | c4da004 | 2008-06-16 19:56:31 +0200 | [diff] [blame] | 138 | { |
Ivo van Doorn | fa69560 | 2010-10-11 15:37:25 +0200 | [diff] [blame] | 139 | if (!entry->skb) |
Ivo van Doorn | 9a61319 | 2008-07-05 15:11:57 +0200 | [diff] [blame] | 140 | return; |
| 141 | |
Ivo van Doorn | fa69560 | 2010-10-11 15:37:25 +0200 | [diff] [blame] | 142 | rt2x00queue_unmap_skb(entry); |
| 143 | dev_kfree_skb_any(entry->skb); |
| 144 | entry->skb = NULL; |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 145 | } |
Gertjan van Wingerde | 239c249 | 2008-06-06 22:54:12 +0200 | [diff] [blame] | 146 | |
Ivo van Doorn | daee6c0 | 2009-08-29 20:30:45 +0200 | [diff] [blame] | 147 | void rt2x00queue_align_frame(struct sk_buff *skb) |
Ivo van Doorn | 9f16617 | 2009-04-26 16:08:50 +0200 | [diff] [blame] | 148 | { |
Ivo van Doorn | 9f16617 | 2009-04-26 16:08:50 +0200 | [diff] [blame] | 149 | unsigned int frame_length = skb->len; |
Ivo van Doorn | daee6c0 | 2009-08-29 20:30:45 +0200 | [diff] [blame] | 150 | unsigned int align = ALIGN_SIZE(skb, 0); |
Ivo van Doorn | 9f16617 | 2009-04-26 16:08:50 +0200 | [diff] [blame] | 151 | |
| 152 | if (!align) |
| 153 | return; |
| 154 | |
Ivo van Doorn | daee6c0 | 2009-08-29 20:30:45 +0200 | [diff] [blame] | 155 | skb_push(skb, align); |
| 156 | memmove(skb->data, skb->data + align, frame_length); |
| 157 | skb_trim(skb, frame_length); |
| 158 | } |
| 159 | |
Stanislaw Gruszka | cfd9167 | 2014-11-11 14:28:47 +0100 | [diff] [blame] | 160 | /* |
| 161 | * H/W needs L2 padding between the header and the paylod if header size |
| 162 | * is not 4 bytes aligned. |
| 163 | */ |
| 164 | void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int hdr_len) |
Ivo van Doorn | daee6c0 | 2009-08-29 20:30:45 +0200 | [diff] [blame] | 165 | { |
Stanislaw Gruszka | cfd9167 | 2014-11-11 14:28:47 +0100 | [diff] [blame] | 166 | unsigned int l2pad = (skb->len > hdr_len) ? L2PAD_SIZE(hdr_len) : 0; |
Ivo van Doorn | daee6c0 | 2009-08-29 20:30:45 +0200 | [diff] [blame] | 167 | |
Gertjan van Wingerde | 354e39d | 2009-12-04 23:47:02 +0100 | [diff] [blame] | 168 | if (!l2pad) |
Ivo van Doorn | daee6c0 | 2009-08-29 20:30:45 +0200 | [diff] [blame] | 169 | return; |
| 170 | |
Stanislaw Gruszka | cfd9167 | 2014-11-11 14:28:47 +0100 | [diff] [blame] | 171 | skb_push(skb, l2pad); |
| 172 | memmove(skb->data, skb->data + l2pad, hdr_len); |
| 173 | } |
| 174 | |
| 175 | void rt2x00queue_remove_l2pad(struct sk_buff *skb, unsigned int hdr_len) |
| 176 | { |
| 177 | unsigned int l2pad = (skb->len > hdr_len) ? L2PAD_SIZE(hdr_len) : 0; |
| 178 | |
| 179 | if (!l2pad) |
| 180 | return; |
| 181 | |
| 182 | memmove(skb->data + l2pad, skb->data, hdr_len); |
Gertjan van Wingerde | a061a93 | 2010-12-13 12:33:12 +0100 | [diff] [blame] | 183 | skb_pull(skb, l2pad); |
Ivo van Doorn | daee6c0 | 2009-08-29 20:30:45 +0200 | [diff] [blame] | 184 | } |
| 185 | |
Gertjan van Wingerde | 77b5621 | 2011-07-06 22:57:00 +0200 | [diff] [blame] | 186 | static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev, |
| 187 | struct sk_buff *skb, |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 188 | struct txentry_desc *txdesc) |
| 189 | { |
Gertjan van Wingerde | 77b5621 | 2011-07-06 22:57:00 +0200 | [diff] [blame] | 190 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 191 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 192 | struct rt2x00_intf *intf = vif_to_intf(tx_info->control.vif); |
Stanislaw Gruszka | e5851da | 2012-06-01 11:29:40 +0200 | [diff] [blame] | 193 | u16 seqno; |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 194 | |
Helmut Schaa | c262e08 | 2011-03-03 19:39:56 +0100 | [diff] [blame] | 195 | if (!(tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)) |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 196 | return; |
| 197 | |
Helmut Schaa | 7fe7ee7 | 2011-03-03 19:42:01 +0100 | [diff] [blame] | 198 | __set_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags); |
| 199 | |
Fred Chou | b9d305c | 2014-12-26 16:19:18 +0800 | [diff] [blame] | 200 | if (!rt2x00_has_cap_flag(rt2x00dev, REQUIRE_SW_SEQNO)) { |
Stanislaw Gruszka | e66a8dd | 2012-04-02 13:21:06 +0200 | [diff] [blame] | 201 | /* |
| 202 | * rt2800 has a H/W (or F/W) bug, device incorrectly increase |
| 203 | * seqno on retransmited data (non-QOS) frames. To workaround |
| 204 | * the problem let's generate seqno in software if QOS is |
| 205 | * disabled. |
| 206 | */ |
| 207 | if (test_bit(CONFIG_QOS_DISABLED, &rt2x00dev->flags)) |
| 208 | __clear_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags); |
| 209 | else |
| 210 | /* H/W will generate sequence number */ |
| 211 | return; |
| 212 | } |
Helmut Schaa | 7fe7ee7 | 2011-03-03 19:42:01 +0100 | [diff] [blame] | 213 | |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 214 | /* |
Helmut Schaa | 7fe7ee7 | 2011-03-03 19:42:01 +0100 | [diff] [blame] | 215 | * The hardware is not able to insert a sequence number. Assign a |
| 216 | * software generated one here. |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 217 | * |
| 218 | * This is wrong because beacons are not getting sequence |
| 219 | * numbers assigned properly. |
| 220 | * |
| 221 | * A secondary problem exists for drivers that cannot toggle |
| 222 | * sequence counting per-frame, since those will override the |
| 223 | * sequence counter given by mac80211. |
| 224 | */ |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 225 | if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags)) |
Stanislaw Gruszka | e5851da | 2012-06-01 11:29:40 +0200 | [diff] [blame] | 226 | seqno = atomic_add_return(0x10, &intf->seqno); |
| 227 | else |
| 228 | seqno = atomic_read(&intf->seqno); |
| 229 | |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 230 | hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); |
Stanislaw Gruszka | e5851da | 2012-06-01 11:29:40 +0200 | [diff] [blame] | 231 | hdr->seq_ctrl |= cpu_to_le16(seqno); |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 232 | } |
| 233 | |
Gertjan van Wingerde | 77b5621 | 2011-07-06 22:57:00 +0200 | [diff] [blame] | 234 | static void rt2x00queue_create_tx_descriptor_plcp(struct rt2x00_dev *rt2x00dev, |
| 235 | struct sk_buff *skb, |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 236 | struct txentry_desc *txdesc, |
| 237 | const struct rt2x00_rate *hwrate) |
| 238 | { |
Gertjan van Wingerde | 77b5621 | 2011-07-06 22:57:00 +0200 | [diff] [blame] | 239 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 240 | struct ieee80211_tx_rate *txrate = &tx_info->control.rates[0]; |
| 241 | unsigned int data_length; |
| 242 | unsigned int duration; |
| 243 | unsigned int residual; |
| 244 | |
Helmut Schaa | 2517794 | 2011-03-03 19:43:25 +0100 | [diff] [blame] | 245 | /* |
| 246 | * Determine with what IFS priority this frame should be send. |
| 247 | * Set ifs to IFS_SIFS when the this is not the first fragment, |
| 248 | * or this fragment came after RTS/CTS. |
| 249 | */ |
| 250 | if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags)) |
| 251 | txdesc->u.plcp.ifs = IFS_BACKOFF; |
| 252 | else |
| 253 | txdesc->u.plcp.ifs = IFS_SIFS; |
| 254 | |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 255 | /* Data length + CRC + Crypto overhead (IV/EIV/ICV/MIC) */ |
Gertjan van Wingerde | 77b5621 | 2011-07-06 22:57:00 +0200 | [diff] [blame] | 256 | data_length = skb->len + 4; |
| 257 | data_length += rt2x00crypto_tx_overhead(rt2x00dev, skb); |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 258 | |
| 259 | /* |
| 260 | * PLCP setup |
| 261 | * Length calculation depends on OFDM/CCK rate. |
| 262 | */ |
Helmut Schaa | 26a1d07 | 2011-03-03 19:42:35 +0100 | [diff] [blame] | 263 | txdesc->u.plcp.signal = hwrate->plcp; |
| 264 | txdesc->u.plcp.service = 0x04; |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 265 | |
| 266 | if (hwrate->flags & DEV_RATE_OFDM) { |
Helmut Schaa | 26a1d07 | 2011-03-03 19:42:35 +0100 | [diff] [blame] | 267 | txdesc->u.plcp.length_high = (data_length >> 6) & 0x3f; |
| 268 | txdesc->u.plcp.length_low = data_length & 0x3f; |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 269 | } else { |
| 270 | /* |
| 271 | * Convert length to microseconds. |
| 272 | */ |
| 273 | residual = GET_DURATION_RES(data_length, hwrate->bitrate); |
| 274 | duration = GET_DURATION(data_length, hwrate->bitrate); |
| 275 | |
| 276 | if (residual != 0) { |
| 277 | duration++; |
| 278 | |
| 279 | /* |
| 280 | * Check if we need to set the Length Extension |
| 281 | */ |
| 282 | if (hwrate->bitrate == 110 && residual <= 30) |
Helmut Schaa | 26a1d07 | 2011-03-03 19:42:35 +0100 | [diff] [blame] | 283 | txdesc->u.plcp.service |= 0x80; |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 284 | } |
| 285 | |
Helmut Schaa | 26a1d07 | 2011-03-03 19:42:35 +0100 | [diff] [blame] | 286 | txdesc->u.plcp.length_high = (duration >> 8) & 0xff; |
| 287 | txdesc->u.plcp.length_low = duration & 0xff; |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 288 | |
| 289 | /* |
| 290 | * When preamble is enabled we should set the |
| 291 | * preamble bit for the signal. |
| 292 | */ |
| 293 | if (txrate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) |
Helmut Schaa | 26a1d07 | 2011-03-03 19:42:35 +0100 | [diff] [blame] | 294 | txdesc->u.plcp.signal |= 0x08; |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
Gertjan van Wingerde | 77b5621 | 2011-07-06 22:57:00 +0200 | [diff] [blame] | 298 | static void rt2x00queue_create_tx_descriptor_ht(struct rt2x00_dev *rt2x00dev, |
| 299 | struct sk_buff *skb, |
Gertjan van Wingerde | 46a01ec | 2011-04-18 15:33:41 +0200 | [diff] [blame] | 300 | struct txentry_desc *txdesc, |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 301 | struct ieee80211_sta *sta, |
Gertjan van Wingerde | 46a01ec | 2011-04-18 15:33:41 +0200 | [diff] [blame] | 302 | const struct rt2x00_rate *hwrate) |
| 303 | { |
Gertjan van Wingerde | 77b5621 | 2011-07-06 22:57:00 +0200 | [diff] [blame] | 304 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
Gertjan van Wingerde | 46a01ec | 2011-04-18 15:33:41 +0200 | [diff] [blame] | 305 | struct ieee80211_tx_rate *txrate = &tx_info->control.rates[0]; |
Gertjan van Wingerde | 77b5621 | 2011-07-06 22:57:00 +0200 | [diff] [blame] | 306 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Helmut Schaa | ead2bb6 | 2011-09-08 14:37:19 +0200 | [diff] [blame] | 307 | struct rt2x00_sta *sta_priv = NULL; |
Stanislaw Gruszka | e49abb1 | 2016-12-19 11:52:48 +0100 | [diff] [blame] | 308 | u8 density = 0; |
Gertjan van Wingerde | 46a01ec | 2011-04-18 15:33:41 +0200 | [diff] [blame] | 309 | |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 310 | if (sta) { |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 311 | sta_priv = sta_to_rt2x00_sta(sta); |
Helmut Schaa | ead2bb6 | 2011-09-08 14:37:19 +0200 | [diff] [blame] | 312 | txdesc->u.ht.wcid = sta_priv->wcid; |
Stanislaw Gruszka | e49abb1 | 2016-12-19 11:52:48 +0100 | [diff] [blame] | 313 | density = sta->ht_cap.ampdu_density; |
Helmut Schaa | ead2bb6 | 2011-09-08 14:37:19 +0200 | [diff] [blame] | 314 | } |
| 315 | |
Gertjan van Wingerde | 46a01ec | 2011-04-18 15:33:41 +0200 | [diff] [blame] | 316 | /* |
| 317 | * If IEEE80211_TX_RC_MCS is set txrate->idx just contains the |
| 318 | * mcs rate to be used |
| 319 | */ |
| 320 | if (txrate->flags & IEEE80211_TX_RC_MCS) { |
| 321 | txdesc->u.ht.mcs = txrate->idx; |
| 322 | |
| 323 | /* |
| 324 | * MIMO PS should be set to 1 for STA's using dynamic SM PS |
| 325 | * when using more then one tx stream (>MCS7). |
| 326 | */ |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 327 | if (sta && txdesc->u.ht.mcs > 7 && |
Johannes Berg | af0ed69 | 2013-02-12 14:21:00 +0100 | [diff] [blame] | 328 | sta->smps_mode == IEEE80211_SMPS_DYNAMIC) |
Gertjan van Wingerde | 46a01ec | 2011-04-18 15:33:41 +0200 | [diff] [blame] | 329 | __set_bit(ENTRY_TXD_HT_MIMO_PS, &txdesc->flags); |
| 330 | } else { |
| 331 | txdesc->u.ht.mcs = rt2x00_get_rate_mcs(hwrate->mcs); |
| 332 | if (txrate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) |
| 333 | txdesc->u.ht.mcs |= 0x08; |
| 334 | } |
| 335 | |
Stanislaw Gruszka | da40f40 | 2012-04-04 16:15:33 +0200 | [diff] [blame] | 336 | if (test_bit(CONFIG_HT_DISABLED, &rt2x00dev->flags)) { |
| 337 | if (!(tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)) |
| 338 | txdesc->u.ht.txop = TXOP_SIFS; |
| 339 | else |
| 340 | txdesc->u.ht.txop = TXOP_BACKOFF; |
| 341 | |
| 342 | /* Left zero on all other settings. */ |
| 343 | return; |
| 344 | } |
| 345 | |
Stanislaw Gruszka | da40f40 | 2012-04-04 16:15:33 +0200 | [diff] [blame] | 346 | /* |
| 347 | * Only one STBC stream is supported for now. |
| 348 | */ |
| 349 | if (tx_info->flags & IEEE80211_TX_CTL_STBC) |
| 350 | txdesc->u.ht.stbc = 1; |
| 351 | |
Gertjan van Wingerde | 46a01ec | 2011-04-18 15:33:41 +0200 | [diff] [blame] | 352 | /* |
| 353 | * This frame is eligible for an AMPDU, however, don't aggregate |
| 354 | * frames that are intended to probe a specific tx rate. |
| 355 | */ |
| 356 | if (tx_info->flags & IEEE80211_TX_CTL_AMPDU && |
Stanislaw Gruszka | e49abb1 | 2016-12-19 11:52:48 +0100 | [diff] [blame] | 357 | !(tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE)) { |
Gertjan van Wingerde | 46a01ec | 2011-04-18 15:33:41 +0200 | [diff] [blame] | 358 | __set_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags); |
Stanislaw Gruszka | e49abb1 | 2016-12-19 11:52:48 +0100 | [diff] [blame] | 359 | txdesc->u.ht.mpdu_density = density; |
| 360 | txdesc->u.ht.ba_size = 7; /* FIXME: What value is needed? */ |
| 361 | } |
Gertjan van Wingerde | 46a01ec | 2011-04-18 15:33:41 +0200 | [diff] [blame] | 362 | |
| 363 | /* |
| 364 | * Set 40Mhz mode if necessary (for legacy rates this will |
| 365 | * duplicate the frame to both channels). |
| 366 | */ |
| 367 | if (txrate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH || |
| 368 | txrate->flags & IEEE80211_TX_RC_DUP_DATA) |
| 369 | __set_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags); |
| 370 | if (txrate->flags & IEEE80211_TX_RC_SHORT_GI) |
| 371 | __set_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags); |
| 372 | |
| 373 | /* |
| 374 | * Determine IFS values |
Stanislaw Gruszka | 52a1923 | 2018-05-28 13:25:06 +0200 | [diff] [blame] | 375 | * - Use TXOP_BACKOFF for management frames except beacons |
Gertjan van Wingerde | 46a01ec | 2011-04-18 15:33:41 +0200 | [diff] [blame] | 376 | * - Use TXOP_SIFS for fragment bursts |
| 377 | * - Use TXOP_HTTXOP for everything else |
| 378 | * |
| 379 | * Note: rt2800 devices won't use CTS protection (if used) |
| 380 | * for frames not transmitted with TXOP_HTTXOP |
| 381 | */ |
Stanislaw Gruszka | 52a1923 | 2018-05-28 13:25:06 +0200 | [diff] [blame] | 382 | if (ieee80211_is_mgmt(hdr->frame_control) && |
| 383 | !ieee80211_is_beacon(hdr->frame_control)) |
Gertjan van Wingerde | 46a01ec | 2011-04-18 15:33:41 +0200 | [diff] [blame] | 384 | txdesc->u.ht.txop = TXOP_BACKOFF; |
| 385 | else if (!(tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)) |
| 386 | txdesc->u.ht.txop = TXOP_SIFS; |
| 387 | else |
| 388 | txdesc->u.ht.txop = TXOP_HTTXOP; |
| 389 | } |
| 390 | |
Gertjan van Wingerde | 77b5621 | 2011-07-06 22:57:00 +0200 | [diff] [blame] | 391 | static void rt2x00queue_create_tx_descriptor(struct rt2x00_dev *rt2x00dev, |
| 392 | struct sk_buff *skb, |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 393 | struct txentry_desc *txdesc, |
| 394 | struct ieee80211_sta *sta) |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 395 | { |
Gertjan van Wingerde | 77b5621 | 2011-07-06 22:57:00 +0200 | [diff] [blame] | 396 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 397 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Helmut Schaa | 55b585e | 2011-03-03 19:43:49 +0100 | [diff] [blame] | 398 | struct ieee80211_tx_rate *txrate = &tx_info->control.rates[0]; |
| 399 | struct ieee80211_rate *rate; |
| 400 | const struct rt2x00_rate *hwrate = NULL; |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 401 | |
| 402 | memset(txdesc, 0, sizeof(*txdesc)); |
| 403 | |
| 404 | /* |
Gertjan van Wingerde | df624ca | 2010-05-03 22:43:05 +0200 | [diff] [blame] | 405 | * Header and frame information. |
Ivo van Doorn | 9f16617 | 2009-04-26 16:08:50 +0200 | [diff] [blame] | 406 | */ |
Gertjan van Wingerde | 77b5621 | 2011-07-06 22:57:00 +0200 | [diff] [blame] | 407 | txdesc->length = skb->len; |
| 408 | txdesc->header_length = ieee80211_get_hdrlen_from_skb(skb); |
Ivo van Doorn | 9f16617 | 2009-04-26 16:08:50 +0200 | [diff] [blame] | 409 | |
| 410 | /* |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 411 | * Check whether this frame is to be acked. |
| 412 | */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 413 | if (!(tx_info->flags & IEEE80211_TX_CTL_NO_ACK)) |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 414 | __set_bit(ENTRY_TXD_ACK, &txdesc->flags); |
| 415 | |
| 416 | /* |
| 417 | * Check if this is a RTS/CTS frame |
| 418 | */ |
Ivo van Doorn | ac10446 | 2008-06-16 19:54:57 +0200 | [diff] [blame] | 419 | if (ieee80211_is_rts(hdr->frame_control) || |
| 420 | ieee80211_is_cts(hdr->frame_control)) { |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 421 | __set_bit(ENTRY_TXD_BURST, &txdesc->flags); |
Ivo van Doorn | ac10446 | 2008-06-16 19:54:57 +0200 | [diff] [blame] | 422 | if (ieee80211_is_rts(hdr->frame_control)) |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 423 | __set_bit(ENTRY_TXD_RTS_FRAME, &txdesc->flags); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 424 | else |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 425 | __set_bit(ENTRY_TXD_CTS_FRAME, &txdesc->flags); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 426 | if (tx_info->control.rts_cts_rate_idx >= 0) |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 427 | rate = |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 428 | ieee80211_get_rts_cts_rate(rt2x00dev->hw, tx_info); |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | /* |
| 432 | * Determine retry information. |
| 433 | */ |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 434 | txdesc->retry_limit = tx_info->control.rates[0].count - 1; |
Ivo van Doorn | 42c8285 | 2008-12-02 18:20:04 +0100 | [diff] [blame] | 435 | if (txdesc->retry_limit >= rt2x00dev->long_retry) |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 436 | __set_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags); |
| 437 | |
| 438 | /* |
| 439 | * Check if more fragments are pending |
| 440 | */ |
Helmut Schaa | 2606e42 | 2010-06-14 22:10:09 +0200 | [diff] [blame] | 441 | if (ieee80211_has_morefrags(hdr->frame_control)) { |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 442 | __set_bit(ENTRY_TXD_BURST, &txdesc->flags); |
| 443 | __set_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags); |
| 444 | } |
| 445 | |
| 446 | /* |
Helmut Schaa | 2606e42 | 2010-06-14 22:10:09 +0200 | [diff] [blame] | 447 | * Check if more frames (!= fragments) are pending |
| 448 | */ |
| 449 | if (tx_info->flags & IEEE80211_TX_CTL_MORE_FRAMES) |
| 450 | __set_bit(ENTRY_TXD_BURST, &txdesc->flags); |
| 451 | |
| 452 | /* |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 453 | * Beacons and probe responses require the tsf timestamp |
Helmut Schaa | 1bce85cf | 2011-02-20 13:56:07 +0100 | [diff] [blame] | 454 | * to be inserted into the frame. |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 455 | */ |
Helmut Schaa | 1bce85cf | 2011-02-20 13:56:07 +0100 | [diff] [blame] | 456 | if (ieee80211_is_beacon(hdr->frame_control) || |
| 457 | ieee80211_is_probe_resp(hdr->frame_control)) |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 458 | __set_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags); |
| 459 | |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 460 | if ((tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) && |
Helmut Schaa | 2517794 | 2011-03-03 19:43:25 +0100 | [diff] [blame] | 461 | !test_bit(ENTRY_TXD_RTS_FRAME, &txdesc->flags)) |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 462 | __set_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags); |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 463 | |
Ivo van Doorn | 076f958 | 2008-12-20 10:59:02 +0100 | [diff] [blame] | 464 | /* |
| 465 | * Determine rate modulation. |
| 466 | */ |
Helmut Schaa | 55b585e | 2011-03-03 19:43:49 +0100 | [diff] [blame] | 467 | if (txrate->flags & IEEE80211_TX_RC_GREEN_FIELD) |
| 468 | txdesc->rate_mode = RATE_MODE_HT_GREENFIELD; |
| 469 | else if (txrate->flags & IEEE80211_TX_RC_MCS) |
| 470 | txdesc->rate_mode = RATE_MODE_HT_MIX; |
| 471 | else { |
| 472 | rate = ieee80211_get_tx_rate(rt2x00dev->hw, tx_info); |
| 473 | hwrate = rt2x00_get_rate(rate->hw_value); |
| 474 | if (hwrate->flags & DEV_RATE_OFDM) |
| 475 | txdesc->rate_mode = RATE_MODE_OFDM; |
| 476 | else |
| 477 | txdesc->rate_mode = RATE_MODE_CCK; |
| 478 | } |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 479 | |
Ivo van Doorn | 7b40982 | 2008-12-20 10:58:33 +0100 | [diff] [blame] | 480 | /* |
| 481 | * Apply TX descriptor handling by components |
| 482 | */ |
Gertjan van Wingerde | 77b5621 | 2011-07-06 22:57:00 +0200 | [diff] [blame] | 483 | rt2x00crypto_create_tx_descriptor(rt2x00dev, skb, txdesc); |
| 484 | rt2x00queue_create_tx_descriptor_seq(rt2x00dev, skb, txdesc); |
Helmut Schaa | 26a1d07 | 2011-03-03 19:42:35 +0100 | [diff] [blame] | 485 | |
Fred Chou | b9d305c | 2014-12-26 16:19:18 +0800 | [diff] [blame] | 486 | if (rt2x00_has_cap_flag(rt2x00dev, REQUIRE_HT_TX_DESC)) |
Gertjan van Wingerde | 77b5621 | 2011-07-06 22:57:00 +0200 | [diff] [blame] | 487 | rt2x00queue_create_tx_descriptor_ht(rt2x00dev, skb, txdesc, |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 488 | sta, hwrate); |
Helmut Schaa | 26a1d07 | 2011-03-03 19:42:35 +0100 | [diff] [blame] | 489 | else |
Gertjan van Wingerde | 77b5621 | 2011-07-06 22:57:00 +0200 | [diff] [blame] | 490 | rt2x00queue_create_tx_descriptor_plcp(rt2x00dev, skb, txdesc, |
| 491 | hwrate); |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 492 | } |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 493 | |
Gertjan van Wingerde | 78eea11 | 2010-06-29 21:41:05 +0200 | [diff] [blame] | 494 | static int rt2x00queue_write_tx_data(struct queue_entry *entry, |
| 495 | struct txentry_desc *txdesc) |
| 496 | { |
| 497 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
| 498 | |
| 499 | /* |
| 500 | * This should not happen, we already checked the entry |
| 501 | * was ours. When the hardware disagrees there has been |
| 502 | * a queue corruption! |
| 503 | */ |
| 504 | if (unlikely(rt2x00dev->ops->lib->get_entry_state && |
| 505 | rt2x00dev->ops->lib->get_entry_state(entry))) { |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 506 | rt2x00_err(rt2x00dev, |
| 507 | "Corrupt queue %d, accessing entry which is not ours\n" |
| 508 | "Please file bug report to %s\n", |
| 509 | entry->queue->qid, DRV_PROJECT); |
Gertjan van Wingerde | 78eea11 | 2010-06-29 21:41:05 +0200 | [diff] [blame] | 510 | return -EINVAL; |
| 511 | } |
| 512 | |
| 513 | /* |
| 514 | * Add the requested extra tx headroom in front of the skb. |
| 515 | */ |
Gabor Juhos | 5616a6e | 2013-06-06 09:36:19 +0200 | [diff] [blame] | 516 | skb_push(entry->skb, rt2x00dev->extra_tx_headroom); |
| 517 | memset(entry->skb->data, 0, rt2x00dev->extra_tx_headroom); |
Gertjan van Wingerde | 78eea11 | 2010-06-29 21:41:05 +0200 | [diff] [blame] | 518 | |
| 519 | /* |
Gertjan van Wingerde | 76dd5dd | 2010-06-29 21:42:23 +0200 | [diff] [blame] | 520 | * Call the driver's write_tx_data function, if it exists. |
Gertjan van Wingerde | 78eea11 | 2010-06-29 21:41:05 +0200 | [diff] [blame] | 521 | */ |
Gertjan van Wingerde | 76dd5dd | 2010-06-29 21:42:23 +0200 | [diff] [blame] | 522 | if (rt2x00dev->ops->lib->write_tx_data) |
| 523 | rt2x00dev->ops->lib->write_tx_data(entry, txdesc); |
Gertjan van Wingerde | 78eea11 | 2010-06-29 21:41:05 +0200 | [diff] [blame] | 524 | |
| 525 | /* |
| 526 | * Map the skb to DMA. |
| 527 | */ |
Fred Chou | b9d305c | 2014-12-26 16:19:18 +0800 | [diff] [blame] | 528 | if (rt2x00_has_cap_flag(rt2x00dev, REQUIRE_DMA) && |
Stanislaw Gruszka | 4ea545d | 2013-02-13 14:27:05 +0100 | [diff] [blame] | 529 | rt2x00queue_map_txskb(entry)) |
| 530 | return -ENOMEM; |
Gertjan van Wingerde | 78eea11 | 2010-06-29 21:41:05 +0200 | [diff] [blame] | 531 | |
| 532 | return 0; |
| 533 | } |
| 534 | |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 535 | static void rt2x00queue_write_tx_descriptor(struct queue_entry *entry, |
| 536 | struct txentry_desc *txdesc) |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 537 | { |
Ivo van Doorn | b869767 | 2008-06-06 22:53:14 +0200 | [diff] [blame] | 538 | struct data_queue *queue = entry->queue; |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 539 | |
Ivo van Doorn | 9333145 | 2010-08-23 19:53:39 +0200 | [diff] [blame] | 540 | queue->rt2x00dev->ops->lib->write_tx_desc(entry, txdesc); |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 541 | |
| 542 | /* |
| 543 | * All processing on the frame has been completed, this means |
| 544 | * it is now ready to be dumped to userspace through debugfs. |
| 545 | */ |
Stanislaw Gruszka | 2ceb813 | 2017-02-08 13:51:30 +0100 | [diff] [blame] | 546 | rt2x00debug_dump_frame(queue->rt2x00dev, DUMP_FRAME_TX, entry); |
Gertjan van Wingerde | 6295d81 | 2010-05-09 21:24:22 +0200 | [diff] [blame] | 547 | } |
| 548 | |
Ivo van Doorn | 8be4eed | 2010-11-06 15:48:23 +0100 | [diff] [blame] | 549 | static void rt2x00queue_kick_tx_queue(struct data_queue *queue, |
Gertjan van Wingerde | 6295d81 | 2010-05-09 21:24:22 +0200 | [diff] [blame] | 550 | struct txentry_desc *txdesc) |
| 551 | { |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 552 | /* |
Ivo van Doorn | b869767 | 2008-06-06 22:53:14 +0200 | [diff] [blame] | 553 | * Check if we need to kick the queue, there are however a few rules |
Gertjan van Wingerde | 6295d81 | 2010-05-09 21:24:22 +0200 | [diff] [blame] | 554 | * 1) Don't kick unless this is the last in frame in a burst. |
Ivo van Doorn | b869767 | 2008-06-06 22:53:14 +0200 | [diff] [blame] | 555 | * When the burst flag is set, this frame is always followed |
| 556 | * by another frame which in some way are related to eachother. |
| 557 | * This is true for fragments, RTS or CTS-to-self frames. |
Gertjan van Wingerde | 6295d81 | 2010-05-09 21:24:22 +0200 | [diff] [blame] | 558 | * 2) Rule 1 can be broken when the available entries |
Ivo van Doorn | b869767 | 2008-06-06 22:53:14 +0200 | [diff] [blame] | 559 | * in the queue are less then a certain threshold. |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 560 | */ |
Ivo van Doorn | b869767 | 2008-06-06 22:53:14 +0200 | [diff] [blame] | 561 | if (rt2x00queue_threshold(queue) || |
| 562 | !test_bit(ENTRY_TXD_BURST, &txdesc->flags)) |
Ivo van Doorn | dbba306 | 2010-12-13 12:34:54 +0100 | [diff] [blame] | 563 | queue->rt2x00dev->ops->lib->kick_queue(queue); |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 564 | } |
Ivo van Doorn | 7050ec8 | 2008-05-10 13:46:13 +0200 | [diff] [blame] | 565 | |
Helmut Schaa | 84e9e8ebd | 2013-01-17 17:34:32 +0100 | [diff] [blame] | 566 | static void rt2x00queue_bar_check(struct queue_entry *entry) |
| 567 | { |
| 568 | struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev; |
| 569 | struct ieee80211_bar *bar = (void *) (entry->skb->data + |
Gabor Juhos | 5616a6e | 2013-06-06 09:36:19 +0200 | [diff] [blame] | 570 | rt2x00dev->extra_tx_headroom); |
Helmut Schaa | 84e9e8ebd | 2013-01-17 17:34:32 +0100 | [diff] [blame] | 571 | struct rt2x00_bar_list_entry *bar_entry; |
| 572 | |
| 573 | if (likely(!ieee80211_is_back_req(bar->frame_control))) |
| 574 | return; |
| 575 | |
| 576 | bar_entry = kmalloc(sizeof(*bar_entry), GFP_ATOMIC); |
| 577 | |
| 578 | /* |
| 579 | * If the alloc fails we still send the BAR out but just don't track |
| 580 | * it in our bar list. And as a result we will report it to mac80211 |
| 581 | * back as failed. |
| 582 | */ |
| 583 | if (!bar_entry) |
| 584 | return; |
| 585 | |
| 586 | bar_entry->entry = entry; |
| 587 | bar_entry->block_acked = 0; |
| 588 | |
| 589 | /* |
| 590 | * Copy the relevant parts of the 802.11 BAR into out check list |
| 591 | * such that we can use RCU for less-overhead in the RX path since |
| 592 | * sending BARs and processing the according BlockAck should be |
| 593 | * the exception. |
| 594 | */ |
| 595 | memcpy(bar_entry->ra, bar->ra, sizeof(bar->ra)); |
| 596 | memcpy(bar_entry->ta, bar->ta, sizeof(bar->ta)); |
| 597 | bar_entry->control = bar->control; |
| 598 | bar_entry->start_seq_num = bar->start_seq_num; |
| 599 | |
| 600 | /* |
| 601 | * Insert BAR into our BAR check list. |
| 602 | */ |
| 603 | spin_lock_bh(&rt2x00dev->bar_list_lock); |
| 604 | list_add_tail_rcu(&bar_entry->list, &rt2x00dev->bar_list); |
| 605 | spin_unlock_bh(&rt2x00dev->bar_list_lock); |
| 606 | } |
| 607 | |
Johannes Berg | 7351c6b | 2009-11-19 01:08:30 +0100 | [diff] [blame] | 608 | int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb, |
Stanislaw Gruszka | 3d8bfe1 | 2013-10-31 11:23:57 +0100 | [diff] [blame] | 609 | struct ieee80211_sta *sta, bool local) |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 610 | { |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 611 | struct ieee80211_tx_info *tx_info; |
Gertjan van Wingerde | 77a861c | 2011-07-06 22:56:24 +0200 | [diff] [blame] | 612 | struct queue_entry *entry; |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 613 | struct txentry_desc txdesc; |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 614 | struct skb_frame_desc *skbdesc; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 615 | u8 rate_idx, rate_flags; |
Gertjan van Wingerde | 77a861c | 2011-07-06 22:56:24 +0200 | [diff] [blame] | 616 | int ret = 0; |
| 617 | |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 618 | /* |
| 619 | * Copy all TX descriptor information into txdesc, |
| 620 | * after that we are free to use the skb->cb array |
| 621 | * for our information. |
| 622 | */ |
Stanislaw Gruszka | 3d8bfe1 | 2013-10-31 11:23:57 +0100 | [diff] [blame] | 623 | rt2x00queue_create_tx_descriptor(queue->rt2x00dev, skb, &txdesc, sta); |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 624 | |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 625 | /* |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 626 | * All information is retrieved from the skb->cb array, |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 627 | * now we should claim ownership of the driver part of that |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 628 | * array, preserving the bitrate index and flags. |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 629 | */ |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 630 | tx_info = IEEE80211_SKB_CB(skb); |
| 631 | rate_idx = tx_info->control.rates[0].idx; |
| 632 | rate_flags = tx_info->control.rates[0].flags; |
Ivo van Doorn | 0e3de99 | 2008-11-12 00:01:37 +0100 | [diff] [blame] | 633 | skbdesc = get_skb_frame_desc(skb); |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 634 | memset(skbdesc, 0, sizeof(*skbdesc)); |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 635 | skbdesc->tx_rate_idx = rate_idx; |
| 636 | skbdesc->tx_rate_flags = rate_flags; |
Ivo van Doorn | d74f5ba | 2008-06-16 19:56:54 +0200 | [diff] [blame] | 637 | |
Johannes Berg | 7351c6b | 2009-11-19 01:08:30 +0100 | [diff] [blame] | 638 | if (local) |
| 639 | skbdesc->flags |= SKBDESC_NOT_MAC80211; |
| 640 | |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 641 | /* |
| 642 | * When hardware encryption is supported, and this frame |
| 643 | * is to be encrypted, we should strip the IV/EIV data from |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 644 | * the frame so we can provide it to the driver separately. |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 645 | */ |
| 646 | if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc.flags) && |
Ivo van Doorn | dddfb47 | 2008-12-02 18:20:42 +0100 | [diff] [blame] | 647 | !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc.flags)) { |
Fred Chou | b9d305c | 2014-12-26 16:19:18 +0800 | [diff] [blame] | 648 | if (rt2x00_has_cap_flag(queue->rt2x00dev, REQUIRE_COPY_IV)) |
Ivo van Doorn | 9eb4e21 | 2009-04-26 16:08:30 +0200 | [diff] [blame] | 649 | rt2x00crypto_tx_copy_iv(skb, &txdesc); |
Ivo van Doorn | dddfb47 | 2008-12-02 18:20:42 +0100 | [diff] [blame] | 650 | else |
Ivo van Doorn | 9eb4e21 | 2009-04-26 16:08:30 +0200 | [diff] [blame] | 651 | rt2x00crypto_tx_remove_iv(skb, &txdesc); |
Ivo van Doorn | dddfb47 | 2008-12-02 18:20:42 +0100 | [diff] [blame] | 652 | } |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 653 | |
Ivo van Doorn | 93354cb | 2009-08-08 23:53:47 +0200 | [diff] [blame] | 654 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 655 | * When DMA allocation is required we should guarantee to the |
Ivo van Doorn | 93354cb | 2009-08-08 23:53:47 +0200 | [diff] [blame] | 656 | * driver that the DMA is aligned to a 4-byte boundary. |
Ivo van Doorn | 93354cb | 2009-08-08 23:53:47 +0200 | [diff] [blame] | 657 | * However some drivers require L2 padding to pad the payload |
| 658 | * rather then the header. This could be a requirement for |
| 659 | * PCI and USB devices, while header alignment only is valid |
| 660 | * for PCI devices. |
| 661 | */ |
Fred Chou | b9d305c | 2014-12-26 16:19:18 +0800 | [diff] [blame] | 662 | if (rt2x00_has_cap_flag(queue->rt2x00dev, REQUIRE_L2PAD)) |
Gertjan van Wingerde | 128f8f7 | 2011-07-06 22:57:37 +0200 | [diff] [blame] | 663 | rt2x00queue_insert_l2pad(skb, txdesc.header_length); |
Fred Chou | b9d305c | 2014-12-26 16:19:18 +0800 | [diff] [blame] | 664 | else if (rt2x00_has_cap_flag(queue->rt2x00dev, REQUIRE_DMA)) |
Gertjan van Wingerde | 128f8f7 | 2011-07-06 22:57:37 +0200 | [diff] [blame] | 665 | rt2x00queue_align_frame(skb); |
| 666 | |
Stanislaw Gruszka | 3780d03 | 2012-03-09 12:39:54 +0100 | [diff] [blame] | 667 | /* |
| 668 | * That function must be called with bh disabled. |
| 669 | */ |
Gertjan van Wingerde | 128f8f7 | 2011-07-06 22:57:37 +0200 | [diff] [blame] | 670 | spin_lock(&queue->tx_lock); |
| 671 | |
| 672 | if (unlikely(rt2x00queue_full(queue))) { |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 673 | rt2x00_err(queue->rt2x00dev, "Dropping frame due to full tx queue %d\n", |
| 674 | queue->qid); |
Gertjan van Wingerde | 128f8f7 | 2011-07-06 22:57:37 +0200 | [diff] [blame] | 675 | ret = -ENOBUFS; |
| 676 | goto out; |
| 677 | } |
| 678 | |
| 679 | entry = rt2x00queue_get_entry(queue, Q_INDEX); |
| 680 | |
| 681 | if (unlikely(test_and_set_bit(ENTRY_OWNER_DEVICE_DATA, |
| 682 | &entry->flags))) { |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 683 | rt2x00_err(queue->rt2x00dev, |
| 684 | "Arrived at non-free entry in the non-full queue %d\n" |
| 685 | "Please file bug report to %s\n", |
| 686 | queue->qid, DRV_PROJECT); |
Gertjan van Wingerde | 128f8f7 | 2011-07-06 22:57:37 +0200 | [diff] [blame] | 687 | ret = -EINVAL; |
| 688 | goto out; |
| 689 | } |
| 690 | |
Gertjan van Wingerde | 128f8f7 | 2011-07-06 22:57:37 +0200 | [diff] [blame] | 691 | entry->skb = skb; |
Ivo van Doorn | 9f16617 | 2009-04-26 16:08:50 +0200 | [diff] [blame] | 692 | |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 693 | /* |
| 694 | * It could be possible that the queue was corrupted and this |
Ivo van Doorn | 0e3de99 | 2008-11-12 00:01:37 +0100 | [diff] [blame] | 695 | * call failed. Since we always return NETDEV_TX_OK to mac80211, |
| 696 | * this frame will simply be dropped. |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 697 | */ |
Gertjan van Wingerde | 78eea11 | 2010-06-29 21:41:05 +0200 | [diff] [blame] | 698 | if (unlikely(rt2x00queue_write_tx_data(entry, &txdesc))) { |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 699 | clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags); |
Ivo van Doorn | 2bb057d | 2008-08-04 16:37:44 +0200 | [diff] [blame] | 700 | entry->skb = NULL; |
Gertjan van Wingerde | 77a861c | 2011-07-06 22:56:24 +0200 | [diff] [blame] | 701 | ret = -EIO; |
| 702 | goto out; |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 703 | } |
| 704 | |
Helmut Schaa | 84e9e8ebd | 2013-01-17 17:34:32 +0100 | [diff] [blame] | 705 | /* |
| 706 | * Put BlockAckReqs into our check list for driver BA processing. |
| 707 | */ |
| 708 | rt2x00queue_bar_check(entry); |
| 709 | |
Ivo van Doorn | 0262ab0 | 2008-08-29 21:04:26 +0200 | [diff] [blame] | 710 | set_bit(ENTRY_DATA_PENDING, &entry->flags); |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 711 | |
Johannes Stezenbach | 75256f0 | 2011-04-18 15:29:38 +0200 | [diff] [blame] | 712 | rt2x00queue_index_inc(entry, Q_INDEX); |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 713 | rt2x00queue_write_tx_descriptor(entry, &txdesc); |
Ivo van Doorn | 8be4eed | 2010-11-06 15:48:23 +0100 | [diff] [blame] | 714 | rt2x00queue_kick_tx_queue(queue, &txdesc); |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 715 | |
Gertjan van Wingerde | 77a861c | 2011-07-06 22:56:24 +0200 | [diff] [blame] | 716 | out: |
Stanislaw Gruszka | 3d8f162 | 2017-12-19 12:33:55 +0100 | [diff] [blame] | 717 | /* |
| 718 | * Pausing queue has to be serialized with rt2x00lib_txdone(), so we |
| 719 | * do this under queue->tx_lock. Bottom halve was already disabled |
| 720 | * before ieee80211_xmit() call. |
| 721 | */ |
| 722 | if (rt2x00queue_threshold(queue)) |
| 723 | rt2x00queue_pause_queue(queue); |
| 724 | |
Gertjan van Wingerde | 77a861c | 2011-07-06 22:56:24 +0200 | [diff] [blame] | 725 | spin_unlock(&queue->tx_lock); |
| 726 | return ret; |
Ivo van Doorn | 6db3786 | 2008-06-06 22:50:28 +0200 | [diff] [blame] | 727 | } |
| 728 | |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 729 | int rt2x00queue_clear_beacon(struct rt2x00_dev *rt2x00dev, |
| 730 | struct ieee80211_vif *vif) |
| 731 | { |
| 732 | struct rt2x00_intf *intf = vif_to_intf(vif); |
| 733 | |
| 734 | if (unlikely(!intf->beacon)) |
| 735 | return -ENOBUFS; |
| 736 | |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 737 | /* |
| 738 | * Clean up the beacon skb. |
| 739 | */ |
| 740 | rt2x00queue_free_skb(intf->beacon); |
| 741 | |
| 742 | /* |
| 743 | * Clear beacon (single bssid devices don't need to clear the beacon |
| 744 | * since the beacon queue will get stopped anyway). |
| 745 | */ |
| 746 | if (rt2x00dev->ops->lib->clear_beacon) |
| 747 | rt2x00dev->ops->lib->clear_beacon(intf->beacon); |
| 748 | |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 749 | return 0; |
| 750 | } |
| 751 | |
Stanislaw Gruszka | 283dafa | 2014-06-05 13:52:23 +0200 | [diff] [blame] | 752 | int rt2x00queue_update_beacon(struct rt2x00_dev *rt2x00dev, |
| 753 | struct ieee80211_vif *vif) |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 754 | { |
| 755 | struct rt2x00_intf *intf = vif_to_intf(vif); |
| 756 | struct skb_frame_desc *skbdesc; |
| 757 | struct txentry_desc txdesc; |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 758 | |
| 759 | if (unlikely(!intf->beacon)) |
| 760 | return -ENOBUFS; |
| 761 | |
Igor Perminov | 17512dc | 2009-08-08 23:55:18 +0200 | [diff] [blame] | 762 | /* |
| 763 | * Clean up the beacon skb. |
| 764 | */ |
Ivo van Doorn | fa69560 | 2010-10-11 15:37:25 +0200 | [diff] [blame] | 765 | rt2x00queue_free_skb(intf->beacon); |
Igor Perminov | 17512dc | 2009-08-08 23:55:18 +0200 | [diff] [blame] | 766 | |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 767 | intf->beacon->skb = ieee80211_beacon_get(rt2x00dev->hw, vif); |
Helmut Schaa | 8414ff0 | 2011-01-30 13:16:28 +0100 | [diff] [blame] | 768 | if (!intf->beacon->skb) |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 769 | return -ENOMEM; |
| 770 | |
| 771 | /* |
| 772 | * Copy all TX descriptor information into txdesc, |
| 773 | * after that we are free to use the skb->cb array |
| 774 | * for our information. |
| 775 | */ |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 776 | rt2x00queue_create_tx_descriptor(rt2x00dev, intf->beacon->skb, &txdesc, NULL); |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 777 | |
| 778 | /* |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 779 | * Fill in skb descriptor |
| 780 | */ |
| 781 | skbdesc = get_skb_frame_desc(intf->beacon->skb); |
| 782 | memset(skbdesc, 0, sizeof(*skbdesc)); |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 783 | |
| 784 | /* |
Helmut Schaa | 69cf36a | 2011-01-30 13:16:03 +0100 | [diff] [blame] | 785 | * Send beacon to hardware. |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 786 | */ |
Gertjan van Wingerde | f224f4e | 2010-05-08 23:40:25 +0200 | [diff] [blame] | 787 | rt2x00dev->ops->lib->write_beacon(intf->beacon, &txdesc); |
Ivo van Doorn | bd88a78 | 2008-07-09 15:12:44 +0200 | [diff] [blame] | 788 | |
Helmut Schaa | 8414ff0 | 2011-01-30 13:16:28 +0100 | [diff] [blame] | 789 | return 0; |
| 790 | |
| 791 | } |
| 792 | |
Helmut Schaa | 10e1156 | 2011-04-18 15:27:43 +0200 | [diff] [blame] | 793 | bool rt2x00queue_for_each_entry(struct data_queue *queue, |
Ivo van Doorn | 5eb7efe | 2010-08-23 19:54:21 +0200 | [diff] [blame] | 794 | enum queue_index start, |
| 795 | enum queue_index end, |
Helmut Schaa | 1dd0dbb | 2013-03-15 09:57:56 +0100 | [diff] [blame] | 796 | void *data, |
| 797 | bool (*fn)(struct queue_entry *entry, |
| 798 | void *data)) |
Ivo van Doorn | 5eb7efe | 2010-08-23 19:54:21 +0200 | [diff] [blame] | 799 | { |
| 800 | unsigned long irqflags; |
| 801 | unsigned int index_start; |
| 802 | unsigned int index_end; |
| 803 | unsigned int i; |
| 804 | |
| 805 | if (unlikely(start >= Q_INDEX_MAX || end >= Q_INDEX_MAX)) { |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 806 | rt2x00_err(queue->rt2x00dev, |
| 807 | "Entry requested from invalid index range (%d - %d)\n", |
| 808 | start, end); |
Helmut Schaa | 10e1156 | 2011-04-18 15:27:43 +0200 | [diff] [blame] | 809 | return true; |
Ivo van Doorn | 5eb7efe | 2010-08-23 19:54:21 +0200 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | /* |
| 813 | * Only protect the range we are going to loop over, |
| 814 | * if during our loop a extra entry is set to pending |
| 815 | * it should not be kicked during this run, since it |
| 816 | * is part of another TX operation. |
| 817 | */ |
Ivo van Doorn | 813f033 | 2010-11-06 15:48:05 +0100 | [diff] [blame] | 818 | spin_lock_irqsave(&queue->index_lock, irqflags); |
Ivo van Doorn | 5eb7efe | 2010-08-23 19:54:21 +0200 | [diff] [blame] | 819 | index_start = queue->index[start]; |
| 820 | index_end = queue->index[end]; |
Ivo van Doorn | 813f033 | 2010-11-06 15:48:05 +0100 | [diff] [blame] | 821 | spin_unlock_irqrestore(&queue->index_lock, irqflags); |
Ivo van Doorn | 5eb7efe | 2010-08-23 19:54:21 +0200 | [diff] [blame] | 822 | |
| 823 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 824 | * Start from the TX done pointer, this guarantees that we will |
Ivo van Doorn | 5eb7efe | 2010-08-23 19:54:21 +0200 | [diff] [blame] | 825 | * send out all frames in the correct order. |
| 826 | */ |
| 827 | if (index_start < index_end) { |
Helmut Schaa | 10e1156 | 2011-04-18 15:27:43 +0200 | [diff] [blame] | 828 | for (i = index_start; i < index_end; i++) { |
Helmut Schaa | 1dd0dbb | 2013-03-15 09:57:56 +0100 | [diff] [blame] | 829 | if (fn(&queue->entries[i], data)) |
Helmut Schaa | 10e1156 | 2011-04-18 15:27:43 +0200 | [diff] [blame] | 830 | return true; |
| 831 | } |
Ivo van Doorn | 5eb7efe | 2010-08-23 19:54:21 +0200 | [diff] [blame] | 832 | } else { |
Helmut Schaa | 10e1156 | 2011-04-18 15:27:43 +0200 | [diff] [blame] | 833 | for (i = index_start; i < queue->limit; i++) { |
Helmut Schaa | 1dd0dbb | 2013-03-15 09:57:56 +0100 | [diff] [blame] | 834 | if (fn(&queue->entries[i], data)) |
Helmut Schaa | 10e1156 | 2011-04-18 15:27:43 +0200 | [diff] [blame] | 835 | return true; |
| 836 | } |
Ivo van Doorn | 5eb7efe | 2010-08-23 19:54:21 +0200 | [diff] [blame] | 837 | |
Helmut Schaa | 10e1156 | 2011-04-18 15:27:43 +0200 | [diff] [blame] | 838 | for (i = 0; i < index_end; i++) { |
Helmut Schaa | 1dd0dbb | 2013-03-15 09:57:56 +0100 | [diff] [blame] | 839 | if (fn(&queue->entries[i], data)) |
Helmut Schaa | 10e1156 | 2011-04-18 15:27:43 +0200 | [diff] [blame] | 840 | return true; |
| 841 | } |
Ivo van Doorn | 5eb7efe | 2010-08-23 19:54:21 +0200 | [diff] [blame] | 842 | } |
Helmut Schaa | 10e1156 | 2011-04-18 15:27:43 +0200 | [diff] [blame] | 843 | |
| 844 | return false; |
Ivo van Doorn | 5eb7efe | 2010-08-23 19:54:21 +0200 | [diff] [blame] | 845 | } |
| 846 | EXPORT_SYMBOL_GPL(rt2x00queue_for_each_entry); |
| 847 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 848 | struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue, |
| 849 | enum queue_index index) |
| 850 | { |
| 851 | struct queue_entry *entry; |
Ivo van Doorn | 5f46c4d | 2008-03-09 22:44:30 +0100 | [diff] [blame] | 852 | unsigned long irqflags; |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 853 | |
| 854 | if (unlikely(index >= Q_INDEX_MAX)) { |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 855 | rt2x00_err(queue->rt2x00dev, "Entry requested from invalid index type (%d)\n", |
| 856 | index); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 857 | return NULL; |
| 858 | } |
| 859 | |
Ivo van Doorn | 813f033 | 2010-11-06 15:48:05 +0100 | [diff] [blame] | 860 | spin_lock_irqsave(&queue->index_lock, irqflags); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 861 | |
| 862 | entry = &queue->entries[queue->index[index]]; |
| 863 | |
Ivo van Doorn | 813f033 | 2010-11-06 15:48:05 +0100 | [diff] [blame] | 864 | spin_unlock_irqrestore(&queue->index_lock, irqflags); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 865 | |
| 866 | return entry; |
| 867 | } |
| 868 | EXPORT_SYMBOL_GPL(rt2x00queue_get_entry); |
| 869 | |
Johannes Stezenbach | 75256f0 | 2011-04-18 15:29:38 +0200 | [diff] [blame] | 870 | void rt2x00queue_index_inc(struct queue_entry *entry, enum queue_index index) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 871 | { |
Johannes Stezenbach | 75256f0 | 2011-04-18 15:29:38 +0200 | [diff] [blame] | 872 | struct data_queue *queue = entry->queue; |
Ivo van Doorn | 5f46c4d | 2008-03-09 22:44:30 +0100 | [diff] [blame] | 873 | unsigned long irqflags; |
| 874 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 875 | if (unlikely(index >= Q_INDEX_MAX)) { |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 876 | rt2x00_err(queue->rt2x00dev, |
| 877 | "Index change on invalid index type (%d)\n", index); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 878 | return; |
| 879 | } |
| 880 | |
Ivo van Doorn | 813f033 | 2010-11-06 15:48:05 +0100 | [diff] [blame] | 881 | spin_lock_irqsave(&queue->index_lock, irqflags); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 882 | |
| 883 | queue->index[index]++; |
| 884 | if (queue->index[index] >= queue->limit) |
| 885 | queue->index[index] = 0; |
| 886 | |
Johannes Stezenbach | 75256f0 | 2011-04-18 15:29:38 +0200 | [diff] [blame] | 887 | entry->last_action = jiffies; |
Ivo van Doorn | 652a9dd | 2010-08-30 21:15:19 +0200 | [diff] [blame] | 888 | |
Ivo van Doorn | 10b6b80 | 2008-02-03 15:55:21 +0100 | [diff] [blame] | 889 | if (index == Q_INDEX) { |
| 890 | queue->length++; |
| 891 | } else if (index == Q_INDEX_DONE) { |
| 892 | queue->length--; |
John Daiker | 5588751 | 2008-10-17 12:16:17 -0700 | [diff] [blame] | 893 | queue->count++; |
Ivo van Doorn | 10b6b80 | 2008-02-03 15:55:21 +0100 | [diff] [blame] | 894 | } |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 895 | |
Ivo van Doorn | 813f033 | 2010-11-06 15:48:05 +0100 | [diff] [blame] | 896 | spin_unlock_irqrestore(&queue->index_lock, irqflags); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 897 | } |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 898 | |
Jingoo Han | 6cdfc1d | 2013-08-06 17:36:03 +0900 | [diff] [blame] | 899 | static void rt2x00queue_pause_queue_nocheck(struct data_queue *queue) |
Ivo van Doorn | 0b7fde5 | 2010-12-13 12:35:17 +0100 | [diff] [blame] | 900 | { |
Ivo van Doorn | 0b7fde5 | 2010-12-13 12:35:17 +0100 | [diff] [blame] | 901 | switch (queue->qid) { |
Ivo van Doorn | f615e9a | 2010-12-13 12:36:38 +0100 | [diff] [blame] | 902 | case QID_AC_VO: |
| 903 | case QID_AC_VI: |
Ivo van Doorn | 0b7fde5 | 2010-12-13 12:35:17 +0100 | [diff] [blame] | 904 | case QID_AC_BE: |
| 905 | case QID_AC_BK: |
Ivo van Doorn | 0b7fde5 | 2010-12-13 12:35:17 +0100 | [diff] [blame] | 906 | /* |
| 907 | * For TX queues, we have to disable the queue |
| 908 | * inside mac80211. |
| 909 | */ |
| 910 | ieee80211_stop_queue(queue->rt2x00dev->hw, queue->qid); |
| 911 | break; |
| 912 | default: |
| 913 | break; |
| 914 | } |
| 915 | } |
Stanislaw Gruszka | e2288b6 | 2013-07-28 13:17:22 +0200 | [diff] [blame] | 916 | void rt2x00queue_pause_queue(struct data_queue *queue) |
| 917 | { |
| 918 | if (!test_bit(DEVICE_STATE_PRESENT, &queue->rt2x00dev->flags) || |
| 919 | !test_bit(QUEUE_STARTED, &queue->flags) || |
| 920 | test_and_set_bit(QUEUE_PAUSED, &queue->flags)) |
| 921 | return; |
| 922 | |
| 923 | rt2x00queue_pause_queue_nocheck(queue); |
| 924 | } |
Ivo van Doorn | 0b7fde5 | 2010-12-13 12:35:17 +0100 | [diff] [blame] | 925 | EXPORT_SYMBOL_GPL(rt2x00queue_pause_queue); |
| 926 | |
| 927 | void rt2x00queue_unpause_queue(struct data_queue *queue) |
| 928 | { |
| 929 | if (!test_bit(DEVICE_STATE_PRESENT, &queue->rt2x00dev->flags) || |
| 930 | !test_bit(QUEUE_STARTED, &queue->flags) || |
| 931 | !test_and_clear_bit(QUEUE_PAUSED, &queue->flags)) |
| 932 | return; |
| 933 | |
| 934 | switch (queue->qid) { |
Ivo van Doorn | f615e9a | 2010-12-13 12:36:38 +0100 | [diff] [blame] | 935 | case QID_AC_VO: |
| 936 | case QID_AC_VI: |
Ivo van Doorn | 0b7fde5 | 2010-12-13 12:35:17 +0100 | [diff] [blame] | 937 | case QID_AC_BE: |
| 938 | case QID_AC_BK: |
Ivo van Doorn | 0b7fde5 | 2010-12-13 12:35:17 +0100 | [diff] [blame] | 939 | /* |
| 940 | * For TX queues, we have to enable the queue |
| 941 | * inside mac80211. |
| 942 | */ |
| 943 | ieee80211_wake_queue(queue->rt2x00dev->hw, queue->qid); |
| 944 | break; |
Ivo van Doorn | 5be6560 | 2010-12-13 12:35:40 +0100 | [diff] [blame] | 945 | case QID_RX: |
| 946 | /* |
| 947 | * For RX we need to kick the queue now in order to |
| 948 | * receive frames. |
| 949 | */ |
| 950 | queue->rt2x00dev->ops->lib->kick_queue(queue); |
Ivo van Doorn | 0b7fde5 | 2010-12-13 12:35:17 +0100 | [diff] [blame] | 951 | default: |
| 952 | break; |
| 953 | } |
| 954 | } |
| 955 | EXPORT_SYMBOL_GPL(rt2x00queue_unpause_queue); |
| 956 | |
| 957 | void rt2x00queue_start_queue(struct data_queue *queue) |
| 958 | { |
| 959 | mutex_lock(&queue->status_lock); |
| 960 | |
| 961 | if (!test_bit(DEVICE_STATE_PRESENT, &queue->rt2x00dev->flags) || |
| 962 | test_and_set_bit(QUEUE_STARTED, &queue->flags)) { |
| 963 | mutex_unlock(&queue->status_lock); |
| 964 | return; |
| 965 | } |
| 966 | |
| 967 | set_bit(QUEUE_PAUSED, &queue->flags); |
| 968 | |
| 969 | queue->rt2x00dev->ops->lib->start_queue(queue); |
| 970 | |
| 971 | rt2x00queue_unpause_queue(queue); |
| 972 | |
| 973 | mutex_unlock(&queue->status_lock); |
| 974 | } |
| 975 | EXPORT_SYMBOL_GPL(rt2x00queue_start_queue); |
| 976 | |
| 977 | void rt2x00queue_stop_queue(struct data_queue *queue) |
| 978 | { |
| 979 | mutex_lock(&queue->status_lock); |
| 980 | |
| 981 | if (!test_and_clear_bit(QUEUE_STARTED, &queue->flags)) { |
| 982 | mutex_unlock(&queue->status_lock); |
| 983 | return; |
| 984 | } |
| 985 | |
Stanislaw Gruszka | e2288b6 | 2013-07-28 13:17:22 +0200 | [diff] [blame] | 986 | rt2x00queue_pause_queue_nocheck(queue); |
Ivo van Doorn | 0b7fde5 | 2010-12-13 12:35:17 +0100 | [diff] [blame] | 987 | |
| 988 | queue->rt2x00dev->ops->lib->stop_queue(queue); |
| 989 | |
| 990 | mutex_unlock(&queue->status_lock); |
| 991 | } |
| 992 | EXPORT_SYMBOL_GPL(rt2x00queue_stop_queue); |
| 993 | |
Ivo van Doorn | 5be6560 | 2010-12-13 12:35:40 +0100 | [diff] [blame] | 994 | void rt2x00queue_flush_queue(struct data_queue *queue, bool drop) |
| 995 | { |
Ivo van Doorn | 5be6560 | 2010-12-13 12:35:40 +0100 | [diff] [blame] | 996 | bool tx_queue = |
Ivo van Doorn | f615e9a | 2010-12-13 12:36:38 +0100 | [diff] [blame] | 997 | (queue->qid == QID_AC_VO) || |
Ivo van Doorn | 5be6560 | 2010-12-13 12:35:40 +0100 | [diff] [blame] | 998 | (queue->qid == QID_AC_VI) || |
Ivo van Doorn | f615e9a | 2010-12-13 12:36:38 +0100 | [diff] [blame] | 999 | (queue->qid == QID_AC_BE) || |
| 1000 | (queue->qid == QID_AC_BK); |
Ivo van Doorn | 5be6560 | 2010-12-13 12:35:40 +0100 | [diff] [blame] | 1001 | |
Ivo van Doorn | 5be6560 | 2010-12-13 12:35:40 +0100 | [diff] [blame] | 1002 | |
| 1003 | /* |
Stanislaw Gruszka | fdbdd25 | 2013-10-05 18:15:33 +0200 | [diff] [blame] | 1004 | * If we are not supposed to drop any pending |
| 1005 | * frames, this means we must force a start (=kick) |
| 1006 | * to the queue to make sure the hardware will |
| 1007 | * start transmitting. |
Ivo van Doorn | 5be6560 | 2010-12-13 12:35:40 +0100 | [diff] [blame] | 1008 | */ |
Stanislaw Gruszka | fdbdd25 | 2013-10-05 18:15:33 +0200 | [diff] [blame] | 1009 | if (!drop && tx_queue) |
| 1010 | queue->rt2x00dev->ops->lib->kick_queue(queue); |
Ivo van Doorn | 5be6560 | 2010-12-13 12:35:40 +0100 | [diff] [blame] | 1011 | |
| 1012 | /* |
Ivo van Doorn | 152a599 | 2011-04-18 15:31:02 +0200 | [diff] [blame] | 1013 | * Check if driver supports flushing, if that is the case we can |
| 1014 | * defer the flushing to the driver. Otherwise we must use the |
| 1015 | * alternative which just waits for the queue to become empty. |
Ivo van Doorn | 5be6560 | 2010-12-13 12:35:40 +0100 | [diff] [blame] | 1016 | */ |
Ivo van Doorn | 152a599 | 2011-04-18 15:31:02 +0200 | [diff] [blame] | 1017 | if (likely(queue->rt2x00dev->ops->lib->flush_queue)) |
| 1018 | queue->rt2x00dev->ops->lib->flush_queue(queue, drop); |
Ivo van Doorn | 5be6560 | 2010-12-13 12:35:40 +0100 | [diff] [blame] | 1019 | |
| 1020 | /* |
| 1021 | * The queue flush has failed... |
| 1022 | */ |
| 1023 | if (unlikely(!rt2x00queue_empty(queue))) |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 1024 | rt2x00_warn(queue->rt2x00dev, "Queue %d failed to flush\n", |
| 1025 | queue->qid); |
Ivo van Doorn | 5be6560 | 2010-12-13 12:35:40 +0100 | [diff] [blame] | 1026 | } |
| 1027 | EXPORT_SYMBOL_GPL(rt2x00queue_flush_queue); |
| 1028 | |
Ivo van Doorn | 0b7fde5 | 2010-12-13 12:35:17 +0100 | [diff] [blame] | 1029 | void rt2x00queue_start_queues(struct rt2x00_dev *rt2x00dev) |
| 1030 | { |
| 1031 | struct data_queue *queue; |
| 1032 | |
| 1033 | /* |
| 1034 | * rt2x00queue_start_queue will call ieee80211_wake_queue |
| 1035 | * for each queue after is has been properly initialized. |
| 1036 | */ |
| 1037 | tx_queue_for_each(rt2x00dev, queue) |
| 1038 | rt2x00queue_start_queue(queue); |
| 1039 | |
| 1040 | rt2x00queue_start_queue(rt2x00dev->rx); |
| 1041 | } |
| 1042 | EXPORT_SYMBOL_GPL(rt2x00queue_start_queues); |
| 1043 | |
| 1044 | void rt2x00queue_stop_queues(struct rt2x00_dev *rt2x00dev) |
| 1045 | { |
| 1046 | struct data_queue *queue; |
| 1047 | |
| 1048 | /* |
| 1049 | * rt2x00queue_stop_queue will call ieee80211_stop_queue |
| 1050 | * as well, but we are completely shutting doing everything |
| 1051 | * now, so it is much safer to stop all TX queues at once, |
| 1052 | * and use rt2x00queue_stop_queue for cleaning up. |
| 1053 | */ |
| 1054 | ieee80211_stop_queues(rt2x00dev->hw); |
| 1055 | |
| 1056 | tx_queue_for_each(rt2x00dev, queue) |
| 1057 | rt2x00queue_stop_queue(queue); |
| 1058 | |
| 1059 | rt2x00queue_stop_queue(rt2x00dev->rx); |
| 1060 | } |
| 1061 | EXPORT_SYMBOL_GPL(rt2x00queue_stop_queues); |
| 1062 | |
Ivo van Doorn | 5be6560 | 2010-12-13 12:35:40 +0100 | [diff] [blame] | 1063 | void rt2x00queue_flush_queues(struct rt2x00_dev *rt2x00dev, bool drop) |
| 1064 | { |
| 1065 | struct data_queue *queue; |
| 1066 | |
| 1067 | tx_queue_for_each(rt2x00dev, queue) |
| 1068 | rt2x00queue_flush_queue(queue, drop); |
| 1069 | |
| 1070 | rt2x00queue_flush_queue(rt2x00dev->rx, drop); |
| 1071 | } |
| 1072 | EXPORT_SYMBOL_GPL(rt2x00queue_flush_queues); |
| 1073 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1074 | static void rt2x00queue_reset(struct data_queue *queue) |
| 1075 | { |
Ivo van Doorn | 5f46c4d | 2008-03-09 22:44:30 +0100 | [diff] [blame] | 1076 | unsigned long irqflags; |
Ivo van Doorn | 652a9dd | 2010-08-30 21:15:19 +0200 | [diff] [blame] | 1077 | unsigned int i; |
Ivo van Doorn | 5f46c4d | 2008-03-09 22:44:30 +0100 | [diff] [blame] | 1078 | |
Ivo van Doorn | 813f033 | 2010-11-06 15:48:05 +0100 | [diff] [blame] | 1079 | spin_lock_irqsave(&queue->index_lock, irqflags); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1080 | |
| 1081 | queue->count = 0; |
| 1082 | queue->length = 0; |
Ivo van Doorn | 652a9dd | 2010-08-30 21:15:19 +0200 | [diff] [blame] | 1083 | |
Johannes Stezenbach | 75256f0 | 2011-04-18 15:29:38 +0200 | [diff] [blame] | 1084 | for (i = 0; i < Q_INDEX_MAX; i++) |
Ivo van Doorn | 652a9dd | 2010-08-30 21:15:19 +0200 | [diff] [blame] | 1085 | queue->index[i] = 0; |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1086 | |
Ivo van Doorn | 813f033 | 2010-11-06 15:48:05 +0100 | [diff] [blame] | 1087 | spin_unlock_irqrestore(&queue->index_lock, irqflags); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1088 | } |
| 1089 | |
Ivo van Doorn | 798b7ad | 2008-11-08 15:25:33 +0100 | [diff] [blame] | 1090 | void rt2x00queue_init_queues(struct rt2x00_dev *rt2x00dev) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1091 | { |
| 1092 | struct data_queue *queue; |
| 1093 | unsigned int i; |
| 1094 | |
Ivo van Doorn | 798b7ad | 2008-11-08 15:25:33 +0100 | [diff] [blame] | 1095 | queue_for_each(rt2x00dev, queue) { |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1096 | rt2x00queue_reset(queue); |
| 1097 | |
Ivo van Doorn | 64e7d72 | 2010-12-13 12:36:00 +0100 | [diff] [blame] | 1098 | for (i = 0; i < queue->limit; i++) |
Ivo van Doorn | 798b7ad | 2008-11-08 15:25:33 +0100 | [diff] [blame] | 1099 | rt2x00dev->ops->lib->clear_entry(&queue->entries[i]); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1100 | } |
| 1101 | } |
| 1102 | |
Gabor Juhos | 15d6c07 | 2013-06-04 13:40:39 +0200 | [diff] [blame] | 1103 | static int rt2x00queue_alloc_entries(struct data_queue *queue) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1104 | { |
| 1105 | struct queue_entry *entries; |
| 1106 | unsigned int entry_size; |
| 1107 | unsigned int i; |
| 1108 | |
| 1109 | rt2x00queue_reset(queue); |
| 1110 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1111 | /* |
| 1112 | * Allocate all queue entries. |
| 1113 | */ |
Gabor Juhos | 568f7a4 | 2013-06-04 13:40:38 +0200 | [diff] [blame] | 1114 | entry_size = sizeof(*entries) + queue->priv_size; |
Joe Perches | baeb2ff | 2010-08-11 07:02:48 +0000 | [diff] [blame] | 1115 | entries = kcalloc(queue->limit, entry_size, GFP_KERNEL); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1116 | if (!entries) |
| 1117 | return -ENOMEM; |
| 1118 | |
| 1119 | #define QUEUE_ENTRY_PRIV_OFFSET(__base, __index, __limit, __esize, __psize) \ |
Mark Einon | f8bfbc3 | 2010-11-06 15:47:25 +0100 | [diff] [blame] | 1120 | (((char *)(__base)) + ((__limit) * (__esize)) + \ |
| 1121 | ((__index) * (__psize))) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1122 | |
| 1123 | for (i = 0; i < queue->limit; i++) { |
| 1124 | entries[i].flags = 0; |
| 1125 | entries[i].queue = queue; |
| 1126 | entries[i].skb = NULL; |
| 1127 | entries[i].entry_idx = i; |
| 1128 | entries[i].priv_data = |
| 1129 | QUEUE_ENTRY_PRIV_OFFSET(entries, i, queue->limit, |
Gabor Juhos | 568f7a4 | 2013-06-04 13:40:38 +0200 | [diff] [blame] | 1130 | sizeof(*entries), queue->priv_size); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | #undef QUEUE_ENTRY_PRIV_OFFSET |
| 1134 | |
| 1135 | queue->entries = entries; |
| 1136 | |
| 1137 | return 0; |
| 1138 | } |
| 1139 | |
Ivo van Doorn | fa69560 | 2010-10-11 15:37:25 +0200 | [diff] [blame] | 1140 | static void rt2x00queue_free_skbs(struct data_queue *queue) |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 1141 | { |
| 1142 | unsigned int i; |
| 1143 | |
| 1144 | if (!queue->entries) |
| 1145 | return; |
| 1146 | |
| 1147 | for (i = 0; i < queue->limit; i++) { |
Ivo van Doorn | fa69560 | 2010-10-11 15:37:25 +0200 | [diff] [blame] | 1148 | rt2x00queue_free_skb(&queue->entries[i]); |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 1149 | } |
| 1150 | } |
| 1151 | |
Ivo van Doorn | fa69560 | 2010-10-11 15:37:25 +0200 | [diff] [blame] | 1152 | static int rt2x00queue_alloc_rxskbs(struct data_queue *queue) |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 1153 | { |
| 1154 | unsigned int i; |
| 1155 | struct sk_buff *skb; |
| 1156 | |
| 1157 | for (i = 0; i < queue->limit; i++) { |
Helmut Schaa | 8821102 | 2012-04-19 13:24:10 +0200 | [diff] [blame] | 1158 | skb = rt2x00queue_alloc_rxskb(&queue->entries[i], GFP_KERNEL); |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 1159 | if (!skb) |
Ivo van Doorn | 61243d8 | 2008-06-20 22:10:53 +0200 | [diff] [blame] | 1160 | return -ENOMEM; |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 1161 | queue->entries[i].skb = skb; |
| 1162 | } |
| 1163 | |
| 1164 | return 0; |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 1165 | } |
| 1166 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1167 | int rt2x00queue_initialize(struct rt2x00_dev *rt2x00dev) |
| 1168 | { |
| 1169 | struct data_queue *queue; |
| 1170 | int status; |
| 1171 | |
Gabor Juhos | 15d6c07 | 2013-06-04 13:40:39 +0200 | [diff] [blame] | 1172 | status = rt2x00queue_alloc_entries(rt2x00dev->rx); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1173 | if (status) |
| 1174 | goto exit; |
| 1175 | |
| 1176 | tx_queue_for_each(rt2x00dev, queue) { |
Gabor Juhos | 15d6c07 | 2013-06-04 13:40:39 +0200 | [diff] [blame] | 1177 | status = rt2x00queue_alloc_entries(queue); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1178 | if (status) |
| 1179 | goto exit; |
| 1180 | } |
| 1181 | |
Gabor Juhos | 15d6c07 | 2013-06-04 13:40:39 +0200 | [diff] [blame] | 1182 | status = rt2x00queue_alloc_entries(rt2x00dev->bcn); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1183 | if (status) |
| 1184 | goto exit; |
| 1185 | |
Fred Chou | b9d305c | 2014-12-26 16:19:18 +0800 | [diff] [blame] | 1186 | if (rt2x00_has_cap_flag(rt2x00dev, REQUIRE_ATIM_QUEUE)) { |
Gabor Juhos | 15d6c07 | 2013-06-04 13:40:39 +0200 | [diff] [blame] | 1187 | status = rt2x00queue_alloc_entries(rt2x00dev->atim); |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 1188 | if (status) |
| 1189 | goto exit; |
| 1190 | } |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1191 | |
Ivo van Doorn | fa69560 | 2010-10-11 15:37:25 +0200 | [diff] [blame] | 1192 | status = rt2x00queue_alloc_rxskbs(rt2x00dev->rx); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1193 | if (status) |
| 1194 | goto exit; |
| 1195 | |
| 1196 | return 0; |
| 1197 | |
| 1198 | exit: |
Joe Perches | ec9c498 | 2013-04-19 08:33:40 -0700 | [diff] [blame] | 1199 | rt2x00_err(rt2x00dev, "Queue entries allocation failed\n"); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1200 | |
| 1201 | rt2x00queue_uninitialize(rt2x00dev); |
| 1202 | |
| 1203 | return status; |
| 1204 | } |
| 1205 | |
| 1206 | void rt2x00queue_uninitialize(struct rt2x00_dev *rt2x00dev) |
| 1207 | { |
| 1208 | struct data_queue *queue; |
| 1209 | |
Ivo van Doorn | fa69560 | 2010-10-11 15:37:25 +0200 | [diff] [blame] | 1210 | rt2x00queue_free_skbs(rt2x00dev->rx); |
Gertjan van Wingerde | 30caa6e | 2008-06-16 19:56:08 +0200 | [diff] [blame] | 1211 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1212 | queue_for_each(rt2x00dev, queue) { |
| 1213 | kfree(queue->entries); |
| 1214 | queue->entries = NULL; |
| 1215 | } |
| 1216 | } |
| 1217 | |
Ivo van Doorn | 8f53927 | 2008-02-10 22:51:41 +0100 | [diff] [blame] | 1218 | static void rt2x00queue_init(struct rt2x00_dev *rt2x00dev, |
| 1219 | struct data_queue *queue, enum data_queue_qid qid) |
| 1220 | { |
Ivo van Doorn | 0b7fde5 | 2010-12-13 12:35:17 +0100 | [diff] [blame] | 1221 | mutex_init(&queue->status_lock); |
Gertjan van Wingerde | 77a861c | 2011-07-06 22:56:24 +0200 | [diff] [blame] | 1222 | spin_lock_init(&queue->tx_lock); |
Ivo van Doorn | 813f033 | 2010-11-06 15:48:05 +0100 | [diff] [blame] | 1223 | spin_lock_init(&queue->index_lock); |
Ivo van Doorn | 8f53927 | 2008-02-10 22:51:41 +0100 | [diff] [blame] | 1224 | |
| 1225 | queue->rt2x00dev = rt2x00dev; |
| 1226 | queue->qid = qid; |
Ivo van Doorn | 2af0a57 | 2008-08-29 21:05:45 +0200 | [diff] [blame] | 1227 | queue->txop = 0; |
Ivo van Doorn | 8f53927 | 2008-02-10 22:51:41 +0100 | [diff] [blame] | 1228 | queue->aifs = 2; |
| 1229 | queue->cw_min = 5; |
| 1230 | queue->cw_max = 10; |
Gabor Juhos | 10af87c | 2013-06-03 23:39:53 +0200 | [diff] [blame] | 1231 | |
Gabor Juhos | 705802b | 2013-06-04 13:40:50 +0200 | [diff] [blame] | 1232 | rt2x00dev->ops->queue_init(queue); |
Gabor Juhos | 04453e9 | 2013-06-04 13:40:41 +0200 | [diff] [blame] | 1233 | |
| 1234 | queue->threshold = DIV_ROUND_UP(queue->limit, 10); |
Ivo van Doorn | 8f53927 | 2008-02-10 22:51:41 +0100 | [diff] [blame] | 1235 | } |
| 1236 | |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1237 | int rt2x00queue_allocate(struct rt2x00_dev *rt2x00dev) |
| 1238 | { |
| 1239 | struct data_queue *queue; |
| 1240 | enum data_queue_qid qid; |
| 1241 | unsigned int req_atim = |
Fred Chou | b9d305c | 2014-12-26 16:19:18 +0800 | [diff] [blame] | 1242 | rt2x00_has_cap_flag(rt2x00dev, REQUIRE_ATIM_QUEUE); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1243 | |
| 1244 | /* |
| 1245 | * We need the following queues: |
| 1246 | * RX: 1 |
Gertjan van Wingerde | 61448f8 | 2008-05-10 13:43:33 +0200 | [diff] [blame] | 1247 | * TX: ops->tx_queues |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1248 | * Beacon: 1 |
| 1249 | * Atim: 1 (if required) |
| 1250 | */ |
Gertjan van Wingerde | 61448f8 | 2008-05-10 13:43:33 +0200 | [diff] [blame] | 1251 | rt2x00dev->data_queues = 2 + rt2x00dev->ops->tx_queues + req_atim; |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1252 | |
Joe Perches | baeb2ff | 2010-08-11 07:02:48 +0000 | [diff] [blame] | 1253 | queue = kcalloc(rt2x00dev->data_queues, sizeof(*queue), GFP_KERNEL); |
Markus Elfring | cd7c0cd | 2017-12-29 22:11:42 +0100 | [diff] [blame] | 1254 | if (!queue) |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1255 | return -ENOMEM; |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1256 | |
| 1257 | /* |
| 1258 | * Initialize pointers |
| 1259 | */ |
| 1260 | rt2x00dev->rx = queue; |
| 1261 | rt2x00dev->tx = &queue[1]; |
Gertjan van Wingerde | 61448f8 | 2008-05-10 13:43:33 +0200 | [diff] [blame] | 1262 | rt2x00dev->bcn = &queue[1 + rt2x00dev->ops->tx_queues]; |
Gertjan van Wingerde | e74df4a | 2011-03-03 19:46:09 +0100 | [diff] [blame] | 1263 | rt2x00dev->atim = req_atim ? &queue[2 + rt2x00dev->ops->tx_queues] : NULL; |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1264 | |
| 1265 | /* |
| 1266 | * Initialize queue parameters. |
| 1267 | * RX: qid = QID_RX |
Ivo van Doorn | f615e9a | 2010-12-13 12:36:38 +0100 | [diff] [blame] | 1268 | * TX: qid = QID_AC_VO + index |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1269 | * TX: cw_min: 2^5 = 32. |
| 1270 | * TX: cw_max: 2^10 = 1024. |
Ivo van Doorn | 565a019 | 2008-06-03 20:29:05 +0200 | [diff] [blame] | 1271 | * BCN: qid = QID_BEACON |
| 1272 | * ATIM: qid = QID_ATIM |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1273 | */ |
Ivo van Doorn | 8f53927 | 2008-02-10 22:51:41 +0100 | [diff] [blame] | 1274 | rt2x00queue_init(rt2x00dev, rt2x00dev->rx, QID_RX); |
| 1275 | |
Ivo van Doorn | f615e9a | 2010-12-13 12:36:38 +0100 | [diff] [blame] | 1276 | qid = QID_AC_VO; |
Ivo van Doorn | 8f53927 | 2008-02-10 22:51:41 +0100 | [diff] [blame] | 1277 | tx_queue_for_each(rt2x00dev, queue) |
| 1278 | rt2x00queue_init(rt2x00dev, queue, qid++); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1279 | |
Gertjan van Wingerde | e74df4a | 2011-03-03 19:46:09 +0100 | [diff] [blame] | 1280 | rt2x00queue_init(rt2x00dev, rt2x00dev->bcn, QID_BEACON); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1281 | if (req_atim) |
Gertjan van Wingerde | e74df4a | 2011-03-03 19:46:09 +0100 | [diff] [blame] | 1282 | rt2x00queue_init(rt2x00dev, rt2x00dev->atim, QID_ATIM); |
Ivo van Doorn | 181d690 | 2008-02-05 16:42:23 -0500 | [diff] [blame] | 1283 | |
| 1284 | return 0; |
| 1285 | } |
| 1286 | |
| 1287 | void rt2x00queue_free(struct rt2x00_dev *rt2x00dev) |
| 1288 | { |
| 1289 | kfree(rt2x00dev->rx); |
| 1290 | rt2x00dev->rx = NULL; |
| 1291 | rt2x00dev->tx = NULL; |
| 1292 | rt2x00dev->bcn = NULL; |
| 1293 | } |