Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1 | /* |
Vladimir Kondratiev | 02525a7 | 2014-08-06 10:31:51 +0300 | [diff] [blame] | 2 | * Copyright (c) 2012-2014 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; |
| 32 | module_param(rtap_include_phy_info, bool, S_IRUGO); |
| 33 | MODULE_PARM_DESC(rtap_include_phy_info, |
| 34 | " Include PHY info in the radiotap header, default - no"); |
| 35 | |
| 36 | static inline int wil_vring_is_empty(struct vring *vring) |
| 37 | { |
| 38 | return vring->swhead == vring->swtail; |
| 39 | } |
| 40 | |
| 41 | static inline u32 wil_vring_next_tail(struct vring *vring) |
| 42 | { |
| 43 | return (vring->swtail + 1) % vring->size; |
| 44 | } |
| 45 | |
| 46 | static inline void wil_vring_advance_head(struct vring *vring, int n) |
| 47 | { |
| 48 | vring->swhead = (vring->swhead + n) % vring->size; |
| 49 | } |
| 50 | |
| 51 | static inline int wil_vring_is_full(struct vring *vring) |
| 52 | { |
| 53 | return wil_vring_next_tail(vring) == vring->swhead; |
| 54 | } |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 55 | |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 56 | /* Used space in Tx Vring */ |
| 57 | static inline int wil_vring_used_tx(struct vring *vring) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 58 | { |
| 59 | u32 swhead = vring->swhead; |
| 60 | u32 swtail = vring->swtail; |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 61 | return (vring->size + swhead - swtail) % vring->size; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 64 | /* Available space in Tx Vring */ |
| 65 | static inline int wil_vring_avail_tx(struct vring *vring) |
| 66 | { |
| 67 | return vring->size - wil_vring_used_tx(vring) - 1; |
| 68 | } |
| 69 | |
| 70 | /* wil_vring_wmark_low - low watermark for available descriptor space */ |
Vladimir Kondratiev | 5bb6423 | 2014-05-27 14:45:46 +0300 | [diff] [blame] | 71 | static inline int wil_vring_wmark_low(struct vring *vring) |
| 72 | { |
| 73 | return vring->size/8; |
| 74 | } |
| 75 | |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 76 | /* wil_vring_wmark_high - high watermark for available descriptor space */ |
Vladimir Kondratiev | 5bb6423 | 2014-05-27 14:45:46 +0300 | [diff] [blame] | 77 | static inline int wil_vring_wmark_high(struct vring *vring) |
| 78 | { |
| 79 | return vring->size/4; |
| 80 | } |
| 81 | |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 82 | /* wil_val_in_range - check if value in [min,max) */ |
| 83 | static inline bool wil_val_in_range(int val, int min, int max) |
| 84 | { |
| 85 | return val >= min && val < max; |
| 86 | } |
| 87 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 88 | static int wil_vring_alloc(struct wil6210_priv *wil, struct vring *vring) |
| 89 | { |
| 90 | struct device *dev = wil_to_dev(wil); |
| 91 | size_t sz = vring->size * sizeof(vring->va[0]); |
| 92 | uint i; |
| 93 | |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 94 | wil_dbg_misc(wil, "%s()\n", __func__); |
| 95 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 96 | BUILD_BUG_ON(sizeof(vring->va[0]) != 32); |
| 97 | |
| 98 | vring->swhead = 0; |
| 99 | vring->swtail = 0; |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 100 | vring->ctx = kcalloc(vring->size, sizeof(vring->ctx[0]), GFP_KERNEL); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 101 | if (!vring->ctx) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 102 | vring->va = NULL; |
| 103 | return -ENOMEM; |
| 104 | } |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 105 | /* vring->va should be aligned on its size rounded up to power of 2 |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 106 | * This is granted by the dma_alloc_coherent |
| 107 | */ |
| 108 | vring->va = dma_alloc_coherent(dev, sz, &vring->pa, GFP_KERNEL); |
| 109 | if (!vring->va) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 110 | kfree(vring->ctx); |
| 111 | vring->ctx = NULL; |
| 112 | return -ENOMEM; |
| 113 | } |
| 114 | /* initially, all descriptors are SW owned |
| 115 | * For Tx and Rx, ownership bit is at the same location, thus |
| 116 | * we can use any |
| 117 | */ |
| 118 | for (i = 0; i < vring->size; i++) { |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 119 | volatile struct vring_tx_desc *_d = &vring->va[i].tx; |
| 120 | |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 121 | _d->dma.status = TX_DMA_STATUS_DU; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Vladimir Kondratiev | 39c52ee | 2014-05-27 14:45:49 +0300 | [diff] [blame] | 124 | wil_dbg_misc(wil, "vring[%d] 0x%p:%pad 0x%p\n", vring->size, |
| 125 | vring->va, &vring->pa, vring->ctx); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 130 | static void wil_txdesc_unmap(struct device *dev, struct vring_tx_desc *d, |
| 131 | struct wil_ctx *ctx) |
| 132 | { |
| 133 | dma_addr_t pa = wil_desc_addr(&d->dma.addr); |
| 134 | u16 dmalen = le16_to_cpu(d->dma.length); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 135 | |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 136 | switch (ctx->mapped_as) { |
| 137 | case wil_mapped_as_single: |
| 138 | dma_unmap_single(dev, pa, dmalen, DMA_TO_DEVICE); |
| 139 | break; |
| 140 | case wil_mapped_as_page: |
| 141 | dma_unmap_page(dev, pa, dmalen, DMA_TO_DEVICE); |
| 142 | break; |
| 143 | default: |
| 144 | break; |
| 145 | } |
| 146 | } |
| 147 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 148 | static void wil_vring_free(struct wil6210_priv *wil, struct vring *vring, |
| 149 | int tx) |
| 150 | { |
| 151 | struct device *dev = wil_to_dev(wil); |
| 152 | size_t sz = vring->size * sizeof(vring->va[0]); |
| 153 | |
Vladimir Kondratiev | ef77285 | 2014-09-10 16:34:31 +0300 | [diff] [blame] | 154 | if (tx) { |
| 155 | int vring_index = vring - wil->vring_tx; |
| 156 | |
| 157 | wil_dbg_misc(wil, "free Tx vring %d [%d] 0x%p:%pad 0x%p\n", |
| 158 | vring_index, vring->size, vring->va, |
| 159 | &vring->pa, vring->ctx); |
| 160 | } else { |
| 161 | wil_dbg_misc(wil, "free Rx vring [%d] 0x%p:%pad 0x%p\n", |
| 162 | vring->size, vring->va, |
| 163 | &vring->pa, vring->ctx); |
| 164 | } |
| 165 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 166 | while (!wil_vring_is_empty(vring)) { |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 167 | dma_addr_t pa; |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 168 | u16 dmalen; |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 169 | struct wil_ctx *ctx; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 170 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 171 | if (tx) { |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 172 | struct vring_tx_desc dd, *d = ⅆ |
| 173 | volatile struct vring_tx_desc *_d = |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 174 | &vring->va[vring->swtail].tx; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 175 | |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 176 | ctx = &vring->ctx[vring->swtail]; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 177 | *d = *_d; |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 178 | wil_txdesc_unmap(dev, d, ctx); |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 179 | if (ctx->skb) |
| 180 | dev_kfree_skb_any(ctx->skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 181 | vring->swtail = wil_vring_next_tail(vring); |
| 182 | } else { /* rx */ |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 183 | struct vring_rx_desc dd, *d = ⅆ |
| 184 | volatile struct vring_rx_desc *_d = |
Vladimir Kondratiev | 4d1ac07 | 2013-07-11 18:03:38 +0300 | [diff] [blame] | 185 | &vring->va[vring->swhead].rx; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 186 | |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 187 | ctx = &vring->ctx[vring->swhead]; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 188 | *d = *_d; |
| 189 | pa = wil_desc_addr(&d->dma.addr); |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 190 | dmalen = le16_to_cpu(d->dma.length); |
| 191 | dma_unmap_single(dev, pa, dmalen, DMA_FROM_DEVICE); |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 192 | kfree_skb(ctx->skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 193 | wil_vring_advance_head(vring, 1); |
| 194 | } |
| 195 | } |
| 196 | dma_free_coherent(dev, sz, (void *)vring->va, vring->pa); |
| 197 | kfree(vring->ctx); |
| 198 | vring->pa = 0; |
| 199 | vring->va = NULL; |
| 200 | vring->ctx = NULL; |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Allocate one skb for Rx VRING |
| 205 | * |
| 206 | * Safe to call from IRQ |
| 207 | */ |
| 208 | static int wil_vring_alloc_skb(struct wil6210_priv *wil, struct vring *vring, |
| 209 | u32 i, int headroom) |
| 210 | { |
| 211 | struct device *dev = wil_to_dev(wil); |
Vladimir Kondratiev | 9a06bec | 2014-10-28 16:51:27 +0200 | [diff] [blame] | 212 | unsigned int sz = mtu_max + ETH_HLEN; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 213 | struct vring_rx_desc dd, *d = ⅆ |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 214 | volatile struct vring_rx_desc *_d = &vring->va[i].rx; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 215 | dma_addr_t pa; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 216 | struct sk_buff *skb = dev_alloc_skb(sz + headroom); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 217 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 218 | if (unlikely(!skb)) |
| 219 | return -ENOMEM; |
| 220 | |
| 221 | skb_reserve(skb, headroom); |
| 222 | skb_put(skb, sz); |
| 223 | |
| 224 | pa = dma_map_single(dev, skb->data, skb->len, DMA_FROM_DEVICE); |
| 225 | if (unlikely(dma_mapping_error(dev, pa))) { |
| 226 | kfree_skb(skb); |
| 227 | return -ENOMEM; |
| 228 | } |
| 229 | |
| 230 | d->dma.d0 = BIT(9) | RX_DMA_D0_CMD_DMA_IT; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 231 | wil_desc_addr_set(&d->dma.addr, pa); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 232 | /* ip_length don't care */ |
| 233 | /* b11 don't care */ |
| 234 | /* error don't care */ |
| 235 | d->dma.status = 0; /* BIT(0) should be 0 for HW_OWNED */ |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 236 | d->dma.length = cpu_to_le16(sz); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 237 | *_d = *d; |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 238 | vring->ctx[i].skb = skb; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 239 | |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Adds radiotap header |
| 245 | * |
| 246 | * Any error indicated as "Bad FCS" |
| 247 | * |
| 248 | * Vendor data for 04:ce:14-1 (Wilocity-1) consists of: |
| 249 | * - Rx descriptor: 32 bytes |
| 250 | * - Phy info |
| 251 | */ |
| 252 | static void wil_rx_add_radiotap_header(struct wil6210_priv *wil, |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 253 | struct sk_buff *skb) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 254 | { |
| 255 | struct wireless_dev *wdev = wil->wdev; |
| 256 | struct wil6210_rtap { |
| 257 | struct ieee80211_radiotap_header rthdr; |
| 258 | /* fields should be in the order of bits in rthdr.it_present */ |
| 259 | /* flags */ |
| 260 | u8 flags; |
| 261 | /* channel */ |
| 262 | __le16 chnl_freq __aligned(2); |
| 263 | __le16 chnl_flags; |
| 264 | /* MCS */ |
| 265 | u8 mcs_present; |
| 266 | u8 mcs_flags; |
| 267 | u8 mcs_index; |
| 268 | } __packed; |
| 269 | struct wil6210_rtap_vendor { |
| 270 | struct wil6210_rtap rtap; |
| 271 | /* vendor */ |
| 272 | u8 vendor_oui[3] __aligned(2); |
| 273 | u8 vendor_ns; |
| 274 | __le16 vendor_skip; |
| 275 | u8 vendor_data[0]; |
| 276 | } __packed; |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 277 | struct vring_rx_desc *d = wil_skb_rxdesc(skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 278 | struct wil6210_rtap_vendor *rtap_vendor; |
| 279 | int rtap_len = sizeof(struct wil6210_rtap); |
| 280 | int phy_length = 0; /* phy info header size, bytes */ |
| 281 | static char phy_data[128]; |
| 282 | struct ieee80211_channel *ch = wdev->preset_chandef.chan; |
| 283 | |
| 284 | if (rtap_include_phy_info) { |
| 285 | rtap_len = sizeof(*rtap_vendor) + sizeof(*d); |
| 286 | /* calculate additional length */ |
| 287 | if (d->dma.status & RX_DMA_STATUS_PHY_INFO) { |
| 288 | /** |
| 289 | * PHY info starts from 8-byte boundary |
| 290 | * there are 8-byte lines, last line may be partially |
| 291 | * written (HW bug), thus FW configures for last line |
| 292 | * to be excessive. Driver skips this last line. |
| 293 | */ |
| 294 | int len = min_t(int, 8 + sizeof(phy_data), |
| 295 | wil_rxdesc_phy_length(d)); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 296 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 297 | if (len > 8) { |
| 298 | void *p = skb_tail_pointer(skb); |
| 299 | void *pa = PTR_ALIGN(p, 8); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 300 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 301 | if (skb_tailroom(skb) >= len + (pa - p)) { |
| 302 | phy_length = len - 8; |
| 303 | memcpy(phy_data, pa, phy_length); |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | rtap_len += phy_length; |
| 308 | } |
| 309 | |
| 310 | if (skb_headroom(skb) < rtap_len && |
| 311 | pskb_expand_head(skb, rtap_len, 0, GFP_ATOMIC)) { |
| 312 | wil_err(wil, "Unable to expand headrom to %d\n", rtap_len); |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | rtap_vendor = (void *)skb_push(skb, rtap_len); |
| 317 | memset(rtap_vendor, 0, rtap_len); |
| 318 | |
| 319 | rtap_vendor->rtap.rthdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 320 | rtap_vendor->rtap.rthdr.it_len = cpu_to_le16(rtap_len); |
| 321 | rtap_vendor->rtap.rthdr.it_present = cpu_to_le32( |
| 322 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
| 323 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 324 | (1 << IEEE80211_RADIOTAP_MCS)); |
| 325 | if (d->dma.status & RX_DMA_STATUS_ERROR) |
| 326 | rtap_vendor->rtap.flags |= IEEE80211_RADIOTAP_F_BADFCS; |
| 327 | |
| 328 | rtap_vendor->rtap.chnl_freq = cpu_to_le16(ch ? ch->center_freq : 58320); |
| 329 | rtap_vendor->rtap.chnl_flags = cpu_to_le16(0); |
| 330 | |
| 331 | rtap_vendor->rtap.mcs_present = IEEE80211_RADIOTAP_MCS_HAVE_MCS; |
| 332 | rtap_vendor->rtap.mcs_flags = 0; |
| 333 | rtap_vendor->rtap.mcs_index = wil_rxdesc_mcs(d); |
| 334 | |
| 335 | if (rtap_include_phy_info) { |
| 336 | rtap_vendor->rtap.rthdr.it_present |= cpu_to_le32(1 << |
| 337 | IEEE80211_RADIOTAP_VENDOR_NAMESPACE); |
| 338 | /* OUI for Wilocity 04:ce:14 */ |
| 339 | rtap_vendor->vendor_oui[0] = 0x04; |
| 340 | rtap_vendor->vendor_oui[1] = 0xce; |
| 341 | rtap_vendor->vendor_oui[2] = 0x14; |
| 342 | rtap_vendor->vendor_ns = 1; |
| 343 | /* Rx descriptor + PHY data */ |
| 344 | rtap_vendor->vendor_skip = cpu_to_le16(sizeof(*d) + |
| 345 | phy_length); |
| 346 | memcpy(rtap_vendor->vendor_data, (void *)d, sizeof(*d)); |
| 347 | memcpy(rtap_vendor->vendor_data + sizeof(*d), phy_data, |
| 348 | phy_length); |
| 349 | } |
| 350 | } |
| 351 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 352 | /** |
| 353 | * reap 1 frame from @swhead |
| 354 | * |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 355 | * Rx descriptor copied to skb->cb |
| 356 | * |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 357 | * Safe to call from IRQ |
| 358 | */ |
| 359 | static struct sk_buff *wil_vring_reap_rx(struct wil6210_priv *wil, |
| 360 | struct vring *vring) |
| 361 | { |
| 362 | struct device *dev = wil_to_dev(wil); |
| 363 | struct net_device *ndev = wil_to_ndev(wil); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 364 | volatile struct vring_rx_desc *_d; |
| 365 | struct vring_rx_desc *d; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 366 | struct sk_buff *skb; |
| 367 | dma_addr_t pa; |
Vladimir Kondratiev | 9a06bec | 2014-10-28 16:51:27 +0200 | [diff] [blame] | 368 | unsigned int sz = mtu_max + ETH_HLEN; |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 369 | u16 dmalen; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 370 | u8 ftype; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 371 | int cid; |
Vladimir Kondratiev | 148416a | 2015-03-15 16:00:16 +0200 | [diff] [blame^] | 372 | int i = (int)vring->swhead; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 373 | struct wil_net_stats *stats; |
| 374 | |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 375 | BUILD_BUG_ON(sizeof(struct vring_rx_desc) > sizeof(skb->cb)); |
| 376 | |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 377 | if (unlikely(wil_vring_is_empty(vring))) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 378 | return NULL; |
| 379 | |
Vladimir Kondratiev | 148416a | 2015-03-15 16:00:16 +0200 | [diff] [blame^] | 380 | _d = &vring->va[i].rx; |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 381 | if (unlikely(!(_d->dma.status & RX_DMA_STATUS_DU))) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 382 | /* it is not error, we just reached end of Rx done area */ |
| 383 | return NULL; |
| 384 | } |
| 385 | |
Vladimir Kondratiev | 148416a | 2015-03-15 16:00:16 +0200 | [diff] [blame^] | 386 | skb = vring->ctx[i].skb; |
| 387 | vring->ctx[i].skb = NULL; |
| 388 | wil_vring_advance_head(vring, 1); |
| 389 | if (!skb) { |
| 390 | wil_err(wil, "No Rx skb at [%d]\n", i); |
| 391 | return NULL; |
| 392 | } |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 393 | d = wil_skb_rxdesc(skb); |
| 394 | *d = *_d; |
| 395 | pa = wil_desc_addr(&d->dma.addr); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 396 | |
| 397 | dma_unmap_single(dev, pa, sz, DMA_FROM_DEVICE); |
| 398 | dmalen = le16_to_cpu(d->dma.length); |
| 399 | |
Vladimir Kondratiev | 148416a | 2015-03-15 16:00:16 +0200 | [diff] [blame^] | 400 | trace_wil6210_rx(i, d); |
| 401 | wil_dbg_txrx(wil, "Rx[%3d] : %d bytes\n", i, dmalen); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 402 | wil_hex_dump_txrx("Rx ", DUMP_PREFIX_NONE, 32, 4, |
| 403 | (const void *)d, sizeof(*d), false); |
| 404 | |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 405 | if (unlikely(dmalen > sz)) { |
Vladimir Kondratiev | e270045 | 2013-05-12 14:43:33 +0300 | [diff] [blame] | 406 | wil_err(wil, "Rx size too large: %d bytes!\n", dmalen); |
Wei Yongjun | 110dea0 | 2013-05-23 17:10:43 +0800 | [diff] [blame] | 407 | kfree_skb(skb); |
Vladimir Kondratiev | e270045 | 2013-05-12 14:43:33 +0300 | [diff] [blame] | 408 | return NULL; |
| 409 | } |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 410 | skb_trim(skb, dmalen); |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 411 | |
Vladimir Kondratiev | 1cbbcb0 | 2014-01-08 11:50:49 +0200 | [diff] [blame] | 412 | prefetch(skb->data); |
| 413 | |
Vladimir Kondratiev | c0d3771 | 2013-05-12 14:43:34 +0300 | [diff] [blame] | 414 | wil_hex_dump_txrx("Rx ", DUMP_PREFIX_OFFSET, 16, 1, |
| 415 | skb->data, skb_headlen(skb), false); |
| 416 | |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 417 | cid = wil_rxdesc_cid(d); |
| 418 | stats = &wil->sta[cid].stats; |
| 419 | stats->last_mcs_rx = wil_rxdesc_mcs(d); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 420 | |
| 421 | /* use radiotap header only if required */ |
| 422 | if (ndev->type == ARPHRD_IEEE80211_RADIOTAP) |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 423 | wil_rx_add_radiotap_header(wil, skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 424 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 425 | /* no extra checks if in sniffer mode */ |
| 426 | if (ndev->type != ARPHRD_ETHER) |
| 427 | return skb; |
| 428 | /* |
| 429 | * Non-data frames may be delivered through Rx DMA channel (ex: BAR) |
| 430 | * Driver should recognize it by frame type, that is found |
| 431 | * in Rx descriptor. If type is not data, it is 802.11 frame as is |
| 432 | */ |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 433 | ftype = wil_rxdesc_ftype(d) << 2; |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 434 | if (unlikely(ftype != IEEE80211_FTYPE_DATA)) { |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 435 | wil_dbg_txrx(wil, "Non-data frame ftype 0x%08x\n", ftype); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 436 | /* TODO: process it */ |
| 437 | kfree_skb(skb); |
| 438 | return NULL; |
| 439 | } |
| 440 | |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 441 | if (unlikely(skb->len < ETH_HLEN)) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 442 | wil_err(wil, "Short frame, len = %d\n", skb->len); |
| 443 | /* TODO: process it (i.e. BAR) */ |
| 444 | kfree_skb(skb); |
| 445 | return NULL; |
| 446 | } |
| 447 | |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 448 | /* L4 IDENT is on when HW calculated checksum, check status |
| 449 | * and in case of error drop the packet |
| 450 | * higher stack layers will handle retransmission (if required) |
| 451 | */ |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 452 | if (likely(d->dma.status & RX_DMA_STATUS_L4I)) { |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 453 | /* L4 protocol identified, csum calculated */ |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 454 | if (likely((d->dma.error & RX_DMA_ERROR_L4_ERR) == 0)) |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 455 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Vladimir Kondratiev | 4a68ab10 | 2013-08-13 15:25:32 +0300 | [diff] [blame] | 456 | /* If HW reports bad checksum, let IP stack re-check it |
| 457 | * For example, HW don't understand Microsoft IP stack that |
| 458 | * mis-calculates TCP checksum - if it should be 0x0, |
| 459 | * it writes 0xffff in violation of RFC 1624 |
| 460 | */ |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 461 | } |
| 462 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 463 | return skb; |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * allocate and fill up to @count buffers in rx ring |
| 468 | * buffers posted at @swtail |
| 469 | */ |
| 470 | static int wil_rx_refill(struct wil6210_priv *wil, int count) |
| 471 | { |
| 472 | struct net_device *ndev = wil_to_ndev(wil); |
| 473 | struct vring *v = &wil->vring_rx; |
| 474 | u32 next_tail; |
| 475 | int rc = 0; |
| 476 | int headroom = ndev->type == ARPHRD_IEEE80211_RADIOTAP ? |
| 477 | WIL6210_RTAP_SIZE : 0; |
| 478 | |
| 479 | for (; next_tail = wil_vring_next_tail(v), |
| 480 | (next_tail != v->swhead) && (count-- > 0); |
| 481 | v->swtail = next_tail) { |
| 482 | rc = wil_vring_alloc_skb(wil, v, v->swtail, headroom); |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 483 | if (unlikely(rc)) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 484 | wil_err(wil, "Error %d in wil_rx_refill[%d]\n", |
| 485 | rc, v->swtail); |
| 486 | break; |
| 487 | } |
| 488 | } |
| 489 | iowrite32(v->swtail, wil->csr + HOSTADDR(v->hwtail)); |
| 490 | |
| 491 | return rc; |
| 492 | } |
| 493 | |
| 494 | /* |
| 495 | * Pass Rx packet to the netif. Update statistics. |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 496 | * Called in softirq context (NAPI poll). |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 497 | */ |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 498 | 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] | 499 | { |
Vladimir Kondratiev | c42da99 | 2015-03-08 15:42:02 +0200 | [diff] [blame] | 500 | gro_result_t rc = GRO_NORMAL; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 501 | struct wil6210_priv *wil = ndev_to_wil(ndev); |
Vladimir Kondratiev | c42da99 | 2015-03-08 15:42:02 +0200 | [diff] [blame] | 502 | struct wireless_dev *wdev = wil_to_wdev(wil); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 503 | unsigned int len = skb->len; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 504 | struct vring_rx_desc *d = wil_skb_rxdesc(skb); |
| 505 | int cid = wil_rxdesc_cid(d); |
Vladimir Kondratiev | c42da99 | 2015-03-08 15:42:02 +0200 | [diff] [blame] | 506 | struct ethhdr *eth = (void *)skb->data; |
| 507 | /* here looking for DA, not A1, thus Rxdesc's 'mcast' indication |
| 508 | * is not suitable, need to look at data |
| 509 | */ |
| 510 | int mcast = is_multicast_ether_addr(eth->h_dest); |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 511 | struct wil_net_stats *stats = &wil->sta[cid].stats; |
Vladimir Kondratiev | c42da99 | 2015-03-08 15:42:02 +0200 | [diff] [blame] | 512 | struct sk_buff *xmit_skb = NULL; |
| 513 | static const char * const gro_res_str[] = { |
| 514 | [GRO_MERGED] = "GRO_MERGED", |
| 515 | [GRO_MERGED_FREE] = "GRO_MERGED_FREE", |
| 516 | [GRO_HELD] = "GRO_HELD", |
| 517 | [GRO_NORMAL] = "GRO_NORMAL", |
| 518 | [GRO_DROP] = "GRO_DROP", |
| 519 | }; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 520 | |
Vladimir Kondratiev | 241804c | 2013-01-28 18:31:02 +0200 | [diff] [blame] | 521 | skb_orphan(skb); |
| 522 | |
Vladimir Kondratiev | 02beaf1 | 2015-03-08 15:42:03 +0200 | [diff] [blame] | 523 | if (wdev->iftype == NL80211_IFTYPE_AP && !wil->ap_isolate) { |
Vladimir Kondratiev | c42da99 | 2015-03-08 15:42:02 +0200 | [diff] [blame] | 524 | if (mcast) { |
| 525 | /* send multicast frames both to higher layers in |
| 526 | * local net stack and back to the wireless medium |
| 527 | */ |
| 528 | xmit_skb = skb_copy(skb, GFP_ATOMIC); |
| 529 | } else { |
| 530 | int xmit_cid = wil_find_cid(wil, eth->h_dest); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 531 | |
Vladimir Kondratiev | c42da99 | 2015-03-08 15:42:02 +0200 | [diff] [blame] | 532 | if (xmit_cid >= 0) { |
| 533 | /* The destination station is associated to |
| 534 | * this AP (in this VLAN), so send the frame |
| 535 | * directly to it and do not pass it to local |
| 536 | * net stack. |
| 537 | */ |
| 538 | xmit_skb = skb; |
| 539 | skb = NULL; |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | if (xmit_skb) { |
| 544 | /* Send to wireless media and increase priority by 256 to |
| 545 | * keep the received priority instead of reclassifying |
| 546 | * the frame (see cfg80211_classify8021d). |
| 547 | */ |
| 548 | xmit_skb->dev = ndev; |
| 549 | xmit_skb->priority += 256; |
| 550 | xmit_skb->protocol = htons(ETH_P_802_3); |
| 551 | skb_reset_network_header(xmit_skb); |
| 552 | skb_reset_mac_header(xmit_skb); |
| 553 | wil_dbg_txrx(wil, "Rx -> Tx %d bytes\n", len); |
| 554 | dev_queue_xmit(xmit_skb); |
| 555 | } |
| 556 | |
| 557 | if (skb) { /* deliver to local stack */ |
| 558 | |
| 559 | skb->protocol = eth_type_trans(skb, ndev); |
| 560 | rc = napi_gro_receive(&wil->napi_rx, skb); |
| 561 | wil_dbg_txrx(wil, "Rx complete %d bytes => %s\n", |
| 562 | len, gro_res_str[rc]); |
| 563 | } |
| 564 | /* statistics. rc set to GRO_NORMAL for AP bridging */ |
Vladimir Kondratiev | b5998e6 | 2014-03-17 15:34:22 +0200 | [diff] [blame] | 565 | if (unlikely(rc == GRO_DROP)) { |
| 566 | ndev->stats.rx_dropped++; |
| 567 | stats->rx_dropped++; |
| 568 | wil_dbg_txrx(wil, "Rx drop %d bytes\n", len); |
| 569 | } else { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 570 | ndev->stats.rx_packets++; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 571 | stats->rx_packets++; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 572 | ndev->stats.rx_bytes += len; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 573 | stats->rx_bytes += len; |
Vladimir Kondratiev | c42da99 | 2015-03-08 15:42:02 +0200 | [diff] [blame] | 574 | if (mcast) |
| 575 | ndev->stats.multicast++; |
Vladimir Kondratiev | 194b482 | 2014-06-16 19:37:14 +0300 | [diff] [blame] | 576 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | /** |
| 580 | * Proceed all completed skb's from Rx VRING |
| 581 | * |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 582 | * Safe to call from NAPI poll, i.e. softirq with interrupts enabled |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 583 | */ |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 584 | void wil_rx_handle(struct wil6210_priv *wil, int *quota) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 585 | { |
| 586 | struct net_device *ndev = wil_to_ndev(wil); |
| 587 | struct vring *v = &wil->vring_rx; |
| 588 | struct sk_buff *skb; |
| 589 | |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 590 | if (unlikely(!v->va)) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 591 | wil_err(wil, "Rx IRQ while Rx not yet initialized\n"); |
| 592 | return; |
| 593 | } |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 594 | wil_dbg_txrx(wil, "%s()\n", __func__); |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 595 | while ((*quota > 0) && (NULL != (skb = wil_vring_reap_rx(wil, v)))) { |
| 596 | (*quota)--; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 597 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 598 | if (wil->wdev->iftype == NL80211_IFTYPE_MONITOR) { |
| 599 | skb->dev = ndev; |
| 600 | skb_reset_mac_header(skb); |
| 601 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 602 | skb->pkt_type = PACKET_OTHERHOST; |
| 603 | skb->protocol = htons(ETH_P_802_2); |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 604 | wil_netif_rx_any(skb, ndev); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 605 | } else { |
Vladimir Kondratiev | e4373d8 | 2014-12-23 09:47:21 +0200 | [diff] [blame] | 606 | wil_rx_reorder(wil, skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 607 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 608 | } |
| 609 | wil_rx_refill(wil, v->size); |
| 610 | } |
| 611 | |
Vladimir Kondratiev | d3762b4 | 2014-12-01 15:35:02 +0200 | [diff] [blame] | 612 | int wil_rx_init(struct wil6210_priv *wil, u16 size) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 613 | { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 614 | struct vring *vring = &wil->vring_rx; |
| 615 | int rc; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 616 | |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 617 | wil_dbg_misc(wil, "%s()\n", __func__); |
| 618 | |
Vladimir Kondratiev | 8bf6adb | 2014-03-17 15:34:17 +0200 | [diff] [blame] | 619 | if (vring->va) { |
| 620 | wil_err(wil, "Rx ring already allocated\n"); |
| 621 | return -EINVAL; |
| 622 | } |
| 623 | |
Vladimir Kondratiev | d3762b4 | 2014-12-01 15:35:02 +0200 | [diff] [blame] | 624 | vring->size = size; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 625 | rc = wil_vring_alloc(wil, vring); |
| 626 | if (rc) |
| 627 | return rc; |
| 628 | |
Vladimir Kondratiev | 47e19af | 2013-01-28 18:30:59 +0200 | [diff] [blame] | 629 | rc = wmi_rx_chain_add(wil, vring); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 630 | if (rc) |
| 631 | goto err_free; |
| 632 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 633 | rc = wil_rx_refill(wil, vring->size); |
| 634 | if (rc) |
| 635 | goto err_free; |
| 636 | |
| 637 | return 0; |
| 638 | err_free: |
| 639 | wil_vring_free(wil, vring, 0); |
| 640 | |
| 641 | return rc; |
| 642 | } |
| 643 | |
| 644 | void wil_rx_fini(struct wil6210_priv *wil) |
| 645 | { |
| 646 | struct vring *vring = &wil->vring_rx; |
| 647 | |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 648 | wil_dbg_misc(wil, "%s()\n", __func__); |
| 649 | |
Vladimir Kondratiev | 2acb422 | 2013-01-28 18:31:08 +0200 | [diff] [blame] | 650 | if (vring->va) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 651 | wil_vring_free(wil, vring, 0); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | int wil_vring_init_tx(struct wil6210_priv *wil, int id, int size, |
| 655 | int cid, int tid) |
| 656 | { |
| 657 | int rc; |
| 658 | struct wmi_vring_cfg_cmd cmd = { |
| 659 | .action = cpu_to_le32(WMI_VRING_CMD_ADD), |
| 660 | .vring_cfg = { |
| 661 | .tx_sw_ring = { |
Vladimir Kondratiev | 9a06bec | 2014-10-28 16:51:27 +0200 | [diff] [blame] | 662 | .max_mpdu_size = |
Vladimir Kondratiev | c44690a | 2014-12-23 09:47:11 +0200 | [diff] [blame] | 663 | cpu_to_le16(wil_mtu2macbuf(mtu_max)), |
Vladimir Kondratiev | b5d98e9 | 2013-04-18 14:33:51 +0300 | [diff] [blame] | 664 | .ring_size = cpu_to_le16(size), |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 665 | }, |
| 666 | .ringid = id, |
Vladimir Kondratiev | a70abea | 2014-03-17 15:34:05 +0200 | [diff] [blame] | 667 | .cidxtid = mk_cidxtid(cid, tid), |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 668 | .encap_trans_type = WMI_VRING_ENC_TYPE_802_3, |
| 669 | .mac_ctrl = 0, |
| 670 | .to_resolution = 0, |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 671 | .agg_max_wsize = 0, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 672 | .schd_params = { |
| 673 | .priority = cpu_to_le16(0), |
| 674 | .timeslot_us = cpu_to_le16(0xfff), |
| 675 | }, |
| 676 | }, |
| 677 | }; |
| 678 | struct { |
| 679 | struct wil6210_mbox_hdr_wmi wmi; |
| 680 | struct wmi_vring_cfg_done_event cmd; |
| 681 | } __packed reply; |
| 682 | struct vring *vring = &wil->vring_tx[id]; |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 683 | struct vring_tx_data *txdata = &wil->vring_tx_data[id]; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 684 | |
Vladimir Kondratiev | e0106ad | 2014-09-10 16:34:45 +0300 | [diff] [blame] | 685 | wil_dbg_misc(wil, "%s() max_mpdu_size %d\n", __func__, |
| 686 | cmd.vring_cfg.tx_sw_ring.max_mpdu_size); |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 687 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 688 | if (vring->va) { |
| 689 | wil_err(wil, "Tx ring [%d] already allocated\n", id); |
| 690 | rc = -EINVAL; |
| 691 | goto out; |
| 692 | } |
| 693 | |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 694 | memset(txdata, 0, sizeof(*txdata)); |
Vladimir Kondratiev | 5933a06 | 2015-02-01 10:55:13 +0200 | [diff] [blame] | 695 | spin_lock_init(&txdata->lock); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 696 | vring->size = size; |
| 697 | rc = wil_vring_alloc(wil, vring); |
| 698 | if (rc) |
| 699 | goto out; |
| 700 | |
Vladimir Kondratiev | 93ae6d4 | 2014-02-27 16:20:51 +0200 | [diff] [blame] | 701 | wil->vring2cid_tid[id][0] = cid; |
| 702 | wil->vring2cid_tid[id][1] = tid; |
| 703 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 704 | 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] | 705 | |
| 706 | rc = wmi_call(wil, WMI_VRING_CFG_CMDID, &cmd, sizeof(cmd), |
| 707 | WMI_VRING_CFG_DONE_EVENTID, &reply, sizeof(reply), 100); |
| 708 | if (rc) |
| 709 | goto out_free; |
| 710 | |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 711 | if (reply.cmd.status != WMI_FW_STATUS_SUCCESS) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 712 | wil_err(wil, "Tx config failed, status 0x%02x\n", |
| 713 | reply.cmd.status); |
Vladimir Kondratiev | c331997 | 2013-01-28 18:31:09 +0200 | [diff] [blame] | 714 | rc = -EINVAL; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 715 | goto out_free; |
| 716 | } |
| 717 | vring->hwtail = le32_to_cpu(reply.cmd.tx_vring_tail_ptr); |
| 718 | |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 719 | txdata->enabled = 1; |
Vladimir Kondratiev | 3a3def8 | 2014-12-23 09:47:05 +0200 | [diff] [blame] | 720 | if (wil->sta[cid].data_port_open && (agg_wsize >= 0)) |
| 721 | wil_addba_tx_request(wil, id, agg_wsize); |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 722 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 723 | return 0; |
| 724 | out_free: |
| 725 | wil_vring_free(wil, vring, 1); |
| 726 | out: |
| 727 | |
| 728 | return rc; |
| 729 | } |
| 730 | |
| 731 | void wil_vring_fini_tx(struct wil6210_priv *wil, int id) |
| 732 | { |
| 733 | struct vring *vring = &wil->vring_tx[id]; |
Vladimir Kondratiev | 3a124ed | 2014-12-23 09:47:04 +0200 | [diff] [blame] | 734 | struct vring_tx_data *txdata = &wil->vring_tx_data[id]; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 735 | |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 736 | WARN_ON(!mutex_is_locked(&wil->mutex)); |
| 737 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 738 | if (!vring->va) |
| 739 | return; |
| 740 | |
Vladimir Kondratiev | 9cf10d6 | 2014-09-10 16:34:36 +0300 | [diff] [blame] | 741 | wil_dbg_misc(wil, "%s() id=%d\n", __func__, id); |
| 742 | |
Vladimir Kondratiev | 5933a06 | 2015-02-01 10:55:13 +0200 | [diff] [blame] | 743 | spin_lock_bh(&txdata->lock); |
| 744 | txdata->enabled = 0; /* no Tx can be in progress or start anew */ |
| 745 | spin_unlock_bh(&txdata->lock); |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 746 | /* make sure NAPI won't touch this vring */ |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 747 | if (test_bit(wil_status_napi_en, wil->status)) |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 748 | napi_synchronize(&wil->napi_tx); |
| 749 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 750 | wil_vring_free(wil, vring, 1); |
Vladimir Kondratiev | 3a124ed | 2014-12-23 09:47:04 +0200 | [diff] [blame] | 751 | memset(txdata, 0, sizeof(*txdata)); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | static struct vring *wil_find_tx_vring(struct wil6210_priv *wil, |
| 755 | struct sk_buff *skb) |
| 756 | { |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 757 | int i; |
| 758 | struct ethhdr *eth = (void *)skb->data; |
| 759 | int cid = wil_find_cid(wil, eth->h_dest); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 760 | |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 761 | if (cid < 0) |
| 762 | return NULL; |
| 763 | |
Vladimir Kondratiev | e58c9f7 | 2014-03-17 15:34:06 +0200 | [diff] [blame] | 764 | if (!wil->sta[cid].data_port_open && |
| 765 | (skb->protocol != cpu_to_be16(ETH_P_PAE))) |
| 766 | return NULL; |
| 767 | |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 768 | /* TODO: fix for multiple TID */ |
| 769 | for (i = 0; i < ARRAY_SIZE(wil->vring2cid_tid); i++) { |
| 770 | if (wil->vring2cid_tid[i][0] == cid) { |
| 771 | struct vring *v = &wil->vring_tx[i]; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 772 | |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 773 | wil_dbg_txrx(wil, "%s(%pM) -> [%d]\n", |
| 774 | __func__, eth->h_dest, i); |
| 775 | if (v->va) { |
| 776 | return v; |
| 777 | } else { |
| 778 | wil_dbg_txrx(wil, "vring[%d] not valid\n", i); |
| 779 | return NULL; |
| 780 | } |
| 781 | } |
| 782 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 783 | |
| 784 | return NULL; |
| 785 | } |
| 786 | |
Vladimir Kondratiev | fb3cac5 | 2014-02-27 16:20:46 +0200 | [diff] [blame] | 787 | static void wil_set_da_for_vring(struct wil6210_priv *wil, |
| 788 | struct sk_buff *skb, int vring_index) |
| 789 | { |
| 790 | struct ethhdr *eth = (void *)skb->data; |
| 791 | int cid = wil->vring2cid_tid[vring_index][0]; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 792 | |
Vladimir Kondratiev | fb3cac5 | 2014-02-27 16:20:46 +0200 | [diff] [blame] | 793 | memcpy(eth->h_dest, wil->sta[cid].addr, ETH_ALEN); |
| 794 | } |
| 795 | |
| 796 | static int wil_tx_vring(struct wil6210_priv *wil, struct vring *vring, |
| 797 | struct sk_buff *skb); |
Vladimir Kondratiev | 54ed90a | 2014-12-23 09:47:15 +0200 | [diff] [blame] | 798 | |
| 799 | static struct vring *wil_find_tx_vring_sta(struct wil6210_priv *wil, |
| 800 | struct sk_buff *skb) |
| 801 | { |
| 802 | struct vring *v; |
| 803 | int i; |
| 804 | u8 cid; |
| 805 | |
| 806 | /* In the STA mode, it is expected to have only 1 VRING |
| 807 | * for the AP we connected to. |
| 808 | * find 1-st vring and see whether it is eligible for data |
| 809 | */ |
| 810 | for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) { |
| 811 | v = &wil->vring_tx[i]; |
| 812 | if (!v->va) |
| 813 | continue; |
| 814 | |
| 815 | cid = wil->vring2cid_tid[i][0]; |
| 816 | if (!wil->sta[cid].data_port_open && |
| 817 | (skb->protocol != cpu_to_be16(ETH_P_PAE))) |
| 818 | break; |
| 819 | |
| 820 | wil_dbg_txrx(wil, "Tx -> ring %d\n", i); |
| 821 | |
| 822 | return v; |
| 823 | } |
| 824 | |
| 825 | wil_dbg_txrx(wil, "Tx while no vrings active?\n"); |
| 826 | |
| 827 | return NULL; |
| 828 | } |
| 829 | |
Vladimir Kondratiev | fb3cac5 | 2014-02-27 16:20:46 +0200 | [diff] [blame] | 830 | /* |
| 831 | * Find 1-st vring and return it; set dest address for this vring in skb |
| 832 | * duplicate skb and send it to other active vrings |
| 833 | */ |
| 834 | static struct vring *wil_tx_bcast(struct wil6210_priv *wil, |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 835 | struct sk_buff *skb) |
Vladimir Kondratiev | fb3cac5 | 2014-02-27 16:20:46 +0200 | [diff] [blame] | 836 | { |
| 837 | struct vring *v, *v2; |
| 838 | struct sk_buff *skb2; |
| 839 | int i; |
Vladimir Kondratiev | e58c9f7 | 2014-03-17 15:34:06 +0200 | [diff] [blame] | 840 | u8 cid; |
Vladimir Kondratiev | fb3cac5 | 2014-02-27 16:20:46 +0200 | [diff] [blame] | 841 | |
Vladimir Kondratiev | e58c9f7 | 2014-03-17 15:34:06 +0200 | [diff] [blame] | 842 | /* find 1-st vring eligible for data */ |
Vladimir Kondratiev | fb3cac5 | 2014-02-27 16:20:46 +0200 | [diff] [blame] | 843 | for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) { |
| 844 | v = &wil->vring_tx[i]; |
Vladimir Kondratiev | e58c9f7 | 2014-03-17 15:34:06 +0200 | [diff] [blame] | 845 | if (!v->va) |
| 846 | continue; |
| 847 | |
| 848 | cid = wil->vring2cid_tid[i][0]; |
| 849 | if (!wil->sta[cid].data_port_open) |
| 850 | continue; |
| 851 | |
| 852 | goto found; |
Vladimir Kondratiev | fb3cac5 | 2014-02-27 16:20:46 +0200 | [diff] [blame] | 853 | } |
| 854 | |
Vladimir Kondratiev | 5aed139 | 2014-06-16 19:37:15 +0300 | [diff] [blame] | 855 | wil_dbg_txrx(wil, "Tx while no vrings active?\n"); |
Vladimir Kondratiev | fb3cac5 | 2014-02-27 16:20:46 +0200 | [diff] [blame] | 856 | |
| 857 | return NULL; |
| 858 | |
| 859 | found: |
| 860 | wil_dbg_txrx(wil, "BCAST -> ring %d\n", i); |
| 861 | wil_set_da_for_vring(wil, skb, i); |
| 862 | |
| 863 | /* find other active vrings and duplicate skb for each */ |
| 864 | for (i++; i < WIL6210_MAX_TX_RINGS; i++) { |
| 865 | v2 = &wil->vring_tx[i]; |
| 866 | if (!v2->va) |
| 867 | continue; |
Vladimir Kondratiev | e58c9f7 | 2014-03-17 15:34:06 +0200 | [diff] [blame] | 868 | cid = wil->vring2cid_tid[i][0]; |
| 869 | if (!wil->sta[cid].data_port_open) |
| 870 | continue; |
| 871 | |
Vladimir Kondratiev | fb3cac5 | 2014-02-27 16:20:46 +0200 | [diff] [blame] | 872 | skb2 = skb_copy(skb, GFP_ATOMIC); |
| 873 | if (skb2) { |
| 874 | wil_dbg_txrx(wil, "BCAST DUP -> ring %d\n", i); |
| 875 | wil_set_da_for_vring(wil, skb2, i); |
| 876 | wil_tx_vring(wil, v2, skb2); |
| 877 | } else { |
| 878 | wil_err(wil, "skb_copy failed\n"); |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | return v; |
| 883 | } |
| 884 | |
Kirshenbaum Erez | 99b55bd | 2013-06-23 12:59:34 +0300 | [diff] [blame] | 885 | static int wil_tx_desc_map(struct vring_tx_desc *d, dma_addr_t pa, u32 len, |
| 886 | int vring_index) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 887 | { |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 888 | wil_desc_addr_set(&d->dma.addr, pa); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 889 | d->dma.ip_length = 0; |
| 890 | /* 0..6: mac_length; 7:ip_version 0-IP6 1-IP4*/ |
| 891 | d->dma.b11 = 0/*14 | BIT(7)*/; |
| 892 | d->dma.error = 0; |
| 893 | d->dma.status = 0; /* BIT(0) should be 0 for HW_OWNED */ |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 894 | d->dma.length = cpu_to_le16((u16)len); |
Kirshenbaum Erez | 99b55bd | 2013-06-23 12:59:34 +0300 | [diff] [blame] | 895 | d->dma.d0 = (vring_index << DMA_CFG_DESC_TX_0_QID_POS); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 896 | d->mac.d[0] = 0; |
| 897 | d->mac.d[1] = 0; |
| 898 | d->mac.d[2] = 0; |
| 899 | d->mac.ucode_cmd = 0; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 900 | /* translation type: 0 - bypass; 1 - 802.3; 2 - native wifi */ |
| 901 | d->mac.d[2] = BIT(MAC_CFG_DESC_TX_2_SNAP_HDR_INSERTION_EN_POS) | |
| 902 | (1 << MAC_CFG_DESC_TX_2_L2_TRANSLATION_TYPE_POS); |
| 903 | |
| 904 | return 0; |
| 905 | } |
| 906 | |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 907 | static inline |
| 908 | void wil_tx_desc_set_nr_frags(struct vring_tx_desc *d, int nr_frags) |
| 909 | { |
| 910 | d->mac.d[2] |= ((nr_frags + 1) << |
| 911 | MAC_CFG_DESC_TX_2_NUM_OF_DESCRIPTORS_POS); |
| 912 | } |
| 913 | |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 914 | static int wil_tx_desc_offload_cksum_set(struct wil6210_priv *wil, |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 915 | struct vring_tx_desc *d, |
| 916 | struct sk_buff *skb) |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 917 | { |
| 918 | int protocol; |
| 919 | |
| 920 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 921 | return 0; |
| 922 | |
Vladimir Kondratiev | df2d08e | 2014-01-08 11:50:48 +0200 | [diff] [blame] | 923 | d->dma.b11 = ETH_HLEN; /* MAC header length */ |
| 924 | |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 925 | switch (skb->protocol) { |
| 926 | case cpu_to_be16(ETH_P_IP): |
| 927 | protocol = ip_hdr(skb)->protocol; |
Vladimir Kondratiev | df2d08e | 2014-01-08 11:50:48 +0200 | [diff] [blame] | 928 | 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] | 929 | break; |
| 930 | case cpu_to_be16(ETH_P_IPV6): |
| 931 | protocol = ipv6_hdr(skb)->nexthdr; |
| 932 | break; |
| 933 | default: |
| 934 | return -EINVAL; |
| 935 | } |
| 936 | |
| 937 | switch (protocol) { |
| 938 | case IPPROTO_TCP: |
| 939 | d->dma.d0 |= (2 << DMA_CFG_DESC_TX_0_L4_TYPE_POS); |
| 940 | /* L4 header len: TCP header length */ |
| 941 | d->dma.d0 |= |
| 942 | (tcp_hdrlen(skb) & DMA_CFG_DESC_TX_0_L4_LENGTH_MSK); |
| 943 | break; |
| 944 | case IPPROTO_UDP: |
| 945 | /* L4 header len: UDP header length */ |
| 946 | d->dma.d0 |= |
| 947 | (sizeof(struct udphdr) & DMA_CFG_DESC_TX_0_L4_LENGTH_MSK); |
| 948 | break; |
| 949 | default: |
| 950 | return -EINVAL; |
| 951 | } |
| 952 | |
| 953 | d->dma.ip_length = skb_network_header_len(skb); |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 954 | /* Enable TCP/UDP checksum */ |
| 955 | d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_TCP_UDP_CHECKSUM_EN_POS); |
| 956 | /* Calculate pseudo-header */ |
| 957 | d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_PSEUDO_HEADER_CALC_EN_POS); |
| 958 | |
| 959 | return 0; |
| 960 | } |
| 961 | |
Vladimir Kondratiev | 5933a06 | 2015-02-01 10:55:13 +0200 | [diff] [blame] | 962 | static int __wil_tx_vring(struct wil6210_priv *wil, struct vring *vring, |
| 963 | struct sk_buff *skb) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 964 | { |
| 965 | struct device *dev = wil_to_dev(wil); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 966 | struct vring_tx_desc dd, *d = ⅆ |
| 967 | volatile struct vring_tx_desc *_d; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 968 | u32 swhead = vring->swhead; |
| 969 | int avail = wil_vring_avail_tx(vring); |
| 970 | int nr_frags = skb_shinfo(skb)->nr_frags; |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 971 | uint f = 0; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 972 | int vring_index = vring - wil->vring_tx; |
Vladimir Kondratiev | 7c0acf8 | 2014-06-16 19:37:05 +0300 | [diff] [blame] | 973 | struct vring_tx_data *txdata = &wil->vring_tx_data[vring_index]; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 974 | uint i = swhead; |
| 975 | dma_addr_t pa; |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 976 | int used; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 977 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 978 | wil_dbg_txrx(wil, "%s()\n", __func__); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 979 | |
Vladimir Kondratiev | 5933a06 | 2015-02-01 10:55:13 +0200 | [diff] [blame] | 980 | if (unlikely(!txdata->enabled)) |
| 981 | return -EINVAL; |
| 982 | |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 983 | if (unlikely(avail < 1 + nr_frags)) { |
Vladimir Kondratiev | 70801e1 | 2014-12-01 15:36:03 +0200 | [diff] [blame] | 984 | wil_err_ratelimited(wil, |
Vladimir Kondratiev | 5b29c57 | 2015-02-01 10:55:14 +0200 | [diff] [blame] | 985 | "Tx ring[%2d] full. No space for %d fragments\n", |
| 986 | vring_index, 1 + nr_frags); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 987 | return -ENOMEM; |
| 988 | } |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 989 | _d = &vring->va[i].tx; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 990 | |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 991 | 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] | 992 | |
Vladimir Kondratiev | 5b29c57 | 2015-02-01 10:55:14 +0200 | [diff] [blame] | 993 | wil_dbg_txrx(wil, "Tx[%2d] skb %d bytes 0x%p -> %pad\n", vring_index, |
| 994 | skb_headlen(skb), skb->data, &pa); |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 995 | wil_hex_dump_txrx("Tx ", DUMP_PREFIX_OFFSET, 16, 1, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 996 | skb->data, skb_headlen(skb), false); |
| 997 | |
| 998 | if (unlikely(dma_mapping_error(dev, pa))) |
| 999 | return -EINVAL; |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 1000 | vring->ctx[i].mapped_as = wil_mapped_as_single; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1001 | /* 1-st segment */ |
Kirshenbaum Erez | 99b55bd | 2013-06-23 12:59:34 +0300 | [diff] [blame] | 1002 | wil_tx_desc_map(d, pa, skb_headlen(skb), vring_index); |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 1003 | /* Process TCP/UDP checksum offloading */ |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 1004 | if (unlikely(wil_tx_desc_offload_cksum_set(wil, d, skb))) { |
Vladimir Kondratiev | 5b29c57 | 2015-02-01 10:55:14 +0200 | [diff] [blame] | 1005 | wil_err(wil, "Tx[%2d] Failed to set cksum, drop packet\n", |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 1006 | vring_index); |
| 1007 | goto dma_error; |
| 1008 | } |
| 1009 | |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1010 | vring->ctx[i].nr_frags = nr_frags; |
| 1011 | wil_tx_desc_set_nr_frags(d, nr_frags); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 1012 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1013 | /* middle segments */ |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 1014 | for (; f < nr_frags; f++) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1015 | const struct skb_frag_struct *frag = |
| 1016 | &skb_shinfo(skb)->frags[f]; |
| 1017 | int len = skb_frag_size(frag); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1018 | |
Vladimir Kondratiev | e59d16c | 2015-02-01 10:55:12 +0200 | [diff] [blame] | 1019 | *_d = *d; |
Vladimir Kondratiev | 5b29c57 | 2015-02-01 10:55:14 +0200 | [diff] [blame] | 1020 | wil_dbg_txrx(wil, "Tx[%2d] desc[%4d]\n", vring_index, i); |
| 1021 | wil_hex_dump_txrx("TxD ", DUMP_PREFIX_NONE, 32, 4, |
| 1022 | (const void *)d, sizeof(*d), false); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1023 | i = (swhead + f + 1) % vring->size; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1024 | _d = &vring->va[i].tx; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1025 | pa = skb_frag_dma_map(dev, frag, 0, skb_frag_size(frag), |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1026 | DMA_TO_DEVICE); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1027 | if (unlikely(dma_mapping_error(dev, pa))) |
| 1028 | goto dma_error; |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 1029 | vring->ctx[i].mapped_as = wil_mapped_as_page; |
Kirshenbaum Erez | 99b55bd | 2013-06-23 12:59:34 +0300 | [diff] [blame] | 1030 | wil_tx_desc_map(d, pa, len, vring_index); |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1031 | /* no need to check return code - |
| 1032 | * if it succeeded for 1-st descriptor, |
| 1033 | * it will succeed here too |
| 1034 | */ |
| 1035 | wil_tx_desc_offload_cksum_set(wil, d, skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1036 | } |
| 1037 | /* for the last seg only */ |
| 1038 | d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_CMD_EOP_POS); |
Kirshenbaum Erez | 668b2bb | 2013-06-23 12:59:35 +0300 | [diff] [blame] | 1039 | 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] | 1040 | 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] | 1041 | *_d = *d; |
Vladimir Kondratiev | 5b29c57 | 2015-02-01 10:55:14 +0200 | [diff] [blame] | 1042 | wil_dbg_txrx(wil, "Tx[%2d] desc[%4d]\n", vring_index, i); |
| 1043 | wil_hex_dump_txrx("TxD ", DUMP_PREFIX_NONE, 32, 4, |
| 1044 | (const void *)d, sizeof(*d), false); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1045 | |
Vladimir Kondratiev | 6cdadd4 | 2013-07-11 18:03:41 +0300 | [diff] [blame] | 1046 | /* hold reference to skb |
| 1047 | * to prevent skb release before accounting |
| 1048 | * in case of immediate "tx done" |
| 1049 | */ |
| 1050 | vring->ctx[i].skb = skb_get(skb); |
| 1051 | |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 1052 | /* performance monitoring */ |
| 1053 | used = wil_vring_used_tx(vring); |
| 1054 | if (wil_val_in_range(vring_idle_trsh, |
| 1055 | used, used + nr_frags + 1)) { |
Vladimir Kondratiev | 7c0acf8 | 2014-06-16 19:37:05 +0300 | [diff] [blame] | 1056 | txdata->idle += get_cycles() - txdata->last_idle; |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 1057 | wil_dbg_txrx(wil, "Ring[%2d] not idle %d -> %d\n", |
| 1058 | vring_index, used, used + nr_frags + 1); |
| 1059 | } |
Vladimir Kondratiev | 7c0acf8 | 2014-06-16 19:37:05 +0300 | [diff] [blame] | 1060 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1061 | /* advance swhead */ |
| 1062 | wil_vring_advance_head(vring, nr_frags + 1); |
Vladimir Kondratiev | 5b29c57 | 2015-02-01 10:55:14 +0200 | [diff] [blame] | 1063 | wil_dbg_txrx(wil, "Tx[%2d] swhead %d -> %d\n", vring_index, swhead, |
| 1064 | vring->swhead); |
Vladimir Kondratiev | 9865809 | 2013-05-12 14:43:35 +0300 | [diff] [blame] | 1065 | trace_wil6210_tx(vring_index, swhead, skb->len, nr_frags); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1066 | iowrite32(vring->swhead, wil->csr + HOSTADDR(vring->hwtail)); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1067 | |
| 1068 | return 0; |
| 1069 | dma_error: |
| 1070 | /* unmap what we have mapped */ |
Vladimir Kondratiev | c2a146f | 2013-07-21 11:34:36 +0300 | [diff] [blame] | 1071 | nr_frags = f + 1; /* frags mapped + one for skb head */ |
| 1072 | for (f = 0; f < nr_frags; f++) { |
Vladimir Kondratiev | c2a146f | 2013-07-21 11:34:36 +0300 | [diff] [blame] | 1073 | struct wil_ctx *ctx; |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 1074 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1075 | i = (swhead + f) % vring->size; |
Vladimir Kondratiev | c2a146f | 2013-07-21 11:34:36 +0300 | [diff] [blame] | 1076 | ctx = &vring->ctx[i]; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1077 | _d = &vring->va[i].tx; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 1078 | *d = *_d; |
| 1079 | _d->dma.status = TX_DMA_STATUS_DU; |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 1080 | wil_txdesc_unmap(dev, d, ctx); |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 1081 | |
| 1082 | if (ctx->skb) |
| 1083 | dev_kfree_skb_any(ctx->skb); |
| 1084 | |
| 1085 | memset(ctx, 0, sizeof(*ctx)); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | return -EINVAL; |
| 1089 | } |
| 1090 | |
Vladimir Kondratiev | 5933a06 | 2015-02-01 10:55:13 +0200 | [diff] [blame] | 1091 | static int wil_tx_vring(struct wil6210_priv *wil, struct vring *vring, |
| 1092 | struct sk_buff *skb) |
| 1093 | { |
| 1094 | int vring_index = vring - wil->vring_tx; |
| 1095 | struct vring_tx_data *txdata = &wil->vring_tx_data[vring_index]; |
| 1096 | int rc; |
| 1097 | |
| 1098 | spin_lock(&txdata->lock); |
| 1099 | rc = __wil_tx_vring(wil, vring, skb); |
| 1100 | spin_unlock(&txdata->lock); |
| 1101 | return rc; |
| 1102 | } |
| 1103 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1104 | netdev_tx_t wil_start_xmit(struct sk_buff *skb, struct net_device *ndev) |
| 1105 | { |
| 1106 | struct wil6210_priv *wil = ndev_to_wil(ndev); |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 1107 | struct ethhdr *eth = (void *)skb->data; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1108 | struct vring *vring; |
Vladimir Kondratiev | aa27dea | 2014-03-17 15:34:11 +0200 | [diff] [blame] | 1109 | static bool pr_once_fw; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1110 | int rc; |
| 1111 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 1112 | wil_dbg_txrx(wil, "%s()\n", __func__); |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 1113 | if (unlikely(!test_bit(wil_status_fwready, wil->status))) { |
Vladimir Kondratiev | aa27dea | 2014-03-17 15:34:11 +0200 | [diff] [blame] | 1114 | if (!pr_once_fw) { |
| 1115 | wil_err(wil, "FW not ready\n"); |
| 1116 | pr_once_fw = true; |
| 1117 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1118 | goto drop; |
| 1119 | } |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 1120 | if (unlikely(!test_bit(wil_status_fwconnected, wil->status))) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1121 | wil_err(wil, "FW not connected\n"); |
| 1122 | goto drop; |
| 1123 | } |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 1124 | if (unlikely(wil->wdev->iftype == NL80211_IFTYPE_MONITOR)) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1125 | wil_err(wil, "Xmit in monitor mode not supported\n"); |
| 1126 | goto drop; |
| 1127 | } |
Vladimir Kondratiev | aa27dea | 2014-03-17 15:34:11 +0200 | [diff] [blame] | 1128 | pr_once_fw = false; |
Vladimir Kondratiev | d58db4e | 2013-06-09 09:12:54 +0300 | [diff] [blame] | 1129 | |
| 1130 | /* find vring */ |
Vladimir Kondratiev | 54ed90a | 2014-12-23 09:47:15 +0200 | [diff] [blame] | 1131 | if (wil->wdev->iftype == NL80211_IFTYPE_STATION) { |
| 1132 | /* in STA mode (ESS), all to same VRING */ |
| 1133 | vring = wil_find_tx_vring_sta(wil, skb); |
| 1134 | } else { /* direct communication, find matching VRING */ |
| 1135 | if (is_unicast_ether_addr(eth->h_dest)) |
| 1136 | vring = wil_find_tx_vring(wil, skb); |
| 1137 | else |
| 1138 | vring = wil_tx_bcast(wil, skb); |
| 1139 | } |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 1140 | if (unlikely(!vring)) { |
Vladimir Kondratiev | 5aed139 | 2014-06-16 19:37:15 +0300 | [diff] [blame] | 1141 | 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] | 1142 | goto drop; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1143 | } |
Vladimir Kondratiev | d58db4e | 2013-06-09 09:12:54 +0300 | [diff] [blame] | 1144 | /* set up vring entry */ |
| 1145 | rc = wil_tx_vring(wil, vring, skb); |
| 1146 | |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 1147 | /* do we still have enough room in the vring? */ |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 1148 | if (unlikely(wil_vring_avail_tx(vring) < wil_vring_wmark_low(vring))) { |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 1149 | netif_tx_stop_all_queues(wil_to_ndev(wil)); |
Vladimir Kondratiev | 55f8f68 | 2014-06-16 19:37:23 +0300 | [diff] [blame] | 1150 | wil_dbg_txrx(wil, "netif_tx_stop : ring full\n"); |
| 1151 | } |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 1152 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1153 | switch (rc) { |
| 1154 | case 0: |
Vladimir Kondratiev | 795ce73 | 2013-01-28 18:31:00 +0200 | [diff] [blame] | 1155 | /* statistics will be updated on the tx_complete */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1156 | dev_kfree_skb_any(skb); |
| 1157 | return NETDEV_TX_OK; |
| 1158 | case -ENOMEM: |
| 1159 | return NETDEV_TX_BUSY; |
| 1160 | default: |
Vladimir Kondratiev | afda8bb | 2013-01-28 18:31:07 +0200 | [diff] [blame] | 1161 | break; /* goto drop; */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1162 | } |
| 1163 | drop: |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1164 | ndev->stats.tx_dropped++; |
| 1165 | dev_kfree_skb_any(skb); |
| 1166 | |
| 1167 | return NET_XMIT_DROP; |
| 1168 | } |
| 1169 | |
Vladimir Kondratiev | 713c8a2 | 2015-01-25 10:52:49 +0200 | [diff] [blame] | 1170 | static inline bool wil_need_txstat(struct sk_buff *skb) |
| 1171 | { |
| 1172 | struct ethhdr *eth = (void *)skb->data; |
| 1173 | |
| 1174 | return is_unicast_ether_addr(eth->h_dest) && skb->sk && |
| 1175 | (skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS); |
| 1176 | } |
| 1177 | |
| 1178 | static inline void wil_consume_skb(struct sk_buff *skb, bool acked) |
| 1179 | { |
| 1180 | if (unlikely(wil_need_txstat(skb))) |
| 1181 | skb_complete_wifi_ack(skb, acked); |
| 1182 | else |
| 1183 | acked ? dev_consume_skb_any(skb) : dev_kfree_skb_any(skb); |
| 1184 | } |
| 1185 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1186 | /** |
| 1187 | * Clean up transmitted skb's from the Tx VRING |
| 1188 | * |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 1189 | * Return number of descriptors cleared |
| 1190 | * |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1191 | * Safe to call from IRQ |
| 1192 | */ |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 1193 | int wil_tx_complete(struct wil6210_priv *wil, int ringid) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1194 | { |
Vladimir Kondratiev | 795ce73 | 2013-01-28 18:31:00 +0200 | [diff] [blame] | 1195 | struct net_device *ndev = wil_to_ndev(wil); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1196 | struct device *dev = wil_to_dev(wil); |
| 1197 | struct vring *vring = &wil->vring_tx[ringid]; |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 1198 | struct vring_tx_data *txdata = &wil->vring_tx_data[ringid]; |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 1199 | int done = 0; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 1200 | int cid = wil->vring2cid_tid[ringid][0]; |
| 1201 | struct wil_net_stats *stats = &wil->sta[cid].stats; |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1202 | volatile struct vring_tx_desc *_d; |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 1203 | int used_before_complete; |
| 1204 | int used_new; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1205 | |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 1206 | if (unlikely(!vring->va)) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1207 | wil_err(wil, "Tx irq[%d]: vring not initialized\n", ringid); |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 1208 | return 0; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1209 | } |
| 1210 | |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 1211 | if (unlikely(!txdata->enabled)) { |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 1212 | wil_info(wil, "Tx irq[%d]: vring disabled\n", ringid); |
| 1213 | return 0; |
| 1214 | } |
| 1215 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 1216 | wil_dbg_txrx(wil, "%s(%d)\n", __func__, ringid); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1217 | |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 1218 | used_before_complete = wil_vring_used_tx(vring); |
| 1219 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1220 | while (!wil_vring_is_empty(vring)) { |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1221 | int new_swtail; |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 1222 | struct wil_ctx *ctx = &vring->ctx[vring->swtail]; |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1223 | /** |
| 1224 | * For the fragmented skb, HW will set DU bit only for the |
| 1225 | * last fragment. look for it |
| 1226 | */ |
| 1227 | int lf = (vring->swtail + ctx->nr_frags) % vring->size; |
| 1228 | /* TODO: check we are not past head */ |
Vladimir Kondratiev | 4de41be | 2013-04-18 14:33:52 +0300 | [diff] [blame] | 1229 | |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1230 | _d = &vring->va[lf].tx; |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 1231 | if (unlikely(!(_d->dma.status & TX_DMA_STATUS_DU))) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1232 | break; |
| 1233 | |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1234 | new_swtail = (lf + 1) % vring->size; |
| 1235 | while (vring->swtail != new_swtail) { |
| 1236 | struct vring_tx_desc dd, *d = ⅆ |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1237 | u16 dmalen; |
Vladimir Kondratiev | 76dfa4b | 2014-07-14 09:49:39 +0300 | [diff] [blame] | 1238 | struct sk_buff *skb; |
| 1239 | |
| 1240 | ctx = &vring->ctx[vring->swtail]; |
| 1241 | skb = ctx->skb; |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1242 | _d = &vring->va[vring->swtail].tx; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1243 | |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1244 | *d = *_d; |
Vladimir Kondratiev | f88f113 | 2013-07-11 18:03:40 +0300 | [diff] [blame] | 1245 | |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1246 | dmalen = le16_to_cpu(d->dma.length); |
| 1247 | trace_wil6210_tx_done(ringid, vring->swtail, dmalen, |
| 1248 | d->dma.error); |
| 1249 | wil_dbg_txrx(wil, |
Vladimir Kondratiev | 5b29c57 | 2015-02-01 10:55:14 +0200 | [diff] [blame] | 1250 | "TxC[%2d][%3d] : %d bytes, status 0x%02x err 0x%02x\n", |
| 1251 | ringid, vring->swtail, dmalen, |
| 1252 | d->dma.status, d->dma.error); |
| 1253 | wil_hex_dump_txrx("TxCD ", DUMP_PREFIX_NONE, 32, 4, |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1254 | (const void *)d, sizeof(*d), false); |
| 1255 | |
Vladimir Kondratiev | 2232abd | 2014-03-17 15:34:09 +0200 | [diff] [blame] | 1256 | wil_txdesc_unmap(dev, d, ctx); |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1257 | |
| 1258 | if (skb) { |
Vladimir Kondratiev | 33c477f | 2015-02-15 14:02:33 +0200 | [diff] [blame] | 1259 | if (likely(d->dma.error == 0)) { |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1260 | ndev->stats.tx_packets++; |
| 1261 | stats->tx_packets++; |
| 1262 | ndev->stats.tx_bytes += skb->len; |
| 1263 | stats->tx_bytes += skb->len; |
| 1264 | } else { |
| 1265 | ndev->stats.tx_errors++; |
| 1266 | stats->tx_errors++; |
| 1267 | } |
Vladimir Kondratiev | 713c8a2 | 2015-01-25 10:52:49 +0200 | [diff] [blame] | 1268 | wil_consume_skb(skb, d->dma.error == 0); |
Vladimir Kondratiev | 795ce73 | 2013-01-28 18:31:00 +0200 | [diff] [blame] | 1269 | } |
Vladimir Kondratiev | c236658 | 2014-03-17 15:34:08 +0200 | [diff] [blame] | 1270 | memset(ctx, 0, sizeof(*ctx)); |
| 1271 | /* There is no need to touch HW descriptor: |
| 1272 | * - ststus bit TX_DMA_STATUS_DU is set by design, |
| 1273 | * so hardware will not try to process this desc., |
| 1274 | * - rest of descriptor will be initialized on Tx. |
| 1275 | */ |
| 1276 | vring->swtail = wil_vring_next_tail(vring); |
| 1277 | done++; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1278 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1279 | } |
Vladimir Kondratiev | 67c3e1b | 2014-06-16 19:37:04 +0300 | [diff] [blame] | 1280 | |
Vladimir Shulman | 0436fd9 | 2015-02-15 14:02:34 +0200 | [diff] [blame] | 1281 | /* performance monitoring */ |
| 1282 | used_new = wil_vring_used_tx(vring); |
| 1283 | if (wil_val_in_range(vring_idle_trsh, |
| 1284 | used_new, used_before_complete)) { |
| 1285 | wil_dbg_txrx(wil, "Ring[%2d] idle %d -> %d\n", |
| 1286 | ringid, used_before_complete, used_new); |
Vladimir Kondratiev | 7c0acf8 | 2014-06-16 19:37:05 +0300 | [diff] [blame] | 1287 | txdata->last_idle = get_cycles(); |
| 1288 | } |
Vladimir Kondratiev | 67c3e1b | 2014-06-16 19:37:04 +0300 | [diff] [blame] | 1289 | |
Vladimir Kondratiev | 55f8f68 | 2014-06-16 19:37:23 +0300 | [diff] [blame] | 1290 | if (wil_vring_avail_tx(vring) > wil_vring_wmark_high(vring)) { |
| 1291 | wil_dbg_txrx(wil, "netif_tx_wake : ring not full\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1292 | netif_tx_wake_all_queues(wil_to_ndev(wil)); |
Vladimir Kondratiev | 55f8f68 | 2014-06-16 19:37:23 +0300 | [diff] [blame] | 1293 | } |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 1294 | |
| 1295 | return done; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1296 | } |