dp_tx.c 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695
  1. /*
  2. * Copyright (c) 2016-2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include "htt.h"
  19. #include "hal_hw_headers.h"
  20. #include "dp_tx.h"
  21. #include "dp_tx_desc.h"
  22. #include "dp_peer.h"
  23. #include "dp_types.h"
  24. #include "hal_tx.h"
  25. #include "qdf_mem.h"
  26. #include "qdf_nbuf.h"
  27. #include "qdf_net_types.h"
  28. #include <wlan_cfg.h>
  29. #ifdef MESH_MODE_SUPPORT
  30. #include "if_meta_hdr.h"
  31. #endif
  32. #define DP_TX_QUEUE_MASK 0x3
  33. /* TODO Add support in TSO */
  34. #define DP_DESC_NUM_FRAG(x) 0
  35. /* disable TQM_BYPASS */
  36. #define TQM_BYPASS_WAR 0
  37. /* invalid peer id for reinject*/
  38. #define DP_INVALID_PEER 0XFFFE
  39. /*mapping between hal encrypt type and cdp_sec_type*/
  40. #define MAX_CDP_SEC_TYPE 12
  41. static const uint8_t sec_type_map[MAX_CDP_SEC_TYPE] = {
  42. HAL_TX_ENCRYPT_TYPE_NO_CIPHER,
  43. HAL_TX_ENCRYPT_TYPE_WEP_128,
  44. HAL_TX_ENCRYPT_TYPE_WEP_104,
  45. HAL_TX_ENCRYPT_TYPE_WEP_40,
  46. HAL_TX_ENCRYPT_TYPE_TKIP_WITH_MIC,
  47. HAL_TX_ENCRYPT_TYPE_TKIP_NO_MIC,
  48. HAL_TX_ENCRYPT_TYPE_AES_CCMP_128,
  49. HAL_TX_ENCRYPT_TYPE_WAPI,
  50. HAL_TX_ENCRYPT_TYPE_AES_CCMP_256,
  51. HAL_TX_ENCRYPT_TYPE_AES_GCMP_128,
  52. HAL_TX_ENCRYPT_TYPE_AES_GCMP_256,
  53. HAL_TX_ENCRYPT_TYPE_WAPI_GCM_SM4};
  54. /**
  55. * dp_tx_get_queue() - Returns Tx queue IDs to be used for this Tx frame
  56. * @vdev: DP Virtual device handle
  57. * @nbuf: Buffer pointer
  58. * @queue: queue ids container for nbuf
  59. *
  60. * TX packet queue has 2 instances, software descriptors id and dma ring id
  61. * Based on tx feature and hardware configuration queue id combination could be
  62. * different.
  63. * For example -
  64. * With XPS enabled,all TX descriptor pools and dma ring are assigned per cpu id
  65. * With no XPS,lock based resource protection, Descriptor pool ids are different
  66. * for each vdev, dma ring id will be same as single pdev id
  67. *
  68. * Return: None
  69. */
  70. #ifdef QCA_OL_TX_MULTIQ_SUPPORT
  71. static inline void dp_tx_get_queue(struct dp_vdev *vdev,
  72. qdf_nbuf_t nbuf, struct dp_tx_queue *queue)
  73. {
  74. uint16_t queue_offset = qdf_nbuf_get_queue_mapping(nbuf) & DP_TX_QUEUE_MASK;
  75. queue->desc_pool_id = queue_offset;
  76. queue->ring_id = vdev->pdev->soc->tx_ring_map[queue_offset];
  77. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  78. "%s, pool_id:%d ring_id: %d",
  79. __func__, queue->desc_pool_id, queue->ring_id);
  80. return;
  81. }
  82. #else /* QCA_OL_TX_MULTIQ_SUPPORT */
  83. static inline void dp_tx_get_queue(struct dp_vdev *vdev,
  84. qdf_nbuf_t nbuf, struct dp_tx_queue *queue)
  85. {
  86. /* get flow id */
  87. queue->desc_pool_id = DP_TX_GET_DESC_POOL_ID(vdev);
  88. queue->ring_id = DP_TX_GET_RING_ID(vdev);
  89. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  90. "%s, pool_id:%d ring_id: %d",
  91. __func__, queue->desc_pool_id, queue->ring_id);
  92. return;
  93. }
  94. #endif
  95. #if defined(FEATURE_TSO)
  96. /**
  97. * dp_tx_tso_unmap_segment() - Unmap TSO segment
  98. *
  99. * @soc - core txrx main context
  100. * @tx_desc - Tx software descriptor
  101. */
  102. static void dp_tx_tso_unmap_segment(struct dp_soc *soc,
  103. struct dp_tx_desc_s *tx_desc)
  104. {
  105. TSO_DEBUG("%s: Unmap the tso segment", __func__);
  106. if (qdf_unlikely(!tx_desc->tso_desc)) {
  107. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  108. "%s %d TSO desc is NULL!",
  109. __func__, __LINE__);
  110. qdf_assert(0);
  111. } else if (qdf_unlikely(!tx_desc->tso_num_desc)) {
  112. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  113. "%s %d TSO num desc is NULL!",
  114. __func__, __LINE__);
  115. qdf_assert(0);
  116. } else {
  117. bool is_last_seg;
  118. struct qdf_tso_num_seg_elem_t *tso_num_desc =
  119. (struct qdf_tso_num_seg_elem_t *)tx_desc->tso_num_desc;
  120. if (tso_num_desc->num_seg.tso_cmn_num_seg > 1)
  121. is_last_seg = false;
  122. else
  123. is_last_seg = true;
  124. tso_num_desc->num_seg.tso_cmn_num_seg--;
  125. qdf_nbuf_unmap_tso_segment(soc->osdev,
  126. tx_desc->tso_desc, is_last_seg);
  127. }
  128. }
  129. /**
  130. * dp_tx_tso_desc_release() - Release the tso segment and tso_cmn_num_seg
  131. * back to the freelist
  132. *
  133. * @soc - soc device handle
  134. * @tx_desc - Tx software descriptor
  135. */
  136. static void dp_tx_tso_desc_release(struct dp_soc *soc,
  137. struct dp_tx_desc_s *tx_desc)
  138. {
  139. TSO_DEBUG("%s: Free the tso descriptor", __func__);
  140. if (qdf_unlikely(!tx_desc->tso_desc)) {
  141. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  142. "%s %d TSO desc is NULL!",
  143. __func__, __LINE__);
  144. qdf_assert(0);
  145. } else if (qdf_unlikely(!tx_desc->tso_num_desc)) {
  146. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  147. "%s %d TSO num desc is NULL!",
  148. __func__, __LINE__);
  149. qdf_assert(0);
  150. } else {
  151. struct qdf_tso_num_seg_elem_t *tso_num_desc =
  152. (struct qdf_tso_num_seg_elem_t *)tx_desc->tso_num_desc;
  153. /* Add the tso num segment into the free list */
  154. if (tso_num_desc->num_seg.tso_cmn_num_seg == 0) {
  155. dp_tso_num_seg_free(soc, tx_desc->pool_id,
  156. tx_desc->tso_num_desc);
  157. tx_desc->tso_num_desc = NULL;
  158. }
  159. /* Add the tso segment into the free list*/
  160. dp_tx_tso_desc_free(soc,
  161. tx_desc->pool_id, tx_desc->tso_desc);
  162. tx_desc->tso_desc = NULL;
  163. }
  164. }
  165. #else
  166. static void dp_tx_tso_unmap_segment(struct dp_soc *soc,
  167. struct dp_tx_desc_s *tx_desc)
  168. {
  169. }
  170. static void dp_tx_tso_desc_release(struct dp_soc *soc,
  171. struct dp_tx_desc_s *tx_desc)
  172. {
  173. }
  174. #endif
  175. /**
  176. * dp_tx_desc_release() - Release Tx Descriptor
  177. * @tx_desc : Tx Descriptor
  178. * @desc_pool_id: Descriptor Pool ID
  179. *
  180. * Deallocate all resources attached to Tx descriptor and free the Tx
  181. * descriptor.
  182. *
  183. * Return:
  184. */
  185. static void
  186. dp_tx_desc_release(struct dp_tx_desc_s *tx_desc, uint8_t desc_pool_id)
  187. {
  188. struct dp_pdev *pdev = tx_desc->pdev;
  189. struct dp_soc *soc;
  190. uint8_t comp_status = 0;
  191. qdf_assert(pdev);
  192. soc = pdev->soc;
  193. if (tx_desc->frm_type == dp_tx_frm_tso)
  194. dp_tx_tso_desc_release(soc, tx_desc);
  195. if (tx_desc->flags & DP_TX_DESC_FLAG_FRAG)
  196. dp_tx_ext_desc_free(soc, tx_desc->msdu_ext_desc, desc_pool_id);
  197. if (tx_desc->flags & DP_TX_DESC_FLAG_ME)
  198. dp_tx_me_free_buf(tx_desc->pdev, tx_desc->me_buffer);
  199. qdf_atomic_dec(&pdev->num_tx_outstanding);
  200. if (tx_desc->flags & DP_TX_DESC_FLAG_TO_FW)
  201. qdf_atomic_dec(&pdev->num_tx_exception);
  202. if (HAL_TX_COMP_RELEASE_SOURCE_TQM ==
  203. hal_tx_comp_get_buffer_source(&tx_desc->comp))
  204. comp_status = hal_tx_comp_get_release_reason(&tx_desc->comp);
  205. else
  206. comp_status = HAL_TX_COMP_RELEASE_REASON_FW;
  207. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  208. "Tx Completion Release desc %d status %d outstanding %d",
  209. tx_desc->id, comp_status,
  210. qdf_atomic_read(&pdev->num_tx_outstanding));
  211. dp_tx_desc_free(soc, tx_desc, desc_pool_id);
  212. return;
  213. }
  214. /**
  215. * dp_tx_htt_metadata_prepare() - Prepare HTT metadata for special frames
  216. * @vdev: DP vdev Handle
  217. * @nbuf: skb
  218. *
  219. * Prepares and fills HTT metadata in the frame pre-header for special frames
  220. * that should be transmitted using varying transmit parameters.
  221. * There are 2 VDEV modes that currently needs this special metadata -
  222. * 1) Mesh Mode
  223. * 2) DSRC Mode
  224. *
  225. * Return: HTT metadata size
  226. *
  227. */
  228. static uint8_t dp_tx_prepare_htt_metadata(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  229. uint32_t *meta_data)
  230. {
  231. struct htt_tx_msdu_desc_ext2_t *desc_ext =
  232. (struct htt_tx_msdu_desc_ext2_t *) meta_data;
  233. uint8_t htt_desc_size;
  234. /* Size rounded of multiple of 8 bytes */
  235. uint8_t htt_desc_size_aligned;
  236. uint8_t *hdr = NULL;
  237. /*
  238. * Metadata - HTT MSDU Extension header
  239. */
  240. htt_desc_size = sizeof(struct htt_tx_msdu_desc_ext2_t);
  241. htt_desc_size_aligned = (htt_desc_size + 7) & ~0x7;
  242. if (vdev->mesh_vdev) {
  243. /* Fill and add HTT metaheader */
  244. hdr = qdf_nbuf_push_head(nbuf, htt_desc_size_aligned);
  245. if (hdr == NULL) {
  246. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  247. "Error in filling HTT metadata\n");
  248. return 0;
  249. }
  250. qdf_mem_copy(hdr, desc_ext, htt_desc_size);
  251. } else if (vdev->opmode == wlan_op_mode_ocb) {
  252. /* Todo - Add support for DSRC */
  253. }
  254. return htt_desc_size_aligned;
  255. }
  256. /**
  257. * dp_tx_prepare_tso_ext_desc() - Prepare MSDU extension descriptor for TSO
  258. * @tso_seg: TSO segment to process
  259. * @ext_desc: Pointer to MSDU extension descriptor
  260. *
  261. * Return: void
  262. */
  263. #if defined(FEATURE_TSO)
  264. static void dp_tx_prepare_tso_ext_desc(struct qdf_tso_seg_t *tso_seg,
  265. void *ext_desc)
  266. {
  267. uint8_t num_frag;
  268. uint32_t tso_flags;
  269. /*
  270. * Set tso_en, tcp_flags(NS, CWR, ECE, URG, ACK, PSH, RST, SYN, FIN),
  271. * tcp_flag_mask
  272. *
  273. * Checksum enable flags are set in TCL descriptor and not in Extension
  274. * Descriptor (H/W ignores checksum_en flags in MSDU ext descriptor)
  275. */
  276. tso_flags = *(uint32_t *) &tso_seg->tso_flags;
  277. hal_tx_ext_desc_set_tso_flags(ext_desc, tso_flags);
  278. hal_tx_ext_desc_set_msdu_length(ext_desc, tso_seg->tso_flags.l2_len,
  279. tso_seg->tso_flags.ip_len);
  280. hal_tx_ext_desc_set_tcp_seq(ext_desc, tso_seg->tso_flags.tcp_seq_num);
  281. hal_tx_ext_desc_set_ip_id(ext_desc, tso_seg->tso_flags.ip_id);
  282. for (num_frag = 0; num_frag < tso_seg->num_frags; num_frag++) {
  283. uint32_t lo = 0;
  284. uint32_t hi = 0;
  285. qdf_dmaaddr_to_32s(
  286. tso_seg->tso_frags[num_frag].paddr, &lo, &hi);
  287. hal_tx_ext_desc_set_buffer(ext_desc, num_frag, lo, hi,
  288. tso_seg->tso_frags[num_frag].length);
  289. }
  290. return;
  291. }
  292. #else
  293. static void dp_tx_prepare_tso_ext_desc(struct qdf_tso_seg_t *tso_seg,
  294. void *ext_desc)
  295. {
  296. return;
  297. }
  298. #endif
  299. #if defined(FEATURE_TSO)
  300. /**
  301. * dp_tx_free_tso_seg() - Loop through the tso segments
  302. * allocated and free them
  303. *
  304. * @soc: soc handle
  305. * @free_seg: list of tso segments
  306. * @msdu_info: msdu descriptor
  307. *
  308. * Return - void
  309. */
  310. static void dp_tx_free_tso_seg(struct dp_soc *soc,
  311. struct qdf_tso_seg_elem_t *free_seg,
  312. struct dp_tx_msdu_info_s *msdu_info)
  313. {
  314. struct qdf_tso_seg_elem_t *next_seg;
  315. while (free_seg) {
  316. next_seg = free_seg->next;
  317. dp_tx_tso_desc_free(soc,
  318. msdu_info->tx_queue.desc_pool_id,
  319. free_seg);
  320. free_seg = next_seg;
  321. }
  322. }
  323. /**
  324. * dp_tx_free_tso_num_seg() - Loop through the tso num segments
  325. * allocated and free them
  326. *
  327. * @soc: soc handle
  328. * @free_seg: list of tso segments
  329. * @msdu_info: msdu descriptor
  330. * Return - void
  331. */
  332. static void dp_tx_free_tso_num_seg(struct dp_soc *soc,
  333. struct qdf_tso_num_seg_elem_t *free_seg,
  334. struct dp_tx_msdu_info_s *msdu_info)
  335. {
  336. struct qdf_tso_num_seg_elem_t *next_seg;
  337. while (free_seg) {
  338. next_seg = free_seg->next;
  339. dp_tso_num_seg_free(soc,
  340. msdu_info->tx_queue.desc_pool_id,
  341. free_seg);
  342. free_seg = next_seg;
  343. }
  344. }
  345. /**
  346. * dp_tx_prepare_tso() - Given a jumbo msdu, prepare the TSO info
  347. * @vdev: virtual device handle
  348. * @msdu: network buffer
  349. * @msdu_info: meta data associated with the msdu
  350. *
  351. * Return: QDF_STATUS_SUCCESS success
  352. */
  353. static QDF_STATUS dp_tx_prepare_tso(struct dp_vdev *vdev,
  354. qdf_nbuf_t msdu, struct dp_tx_msdu_info_s *msdu_info)
  355. {
  356. struct qdf_tso_seg_elem_t *tso_seg;
  357. int num_seg = qdf_nbuf_get_tso_num_seg(msdu);
  358. struct dp_soc *soc = vdev->pdev->soc;
  359. struct qdf_tso_info_t *tso_info;
  360. struct qdf_tso_num_seg_elem_t *tso_num_seg;
  361. tso_info = &msdu_info->u.tso_info;
  362. tso_info->curr_seg = NULL;
  363. tso_info->tso_seg_list = NULL;
  364. tso_info->num_segs = num_seg;
  365. msdu_info->frm_type = dp_tx_frm_tso;
  366. tso_info->tso_num_seg_list = NULL;
  367. TSO_DEBUG(" %s: num_seg: %d", __func__, num_seg);
  368. while (num_seg) {
  369. tso_seg = dp_tx_tso_desc_alloc(
  370. soc, msdu_info->tx_queue.desc_pool_id);
  371. if (tso_seg) {
  372. tso_seg->next = tso_info->tso_seg_list;
  373. tso_info->tso_seg_list = tso_seg;
  374. num_seg--;
  375. } else {
  376. struct qdf_tso_seg_elem_t *free_seg =
  377. tso_info->tso_seg_list;
  378. dp_tx_free_tso_seg(soc, free_seg, msdu_info);
  379. return QDF_STATUS_E_NOMEM;
  380. }
  381. }
  382. TSO_DEBUG(" %s: num_seg: %d", __func__, num_seg);
  383. tso_num_seg = dp_tso_num_seg_alloc(soc,
  384. msdu_info->tx_queue.desc_pool_id);
  385. if (tso_num_seg) {
  386. tso_num_seg->next = tso_info->tso_num_seg_list;
  387. tso_info->tso_num_seg_list = tso_num_seg;
  388. } else {
  389. /* Bug: free tso_num_seg and tso_seg */
  390. /* Free the already allocated num of segments */
  391. struct qdf_tso_seg_elem_t *free_seg =
  392. tso_info->tso_seg_list;
  393. TSO_DEBUG(" %s: Failed alloc - Number of segs for a TSO packet",
  394. __func__);
  395. dp_tx_free_tso_seg(soc, free_seg, msdu_info);
  396. return QDF_STATUS_E_NOMEM;
  397. }
  398. msdu_info->num_seg =
  399. qdf_nbuf_get_tso_info(soc->osdev, msdu, tso_info);
  400. TSO_DEBUG(" %s: msdu_info->num_seg: %d", __func__,
  401. msdu_info->num_seg);
  402. if (!(msdu_info->num_seg)) {
  403. dp_tx_free_tso_seg(soc, tso_info->tso_seg_list, msdu_info);
  404. dp_tx_free_tso_num_seg(soc, tso_info->tso_num_seg_list,
  405. msdu_info);
  406. return QDF_STATUS_E_INVAL;
  407. }
  408. tso_info->curr_seg = tso_info->tso_seg_list;
  409. return QDF_STATUS_SUCCESS;
  410. }
  411. #else
  412. static QDF_STATUS dp_tx_prepare_tso(struct dp_vdev *vdev,
  413. qdf_nbuf_t msdu, struct dp_tx_msdu_info_s *msdu_info)
  414. {
  415. return QDF_STATUS_E_NOMEM;
  416. }
  417. #endif
  418. /**
  419. * dp_tx_prepare_ext_desc() - Allocate and prepare MSDU extension descriptor
  420. * @vdev: DP Vdev handle
  421. * @msdu_info: MSDU info to be setup in MSDU extension descriptor
  422. * @desc_pool_id: Descriptor Pool ID
  423. *
  424. * Return:
  425. */
  426. static
  427. struct dp_tx_ext_desc_elem_s *dp_tx_prepare_ext_desc(struct dp_vdev *vdev,
  428. struct dp_tx_msdu_info_s *msdu_info, uint8_t desc_pool_id)
  429. {
  430. uint8_t i;
  431. uint8_t cached_ext_desc[HAL_TX_EXT_DESC_WITH_META_DATA];
  432. struct dp_tx_seg_info_s *seg_info;
  433. struct dp_tx_ext_desc_elem_s *msdu_ext_desc;
  434. struct dp_soc *soc = vdev->pdev->soc;
  435. /* Allocate an extension descriptor */
  436. msdu_ext_desc = dp_tx_ext_desc_alloc(soc, desc_pool_id);
  437. qdf_mem_zero(&cached_ext_desc[0], HAL_TX_EXT_DESC_WITH_META_DATA);
  438. if (!msdu_ext_desc) {
  439. DP_STATS_INC(vdev, tx_i.dropped.desc_na.num, 1);
  440. return NULL;
  441. }
  442. if (msdu_info->exception_fw &&
  443. qdf_unlikely(vdev->mesh_vdev)) {
  444. qdf_mem_copy(&cached_ext_desc[HAL_TX_EXTENSION_DESC_LEN_BYTES],
  445. &msdu_info->meta_data[0],
  446. sizeof(struct htt_tx_msdu_desc_ext2_t));
  447. qdf_atomic_inc(&vdev->pdev->num_tx_exception);
  448. }
  449. switch (msdu_info->frm_type) {
  450. case dp_tx_frm_sg:
  451. case dp_tx_frm_me:
  452. case dp_tx_frm_raw:
  453. seg_info = msdu_info->u.sg_info.curr_seg;
  454. /* Update the buffer pointers in MSDU Extension Descriptor */
  455. for (i = 0; i < seg_info->frag_cnt; i++) {
  456. hal_tx_ext_desc_set_buffer(&cached_ext_desc[0], i,
  457. seg_info->frags[i].paddr_lo,
  458. seg_info->frags[i].paddr_hi,
  459. seg_info->frags[i].len);
  460. }
  461. break;
  462. case dp_tx_frm_tso:
  463. dp_tx_prepare_tso_ext_desc(&msdu_info->u.tso_info.curr_seg->seg,
  464. &cached_ext_desc[0]);
  465. break;
  466. default:
  467. break;
  468. }
  469. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  470. cached_ext_desc, HAL_TX_EXT_DESC_WITH_META_DATA);
  471. hal_tx_ext_desc_sync(&cached_ext_desc[0],
  472. msdu_ext_desc->vaddr);
  473. return msdu_ext_desc;
  474. }
  475. /**
  476. * dp_tx_trace_pkt() - Trace TX packet at DP layer
  477. *
  478. * @skb: skb to be traced
  479. * @msdu_id: msdu_id of the packet
  480. * @vdev_id: vdev_id of the packet
  481. *
  482. * Return: None
  483. */
  484. static void dp_tx_trace_pkt(qdf_nbuf_t skb, uint16_t msdu_id,
  485. uint8_t vdev_id)
  486. {
  487. QDF_NBUF_CB_TX_PACKET_TRACK(skb) = QDF_NBUF_TX_PKT_DATA_TRACK;
  488. QDF_NBUF_CB_TX_DP_TRACE(skb) = 1;
  489. DPTRACE(qdf_dp_trace_ptr(skb,
  490. QDF_DP_TRACE_LI_DP_TX_PACKET_PTR_RECORD,
  491. QDF_TRACE_DEFAULT_PDEV_ID,
  492. qdf_nbuf_data_addr(skb),
  493. sizeof(qdf_nbuf_data(skb)),
  494. msdu_id, vdev_id));
  495. qdf_dp_trace_log_pkt(vdev_id, skb, QDF_TX, QDF_TRACE_DEFAULT_PDEV_ID);
  496. DPTRACE(qdf_dp_trace_data_pkt(skb, QDF_TRACE_DEFAULT_PDEV_ID,
  497. QDF_DP_TRACE_LI_DP_TX_PACKET_RECORD,
  498. msdu_id, QDF_TX));
  499. }
  500. /**
  501. * dp_tx_desc_prepare_single - Allocate and prepare Tx descriptor
  502. * @vdev: DP vdev handle
  503. * @nbuf: skb
  504. * @desc_pool_id: Descriptor pool ID
  505. * @meta_data: Metadata to the fw
  506. * @tx_exc_metadata: Handle that holds exception path metadata
  507. * Allocate and prepare Tx descriptor with msdu information.
  508. *
  509. * Return: Pointer to Tx Descriptor on success,
  510. * NULL on failure
  511. */
  512. static
  513. struct dp_tx_desc_s *dp_tx_prepare_desc_single(struct dp_vdev *vdev,
  514. qdf_nbuf_t nbuf, uint8_t desc_pool_id,
  515. struct dp_tx_msdu_info_s *msdu_info,
  516. struct cdp_tx_exception_metadata *tx_exc_metadata)
  517. {
  518. uint8_t align_pad;
  519. uint8_t is_exception = 0;
  520. uint8_t htt_hdr_size;
  521. struct ether_header *eh;
  522. struct dp_tx_desc_s *tx_desc;
  523. struct dp_pdev *pdev = vdev->pdev;
  524. struct dp_soc *soc = pdev->soc;
  525. /* Allocate software Tx descriptor */
  526. tx_desc = dp_tx_desc_alloc(soc, desc_pool_id);
  527. if (qdf_unlikely(!tx_desc)) {
  528. DP_STATS_INC(vdev, tx_i.dropped.desc_na.num, 1);
  529. return NULL;
  530. }
  531. /* Flow control/Congestion Control counters */
  532. qdf_atomic_inc(&pdev->num_tx_outstanding);
  533. /* Initialize the SW tx descriptor */
  534. tx_desc->nbuf = nbuf;
  535. tx_desc->frm_type = dp_tx_frm_std;
  536. tx_desc->tx_encap_type = (tx_exc_metadata ?
  537. tx_exc_metadata->tx_encap_type : vdev->tx_encap_type);
  538. tx_desc->vdev = vdev;
  539. tx_desc->pdev = pdev;
  540. tx_desc->msdu_ext_desc = NULL;
  541. tx_desc->pkt_offset = 0;
  542. dp_tx_trace_pkt(nbuf, tx_desc->id, vdev->vdev_id);
  543. /*
  544. * For special modes (vdev_type == ocb or mesh), data frames should be
  545. * transmitted using varying transmit parameters (tx spec) which include
  546. * transmit rate, power, priority, channel, channel bandwidth , nss etc.
  547. * These are filled in HTT MSDU descriptor and sent in frame pre-header.
  548. * These frames are sent as exception packets to firmware.
  549. *
  550. * HW requirement is that metadata should always point to a
  551. * 8-byte aligned address. So we add alignment pad to start of buffer.
  552. * HTT Metadata should be ensured to be multiple of 8-bytes,
  553. * to get 8-byte aligned start address along with align_pad added
  554. *
  555. * |-----------------------------|
  556. * | |
  557. * |-----------------------------| <-----Buffer Pointer Address given
  558. * | | ^ in HW descriptor (aligned)
  559. * | HTT Metadata | |
  560. * | | |
  561. * | | | Packet Offset given in descriptor
  562. * | | |
  563. * |-----------------------------| |
  564. * | Alignment Pad | v
  565. * |-----------------------------| <----- Actual buffer start address
  566. * | SKB Data | (Unaligned)
  567. * | |
  568. * | |
  569. * | |
  570. * | |
  571. * | |
  572. * |-----------------------------|
  573. */
  574. if (qdf_unlikely((msdu_info->exception_fw)) ||
  575. (vdev->opmode == wlan_op_mode_ocb)) {
  576. align_pad = ((unsigned long) qdf_nbuf_data(nbuf)) & 0x7;
  577. if (qdf_nbuf_push_head(nbuf, align_pad) == NULL) {
  578. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  579. "qdf_nbuf_push_head failed\n");
  580. goto failure;
  581. }
  582. htt_hdr_size = dp_tx_prepare_htt_metadata(vdev, nbuf,
  583. msdu_info->meta_data);
  584. if (htt_hdr_size == 0)
  585. goto failure;
  586. tx_desc->pkt_offset = align_pad + htt_hdr_size;
  587. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  588. is_exception = 1;
  589. }
  590. if (qdf_unlikely(QDF_STATUS_SUCCESS !=
  591. qdf_nbuf_map(soc->osdev, nbuf,
  592. QDF_DMA_TO_DEVICE))) {
  593. /* Handle failure */
  594. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  595. "qdf_nbuf_map failed\n");
  596. DP_STATS_INC(vdev, tx_i.dropped.dma_error, 1);
  597. goto failure;
  598. }
  599. if (qdf_unlikely(vdev->nawds_enabled)) {
  600. eh = (struct ether_header *) qdf_nbuf_data(nbuf);
  601. if (DP_FRAME_IS_MULTICAST((eh)->ether_dhost)) {
  602. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  603. is_exception = 1;
  604. }
  605. }
  606. #if !TQM_BYPASS_WAR
  607. if (is_exception || tx_exc_metadata)
  608. #endif
  609. {
  610. /* Temporary WAR due to TQM VP issues */
  611. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  612. qdf_atomic_inc(&pdev->num_tx_exception);
  613. }
  614. return tx_desc;
  615. failure:
  616. dp_tx_desc_release(tx_desc, desc_pool_id);
  617. return NULL;
  618. }
  619. /**
  620. * dp_tx_prepare_desc() - Allocate and prepare Tx descriptor for multisegment frame
  621. * @vdev: DP vdev handle
  622. * @nbuf: skb
  623. * @msdu_info: Info to be setup in MSDU descriptor and MSDU extension descriptor
  624. * @desc_pool_id : Descriptor Pool ID
  625. *
  626. * Allocate and prepare Tx descriptor with msdu and fragment descritor
  627. * information. For frames wth fragments, allocate and prepare
  628. * an MSDU extension descriptor
  629. *
  630. * Return: Pointer to Tx Descriptor on success,
  631. * NULL on failure
  632. */
  633. static struct dp_tx_desc_s *dp_tx_prepare_desc(struct dp_vdev *vdev,
  634. qdf_nbuf_t nbuf, struct dp_tx_msdu_info_s *msdu_info,
  635. uint8_t desc_pool_id)
  636. {
  637. struct dp_tx_desc_s *tx_desc;
  638. struct dp_tx_ext_desc_elem_s *msdu_ext_desc;
  639. struct dp_pdev *pdev = vdev->pdev;
  640. struct dp_soc *soc = pdev->soc;
  641. /* Allocate software Tx descriptor */
  642. tx_desc = dp_tx_desc_alloc(soc, desc_pool_id);
  643. if (!tx_desc) {
  644. DP_STATS_INC(vdev, tx_i.dropped.desc_na.num, 1);
  645. return NULL;
  646. }
  647. /* Flow control/Congestion Control counters */
  648. qdf_atomic_inc(&pdev->num_tx_outstanding);
  649. /* Initialize the SW tx descriptor */
  650. tx_desc->nbuf = nbuf;
  651. tx_desc->frm_type = msdu_info->frm_type;
  652. tx_desc->tx_encap_type = vdev->tx_encap_type;
  653. tx_desc->vdev = vdev;
  654. tx_desc->pdev = pdev;
  655. tx_desc->pkt_offset = 0;
  656. tx_desc->tso_desc = msdu_info->u.tso_info.curr_seg;
  657. tx_desc->tso_num_desc = msdu_info->u.tso_info.tso_num_seg_list;
  658. dp_tx_trace_pkt(nbuf, tx_desc->id, vdev->vdev_id);
  659. /* Handle scattered frames - TSO/SG/ME */
  660. /* Allocate and prepare an extension descriptor for scattered frames */
  661. msdu_ext_desc = dp_tx_prepare_ext_desc(vdev, msdu_info, desc_pool_id);
  662. if (!msdu_ext_desc) {
  663. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  664. "%s Tx Extension Descriptor Alloc Fail\n",
  665. __func__);
  666. goto failure;
  667. }
  668. #if TQM_BYPASS_WAR
  669. /* Temporary WAR due to TQM VP issues */
  670. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  671. qdf_atomic_inc(&pdev->num_tx_exception);
  672. #endif
  673. if (qdf_unlikely(msdu_info->exception_fw))
  674. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  675. tx_desc->msdu_ext_desc = msdu_ext_desc;
  676. tx_desc->flags |= DP_TX_DESC_FLAG_FRAG;
  677. return tx_desc;
  678. failure:
  679. dp_tx_desc_release(tx_desc, desc_pool_id);
  680. return NULL;
  681. }
  682. /**
  683. * dp_tx_prepare_raw() - Prepare RAW packet TX
  684. * @vdev: DP vdev handle
  685. * @nbuf: buffer pointer
  686. * @seg_info: Pointer to Segment info Descriptor to be prepared
  687. * @msdu_info: MSDU info to be setup in MSDU descriptor and MSDU extension
  688. * descriptor
  689. *
  690. * Return:
  691. */
  692. static qdf_nbuf_t dp_tx_prepare_raw(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  693. struct dp_tx_seg_info_s *seg_info, struct dp_tx_msdu_info_s *msdu_info)
  694. {
  695. qdf_nbuf_t curr_nbuf = NULL;
  696. uint16_t total_len = 0;
  697. qdf_dma_addr_t paddr;
  698. int32_t i;
  699. int32_t mapped_buf_num = 0;
  700. struct dp_tx_sg_info_s *sg_info = &msdu_info->u.sg_info;
  701. qdf_dot3_qosframe_t *qos_wh = (qdf_dot3_qosframe_t *) nbuf->data;
  702. DP_STATS_INC_PKT(vdev, tx_i.raw.raw_pkt, 1, qdf_nbuf_len(nbuf));
  703. /* SWAR for HW: Enable WEP bit in the AMSDU frames for RAW mode */
  704. if (qos_wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_QOS)
  705. qos_wh->i_fc[1] |= IEEE80211_FC1_WEP;
  706. for (curr_nbuf = nbuf, i = 0; curr_nbuf;
  707. curr_nbuf = qdf_nbuf_next(curr_nbuf), i++) {
  708. if (QDF_STATUS_SUCCESS != qdf_nbuf_map(vdev->osdev, curr_nbuf,
  709. QDF_DMA_TO_DEVICE)) {
  710. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  711. "%s dma map error \n", __func__);
  712. DP_STATS_INC(vdev, tx_i.raw.dma_map_error, 1);
  713. mapped_buf_num = i;
  714. goto error;
  715. }
  716. paddr = qdf_nbuf_get_frag_paddr(curr_nbuf, 0);
  717. seg_info->frags[i].paddr_lo = paddr;
  718. seg_info->frags[i].paddr_hi = ((uint64_t)paddr >> 32);
  719. seg_info->frags[i].len = qdf_nbuf_len(curr_nbuf);
  720. seg_info->frags[i].vaddr = (void *) curr_nbuf;
  721. total_len += qdf_nbuf_len(curr_nbuf);
  722. }
  723. seg_info->frag_cnt = i;
  724. seg_info->total_len = total_len;
  725. seg_info->next = NULL;
  726. sg_info->curr_seg = seg_info;
  727. msdu_info->frm_type = dp_tx_frm_raw;
  728. msdu_info->num_seg = 1;
  729. return nbuf;
  730. error:
  731. i = 0;
  732. while (nbuf) {
  733. curr_nbuf = nbuf;
  734. if (i < mapped_buf_num) {
  735. qdf_nbuf_unmap(vdev->osdev, curr_nbuf, QDF_DMA_TO_DEVICE);
  736. i++;
  737. }
  738. nbuf = qdf_nbuf_next(nbuf);
  739. qdf_nbuf_free(curr_nbuf);
  740. }
  741. return NULL;
  742. }
  743. /**
  744. * dp_tx_hw_enqueue() - Enqueue to TCL HW for transmit
  745. * @soc: DP Soc Handle
  746. * @vdev: DP vdev handle
  747. * @tx_desc: Tx Descriptor Handle
  748. * @tid: TID from HLOS for overriding default DSCP-TID mapping
  749. * @fw_metadata: Metadata to send to Target Firmware along with frame
  750. * @ring_id: Ring ID of H/W ring to which we enqueue the packet
  751. * @tx_exc_metadata: Handle that holds exception path meta data
  752. *
  753. * Gets the next free TCL HW DMA descriptor and sets up required parameters
  754. * from software Tx descriptor
  755. *
  756. * Return:
  757. */
  758. static QDF_STATUS dp_tx_hw_enqueue(struct dp_soc *soc, struct dp_vdev *vdev,
  759. struct dp_tx_desc_s *tx_desc, uint8_t tid,
  760. uint16_t fw_metadata, uint8_t ring_id,
  761. struct cdp_tx_exception_metadata
  762. *tx_exc_metadata)
  763. {
  764. uint8_t type;
  765. uint16_t length;
  766. void *hal_tx_desc, *hal_tx_desc_cached;
  767. qdf_dma_addr_t dma_addr;
  768. uint8_t cached_desc[HAL_TX_DESC_LEN_BYTES];
  769. enum cdp_sec_type sec_type = (tx_exc_metadata ?
  770. tx_exc_metadata->sec_type : vdev->sec_type);
  771. /* Return Buffer Manager ID */
  772. uint8_t bm_id = ring_id;
  773. void *hal_srng = soc->tcl_data_ring[ring_id].hal_srng;
  774. hal_tx_desc_cached = (void *) cached_desc;
  775. qdf_mem_zero_outline(hal_tx_desc_cached, HAL_TX_DESC_LEN_BYTES);
  776. if (tx_desc->flags & DP_TX_DESC_FLAG_FRAG) {
  777. length = HAL_TX_EXT_DESC_WITH_META_DATA;
  778. type = HAL_TX_BUF_TYPE_EXT_DESC;
  779. dma_addr = tx_desc->msdu_ext_desc->paddr;
  780. } else {
  781. length = qdf_nbuf_len(tx_desc->nbuf) - tx_desc->pkt_offset;
  782. type = HAL_TX_BUF_TYPE_BUFFER;
  783. dma_addr = qdf_nbuf_mapped_paddr_get(tx_desc->nbuf);
  784. }
  785. hal_tx_desc_set_fw_metadata(hal_tx_desc_cached, fw_metadata);
  786. hal_tx_desc_set_buf_addr(hal_tx_desc_cached,
  787. dma_addr , bm_id, tx_desc->id, type);
  788. if (!dp_tx_is_desc_id_valid(soc, tx_desc->id))
  789. return QDF_STATUS_E_RESOURCES;
  790. hal_tx_desc_set_buf_length(hal_tx_desc_cached, length);
  791. hal_tx_desc_set_buf_offset(hal_tx_desc_cached, tx_desc->pkt_offset);
  792. hal_tx_desc_set_encap_type(hal_tx_desc_cached, tx_desc->tx_encap_type);
  793. hal_tx_desc_set_lmac_id(soc->hal_soc, hal_tx_desc_cached,
  794. HAL_TX_DESC_DEFAULT_LMAC_ID);
  795. hal_tx_desc_set_dscp_tid_table_id(soc->hal_soc, hal_tx_desc_cached,
  796. vdev->dscp_tid_map_id);
  797. hal_tx_desc_set_encrypt_type(hal_tx_desc_cached,
  798. sec_type_map[sec_type]);
  799. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  800. "%s length:%d , type = %d, dma_addr %llx, offset %d desc id %u",
  801. __func__, length, type, (uint64_t)dma_addr,
  802. tx_desc->pkt_offset, tx_desc->id);
  803. if (tx_desc->flags & DP_TX_DESC_FLAG_TO_FW)
  804. hal_tx_desc_set_to_fw(hal_tx_desc_cached, 1);
  805. hal_tx_desc_set_addr_search_flags(hal_tx_desc_cached,
  806. vdev->hal_desc_addr_search_flags);
  807. /* verify checksum offload configuration*/
  808. if ((wlan_cfg_get_checksum_offload(soc->wlan_cfg_ctx)) &&
  809. ((qdf_nbuf_get_tx_cksum(tx_desc->nbuf) == QDF_NBUF_TX_CKSUM_TCP_UDP)
  810. || qdf_nbuf_is_tso(tx_desc->nbuf))) {
  811. hal_tx_desc_set_l3_checksum_en(hal_tx_desc_cached, 1);
  812. hal_tx_desc_set_l4_checksum_en(hal_tx_desc_cached, 1);
  813. }
  814. if (tid != HTT_TX_EXT_TID_INVALID)
  815. hal_tx_desc_set_hlos_tid(hal_tx_desc_cached, tid);
  816. if (tx_desc->flags & DP_TX_DESC_FLAG_MESH)
  817. hal_tx_desc_set_mesh_en(hal_tx_desc_cached, 1);
  818. /* Sync cached descriptor with HW */
  819. hal_tx_desc = hal_srng_src_get_next(soc->hal_soc, hal_srng);
  820. if (!hal_tx_desc) {
  821. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  822. "%s TCL ring full ring_id:%d\n", __func__, ring_id);
  823. DP_STATS_INC(soc, tx.tcl_ring_full[ring_id], 1);
  824. DP_STATS_INC(vdev, tx_i.dropped.enqueue_fail, 1);
  825. return QDF_STATUS_E_RESOURCES;
  826. }
  827. tx_desc->flags |= DP_TX_DESC_FLAG_QUEUED_TX;
  828. hal_tx_desc_sync(hal_tx_desc_cached, hal_tx_desc);
  829. DP_STATS_INC_PKT(vdev, tx_i.processed, 1, length);
  830. /*
  831. * If one packet is enqueued in HW, PM usage count needs to be
  832. * incremented by one to prevent future runtime suspend. This
  833. * should be tied with the success of enqueuing. It will be
  834. * decremented after the packet has been sent.
  835. */
  836. hif_pm_runtime_get_noresume(soc->hif_handle);
  837. return QDF_STATUS_SUCCESS;
  838. }
  839. /**
  840. * dp_cce_classify() - Classify the frame based on CCE rules
  841. * @vdev: DP vdev handle
  842. * @nbuf: skb
  843. *
  844. * Classify frames based on CCE rules
  845. * Return: bool( true if classified,
  846. * else false)
  847. */
  848. static bool dp_cce_classify(struct dp_vdev *vdev, qdf_nbuf_t nbuf)
  849. {
  850. struct ether_header *eh = NULL;
  851. uint16_t ether_type;
  852. qdf_llc_t *llcHdr;
  853. qdf_nbuf_t nbuf_clone = NULL;
  854. qdf_dot3_qosframe_t *qos_wh = NULL;
  855. /* for mesh packets don't do any classification */
  856. if (qdf_unlikely(vdev->mesh_vdev))
  857. return false;
  858. if (qdf_likely(vdev->tx_encap_type != htt_cmn_pkt_type_raw)) {
  859. eh = (struct ether_header *) qdf_nbuf_data(nbuf);
  860. ether_type = eh->ether_type;
  861. llcHdr = (qdf_llc_t *)(nbuf->data +
  862. sizeof(struct ether_header));
  863. } else {
  864. qos_wh = (qdf_dot3_qosframe_t *) nbuf->data;
  865. /* For encrypted packets don't do any classification */
  866. if (qdf_unlikely(qos_wh->i_fc[1] & IEEE80211_FC1_WEP))
  867. return false;
  868. if (qdf_unlikely(qos_wh->i_fc[0] & QDF_IEEE80211_FC0_SUBTYPE_QOS)) {
  869. if (qdf_unlikely(
  870. qos_wh->i_fc[1] & QDF_IEEE80211_FC1_TODS &&
  871. qos_wh->i_fc[1] & QDF_IEEE80211_FC1_FROMDS)) {
  872. ether_type = *(uint16_t *)(nbuf->data
  873. + QDF_IEEE80211_4ADDR_HDR_LEN
  874. + sizeof(qdf_llc_t)
  875. - sizeof(ether_type));
  876. llcHdr = (qdf_llc_t *)(nbuf->data +
  877. QDF_IEEE80211_4ADDR_HDR_LEN);
  878. } else {
  879. ether_type = *(uint16_t *)(nbuf->data
  880. + QDF_IEEE80211_3ADDR_HDR_LEN
  881. + sizeof(qdf_llc_t)
  882. - sizeof(ether_type));
  883. llcHdr = (qdf_llc_t *)(nbuf->data +
  884. QDF_IEEE80211_3ADDR_HDR_LEN);
  885. }
  886. if (qdf_unlikely(DP_FRAME_IS_SNAP(llcHdr)
  887. && (ether_type ==
  888. qdf_htons(QDF_NBUF_TRAC_EAPOL_ETH_TYPE)))) {
  889. DP_STATS_INC(vdev, tx_i.cce_classified_raw, 1);
  890. return true;
  891. }
  892. }
  893. return false;
  894. }
  895. if (qdf_unlikely(DP_FRAME_IS_SNAP(llcHdr))) {
  896. ether_type = *(uint16_t *)(nbuf->data + 2*ETHER_ADDR_LEN +
  897. sizeof(*llcHdr));
  898. nbuf_clone = qdf_nbuf_clone(nbuf);
  899. if (qdf_unlikely(nbuf_clone)) {
  900. qdf_nbuf_pull_head(nbuf_clone, sizeof(*llcHdr));
  901. if (ether_type == htons(ETHERTYPE_8021Q)) {
  902. qdf_nbuf_pull_head(nbuf_clone,
  903. sizeof(qdf_net_vlanhdr_t));
  904. }
  905. }
  906. } else {
  907. if (ether_type == htons(ETHERTYPE_8021Q)) {
  908. nbuf_clone = qdf_nbuf_clone(nbuf);
  909. if (qdf_unlikely(nbuf_clone)) {
  910. qdf_nbuf_pull_head(nbuf_clone,
  911. sizeof(qdf_net_vlanhdr_t));
  912. }
  913. }
  914. }
  915. if (qdf_unlikely(nbuf_clone))
  916. nbuf = nbuf_clone;
  917. if (qdf_unlikely(qdf_nbuf_is_ipv4_eapol_pkt(nbuf)
  918. || qdf_nbuf_is_ipv4_arp_pkt(nbuf)
  919. || qdf_nbuf_is_ipv4_wapi_pkt(nbuf)
  920. || qdf_nbuf_is_ipv4_tdls_pkt(nbuf)
  921. || (qdf_nbuf_is_ipv4_pkt(nbuf)
  922. && qdf_nbuf_is_ipv4_dhcp_pkt(nbuf))
  923. || (qdf_nbuf_is_ipv6_pkt(nbuf) &&
  924. qdf_nbuf_is_ipv6_dhcp_pkt(nbuf)))) {
  925. if (qdf_unlikely(nbuf_clone != NULL))
  926. qdf_nbuf_free(nbuf_clone);
  927. return true;
  928. }
  929. if (qdf_unlikely(nbuf_clone != NULL))
  930. qdf_nbuf_free(nbuf_clone);
  931. return false;
  932. }
  933. /**
  934. * dp_tx_classify_tid() - Obtain TID to be used for this frame
  935. * @vdev: DP vdev handle
  936. * @nbuf: skb
  937. *
  938. * Extract the DSCP or PCP information from frame and map into TID value.
  939. * Software based TID classification is required when more than 2 DSCP-TID
  940. * mapping tables are needed.
  941. * Hardware supports 2 DSCP-TID mapping tables
  942. *
  943. * Return: void
  944. */
  945. static void dp_tx_classify_tid(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  946. struct dp_tx_msdu_info_s *msdu_info)
  947. {
  948. uint8_t tos = 0, dscp_tid_override = 0;
  949. uint8_t *hdr_ptr, *L3datap;
  950. uint8_t is_mcast = 0;
  951. struct ether_header *eh = NULL;
  952. qdf_ethervlan_header_t *evh = NULL;
  953. uint16_t ether_type;
  954. qdf_llc_t *llcHdr;
  955. struct dp_pdev *pdev = (struct dp_pdev *)vdev->pdev;
  956. DP_TX_TID_OVERRIDE(msdu_info, nbuf);
  957. if (vdev->dscp_tid_map_id <= 1)
  958. return;
  959. /* for mesh packets don't do any classification */
  960. if (qdf_unlikely(vdev->mesh_vdev))
  961. return;
  962. if (qdf_likely(vdev->tx_encap_type != htt_cmn_pkt_type_raw)) {
  963. eh = (struct ether_header *) nbuf->data;
  964. hdr_ptr = eh->ether_dhost;
  965. L3datap = hdr_ptr + sizeof(struct ether_header);
  966. } else {
  967. qdf_dot3_qosframe_t *qos_wh =
  968. (qdf_dot3_qosframe_t *) nbuf->data;
  969. msdu_info->tid = qos_wh->i_fc[0] & DP_FC0_SUBTYPE_QOS ?
  970. qos_wh->i_qos[0] & DP_QOS_TID : 0;
  971. return;
  972. }
  973. is_mcast = DP_FRAME_IS_MULTICAST(hdr_ptr);
  974. ether_type = eh->ether_type;
  975. llcHdr = (qdf_llc_t *)(nbuf->data + sizeof(struct ether_header));
  976. /*
  977. * Check if packet is dot3 or eth2 type.
  978. */
  979. if (DP_FRAME_IS_LLC(ether_type) && DP_FRAME_IS_SNAP(llcHdr)) {
  980. ether_type = (uint16_t)*(nbuf->data + 2*ETHER_ADDR_LEN +
  981. sizeof(*llcHdr));
  982. if (ether_type == htons(ETHERTYPE_8021Q)) {
  983. L3datap = hdr_ptr + sizeof(qdf_ethervlan_header_t) +
  984. sizeof(*llcHdr);
  985. ether_type = (uint16_t)*(nbuf->data + 2*ETHER_ADDR_LEN
  986. + sizeof(*llcHdr) +
  987. sizeof(qdf_net_vlanhdr_t));
  988. } else {
  989. L3datap = hdr_ptr + sizeof(struct ether_header) +
  990. sizeof(*llcHdr);
  991. }
  992. } else {
  993. if (ether_type == htons(ETHERTYPE_8021Q)) {
  994. evh = (qdf_ethervlan_header_t *) eh;
  995. ether_type = evh->ether_type;
  996. L3datap = hdr_ptr + sizeof(qdf_ethervlan_header_t);
  997. }
  998. }
  999. /*
  1000. * Find priority from IP TOS DSCP field
  1001. */
  1002. if (qdf_nbuf_is_ipv4_pkt(nbuf)) {
  1003. qdf_net_iphdr_t *ip = (qdf_net_iphdr_t *) L3datap;
  1004. if (qdf_nbuf_is_ipv4_dhcp_pkt(nbuf)) {
  1005. /* Only for unicast frames */
  1006. if (!is_mcast) {
  1007. /* send it on VO queue */
  1008. msdu_info->tid = DP_VO_TID;
  1009. }
  1010. } else {
  1011. /*
  1012. * IP frame: exclude ECN bits 0-1 and map DSCP bits 2-7
  1013. * from TOS byte.
  1014. */
  1015. tos = ip->ip_tos;
  1016. dscp_tid_override = 1;
  1017. }
  1018. } else if (qdf_nbuf_is_ipv6_pkt(nbuf)) {
  1019. /* TODO
  1020. * use flowlabel
  1021. *igmpmld cases to be handled in phase 2
  1022. */
  1023. unsigned long ver_pri_flowlabel;
  1024. unsigned long pri;
  1025. ver_pri_flowlabel = *(unsigned long *) L3datap;
  1026. pri = (ntohl(ver_pri_flowlabel) & IPV6_FLOWINFO_PRIORITY) >>
  1027. DP_IPV6_PRIORITY_SHIFT;
  1028. tos = pri;
  1029. dscp_tid_override = 1;
  1030. } else if (qdf_nbuf_is_ipv4_eapol_pkt(nbuf))
  1031. msdu_info->tid = DP_VO_TID;
  1032. else if (qdf_nbuf_is_ipv4_arp_pkt(nbuf)) {
  1033. /* Only for unicast frames */
  1034. if (!is_mcast) {
  1035. /* send ucast arp on VO queue */
  1036. msdu_info->tid = DP_VO_TID;
  1037. }
  1038. }
  1039. /*
  1040. * Assign all MCAST packets to BE
  1041. */
  1042. if (qdf_unlikely(vdev->tx_encap_type != htt_cmn_pkt_type_raw)) {
  1043. if (is_mcast) {
  1044. tos = 0;
  1045. dscp_tid_override = 1;
  1046. }
  1047. }
  1048. if (dscp_tid_override == 1) {
  1049. tos = (tos >> DP_IP_DSCP_SHIFT) & DP_IP_DSCP_MASK;
  1050. msdu_info->tid = pdev->dscp_tid_map[vdev->dscp_tid_map_id][tos];
  1051. }
  1052. return;
  1053. }
  1054. #ifdef CONVERGED_TDLS_ENABLE
  1055. /**
  1056. * dp_tx_update_tdls_flags() - Update descriptor flags for TDLS frame
  1057. * @tx_desc: TX descriptor
  1058. *
  1059. * Return: None
  1060. */
  1061. static void dp_tx_update_tdls_flags(struct dp_tx_desc_s *tx_desc)
  1062. {
  1063. if (tx_desc->vdev) {
  1064. if (tx_desc->vdev->is_tdls_frame)
  1065. tx_desc->flags |= DP_TX_DESC_FLAG_TDLS_FRAME;
  1066. tx_desc->vdev->is_tdls_frame = false;
  1067. }
  1068. }
  1069. /**
  1070. * dp_non_std_tx_comp_free_buff() - Free the non std tx packet buffer
  1071. * @tx_desc: TX descriptor
  1072. * @vdev: datapath vdev handle
  1073. *
  1074. * Return: None
  1075. */
  1076. static void dp_non_std_tx_comp_free_buff(struct dp_tx_desc_s *tx_desc,
  1077. struct dp_vdev *vdev)
  1078. {
  1079. struct hal_tx_completion_status ts = {0};
  1080. qdf_nbuf_t nbuf = tx_desc->nbuf;
  1081. hal_tx_comp_get_status(&tx_desc->comp, &ts);
  1082. if (vdev->tx_non_std_data_callback.func) {
  1083. qdf_nbuf_set_next(tx_desc->nbuf, NULL);
  1084. vdev->tx_non_std_data_callback.func(
  1085. vdev->tx_non_std_data_callback.ctxt,
  1086. nbuf, ts.status);
  1087. return;
  1088. }
  1089. }
  1090. #endif
  1091. /**
  1092. * dp_tx_send_msdu_single() - Setup descriptor and enqueue single MSDU to TCL
  1093. * @vdev: DP vdev handle
  1094. * @nbuf: skb
  1095. * @tid: TID from HLOS for overriding default DSCP-TID mapping
  1096. * @meta_data: Metadata to the fw
  1097. * @tx_q: Tx queue to be used for this Tx frame
  1098. * @peer_id: peer_id of the peer in case of NAWDS frames
  1099. * @tx_exc_metadata: Handle that holds exception path metadata
  1100. *
  1101. * Return: NULL on success,
  1102. * nbuf when it fails to send
  1103. */
  1104. static qdf_nbuf_t dp_tx_send_msdu_single(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1105. struct dp_tx_msdu_info_s *msdu_info, uint16_t peer_id,
  1106. struct cdp_tx_exception_metadata *tx_exc_metadata)
  1107. {
  1108. struct dp_pdev *pdev = vdev->pdev;
  1109. struct dp_soc *soc = pdev->soc;
  1110. struct dp_tx_desc_s *tx_desc;
  1111. QDF_STATUS status;
  1112. struct dp_tx_queue *tx_q = &(msdu_info->tx_queue);
  1113. void *hal_srng = soc->tcl_data_ring[tx_q->ring_id].hal_srng;
  1114. uint16_t htt_tcl_metadata = 0;
  1115. uint8_t tid = msdu_info->tid;
  1116. /* Setup Tx descriptor for an MSDU, and MSDU extension descriptor */
  1117. tx_desc = dp_tx_prepare_desc_single(vdev, nbuf, tx_q->desc_pool_id,
  1118. msdu_info, tx_exc_metadata);
  1119. if (!tx_desc) {
  1120. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1121. "%s Tx_desc prepare Fail vdev %pK queue %d\n",
  1122. __func__, vdev, tx_q->desc_pool_id);
  1123. return nbuf;
  1124. }
  1125. if (qdf_unlikely(soc->cce_disable)) {
  1126. if (dp_cce_classify(vdev, nbuf) == true) {
  1127. DP_STATS_INC(vdev, tx_i.cce_classified, 1);
  1128. tid = DP_VO_TID;
  1129. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  1130. }
  1131. }
  1132. dp_tx_update_tdls_flags(tx_desc);
  1133. if (qdf_unlikely(hal_srng_access_start(soc->hal_soc, hal_srng))) {
  1134. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1135. "%s %d : HAL RING Access Failed -- %pK\n",
  1136. __func__, __LINE__, hal_srng);
  1137. DP_STATS_INC(vdev, tx_i.dropped.ring_full, 1);
  1138. dp_tx_desc_release(tx_desc, tx_q->desc_pool_id);
  1139. goto fail_return;
  1140. }
  1141. if (qdf_unlikely(peer_id == DP_INVALID_PEER)) {
  1142. htt_tcl_metadata = vdev->htt_tcl_metadata;
  1143. HTT_TX_TCL_METADATA_HOST_INSPECTED_SET(htt_tcl_metadata, 1);
  1144. } else if (qdf_unlikely(peer_id != HTT_INVALID_PEER)) {
  1145. HTT_TX_TCL_METADATA_TYPE_SET(htt_tcl_metadata,
  1146. HTT_TCL_METADATA_TYPE_PEER_BASED);
  1147. HTT_TX_TCL_METADATA_PEER_ID_SET(htt_tcl_metadata,
  1148. peer_id);
  1149. } else
  1150. htt_tcl_metadata = vdev->htt_tcl_metadata;
  1151. if (msdu_info->exception_fw) {
  1152. HTT_TX_TCL_METADATA_VALID_HTT_SET(htt_tcl_metadata, 1);
  1153. }
  1154. /* Enqueue the Tx MSDU descriptor to HW for transmit */
  1155. status = dp_tx_hw_enqueue(soc, vdev, tx_desc, tid,
  1156. htt_tcl_metadata, tx_q->ring_id, tx_exc_metadata);
  1157. if (status != QDF_STATUS_SUCCESS) {
  1158. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1159. "%s Tx_hw_enqueue Fail tx_desc %pK queue %d\n",
  1160. __func__, tx_desc, tx_q->ring_id);
  1161. dp_tx_desc_release(tx_desc, tx_q->desc_pool_id);
  1162. goto fail_return;
  1163. }
  1164. nbuf = NULL;
  1165. fail_return:
  1166. if (hif_pm_runtime_get(soc->hif_handle) == 0) {
  1167. hal_srng_access_end(soc->hal_soc, hal_srng);
  1168. hif_pm_runtime_put(soc->hif_handle);
  1169. } else {
  1170. hal_srng_access_end_reap(soc->hal_soc, hal_srng);
  1171. }
  1172. return nbuf;
  1173. }
  1174. /**
  1175. * dp_tx_send_msdu_multiple() - Enqueue multiple MSDUs
  1176. * @vdev: DP vdev handle
  1177. * @nbuf: skb
  1178. * @msdu_info: MSDU info to be setup in MSDU extension descriptor
  1179. *
  1180. * Prepare descriptors for multiple MSDUs (TSO segments) and enqueue to TCL
  1181. *
  1182. * Return: NULL on success,
  1183. * nbuf when it fails to send
  1184. */
  1185. #if QDF_LOCK_STATS
  1186. static noinline
  1187. #else
  1188. static
  1189. #endif
  1190. qdf_nbuf_t dp_tx_send_msdu_multiple(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1191. struct dp_tx_msdu_info_s *msdu_info)
  1192. {
  1193. uint8_t i;
  1194. struct dp_pdev *pdev = vdev->pdev;
  1195. struct dp_soc *soc = pdev->soc;
  1196. struct dp_tx_desc_s *tx_desc;
  1197. bool is_cce_classified = false;
  1198. QDF_STATUS status;
  1199. uint16_t htt_tcl_metadata = 0;
  1200. struct dp_tx_queue *tx_q = &msdu_info->tx_queue;
  1201. void *hal_srng = soc->tcl_data_ring[tx_q->ring_id].hal_srng;
  1202. if (qdf_unlikely(hal_srng_access_start(soc->hal_soc, hal_srng))) {
  1203. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1204. "%s %d : HAL RING Access Failed -- %pK\n",
  1205. __func__, __LINE__, hal_srng);
  1206. DP_STATS_INC(vdev, tx_i.dropped.ring_full, 1);
  1207. return nbuf;
  1208. }
  1209. if (qdf_unlikely(soc->cce_disable)) {
  1210. is_cce_classified = dp_cce_classify(vdev, nbuf);
  1211. if (is_cce_classified) {
  1212. DP_STATS_INC(vdev, tx_i.cce_classified, 1);
  1213. msdu_info->tid = DP_VO_TID;
  1214. }
  1215. }
  1216. if (msdu_info->frm_type == dp_tx_frm_me)
  1217. nbuf = msdu_info->u.sg_info.curr_seg->nbuf;
  1218. i = 0;
  1219. /* Print statement to track i and num_seg */
  1220. /*
  1221. * For each segment (maps to 1 MSDU) , prepare software and hardware
  1222. * descriptors using information in msdu_info
  1223. */
  1224. while (i < msdu_info->num_seg) {
  1225. /*
  1226. * Setup Tx descriptor for an MSDU, and MSDU extension
  1227. * descriptor
  1228. */
  1229. tx_desc = dp_tx_prepare_desc(vdev, nbuf, msdu_info,
  1230. tx_q->desc_pool_id);
  1231. if (!tx_desc) {
  1232. if (msdu_info->frm_type == dp_tx_frm_me) {
  1233. dp_tx_me_free_buf(pdev,
  1234. (void *)(msdu_info->u.sg_info
  1235. .curr_seg->frags[0].vaddr));
  1236. }
  1237. goto done;
  1238. }
  1239. if (msdu_info->frm_type == dp_tx_frm_me) {
  1240. tx_desc->me_buffer =
  1241. msdu_info->u.sg_info.curr_seg->frags[0].vaddr;
  1242. tx_desc->flags |= DP_TX_DESC_FLAG_ME;
  1243. }
  1244. if (is_cce_classified)
  1245. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  1246. htt_tcl_metadata = vdev->htt_tcl_metadata;
  1247. if (msdu_info->exception_fw) {
  1248. HTT_TX_TCL_METADATA_VALID_HTT_SET(htt_tcl_metadata, 1);
  1249. }
  1250. /*
  1251. * Enqueue the Tx MSDU descriptor to HW for transmit
  1252. */
  1253. status = dp_tx_hw_enqueue(soc, vdev, tx_desc, msdu_info->tid,
  1254. htt_tcl_metadata, tx_q->ring_id, NULL);
  1255. if (status != QDF_STATUS_SUCCESS) {
  1256. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1257. "%s Tx_hw_enqueue Fail tx_desc %pK queue %d\n",
  1258. __func__, tx_desc, tx_q->ring_id);
  1259. if (tx_desc->flags & DP_TX_DESC_FLAG_ME)
  1260. dp_tx_me_free_buf(pdev, tx_desc->me_buffer);
  1261. dp_tx_desc_release(tx_desc, tx_q->desc_pool_id);
  1262. goto done;
  1263. }
  1264. /*
  1265. * TODO
  1266. * if tso_info structure can be modified to have curr_seg
  1267. * as first element, following 2 blocks of code (for TSO and SG)
  1268. * can be combined into 1
  1269. */
  1270. /*
  1271. * For frames with multiple segments (TSO, ME), jump to next
  1272. * segment.
  1273. */
  1274. if (msdu_info->frm_type == dp_tx_frm_tso) {
  1275. if (msdu_info->u.tso_info.curr_seg->next) {
  1276. msdu_info->u.tso_info.curr_seg =
  1277. msdu_info->u.tso_info.curr_seg->next;
  1278. /*
  1279. * If this is a jumbo nbuf, then increment the number of
  1280. * nbuf users for each additional segment of the msdu.
  1281. * This will ensure that the skb is freed only after
  1282. * receiving tx completion for all segments of an nbuf
  1283. */
  1284. qdf_nbuf_inc_users(nbuf);
  1285. /* Check with MCL if this is needed */
  1286. /* nbuf = msdu_info->u.tso_info.curr_seg->nbuf; */
  1287. }
  1288. }
  1289. /*
  1290. * For Multicast-Unicast converted packets,
  1291. * each converted frame (for a client) is represented as
  1292. * 1 segment
  1293. */
  1294. if ((msdu_info->frm_type == dp_tx_frm_sg) ||
  1295. (msdu_info->frm_type == dp_tx_frm_me)) {
  1296. if (msdu_info->u.sg_info.curr_seg->next) {
  1297. msdu_info->u.sg_info.curr_seg =
  1298. msdu_info->u.sg_info.curr_seg->next;
  1299. nbuf = msdu_info->u.sg_info.curr_seg->nbuf;
  1300. }
  1301. }
  1302. i++;
  1303. }
  1304. nbuf = NULL;
  1305. done:
  1306. if (hif_pm_runtime_get(soc->hif_handle) == 0) {
  1307. hal_srng_access_end(soc->hal_soc, hal_srng);
  1308. hif_pm_runtime_put(soc->hif_handle);
  1309. } else {
  1310. hal_srng_access_end_reap(soc->hal_soc, hal_srng);
  1311. }
  1312. return nbuf;
  1313. }
  1314. /**
  1315. * dp_tx_prepare_sg()- Extract SG info from NBUF and prepare msdu_info
  1316. * for SG frames
  1317. * @vdev: DP vdev handle
  1318. * @nbuf: skb
  1319. * @seg_info: Pointer to Segment info Descriptor to be prepared
  1320. * @msdu_info: MSDU info to be setup in MSDU descriptor and MSDU extension desc.
  1321. *
  1322. * Return: NULL on success,
  1323. * nbuf when it fails to send
  1324. */
  1325. static qdf_nbuf_t dp_tx_prepare_sg(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1326. struct dp_tx_seg_info_s *seg_info, struct dp_tx_msdu_info_s *msdu_info)
  1327. {
  1328. uint32_t cur_frag, nr_frags;
  1329. qdf_dma_addr_t paddr;
  1330. struct dp_tx_sg_info_s *sg_info;
  1331. sg_info = &msdu_info->u.sg_info;
  1332. nr_frags = qdf_nbuf_get_nr_frags(nbuf);
  1333. if (QDF_STATUS_SUCCESS != qdf_nbuf_map(vdev->osdev, nbuf,
  1334. QDF_DMA_TO_DEVICE)) {
  1335. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1336. "dma map error\n");
  1337. DP_STATS_INC(vdev, tx_i.sg.dma_map_error, 1);
  1338. qdf_nbuf_free(nbuf);
  1339. return NULL;
  1340. }
  1341. paddr = qdf_nbuf_get_frag_paddr(nbuf, 0);
  1342. seg_info->frags[0].paddr_lo = paddr;
  1343. seg_info->frags[0].paddr_hi = ((uint64_t) paddr) >> 32;
  1344. seg_info->frags[0].len = qdf_nbuf_headlen(nbuf);
  1345. seg_info->frags[0].vaddr = (void *) nbuf;
  1346. for (cur_frag = 0; cur_frag < nr_frags; cur_frag++) {
  1347. if (QDF_STATUS_E_FAILURE == qdf_nbuf_frag_map(vdev->osdev,
  1348. nbuf, 0, QDF_DMA_TO_DEVICE, cur_frag)) {
  1349. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1350. "frag dma map error\n");
  1351. DP_STATS_INC(vdev, tx_i.sg.dma_map_error, 1);
  1352. qdf_nbuf_free(nbuf);
  1353. return NULL;
  1354. }
  1355. paddr = qdf_nbuf_get_frag_paddr(nbuf, 0);
  1356. seg_info->frags[cur_frag + 1].paddr_lo = paddr;
  1357. seg_info->frags[cur_frag + 1].paddr_hi =
  1358. ((uint64_t) paddr) >> 32;
  1359. seg_info->frags[cur_frag + 1].len =
  1360. qdf_nbuf_get_frag_size(nbuf, cur_frag);
  1361. }
  1362. seg_info->frag_cnt = (cur_frag + 1);
  1363. seg_info->total_len = qdf_nbuf_len(nbuf);
  1364. seg_info->next = NULL;
  1365. sg_info->curr_seg = seg_info;
  1366. msdu_info->frm_type = dp_tx_frm_sg;
  1367. msdu_info->num_seg = 1;
  1368. return nbuf;
  1369. }
  1370. #ifdef MESH_MODE_SUPPORT
  1371. /**
  1372. * dp_tx_extract_mesh_meta_data()- Extract mesh meta hdr info from nbuf
  1373. and prepare msdu_info for mesh frames.
  1374. * @vdev: DP vdev handle
  1375. * @nbuf: skb
  1376. * @msdu_info: MSDU info to be setup in MSDU descriptor and MSDU extension desc.
  1377. *
  1378. * Return: NULL on failure,
  1379. * nbuf when extracted successfully
  1380. */
  1381. static
  1382. qdf_nbuf_t dp_tx_extract_mesh_meta_data(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1383. struct dp_tx_msdu_info_s *msdu_info)
  1384. {
  1385. struct meta_hdr_s *mhdr;
  1386. struct htt_tx_msdu_desc_ext2_t *meta_data =
  1387. (struct htt_tx_msdu_desc_ext2_t *)&msdu_info->meta_data[0];
  1388. mhdr = (struct meta_hdr_s *)qdf_nbuf_data(nbuf);
  1389. if (CB_FTYPE_MESH_TX_INFO != qdf_nbuf_get_tx_ftype(nbuf)) {
  1390. msdu_info->exception_fw = 0;
  1391. goto remove_meta_hdr;
  1392. }
  1393. msdu_info->exception_fw = 1;
  1394. qdf_mem_set(meta_data, sizeof(struct htt_tx_msdu_desc_ext2_t), 0);
  1395. meta_data->host_tx_desc_pool = 1;
  1396. meta_data->update_peer_cache = 1;
  1397. meta_data->learning_frame = 1;
  1398. if (!(mhdr->flags & METAHDR_FLAG_AUTO_RATE)) {
  1399. meta_data->power = mhdr->power;
  1400. meta_data->mcs_mask = 1 << mhdr->rate_info[0].mcs;
  1401. meta_data->nss_mask = 1 << mhdr->rate_info[0].nss;
  1402. meta_data->pream_type = mhdr->rate_info[0].preamble_type;
  1403. meta_data->retry_limit = mhdr->rate_info[0].max_tries;
  1404. meta_data->dyn_bw = 1;
  1405. meta_data->valid_pwr = 1;
  1406. meta_data->valid_mcs_mask = 1;
  1407. meta_data->valid_nss_mask = 1;
  1408. meta_data->valid_preamble_type = 1;
  1409. meta_data->valid_retries = 1;
  1410. meta_data->valid_bw_info = 1;
  1411. }
  1412. if (mhdr->flags & METAHDR_FLAG_NOENCRYPT) {
  1413. meta_data->encrypt_type = 0;
  1414. meta_data->valid_encrypt_type = 1;
  1415. meta_data->learning_frame = 0;
  1416. }
  1417. meta_data->valid_key_flags = 1;
  1418. meta_data->key_flags = (mhdr->keyix & 0x3);
  1419. remove_meta_hdr:
  1420. if (qdf_nbuf_pull_head(nbuf, sizeof(struct meta_hdr_s)) == NULL) {
  1421. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1422. "qdf_nbuf_pull_head failed\n");
  1423. qdf_nbuf_free(nbuf);
  1424. return NULL;
  1425. }
  1426. if (mhdr->flags & METAHDR_FLAG_NOQOS)
  1427. msdu_info->tid = HTT_TX_EXT_TID_NON_QOS_MCAST_BCAST;
  1428. else
  1429. msdu_info->tid = qdf_nbuf_get_priority(nbuf);
  1430. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  1431. "%s , Meta hdr %0x %0x %0x %0x %0x %0x"
  1432. " tid %d to_fw %d\n",
  1433. __func__, msdu_info->meta_data[0],
  1434. msdu_info->meta_data[1],
  1435. msdu_info->meta_data[2],
  1436. msdu_info->meta_data[3],
  1437. msdu_info->meta_data[4],
  1438. msdu_info->meta_data[5],
  1439. msdu_info->tid, msdu_info->exception_fw);
  1440. return nbuf;
  1441. }
  1442. #else
  1443. static
  1444. qdf_nbuf_t dp_tx_extract_mesh_meta_data(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1445. struct dp_tx_msdu_info_s *msdu_info)
  1446. {
  1447. return nbuf;
  1448. }
  1449. #endif
  1450. #ifdef DP_FEATURE_NAWDS_TX
  1451. /**
  1452. * dp_tx_prepare_nawds(): Tramit NAWDS frames
  1453. * @vdev: dp_vdev handle
  1454. * @nbuf: skb
  1455. * @tid: TID from HLOS for overriding default DSCP-TID mapping
  1456. * @tx_q: Tx queue to be used for this Tx frame
  1457. * @meta_data: Meta date for mesh
  1458. * @peer_id: peer_id of the peer in case of NAWDS frames
  1459. *
  1460. * return: NULL on success nbuf on failure
  1461. */
  1462. static qdf_nbuf_t dp_tx_prepare_nawds(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1463. struct dp_tx_msdu_info_s *msdu_info)
  1464. {
  1465. struct dp_peer *peer = NULL;
  1466. struct dp_soc *soc = vdev->pdev->soc;
  1467. struct dp_ast_entry *ast_entry = NULL;
  1468. struct ether_header *eh = (struct ether_header *)qdf_nbuf_data(nbuf);
  1469. uint16_t peer_id = HTT_INVALID_PEER;
  1470. struct dp_peer *sa_peer = NULL;
  1471. qdf_nbuf_t nbuf_copy;
  1472. qdf_spin_lock_bh(&(soc->ast_lock));
  1473. ast_entry = dp_peer_ast_hash_find(soc, (uint8_t *)(eh->ether_shost));
  1474. if (ast_entry)
  1475. sa_peer = ast_entry->peer;
  1476. qdf_spin_unlock_bh(&(soc->ast_lock));
  1477. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  1478. if ((peer->peer_ids[0] != HTT_INVALID_PEER) &&
  1479. (peer->nawds_enabled)) {
  1480. if (sa_peer == peer) {
  1481. QDF_TRACE(QDF_MODULE_ID_DP,
  1482. QDF_TRACE_LEVEL_DEBUG,
  1483. " %s: broadcast multicast packet",
  1484. __func__);
  1485. DP_STATS_INC(peer, tx.nawds_mcast_drop, 1);
  1486. continue;
  1487. }
  1488. nbuf_copy = qdf_nbuf_copy(nbuf);
  1489. if (!nbuf_copy) {
  1490. QDF_TRACE(QDF_MODULE_ID_DP,
  1491. QDF_TRACE_LEVEL_ERROR,
  1492. "nbuf copy failed");
  1493. }
  1494. peer_id = peer->peer_ids[0];
  1495. nbuf_copy = dp_tx_send_msdu_single(vdev, nbuf_copy,
  1496. msdu_info, peer_id, NULL);
  1497. if (nbuf_copy != NULL) {
  1498. qdf_nbuf_free(nbuf_copy);
  1499. continue;
  1500. }
  1501. DP_STATS_INC_PKT(peer, tx.nawds_mcast,
  1502. 1, qdf_nbuf_len(nbuf));
  1503. }
  1504. }
  1505. if (peer_id == HTT_INVALID_PEER)
  1506. return nbuf;
  1507. return NULL;
  1508. }
  1509. #endif
  1510. /**
  1511. * dp_check_exc_metadata() - Checks if parameters are valid
  1512. * @tx_exc - holds all exception path parameters
  1513. *
  1514. * Returns true when all the parameters are valid else false
  1515. *
  1516. */
  1517. static bool dp_check_exc_metadata(struct cdp_tx_exception_metadata *tx_exc)
  1518. {
  1519. if ((tx_exc->tid > DP_MAX_TIDS && tx_exc->tid != HTT_INVALID_TID) ||
  1520. tx_exc->tx_encap_type > htt_cmn_pkt_num_types ||
  1521. tx_exc->sec_type > cdp_num_sec_types) {
  1522. return false;
  1523. }
  1524. return true;
  1525. }
  1526. /**
  1527. * dp_tx_send_exception() - Transmit a frame on a given VAP in exception path
  1528. * @vap_dev: DP vdev handle
  1529. * @nbuf: skb
  1530. * @tx_exc_metadata: Handle that holds exception path meta data
  1531. *
  1532. * Entry point for Core Tx layer (DP_TX) invoked from
  1533. * hard_start_xmit in OSIF/HDD to transmit frames through fw
  1534. *
  1535. * Return: NULL on success,
  1536. * nbuf when it fails to send
  1537. */
  1538. qdf_nbuf_t dp_tx_send_exception(void *vap_dev, qdf_nbuf_t nbuf,
  1539. struct cdp_tx_exception_metadata *tx_exc_metadata)
  1540. {
  1541. struct ether_header *eh = NULL;
  1542. struct dp_vdev *vdev = (struct dp_vdev *) vap_dev;
  1543. struct dp_tx_msdu_info_s msdu_info;
  1544. qdf_mem_set(&msdu_info, sizeof(msdu_info), 0x0);
  1545. msdu_info.tid = tx_exc_metadata->tid;
  1546. eh = (struct ether_header *)qdf_nbuf_data(nbuf);
  1547. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1548. "%s , skb %pM",
  1549. __func__, nbuf->data);
  1550. DP_STATS_INC_PKT(vdev, tx_i.rcvd, 1, qdf_nbuf_len(nbuf));
  1551. if (qdf_unlikely(!dp_check_exc_metadata(tx_exc_metadata))) {
  1552. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1553. "Invalid parameters in exception path");
  1554. goto fail;
  1555. }
  1556. /* Basic sanity checks for unsupported packets */
  1557. /* MESH mode */
  1558. if (qdf_unlikely(vdev->mesh_vdev)) {
  1559. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1560. "Mesh mode is not supported in exception path");
  1561. goto fail;
  1562. }
  1563. /* TSO or SG */
  1564. if (qdf_unlikely(qdf_nbuf_is_tso(nbuf)) ||
  1565. qdf_unlikely(qdf_nbuf_is_nonlinear(nbuf))) {
  1566. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1567. "TSO and SG are not supported in exception path");
  1568. goto fail;
  1569. }
  1570. /* RAW */
  1571. if (qdf_unlikely(tx_exc_metadata->tx_encap_type == htt_cmn_pkt_type_raw)) {
  1572. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1573. "Raw frame is not supported in exception path");
  1574. goto fail;
  1575. }
  1576. /* Mcast enhancement*/
  1577. if (qdf_unlikely(vdev->mcast_enhancement_en > 0)) {
  1578. if (DP_FRAME_IS_MULTICAST((eh)->ether_dhost)) {
  1579. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1580. "Ignoring mcast_enhancement_en which is set and sending the mcast packet to the FW\n");
  1581. }
  1582. }
  1583. /*
  1584. * Get HW Queue to use for this frame.
  1585. * TCL supports upto 4 DMA rings, out of which 3 rings are
  1586. * dedicated for data and 1 for command.
  1587. * "queue_id" maps to one hardware ring.
  1588. * With each ring, we also associate a unique Tx descriptor pool
  1589. * to minimize lock contention for these resources.
  1590. */
  1591. dp_tx_get_queue(vdev, nbuf, &msdu_info.tx_queue);
  1592. /* Reset the control block */
  1593. qdf_nbuf_reset_ctxt(nbuf);
  1594. /* Single linear frame */
  1595. /*
  1596. * If nbuf is a simple linear frame, use send_single function to
  1597. * prepare direct-buffer type TCL descriptor and enqueue to TCL
  1598. * SRNG. There is no need to setup a MSDU extension descriptor.
  1599. */
  1600. nbuf = dp_tx_send_msdu_single(vdev, nbuf, &msdu_info,
  1601. tx_exc_metadata->peer_id, tx_exc_metadata);
  1602. return nbuf;
  1603. fail:
  1604. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1605. "pkt send failed");
  1606. return nbuf;
  1607. }
  1608. /**
  1609. * dp_tx_send_mesh() - Transmit mesh frame on a given VAP
  1610. * @vap_dev: DP vdev handle
  1611. * @nbuf: skb
  1612. *
  1613. * Entry point for Core Tx layer (DP_TX) invoked from
  1614. * hard_start_xmit in OSIF/HDD
  1615. *
  1616. * Return: NULL on success,
  1617. * nbuf when it fails to send
  1618. */
  1619. #ifdef MESH_MODE_SUPPORT
  1620. qdf_nbuf_t dp_tx_send_mesh(void *vap_dev, qdf_nbuf_t nbuf)
  1621. {
  1622. struct meta_hdr_s *mhdr;
  1623. qdf_nbuf_t nbuf_mesh = NULL;
  1624. qdf_nbuf_t nbuf_clone = NULL;
  1625. struct dp_vdev *vdev = (struct dp_vdev *) vap_dev;
  1626. uint8_t no_enc_frame = 0;
  1627. nbuf_mesh = qdf_nbuf_unshare(nbuf);
  1628. if (nbuf_mesh == NULL) {
  1629. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1630. "qdf_nbuf_unshare failed\n");
  1631. return nbuf;
  1632. }
  1633. nbuf = nbuf_mesh;
  1634. mhdr = (struct meta_hdr_s *)qdf_nbuf_data(nbuf);
  1635. if ((vdev->sec_type != cdp_sec_type_none) &&
  1636. (mhdr->flags & METAHDR_FLAG_NOENCRYPT))
  1637. no_enc_frame = 1;
  1638. if ((mhdr->flags & METAHDR_FLAG_INFO_UPDATED) &&
  1639. !no_enc_frame) {
  1640. nbuf_clone = qdf_nbuf_clone(nbuf);
  1641. if (nbuf_clone == NULL) {
  1642. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1643. "qdf_nbuf_clone failed\n");
  1644. return nbuf;
  1645. }
  1646. qdf_nbuf_set_tx_ftype(nbuf_clone, CB_FTYPE_MESH_TX_INFO);
  1647. }
  1648. if (nbuf_clone) {
  1649. if (!dp_tx_send(vap_dev, nbuf_clone)) {
  1650. DP_STATS_INC(vdev, tx_i.mesh.exception_fw, 1);
  1651. } else {
  1652. qdf_nbuf_free(nbuf_clone);
  1653. }
  1654. }
  1655. if (no_enc_frame)
  1656. qdf_nbuf_set_tx_ftype(nbuf, CB_FTYPE_MESH_TX_INFO);
  1657. else
  1658. qdf_nbuf_set_tx_ftype(nbuf, CB_FTYPE_INVALID);
  1659. nbuf = dp_tx_send(vap_dev, nbuf);
  1660. if ((nbuf == NULL) && no_enc_frame) {
  1661. DP_STATS_INC(vdev, tx_i.mesh.exception_fw, 1);
  1662. }
  1663. return nbuf;
  1664. }
  1665. #else
  1666. qdf_nbuf_t dp_tx_send_mesh(void *vap_dev, qdf_nbuf_t nbuf)
  1667. {
  1668. return dp_tx_send(vap_dev, nbuf);
  1669. }
  1670. #endif
  1671. /**
  1672. * dp_tx_send() - Transmit a frame on a given VAP
  1673. * @vap_dev: DP vdev handle
  1674. * @nbuf: skb
  1675. *
  1676. * Entry point for Core Tx layer (DP_TX) invoked from
  1677. * hard_start_xmit in OSIF/HDD or from dp_rx_process for intravap forwarding
  1678. * cases
  1679. *
  1680. * Return: NULL on success,
  1681. * nbuf when it fails to send
  1682. */
  1683. qdf_nbuf_t dp_tx_send(void *vap_dev, qdf_nbuf_t nbuf)
  1684. {
  1685. struct ether_header *eh = NULL;
  1686. struct dp_tx_msdu_info_s msdu_info;
  1687. struct dp_tx_seg_info_s seg_info;
  1688. struct dp_vdev *vdev = (struct dp_vdev *) vap_dev;
  1689. uint16_t peer_id = HTT_INVALID_PEER;
  1690. qdf_nbuf_t nbuf_mesh = NULL;
  1691. qdf_mem_set(&msdu_info, sizeof(msdu_info), 0x0);
  1692. qdf_mem_set(&seg_info, sizeof(seg_info), 0x0);
  1693. eh = (struct ether_header *)qdf_nbuf_data(nbuf);
  1694. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1695. "%s , skb %pM",
  1696. __func__, nbuf->data);
  1697. /*
  1698. * Set Default Host TID value to invalid TID
  1699. * (TID override disabled)
  1700. */
  1701. msdu_info.tid = HTT_TX_EXT_TID_INVALID;
  1702. DP_STATS_INC_PKT(vdev, tx_i.rcvd, 1, qdf_nbuf_len(nbuf));
  1703. if (qdf_unlikely(vdev->mesh_vdev)) {
  1704. nbuf_mesh = dp_tx_extract_mesh_meta_data(vdev, nbuf,
  1705. &msdu_info);
  1706. if (nbuf_mesh == NULL) {
  1707. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1708. "Extracting mesh metadata failed\n");
  1709. return nbuf;
  1710. }
  1711. nbuf = nbuf_mesh;
  1712. }
  1713. /*
  1714. * Get HW Queue to use for this frame.
  1715. * TCL supports upto 4 DMA rings, out of which 3 rings are
  1716. * dedicated for data and 1 for command.
  1717. * "queue_id" maps to one hardware ring.
  1718. * With each ring, we also associate a unique Tx descriptor pool
  1719. * to minimize lock contention for these resources.
  1720. */
  1721. dp_tx_get_queue(vdev, nbuf, &msdu_info.tx_queue);
  1722. /*
  1723. * TCL H/W supports 2 DSCP-TID mapping tables.
  1724. * Table 1 - Default DSCP-TID mapping table
  1725. * Table 2 - 1 DSCP-TID override table
  1726. *
  1727. * If we need a different DSCP-TID mapping for this vap,
  1728. * call tid_classify to extract DSCP/ToS from frame and
  1729. * map to a TID and store in msdu_info. This is later used
  1730. * to fill in TCL Input descriptor (per-packet TID override).
  1731. */
  1732. dp_tx_classify_tid(vdev, nbuf, &msdu_info);
  1733. /* Reset the control block */
  1734. qdf_nbuf_reset_ctxt(nbuf);
  1735. /*
  1736. * Classify the frame and call corresponding
  1737. * "prepare" function which extracts the segment (TSO)
  1738. * and fragmentation information (for TSO , SG, ME, or Raw)
  1739. * into MSDU_INFO structure which is later used to fill
  1740. * SW and HW descriptors.
  1741. */
  1742. if (qdf_nbuf_is_tso(nbuf)) {
  1743. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1744. "%s TSO frame %pK\n", __func__, vdev);
  1745. DP_STATS_INC_PKT(vdev, tx_i.tso.tso_pkt, 1,
  1746. qdf_nbuf_len(nbuf));
  1747. if (dp_tx_prepare_tso(vdev, nbuf, &msdu_info)) {
  1748. DP_STATS_INC_PKT(vdev, tx_i.tso.dropped_host, 1,
  1749. qdf_nbuf_len(nbuf));
  1750. return nbuf;
  1751. }
  1752. goto send_multiple;
  1753. }
  1754. /* SG */
  1755. if (qdf_unlikely(qdf_nbuf_is_nonlinear(nbuf))) {
  1756. nbuf = dp_tx_prepare_sg(vdev, nbuf, &seg_info, &msdu_info);
  1757. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1758. "%s non-TSO SG frame %pK\n", __func__, vdev);
  1759. DP_STATS_INC_PKT(vdev, tx_i.sg.sg_pkt, 1,
  1760. qdf_nbuf_len(nbuf));
  1761. goto send_multiple;
  1762. }
  1763. #ifdef ATH_SUPPORT_IQUE
  1764. /* Mcast to Ucast Conversion*/
  1765. if (qdf_unlikely(vdev->mcast_enhancement_en > 0)) {
  1766. eh = (struct ether_header *)qdf_nbuf_data(nbuf);
  1767. if (DP_FRAME_IS_MULTICAST((eh)->ether_dhost)) {
  1768. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1769. "%s Mcast frm for ME %pK\n", __func__, vdev);
  1770. DP_STATS_INC_PKT(vdev,
  1771. tx_i.mcast_en.mcast_pkt, 1,
  1772. qdf_nbuf_len(nbuf));
  1773. if (dp_tx_prepare_send_me(vdev, nbuf) ==
  1774. QDF_STATUS_SUCCESS) {
  1775. return NULL;
  1776. }
  1777. }
  1778. }
  1779. #endif
  1780. /* RAW */
  1781. if (qdf_unlikely(vdev->tx_encap_type == htt_cmn_pkt_type_raw)) {
  1782. nbuf = dp_tx_prepare_raw(vdev, nbuf, &seg_info, &msdu_info);
  1783. if (nbuf == NULL)
  1784. return NULL;
  1785. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1786. "%s Raw frame %pK\n", __func__, vdev);
  1787. goto send_multiple;
  1788. }
  1789. /* Single linear frame */
  1790. /*
  1791. * If nbuf is a simple linear frame, use send_single function to
  1792. * prepare direct-buffer type TCL descriptor and enqueue to TCL
  1793. * SRNG. There is no need to setup a MSDU extension descriptor.
  1794. */
  1795. nbuf = dp_tx_send_msdu_single(vdev, nbuf, &msdu_info, peer_id, NULL);
  1796. return nbuf;
  1797. send_multiple:
  1798. nbuf = dp_tx_send_msdu_multiple(vdev, nbuf, &msdu_info);
  1799. return nbuf;
  1800. }
  1801. /**
  1802. * dp_tx_reinject_handler() - Tx Reinject Handler
  1803. * @tx_desc: software descriptor head pointer
  1804. * @status : Tx completion status from HTT descriptor
  1805. *
  1806. * This function reinjects frames back to Target.
  1807. * Todo - Host queue needs to be added
  1808. *
  1809. * Return: none
  1810. */
  1811. static
  1812. void dp_tx_reinject_handler(struct dp_tx_desc_s *tx_desc, uint8_t *status)
  1813. {
  1814. struct dp_vdev *vdev;
  1815. struct dp_peer *peer = NULL;
  1816. uint32_t peer_id = HTT_INVALID_PEER;
  1817. qdf_nbuf_t nbuf = tx_desc->nbuf;
  1818. qdf_nbuf_t nbuf_copy = NULL;
  1819. struct dp_tx_msdu_info_s msdu_info;
  1820. struct dp_peer *sa_peer = NULL;
  1821. struct dp_ast_entry *ast_entry = NULL;
  1822. struct dp_soc *soc = NULL;
  1823. struct ether_header *eh = (struct ether_header *)qdf_nbuf_data(nbuf);
  1824. #ifdef WDS_VENDOR_EXTENSION
  1825. int is_mcast = 0, is_ucast = 0;
  1826. int num_peers_3addr = 0;
  1827. struct ether_header *eth_hdr = (struct ether_header *)(qdf_nbuf_data(nbuf));
  1828. struct ieee80211_frame_addr4 *wh = (struct ieee80211_frame_addr4 *)(qdf_nbuf_data(nbuf));
  1829. #endif
  1830. vdev = tx_desc->vdev;
  1831. soc = vdev->pdev->soc;
  1832. qdf_assert(vdev);
  1833. qdf_mem_set(&msdu_info, sizeof(msdu_info), 0x0);
  1834. dp_tx_get_queue(vdev, nbuf, &msdu_info.tx_queue);
  1835. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1836. "%s Tx reinject path\n", __func__);
  1837. DP_STATS_INC_PKT(vdev, tx_i.reinject_pkts, 1,
  1838. qdf_nbuf_len(tx_desc->nbuf));
  1839. qdf_spin_lock_bh(&(soc->ast_lock));
  1840. ast_entry = dp_peer_ast_hash_find(soc, (uint8_t *)(eh->ether_shost));
  1841. if (ast_entry)
  1842. sa_peer = ast_entry->peer;
  1843. qdf_spin_unlock_bh(&(soc->ast_lock));
  1844. #ifdef WDS_VENDOR_EXTENSION
  1845. if (qdf_unlikely(vdev->tx_encap_type != htt_cmn_pkt_type_raw)) {
  1846. is_mcast = (IS_MULTICAST(wh->i_addr1)) ? 1 : 0;
  1847. } else {
  1848. is_mcast = (IS_MULTICAST(eth_hdr->ether_dhost)) ? 1 : 0;
  1849. }
  1850. is_ucast = !is_mcast;
  1851. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  1852. if (peer->bss_peer)
  1853. continue;
  1854. /* Detect wds peers that use 3-addr framing for mcast.
  1855. * if there are any, the bss_peer is used to send the
  1856. * the mcast frame using 3-addr format. all wds enabled
  1857. * peers that use 4-addr framing for mcast frames will
  1858. * be duplicated and sent as 4-addr frames below.
  1859. */
  1860. if (!peer->wds_enabled || !peer->wds_ecm.wds_tx_mcast_4addr) {
  1861. num_peers_3addr = 1;
  1862. break;
  1863. }
  1864. }
  1865. #endif
  1866. if (qdf_unlikely(vdev->mesh_vdev)) {
  1867. DP_TX_FREE_SINGLE_BUF(vdev->pdev->soc, tx_desc->nbuf);
  1868. } else {
  1869. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  1870. if ((peer->peer_ids[0] != HTT_INVALID_PEER) &&
  1871. #ifdef WDS_VENDOR_EXTENSION
  1872. /*
  1873. * . if 3-addr STA, then send on BSS Peer
  1874. * . if Peer WDS enabled and accept 4-addr mcast,
  1875. * send mcast on that peer only
  1876. * . if Peer WDS enabled and accept 4-addr ucast,
  1877. * send ucast on that peer only
  1878. */
  1879. ((peer->bss_peer && num_peers_3addr && is_mcast) ||
  1880. (peer->wds_enabled &&
  1881. ((is_mcast && peer->wds_ecm.wds_tx_mcast_4addr) ||
  1882. (is_ucast && peer->wds_ecm.wds_tx_ucast_4addr))))) {
  1883. #else
  1884. ((peer->bss_peer &&
  1885. !(vdev->osif_proxy_arp(vdev->osif_vdev, nbuf))) ||
  1886. peer->nawds_enabled)) {
  1887. #endif
  1888. peer_id = DP_INVALID_PEER;
  1889. if (peer->nawds_enabled) {
  1890. peer_id = peer->peer_ids[0];
  1891. if (sa_peer == peer) {
  1892. QDF_TRACE(
  1893. QDF_MODULE_ID_DP,
  1894. QDF_TRACE_LEVEL_DEBUG,
  1895. " %s: multicast packet",
  1896. __func__);
  1897. DP_STATS_INC(peer,
  1898. tx.nawds_mcast_drop, 1);
  1899. continue;
  1900. }
  1901. }
  1902. nbuf_copy = qdf_nbuf_copy(nbuf);
  1903. if (!nbuf_copy) {
  1904. QDF_TRACE(QDF_MODULE_ID_DP,
  1905. QDF_TRACE_LEVEL_DEBUG,
  1906. FL("nbuf copy failed"));
  1907. break;
  1908. }
  1909. nbuf_copy = dp_tx_send_msdu_single(vdev,
  1910. nbuf_copy,
  1911. &msdu_info,
  1912. peer_id,
  1913. NULL);
  1914. if (nbuf_copy) {
  1915. QDF_TRACE(QDF_MODULE_ID_DP,
  1916. QDF_TRACE_LEVEL_DEBUG,
  1917. FL("pkt send failed"));
  1918. qdf_nbuf_free(nbuf_copy);
  1919. } else {
  1920. if (peer_id != DP_INVALID_PEER)
  1921. DP_STATS_INC_PKT(peer,
  1922. tx.nawds_mcast,
  1923. 1, qdf_nbuf_len(nbuf));
  1924. }
  1925. }
  1926. }
  1927. }
  1928. if (vdev->nawds_enabled) {
  1929. peer_id = DP_INVALID_PEER;
  1930. DP_STATS_INC_PKT(vdev, tx_i.nawds_mcast,
  1931. 1, qdf_nbuf_len(nbuf));
  1932. nbuf = dp_tx_send_msdu_single(vdev,
  1933. nbuf,
  1934. &msdu_info,
  1935. peer_id, NULL);
  1936. if (nbuf) {
  1937. QDF_TRACE(QDF_MODULE_ID_DP,
  1938. QDF_TRACE_LEVEL_DEBUG,
  1939. FL("pkt send failed"));
  1940. qdf_nbuf_free(nbuf);
  1941. }
  1942. } else
  1943. qdf_nbuf_free(nbuf);
  1944. dp_tx_desc_release(tx_desc, tx_desc->pool_id);
  1945. }
  1946. /**
  1947. * dp_tx_inspect_handler() - Tx Inspect Handler
  1948. * @tx_desc: software descriptor head pointer
  1949. * @status : Tx completion status from HTT descriptor
  1950. *
  1951. * Handles Tx frames sent back to Host for inspection
  1952. * (ProxyARP)
  1953. *
  1954. * Return: none
  1955. */
  1956. static void dp_tx_inspect_handler(struct dp_tx_desc_s *tx_desc, uint8_t *status)
  1957. {
  1958. struct dp_soc *soc;
  1959. struct dp_pdev *pdev = tx_desc->pdev;
  1960. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  1961. "%s Tx inspect path\n",
  1962. __func__);
  1963. qdf_assert(pdev);
  1964. soc = pdev->soc;
  1965. DP_STATS_INC_PKT(tx_desc->vdev, tx_i.inspect_pkts, 1,
  1966. qdf_nbuf_len(tx_desc->nbuf));
  1967. DP_TX_FREE_SINGLE_BUF(soc, tx_desc->nbuf);
  1968. dp_tx_desc_release(tx_desc, tx_desc->pool_id);
  1969. }
  1970. #ifdef FEATURE_PERPKT_INFO
  1971. /**
  1972. * dp_get_completion_indication_for_stack() - send completion to stack
  1973. * @soc : dp_soc handle
  1974. * @pdev: dp_pdev handle
  1975. * @peer_id: peer_id of the peer for which completion came
  1976. * @ppdu_id: ppdu_id
  1977. * @first_msdu: first msdu
  1978. * @last_msdu: last msdu
  1979. * @netbuf: Buffer pointer for free
  1980. *
  1981. * This function is used for indication whether buffer needs to be
  1982. * send to stack for free or not
  1983. */
  1984. QDF_STATUS
  1985. dp_get_completion_indication_for_stack(struct dp_soc *soc, struct dp_pdev *pdev,
  1986. uint16_t peer_id, uint32_t ppdu_id, uint8_t first_msdu,
  1987. uint8_t last_msdu, qdf_nbuf_t netbuf)
  1988. {
  1989. struct tx_capture_hdr *ppdu_hdr;
  1990. struct dp_peer *peer = NULL;
  1991. struct ether_header *eh;
  1992. if (qdf_unlikely(!pdev->tx_sniffer_enable && !pdev->mcopy_mode))
  1993. return QDF_STATUS_E_NOSUPPORT;
  1994. peer = (peer_id == HTT_INVALID_PEER) ? NULL :
  1995. dp_peer_find_by_id(soc, peer_id);
  1996. if (!peer) {
  1997. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1998. FL("Peer Invalid"));
  1999. return QDF_STATUS_E_INVAL;
  2000. }
  2001. if (pdev->mcopy_mode) {
  2002. if ((pdev->m_copy_id.tx_ppdu_id == ppdu_id) &&
  2003. (pdev->m_copy_id.tx_peer_id == peer_id)) {
  2004. return QDF_STATUS_E_INVAL;
  2005. }
  2006. pdev->m_copy_id.tx_ppdu_id = ppdu_id;
  2007. pdev->m_copy_id.tx_peer_id = peer_id;
  2008. }
  2009. eh = (struct ether_header *)qdf_nbuf_data(netbuf);
  2010. if (!qdf_nbuf_push_head(netbuf, sizeof(struct tx_capture_hdr))) {
  2011. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2012. FL("No headroom"));
  2013. return QDF_STATUS_E_NOMEM;
  2014. }
  2015. ppdu_hdr = (struct tx_capture_hdr *)qdf_nbuf_data(netbuf);
  2016. qdf_mem_copy(ppdu_hdr->ta, peer->vdev->mac_addr.raw,
  2017. IEEE80211_ADDR_LEN);
  2018. if (peer->bss_peer) {
  2019. qdf_mem_copy(ppdu_hdr->ra, eh->ether_dhost, IEEE80211_ADDR_LEN);
  2020. } else {
  2021. qdf_mem_copy(ppdu_hdr->ra, peer->mac_addr.raw,
  2022. IEEE80211_ADDR_LEN);
  2023. }
  2024. ppdu_hdr->ppdu_id = ppdu_id;
  2025. ppdu_hdr->peer_id = peer_id;
  2026. ppdu_hdr->first_msdu = first_msdu;
  2027. ppdu_hdr->last_msdu = last_msdu;
  2028. return QDF_STATUS_SUCCESS;
  2029. }
  2030. /**
  2031. * dp_send_completion_to_stack() - send completion to stack
  2032. * @soc : dp_soc handle
  2033. * @pdev: dp_pdev handle
  2034. * @peer_id: peer_id of the peer for which completion came
  2035. * @ppdu_id: ppdu_id
  2036. * @netbuf: Buffer pointer for free
  2037. *
  2038. * This function is used to send completion to stack
  2039. * to free buffer
  2040. */
  2041. void dp_send_completion_to_stack(struct dp_soc *soc, struct dp_pdev *pdev,
  2042. uint16_t peer_id, uint32_t ppdu_id,
  2043. qdf_nbuf_t netbuf)
  2044. {
  2045. dp_wdi_event_handler(WDI_EVENT_TX_DATA, soc,
  2046. netbuf, peer_id,
  2047. WDI_NO_VAL, pdev->pdev_id);
  2048. }
  2049. #else
  2050. static QDF_STATUS
  2051. dp_get_completion_indication_for_stack(struct dp_soc *soc, struct dp_pdev *pdev,
  2052. uint16_t peer_id, uint32_t ppdu_id, uint8_t first_msdu,
  2053. uint8_t last_msdu, qdf_nbuf_t netbuf)
  2054. {
  2055. return QDF_STATUS_E_NOSUPPORT;
  2056. }
  2057. static void
  2058. dp_send_completion_to_stack(struct dp_soc *soc, struct dp_pdev *pdev,
  2059. uint16_t peer_id, uint32_t ppdu_id, qdf_nbuf_t netbuf)
  2060. {
  2061. }
  2062. #endif
  2063. /**
  2064. * dp_tx_comp_free_buf() - Free nbuf associated with the Tx Descriptor
  2065. * @soc: Soc handle
  2066. * @desc: software Tx descriptor to be processed
  2067. *
  2068. * Return: none
  2069. */
  2070. static inline void dp_tx_comp_free_buf(struct dp_soc *soc,
  2071. struct dp_tx_desc_s *desc)
  2072. {
  2073. struct dp_vdev *vdev = desc->vdev;
  2074. qdf_nbuf_t nbuf = desc->nbuf;
  2075. /* If it is TDLS mgmt, don't unmap or free the frame */
  2076. if (desc->flags & DP_TX_DESC_FLAG_TDLS_FRAME)
  2077. return dp_non_std_tx_comp_free_buff(desc, vdev);
  2078. /* 0 : MSDU buffer, 1 : MLE */
  2079. if (desc->msdu_ext_desc) {
  2080. /* TSO free */
  2081. if (hal_tx_ext_desc_get_tso_enable(
  2082. desc->msdu_ext_desc->vaddr)) {
  2083. /* unmap eash TSO seg before free the nbuf */
  2084. dp_tx_tso_unmap_segment(soc, desc);
  2085. qdf_nbuf_free(nbuf);
  2086. return;
  2087. }
  2088. }
  2089. qdf_nbuf_unmap(soc->osdev, nbuf, QDF_DMA_TO_DEVICE);
  2090. if (qdf_likely(!vdev->mesh_vdev))
  2091. qdf_nbuf_free(nbuf);
  2092. else {
  2093. if (desc->flags & DP_TX_DESC_FLAG_TO_FW) {
  2094. qdf_nbuf_free(nbuf);
  2095. DP_STATS_INC(vdev, tx_i.mesh.completion_fw, 1);
  2096. } else
  2097. vdev->osif_tx_free_ext((nbuf));
  2098. }
  2099. }
  2100. /**
  2101. * dp_tx_mec_handler() - Tx MEC Notify Handler
  2102. * @vdev: pointer to dp dev handler
  2103. * @status : Tx completion status from HTT descriptor
  2104. *
  2105. * Handles MEC notify event sent from fw to Host
  2106. *
  2107. * Return: none
  2108. */
  2109. #ifdef FEATURE_WDS
  2110. void dp_tx_mec_handler(struct dp_vdev *vdev, uint8_t *status)
  2111. {
  2112. struct dp_soc *soc;
  2113. uint32_t flags = IEEE80211_NODE_F_WDS_HM;
  2114. struct dp_peer *peer;
  2115. uint8_t mac_addr[DP_MAC_ADDR_LEN], i;
  2116. if (!vdev->wds_enabled)
  2117. return;
  2118. soc = vdev->pdev->soc;
  2119. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  2120. peer = TAILQ_FIRST(&vdev->peer_list);
  2121. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  2122. if (!peer) {
  2123. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2124. FL("peer is NULL"));
  2125. return;
  2126. }
  2127. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2128. "%s Tx MEC Handler\n",
  2129. __func__);
  2130. for (i = 0; i < DP_MAC_ADDR_LEN; i++)
  2131. mac_addr[(DP_MAC_ADDR_LEN - 1) - i] =
  2132. status[(DP_MAC_ADDR_LEN - 2) + i];
  2133. if (qdf_mem_cmp(mac_addr, vdev->mac_addr.raw, DP_MAC_ADDR_LEN))
  2134. dp_peer_add_ast(soc,
  2135. peer,
  2136. mac_addr,
  2137. CDP_TXRX_AST_TYPE_MEC,
  2138. flags);
  2139. }
  2140. #endif
  2141. /**
  2142. * dp_tx_process_htt_completion() - Tx HTT Completion Indication Handler
  2143. * @tx_desc: software descriptor head pointer
  2144. * @status : Tx completion status from HTT descriptor
  2145. *
  2146. * This function will process HTT Tx indication messages from Target
  2147. *
  2148. * Return: none
  2149. */
  2150. static
  2151. void dp_tx_process_htt_completion(struct dp_tx_desc_s *tx_desc, uint8_t *status)
  2152. {
  2153. uint8_t tx_status;
  2154. struct dp_pdev *pdev;
  2155. struct dp_vdev *vdev;
  2156. struct dp_soc *soc;
  2157. uint32_t *htt_status_word = (uint32_t *) status;
  2158. qdf_assert(tx_desc->pdev);
  2159. pdev = tx_desc->pdev;
  2160. vdev = tx_desc->vdev;
  2161. soc = pdev->soc;
  2162. tx_status = HTT_TX_WBM_COMPLETION_V2_TX_STATUS_GET(htt_status_word[0]);
  2163. switch (tx_status) {
  2164. case HTT_TX_FW2WBM_TX_STATUS_OK:
  2165. case HTT_TX_FW2WBM_TX_STATUS_DROP:
  2166. case HTT_TX_FW2WBM_TX_STATUS_TTL:
  2167. {
  2168. dp_tx_comp_free_buf(soc, tx_desc);
  2169. dp_tx_desc_release(tx_desc, tx_desc->pool_id);
  2170. break;
  2171. }
  2172. case HTT_TX_FW2WBM_TX_STATUS_REINJECT:
  2173. {
  2174. dp_tx_reinject_handler(tx_desc, status);
  2175. break;
  2176. }
  2177. case HTT_TX_FW2WBM_TX_STATUS_INSPECT:
  2178. {
  2179. dp_tx_inspect_handler(tx_desc, status);
  2180. break;
  2181. }
  2182. case HTT_TX_FW2WBM_TX_STATUS_MEC_NOTIFY:
  2183. {
  2184. dp_tx_mec_handler(vdev, status);
  2185. break;
  2186. }
  2187. default:
  2188. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2189. "%s Invalid HTT tx_status %d\n",
  2190. __func__, tx_status);
  2191. break;
  2192. }
  2193. }
  2194. #ifdef MESH_MODE_SUPPORT
  2195. /**
  2196. * dp_tx_comp_fill_tx_completion_stats() - Fill per packet Tx completion stats
  2197. * in mesh meta header
  2198. * @tx_desc: software descriptor head pointer
  2199. * @ts: pointer to tx completion stats
  2200. * Return: none
  2201. */
  2202. static
  2203. void dp_tx_comp_fill_tx_completion_stats(struct dp_tx_desc_s *tx_desc,
  2204. struct hal_tx_completion_status *ts)
  2205. {
  2206. struct meta_hdr_s *mhdr;
  2207. qdf_nbuf_t netbuf = tx_desc->nbuf;
  2208. if (!tx_desc->msdu_ext_desc) {
  2209. if (qdf_nbuf_pull_head(netbuf, tx_desc->pkt_offset) == NULL) {
  2210. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2211. "netbuf %pK offset %d\n",
  2212. netbuf, tx_desc->pkt_offset);
  2213. return;
  2214. }
  2215. }
  2216. if (qdf_nbuf_push_head(netbuf, sizeof(struct meta_hdr_s)) == NULL) {
  2217. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2218. "netbuf %pK offset %d\n", netbuf,
  2219. sizeof(struct meta_hdr_s));
  2220. return;
  2221. }
  2222. mhdr = (struct meta_hdr_s *)qdf_nbuf_data(netbuf);
  2223. mhdr->rssi = ts->ack_frame_rssi;
  2224. mhdr->channel = tx_desc->pdev->operating_channel;
  2225. }
  2226. #else
  2227. static
  2228. void dp_tx_comp_fill_tx_completion_stats(struct dp_tx_desc_s *tx_desc,
  2229. struct hal_tx_completion_status *ts)
  2230. {
  2231. }
  2232. #endif
  2233. /**
  2234. * dp_tx_update_peer_stats() - Update peer stats from Tx completion indications
  2235. * @peer: Handle to DP peer
  2236. * @ts: pointer to HAL Tx completion stats
  2237. * @length: MSDU length
  2238. *
  2239. * Return: None
  2240. */
  2241. static void dp_tx_update_peer_stats(struct dp_peer *peer,
  2242. struct hal_tx_completion_status *ts, uint32_t length)
  2243. {
  2244. struct dp_pdev *pdev = peer->vdev->pdev;
  2245. struct dp_soc *soc = pdev->soc;
  2246. uint8_t mcs, pkt_type;
  2247. mcs = ts->mcs;
  2248. pkt_type = ts->pkt_type;
  2249. if (!ts->release_src == HAL_TX_COMP_RELEASE_SOURCE_TQM)
  2250. return;
  2251. if (peer->bss_peer) {
  2252. DP_STATS_INC_PKT(peer, tx.mcast, 1, length);
  2253. } else {
  2254. DP_STATS_INC_PKT(peer, tx.ucast, 1, length);
  2255. }
  2256. DP_STATS_INC_PKT(peer, tx.comp_pkt, 1, length);
  2257. DP_STATS_INCC_PKT(peer, tx.tx_success, 1, length,
  2258. (ts->status == HAL_TX_TQM_RR_FRAME_ACKED));
  2259. DP_STATS_INCC(peer, tx.dropped.age_out, 1,
  2260. (ts->status == HAL_TX_TQM_RR_REM_CMD_AGED));
  2261. DP_STATS_INCC(peer, tx.dropped.fw_rem, 1,
  2262. (ts->status == HAL_TX_TQM_RR_REM_CMD_REM));
  2263. DP_STATS_INCC(peer, tx.dropped.fw_rem_notx, 1,
  2264. (ts->status == HAL_TX_TQM_RR_REM_CMD_NOTX));
  2265. DP_STATS_INCC(peer, tx.dropped.fw_rem_tx, 1,
  2266. (ts->status == HAL_TX_TQM_RR_REM_CMD_TX));
  2267. DP_STATS_INCC(peer, tx.dropped.fw_reason1, 1,
  2268. (ts->status == HAL_TX_TQM_RR_FW_REASON1));
  2269. DP_STATS_INCC(peer, tx.dropped.fw_reason2, 1,
  2270. (ts->status == HAL_TX_TQM_RR_FW_REASON2));
  2271. DP_STATS_INCC(peer, tx.dropped.fw_reason3, 1,
  2272. (ts->status == HAL_TX_TQM_RR_FW_REASON3));
  2273. if (!ts->status == HAL_TX_TQM_RR_FRAME_ACKED)
  2274. return;
  2275. DP_STATS_INCC(peer, tx.ofdma, 1, ts->ofdma);
  2276. DP_STATS_INCC(peer, tx.amsdu_cnt, 1, ts->msdu_part_of_amsdu);
  2277. DP_STATS_INCC(peer, tx.non_amsdu_cnt, 1, !ts->msdu_part_of_amsdu);
  2278. if (!(soc->process_tx_status))
  2279. return;
  2280. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  2281. ((mcs >= MAX_MCS_11A) && (pkt_type == DOT11_A)));
  2282. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[mcs], 1,
  2283. ((mcs < (MAX_MCS_11A)) && (pkt_type == DOT11_A)));
  2284. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  2285. ((mcs >= MAX_MCS_11B) && (pkt_type == DOT11_B)));
  2286. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[mcs], 1,
  2287. ((mcs < MAX_MCS_11B) && (pkt_type == DOT11_B)));
  2288. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  2289. ((mcs >= MAX_MCS_11A) && (pkt_type == DOT11_N)));
  2290. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[mcs], 1,
  2291. ((mcs < MAX_MCS_11A) && (pkt_type == DOT11_N)));
  2292. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  2293. ((mcs >= MAX_MCS_11AC) && (pkt_type == DOT11_AC)));
  2294. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[mcs], 1,
  2295. ((mcs < MAX_MCS_11AC) && (pkt_type == DOT11_AC)));
  2296. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  2297. ((mcs >= (MAX_MCS - 1)) && (pkt_type == DOT11_AX)));
  2298. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[mcs], 1,
  2299. ((mcs < (MAX_MCS - 1)) && (pkt_type == DOT11_AX)));
  2300. DP_STATS_INC(peer, tx.sgi_count[ts->sgi], 1);
  2301. DP_STATS_INC(peer, tx.bw[ts->bw], 1);
  2302. DP_STATS_UPD(peer, tx.last_ack_rssi, ts->ack_frame_rssi);
  2303. DP_STATS_INC(peer, tx.wme_ac_type[TID_TO_WME_AC(ts->tid)], 1);
  2304. DP_STATS_INCC(peer, tx.stbc, 1, ts->stbc);
  2305. DP_STATS_INCC(peer, tx.ldpc, 1, ts->ldpc);
  2306. DP_STATS_INCC(peer, tx.retries, 1, ts->transmit_cnt > 1);
  2307. if (soc->cdp_soc.ol_ops->update_dp_stats) {
  2308. soc->cdp_soc.ol_ops->update_dp_stats(pdev->ctrl_pdev,
  2309. &peer->stats, ts->peer_id,
  2310. UPDATE_PEER_STATS);
  2311. }
  2312. }
  2313. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  2314. /**
  2315. * dp_tx_flow_pool_lock() - take flow pool lock
  2316. * @soc: core txrx main context
  2317. * @tx_desc: tx desc
  2318. *
  2319. * Return: None
  2320. */
  2321. static inline
  2322. void dp_tx_flow_pool_lock(struct dp_soc *soc,
  2323. struct dp_tx_desc_s *tx_desc)
  2324. {
  2325. struct dp_tx_desc_pool_s *pool;
  2326. uint8_t desc_pool_id;
  2327. desc_pool_id = tx_desc->pool_id;
  2328. pool = &soc->tx_desc[desc_pool_id];
  2329. qdf_spin_lock_bh(&pool->flow_pool_lock);
  2330. }
  2331. /**
  2332. * dp_tx_flow_pool_unlock() - release flow pool lock
  2333. * @soc: core txrx main context
  2334. * @tx_desc: tx desc
  2335. *
  2336. * Return: None
  2337. */
  2338. static inline
  2339. void dp_tx_flow_pool_unlock(struct dp_soc *soc,
  2340. struct dp_tx_desc_s *tx_desc)
  2341. {
  2342. struct dp_tx_desc_pool_s *pool;
  2343. uint8_t desc_pool_id;
  2344. desc_pool_id = tx_desc->pool_id;
  2345. pool = &soc->tx_desc[desc_pool_id];
  2346. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  2347. }
  2348. #else
  2349. static inline
  2350. void dp_tx_flow_pool_lock(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc)
  2351. {
  2352. }
  2353. static inline
  2354. void dp_tx_flow_pool_unlock(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc)
  2355. {
  2356. }
  2357. #endif
  2358. /**
  2359. * dp_tx_notify_completion() - Notify tx completion for this desc
  2360. * @soc: core txrx main context
  2361. * @tx_desc: tx desc
  2362. * @netbuf: buffer
  2363. *
  2364. * Return: none
  2365. */
  2366. static inline void dp_tx_notify_completion(struct dp_soc *soc,
  2367. struct dp_tx_desc_s *tx_desc,
  2368. qdf_nbuf_t netbuf)
  2369. {
  2370. void *osif_dev;
  2371. ol_txrx_completion_fp tx_compl_cbk = NULL;
  2372. qdf_assert(tx_desc);
  2373. dp_tx_flow_pool_lock(soc, tx_desc);
  2374. if (!tx_desc->vdev ||
  2375. !tx_desc->vdev->osif_vdev) {
  2376. dp_tx_flow_pool_unlock(soc, tx_desc);
  2377. return;
  2378. }
  2379. osif_dev = tx_desc->vdev->osif_vdev;
  2380. tx_compl_cbk = tx_desc->vdev->tx_comp;
  2381. dp_tx_flow_pool_unlock(soc, tx_desc);
  2382. if (tx_compl_cbk)
  2383. tx_compl_cbk(netbuf, osif_dev);
  2384. }
  2385. /**
  2386. * dp_tx_comp_process_tx_status() - Parse and Dump Tx completion status info
  2387. * @tx_desc: software descriptor head pointer
  2388. * @length: packet length
  2389. *
  2390. * Return: none
  2391. */
  2392. static inline void dp_tx_comp_process_tx_status(struct dp_tx_desc_s *tx_desc,
  2393. uint32_t length)
  2394. {
  2395. struct hal_tx_completion_status ts;
  2396. struct dp_soc *soc = NULL;
  2397. struct dp_vdev *vdev = tx_desc->vdev;
  2398. struct dp_peer *peer = NULL;
  2399. struct ether_header *eh =
  2400. (struct ether_header *)qdf_nbuf_data(tx_desc->nbuf);
  2401. hal_tx_comp_get_status(&tx_desc->comp, &ts);
  2402. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2403. "-------------------- \n"
  2404. "Tx Completion Stats: \n"
  2405. "-------------------- \n"
  2406. "ack_frame_rssi = %d \n"
  2407. "first_msdu = %d \n"
  2408. "last_msdu = %d \n"
  2409. "msdu_part_of_amsdu = %d \n"
  2410. "rate_stats valid = %d \n"
  2411. "bw = %d \n"
  2412. "pkt_type = %d \n"
  2413. "stbc = %d \n"
  2414. "ldpc = %d \n"
  2415. "sgi = %d \n"
  2416. "mcs = %d \n"
  2417. "ofdma = %d \n"
  2418. "tones_in_ru = %d \n"
  2419. "tsf = %d \n"
  2420. "ppdu_id = %d \n"
  2421. "transmit_cnt = %d \n"
  2422. "tid = %d \n"
  2423. "peer_id = %d \n",
  2424. ts.ack_frame_rssi, ts.first_msdu, ts.last_msdu,
  2425. ts.msdu_part_of_amsdu, ts.valid, ts.bw,
  2426. ts.pkt_type, ts.stbc, ts.ldpc, ts.sgi,
  2427. ts.mcs, ts.ofdma, ts.tones_in_ru, ts.tsf,
  2428. ts.ppdu_id, ts.transmit_cnt, ts.tid,
  2429. ts.peer_id);
  2430. if (!vdev) {
  2431. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2432. "invalid vdev");
  2433. goto out;
  2434. }
  2435. soc = vdev->pdev->soc;
  2436. /* Update SoC level stats */
  2437. DP_STATS_INCC(soc, tx.dropped_fw_removed, 1,
  2438. (ts.status == HAL_TX_TQM_RR_REM_CMD_REM));
  2439. /* Update per-packet stats */
  2440. if (qdf_unlikely(vdev->mesh_vdev) &&
  2441. !(tx_desc->flags & DP_TX_DESC_FLAG_TO_FW))
  2442. dp_tx_comp_fill_tx_completion_stats(tx_desc, &ts);
  2443. /* Update peer level stats */
  2444. peer = dp_peer_find_by_id(soc, ts.peer_id);
  2445. if (!peer) {
  2446. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2447. "invalid peer");
  2448. DP_STATS_INC_PKT(soc, tx.tx_invalid_peer, 1, length);
  2449. goto out;
  2450. }
  2451. if (qdf_likely(peer->vdev->tx_encap_type ==
  2452. htt_cmn_pkt_type_ethernet)) {
  2453. if (peer->bss_peer && IEEE80211_IS_BROADCAST(eh->ether_dhost))
  2454. DP_STATS_INC_PKT(peer, tx.bcast, 1, length);
  2455. }
  2456. dp_tx_update_peer_stats(peer, &ts, length);
  2457. out:
  2458. return;
  2459. }
  2460. /**
  2461. * dp_tx_comp_process_desc() - Tx complete software descriptor handler
  2462. * @soc: core txrx main context
  2463. * @comp_head: software descriptor head pointer
  2464. *
  2465. * This function will process batch of descriptors reaped by dp_tx_comp_handler
  2466. * and release the software descriptors after processing is complete
  2467. *
  2468. * Return: none
  2469. */
  2470. static void dp_tx_comp_process_desc(struct dp_soc *soc,
  2471. struct dp_tx_desc_s *comp_head)
  2472. {
  2473. struct dp_tx_desc_s *desc;
  2474. struct dp_tx_desc_s *next;
  2475. struct hal_tx_completion_status ts = {0};
  2476. uint32_t length;
  2477. struct dp_peer *peer;
  2478. DP_HIST_INIT();
  2479. desc = comp_head;
  2480. while (desc) {
  2481. hal_tx_comp_get_status(&desc->comp, &ts);
  2482. peer = dp_peer_find_by_id(soc, ts.peer_id);
  2483. length = qdf_nbuf_len(desc->nbuf);
  2484. /* check tx completion notification */
  2485. if (QDF_NBUF_CB_TX_EXTRA_FRAG_FLAGS_NOTIFY_COMP(desc->nbuf))
  2486. dp_tx_notify_completion(soc, desc, desc->nbuf);
  2487. dp_tx_comp_process_tx_status(desc, length);
  2488. DPTRACE(qdf_dp_trace_ptr
  2489. (desc->nbuf,
  2490. QDF_DP_TRACE_LI_DP_FREE_PACKET_PTR_RECORD,
  2491. QDF_TRACE_DEFAULT_PDEV_ID,
  2492. qdf_nbuf_data_addr(desc->nbuf),
  2493. sizeof(qdf_nbuf_data(desc->nbuf)),
  2494. desc->id, ts.status)
  2495. );
  2496. /*currently m_copy/tx_capture is not supported for scatter gather packets*/
  2497. if (!(desc->msdu_ext_desc) && (dp_get_completion_indication_for_stack(soc,
  2498. desc->pdev, ts.peer_id, ts.ppdu_id,
  2499. ts.first_msdu, ts.last_msdu,
  2500. desc->nbuf) == QDF_STATUS_SUCCESS)) {
  2501. qdf_nbuf_unmap(soc->osdev, desc->nbuf,
  2502. QDF_DMA_TO_DEVICE);
  2503. dp_send_completion_to_stack(soc, desc->pdev, ts.peer_id,
  2504. ts.ppdu_id, desc->nbuf);
  2505. } else {
  2506. dp_tx_comp_free_buf(soc, desc);
  2507. }
  2508. DP_HIST_PACKET_COUNT_INC(desc->pdev->pdev_id);
  2509. next = desc->next;
  2510. dp_tx_desc_release(desc, desc->pool_id);
  2511. desc = next;
  2512. }
  2513. DP_TX_HIST_STATS_PER_PDEV();
  2514. }
  2515. /**
  2516. * dp_tx_comp_handler() - Tx completion handler
  2517. * @soc: core txrx main context
  2518. * @ring_id: completion ring id
  2519. * @quota: No. of packets/descriptors that can be serviced in one loop
  2520. *
  2521. * This function will collect hardware release ring element contents and
  2522. * handle descriptor contents. Based on contents, free packet or handle error
  2523. * conditions
  2524. *
  2525. * Return: none
  2526. */
  2527. uint32_t dp_tx_comp_handler(struct dp_soc *soc, void *hal_srng, uint32_t quota)
  2528. {
  2529. void *tx_comp_hal_desc;
  2530. uint8_t buffer_src;
  2531. uint8_t pool_id;
  2532. uint32_t tx_desc_id;
  2533. struct dp_tx_desc_s *tx_desc = NULL;
  2534. struct dp_tx_desc_s *head_desc = NULL;
  2535. struct dp_tx_desc_s *tail_desc = NULL;
  2536. uint32_t num_processed;
  2537. uint32_t count;
  2538. if (qdf_unlikely(hal_srng_access_start(soc->hal_soc, hal_srng))) {
  2539. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  2540. "%s %d : HAL RING Access Failed -- %pK\n",
  2541. __func__, __LINE__, hal_srng);
  2542. return 0;
  2543. }
  2544. num_processed = 0;
  2545. count = 0;
  2546. /* Find head descriptor from completion ring */
  2547. while (qdf_likely(tx_comp_hal_desc =
  2548. hal_srng_dst_get_next(soc->hal_soc, hal_srng))) {
  2549. buffer_src = hal_tx_comp_get_buffer_source(tx_comp_hal_desc);
  2550. /* If this buffer was not released by TQM or FW, then it is not
  2551. * Tx completion indication, assert */
  2552. if ((buffer_src != HAL_TX_COMP_RELEASE_SOURCE_TQM) &&
  2553. (buffer_src != HAL_TX_COMP_RELEASE_SOURCE_FW)) {
  2554. QDF_TRACE(QDF_MODULE_ID_DP,
  2555. QDF_TRACE_LEVEL_FATAL,
  2556. "Tx comp release_src != TQM | FW");
  2557. qdf_assert_always(0);
  2558. }
  2559. /* Get descriptor id */
  2560. tx_desc_id = hal_tx_comp_get_desc_id(tx_comp_hal_desc);
  2561. pool_id = (tx_desc_id & DP_TX_DESC_ID_POOL_MASK) >>
  2562. DP_TX_DESC_ID_POOL_OS;
  2563. if (!dp_tx_is_desc_id_valid(soc, tx_desc_id))
  2564. continue;
  2565. /* Find Tx descriptor */
  2566. tx_desc = dp_tx_desc_find(soc, pool_id,
  2567. (tx_desc_id & DP_TX_DESC_ID_PAGE_MASK) >>
  2568. DP_TX_DESC_ID_PAGE_OS,
  2569. (tx_desc_id & DP_TX_DESC_ID_OFFSET_MASK) >>
  2570. DP_TX_DESC_ID_OFFSET_OS);
  2571. /*
  2572. * If the release source is FW, process the HTT status
  2573. */
  2574. if (qdf_unlikely(buffer_src ==
  2575. HAL_TX_COMP_RELEASE_SOURCE_FW)) {
  2576. uint8_t htt_tx_status[HAL_TX_COMP_HTT_STATUS_LEN];
  2577. hal_tx_comp_get_htt_desc(tx_comp_hal_desc,
  2578. htt_tx_status);
  2579. dp_tx_process_htt_completion(tx_desc,
  2580. htt_tx_status);
  2581. } else {
  2582. /* Pool id is not matching. Error */
  2583. if (tx_desc->pool_id != pool_id) {
  2584. QDF_TRACE(QDF_MODULE_ID_DP,
  2585. QDF_TRACE_LEVEL_FATAL,
  2586. "Tx Comp pool id %d not matched %d",
  2587. pool_id, tx_desc->pool_id);
  2588. qdf_assert_always(0);
  2589. }
  2590. if (!(tx_desc->flags & DP_TX_DESC_FLAG_ALLOCATED) ||
  2591. !(tx_desc->flags & DP_TX_DESC_FLAG_QUEUED_TX)) {
  2592. QDF_TRACE(QDF_MODULE_ID_DP,
  2593. QDF_TRACE_LEVEL_FATAL,
  2594. "Txdesc invalid, flgs = %x,id = %d",
  2595. tx_desc->flags, tx_desc_id);
  2596. qdf_assert_always(0);
  2597. }
  2598. /* First ring descriptor on the cycle */
  2599. if (!head_desc) {
  2600. head_desc = tx_desc;
  2601. tail_desc = tx_desc;
  2602. }
  2603. tail_desc->next = tx_desc;
  2604. tx_desc->next = NULL;
  2605. tail_desc = tx_desc;
  2606. /* Collect hw completion contents */
  2607. hal_tx_comp_desc_sync(tx_comp_hal_desc,
  2608. &tx_desc->comp, 1);
  2609. }
  2610. num_processed += !(count & DP_TX_NAPI_BUDGET_DIV_MASK);
  2611. /* Decrement PM usage count if the packet has been sent.*/
  2612. hif_pm_runtime_put(soc->hif_handle);
  2613. /*
  2614. * Processed packet count is more than given quota
  2615. * stop to processing
  2616. */
  2617. if ((num_processed >= quota))
  2618. break;
  2619. count++;
  2620. }
  2621. hal_srng_access_end(soc->hal_soc, hal_srng);
  2622. /* Process the reaped descriptors */
  2623. if (head_desc)
  2624. dp_tx_comp_process_desc(soc, head_desc);
  2625. return num_processed;
  2626. }
  2627. #ifdef CONVERGED_TDLS_ENABLE
  2628. /**
  2629. * dp_tx_non_std() - Allow the control-path SW to send data frames
  2630. *
  2631. * @data_vdev - which vdev should transmit the tx data frames
  2632. * @tx_spec - what non-standard handling to apply to the tx data frames
  2633. * @msdu_list - NULL-terminated list of tx MSDUs
  2634. *
  2635. * Return: NULL on success,
  2636. * nbuf when it fails to send
  2637. */
  2638. qdf_nbuf_t dp_tx_non_std(struct cdp_vdev *vdev_handle,
  2639. enum ol_tx_spec tx_spec, qdf_nbuf_t msdu_list)
  2640. {
  2641. struct dp_vdev *vdev = (struct dp_vdev *) vdev_handle;
  2642. if (tx_spec & OL_TX_SPEC_NO_FREE)
  2643. vdev->is_tdls_frame = true;
  2644. return dp_tx_send(vdev_handle, msdu_list);
  2645. }
  2646. #endif
  2647. /**
  2648. * dp_tx_vdev_attach() - attach vdev to dp tx
  2649. * @vdev: virtual device instance
  2650. *
  2651. * Return: QDF_STATUS_SUCCESS: success
  2652. * QDF_STATUS_E_RESOURCES: Error return
  2653. */
  2654. QDF_STATUS dp_tx_vdev_attach(struct dp_vdev *vdev)
  2655. {
  2656. /*
  2657. * Fill HTT TCL Metadata with Vdev ID and MAC ID
  2658. */
  2659. HTT_TX_TCL_METADATA_TYPE_SET(vdev->htt_tcl_metadata,
  2660. HTT_TCL_METADATA_TYPE_VDEV_BASED);
  2661. HTT_TX_TCL_METADATA_VDEV_ID_SET(vdev->htt_tcl_metadata,
  2662. vdev->vdev_id);
  2663. HTT_TX_TCL_METADATA_PDEV_ID_SET(vdev->htt_tcl_metadata,
  2664. DP_SW2HW_MACID(vdev->pdev->pdev_id));
  2665. /*
  2666. * Set HTT Extension Valid bit to 0 by default
  2667. */
  2668. HTT_TX_TCL_METADATA_VALID_HTT_SET(vdev->htt_tcl_metadata, 0);
  2669. dp_tx_vdev_update_search_flags(vdev);
  2670. return QDF_STATUS_SUCCESS;
  2671. }
  2672. /**
  2673. * dp_tx_vdev_update_search_flags() - Update vdev flags as per opmode
  2674. * @vdev: virtual device instance
  2675. *
  2676. * Return: void
  2677. *
  2678. */
  2679. void dp_tx_vdev_update_search_flags(struct dp_vdev *vdev)
  2680. {
  2681. /*
  2682. * Enable both AddrY (SA based search) and AddrX (Da based search)
  2683. * for TDLS link
  2684. *
  2685. * Enable AddrY (SA based search) only for non-WDS STA and
  2686. * ProxySTA VAP modes.
  2687. *
  2688. * In all other VAP modes, only DA based search should be
  2689. * enabled
  2690. */
  2691. if (vdev->opmode == wlan_op_mode_sta &&
  2692. vdev->tdls_link_connected)
  2693. vdev->hal_desc_addr_search_flags =
  2694. (HAL_TX_DESC_ADDRX_EN | HAL_TX_DESC_ADDRY_EN);
  2695. else if ((vdev->opmode == wlan_op_mode_sta &&
  2696. (!vdev->wds_enabled || vdev->proxysta_vdev)))
  2697. vdev->hal_desc_addr_search_flags = HAL_TX_DESC_ADDRY_EN;
  2698. else
  2699. vdev->hal_desc_addr_search_flags = HAL_TX_DESC_ADDRX_EN;
  2700. }
  2701. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  2702. static void dp_tx_desc_flush(struct dp_vdev *vdev)
  2703. {
  2704. }
  2705. #else /* QCA_LL_TX_FLOW_CONTROL_V2! */
  2706. /* dp_tx_desc_flush() - release resources associated
  2707. * to tx_desc
  2708. * @vdev: virtual device instance
  2709. *
  2710. * This function will free all outstanding Tx buffers,
  2711. * including ME buffer for which either free during
  2712. * completion didn't happened or completion is not
  2713. * received.
  2714. */
  2715. static void dp_tx_desc_flush(struct dp_vdev *vdev)
  2716. {
  2717. uint8_t i, num_pool;
  2718. uint32_t j;
  2719. uint32_t num_desc;
  2720. struct dp_soc *soc = vdev->pdev->soc;
  2721. struct dp_tx_desc_s *tx_desc = NULL;
  2722. struct dp_tx_desc_pool_s *tx_desc_pool = NULL;
  2723. num_desc = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  2724. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  2725. for (i = 0; i < num_pool; i++) {
  2726. for (j = 0; j < num_desc; j++) {
  2727. tx_desc_pool = &((soc)->tx_desc[(i)]);
  2728. if (tx_desc_pool &&
  2729. tx_desc_pool->desc_pages.cacheable_pages) {
  2730. tx_desc = dp_tx_desc_find(soc, i,
  2731. (j & DP_TX_DESC_ID_PAGE_MASK) >>
  2732. DP_TX_DESC_ID_PAGE_OS,
  2733. (j & DP_TX_DESC_ID_OFFSET_MASK) >>
  2734. DP_TX_DESC_ID_OFFSET_OS);
  2735. if (tx_desc && (tx_desc->vdev == vdev) &&
  2736. (tx_desc->flags & DP_TX_DESC_FLAG_ALLOCATED)) {
  2737. dp_tx_comp_free_buf(soc, tx_desc);
  2738. dp_tx_desc_release(tx_desc, i);
  2739. }
  2740. }
  2741. }
  2742. }
  2743. }
  2744. #endif /* !QCA_LL_TX_FLOW_CONTROL_V2 */
  2745. /**
  2746. * dp_tx_vdev_detach() - detach vdev from dp tx
  2747. * @vdev: virtual device instance
  2748. *
  2749. * Return: QDF_STATUS_SUCCESS: success
  2750. * QDF_STATUS_E_RESOURCES: Error return
  2751. */
  2752. QDF_STATUS dp_tx_vdev_detach(struct dp_vdev *vdev)
  2753. {
  2754. dp_tx_desc_flush(vdev);
  2755. return QDF_STATUS_SUCCESS;
  2756. }
  2757. /**
  2758. * dp_tx_pdev_attach() - attach pdev to dp tx
  2759. * @pdev: physical device instance
  2760. *
  2761. * Return: QDF_STATUS_SUCCESS: success
  2762. * QDF_STATUS_E_RESOURCES: Error return
  2763. */
  2764. QDF_STATUS dp_tx_pdev_attach(struct dp_pdev *pdev)
  2765. {
  2766. struct dp_soc *soc = pdev->soc;
  2767. /* Initialize Flow control counters */
  2768. qdf_atomic_init(&pdev->num_tx_exception);
  2769. qdf_atomic_init(&pdev->num_tx_outstanding);
  2770. if (wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  2771. /* Initialize descriptors in TCL Ring */
  2772. hal_tx_init_data_ring(soc->hal_soc,
  2773. soc->tcl_data_ring[pdev->pdev_id].hal_srng);
  2774. }
  2775. return QDF_STATUS_SUCCESS;
  2776. }
  2777. /**
  2778. * dp_tx_pdev_detach() - detach pdev from dp tx
  2779. * @pdev: physical device instance
  2780. *
  2781. * Return: QDF_STATUS_SUCCESS: success
  2782. * QDF_STATUS_E_RESOURCES: Error return
  2783. */
  2784. QDF_STATUS dp_tx_pdev_detach(struct dp_pdev *pdev)
  2785. {
  2786. dp_tx_me_exit(pdev);
  2787. return QDF_STATUS_SUCCESS;
  2788. }
  2789. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  2790. /* Pools will be allocated dynamically */
  2791. static int dp_tx_alloc_static_pools(struct dp_soc *soc, int num_pool,
  2792. int num_desc)
  2793. {
  2794. uint8_t i;
  2795. for (i = 0; i < num_pool; i++) {
  2796. qdf_spinlock_create(&soc->tx_desc[i].flow_pool_lock);
  2797. soc->tx_desc[i].status = FLOW_POOL_INACTIVE;
  2798. }
  2799. return 0;
  2800. }
  2801. static void dp_tx_delete_static_pools(struct dp_soc *soc, int num_pool)
  2802. {
  2803. uint8_t i;
  2804. for (i = 0; i < num_pool; i++)
  2805. qdf_spinlock_destroy(&soc->tx_desc[i].flow_pool_lock);
  2806. }
  2807. #else /* QCA_LL_TX_FLOW_CONTROL_V2! */
  2808. static int dp_tx_alloc_static_pools(struct dp_soc *soc, int num_pool,
  2809. int num_desc)
  2810. {
  2811. uint8_t i;
  2812. /* Allocate software Tx descriptor pools */
  2813. for (i = 0; i < num_pool; i++) {
  2814. if (dp_tx_desc_pool_alloc(soc, i, num_desc)) {
  2815. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2816. "%s Tx Desc Pool alloc %d failed %pK\n",
  2817. __func__, i, soc);
  2818. return ENOMEM;
  2819. }
  2820. }
  2821. return 0;
  2822. }
  2823. static void dp_tx_delete_static_pools(struct dp_soc *soc, int num_pool)
  2824. {
  2825. uint8_t i;
  2826. for (i = 0; i < num_pool; i++) {
  2827. qdf_assert_always(!soc->tx_desc[i].num_allocated);
  2828. if (dp_tx_desc_pool_free(soc, i)) {
  2829. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2830. "%s Tx Desc Pool Free failed\n", __func__);
  2831. }
  2832. }
  2833. }
  2834. #endif /* !QCA_LL_TX_FLOW_CONTROL_V2 */
  2835. /**
  2836. * dp_tx_soc_detach() - detach soc from dp tx
  2837. * @soc: core txrx main context
  2838. *
  2839. * This function will detach dp tx into main device context
  2840. * will free dp tx resource and initialize resources
  2841. *
  2842. * Return: QDF_STATUS_SUCCESS: success
  2843. * QDF_STATUS_E_RESOURCES: Error return
  2844. */
  2845. QDF_STATUS dp_tx_soc_detach(struct dp_soc *soc)
  2846. {
  2847. uint8_t num_pool;
  2848. uint16_t num_desc;
  2849. uint16_t num_ext_desc;
  2850. uint8_t i;
  2851. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  2852. num_desc = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  2853. num_ext_desc = wlan_cfg_get_num_tx_ext_desc(soc->wlan_cfg_ctx);
  2854. dp_tx_flow_control_deinit(soc);
  2855. dp_tx_delete_static_pools(soc, num_pool);
  2856. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2857. "%s Tx Desc Pool Free num_pool = %d, descs = %d\n",
  2858. __func__, num_pool, num_desc);
  2859. for (i = 0; i < num_pool; i++) {
  2860. if (dp_tx_ext_desc_pool_free(soc, i)) {
  2861. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2862. "%s Tx Ext Desc Pool Free failed\n",
  2863. __func__);
  2864. return QDF_STATUS_E_RESOURCES;
  2865. }
  2866. }
  2867. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2868. "%s MSDU Ext Desc Pool %d Free descs = %d\n",
  2869. __func__, num_pool, num_ext_desc);
  2870. for (i = 0; i < num_pool; i++) {
  2871. dp_tx_tso_desc_pool_free(soc, i);
  2872. }
  2873. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2874. "%s TSO Desc Pool %d Free descs = %d\n",
  2875. __func__, num_pool, num_desc);
  2876. for (i = 0; i < num_pool; i++)
  2877. dp_tx_tso_num_seg_pool_free(soc, i);
  2878. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2879. "%s TSO Num of seg Desc Pool %d Free descs = %d\n",
  2880. __func__, num_pool, num_desc);
  2881. return QDF_STATUS_SUCCESS;
  2882. }
  2883. /**
  2884. * dp_tx_soc_attach() - attach soc to dp tx
  2885. * @soc: core txrx main context
  2886. *
  2887. * This function will attach dp tx into main device context
  2888. * will allocate dp tx resource and initialize resources
  2889. *
  2890. * Return: QDF_STATUS_SUCCESS: success
  2891. * QDF_STATUS_E_RESOURCES: Error return
  2892. */
  2893. QDF_STATUS dp_tx_soc_attach(struct dp_soc *soc)
  2894. {
  2895. uint8_t i;
  2896. uint8_t num_pool;
  2897. uint32_t num_desc;
  2898. uint32_t num_ext_desc;
  2899. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  2900. num_desc = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  2901. num_ext_desc = wlan_cfg_get_num_tx_ext_desc(soc->wlan_cfg_ctx);
  2902. if (dp_tx_alloc_static_pools(soc, num_pool, num_desc))
  2903. goto fail;
  2904. dp_tx_flow_control_init(soc);
  2905. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2906. "%s Tx Desc Alloc num_pool = %d, descs = %d\n",
  2907. __func__, num_pool, num_desc);
  2908. /* Allocate extension tx descriptor pools */
  2909. for (i = 0; i < num_pool; i++) {
  2910. if (dp_tx_ext_desc_pool_alloc(soc, i, num_ext_desc)) {
  2911. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2912. "MSDU Ext Desc Pool alloc %d failed %pK\n",
  2913. i, soc);
  2914. goto fail;
  2915. }
  2916. }
  2917. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2918. "%s MSDU Ext Desc Alloc %d, descs = %d\n",
  2919. __func__, num_pool, num_ext_desc);
  2920. for (i = 0; i < num_pool; i++) {
  2921. if (dp_tx_tso_desc_pool_alloc(soc, i, num_desc)) {
  2922. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2923. "TSO Desc Pool alloc %d failed %pK\n",
  2924. i, soc);
  2925. goto fail;
  2926. }
  2927. }
  2928. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2929. "%s TSO Desc Alloc %d, descs = %d\n",
  2930. __func__, num_pool, num_desc);
  2931. for (i = 0; i < num_pool; i++) {
  2932. if (dp_tx_tso_num_seg_pool_alloc(soc, i, num_desc)) {
  2933. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2934. "TSO Num of seg Pool alloc %d failed %pK\n",
  2935. i, soc);
  2936. goto fail;
  2937. }
  2938. }
  2939. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2940. "%s TSO Num of seg pool Alloc %d, descs = %d\n",
  2941. __func__, num_pool, num_desc);
  2942. /* Initialize descriptors in TCL Rings */
  2943. if (!wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  2944. for (i = 0; i < soc->num_tcl_data_rings; i++) {
  2945. hal_tx_init_data_ring(soc->hal_soc,
  2946. soc->tcl_data_ring[i].hal_srng);
  2947. }
  2948. }
  2949. /*
  2950. * todo - Add a runtime config option to enable this.
  2951. */
  2952. /*
  2953. * Due to multiple issues on NPR EMU, enable it selectively
  2954. * only for NPR EMU, should be removed, once NPR platforms
  2955. * are stable.
  2956. */
  2957. soc->process_tx_status = CONFIG_PROCESS_TX_STATUS;
  2958. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2959. "%s HAL Tx init Success\n", __func__);
  2960. return QDF_STATUS_SUCCESS;
  2961. fail:
  2962. /* Detach will take care of freeing only allocated resources */
  2963. dp_tx_soc_detach(soc);
  2964. return QDF_STATUS_E_RESOURCES;
  2965. }
  2966. /*
  2967. * dp_tx_me_mem_free(): Function to free allocated memory in mcast enahncement
  2968. * pdev: pointer to DP PDEV structure
  2969. * seg_info_head: Pointer to the head of list
  2970. *
  2971. * return: void
  2972. */
  2973. static void dp_tx_me_mem_free(struct dp_pdev *pdev,
  2974. struct dp_tx_seg_info_s *seg_info_head)
  2975. {
  2976. struct dp_tx_me_buf_t *mc_uc_buf;
  2977. struct dp_tx_seg_info_s *seg_info_new = NULL;
  2978. qdf_nbuf_t nbuf = NULL;
  2979. uint64_t phy_addr;
  2980. while (seg_info_head) {
  2981. nbuf = seg_info_head->nbuf;
  2982. mc_uc_buf = (struct dp_tx_me_buf_t *)
  2983. seg_info_head->frags[0].vaddr;
  2984. phy_addr = seg_info_head->frags[0].paddr_hi;
  2985. phy_addr = (phy_addr << 32) | seg_info_head->frags[0].paddr_lo;
  2986. qdf_mem_unmap_nbytes_single(pdev->soc->osdev,
  2987. phy_addr,
  2988. QDF_DMA_TO_DEVICE , DP_MAC_ADDR_LEN);
  2989. dp_tx_me_free_buf(pdev, mc_uc_buf);
  2990. qdf_nbuf_free(nbuf);
  2991. seg_info_new = seg_info_head;
  2992. seg_info_head = seg_info_head->next;
  2993. qdf_mem_free(seg_info_new);
  2994. }
  2995. }
  2996. /**
  2997. * dp_tx_me_send_convert_ucast(): function to convert multicast to unicast
  2998. * @vdev: DP VDEV handle
  2999. * @nbuf: Multicast nbuf
  3000. * @newmac: Table of the clients to which packets have to be sent
  3001. * @new_mac_cnt: No of clients
  3002. *
  3003. * return: no of converted packets
  3004. */
  3005. uint16_t
  3006. dp_tx_me_send_convert_ucast(struct cdp_vdev *vdev_handle, qdf_nbuf_t nbuf,
  3007. uint8_t newmac[][DP_MAC_ADDR_LEN], uint8_t new_mac_cnt)
  3008. {
  3009. struct dp_vdev *vdev = (struct dp_vdev *) vdev_handle;
  3010. struct dp_pdev *pdev = vdev->pdev;
  3011. struct ether_header *eh;
  3012. uint8_t *data;
  3013. uint16_t len;
  3014. /* reference to frame dst addr */
  3015. uint8_t *dstmac;
  3016. /* copy of original frame src addr */
  3017. uint8_t srcmac[DP_MAC_ADDR_LEN];
  3018. /* local index into newmac */
  3019. uint8_t new_mac_idx = 0;
  3020. struct dp_tx_me_buf_t *mc_uc_buf;
  3021. qdf_nbuf_t nbuf_clone;
  3022. struct dp_tx_msdu_info_s msdu_info;
  3023. struct dp_tx_seg_info_s *seg_info_head = NULL;
  3024. struct dp_tx_seg_info_s *seg_info_tail = NULL;
  3025. struct dp_tx_seg_info_s *seg_info_new;
  3026. struct dp_tx_frag_info_s data_frag;
  3027. qdf_dma_addr_t paddr_data;
  3028. qdf_dma_addr_t paddr_mcbuf = 0;
  3029. uint8_t empty_entry_mac[DP_MAC_ADDR_LEN] = {0};
  3030. QDF_STATUS status;
  3031. qdf_mem_set(&msdu_info, sizeof(msdu_info), 0x0);
  3032. dp_tx_get_queue(vdev, nbuf, &msdu_info.tx_queue);
  3033. eh = (struct ether_header *) nbuf;
  3034. qdf_mem_copy(srcmac, eh->ether_shost, DP_MAC_ADDR_LEN);
  3035. len = qdf_nbuf_len(nbuf);
  3036. data = qdf_nbuf_data(nbuf);
  3037. status = qdf_nbuf_map(vdev->osdev, nbuf,
  3038. QDF_DMA_TO_DEVICE);
  3039. if (status) {
  3040. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3041. "Mapping failure Error:%d", status);
  3042. DP_STATS_INC(vdev, tx_i.mcast_en.dropped_map_error, 1);
  3043. qdf_nbuf_free(nbuf);
  3044. return 1;
  3045. }
  3046. paddr_data = qdf_nbuf_get_frag_paddr(nbuf, 0) + IEEE80211_ADDR_LEN;
  3047. /*preparing data fragment*/
  3048. data_frag.vaddr = qdf_nbuf_data(nbuf) + IEEE80211_ADDR_LEN;
  3049. data_frag.paddr_lo = (uint32_t)paddr_data;
  3050. data_frag.paddr_hi = (((uint64_t) paddr_data) >> 32);
  3051. data_frag.len = len - DP_MAC_ADDR_LEN;
  3052. for (new_mac_idx = 0; new_mac_idx < new_mac_cnt; new_mac_idx++) {
  3053. dstmac = newmac[new_mac_idx];
  3054. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  3055. "added mac addr (%pM)", dstmac);
  3056. /* Check for NULL Mac Address */
  3057. if (!qdf_mem_cmp(dstmac, empty_entry_mac, DP_MAC_ADDR_LEN))
  3058. continue;
  3059. /* frame to self mac. skip */
  3060. if (!qdf_mem_cmp(dstmac, srcmac, DP_MAC_ADDR_LEN))
  3061. continue;
  3062. /*
  3063. * TODO: optimize to avoid malloc in per-packet path
  3064. * For eg. seg_pool can be made part of vdev structure
  3065. */
  3066. seg_info_new = qdf_mem_malloc(sizeof(*seg_info_new));
  3067. if (!seg_info_new) {
  3068. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3069. "alloc failed");
  3070. DP_STATS_INC(vdev, tx_i.mcast_en.fail_seg_alloc, 1);
  3071. goto fail_seg_alloc;
  3072. }
  3073. mc_uc_buf = dp_tx_me_alloc_buf(pdev);
  3074. if (mc_uc_buf == NULL)
  3075. goto fail_buf_alloc;
  3076. /*
  3077. * TODO: Check if we need to clone the nbuf
  3078. * Or can we just use the reference for all cases
  3079. */
  3080. if (new_mac_idx < (new_mac_cnt - 1)) {
  3081. nbuf_clone = qdf_nbuf_clone((qdf_nbuf_t)nbuf);
  3082. if (nbuf_clone == NULL) {
  3083. DP_STATS_INC(vdev, tx_i.mcast_en.clone_fail, 1);
  3084. goto fail_clone;
  3085. }
  3086. } else {
  3087. /*
  3088. * Update the ref
  3089. * to account for frame sent without cloning
  3090. */
  3091. qdf_nbuf_ref(nbuf);
  3092. nbuf_clone = nbuf;
  3093. }
  3094. qdf_mem_copy(mc_uc_buf->data, dstmac, DP_MAC_ADDR_LEN);
  3095. status = qdf_mem_map_nbytes_single(vdev->osdev, mc_uc_buf->data,
  3096. QDF_DMA_TO_DEVICE, DP_MAC_ADDR_LEN,
  3097. &paddr_mcbuf);
  3098. if (status) {
  3099. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3100. "Mapping failure Error:%d", status);
  3101. DP_STATS_INC(vdev, tx_i.mcast_en.dropped_map_error, 1);
  3102. goto fail_map;
  3103. }
  3104. seg_info_new->frags[0].vaddr = (uint8_t *)mc_uc_buf;
  3105. seg_info_new->frags[0].paddr_lo = (uint32_t) paddr_mcbuf;
  3106. seg_info_new->frags[0].paddr_hi =
  3107. ((uint64_t) paddr_mcbuf >> 32);
  3108. seg_info_new->frags[0].len = DP_MAC_ADDR_LEN;
  3109. seg_info_new->frags[1] = data_frag;
  3110. seg_info_new->nbuf = nbuf_clone;
  3111. seg_info_new->frag_cnt = 2;
  3112. seg_info_new->total_len = len;
  3113. seg_info_new->next = NULL;
  3114. if (seg_info_head == NULL)
  3115. seg_info_head = seg_info_new;
  3116. else
  3117. seg_info_tail->next = seg_info_new;
  3118. seg_info_tail = seg_info_new;
  3119. }
  3120. if (!seg_info_head) {
  3121. goto free_return;
  3122. }
  3123. msdu_info.u.sg_info.curr_seg = seg_info_head;
  3124. msdu_info.num_seg = new_mac_cnt;
  3125. msdu_info.frm_type = dp_tx_frm_me;
  3126. DP_STATS_INC(vdev, tx_i.mcast_en.ucast, new_mac_cnt);
  3127. dp_tx_send_msdu_multiple(vdev, nbuf, &msdu_info);
  3128. while (seg_info_head->next) {
  3129. seg_info_new = seg_info_head;
  3130. seg_info_head = seg_info_head->next;
  3131. qdf_mem_free(seg_info_new);
  3132. }
  3133. qdf_mem_free(seg_info_head);
  3134. qdf_nbuf_unmap(pdev->soc->osdev, nbuf, QDF_DMA_TO_DEVICE);
  3135. qdf_nbuf_free(nbuf);
  3136. return new_mac_cnt;
  3137. fail_map:
  3138. qdf_nbuf_free(nbuf_clone);
  3139. fail_clone:
  3140. dp_tx_me_free_buf(pdev, mc_uc_buf);
  3141. fail_buf_alloc:
  3142. qdf_mem_free(seg_info_new);
  3143. fail_seg_alloc:
  3144. dp_tx_me_mem_free(pdev, seg_info_head);
  3145. free_return:
  3146. qdf_nbuf_unmap(pdev->soc->osdev, nbuf, QDF_DMA_TO_DEVICE);
  3147. qdf_nbuf_free(nbuf);
  3148. return 1;
  3149. }