txrx.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285
  1. /*
  2. * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
  3. * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <linux/etherdevice.h>
  18. #include <net/ieee80211_radiotap.h>
  19. #include <linux/if_arp.h>
  20. #include <linux/moduleparam.h>
  21. #include <linux/ip.h>
  22. #include <linux/ipv6.h>
  23. #include <net/ipv6.h>
  24. #include <linux/prefetch.h>
  25. #include "wil6210.h"
  26. #include "wmi.h"
  27. #include "txrx.h"
  28. #include "trace.h"
  29. #include "txrx_edma.h"
  30. static bool rtap_include_phy_info;
  31. module_param(rtap_include_phy_info, bool, 0444);
  32. MODULE_PARM_DESC(rtap_include_phy_info,
  33. " Include PHY info in the radiotap header, default - no");
  34. bool rx_align_2;
  35. module_param(rx_align_2, bool, 0444);
  36. MODULE_PARM_DESC(rx_align_2, " align Rx buffers on 4*n+2, default - no");
  37. bool rx_large_buf;
  38. module_param(rx_large_buf, bool, 0444);
  39. MODULE_PARM_DESC(rx_large_buf, " allocate 8KB RX buffers, default - no");
  40. static inline uint wil_rx_snaplen(void)
  41. {
  42. return rx_align_2 ? 6 : 0;
  43. }
  44. /* wil_ring_wmark_low - low watermark for available descriptor space */
  45. static inline int wil_ring_wmark_low(struct wil_ring *ring)
  46. {
  47. return ring->size / 8;
  48. }
  49. /* wil_ring_wmark_high - high watermark for available descriptor space */
  50. static inline int wil_ring_wmark_high(struct wil_ring *ring)
  51. {
  52. return ring->size / 4;
  53. }
  54. /* returns true if num avail descriptors is lower than wmark_low */
  55. static inline int wil_ring_avail_low(struct wil_ring *ring)
  56. {
  57. return wil_ring_avail_tx(ring) < wil_ring_wmark_low(ring);
  58. }
  59. /* returns true if num avail descriptors is higher than wmark_high */
  60. static inline int wil_ring_avail_high(struct wil_ring *ring)
  61. {
  62. return wil_ring_avail_tx(ring) > wil_ring_wmark_high(ring);
  63. }
  64. /* returns true when all tx vrings are empty */
  65. bool wil_is_tx_idle(struct wil6210_priv *wil)
  66. {
  67. int i;
  68. unsigned long data_comp_to;
  69. for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
  70. struct wil_ring *vring = &wil->ring_tx[i];
  71. int vring_index = vring - wil->ring_tx;
  72. struct wil_ring_tx_data *txdata =
  73. &wil->ring_tx_data[vring_index];
  74. spin_lock(&txdata->lock);
  75. if (!vring->va || !txdata->enabled) {
  76. spin_unlock(&txdata->lock);
  77. continue;
  78. }
  79. data_comp_to = jiffies + msecs_to_jiffies(
  80. WIL_DATA_COMPLETION_TO_MS);
  81. if (test_bit(wil_status_napi_en, wil->status)) {
  82. while (!wil_ring_is_empty(vring)) {
  83. if (time_after(jiffies, data_comp_to)) {
  84. wil_dbg_pm(wil,
  85. "TO waiting for idle tx\n");
  86. spin_unlock(&txdata->lock);
  87. return false;
  88. }
  89. wil_dbg_ratelimited(wil,
  90. "tx vring is not empty -> NAPI\n");
  91. spin_unlock(&txdata->lock);
  92. napi_synchronize(&wil->napi_tx);
  93. msleep(20);
  94. spin_lock(&txdata->lock);
  95. if (!vring->va || !txdata->enabled)
  96. break;
  97. }
  98. }
  99. spin_unlock(&txdata->lock);
  100. }
  101. return true;
  102. }
  103. static int wil_vring_alloc(struct wil6210_priv *wil, struct wil_ring *vring)
  104. {
  105. struct device *dev = wil_to_dev(wil);
  106. size_t sz = vring->size * sizeof(vring->va[0]);
  107. uint i;
  108. wil_dbg_misc(wil, "vring_alloc:\n");
  109. BUILD_BUG_ON(sizeof(vring->va[0]) != 32);
  110. vring->swhead = 0;
  111. vring->swtail = 0;
  112. vring->ctx = kcalloc(vring->size, sizeof(vring->ctx[0]), GFP_KERNEL);
  113. if (!vring->ctx) {
  114. vring->va = NULL;
  115. return -ENOMEM;
  116. }
  117. /* vring->va should be aligned on its size rounded up to power of 2
  118. * This is granted by the dma_alloc_coherent.
  119. *
  120. * HW has limitation that all vrings addresses must share the same
  121. * upper 16 msb bits part of 48 bits address. To workaround that,
  122. * if we are using more than 32 bit addresses switch to 32 bit
  123. * allocation before allocating vring memory.
  124. *
  125. * There's no check for the return value of dma_set_mask_and_coherent,
  126. * since we assume if we were able to set the mask during
  127. * initialization in this system it will not fail if we set it again
  128. */
  129. if (wil->dma_addr_size > 32)
  130. dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
  131. vring->va = dma_alloc_coherent(dev, sz, &vring->pa, GFP_KERNEL);
  132. if (!vring->va) {
  133. kfree(vring->ctx);
  134. vring->ctx = NULL;
  135. return -ENOMEM;
  136. }
  137. if (wil->dma_addr_size > 32)
  138. dma_set_mask_and_coherent(dev,
  139. DMA_BIT_MASK(wil->dma_addr_size));
  140. /* initially, all descriptors are SW owned
  141. * For Tx and Rx, ownership bit is at the same location, thus
  142. * we can use any
  143. */
  144. for (i = 0; i < vring->size; i++) {
  145. volatile struct vring_tx_desc *_d =
  146. &vring->va[i].tx.legacy;
  147. _d->dma.status = TX_DMA_STATUS_DU;
  148. }
  149. wil_dbg_misc(wil, "vring[%d] 0x%p:%pad 0x%p\n", vring->size,
  150. vring->va, &vring->pa, vring->ctx);
  151. return 0;
  152. }
  153. static void wil_txdesc_unmap(struct device *dev, union wil_tx_desc *desc,
  154. struct wil_ctx *ctx)
  155. {
  156. struct vring_tx_desc *d = &desc->legacy;
  157. dma_addr_t pa = wil_desc_addr(&d->dma.addr);
  158. u16 dmalen = le16_to_cpu(d->dma.length);
  159. switch (ctx->mapped_as) {
  160. case wil_mapped_as_single:
  161. dma_unmap_single(dev, pa, dmalen, DMA_TO_DEVICE);
  162. break;
  163. case wil_mapped_as_page:
  164. dma_unmap_page(dev, pa, dmalen, DMA_TO_DEVICE);
  165. break;
  166. default:
  167. break;
  168. }
  169. }
  170. static void wil_vring_free(struct wil6210_priv *wil, struct wil_ring *vring)
  171. {
  172. struct device *dev = wil_to_dev(wil);
  173. size_t sz = vring->size * sizeof(vring->va[0]);
  174. lockdep_assert_held(&wil->mutex);
  175. if (!vring->is_rx) {
  176. int vring_index = vring - wil->ring_tx;
  177. wil_dbg_misc(wil, "free Tx vring %d [%d] 0x%p:%pad 0x%p\n",
  178. vring_index, vring->size, vring->va,
  179. &vring->pa, vring->ctx);
  180. } else {
  181. wil_dbg_misc(wil, "free Rx vring [%d] 0x%p:%pad 0x%p\n",
  182. vring->size, vring->va,
  183. &vring->pa, vring->ctx);
  184. }
  185. while (!wil_ring_is_empty(vring)) {
  186. dma_addr_t pa;
  187. u16 dmalen;
  188. struct wil_ctx *ctx;
  189. if (!vring->is_rx) {
  190. struct vring_tx_desc dd, *d = &dd;
  191. volatile struct vring_tx_desc *_d =
  192. &vring->va[vring->swtail].tx.legacy;
  193. ctx = &vring->ctx[vring->swtail];
  194. if (!ctx) {
  195. wil_dbg_txrx(wil,
  196. "ctx(%d) was already completed\n",
  197. vring->swtail);
  198. vring->swtail = wil_ring_next_tail(vring);
  199. continue;
  200. }
  201. *d = *_d;
  202. wil_txdesc_unmap(dev, (union wil_tx_desc *)d, ctx);
  203. if (ctx->skb)
  204. dev_kfree_skb_any(ctx->skb);
  205. vring->swtail = wil_ring_next_tail(vring);
  206. } else { /* rx */
  207. struct vring_rx_desc dd, *d = &dd;
  208. volatile struct vring_rx_desc *_d =
  209. &vring->va[vring->swhead].rx.legacy;
  210. ctx = &vring->ctx[vring->swhead];
  211. *d = *_d;
  212. pa = wil_desc_addr(&d->dma.addr);
  213. dmalen = le16_to_cpu(d->dma.length);
  214. dma_unmap_single(dev, pa, dmalen, DMA_FROM_DEVICE);
  215. kfree_skb(ctx->skb);
  216. wil_ring_advance_head(vring, 1);
  217. }
  218. }
  219. dma_free_coherent(dev, sz, (void *)vring->va, vring->pa);
  220. kfree(vring->ctx);
  221. vring->pa = 0;
  222. vring->va = NULL;
  223. vring->ctx = NULL;
  224. }
  225. /**
  226. * Allocate one skb for Rx VRING
  227. *
  228. * Safe to call from IRQ
  229. */
  230. static int wil_vring_alloc_skb(struct wil6210_priv *wil, struct wil_ring *vring,
  231. u32 i, int headroom)
  232. {
  233. struct device *dev = wil_to_dev(wil);
  234. unsigned int sz = wil->rx_buf_len + ETH_HLEN + wil_rx_snaplen();
  235. struct vring_rx_desc dd, *d = &dd;
  236. volatile struct vring_rx_desc *_d = &vring->va[i].rx.legacy;
  237. dma_addr_t pa;
  238. struct sk_buff *skb = dev_alloc_skb(sz + headroom);
  239. if (unlikely(!skb))
  240. return -ENOMEM;
  241. skb_reserve(skb, headroom);
  242. skb_put(skb, sz);
  243. /**
  244. * Make sure that the network stack calculates checksum for packets
  245. * which failed the HW checksum calculation
  246. */
  247. skb->ip_summed = CHECKSUM_NONE;
  248. pa = dma_map_single(dev, skb->data, skb->len, DMA_FROM_DEVICE);
  249. if (unlikely(dma_mapping_error(dev, pa))) {
  250. kfree_skb(skb);
  251. return -ENOMEM;
  252. }
  253. d->dma.d0 = RX_DMA_D0_CMD_DMA_RT | RX_DMA_D0_CMD_DMA_IT;
  254. wil_desc_addr_set(&d->dma.addr, pa);
  255. /* ip_length don't care */
  256. /* b11 don't care */
  257. /* error don't care */
  258. d->dma.status = 0; /* BIT(0) should be 0 for HW_OWNED */
  259. d->dma.length = cpu_to_le16(sz);
  260. *_d = *d;
  261. vring->ctx[i].skb = skb;
  262. return 0;
  263. }
  264. /**
  265. * Adds radiotap header
  266. *
  267. * Any error indicated as "Bad FCS"
  268. *
  269. * Vendor data for 04:ce:14-1 (Wilocity-1) consists of:
  270. * - Rx descriptor: 32 bytes
  271. * - Phy info
  272. */
  273. static void wil_rx_add_radiotap_header(struct wil6210_priv *wil,
  274. struct sk_buff *skb)
  275. {
  276. struct wil6210_rtap {
  277. struct ieee80211_radiotap_header rthdr;
  278. /* fields should be in the order of bits in rthdr.it_present */
  279. /* flags */
  280. u8 flags;
  281. /* channel */
  282. __le16 chnl_freq __aligned(2);
  283. __le16 chnl_flags;
  284. /* MCS */
  285. u8 mcs_present;
  286. u8 mcs_flags;
  287. u8 mcs_index;
  288. } __packed;
  289. struct wil6210_rtap_vendor {
  290. struct wil6210_rtap rtap;
  291. /* vendor */
  292. u8 vendor_oui[3] __aligned(2);
  293. u8 vendor_ns;
  294. __le16 vendor_skip;
  295. u8 vendor_data[0];
  296. } __packed;
  297. struct vring_rx_desc *d = wil_skb_rxdesc(skb);
  298. struct wil6210_rtap_vendor *rtap_vendor;
  299. int rtap_len = sizeof(struct wil6210_rtap);
  300. int phy_length = 0; /* phy info header size, bytes */
  301. static char phy_data[128];
  302. struct ieee80211_channel *ch = wil->monitor_chandef.chan;
  303. if (rtap_include_phy_info) {
  304. rtap_len = sizeof(*rtap_vendor) + sizeof(*d);
  305. /* calculate additional length */
  306. if (d->dma.status & RX_DMA_STATUS_PHY_INFO) {
  307. /**
  308. * PHY info starts from 8-byte boundary
  309. * there are 8-byte lines, last line may be partially
  310. * written (HW bug), thus FW configures for last line
  311. * to be excessive. Driver skips this last line.
  312. */
  313. int len = min_t(int, 8 + sizeof(phy_data),
  314. wil_rxdesc_phy_length(d));
  315. if (len > 8) {
  316. void *p = skb_tail_pointer(skb);
  317. void *pa = PTR_ALIGN(p, 8);
  318. if (skb_tailroom(skb) >= len + (pa - p)) {
  319. phy_length = len - 8;
  320. memcpy(phy_data, pa, phy_length);
  321. }
  322. }
  323. }
  324. rtap_len += phy_length;
  325. }
  326. if (skb_headroom(skb) < rtap_len &&
  327. pskb_expand_head(skb, rtap_len, 0, GFP_ATOMIC)) {
  328. wil_err(wil, "Unable to expand headroom to %d\n", rtap_len);
  329. return;
  330. }
  331. rtap_vendor = skb_push(skb, rtap_len);
  332. memset(rtap_vendor, 0, rtap_len);
  333. rtap_vendor->rtap.rthdr.it_version = PKTHDR_RADIOTAP_VERSION;
  334. rtap_vendor->rtap.rthdr.it_len = cpu_to_le16(rtap_len);
  335. rtap_vendor->rtap.rthdr.it_present = cpu_to_le32(
  336. (1 << IEEE80211_RADIOTAP_FLAGS) |
  337. (1 << IEEE80211_RADIOTAP_CHANNEL) |
  338. (1 << IEEE80211_RADIOTAP_MCS));
  339. if (d->dma.status & RX_DMA_STATUS_ERROR)
  340. rtap_vendor->rtap.flags |= IEEE80211_RADIOTAP_F_BADFCS;
  341. rtap_vendor->rtap.chnl_freq = cpu_to_le16(ch ? ch->center_freq : 58320);
  342. rtap_vendor->rtap.chnl_flags = cpu_to_le16(0);
  343. rtap_vendor->rtap.mcs_present = IEEE80211_RADIOTAP_MCS_HAVE_MCS;
  344. rtap_vendor->rtap.mcs_flags = 0;
  345. rtap_vendor->rtap.mcs_index = wil_rxdesc_mcs(d);
  346. if (rtap_include_phy_info) {
  347. rtap_vendor->rtap.rthdr.it_present |= cpu_to_le32(1 <<
  348. IEEE80211_RADIOTAP_VENDOR_NAMESPACE);
  349. /* OUI for Wilocity 04:ce:14 */
  350. rtap_vendor->vendor_oui[0] = 0x04;
  351. rtap_vendor->vendor_oui[1] = 0xce;
  352. rtap_vendor->vendor_oui[2] = 0x14;
  353. rtap_vendor->vendor_ns = 1;
  354. /* Rx descriptor + PHY data */
  355. rtap_vendor->vendor_skip = cpu_to_le16(sizeof(*d) +
  356. phy_length);
  357. memcpy(rtap_vendor->vendor_data, (void *)d, sizeof(*d));
  358. memcpy(rtap_vendor->vendor_data + sizeof(*d), phy_data,
  359. phy_length);
  360. }
  361. }
  362. static bool wil_is_rx_idle(struct wil6210_priv *wil)
  363. {
  364. struct vring_rx_desc *_d;
  365. struct wil_ring *ring = &wil->ring_rx;
  366. _d = (struct vring_rx_desc *)&ring->va[ring->swhead].rx.legacy;
  367. if (_d->dma.status & RX_DMA_STATUS_DU)
  368. return false;
  369. return true;
  370. }
  371. /**
  372. * reap 1 frame from @swhead
  373. *
  374. * Rx descriptor copied to skb->cb
  375. *
  376. * Safe to call from IRQ
  377. */
  378. static struct sk_buff *wil_vring_reap_rx(struct wil6210_priv *wil,
  379. struct wil_ring *vring)
  380. {
  381. struct device *dev = wil_to_dev(wil);
  382. struct wil6210_vif *vif;
  383. struct net_device *ndev;
  384. volatile struct vring_rx_desc *_d;
  385. struct vring_rx_desc *d;
  386. struct sk_buff *skb;
  387. dma_addr_t pa;
  388. unsigned int snaplen = wil_rx_snaplen();
  389. unsigned int sz = wil->rx_buf_len + ETH_HLEN + snaplen;
  390. u16 dmalen;
  391. u8 ftype;
  392. int cid, mid;
  393. int i;
  394. struct wil_net_stats *stats;
  395. BUILD_BUG_ON(sizeof(struct vring_rx_desc) > sizeof(skb->cb));
  396. again:
  397. if (unlikely(wil_ring_is_empty(vring)))
  398. return NULL;
  399. i = (int)vring->swhead;
  400. _d = &vring->va[i].rx.legacy;
  401. if (unlikely(!(_d->dma.status & RX_DMA_STATUS_DU))) {
  402. /* it is not error, we just reached end of Rx done area */
  403. return NULL;
  404. }
  405. skb = vring->ctx[i].skb;
  406. vring->ctx[i].skb = NULL;
  407. wil_ring_advance_head(vring, 1);
  408. if (!skb) {
  409. wil_err(wil, "No Rx skb at [%d]\n", i);
  410. goto again;
  411. }
  412. d = wil_skb_rxdesc(skb);
  413. *d = *_d;
  414. pa = wil_desc_addr(&d->dma.addr);
  415. dma_unmap_single(dev, pa, sz, DMA_FROM_DEVICE);
  416. dmalen = le16_to_cpu(d->dma.length);
  417. trace_wil6210_rx(i, d);
  418. wil_dbg_txrx(wil, "Rx[%3d] : %d bytes\n", i, dmalen);
  419. wil_hex_dump_txrx("RxD ", DUMP_PREFIX_NONE, 32, 4,
  420. (const void *)d, sizeof(*d), false);
  421. cid = wil_rxdesc_cid(d);
  422. mid = wil_rxdesc_mid(d);
  423. vif = wil->vifs[mid];
  424. if (unlikely(!vif)) {
  425. wil_dbg_txrx(wil, "skipped RX descriptor with invalid mid %d",
  426. mid);
  427. kfree_skb(skb);
  428. goto again;
  429. }
  430. ndev = vif_to_ndev(vif);
  431. stats = &wil->sta[cid].stats;
  432. if (unlikely(dmalen > sz)) {
  433. wil_err(wil, "Rx size too large: %d bytes!\n", dmalen);
  434. stats->rx_large_frame++;
  435. kfree_skb(skb);
  436. goto again;
  437. }
  438. skb_trim(skb, dmalen);
  439. prefetch(skb->data);
  440. wil_hex_dump_txrx("Rx ", DUMP_PREFIX_OFFSET, 16, 1,
  441. skb->data, skb_headlen(skb), false);
  442. stats->last_mcs_rx = wil_rxdesc_mcs(d);
  443. if (stats->last_mcs_rx < ARRAY_SIZE(stats->rx_per_mcs))
  444. stats->rx_per_mcs[stats->last_mcs_rx]++;
  445. /* use radiotap header only if required */
  446. if (ndev->type == ARPHRD_IEEE80211_RADIOTAP)
  447. wil_rx_add_radiotap_header(wil, skb);
  448. /* no extra checks if in sniffer mode */
  449. if (ndev->type != ARPHRD_ETHER)
  450. return skb;
  451. /* Non-data frames may be delivered through Rx DMA channel (ex: BAR)
  452. * Driver should recognize it by frame type, that is found
  453. * in Rx descriptor. If type is not data, it is 802.11 frame as is
  454. */
  455. ftype = wil_rxdesc_ftype(d) << 2;
  456. if (unlikely(ftype != IEEE80211_FTYPE_DATA)) {
  457. u8 fc1 = wil_rxdesc_fc1(d);
  458. int tid = wil_rxdesc_tid(d);
  459. u16 seq = wil_rxdesc_seq(d);
  460. wil_dbg_txrx(wil,
  461. "Non-data frame FC[7:0] 0x%02x MID %d CID %d TID %d Seq 0x%03x\n",
  462. fc1, mid, cid, tid, seq);
  463. stats->rx_non_data_frame++;
  464. if (wil_is_back_req(fc1)) {
  465. wil_dbg_txrx(wil,
  466. "BAR: MID %d CID %d TID %d Seq 0x%03x\n",
  467. mid, cid, tid, seq);
  468. wil_rx_bar(wil, vif, cid, tid, seq);
  469. } else {
  470. /* print again all info. One can enable only this
  471. * without overhead for printing every Rx frame
  472. */
  473. wil_dbg_txrx(wil,
  474. "Unhandled non-data frame FC[7:0] 0x%02x MID %d CID %d TID %d Seq 0x%03x\n",
  475. fc1, mid, cid, tid, seq);
  476. wil_hex_dump_txrx("RxD ", DUMP_PREFIX_NONE, 32, 4,
  477. (const void *)d, sizeof(*d), false);
  478. wil_hex_dump_txrx("Rx ", DUMP_PREFIX_OFFSET, 16, 1,
  479. skb->data, skb_headlen(skb), false);
  480. }
  481. kfree_skb(skb);
  482. goto again;
  483. }
  484. if (unlikely(skb->len < ETH_HLEN + snaplen)) {
  485. wil_err(wil, "Short frame, len = %d\n", skb->len);
  486. stats->rx_short_frame++;
  487. kfree_skb(skb);
  488. goto again;
  489. }
  490. /* L4 IDENT is on when HW calculated checksum, check status
  491. * and in case of error drop the packet
  492. * higher stack layers will handle retransmission (if required)
  493. */
  494. if (likely(d->dma.status & RX_DMA_STATUS_L4I)) {
  495. /* L4 protocol identified, csum calculated */
  496. if (likely((d->dma.error & RX_DMA_ERROR_L4_ERR) == 0))
  497. skb->ip_summed = CHECKSUM_UNNECESSARY;
  498. /* If HW reports bad checksum, let IP stack re-check it
  499. * For example, HW don't understand Microsoft IP stack that
  500. * mis-calculates TCP checksum - if it should be 0x0,
  501. * it writes 0xffff in violation of RFC 1624
  502. */
  503. else
  504. stats->rx_csum_err++;
  505. }
  506. if (snaplen) {
  507. /* Packet layout
  508. * +-------+-------+---------+------------+------+
  509. * | SA(6) | DA(6) | SNAP(6) | ETHTYPE(2) | DATA |
  510. * +-------+-------+---------+------------+------+
  511. * Need to remove SNAP, shifting SA and DA forward
  512. */
  513. memmove(skb->data + snaplen, skb->data, 2 * ETH_ALEN);
  514. skb_pull(skb, snaplen);
  515. }
  516. return skb;
  517. }
  518. /**
  519. * allocate and fill up to @count buffers in rx ring
  520. * buffers posted at @swtail
  521. * Note: we have a single RX queue for servicing all VIFs, but we
  522. * allocate skbs with headroom according to main interface only. This
  523. * means it will not work with monitor interface together with other VIFs.
  524. * Currently we only support monitor interface on its own without other VIFs,
  525. * and we will need to fix this code once we add support.
  526. */
  527. static int wil_rx_refill(struct wil6210_priv *wil, int count)
  528. {
  529. struct net_device *ndev = wil->main_ndev;
  530. struct wil_ring *v = &wil->ring_rx;
  531. u32 next_tail;
  532. int rc = 0;
  533. int headroom = ndev->type == ARPHRD_IEEE80211_RADIOTAP ?
  534. WIL6210_RTAP_SIZE : 0;
  535. for (; next_tail = wil_ring_next_tail(v),
  536. (next_tail != v->swhead) && (count-- > 0);
  537. v->swtail = next_tail) {
  538. rc = wil_vring_alloc_skb(wil, v, v->swtail, headroom);
  539. if (unlikely(rc)) {
  540. wil_err_ratelimited(wil, "Error %d in rx refill[%d]\n",
  541. rc, v->swtail);
  542. break;
  543. }
  544. }
  545. /* make sure all writes to descriptors (shared memory) are done before
  546. * committing them to HW
  547. */
  548. wmb();
  549. wil_w(wil, v->hwtail, v->swtail);
  550. return rc;
  551. }
  552. /**
  553. * reverse_memcmp - Compare two areas of memory, in reverse order
  554. * @cs: One area of memory
  555. * @ct: Another area of memory
  556. * @count: The size of the area.
  557. *
  558. * Cut'n'paste from original memcmp (see lib/string.c)
  559. * with minimal modifications
  560. */
  561. int reverse_memcmp(const void *cs, const void *ct, size_t count)
  562. {
  563. const unsigned char *su1, *su2;
  564. int res = 0;
  565. for (su1 = cs + count - 1, su2 = ct + count - 1; count > 0;
  566. --su1, --su2, count--) {
  567. res = *su1 - *su2;
  568. if (res)
  569. break;
  570. }
  571. return res;
  572. }
  573. static int wil_rx_crypto_check(struct wil6210_priv *wil, struct sk_buff *skb)
  574. {
  575. struct vring_rx_desc *d = wil_skb_rxdesc(skb);
  576. int cid = wil_rxdesc_cid(d);
  577. int tid = wil_rxdesc_tid(d);
  578. int key_id = wil_rxdesc_key_id(d);
  579. int mc = wil_rxdesc_mcast(d);
  580. struct wil_sta_info *s = &wil->sta[cid];
  581. struct wil_tid_crypto_rx *c = mc ? &s->group_crypto_rx :
  582. &s->tid_crypto_rx[tid];
  583. struct wil_tid_crypto_rx_single *cc = &c->key_id[key_id];
  584. const u8 *pn = (u8 *)&d->mac.pn_15_0;
  585. if (!cc->key_set) {
  586. wil_err_ratelimited(wil,
  587. "Key missing. CID %d TID %d MCast %d KEY_ID %d\n",
  588. cid, tid, mc, key_id);
  589. return -EINVAL;
  590. }
  591. if (reverse_memcmp(pn, cc->pn, IEEE80211_GCMP_PN_LEN) <= 0) {
  592. wil_err_ratelimited(wil,
  593. "Replay attack. CID %d TID %d MCast %d KEY_ID %d PN %6phN last %6phN\n",
  594. cid, tid, mc, key_id, pn, cc->pn);
  595. return -EINVAL;
  596. }
  597. memcpy(cc->pn, pn, IEEE80211_GCMP_PN_LEN);
  598. return 0;
  599. }
  600. static int wil_rx_error_check(struct wil6210_priv *wil, struct sk_buff *skb,
  601. struct wil_net_stats *stats)
  602. {
  603. struct vring_rx_desc *d = wil_skb_rxdesc(skb);
  604. if ((d->dma.status & RX_DMA_STATUS_ERROR) &&
  605. (d->dma.error & RX_DMA_ERROR_MIC)) {
  606. stats->rx_mic_error++;
  607. wil_dbg_txrx(wil, "MIC error, dropping packet\n");
  608. return -EFAULT;
  609. }
  610. return 0;
  611. }
  612. static void wil_get_netif_rx_params(struct sk_buff *skb, int *cid,
  613. int *security)
  614. {
  615. struct vring_rx_desc *d = wil_skb_rxdesc(skb);
  616. *cid = wil_rxdesc_cid(d); /* always 0..7, no need to check */
  617. *security = wil_rxdesc_security(d);
  618. }
  619. /*
  620. * Pass Rx packet to the netif. Update statistics.
  621. * Called in softirq context (NAPI poll).
  622. */
  623. void wil_netif_rx_any(struct sk_buff *skb, struct net_device *ndev)
  624. {
  625. gro_result_t rc = GRO_NORMAL;
  626. struct wil6210_vif *vif = ndev_to_vif(ndev);
  627. struct wil6210_priv *wil = ndev_to_wil(ndev);
  628. struct wireless_dev *wdev = vif_to_wdev(vif);
  629. unsigned int len = skb->len;
  630. int cid;
  631. int security;
  632. struct ethhdr *eth = (void *)skb->data;
  633. /* here looking for DA, not A1, thus Rxdesc's 'mcast' indication
  634. * is not suitable, need to look at data
  635. */
  636. int mcast = is_multicast_ether_addr(eth->h_dest);
  637. struct wil_net_stats *stats;
  638. struct sk_buff *xmit_skb = NULL;
  639. static const char * const gro_res_str[] = {
  640. [GRO_MERGED] = "GRO_MERGED",
  641. [GRO_MERGED_FREE] = "GRO_MERGED_FREE",
  642. [GRO_HELD] = "GRO_HELD",
  643. [GRO_NORMAL] = "GRO_NORMAL",
  644. [GRO_DROP] = "GRO_DROP",
  645. };
  646. wil->txrx_ops.get_netif_rx_params(skb, &cid, &security);
  647. stats = &wil->sta[cid].stats;
  648. if (ndev->features & NETIF_F_RXHASH)
  649. /* fake L4 to ensure it won't be re-calculated later
  650. * set hash to any non-zero value to activate rps
  651. * mechanism, core will be chosen according
  652. * to user-level rps configuration.
  653. */
  654. skb_set_hash(skb, 1, PKT_HASH_TYPE_L4);
  655. skb_orphan(skb);
  656. if (security && (wil->txrx_ops.rx_crypto_check(wil, skb) != 0)) {
  657. rc = GRO_DROP;
  658. dev_kfree_skb(skb);
  659. stats->rx_replay++;
  660. goto stats;
  661. }
  662. /* check errors reported by HW and update statistics */
  663. if (unlikely(wil->txrx_ops.rx_error_check(wil, skb, stats))) {
  664. dev_kfree_skb(skb);
  665. return;
  666. }
  667. if (wdev->iftype == NL80211_IFTYPE_AP && !vif->ap_isolate) {
  668. if (mcast) {
  669. /* send multicast frames both to higher layers in
  670. * local net stack and back to the wireless medium
  671. */
  672. xmit_skb = skb_copy(skb, GFP_ATOMIC);
  673. } else {
  674. int xmit_cid = wil_find_cid(wil, vif->mid,
  675. eth->h_dest);
  676. if (xmit_cid >= 0) {
  677. /* The destination station is associated to
  678. * this AP (in this VLAN), so send the frame
  679. * directly to it and do not pass it to local
  680. * net stack.
  681. */
  682. xmit_skb = skb;
  683. skb = NULL;
  684. }
  685. }
  686. }
  687. if (xmit_skb) {
  688. /* Send to wireless media and increase priority by 256 to
  689. * keep the received priority instead of reclassifying
  690. * the frame (see cfg80211_classify8021d).
  691. */
  692. xmit_skb->dev = ndev;
  693. xmit_skb->priority += 256;
  694. xmit_skb->protocol = htons(ETH_P_802_3);
  695. skb_reset_network_header(xmit_skb);
  696. skb_reset_mac_header(xmit_skb);
  697. wil_dbg_txrx(wil, "Rx -> Tx %d bytes\n", len);
  698. dev_queue_xmit(xmit_skb);
  699. }
  700. if (skb) { /* deliver to local stack */
  701. skb->protocol = eth_type_trans(skb, ndev);
  702. skb->dev = ndev;
  703. rc = napi_gro_receive(&wil->napi_rx, skb);
  704. wil_dbg_txrx(wil, "Rx complete %d bytes => %s\n",
  705. len, gro_res_str[rc]);
  706. }
  707. stats:
  708. /* statistics. rc set to GRO_NORMAL for AP bridging */
  709. if (unlikely(rc == GRO_DROP)) {
  710. ndev->stats.rx_dropped++;
  711. stats->rx_dropped++;
  712. wil_dbg_txrx(wil, "Rx drop %d bytes\n", len);
  713. } else {
  714. ndev->stats.rx_packets++;
  715. stats->rx_packets++;
  716. ndev->stats.rx_bytes += len;
  717. stats->rx_bytes += len;
  718. if (mcast)
  719. ndev->stats.multicast++;
  720. }
  721. }
  722. /**
  723. * Proceed all completed skb's from Rx VRING
  724. *
  725. * Safe to call from NAPI poll, i.e. softirq with interrupts enabled
  726. */
  727. void wil_rx_handle(struct wil6210_priv *wil, int *quota)
  728. {
  729. struct net_device *ndev = wil->main_ndev;
  730. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  731. struct wil_ring *v = &wil->ring_rx;
  732. struct sk_buff *skb;
  733. if (unlikely(!v->va)) {
  734. wil_err(wil, "Rx IRQ while Rx not yet initialized\n");
  735. return;
  736. }
  737. wil_dbg_txrx(wil, "rx_handle\n");
  738. while ((*quota > 0) && (NULL != (skb = wil_vring_reap_rx(wil, v)))) {
  739. (*quota)--;
  740. /* monitor is currently supported on main interface only */
  741. if (wdev->iftype == NL80211_IFTYPE_MONITOR) {
  742. skb->dev = ndev;
  743. skb_reset_mac_header(skb);
  744. skb->ip_summed = CHECKSUM_UNNECESSARY;
  745. skb->pkt_type = PACKET_OTHERHOST;
  746. skb->protocol = htons(ETH_P_802_2);
  747. wil_netif_rx_any(skb, ndev);
  748. } else {
  749. wil_rx_reorder(wil, skb);
  750. }
  751. }
  752. wil_rx_refill(wil, v->size);
  753. }
  754. static void wil_rx_buf_len_init(struct wil6210_priv *wil)
  755. {
  756. wil->rx_buf_len = rx_large_buf ?
  757. WIL_MAX_ETH_MTU : TXRX_BUF_LEN_DEFAULT - WIL_MAX_MPDU_OVERHEAD;
  758. if (mtu_max > wil->rx_buf_len) {
  759. /* do not allow RX buffers to be smaller than mtu_max, for
  760. * backward compatibility (mtu_max parameter was also used
  761. * to support receiving large packets)
  762. */
  763. wil_info(wil, "Override RX buffer to mtu_max(%d)\n", mtu_max);
  764. wil->rx_buf_len = mtu_max;
  765. }
  766. }
  767. static int wil_rx_init(struct wil6210_priv *wil, u16 size)
  768. {
  769. struct wil_ring *vring = &wil->ring_rx;
  770. int rc;
  771. wil_dbg_misc(wil, "rx_init\n");
  772. if (vring->va) {
  773. wil_err(wil, "Rx ring already allocated\n");
  774. return -EINVAL;
  775. }
  776. wil_rx_buf_len_init(wil);
  777. vring->size = size;
  778. vring->is_rx = true;
  779. rc = wil_vring_alloc(wil, vring);
  780. if (rc)
  781. return rc;
  782. rc = wmi_rx_chain_add(wil, vring);
  783. if (rc)
  784. goto err_free;
  785. rc = wil_rx_refill(wil, vring->size);
  786. if (rc)
  787. goto err_free;
  788. return 0;
  789. err_free:
  790. wil_vring_free(wil, vring);
  791. return rc;
  792. }
  793. static void wil_rx_fini(struct wil6210_priv *wil)
  794. {
  795. struct wil_ring *vring = &wil->ring_rx;
  796. wil_dbg_misc(wil, "rx_fini\n");
  797. if (vring->va)
  798. wil_vring_free(wil, vring);
  799. }
  800. static int wil_tx_desc_map(union wil_tx_desc *desc, dma_addr_t pa,
  801. u32 len, int vring_index)
  802. {
  803. struct vring_tx_desc *d = &desc->legacy;
  804. wil_desc_addr_set(&d->dma.addr, pa);
  805. d->dma.ip_length = 0;
  806. /* 0..6: mac_length; 7:ip_version 0-IP6 1-IP4*/
  807. d->dma.b11 = 0/*14 | BIT(7)*/;
  808. d->dma.error = 0;
  809. d->dma.status = 0; /* BIT(0) should be 0 for HW_OWNED */
  810. d->dma.length = cpu_to_le16((u16)len);
  811. d->dma.d0 = (vring_index << DMA_CFG_DESC_TX_0_QID_POS);
  812. d->mac.d[0] = 0;
  813. d->mac.d[1] = 0;
  814. d->mac.d[2] = 0;
  815. d->mac.ucode_cmd = 0;
  816. /* translation type: 0 - bypass; 1 - 802.3; 2 - native wifi */
  817. d->mac.d[2] = BIT(MAC_CFG_DESC_TX_2_SNAP_HDR_INSERTION_EN_POS) |
  818. (1 << MAC_CFG_DESC_TX_2_L2_TRANSLATION_TYPE_POS);
  819. return 0;
  820. }
  821. void wil_tx_data_init(struct wil_ring_tx_data *txdata)
  822. {
  823. spin_lock_bh(&txdata->lock);
  824. txdata->dot1x_open = 0;
  825. txdata->enabled = 0;
  826. txdata->idle = 0;
  827. txdata->last_idle = 0;
  828. txdata->begin = 0;
  829. txdata->agg_wsize = 0;
  830. txdata->agg_timeout = 0;
  831. txdata->agg_amsdu = 0;
  832. txdata->addba_in_progress = false;
  833. txdata->mid = U8_MAX;
  834. spin_unlock_bh(&txdata->lock);
  835. }
  836. static int wil_vring_init_tx(struct wil6210_vif *vif, int id, int size,
  837. int cid, int tid)
  838. {
  839. struct wil6210_priv *wil = vif_to_wil(vif);
  840. int rc;
  841. struct wmi_vring_cfg_cmd cmd = {
  842. .action = cpu_to_le32(WMI_VRING_CMD_ADD),
  843. .vring_cfg = {
  844. .tx_sw_ring = {
  845. .max_mpdu_size =
  846. cpu_to_le16(wil_mtu2macbuf(mtu_max)),
  847. .ring_size = cpu_to_le16(size),
  848. },
  849. .ringid = id,
  850. .cidxtid = mk_cidxtid(cid, tid),
  851. .encap_trans_type = WMI_VRING_ENC_TYPE_802_3,
  852. .mac_ctrl = 0,
  853. .to_resolution = 0,
  854. .agg_max_wsize = 0,
  855. .schd_params = {
  856. .priority = cpu_to_le16(0),
  857. .timeslot_us = cpu_to_le16(0xfff),
  858. },
  859. },
  860. };
  861. struct {
  862. struct wmi_cmd_hdr wmi;
  863. struct wmi_vring_cfg_done_event cmd;
  864. } __packed reply = {
  865. .cmd = {.status = WMI_FW_STATUS_FAILURE},
  866. };
  867. struct wil_ring *vring = &wil->ring_tx[id];
  868. struct wil_ring_tx_data *txdata = &wil->ring_tx_data[id];
  869. wil_dbg_misc(wil, "vring_init_tx: max_mpdu_size %d\n",
  870. cmd.vring_cfg.tx_sw_ring.max_mpdu_size);
  871. lockdep_assert_held(&wil->mutex);
  872. if (vring->va) {
  873. wil_err(wil, "Tx ring [%d] already allocated\n", id);
  874. rc = -EINVAL;
  875. goto out;
  876. }
  877. wil_tx_data_init(txdata);
  878. vring->is_rx = false;
  879. vring->size = size;
  880. rc = wil_vring_alloc(wil, vring);
  881. if (rc)
  882. goto out;
  883. wil->ring2cid_tid[id][0] = cid;
  884. wil->ring2cid_tid[id][1] = tid;
  885. cmd.vring_cfg.tx_sw_ring.ring_mem_base = cpu_to_le64(vring->pa);
  886. if (!vif->privacy)
  887. txdata->dot1x_open = true;
  888. rc = wmi_call(wil, WMI_VRING_CFG_CMDID, vif->mid, &cmd, sizeof(cmd),
  889. WMI_VRING_CFG_DONE_EVENTID, &reply, sizeof(reply), 100);
  890. if (rc)
  891. goto out_free;
  892. if (reply.cmd.status != WMI_FW_STATUS_SUCCESS) {
  893. wil_err(wil, "Tx config failed, status 0x%02x\n",
  894. reply.cmd.status);
  895. rc = -EINVAL;
  896. goto out_free;
  897. }
  898. spin_lock_bh(&txdata->lock);
  899. vring->hwtail = le32_to_cpu(reply.cmd.tx_vring_tail_ptr);
  900. txdata->mid = vif->mid;
  901. txdata->enabled = 1;
  902. spin_unlock_bh(&txdata->lock);
  903. if (txdata->dot1x_open && (agg_wsize >= 0))
  904. wil_addba_tx_request(wil, id, agg_wsize);
  905. return 0;
  906. out_free:
  907. spin_lock_bh(&txdata->lock);
  908. txdata->dot1x_open = false;
  909. txdata->enabled = 0;
  910. spin_unlock_bh(&txdata->lock);
  911. wil_vring_free(wil, vring);
  912. wil->ring2cid_tid[id][0] = WIL6210_MAX_CID;
  913. wil->ring2cid_tid[id][1] = 0;
  914. out:
  915. return rc;
  916. }
  917. int wil_vring_init_bcast(struct wil6210_vif *vif, int id, int size)
  918. {
  919. struct wil6210_priv *wil = vif_to_wil(vif);
  920. int rc;
  921. struct wmi_bcast_vring_cfg_cmd cmd = {
  922. .action = cpu_to_le32(WMI_VRING_CMD_ADD),
  923. .vring_cfg = {
  924. .tx_sw_ring = {
  925. .max_mpdu_size =
  926. cpu_to_le16(wil_mtu2macbuf(mtu_max)),
  927. .ring_size = cpu_to_le16(size),
  928. },
  929. .ringid = id,
  930. .encap_trans_type = WMI_VRING_ENC_TYPE_802_3,
  931. },
  932. };
  933. struct {
  934. struct wmi_cmd_hdr wmi;
  935. struct wmi_vring_cfg_done_event cmd;
  936. } __packed reply = {
  937. .cmd = {.status = WMI_FW_STATUS_FAILURE},
  938. };
  939. struct wil_ring *vring = &wil->ring_tx[id];
  940. struct wil_ring_tx_data *txdata = &wil->ring_tx_data[id];
  941. wil_dbg_misc(wil, "vring_init_bcast: max_mpdu_size %d\n",
  942. cmd.vring_cfg.tx_sw_ring.max_mpdu_size);
  943. lockdep_assert_held(&wil->mutex);
  944. if (vring->va) {
  945. wil_err(wil, "Tx ring [%d] already allocated\n", id);
  946. rc = -EINVAL;
  947. goto out;
  948. }
  949. wil_tx_data_init(txdata);
  950. vring->is_rx = false;
  951. vring->size = size;
  952. rc = wil_vring_alloc(wil, vring);
  953. if (rc)
  954. goto out;
  955. wil->ring2cid_tid[id][0] = WIL6210_MAX_CID; /* CID */
  956. wil->ring2cid_tid[id][1] = 0; /* TID */
  957. cmd.vring_cfg.tx_sw_ring.ring_mem_base = cpu_to_le64(vring->pa);
  958. if (!vif->privacy)
  959. txdata->dot1x_open = true;
  960. rc = wmi_call(wil, WMI_BCAST_VRING_CFG_CMDID, vif->mid,
  961. &cmd, sizeof(cmd),
  962. WMI_VRING_CFG_DONE_EVENTID, &reply, sizeof(reply), 100);
  963. if (rc)
  964. goto out_free;
  965. if (reply.cmd.status != WMI_FW_STATUS_SUCCESS) {
  966. wil_err(wil, "Tx config failed, status 0x%02x\n",
  967. reply.cmd.status);
  968. rc = -EINVAL;
  969. goto out_free;
  970. }
  971. spin_lock_bh(&txdata->lock);
  972. vring->hwtail = le32_to_cpu(reply.cmd.tx_vring_tail_ptr);
  973. txdata->mid = vif->mid;
  974. txdata->enabled = 1;
  975. spin_unlock_bh(&txdata->lock);
  976. return 0;
  977. out_free:
  978. spin_lock_bh(&txdata->lock);
  979. txdata->enabled = 0;
  980. txdata->dot1x_open = false;
  981. spin_unlock_bh(&txdata->lock);
  982. wil_vring_free(wil, vring);
  983. out:
  984. return rc;
  985. }
  986. static struct wil_ring *wil_find_tx_ucast(struct wil6210_priv *wil,
  987. struct wil6210_vif *vif,
  988. struct sk_buff *skb)
  989. {
  990. int i;
  991. struct ethhdr *eth = (void *)skb->data;
  992. int cid = wil_find_cid(wil, vif->mid, eth->h_dest);
  993. int min_ring_id = wil_get_min_tx_ring_id(wil);
  994. if (cid < 0)
  995. return NULL;
  996. /* TODO: fix for multiple TID */
  997. for (i = min_ring_id; i < ARRAY_SIZE(wil->ring2cid_tid); i++) {
  998. if (!wil->ring_tx_data[i].dot1x_open &&
  999. skb->protocol != cpu_to_be16(ETH_P_PAE))
  1000. continue;
  1001. if (wil->ring2cid_tid[i][0] == cid) {
  1002. struct wil_ring *v = &wil->ring_tx[i];
  1003. struct wil_ring_tx_data *txdata = &wil->ring_tx_data[i];
  1004. wil_dbg_txrx(wil, "find_tx_ucast: (%pM) -> [%d]\n",
  1005. eth->h_dest, i);
  1006. if (v->va && txdata->enabled) {
  1007. return v;
  1008. } else {
  1009. wil_dbg_txrx(wil,
  1010. "find_tx_ucast: vring[%d] not valid\n",
  1011. i);
  1012. return NULL;
  1013. }
  1014. }
  1015. }
  1016. return NULL;
  1017. }
  1018. static int wil_tx_ring(struct wil6210_priv *wil, struct wil6210_vif *vif,
  1019. struct wil_ring *ring, struct sk_buff *skb);
  1020. static struct wil_ring *wil_find_tx_ring_sta(struct wil6210_priv *wil,
  1021. struct wil6210_vif *vif,
  1022. struct sk_buff *skb)
  1023. {
  1024. struct wil_ring *ring;
  1025. int i;
  1026. u8 cid;
  1027. struct wil_ring_tx_data *txdata;
  1028. int min_ring_id = wil_get_min_tx_ring_id(wil);
  1029. /* In the STA mode, it is expected to have only 1 VRING
  1030. * for the AP we connected to.
  1031. * find 1-st vring eligible for this skb and use it.
  1032. */
  1033. for (i = min_ring_id; i < WIL6210_MAX_TX_RINGS; i++) {
  1034. ring = &wil->ring_tx[i];
  1035. txdata = &wil->ring_tx_data[i];
  1036. if (!ring->va || !txdata->enabled || txdata->mid != vif->mid)
  1037. continue;
  1038. cid = wil->ring2cid_tid[i][0];
  1039. if (cid >= WIL6210_MAX_CID) /* skip BCAST */
  1040. continue;
  1041. if (!wil->ring_tx_data[i].dot1x_open &&
  1042. skb->protocol != cpu_to_be16(ETH_P_PAE))
  1043. continue;
  1044. wil_dbg_txrx(wil, "Tx -> ring %d\n", i);
  1045. return ring;
  1046. }
  1047. wil_dbg_txrx(wil, "Tx while no rings active?\n");
  1048. return NULL;
  1049. }
  1050. /* Use one of 2 strategies:
  1051. *
  1052. * 1. New (real broadcast):
  1053. * use dedicated broadcast vring
  1054. * 2. Old (pseudo-DMS):
  1055. * Find 1-st vring and return it;
  1056. * duplicate skb and send it to other active vrings;
  1057. * in all cases override dest address to unicast peer's address
  1058. * Use old strategy when new is not supported yet:
  1059. * - for PBSS
  1060. */
  1061. static struct wil_ring *wil_find_tx_bcast_1(struct wil6210_priv *wil,
  1062. struct wil6210_vif *vif,
  1063. struct sk_buff *skb)
  1064. {
  1065. struct wil_ring *v;
  1066. struct wil_ring_tx_data *txdata;
  1067. int i = vif->bcast_ring;
  1068. if (i < 0)
  1069. return NULL;
  1070. v = &wil->ring_tx[i];
  1071. txdata = &wil->ring_tx_data[i];
  1072. if (!v->va || !txdata->enabled)
  1073. return NULL;
  1074. if (!wil->ring_tx_data[i].dot1x_open &&
  1075. skb->protocol != cpu_to_be16(ETH_P_PAE))
  1076. return NULL;
  1077. return v;
  1078. }
  1079. static void wil_set_da_for_vring(struct wil6210_priv *wil,
  1080. struct sk_buff *skb, int vring_index)
  1081. {
  1082. struct ethhdr *eth = (void *)skb->data;
  1083. int cid = wil->ring2cid_tid[vring_index][0];
  1084. ether_addr_copy(eth->h_dest, wil->sta[cid].addr);
  1085. }
  1086. static struct wil_ring *wil_find_tx_bcast_2(struct wil6210_priv *wil,
  1087. struct wil6210_vif *vif,
  1088. struct sk_buff *skb)
  1089. {
  1090. struct wil_ring *v, *v2;
  1091. struct sk_buff *skb2;
  1092. int i;
  1093. u8 cid;
  1094. struct ethhdr *eth = (void *)skb->data;
  1095. char *src = eth->h_source;
  1096. struct wil_ring_tx_data *txdata, *txdata2;
  1097. int min_ring_id = wil_get_min_tx_ring_id(wil);
  1098. /* find 1-st vring eligible for data */
  1099. for (i = min_ring_id; i < WIL6210_MAX_TX_RINGS; i++) {
  1100. v = &wil->ring_tx[i];
  1101. txdata = &wil->ring_tx_data[i];
  1102. if (!v->va || !txdata->enabled || txdata->mid != vif->mid)
  1103. continue;
  1104. cid = wil->ring2cid_tid[i][0];
  1105. if (cid >= WIL6210_MAX_CID) /* skip BCAST */
  1106. continue;
  1107. if (!wil->ring_tx_data[i].dot1x_open &&
  1108. skb->protocol != cpu_to_be16(ETH_P_PAE))
  1109. continue;
  1110. /* don't Tx back to source when re-routing Rx->Tx at the AP */
  1111. if (0 == memcmp(wil->sta[cid].addr, src, ETH_ALEN))
  1112. continue;
  1113. goto found;
  1114. }
  1115. wil_dbg_txrx(wil, "Tx while no vrings active?\n");
  1116. return NULL;
  1117. found:
  1118. wil_dbg_txrx(wil, "BCAST -> ring %d\n", i);
  1119. wil_set_da_for_vring(wil, skb, i);
  1120. /* find other active vrings and duplicate skb for each */
  1121. for (i++; i < WIL6210_MAX_TX_RINGS; i++) {
  1122. v2 = &wil->ring_tx[i];
  1123. txdata2 = &wil->ring_tx_data[i];
  1124. if (!v2->va || txdata2->mid != vif->mid)
  1125. continue;
  1126. cid = wil->ring2cid_tid[i][0];
  1127. if (cid >= WIL6210_MAX_CID) /* skip BCAST */
  1128. continue;
  1129. if (!wil->ring_tx_data[i].dot1x_open &&
  1130. skb->protocol != cpu_to_be16(ETH_P_PAE))
  1131. continue;
  1132. if (0 == memcmp(wil->sta[cid].addr, src, ETH_ALEN))
  1133. continue;
  1134. skb2 = skb_copy(skb, GFP_ATOMIC);
  1135. if (skb2) {
  1136. wil_dbg_txrx(wil, "BCAST DUP -> ring %d\n", i);
  1137. wil_set_da_for_vring(wil, skb2, i);
  1138. wil_tx_ring(wil, vif, v2, skb2);
  1139. } else {
  1140. wil_err(wil, "skb_copy failed\n");
  1141. }
  1142. }
  1143. return v;
  1144. }
  1145. static inline
  1146. void wil_tx_desc_set_nr_frags(struct vring_tx_desc *d, int nr_frags)
  1147. {
  1148. d->mac.d[2] |= (nr_frags << MAC_CFG_DESC_TX_2_NUM_OF_DESCRIPTORS_POS);
  1149. }
  1150. /**
  1151. * Sets the descriptor @d up for csum and/or TSO offloading. The corresponding
  1152. * @skb is used to obtain the protocol and headers length.
  1153. * @tso_desc_type is a descriptor type for TSO: 0 - a header, 1 - first data,
  1154. * 2 - middle, 3 - last descriptor.
  1155. */
  1156. static void wil_tx_desc_offload_setup_tso(struct vring_tx_desc *d,
  1157. struct sk_buff *skb,
  1158. int tso_desc_type, bool is_ipv4,
  1159. int tcp_hdr_len, int skb_net_hdr_len)
  1160. {
  1161. d->dma.b11 = ETH_HLEN; /* MAC header length */
  1162. d->dma.b11 |= is_ipv4 << DMA_CFG_DESC_TX_OFFLOAD_CFG_L3T_IPV4_POS;
  1163. d->dma.d0 |= (2 << DMA_CFG_DESC_TX_0_L4_TYPE_POS);
  1164. /* L4 header len: TCP header length */
  1165. d->dma.d0 |= (tcp_hdr_len & DMA_CFG_DESC_TX_0_L4_LENGTH_MSK);
  1166. /* Setup TSO: bit and desc type */
  1167. d->dma.d0 |= (BIT(DMA_CFG_DESC_TX_0_TCP_SEG_EN_POS)) |
  1168. (tso_desc_type << DMA_CFG_DESC_TX_0_SEGMENT_BUF_DETAILS_POS);
  1169. d->dma.d0 |= (is_ipv4 << DMA_CFG_DESC_TX_0_IPV4_CHECKSUM_EN_POS);
  1170. d->dma.ip_length = skb_net_hdr_len;
  1171. /* Enable TCP/UDP checksum */
  1172. d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_TCP_UDP_CHECKSUM_EN_POS);
  1173. /* Calculate pseudo-header */
  1174. d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_PSEUDO_HEADER_CALC_EN_POS);
  1175. }
  1176. /**
  1177. * Sets the descriptor @d up for csum. The corresponding
  1178. * @skb is used to obtain the protocol and headers length.
  1179. * Returns the protocol: 0 - not TCP, 1 - TCPv4, 2 - TCPv6.
  1180. * Note, if d==NULL, the function only returns the protocol result.
  1181. *
  1182. * It is very similar to previous wil_tx_desc_offload_setup_tso. This
  1183. * is "if unrolling" to optimize the critical path.
  1184. */
  1185. static int wil_tx_desc_offload_setup(struct vring_tx_desc *d,
  1186. struct sk_buff *skb){
  1187. int protocol;
  1188. if (skb->ip_summed != CHECKSUM_PARTIAL)
  1189. return 0;
  1190. d->dma.b11 = ETH_HLEN; /* MAC header length */
  1191. switch (skb->protocol) {
  1192. case cpu_to_be16(ETH_P_IP):
  1193. protocol = ip_hdr(skb)->protocol;
  1194. d->dma.b11 |= BIT(DMA_CFG_DESC_TX_OFFLOAD_CFG_L3T_IPV4_POS);
  1195. break;
  1196. case cpu_to_be16(ETH_P_IPV6):
  1197. protocol = ipv6_hdr(skb)->nexthdr;
  1198. break;
  1199. default:
  1200. return -EINVAL;
  1201. }
  1202. switch (protocol) {
  1203. case IPPROTO_TCP:
  1204. d->dma.d0 |= (2 << DMA_CFG_DESC_TX_0_L4_TYPE_POS);
  1205. /* L4 header len: TCP header length */
  1206. d->dma.d0 |=
  1207. (tcp_hdrlen(skb) & DMA_CFG_DESC_TX_0_L4_LENGTH_MSK);
  1208. break;
  1209. case IPPROTO_UDP:
  1210. /* L4 header len: UDP header length */
  1211. d->dma.d0 |=
  1212. (sizeof(struct udphdr) & DMA_CFG_DESC_TX_0_L4_LENGTH_MSK);
  1213. break;
  1214. default:
  1215. return -EINVAL;
  1216. }
  1217. d->dma.ip_length = skb_network_header_len(skb);
  1218. /* Enable TCP/UDP checksum */
  1219. d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_TCP_UDP_CHECKSUM_EN_POS);
  1220. /* Calculate pseudo-header */
  1221. d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_PSEUDO_HEADER_CALC_EN_POS);
  1222. return 0;
  1223. }
  1224. static inline void wil_tx_last_desc(struct vring_tx_desc *d)
  1225. {
  1226. d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_CMD_EOP_POS) |
  1227. BIT(DMA_CFG_DESC_TX_0_CMD_MARK_WB_POS) |
  1228. BIT(DMA_CFG_DESC_TX_0_CMD_DMA_IT_POS);
  1229. }
  1230. static inline void wil_set_tx_desc_last_tso(volatile struct vring_tx_desc *d)
  1231. {
  1232. d->dma.d0 |= wil_tso_type_lst <<
  1233. DMA_CFG_DESC_TX_0_SEGMENT_BUF_DETAILS_POS;
  1234. }
  1235. static int __wil_tx_vring_tso(struct wil6210_priv *wil, struct wil6210_vif *vif,
  1236. struct wil_ring *vring, struct sk_buff *skb)
  1237. {
  1238. struct device *dev = wil_to_dev(wil);
  1239. /* point to descriptors in shared memory */
  1240. volatile struct vring_tx_desc *_desc = NULL, *_hdr_desc,
  1241. *_first_desc = NULL;
  1242. /* pointers to shadow descriptors */
  1243. struct vring_tx_desc desc_mem, hdr_desc_mem, first_desc_mem,
  1244. *d = &hdr_desc_mem, *hdr_desc = &hdr_desc_mem,
  1245. *first_desc = &first_desc_mem;
  1246. /* pointer to shadow descriptors' context */
  1247. struct wil_ctx *hdr_ctx, *first_ctx = NULL;
  1248. int descs_used = 0; /* total number of used descriptors */
  1249. int sg_desc_cnt = 0; /* number of descriptors for current mss*/
  1250. u32 swhead = vring->swhead;
  1251. int used, avail = wil_ring_avail_tx(vring);
  1252. int nr_frags = skb_shinfo(skb)->nr_frags;
  1253. int min_desc_required = nr_frags + 1;
  1254. int mss = skb_shinfo(skb)->gso_size; /* payload size w/o headers */
  1255. int f, len, hdrlen, headlen;
  1256. int vring_index = vring - wil->ring_tx;
  1257. struct wil_ring_tx_data *txdata = &wil->ring_tx_data[vring_index];
  1258. uint i = swhead;
  1259. dma_addr_t pa;
  1260. const skb_frag_t *frag = NULL;
  1261. int rem_data = mss;
  1262. int lenmss;
  1263. int hdr_compensation_need = true;
  1264. int desc_tso_type = wil_tso_type_first;
  1265. bool is_ipv4;
  1266. int tcp_hdr_len;
  1267. int skb_net_hdr_len;
  1268. int gso_type;
  1269. int rc = -EINVAL;
  1270. wil_dbg_txrx(wil, "tx_vring_tso: %d bytes to vring %d\n", skb->len,
  1271. vring_index);
  1272. if (unlikely(!txdata->enabled))
  1273. return -EINVAL;
  1274. /* A typical page 4K is 3-4 payloads, we assume each fragment
  1275. * is a full payload, that's how min_desc_required has been
  1276. * calculated. In real we might need more or less descriptors,
  1277. * this is the initial check only.
  1278. */
  1279. if (unlikely(avail < min_desc_required)) {
  1280. wil_err_ratelimited(wil,
  1281. "TSO: Tx ring[%2d] full. No space for %d fragments\n",
  1282. vring_index, min_desc_required);
  1283. return -ENOMEM;
  1284. }
  1285. /* Header Length = MAC header len + IP header len + TCP header len*/
  1286. hdrlen = ETH_HLEN +
  1287. (int)skb_network_header_len(skb) +
  1288. tcp_hdrlen(skb);
  1289. gso_type = skb_shinfo(skb)->gso_type & (SKB_GSO_TCPV6 | SKB_GSO_TCPV4);
  1290. switch (gso_type) {
  1291. case SKB_GSO_TCPV4:
  1292. /* TCP v4, zero out the IP length and IPv4 checksum fields
  1293. * as required by the offloading doc
  1294. */
  1295. ip_hdr(skb)->tot_len = 0;
  1296. ip_hdr(skb)->check = 0;
  1297. is_ipv4 = true;
  1298. break;
  1299. case SKB_GSO_TCPV6:
  1300. /* TCP v6, zero out the payload length */
  1301. ipv6_hdr(skb)->payload_len = 0;
  1302. is_ipv4 = false;
  1303. break;
  1304. default:
  1305. /* other than TCPv4 or TCPv6 types are not supported for TSO.
  1306. * It is also illegal for both to be set simultaneously
  1307. */
  1308. return -EINVAL;
  1309. }
  1310. if (skb->ip_summed != CHECKSUM_PARTIAL)
  1311. return -EINVAL;
  1312. /* tcp header length and skb network header length are fixed for all
  1313. * packet's descriptors - read then once here
  1314. */
  1315. tcp_hdr_len = tcp_hdrlen(skb);
  1316. skb_net_hdr_len = skb_network_header_len(skb);
  1317. _hdr_desc = &vring->va[i].tx.legacy;
  1318. pa = dma_map_single(dev, skb->data, hdrlen, DMA_TO_DEVICE);
  1319. if (unlikely(dma_mapping_error(dev, pa))) {
  1320. wil_err(wil, "TSO: Skb head DMA map error\n");
  1321. goto err_exit;
  1322. }
  1323. wil->txrx_ops.tx_desc_map((union wil_tx_desc *)hdr_desc, pa,
  1324. hdrlen, vring_index);
  1325. wil_tx_desc_offload_setup_tso(hdr_desc, skb, wil_tso_type_hdr, is_ipv4,
  1326. tcp_hdr_len, skb_net_hdr_len);
  1327. wil_tx_last_desc(hdr_desc);
  1328. vring->ctx[i].mapped_as = wil_mapped_as_single;
  1329. hdr_ctx = &vring->ctx[i];
  1330. descs_used++;
  1331. headlen = skb_headlen(skb) - hdrlen;
  1332. for (f = headlen ? -1 : 0; f < nr_frags; f++) {
  1333. if (headlen) {
  1334. len = headlen;
  1335. wil_dbg_txrx(wil, "TSO: process skb head, len %u\n",
  1336. len);
  1337. } else {
  1338. frag = &skb_shinfo(skb)->frags[f];
  1339. len = frag->size;
  1340. wil_dbg_txrx(wil, "TSO: frag[%d]: len %u\n", f, len);
  1341. }
  1342. while (len) {
  1343. wil_dbg_txrx(wil,
  1344. "TSO: len %d, rem_data %d, descs_used %d\n",
  1345. len, rem_data, descs_used);
  1346. if (descs_used == avail) {
  1347. wil_err_ratelimited(wil, "TSO: ring overflow\n");
  1348. rc = -ENOMEM;
  1349. goto mem_error;
  1350. }
  1351. lenmss = min_t(int, rem_data, len);
  1352. i = (swhead + descs_used) % vring->size;
  1353. wil_dbg_txrx(wil, "TSO: lenmss %d, i %d\n", lenmss, i);
  1354. if (!headlen) {
  1355. pa = skb_frag_dma_map(dev, frag,
  1356. frag->size - len, lenmss,
  1357. DMA_TO_DEVICE);
  1358. vring->ctx[i].mapped_as = wil_mapped_as_page;
  1359. } else {
  1360. pa = dma_map_single(dev,
  1361. skb->data +
  1362. skb_headlen(skb) - headlen,
  1363. lenmss,
  1364. DMA_TO_DEVICE);
  1365. vring->ctx[i].mapped_as = wil_mapped_as_single;
  1366. headlen -= lenmss;
  1367. }
  1368. if (unlikely(dma_mapping_error(dev, pa))) {
  1369. wil_err(wil, "TSO: DMA map page error\n");
  1370. goto mem_error;
  1371. }
  1372. _desc = &vring->va[i].tx.legacy;
  1373. if (!_first_desc) {
  1374. _first_desc = _desc;
  1375. first_ctx = &vring->ctx[i];
  1376. d = first_desc;
  1377. } else {
  1378. d = &desc_mem;
  1379. }
  1380. wil->txrx_ops.tx_desc_map((union wil_tx_desc *)d,
  1381. pa, lenmss, vring_index);
  1382. wil_tx_desc_offload_setup_tso(d, skb, desc_tso_type,
  1383. is_ipv4, tcp_hdr_len,
  1384. skb_net_hdr_len);
  1385. /* use tso_type_first only once */
  1386. desc_tso_type = wil_tso_type_mid;
  1387. descs_used++; /* desc used so far */
  1388. sg_desc_cnt++; /* desc used for this segment */
  1389. len -= lenmss;
  1390. rem_data -= lenmss;
  1391. wil_dbg_txrx(wil,
  1392. "TSO: len %d, rem_data %d, descs_used %d, sg_desc_cnt %d,\n",
  1393. len, rem_data, descs_used, sg_desc_cnt);
  1394. /* Close the segment if reached mss size or last frag*/
  1395. if (rem_data == 0 || (f == nr_frags - 1 && len == 0)) {
  1396. if (hdr_compensation_need) {
  1397. /* first segment include hdr desc for
  1398. * release
  1399. */
  1400. hdr_ctx->nr_frags = sg_desc_cnt;
  1401. wil_tx_desc_set_nr_frags(first_desc,
  1402. sg_desc_cnt +
  1403. 1);
  1404. hdr_compensation_need = false;
  1405. } else {
  1406. wil_tx_desc_set_nr_frags(first_desc,
  1407. sg_desc_cnt);
  1408. }
  1409. first_ctx->nr_frags = sg_desc_cnt - 1;
  1410. wil_tx_last_desc(d);
  1411. /* first descriptor may also be the last
  1412. * for this mss - make sure not to copy
  1413. * it twice
  1414. */
  1415. if (first_desc != d)
  1416. *_first_desc = *first_desc;
  1417. /*last descriptor will be copied at the end
  1418. * of this TS processing
  1419. */
  1420. if (f < nr_frags - 1 || len > 0)
  1421. *_desc = *d;
  1422. rem_data = mss;
  1423. _first_desc = NULL;
  1424. sg_desc_cnt = 0;
  1425. } else if (first_desc != d) /* update mid descriptor */
  1426. *_desc = *d;
  1427. }
  1428. }
  1429. /* first descriptor may also be the last.
  1430. * in this case d pointer is invalid
  1431. */
  1432. if (_first_desc == _desc)
  1433. d = first_desc;
  1434. /* Last data descriptor */
  1435. wil_set_tx_desc_last_tso(d);
  1436. *_desc = *d;
  1437. /* Fill the total number of descriptors in first desc (hdr)*/
  1438. wil_tx_desc_set_nr_frags(hdr_desc, descs_used);
  1439. *_hdr_desc = *hdr_desc;
  1440. /* hold reference to skb
  1441. * to prevent skb release before accounting
  1442. * in case of immediate "tx done"
  1443. */
  1444. vring->ctx[i].skb = skb_get(skb);
  1445. /* performance monitoring */
  1446. used = wil_ring_used_tx(vring);
  1447. if (wil_val_in_range(wil->ring_idle_trsh,
  1448. used, used + descs_used)) {
  1449. txdata->idle += get_cycles() - txdata->last_idle;
  1450. wil_dbg_txrx(wil, "Ring[%2d] not idle %d -> %d\n",
  1451. vring_index, used, used + descs_used);
  1452. }
  1453. /* Make sure to advance the head only after descriptor update is done.
  1454. * This will prevent a race condition where the completion thread
  1455. * will see the DU bit set from previous run and will handle the
  1456. * skb before it was completed.
  1457. */
  1458. wmb();
  1459. /* advance swhead */
  1460. wil_ring_advance_head(vring, descs_used);
  1461. wil_dbg_txrx(wil, "TSO: Tx swhead %d -> %d\n", swhead, vring->swhead);
  1462. /* make sure all writes to descriptors (shared memory) are done before
  1463. * committing them to HW
  1464. */
  1465. wmb();
  1466. if (wil->tx_latency)
  1467. *(ktime_t *)&skb->cb = ktime_get();
  1468. else
  1469. memset(skb->cb, 0, sizeof(ktime_t));
  1470. wil_w(wil, vring->hwtail, vring->swhead);
  1471. return 0;
  1472. mem_error:
  1473. while (descs_used > 0) {
  1474. struct wil_ctx *ctx;
  1475. i = (swhead + descs_used - 1) % vring->size;
  1476. d = (struct vring_tx_desc *)&vring->va[i].tx.legacy;
  1477. _desc = &vring->va[i].tx.legacy;
  1478. *d = *_desc;
  1479. _desc->dma.status = TX_DMA_STATUS_DU;
  1480. ctx = &vring->ctx[i];
  1481. wil_txdesc_unmap(dev, (union wil_tx_desc *)d, ctx);
  1482. memset(ctx, 0, sizeof(*ctx));
  1483. descs_used--;
  1484. }
  1485. err_exit:
  1486. return rc;
  1487. }
  1488. static int __wil_tx_ring(struct wil6210_priv *wil, struct wil6210_vif *vif,
  1489. struct wil_ring *ring, struct sk_buff *skb)
  1490. {
  1491. struct device *dev = wil_to_dev(wil);
  1492. struct vring_tx_desc dd, *d = &dd;
  1493. volatile struct vring_tx_desc *_d;
  1494. u32 swhead = ring->swhead;
  1495. int avail = wil_ring_avail_tx(ring);
  1496. int nr_frags = skb_shinfo(skb)->nr_frags;
  1497. uint f = 0;
  1498. int ring_index = ring - wil->ring_tx;
  1499. struct wil_ring_tx_data *txdata = &wil->ring_tx_data[ring_index];
  1500. uint i = swhead;
  1501. dma_addr_t pa;
  1502. int used;
  1503. bool mcast = (ring_index == vif->bcast_ring);
  1504. uint len = skb_headlen(skb);
  1505. wil_dbg_txrx(wil, "tx_ring: %d bytes to ring %d, nr_frags %d\n",
  1506. skb->len, ring_index, nr_frags);
  1507. if (unlikely(!txdata->enabled))
  1508. return -EINVAL;
  1509. if (unlikely(avail < 1 + nr_frags)) {
  1510. wil_err_ratelimited(wil,
  1511. "Tx ring[%2d] full. No space for %d fragments\n",
  1512. ring_index, 1 + nr_frags);
  1513. return -ENOMEM;
  1514. }
  1515. _d = &ring->va[i].tx.legacy;
  1516. pa = dma_map_single(dev, skb->data, skb_headlen(skb), DMA_TO_DEVICE);
  1517. wil_dbg_txrx(wil, "Tx[%2d] skb %d bytes 0x%p -> %pad\n", ring_index,
  1518. skb_headlen(skb), skb->data, &pa);
  1519. wil_hex_dump_txrx("Tx ", DUMP_PREFIX_OFFSET, 16, 1,
  1520. skb->data, skb_headlen(skb), false);
  1521. if (unlikely(dma_mapping_error(dev, pa)))
  1522. return -EINVAL;
  1523. ring->ctx[i].mapped_as = wil_mapped_as_single;
  1524. /* 1-st segment */
  1525. wil->txrx_ops.tx_desc_map((union wil_tx_desc *)d, pa, len,
  1526. ring_index);
  1527. if (unlikely(mcast)) {
  1528. d->mac.d[0] |= BIT(MAC_CFG_DESC_TX_0_MCS_EN_POS); /* MCS 0 */
  1529. if (unlikely(len > WIL_BCAST_MCS0_LIMIT)) /* set MCS 1 */
  1530. d->mac.d[0] |= (1 << MAC_CFG_DESC_TX_0_MCS_INDEX_POS);
  1531. }
  1532. /* Process TCP/UDP checksum offloading */
  1533. if (unlikely(wil_tx_desc_offload_setup(d, skb))) {
  1534. wil_err(wil, "Tx[%2d] Failed to set cksum, drop packet\n",
  1535. ring_index);
  1536. goto dma_error;
  1537. }
  1538. ring->ctx[i].nr_frags = nr_frags;
  1539. wil_tx_desc_set_nr_frags(d, nr_frags + 1);
  1540. /* middle segments */
  1541. for (; f < nr_frags; f++) {
  1542. const struct skb_frag_struct *frag =
  1543. &skb_shinfo(skb)->frags[f];
  1544. int len = skb_frag_size(frag);
  1545. *_d = *d;
  1546. wil_dbg_txrx(wil, "Tx[%2d] desc[%4d]\n", ring_index, i);
  1547. wil_hex_dump_txrx("TxD ", DUMP_PREFIX_NONE, 32, 4,
  1548. (const void *)d, sizeof(*d), false);
  1549. i = (swhead + f + 1) % ring->size;
  1550. _d = &ring->va[i].tx.legacy;
  1551. pa = skb_frag_dma_map(dev, frag, 0, skb_frag_size(frag),
  1552. DMA_TO_DEVICE);
  1553. if (unlikely(dma_mapping_error(dev, pa))) {
  1554. wil_err(wil, "Tx[%2d] failed to map fragment\n",
  1555. ring_index);
  1556. goto dma_error;
  1557. }
  1558. ring->ctx[i].mapped_as = wil_mapped_as_page;
  1559. wil->txrx_ops.tx_desc_map((union wil_tx_desc *)d,
  1560. pa, len, ring_index);
  1561. /* no need to check return code -
  1562. * if it succeeded for 1-st descriptor,
  1563. * it will succeed here too
  1564. */
  1565. wil_tx_desc_offload_setup(d, skb);
  1566. }
  1567. /* for the last seg only */
  1568. d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_CMD_EOP_POS);
  1569. d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_CMD_MARK_WB_POS);
  1570. d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_CMD_DMA_IT_POS);
  1571. *_d = *d;
  1572. wil_dbg_txrx(wil, "Tx[%2d] desc[%4d]\n", ring_index, i);
  1573. wil_hex_dump_txrx("TxD ", DUMP_PREFIX_NONE, 32, 4,
  1574. (const void *)d, sizeof(*d), false);
  1575. /* hold reference to skb
  1576. * to prevent skb release before accounting
  1577. * in case of immediate "tx done"
  1578. */
  1579. ring->ctx[i].skb = skb_get(skb);
  1580. /* performance monitoring */
  1581. used = wil_ring_used_tx(ring);
  1582. if (wil_val_in_range(wil->ring_idle_trsh,
  1583. used, used + nr_frags + 1)) {
  1584. txdata->idle += get_cycles() - txdata->last_idle;
  1585. wil_dbg_txrx(wil, "Ring[%2d] not idle %d -> %d\n",
  1586. ring_index, used, used + nr_frags + 1);
  1587. }
  1588. /* Make sure to advance the head only after descriptor update is done.
  1589. * This will prevent a race condition where the completion thread
  1590. * will see the DU bit set from previous run and will handle the
  1591. * skb before it was completed.
  1592. */
  1593. wmb();
  1594. /* advance swhead */
  1595. wil_ring_advance_head(ring, nr_frags + 1);
  1596. wil_dbg_txrx(wil, "Tx[%2d] swhead %d -> %d\n", ring_index, swhead,
  1597. ring->swhead);
  1598. trace_wil6210_tx(ring_index, swhead, skb->len, nr_frags);
  1599. /* make sure all writes to descriptors (shared memory) are done before
  1600. * committing them to HW
  1601. */
  1602. wmb();
  1603. if (wil->tx_latency)
  1604. *(ktime_t *)&skb->cb = ktime_get();
  1605. else
  1606. memset(skb->cb, 0, sizeof(ktime_t));
  1607. wil_w(wil, ring->hwtail, ring->swhead);
  1608. return 0;
  1609. dma_error:
  1610. /* unmap what we have mapped */
  1611. nr_frags = f + 1; /* frags mapped + one for skb head */
  1612. for (f = 0; f < nr_frags; f++) {
  1613. struct wil_ctx *ctx;
  1614. i = (swhead + f) % ring->size;
  1615. ctx = &ring->ctx[i];
  1616. _d = &ring->va[i].tx.legacy;
  1617. *d = *_d;
  1618. _d->dma.status = TX_DMA_STATUS_DU;
  1619. wil->txrx_ops.tx_desc_unmap(dev,
  1620. (union wil_tx_desc *)d,
  1621. ctx);
  1622. memset(ctx, 0, sizeof(*ctx));
  1623. }
  1624. return -EINVAL;
  1625. }
  1626. static int wil_tx_ring(struct wil6210_priv *wil, struct wil6210_vif *vif,
  1627. struct wil_ring *ring, struct sk_buff *skb)
  1628. {
  1629. int ring_index = ring - wil->ring_tx;
  1630. struct wil_ring_tx_data *txdata = &wil->ring_tx_data[ring_index];
  1631. int rc;
  1632. spin_lock(&txdata->lock);
  1633. if (test_bit(wil_status_suspending, wil->status) ||
  1634. test_bit(wil_status_suspended, wil->status) ||
  1635. test_bit(wil_status_resuming, wil->status)) {
  1636. wil_dbg_txrx(wil,
  1637. "suspend/resume in progress. drop packet\n");
  1638. spin_unlock(&txdata->lock);
  1639. return -EINVAL;
  1640. }
  1641. rc = (skb_is_gso(skb) ? wil->txrx_ops.tx_ring_tso : __wil_tx_ring)
  1642. (wil, vif, ring, skb);
  1643. spin_unlock(&txdata->lock);
  1644. return rc;
  1645. }
  1646. /**
  1647. * Check status of tx vrings and stop/wake net queues if needed
  1648. * It will start/stop net queues of a specific VIF net_device.
  1649. *
  1650. * This function does one of two checks:
  1651. * In case check_stop is true, will check if net queues need to be stopped. If
  1652. * the conditions for stopping are met, netif_tx_stop_all_queues() is called.
  1653. * In case check_stop is false, will check if net queues need to be waked. If
  1654. * the conditions for waking are met, netif_tx_wake_all_queues() is called.
  1655. * vring is the vring which is currently being modified by either adding
  1656. * descriptors (tx) into it or removing descriptors (tx complete) from it. Can
  1657. * be null when irrelevant (e.g. connect/disconnect events).
  1658. *
  1659. * The implementation is to stop net queues if modified vring has low
  1660. * descriptor availability. Wake if all vrings are not in low descriptor
  1661. * availability and modified vring has high descriptor availability.
  1662. */
  1663. static inline void __wil_update_net_queues(struct wil6210_priv *wil,
  1664. struct wil6210_vif *vif,
  1665. struct wil_ring *ring,
  1666. bool check_stop)
  1667. {
  1668. int i;
  1669. if (unlikely(!vif))
  1670. return;
  1671. if (ring)
  1672. wil_dbg_txrx(wil, "vring %d, mid %d, check_stop=%d, stopped=%d",
  1673. (int)(ring - wil->ring_tx), vif->mid, check_stop,
  1674. vif->net_queue_stopped);
  1675. else
  1676. wil_dbg_txrx(wil, "check_stop=%d, mid=%d, stopped=%d",
  1677. check_stop, vif->mid, vif->net_queue_stopped);
  1678. if (check_stop == vif->net_queue_stopped)
  1679. /* net queues already in desired state */
  1680. return;
  1681. if (check_stop) {
  1682. if (!ring || unlikely(wil_ring_avail_low(ring))) {
  1683. /* not enough room in the vring */
  1684. netif_tx_stop_all_queues(vif_to_ndev(vif));
  1685. vif->net_queue_stopped = true;
  1686. wil_dbg_txrx(wil, "netif_tx_stop called\n");
  1687. }
  1688. return;
  1689. }
  1690. /* Do not wake the queues in suspend flow */
  1691. if (test_bit(wil_status_suspending, wil->status) ||
  1692. test_bit(wil_status_suspended, wil->status))
  1693. return;
  1694. /* check wake */
  1695. for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
  1696. struct wil_ring *cur_ring = &wil->ring_tx[i];
  1697. struct wil_ring_tx_data *txdata = &wil->ring_tx_data[i];
  1698. if (txdata->mid != vif->mid || !cur_ring->va ||
  1699. !txdata->enabled || cur_ring == ring)
  1700. continue;
  1701. if (wil_ring_avail_low(cur_ring)) {
  1702. wil_dbg_txrx(wil, "ring %d full, can't wake\n",
  1703. (int)(cur_ring - wil->ring_tx));
  1704. return;
  1705. }
  1706. }
  1707. if (!ring || wil_ring_avail_high(ring)) {
  1708. /* enough room in the ring */
  1709. wil_dbg_txrx(wil, "calling netif_tx_wake\n");
  1710. netif_tx_wake_all_queues(vif_to_ndev(vif));
  1711. vif->net_queue_stopped = false;
  1712. }
  1713. }
  1714. void wil_update_net_queues(struct wil6210_priv *wil, struct wil6210_vif *vif,
  1715. struct wil_ring *ring, bool check_stop)
  1716. {
  1717. spin_lock(&wil->net_queue_lock);
  1718. __wil_update_net_queues(wil, vif, ring, check_stop);
  1719. spin_unlock(&wil->net_queue_lock);
  1720. }
  1721. void wil_update_net_queues_bh(struct wil6210_priv *wil, struct wil6210_vif *vif,
  1722. struct wil_ring *ring, bool check_stop)
  1723. {
  1724. spin_lock_bh(&wil->net_queue_lock);
  1725. __wil_update_net_queues(wil, vif, ring, check_stop);
  1726. spin_unlock_bh(&wil->net_queue_lock);
  1727. }
  1728. netdev_tx_t wil_start_xmit(struct sk_buff *skb, struct net_device *ndev)
  1729. {
  1730. struct wil6210_vif *vif = ndev_to_vif(ndev);
  1731. struct wil6210_priv *wil = vif_to_wil(vif);
  1732. struct ethhdr *eth = (void *)skb->data;
  1733. bool bcast = is_multicast_ether_addr(eth->h_dest);
  1734. struct wil_ring *ring;
  1735. static bool pr_once_fw;
  1736. int rc;
  1737. wil_dbg_txrx(wil, "start_xmit\n");
  1738. if (unlikely(!test_bit(wil_status_fwready, wil->status))) {
  1739. if (!pr_once_fw) {
  1740. wil_err(wil, "FW not ready\n");
  1741. pr_once_fw = true;
  1742. }
  1743. goto drop;
  1744. }
  1745. if (unlikely(!test_bit(wil_vif_fwconnected, vif->status))) {
  1746. wil_dbg_ratelimited(wil,
  1747. "VIF not connected, packet dropped\n");
  1748. goto drop;
  1749. }
  1750. if (unlikely(vif->wdev.iftype == NL80211_IFTYPE_MONITOR)) {
  1751. wil_err(wil, "Xmit in monitor mode not supported\n");
  1752. goto drop;
  1753. }
  1754. pr_once_fw = false;
  1755. /* find vring */
  1756. if (vif->wdev.iftype == NL80211_IFTYPE_STATION && !vif->pbss) {
  1757. /* in STA mode (ESS), all to same VRING (to AP) */
  1758. ring = wil_find_tx_ring_sta(wil, vif, skb);
  1759. } else if (bcast) {
  1760. if (vif->pbss)
  1761. /* in pbss, no bcast VRING - duplicate skb in
  1762. * all stations VRINGs
  1763. */
  1764. ring = wil_find_tx_bcast_2(wil, vif, skb);
  1765. else if (vif->wdev.iftype == NL80211_IFTYPE_AP)
  1766. /* AP has a dedicated bcast VRING */
  1767. ring = wil_find_tx_bcast_1(wil, vif, skb);
  1768. else
  1769. /* unexpected combination, fallback to duplicating
  1770. * the skb in all stations VRINGs
  1771. */
  1772. ring = wil_find_tx_bcast_2(wil, vif, skb);
  1773. } else {
  1774. /* unicast, find specific VRING by dest. address */
  1775. ring = wil_find_tx_ucast(wil, vif, skb);
  1776. }
  1777. if (unlikely(!ring)) {
  1778. wil_dbg_txrx(wil, "No Tx RING found for %pM\n", eth->h_dest);
  1779. goto drop;
  1780. }
  1781. /* set up vring entry */
  1782. rc = wil_tx_ring(wil, vif, ring, skb);
  1783. switch (rc) {
  1784. case 0:
  1785. /* shall we stop net queues? */
  1786. wil_update_net_queues_bh(wil, vif, ring, true);
  1787. /* statistics will be updated on the tx_complete */
  1788. dev_kfree_skb_any(skb);
  1789. return NETDEV_TX_OK;
  1790. case -ENOMEM:
  1791. return NETDEV_TX_BUSY;
  1792. default:
  1793. break; /* goto drop; */
  1794. }
  1795. drop:
  1796. ndev->stats.tx_dropped++;
  1797. dev_kfree_skb_any(skb);
  1798. return NET_XMIT_DROP;
  1799. }
  1800. void wil_tx_latency_calc(struct wil6210_priv *wil, struct sk_buff *skb,
  1801. struct wil_sta_info *sta)
  1802. {
  1803. int skb_time_us;
  1804. int bin;
  1805. if (!wil->tx_latency)
  1806. return;
  1807. if (ktime_to_ms(*(ktime_t *)&skb->cb) == 0)
  1808. return;
  1809. skb_time_us = ktime_us_delta(ktime_get(), *(ktime_t *)&skb->cb);
  1810. bin = skb_time_us / wil->tx_latency_res;
  1811. bin = min_t(int, bin, WIL_NUM_LATENCY_BINS - 1);
  1812. wil_dbg_txrx(wil, "skb time %dus => bin %d\n", skb_time_us, bin);
  1813. sta->tx_latency_bins[bin]++;
  1814. sta->stats.tx_latency_total_us += skb_time_us;
  1815. if (skb_time_us < sta->stats.tx_latency_min_us)
  1816. sta->stats.tx_latency_min_us = skb_time_us;
  1817. if (skb_time_us > sta->stats.tx_latency_max_us)
  1818. sta->stats.tx_latency_max_us = skb_time_us;
  1819. }
  1820. /**
  1821. * Clean up transmitted skb's from the Tx VRING
  1822. *
  1823. * Return number of descriptors cleared
  1824. *
  1825. * Safe to call from IRQ
  1826. */
  1827. int wil_tx_complete(struct wil6210_vif *vif, int ringid)
  1828. {
  1829. struct wil6210_priv *wil = vif_to_wil(vif);
  1830. struct net_device *ndev = vif_to_ndev(vif);
  1831. struct device *dev = wil_to_dev(wil);
  1832. struct wil_ring *vring = &wil->ring_tx[ringid];
  1833. struct wil_ring_tx_data *txdata = &wil->ring_tx_data[ringid];
  1834. int done = 0;
  1835. int cid = wil->ring2cid_tid[ringid][0];
  1836. struct wil_net_stats *stats = NULL;
  1837. volatile struct vring_tx_desc *_d;
  1838. int used_before_complete;
  1839. int used_new;
  1840. if (unlikely(!vring->va)) {
  1841. wil_err(wil, "Tx irq[%d]: vring not initialized\n", ringid);
  1842. return 0;
  1843. }
  1844. if (unlikely(!txdata->enabled)) {
  1845. wil_info(wil, "Tx irq[%d]: vring disabled\n", ringid);
  1846. return 0;
  1847. }
  1848. wil_dbg_txrx(wil, "tx_complete: (%d)\n", ringid);
  1849. used_before_complete = wil_ring_used_tx(vring);
  1850. if (cid < WIL6210_MAX_CID)
  1851. stats = &wil->sta[cid].stats;
  1852. while (!wil_ring_is_empty(vring)) {
  1853. int new_swtail;
  1854. struct wil_ctx *ctx = &vring->ctx[vring->swtail];
  1855. /**
  1856. * For the fragmented skb, HW will set DU bit only for the
  1857. * last fragment. look for it.
  1858. * In TSO the first DU will include hdr desc
  1859. */
  1860. int lf = (vring->swtail + ctx->nr_frags) % vring->size;
  1861. /* TODO: check we are not past head */
  1862. _d = &vring->va[lf].tx.legacy;
  1863. if (unlikely(!(_d->dma.status & TX_DMA_STATUS_DU)))
  1864. break;
  1865. new_swtail = (lf + 1) % vring->size;
  1866. while (vring->swtail != new_swtail) {
  1867. struct vring_tx_desc dd, *d = &dd;
  1868. u16 dmalen;
  1869. struct sk_buff *skb;
  1870. ctx = &vring->ctx[vring->swtail];
  1871. skb = ctx->skb;
  1872. _d = &vring->va[vring->swtail].tx.legacy;
  1873. *d = *_d;
  1874. dmalen = le16_to_cpu(d->dma.length);
  1875. trace_wil6210_tx_done(ringid, vring->swtail, dmalen,
  1876. d->dma.error);
  1877. wil_dbg_txrx(wil,
  1878. "TxC[%2d][%3d] : %d bytes, status 0x%02x err 0x%02x\n",
  1879. ringid, vring->swtail, dmalen,
  1880. d->dma.status, d->dma.error);
  1881. wil_hex_dump_txrx("TxCD ", DUMP_PREFIX_NONE, 32, 4,
  1882. (const void *)d, sizeof(*d), false);
  1883. wil->txrx_ops.tx_desc_unmap(dev,
  1884. (union wil_tx_desc *)d,
  1885. ctx);
  1886. if (skb) {
  1887. if (likely(d->dma.error == 0)) {
  1888. ndev->stats.tx_packets++;
  1889. ndev->stats.tx_bytes += skb->len;
  1890. if (stats) {
  1891. stats->tx_packets++;
  1892. stats->tx_bytes += skb->len;
  1893. wil_tx_latency_calc(wil, skb,
  1894. &wil->sta[cid]);
  1895. }
  1896. } else {
  1897. ndev->stats.tx_errors++;
  1898. if (stats)
  1899. stats->tx_errors++;
  1900. }
  1901. wil_consume_skb(skb, d->dma.error == 0);
  1902. }
  1903. memset(ctx, 0, sizeof(*ctx));
  1904. /* Make sure the ctx is zeroed before updating the tail
  1905. * to prevent a case where wil_tx_ring will see
  1906. * this descriptor as used and handle it before ctx zero
  1907. * is completed.
  1908. */
  1909. wmb();
  1910. /* There is no need to touch HW descriptor:
  1911. * - ststus bit TX_DMA_STATUS_DU is set by design,
  1912. * so hardware will not try to process this desc.,
  1913. * - rest of descriptor will be initialized on Tx.
  1914. */
  1915. vring->swtail = wil_ring_next_tail(vring);
  1916. done++;
  1917. }
  1918. }
  1919. /* performance monitoring */
  1920. used_new = wil_ring_used_tx(vring);
  1921. if (wil_val_in_range(wil->ring_idle_trsh,
  1922. used_new, used_before_complete)) {
  1923. wil_dbg_txrx(wil, "Ring[%2d] idle %d -> %d\n",
  1924. ringid, used_before_complete, used_new);
  1925. txdata->last_idle = get_cycles();
  1926. }
  1927. /* shall we wake net queues? */
  1928. if (done)
  1929. wil_update_net_queues(wil, vif, vring, false);
  1930. return done;
  1931. }
  1932. static inline int wil_tx_init(struct wil6210_priv *wil)
  1933. {
  1934. return 0;
  1935. }
  1936. static inline void wil_tx_fini(struct wil6210_priv *wil) {}
  1937. static void wil_get_reorder_params(struct wil6210_priv *wil,
  1938. struct sk_buff *skb, int *tid, int *cid,
  1939. int *mid, u16 *seq, int *mcast, int *retry)
  1940. {
  1941. struct vring_rx_desc *d = wil_skb_rxdesc(skb);
  1942. *tid = wil_rxdesc_tid(d);
  1943. *cid = wil_rxdesc_cid(d);
  1944. *mid = wil_rxdesc_mid(d);
  1945. *seq = wil_rxdesc_seq(d);
  1946. *mcast = wil_rxdesc_mcast(d);
  1947. *retry = wil_rxdesc_retry(d);
  1948. }
  1949. void wil_init_txrx_ops_legacy_dma(struct wil6210_priv *wil)
  1950. {
  1951. wil->txrx_ops.configure_interrupt_moderation =
  1952. wil_configure_interrupt_moderation;
  1953. /* TX ops */
  1954. wil->txrx_ops.tx_desc_map = wil_tx_desc_map;
  1955. wil->txrx_ops.tx_desc_unmap = wil_txdesc_unmap;
  1956. wil->txrx_ops.tx_ring_tso = __wil_tx_vring_tso;
  1957. wil->txrx_ops.ring_init_tx = wil_vring_init_tx;
  1958. wil->txrx_ops.ring_fini_tx = wil_vring_free;
  1959. wil->txrx_ops.ring_init_bcast = wil_vring_init_bcast;
  1960. wil->txrx_ops.tx_init = wil_tx_init;
  1961. wil->txrx_ops.tx_fini = wil_tx_fini;
  1962. /* RX ops */
  1963. wil->txrx_ops.rx_init = wil_rx_init;
  1964. wil->txrx_ops.wmi_addba_rx_resp = wmi_addba_rx_resp;
  1965. wil->txrx_ops.get_reorder_params = wil_get_reorder_params;
  1966. wil->txrx_ops.get_netif_rx_params =
  1967. wil_get_netif_rx_params;
  1968. wil->txrx_ops.rx_crypto_check = wil_rx_crypto_check;
  1969. wil->txrx_ops.rx_error_check = wil_rx_error_check;
  1970. wil->txrx_ops.is_rx_idle = wil_is_rx_idle;
  1971. wil->txrx_ops.rx_fini = wil_rx_fini;
  1972. }