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