dp_tx.c 102 KB

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