dp_tx.c 103 KB

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