dp_tx.c 85 KB

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