txrx.c 30 KB

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