blob: 0499ebcdeff514ea24724b7dba7664f3e726726e [file] [log] [blame]
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001/*
Vladimir Kondratiev02525a72014-08-06 10:31:51 +03002 * Copyright (c) 2012-2014 Qualcomm Atheros, Inc.
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08003 *
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 Kondratiev2be7d222012-12-20 13:13:19 -080017#include <linux/etherdevice.h>
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080018#include <net/ieee80211_radiotap.h>
19#include <linux/if_arp.h>
20#include <linux/moduleparam.h>
Kirshenbaum Erez504937d2013-07-21 11:34:37 +030021#include <linux/ip.h>
22#include <linux/ipv6.h>
23#include <net/ipv6.h>
Vladimir Kondratiev0786dc42014-01-14 20:31:26 +020024#include <linux/prefetch.h>
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080025
26#include "wil6210.h"
27#include "wmi.h"
28#include "txrx.h"
Vladimir Kondratiev98658092013-05-12 14:43:35 +030029#include "trace.h"
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080030
31static bool rtap_include_phy_info;
32module_param(rtap_include_phy_info, bool, S_IRUGO);
33MODULE_PARM_DESC(rtap_include_phy_info,
34 " Include PHY info in the radiotap header, default - no");
35
36static inline int wil_vring_is_empty(struct vring *vring)
37{
38 return vring->swhead == vring->swtail;
39}
40
41static inline u32 wil_vring_next_tail(struct vring *vring)
42{
43 return (vring->swtail + 1) % vring->size;
44}
45
46static inline void wil_vring_advance_head(struct vring *vring, int n)
47{
48 vring->swhead = (vring->swhead + n) % vring->size;
49}
50
51static inline int wil_vring_is_full(struct vring *vring)
52{
53 return wil_vring_next_tail(vring) == vring->swhead;
54}
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +030055
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080056/*
57 * Available space in Tx Vring
58 */
59static inline int wil_vring_avail_tx(struct vring *vring)
60{
61 u32 swhead = vring->swhead;
62 u32 swtail = vring->swtail;
63 int used = (vring->size + swhead - swtail) % vring->size;
64
65 return vring->size - used - 1;
66}
67
Vladimir Kondratiev5bb64232014-05-27 14:45:46 +030068/**
69 * wil_vring_wmark_low - low watermark for available descriptor space
70 */
71static inline int wil_vring_wmark_low(struct vring *vring)
72{
73 return vring->size/8;
74}
75
76/**
77 * wil_vring_wmark_high - high watermark for available descriptor space
78 */
79static inline int wil_vring_wmark_high(struct vring *vring)
80{
81 return vring->size/4;
82}
83
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080084static int wil_vring_alloc(struct wil6210_priv *wil, struct vring *vring)
85{
86 struct device *dev = wil_to_dev(wil);
87 size_t sz = vring->size * sizeof(vring->va[0]);
88 uint i;
89
Vladimir Kondratiev9cf10d62014-09-10 16:34:36 +030090 wil_dbg_misc(wil, "%s()\n", __func__);
91
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080092 BUILD_BUG_ON(sizeof(vring->va[0]) != 32);
93
94 vring->swhead = 0;
95 vring->swtail = 0;
Vladimir Kondratievf88f1132013-07-11 18:03:40 +030096 vring->ctx = kcalloc(vring->size, sizeof(vring->ctx[0]), GFP_KERNEL);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080097 if (!vring->ctx) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080098 vring->va = NULL;
99 return -ENOMEM;
100 }
101 /*
102 * vring->va should be aligned on its size rounded up to power of 2
103 * This is granted by the dma_alloc_coherent
104 */
105 vring->va = dma_alloc_coherent(dev, sz, &vring->pa, GFP_KERNEL);
106 if (!vring->va) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800107 kfree(vring->ctx);
108 vring->ctx = NULL;
109 return -ENOMEM;
110 }
111 /* initially, all descriptors are SW owned
112 * For Tx and Rx, ownership bit is at the same location, thus
113 * we can use any
114 */
115 for (i = 0; i < vring->size; i++) {
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300116 volatile struct vring_tx_desc *_d = &vring->va[i].tx;
117
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300118 _d->dma.status = TX_DMA_STATUS_DU;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800119 }
120
Vladimir Kondratiev39c52ee2014-05-27 14:45:49 +0300121 wil_dbg_misc(wil, "vring[%d] 0x%p:%pad 0x%p\n", vring->size,
122 vring->va, &vring->pa, vring->ctx);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800123
124 return 0;
125}
126
Vladimir Kondratiev2232abd2014-03-17 15:34:09 +0200127static void wil_txdesc_unmap(struct device *dev, struct vring_tx_desc *d,
128 struct wil_ctx *ctx)
129{
130 dma_addr_t pa = wil_desc_addr(&d->dma.addr);
131 u16 dmalen = le16_to_cpu(d->dma.length);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300132
Vladimir Kondratiev2232abd2014-03-17 15:34:09 +0200133 switch (ctx->mapped_as) {
134 case wil_mapped_as_single:
135 dma_unmap_single(dev, pa, dmalen, DMA_TO_DEVICE);
136 break;
137 case wil_mapped_as_page:
138 dma_unmap_page(dev, pa, dmalen, DMA_TO_DEVICE);
139 break;
140 default:
141 break;
142 }
143}
144
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800145static void wil_vring_free(struct wil6210_priv *wil, struct vring *vring,
146 int tx)
147{
148 struct device *dev = wil_to_dev(wil);
149 size_t sz = vring->size * sizeof(vring->va[0]);
150
Vladimir Kondratievef772852014-09-10 16:34:31 +0300151 if (tx) {
152 int vring_index = vring - wil->vring_tx;
153
154 wil_dbg_misc(wil, "free Tx vring %d [%d] 0x%p:%pad 0x%p\n",
155 vring_index, vring->size, vring->va,
156 &vring->pa, vring->ctx);
157 } else {
158 wil_dbg_misc(wil, "free Rx vring [%d] 0x%p:%pad 0x%p\n",
159 vring->size, vring->va,
160 &vring->pa, vring->ctx);
161 }
162
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800163 while (!wil_vring_is_empty(vring)) {
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300164 dma_addr_t pa;
Vladimir Kondratiev7e5944442013-05-12 14:43:32 +0300165 u16 dmalen;
Vladimir Kondratievf88f1132013-07-11 18:03:40 +0300166 struct wil_ctx *ctx;
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300167
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800168 if (tx) {
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300169 struct vring_tx_desc dd, *d = &dd;
170 volatile struct vring_tx_desc *_d =
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800171 &vring->va[vring->swtail].tx;
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300172
Vladimir Kondratievf88f1132013-07-11 18:03:40 +0300173 ctx = &vring->ctx[vring->swtail];
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300174 *d = *_d;
Vladimir Kondratiev2232abd2014-03-17 15:34:09 +0200175 wil_txdesc_unmap(dev, d, ctx);
Vladimir Kondratievf88f1132013-07-11 18:03:40 +0300176 if (ctx->skb)
177 dev_kfree_skb_any(ctx->skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800178 vring->swtail = wil_vring_next_tail(vring);
179 } else { /* rx */
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300180 struct vring_rx_desc dd, *d = &dd;
181 volatile struct vring_rx_desc *_d =
Vladimir Kondratiev4d1ac072013-07-11 18:03:38 +0300182 &vring->va[vring->swhead].rx;
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300183
Vladimir Kondratievf88f1132013-07-11 18:03:40 +0300184 ctx = &vring->ctx[vring->swhead];
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300185 *d = *_d;
186 pa = wil_desc_addr(&d->dma.addr);
Vladimir Kondratiev7e5944442013-05-12 14:43:32 +0300187 dmalen = le16_to_cpu(d->dma.length);
188 dma_unmap_single(dev, pa, dmalen, DMA_FROM_DEVICE);
Vladimir Kondratievf88f1132013-07-11 18:03:40 +0300189 kfree_skb(ctx->skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800190 wil_vring_advance_head(vring, 1);
191 }
192 }
193 dma_free_coherent(dev, sz, (void *)vring->va, vring->pa);
194 kfree(vring->ctx);
195 vring->pa = 0;
196 vring->va = NULL;
197 vring->ctx = NULL;
198}
199
200/**
201 * Allocate one skb for Rx VRING
202 *
203 * Safe to call from IRQ
204 */
205static int wil_vring_alloc_skb(struct wil6210_priv *wil, struct vring *vring,
206 u32 i, int headroom)
207{
208 struct device *dev = wil_to_dev(wil);
Vladimir Kondratiev9a06bec2014-10-28 16:51:27 +0200209 unsigned int sz = mtu_max + ETH_HLEN;
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300210 struct vring_rx_desc dd, *d = &dd;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300211 volatile struct vring_rx_desc *_d = &vring->va[i].rx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800212 dma_addr_t pa;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800213 struct sk_buff *skb = dev_alloc_skb(sz + headroom);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300214
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800215 if (unlikely(!skb))
216 return -ENOMEM;
217
218 skb_reserve(skb, headroom);
219 skb_put(skb, sz);
220
221 pa = dma_map_single(dev, skb->data, skb->len, DMA_FROM_DEVICE);
222 if (unlikely(dma_mapping_error(dev, pa))) {
223 kfree_skb(skb);
224 return -ENOMEM;
225 }
226
227 d->dma.d0 = BIT(9) | RX_DMA_D0_CMD_DMA_IT;
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300228 wil_desc_addr_set(&d->dma.addr, pa);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800229 /* ip_length don't care */
230 /* b11 don't care */
231 /* error don't care */
232 d->dma.status = 0; /* BIT(0) should be 0 for HW_OWNED */
Vladimir Kondratiev7e5944442013-05-12 14:43:32 +0300233 d->dma.length = cpu_to_le16(sz);
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300234 *_d = *d;
Vladimir Kondratievf88f1132013-07-11 18:03:40 +0300235 vring->ctx[i].skb = skb;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800236
237 return 0;
238}
239
240/**
241 * Adds radiotap header
242 *
243 * Any error indicated as "Bad FCS"
244 *
245 * Vendor data for 04:ce:14-1 (Wilocity-1) consists of:
246 * - Rx descriptor: 32 bytes
247 * - Phy info
248 */
249static void wil_rx_add_radiotap_header(struct wil6210_priv *wil,
Vladimir Kondratiev33e61162013-04-18 14:33:50 +0300250 struct sk_buff *skb)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800251{
252 struct wireless_dev *wdev = wil->wdev;
253 struct wil6210_rtap {
254 struct ieee80211_radiotap_header rthdr;
255 /* fields should be in the order of bits in rthdr.it_present */
256 /* flags */
257 u8 flags;
258 /* channel */
259 __le16 chnl_freq __aligned(2);
260 __le16 chnl_flags;
261 /* MCS */
262 u8 mcs_present;
263 u8 mcs_flags;
264 u8 mcs_index;
265 } __packed;
266 struct wil6210_rtap_vendor {
267 struct wil6210_rtap rtap;
268 /* vendor */
269 u8 vendor_oui[3] __aligned(2);
270 u8 vendor_ns;
271 __le16 vendor_skip;
272 u8 vendor_data[0];
273 } __packed;
Vladimir Kondratiev33e61162013-04-18 14:33:50 +0300274 struct vring_rx_desc *d = wil_skb_rxdesc(skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800275 struct wil6210_rtap_vendor *rtap_vendor;
276 int rtap_len = sizeof(struct wil6210_rtap);
277 int phy_length = 0; /* phy info header size, bytes */
278 static char phy_data[128];
279 struct ieee80211_channel *ch = wdev->preset_chandef.chan;
280
281 if (rtap_include_phy_info) {
282 rtap_len = sizeof(*rtap_vendor) + sizeof(*d);
283 /* calculate additional length */
284 if (d->dma.status & RX_DMA_STATUS_PHY_INFO) {
285 /**
286 * PHY info starts from 8-byte boundary
287 * there are 8-byte lines, last line may be partially
288 * written (HW bug), thus FW configures for last line
289 * to be excessive. Driver skips this last line.
290 */
291 int len = min_t(int, 8 + sizeof(phy_data),
292 wil_rxdesc_phy_length(d));
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300293
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800294 if (len > 8) {
295 void *p = skb_tail_pointer(skb);
296 void *pa = PTR_ALIGN(p, 8);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300297
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800298 if (skb_tailroom(skb) >= len + (pa - p)) {
299 phy_length = len - 8;
300 memcpy(phy_data, pa, phy_length);
301 }
302 }
303 }
304 rtap_len += phy_length;
305 }
306
307 if (skb_headroom(skb) < rtap_len &&
308 pskb_expand_head(skb, rtap_len, 0, GFP_ATOMIC)) {
309 wil_err(wil, "Unable to expand headrom to %d\n", rtap_len);
310 return;
311 }
312
313 rtap_vendor = (void *)skb_push(skb, rtap_len);
314 memset(rtap_vendor, 0, rtap_len);
315
316 rtap_vendor->rtap.rthdr.it_version = PKTHDR_RADIOTAP_VERSION;
317 rtap_vendor->rtap.rthdr.it_len = cpu_to_le16(rtap_len);
318 rtap_vendor->rtap.rthdr.it_present = cpu_to_le32(
319 (1 << IEEE80211_RADIOTAP_FLAGS) |
320 (1 << IEEE80211_RADIOTAP_CHANNEL) |
321 (1 << IEEE80211_RADIOTAP_MCS));
322 if (d->dma.status & RX_DMA_STATUS_ERROR)
323 rtap_vendor->rtap.flags |= IEEE80211_RADIOTAP_F_BADFCS;
324
325 rtap_vendor->rtap.chnl_freq = cpu_to_le16(ch ? ch->center_freq : 58320);
326 rtap_vendor->rtap.chnl_flags = cpu_to_le16(0);
327
328 rtap_vendor->rtap.mcs_present = IEEE80211_RADIOTAP_MCS_HAVE_MCS;
329 rtap_vendor->rtap.mcs_flags = 0;
330 rtap_vendor->rtap.mcs_index = wil_rxdesc_mcs(d);
331
332 if (rtap_include_phy_info) {
333 rtap_vendor->rtap.rthdr.it_present |= cpu_to_le32(1 <<
334 IEEE80211_RADIOTAP_VENDOR_NAMESPACE);
335 /* OUI for Wilocity 04:ce:14 */
336 rtap_vendor->vendor_oui[0] = 0x04;
337 rtap_vendor->vendor_oui[1] = 0xce;
338 rtap_vendor->vendor_oui[2] = 0x14;
339 rtap_vendor->vendor_ns = 1;
340 /* Rx descriptor + PHY data */
341 rtap_vendor->vendor_skip = cpu_to_le16(sizeof(*d) +
342 phy_length);
343 memcpy(rtap_vendor->vendor_data, (void *)d, sizeof(*d));
344 memcpy(rtap_vendor->vendor_data + sizeof(*d), phy_data,
345 phy_length);
346 }
347}
348
349/*
350 * Fast swap in place between 2 registers
351 */
352static void wil_swap_u16(u16 *a, u16 *b)
353{
354 *a ^= *b;
355 *b ^= *a;
356 *a ^= *b;
357}
358
359static void wil_swap_ethaddr(void *data)
360{
361 struct ethhdr *eth = data;
362 u16 *s = (u16 *)eth->h_source;
363 u16 *d = (u16 *)eth->h_dest;
364
365 wil_swap_u16(s++, d++);
366 wil_swap_u16(s++, d++);
367 wil_swap_u16(s, d);
368}
369
370/**
371 * reap 1 frame from @swhead
372 *
Vladimir Kondratiev33e61162013-04-18 14:33:50 +0300373 * Rx descriptor copied to skb->cb
374 *
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800375 * Safe to call from IRQ
376 */
377static struct sk_buff *wil_vring_reap_rx(struct wil6210_priv *wil,
378 struct vring *vring)
379{
380 struct device *dev = wil_to_dev(wil);
381 struct net_device *ndev = wil_to_ndev(wil);
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300382 volatile struct vring_rx_desc *_d;
383 struct vring_rx_desc *d;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800384 struct sk_buff *skb;
385 dma_addr_t pa;
Vladimir Kondratiev9a06bec2014-10-28 16:51:27 +0200386 unsigned int sz = mtu_max + ETH_HLEN;
Vladimir Kondratiev7e5944442013-05-12 14:43:32 +0300387 u16 dmalen;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800388 u8 ftype;
389 u8 ds_bits;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200390 int cid;
391 struct wil_net_stats *stats;
392
Vladimir Kondratiev33e61162013-04-18 14:33:50 +0300393 BUILD_BUG_ON(sizeof(struct vring_rx_desc) > sizeof(skb->cb));
394
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800395 if (wil_vring_is_empty(vring))
396 return NULL;
397
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300398 _d = &vring->va[vring->swhead].rx;
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300399 if (!(_d->dma.status & RX_DMA_STATUS_DU)) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800400 /* it is not error, we just reached end of Rx done area */
401 return NULL;
402 }
403
Vladimir Kondratievf88f1132013-07-11 18:03:40 +0300404 skb = vring->ctx[vring->swhead].skb;
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300405 d = wil_skb_rxdesc(skb);
406 *d = *_d;
407 pa = wil_desc_addr(&d->dma.addr);
Vladimir Kondratievf88f1132013-07-11 18:03:40 +0300408 vring->ctx[vring->swhead].skb = NULL;
Vladimir Kondratieve2700452013-05-12 14:43:33 +0300409 wil_vring_advance_head(vring, 1);
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300410
411 dma_unmap_single(dev, pa, sz, DMA_FROM_DEVICE);
412 dmalen = le16_to_cpu(d->dma.length);
413
414 trace_wil6210_rx(vring->swhead, d);
415 wil_dbg_txrx(wil, "Rx[%3d] : %d bytes\n", vring->swhead, dmalen);
416 wil_hex_dump_txrx("Rx ", DUMP_PREFIX_NONE, 32, 4,
417 (const void *)d, sizeof(*d), false);
418
Vladimir Kondratieve2700452013-05-12 14:43:33 +0300419 if (dmalen > sz) {
420 wil_err(wil, "Rx size too large: %d bytes!\n", dmalen);
Wei Yongjun110dea02013-05-23 17:10:43 +0800421 kfree_skb(skb);
Vladimir Kondratieve2700452013-05-12 14:43:33 +0300422 return NULL;
423 }
Vladimir Kondratiev7e5944442013-05-12 14:43:32 +0300424 skb_trim(skb, dmalen);
Vladimir Kondratiev33e61162013-04-18 14:33:50 +0300425
Vladimir Kondratiev1cbbcb02014-01-08 11:50:49 +0200426 prefetch(skb->data);
427
Vladimir Kondratievc0d37712013-05-12 14:43:34 +0300428 wil_hex_dump_txrx("Rx ", DUMP_PREFIX_OFFSET, 16, 1,
429 skb->data, skb_headlen(skb), false);
430
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200431 cid = wil_rxdesc_cid(d);
432 stats = &wil->sta[cid].stats;
433 stats->last_mcs_rx = wil_rxdesc_mcs(d);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800434
435 /* use radiotap header only if required */
436 if (ndev->type == ARPHRD_IEEE80211_RADIOTAP)
Vladimir Kondratiev33e61162013-04-18 14:33:50 +0300437 wil_rx_add_radiotap_header(wil, skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800438
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800439 /* no extra checks if in sniffer mode */
440 if (ndev->type != ARPHRD_ETHER)
441 return skb;
442 /*
443 * Non-data frames may be delivered through Rx DMA channel (ex: BAR)
444 * Driver should recognize it by frame type, that is found
445 * in Rx descriptor. If type is not data, it is 802.11 frame as is
446 */
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300447 ftype = wil_rxdesc_ftype(d) << 2;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800448 if (ftype != IEEE80211_FTYPE_DATA) {
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200449 wil_dbg_txrx(wil, "Non-data frame ftype 0x%08x\n", ftype);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800450 /* TODO: process it */
451 kfree_skb(skb);
452 return NULL;
453 }
454
455 if (skb->len < ETH_HLEN) {
456 wil_err(wil, "Short frame, len = %d\n", skb->len);
457 /* TODO: process it (i.e. BAR) */
458 kfree_skb(skb);
459 return NULL;
460 }
461
Kirshenbaum Erez504937d2013-07-21 11:34:37 +0300462 /* L4 IDENT is on when HW calculated checksum, check status
463 * and in case of error drop the packet
464 * higher stack layers will handle retransmission (if required)
465 */
Vladimir Kondratiev8d3b2f02014-12-23 09:47:22 +0200466 if (d->dma.status & RX_DMA_STATUS_L4I) {
Kirshenbaum Erez504937d2013-07-21 11:34:37 +0300467 /* L4 protocol identified, csum calculated */
Vladimir Kondratiev4a68ab102013-08-13 15:25:32 +0300468 if ((d->dma.error & RX_DMA_ERROR_L4_ERR) == 0)
Kirshenbaum Erez504937d2013-07-21 11:34:37 +0300469 skb->ip_summed = CHECKSUM_UNNECESSARY;
Vladimir Kondratiev4a68ab102013-08-13 15:25:32 +0300470 /* If HW reports bad checksum, let IP stack re-check it
471 * For example, HW don't understand Microsoft IP stack that
472 * mis-calculates TCP checksum - if it should be 0x0,
473 * it writes 0xffff in violation of RFC 1624
474 */
Kirshenbaum Erez504937d2013-07-21 11:34:37 +0300475 }
476
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300477 ds_bits = wil_rxdesc_ds_bits(d);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800478 if (ds_bits == 1) {
479 /*
480 * HW bug - in ToDS mode, i.e. Rx on AP side,
481 * addresses get swapped
482 */
483 wil_swap_ethaddr(skb->data);
484 }
485
486 return skb;
487}
488
489/**
490 * allocate and fill up to @count buffers in rx ring
491 * buffers posted at @swtail
492 */
493static int wil_rx_refill(struct wil6210_priv *wil, int count)
494{
495 struct net_device *ndev = wil_to_ndev(wil);
496 struct vring *v = &wil->vring_rx;
497 u32 next_tail;
498 int rc = 0;
499 int headroom = ndev->type == ARPHRD_IEEE80211_RADIOTAP ?
500 WIL6210_RTAP_SIZE : 0;
501
502 for (; next_tail = wil_vring_next_tail(v),
503 (next_tail != v->swhead) && (count-- > 0);
504 v->swtail = next_tail) {
505 rc = wil_vring_alloc_skb(wil, v, v->swtail, headroom);
506 if (rc) {
507 wil_err(wil, "Error %d in wil_rx_refill[%d]\n",
508 rc, v->swtail);
509 break;
510 }
511 }
512 iowrite32(v->swtail, wil->csr + HOSTADDR(v->hwtail));
513
514 return rc;
515}
516
517/*
518 * Pass Rx packet to the netif. Update statistics.
Vladimir Kondratieve0287c42013-05-12 14:43:36 +0300519 * Called in softirq context (NAPI poll).
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800520 */
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200521void wil_netif_rx_any(struct sk_buff *skb, struct net_device *ndev)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800522{
Vladimir Kondratievb5998e62014-03-17 15:34:22 +0200523 gro_result_t rc;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200524 struct wil6210_priv *wil = ndev_to_wil(ndev);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800525 unsigned int len = skb->len;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200526 struct vring_rx_desc *d = wil_skb_rxdesc(skb);
527 int cid = wil_rxdesc_cid(d);
528 struct wil_net_stats *stats = &wil->sta[cid].stats;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800529
Vladimir Kondratiev241804c2013-01-28 18:31:02 +0200530 skb_orphan(skb);
531
Vladimir Kondratievb5998e62014-03-17 15:34:22 +0200532 rc = napi_gro_receive(&wil->napi_rx, skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800533
Vladimir Kondratievb5998e62014-03-17 15:34:22 +0200534 if (unlikely(rc == GRO_DROP)) {
535 ndev->stats.rx_dropped++;
536 stats->rx_dropped++;
537 wil_dbg_txrx(wil, "Rx drop %d bytes\n", len);
538 } else {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800539 ndev->stats.rx_packets++;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200540 stats->rx_packets++;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800541 ndev->stats.rx_bytes += len;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200542 stats->rx_bytes += len;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800543 }
Vladimir Kondratiev194b4822014-06-16 19:37:14 +0300544 {
545 static const char * const gro_res_str[] = {
546 [GRO_MERGED] = "GRO_MERGED",
547 [GRO_MERGED_FREE] = "GRO_MERGED_FREE",
548 [GRO_HELD] = "GRO_HELD",
549 [GRO_NORMAL] = "GRO_NORMAL",
550 [GRO_DROP] = "GRO_DROP",
551 };
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300552 wil_dbg_txrx(wil, "Rx complete %d bytes => %s\n",
Vladimir Kondratiev194b4822014-06-16 19:37:14 +0300553 len, gro_res_str[rc]);
554 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800555}
556
557/**
558 * Proceed all completed skb's from Rx VRING
559 *
Vladimir Kondratieve0287c42013-05-12 14:43:36 +0300560 * Safe to call from NAPI poll, i.e. softirq with interrupts enabled
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800561 */
Vladimir Kondratieve0287c42013-05-12 14:43:36 +0300562void wil_rx_handle(struct wil6210_priv *wil, int *quota)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800563{
564 struct net_device *ndev = wil_to_ndev(wil);
565 struct vring *v = &wil->vring_rx;
566 struct sk_buff *skb;
567
568 if (!v->va) {
569 wil_err(wil, "Rx IRQ while Rx not yet initialized\n");
570 return;
571 }
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200572 wil_dbg_txrx(wil, "%s()\n", __func__);
Vladimir Kondratieve0287c42013-05-12 14:43:36 +0300573 while ((*quota > 0) && (NULL != (skb = wil_vring_reap_rx(wil, v)))) {
574 (*quota)--;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800575
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800576 if (wil->wdev->iftype == NL80211_IFTYPE_MONITOR) {
577 skb->dev = ndev;
578 skb_reset_mac_header(skb);
579 skb->ip_summed = CHECKSUM_UNNECESSARY;
580 skb->pkt_type = PACKET_OTHERHOST;
581 skb->protocol = htons(ETH_P_802_2);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200582 wil_netif_rx_any(skb, ndev);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800583 } else {
584 skb->protocol = eth_type_trans(skb, ndev);
Vladimir Kondratieve4373d82014-12-23 09:47:21 +0200585 wil_rx_reorder(wil, skb);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800586 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800587 }
588 wil_rx_refill(wil, v->size);
589}
590
Vladimir Kondratievd3762b42014-12-01 15:35:02 +0200591int wil_rx_init(struct wil6210_priv *wil, u16 size)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800592{
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800593 struct vring *vring = &wil->vring_rx;
594 int rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800595
Vladimir Kondratiev9cf10d62014-09-10 16:34:36 +0300596 wil_dbg_misc(wil, "%s()\n", __func__);
597
Vladimir Kondratiev8bf6adb2014-03-17 15:34:17 +0200598 if (vring->va) {
599 wil_err(wil, "Rx ring already allocated\n");
600 return -EINVAL;
601 }
602
Vladimir Kondratievd3762b42014-12-01 15:35:02 +0200603 vring->size = size;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800604 rc = wil_vring_alloc(wil, vring);
605 if (rc)
606 return rc;
607
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +0200608 rc = wmi_rx_chain_add(wil, vring);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800609 if (rc)
610 goto err_free;
611
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800612 rc = wil_rx_refill(wil, vring->size);
613 if (rc)
614 goto err_free;
615
616 return 0;
617 err_free:
618 wil_vring_free(wil, vring, 0);
619
620 return rc;
621}
622
623void wil_rx_fini(struct wil6210_priv *wil)
624{
625 struct vring *vring = &wil->vring_rx;
626
Vladimir Kondratiev9cf10d62014-09-10 16:34:36 +0300627 wil_dbg_misc(wil, "%s()\n", __func__);
628
Vladimir Kondratiev2acb4222013-01-28 18:31:08 +0200629 if (vring->va)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800630 wil_vring_free(wil, vring, 0);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800631}
632
633int wil_vring_init_tx(struct wil6210_priv *wil, int id, int size,
634 int cid, int tid)
635{
636 int rc;
637 struct wmi_vring_cfg_cmd cmd = {
638 .action = cpu_to_le32(WMI_VRING_CMD_ADD),
639 .vring_cfg = {
640 .tx_sw_ring = {
Vladimir Kondratiev9a06bec2014-10-28 16:51:27 +0200641 .max_mpdu_size =
Vladimir Kondratievc44690a2014-12-23 09:47:11 +0200642 cpu_to_le16(wil_mtu2macbuf(mtu_max)),
Vladimir Kondratievb5d98e92013-04-18 14:33:51 +0300643 .ring_size = cpu_to_le16(size),
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800644 },
645 .ringid = id,
Vladimir Kondratieva70abea2014-03-17 15:34:05 +0200646 .cidxtid = mk_cidxtid(cid, tid),
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800647 .encap_trans_type = WMI_VRING_ENC_TYPE_802_3,
648 .mac_ctrl = 0,
649 .to_resolution = 0,
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200650 .agg_max_wsize = 0,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800651 .schd_params = {
652 .priority = cpu_to_le16(0),
653 .timeslot_us = cpu_to_le16(0xfff),
654 },
655 },
656 };
657 struct {
658 struct wil6210_mbox_hdr_wmi wmi;
659 struct wmi_vring_cfg_done_event cmd;
660 } __packed reply;
661 struct vring *vring = &wil->vring_tx[id];
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200662 struct vring_tx_data *txdata = &wil->vring_tx_data[id];
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800663
Vladimir Kondratieve0106ad2014-09-10 16:34:45 +0300664 wil_dbg_misc(wil, "%s() max_mpdu_size %d\n", __func__,
665 cmd.vring_cfg.tx_sw_ring.max_mpdu_size);
Vladimir Kondratiev9cf10d62014-09-10 16:34:36 +0300666
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800667 if (vring->va) {
668 wil_err(wil, "Tx ring [%d] already allocated\n", id);
669 rc = -EINVAL;
670 goto out;
671 }
672
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200673 memset(txdata, 0, sizeof(*txdata));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800674 vring->size = size;
675 rc = wil_vring_alloc(wil, vring);
676 if (rc)
677 goto out;
678
Vladimir Kondratiev93ae6d42014-02-27 16:20:51 +0200679 wil->vring2cid_tid[id][0] = cid;
680 wil->vring2cid_tid[id][1] = tid;
681
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800682 cmd.vring_cfg.tx_sw_ring.ring_mem_base = cpu_to_le64(vring->pa);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800683
684 rc = wmi_call(wil, WMI_VRING_CFG_CMDID, &cmd, sizeof(cmd),
685 WMI_VRING_CFG_DONE_EVENTID, &reply, sizeof(reply), 100);
686 if (rc)
687 goto out_free;
688
Vladimir Kondratievb8023172013-03-13 14:12:50 +0200689 if (reply.cmd.status != WMI_FW_STATUS_SUCCESS) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800690 wil_err(wil, "Tx config failed, status 0x%02x\n",
691 reply.cmd.status);
Vladimir Kondratievc3319972013-01-28 18:31:09 +0200692 rc = -EINVAL;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800693 goto out_free;
694 }
695 vring->hwtail = le32_to_cpu(reply.cmd.tx_vring_tail_ptr);
696
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200697 txdata->enabled = 1;
Vladimir Kondratiev3a3def82014-12-23 09:47:05 +0200698 if (wil->sta[cid].data_port_open && (agg_wsize >= 0))
699 wil_addba_tx_request(wil, id, agg_wsize);
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200700
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800701 return 0;
702 out_free:
703 wil_vring_free(wil, vring, 1);
704 out:
705
706 return rc;
707}
708
709void wil_vring_fini_tx(struct wil6210_priv *wil, int id)
710{
711 struct vring *vring = &wil->vring_tx[id];
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200712 struct vring_tx_data *txdata = &wil->vring_tx_data[id];
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800713
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200714 WARN_ON(!mutex_is_locked(&wil->mutex));
715
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800716 if (!vring->va)
717 return;
718
Vladimir Kondratiev9cf10d62014-09-10 16:34:36 +0300719 wil_dbg_misc(wil, "%s() id=%d\n", __func__, id);
720
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200721 /* make sure NAPI won't touch this vring */
722 wil->vring_tx_data[id].enabled = 0;
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200723 if (test_bit(wil_status_napi_en, wil->status))
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200724 napi_synchronize(&wil->napi_tx);
725
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800726 wil_vring_free(wil, vring, 1);
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200727 memset(txdata, 0, sizeof(*txdata));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800728}
729
730static struct vring *wil_find_tx_vring(struct wil6210_priv *wil,
731 struct sk_buff *skb)
732{
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200733 int i;
734 struct ethhdr *eth = (void *)skb->data;
735 int cid = wil_find_cid(wil, eth->h_dest);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800736
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200737 if (cid < 0)
738 return NULL;
739
Vladimir Kondratieve58c9f72014-03-17 15:34:06 +0200740 if (!wil->sta[cid].data_port_open &&
741 (skb->protocol != cpu_to_be16(ETH_P_PAE)))
742 return NULL;
743
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200744 /* TODO: fix for multiple TID */
745 for (i = 0; i < ARRAY_SIZE(wil->vring2cid_tid); i++) {
746 if (wil->vring2cid_tid[i][0] == cid) {
747 struct vring *v = &wil->vring_tx[i];
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300748
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200749 wil_dbg_txrx(wil, "%s(%pM) -> [%d]\n",
750 __func__, eth->h_dest, i);
751 if (v->va) {
752 return v;
753 } else {
754 wil_dbg_txrx(wil, "vring[%d] not valid\n", i);
755 return NULL;
756 }
757 }
758 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800759
760 return NULL;
761}
762
Vladimir Kondratievfb3cac52014-02-27 16:20:46 +0200763static void wil_set_da_for_vring(struct wil6210_priv *wil,
764 struct sk_buff *skb, int vring_index)
765{
766 struct ethhdr *eth = (void *)skb->data;
767 int cid = wil->vring2cid_tid[vring_index][0];
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300768
Vladimir Kondratievfb3cac52014-02-27 16:20:46 +0200769 memcpy(eth->h_dest, wil->sta[cid].addr, ETH_ALEN);
770}
771
772static int wil_tx_vring(struct wil6210_priv *wil, struct vring *vring,
773 struct sk_buff *skb);
Vladimir Kondratiev54ed90a2014-12-23 09:47:15 +0200774
775static struct vring *wil_find_tx_vring_sta(struct wil6210_priv *wil,
776 struct sk_buff *skb)
777{
778 struct vring *v;
779 int i;
780 u8 cid;
781
782 /* In the STA mode, it is expected to have only 1 VRING
783 * for the AP we connected to.
784 * find 1-st vring and see whether it is eligible for data
785 */
786 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
787 v = &wil->vring_tx[i];
788 if (!v->va)
789 continue;
790
791 cid = wil->vring2cid_tid[i][0];
792 if (!wil->sta[cid].data_port_open &&
793 (skb->protocol != cpu_to_be16(ETH_P_PAE)))
794 break;
795
796 wil_dbg_txrx(wil, "Tx -> ring %d\n", i);
797
798 return v;
799 }
800
801 wil_dbg_txrx(wil, "Tx while no vrings active?\n");
802
803 return NULL;
804}
805
Vladimir Kondratievfb3cac52014-02-27 16:20:46 +0200806/*
807 * Find 1-st vring and return it; set dest address for this vring in skb
808 * duplicate skb and send it to other active vrings
809 */
810static struct vring *wil_tx_bcast(struct wil6210_priv *wil,
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300811 struct sk_buff *skb)
Vladimir Kondratievfb3cac52014-02-27 16:20:46 +0200812{
813 struct vring *v, *v2;
814 struct sk_buff *skb2;
815 int i;
Vladimir Kondratieve58c9f72014-03-17 15:34:06 +0200816 u8 cid;
Vladimir Kondratievfb3cac52014-02-27 16:20:46 +0200817
Vladimir Kondratieve58c9f72014-03-17 15:34:06 +0200818 /* find 1-st vring eligible for data */
Vladimir Kondratievfb3cac52014-02-27 16:20:46 +0200819 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
820 v = &wil->vring_tx[i];
Vladimir Kondratieve58c9f72014-03-17 15:34:06 +0200821 if (!v->va)
822 continue;
823
824 cid = wil->vring2cid_tid[i][0];
825 if (!wil->sta[cid].data_port_open)
826 continue;
827
828 goto found;
Vladimir Kondratievfb3cac52014-02-27 16:20:46 +0200829 }
830
Vladimir Kondratiev5aed1392014-06-16 19:37:15 +0300831 wil_dbg_txrx(wil, "Tx while no vrings active?\n");
Vladimir Kondratievfb3cac52014-02-27 16:20:46 +0200832
833 return NULL;
834
835found:
836 wil_dbg_txrx(wil, "BCAST -> ring %d\n", i);
837 wil_set_da_for_vring(wil, skb, i);
838
839 /* find other active vrings and duplicate skb for each */
840 for (i++; i < WIL6210_MAX_TX_RINGS; i++) {
841 v2 = &wil->vring_tx[i];
842 if (!v2->va)
843 continue;
Vladimir Kondratieve58c9f72014-03-17 15:34:06 +0200844 cid = wil->vring2cid_tid[i][0];
845 if (!wil->sta[cid].data_port_open)
846 continue;
847
Vladimir Kondratievfb3cac52014-02-27 16:20:46 +0200848 skb2 = skb_copy(skb, GFP_ATOMIC);
849 if (skb2) {
850 wil_dbg_txrx(wil, "BCAST DUP -> ring %d\n", i);
851 wil_set_da_for_vring(wil, skb2, i);
852 wil_tx_vring(wil, v2, skb2);
853 } else {
854 wil_err(wil, "skb_copy failed\n");
855 }
856 }
857
858 return v;
859}
860
Kirshenbaum Erez99b55bd2013-06-23 12:59:34 +0300861static int wil_tx_desc_map(struct vring_tx_desc *d, dma_addr_t pa, u32 len,
862 int vring_index)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800863{
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300864 wil_desc_addr_set(&d->dma.addr, pa);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800865 d->dma.ip_length = 0;
866 /* 0..6: mac_length; 7:ip_version 0-IP6 1-IP4*/
867 d->dma.b11 = 0/*14 | BIT(7)*/;
868 d->dma.error = 0;
869 d->dma.status = 0; /* BIT(0) should be 0 for HW_OWNED */
Vladimir Kondratiev7e5944442013-05-12 14:43:32 +0300870 d->dma.length = cpu_to_le16((u16)len);
Kirshenbaum Erez99b55bd2013-06-23 12:59:34 +0300871 d->dma.d0 = (vring_index << DMA_CFG_DESC_TX_0_QID_POS);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800872 d->mac.d[0] = 0;
873 d->mac.d[1] = 0;
874 d->mac.d[2] = 0;
875 d->mac.ucode_cmd = 0;
876 /* use dst index 0 */
877 d->mac.d[1] |= BIT(MAC_CFG_DESC_TX_1_DST_INDEX_EN_POS) |
878 (0 << MAC_CFG_DESC_TX_1_DST_INDEX_POS);
879 /* translation type: 0 - bypass; 1 - 802.3; 2 - native wifi */
880 d->mac.d[2] = BIT(MAC_CFG_DESC_TX_2_SNAP_HDR_INSERTION_EN_POS) |
881 (1 << MAC_CFG_DESC_TX_2_L2_TRANSLATION_TYPE_POS);
882
883 return 0;
884}
885
Vladimir Kondratievc2366582014-03-17 15:34:08 +0200886static inline
887void wil_tx_desc_set_nr_frags(struct vring_tx_desc *d, int nr_frags)
888{
889 d->mac.d[2] |= ((nr_frags + 1) <<
890 MAC_CFG_DESC_TX_2_NUM_OF_DESCRIPTORS_POS);
891}
892
Kirshenbaum Erez504937d2013-07-21 11:34:37 +0300893static int wil_tx_desc_offload_cksum_set(struct wil6210_priv *wil,
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300894 struct vring_tx_desc *d,
895 struct sk_buff *skb)
Kirshenbaum Erez504937d2013-07-21 11:34:37 +0300896{
897 int protocol;
898
899 if (skb->ip_summed != CHECKSUM_PARTIAL)
900 return 0;
901
Vladimir Kondratievdf2d08e2014-01-08 11:50:48 +0200902 d->dma.b11 = ETH_HLEN; /* MAC header length */
903
Kirshenbaum Erez504937d2013-07-21 11:34:37 +0300904 switch (skb->protocol) {
905 case cpu_to_be16(ETH_P_IP):
906 protocol = ip_hdr(skb)->protocol;
Vladimir Kondratievdf2d08e2014-01-08 11:50:48 +0200907 d->dma.b11 |= BIT(DMA_CFG_DESC_TX_OFFLOAD_CFG_L3T_IPV4_POS);
Kirshenbaum Erez504937d2013-07-21 11:34:37 +0300908 break;
909 case cpu_to_be16(ETH_P_IPV6):
910 protocol = ipv6_hdr(skb)->nexthdr;
911 break;
912 default:
913 return -EINVAL;
914 }
915
916 switch (protocol) {
917 case IPPROTO_TCP:
918 d->dma.d0 |= (2 << DMA_CFG_DESC_TX_0_L4_TYPE_POS);
919 /* L4 header len: TCP header length */
920 d->dma.d0 |=
921 (tcp_hdrlen(skb) & DMA_CFG_DESC_TX_0_L4_LENGTH_MSK);
922 break;
923 case IPPROTO_UDP:
924 /* L4 header len: UDP header length */
925 d->dma.d0 |=
926 (sizeof(struct udphdr) & DMA_CFG_DESC_TX_0_L4_LENGTH_MSK);
927 break;
928 default:
929 return -EINVAL;
930 }
931
932 d->dma.ip_length = skb_network_header_len(skb);
Kirshenbaum Erez504937d2013-07-21 11:34:37 +0300933 /* Enable TCP/UDP checksum */
934 d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_TCP_UDP_CHECKSUM_EN_POS);
935 /* Calculate pseudo-header */
936 d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_PSEUDO_HEADER_CALC_EN_POS);
937
938 return 0;
939}
940
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800941static int wil_tx_vring(struct wil6210_priv *wil, struct vring *vring,
942 struct sk_buff *skb)
943{
944 struct device *dev = wil_to_dev(wil);
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300945 struct vring_tx_desc dd, *d = &dd;
946 volatile struct vring_tx_desc *_d;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800947 u32 swhead = vring->swhead;
948 int avail = wil_vring_avail_tx(vring);
949 int nr_frags = skb_shinfo(skb)->nr_frags;
Kirshenbaum Erez504937d2013-07-21 11:34:37 +0300950 uint f = 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800951 int vring_index = vring - wil->vring_tx;
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +0300952 struct vring_tx_data *txdata = &wil->vring_tx_data[vring_index];
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800953 uint i = swhead;
954 dma_addr_t pa;
955
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200956 wil_dbg_txrx(wil, "%s()\n", __func__);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800957
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800958 if (avail < 1 + nr_frags) {
Vladimir Kondratiev70801e12014-12-01 15:36:03 +0200959 wil_err_ratelimited(wil,
960 "Tx ring full. No space for %d fragments\n",
961 1 + nr_frags);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800962 return -ENOMEM;
963 }
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300964 _d = &vring->va[i].tx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800965
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300966 pa = dma_map_single(dev, skb->data, skb_headlen(skb), DMA_TO_DEVICE);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800967
Vladimir Kondratiev39c52ee2014-05-27 14:45:49 +0300968 wil_dbg_txrx(wil, "Tx skb %d bytes 0x%p -> %pad\n", skb_headlen(skb),
969 skb->data, &pa);
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200970 wil_hex_dump_txrx("Tx ", DUMP_PREFIX_OFFSET, 16, 1,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800971 skb->data, skb_headlen(skb), false);
972
973 if (unlikely(dma_mapping_error(dev, pa)))
974 return -EINVAL;
Vladimir Kondratiev2232abd2014-03-17 15:34:09 +0200975 vring->ctx[i].mapped_as = wil_mapped_as_single;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800976 /* 1-st segment */
Kirshenbaum Erez99b55bd2013-06-23 12:59:34 +0300977 wil_tx_desc_map(d, pa, skb_headlen(skb), vring_index);
Kirshenbaum Erez504937d2013-07-21 11:34:37 +0300978 /* Process TCP/UDP checksum offloading */
979 if (wil_tx_desc_offload_cksum_set(wil, d, skb)) {
980 wil_err(wil, "VRING #%d Failed to set cksum, drop packet\n",
981 vring_index);
982 goto dma_error;
983 }
984
Vladimir Kondratievc2366582014-03-17 15:34:08 +0200985 vring->ctx[i].nr_frags = nr_frags;
986 wil_tx_desc_set_nr_frags(d, nr_frags);
Vladimir Kondratiev68ada712013-05-12 14:43:37 +0300987 if (nr_frags)
988 *_d = *d;
989
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800990 /* middle segments */
Kirshenbaum Erez504937d2013-07-21 11:34:37 +0300991 for (; f < nr_frags; f++) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800992 const struct skb_frag_struct *frag =
993 &skb_shinfo(skb)->frags[f];
994 int len = skb_frag_size(frag);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300995
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800996 i = (swhead + f + 1) % vring->size;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300997 _d = &vring->va[i].tx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800998 pa = skb_frag_dma_map(dev, frag, 0, skb_frag_size(frag),
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300999 DMA_TO_DEVICE);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001000 if (unlikely(dma_mapping_error(dev, pa)))
1001 goto dma_error;
Vladimir Kondratiev2232abd2014-03-17 15:34:09 +02001002 vring->ctx[i].mapped_as = wil_mapped_as_page;
Kirshenbaum Erez99b55bd2013-06-23 12:59:34 +03001003 wil_tx_desc_map(d, pa, len, vring_index);
Vladimir Kondratievc2366582014-03-17 15:34:08 +02001004 /* no need to check return code -
1005 * if it succeeded for 1-st descriptor,
1006 * it will succeed here too
1007 */
1008 wil_tx_desc_offload_cksum_set(wil, d, skb);
Vladimir Kondratiev68ada712013-05-12 14:43:37 +03001009 *_d = *d;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001010 }
1011 /* for the last seg only */
1012 d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_CMD_EOP_POS);
Kirshenbaum Erez668b2bb2013-06-23 12:59:35 +03001013 d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_CMD_MARK_WB_POS);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001014 d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_CMD_DMA_IT_POS);
Vladimir Kondratiev68ada712013-05-12 14:43:37 +03001015 *_d = *d;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001016
Vladimir Kondratiev6cdadd42013-07-11 18:03:41 +03001017 /* hold reference to skb
1018 * to prevent skb release before accounting
1019 * in case of immediate "tx done"
1020 */
1021 vring->ctx[i].skb = skb_get(skb);
1022
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001023 wil_hex_dump_txrx("Tx ", DUMP_PREFIX_NONE, 32, 4,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001024 (const void *)d, sizeof(*d), false);
1025
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +03001026 if (wil_vring_is_empty(vring)) /* performance monitoring */
1027 txdata->idle += get_cycles() - txdata->last_idle;
1028
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001029 /* advance swhead */
1030 wil_vring_advance_head(vring, nr_frags + 1);
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001031 wil_dbg_txrx(wil, "Tx swhead %d -> %d\n", swhead, vring->swhead);
Vladimir Kondratiev98658092013-05-12 14:43:35 +03001032 trace_wil6210_tx(vring_index, swhead, skb->len, nr_frags);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001033 iowrite32(vring->swhead, wil->csr + HOSTADDR(vring->hwtail));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001034
1035 return 0;
1036 dma_error:
1037 /* unmap what we have mapped */
Vladimir Kondratievc2a146f2013-07-21 11:34:36 +03001038 nr_frags = f + 1; /* frags mapped + one for skb head */
1039 for (f = 0; f < nr_frags; f++) {
Vladimir Kondratievc2a146f2013-07-21 11:34:36 +03001040 struct wil_ctx *ctx;
Vladimir Kondratiev7e5944442013-05-12 14:43:32 +03001041
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001042 i = (swhead + f) % vring->size;
Vladimir Kondratievc2a146f2013-07-21 11:34:36 +03001043 ctx = &vring->ctx[i];
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001044 _d = &vring->va[i].tx;
Vladimir Kondratiev68ada712013-05-12 14:43:37 +03001045 *d = *_d;
1046 _d->dma.status = TX_DMA_STATUS_DU;
Vladimir Kondratiev2232abd2014-03-17 15:34:09 +02001047 wil_txdesc_unmap(dev, d, ctx);
Vladimir Kondratievf88f1132013-07-11 18:03:40 +03001048
1049 if (ctx->skb)
1050 dev_kfree_skb_any(ctx->skb);
1051
1052 memset(ctx, 0, sizeof(*ctx));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001053 }
1054
1055 return -EINVAL;
1056}
1057
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001058netdev_tx_t wil_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1059{
1060 struct wil6210_priv *wil = ndev_to_wil(ndev);
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001061 struct ethhdr *eth = (void *)skb->data;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001062 struct vring *vring;
Vladimir Kondratievaa27dea2014-03-17 15:34:11 +02001063 static bool pr_once_fw;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001064 int rc;
1065
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001066 wil_dbg_txrx(wil, "%s()\n", __func__);
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +02001067 if (!test_bit(wil_status_fwready, wil->status)) {
Vladimir Kondratievaa27dea2014-03-17 15:34:11 +02001068 if (!pr_once_fw) {
1069 wil_err(wil, "FW not ready\n");
1070 pr_once_fw = true;
1071 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001072 goto drop;
1073 }
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +02001074 if (!test_bit(wil_status_fwconnected, wil->status)) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001075 wil_err(wil, "FW not connected\n");
1076 goto drop;
1077 }
1078 if (wil->wdev->iftype == NL80211_IFTYPE_MONITOR) {
1079 wil_err(wil, "Xmit in monitor mode not supported\n");
1080 goto drop;
1081 }
Vladimir Kondratievaa27dea2014-03-17 15:34:11 +02001082 pr_once_fw = false;
Vladimir Kondratievd58db4e2013-06-09 09:12:54 +03001083
1084 /* find vring */
Vladimir Kondratiev54ed90a2014-12-23 09:47:15 +02001085 if (wil->wdev->iftype == NL80211_IFTYPE_STATION) {
1086 /* in STA mode (ESS), all to same VRING */
1087 vring = wil_find_tx_vring_sta(wil, skb);
1088 } else { /* direct communication, find matching VRING */
1089 if (is_unicast_ether_addr(eth->h_dest))
1090 vring = wil_find_tx_vring(wil, skb);
1091 else
1092 vring = wil_tx_bcast(wil, skb);
1093 }
Vladimir Kondratievd58db4e2013-06-09 09:12:54 +03001094 if (!vring) {
Vladimir Kondratiev5aed1392014-06-16 19:37:15 +03001095 wil_dbg_txrx(wil, "No Tx VRING found for %pM\n", eth->h_dest);
Vladimir Kondratievd58db4e2013-06-09 09:12:54 +03001096 goto drop;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001097 }
Vladimir Kondratievd58db4e2013-06-09 09:12:54 +03001098 /* set up vring entry */
1099 rc = wil_tx_vring(wil, vring, skb);
1100
Vladimir Kondratiev2232abd2014-03-17 15:34:09 +02001101 /* do we still have enough room in the vring? */
Vladimir Kondratiev55f8f682014-06-16 19:37:23 +03001102 if (wil_vring_avail_tx(vring) < wil_vring_wmark_low(vring)) {
Vladimir Kondratiev2232abd2014-03-17 15:34:09 +02001103 netif_tx_stop_all_queues(wil_to_ndev(wil));
Vladimir Kondratiev55f8f682014-06-16 19:37:23 +03001104 wil_dbg_txrx(wil, "netif_tx_stop : ring full\n");
1105 }
Vladimir Kondratiev2232abd2014-03-17 15:34:09 +02001106
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001107 switch (rc) {
1108 case 0:
Vladimir Kondratiev795ce732013-01-28 18:31:00 +02001109 /* statistics will be updated on the tx_complete */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001110 dev_kfree_skb_any(skb);
1111 return NETDEV_TX_OK;
1112 case -ENOMEM:
1113 return NETDEV_TX_BUSY;
1114 default:
Vladimir Kondratievafda8bb2013-01-28 18:31:07 +02001115 break; /* goto drop; */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001116 }
1117 drop:
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001118 ndev->stats.tx_dropped++;
1119 dev_kfree_skb_any(skb);
1120
1121 return NET_XMIT_DROP;
1122}
1123
Vladimir Kondratiev713c8a22015-01-25 10:52:49 +02001124static inline bool wil_need_txstat(struct sk_buff *skb)
1125{
1126 struct ethhdr *eth = (void *)skb->data;
1127
1128 return is_unicast_ether_addr(eth->h_dest) && skb->sk &&
1129 (skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS);
1130}
1131
1132static inline void wil_consume_skb(struct sk_buff *skb, bool acked)
1133{
1134 if (unlikely(wil_need_txstat(skb)))
1135 skb_complete_wifi_ack(skb, acked);
1136 else
1137 acked ? dev_consume_skb_any(skb) : dev_kfree_skb_any(skb);
1138}
1139
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001140/**
1141 * Clean up transmitted skb's from the Tx VRING
1142 *
Vladimir Kondratieve0287c42013-05-12 14:43:36 +03001143 * Return number of descriptors cleared
1144 *
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001145 * Safe to call from IRQ
1146 */
Vladimir Kondratieve0287c42013-05-12 14:43:36 +03001147int wil_tx_complete(struct wil6210_priv *wil, int ringid)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001148{
Vladimir Kondratiev795ce732013-01-28 18:31:00 +02001149 struct net_device *ndev = wil_to_ndev(wil);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001150 struct device *dev = wil_to_dev(wil);
1151 struct vring *vring = &wil->vring_tx[ringid];
Vladimir Kondratiev097638a2014-03-17 15:34:25 +02001152 struct vring_tx_data *txdata = &wil->vring_tx_data[ringid];
Vladimir Kondratieve0287c42013-05-12 14:43:36 +03001153 int done = 0;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +02001154 int cid = wil->vring2cid_tid[ringid][0];
1155 struct wil_net_stats *stats = &wil->sta[cid].stats;
Vladimir Kondratievc2366582014-03-17 15:34:08 +02001156 volatile struct vring_tx_desc *_d;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001157
1158 if (!vring->va) {
1159 wil_err(wil, "Tx irq[%d]: vring not initialized\n", ringid);
Vladimir Kondratieve0287c42013-05-12 14:43:36 +03001160 return 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001161 }
1162
Vladimir Kondratiev097638a2014-03-17 15:34:25 +02001163 if (!txdata->enabled) {
1164 wil_info(wil, "Tx irq[%d]: vring disabled\n", ringid);
1165 return 0;
1166 }
1167
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001168 wil_dbg_txrx(wil, "%s(%d)\n", __func__, ringid);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001169
1170 while (!wil_vring_is_empty(vring)) {
Vladimir Kondratievc2366582014-03-17 15:34:08 +02001171 int new_swtail;
Vladimir Kondratievf88f1132013-07-11 18:03:40 +03001172 struct wil_ctx *ctx = &vring->ctx[vring->swtail];
Vladimir Kondratievc2366582014-03-17 15:34:08 +02001173 /**
1174 * For the fragmented skb, HW will set DU bit only for the
1175 * last fragment. look for it
1176 */
1177 int lf = (vring->swtail + ctx->nr_frags) % vring->size;
1178 /* TODO: check we are not past head */
Vladimir Kondratiev4de41be2013-04-18 14:33:52 +03001179
Vladimir Kondratievc2366582014-03-17 15:34:08 +02001180 _d = &vring->va[lf].tx;
1181 if (!(_d->dma.status & TX_DMA_STATUS_DU))
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001182 break;
1183
Vladimir Kondratievc2366582014-03-17 15:34:08 +02001184 new_swtail = (lf + 1) % vring->size;
1185 while (vring->swtail != new_swtail) {
1186 struct vring_tx_desc dd, *d = &dd;
Vladimir Kondratievc2366582014-03-17 15:34:08 +02001187 u16 dmalen;
Vladimir Kondratiev76dfa4b2014-07-14 09:49:39 +03001188 struct sk_buff *skb;
1189
1190 ctx = &vring->ctx[vring->swtail];
1191 skb = ctx->skb;
Vladimir Kondratievc2366582014-03-17 15:34:08 +02001192 _d = &vring->va[vring->swtail].tx;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001193
Vladimir Kondratievc2366582014-03-17 15:34:08 +02001194 *d = *_d;
Vladimir Kondratievf88f1132013-07-11 18:03:40 +03001195
Vladimir Kondratievc2366582014-03-17 15:34:08 +02001196 dmalen = le16_to_cpu(d->dma.length);
1197 trace_wil6210_tx_done(ringid, vring->swtail, dmalen,
1198 d->dma.error);
1199 wil_dbg_txrx(wil,
1200 "Tx[%3d] : %d bytes, status 0x%02x err 0x%02x\n",
1201 vring->swtail, dmalen, d->dma.status,
1202 d->dma.error);
1203 wil_hex_dump_txrx("TxC ", DUMP_PREFIX_NONE, 32, 4,
1204 (const void *)d, sizeof(*d), false);
1205
Vladimir Kondratiev2232abd2014-03-17 15:34:09 +02001206 wil_txdesc_unmap(dev, d, ctx);
Vladimir Kondratievc2366582014-03-17 15:34:08 +02001207
1208 if (skb) {
1209 if (d->dma.error == 0) {
1210 ndev->stats.tx_packets++;
1211 stats->tx_packets++;
1212 ndev->stats.tx_bytes += skb->len;
1213 stats->tx_bytes += skb->len;
1214 } else {
1215 ndev->stats.tx_errors++;
1216 stats->tx_errors++;
1217 }
Vladimir Kondratiev713c8a22015-01-25 10:52:49 +02001218 wil_consume_skb(skb, d->dma.error == 0);
Vladimir Kondratiev795ce732013-01-28 18:31:00 +02001219 }
Vladimir Kondratievc2366582014-03-17 15:34:08 +02001220 memset(ctx, 0, sizeof(*ctx));
1221 /* There is no need to touch HW descriptor:
1222 * - ststus bit TX_DMA_STATUS_DU is set by design,
1223 * so hardware will not try to process this desc.,
1224 * - rest of descriptor will be initialized on Tx.
1225 */
1226 vring->swtail = wil_vring_next_tail(vring);
1227 done++;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001228 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001229 }
Vladimir Kondratiev67c3e1b2014-06-16 19:37:04 +03001230
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +03001231 if (wil_vring_is_empty(vring)) { /* performance monitoring */
Vladimir Kondratiev67c3e1b2014-06-16 19:37:04 +03001232 wil_dbg_txrx(wil, "Ring[%2d] empty\n", ringid);
Vladimir Kondratiev7c0acf82014-06-16 19:37:05 +03001233 txdata->last_idle = get_cycles();
1234 }
Vladimir Kondratiev67c3e1b2014-06-16 19:37:04 +03001235
Vladimir Kondratiev55f8f682014-06-16 19:37:23 +03001236 if (wil_vring_avail_tx(vring) > wil_vring_wmark_high(vring)) {
1237 wil_dbg_txrx(wil, "netif_tx_wake : ring not full\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001238 netif_tx_wake_all_queues(wil_to_ndev(wil));
Vladimir Kondratiev55f8f682014-06-16 19:37:23 +03001239 }
Vladimir Kondratieve0287c42013-05-12 14:43:36 +03001240
1241 return done;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001242}