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