dp_tx.c 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819
  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(soc, (uint8_t *)(eh->ether_shost));
  1489. if (ast_entry)
  1490. sa_peer = ast_entry->peer;
  1491. qdf_spin_unlock_bh(&(soc->ast_lock));
  1492. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  1493. if ((peer->peer_ids[0] != HTT_INVALID_PEER) &&
  1494. (peer->nawds_enabled)) {
  1495. if (sa_peer == peer) {
  1496. QDF_TRACE(QDF_MODULE_ID_DP,
  1497. QDF_TRACE_LEVEL_DEBUG,
  1498. " %s: broadcast multicast packet",
  1499. __func__);
  1500. DP_STATS_INC(peer, tx.nawds_mcast_drop, 1);
  1501. continue;
  1502. }
  1503. nbuf_copy = qdf_nbuf_copy(nbuf);
  1504. if (!nbuf_copy) {
  1505. QDF_TRACE(QDF_MODULE_ID_DP,
  1506. QDF_TRACE_LEVEL_ERROR,
  1507. "nbuf copy failed");
  1508. }
  1509. peer_id = peer->peer_ids[0];
  1510. nbuf_copy = dp_tx_send_msdu_single(vdev, nbuf_copy,
  1511. msdu_info, peer_id, NULL);
  1512. if (nbuf_copy != NULL) {
  1513. qdf_nbuf_free(nbuf_copy);
  1514. continue;
  1515. }
  1516. DP_STATS_INC_PKT(peer, tx.nawds_mcast,
  1517. 1, qdf_nbuf_len(nbuf));
  1518. }
  1519. }
  1520. if (peer_id == HTT_INVALID_PEER)
  1521. return nbuf;
  1522. return NULL;
  1523. }
  1524. #endif
  1525. /**
  1526. * dp_check_exc_metadata() - Checks if parameters are valid
  1527. * @tx_exc - holds all exception path parameters
  1528. *
  1529. * Returns true when all the parameters are valid else false
  1530. *
  1531. */
  1532. static bool dp_check_exc_metadata(struct cdp_tx_exception_metadata *tx_exc)
  1533. {
  1534. if ((tx_exc->tid > DP_MAX_TIDS && tx_exc->tid != HTT_INVALID_TID) ||
  1535. tx_exc->tx_encap_type > htt_cmn_pkt_num_types ||
  1536. tx_exc->sec_type > cdp_num_sec_types) {
  1537. return false;
  1538. }
  1539. return true;
  1540. }
  1541. /**
  1542. * dp_tx_send_exception() - Transmit a frame on a given VAP in exception path
  1543. * @vap_dev: DP vdev handle
  1544. * @nbuf: skb
  1545. * @tx_exc_metadata: Handle that holds exception path meta data
  1546. *
  1547. * Entry point for Core Tx layer (DP_TX) invoked from
  1548. * hard_start_xmit in OSIF/HDD to transmit frames through fw
  1549. *
  1550. * Return: NULL on success,
  1551. * nbuf when it fails to send
  1552. */
  1553. qdf_nbuf_t dp_tx_send_exception(void *vap_dev, qdf_nbuf_t nbuf,
  1554. struct cdp_tx_exception_metadata *tx_exc_metadata)
  1555. {
  1556. struct ether_header *eh = NULL;
  1557. struct dp_vdev *vdev = (struct dp_vdev *) vap_dev;
  1558. struct dp_tx_msdu_info_s msdu_info;
  1559. qdf_mem_set(&msdu_info, sizeof(msdu_info), 0x0);
  1560. msdu_info.tid = tx_exc_metadata->tid;
  1561. eh = (struct ether_header *)qdf_nbuf_data(nbuf);
  1562. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1563. "%s , skb %pM",
  1564. __func__, nbuf->data);
  1565. DP_STATS_INC_PKT(vdev, tx_i.rcvd, 1, qdf_nbuf_len(nbuf));
  1566. if (qdf_unlikely(!dp_check_exc_metadata(tx_exc_metadata))) {
  1567. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1568. "Invalid parameters in exception path");
  1569. goto fail;
  1570. }
  1571. /* Basic sanity checks for unsupported packets */
  1572. /* MESH mode */
  1573. if (qdf_unlikely(vdev->mesh_vdev)) {
  1574. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1575. "Mesh mode is not supported in exception path");
  1576. goto fail;
  1577. }
  1578. /* TSO or SG */
  1579. if (qdf_unlikely(qdf_nbuf_is_tso(nbuf)) ||
  1580. qdf_unlikely(qdf_nbuf_is_nonlinear(nbuf))) {
  1581. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1582. "TSO and SG are not supported in exception path");
  1583. goto fail;
  1584. }
  1585. /* RAW */
  1586. if (qdf_unlikely(tx_exc_metadata->tx_encap_type == htt_cmn_pkt_type_raw)) {
  1587. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1588. "Raw frame is not supported in exception path");
  1589. goto fail;
  1590. }
  1591. /* Mcast enhancement*/
  1592. if (qdf_unlikely(vdev->mcast_enhancement_en > 0)) {
  1593. if (DP_FRAME_IS_MULTICAST((eh)->ether_dhost)) {
  1594. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1595. "Ignoring mcast_enhancement_en which is set and sending the mcast packet to the FW");
  1596. }
  1597. }
  1598. /*
  1599. * Get HW Queue to use for this frame.
  1600. * TCL supports upto 4 DMA rings, out of which 3 rings are
  1601. * dedicated for data and 1 for command.
  1602. * "queue_id" maps to one hardware ring.
  1603. * With each ring, we also associate a unique Tx descriptor pool
  1604. * to minimize lock contention for these resources.
  1605. */
  1606. dp_tx_get_queue(vdev, nbuf, &msdu_info.tx_queue);
  1607. /* Single linear frame */
  1608. /*
  1609. * If nbuf is a simple linear frame, use send_single function to
  1610. * prepare direct-buffer type TCL descriptor and enqueue to TCL
  1611. * SRNG. There is no need to setup a MSDU extension descriptor.
  1612. */
  1613. nbuf = dp_tx_send_msdu_single(vdev, nbuf, &msdu_info,
  1614. tx_exc_metadata->peer_id, tx_exc_metadata);
  1615. return nbuf;
  1616. fail:
  1617. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1618. "pkt send failed");
  1619. return nbuf;
  1620. }
  1621. /**
  1622. * dp_tx_send_mesh() - Transmit mesh frame on a given VAP
  1623. * @vap_dev: DP vdev handle
  1624. * @nbuf: skb
  1625. *
  1626. * Entry point for Core Tx layer (DP_TX) invoked from
  1627. * hard_start_xmit in OSIF/HDD
  1628. *
  1629. * Return: NULL on success,
  1630. * nbuf when it fails to send
  1631. */
  1632. #ifdef MESH_MODE_SUPPORT
  1633. qdf_nbuf_t dp_tx_send_mesh(void *vap_dev, qdf_nbuf_t nbuf)
  1634. {
  1635. struct meta_hdr_s *mhdr;
  1636. qdf_nbuf_t nbuf_mesh = NULL;
  1637. qdf_nbuf_t nbuf_clone = NULL;
  1638. struct dp_vdev *vdev = (struct dp_vdev *) vap_dev;
  1639. uint8_t no_enc_frame = 0;
  1640. nbuf_mesh = qdf_nbuf_unshare(nbuf);
  1641. if (nbuf_mesh == NULL) {
  1642. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1643. "qdf_nbuf_unshare failed");
  1644. return nbuf;
  1645. }
  1646. nbuf = nbuf_mesh;
  1647. mhdr = (struct meta_hdr_s *)qdf_nbuf_data(nbuf);
  1648. if ((vdev->sec_type != cdp_sec_type_none) &&
  1649. (mhdr->flags & METAHDR_FLAG_NOENCRYPT))
  1650. no_enc_frame = 1;
  1651. if ((mhdr->flags & METAHDR_FLAG_INFO_UPDATED) &&
  1652. !no_enc_frame) {
  1653. nbuf_clone = qdf_nbuf_clone(nbuf);
  1654. if (nbuf_clone == NULL) {
  1655. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1656. "qdf_nbuf_clone failed");
  1657. return nbuf;
  1658. }
  1659. qdf_nbuf_set_tx_ftype(nbuf_clone, CB_FTYPE_MESH_TX_INFO);
  1660. }
  1661. if (nbuf_clone) {
  1662. if (!dp_tx_send(vap_dev, nbuf_clone)) {
  1663. DP_STATS_INC(vdev, tx_i.mesh.exception_fw, 1);
  1664. } else {
  1665. qdf_nbuf_free(nbuf_clone);
  1666. }
  1667. }
  1668. if (no_enc_frame)
  1669. qdf_nbuf_set_tx_ftype(nbuf, CB_FTYPE_MESH_TX_INFO);
  1670. else
  1671. qdf_nbuf_set_tx_ftype(nbuf, CB_FTYPE_INVALID);
  1672. nbuf = dp_tx_send(vap_dev, nbuf);
  1673. if ((nbuf == NULL) && no_enc_frame) {
  1674. DP_STATS_INC(vdev, tx_i.mesh.exception_fw, 1);
  1675. }
  1676. return nbuf;
  1677. }
  1678. #else
  1679. qdf_nbuf_t dp_tx_send_mesh(void *vap_dev, qdf_nbuf_t nbuf)
  1680. {
  1681. return dp_tx_send(vap_dev, nbuf);
  1682. }
  1683. #endif
  1684. /**
  1685. * dp_tx_send() - Transmit a frame on a given VAP
  1686. * @vap_dev: DP vdev handle
  1687. * @nbuf: skb
  1688. *
  1689. * Entry point for Core Tx layer (DP_TX) invoked from
  1690. * hard_start_xmit in OSIF/HDD or from dp_rx_process for intravap forwarding
  1691. * cases
  1692. *
  1693. * Return: NULL on success,
  1694. * nbuf when it fails to send
  1695. */
  1696. qdf_nbuf_t dp_tx_send(void *vap_dev, qdf_nbuf_t nbuf)
  1697. {
  1698. struct ether_header *eh = NULL;
  1699. struct dp_tx_msdu_info_s msdu_info;
  1700. struct dp_tx_seg_info_s seg_info;
  1701. struct dp_vdev *vdev = (struct dp_vdev *) vap_dev;
  1702. uint16_t peer_id = HTT_INVALID_PEER;
  1703. qdf_nbuf_t nbuf_mesh = NULL;
  1704. qdf_mem_set(&msdu_info, sizeof(msdu_info), 0x0);
  1705. qdf_mem_set(&seg_info, sizeof(seg_info), 0x0);
  1706. eh = (struct ether_header *)qdf_nbuf_data(nbuf);
  1707. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1708. "%s , skb %pM",
  1709. __func__, nbuf->data);
  1710. /*
  1711. * Set Default Host TID value to invalid TID
  1712. * (TID override disabled)
  1713. */
  1714. msdu_info.tid = HTT_TX_EXT_TID_INVALID;
  1715. DP_STATS_INC_PKT(vdev, tx_i.rcvd, 1, qdf_nbuf_len(nbuf));
  1716. if (qdf_unlikely(vdev->mesh_vdev)) {
  1717. nbuf_mesh = dp_tx_extract_mesh_meta_data(vdev, nbuf,
  1718. &msdu_info);
  1719. if (nbuf_mesh == NULL) {
  1720. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1721. "Extracting mesh metadata failed");
  1722. return nbuf;
  1723. }
  1724. nbuf = nbuf_mesh;
  1725. }
  1726. /*
  1727. * Get HW Queue to use for this frame.
  1728. * TCL supports upto 4 DMA rings, out of which 3 rings are
  1729. * dedicated for data and 1 for command.
  1730. * "queue_id" maps to one hardware ring.
  1731. * With each ring, we also associate a unique Tx descriptor pool
  1732. * to minimize lock contention for these resources.
  1733. */
  1734. dp_tx_get_queue(vdev, nbuf, &msdu_info.tx_queue);
  1735. /*
  1736. * TCL H/W supports 2 DSCP-TID mapping tables.
  1737. * Table 1 - Default DSCP-TID mapping table
  1738. * Table 2 - 1 DSCP-TID override table
  1739. *
  1740. * If we need a different DSCP-TID mapping for this vap,
  1741. * call tid_classify to extract DSCP/ToS from frame and
  1742. * map to a TID and store in msdu_info. This is later used
  1743. * to fill in TCL Input descriptor (per-packet TID override).
  1744. */
  1745. dp_tx_classify_tid(vdev, nbuf, &msdu_info);
  1746. /*
  1747. * Classify the frame and call corresponding
  1748. * "prepare" function which extracts the segment (TSO)
  1749. * and fragmentation information (for TSO , SG, ME, or Raw)
  1750. * into MSDU_INFO structure which is later used to fill
  1751. * SW and HW descriptors.
  1752. */
  1753. if (qdf_nbuf_is_tso(nbuf)) {
  1754. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1755. "%s TSO frame %pK", __func__, vdev);
  1756. DP_STATS_INC_PKT(vdev, tx_i.tso.tso_pkt, 1,
  1757. qdf_nbuf_len(nbuf));
  1758. if (dp_tx_prepare_tso(vdev, nbuf, &msdu_info)) {
  1759. DP_STATS_INC_PKT(vdev, tx_i.tso.dropped_host, 1,
  1760. qdf_nbuf_len(nbuf));
  1761. return nbuf;
  1762. }
  1763. goto send_multiple;
  1764. }
  1765. /* SG */
  1766. if (qdf_unlikely(qdf_nbuf_is_nonlinear(nbuf))) {
  1767. nbuf = dp_tx_prepare_sg(vdev, nbuf, &seg_info, &msdu_info);
  1768. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1769. "%s non-TSO SG frame %pK", __func__, vdev);
  1770. DP_STATS_INC_PKT(vdev, tx_i.sg.sg_pkt, 1,
  1771. qdf_nbuf_len(nbuf));
  1772. goto send_multiple;
  1773. }
  1774. #ifdef ATH_SUPPORT_IQUE
  1775. /* Mcast to Ucast Conversion*/
  1776. if (qdf_unlikely(vdev->mcast_enhancement_en > 0)) {
  1777. eh = (struct ether_header *)qdf_nbuf_data(nbuf);
  1778. if (DP_FRAME_IS_MULTICAST((eh)->ether_dhost)) {
  1779. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1780. "%s Mcast frm for ME %pK", __func__, vdev);
  1781. DP_STATS_INC_PKT(vdev,
  1782. tx_i.mcast_en.mcast_pkt, 1,
  1783. qdf_nbuf_len(nbuf));
  1784. if (dp_tx_prepare_send_me(vdev, nbuf) ==
  1785. QDF_STATUS_SUCCESS) {
  1786. return NULL;
  1787. }
  1788. }
  1789. }
  1790. #endif
  1791. /* RAW */
  1792. if (qdf_unlikely(vdev->tx_encap_type == htt_cmn_pkt_type_raw)) {
  1793. nbuf = dp_tx_prepare_raw(vdev, nbuf, &seg_info, &msdu_info);
  1794. if (nbuf == NULL)
  1795. return NULL;
  1796. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1797. "%s Raw frame %pK", __func__, vdev);
  1798. goto send_multiple;
  1799. }
  1800. /* Single linear frame */
  1801. /*
  1802. * If nbuf is a simple linear frame, use send_single function to
  1803. * prepare direct-buffer type TCL descriptor and enqueue to TCL
  1804. * SRNG. There is no need to setup a MSDU extension descriptor.
  1805. */
  1806. nbuf = dp_tx_send_msdu_single(vdev, nbuf, &msdu_info, peer_id, NULL);
  1807. return nbuf;
  1808. send_multiple:
  1809. nbuf = dp_tx_send_msdu_multiple(vdev, nbuf, &msdu_info);
  1810. return nbuf;
  1811. }
  1812. /**
  1813. * dp_tx_reinject_handler() - Tx Reinject Handler
  1814. * @tx_desc: software descriptor head pointer
  1815. * @status : Tx completion status from HTT descriptor
  1816. *
  1817. * This function reinjects frames back to Target.
  1818. * Todo - Host queue needs to be added
  1819. *
  1820. * Return: none
  1821. */
  1822. static
  1823. void dp_tx_reinject_handler(struct dp_tx_desc_s *tx_desc, uint8_t *status)
  1824. {
  1825. struct dp_vdev *vdev;
  1826. struct dp_peer *peer = NULL;
  1827. uint32_t peer_id = HTT_INVALID_PEER;
  1828. qdf_nbuf_t nbuf = tx_desc->nbuf;
  1829. qdf_nbuf_t nbuf_copy = NULL;
  1830. struct dp_tx_msdu_info_s msdu_info;
  1831. struct dp_peer *sa_peer = NULL;
  1832. struct dp_ast_entry *ast_entry = NULL;
  1833. struct dp_soc *soc = NULL;
  1834. struct ether_header *eh = (struct ether_header *)qdf_nbuf_data(nbuf);
  1835. #ifdef WDS_VENDOR_EXTENSION
  1836. int is_mcast = 0, is_ucast = 0;
  1837. int num_peers_3addr = 0;
  1838. struct ether_header *eth_hdr = (struct ether_header *)(qdf_nbuf_data(nbuf));
  1839. struct ieee80211_frame_addr4 *wh = (struct ieee80211_frame_addr4 *)(qdf_nbuf_data(nbuf));
  1840. #endif
  1841. vdev = tx_desc->vdev;
  1842. soc = vdev->pdev->soc;
  1843. qdf_assert(vdev);
  1844. qdf_mem_set(&msdu_info, sizeof(msdu_info), 0x0);
  1845. dp_tx_get_queue(vdev, nbuf, &msdu_info.tx_queue);
  1846. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1847. "%s Tx reinject path", __func__);
  1848. DP_STATS_INC_PKT(vdev, tx_i.reinject_pkts, 1,
  1849. qdf_nbuf_len(tx_desc->nbuf));
  1850. qdf_spin_lock_bh(&(soc->ast_lock));
  1851. ast_entry = dp_peer_ast_hash_find(soc, (uint8_t *)(eh->ether_shost));
  1852. if (ast_entry)
  1853. sa_peer = ast_entry->peer;
  1854. qdf_spin_unlock_bh(&(soc->ast_lock));
  1855. #ifdef WDS_VENDOR_EXTENSION
  1856. if (qdf_unlikely(vdev->tx_encap_type != htt_cmn_pkt_type_raw)) {
  1857. is_mcast = (IS_MULTICAST(wh->i_addr1)) ? 1 : 0;
  1858. } else {
  1859. is_mcast = (IS_MULTICAST(eth_hdr->ether_dhost)) ? 1 : 0;
  1860. }
  1861. is_ucast = !is_mcast;
  1862. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  1863. if (peer->bss_peer)
  1864. continue;
  1865. /* Detect wds peers that use 3-addr framing for mcast.
  1866. * if there are any, the bss_peer is used to send the
  1867. * the mcast frame using 3-addr format. all wds enabled
  1868. * peers that use 4-addr framing for mcast frames will
  1869. * be duplicated and sent as 4-addr frames below.
  1870. */
  1871. if (!peer->wds_enabled || !peer->wds_ecm.wds_tx_mcast_4addr) {
  1872. num_peers_3addr = 1;
  1873. break;
  1874. }
  1875. }
  1876. #endif
  1877. if (qdf_unlikely(vdev->mesh_vdev)) {
  1878. DP_TX_FREE_SINGLE_BUF(vdev->pdev->soc, tx_desc->nbuf);
  1879. } else {
  1880. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  1881. if ((peer->peer_ids[0] != HTT_INVALID_PEER) &&
  1882. #ifdef WDS_VENDOR_EXTENSION
  1883. /*
  1884. * . if 3-addr STA, then send on BSS Peer
  1885. * . if Peer WDS enabled and accept 4-addr mcast,
  1886. * send mcast on that peer only
  1887. * . if Peer WDS enabled and accept 4-addr ucast,
  1888. * send ucast on that peer only
  1889. */
  1890. ((peer->bss_peer && num_peers_3addr && is_mcast) ||
  1891. (peer->wds_enabled &&
  1892. ((is_mcast && peer->wds_ecm.wds_tx_mcast_4addr) ||
  1893. (is_ucast && peer->wds_ecm.wds_tx_ucast_4addr))))) {
  1894. #else
  1895. ((peer->bss_peer &&
  1896. !(vdev->osif_proxy_arp(vdev->osif_vdev, nbuf))) ||
  1897. peer->nawds_enabled)) {
  1898. #endif
  1899. peer_id = DP_INVALID_PEER;
  1900. if (peer->nawds_enabled) {
  1901. peer_id = peer->peer_ids[0];
  1902. if (sa_peer == peer) {
  1903. QDF_TRACE(
  1904. QDF_MODULE_ID_DP,
  1905. QDF_TRACE_LEVEL_DEBUG,
  1906. " %s: multicast packet",
  1907. __func__);
  1908. DP_STATS_INC(peer,
  1909. tx.nawds_mcast_drop, 1);
  1910. continue;
  1911. }
  1912. }
  1913. nbuf_copy = qdf_nbuf_copy(nbuf);
  1914. if (!nbuf_copy) {
  1915. QDF_TRACE(QDF_MODULE_ID_DP,
  1916. QDF_TRACE_LEVEL_DEBUG,
  1917. FL("nbuf copy failed"));
  1918. break;
  1919. }
  1920. nbuf_copy = dp_tx_send_msdu_single(vdev,
  1921. nbuf_copy,
  1922. &msdu_info,
  1923. peer_id,
  1924. NULL);
  1925. if (nbuf_copy) {
  1926. QDF_TRACE(QDF_MODULE_ID_DP,
  1927. QDF_TRACE_LEVEL_DEBUG,
  1928. FL("pkt send failed"));
  1929. qdf_nbuf_free(nbuf_copy);
  1930. } else {
  1931. if (peer_id != DP_INVALID_PEER)
  1932. DP_STATS_INC_PKT(peer,
  1933. tx.nawds_mcast,
  1934. 1, qdf_nbuf_len(nbuf));
  1935. }
  1936. }
  1937. }
  1938. }
  1939. if (vdev->nawds_enabled) {
  1940. peer_id = DP_INVALID_PEER;
  1941. DP_STATS_INC_PKT(vdev, tx_i.nawds_mcast,
  1942. 1, qdf_nbuf_len(nbuf));
  1943. nbuf = dp_tx_send_msdu_single(vdev,
  1944. nbuf,
  1945. &msdu_info,
  1946. peer_id, NULL);
  1947. if (nbuf) {
  1948. QDF_TRACE(QDF_MODULE_ID_DP,
  1949. QDF_TRACE_LEVEL_DEBUG,
  1950. FL("pkt send failed"));
  1951. qdf_nbuf_free(nbuf);
  1952. }
  1953. } else
  1954. qdf_nbuf_free(nbuf);
  1955. dp_tx_desc_release(tx_desc, tx_desc->pool_id);
  1956. }
  1957. /**
  1958. * dp_tx_inspect_handler() - Tx Inspect Handler
  1959. * @tx_desc: software descriptor head pointer
  1960. * @status : Tx completion status from HTT descriptor
  1961. *
  1962. * Handles Tx frames sent back to Host for inspection
  1963. * (ProxyARP)
  1964. *
  1965. * Return: none
  1966. */
  1967. static void dp_tx_inspect_handler(struct dp_tx_desc_s *tx_desc, uint8_t *status)
  1968. {
  1969. struct dp_soc *soc;
  1970. struct dp_pdev *pdev = tx_desc->pdev;
  1971. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  1972. "%s Tx inspect path",
  1973. __func__);
  1974. qdf_assert(pdev);
  1975. soc = pdev->soc;
  1976. DP_STATS_INC_PKT(tx_desc->vdev, tx_i.inspect_pkts, 1,
  1977. qdf_nbuf_len(tx_desc->nbuf));
  1978. DP_TX_FREE_SINGLE_BUF(soc, tx_desc->nbuf);
  1979. dp_tx_desc_release(tx_desc, tx_desc->pool_id);
  1980. }
  1981. #ifdef FEATURE_PERPKT_INFO
  1982. /**
  1983. * dp_get_completion_indication_for_stack() - send completion to stack
  1984. * @soc : dp_soc handle
  1985. * @pdev: dp_pdev handle
  1986. * @peer: dp peer handle
  1987. * @ts: transmit completion status structure
  1988. * @netbuf: Buffer pointer for free
  1989. *
  1990. * This function is used for indication whether buffer needs to be
  1991. * sent to stack for freeing or not
  1992. */
  1993. QDF_STATUS
  1994. dp_get_completion_indication_for_stack(struct dp_soc *soc,
  1995. struct dp_pdev *pdev,
  1996. struct dp_peer *peer,
  1997. struct hal_tx_completion_status *ts,
  1998. qdf_nbuf_t netbuf)
  1999. {
  2000. struct tx_capture_hdr *ppdu_hdr;
  2001. uint16_t peer_id = ts->peer_id;
  2002. uint32_t ppdu_id = ts->ppdu_id;
  2003. uint8_t first_msdu = ts->first_msdu;
  2004. uint8_t last_msdu = ts->last_msdu;
  2005. if (qdf_unlikely(!pdev->tx_sniffer_enable && !pdev->mcopy_mode))
  2006. return QDF_STATUS_E_NOSUPPORT;
  2007. if (!peer) {
  2008. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2009. FL("Peer Invalid"));
  2010. return QDF_STATUS_E_INVAL;
  2011. }
  2012. if (pdev->mcopy_mode) {
  2013. if ((pdev->m_copy_id.tx_ppdu_id == ppdu_id) &&
  2014. (pdev->m_copy_id.tx_peer_id == peer_id)) {
  2015. return QDF_STATUS_E_INVAL;
  2016. }
  2017. pdev->m_copy_id.tx_ppdu_id = ppdu_id;
  2018. pdev->m_copy_id.tx_peer_id = peer_id;
  2019. }
  2020. if (!qdf_nbuf_push_head(netbuf, sizeof(struct tx_capture_hdr))) {
  2021. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2022. FL("No headroom"));
  2023. return QDF_STATUS_E_NOMEM;
  2024. }
  2025. ppdu_hdr = (struct tx_capture_hdr *)qdf_nbuf_data(netbuf);
  2026. qdf_mem_copy(ppdu_hdr->ta, peer->vdev->mac_addr.raw,
  2027. IEEE80211_ADDR_LEN);
  2028. qdf_mem_copy(ppdu_hdr->ra, peer->mac_addr.raw,
  2029. IEEE80211_ADDR_LEN);
  2030. ppdu_hdr->ppdu_id = ppdu_id;
  2031. ppdu_hdr->peer_id = peer_id;
  2032. ppdu_hdr->first_msdu = first_msdu;
  2033. ppdu_hdr->last_msdu = last_msdu;
  2034. return QDF_STATUS_SUCCESS;
  2035. }
  2036. /**
  2037. * dp_send_completion_to_stack() - send completion to stack
  2038. * @soc : dp_soc handle
  2039. * @pdev: dp_pdev handle
  2040. * @peer_id: peer_id of the peer for which completion came
  2041. * @ppdu_id: ppdu_id
  2042. * @netbuf: Buffer pointer for free
  2043. *
  2044. * This function is used to send completion to stack
  2045. * to free buffer
  2046. */
  2047. void dp_send_completion_to_stack(struct dp_soc *soc, struct dp_pdev *pdev,
  2048. uint16_t peer_id, uint32_t ppdu_id,
  2049. qdf_nbuf_t netbuf)
  2050. {
  2051. dp_wdi_event_handler(WDI_EVENT_TX_DATA, soc,
  2052. netbuf, peer_id,
  2053. WDI_NO_VAL, pdev->pdev_id);
  2054. }
  2055. #else
  2056. static QDF_STATUS
  2057. dp_get_completion_indication_for_stack(struct dp_soc *soc,
  2058. struct dp_pdev *pdev,
  2059. struct dp_peer *peer,
  2060. struct hal_tx_completion_status *ts,
  2061. qdf_nbuf_t netbuf)
  2062. {
  2063. return QDF_STATUS_E_NOSUPPORT;
  2064. }
  2065. static void
  2066. dp_send_completion_to_stack(struct dp_soc *soc, struct dp_pdev *pdev,
  2067. uint16_t peer_id, uint32_t ppdu_id, qdf_nbuf_t netbuf)
  2068. {
  2069. }
  2070. #endif
  2071. /**
  2072. * dp_tx_comp_free_buf() - Free nbuf associated with the Tx Descriptor
  2073. * @soc: Soc handle
  2074. * @desc: software Tx descriptor to be processed
  2075. *
  2076. * Return: none
  2077. */
  2078. static inline void dp_tx_comp_free_buf(struct dp_soc *soc,
  2079. struct dp_tx_desc_s *desc)
  2080. {
  2081. struct dp_vdev *vdev = desc->vdev;
  2082. qdf_nbuf_t nbuf = desc->nbuf;
  2083. /* If it is TDLS mgmt, don't unmap or free the frame */
  2084. if (desc->flags & DP_TX_DESC_FLAG_TDLS_FRAME)
  2085. return dp_non_std_tx_comp_free_buff(desc, vdev);
  2086. /* 0 : MSDU buffer, 1 : MLE */
  2087. if (desc->msdu_ext_desc) {
  2088. /* TSO free */
  2089. if (hal_tx_ext_desc_get_tso_enable(
  2090. desc->msdu_ext_desc->vaddr)) {
  2091. /* unmap eash TSO seg before free the nbuf */
  2092. dp_tx_tso_unmap_segment(soc, desc);
  2093. qdf_nbuf_free(nbuf);
  2094. return;
  2095. }
  2096. }
  2097. qdf_nbuf_unmap(soc->osdev, nbuf, QDF_DMA_TO_DEVICE);
  2098. if (qdf_likely(!vdev->mesh_vdev))
  2099. qdf_nbuf_free(nbuf);
  2100. else {
  2101. if (desc->flags & DP_TX_DESC_FLAG_TO_FW) {
  2102. qdf_nbuf_free(nbuf);
  2103. DP_STATS_INC(vdev, tx_i.mesh.completion_fw, 1);
  2104. } else
  2105. vdev->osif_tx_free_ext((nbuf));
  2106. }
  2107. }
  2108. /**
  2109. * dp_tx_mec_handler() - Tx MEC Notify Handler
  2110. * @vdev: pointer to dp dev handler
  2111. * @status : Tx completion status from HTT descriptor
  2112. *
  2113. * Handles MEC notify event sent from fw to Host
  2114. *
  2115. * Return: none
  2116. */
  2117. #ifdef FEATURE_WDS
  2118. void dp_tx_mec_handler(struct dp_vdev *vdev, uint8_t *status)
  2119. {
  2120. struct dp_soc *soc;
  2121. uint32_t flags = IEEE80211_NODE_F_WDS_HM;
  2122. struct dp_peer *peer;
  2123. uint8_t mac_addr[DP_MAC_ADDR_LEN], i;
  2124. if (!vdev->wds_enabled)
  2125. return;
  2126. /* MEC required only in STA mode */
  2127. if (vdev->opmode != wlan_op_mode_sta)
  2128. return;
  2129. soc = vdev->pdev->soc;
  2130. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  2131. peer = TAILQ_FIRST(&vdev->peer_list);
  2132. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  2133. if (!peer) {
  2134. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2135. FL("peer is NULL"));
  2136. return;
  2137. }
  2138. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2139. "%s Tx MEC Handler",
  2140. __func__);
  2141. for (i = 0; i < DP_MAC_ADDR_LEN; i++)
  2142. mac_addr[(DP_MAC_ADDR_LEN - 1) - i] =
  2143. status[(DP_MAC_ADDR_LEN - 2) + i];
  2144. if (qdf_mem_cmp(mac_addr, vdev->mac_addr.raw, DP_MAC_ADDR_LEN))
  2145. dp_peer_add_ast(soc,
  2146. peer,
  2147. mac_addr,
  2148. CDP_TXRX_AST_TYPE_MEC,
  2149. flags);
  2150. }
  2151. #endif
  2152. #ifdef MESH_MODE_SUPPORT
  2153. /**
  2154. * dp_tx_comp_fill_tx_completion_stats() - Fill per packet Tx completion stats
  2155. * in mesh meta header
  2156. * @tx_desc: software descriptor head pointer
  2157. * @ts: pointer to tx completion stats
  2158. * Return: none
  2159. */
  2160. static
  2161. void dp_tx_comp_fill_tx_completion_stats(struct dp_tx_desc_s *tx_desc,
  2162. struct hal_tx_completion_status *ts)
  2163. {
  2164. struct meta_hdr_s *mhdr;
  2165. qdf_nbuf_t netbuf = tx_desc->nbuf;
  2166. if (!tx_desc->msdu_ext_desc) {
  2167. if (qdf_nbuf_pull_head(netbuf, tx_desc->pkt_offset) == NULL) {
  2168. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2169. "netbuf %pK offset %d",
  2170. netbuf, tx_desc->pkt_offset);
  2171. return;
  2172. }
  2173. }
  2174. if (qdf_nbuf_push_head(netbuf, sizeof(struct meta_hdr_s)) == NULL) {
  2175. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2176. "netbuf %pK offset %d", netbuf,
  2177. sizeof(struct meta_hdr_s));
  2178. return;
  2179. }
  2180. mhdr = (struct meta_hdr_s *)qdf_nbuf_data(netbuf);
  2181. mhdr->rssi = ts->ack_frame_rssi;
  2182. mhdr->channel = tx_desc->pdev->operating_channel;
  2183. }
  2184. #else
  2185. static
  2186. void dp_tx_comp_fill_tx_completion_stats(struct dp_tx_desc_s *tx_desc,
  2187. struct hal_tx_completion_status *ts)
  2188. {
  2189. }
  2190. #endif
  2191. /**
  2192. * dp_tx_update_peer_stats() - Update peer stats from Tx completion indications
  2193. * @peer: Handle to DP peer
  2194. * @ts: pointer to HAL Tx completion stats
  2195. *
  2196. * Return: None
  2197. */
  2198. static inline void
  2199. dp_tx_update_peer_stats(struct dp_peer *peer,
  2200. struct hal_tx_completion_status *ts)
  2201. {
  2202. struct dp_pdev *pdev = peer->vdev->pdev;
  2203. struct dp_soc *soc = pdev->soc;
  2204. uint8_t mcs, pkt_type;
  2205. mcs = ts->mcs;
  2206. pkt_type = ts->pkt_type;
  2207. if (!ts->release_src == HAL_TX_COMP_RELEASE_SOURCE_TQM)
  2208. return;
  2209. DP_STATS_INCC(peer, tx.dropped.age_out, 1,
  2210. (ts->status == HAL_TX_TQM_RR_REM_CMD_AGED));
  2211. DP_STATS_INCC(peer, tx.dropped.fw_rem, 1,
  2212. (ts->status == HAL_TX_TQM_RR_REM_CMD_REM));
  2213. DP_STATS_INCC(peer, tx.dropped.fw_rem_notx, 1,
  2214. (ts->status == HAL_TX_TQM_RR_REM_CMD_NOTX));
  2215. DP_STATS_INCC(peer, tx.dropped.fw_rem_tx, 1,
  2216. (ts->status == HAL_TX_TQM_RR_REM_CMD_TX));
  2217. DP_STATS_INCC(peer, tx.dropped.fw_reason1, 1,
  2218. (ts->status == HAL_TX_TQM_RR_FW_REASON1));
  2219. DP_STATS_INCC(peer, tx.dropped.fw_reason2, 1,
  2220. (ts->status == HAL_TX_TQM_RR_FW_REASON2));
  2221. DP_STATS_INCC(peer, tx.dropped.fw_reason3, 1,
  2222. (ts->status == HAL_TX_TQM_RR_FW_REASON3));
  2223. if (!ts->status == HAL_TX_TQM_RR_FRAME_ACKED)
  2224. return;
  2225. DP_STATS_INCC(peer, tx.ofdma, 1, ts->ofdma);
  2226. DP_STATS_INCC(peer, tx.amsdu_cnt, 1, ts->msdu_part_of_amsdu);
  2227. DP_STATS_INCC(peer, tx.non_amsdu_cnt, 1, !ts->msdu_part_of_amsdu);
  2228. /*
  2229. * Following Rate Statistics are updated from HTT PPDU events from FW.
  2230. * Return from here if HTT PPDU events are enabled.
  2231. */
  2232. if (!(soc->process_tx_status))
  2233. return;
  2234. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  2235. ((mcs >= MAX_MCS_11A) && (pkt_type == DOT11_A)));
  2236. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[mcs], 1,
  2237. ((mcs < (MAX_MCS_11A)) && (pkt_type == DOT11_A)));
  2238. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  2239. ((mcs >= MAX_MCS_11B) && (pkt_type == DOT11_B)));
  2240. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[mcs], 1,
  2241. ((mcs < MAX_MCS_11B) && (pkt_type == DOT11_B)));
  2242. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  2243. ((mcs >= MAX_MCS_11A) && (pkt_type == DOT11_N)));
  2244. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[mcs], 1,
  2245. ((mcs < MAX_MCS_11A) && (pkt_type == DOT11_N)));
  2246. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  2247. ((mcs >= MAX_MCS_11AC) && (pkt_type == DOT11_AC)));
  2248. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[mcs], 1,
  2249. ((mcs < MAX_MCS_11AC) && (pkt_type == DOT11_AC)));
  2250. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  2251. ((mcs >= (MAX_MCS - 1)) && (pkt_type == DOT11_AX)));
  2252. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[mcs], 1,
  2253. ((mcs < (MAX_MCS - 1)) && (pkt_type == DOT11_AX)));
  2254. DP_STATS_INC(peer, tx.sgi_count[ts->sgi], 1);
  2255. DP_STATS_INC(peer, tx.bw[ts->bw], 1);
  2256. DP_STATS_UPD(peer, tx.last_ack_rssi, ts->ack_frame_rssi);
  2257. DP_STATS_INC(peer, tx.wme_ac_type[TID_TO_WME_AC(ts->tid)], 1);
  2258. DP_STATS_INCC(peer, tx.stbc, 1, ts->stbc);
  2259. DP_STATS_INCC(peer, tx.ldpc, 1, ts->ldpc);
  2260. DP_STATS_INCC(peer, tx.retries, 1, ts->transmit_cnt > 1);
  2261. if (soc->cdp_soc.ol_ops->update_dp_stats) {
  2262. soc->cdp_soc.ol_ops->update_dp_stats(pdev->ctrl_pdev,
  2263. &peer->stats, ts->peer_id,
  2264. UPDATE_PEER_STATS);
  2265. }
  2266. }
  2267. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  2268. /**
  2269. * dp_tx_flow_pool_lock() - take flow pool lock
  2270. * @soc: core txrx main context
  2271. * @tx_desc: tx desc
  2272. *
  2273. * Return: None
  2274. */
  2275. static inline
  2276. void dp_tx_flow_pool_lock(struct dp_soc *soc,
  2277. struct dp_tx_desc_s *tx_desc)
  2278. {
  2279. struct dp_tx_desc_pool_s *pool;
  2280. uint8_t desc_pool_id;
  2281. desc_pool_id = tx_desc->pool_id;
  2282. pool = &soc->tx_desc[desc_pool_id];
  2283. qdf_spin_lock_bh(&pool->flow_pool_lock);
  2284. }
  2285. /**
  2286. * dp_tx_flow_pool_unlock() - release flow pool lock
  2287. * @soc: core txrx main context
  2288. * @tx_desc: tx desc
  2289. *
  2290. * Return: None
  2291. */
  2292. static inline
  2293. void dp_tx_flow_pool_unlock(struct dp_soc *soc,
  2294. struct dp_tx_desc_s *tx_desc)
  2295. {
  2296. struct dp_tx_desc_pool_s *pool;
  2297. uint8_t desc_pool_id;
  2298. desc_pool_id = tx_desc->pool_id;
  2299. pool = &soc->tx_desc[desc_pool_id];
  2300. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  2301. }
  2302. #else
  2303. static inline
  2304. void dp_tx_flow_pool_lock(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc)
  2305. {
  2306. }
  2307. static inline
  2308. void dp_tx_flow_pool_unlock(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc)
  2309. {
  2310. }
  2311. #endif
  2312. /**
  2313. * dp_tx_notify_completion() - Notify tx completion for this desc
  2314. * @soc: core txrx main context
  2315. * @tx_desc: tx desc
  2316. * @netbuf: buffer
  2317. *
  2318. * Return: none
  2319. */
  2320. static inline void dp_tx_notify_completion(struct dp_soc *soc,
  2321. struct dp_tx_desc_s *tx_desc,
  2322. qdf_nbuf_t netbuf)
  2323. {
  2324. void *osif_dev;
  2325. ol_txrx_completion_fp tx_compl_cbk = NULL;
  2326. qdf_assert(tx_desc);
  2327. dp_tx_flow_pool_lock(soc, tx_desc);
  2328. if (!tx_desc->vdev ||
  2329. !tx_desc->vdev->osif_vdev) {
  2330. dp_tx_flow_pool_unlock(soc, tx_desc);
  2331. return;
  2332. }
  2333. osif_dev = tx_desc->vdev->osif_vdev;
  2334. tx_compl_cbk = tx_desc->vdev->tx_comp;
  2335. dp_tx_flow_pool_unlock(soc, tx_desc);
  2336. if (tx_compl_cbk)
  2337. tx_compl_cbk(netbuf, osif_dev);
  2338. }
  2339. /** dp_tx_sojourn_stats_process() - Collect sojourn stats
  2340. * @pdev: pdev handle
  2341. * @tid: tid value
  2342. * @txdesc_ts: timestamp from txdesc
  2343. * @ppdu_id: ppdu id
  2344. *
  2345. * Return: none
  2346. */
  2347. #ifdef FEATURE_PERPKT_INFO
  2348. static inline void dp_tx_sojourn_stats_process(struct dp_pdev *pdev,
  2349. uint8_t tid,
  2350. uint64_t txdesc_ts,
  2351. uint32_t ppdu_id)
  2352. {
  2353. uint64_t delta_ms;
  2354. struct cdp_tx_sojourn_stats *sojourn_stats;
  2355. if (pdev->enhanced_stats_en == 0)
  2356. return;
  2357. if (pdev->sojourn_stats.ppdu_seq_id == 0)
  2358. pdev->sojourn_stats.ppdu_seq_id = ppdu_id;
  2359. if (ppdu_id != pdev->sojourn_stats.ppdu_seq_id) {
  2360. if (!pdev->sojourn_buf)
  2361. return;
  2362. sojourn_stats = (struct cdp_tx_sojourn_stats *)
  2363. qdf_nbuf_data(pdev->sojourn_buf);
  2364. qdf_mem_copy(sojourn_stats, &pdev->sojourn_stats,
  2365. sizeof(struct cdp_tx_sojourn_stats));
  2366. qdf_mem_zero(&pdev->sojourn_stats,
  2367. sizeof(struct cdp_tx_sojourn_stats));
  2368. dp_wdi_event_handler(WDI_EVENT_TX_SOJOURN_STAT, pdev->soc,
  2369. pdev->sojourn_buf, HTT_INVALID_PEER,
  2370. WDI_NO_VAL, pdev->pdev_id);
  2371. pdev->sojourn_stats.ppdu_seq_id = ppdu_id;
  2372. }
  2373. if (tid == HTT_INVALID_TID)
  2374. return;
  2375. delta_ms = qdf_ktime_to_ms(qdf_ktime_get()) -
  2376. txdesc_ts;
  2377. qdf_ewma_tx_lag_add(&pdev->sojourn_stats.avg_sojourn_msdu[tid],
  2378. delta_ms);
  2379. pdev->sojourn_stats.sum_sojourn_msdu[tid] += delta_ms;
  2380. pdev->sojourn_stats.num_msdus[tid]++;
  2381. }
  2382. #else
  2383. static inline void dp_tx_sojourn_stats_process(struct dp_pdev *pdev,
  2384. uint8_t tid,
  2385. uint64_t txdesc_ts,
  2386. uint32_t ppdu_id)
  2387. {
  2388. }
  2389. #endif
  2390. /**
  2391. * dp_tx_comp_process_desc() - Process tx descriptor and free associated nbuf
  2392. * @soc: DP Soc handle
  2393. * @tx_desc: software Tx descriptor
  2394. * @ts : Tx completion status from HAL/HTT descriptor
  2395. *
  2396. * Return: none
  2397. */
  2398. static inline void
  2399. dp_tx_comp_process_desc(struct dp_soc *soc,
  2400. struct dp_tx_desc_s *desc,
  2401. struct hal_tx_completion_status *ts,
  2402. struct dp_peer *peer)
  2403. {
  2404. /*
  2405. * m_copy/tx_capture modes are not supported for
  2406. * scatter gather packets
  2407. */
  2408. if (!(desc->msdu_ext_desc) &&
  2409. (dp_get_completion_indication_for_stack(soc, desc->pdev,
  2410. peer, ts, desc->nbuf)
  2411. == QDF_STATUS_SUCCESS)) {
  2412. qdf_nbuf_unmap(soc->osdev, desc->nbuf,
  2413. QDF_DMA_TO_DEVICE);
  2414. dp_send_completion_to_stack(soc, desc->pdev, ts->peer_id,
  2415. ts->ppdu_id, desc->nbuf);
  2416. } else {
  2417. dp_tx_comp_free_buf(soc, desc);
  2418. }
  2419. }
  2420. /**
  2421. * dp_tx_comp_process_tx_status() - Parse and Dump Tx completion status info
  2422. * @tx_desc: software descriptor head pointer
  2423. * @ts: Tx completion status
  2424. * @peer: peer handle
  2425. *
  2426. * Return: none
  2427. */
  2428. static inline
  2429. void dp_tx_comp_process_tx_status(struct dp_tx_desc_s *tx_desc,
  2430. struct hal_tx_completion_status *ts,
  2431. struct dp_peer *peer)
  2432. {
  2433. uint32_t length;
  2434. struct dp_soc *soc = NULL;
  2435. struct dp_vdev *vdev = tx_desc->vdev;
  2436. struct ether_header *eh =
  2437. (struct ether_header *)qdf_nbuf_data(tx_desc->nbuf);
  2438. if (!vdev) {
  2439. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2440. "invalid vdev");
  2441. goto out;
  2442. }
  2443. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2444. "-------------------- \n"
  2445. "Tx Completion Stats: \n"
  2446. "-------------------- \n"
  2447. "ack_frame_rssi = %d \n"
  2448. "first_msdu = %d \n"
  2449. "last_msdu = %d \n"
  2450. "msdu_part_of_amsdu = %d \n"
  2451. "rate_stats valid = %d \n"
  2452. "bw = %d \n"
  2453. "pkt_type = %d \n"
  2454. "stbc = %d \n"
  2455. "ldpc = %d \n"
  2456. "sgi = %d \n"
  2457. "mcs = %d \n"
  2458. "ofdma = %d \n"
  2459. "tones_in_ru = %d \n"
  2460. "tsf = %d \n"
  2461. "ppdu_id = %d \n"
  2462. "transmit_cnt = %d \n"
  2463. "tid = %d \n"
  2464. "peer_id = %d\n",
  2465. ts->ack_frame_rssi, ts->first_msdu,
  2466. ts->last_msdu, ts->msdu_part_of_amsdu,
  2467. ts->valid, ts->bw, ts->pkt_type, ts->stbc,
  2468. ts->ldpc, ts->sgi, ts->mcs, ts->ofdma,
  2469. ts->tones_in_ru, ts->tsf, ts->ppdu_id,
  2470. ts->transmit_cnt, ts->tid, ts->peer_id);
  2471. soc = vdev->pdev->soc;
  2472. /* Update SoC level stats */
  2473. DP_STATS_INCC(soc, tx.dropped_fw_removed, 1,
  2474. (ts->status == HAL_TX_TQM_RR_REM_CMD_REM));
  2475. /* Update per-packet stats for mesh mode */
  2476. if (qdf_unlikely(vdev->mesh_vdev) &&
  2477. !(tx_desc->flags & DP_TX_DESC_FLAG_TO_FW))
  2478. dp_tx_comp_fill_tx_completion_stats(tx_desc, ts);
  2479. length = qdf_nbuf_len(tx_desc->nbuf);
  2480. /* Update peer level stats */
  2481. if (!peer) {
  2482. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2483. "invalid peer");
  2484. DP_STATS_INC_PKT(soc, tx.tx_invalid_peer, 1, length);
  2485. goto out;
  2486. }
  2487. if (qdf_likely(!peer->bss_peer)) {
  2488. DP_STATS_INC_PKT(peer, tx.ucast, 1, length);
  2489. if (ts->status == HAL_TX_TQM_RR_FRAME_ACKED)
  2490. DP_STATS_INC_PKT(peer, tx.tx_success, 1, length);
  2491. } else {
  2492. if (ts->status != HAL_TX_TQM_RR_REM_CMD_REM) {
  2493. DP_STATS_INC_PKT(peer, tx.mcast, 1, length);
  2494. if ((peer->vdev->tx_encap_type ==
  2495. htt_cmn_pkt_type_ethernet) &&
  2496. IEEE80211_IS_BROADCAST(eh->ether_dhost)) {
  2497. DP_STATS_INC_PKT(peer, tx.bcast, 1, length);
  2498. }
  2499. }
  2500. }
  2501. dp_tx_update_peer_stats(peer, ts);
  2502. out:
  2503. return;
  2504. }
  2505. /**
  2506. * dp_tx_comp_process_desc_list() - Tx complete software descriptor handler
  2507. * @soc: core txrx main context
  2508. * @comp_head: software descriptor head pointer
  2509. *
  2510. * This function will process batch of descriptors reaped by dp_tx_comp_handler
  2511. * and release the software descriptors after processing is complete
  2512. *
  2513. * Return: none
  2514. */
  2515. static void
  2516. dp_tx_comp_process_desc_list(struct dp_soc *soc,
  2517. struct dp_tx_desc_s *comp_head)
  2518. {
  2519. struct dp_tx_desc_s *desc;
  2520. struct dp_tx_desc_s *next;
  2521. struct hal_tx_completion_status ts = {0};
  2522. struct dp_peer *peer;
  2523. DP_HIST_INIT();
  2524. desc = comp_head;
  2525. while (desc) {
  2526. hal_tx_comp_get_status(&desc->comp, &ts, soc->hal_soc);
  2527. peer = dp_peer_find_by_id(soc, ts.peer_id);
  2528. dp_tx_comp_process_tx_status(desc, &ts, peer);
  2529. dp_tx_comp_process_desc(soc, desc, &ts, peer);
  2530. if (peer)
  2531. dp_peer_unref_del_find_by_id(peer);
  2532. DP_HIST_PACKET_COUNT_INC(desc->pdev->pdev_id);
  2533. next = desc->next;
  2534. dp_tx_desc_release(desc, desc->pool_id);
  2535. desc = next;
  2536. }
  2537. DP_TX_HIST_STATS_PER_PDEV();
  2538. }
  2539. /**
  2540. * dp_tx_process_htt_completion() - Tx HTT Completion Indication Handler
  2541. * @tx_desc: software descriptor head pointer
  2542. * @status : Tx completion status from HTT descriptor
  2543. *
  2544. * This function will process HTT Tx indication messages from Target
  2545. *
  2546. * Return: none
  2547. */
  2548. static
  2549. void dp_tx_process_htt_completion(struct dp_tx_desc_s *tx_desc, uint8_t *status)
  2550. {
  2551. uint8_t tx_status;
  2552. struct dp_pdev *pdev;
  2553. struct dp_vdev *vdev;
  2554. struct dp_soc *soc;
  2555. struct hal_tx_completion_status ts = {0};
  2556. uint32_t *htt_desc = (uint32_t *)status;
  2557. struct dp_peer *peer;
  2558. qdf_assert(tx_desc->pdev);
  2559. pdev = tx_desc->pdev;
  2560. vdev = tx_desc->vdev;
  2561. soc = pdev->soc;
  2562. tx_status = HTT_TX_WBM_COMPLETION_V2_TX_STATUS_GET(htt_desc[0]);
  2563. switch (tx_status) {
  2564. case HTT_TX_FW2WBM_TX_STATUS_OK:
  2565. case HTT_TX_FW2WBM_TX_STATUS_DROP:
  2566. case HTT_TX_FW2WBM_TX_STATUS_TTL:
  2567. {
  2568. if (HTT_TX_WBM_COMPLETION_V2_VALID_GET(htt_desc[2])) {
  2569. ts.peer_id =
  2570. HTT_TX_WBM_COMPLETION_V2_SW_PEER_ID_GET(
  2571. htt_desc[2]);
  2572. ts.tid =
  2573. HTT_TX_WBM_COMPLETION_V2_TID_NUM_GET(
  2574. htt_desc[2]);
  2575. } else {
  2576. ts.peer_id = HTT_INVALID_PEER;
  2577. ts.tid = HTT_INVALID_TID;
  2578. }
  2579. ts.ppdu_id =
  2580. HTT_TX_WBM_COMPLETION_V2_SCH_CMD_ID_GET(
  2581. htt_desc[1]);
  2582. ts.ack_frame_rssi =
  2583. HTT_TX_WBM_COMPLETION_V2_ACK_FRAME_RSSI_GET(
  2584. htt_desc[1]);
  2585. ts.first_msdu = 1;
  2586. ts.last_msdu = 1;
  2587. if (tx_status != HTT_TX_FW2WBM_TX_STATUS_OK)
  2588. ts.status = HAL_TX_TQM_RR_REM_CMD_REM;
  2589. peer = dp_peer_find_by_id(soc, ts.peer_id);
  2590. dp_tx_comp_process_tx_status(tx_desc, &ts, peer);
  2591. dp_tx_comp_process_desc(soc, tx_desc, &ts, peer);
  2592. dp_tx_desc_release(tx_desc, tx_desc->pool_id);
  2593. break;
  2594. }
  2595. case HTT_TX_FW2WBM_TX_STATUS_REINJECT:
  2596. {
  2597. dp_tx_reinject_handler(tx_desc, status);
  2598. break;
  2599. }
  2600. case HTT_TX_FW2WBM_TX_STATUS_INSPECT:
  2601. {
  2602. dp_tx_inspect_handler(tx_desc, status);
  2603. break;
  2604. }
  2605. case HTT_TX_FW2WBM_TX_STATUS_MEC_NOTIFY:
  2606. {
  2607. dp_tx_mec_handler(vdev, status);
  2608. break;
  2609. }
  2610. default:
  2611. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2612. "%s Invalid HTT tx_status %d\n",
  2613. __func__, tx_status);
  2614. break;
  2615. }
  2616. }
  2617. /**
  2618. * dp_tx_comp_handler() - Tx completion handler
  2619. * @soc: core txrx main context
  2620. * @ring_id: completion ring id
  2621. * @quota: No. of packets/descriptors that can be serviced in one loop
  2622. *
  2623. * This function will collect hardware release ring element contents and
  2624. * handle descriptor contents. Based on contents, free packet or handle error
  2625. * conditions
  2626. *
  2627. * Return: none
  2628. */
  2629. uint32_t dp_tx_comp_handler(struct dp_soc *soc, void *hal_srng, uint32_t quota)
  2630. {
  2631. void *tx_comp_hal_desc;
  2632. uint8_t buffer_src;
  2633. uint8_t pool_id;
  2634. uint32_t tx_desc_id;
  2635. struct dp_tx_desc_s *tx_desc = NULL;
  2636. struct dp_tx_desc_s *head_desc = NULL;
  2637. struct dp_tx_desc_s *tail_desc = NULL;
  2638. uint32_t num_processed;
  2639. uint32_t count;
  2640. if (qdf_unlikely(hal_srng_access_start(soc->hal_soc, hal_srng))) {
  2641. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  2642. "%s %d : HAL RING Access Failed -- %pK",
  2643. __func__, __LINE__, hal_srng);
  2644. return 0;
  2645. }
  2646. num_processed = 0;
  2647. count = 0;
  2648. /* Find head descriptor from completion ring */
  2649. while (qdf_likely(tx_comp_hal_desc =
  2650. hal_srng_dst_get_next(soc->hal_soc, hal_srng))) {
  2651. buffer_src = hal_tx_comp_get_buffer_source(tx_comp_hal_desc);
  2652. /* If this buffer was not released by TQM or FW, then it is not
  2653. * Tx completion indication, assert */
  2654. if ((buffer_src != HAL_TX_COMP_RELEASE_SOURCE_TQM) &&
  2655. (buffer_src != HAL_TX_COMP_RELEASE_SOURCE_FW)) {
  2656. QDF_TRACE(QDF_MODULE_ID_DP,
  2657. QDF_TRACE_LEVEL_FATAL,
  2658. "Tx comp release_src != TQM | FW");
  2659. qdf_assert_always(0);
  2660. }
  2661. /* Get descriptor id */
  2662. tx_desc_id = hal_tx_comp_get_desc_id(tx_comp_hal_desc);
  2663. pool_id = (tx_desc_id & DP_TX_DESC_ID_POOL_MASK) >>
  2664. DP_TX_DESC_ID_POOL_OS;
  2665. if (!dp_tx_is_desc_id_valid(soc, tx_desc_id))
  2666. continue;
  2667. /* Find Tx descriptor */
  2668. tx_desc = dp_tx_desc_find(soc, pool_id,
  2669. (tx_desc_id & DP_TX_DESC_ID_PAGE_MASK) >>
  2670. DP_TX_DESC_ID_PAGE_OS,
  2671. (tx_desc_id & DP_TX_DESC_ID_OFFSET_MASK) >>
  2672. DP_TX_DESC_ID_OFFSET_OS);
  2673. /*
  2674. * If the release source is FW, process the HTT status
  2675. */
  2676. if (qdf_unlikely(buffer_src ==
  2677. HAL_TX_COMP_RELEASE_SOURCE_FW)) {
  2678. uint8_t htt_tx_status[HAL_TX_COMP_HTT_STATUS_LEN];
  2679. hal_tx_comp_get_htt_desc(tx_comp_hal_desc,
  2680. htt_tx_status);
  2681. dp_tx_process_htt_completion(tx_desc,
  2682. htt_tx_status);
  2683. } else {
  2684. /* Pool id is not matching. Error */
  2685. if (tx_desc->pool_id != pool_id) {
  2686. QDF_TRACE(QDF_MODULE_ID_DP,
  2687. QDF_TRACE_LEVEL_FATAL,
  2688. "Tx Comp pool id %d not matched %d",
  2689. pool_id, tx_desc->pool_id);
  2690. qdf_assert_always(0);
  2691. }
  2692. if (!(tx_desc->flags & DP_TX_DESC_FLAG_ALLOCATED) ||
  2693. !(tx_desc->flags & DP_TX_DESC_FLAG_QUEUED_TX)) {
  2694. QDF_TRACE(QDF_MODULE_ID_DP,
  2695. QDF_TRACE_LEVEL_FATAL,
  2696. "Txdesc invalid, flgs = %x,id = %d",
  2697. tx_desc->flags, tx_desc_id);
  2698. qdf_assert_always(0);
  2699. }
  2700. /* First ring descriptor on the cycle */
  2701. if (!head_desc) {
  2702. head_desc = tx_desc;
  2703. tail_desc = tx_desc;
  2704. }
  2705. tail_desc->next = tx_desc;
  2706. tx_desc->next = NULL;
  2707. tail_desc = tx_desc;
  2708. /* Collect hw completion contents */
  2709. hal_tx_comp_desc_sync(tx_comp_hal_desc,
  2710. &tx_desc->comp, 1);
  2711. }
  2712. num_processed += !(count & DP_TX_NAPI_BUDGET_DIV_MASK);
  2713. /* Decrement PM usage count if the packet has been sent.*/
  2714. hif_pm_runtime_put(soc->hif_handle);
  2715. /*
  2716. * Processed packet count is more than given quota
  2717. * stop to processing
  2718. */
  2719. if ((num_processed >= quota))
  2720. break;
  2721. count++;
  2722. }
  2723. hal_srng_access_end(soc->hal_soc, hal_srng);
  2724. /* Process the reaped descriptors */
  2725. if (head_desc)
  2726. dp_tx_comp_process_desc_list(soc, head_desc);
  2727. return num_processed;
  2728. }
  2729. #ifdef CONVERGED_TDLS_ENABLE
  2730. /**
  2731. * dp_tx_non_std() - Allow the control-path SW to send data frames
  2732. *
  2733. * @data_vdev - which vdev should transmit the tx data frames
  2734. * @tx_spec - what non-standard handling to apply to the tx data frames
  2735. * @msdu_list - NULL-terminated list of tx MSDUs
  2736. *
  2737. * Return: NULL on success,
  2738. * nbuf when it fails to send
  2739. */
  2740. qdf_nbuf_t dp_tx_non_std(struct cdp_vdev *vdev_handle,
  2741. enum ol_tx_spec tx_spec, qdf_nbuf_t msdu_list)
  2742. {
  2743. struct dp_vdev *vdev = (struct dp_vdev *) vdev_handle;
  2744. if (tx_spec & OL_TX_SPEC_NO_FREE)
  2745. vdev->is_tdls_frame = true;
  2746. return dp_tx_send(vdev_handle, msdu_list);
  2747. }
  2748. #endif
  2749. /**
  2750. * dp_tx_vdev_attach() - attach vdev to dp tx
  2751. * @vdev: virtual device instance
  2752. *
  2753. * Return: QDF_STATUS_SUCCESS: success
  2754. * QDF_STATUS_E_RESOURCES: Error return
  2755. */
  2756. QDF_STATUS dp_tx_vdev_attach(struct dp_vdev *vdev)
  2757. {
  2758. /*
  2759. * Fill HTT TCL Metadata with Vdev ID and MAC ID
  2760. */
  2761. HTT_TX_TCL_METADATA_TYPE_SET(vdev->htt_tcl_metadata,
  2762. HTT_TCL_METADATA_TYPE_VDEV_BASED);
  2763. HTT_TX_TCL_METADATA_VDEV_ID_SET(vdev->htt_tcl_metadata,
  2764. vdev->vdev_id);
  2765. HTT_TX_TCL_METADATA_PDEV_ID_SET(vdev->htt_tcl_metadata,
  2766. DP_SW2HW_MACID(vdev->pdev->pdev_id));
  2767. /*
  2768. * Set HTT Extension Valid bit to 0 by default
  2769. */
  2770. HTT_TX_TCL_METADATA_VALID_HTT_SET(vdev->htt_tcl_metadata, 0);
  2771. dp_tx_vdev_update_search_flags(vdev);
  2772. return QDF_STATUS_SUCCESS;
  2773. }
  2774. /**
  2775. * dp_tx_vdev_update_search_flags() - Update vdev flags as per opmode
  2776. * @vdev: virtual device instance
  2777. *
  2778. * Return: void
  2779. *
  2780. */
  2781. void dp_tx_vdev_update_search_flags(struct dp_vdev *vdev)
  2782. {
  2783. struct dp_soc *soc = vdev->pdev->soc;
  2784. /*
  2785. * Enable both AddrY (SA based search) and AddrX (Da based search)
  2786. * for TDLS link
  2787. *
  2788. * Enable AddrY (SA based search) only for non-WDS STA and
  2789. * ProxySTA VAP modes.
  2790. *
  2791. * In all other VAP modes, only DA based search should be
  2792. * enabled
  2793. */
  2794. if (vdev->opmode == wlan_op_mode_sta &&
  2795. vdev->tdls_link_connected)
  2796. vdev->hal_desc_addr_search_flags =
  2797. (HAL_TX_DESC_ADDRX_EN | HAL_TX_DESC_ADDRY_EN);
  2798. else if ((vdev->opmode == wlan_op_mode_sta &&
  2799. (!vdev->wds_enabled || vdev->proxysta_vdev)))
  2800. vdev->hal_desc_addr_search_flags = HAL_TX_DESC_ADDRY_EN;
  2801. else
  2802. vdev->hal_desc_addr_search_flags = HAL_TX_DESC_ADDRX_EN;
  2803. /* Set search type only when peer map v2 messaging is enabled
  2804. * as we will have the search index (AST hash) only when v2 is
  2805. * enabled
  2806. */
  2807. if (soc->is_peer_map_unmap_v2 && vdev->opmode == wlan_op_mode_sta)
  2808. vdev->search_type = HAL_TX_ADDR_INDEX_SEARCH;
  2809. else
  2810. vdev->search_type = HAL_TX_ADDR_SEARCH_DEFAULT;
  2811. }
  2812. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  2813. static void dp_tx_desc_flush(struct dp_vdev *vdev)
  2814. {
  2815. }
  2816. #else /* QCA_LL_TX_FLOW_CONTROL_V2! */
  2817. /* dp_tx_desc_flush() - release resources associated
  2818. * to tx_desc
  2819. * @vdev: virtual device instance
  2820. *
  2821. * This function will free all outstanding Tx buffers,
  2822. * including ME buffer for which either free during
  2823. * completion didn't happened or completion is not
  2824. * received.
  2825. */
  2826. static void dp_tx_desc_flush(struct dp_vdev *vdev)
  2827. {
  2828. uint8_t i, num_pool;
  2829. uint32_t j;
  2830. uint32_t num_desc;
  2831. struct dp_soc *soc = vdev->pdev->soc;
  2832. struct dp_tx_desc_s *tx_desc = NULL;
  2833. struct dp_tx_desc_pool_s *tx_desc_pool = NULL;
  2834. num_desc = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  2835. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  2836. for (i = 0; i < num_pool; i++) {
  2837. for (j = 0; j < num_desc; j++) {
  2838. tx_desc_pool = &((soc)->tx_desc[(i)]);
  2839. if (tx_desc_pool &&
  2840. tx_desc_pool->desc_pages.cacheable_pages) {
  2841. tx_desc = dp_tx_desc_find(soc, i,
  2842. (j & DP_TX_DESC_ID_PAGE_MASK) >>
  2843. DP_TX_DESC_ID_PAGE_OS,
  2844. (j & DP_TX_DESC_ID_OFFSET_MASK) >>
  2845. DP_TX_DESC_ID_OFFSET_OS);
  2846. if (tx_desc && (tx_desc->vdev == vdev) &&
  2847. (tx_desc->flags & DP_TX_DESC_FLAG_ALLOCATED)) {
  2848. dp_tx_comp_free_buf(soc, tx_desc);
  2849. dp_tx_desc_release(tx_desc, i);
  2850. }
  2851. }
  2852. }
  2853. }
  2854. }
  2855. #endif /* !QCA_LL_TX_FLOW_CONTROL_V2 */
  2856. /**
  2857. * dp_tx_vdev_detach() - detach vdev from dp tx
  2858. * @vdev: virtual device instance
  2859. *
  2860. * Return: QDF_STATUS_SUCCESS: success
  2861. * QDF_STATUS_E_RESOURCES: Error return
  2862. */
  2863. QDF_STATUS dp_tx_vdev_detach(struct dp_vdev *vdev)
  2864. {
  2865. dp_tx_desc_flush(vdev);
  2866. return QDF_STATUS_SUCCESS;
  2867. }
  2868. /**
  2869. * dp_tx_pdev_attach() - attach pdev to dp tx
  2870. * @pdev: physical device instance
  2871. *
  2872. * Return: QDF_STATUS_SUCCESS: success
  2873. * QDF_STATUS_E_RESOURCES: Error return
  2874. */
  2875. QDF_STATUS dp_tx_pdev_attach(struct dp_pdev *pdev)
  2876. {
  2877. struct dp_soc *soc = pdev->soc;
  2878. /* Initialize Flow control counters */
  2879. qdf_atomic_init(&pdev->num_tx_exception);
  2880. qdf_atomic_init(&pdev->num_tx_outstanding);
  2881. if (wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  2882. /* Initialize descriptors in TCL Ring */
  2883. hal_tx_init_data_ring(soc->hal_soc,
  2884. soc->tcl_data_ring[pdev->pdev_id].hal_srng);
  2885. }
  2886. return QDF_STATUS_SUCCESS;
  2887. }
  2888. /**
  2889. * dp_tx_pdev_detach() - detach pdev from dp tx
  2890. * @pdev: physical device instance
  2891. *
  2892. * Return: QDF_STATUS_SUCCESS: success
  2893. * QDF_STATUS_E_RESOURCES: Error return
  2894. */
  2895. QDF_STATUS dp_tx_pdev_detach(struct dp_pdev *pdev)
  2896. {
  2897. dp_tx_me_exit(pdev);
  2898. return QDF_STATUS_SUCCESS;
  2899. }
  2900. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  2901. /* Pools will be allocated dynamically */
  2902. static int dp_tx_alloc_static_pools(struct dp_soc *soc, int num_pool,
  2903. int num_desc)
  2904. {
  2905. uint8_t i;
  2906. for (i = 0; i < num_pool; i++) {
  2907. qdf_spinlock_create(&soc->tx_desc[i].flow_pool_lock);
  2908. soc->tx_desc[i].status = FLOW_POOL_INACTIVE;
  2909. }
  2910. return 0;
  2911. }
  2912. static void dp_tx_delete_static_pools(struct dp_soc *soc, int num_pool)
  2913. {
  2914. uint8_t i;
  2915. for (i = 0; i < num_pool; i++)
  2916. qdf_spinlock_destroy(&soc->tx_desc[i].flow_pool_lock);
  2917. }
  2918. #else /* QCA_LL_TX_FLOW_CONTROL_V2! */
  2919. static int dp_tx_alloc_static_pools(struct dp_soc *soc, int num_pool,
  2920. int num_desc)
  2921. {
  2922. uint8_t i;
  2923. /* Allocate software Tx descriptor pools */
  2924. for (i = 0; i < num_pool; i++) {
  2925. if (dp_tx_desc_pool_alloc(soc, i, num_desc)) {
  2926. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2927. "%s Tx Desc Pool alloc %d failed %pK",
  2928. __func__, i, soc);
  2929. return ENOMEM;
  2930. }
  2931. }
  2932. return 0;
  2933. }
  2934. static void dp_tx_delete_static_pools(struct dp_soc *soc, int num_pool)
  2935. {
  2936. uint8_t i;
  2937. for (i = 0; i < num_pool; i++) {
  2938. qdf_assert_always(!soc->tx_desc[i].num_allocated);
  2939. if (dp_tx_desc_pool_free(soc, i)) {
  2940. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2941. "%s Tx Desc Pool Free failed", __func__);
  2942. }
  2943. }
  2944. }
  2945. #endif /* !QCA_LL_TX_FLOW_CONTROL_V2 */
  2946. /**
  2947. * dp_tx_soc_detach() - detach soc from dp tx
  2948. * @soc: core txrx main context
  2949. *
  2950. * This function will detach dp tx into main device context
  2951. * will free dp tx resource and initialize resources
  2952. *
  2953. * Return: QDF_STATUS_SUCCESS: success
  2954. * QDF_STATUS_E_RESOURCES: Error return
  2955. */
  2956. QDF_STATUS dp_tx_soc_detach(struct dp_soc *soc)
  2957. {
  2958. uint8_t num_pool;
  2959. uint16_t num_desc;
  2960. uint16_t num_ext_desc;
  2961. uint8_t i;
  2962. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  2963. num_desc = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  2964. num_ext_desc = wlan_cfg_get_num_tx_ext_desc(soc->wlan_cfg_ctx);
  2965. dp_tx_flow_control_deinit(soc);
  2966. dp_tx_delete_static_pools(soc, num_pool);
  2967. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2968. "%s Tx Desc Pool Free num_pool = %d, descs = %d",
  2969. __func__, num_pool, num_desc);
  2970. for (i = 0; i < num_pool; i++) {
  2971. if (dp_tx_ext_desc_pool_free(soc, i)) {
  2972. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2973. "%s Tx Ext Desc Pool Free failed",
  2974. __func__);
  2975. return QDF_STATUS_E_RESOURCES;
  2976. }
  2977. }
  2978. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2979. "%s MSDU Ext Desc Pool %d Free descs = %d",
  2980. __func__, num_pool, num_ext_desc);
  2981. for (i = 0; i < num_pool; i++) {
  2982. dp_tx_tso_desc_pool_free(soc, i);
  2983. }
  2984. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2985. "%s TSO Desc Pool %d Free descs = %d",
  2986. __func__, num_pool, num_desc);
  2987. for (i = 0; i < num_pool; i++)
  2988. dp_tx_tso_num_seg_pool_free(soc, i);
  2989. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2990. "%s TSO Num of seg Desc Pool %d Free descs = %d",
  2991. __func__, num_pool, num_desc);
  2992. return QDF_STATUS_SUCCESS;
  2993. }
  2994. /**
  2995. * dp_tx_soc_attach() - attach soc to dp tx
  2996. * @soc: core txrx main context
  2997. *
  2998. * This function will attach dp tx into main device context
  2999. * will allocate dp tx resource and initialize resources
  3000. *
  3001. * Return: QDF_STATUS_SUCCESS: success
  3002. * QDF_STATUS_E_RESOURCES: Error return
  3003. */
  3004. QDF_STATUS dp_tx_soc_attach(struct dp_soc *soc)
  3005. {
  3006. uint8_t i;
  3007. uint8_t num_pool;
  3008. uint32_t num_desc;
  3009. uint32_t num_ext_desc;
  3010. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  3011. num_desc = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  3012. num_ext_desc = wlan_cfg_get_num_tx_ext_desc(soc->wlan_cfg_ctx);
  3013. if (dp_tx_alloc_static_pools(soc, num_pool, num_desc))
  3014. goto fail;
  3015. dp_tx_flow_control_init(soc);
  3016. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  3017. "%s Tx Desc Alloc num_pool = %d, descs = %d",
  3018. __func__, num_pool, num_desc);
  3019. /* Allocate extension tx descriptor pools */
  3020. for (i = 0; i < num_pool; i++) {
  3021. if (dp_tx_ext_desc_pool_alloc(soc, i, num_ext_desc)) {
  3022. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3023. "MSDU Ext Desc Pool alloc %d failed %pK",
  3024. i, soc);
  3025. goto fail;
  3026. }
  3027. }
  3028. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  3029. "%s MSDU Ext Desc Alloc %d, descs = %d",
  3030. __func__, num_pool, num_ext_desc);
  3031. for (i = 0; i < num_pool; i++) {
  3032. if (dp_tx_tso_desc_pool_alloc(soc, i, num_desc)) {
  3033. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3034. "TSO Desc Pool alloc %d failed %pK",
  3035. i, soc);
  3036. goto fail;
  3037. }
  3038. }
  3039. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  3040. "%s TSO Desc Alloc %d, descs = %d",
  3041. __func__, num_pool, num_desc);
  3042. for (i = 0; i < num_pool; i++) {
  3043. if (dp_tx_tso_num_seg_pool_alloc(soc, i, num_desc)) {
  3044. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3045. "TSO Num of seg Pool alloc %d failed %pK",
  3046. i, soc);
  3047. goto fail;
  3048. }
  3049. }
  3050. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  3051. "%s TSO Num of seg pool Alloc %d, descs = %d",
  3052. __func__, num_pool, num_desc);
  3053. /* Initialize descriptors in TCL Rings */
  3054. if (!wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  3055. for (i = 0; i < soc->num_tcl_data_rings; i++) {
  3056. hal_tx_init_data_ring(soc->hal_soc,
  3057. soc->tcl_data_ring[i].hal_srng);
  3058. }
  3059. }
  3060. /*
  3061. * todo - Add a runtime config option to enable this.
  3062. */
  3063. /*
  3064. * Due to multiple issues on NPR EMU, enable it selectively
  3065. * only for NPR EMU, should be removed, once NPR platforms
  3066. * are stable.
  3067. */
  3068. soc->process_tx_status = CONFIG_PROCESS_TX_STATUS;
  3069. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  3070. "%s HAL Tx init Success", __func__);
  3071. return QDF_STATUS_SUCCESS;
  3072. fail:
  3073. /* Detach will take care of freeing only allocated resources */
  3074. dp_tx_soc_detach(soc);
  3075. return QDF_STATUS_E_RESOURCES;
  3076. }
  3077. /*
  3078. * dp_tx_me_mem_free(): Function to free allocated memory in mcast enahncement
  3079. * pdev: pointer to DP PDEV structure
  3080. * seg_info_head: Pointer to the head of list
  3081. *
  3082. * return: void
  3083. */
  3084. static void dp_tx_me_mem_free(struct dp_pdev *pdev,
  3085. struct dp_tx_seg_info_s *seg_info_head)
  3086. {
  3087. struct dp_tx_me_buf_t *mc_uc_buf;
  3088. struct dp_tx_seg_info_s *seg_info_new = NULL;
  3089. qdf_nbuf_t nbuf = NULL;
  3090. uint64_t phy_addr;
  3091. while (seg_info_head) {
  3092. nbuf = seg_info_head->nbuf;
  3093. mc_uc_buf = (struct dp_tx_me_buf_t *)
  3094. seg_info_head->frags[0].vaddr;
  3095. phy_addr = seg_info_head->frags[0].paddr_hi;
  3096. phy_addr = (phy_addr << 32) | seg_info_head->frags[0].paddr_lo;
  3097. qdf_mem_unmap_nbytes_single(pdev->soc->osdev,
  3098. phy_addr,
  3099. QDF_DMA_TO_DEVICE , DP_MAC_ADDR_LEN);
  3100. dp_tx_me_free_buf(pdev, mc_uc_buf);
  3101. qdf_nbuf_free(nbuf);
  3102. seg_info_new = seg_info_head;
  3103. seg_info_head = seg_info_head->next;
  3104. qdf_mem_free(seg_info_new);
  3105. }
  3106. }
  3107. /**
  3108. * dp_tx_me_send_convert_ucast(): function to convert multicast to unicast
  3109. * @vdev: DP VDEV handle
  3110. * @nbuf: Multicast nbuf
  3111. * @newmac: Table of the clients to which packets have to be sent
  3112. * @new_mac_cnt: No of clients
  3113. *
  3114. * return: no of converted packets
  3115. */
  3116. uint16_t
  3117. dp_tx_me_send_convert_ucast(struct cdp_vdev *vdev_handle, qdf_nbuf_t nbuf,
  3118. uint8_t newmac[][DP_MAC_ADDR_LEN], uint8_t new_mac_cnt)
  3119. {
  3120. struct dp_vdev *vdev = (struct dp_vdev *) vdev_handle;
  3121. struct dp_pdev *pdev = vdev->pdev;
  3122. struct ether_header *eh;
  3123. uint8_t *data;
  3124. uint16_t len;
  3125. /* reference to frame dst addr */
  3126. uint8_t *dstmac;
  3127. /* copy of original frame src addr */
  3128. uint8_t srcmac[DP_MAC_ADDR_LEN];
  3129. /* local index into newmac */
  3130. uint8_t new_mac_idx = 0;
  3131. struct dp_tx_me_buf_t *mc_uc_buf;
  3132. qdf_nbuf_t nbuf_clone;
  3133. struct dp_tx_msdu_info_s msdu_info;
  3134. struct dp_tx_seg_info_s *seg_info_head = NULL;
  3135. struct dp_tx_seg_info_s *seg_info_tail = NULL;
  3136. struct dp_tx_seg_info_s *seg_info_new;
  3137. struct dp_tx_frag_info_s data_frag;
  3138. qdf_dma_addr_t paddr_data;
  3139. qdf_dma_addr_t paddr_mcbuf = 0;
  3140. uint8_t empty_entry_mac[DP_MAC_ADDR_LEN] = {0};
  3141. QDF_STATUS status;
  3142. qdf_mem_set(&msdu_info, sizeof(msdu_info), 0x0);
  3143. dp_tx_get_queue(vdev, nbuf, &msdu_info.tx_queue);
  3144. eh = (struct ether_header *) nbuf;
  3145. qdf_mem_copy(srcmac, eh->ether_shost, DP_MAC_ADDR_LEN);
  3146. len = qdf_nbuf_len(nbuf);
  3147. data = qdf_nbuf_data(nbuf);
  3148. status = qdf_nbuf_map(vdev->osdev, nbuf,
  3149. QDF_DMA_TO_DEVICE);
  3150. if (status) {
  3151. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3152. "Mapping failure Error:%d", status);
  3153. DP_STATS_INC(vdev, tx_i.mcast_en.dropped_map_error, 1);
  3154. qdf_nbuf_free(nbuf);
  3155. return 1;
  3156. }
  3157. paddr_data = qdf_nbuf_get_frag_paddr(nbuf, 0) + IEEE80211_ADDR_LEN;
  3158. /*preparing data fragment*/
  3159. data_frag.vaddr = qdf_nbuf_data(nbuf) + IEEE80211_ADDR_LEN;
  3160. data_frag.paddr_lo = (uint32_t)paddr_data;
  3161. data_frag.paddr_hi = (((uint64_t) paddr_data) >> 32);
  3162. data_frag.len = len - DP_MAC_ADDR_LEN;
  3163. for (new_mac_idx = 0; new_mac_idx < new_mac_cnt; new_mac_idx++) {
  3164. dstmac = newmac[new_mac_idx];
  3165. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  3166. "added mac addr (%pM)", dstmac);
  3167. /* Check for NULL Mac Address */
  3168. if (!qdf_mem_cmp(dstmac, empty_entry_mac, DP_MAC_ADDR_LEN))
  3169. continue;
  3170. /* frame to self mac. skip */
  3171. if (!qdf_mem_cmp(dstmac, srcmac, DP_MAC_ADDR_LEN))
  3172. continue;
  3173. /*
  3174. * TODO: optimize to avoid malloc in per-packet path
  3175. * For eg. seg_pool can be made part of vdev structure
  3176. */
  3177. seg_info_new = qdf_mem_malloc(sizeof(*seg_info_new));
  3178. if (!seg_info_new) {
  3179. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3180. "alloc failed");
  3181. DP_STATS_INC(vdev, tx_i.mcast_en.fail_seg_alloc, 1);
  3182. goto fail_seg_alloc;
  3183. }
  3184. mc_uc_buf = dp_tx_me_alloc_buf(pdev);
  3185. if (mc_uc_buf == NULL)
  3186. goto fail_buf_alloc;
  3187. /*
  3188. * TODO: Check if we need to clone the nbuf
  3189. * Or can we just use the reference for all cases
  3190. */
  3191. if (new_mac_idx < (new_mac_cnt - 1)) {
  3192. nbuf_clone = qdf_nbuf_clone((qdf_nbuf_t)nbuf);
  3193. if (nbuf_clone == NULL) {
  3194. DP_STATS_INC(vdev, tx_i.mcast_en.clone_fail, 1);
  3195. goto fail_clone;
  3196. }
  3197. } else {
  3198. /*
  3199. * Update the ref
  3200. * to account for frame sent without cloning
  3201. */
  3202. qdf_nbuf_ref(nbuf);
  3203. nbuf_clone = nbuf;
  3204. }
  3205. qdf_mem_copy(mc_uc_buf->data, dstmac, DP_MAC_ADDR_LEN);
  3206. status = qdf_mem_map_nbytes_single(vdev->osdev, mc_uc_buf->data,
  3207. QDF_DMA_TO_DEVICE, DP_MAC_ADDR_LEN,
  3208. &paddr_mcbuf);
  3209. if (status) {
  3210. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3211. "Mapping failure Error:%d", status);
  3212. DP_STATS_INC(vdev, tx_i.mcast_en.dropped_map_error, 1);
  3213. goto fail_map;
  3214. }
  3215. seg_info_new->frags[0].vaddr = (uint8_t *)mc_uc_buf;
  3216. seg_info_new->frags[0].paddr_lo = (uint32_t) paddr_mcbuf;
  3217. seg_info_new->frags[0].paddr_hi =
  3218. ((uint64_t) paddr_mcbuf >> 32);
  3219. seg_info_new->frags[0].len = DP_MAC_ADDR_LEN;
  3220. seg_info_new->frags[1] = data_frag;
  3221. seg_info_new->nbuf = nbuf_clone;
  3222. seg_info_new->frag_cnt = 2;
  3223. seg_info_new->total_len = len;
  3224. seg_info_new->next = NULL;
  3225. if (seg_info_head == NULL)
  3226. seg_info_head = seg_info_new;
  3227. else
  3228. seg_info_tail->next = seg_info_new;
  3229. seg_info_tail = seg_info_new;
  3230. }
  3231. if (!seg_info_head) {
  3232. goto free_return;
  3233. }
  3234. msdu_info.u.sg_info.curr_seg = seg_info_head;
  3235. msdu_info.num_seg = new_mac_cnt;
  3236. msdu_info.frm_type = dp_tx_frm_me;
  3237. DP_STATS_INC(vdev, tx_i.mcast_en.ucast, new_mac_cnt);
  3238. dp_tx_send_msdu_multiple(vdev, nbuf, &msdu_info);
  3239. while (seg_info_head->next) {
  3240. seg_info_new = seg_info_head;
  3241. seg_info_head = seg_info_head->next;
  3242. qdf_mem_free(seg_info_new);
  3243. }
  3244. qdf_mem_free(seg_info_head);
  3245. qdf_nbuf_unmap(pdev->soc->osdev, nbuf, QDF_DMA_TO_DEVICE);
  3246. qdf_nbuf_free(nbuf);
  3247. return new_mac_cnt;
  3248. fail_map:
  3249. qdf_nbuf_free(nbuf_clone);
  3250. fail_clone:
  3251. dp_tx_me_free_buf(pdev, mc_uc_buf);
  3252. fail_buf_alloc:
  3253. qdf_mem_free(seg_info_new);
  3254. fail_seg_alloc:
  3255. dp_tx_me_mem_free(pdev, seg_info_head);
  3256. free_return:
  3257. qdf_nbuf_unmap(pdev->soc->osdev, nbuf, QDF_DMA_TO_DEVICE);
  3258. qdf_nbuf_free(nbuf);
  3259. return 1;
  3260. }