Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1 | /* |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 2 | * Copyright (c) 2012-2017 Qualcomm Atheros, Inc. |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 18 | #include <net/ieee80211_radiotap.h> |
| 19 | #include <linux/if_arp.h> |
| 20 | #include <linux/moduleparam.h> |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 21 | #include <linux/ip.h> |
| 22 | #include <linux/ipv6.h> |
| 23 | #include <net/ipv6.h> |
Vladimir Kondratiev | 0786dc4 | 2014-01-14 20:31:26 +0200 | [diff] [blame] | 24 | #include <linux/prefetch.h> |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 25 | |
| 26 | #include "wil6210.h" |
| 27 | #include "wmi.h" |
| 28 | #include "txrx.h" |
Vladimir Kondratiev | 9865809 | 2013-05-12 14:43:35 +0300 | [diff] [blame] | 29 | #include "trace.h" |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 30 | |
| 31 | static bool rtap_include_phy_info; |
Maya Erez | c2256ec | 2017-02-08 13:18:42 +0200 | [diff] [blame^] | 32 | module_param(rtap_include_phy_info, bool, 0444); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 33 | MODULE_PARM_DESC(rtap_include_phy_info, |
| 34 | " Include PHY info in the radiotap header, default - no"); |
| 35 | |
Vladimir Kondratiev | c406ea7 | 2015-03-15 16:00:19 +0200 | [diff] [blame] | 36 | bool rx_align_2; |
Maya Erez | c2256ec | 2017-02-08 13:18:42 +0200 | [diff] [blame^] | 37 | module_param(rx_align_2, bool, 0444); |
Vladimir Kondratiev | c406ea7 | 2015-03-15 16:00:19 +0200 | [diff] [blame] | 38 | MODULE_PARM_DESC(rx_align_2, " align Rx buffers on 4*n+2, default - no"); |
| 39 | |
| 40 | static inline uint wil_rx_snaplen(void) |
| 41 | { |
| 42 | return rx_align_2 ? 6 : 0; |
| 43 | } |
| 44 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 45 | static inline int wil_vring_is_empty(struct vring *vring) |
| 46 | { |
| 47 | return vring->swhead == vring->swtail; |
| 48 | } |
| 49 | |
| 50 | static inline u32 wil_vring_next_tail(struct vring *vring) |
| 51 | { |
| 52 | return (vring->swtail + 1) % vring->size; |
| 53 | } |
| 54 | |
| 55 | static inline void wil_vring_advance_head(struct vring *vring, int n) |
| 56 | { |
| 57 | vring->swhead = (vring->swhead + n) % vring->size; |
| 58 | } |
| 59 | |
| 60 | static inline int wil_vring_is_full(struct vring *vring) |
| 61 | { |
| 62 | return wil_vring_next_tail(vring) == vring->swhead; |
| 63 | } |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 64 | |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 65 | /* Used space in Tx Vring */ |
| 66 | static inline int wil_vring_used_tx(struct vring *vring) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 67 | { |
| 68 | u32 swhead = vring->swhead; |
| 69 | u32 swtail = vring->swtail; |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 70 | return (vring->size + swhead - swtail) % vring->size; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 73 | /* Available space in Tx Vring */ |
| 74 | static inline int wil_vring_avail_tx(struct vring *vring) |
| 75 | { |
| 76 | return vring->size - wil_vring_used_tx(vring) - 1; |
| 77 | } |
| 78 | |
| 79 | /* wil_vring_wmark_low - low watermark for available descriptor space */ |
Vladimir Kondratiev | 5bb6423 | 2014-05-27 14:45:46 +0300 | [diff] [blame] | 80 | static inline int wil_vring_wmark_low(struct vring *vring) |
| 81 | { |
| 82 | return vring->size/8; |
| 83 | } |
| 84 | |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 85 | /* wil_vring_wmark_high - high watermark for available descriptor space */ |
Vladimir Kondratiev | 5bb6423 | 2014-05-27 14:45:46 +0300 | [diff] [blame] | 86 | static inline int wil_vring_wmark_high(struct vring *vring) |
| 87 | { |
| 88 | return vring->size/4; |
| 89 | } |
| 90 | |
Dedy Lansky | 970a98f | 2016-12-06 08:26:49 +0200 | [diff] [blame] | 91 | /* returns true if num avail descriptors is lower than wmark_low */ |
| 92 | static inline int wil_vring_avail_low(struct vring *vring) |
| 93 | { |
| 94 | return wil_vring_avail_tx(vring) < wil_vring_wmark_low(vring); |
| 95 | } |
| 96 | |
| 97 | /* returns true if num avail descriptors is higher than wmark_high */ |
| 98 | static inline int wil_vring_avail_high(struct vring *vring) |
| 99 | { |
| 100 | return wil_vring_avail_tx(vring) > wil_vring_wmark_high(vring); |
| 101 | } |
| 102 | |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 103 | /* wil_val_in_range - check if value in [min,max) */ |
| 104 | static inline bool wil_val_in_range(int val, int min, int max) |
| 105 | { |
| 106 | return val >= min && val < max; |
| 107 | } |
| 108 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 109 | static int wil_vring_alloc(struct wil6210_priv *wil, struct vring *vring) |
| 110 | { |
| 111 | struct device *dev = wil_to_dev(wil); |
| 112 | size_t sz = vring->size * sizeof(vring->va[0]); |
| 113 | uint i; |
| 114 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 115 | wil_dbg_misc(wil, "vring_alloc:\n"); |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 116 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 117 | BUILD_BUG_ON(sizeof(vring->va[0]) != 32); |
| 118 | |
| 119 | vring->swhead = 0; |
| 120 | vring->swtail = 0; |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 121 | vring->ctx = kcalloc(vring->size, sizeof(vring->ctx[0]), GFP_KERNEL); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 122 | if (!vring->ctx) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 123 | vring->va = NULL; |
| 124 | return -ENOMEM; |
| 125 | } |
Hamad Kadmany | 8b5dc9c | 2017-02-16 10:59:10 +0200 | [diff] [blame] | 126 | |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 127 | /* vring->va should be aligned on its size rounded up to power of 2 |
Hamad Kadmany | 8b5dc9c | 2017-02-16 10:59:10 +0200 | [diff] [blame] | 128 | * This is granted by the dma_alloc_coherent. |
| 129 | * |
| 130 | * HW has limitation that all vrings addresses must share the same |
| 131 | * upper 16 msb bits part of 48 bits address. To workaround that, |
| 132 | * if we are using 48 bit addresses switch to 32 bit allocation |
| 133 | * before allocating vring memory. |
| 134 | * |
| 135 | * There's no check for the return value of dma_set_mask_and_coherent, |
| 136 | * since we assume if we were able to set the mask during |
| 137 | * initialization in this system it will not fail if we set it again |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 138 | */ |
Hamad Kadmany | 8b5dc9c | 2017-02-16 10:59:10 +0200 | [diff] [blame] | 139 | if (wil->use_extended_dma_addr) |
| 140 | dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); |
| 141 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 142 | vring->va = dma_alloc_coherent(dev, sz, &vring->pa, GFP_KERNEL); |
| 143 | if (!vring->va) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 144 | kfree(vring->ctx); |
| 145 | vring->ctx = NULL; |
| 146 | return -ENOMEM; |
| 147 | } |
Hamad Kadmany | 8b5dc9c | 2017-02-16 10:59:10 +0200 | [diff] [blame] | 148 | |
| 149 | if (wil->use_extended_dma_addr) |
| 150 | dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48)); |
| 151 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 152 | /* initially, all descriptors are SW owned |
| 153 | * For Tx and Rx, ownership bit is at the same location, thus |
| 154 | * we can use any |
| 155 | */ |
| 156 | for (i = 0; i < vring->size; i++) { |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 157 | volatile struct vring_tx_desc *_d = &vring->va[i].tx; |
| 158 | |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 159 | _d->dma.status = TX_DMA_STATUS_DU; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 160 | } |
| 161 | |
Vladimir Kondratiev | 39c52ee | 2014-05-27 14:45:49 +0300 | [diff] [blame] | 162 | wil_dbg_misc(wil, "vring[%d] 0x%p:%pad 0x%p\n", vring->size, |
| 163 | vring->va, &vring->pa, vring->ctx); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 168 | static void wil_txdesc_unmap(struct device *dev, struct vring_tx_desc *d, |
| 169 | struct wil_ctx *ctx) |
| 170 | { |
| 171 | dma_addr_t pa = wil_desc_addr(&d->dma.addr); |
| 172 | u16 dmalen = le16_to_cpu(d->dma.length); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 173 | |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 174 | switch (ctx->mapped_as) { |
| 175 | case wil_mapped_as_single: |
| 176 | dma_unmap_single(dev, pa, dmalen, DMA_TO_DEVICE); |
| 177 | break; |
| 178 | case wil_mapped_as_page: |
| 179 | dma_unmap_page(dev, pa, dmalen, DMA_TO_DEVICE); |
| 180 | break; |
| 181 | default: |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 186 | static void wil_vring_free(struct wil6210_priv *wil, struct vring *vring, |
| 187 | int tx) |
| 188 | { |
| 189 | struct device *dev = wil_to_dev(wil); |
| 190 | size_t sz = vring->size * sizeof(vring->va[0]); |
| 191 | |
Vladimir Kondratiev | 9b1ba7b | 2015-11-06 12:50:44 +0200 | [diff] [blame] | 192 | lockdep_assert_held(&wil->mutex); |
Vladimir Kondratiev | ef77285 | 2014-09-10 16:34:31 +0300 | [diff] [blame] | 193 | if (tx) { |
| 194 | int vring_index = vring - wil->vring_tx; |
| 195 | |
| 196 | wil_dbg_misc(wil, "free Tx vring %d [%d] 0x%p:%pad 0x%p\n", |
| 197 | vring_index, vring->size, vring->va, |
| 198 | &vring->pa, vring->ctx); |
| 199 | } else { |
| 200 | wil_dbg_misc(wil, "free Rx vring [%d] 0x%p:%pad 0x%p\n", |
| 201 | vring->size, vring->va, |
| 202 | &vring->pa, vring->ctx); |
| 203 | } |
| 204 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 205 | while (!wil_vring_is_empty(vring)) { |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 206 | dma_addr_t pa; |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 207 | u16 dmalen; |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 208 | struct wil_ctx *ctx; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 209 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 210 | if (tx) { |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 211 | struct vring_tx_desc dd, *d = ⅆ |
| 212 | volatile struct vring_tx_desc *_d = |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 213 | &vring->va[vring->swtail].tx; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 214 | |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 215 | ctx = &vring->ctx[vring->swtail]; |
Maya Erez | 34b8886 | 2016-05-16 22:23:32 +0300 | [diff] [blame] | 216 | if (!ctx) { |
| 217 | wil_dbg_txrx(wil, |
| 218 | "ctx(%d) was already completed\n", |
| 219 | vring->swtail); |
| 220 | vring->swtail = wil_vring_next_tail(vring); |
| 221 | continue; |
| 222 | } |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 223 | *d = *_d; |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 224 | wil_txdesc_unmap(dev, d, ctx); |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 225 | if (ctx->skb) |
| 226 | dev_kfree_skb_any(ctx->skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 227 | vring->swtail = wil_vring_next_tail(vring); |
| 228 | } else { /* rx */ |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 229 | struct vring_rx_desc dd, *d = ⅆ |
| 230 | volatile struct vring_rx_desc *_d = |
Vladimir Kondratiev | 4d1ac07 | 2013-07-11 18:03:38 +0300 | [diff] [blame] | 231 | &vring->va[vring->swhead].rx; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 232 | |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 233 | ctx = &vring->ctx[vring->swhead]; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 234 | *d = *_d; |
| 235 | pa = wil_desc_addr(&d->dma.addr); |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 236 | dmalen = le16_to_cpu(d->dma.length); |
| 237 | dma_unmap_single(dev, pa, dmalen, DMA_FROM_DEVICE); |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 238 | kfree_skb(ctx->skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 239 | wil_vring_advance_head(vring, 1); |
| 240 | } |
| 241 | } |
| 242 | dma_free_coherent(dev, sz, (void *)vring->va, vring->pa); |
| 243 | kfree(vring->ctx); |
| 244 | vring->pa = 0; |
| 245 | vring->va = NULL; |
| 246 | vring->ctx = NULL; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Allocate one skb for Rx VRING |
| 251 | * |
| 252 | * Safe to call from IRQ |
| 253 | */ |
| 254 | static int wil_vring_alloc_skb(struct wil6210_priv *wil, struct vring *vring, |
| 255 | u32 i, int headroom) |
| 256 | { |
| 257 | struct device *dev = wil_to_dev(wil); |
Vladimir Kondratiev | c406ea7 | 2015-03-15 16:00:19 +0200 | [diff] [blame] | 258 | unsigned int sz = mtu_max + ETH_HLEN + wil_rx_snaplen(); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 259 | struct vring_rx_desc dd, *d = ⅆ |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 260 | volatile struct vring_rx_desc *_d = &vring->va[i].rx; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 261 | dma_addr_t pa; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 262 | struct sk_buff *skb = dev_alloc_skb(sz + headroom); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 263 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 264 | if (unlikely(!skb)) |
| 265 | return -ENOMEM; |
| 266 | |
| 267 | skb_reserve(skb, headroom); |
| 268 | skb_put(skb, sz); |
| 269 | |
| 270 | pa = dma_map_single(dev, skb->data, skb->len, DMA_FROM_DEVICE); |
| 271 | if (unlikely(dma_mapping_error(dev, pa))) { |
| 272 | kfree_skb(skb); |
| 273 | return -ENOMEM; |
| 274 | } |
| 275 | |
Vladimir Kondratiev | 48c963a | 2015-04-30 16:25:06 +0300 | [diff] [blame] | 276 | d->dma.d0 = RX_DMA_D0_CMD_DMA_RT | RX_DMA_D0_CMD_DMA_IT; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 277 | wil_desc_addr_set(&d->dma.addr, pa); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 278 | /* ip_length don't care */ |
| 279 | /* b11 don't care */ |
| 280 | /* error don't care */ |
| 281 | d->dma.status = 0; /* BIT(0) should be 0 for HW_OWNED */ |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 282 | d->dma.length = cpu_to_le16(sz); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 283 | *_d = *d; |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 284 | vring->ctx[i].skb = skb; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 285 | |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * Adds radiotap header |
| 291 | * |
| 292 | * Any error indicated as "Bad FCS" |
| 293 | * |
| 294 | * Vendor data for 04:ce:14-1 (Wilocity-1) consists of: |
| 295 | * - Rx descriptor: 32 bytes |
| 296 | * - Phy info |
| 297 | */ |
| 298 | static void wil_rx_add_radiotap_header(struct wil6210_priv *wil, |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 299 | struct sk_buff *skb) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 300 | { |
| 301 | struct wireless_dev *wdev = wil->wdev; |
| 302 | struct wil6210_rtap { |
| 303 | struct ieee80211_radiotap_header rthdr; |
| 304 | /* fields should be in the order of bits in rthdr.it_present */ |
| 305 | /* flags */ |
| 306 | u8 flags; |
| 307 | /* channel */ |
| 308 | __le16 chnl_freq __aligned(2); |
| 309 | __le16 chnl_flags; |
| 310 | /* MCS */ |
| 311 | u8 mcs_present; |
| 312 | u8 mcs_flags; |
| 313 | u8 mcs_index; |
| 314 | } __packed; |
| 315 | struct wil6210_rtap_vendor { |
| 316 | struct wil6210_rtap rtap; |
| 317 | /* vendor */ |
| 318 | u8 vendor_oui[3] __aligned(2); |
| 319 | u8 vendor_ns; |
| 320 | __le16 vendor_skip; |
| 321 | u8 vendor_data[0]; |
| 322 | } __packed; |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 323 | struct vring_rx_desc *d = wil_skb_rxdesc(skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 324 | struct wil6210_rtap_vendor *rtap_vendor; |
| 325 | int rtap_len = sizeof(struct wil6210_rtap); |
| 326 | int phy_length = 0; /* phy info header size, bytes */ |
| 327 | static char phy_data[128]; |
| 328 | struct ieee80211_channel *ch = wdev->preset_chandef.chan; |
| 329 | |
| 330 | if (rtap_include_phy_info) { |
| 331 | rtap_len = sizeof(*rtap_vendor) + sizeof(*d); |
| 332 | /* calculate additional length */ |
| 333 | if (d->dma.status & RX_DMA_STATUS_PHY_INFO) { |
| 334 | /** |
| 335 | * PHY info starts from 8-byte boundary |
| 336 | * there are 8-byte lines, last line may be partially |
| 337 | * written (HW bug), thus FW configures for last line |
| 338 | * to be excessive. Driver skips this last line. |
| 339 | */ |
| 340 | int len = min_t(int, 8 + sizeof(phy_data), |
| 341 | wil_rxdesc_phy_length(d)); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 342 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 343 | if (len > 8) { |
| 344 | void *p = skb_tail_pointer(skb); |
| 345 | void *pa = PTR_ALIGN(p, 8); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 346 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 347 | if (skb_tailroom(skb) >= len + (pa - p)) { |
| 348 | phy_length = len - 8; |
| 349 | memcpy(phy_data, pa, phy_length); |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | rtap_len += phy_length; |
| 354 | } |
| 355 | |
| 356 | if (skb_headroom(skb) < rtap_len && |
| 357 | pskb_expand_head(skb, rtap_len, 0, GFP_ATOMIC)) { |
| 358 | wil_err(wil, "Unable to expand headrom to %d\n", rtap_len); |
| 359 | return; |
| 360 | } |
| 361 | |
| 362 | rtap_vendor = (void *)skb_push(skb, rtap_len); |
| 363 | memset(rtap_vendor, 0, rtap_len); |
| 364 | |
| 365 | rtap_vendor->rtap.rthdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 366 | rtap_vendor->rtap.rthdr.it_len = cpu_to_le16(rtap_len); |
| 367 | rtap_vendor->rtap.rthdr.it_present = cpu_to_le32( |
| 368 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
| 369 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 370 | (1 << IEEE80211_RADIOTAP_MCS)); |
| 371 | if (d->dma.status & RX_DMA_STATUS_ERROR) |
| 372 | rtap_vendor->rtap.flags |= IEEE80211_RADIOTAP_F_BADFCS; |
| 373 | |
| 374 | rtap_vendor->rtap.chnl_freq = cpu_to_le16(ch ? ch->center_freq : 58320); |
| 375 | rtap_vendor->rtap.chnl_flags = cpu_to_le16(0); |
| 376 | |
| 377 | rtap_vendor->rtap.mcs_present = IEEE80211_RADIOTAP_MCS_HAVE_MCS; |
| 378 | rtap_vendor->rtap.mcs_flags = 0; |
| 379 | rtap_vendor->rtap.mcs_index = wil_rxdesc_mcs(d); |
| 380 | |
| 381 | if (rtap_include_phy_info) { |
| 382 | rtap_vendor->rtap.rthdr.it_present |= cpu_to_le32(1 << |
| 383 | IEEE80211_RADIOTAP_VENDOR_NAMESPACE); |
| 384 | /* OUI for Wilocity 04:ce:14 */ |
| 385 | rtap_vendor->vendor_oui[0] = 0x04; |
| 386 | rtap_vendor->vendor_oui[1] = 0xce; |
| 387 | rtap_vendor->vendor_oui[2] = 0x14; |
| 388 | rtap_vendor->vendor_ns = 1; |
| 389 | /* Rx descriptor + PHY data */ |
| 390 | rtap_vendor->vendor_skip = cpu_to_le16(sizeof(*d) + |
| 391 | phy_length); |
| 392 | memcpy(rtap_vendor->vendor_data, (void *)d, sizeof(*d)); |
| 393 | memcpy(rtap_vendor->vendor_data + sizeof(*d), phy_data, |
| 394 | phy_length); |
| 395 | } |
| 396 | } |
| 397 | |
Vladimir Kondratiev | a831334 | 2015-10-04 10:23:23 +0300 | [diff] [blame] | 398 | /* similar to ieee80211_ version, but FC contain only 1-st byte */ |
| 399 | static inline int wil_is_back_req(u8 fc) |
| 400 | { |
| 401 | return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) == |
| 402 | (IEEE80211_FTYPE_CTL | IEEE80211_STYPE_BACK_REQ); |
| 403 | } |
| 404 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 405 | /** |
| 406 | * reap 1 frame from @swhead |
| 407 | * |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 408 | * Rx descriptor copied to skb->cb |
| 409 | * |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 410 | * Safe to call from IRQ |
| 411 | */ |
| 412 | static struct sk_buff *wil_vring_reap_rx(struct wil6210_priv *wil, |
| 413 | struct vring *vring) |
| 414 | { |
| 415 | struct device *dev = wil_to_dev(wil); |
| 416 | struct net_device *ndev = wil_to_ndev(wil); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 417 | volatile struct vring_rx_desc *_d; |
| 418 | struct vring_rx_desc *d; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 419 | struct sk_buff *skb; |
| 420 | dma_addr_t pa; |
Vladimir Kondratiev | c406ea7 | 2015-03-15 16:00:19 +0200 | [diff] [blame] | 421 | unsigned int snaplen = wil_rx_snaplen(); |
| 422 | unsigned int sz = mtu_max + ETH_HLEN + snaplen; |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 423 | u16 dmalen; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 424 | u8 ftype; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 425 | int cid; |
Vladimir Kondratiev | 3b282bc | 2015-10-04 10:23:19 +0300 | [diff] [blame] | 426 | int i; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 427 | struct wil_net_stats *stats; |
| 428 | |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 429 | BUILD_BUG_ON(sizeof(struct vring_rx_desc) > sizeof(skb->cb)); |
| 430 | |
Vladimir Kondratiev | 3b282bc | 2015-10-04 10:23:19 +0300 | [diff] [blame] | 431 | again: |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 432 | if (unlikely(wil_vring_is_empty(vring))) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 433 | return NULL; |
| 434 | |
Vladimir Kondratiev | 3b282bc | 2015-10-04 10:23:19 +0300 | [diff] [blame] | 435 | i = (int)vring->swhead; |
Vladimir Kondratiev | 148416a | 2015-03-15 16:00:16 +0200 | [diff] [blame] | 436 | _d = &vring->va[i].rx; |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 437 | if (unlikely(!(_d->dma.status & RX_DMA_STATUS_DU))) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 438 | /* it is not error, we just reached end of Rx done area */ |
| 439 | return NULL; |
| 440 | } |
| 441 | |
Vladimir Kondratiev | 148416a | 2015-03-15 16:00:16 +0200 | [diff] [blame] | 442 | skb = vring->ctx[i].skb; |
| 443 | vring->ctx[i].skb = NULL; |
| 444 | wil_vring_advance_head(vring, 1); |
| 445 | if (!skb) { |
| 446 | wil_err(wil, "No Rx skb at [%d]\n", i); |
Vladimir Kondratiev | 3b282bc | 2015-10-04 10:23:19 +0300 | [diff] [blame] | 447 | goto again; |
Vladimir Kondratiev | 148416a | 2015-03-15 16:00:16 +0200 | [diff] [blame] | 448 | } |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 449 | d = wil_skb_rxdesc(skb); |
| 450 | *d = *_d; |
| 451 | pa = wil_desc_addr(&d->dma.addr); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 452 | |
| 453 | dma_unmap_single(dev, pa, sz, DMA_FROM_DEVICE); |
| 454 | dmalen = le16_to_cpu(d->dma.length); |
| 455 | |
Vladimir Kondratiev | 148416a | 2015-03-15 16:00:16 +0200 | [diff] [blame] | 456 | trace_wil6210_rx(i, d); |
| 457 | wil_dbg_txrx(wil, "Rx[%3d] : %d bytes\n", i, dmalen); |
Vladimir Kondratiev | a831334 | 2015-10-04 10:23:23 +0300 | [diff] [blame] | 458 | wil_hex_dump_txrx("RxD ", DUMP_PREFIX_NONE, 32, 4, |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 459 | (const void *)d, sizeof(*d), false); |
| 460 | |
Vladimir Kondratiev | 3b282bc | 2015-10-04 10:23:19 +0300 | [diff] [blame] | 461 | cid = wil_rxdesc_cid(d); |
| 462 | stats = &wil->sta[cid].stats; |
| 463 | |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 464 | if (unlikely(dmalen > sz)) { |
Vladimir Kondratiev | e270045 | 2013-05-12 14:43:33 +0300 | [diff] [blame] | 465 | wil_err(wil, "Rx size too large: %d bytes!\n", dmalen); |
Vladimir Kondratiev | 3b282bc | 2015-10-04 10:23:19 +0300 | [diff] [blame] | 466 | stats->rx_large_frame++; |
Wei Yongjun | 110dea0 | 2013-05-23 17:10:43 +0800 | [diff] [blame] | 467 | kfree_skb(skb); |
Vladimir Kondratiev | 3b282bc | 2015-10-04 10:23:19 +0300 | [diff] [blame] | 468 | goto again; |
Vladimir Kondratiev | e270045 | 2013-05-12 14:43:33 +0300 | [diff] [blame] | 469 | } |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 470 | skb_trim(skb, dmalen); |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 471 | |
Vladimir Kondratiev | 1cbbcb0 | 2014-01-08 11:50:49 +0200 | [diff] [blame] | 472 | prefetch(skb->data); |
| 473 | |
Vladimir Kondratiev | c0d3771 | 2013-05-12 14:43:34 +0300 | [diff] [blame] | 474 | wil_hex_dump_txrx("Rx ", DUMP_PREFIX_OFFSET, 16, 1, |
| 475 | skb->data, skb_headlen(skb), false); |
| 476 | |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 477 | stats->last_mcs_rx = wil_rxdesc_mcs(d); |
Vladimir Kondratiev | c4a110d | 2015-06-09 14:11:18 +0300 | [diff] [blame] | 478 | if (stats->last_mcs_rx < ARRAY_SIZE(stats->rx_per_mcs)) |
| 479 | stats->rx_per_mcs[stats->last_mcs_rx]++; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 480 | |
| 481 | /* use radiotap header only if required */ |
| 482 | if (ndev->type == ARPHRD_IEEE80211_RADIOTAP) |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 483 | wil_rx_add_radiotap_header(wil, skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 484 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 485 | /* no extra checks if in sniffer mode */ |
| 486 | if (ndev->type != ARPHRD_ETHER) |
| 487 | return skb; |
Vladimir Kondratiev | a831334 | 2015-10-04 10:23:23 +0300 | [diff] [blame] | 488 | /* Non-data frames may be delivered through Rx DMA channel (ex: BAR) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 489 | * Driver should recognize it by frame type, that is found |
| 490 | * in Rx descriptor. If type is not data, it is 802.11 frame as is |
| 491 | */ |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 492 | ftype = wil_rxdesc_ftype(d) << 2; |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 493 | if (unlikely(ftype != IEEE80211_FTYPE_DATA)) { |
Vladimir Kondratiev | a831334 | 2015-10-04 10:23:23 +0300 | [diff] [blame] | 494 | u8 fc1 = wil_rxdesc_fc1(d); |
| 495 | int mid = wil_rxdesc_mid(d); |
| 496 | int tid = wil_rxdesc_tid(d); |
| 497 | u16 seq = wil_rxdesc_seq(d); |
| 498 | |
| 499 | wil_dbg_txrx(wil, |
| 500 | "Non-data frame FC[7:0] 0x%02x MID %d CID %d TID %d Seq 0x%03x\n", |
| 501 | fc1, mid, cid, tid, seq); |
Vladimir Kondratiev | 3b282bc | 2015-10-04 10:23:19 +0300 | [diff] [blame] | 502 | stats->rx_non_data_frame++; |
Vladimir Kondratiev | a831334 | 2015-10-04 10:23:23 +0300 | [diff] [blame] | 503 | if (wil_is_back_req(fc1)) { |
| 504 | wil_dbg_txrx(wil, |
| 505 | "BAR: MID %d CID %d TID %d Seq 0x%03x\n", |
| 506 | mid, cid, tid, seq); |
| 507 | wil_rx_bar(wil, cid, tid, seq); |
| 508 | } else { |
| 509 | /* print again all info. One can enable only this |
| 510 | * without overhead for printing every Rx frame |
| 511 | */ |
| 512 | wil_dbg_txrx(wil, |
| 513 | "Unhandled non-data frame FC[7:0] 0x%02x MID %d CID %d TID %d Seq 0x%03x\n", |
| 514 | fc1, mid, cid, tid, seq); |
| 515 | wil_hex_dump_txrx("RxD ", DUMP_PREFIX_NONE, 32, 4, |
| 516 | (const void *)d, sizeof(*d), false); |
| 517 | wil_hex_dump_txrx("Rx ", DUMP_PREFIX_OFFSET, 16, 1, |
| 518 | skb->data, skb_headlen(skb), false); |
| 519 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 520 | kfree_skb(skb); |
Vladimir Kondratiev | 3b282bc | 2015-10-04 10:23:19 +0300 | [diff] [blame] | 521 | goto again; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 522 | } |
| 523 | |
Vladimir Kondratiev | c406ea7 | 2015-03-15 16:00:19 +0200 | [diff] [blame] | 524 | if (unlikely(skb->len < ETH_HLEN + snaplen)) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 525 | wil_err(wil, "Short frame, len = %d\n", skb->len); |
Vladimir Kondratiev | 3b282bc | 2015-10-04 10:23:19 +0300 | [diff] [blame] | 526 | stats->rx_short_frame++; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 527 | kfree_skb(skb); |
Vladimir Kondratiev | 3b282bc | 2015-10-04 10:23:19 +0300 | [diff] [blame] | 528 | goto again; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 529 | } |
| 530 | |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 531 | /* L4 IDENT is on when HW calculated checksum, check status |
| 532 | * and in case of error drop the packet |
| 533 | * higher stack layers will handle retransmission (if required) |
| 534 | */ |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 535 | if (likely(d->dma.status & RX_DMA_STATUS_L4I)) { |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 536 | /* L4 protocol identified, csum calculated */ |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 537 | if (likely((d->dma.error & RX_DMA_ERROR_L4_ERR) == 0)) |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 538 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Vladimir Kondratiev | 4a68ab10 | 2013-08-13 15:25:32 +0300 | [diff] [blame] | 539 | /* If HW reports bad checksum, let IP stack re-check it |
| 540 | * For example, HW don't understand Microsoft IP stack that |
| 541 | * mis-calculates TCP checksum - if it should be 0x0, |
| 542 | * it writes 0xffff in violation of RFC 1624 |
| 543 | */ |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 544 | } |
| 545 | |
Vladimir Kondratiev | c406ea7 | 2015-03-15 16:00:19 +0200 | [diff] [blame] | 546 | if (snaplen) { |
| 547 | /* Packet layout |
| 548 | * +-------+-------+---------+------------+------+ |
| 549 | * | SA(6) | DA(6) | SNAP(6) | ETHTYPE(2) | DATA | |
| 550 | * +-------+-------+---------+------------+------+ |
| 551 | * Need to remove SNAP, shifting SA and DA forward |
| 552 | */ |
| 553 | memmove(skb->data + snaplen, skb->data, 2 * ETH_ALEN); |
| 554 | skb_pull(skb, snaplen); |
| 555 | } |
| 556 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 557 | return skb; |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * allocate and fill up to @count buffers in rx ring |
| 562 | * buffers posted at @swtail |
| 563 | */ |
| 564 | static int wil_rx_refill(struct wil6210_priv *wil, int count) |
| 565 | { |
| 566 | struct net_device *ndev = wil_to_ndev(wil); |
| 567 | struct vring *v = &wil->vring_rx; |
| 568 | u32 next_tail; |
| 569 | int rc = 0; |
| 570 | int headroom = ndev->type == ARPHRD_IEEE80211_RADIOTAP ? |
| 571 | WIL6210_RTAP_SIZE : 0; |
| 572 | |
| 573 | for (; next_tail = wil_vring_next_tail(v), |
| 574 | (next_tail != v->swhead) && (count-- > 0); |
| 575 | v->swtail = next_tail) { |
| 576 | rc = wil_vring_alloc_skb(wil, v, v->swtail, headroom); |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 577 | if (unlikely(rc)) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 578 | wil_err(wil, "Error %d in wil_rx_refill[%d]\n", |
| 579 | rc, v->swtail); |
| 580 | break; |
| 581 | } |
| 582 | } |
Maya Erez | ab6d7cc | 2016-05-16 22:23:31 +0300 | [diff] [blame] | 583 | |
| 584 | /* make sure all writes to descriptors (shared memory) are done before |
| 585 | * committing them to HW |
| 586 | */ |
| 587 | wmb(); |
| 588 | |
Vladimir Kondratiev | b9eeb51 | 2015-07-30 13:52:03 +0300 | [diff] [blame] | 589 | wil_w(wil, v->hwtail, v->swtail); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 590 | |
| 591 | return rc; |
| 592 | } |
| 593 | |
Vladimir Kondratiev | 5852742 | 2016-03-01 19:18:07 +0200 | [diff] [blame] | 594 | /** |
| 595 | * reverse_memcmp - Compare two areas of memory, in reverse order |
| 596 | * @cs: One area of memory |
| 597 | * @ct: Another area of memory |
| 598 | * @count: The size of the area. |
| 599 | * |
| 600 | * Cut'n'paste from original memcmp (see lib/string.c) |
| 601 | * with minimal modifications |
| 602 | */ |
| 603 | static int reverse_memcmp(const void *cs, const void *ct, size_t count) |
| 604 | { |
| 605 | const unsigned char *su1, *su2; |
| 606 | int res = 0; |
| 607 | |
| 608 | for (su1 = cs + count - 1, su2 = ct + count - 1; count > 0; |
| 609 | --su1, --su2, count--) { |
| 610 | res = *su1 - *su2; |
| 611 | if (res) |
| 612 | break; |
| 613 | } |
| 614 | return res; |
| 615 | } |
| 616 | |
| 617 | static int wil_rx_crypto_check(struct wil6210_priv *wil, struct sk_buff *skb) |
| 618 | { |
| 619 | struct vring_rx_desc *d = wil_skb_rxdesc(skb); |
| 620 | int cid = wil_rxdesc_cid(d); |
| 621 | int tid = wil_rxdesc_tid(d); |
| 622 | int key_id = wil_rxdesc_key_id(d); |
| 623 | int mc = wil_rxdesc_mcast(d); |
| 624 | struct wil_sta_info *s = &wil->sta[cid]; |
| 625 | struct wil_tid_crypto_rx *c = mc ? &s->group_crypto_rx : |
| 626 | &s->tid_crypto_rx[tid]; |
| 627 | struct wil_tid_crypto_rx_single *cc = &c->key_id[key_id]; |
| 628 | const u8 *pn = (u8 *)&d->mac.pn_15_0; |
| 629 | |
| 630 | if (!cc->key_set) { |
| 631 | wil_err_ratelimited(wil, |
| 632 | "Key missing. CID %d TID %d MCast %d KEY_ID %d\n", |
| 633 | cid, tid, mc, key_id); |
| 634 | return -EINVAL; |
| 635 | } |
| 636 | |
| 637 | if (reverse_memcmp(pn, cc->pn, IEEE80211_GCMP_PN_LEN) <= 0) { |
| 638 | wil_err_ratelimited(wil, |
| 639 | "Replay attack. CID %d TID %d MCast %d KEY_ID %d PN %6phN last %6phN\n", |
| 640 | cid, tid, mc, key_id, pn, cc->pn); |
| 641 | return -EINVAL; |
| 642 | } |
| 643 | memcpy(cc->pn, pn, IEEE80211_GCMP_PN_LEN); |
| 644 | |
| 645 | return 0; |
| 646 | } |
| 647 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 648 | /* |
| 649 | * Pass Rx packet to the netif. Update statistics. |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 650 | * Called in softirq context (NAPI poll). |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 651 | */ |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 652 | void wil_netif_rx_any(struct sk_buff *skb, struct net_device *ndev) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 653 | { |
Vladimir Kondratiev | c42da99 | 2015-03-08 15:42:02 +0200 | [diff] [blame] | 654 | gro_result_t rc = GRO_NORMAL; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 655 | struct wil6210_priv *wil = ndev_to_wil(ndev); |
Vladimir Kondratiev | c42da99 | 2015-03-08 15:42:02 +0200 | [diff] [blame] | 656 | struct wireless_dev *wdev = wil_to_wdev(wil); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 657 | unsigned int len = skb->len; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 658 | struct vring_rx_desc *d = wil_skb_rxdesc(skb); |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 659 | int cid = wil_rxdesc_cid(d); /* always 0..7, no need to check */ |
Vladimir Kondratiev | 5852742 | 2016-03-01 19:18:07 +0200 | [diff] [blame] | 660 | int security = wil_rxdesc_security(d); |
Vladimir Kondratiev | c42da99 | 2015-03-08 15:42:02 +0200 | [diff] [blame] | 661 | struct ethhdr *eth = (void *)skb->data; |
| 662 | /* here looking for DA, not A1, thus Rxdesc's 'mcast' indication |
| 663 | * is not suitable, need to look at data |
| 664 | */ |
| 665 | int mcast = is_multicast_ether_addr(eth->h_dest); |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 666 | struct wil_net_stats *stats = &wil->sta[cid].stats; |
Vladimir Kondratiev | c42da99 | 2015-03-08 15:42:02 +0200 | [diff] [blame] | 667 | struct sk_buff *xmit_skb = NULL; |
| 668 | static const char * const gro_res_str[] = { |
| 669 | [GRO_MERGED] = "GRO_MERGED", |
| 670 | [GRO_MERGED_FREE] = "GRO_MERGED_FREE", |
| 671 | [GRO_HELD] = "GRO_HELD", |
| 672 | [GRO_NORMAL] = "GRO_NORMAL", |
| 673 | [GRO_DROP] = "GRO_DROP", |
| 674 | }; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 675 | |
Vladimir Shulman | 0553640 | 2015-07-30 13:52:04 +0300 | [diff] [blame] | 676 | if (ndev->features & NETIF_F_RXHASH) |
| 677 | /* fake L4 to ensure it won't be re-calculated later |
| 678 | * set hash to any non-zero value to activate rps |
| 679 | * mechanism, core will be chosen according |
| 680 | * to user-level rps configuration. |
| 681 | */ |
| 682 | skb_set_hash(skb, 1, PKT_HASH_TYPE_L4); |
| 683 | |
Vladimir Kondratiev | 241804c | 2013-01-28 18:31:02 +0200 | [diff] [blame] | 684 | skb_orphan(skb); |
| 685 | |
Vladimir Kondratiev | 5852742 | 2016-03-01 19:18:07 +0200 | [diff] [blame] | 686 | if (security && (wil_rx_crypto_check(wil, skb) != 0)) { |
| 687 | rc = GRO_DROP; |
| 688 | dev_kfree_skb(skb); |
| 689 | stats->rx_replay++; |
| 690 | goto stats; |
| 691 | } |
| 692 | |
Vladimir Kondratiev | 02beaf1 | 2015-03-08 15:42:03 +0200 | [diff] [blame] | 693 | if (wdev->iftype == NL80211_IFTYPE_AP && !wil->ap_isolate) { |
Vladimir Kondratiev | c42da99 | 2015-03-08 15:42:02 +0200 | [diff] [blame] | 694 | if (mcast) { |
| 695 | /* send multicast frames both to higher layers in |
| 696 | * local net stack and back to the wireless medium |
| 697 | */ |
| 698 | xmit_skb = skb_copy(skb, GFP_ATOMIC); |
| 699 | } else { |
| 700 | int xmit_cid = wil_find_cid(wil, eth->h_dest); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 701 | |
Vladimir Kondratiev | c42da99 | 2015-03-08 15:42:02 +0200 | [diff] [blame] | 702 | if (xmit_cid >= 0) { |
| 703 | /* The destination station is associated to |
| 704 | * this AP (in this VLAN), so send the frame |
| 705 | * directly to it and do not pass it to local |
| 706 | * net stack. |
| 707 | */ |
| 708 | xmit_skb = skb; |
| 709 | skb = NULL; |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | if (xmit_skb) { |
| 714 | /* Send to wireless media and increase priority by 256 to |
| 715 | * keep the received priority instead of reclassifying |
| 716 | * the frame (see cfg80211_classify8021d). |
| 717 | */ |
| 718 | xmit_skb->dev = ndev; |
| 719 | xmit_skb->priority += 256; |
| 720 | xmit_skb->protocol = htons(ETH_P_802_3); |
| 721 | skb_reset_network_header(xmit_skb); |
| 722 | skb_reset_mac_header(xmit_skb); |
| 723 | wil_dbg_txrx(wil, "Rx -> Tx %d bytes\n", len); |
| 724 | dev_queue_xmit(xmit_skb); |
| 725 | } |
| 726 | |
| 727 | if (skb) { /* deliver to local stack */ |
| 728 | |
| 729 | skb->protocol = eth_type_trans(skb, ndev); |
| 730 | rc = napi_gro_receive(&wil->napi_rx, skb); |
| 731 | wil_dbg_txrx(wil, "Rx complete %d bytes => %s\n", |
| 732 | len, gro_res_str[rc]); |
| 733 | } |
Vladimir Kondratiev | 5852742 | 2016-03-01 19:18:07 +0200 | [diff] [blame] | 734 | stats: |
Vladimir Kondratiev | c42da99 | 2015-03-08 15:42:02 +0200 | [diff] [blame] | 735 | /* statistics. rc set to GRO_NORMAL for AP bridging */ |
Vladimir Kondratiev | b5998e6 | 2014-03-17 15:34:22 +0200 | [diff] [blame] | 736 | if (unlikely(rc == GRO_DROP)) { |
| 737 | ndev->stats.rx_dropped++; |
| 738 | stats->rx_dropped++; |
| 739 | wil_dbg_txrx(wil, "Rx drop %d bytes\n", len); |
| 740 | } else { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 741 | ndev->stats.rx_packets++; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 742 | stats->rx_packets++; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 743 | ndev->stats.rx_bytes += len; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 744 | stats->rx_bytes += len; |
Vladimir Kondratiev | c42da99 | 2015-03-08 15:42:02 +0200 | [diff] [blame] | 745 | if (mcast) |
| 746 | ndev->stats.multicast++; |
Vladimir Kondratiev | 194b482 | 2014-06-16 19:37:14 +0300 | [diff] [blame] | 747 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | /** |
| 751 | * Proceed all completed skb's from Rx VRING |
| 752 | * |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 753 | * Safe to call from NAPI poll, i.e. softirq with interrupts enabled |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 754 | */ |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 755 | void wil_rx_handle(struct wil6210_priv *wil, int *quota) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 756 | { |
| 757 | struct net_device *ndev = wil_to_ndev(wil); |
| 758 | struct vring *v = &wil->vring_rx; |
| 759 | struct sk_buff *skb; |
| 760 | |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 761 | if (unlikely(!v->va)) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 762 | wil_err(wil, "Rx IRQ while Rx not yet initialized\n"); |
| 763 | return; |
| 764 | } |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 765 | wil_dbg_txrx(wil, "rx_handle\n"); |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 766 | while ((*quota > 0) && (NULL != (skb = wil_vring_reap_rx(wil, v)))) { |
| 767 | (*quota)--; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 768 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 769 | if (wil->wdev->iftype == NL80211_IFTYPE_MONITOR) { |
| 770 | skb->dev = ndev; |
| 771 | skb_reset_mac_header(skb); |
| 772 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 773 | skb->pkt_type = PACKET_OTHERHOST; |
| 774 | skb->protocol = htons(ETH_P_802_2); |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 775 | wil_netif_rx_any(skb, ndev); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 776 | } else { |
Vladimir Kondratiev | e4373d8 | 2014-12-23 09:47:21 +0200 | [diff] [blame] | 777 | wil_rx_reorder(wil, skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 778 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 779 | } |
| 780 | wil_rx_refill(wil, v->size); |
| 781 | } |
| 782 | |
Vladimir Kondratiev | d3762b4 | 2014-12-01 15:35:02 +0200 | [diff] [blame] | 783 | int wil_rx_init(struct wil6210_priv *wil, u16 size) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 784 | { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 785 | struct vring *vring = &wil->vring_rx; |
| 786 | int rc; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 787 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 788 | wil_dbg_misc(wil, "rx_init\n"); |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 789 | |
Vladimir Kondratiev | 8bf6adb | 2014-03-17 15:34:17 +0200 | [diff] [blame] | 790 | if (vring->va) { |
| 791 | wil_err(wil, "Rx ring already allocated\n"); |
| 792 | return -EINVAL; |
| 793 | } |
| 794 | |
Vladimir Kondratiev | d3762b4 | 2014-12-01 15:35:02 +0200 | [diff] [blame] | 795 | vring->size = size; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 796 | rc = wil_vring_alloc(wil, vring); |
| 797 | if (rc) |
| 798 | return rc; |
| 799 | |
Vladimir Kondratiev | 47e19af | 2013-01-28 18:30:59 +0200 | [diff] [blame] | 800 | rc = wmi_rx_chain_add(wil, vring); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 801 | if (rc) |
| 802 | goto err_free; |
| 803 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 804 | rc = wil_rx_refill(wil, vring->size); |
| 805 | if (rc) |
| 806 | goto err_free; |
| 807 | |
| 808 | return 0; |
| 809 | err_free: |
| 810 | wil_vring_free(wil, vring, 0); |
| 811 | |
| 812 | return rc; |
| 813 | } |
| 814 | |
| 815 | void wil_rx_fini(struct wil6210_priv *wil) |
| 816 | { |
| 817 | struct vring *vring = &wil->vring_rx; |
| 818 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 819 | wil_dbg_misc(wil, "rx_fini\n"); |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 820 | |
Vladimir Kondratiev | 2acb422 | 2013-01-28 18:31:08 +0200 | [diff] [blame] | 821 | if (vring->va) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 822 | wil_vring_free(wil, vring, 0); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 823 | } |
| 824 | |
Maya Erez | 875e943 | 2016-01-28 19:24:02 +0200 | [diff] [blame] | 825 | static inline void wil_tx_data_init(struct vring_tx_data *txdata) |
| 826 | { |
| 827 | spin_lock_bh(&txdata->lock); |
| 828 | txdata->dot1x_open = 0; |
| 829 | txdata->enabled = 0; |
| 830 | txdata->idle = 0; |
| 831 | txdata->last_idle = 0; |
| 832 | txdata->begin = 0; |
| 833 | txdata->agg_wsize = 0; |
| 834 | txdata->agg_timeout = 0; |
| 835 | txdata->agg_amsdu = 0; |
| 836 | txdata->addba_in_progress = false; |
| 837 | spin_unlock_bh(&txdata->lock); |
| 838 | } |
| 839 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 840 | int wil_vring_init_tx(struct wil6210_priv *wil, int id, int size, |
| 841 | int cid, int tid) |
| 842 | { |
| 843 | int rc; |
| 844 | struct wmi_vring_cfg_cmd cmd = { |
| 845 | .action = cpu_to_le32(WMI_VRING_CMD_ADD), |
| 846 | .vring_cfg = { |
| 847 | .tx_sw_ring = { |
Vladimir Kondratiev | 9a06bec | 2014-10-28 16:51:27 +0200 | [diff] [blame] | 848 | .max_mpdu_size = |
Vladimir Kondratiev | c44690a | 2014-12-23 09:47:11 +0200 | [diff] [blame] | 849 | cpu_to_le16(wil_mtu2macbuf(mtu_max)), |
Vladimir Kondratiev | b5d98e9 | 2013-04-18 14:33:51 +0300 | [diff] [blame] | 850 | .ring_size = cpu_to_le16(size), |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 851 | }, |
| 852 | .ringid = id, |
Vladimir Kondratiev | a70abea | 2014-03-17 15:34:05 +0200 | [diff] [blame] | 853 | .cidxtid = mk_cidxtid(cid, tid), |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 854 | .encap_trans_type = WMI_VRING_ENC_TYPE_802_3, |
| 855 | .mac_ctrl = 0, |
| 856 | .to_resolution = 0, |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 857 | .agg_max_wsize = 0, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 858 | .schd_params = { |
| 859 | .priority = cpu_to_le16(0), |
| 860 | .timeslot_us = cpu_to_le16(0xfff), |
| 861 | }, |
| 862 | }, |
| 863 | }; |
| 864 | struct { |
Lior David | b874dde | 2016-03-01 19:18:09 +0200 | [diff] [blame] | 865 | struct wmi_cmd_hdr wmi; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 866 | struct wmi_vring_cfg_done_event cmd; |
| 867 | } __packed reply; |
| 868 | struct vring *vring = &wil->vring_tx[id]; |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 869 | struct vring_tx_data *txdata = &wil->vring_tx_data[id]; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 870 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 871 | wil_dbg_misc(wil, "vring_init_tx: max_mpdu_size %d\n", |
Vladimir Kondratiev | e0106ad | 2014-09-10 16:34:45 +0300 | [diff] [blame] | 872 | cmd.vring_cfg.tx_sw_ring.max_mpdu_size); |
Vladimir Kondratiev | 9b1ba7b | 2015-11-06 12:50:44 +0200 | [diff] [blame] | 873 | lockdep_assert_held(&wil->mutex); |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 874 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 875 | if (vring->va) { |
| 876 | wil_err(wil, "Tx ring [%d] already allocated\n", id); |
| 877 | rc = -EINVAL; |
| 878 | goto out; |
| 879 | } |
| 880 | |
Maya Erez | 875e943 | 2016-01-28 19:24:02 +0200 | [diff] [blame] | 881 | wil_tx_data_init(txdata); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 882 | vring->size = size; |
| 883 | rc = wil_vring_alloc(wil, vring); |
| 884 | if (rc) |
| 885 | goto out; |
| 886 | |
Vladimir Kondratiev | 93ae6d4 | 2014-02-27 16:20:51 +0200 | [diff] [blame] | 887 | wil->vring2cid_tid[id][0] = cid; |
| 888 | wil->vring2cid_tid[id][1] = tid; |
| 889 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 890 | cmd.vring_cfg.tx_sw_ring.ring_mem_base = cpu_to_le64(vring->pa); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 891 | |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 892 | if (!wil->privacy) |
| 893 | txdata->dot1x_open = true; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 894 | rc = wmi_call(wil, WMI_VRING_CFG_CMDID, &cmd, sizeof(cmd), |
| 895 | WMI_VRING_CFG_DONE_EVENTID, &reply, sizeof(reply), 100); |
| 896 | if (rc) |
| 897 | goto out_free; |
| 898 | |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 899 | if (reply.cmd.status != WMI_FW_STATUS_SUCCESS) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 900 | wil_err(wil, "Tx config failed, status 0x%02x\n", |
| 901 | reply.cmd.status); |
Vladimir Kondratiev | c331997 | 2013-01-28 18:31:09 +0200 | [diff] [blame] | 902 | rc = -EINVAL; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 903 | goto out_free; |
| 904 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 905 | |
Maya Erez | dc90506 | 2016-08-18 16:52:15 +0300 | [diff] [blame] | 906 | spin_lock_bh(&txdata->lock); |
| 907 | vring->hwtail = le32_to_cpu(reply.cmd.tx_vring_tail_ptr); |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 908 | txdata->enabled = 1; |
Maya Erez | dc90506 | 2016-08-18 16:52:15 +0300 | [diff] [blame] | 909 | spin_unlock_bh(&txdata->lock); |
| 910 | |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 911 | if (txdata->dot1x_open && (agg_wsize >= 0)) |
Vladimir Kondratiev | 3a3def8 | 2014-12-23 09:47:05 +0200 | [diff] [blame] | 912 | wil_addba_tx_request(wil, id, agg_wsize); |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 913 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 914 | return 0; |
| 915 | out_free: |
Maya Erez | 875e943 | 2016-01-28 19:24:02 +0200 | [diff] [blame] | 916 | spin_lock_bh(&txdata->lock); |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 917 | txdata->dot1x_open = false; |
| 918 | txdata->enabled = 0; |
Maya Erez | 875e943 | 2016-01-28 19:24:02 +0200 | [diff] [blame] | 919 | spin_unlock_bh(&txdata->lock); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 920 | wil_vring_free(wil, vring, 1); |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 921 | wil->vring2cid_tid[id][0] = WIL6210_MAX_CID; |
| 922 | wil->vring2cid_tid[id][1] = 0; |
| 923 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 924 | out: |
| 925 | |
| 926 | return rc; |
| 927 | } |
| 928 | |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 929 | int wil_vring_init_bcast(struct wil6210_priv *wil, int id, int size) |
| 930 | { |
| 931 | int rc; |
| 932 | struct wmi_bcast_vring_cfg_cmd cmd = { |
| 933 | .action = cpu_to_le32(WMI_VRING_CMD_ADD), |
| 934 | .vring_cfg = { |
| 935 | .tx_sw_ring = { |
| 936 | .max_mpdu_size = |
| 937 | cpu_to_le16(wil_mtu2macbuf(mtu_max)), |
| 938 | .ring_size = cpu_to_le16(size), |
| 939 | }, |
| 940 | .ringid = id, |
| 941 | .encap_trans_type = WMI_VRING_ENC_TYPE_802_3, |
| 942 | }, |
| 943 | }; |
| 944 | struct { |
Lior David | b874dde | 2016-03-01 19:18:09 +0200 | [diff] [blame] | 945 | struct wmi_cmd_hdr wmi; |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 946 | struct wmi_vring_cfg_done_event cmd; |
| 947 | } __packed reply; |
| 948 | struct vring *vring = &wil->vring_tx[id]; |
| 949 | struct vring_tx_data *txdata = &wil->vring_tx_data[id]; |
| 950 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 951 | wil_dbg_misc(wil, "vring_init_bcast: max_mpdu_size %d\n", |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 952 | cmd.vring_cfg.tx_sw_ring.max_mpdu_size); |
Vladimir Kondratiev | 9b1ba7b | 2015-11-06 12:50:44 +0200 | [diff] [blame] | 953 | lockdep_assert_held(&wil->mutex); |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 954 | |
| 955 | if (vring->va) { |
| 956 | wil_err(wil, "Tx ring [%d] already allocated\n", id); |
| 957 | rc = -EINVAL; |
| 958 | goto out; |
| 959 | } |
| 960 | |
Maya Erez | 875e943 | 2016-01-28 19:24:02 +0200 | [diff] [blame] | 961 | wil_tx_data_init(txdata); |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 962 | vring->size = size; |
| 963 | rc = wil_vring_alloc(wil, vring); |
| 964 | if (rc) |
| 965 | goto out; |
| 966 | |
| 967 | wil->vring2cid_tid[id][0] = WIL6210_MAX_CID; /* CID */ |
| 968 | wil->vring2cid_tid[id][1] = 0; /* TID */ |
| 969 | |
| 970 | cmd.vring_cfg.tx_sw_ring.ring_mem_base = cpu_to_le64(vring->pa); |
| 971 | |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 972 | if (!wil->privacy) |
| 973 | txdata->dot1x_open = true; |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 974 | rc = wmi_call(wil, WMI_BCAST_VRING_CFG_CMDID, &cmd, sizeof(cmd), |
| 975 | WMI_VRING_CFG_DONE_EVENTID, &reply, sizeof(reply), 100); |
| 976 | if (rc) |
| 977 | goto out_free; |
| 978 | |
| 979 | if (reply.cmd.status != WMI_FW_STATUS_SUCCESS) { |
| 980 | wil_err(wil, "Tx config failed, status 0x%02x\n", |
| 981 | reply.cmd.status); |
| 982 | rc = -EINVAL; |
| 983 | goto out_free; |
| 984 | } |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 985 | |
Maya Erez | dc90506 | 2016-08-18 16:52:15 +0300 | [diff] [blame] | 986 | spin_lock_bh(&txdata->lock); |
| 987 | vring->hwtail = le32_to_cpu(reply.cmd.tx_vring_tail_ptr); |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 988 | txdata->enabled = 1; |
Maya Erez | dc90506 | 2016-08-18 16:52:15 +0300 | [diff] [blame] | 989 | spin_unlock_bh(&txdata->lock); |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 990 | |
| 991 | return 0; |
| 992 | out_free: |
Maya Erez | 875e943 | 2016-01-28 19:24:02 +0200 | [diff] [blame] | 993 | spin_lock_bh(&txdata->lock); |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 994 | txdata->enabled = 0; |
| 995 | txdata->dot1x_open = false; |
Maya Erez | 875e943 | 2016-01-28 19:24:02 +0200 | [diff] [blame] | 996 | spin_unlock_bh(&txdata->lock); |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 997 | wil_vring_free(wil, vring, 1); |
| 998 | out: |
| 999 | |
| 1000 | return rc; |
| 1001 | } |
| 1002 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1003 | void wil_vring_fini_tx(struct wil6210_priv *wil, int id) |
| 1004 | { |
| 1005 | struct vring *vring = &wil->vring_tx[id]; |
Vladimir Kondratiev | 3a124ed | 2014-12-23 09:47:04 +0200 | [diff] [blame] | 1006 | struct vring_tx_data *txdata = &wil->vring_tx_data[id]; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1007 | |
Vladimir Kondratiev | 9b1ba7b | 2015-11-06 12:50:44 +0200 | [diff] [blame] | 1008 | lockdep_assert_held(&wil->mutex); |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 1009 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1010 | if (!vring->va) |
| 1011 | return; |
| 1012 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 1013 | wil_dbg_misc(wil, "vring_fini_tx: id=%d\n", id); |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 1014 | |
Vladimir Kondratiev | 5933a06 | 2015-02-01 10:55:13 +0200 | [diff] [blame] | 1015 | spin_lock_bh(&txdata->lock); |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 1016 | txdata->dot1x_open = false; |
Vladimir Kondratiev | 5933a06 | 2015-02-01 10:55:13 +0200 | [diff] [blame] | 1017 | txdata->enabled = 0; /* no Tx can be in progress or start anew */ |
| 1018 | spin_unlock_bh(&txdata->lock); |
Maya Erez | 34b8886 | 2016-05-16 22:23:32 +0300 | [diff] [blame] | 1019 | /* napi_synchronize waits for completion of the current NAPI but will |
| 1020 | * not prevent the next NAPI run. |
| 1021 | * Add a memory barrier to guarantee that txdata->enabled is zeroed |
| 1022 | * before napi_synchronize so that the next scheduled NAPI will not |
| 1023 | * handle this vring |
| 1024 | */ |
| 1025 | wmb(); |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 1026 | /* make sure NAPI won't touch this vring */ |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 1027 | if (test_bit(wil_status_napi_en, wil->status)) |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 1028 | napi_synchronize(&wil->napi_tx); |
| 1029 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1030 | wil_vring_free(wil, vring, 1); |
| 1031 | } |
| 1032 | |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 1033 | static struct vring *wil_find_tx_ucast(struct wil6210_priv *wil, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1034 | struct sk_buff *skb) |
| 1035 | { |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 1036 | int i; |
| 1037 | struct ethhdr *eth = (void *)skb->data; |
| 1038 | int cid = wil_find_cid(wil, eth->h_dest); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1039 | |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 1040 | if (cid < 0) |
| 1041 | return NULL; |
| 1042 | |
| 1043 | /* TODO: fix for multiple TID */ |
| 1044 | for (i = 0; i < ARRAY_SIZE(wil->vring2cid_tid); i++) { |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 1045 | if (!wil->vring_tx_data[i].dot1x_open && |
| 1046 | (skb->protocol != cpu_to_be16(ETH_P_PAE))) |
| 1047 | continue; |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 1048 | if (wil->vring2cid_tid[i][0] == cid) { |
| 1049 | struct vring *v = &wil->vring_tx[i]; |
Maya Erez | b729aaf | 2016-01-17 12:39:09 +0200 | [diff] [blame] | 1050 | struct vring_tx_data *txdata = &wil->vring_tx_data[i]; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1051 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 1052 | wil_dbg_txrx(wil, "find_tx_ucast: (%pM) -> [%d]\n", |
| 1053 | eth->h_dest, i); |
Maya Erez | b729aaf | 2016-01-17 12:39:09 +0200 | [diff] [blame] | 1054 | if (v->va && txdata->enabled) { |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 1055 | return v; |
| 1056 | } else { |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 1057 | wil_dbg_txrx(wil, |
| 1058 | "find_tx_ucast: vring[%d] not valid\n", |
| 1059 | i); |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 1060 | return NULL; |
| 1061 | } |
| 1062 | } |
| 1063 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1064 | |
| 1065 | return NULL; |
| 1066 | } |
| 1067 | |
Vladimir Kondratiev | fb3cac5 | 2014-02-27 16:20:46 +0200 | [diff] [blame] | 1068 | static int wil_tx_vring(struct wil6210_priv *wil, struct vring *vring, |
| 1069 | struct sk_buff *skb); |
Vladimir Kondratiev | 54ed90a | 2014-12-23 09:47:15 +0200 | [diff] [blame] | 1070 | |
| 1071 | static struct vring *wil_find_tx_vring_sta(struct wil6210_priv *wil, |
| 1072 | struct sk_buff *skb) |
| 1073 | { |
| 1074 | struct vring *v; |
| 1075 | int i; |
| 1076 | u8 cid; |
Maya Erez | b729aaf | 2016-01-17 12:39:09 +0200 | [diff] [blame] | 1077 | struct vring_tx_data *txdata; |
Vladimir Kondratiev | 54ed90a | 2014-12-23 09:47:15 +0200 | [diff] [blame] | 1078 | |
| 1079 | /* In the STA mode, it is expected to have only 1 VRING |
| 1080 | * for the AP we connected to. |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 1081 | * find 1-st vring eligible for this skb and use it. |
Vladimir Kondratiev | 54ed90a | 2014-12-23 09:47:15 +0200 | [diff] [blame] | 1082 | */ |
| 1083 | for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) { |
| 1084 | v = &wil->vring_tx[i]; |
Maya Erez | b729aaf | 2016-01-17 12:39:09 +0200 | [diff] [blame] | 1085 | txdata = &wil->vring_tx_data[i]; |
| 1086 | if (!v->va || !txdata->enabled) |
Vladimir Kondratiev | 54ed90a | 2014-12-23 09:47:15 +0200 | [diff] [blame] | 1087 | continue; |
| 1088 | |
| 1089 | cid = wil->vring2cid_tid[i][0]; |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 1090 | if (cid >= WIL6210_MAX_CID) /* skip BCAST */ |
| 1091 | continue; |
| 1092 | |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 1093 | if (!wil->vring_tx_data[i].dot1x_open && |
Vladimir Kondratiev | 54ed90a | 2014-12-23 09:47:15 +0200 | [diff] [blame] | 1094 | (skb->protocol != cpu_to_be16(ETH_P_PAE))) |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 1095 | continue; |
Vladimir Kondratiev | 54ed90a | 2014-12-23 09:47:15 +0200 | [diff] [blame] | 1096 | |
| 1097 | wil_dbg_txrx(wil, "Tx -> ring %d\n", i); |
| 1098 | |
| 1099 | return v; |
| 1100 | } |
| 1101 | |
| 1102 | wil_dbg_txrx(wil, "Tx while no vrings active?\n"); |
| 1103 | |
| 1104 | return NULL; |
| 1105 | } |
| 1106 | |
Vladimir Kondratiev | 7081242 | 2015-03-15 16:00:24 +0200 | [diff] [blame] | 1107 | /* Use one of 2 strategies: |
| 1108 | * |
| 1109 | * 1. New (real broadcast): |
| 1110 | * use dedicated broadcast vring |
| 1111 | * 2. Old (pseudo-DMS): |
| 1112 | * Find 1-st vring and return it; |
| 1113 | * duplicate skb and send it to other active vrings; |
| 1114 | * in all cases override dest address to unicast peer's address |
| 1115 | * Use old strategy when new is not supported yet: |
| 1116 | * - for PBSS |
Vladimir Kondratiev | 7081242 | 2015-03-15 16:00:24 +0200 | [diff] [blame] | 1117 | */ |
| 1118 | static struct vring *wil_find_tx_bcast_1(struct wil6210_priv *wil, |
| 1119 | struct sk_buff *skb) |
Vladimir Kondratiev | fb3cac5 | 2014-02-27 16:20:46 +0200 | [diff] [blame] | 1120 | { |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 1121 | struct vring *v; |
Maya Erez | b729aaf | 2016-01-17 12:39:09 +0200 | [diff] [blame] | 1122 | struct vring_tx_data *txdata; |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 1123 | int i = wil->bcast_vring; |
Vladimir Kondratiev | fb3cac5 | 2014-02-27 16:20:46 +0200 | [diff] [blame] | 1124 | |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 1125 | if (i < 0) |
| 1126 | return NULL; |
| 1127 | v = &wil->vring_tx[i]; |
Maya Erez | b729aaf | 2016-01-17 12:39:09 +0200 | [diff] [blame] | 1128 | txdata = &wil->vring_tx_data[i]; |
| 1129 | if (!v->va || !txdata->enabled) |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 1130 | return NULL; |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 1131 | if (!wil->vring_tx_data[i].dot1x_open && |
| 1132 | (skb->protocol != cpu_to_be16(ETH_P_PAE))) |
| 1133 | return NULL; |
Vladimir Kondratiev | fb3cac5 | 2014-02-27 16:20:46 +0200 | [diff] [blame] | 1134 | |
| 1135 | return v; |
| 1136 | } |
| 1137 | |
Vladimir Kondratiev | 7081242 | 2015-03-15 16:00:24 +0200 | [diff] [blame] | 1138 | static void wil_set_da_for_vring(struct wil6210_priv *wil, |
| 1139 | struct sk_buff *skb, int vring_index) |
| 1140 | { |
| 1141 | struct ethhdr *eth = (void *)skb->data; |
| 1142 | int cid = wil->vring2cid_tid[vring_index][0]; |
| 1143 | |
| 1144 | ether_addr_copy(eth->h_dest, wil->sta[cid].addr); |
| 1145 | } |
| 1146 | |
| 1147 | static struct vring *wil_find_tx_bcast_2(struct wil6210_priv *wil, |
| 1148 | struct sk_buff *skb) |
| 1149 | { |
| 1150 | struct vring *v, *v2; |
| 1151 | struct sk_buff *skb2; |
| 1152 | int i; |
| 1153 | u8 cid; |
| 1154 | struct ethhdr *eth = (void *)skb->data; |
| 1155 | char *src = eth->h_source; |
Maya Erez | b729aaf | 2016-01-17 12:39:09 +0200 | [diff] [blame] | 1156 | struct vring_tx_data *txdata; |
Vladimir Kondratiev | 7081242 | 2015-03-15 16:00:24 +0200 | [diff] [blame] | 1157 | |
| 1158 | /* find 1-st vring eligible for data */ |
| 1159 | for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) { |
| 1160 | v = &wil->vring_tx[i]; |
Maya Erez | b729aaf | 2016-01-17 12:39:09 +0200 | [diff] [blame] | 1161 | txdata = &wil->vring_tx_data[i]; |
| 1162 | if (!v->va || !txdata->enabled) |
Vladimir Kondratiev | 7081242 | 2015-03-15 16:00:24 +0200 | [diff] [blame] | 1163 | continue; |
| 1164 | |
| 1165 | cid = wil->vring2cid_tid[i][0]; |
| 1166 | if (cid >= WIL6210_MAX_CID) /* skip BCAST */ |
| 1167 | continue; |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 1168 | if (!wil->vring_tx_data[i].dot1x_open && |
| 1169 | (skb->protocol != cpu_to_be16(ETH_P_PAE))) |
Vladimir Kondratiev | 7081242 | 2015-03-15 16:00:24 +0200 | [diff] [blame] | 1170 | continue; |
| 1171 | |
| 1172 | /* don't Tx back to source when re-routing Rx->Tx at the AP */ |
| 1173 | if (0 == memcmp(wil->sta[cid].addr, src, ETH_ALEN)) |
| 1174 | continue; |
| 1175 | |
| 1176 | goto found; |
| 1177 | } |
| 1178 | |
| 1179 | wil_dbg_txrx(wil, "Tx while no vrings active?\n"); |
| 1180 | |
| 1181 | return NULL; |
| 1182 | |
| 1183 | found: |
| 1184 | wil_dbg_txrx(wil, "BCAST -> ring %d\n", i); |
| 1185 | wil_set_da_for_vring(wil, skb, i); |
| 1186 | |
| 1187 | /* find other active vrings and duplicate skb for each */ |
| 1188 | for (i++; i < WIL6210_MAX_TX_RINGS; i++) { |
| 1189 | v2 = &wil->vring_tx[i]; |
| 1190 | if (!v2->va) |
| 1191 | continue; |
| 1192 | cid = wil->vring2cid_tid[i][0]; |
| 1193 | if (cid >= WIL6210_MAX_CID) /* skip BCAST */ |
| 1194 | continue; |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 1195 | if (!wil->vring_tx_data[i].dot1x_open && |
| 1196 | (skb->protocol != cpu_to_be16(ETH_P_PAE))) |
Vladimir Kondratiev | 7081242 | 2015-03-15 16:00:24 +0200 | [diff] [blame] | 1197 | continue; |
| 1198 | |
| 1199 | if (0 == memcmp(wil->sta[cid].addr, src, ETH_ALEN)) |
| 1200 | continue; |
| 1201 | |
| 1202 | skb2 = skb_copy(skb, GFP_ATOMIC); |
| 1203 | if (skb2) { |
| 1204 | wil_dbg_txrx(wil, "BCAST DUP -> ring %d\n", i); |
| 1205 | wil_set_da_for_vring(wil, skb2, i); |
| 1206 | wil_tx_vring(wil, v2, skb2); |
| 1207 | } else { |
| 1208 | wil_err(wil, "skb_copy failed\n"); |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | return v; |
| 1213 | } |
| 1214 | |
Kirshenbaum Erez | 99b55bd | 2013-06-23 12:59:34 +0300 | [diff] [blame] | 1215 | static int wil_tx_desc_map(struct vring_tx_desc *d, dma_addr_t pa, u32 len, |
| 1216 | int vring_index) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1217 | { |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 1218 | wil_desc_addr_set(&d->dma.addr, pa); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1219 | d->dma.ip_length = 0; |
| 1220 | /* 0..6: mac_length; 7:ip_version 0-IP6 1-IP4*/ |
| 1221 | d->dma.b11 = 0/*14 | BIT(7)*/; |
| 1222 | d->dma.error = 0; |
| 1223 | d->dma.status = 0; /* BIT(0) should be 0 for HW_OWNED */ |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 1224 | d->dma.length = cpu_to_le16((u16)len); |
Kirshenbaum Erez | 99b55bd | 2013-06-23 12:59:34 +0300 | [diff] [blame] | 1225 | d->dma.d0 = (vring_index << DMA_CFG_DESC_TX_0_QID_POS); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1226 | d->mac.d[0] = 0; |
| 1227 | d->mac.d[1] = 0; |
| 1228 | d->mac.d[2] = 0; |
| 1229 | d->mac.ucode_cmd = 0; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1230 | /* translation type: 0 - bypass; 1 - 802.3; 2 - native wifi */ |
| 1231 | d->mac.d[2] = BIT(MAC_CFG_DESC_TX_2_SNAP_HDR_INSERTION_EN_POS) | |
| 1232 | (1 << MAC_CFG_DESC_TX_2_L2_TRANSLATION_TYPE_POS); |
| 1233 | |
| 1234 | return 0; |
| 1235 | } |
| 1236 | |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1237 | static inline |
| 1238 | void wil_tx_desc_set_nr_frags(struct vring_tx_desc *d, int nr_frags) |
| 1239 | { |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1240 | d->mac.d[2] |= (nr_frags << MAC_CFG_DESC_TX_2_NUM_OF_DESCRIPTORS_POS); |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1241 | } |
| 1242 | |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1243 | /** |
| 1244 | * Sets the descriptor @d up for csum and/or TSO offloading. The corresponding |
| 1245 | * @skb is used to obtain the protocol and headers length. |
| 1246 | * @tso_desc_type is a descriptor type for TSO: 0 - a header, 1 - first data, |
| 1247 | * 2 - middle, 3 - last descriptor. |
| 1248 | */ |
| 1249 | |
| 1250 | static void wil_tx_desc_offload_setup_tso(struct vring_tx_desc *d, |
| 1251 | struct sk_buff *skb, |
| 1252 | int tso_desc_type, bool is_ipv4, |
| 1253 | int tcp_hdr_len, int skb_net_hdr_len) |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 1254 | { |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1255 | d->dma.b11 = ETH_HLEN; /* MAC header length */ |
| 1256 | d->dma.b11 |= is_ipv4 << DMA_CFG_DESC_TX_OFFLOAD_CFG_L3T_IPV4_POS; |
| 1257 | |
| 1258 | d->dma.d0 |= (2 << DMA_CFG_DESC_TX_0_L4_TYPE_POS); |
| 1259 | /* L4 header len: TCP header length */ |
| 1260 | d->dma.d0 |= (tcp_hdr_len & DMA_CFG_DESC_TX_0_L4_LENGTH_MSK); |
| 1261 | |
| 1262 | /* Setup TSO: bit and desc type */ |
| 1263 | d->dma.d0 |= (BIT(DMA_CFG_DESC_TX_0_TCP_SEG_EN_POS)) | |
| 1264 | (tso_desc_type << DMA_CFG_DESC_TX_0_SEGMENT_BUF_DETAILS_POS); |
| 1265 | d->dma.d0 |= (is_ipv4 << DMA_CFG_DESC_TX_0_IPV4_CHECKSUM_EN_POS); |
| 1266 | |
| 1267 | d->dma.ip_length = skb_net_hdr_len; |
| 1268 | /* Enable TCP/UDP checksum */ |
| 1269 | d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_TCP_UDP_CHECKSUM_EN_POS); |
| 1270 | /* Calculate pseudo-header */ |
| 1271 | d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_PSEUDO_HEADER_CALC_EN_POS); |
| 1272 | } |
| 1273 | |
| 1274 | /** |
| 1275 | * Sets the descriptor @d up for csum. The corresponding |
| 1276 | * @skb is used to obtain the protocol and headers length. |
| 1277 | * Returns the protocol: 0 - not TCP, 1 - TCPv4, 2 - TCPv6. |
| 1278 | * Note, if d==NULL, the function only returns the protocol result. |
| 1279 | * |
| 1280 | * It is very similar to previous wil_tx_desc_offload_setup_tso. This |
| 1281 | * is "if unrolling" to optimize the critical path. |
| 1282 | */ |
| 1283 | |
| 1284 | static int wil_tx_desc_offload_setup(struct vring_tx_desc *d, |
| 1285 | struct sk_buff *skb){ |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 1286 | int protocol; |
| 1287 | |
| 1288 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 1289 | return 0; |
| 1290 | |
Vladimir Kondratiev | df2d08e | 2014-01-08 11:50:48 +0200 | [diff] [blame] | 1291 | d->dma.b11 = ETH_HLEN; /* MAC header length */ |
| 1292 | |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 1293 | switch (skb->protocol) { |
| 1294 | case cpu_to_be16(ETH_P_IP): |
| 1295 | protocol = ip_hdr(skb)->protocol; |
Vladimir Kondratiev | df2d08e | 2014-01-08 11:50:48 +0200 | [diff] [blame] | 1296 | d->dma.b11 |= BIT(DMA_CFG_DESC_TX_OFFLOAD_CFG_L3T_IPV4_POS); |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 1297 | break; |
| 1298 | case cpu_to_be16(ETH_P_IPV6): |
| 1299 | protocol = ipv6_hdr(skb)->nexthdr; |
| 1300 | break; |
| 1301 | default: |
| 1302 | return -EINVAL; |
| 1303 | } |
| 1304 | |
| 1305 | switch (protocol) { |
| 1306 | case IPPROTO_TCP: |
| 1307 | d->dma.d0 |= (2 << DMA_CFG_DESC_TX_0_L4_TYPE_POS); |
| 1308 | /* L4 header len: TCP header length */ |
| 1309 | d->dma.d0 |= |
| 1310 | (tcp_hdrlen(skb) & DMA_CFG_DESC_TX_0_L4_LENGTH_MSK); |
| 1311 | break; |
| 1312 | case IPPROTO_UDP: |
| 1313 | /* L4 header len: UDP header length */ |
| 1314 | d->dma.d0 |= |
| 1315 | (sizeof(struct udphdr) & DMA_CFG_DESC_TX_0_L4_LENGTH_MSK); |
| 1316 | break; |
| 1317 | default: |
| 1318 | return -EINVAL; |
| 1319 | } |
| 1320 | |
| 1321 | d->dma.ip_length = skb_network_header_len(skb); |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 1322 | /* Enable TCP/UDP checksum */ |
| 1323 | d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_TCP_UDP_CHECKSUM_EN_POS); |
| 1324 | /* Calculate pseudo-header */ |
| 1325 | d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_PSEUDO_HEADER_CALC_EN_POS); |
| 1326 | |
| 1327 | return 0; |
| 1328 | } |
| 1329 | |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1330 | static inline void wil_tx_last_desc(struct vring_tx_desc *d) |
| 1331 | { |
| 1332 | d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_CMD_EOP_POS) | |
| 1333 | BIT(DMA_CFG_DESC_TX_0_CMD_MARK_WB_POS) | |
| 1334 | BIT(DMA_CFG_DESC_TX_0_CMD_DMA_IT_POS); |
| 1335 | } |
| 1336 | |
| 1337 | static inline void wil_set_tx_desc_last_tso(volatile struct vring_tx_desc *d) |
| 1338 | { |
| 1339 | d->dma.d0 |= wil_tso_type_lst << |
| 1340 | DMA_CFG_DESC_TX_0_SEGMENT_BUF_DETAILS_POS; |
| 1341 | } |
| 1342 | |
| 1343 | static int __wil_tx_vring_tso(struct wil6210_priv *wil, struct vring *vring, |
| 1344 | struct sk_buff *skb) |
| 1345 | { |
| 1346 | struct device *dev = wil_to_dev(wil); |
| 1347 | |
| 1348 | /* point to descriptors in shared memory */ |
| 1349 | volatile struct vring_tx_desc *_desc = NULL, *_hdr_desc, |
| 1350 | *_first_desc = NULL; |
| 1351 | |
| 1352 | /* pointers to shadow descriptors */ |
| 1353 | struct vring_tx_desc desc_mem, hdr_desc_mem, first_desc_mem, |
| 1354 | *d = &hdr_desc_mem, *hdr_desc = &hdr_desc_mem, |
| 1355 | *first_desc = &first_desc_mem; |
| 1356 | |
| 1357 | /* pointer to shadow descriptors' context */ |
| 1358 | struct wil_ctx *hdr_ctx, *first_ctx = NULL; |
| 1359 | |
| 1360 | int descs_used = 0; /* total number of used descriptors */ |
| 1361 | int sg_desc_cnt = 0; /* number of descriptors for current mss*/ |
| 1362 | |
| 1363 | u32 swhead = vring->swhead; |
| 1364 | int used, avail = wil_vring_avail_tx(vring); |
| 1365 | int nr_frags = skb_shinfo(skb)->nr_frags; |
| 1366 | int min_desc_required = nr_frags + 1; |
| 1367 | int mss = skb_shinfo(skb)->gso_size; /* payload size w/o headers */ |
| 1368 | int f, len, hdrlen, headlen; |
| 1369 | int vring_index = vring - wil->vring_tx; |
| 1370 | struct vring_tx_data *txdata = &wil->vring_tx_data[vring_index]; |
| 1371 | uint i = swhead; |
| 1372 | dma_addr_t pa; |
| 1373 | const skb_frag_t *frag = NULL; |
| 1374 | int rem_data = mss; |
| 1375 | int lenmss; |
| 1376 | int hdr_compensation_need = true; |
| 1377 | int desc_tso_type = wil_tso_type_first; |
| 1378 | bool is_ipv4; |
| 1379 | int tcp_hdr_len; |
| 1380 | int skb_net_hdr_len; |
| 1381 | int gso_type; |
Hamad Kadmany | e3d2ed9 | 2015-10-25 15:59:22 +0200 | [diff] [blame] | 1382 | int rc = -EINVAL; |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1383 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 1384 | wil_dbg_txrx(wil, "tx_vring_tso: %d bytes to vring %d\n", skb->len, |
| 1385 | vring_index); |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1386 | |
| 1387 | if (unlikely(!txdata->enabled)) |
| 1388 | return -EINVAL; |
| 1389 | |
| 1390 | /* A typical page 4K is 3-4 payloads, we assume each fragment |
| 1391 | * is a full payload, that's how min_desc_required has been |
| 1392 | * calculated. In real we might need more or less descriptors, |
| 1393 | * this is the initial check only. |
| 1394 | */ |
| 1395 | if (unlikely(avail < min_desc_required)) { |
| 1396 | wil_err_ratelimited(wil, |
| 1397 | "TSO: Tx ring[%2d] full. No space for %d fragments\n", |
| 1398 | vring_index, min_desc_required); |
| 1399 | return -ENOMEM; |
| 1400 | } |
| 1401 | |
| 1402 | /* Header Length = MAC header len + IP header len + TCP header len*/ |
| 1403 | hdrlen = ETH_HLEN + |
| 1404 | (int)skb_network_header_len(skb) + |
| 1405 | tcp_hdrlen(skb); |
| 1406 | |
| 1407 | gso_type = skb_shinfo(skb)->gso_type & (SKB_GSO_TCPV6 | SKB_GSO_TCPV4); |
| 1408 | switch (gso_type) { |
| 1409 | case SKB_GSO_TCPV4: |
| 1410 | /* TCP v4, zero out the IP length and IPv4 checksum fields |
| 1411 | * as required by the offloading doc |
| 1412 | */ |
| 1413 | ip_hdr(skb)->tot_len = 0; |
| 1414 | ip_hdr(skb)->check = 0; |
| 1415 | is_ipv4 = true; |
| 1416 | break; |
| 1417 | case SKB_GSO_TCPV6: |
| 1418 | /* TCP v6, zero out the payload length */ |
| 1419 | ipv6_hdr(skb)->payload_len = 0; |
| 1420 | is_ipv4 = false; |
| 1421 | break; |
| 1422 | default: |
| 1423 | /* other than TCPv4 or TCPv6 types are not supported for TSO. |
| 1424 | * It is also illegal for both to be set simultaneously |
| 1425 | */ |
| 1426 | return -EINVAL; |
| 1427 | } |
| 1428 | |
| 1429 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 1430 | return -EINVAL; |
| 1431 | |
| 1432 | /* tcp header length and skb network header length are fixed for all |
| 1433 | * packet's descriptors - read then once here |
| 1434 | */ |
| 1435 | tcp_hdr_len = tcp_hdrlen(skb); |
| 1436 | skb_net_hdr_len = skb_network_header_len(skb); |
| 1437 | |
| 1438 | _hdr_desc = &vring->va[i].tx; |
| 1439 | |
| 1440 | pa = dma_map_single(dev, skb->data, hdrlen, DMA_TO_DEVICE); |
| 1441 | if (unlikely(dma_mapping_error(dev, pa))) { |
| 1442 | wil_err(wil, "TSO: Skb head DMA map error\n"); |
| 1443 | goto err_exit; |
| 1444 | } |
| 1445 | |
| 1446 | wil_tx_desc_map(hdr_desc, pa, hdrlen, vring_index); |
| 1447 | wil_tx_desc_offload_setup_tso(hdr_desc, skb, wil_tso_type_hdr, is_ipv4, |
| 1448 | tcp_hdr_len, skb_net_hdr_len); |
| 1449 | wil_tx_last_desc(hdr_desc); |
| 1450 | |
| 1451 | vring->ctx[i].mapped_as = wil_mapped_as_single; |
| 1452 | hdr_ctx = &vring->ctx[i]; |
| 1453 | |
| 1454 | descs_used++; |
| 1455 | headlen = skb_headlen(skb) - hdrlen; |
| 1456 | |
| 1457 | for (f = headlen ? -1 : 0; f < nr_frags; f++) { |
| 1458 | if (headlen) { |
| 1459 | len = headlen; |
| 1460 | wil_dbg_txrx(wil, "TSO: process skb head, len %u\n", |
| 1461 | len); |
| 1462 | } else { |
| 1463 | frag = &skb_shinfo(skb)->frags[f]; |
| 1464 | len = frag->size; |
| 1465 | wil_dbg_txrx(wil, "TSO: frag[%d]: len %u\n", f, len); |
| 1466 | } |
| 1467 | |
| 1468 | while (len) { |
| 1469 | wil_dbg_txrx(wil, |
| 1470 | "TSO: len %d, rem_data %d, descs_used %d\n", |
| 1471 | len, rem_data, descs_used); |
| 1472 | |
| 1473 | if (descs_used == avail) { |
Hamad Kadmany | e3d2ed9 | 2015-10-25 15:59:22 +0200 | [diff] [blame] | 1474 | wil_err_ratelimited(wil, "TSO: ring overflow\n"); |
| 1475 | rc = -ENOMEM; |
| 1476 | goto mem_error; |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | lenmss = min_t(int, rem_data, len); |
| 1480 | i = (swhead + descs_used) % vring->size; |
| 1481 | wil_dbg_txrx(wil, "TSO: lenmss %d, i %d\n", lenmss, i); |
| 1482 | |
| 1483 | if (!headlen) { |
| 1484 | pa = skb_frag_dma_map(dev, frag, |
| 1485 | frag->size - len, lenmss, |
| 1486 | DMA_TO_DEVICE); |
| 1487 | vring->ctx[i].mapped_as = wil_mapped_as_page; |
| 1488 | } else { |
| 1489 | pa = dma_map_single(dev, |
| 1490 | skb->data + |
| 1491 | skb_headlen(skb) - headlen, |
| 1492 | lenmss, |
| 1493 | DMA_TO_DEVICE); |
| 1494 | vring->ctx[i].mapped_as = wil_mapped_as_single; |
| 1495 | headlen -= lenmss; |
| 1496 | } |
| 1497 | |
Hamad Kadmany | e3d2ed9 | 2015-10-25 15:59:22 +0200 | [diff] [blame] | 1498 | if (unlikely(dma_mapping_error(dev, pa))) { |
| 1499 | wil_err(wil, "TSO: DMA map page error\n"); |
| 1500 | goto mem_error; |
| 1501 | } |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1502 | |
| 1503 | _desc = &vring->va[i].tx; |
| 1504 | |
| 1505 | if (!_first_desc) { |
| 1506 | _first_desc = _desc; |
| 1507 | first_ctx = &vring->ctx[i]; |
| 1508 | d = first_desc; |
| 1509 | } else { |
| 1510 | d = &desc_mem; |
| 1511 | } |
| 1512 | |
| 1513 | wil_tx_desc_map(d, pa, lenmss, vring_index); |
| 1514 | wil_tx_desc_offload_setup_tso(d, skb, desc_tso_type, |
| 1515 | is_ipv4, tcp_hdr_len, |
| 1516 | skb_net_hdr_len); |
| 1517 | |
| 1518 | /* use tso_type_first only once */ |
| 1519 | desc_tso_type = wil_tso_type_mid; |
| 1520 | |
| 1521 | descs_used++; /* desc used so far */ |
| 1522 | sg_desc_cnt++; /* desc used for this segment */ |
| 1523 | len -= lenmss; |
| 1524 | rem_data -= lenmss; |
| 1525 | |
| 1526 | wil_dbg_txrx(wil, |
| 1527 | "TSO: len %d, rem_data %d, descs_used %d, sg_desc_cnt %d,\n", |
| 1528 | len, rem_data, descs_used, sg_desc_cnt); |
| 1529 | |
| 1530 | /* Close the segment if reached mss size or last frag*/ |
| 1531 | if (rem_data == 0 || (f == nr_frags - 1 && len == 0)) { |
| 1532 | if (hdr_compensation_need) { |
| 1533 | /* first segment include hdr desc for |
| 1534 | * release |
| 1535 | */ |
| 1536 | hdr_ctx->nr_frags = sg_desc_cnt; |
| 1537 | wil_tx_desc_set_nr_frags(first_desc, |
| 1538 | sg_desc_cnt + |
| 1539 | 1); |
| 1540 | hdr_compensation_need = false; |
| 1541 | } else { |
| 1542 | wil_tx_desc_set_nr_frags(first_desc, |
| 1543 | sg_desc_cnt); |
| 1544 | } |
| 1545 | first_ctx->nr_frags = sg_desc_cnt - 1; |
| 1546 | |
| 1547 | wil_tx_last_desc(d); |
| 1548 | |
| 1549 | /* first descriptor may also be the last |
| 1550 | * for this mss - make sure not to copy |
| 1551 | * it twice |
| 1552 | */ |
| 1553 | if (first_desc != d) |
| 1554 | *_first_desc = *first_desc; |
| 1555 | |
| 1556 | /*last descriptor will be copied at the end |
| 1557 | * of this TS processing |
| 1558 | */ |
| 1559 | if (f < nr_frags - 1 || len > 0) |
| 1560 | *_desc = *d; |
| 1561 | |
| 1562 | rem_data = mss; |
| 1563 | _first_desc = NULL; |
| 1564 | sg_desc_cnt = 0; |
| 1565 | } else if (first_desc != d) /* update mid descriptor */ |
| 1566 | *_desc = *d; |
| 1567 | } |
| 1568 | } |
| 1569 | |
| 1570 | /* first descriptor may also be the last. |
| 1571 | * in this case d pointer is invalid |
| 1572 | */ |
| 1573 | if (_first_desc == _desc) |
| 1574 | d = first_desc; |
| 1575 | |
| 1576 | /* Last data descriptor */ |
| 1577 | wil_set_tx_desc_last_tso(d); |
| 1578 | *_desc = *d; |
| 1579 | |
| 1580 | /* Fill the total number of descriptors in first desc (hdr)*/ |
| 1581 | wil_tx_desc_set_nr_frags(hdr_desc, descs_used); |
| 1582 | *_hdr_desc = *hdr_desc; |
| 1583 | |
| 1584 | /* hold reference to skb |
| 1585 | * to prevent skb release before accounting |
| 1586 | * in case of immediate "tx done" |
| 1587 | */ |
| 1588 | vring->ctx[i].skb = skb_get(skb); |
| 1589 | |
| 1590 | /* performance monitoring */ |
| 1591 | used = wil_vring_used_tx(vring); |
| 1592 | if (wil_val_in_range(vring_idle_trsh, |
| 1593 | used, used + descs_used)) { |
| 1594 | txdata->idle += get_cycles() - txdata->last_idle; |
| 1595 | wil_dbg_txrx(wil, "Ring[%2d] not idle %d -> %d\n", |
| 1596 | vring_index, used, used + descs_used); |
| 1597 | } |
| 1598 | |
Maya Erez | eb26cff | 2016-05-16 22:23:30 +0300 | [diff] [blame] | 1599 | /* Make sure to advance the head only after descriptor update is done. |
| 1600 | * This will prevent a race condition where the completion thread |
| 1601 | * will see the DU bit set from previous run and will handle the |
| 1602 | * skb before it was completed. |
| 1603 | */ |
| 1604 | wmb(); |
| 1605 | |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1606 | /* advance swhead */ |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1607 | wil_vring_advance_head(vring, descs_used); |
Hamad Kadmany | e3d2ed9 | 2015-10-25 15:59:22 +0200 | [diff] [blame] | 1608 | wil_dbg_txrx(wil, "TSO: Tx swhead %d -> %d\n", swhead, vring->swhead); |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1609 | |
| 1610 | /* make sure all writes to descriptors (shared memory) are done before |
| 1611 | * committing them to HW |
| 1612 | */ |
| 1613 | wmb(); |
| 1614 | |
Vladimir Kondratiev | b9eeb51 | 2015-07-30 13:52:03 +0300 | [diff] [blame] | 1615 | wil_w(wil, vring->hwtail, vring->swhead); |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1616 | return 0; |
| 1617 | |
Hamad Kadmany | e3d2ed9 | 2015-10-25 15:59:22 +0200 | [diff] [blame] | 1618 | mem_error: |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1619 | while (descs_used > 0) { |
| 1620 | struct wil_ctx *ctx; |
| 1621 | |
Maya Erez | a1526f7 | 2016-05-16 22:23:33 +0300 | [diff] [blame] | 1622 | i = (swhead + descs_used - 1) % vring->size; |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1623 | d = (struct vring_tx_desc *)&vring->va[i].tx; |
| 1624 | _desc = &vring->va[i].tx; |
| 1625 | *d = *_desc; |
| 1626 | _desc->dma.status = TX_DMA_STATUS_DU; |
| 1627 | ctx = &vring->ctx[i]; |
| 1628 | wil_txdesc_unmap(dev, d, ctx); |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1629 | memset(ctx, 0, sizeof(*ctx)); |
| 1630 | descs_used--; |
| 1631 | } |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1632 | err_exit: |
Hamad Kadmany | e3d2ed9 | 2015-10-25 15:59:22 +0200 | [diff] [blame] | 1633 | return rc; |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1634 | } |
| 1635 | |
Vladimir Kondratiev | 5933a06 | 2015-02-01 10:55:13 +0200 | [diff] [blame] | 1636 | static int __wil_tx_vring(struct wil6210_priv *wil, struct vring *vring, |
| 1637 | struct sk_buff *skb) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1638 | { |
| 1639 | struct device *dev = wil_to_dev(wil); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 1640 | struct vring_tx_desc dd, *d = ⅆ |
| 1641 | volatile struct vring_tx_desc *_d; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1642 | u32 swhead = vring->swhead; |
| 1643 | int avail = wil_vring_avail_tx(vring); |
| 1644 | int nr_frags = skb_shinfo(skb)->nr_frags; |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 1645 | uint f = 0; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1646 | int vring_index = vring - wil->vring_tx; |
Vladimir Kondratiev | 7c0acf8 | 2014-06-16 19:37:05 +0300 | [diff] [blame] | 1647 | struct vring_tx_data *txdata = &wil->vring_tx_data[vring_index]; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1648 | uint i = swhead; |
| 1649 | dma_addr_t pa; |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 1650 | int used; |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 1651 | bool mcast = (vring_index == wil->bcast_vring); |
| 1652 | uint len = skb_headlen(skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1653 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 1654 | wil_dbg_txrx(wil, "tx_vring: %d bytes to vring %d\n", skb->len, |
| 1655 | vring_index); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1656 | |
Vladimir Kondratiev | 5933a06 | 2015-02-01 10:55:13 +0200 | [diff] [blame] | 1657 | if (unlikely(!txdata->enabled)) |
| 1658 | return -EINVAL; |
| 1659 | |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 1660 | if (unlikely(avail < 1 + nr_frags)) { |
Vladimir Kondratiev | 70801e1 | 2014-12-01 15:36:03 +0200 | [diff] [blame] | 1661 | wil_err_ratelimited(wil, |
Vladimir Kondratiev | 5b29c57 | 2015-02-01 10:55:14 +0200 | [diff] [blame] | 1662 | "Tx ring[%2d] full. No space for %d fragments\n", |
| 1663 | vring_index, 1 + nr_frags); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1664 | return -ENOMEM; |
| 1665 | } |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1666 | _d = &vring->va[i].tx; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1667 | |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1668 | pa = dma_map_single(dev, skb->data, skb_headlen(skb), DMA_TO_DEVICE); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1669 | |
Vladimir Kondratiev | 5b29c57 | 2015-02-01 10:55:14 +0200 | [diff] [blame] | 1670 | wil_dbg_txrx(wil, "Tx[%2d] skb %d bytes 0x%p -> %pad\n", vring_index, |
| 1671 | skb_headlen(skb), skb->data, &pa); |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 1672 | wil_hex_dump_txrx("Tx ", DUMP_PREFIX_OFFSET, 16, 1, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1673 | skb->data, skb_headlen(skb), false); |
| 1674 | |
| 1675 | if (unlikely(dma_mapping_error(dev, pa))) |
| 1676 | return -EINVAL; |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 1677 | vring->ctx[i].mapped_as = wil_mapped_as_single; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1678 | /* 1-st segment */ |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 1679 | wil_tx_desc_map(d, pa, len, vring_index); |
| 1680 | if (unlikely(mcast)) { |
| 1681 | d->mac.d[0] |= BIT(MAC_CFG_DESC_TX_0_MCS_EN_POS); /* MCS 0 */ |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 1682 | if (unlikely(len > WIL_BCAST_MCS0_LIMIT)) /* set MCS 1 */ |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 1683 | d->mac.d[0] |= (1 << MAC_CFG_DESC_TX_0_MCS_INDEX_POS); |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 1684 | } |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 1685 | /* Process TCP/UDP checksum offloading */ |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1686 | if (unlikely(wil_tx_desc_offload_setup(d, skb))) { |
Vladimir Kondratiev | 5b29c57 | 2015-02-01 10:55:14 +0200 | [diff] [blame] | 1687 | wil_err(wil, "Tx[%2d] Failed to set cksum, drop packet\n", |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 1688 | vring_index); |
| 1689 | goto dma_error; |
| 1690 | } |
| 1691 | |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1692 | vring->ctx[i].nr_frags = nr_frags; |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1693 | wil_tx_desc_set_nr_frags(d, nr_frags + 1); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 1694 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1695 | /* middle segments */ |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 1696 | for (; f < nr_frags; f++) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1697 | const struct skb_frag_struct *frag = |
| 1698 | &skb_shinfo(skb)->frags[f]; |
| 1699 | int len = skb_frag_size(frag); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1700 | |
Vladimir Kondratiev | e59d16c | 2015-02-01 10:55:12 +0200 | [diff] [blame] | 1701 | *_d = *d; |
Vladimir Kondratiev | 5b29c57 | 2015-02-01 10:55:14 +0200 | [diff] [blame] | 1702 | wil_dbg_txrx(wil, "Tx[%2d] desc[%4d]\n", vring_index, i); |
| 1703 | wil_hex_dump_txrx("TxD ", DUMP_PREFIX_NONE, 32, 4, |
| 1704 | (const void *)d, sizeof(*d), false); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1705 | i = (swhead + f + 1) % vring->size; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1706 | _d = &vring->va[i].tx; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1707 | pa = skb_frag_dma_map(dev, frag, 0, skb_frag_size(frag), |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1708 | DMA_TO_DEVICE); |
Hamad Kadmany | e3d2ed9 | 2015-10-25 15:59:22 +0200 | [diff] [blame] | 1709 | if (unlikely(dma_mapping_error(dev, pa))) { |
| 1710 | wil_err(wil, "Tx[%2d] failed to map fragment\n", |
| 1711 | vring_index); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1712 | goto dma_error; |
Hamad Kadmany | e3d2ed9 | 2015-10-25 15:59:22 +0200 | [diff] [blame] | 1713 | } |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 1714 | vring->ctx[i].mapped_as = wil_mapped_as_page; |
Kirshenbaum Erez | 99b55bd | 2013-06-23 12:59:34 +0300 | [diff] [blame] | 1715 | wil_tx_desc_map(d, pa, len, vring_index); |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1716 | /* no need to check return code - |
| 1717 | * if it succeeded for 1-st descriptor, |
| 1718 | * it will succeed here too |
| 1719 | */ |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1720 | wil_tx_desc_offload_setup(d, skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1721 | } |
| 1722 | /* for the last seg only */ |
| 1723 | d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_CMD_EOP_POS); |
Kirshenbaum Erez | 668b2bb | 2013-06-23 12:59:35 +0300 | [diff] [blame] | 1724 | d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_CMD_MARK_WB_POS); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1725 | d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_CMD_DMA_IT_POS); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 1726 | *_d = *d; |
Vladimir Kondratiev | 5b29c57 | 2015-02-01 10:55:14 +0200 | [diff] [blame] | 1727 | wil_dbg_txrx(wil, "Tx[%2d] desc[%4d]\n", vring_index, i); |
| 1728 | wil_hex_dump_txrx("TxD ", DUMP_PREFIX_NONE, 32, 4, |
| 1729 | (const void *)d, sizeof(*d), false); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1730 | |
Vladimir Kondratiev | 6cdadd4 | 2013-07-11 18:03:41 +0300 | [diff] [blame] | 1731 | /* hold reference to skb |
| 1732 | * to prevent skb release before accounting |
| 1733 | * in case of immediate "tx done" |
| 1734 | */ |
| 1735 | vring->ctx[i].skb = skb_get(skb); |
| 1736 | |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 1737 | /* performance monitoring */ |
| 1738 | used = wil_vring_used_tx(vring); |
| 1739 | if (wil_val_in_range(vring_idle_trsh, |
| 1740 | used, used + nr_frags + 1)) { |
Vladimir Kondratiev | 7c0acf8 | 2014-06-16 19:37:05 +0300 | [diff] [blame] | 1741 | txdata->idle += get_cycles() - txdata->last_idle; |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 1742 | wil_dbg_txrx(wil, "Ring[%2d] not idle %d -> %d\n", |
| 1743 | vring_index, used, used + nr_frags + 1); |
| 1744 | } |
Vladimir Kondratiev | 7c0acf8 | 2014-06-16 19:37:05 +0300 | [diff] [blame] | 1745 | |
Maya Erez | eb26cff | 2016-05-16 22:23:30 +0300 | [diff] [blame] | 1746 | /* Make sure to advance the head only after descriptor update is done. |
| 1747 | * This will prevent a race condition where the completion thread |
| 1748 | * will see the DU bit set from previous run and will handle the |
| 1749 | * skb before it was completed. |
| 1750 | */ |
| 1751 | wmb(); |
| 1752 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1753 | /* advance swhead */ |
| 1754 | wil_vring_advance_head(vring, nr_frags + 1); |
Vladimir Kondratiev | 5b29c57 | 2015-02-01 10:55:14 +0200 | [diff] [blame] | 1755 | wil_dbg_txrx(wil, "Tx[%2d] swhead %d -> %d\n", vring_index, swhead, |
| 1756 | vring->swhead); |
Vladimir Kondratiev | 9865809 | 2013-05-12 14:43:35 +0300 | [diff] [blame] | 1757 | trace_wil6210_tx(vring_index, swhead, skb->len, nr_frags); |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1758 | |
| 1759 | /* make sure all writes to descriptors (shared memory) are done before |
| 1760 | * committing them to HW |
| 1761 | */ |
| 1762 | wmb(); |
| 1763 | |
Vladimir Kondratiev | b9eeb51 | 2015-07-30 13:52:03 +0300 | [diff] [blame] | 1764 | wil_w(wil, vring->hwtail, vring->swhead); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1765 | |
| 1766 | return 0; |
| 1767 | dma_error: |
| 1768 | /* unmap what we have mapped */ |
Vladimir Kondratiev | c2a146f | 2013-07-21 11:34:36 +0300 | [diff] [blame] | 1769 | nr_frags = f + 1; /* frags mapped + one for skb head */ |
| 1770 | for (f = 0; f < nr_frags; f++) { |
Vladimir Kondratiev | c2a146f | 2013-07-21 11:34:36 +0300 | [diff] [blame] | 1771 | struct wil_ctx *ctx; |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 1772 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1773 | i = (swhead + f) % vring->size; |
Vladimir Kondratiev | c2a146f | 2013-07-21 11:34:36 +0300 | [diff] [blame] | 1774 | ctx = &vring->ctx[i]; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1775 | _d = &vring->va[i].tx; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 1776 | *d = *_d; |
| 1777 | _d->dma.status = TX_DMA_STATUS_DU; |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 1778 | wil_txdesc_unmap(dev, d, ctx); |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 1779 | |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 1780 | memset(ctx, 0, sizeof(*ctx)); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | return -EINVAL; |
| 1784 | } |
| 1785 | |
Vladimir Kondratiev | 5933a06 | 2015-02-01 10:55:13 +0200 | [diff] [blame] | 1786 | static int wil_tx_vring(struct wil6210_priv *wil, struct vring *vring, |
| 1787 | struct sk_buff *skb) |
| 1788 | { |
| 1789 | int vring_index = vring - wil->vring_tx; |
| 1790 | struct vring_tx_data *txdata = &wil->vring_tx_data[vring_index]; |
| 1791 | int rc; |
| 1792 | |
| 1793 | spin_lock(&txdata->lock); |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1794 | |
| 1795 | rc = (skb_is_gso(skb) ? __wil_tx_vring_tso : __wil_tx_vring) |
| 1796 | (wil, vring, skb); |
| 1797 | |
Vladimir Kondratiev | 5933a06 | 2015-02-01 10:55:13 +0200 | [diff] [blame] | 1798 | spin_unlock(&txdata->lock); |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 1799 | |
Vladimir Kondratiev | 5933a06 | 2015-02-01 10:55:13 +0200 | [diff] [blame] | 1800 | return rc; |
| 1801 | } |
| 1802 | |
Dedy Lansky | 970a98f | 2016-12-06 08:26:49 +0200 | [diff] [blame] | 1803 | /** |
| 1804 | * Check status of tx vrings and stop/wake net queues if needed |
| 1805 | * |
| 1806 | * This function does one of two checks: |
| 1807 | * In case check_stop is true, will check if net queues need to be stopped. If |
| 1808 | * the conditions for stopping are met, netif_tx_stop_all_queues() is called. |
| 1809 | * In case check_stop is false, will check if net queues need to be waked. If |
| 1810 | * the conditions for waking are met, netif_tx_wake_all_queues() is called. |
| 1811 | * vring is the vring which is currently being modified by either adding |
| 1812 | * descriptors (tx) into it or removing descriptors (tx complete) from it. Can |
| 1813 | * be null when irrelevant (e.g. connect/disconnect events). |
| 1814 | * |
| 1815 | * The implementation is to stop net queues if modified vring has low |
| 1816 | * descriptor availability. Wake if all vrings are not in low descriptor |
| 1817 | * availability and modified vring has high descriptor availability. |
| 1818 | */ |
| 1819 | static inline void __wil_update_net_queues(struct wil6210_priv *wil, |
| 1820 | struct vring *vring, |
| 1821 | bool check_stop) |
| 1822 | { |
| 1823 | int i; |
| 1824 | |
| 1825 | if (vring) |
| 1826 | wil_dbg_txrx(wil, "vring %d, check_stop=%d, stopped=%d", |
| 1827 | (int)(vring - wil->vring_tx), check_stop, |
| 1828 | wil->net_queue_stopped); |
| 1829 | else |
| 1830 | wil_dbg_txrx(wil, "check_stop=%d, stopped=%d", |
| 1831 | check_stop, wil->net_queue_stopped); |
| 1832 | |
| 1833 | if (check_stop == wil->net_queue_stopped) |
| 1834 | /* net queues already in desired state */ |
| 1835 | return; |
| 1836 | |
| 1837 | if (check_stop) { |
| 1838 | if (!vring || unlikely(wil_vring_avail_low(vring))) { |
| 1839 | /* not enough room in the vring */ |
| 1840 | netif_tx_stop_all_queues(wil_to_ndev(wil)); |
| 1841 | wil->net_queue_stopped = true; |
| 1842 | wil_dbg_txrx(wil, "netif_tx_stop called\n"); |
| 1843 | } |
| 1844 | return; |
| 1845 | } |
| 1846 | |
| 1847 | /* check wake */ |
| 1848 | for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) { |
| 1849 | struct vring *cur_vring = &wil->vring_tx[i]; |
| 1850 | struct vring_tx_data *txdata = &wil->vring_tx_data[i]; |
| 1851 | |
| 1852 | if (!cur_vring->va || !txdata->enabled || cur_vring == vring) |
| 1853 | continue; |
| 1854 | |
| 1855 | if (wil_vring_avail_low(cur_vring)) { |
| 1856 | wil_dbg_txrx(wil, "vring %d full, can't wake\n", |
| 1857 | (int)(cur_vring - wil->vring_tx)); |
| 1858 | return; |
| 1859 | } |
| 1860 | } |
| 1861 | |
| 1862 | if (!vring || wil_vring_avail_high(vring)) { |
| 1863 | /* enough room in the vring */ |
| 1864 | wil_dbg_txrx(wil, "calling netif_tx_wake\n"); |
| 1865 | netif_tx_wake_all_queues(wil_to_ndev(wil)); |
| 1866 | wil->net_queue_stopped = false; |
| 1867 | } |
| 1868 | } |
| 1869 | |
| 1870 | void wil_update_net_queues(struct wil6210_priv *wil, struct vring *vring, |
| 1871 | bool check_stop) |
| 1872 | { |
| 1873 | spin_lock(&wil->net_queue_lock); |
| 1874 | __wil_update_net_queues(wil, vring, check_stop); |
| 1875 | spin_unlock(&wil->net_queue_lock); |
| 1876 | } |
| 1877 | |
| 1878 | void wil_update_net_queues_bh(struct wil6210_priv *wil, struct vring *vring, |
| 1879 | bool check_stop) |
| 1880 | { |
| 1881 | spin_lock_bh(&wil->net_queue_lock); |
| 1882 | __wil_update_net_queues(wil, vring, check_stop); |
| 1883 | spin_unlock_bh(&wil->net_queue_lock); |
| 1884 | } |
| 1885 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1886 | netdev_tx_t wil_start_xmit(struct sk_buff *skb, struct net_device *ndev) |
| 1887 | { |
| 1888 | struct wil6210_priv *wil = ndev_to_wil(ndev); |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 1889 | struct ethhdr *eth = (void *)skb->data; |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 1890 | bool bcast = is_multicast_ether_addr(eth->h_dest); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1891 | struct vring *vring; |
Vladimir Kondratiev | aa27dea | 2014-03-17 15:34:11 +0200 | [diff] [blame] | 1892 | static bool pr_once_fw; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1893 | int rc; |
| 1894 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 1895 | wil_dbg_txrx(wil, "start_xmit\n"); |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 1896 | if (unlikely(!test_bit(wil_status_fwready, wil->status))) { |
Vladimir Kondratiev | aa27dea | 2014-03-17 15:34:11 +0200 | [diff] [blame] | 1897 | if (!pr_once_fw) { |
| 1898 | wil_err(wil, "FW not ready\n"); |
| 1899 | pr_once_fw = true; |
| 1900 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1901 | goto drop; |
| 1902 | } |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 1903 | if (unlikely(!test_bit(wil_status_fwconnected, wil->status))) { |
Maya Erez | d8ed043 | 2016-04-26 14:41:39 +0300 | [diff] [blame] | 1904 | wil_dbg_ratelimited(wil, "FW not connected, packet dropped\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1905 | goto drop; |
| 1906 | } |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 1907 | if (unlikely(wil->wdev->iftype == NL80211_IFTYPE_MONITOR)) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1908 | wil_err(wil, "Xmit in monitor mode not supported\n"); |
| 1909 | goto drop; |
| 1910 | } |
Vladimir Kondratiev | aa27dea | 2014-03-17 15:34:11 +0200 | [diff] [blame] | 1911 | pr_once_fw = false; |
Vladimir Kondratiev | d58db4e | 2013-06-09 09:12:54 +0300 | [diff] [blame] | 1912 | |
| 1913 | /* find vring */ |
Lior David | b1c0bbf | 2017-02-08 13:14:13 +0200 | [diff] [blame] | 1914 | if (wil->wdev->iftype == NL80211_IFTYPE_STATION && !wil->pbss) { |
| 1915 | /* in STA mode (ESS), all to same VRING (to AP) */ |
Vladimir Kondratiev | 54ed90a | 2014-12-23 09:47:15 +0200 | [diff] [blame] | 1916 | vring = wil_find_tx_vring_sta(wil, skb); |
Lior David | b1c0bbf | 2017-02-08 13:14:13 +0200 | [diff] [blame] | 1917 | } else if (bcast) { |
| 1918 | if (wil->pbss) |
| 1919 | /* in pbss, no bcast VRING - duplicate skb in |
| 1920 | * all stations VRINGs |
| 1921 | */ |
| 1922 | vring = wil_find_tx_bcast_2(wil, skb); |
| 1923 | else if (wil->wdev->iftype == NL80211_IFTYPE_AP) |
| 1924 | /* AP has a dedicated bcast VRING */ |
| 1925 | vring = wil_find_tx_bcast_1(wil, skb); |
| 1926 | else |
| 1927 | /* unexpected combination, fallback to duplicating |
| 1928 | * the skb in all stations VRINGs |
| 1929 | */ |
| 1930 | vring = wil_find_tx_bcast_2(wil, skb); |
| 1931 | } else { |
| 1932 | /* unicast, find specific VRING by dest. address */ |
| 1933 | vring = wil_find_tx_ucast(wil, skb); |
Vladimir Kondratiev | 54ed90a | 2014-12-23 09:47:15 +0200 | [diff] [blame] | 1934 | } |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 1935 | if (unlikely(!vring)) { |
Vladimir Kondratiev | 5aed139 | 2014-06-16 19:37:15 +0300 | [diff] [blame] | 1936 | wil_dbg_txrx(wil, "No Tx VRING found for %pM\n", eth->h_dest); |
Vladimir Kondratiev | d58db4e | 2013-06-09 09:12:54 +0300 | [diff] [blame] | 1937 | goto drop; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1938 | } |
Vladimir Kondratiev | d58db4e | 2013-06-09 09:12:54 +0300 | [diff] [blame] | 1939 | /* set up vring entry */ |
| 1940 | rc = wil_tx_vring(wil, vring, skb); |
| 1941 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1942 | switch (rc) { |
| 1943 | case 0: |
Dedy Lansky | 970a98f | 2016-12-06 08:26:49 +0200 | [diff] [blame] | 1944 | /* shall we stop net queues? */ |
| 1945 | wil_update_net_queues_bh(wil, vring, true); |
Vladimir Kondratiev | 795ce73 | 2013-01-28 18:31:00 +0200 | [diff] [blame] | 1946 | /* statistics will be updated on the tx_complete */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1947 | dev_kfree_skb_any(skb); |
| 1948 | return NETDEV_TX_OK; |
| 1949 | case -ENOMEM: |
| 1950 | return NETDEV_TX_BUSY; |
| 1951 | default: |
Vladimir Kondratiev | afda8bb | 2013-01-28 18:31:07 +0200 | [diff] [blame] | 1952 | break; /* goto drop; */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1953 | } |
| 1954 | drop: |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1955 | ndev->stats.tx_dropped++; |
| 1956 | dev_kfree_skb_any(skb); |
| 1957 | |
| 1958 | return NET_XMIT_DROP; |
| 1959 | } |
| 1960 | |
Vladimir Kondratiev | 713c8a2 | 2015-01-25 10:52:49 +0200 | [diff] [blame] | 1961 | static inline bool wil_need_txstat(struct sk_buff *skb) |
| 1962 | { |
| 1963 | struct ethhdr *eth = (void *)skb->data; |
| 1964 | |
| 1965 | return is_unicast_ether_addr(eth->h_dest) && skb->sk && |
| 1966 | (skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS); |
| 1967 | } |
| 1968 | |
| 1969 | static inline void wil_consume_skb(struct sk_buff *skb, bool acked) |
| 1970 | { |
| 1971 | if (unlikely(wil_need_txstat(skb))) |
| 1972 | skb_complete_wifi_ack(skb, acked); |
| 1973 | else |
| 1974 | acked ? dev_consume_skb_any(skb) : dev_kfree_skb_any(skb); |
| 1975 | } |
| 1976 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1977 | /** |
| 1978 | * Clean up transmitted skb's from the Tx VRING |
| 1979 | * |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 1980 | * Return number of descriptors cleared |
| 1981 | * |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1982 | * Safe to call from IRQ |
| 1983 | */ |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 1984 | int wil_tx_complete(struct wil6210_priv *wil, int ringid) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1985 | { |
Vladimir Kondratiev | 795ce73 | 2013-01-28 18:31:00 +0200 | [diff] [blame] | 1986 | struct net_device *ndev = wil_to_ndev(wil); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1987 | struct device *dev = wil_to_dev(wil); |
| 1988 | struct vring *vring = &wil->vring_tx[ringid]; |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 1989 | struct vring_tx_data *txdata = &wil->vring_tx_data[ringid]; |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 1990 | int done = 0; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 1991 | int cid = wil->vring2cid_tid[ringid][0]; |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 1992 | struct wil_net_stats *stats = NULL; |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1993 | volatile struct vring_tx_desc *_d; |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 1994 | int used_before_complete; |
| 1995 | int used_new; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1996 | |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 1997 | if (unlikely(!vring->va)) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1998 | wil_err(wil, "Tx irq[%d]: vring not initialized\n", ringid); |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 1999 | return 0; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 2000 | } |
| 2001 | |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 2002 | if (unlikely(!txdata->enabled)) { |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 2003 | wil_info(wil, "Tx irq[%d]: vring disabled\n", ringid); |
| 2004 | return 0; |
| 2005 | } |
| 2006 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 2007 | wil_dbg_txrx(wil, "tx_complete: (%d)\n", ringid); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 2008 | |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 2009 | used_before_complete = wil_vring_used_tx(vring); |
| 2010 | |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 2011 | if (cid < WIL6210_MAX_CID) |
| 2012 | stats = &wil->sta[cid].stats; |
| 2013 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 2014 | while (!wil_vring_is_empty(vring)) { |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2015 | int new_swtail; |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 2016 | struct wil_ctx *ctx = &vring->ctx[vring->swtail]; |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2017 | /** |
| 2018 | * For the fragmented skb, HW will set DU bit only for the |
Vladimir Kondratiev | 3d4bde1 | 2015-07-30 13:51:56 +0300 | [diff] [blame] | 2019 | * last fragment. look for it. |
| 2020 | * In TSO the first DU will include hdr desc |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2021 | */ |
| 2022 | int lf = (vring->swtail + ctx->nr_frags) % vring->size; |
| 2023 | /* TODO: check we are not past head */ |
Vladimir Kondratiev | 4de41be | 2013-04-18 14:33:52 +0300 | [diff] [blame] | 2024 | |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2025 | _d = &vring->va[lf].tx; |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 2026 | if (unlikely(!(_d->dma.status & TX_DMA_STATUS_DU))) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 2027 | break; |
| 2028 | |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2029 | new_swtail = (lf + 1) % vring->size; |
| 2030 | while (vring->swtail != new_swtail) { |
| 2031 | struct vring_tx_desc dd, *d = ⅆ |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2032 | u16 dmalen; |
Vladimir Kondratiev | 76dfa4b | 2014-07-14 09:49:39 +0300 | [diff] [blame] | 2033 | struct sk_buff *skb; |
| 2034 | |
| 2035 | ctx = &vring->ctx[vring->swtail]; |
| 2036 | skb = ctx->skb; |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2037 | _d = &vring->va[vring->swtail].tx; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 2038 | |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2039 | *d = *_d; |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 2040 | |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2041 | dmalen = le16_to_cpu(d->dma.length); |
| 2042 | trace_wil6210_tx_done(ringid, vring->swtail, dmalen, |
| 2043 | d->dma.error); |
| 2044 | wil_dbg_txrx(wil, |
Vladimir Kondratiev | 5b29c57 | 2015-02-01 10:55:14 +0200 | [diff] [blame] | 2045 | "TxC[%2d][%3d] : %d bytes, status 0x%02x err 0x%02x\n", |
| 2046 | ringid, vring->swtail, dmalen, |
| 2047 | d->dma.status, d->dma.error); |
| 2048 | wil_hex_dump_txrx("TxCD ", DUMP_PREFIX_NONE, 32, 4, |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2049 | (const void *)d, sizeof(*d), false); |
| 2050 | |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 2051 | wil_txdesc_unmap(dev, d, ctx); |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2052 | |
| 2053 | if (skb) { |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 2054 | if (likely(d->dma.error == 0)) { |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2055 | ndev->stats.tx_packets++; |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2056 | ndev->stats.tx_bytes += skb->len; |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 2057 | if (stats) { |
| 2058 | stats->tx_packets++; |
| 2059 | stats->tx_bytes += skb->len; |
| 2060 | } |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2061 | } else { |
| 2062 | ndev->stats.tx_errors++; |
Vladimir Kondratiev | 41d6b09 | 2015-03-15 16:00:23 +0200 | [diff] [blame] | 2063 | if (stats) |
| 2064 | stats->tx_errors++; |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2065 | } |
Vladimir Kondratiev | 713c8a2 | 2015-01-25 10:52:49 +0200 | [diff] [blame] | 2066 | wil_consume_skb(skb, d->dma.error == 0); |
Vladimir Kondratiev | 795ce73 | 2013-01-28 18:31:00 +0200 | [diff] [blame] | 2067 | } |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2068 | memset(ctx, 0, sizeof(*ctx)); |
Maya Erez | eb26cff | 2016-05-16 22:23:30 +0300 | [diff] [blame] | 2069 | /* Make sure the ctx is zeroed before updating the tail |
| 2070 | * to prevent a case where wil_tx_vring will see |
| 2071 | * this descriptor as used and handle it before ctx zero |
| 2072 | * is completed. |
| 2073 | */ |
| 2074 | wmb(); |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 2075 | /* There is no need to touch HW descriptor: |
| 2076 | * - ststus bit TX_DMA_STATUS_DU is set by design, |
| 2077 | * so hardware will not try to process this desc., |
| 2078 | * - rest of descriptor will be initialized on Tx. |
| 2079 | */ |
| 2080 | vring->swtail = wil_vring_next_tail(vring); |
| 2081 | done++; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 2082 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 2083 | } |
Vladimir Kondratiev | 67c3e1b | 2014-06-16 19:37:04 +0300 | [diff] [blame] | 2084 | |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 2085 | /* performance monitoring */ |
| 2086 | used_new = wil_vring_used_tx(vring); |
| 2087 | if (wil_val_in_range(vring_idle_trsh, |
| 2088 | used_new, used_before_complete)) { |
| 2089 | wil_dbg_txrx(wil, "Ring[%2d] idle %d -> %d\n", |
| 2090 | ringid, used_before_complete, used_new); |
Vladimir Kondratiev | 7c0acf8 | 2014-06-16 19:37:05 +0300 | [diff] [blame] | 2091 | txdata->last_idle = get_cycles(); |
| 2092 | } |
Vladimir Kondratiev | 67c3e1b | 2014-06-16 19:37:04 +0300 | [diff] [blame] | 2093 | |
Dedy Lansky | 970a98f | 2016-12-06 08:26:49 +0200 | [diff] [blame] | 2094 | /* shall we wake net queues? */ |
| 2095 | if (done) |
| 2096 | wil_update_net_queues(wil, vring, false); |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 2097 | |
| 2098 | return done; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 2099 | } |