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> |
| 21 | |
| 22 | #include "wil6210.h" |
| 23 | #include "wmi.h" |
| 24 | #include "txrx.h" |
Vladimir Kondratiev | 9865809 | 2013-05-12 14:43:35 +0300 | [diff] [blame] | 25 | #include "trace.h" |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 26 | |
| 27 | static bool rtap_include_phy_info; |
| 28 | module_param(rtap_include_phy_info, bool, S_IRUGO); |
| 29 | MODULE_PARM_DESC(rtap_include_phy_info, |
| 30 | " Include PHY info in the radiotap header, default - no"); |
| 31 | |
| 32 | static inline int wil_vring_is_empty(struct vring *vring) |
| 33 | { |
| 34 | return vring->swhead == vring->swtail; |
| 35 | } |
| 36 | |
| 37 | static inline u32 wil_vring_next_tail(struct vring *vring) |
| 38 | { |
| 39 | return (vring->swtail + 1) % vring->size; |
| 40 | } |
| 41 | |
| 42 | static inline void wil_vring_advance_head(struct vring *vring, int n) |
| 43 | { |
| 44 | vring->swhead = (vring->swhead + n) % vring->size; |
| 45 | } |
| 46 | |
| 47 | static inline int wil_vring_is_full(struct vring *vring) |
| 48 | { |
| 49 | return wil_vring_next_tail(vring) == vring->swhead; |
| 50 | } |
| 51 | /* |
| 52 | * Available space in Tx Vring |
| 53 | */ |
| 54 | static inline int wil_vring_avail_tx(struct vring *vring) |
| 55 | { |
| 56 | u32 swhead = vring->swhead; |
| 57 | u32 swtail = vring->swtail; |
| 58 | int used = (vring->size + swhead - swtail) % vring->size; |
| 59 | |
| 60 | return vring->size - used - 1; |
| 61 | } |
| 62 | |
| 63 | static int wil_vring_alloc(struct wil6210_priv *wil, struct vring *vring) |
| 64 | { |
| 65 | struct device *dev = wil_to_dev(wil); |
| 66 | size_t sz = vring->size * sizeof(vring->va[0]); |
| 67 | uint i; |
| 68 | |
| 69 | BUILD_BUG_ON(sizeof(vring->va[0]) != 32); |
| 70 | |
| 71 | vring->swhead = 0; |
| 72 | vring->swtail = 0; |
| 73 | vring->ctx = kzalloc(vring->size * sizeof(vring->ctx[0]), GFP_KERNEL); |
| 74 | if (!vring->ctx) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 75 | vring->va = NULL; |
| 76 | return -ENOMEM; |
| 77 | } |
| 78 | /* |
| 79 | * vring->va should be aligned on its size rounded up to power of 2 |
| 80 | * This is granted by the dma_alloc_coherent |
| 81 | */ |
| 82 | vring->va = dma_alloc_coherent(dev, sz, &vring->pa, GFP_KERNEL); |
| 83 | if (!vring->va) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 84 | kfree(vring->ctx); |
| 85 | vring->ctx = NULL; |
| 86 | return -ENOMEM; |
| 87 | } |
| 88 | /* initially, all descriptors are SW owned |
| 89 | * For Tx and Rx, ownership bit is at the same location, thus |
| 90 | * we can use any |
| 91 | */ |
| 92 | for (i = 0; i < vring->size; i++) { |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 93 | volatile struct vring_tx_desc *_d = &(vring->va[i].tx); |
| 94 | _d->dma.status = TX_DMA_STATUS_DU; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 95 | } |
| 96 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 97 | 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] | 98 | vring->va, (unsigned long long)vring->pa, vring->ctx); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | static void wil_vring_free(struct wil6210_priv *wil, struct vring *vring, |
| 104 | int tx) |
| 105 | { |
| 106 | struct device *dev = wil_to_dev(wil); |
| 107 | size_t sz = vring->size * sizeof(vring->va[0]); |
| 108 | |
| 109 | while (!wil_vring_is_empty(vring)) { |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 110 | dma_addr_t pa; |
| 111 | struct sk_buff *skb; |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 112 | u16 dmalen; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 113 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 114 | if (tx) { |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 115 | struct vring_tx_desc dd, *d = ⅆ |
| 116 | volatile struct vring_tx_desc *_d = |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 117 | &vring->va[vring->swtail].tx; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 118 | |
| 119 | *d = *_d; |
| 120 | pa = wil_desc_addr(&d->dma.addr); |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 121 | dmalen = le16_to_cpu(d->dma.length); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 122 | skb = vring->ctx[vring->swtail]; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 123 | if (skb) { |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 124 | dma_unmap_single(dev, pa, dmalen, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 125 | DMA_TO_DEVICE); |
| 126 | dev_kfree_skb_any(skb); |
| 127 | vring->ctx[vring->swtail] = NULL; |
| 128 | } else { |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 129 | dma_unmap_page(dev, pa, dmalen, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 130 | DMA_TO_DEVICE); |
| 131 | } |
| 132 | vring->swtail = wil_vring_next_tail(vring); |
| 133 | } else { /* rx */ |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 134 | struct vring_rx_desc dd, *d = ⅆ |
| 135 | volatile struct vring_rx_desc *_d = |
Vladimir Kondratiev | 4d1ac07 | 2013-07-11 18:03:38 +0300 | [diff] [blame^] | 136 | &vring->va[vring->swhead].rx; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 137 | |
| 138 | *d = *_d; |
| 139 | pa = wil_desc_addr(&d->dma.addr); |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 140 | dmalen = le16_to_cpu(d->dma.length); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 141 | skb = vring->ctx[vring->swhead]; |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 142 | dma_unmap_single(dev, pa, dmalen, DMA_FROM_DEVICE); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 143 | kfree_skb(skb); |
| 144 | wil_vring_advance_head(vring, 1); |
| 145 | } |
| 146 | } |
| 147 | dma_free_coherent(dev, sz, (void *)vring->va, vring->pa); |
| 148 | kfree(vring->ctx); |
| 149 | vring->pa = 0; |
| 150 | vring->va = NULL; |
| 151 | vring->ctx = NULL; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Allocate one skb for Rx VRING |
| 156 | * |
| 157 | * Safe to call from IRQ |
| 158 | */ |
| 159 | static int wil_vring_alloc_skb(struct wil6210_priv *wil, struct vring *vring, |
| 160 | u32 i, int headroom) |
| 161 | { |
| 162 | struct device *dev = wil_to_dev(wil); |
| 163 | unsigned int sz = RX_BUF_LEN; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 164 | struct vring_rx_desc dd, *d = ⅆ |
| 165 | volatile struct vring_rx_desc *_d = &(vring->va[i].rx); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 166 | dma_addr_t pa; |
| 167 | |
| 168 | /* TODO align */ |
| 169 | struct sk_buff *skb = dev_alloc_skb(sz + headroom); |
| 170 | if (unlikely(!skb)) |
| 171 | return -ENOMEM; |
| 172 | |
| 173 | skb_reserve(skb, headroom); |
| 174 | skb_put(skb, sz); |
| 175 | |
| 176 | pa = dma_map_single(dev, skb->data, skb->len, DMA_FROM_DEVICE); |
| 177 | if (unlikely(dma_mapping_error(dev, pa))) { |
| 178 | kfree_skb(skb); |
| 179 | return -ENOMEM; |
| 180 | } |
| 181 | |
| 182 | d->dma.d0 = BIT(9) | RX_DMA_D0_CMD_DMA_IT; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 183 | wil_desc_addr_set(&d->dma.addr, pa); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 184 | /* ip_length don't care */ |
| 185 | /* b11 don't care */ |
| 186 | /* error don't care */ |
| 187 | d->dma.status = 0; /* BIT(0) should be 0 for HW_OWNED */ |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 188 | d->dma.length = cpu_to_le16(sz); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 189 | *_d = *d; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 190 | vring->ctx[i] = skb; |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Adds radiotap header |
| 197 | * |
| 198 | * Any error indicated as "Bad FCS" |
| 199 | * |
| 200 | * Vendor data for 04:ce:14-1 (Wilocity-1) consists of: |
| 201 | * - Rx descriptor: 32 bytes |
| 202 | * - Phy info |
| 203 | */ |
| 204 | static void wil_rx_add_radiotap_header(struct wil6210_priv *wil, |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 205 | struct sk_buff *skb) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 206 | { |
| 207 | struct wireless_dev *wdev = wil->wdev; |
| 208 | struct wil6210_rtap { |
| 209 | struct ieee80211_radiotap_header rthdr; |
| 210 | /* fields should be in the order of bits in rthdr.it_present */ |
| 211 | /* flags */ |
| 212 | u8 flags; |
| 213 | /* channel */ |
| 214 | __le16 chnl_freq __aligned(2); |
| 215 | __le16 chnl_flags; |
| 216 | /* MCS */ |
| 217 | u8 mcs_present; |
| 218 | u8 mcs_flags; |
| 219 | u8 mcs_index; |
| 220 | } __packed; |
| 221 | struct wil6210_rtap_vendor { |
| 222 | struct wil6210_rtap rtap; |
| 223 | /* vendor */ |
| 224 | u8 vendor_oui[3] __aligned(2); |
| 225 | u8 vendor_ns; |
| 226 | __le16 vendor_skip; |
| 227 | u8 vendor_data[0]; |
| 228 | } __packed; |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 229 | struct vring_rx_desc *d = wil_skb_rxdesc(skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 230 | struct wil6210_rtap_vendor *rtap_vendor; |
| 231 | int rtap_len = sizeof(struct wil6210_rtap); |
| 232 | int phy_length = 0; /* phy info header size, bytes */ |
| 233 | static char phy_data[128]; |
| 234 | struct ieee80211_channel *ch = wdev->preset_chandef.chan; |
| 235 | |
| 236 | if (rtap_include_phy_info) { |
| 237 | rtap_len = sizeof(*rtap_vendor) + sizeof(*d); |
| 238 | /* calculate additional length */ |
| 239 | if (d->dma.status & RX_DMA_STATUS_PHY_INFO) { |
| 240 | /** |
| 241 | * PHY info starts from 8-byte boundary |
| 242 | * there are 8-byte lines, last line may be partially |
| 243 | * written (HW bug), thus FW configures for last line |
| 244 | * to be excessive. Driver skips this last line. |
| 245 | */ |
| 246 | int len = min_t(int, 8 + sizeof(phy_data), |
| 247 | wil_rxdesc_phy_length(d)); |
| 248 | if (len > 8) { |
| 249 | void *p = skb_tail_pointer(skb); |
| 250 | void *pa = PTR_ALIGN(p, 8); |
| 251 | if (skb_tailroom(skb) >= len + (pa - p)) { |
| 252 | phy_length = len - 8; |
| 253 | memcpy(phy_data, pa, phy_length); |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | rtap_len += phy_length; |
| 258 | } |
| 259 | |
| 260 | if (skb_headroom(skb) < rtap_len && |
| 261 | pskb_expand_head(skb, rtap_len, 0, GFP_ATOMIC)) { |
| 262 | wil_err(wil, "Unable to expand headrom to %d\n", rtap_len); |
| 263 | return; |
| 264 | } |
| 265 | |
| 266 | rtap_vendor = (void *)skb_push(skb, rtap_len); |
| 267 | memset(rtap_vendor, 0, rtap_len); |
| 268 | |
| 269 | rtap_vendor->rtap.rthdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 270 | rtap_vendor->rtap.rthdr.it_len = cpu_to_le16(rtap_len); |
| 271 | rtap_vendor->rtap.rthdr.it_present = cpu_to_le32( |
| 272 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
| 273 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 274 | (1 << IEEE80211_RADIOTAP_MCS)); |
| 275 | if (d->dma.status & RX_DMA_STATUS_ERROR) |
| 276 | rtap_vendor->rtap.flags |= IEEE80211_RADIOTAP_F_BADFCS; |
| 277 | |
| 278 | rtap_vendor->rtap.chnl_freq = cpu_to_le16(ch ? ch->center_freq : 58320); |
| 279 | rtap_vendor->rtap.chnl_flags = cpu_to_le16(0); |
| 280 | |
| 281 | rtap_vendor->rtap.mcs_present = IEEE80211_RADIOTAP_MCS_HAVE_MCS; |
| 282 | rtap_vendor->rtap.mcs_flags = 0; |
| 283 | rtap_vendor->rtap.mcs_index = wil_rxdesc_mcs(d); |
| 284 | |
| 285 | if (rtap_include_phy_info) { |
| 286 | rtap_vendor->rtap.rthdr.it_present |= cpu_to_le32(1 << |
| 287 | IEEE80211_RADIOTAP_VENDOR_NAMESPACE); |
| 288 | /* OUI for Wilocity 04:ce:14 */ |
| 289 | rtap_vendor->vendor_oui[0] = 0x04; |
| 290 | rtap_vendor->vendor_oui[1] = 0xce; |
| 291 | rtap_vendor->vendor_oui[2] = 0x14; |
| 292 | rtap_vendor->vendor_ns = 1; |
| 293 | /* Rx descriptor + PHY data */ |
| 294 | rtap_vendor->vendor_skip = cpu_to_le16(sizeof(*d) + |
| 295 | phy_length); |
| 296 | memcpy(rtap_vendor->vendor_data, (void *)d, sizeof(*d)); |
| 297 | memcpy(rtap_vendor->vendor_data + sizeof(*d), phy_data, |
| 298 | phy_length); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | /* |
| 303 | * Fast swap in place between 2 registers |
| 304 | */ |
| 305 | static void wil_swap_u16(u16 *a, u16 *b) |
| 306 | { |
| 307 | *a ^= *b; |
| 308 | *b ^= *a; |
| 309 | *a ^= *b; |
| 310 | } |
| 311 | |
| 312 | static void wil_swap_ethaddr(void *data) |
| 313 | { |
| 314 | struct ethhdr *eth = data; |
| 315 | u16 *s = (u16 *)eth->h_source; |
| 316 | u16 *d = (u16 *)eth->h_dest; |
| 317 | |
| 318 | wil_swap_u16(s++, d++); |
| 319 | wil_swap_u16(s++, d++); |
| 320 | wil_swap_u16(s, d); |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * reap 1 frame from @swhead |
| 325 | * |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 326 | * Rx descriptor copied to skb->cb |
| 327 | * |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 328 | * Safe to call from IRQ |
| 329 | */ |
| 330 | static struct sk_buff *wil_vring_reap_rx(struct wil6210_priv *wil, |
| 331 | struct vring *vring) |
| 332 | { |
| 333 | struct device *dev = wil_to_dev(wil); |
| 334 | struct net_device *ndev = wil_to_ndev(wil); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 335 | volatile struct vring_rx_desc *_d; |
| 336 | struct vring_rx_desc *d; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 337 | struct sk_buff *skb; |
| 338 | dma_addr_t pa; |
| 339 | unsigned int sz = RX_BUF_LEN; |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 340 | u16 dmalen; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 341 | u8 ftype; |
| 342 | u8 ds_bits; |
| 343 | |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 344 | BUILD_BUG_ON(sizeof(struct vring_rx_desc) > sizeof(skb->cb)); |
| 345 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 346 | if (wil_vring_is_empty(vring)) |
| 347 | return NULL; |
| 348 | |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 349 | _d = &(vring->va[vring->swhead].rx); |
| 350 | if (!(_d->dma.status & RX_DMA_STATUS_DU)) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 351 | /* it is not error, we just reached end of Rx done area */ |
| 352 | return NULL; |
| 353 | } |
| 354 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 355 | skb = vring->ctx[vring->swhead]; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 356 | d = wil_skb_rxdesc(skb); |
| 357 | *d = *_d; |
| 358 | pa = wil_desc_addr(&d->dma.addr); |
| 359 | vring->ctx[vring->swhead] = NULL; |
Vladimir Kondratiev | e270045 | 2013-05-12 14:43:33 +0300 | [diff] [blame] | 360 | wil_vring_advance_head(vring, 1); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 361 | |
| 362 | dma_unmap_single(dev, pa, sz, DMA_FROM_DEVICE); |
| 363 | dmalen = le16_to_cpu(d->dma.length); |
| 364 | |
| 365 | trace_wil6210_rx(vring->swhead, d); |
| 366 | wil_dbg_txrx(wil, "Rx[%3d] : %d bytes\n", vring->swhead, dmalen); |
| 367 | wil_hex_dump_txrx("Rx ", DUMP_PREFIX_NONE, 32, 4, |
| 368 | (const void *)d, sizeof(*d), false); |
| 369 | |
Vladimir Kondratiev | e270045 | 2013-05-12 14:43:33 +0300 | [diff] [blame] | 370 | if (dmalen > sz) { |
| 371 | wil_err(wil, "Rx size too large: %d bytes!\n", dmalen); |
Wei Yongjun | 110dea0 | 2013-05-23 17:10:43 +0800 | [diff] [blame] | 372 | kfree_skb(skb); |
Vladimir Kondratiev | e270045 | 2013-05-12 14:43:33 +0300 | [diff] [blame] | 373 | return NULL; |
| 374 | } |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 375 | skb_trim(skb, dmalen); |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 376 | |
Vladimir Kondratiev | c0d3771 | 2013-05-12 14:43:34 +0300 | [diff] [blame] | 377 | wil_hex_dump_txrx("Rx ", DUMP_PREFIX_OFFSET, 16, 1, |
| 378 | skb->data, skb_headlen(skb), false); |
| 379 | |
| 380 | |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 381 | wil->stats.last_mcs_rx = wil_rxdesc_mcs(d); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 382 | |
| 383 | /* use radiotap header only if required */ |
| 384 | if (ndev->type == ARPHRD_IEEE80211_RADIOTAP) |
Vladimir Kondratiev | 33e6116 | 2013-04-18 14:33:50 +0300 | [diff] [blame] | 385 | wil_rx_add_radiotap_header(wil, skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 386 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 387 | /* no extra checks if in sniffer mode */ |
| 388 | if (ndev->type != ARPHRD_ETHER) |
| 389 | return skb; |
| 390 | /* |
| 391 | * Non-data frames may be delivered through Rx DMA channel (ex: BAR) |
| 392 | * Driver should recognize it by frame type, that is found |
| 393 | * in Rx descriptor. If type is not data, it is 802.11 frame as is |
| 394 | */ |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 395 | ftype = wil_rxdesc_ftype(d) << 2; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 396 | if (ftype != IEEE80211_FTYPE_DATA) { |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 397 | wil_dbg_txrx(wil, "Non-data frame ftype 0x%08x\n", ftype); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 398 | /* TODO: process it */ |
| 399 | kfree_skb(skb); |
| 400 | return NULL; |
| 401 | } |
| 402 | |
| 403 | if (skb->len < ETH_HLEN) { |
| 404 | wil_err(wil, "Short frame, len = %d\n", skb->len); |
| 405 | /* TODO: process it (i.e. BAR) */ |
| 406 | kfree_skb(skb); |
| 407 | return NULL; |
| 408 | } |
| 409 | |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 410 | ds_bits = wil_rxdesc_ds_bits(d); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 411 | if (ds_bits == 1) { |
| 412 | /* |
| 413 | * HW bug - in ToDS mode, i.e. Rx on AP side, |
| 414 | * addresses get swapped |
| 415 | */ |
| 416 | wil_swap_ethaddr(skb->data); |
| 417 | } |
| 418 | |
| 419 | return skb; |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * allocate and fill up to @count buffers in rx ring |
| 424 | * buffers posted at @swtail |
| 425 | */ |
| 426 | static int wil_rx_refill(struct wil6210_priv *wil, int count) |
| 427 | { |
| 428 | struct net_device *ndev = wil_to_ndev(wil); |
| 429 | struct vring *v = &wil->vring_rx; |
| 430 | u32 next_tail; |
| 431 | int rc = 0; |
| 432 | int headroom = ndev->type == ARPHRD_IEEE80211_RADIOTAP ? |
| 433 | WIL6210_RTAP_SIZE : 0; |
| 434 | |
| 435 | for (; next_tail = wil_vring_next_tail(v), |
| 436 | (next_tail != v->swhead) && (count-- > 0); |
| 437 | v->swtail = next_tail) { |
| 438 | rc = wil_vring_alloc_skb(wil, v, v->swtail, headroom); |
| 439 | if (rc) { |
| 440 | wil_err(wil, "Error %d in wil_rx_refill[%d]\n", |
| 441 | rc, v->swtail); |
| 442 | break; |
| 443 | } |
| 444 | } |
| 445 | iowrite32(v->swtail, wil->csr + HOSTADDR(v->hwtail)); |
| 446 | |
| 447 | return rc; |
| 448 | } |
| 449 | |
| 450 | /* |
| 451 | * Pass Rx packet to the netif. Update statistics. |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 452 | * Called in softirq context (NAPI poll). |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 453 | */ |
| 454 | static void wil_netif_rx_any(struct sk_buff *skb, struct net_device *ndev) |
| 455 | { |
| 456 | int rc; |
| 457 | unsigned int len = skb->len; |
| 458 | |
Vladimir Kondratiev | 241804c | 2013-01-28 18:31:02 +0200 | [diff] [blame] | 459 | skb_orphan(skb); |
| 460 | |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 461 | rc = netif_receive_skb(skb); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 462 | |
| 463 | if (likely(rc == NET_RX_SUCCESS)) { |
| 464 | ndev->stats.rx_packets++; |
| 465 | ndev->stats.rx_bytes += len; |
| 466 | |
| 467 | } else { |
| 468 | ndev->stats.rx_dropped++; |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * Proceed all completed skb's from Rx VRING |
| 474 | * |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 475 | * Safe to call from NAPI poll, i.e. softirq with interrupts enabled |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 476 | */ |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 477 | void wil_rx_handle(struct wil6210_priv *wil, int *quota) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 478 | { |
| 479 | struct net_device *ndev = wil_to_ndev(wil); |
| 480 | struct vring *v = &wil->vring_rx; |
| 481 | struct sk_buff *skb; |
| 482 | |
| 483 | if (!v->va) { |
| 484 | wil_err(wil, "Rx IRQ while Rx not yet initialized\n"); |
| 485 | return; |
| 486 | } |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 487 | wil_dbg_txrx(wil, "%s()\n", __func__); |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 488 | while ((*quota > 0) && (NULL != (skb = wil_vring_reap_rx(wil, v)))) { |
| 489 | (*quota)--; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 490 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 491 | if (wil->wdev->iftype == NL80211_IFTYPE_MONITOR) { |
| 492 | skb->dev = ndev; |
| 493 | skb_reset_mac_header(skb); |
| 494 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 495 | skb->pkt_type = PACKET_OTHERHOST; |
| 496 | skb->protocol = htons(ETH_P_802_2); |
| 497 | |
| 498 | } else { |
| 499 | skb->protocol = eth_type_trans(skb, ndev); |
| 500 | } |
| 501 | |
| 502 | wil_netif_rx_any(skb, ndev); |
| 503 | } |
| 504 | wil_rx_refill(wil, v->size); |
| 505 | } |
| 506 | |
| 507 | int wil_rx_init(struct wil6210_priv *wil) |
| 508 | { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 509 | struct vring *vring = &wil->vring_rx; |
| 510 | int rc; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 511 | |
| 512 | vring->size = WIL6210_RX_RING_SIZE; |
| 513 | rc = wil_vring_alloc(wil, vring); |
| 514 | if (rc) |
| 515 | return rc; |
| 516 | |
Vladimir Kondratiev | 47e19af | 2013-01-28 18:30:59 +0200 | [diff] [blame] | 517 | rc = wmi_rx_chain_add(wil, vring); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 518 | if (rc) |
| 519 | goto err_free; |
| 520 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 521 | rc = wil_rx_refill(wil, vring->size); |
| 522 | if (rc) |
| 523 | goto err_free; |
| 524 | |
| 525 | return 0; |
| 526 | err_free: |
| 527 | wil_vring_free(wil, vring, 0); |
| 528 | |
| 529 | return rc; |
| 530 | } |
| 531 | |
| 532 | void wil_rx_fini(struct wil6210_priv *wil) |
| 533 | { |
| 534 | struct vring *vring = &wil->vring_rx; |
| 535 | |
Vladimir Kondratiev | 2acb422 | 2013-01-28 18:31:08 +0200 | [diff] [blame] | 536 | if (vring->va) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 537 | wil_vring_free(wil, vring, 0); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | int wil_vring_init_tx(struct wil6210_priv *wil, int id, int size, |
| 541 | int cid, int tid) |
| 542 | { |
| 543 | int rc; |
| 544 | struct wmi_vring_cfg_cmd cmd = { |
| 545 | .action = cpu_to_le32(WMI_VRING_CMD_ADD), |
| 546 | .vring_cfg = { |
| 547 | .tx_sw_ring = { |
| 548 | .max_mpdu_size = cpu_to_le16(TX_BUF_LEN), |
Vladimir Kondratiev | b5d98e9 | 2013-04-18 14:33:51 +0300 | [diff] [blame] | 549 | .ring_size = cpu_to_le16(size), |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 550 | }, |
| 551 | .ringid = id, |
| 552 | .cidxtid = (cid & 0xf) | ((tid & 0xf) << 4), |
| 553 | .encap_trans_type = WMI_VRING_ENC_TYPE_802_3, |
| 554 | .mac_ctrl = 0, |
| 555 | .to_resolution = 0, |
| 556 | .agg_max_wsize = 16, |
| 557 | .schd_params = { |
| 558 | .priority = cpu_to_le16(0), |
| 559 | .timeslot_us = cpu_to_le16(0xfff), |
| 560 | }, |
| 561 | }, |
| 562 | }; |
| 563 | struct { |
| 564 | struct wil6210_mbox_hdr_wmi wmi; |
| 565 | struct wmi_vring_cfg_done_event cmd; |
| 566 | } __packed reply; |
| 567 | struct vring *vring = &wil->vring_tx[id]; |
| 568 | |
| 569 | if (vring->va) { |
| 570 | wil_err(wil, "Tx ring [%d] already allocated\n", id); |
| 571 | rc = -EINVAL; |
| 572 | goto out; |
| 573 | } |
| 574 | |
| 575 | vring->size = size; |
| 576 | rc = wil_vring_alloc(wil, vring); |
| 577 | if (rc) |
| 578 | goto out; |
| 579 | |
| 580 | 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] | 581 | |
| 582 | rc = wmi_call(wil, WMI_VRING_CFG_CMDID, &cmd, sizeof(cmd), |
| 583 | WMI_VRING_CFG_DONE_EVENTID, &reply, sizeof(reply), 100); |
| 584 | if (rc) |
| 585 | goto out_free; |
| 586 | |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 587 | if (reply.cmd.status != WMI_FW_STATUS_SUCCESS) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 588 | wil_err(wil, "Tx config failed, status 0x%02x\n", |
| 589 | reply.cmd.status); |
Vladimir Kondratiev | c331997 | 2013-01-28 18:31:09 +0200 | [diff] [blame] | 590 | rc = -EINVAL; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 591 | goto out_free; |
| 592 | } |
| 593 | vring->hwtail = le32_to_cpu(reply.cmd.tx_vring_tail_ptr); |
| 594 | |
| 595 | return 0; |
| 596 | out_free: |
| 597 | wil_vring_free(wil, vring, 1); |
| 598 | out: |
| 599 | |
| 600 | return rc; |
| 601 | } |
| 602 | |
| 603 | void wil_vring_fini_tx(struct wil6210_priv *wil, int id) |
| 604 | { |
| 605 | struct vring *vring = &wil->vring_tx[id]; |
| 606 | |
| 607 | if (!vring->va) |
| 608 | return; |
| 609 | |
| 610 | wil_vring_free(wil, vring, 1); |
| 611 | } |
| 612 | |
| 613 | static struct vring *wil_find_tx_vring(struct wil6210_priv *wil, |
| 614 | struct sk_buff *skb) |
| 615 | { |
| 616 | struct vring *v = &wil->vring_tx[0]; |
| 617 | |
| 618 | if (v->va) |
| 619 | return v; |
| 620 | |
| 621 | return NULL; |
| 622 | } |
| 623 | |
Kirshenbaum Erez | 99b55bd | 2013-06-23 12:59:34 +0300 | [diff] [blame] | 624 | static int wil_tx_desc_map(struct vring_tx_desc *d, dma_addr_t pa, u32 len, |
| 625 | int vring_index) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 626 | { |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 627 | wil_desc_addr_set(&d->dma.addr, pa); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 628 | d->dma.ip_length = 0; |
| 629 | /* 0..6: mac_length; 7:ip_version 0-IP6 1-IP4*/ |
| 630 | d->dma.b11 = 0/*14 | BIT(7)*/; |
| 631 | d->dma.error = 0; |
| 632 | d->dma.status = 0; /* BIT(0) should be 0 for HW_OWNED */ |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 633 | d->dma.length = cpu_to_le16((u16)len); |
Kirshenbaum Erez | 99b55bd | 2013-06-23 12:59:34 +0300 | [diff] [blame] | 634 | d->dma.d0 = (vring_index << DMA_CFG_DESC_TX_0_QID_POS); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 635 | d->mac.d[0] = 0; |
| 636 | d->mac.d[1] = 0; |
| 637 | d->mac.d[2] = 0; |
| 638 | d->mac.ucode_cmd = 0; |
| 639 | /* use dst index 0 */ |
| 640 | d->mac.d[1] |= BIT(MAC_CFG_DESC_TX_1_DST_INDEX_EN_POS) | |
| 641 | (0 << MAC_CFG_DESC_TX_1_DST_INDEX_POS); |
| 642 | /* translation type: 0 - bypass; 1 - 802.3; 2 - native wifi */ |
| 643 | d->mac.d[2] = BIT(MAC_CFG_DESC_TX_2_SNAP_HDR_INSERTION_EN_POS) | |
| 644 | (1 << MAC_CFG_DESC_TX_2_L2_TRANSLATION_TYPE_POS); |
| 645 | |
| 646 | return 0; |
| 647 | } |
| 648 | |
| 649 | static int wil_tx_vring(struct wil6210_priv *wil, struct vring *vring, |
| 650 | struct sk_buff *skb) |
| 651 | { |
| 652 | struct device *dev = wil_to_dev(wil); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 653 | struct vring_tx_desc dd, *d = ⅆ |
| 654 | volatile struct vring_tx_desc *_d; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 655 | u32 swhead = vring->swhead; |
| 656 | int avail = wil_vring_avail_tx(vring); |
| 657 | int nr_frags = skb_shinfo(skb)->nr_frags; |
| 658 | uint f; |
| 659 | int vring_index = vring - wil->vring_tx; |
| 660 | uint i = swhead; |
| 661 | dma_addr_t pa; |
| 662 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 663 | wil_dbg_txrx(wil, "%s()\n", __func__); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 664 | |
| 665 | if (avail < vring->size/8) |
| 666 | netif_tx_stop_all_queues(wil_to_ndev(wil)); |
| 667 | if (avail < 1 + nr_frags) { |
| 668 | wil_err(wil, "Tx ring full. No space for %d fragments\n", |
| 669 | 1 + nr_frags); |
| 670 | return -ENOMEM; |
| 671 | } |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 672 | _d = &(vring->va[i].tx); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 673 | |
| 674 | /* FIXME FW can accept only unicast frames for the peer */ |
| 675 | memcpy(skb->data, wil->dst_addr[vring_index], ETH_ALEN); |
| 676 | |
| 677 | pa = dma_map_single(dev, skb->data, |
| 678 | skb_headlen(skb), DMA_TO_DEVICE); |
| 679 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 680 | 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] | 681 | skb->data, (unsigned long long)pa); |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 682 | wil_hex_dump_txrx("Tx ", DUMP_PREFIX_OFFSET, 16, 1, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 683 | skb->data, skb_headlen(skb), false); |
| 684 | |
| 685 | if (unlikely(dma_mapping_error(dev, pa))) |
| 686 | return -EINVAL; |
| 687 | /* 1-st segment */ |
Kirshenbaum Erez | 99b55bd | 2013-06-23 12:59:34 +0300 | [diff] [blame] | 688 | wil_tx_desc_map(d, pa, skb_headlen(skb), vring_index); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 689 | d->mac.d[2] |= ((nr_frags + 1) << |
| 690 | MAC_CFG_DESC_TX_2_NUM_OF_DESCRIPTORS_POS); |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 691 | if (nr_frags) |
| 692 | *_d = *d; |
| 693 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 694 | /* middle segments */ |
| 695 | for (f = 0; f < nr_frags; f++) { |
| 696 | const struct skb_frag_struct *frag = |
| 697 | &skb_shinfo(skb)->frags[f]; |
| 698 | int len = skb_frag_size(frag); |
| 699 | i = (swhead + f + 1) % vring->size; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 700 | _d = &(vring->va[i].tx); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 701 | pa = skb_frag_dma_map(dev, frag, 0, skb_frag_size(frag), |
| 702 | DMA_TO_DEVICE); |
| 703 | if (unlikely(dma_mapping_error(dev, pa))) |
| 704 | goto dma_error; |
Kirshenbaum Erez | 99b55bd | 2013-06-23 12:59:34 +0300 | [diff] [blame] | 705 | wil_tx_desc_map(d, pa, len, vring_index); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 706 | vring->ctx[i] = NULL; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 707 | *_d = *d; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 708 | } |
| 709 | /* for the last seg only */ |
| 710 | d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_CMD_EOP_POS); |
Kirshenbaum Erez | 668b2bb | 2013-06-23 12:59:35 +0300 | [diff] [blame] | 711 | 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] | 712 | 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] | 713 | *_d = *d; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 714 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 715 | wil_hex_dump_txrx("Tx ", DUMP_PREFIX_NONE, 32, 4, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 716 | (const void *)d, sizeof(*d), false); |
| 717 | |
| 718 | /* advance swhead */ |
| 719 | wil_vring_advance_head(vring, nr_frags + 1); |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 720 | wil_dbg_txrx(wil, "Tx swhead %d -> %d\n", swhead, vring->swhead); |
Vladimir Kondratiev | 9865809 | 2013-05-12 14:43:35 +0300 | [diff] [blame] | 721 | trace_wil6210_tx(vring_index, swhead, skb->len, nr_frags); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 722 | iowrite32(vring->swhead, wil->csr + HOSTADDR(vring->hwtail)); |
| 723 | /* hold reference to skb |
| 724 | * to prevent skb release before accounting |
| 725 | * in case of immediate "tx done" |
| 726 | */ |
| 727 | vring->ctx[i] = skb_get(skb); |
| 728 | |
| 729 | return 0; |
| 730 | dma_error: |
| 731 | /* unmap what we have mapped */ |
| 732 | /* Note: increment @f to operate with positive index */ |
| 733 | for (f++; f > 0; f--) { |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 734 | u16 dmalen; |
| 735 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 736 | i = (swhead + f) % vring->size; |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 737 | _d = &(vring->va[i].tx); |
| 738 | *d = *_d; |
| 739 | _d->dma.status = TX_DMA_STATUS_DU; |
| 740 | pa = wil_desc_addr(&d->dma.addr); |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 741 | dmalen = le16_to_cpu(d->dma.length); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 742 | if (vring->ctx[i]) |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 743 | dma_unmap_single(dev, pa, dmalen, DMA_TO_DEVICE); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 744 | else |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 745 | dma_unmap_page(dev, pa, dmalen, DMA_TO_DEVICE); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | return -EINVAL; |
| 749 | } |
| 750 | |
| 751 | |
| 752 | netdev_tx_t wil_start_xmit(struct sk_buff *skb, struct net_device *ndev) |
| 753 | { |
| 754 | struct wil6210_priv *wil = ndev_to_wil(ndev); |
| 755 | struct vring *vring; |
| 756 | int rc; |
| 757 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 758 | wil_dbg_txrx(wil, "%s()\n", __func__); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 759 | if (!test_bit(wil_status_fwready, &wil->status)) { |
| 760 | wil_err(wil, "FW not ready\n"); |
| 761 | goto drop; |
| 762 | } |
| 763 | if (!test_bit(wil_status_fwconnected, &wil->status)) { |
| 764 | wil_err(wil, "FW not connected\n"); |
| 765 | goto drop; |
| 766 | } |
| 767 | if (wil->wdev->iftype == NL80211_IFTYPE_MONITOR) { |
| 768 | wil_err(wil, "Xmit in monitor mode not supported\n"); |
| 769 | goto drop; |
| 770 | } |
Vladimir Kondratiev | d58db4e | 2013-06-09 09:12:54 +0300 | [diff] [blame] | 771 | |
| 772 | /* find vring */ |
| 773 | vring = wil_find_tx_vring(wil, skb); |
| 774 | if (!vring) { |
| 775 | wil_err(wil, "No Tx VRING available\n"); |
| 776 | goto drop; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 777 | } |
Vladimir Kondratiev | d58db4e | 2013-06-09 09:12:54 +0300 | [diff] [blame] | 778 | /* set up vring entry */ |
| 779 | rc = wil_tx_vring(wil, vring, skb); |
| 780 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 781 | switch (rc) { |
| 782 | case 0: |
Vladimir Kondratiev | 795ce73 | 2013-01-28 18:31:00 +0200 | [diff] [blame] | 783 | /* statistics will be updated on the tx_complete */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 784 | dev_kfree_skb_any(skb); |
| 785 | return NETDEV_TX_OK; |
| 786 | case -ENOMEM: |
| 787 | return NETDEV_TX_BUSY; |
| 788 | default: |
Vladimir Kondratiev | afda8bb | 2013-01-28 18:31:07 +0200 | [diff] [blame] | 789 | break; /* goto drop; */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 790 | } |
| 791 | drop: |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 792 | ndev->stats.tx_dropped++; |
| 793 | dev_kfree_skb_any(skb); |
| 794 | |
| 795 | return NET_XMIT_DROP; |
| 796 | } |
| 797 | |
| 798 | /** |
| 799 | * Clean up transmitted skb's from the Tx VRING |
| 800 | * |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 801 | * Return number of descriptors cleared |
| 802 | * |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 803 | * Safe to call from IRQ |
| 804 | */ |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 805 | int wil_tx_complete(struct wil6210_priv *wil, int ringid) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 806 | { |
Vladimir Kondratiev | 795ce73 | 2013-01-28 18:31:00 +0200 | [diff] [blame] | 807 | struct net_device *ndev = wil_to_ndev(wil); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 808 | struct device *dev = wil_to_dev(wil); |
| 809 | struct vring *vring = &wil->vring_tx[ringid]; |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 810 | int done = 0; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 811 | |
| 812 | if (!vring->va) { |
| 813 | wil_err(wil, "Tx irq[%d]: vring not initialized\n", ringid); |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 814 | return 0; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 815 | } |
| 816 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 817 | wil_dbg_txrx(wil, "%s(%d)\n", __func__, ringid); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 818 | |
| 819 | while (!wil_vring_is_empty(vring)) { |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 820 | volatile struct vring_tx_desc *_d = |
Vladimir Kondratiev | 4de41be | 2013-04-18 14:33:52 +0300 | [diff] [blame] | 821 | &vring->va[vring->swtail].tx; |
| 822 | struct vring_tx_desc dd, *d = ⅆ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 823 | dma_addr_t pa; |
| 824 | struct sk_buff *skb; |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 825 | u16 dmalen; |
Vladimir Kondratiev | 4de41be | 2013-04-18 14:33:52 +0300 | [diff] [blame] | 826 | |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 827 | *d = *_d; |
Vladimir Kondratiev | 4de41be | 2013-04-18 14:33:52 +0300 | [diff] [blame] | 828 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 829 | if (!(d->dma.status & TX_DMA_STATUS_DU)) |
| 830 | break; |
| 831 | |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 832 | dmalen = le16_to_cpu(d->dma.length); |
Vladimir Kondratiev | 9865809 | 2013-05-12 14:43:35 +0300 | [diff] [blame] | 833 | trace_wil6210_tx_done(ringid, vring->swtail, dmalen, |
| 834 | d->dma.error); |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 835 | wil_dbg_txrx(wil, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 836 | "Tx[%3d] : %d bytes, status 0x%02x err 0x%02x\n", |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 837 | vring->swtail, dmalen, d->dma.status, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 838 | d->dma.error); |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 839 | wil_hex_dump_txrx("TxC ", DUMP_PREFIX_NONE, 32, 4, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 840 | (const void *)d, sizeof(*d), false); |
| 841 | |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 842 | pa = wil_desc_addr(&d->dma.addr); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 843 | skb = vring->ctx[vring->swtail]; |
| 844 | if (skb) { |
Vladimir Kondratiev | 795ce73 | 2013-01-28 18:31:00 +0200 | [diff] [blame] | 845 | if (d->dma.error == 0) { |
| 846 | ndev->stats.tx_packets++; |
| 847 | ndev->stats.tx_bytes += skb->len; |
| 848 | } else { |
| 849 | ndev->stats.tx_errors++; |
| 850 | } |
| 851 | |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 852 | dma_unmap_single(dev, pa, dmalen, DMA_TO_DEVICE); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 853 | dev_kfree_skb_any(skb); |
| 854 | vring->ctx[vring->swtail] = NULL; |
| 855 | } else { |
Vladimir Kondratiev | 7e594444 | 2013-05-12 14:43:32 +0300 | [diff] [blame] | 856 | dma_unmap_page(dev, pa, dmalen, DMA_TO_DEVICE); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 857 | } |
Vladimir Kondratiev | 68ada71 | 2013-05-12 14:43:37 +0300 | [diff] [blame] | 858 | d->dma.addr.addr_low = 0; |
| 859 | d->dma.addr.addr_high = 0; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 860 | d->dma.length = 0; |
| 861 | d->dma.status = TX_DMA_STATUS_DU; |
| 862 | vring->swtail = wil_vring_next_tail(vring); |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 863 | done++; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 864 | } |
| 865 | if (wil_vring_avail_tx(vring) > vring->size/4) |
| 866 | netif_tx_wake_all_queues(wil_to_ndev(wil)); |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 867 | |
| 868 | return done; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 869 | } |