dp_tx.c 141 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327
  1. /*
  2. * Copyright (c) 2016-2021 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_htt.h"
  20. #include "hal_hw_headers.h"
  21. #include "dp_tx.h"
  22. #include "dp_tx_desc.h"
  23. #include "dp_peer.h"
  24. #include "dp_types.h"
  25. #include "hal_tx.h"
  26. #include "qdf_mem.h"
  27. #include "qdf_nbuf.h"
  28. #include "qdf_net_types.h"
  29. #include <wlan_cfg.h>
  30. #include "dp_ipa.h"
  31. #if defined(MESH_MODE_SUPPORT) || defined(FEATURE_PERPKT_INFO)
  32. #include "if_meta_hdr.h"
  33. #endif
  34. #include "enet.h"
  35. #include "dp_internal.h"
  36. #ifdef FEATURE_WDS
  37. #include "dp_txrx_wds.h"
  38. #endif
  39. #ifdef ATH_SUPPORT_IQUE
  40. #include "dp_txrx_me.h"
  41. #endif
  42. #include "dp_hist.h"
  43. #ifdef WLAN_DP_FEATURE_SW_LATENCY_MGR
  44. #include <dp_swlm.h>
  45. #endif
  46. /* Flag to skip CCE classify when mesh or tid override enabled */
  47. #define DP_TX_SKIP_CCE_CLASSIFY \
  48. (DP_TXRX_HLOS_TID_OVERRIDE_ENABLED | DP_TX_MESH_ENABLED)
  49. /* TODO Add support in TSO */
  50. #define DP_DESC_NUM_FRAG(x) 0
  51. /* disable TQM_BYPASS */
  52. #define TQM_BYPASS_WAR 0
  53. /* invalid peer id for reinject*/
  54. #define DP_INVALID_PEER 0XFFFE
  55. /*mapping between hal encrypt type and cdp_sec_type*/
  56. #define MAX_CDP_SEC_TYPE 12
  57. static const uint8_t sec_type_map[MAX_CDP_SEC_TYPE] = {
  58. HAL_TX_ENCRYPT_TYPE_NO_CIPHER,
  59. HAL_TX_ENCRYPT_TYPE_WEP_128,
  60. HAL_TX_ENCRYPT_TYPE_WEP_104,
  61. HAL_TX_ENCRYPT_TYPE_WEP_40,
  62. HAL_TX_ENCRYPT_TYPE_TKIP_WITH_MIC,
  63. HAL_TX_ENCRYPT_TYPE_TKIP_NO_MIC,
  64. HAL_TX_ENCRYPT_TYPE_AES_CCMP_128,
  65. HAL_TX_ENCRYPT_TYPE_WAPI,
  66. HAL_TX_ENCRYPT_TYPE_AES_CCMP_256,
  67. HAL_TX_ENCRYPT_TYPE_AES_GCMP_128,
  68. HAL_TX_ENCRYPT_TYPE_AES_GCMP_256,
  69. HAL_TX_ENCRYPT_TYPE_WAPI_GCM_SM4};
  70. #ifdef CONFIG_WLAN_SYSFS_MEM_STATS
  71. /**
  72. * dp_update_tx_desc_stats - Update the increase or decrease in
  73. * outstanding tx desc count
  74. * values on pdev and soc
  75. * @vdev: DP pdev handle
  76. *
  77. * Return: void
  78. */
  79. static inline void
  80. dp_update_tx_desc_stats(struct dp_pdev *pdev)
  81. {
  82. int32_t tx_descs_cnt =
  83. qdf_atomic_read(&pdev->num_tx_outstanding);
  84. if (pdev->tx_descs_max < tx_descs_cnt)
  85. pdev->tx_descs_max = tx_descs_cnt;
  86. qdf_mem_tx_desc_cnt_update(pdev->num_tx_outstanding,
  87. pdev->tx_descs_max);
  88. }
  89. #else /* CONFIG_WLAN_SYSFS_MEM_STATS */
  90. static inline void
  91. dp_update_tx_desc_stats(struct dp_pdev *pdev)
  92. {
  93. }
  94. #endif /* CONFIG_WLAN_SYSFS_MEM_STATS */
  95. #if defined(WLAN_TX_PKT_CAPTURE_ENH) || defined(FEATURE_PERPKT_INFO)
  96. static inline
  97. void dp_tx_enh_unmap(struct dp_soc *soc, struct dp_tx_desc_s *desc)
  98. {
  99. qdf_nbuf_unmap_nbytes_single(soc->osdev, desc->nbuf,
  100. QDF_DMA_TO_DEVICE,
  101. desc->nbuf->len);
  102. desc->flags |= DP_TX_DESC_FLAG_UNMAP_DONE;
  103. }
  104. static inline void dp_tx_unmap(struct dp_soc *soc, struct dp_tx_desc_s *desc)
  105. {
  106. if (qdf_likely(!(desc->flags & DP_TX_DESC_FLAG_UNMAP_DONE)))
  107. qdf_nbuf_unmap_nbytes_single(soc->osdev, desc->nbuf,
  108. QDF_DMA_TO_DEVICE,
  109. desc->nbuf->len);
  110. }
  111. #else
  112. static inline
  113. void dp_tx_enh_unmap(struct dp_soc *soc, struct dp_tx_desc_s *desc)
  114. {
  115. }
  116. static inline void dp_tx_unmap(struct dp_soc *soc, struct dp_tx_desc_s *desc)
  117. {
  118. qdf_nbuf_unmap_nbytes_single(soc->osdev, desc->nbuf,
  119. QDF_DMA_TO_DEVICE, desc->nbuf->len);
  120. }
  121. #endif
  122. #ifdef QCA_TX_LIMIT_CHECK
  123. /**
  124. * dp_tx_limit_check - Check if allocated tx descriptors reached
  125. * soc max limit and pdev max limit
  126. * @vdev: DP vdev handle
  127. *
  128. * Return: true if allocated tx descriptors reached max configured value, else
  129. * false
  130. */
  131. static inline bool
  132. dp_tx_limit_check(struct dp_vdev *vdev)
  133. {
  134. struct dp_pdev *pdev = vdev->pdev;
  135. struct dp_soc *soc = pdev->soc;
  136. if (qdf_atomic_read(&soc->num_tx_outstanding) >=
  137. soc->num_tx_allowed) {
  138. dp_tx_info("queued packets are more than max tx, drop the frame");
  139. DP_STATS_INC(vdev, tx_i.dropped.desc_na.num, 1);
  140. return true;
  141. }
  142. if (qdf_atomic_read(&pdev->num_tx_outstanding) >=
  143. pdev->num_tx_allowed) {
  144. dp_tx_info("queued packets are more than max tx, drop the frame");
  145. DP_STATS_INC(vdev, tx_i.dropped.desc_na.num, 1);
  146. DP_STATS_INC(vdev, tx_i.dropped.desc_na_exc_outstand.num, 1);
  147. return true;
  148. }
  149. return false;
  150. }
  151. /**
  152. * dp_tx_exception_limit_check - Check if allocated tx exception descriptors
  153. * reached soc max limit
  154. * @vdev: DP vdev handle
  155. *
  156. * Return: true if allocated tx descriptors reached max configured value, else
  157. * false
  158. */
  159. static inline bool
  160. dp_tx_exception_limit_check(struct dp_vdev *vdev)
  161. {
  162. struct dp_pdev *pdev = vdev->pdev;
  163. struct dp_soc *soc = pdev->soc;
  164. if (qdf_atomic_read(&soc->num_tx_exception) >=
  165. soc->num_msdu_exception_desc) {
  166. dp_info("exc packets are more than max drop the exc pkt");
  167. DP_STATS_INC(vdev, tx_i.dropped.exc_desc_na.num, 1);
  168. return true;
  169. }
  170. return false;
  171. }
  172. /**
  173. * dp_tx_outstanding_inc - Increment outstanding tx desc values on pdev and soc
  174. * @vdev: DP pdev handle
  175. *
  176. * Return: void
  177. */
  178. static inline void
  179. dp_tx_outstanding_inc(struct dp_pdev *pdev)
  180. {
  181. struct dp_soc *soc = pdev->soc;
  182. qdf_atomic_inc(&pdev->num_tx_outstanding);
  183. qdf_atomic_inc(&soc->num_tx_outstanding);
  184. dp_update_tx_desc_stats(pdev);
  185. }
  186. /**
  187. * dp_tx_outstanding__dec - Decrement outstanding tx desc values on pdev and soc
  188. * @vdev: DP pdev handle
  189. *
  190. * Return: void
  191. */
  192. static inline void
  193. dp_tx_outstanding_dec(struct dp_pdev *pdev)
  194. {
  195. struct dp_soc *soc = pdev->soc;
  196. qdf_atomic_dec(&pdev->num_tx_outstanding);
  197. qdf_atomic_dec(&soc->num_tx_outstanding);
  198. dp_update_tx_desc_stats(pdev);
  199. }
  200. #else //QCA_TX_LIMIT_CHECK
  201. static inline bool
  202. dp_tx_limit_check(struct dp_vdev *vdev)
  203. {
  204. return false;
  205. }
  206. static inline bool
  207. dp_tx_exception_limit_check(struct dp_vdev *vdev)
  208. {
  209. return false;
  210. }
  211. static inline void
  212. dp_tx_outstanding_inc(struct dp_pdev *pdev)
  213. {
  214. qdf_atomic_inc(&pdev->num_tx_outstanding);
  215. dp_update_tx_desc_stats(pdev);
  216. }
  217. static inline void
  218. dp_tx_outstanding_dec(struct dp_pdev *pdev)
  219. {
  220. qdf_atomic_dec(&pdev->num_tx_outstanding);
  221. dp_update_tx_desc_stats(pdev);
  222. }
  223. #endif //QCA_TX_LIMIT_CHECK
  224. #if defined(FEATURE_TSO)
  225. /**
  226. * dp_tx_tso_unmap_segment() - Unmap TSO segment
  227. *
  228. * @soc - core txrx main context
  229. * @seg_desc - tso segment descriptor
  230. * @num_seg_desc - tso number segment descriptor
  231. */
  232. static void dp_tx_tso_unmap_segment(
  233. struct dp_soc *soc,
  234. struct qdf_tso_seg_elem_t *seg_desc,
  235. struct qdf_tso_num_seg_elem_t *num_seg_desc)
  236. {
  237. TSO_DEBUG("%s: Unmap the tso segment", __func__);
  238. if (qdf_unlikely(!seg_desc)) {
  239. DP_TRACE(ERROR, "%s %d TSO desc is NULL!",
  240. __func__, __LINE__);
  241. qdf_assert(0);
  242. } else if (qdf_unlikely(!num_seg_desc)) {
  243. DP_TRACE(ERROR, "%s %d TSO num desc is NULL!",
  244. __func__, __LINE__);
  245. qdf_assert(0);
  246. } else {
  247. bool is_last_seg;
  248. /* no tso segment left to do dma unmap */
  249. if (num_seg_desc->num_seg.tso_cmn_num_seg < 1)
  250. return;
  251. is_last_seg = (num_seg_desc->num_seg.tso_cmn_num_seg == 1) ?
  252. true : false;
  253. qdf_nbuf_unmap_tso_segment(soc->osdev,
  254. seg_desc, is_last_seg);
  255. num_seg_desc->num_seg.tso_cmn_num_seg--;
  256. }
  257. }
  258. /**
  259. * dp_tx_tso_desc_release() - Release the tso segment and tso_cmn_num_seg
  260. * back to the freelist
  261. *
  262. * @soc - soc device handle
  263. * @tx_desc - Tx software descriptor
  264. */
  265. static void dp_tx_tso_desc_release(struct dp_soc *soc,
  266. struct dp_tx_desc_s *tx_desc)
  267. {
  268. TSO_DEBUG("%s: Free the tso descriptor", __func__);
  269. if (qdf_unlikely(!tx_desc->tso_desc)) {
  270. dp_tx_err("SO desc is NULL!");
  271. qdf_assert(0);
  272. } else if (qdf_unlikely(!tx_desc->tso_num_desc)) {
  273. dp_tx_err("TSO num desc is NULL!");
  274. qdf_assert(0);
  275. } else {
  276. struct qdf_tso_num_seg_elem_t *tso_num_desc =
  277. (struct qdf_tso_num_seg_elem_t *)tx_desc->tso_num_desc;
  278. /* Add the tso num segment into the free list */
  279. if (tso_num_desc->num_seg.tso_cmn_num_seg == 0) {
  280. dp_tso_num_seg_free(soc, tx_desc->pool_id,
  281. tx_desc->tso_num_desc);
  282. tx_desc->tso_num_desc = NULL;
  283. DP_STATS_INC(tx_desc->pdev, tso_stats.tso_comp, 1);
  284. }
  285. /* Add the tso segment into the free list*/
  286. dp_tx_tso_desc_free(soc,
  287. tx_desc->pool_id, tx_desc->tso_desc);
  288. tx_desc->tso_desc = NULL;
  289. }
  290. }
  291. #else
  292. static void dp_tx_tso_unmap_segment(
  293. struct dp_soc *soc,
  294. struct qdf_tso_seg_elem_t *seg_desc,
  295. struct qdf_tso_num_seg_elem_t *num_seg_desc)
  296. {
  297. }
  298. static void dp_tx_tso_desc_release(struct dp_soc *soc,
  299. struct dp_tx_desc_s *tx_desc)
  300. {
  301. }
  302. #endif
  303. /**
  304. * dp_tx_desc_release() - Release Tx Descriptor
  305. * @tx_desc : Tx Descriptor
  306. * @desc_pool_id: Descriptor Pool ID
  307. *
  308. * Deallocate all resources attached to Tx descriptor and free the Tx
  309. * descriptor.
  310. *
  311. * Return:
  312. */
  313. static void
  314. dp_tx_desc_release(struct dp_tx_desc_s *tx_desc, uint8_t desc_pool_id)
  315. {
  316. struct dp_pdev *pdev = tx_desc->pdev;
  317. struct dp_soc *soc;
  318. uint8_t comp_status = 0;
  319. qdf_assert(pdev);
  320. soc = pdev->soc;
  321. dp_tx_outstanding_dec(pdev);
  322. if (tx_desc->frm_type == dp_tx_frm_tso)
  323. dp_tx_tso_desc_release(soc, tx_desc);
  324. if (tx_desc->flags & DP_TX_DESC_FLAG_FRAG)
  325. dp_tx_ext_desc_free(soc, tx_desc->msdu_ext_desc, desc_pool_id);
  326. if (tx_desc->flags & DP_TX_DESC_FLAG_ME)
  327. dp_tx_me_free_buf(tx_desc->pdev, tx_desc->me_buffer);
  328. if (tx_desc->flags & DP_TX_DESC_FLAG_TO_FW)
  329. qdf_atomic_dec(&soc->num_tx_exception);
  330. if (HAL_TX_COMP_RELEASE_SOURCE_TQM ==
  331. hal_tx_comp_get_buffer_source(&tx_desc->comp))
  332. comp_status = hal_tx_comp_get_release_reason(&tx_desc->comp,
  333. soc->hal_soc);
  334. else
  335. comp_status = HAL_TX_COMP_RELEASE_REASON_FW;
  336. dp_tx_debug("Tx Completion Release desc %d status %d outstanding %d",
  337. tx_desc->id, comp_status,
  338. qdf_atomic_read(&pdev->num_tx_outstanding));
  339. dp_tx_desc_free(soc, tx_desc, desc_pool_id);
  340. return;
  341. }
  342. /**
  343. * dp_tx_htt_metadata_prepare() - Prepare HTT metadata for special frames
  344. * @vdev: DP vdev Handle
  345. * @nbuf: skb
  346. * @msdu_info: msdu_info required to create HTT metadata
  347. *
  348. * Prepares and fills HTT metadata in the frame pre-header for special frames
  349. * that should be transmitted using varying transmit parameters.
  350. * There are 2 VDEV modes that currently needs this special metadata -
  351. * 1) Mesh Mode
  352. * 2) DSRC Mode
  353. *
  354. * Return: HTT metadata size
  355. *
  356. */
  357. static uint8_t dp_tx_prepare_htt_metadata(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  358. struct dp_tx_msdu_info_s *msdu_info)
  359. {
  360. uint32_t *meta_data = msdu_info->meta_data;
  361. struct htt_tx_msdu_desc_ext2_t *desc_ext =
  362. (struct htt_tx_msdu_desc_ext2_t *) meta_data;
  363. uint8_t htt_desc_size;
  364. /* Size rounded of multiple of 8 bytes */
  365. uint8_t htt_desc_size_aligned;
  366. uint8_t *hdr = NULL;
  367. /*
  368. * Metadata - HTT MSDU Extension header
  369. */
  370. htt_desc_size = sizeof(struct htt_tx_msdu_desc_ext2_t);
  371. htt_desc_size_aligned = (htt_desc_size + 7) & ~0x7;
  372. if (vdev->mesh_vdev || msdu_info->is_tx_sniffer ||
  373. HTT_TX_MSDU_EXT2_DESC_FLAG_VALID_KEY_FLAGS_GET(msdu_info->
  374. meta_data[0])) {
  375. if (qdf_unlikely(qdf_nbuf_headroom(nbuf) <
  376. htt_desc_size_aligned)) {
  377. nbuf = qdf_nbuf_realloc_headroom(nbuf,
  378. htt_desc_size_aligned);
  379. if (!nbuf) {
  380. /*
  381. * qdf_nbuf_realloc_headroom won't do skb_clone
  382. * as skb_realloc_headroom does. so, no free is
  383. * needed here.
  384. */
  385. DP_STATS_INC(vdev,
  386. tx_i.dropped.headroom_insufficient,
  387. 1);
  388. qdf_print(" %s[%d] skb_realloc_headroom failed",
  389. __func__, __LINE__);
  390. return 0;
  391. }
  392. }
  393. /* Fill and add HTT metaheader */
  394. hdr = qdf_nbuf_push_head(nbuf, htt_desc_size_aligned);
  395. if (!hdr) {
  396. dp_tx_err("Error in filling HTT metadata");
  397. return 0;
  398. }
  399. qdf_mem_copy(hdr, desc_ext, htt_desc_size);
  400. } else if (vdev->opmode == wlan_op_mode_ocb) {
  401. /* Todo - Add support for DSRC */
  402. }
  403. return htt_desc_size_aligned;
  404. }
  405. /**
  406. * dp_tx_prepare_tso_ext_desc() - Prepare MSDU extension descriptor for TSO
  407. * @tso_seg: TSO segment to process
  408. * @ext_desc: Pointer to MSDU extension descriptor
  409. *
  410. * Return: void
  411. */
  412. #if defined(FEATURE_TSO)
  413. static void dp_tx_prepare_tso_ext_desc(struct qdf_tso_seg_t *tso_seg,
  414. void *ext_desc)
  415. {
  416. uint8_t num_frag;
  417. uint32_t tso_flags;
  418. /*
  419. * Set tso_en, tcp_flags(NS, CWR, ECE, URG, ACK, PSH, RST, SYN, FIN),
  420. * tcp_flag_mask
  421. *
  422. * Checksum enable flags are set in TCL descriptor and not in Extension
  423. * Descriptor (H/W ignores checksum_en flags in MSDU ext descriptor)
  424. */
  425. tso_flags = *(uint32_t *) &tso_seg->tso_flags;
  426. hal_tx_ext_desc_set_tso_flags(ext_desc, tso_flags);
  427. hal_tx_ext_desc_set_msdu_length(ext_desc, tso_seg->tso_flags.l2_len,
  428. tso_seg->tso_flags.ip_len);
  429. hal_tx_ext_desc_set_tcp_seq(ext_desc, tso_seg->tso_flags.tcp_seq_num);
  430. hal_tx_ext_desc_set_ip_id(ext_desc, tso_seg->tso_flags.ip_id);
  431. for (num_frag = 0; num_frag < tso_seg->num_frags; num_frag++) {
  432. uint32_t lo = 0;
  433. uint32_t hi = 0;
  434. qdf_assert_always((tso_seg->tso_frags[num_frag].paddr) &&
  435. (tso_seg->tso_frags[num_frag].length));
  436. qdf_dmaaddr_to_32s(
  437. tso_seg->tso_frags[num_frag].paddr, &lo, &hi);
  438. hal_tx_ext_desc_set_buffer(ext_desc, num_frag, lo, hi,
  439. tso_seg->tso_frags[num_frag].length);
  440. }
  441. return;
  442. }
  443. #else
  444. static void dp_tx_prepare_tso_ext_desc(struct qdf_tso_seg_t *tso_seg,
  445. void *ext_desc)
  446. {
  447. return;
  448. }
  449. #endif
  450. #if defined(FEATURE_TSO)
  451. /**
  452. * dp_tx_free_tso_seg_list() - Loop through the tso segments
  453. * allocated and free them
  454. *
  455. * @soc: soc handle
  456. * @free_seg: list of tso segments
  457. * @msdu_info: msdu descriptor
  458. *
  459. * Return - void
  460. */
  461. static void dp_tx_free_tso_seg_list(
  462. struct dp_soc *soc,
  463. struct qdf_tso_seg_elem_t *free_seg,
  464. struct dp_tx_msdu_info_s *msdu_info)
  465. {
  466. struct qdf_tso_seg_elem_t *next_seg;
  467. while (free_seg) {
  468. next_seg = free_seg->next;
  469. dp_tx_tso_desc_free(soc,
  470. msdu_info->tx_queue.desc_pool_id,
  471. free_seg);
  472. free_seg = next_seg;
  473. }
  474. }
  475. /**
  476. * dp_tx_free_tso_num_seg_list() - Loop through the tso num segments
  477. * allocated and free them
  478. *
  479. * @soc: soc handle
  480. * @free_num_seg: list of tso number segments
  481. * @msdu_info: msdu descriptor
  482. * Return - void
  483. */
  484. static void dp_tx_free_tso_num_seg_list(
  485. struct dp_soc *soc,
  486. struct qdf_tso_num_seg_elem_t *free_num_seg,
  487. struct dp_tx_msdu_info_s *msdu_info)
  488. {
  489. struct qdf_tso_num_seg_elem_t *next_num_seg;
  490. while (free_num_seg) {
  491. next_num_seg = free_num_seg->next;
  492. dp_tso_num_seg_free(soc,
  493. msdu_info->tx_queue.desc_pool_id,
  494. free_num_seg);
  495. free_num_seg = next_num_seg;
  496. }
  497. }
  498. /**
  499. * dp_tx_unmap_tso_seg_list() - Loop through the tso segments
  500. * do dma unmap for each segment
  501. *
  502. * @soc: soc handle
  503. * @free_seg: list of tso segments
  504. * @num_seg_desc: tso number segment descriptor
  505. *
  506. * Return - void
  507. */
  508. static void dp_tx_unmap_tso_seg_list(
  509. struct dp_soc *soc,
  510. struct qdf_tso_seg_elem_t *free_seg,
  511. struct qdf_tso_num_seg_elem_t *num_seg_desc)
  512. {
  513. struct qdf_tso_seg_elem_t *next_seg;
  514. if (qdf_unlikely(!num_seg_desc)) {
  515. DP_TRACE(ERROR, "TSO number seg desc is NULL!");
  516. return;
  517. }
  518. while (free_seg) {
  519. next_seg = free_seg->next;
  520. dp_tx_tso_unmap_segment(soc, free_seg, num_seg_desc);
  521. free_seg = next_seg;
  522. }
  523. }
  524. #ifdef FEATURE_TSO_STATS
  525. /**
  526. * dp_tso_get_stats_idx: Retrieve the tso packet id
  527. * @pdev - pdev handle
  528. *
  529. * Return: id
  530. */
  531. static uint32_t dp_tso_get_stats_idx(struct dp_pdev *pdev)
  532. {
  533. uint32_t stats_idx;
  534. stats_idx = (((uint32_t)qdf_atomic_inc_return(&pdev->tso_idx))
  535. % CDP_MAX_TSO_PACKETS);
  536. return stats_idx;
  537. }
  538. #else
  539. static int dp_tso_get_stats_idx(struct dp_pdev *pdev)
  540. {
  541. return 0;
  542. }
  543. #endif /* FEATURE_TSO_STATS */
  544. /**
  545. * dp_tx_free_remaining_tso_desc() - do dma unmap for tso segments if any,
  546. * free the tso segments descriptor and
  547. * tso num segments descriptor
  548. *
  549. * @soc: soc handle
  550. * @msdu_info: msdu descriptor
  551. * @tso_seg_unmap: flag to show if dma unmap is necessary
  552. *
  553. * Return - void
  554. */
  555. static void dp_tx_free_remaining_tso_desc(struct dp_soc *soc,
  556. struct dp_tx_msdu_info_s *msdu_info,
  557. bool tso_seg_unmap)
  558. {
  559. struct qdf_tso_info_t *tso_info = &msdu_info->u.tso_info;
  560. struct qdf_tso_seg_elem_t *free_seg = tso_info->tso_seg_list;
  561. struct qdf_tso_num_seg_elem_t *tso_num_desc =
  562. tso_info->tso_num_seg_list;
  563. /* do dma unmap for each segment */
  564. if (tso_seg_unmap)
  565. dp_tx_unmap_tso_seg_list(soc, free_seg, tso_num_desc);
  566. /* free all tso number segment descriptor though looks only have 1 */
  567. dp_tx_free_tso_num_seg_list(soc, tso_num_desc, msdu_info);
  568. /* free all tso segment descriptor */
  569. dp_tx_free_tso_seg_list(soc, free_seg, msdu_info);
  570. }
  571. /**
  572. * dp_tx_prepare_tso() - Given a jumbo msdu, prepare the TSO info
  573. * @vdev: virtual device handle
  574. * @msdu: network buffer
  575. * @msdu_info: meta data associated with the msdu
  576. *
  577. * Return: QDF_STATUS_SUCCESS success
  578. */
  579. static QDF_STATUS dp_tx_prepare_tso(struct dp_vdev *vdev,
  580. qdf_nbuf_t msdu, struct dp_tx_msdu_info_s *msdu_info)
  581. {
  582. struct qdf_tso_seg_elem_t *tso_seg;
  583. int num_seg = qdf_nbuf_get_tso_num_seg(msdu);
  584. struct dp_soc *soc = vdev->pdev->soc;
  585. struct dp_pdev *pdev = vdev->pdev;
  586. struct qdf_tso_info_t *tso_info;
  587. struct qdf_tso_num_seg_elem_t *tso_num_seg;
  588. tso_info = &msdu_info->u.tso_info;
  589. tso_info->curr_seg = NULL;
  590. tso_info->tso_seg_list = NULL;
  591. tso_info->num_segs = num_seg;
  592. msdu_info->frm_type = dp_tx_frm_tso;
  593. tso_info->tso_num_seg_list = NULL;
  594. TSO_DEBUG(" %s: num_seg: %d", __func__, num_seg);
  595. while (num_seg) {
  596. tso_seg = dp_tx_tso_desc_alloc(
  597. soc, msdu_info->tx_queue.desc_pool_id);
  598. if (tso_seg) {
  599. tso_seg->next = tso_info->tso_seg_list;
  600. tso_info->tso_seg_list = tso_seg;
  601. num_seg--;
  602. } else {
  603. dp_err_rl("Failed to alloc tso seg desc");
  604. DP_STATS_INC_PKT(vdev->pdev,
  605. tso_stats.tso_no_mem_dropped, 1,
  606. qdf_nbuf_len(msdu));
  607. dp_tx_free_remaining_tso_desc(soc, msdu_info, false);
  608. return QDF_STATUS_E_NOMEM;
  609. }
  610. }
  611. TSO_DEBUG(" %s: num_seg: %d", __func__, num_seg);
  612. tso_num_seg = dp_tso_num_seg_alloc(soc,
  613. msdu_info->tx_queue.desc_pool_id);
  614. if (tso_num_seg) {
  615. tso_num_seg->next = tso_info->tso_num_seg_list;
  616. tso_info->tso_num_seg_list = tso_num_seg;
  617. } else {
  618. DP_TRACE(ERROR, "%s: Failed to alloc - Number of segs desc",
  619. __func__);
  620. dp_tx_free_remaining_tso_desc(soc, msdu_info, false);
  621. return QDF_STATUS_E_NOMEM;
  622. }
  623. msdu_info->num_seg =
  624. qdf_nbuf_get_tso_info(soc->osdev, msdu, tso_info);
  625. TSO_DEBUG(" %s: msdu_info->num_seg: %d", __func__,
  626. msdu_info->num_seg);
  627. if (!(msdu_info->num_seg)) {
  628. /*
  629. * Free allocated TSO seg desc and number seg desc,
  630. * do unmap for segments if dma map has done.
  631. */
  632. DP_TRACE(ERROR, "%s: Failed to get tso info", __func__);
  633. dp_tx_free_remaining_tso_desc(soc, msdu_info, true);
  634. return QDF_STATUS_E_INVAL;
  635. }
  636. tso_info->curr_seg = tso_info->tso_seg_list;
  637. tso_info->msdu_stats_idx = dp_tso_get_stats_idx(pdev);
  638. dp_tso_packet_update(pdev, tso_info->msdu_stats_idx,
  639. msdu, msdu_info->num_seg);
  640. dp_tso_segment_stats_update(pdev, tso_info->tso_seg_list,
  641. tso_info->msdu_stats_idx);
  642. dp_stats_tso_segment_histogram_update(pdev, msdu_info->num_seg);
  643. return QDF_STATUS_SUCCESS;
  644. }
  645. #else
  646. static QDF_STATUS dp_tx_prepare_tso(struct dp_vdev *vdev,
  647. qdf_nbuf_t msdu, struct dp_tx_msdu_info_s *msdu_info)
  648. {
  649. return QDF_STATUS_E_NOMEM;
  650. }
  651. #endif
  652. QDF_COMPILE_TIME_ASSERT(dp_tx_htt_metadata_len_check,
  653. (DP_TX_MSDU_INFO_META_DATA_DWORDS * 4 >=
  654. sizeof(struct htt_tx_msdu_desc_ext2_t)));
  655. /**
  656. * dp_tx_prepare_ext_desc() - Allocate and prepare MSDU extension descriptor
  657. * @vdev: DP Vdev handle
  658. * @msdu_info: MSDU info to be setup in MSDU extension descriptor
  659. * @desc_pool_id: Descriptor Pool ID
  660. *
  661. * Return:
  662. */
  663. static
  664. struct dp_tx_ext_desc_elem_s *dp_tx_prepare_ext_desc(struct dp_vdev *vdev,
  665. struct dp_tx_msdu_info_s *msdu_info, uint8_t desc_pool_id)
  666. {
  667. uint8_t i;
  668. uint8_t cached_ext_desc[HAL_TX_EXT_DESC_WITH_META_DATA];
  669. struct dp_tx_seg_info_s *seg_info;
  670. struct dp_tx_ext_desc_elem_s *msdu_ext_desc;
  671. struct dp_soc *soc = vdev->pdev->soc;
  672. /* Allocate an extension descriptor */
  673. msdu_ext_desc = dp_tx_ext_desc_alloc(soc, desc_pool_id);
  674. qdf_mem_zero(&cached_ext_desc[0], HAL_TX_EXT_DESC_WITH_META_DATA);
  675. if (!msdu_ext_desc) {
  676. DP_STATS_INC(vdev, tx_i.dropped.desc_na.num, 1);
  677. return NULL;
  678. }
  679. if (msdu_info->exception_fw &&
  680. qdf_unlikely(vdev->mesh_vdev)) {
  681. qdf_mem_copy(&cached_ext_desc[HAL_TX_EXTENSION_DESC_LEN_BYTES],
  682. &msdu_info->meta_data[0],
  683. sizeof(struct htt_tx_msdu_desc_ext2_t));
  684. qdf_atomic_inc(&soc->num_tx_exception);
  685. msdu_ext_desc->flags |= DP_TX_EXT_DESC_FLAG_METADATA_VALID;
  686. }
  687. switch (msdu_info->frm_type) {
  688. case dp_tx_frm_sg:
  689. case dp_tx_frm_me:
  690. case dp_tx_frm_raw:
  691. seg_info = msdu_info->u.sg_info.curr_seg;
  692. /* Update the buffer pointers in MSDU Extension Descriptor */
  693. for (i = 0; i < seg_info->frag_cnt; i++) {
  694. hal_tx_ext_desc_set_buffer(&cached_ext_desc[0], i,
  695. seg_info->frags[i].paddr_lo,
  696. seg_info->frags[i].paddr_hi,
  697. seg_info->frags[i].len);
  698. }
  699. break;
  700. case dp_tx_frm_tso:
  701. dp_tx_prepare_tso_ext_desc(&msdu_info->u.tso_info.curr_seg->seg,
  702. &cached_ext_desc[0]);
  703. break;
  704. default:
  705. break;
  706. }
  707. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  708. cached_ext_desc, HAL_TX_EXT_DESC_WITH_META_DATA);
  709. hal_tx_ext_desc_sync(&cached_ext_desc[0],
  710. msdu_ext_desc->vaddr);
  711. return msdu_ext_desc;
  712. }
  713. /**
  714. * dp_tx_trace_pkt() - Trace TX packet at DP layer
  715. *
  716. * @skb: skb to be traced
  717. * @msdu_id: msdu_id of the packet
  718. * @vdev_id: vdev_id of the packet
  719. *
  720. * Return: None
  721. */
  722. #ifdef DP_DISABLE_TX_PKT_TRACE
  723. static void dp_tx_trace_pkt(qdf_nbuf_t skb, uint16_t msdu_id,
  724. uint8_t vdev_id)
  725. {
  726. }
  727. #else
  728. static void dp_tx_trace_pkt(qdf_nbuf_t skb, uint16_t msdu_id,
  729. uint8_t vdev_id)
  730. {
  731. QDF_NBUF_CB_TX_PACKET_TRACK(skb) = QDF_NBUF_TX_PKT_DATA_TRACK;
  732. QDF_NBUF_CB_TX_DP_TRACE(skb) = 1;
  733. DPTRACE(qdf_dp_trace_ptr(skb,
  734. QDF_DP_TRACE_LI_DP_TX_PACKET_PTR_RECORD,
  735. QDF_TRACE_DEFAULT_PDEV_ID,
  736. qdf_nbuf_data_addr(skb),
  737. sizeof(qdf_nbuf_data(skb)),
  738. msdu_id, vdev_id, 0));
  739. qdf_dp_trace_log_pkt(vdev_id, skb, QDF_TX, QDF_TRACE_DEFAULT_PDEV_ID);
  740. DPTRACE(qdf_dp_trace_data_pkt(skb, QDF_TRACE_DEFAULT_PDEV_ID,
  741. QDF_DP_TRACE_LI_DP_TX_PACKET_RECORD,
  742. msdu_id, QDF_TX));
  743. }
  744. #endif
  745. #ifdef WLAN_DP_FEATURE_MARK_ICMP_REQ_TO_FW
  746. /**
  747. * dp_tx_is_nbuf_marked_exception() - Check if the packet has been marked as
  748. * exception by the upper layer (OS_IF)
  749. * @soc: DP soc handle
  750. * @nbuf: packet to be transmitted
  751. *
  752. * Returns: 1 if the packet is marked as exception,
  753. * 0, if the packet is not marked as exception.
  754. */
  755. static inline int dp_tx_is_nbuf_marked_exception(struct dp_soc *soc,
  756. qdf_nbuf_t nbuf)
  757. {
  758. return QDF_NBUF_CB_TX_PACKET_TO_FW(nbuf);
  759. }
  760. #else
  761. static inline int dp_tx_is_nbuf_marked_exception(struct dp_soc *soc,
  762. qdf_nbuf_t nbuf)
  763. {
  764. return 0;
  765. }
  766. #endif
  767. /**
  768. * dp_tx_desc_prepare_single - Allocate and prepare Tx descriptor
  769. * @vdev: DP vdev handle
  770. * @nbuf: skb
  771. * @desc_pool_id: Descriptor pool ID
  772. * @meta_data: Metadata to the fw
  773. * @tx_exc_metadata: Handle that holds exception path metadata
  774. * Allocate and prepare Tx descriptor with msdu information.
  775. *
  776. * Return: Pointer to Tx Descriptor on success,
  777. * NULL on failure
  778. */
  779. static
  780. struct dp_tx_desc_s *dp_tx_prepare_desc_single(struct dp_vdev *vdev,
  781. qdf_nbuf_t nbuf, uint8_t desc_pool_id,
  782. struct dp_tx_msdu_info_s *msdu_info,
  783. struct cdp_tx_exception_metadata *tx_exc_metadata)
  784. {
  785. uint8_t align_pad;
  786. uint8_t is_exception = 0;
  787. uint8_t htt_hdr_size;
  788. struct dp_tx_desc_s *tx_desc;
  789. struct dp_pdev *pdev = vdev->pdev;
  790. struct dp_soc *soc = pdev->soc;
  791. if (dp_tx_limit_check(vdev))
  792. return NULL;
  793. /* Allocate software Tx descriptor */
  794. tx_desc = dp_tx_desc_alloc(soc, desc_pool_id);
  795. if (qdf_unlikely(!tx_desc)) {
  796. DP_STATS_INC(vdev, tx_i.dropped.desc_na.num, 1);
  797. DP_STATS_INC(vdev, tx_i.dropped.desc_na_exc_alloc_fail.num, 1);
  798. return NULL;
  799. }
  800. dp_tx_outstanding_inc(pdev);
  801. /* Initialize the SW tx descriptor */
  802. tx_desc->nbuf = nbuf;
  803. tx_desc->frm_type = dp_tx_frm_std;
  804. tx_desc->tx_encap_type = ((tx_exc_metadata &&
  805. (tx_exc_metadata->tx_encap_type != CDP_INVALID_TX_ENCAP_TYPE)) ?
  806. tx_exc_metadata->tx_encap_type : vdev->tx_encap_type);
  807. tx_desc->vdev_id = vdev->vdev_id;
  808. tx_desc->pdev = pdev;
  809. tx_desc->msdu_ext_desc = NULL;
  810. tx_desc->pkt_offset = 0;
  811. tx_desc->length = qdf_nbuf_headlen(nbuf);
  812. dp_tx_trace_pkt(nbuf, tx_desc->id, vdev->vdev_id);
  813. if (qdf_unlikely(vdev->multipass_en)) {
  814. if (!dp_tx_multipass_process(soc, vdev, nbuf, msdu_info))
  815. goto failure;
  816. }
  817. /* Packets marked by upper layer (OS-IF) to be sent to FW */
  818. if (dp_tx_is_nbuf_marked_exception(soc, nbuf))
  819. is_exception = 1;
  820. /*
  821. * For special modes (vdev_type == ocb or mesh), data frames should be
  822. * transmitted using varying transmit parameters (tx spec) which include
  823. * transmit rate, power, priority, channel, channel bandwidth , nss etc.
  824. * These are filled in HTT MSDU descriptor and sent in frame pre-header.
  825. * These frames are sent as exception packets to firmware.
  826. *
  827. * HW requirement is that metadata should always point to a
  828. * 8-byte aligned address. So we add alignment pad to start of buffer.
  829. * HTT Metadata should be ensured to be multiple of 8-bytes,
  830. * to get 8-byte aligned start address along with align_pad added
  831. *
  832. * |-----------------------------|
  833. * | |
  834. * |-----------------------------| <-----Buffer Pointer Address given
  835. * | | ^ in HW descriptor (aligned)
  836. * | HTT Metadata | |
  837. * | | |
  838. * | | | Packet Offset given in descriptor
  839. * | | |
  840. * |-----------------------------| |
  841. * | Alignment Pad | v
  842. * |-----------------------------| <----- Actual buffer start address
  843. * | SKB Data | (Unaligned)
  844. * | |
  845. * | |
  846. * | |
  847. * | |
  848. * | |
  849. * |-----------------------------|
  850. */
  851. if (qdf_unlikely((msdu_info->exception_fw)) ||
  852. (vdev->opmode == wlan_op_mode_ocb) ||
  853. (tx_exc_metadata &&
  854. tx_exc_metadata->is_tx_sniffer)) {
  855. align_pad = ((unsigned long) qdf_nbuf_data(nbuf)) & 0x7;
  856. if (qdf_unlikely(qdf_nbuf_headroom(nbuf) < align_pad)) {
  857. DP_STATS_INC(vdev,
  858. tx_i.dropped.headroom_insufficient, 1);
  859. goto failure;
  860. }
  861. if (qdf_nbuf_push_head(nbuf, align_pad) == NULL) {
  862. dp_tx_err("qdf_nbuf_push_head failed");
  863. goto failure;
  864. }
  865. htt_hdr_size = dp_tx_prepare_htt_metadata(vdev, nbuf,
  866. msdu_info);
  867. if (htt_hdr_size == 0)
  868. goto failure;
  869. tx_desc->length = qdf_nbuf_headlen(nbuf);
  870. tx_desc->pkt_offset = align_pad + htt_hdr_size;
  871. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  872. is_exception = 1;
  873. tx_desc->length -= tx_desc->pkt_offset;
  874. }
  875. #if !TQM_BYPASS_WAR
  876. if (is_exception || tx_exc_metadata)
  877. #endif
  878. {
  879. /* Temporary WAR due to TQM VP issues */
  880. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  881. qdf_atomic_inc(&soc->num_tx_exception);
  882. }
  883. return tx_desc;
  884. failure:
  885. dp_tx_desc_release(tx_desc, desc_pool_id);
  886. return NULL;
  887. }
  888. /**
  889. * dp_tx_prepare_desc() - Allocate and prepare Tx descriptor for multisegment frame
  890. * @vdev: DP vdev handle
  891. * @nbuf: skb
  892. * @msdu_info: Info to be setup in MSDU descriptor and MSDU extension descriptor
  893. * @desc_pool_id : Descriptor Pool ID
  894. *
  895. * Allocate and prepare Tx descriptor with msdu and fragment descritor
  896. * information. For frames wth fragments, allocate and prepare
  897. * an MSDU extension descriptor
  898. *
  899. * Return: Pointer to Tx Descriptor on success,
  900. * NULL on failure
  901. */
  902. static struct dp_tx_desc_s *dp_tx_prepare_desc(struct dp_vdev *vdev,
  903. qdf_nbuf_t nbuf, struct dp_tx_msdu_info_s *msdu_info,
  904. uint8_t desc_pool_id)
  905. {
  906. struct dp_tx_desc_s *tx_desc;
  907. struct dp_tx_ext_desc_elem_s *msdu_ext_desc;
  908. struct dp_pdev *pdev = vdev->pdev;
  909. struct dp_soc *soc = pdev->soc;
  910. if (dp_tx_limit_check(vdev))
  911. return NULL;
  912. /* Allocate software Tx descriptor */
  913. tx_desc = dp_tx_desc_alloc(soc, desc_pool_id);
  914. if (!tx_desc) {
  915. DP_STATS_INC(vdev, tx_i.dropped.desc_na.num, 1);
  916. return NULL;
  917. }
  918. dp_tx_outstanding_inc(pdev);
  919. /* Initialize the SW tx descriptor */
  920. tx_desc->nbuf = nbuf;
  921. tx_desc->frm_type = msdu_info->frm_type;
  922. tx_desc->tx_encap_type = vdev->tx_encap_type;
  923. tx_desc->vdev_id = vdev->vdev_id;
  924. tx_desc->pdev = pdev;
  925. tx_desc->pkt_offset = 0;
  926. tx_desc->tso_desc = msdu_info->u.tso_info.curr_seg;
  927. tx_desc->tso_num_desc = msdu_info->u.tso_info.tso_num_seg_list;
  928. dp_tx_trace_pkt(nbuf, tx_desc->id, vdev->vdev_id);
  929. /* Handle scattered frames - TSO/SG/ME */
  930. /* Allocate and prepare an extension descriptor for scattered frames */
  931. msdu_ext_desc = dp_tx_prepare_ext_desc(vdev, msdu_info, desc_pool_id);
  932. if (!msdu_ext_desc) {
  933. dp_tx_info("Tx Extension Descriptor Alloc Fail");
  934. goto failure;
  935. }
  936. #if TQM_BYPASS_WAR
  937. /* Temporary WAR due to TQM VP issues */
  938. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  939. qdf_atomic_inc(&soc->num_tx_exception);
  940. #endif
  941. if (qdf_unlikely(msdu_info->exception_fw))
  942. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  943. tx_desc->msdu_ext_desc = msdu_ext_desc;
  944. tx_desc->flags |= DP_TX_DESC_FLAG_FRAG;
  945. tx_desc->dma_addr = msdu_ext_desc->paddr;
  946. if (msdu_ext_desc->flags & DP_TX_EXT_DESC_FLAG_METADATA_VALID)
  947. tx_desc->length = HAL_TX_EXT_DESC_WITH_META_DATA;
  948. else
  949. tx_desc->length = HAL_TX_EXTENSION_DESC_LEN_BYTES;
  950. return tx_desc;
  951. failure:
  952. dp_tx_desc_release(tx_desc, desc_pool_id);
  953. return NULL;
  954. }
  955. /**
  956. * dp_tx_prepare_raw() - Prepare RAW packet TX
  957. * @vdev: DP vdev handle
  958. * @nbuf: buffer pointer
  959. * @seg_info: Pointer to Segment info Descriptor to be prepared
  960. * @msdu_info: MSDU info to be setup in MSDU descriptor and MSDU extension
  961. * descriptor
  962. *
  963. * Return:
  964. */
  965. static qdf_nbuf_t dp_tx_prepare_raw(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  966. struct dp_tx_seg_info_s *seg_info, struct dp_tx_msdu_info_s *msdu_info)
  967. {
  968. qdf_nbuf_t curr_nbuf = NULL;
  969. uint16_t total_len = 0;
  970. qdf_dma_addr_t paddr;
  971. int32_t i;
  972. int32_t mapped_buf_num = 0;
  973. struct dp_tx_sg_info_s *sg_info = &msdu_info->u.sg_info;
  974. qdf_dot3_qosframe_t *qos_wh = (qdf_dot3_qosframe_t *) nbuf->data;
  975. DP_STATS_INC_PKT(vdev, tx_i.raw.raw_pkt, 1, qdf_nbuf_len(nbuf));
  976. /* Continue only if frames are of DATA type */
  977. if (!DP_FRAME_IS_DATA(qos_wh)) {
  978. DP_STATS_INC(vdev, tx_i.raw.invalid_raw_pkt_datatype, 1);
  979. dp_tx_debug("Pkt. recd is of not data type");
  980. goto error;
  981. }
  982. /* SWAR for HW: Enable WEP bit in the AMSDU frames for RAW mode */
  983. if (vdev->raw_mode_war &&
  984. (qos_wh->i_fc[0] & QDF_IEEE80211_FC0_SUBTYPE_QOS) &&
  985. (qos_wh->i_qos[0] & IEEE80211_QOS_AMSDU))
  986. qos_wh->i_fc[1] |= IEEE80211_FC1_WEP;
  987. for (curr_nbuf = nbuf, i = 0; curr_nbuf;
  988. curr_nbuf = qdf_nbuf_next(curr_nbuf), i++) {
  989. /*
  990. * Number of nbuf's must not exceed the size of the frags
  991. * array in seg_info.
  992. */
  993. if (i >= DP_TX_MAX_NUM_FRAGS) {
  994. dp_err_rl("nbuf cnt exceeds the max number of segs");
  995. DP_STATS_INC(vdev, tx_i.raw.num_frags_overflow_err, 1);
  996. goto error;
  997. }
  998. if (QDF_STATUS_SUCCESS !=
  999. qdf_nbuf_map_nbytes_single(vdev->osdev,
  1000. curr_nbuf,
  1001. QDF_DMA_TO_DEVICE,
  1002. curr_nbuf->len)) {
  1003. dp_tx_err("%s dma map error ", __func__);
  1004. DP_STATS_INC(vdev, tx_i.raw.dma_map_error, 1);
  1005. goto error;
  1006. }
  1007. /* Update the count of mapped nbuf's */
  1008. mapped_buf_num++;
  1009. paddr = qdf_nbuf_get_frag_paddr(curr_nbuf, 0);
  1010. seg_info->frags[i].paddr_lo = paddr;
  1011. seg_info->frags[i].paddr_hi = ((uint64_t)paddr >> 32);
  1012. seg_info->frags[i].len = qdf_nbuf_len(curr_nbuf);
  1013. seg_info->frags[i].vaddr = (void *) curr_nbuf;
  1014. total_len += qdf_nbuf_len(curr_nbuf);
  1015. }
  1016. seg_info->frag_cnt = i;
  1017. seg_info->total_len = total_len;
  1018. seg_info->next = NULL;
  1019. sg_info->curr_seg = seg_info;
  1020. msdu_info->frm_type = dp_tx_frm_raw;
  1021. msdu_info->num_seg = 1;
  1022. return nbuf;
  1023. error:
  1024. i = 0;
  1025. while (nbuf) {
  1026. curr_nbuf = nbuf;
  1027. if (i < mapped_buf_num) {
  1028. qdf_nbuf_unmap_nbytes_single(vdev->osdev, curr_nbuf,
  1029. QDF_DMA_TO_DEVICE,
  1030. curr_nbuf->len);
  1031. i++;
  1032. }
  1033. nbuf = qdf_nbuf_next(nbuf);
  1034. qdf_nbuf_free(curr_nbuf);
  1035. }
  1036. return NULL;
  1037. }
  1038. /**
  1039. * dp_tx_raw_prepare_unset() - unmap the chain of nbufs belonging to RAW frame.
  1040. * @soc: DP soc handle
  1041. * @nbuf: Buffer pointer
  1042. *
  1043. * unmap the chain of nbufs that belong to this RAW frame.
  1044. *
  1045. * Return: None
  1046. */
  1047. static void dp_tx_raw_prepare_unset(struct dp_soc *soc,
  1048. qdf_nbuf_t nbuf)
  1049. {
  1050. qdf_nbuf_t cur_nbuf = nbuf;
  1051. do {
  1052. qdf_nbuf_unmap_nbytes_single(soc->osdev, cur_nbuf,
  1053. QDF_DMA_TO_DEVICE,
  1054. cur_nbuf->len);
  1055. cur_nbuf = qdf_nbuf_next(cur_nbuf);
  1056. } while (cur_nbuf);
  1057. }
  1058. #ifdef VDEV_PEER_PROTOCOL_COUNT
  1059. #define dp_vdev_peer_stats_update_protocol_cnt_tx(vdev_hdl, nbuf) \
  1060. { \
  1061. qdf_nbuf_t nbuf_local; \
  1062. struct dp_vdev *vdev_local = vdev_hdl; \
  1063. do { \
  1064. if (qdf_likely(!((vdev_local)->peer_protocol_count_track))) \
  1065. break; \
  1066. nbuf_local = nbuf; \
  1067. if (qdf_unlikely(((vdev_local)->tx_encap_type) == \
  1068. htt_cmn_pkt_type_raw)) \
  1069. break; \
  1070. else if (qdf_unlikely(qdf_nbuf_is_nonlinear((nbuf_local)))) \
  1071. break; \
  1072. else if (qdf_nbuf_is_tso((nbuf_local))) \
  1073. break; \
  1074. dp_vdev_peer_stats_update_protocol_cnt((vdev_local), \
  1075. (nbuf_local), \
  1076. NULL, 1, 0); \
  1077. } while (0); \
  1078. }
  1079. #else
  1080. #define dp_vdev_peer_stats_update_protocol_cnt_tx(vdev_hdl, skb)
  1081. #endif
  1082. #ifdef WLAN_DP_FEATURE_SW_LATENCY_MGR
  1083. /**
  1084. * dp_tx_update_stats() - Update soc level tx stats
  1085. * @soc: DP soc handle
  1086. * @nbuf: packet being transmitted
  1087. *
  1088. * Returns: none
  1089. */
  1090. static inline void dp_tx_update_stats(struct dp_soc *soc,
  1091. qdf_nbuf_t nbuf)
  1092. {
  1093. DP_STATS_INC_PKT(soc, tx.egress, 1, qdf_nbuf_len(nbuf));
  1094. }
  1095. /**
  1096. * dp_tx_attempt_coalescing() - Check and attempt TCL register write coalescing
  1097. * @soc: Datapath soc handle
  1098. * @tx_desc: tx packet descriptor
  1099. * @tid: TID for pkt transmission
  1100. *
  1101. * Returns: 1, if coalescing is to be done
  1102. * 0, if coalescing is not to be done
  1103. */
  1104. static inline int
  1105. dp_tx_attempt_coalescing(struct dp_soc *soc, struct dp_vdev *vdev,
  1106. struct dp_tx_desc_s *tx_desc,
  1107. uint8_t tid)
  1108. {
  1109. struct dp_swlm *swlm = &soc->swlm;
  1110. union swlm_data swlm_query_data;
  1111. struct dp_swlm_tcl_data tcl_data;
  1112. QDF_STATUS status;
  1113. int ret;
  1114. if (qdf_unlikely(!swlm->is_enabled))
  1115. return 0;
  1116. tcl_data.nbuf = tx_desc->nbuf;
  1117. tcl_data.tid = tid;
  1118. tcl_data.num_ll_connections = vdev->num_latency_critical_conn;
  1119. swlm_query_data.tcl_data = &tcl_data;
  1120. status = dp_swlm_tcl_pre_check(soc, &tcl_data);
  1121. if (QDF_IS_STATUS_ERROR(status)) {
  1122. dp_swlm_tcl_reset_session_data(soc);
  1123. DP_STATS_INC(swlm, tcl.coalesce_fail, 1);
  1124. return 0;
  1125. }
  1126. ret = dp_swlm_query_policy(soc, TCL_DATA, swlm_query_data);
  1127. if (ret) {
  1128. DP_STATS_INC(swlm, tcl.coalesce_success, 1);
  1129. } else {
  1130. DP_STATS_INC(swlm, tcl.coalesce_fail, 1);
  1131. }
  1132. return ret;
  1133. }
  1134. /**
  1135. * dp_tx_ring_access_end() - HAL ring access end for data transmission
  1136. * @soc: Datapath soc handle
  1137. * @hal_ring_hdl: HAL ring handle
  1138. * @coalesce: Coalesce the current write or not
  1139. *
  1140. * Returns: none
  1141. */
  1142. static inline void
  1143. dp_tx_ring_access_end(struct dp_soc *soc, hal_ring_handle_t hal_ring_hdl,
  1144. int coalesce)
  1145. {
  1146. if (coalesce)
  1147. dp_tx_hal_ring_access_end_reap(soc, hal_ring_hdl);
  1148. else
  1149. dp_tx_hal_ring_access_end(soc, hal_ring_hdl);
  1150. }
  1151. #else
  1152. static inline void dp_tx_update_stats(struct dp_soc *soc,
  1153. qdf_nbuf_t nbuf)
  1154. {
  1155. }
  1156. static inline int
  1157. dp_tx_attempt_coalescing(struct dp_soc *soc, struct dp_vdev *vdev,
  1158. struct dp_tx_desc_s *tx_desc,
  1159. uint8_t tid)
  1160. {
  1161. return 0;
  1162. }
  1163. static inline void
  1164. dp_tx_ring_access_end(struct dp_soc *soc, hal_ring_handle_t hal_ring_hdl,
  1165. int coalesce)
  1166. {
  1167. dp_tx_hal_ring_access_end(soc, hal_ring_hdl);
  1168. }
  1169. #endif
  1170. #ifdef FEATURE_RUNTIME_PM
  1171. /**
  1172. * dp_tx_ring_access_end_wrapper() - Wrapper for ring access end
  1173. * @soc: Datapath soc handle
  1174. * @hal_ring_hdl: HAL ring handle
  1175. * @coalesce: Coalesce the current write or not
  1176. *
  1177. * Wrapper for HAL ring access end for data transmission for
  1178. * FEATURE_RUNTIME_PM
  1179. *
  1180. * Returns: none
  1181. */
  1182. static inline void
  1183. dp_tx_ring_access_end_wrapper(struct dp_soc *soc,
  1184. hal_ring_handle_t hal_ring_hdl,
  1185. int coalesce)
  1186. {
  1187. int ret;
  1188. ret = hif_pm_runtime_get(soc->hif_handle,
  1189. RTPM_ID_DW_TX_HW_ENQUEUE, true);
  1190. switch (ret) {
  1191. case 0:
  1192. dp_tx_ring_access_end(soc, hal_ring_hdl, coalesce);
  1193. hif_pm_runtime_put(soc->hif_handle,
  1194. RTPM_ID_DW_TX_HW_ENQUEUE);
  1195. break;
  1196. /*
  1197. * If hif_pm_runtime_get returns -EBUSY or -EINPROGRESS,
  1198. * take the dp runtime refcount using dp_runtime_get,
  1199. * check link state,if up, write TX ring HP, else just set flush event.
  1200. * In dp_runtime_resume, wait until dp runtime refcount becomes
  1201. * zero or time out, then flush pending tx.
  1202. */
  1203. case -EBUSY:
  1204. case -EINPROGRESS:
  1205. dp_runtime_get(soc);
  1206. if (hif_pm_get_link_state(soc->hif_handle) ==
  1207. HIF_PM_LINK_STATE_UP) {
  1208. dp_tx_ring_access_end(soc, hal_ring_hdl, coalesce);
  1209. } else {
  1210. dp_tx_hal_ring_access_end_reap(soc, hal_ring_hdl);
  1211. hal_srng_set_event(hal_ring_hdl, HAL_SRNG_FLUSH_EVENT);
  1212. hal_srng_inc_flush_cnt(hal_ring_hdl);
  1213. }
  1214. dp_runtime_put(soc);
  1215. break;
  1216. default:
  1217. dp_runtime_get(soc);
  1218. dp_tx_hal_ring_access_end_reap(soc, hal_ring_hdl);
  1219. hal_srng_set_event(hal_ring_hdl, HAL_SRNG_FLUSH_EVENT);
  1220. hal_srng_inc_flush_cnt(hal_ring_hdl);
  1221. dp_runtime_put(soc);
  1222. }
  1223. }
  1224. #else
  1225. static inline void
  1226. dp_tx_ring_access_end_wrapper(struct dp_soc *soc,
  1227. hal_ring_handle_t hal_ring_hdl,
  1228. int coalesce)
  1229. {
  1230. dp_tx_ring_access_end(soc, hal_ring_hdl, coalesce);
  1231. }
  1232. #endif
  1233. /**
  1234. * dp_tx_hw_enqueue() - Enqueue to TCL HW for transmit
  1235. * @soc: DP Soc Handle
  1236. * @vdev: DP vdev handle
  1237. * @tx_desc: Tx Descriptor Handle
  1238. * @tid: TID from HLOS for overriding default DSCP-TID mapping
  1239. * @fw_metadata: Metadata to send to Target Firmware along with frame
  1240. * @ring_id: Ring ID of H/W ring to which we enqueue the packet
  1241. * @tx_exc_metadata: Handle that holds exception path meta data
  1242. *
  1243. * Gets the next free TCL HW DMA descriptor and sets up required parameters
  1244. * from software Tx descriptor
  1245. *
  1246. * Return: QDF_STATUS_SUCCESS: success
  1247. * QDF_STATUS_E_RESOURCES: Error return
  1248. */
  1249. static QDF_STATUS
  1250. dp_tx_hw_enqueue(struct dp_soc *soc, struct dp_vdev *vdev,
  1251. struct dp_tx_desc_s *tx_desc, uint16_t fw_metadata,
  1252. struct cdp_tx_exception_metadata *tx_exc_metadata,
  1253. struct dp_tx_msdu_info_s *msdu_info)
  1254. {
  1255. void *hal_tx_desc;
  1256. uint32_t *hal_tx_desc_cached;
  1257. int coalesce = 0;
  1258. struct dp_tx_queue *tx_q = &msdu_info->tx_queue;
  1259. uint8_t ring_id = tx_q->ring_id & DP_TX_QUEUE_MASK;
  1260. uint8_t tid = msdu_info->tid;
  1261. /*
  1262. * Setting it initialization statically here to avoid
  1263. * a memset call jump with qdf_mem_set call
  1264. */
  1265. uint8_t cached_desc[HAL_TX_DESC_LEN_BYTES] = { 0 };
  1266. enum cdp_sec_type sec_type = ((tx_exc_metadata &&
  1267. tx_exc_metadata->sec_type != CDP_INVALID_SEC_TYPE) ?
  1268. tx_exc_metadata->sec_type : vdev->sec_type);
  1269. /* Return Buffer Manager ID */
  1270. uint8_t bm_id = dp_tx_get_rbm_id(soc, ring_id);
  1271. hal_ring_handle_t hal_ring_hdl = NULL;
  1272. QDF_STATUS status = QDF_STATUS_E_RESOURCES;
  1273. if (!dp_tx_is_desc_id_valid(soc, tx_desc->id)) {
  1274. dp_err_rl("Invalid tx desc id:%d", tx_desc->id);
  1275. return QDF_STATUS_E_RESOURCES;
  1276. }
  1277. hal_tx_desc_cached = (void *) cached_desc;
  1278. hal_tx_desc_set_buf_addr(soc->hal_soc, hal_tx_desc_cached,
  1279. tx_desc->dma_addr, bm_id, tx_desc->id,
  1280. (tx_desc->flags & DP_TX_DESC_FLAG_FRAG));
  1281. hal_tx_desc_set_lmac_id(soc->hal_soc, hal_tx_desc_cached,
  1282. vdev->lmac_id);
  1283. hal_tx_desc_set_search_type(soc->hal_soc, hal_tx_desc_cached,
  1284. vdev->search_type);
  1285. hal_tx_desc_set_search_index(soc->hal_soc, hal_tx_desc_cached,
  1286. vdev->bss_ast_idx);
  1287. hal_tx_desc_set_dscp_tid_table_id(soc->hal_soc, hal_tx_desc_cached,
  1288. vdev->dscp_tid_map_id);
  1289. hal_tx_desc_set_encrypt_type(hal_tx_desc_cached,
  1290. sec_type_map[sec_type]);
  1291. hal_tx_desc_set_cache_set_num(soc->hal_soc, hal_tx_desc_cached,
  1292. (vdev->bss_ast_hash & 0xF));
  1293. hal_tx_desc_set_fw_metadata(hal_tx_desc_cached, fw_metadata);
  1294. hal_tx_desc_set_buf_length(hal_tx_desc_cached, tx_desc->length);
  1295. hal_tx_desc_set_buf_offset(hal_tx_desc_cached, tx_desc->pkt_offset);
  1296. hal_tx_desc_set_encap_type(hal_tx_desc_cached, tx_desc->tx_encap_type);
  1297. hal_tx_desc_set_addr_search_flags(hal_tx_desc_cached,
  1298. vdev->hal_desc_addr_search_flags);
  1299. if (tx_desc->flags & DP_TX_DESC_FLAG_TO_FW)
  1300. hal_tx_desc_set_to_fw(hal_tx_desc_cached, 1);
  1301. /* verify checksum offload configuration*/
  1302. if (vdev->csum_enabled &&
  1303. ((qdf_nbuf_get_tx_cksum(tx_desc->nbuf) == QDF_NBUF_TX_CKSUM_TCP_UDP)
  1304. || qdf_nbuf_is_tso(tx_desc->nbuf))) {
  1305. hal_tx_desc_set_l3_checksum_en(hal_tx_desc_cached, 1);
  1306. hal_tx_desc_set_l4_checksum_en(hal_tx_desc_cached, 1);
  1307. }
  1308. if (tid != HTT_TX_EXT_TID_INVALID)
  1309. hal_tx_desc_set_hlos_tid(hal_tx_desc_cached, tid);
  1310. if (tx_desc->flags & DP_TX_DESC_FLAG_MESH)
  1311. hal_tx_desc_set_mesh_en(soc->hal_soc, hal_tx_desc_cached, 1);
  1312. if (qdf_unlikely(vdev->pdev->delay_stats_flag) ||
  1313. qdf_unlikely(wlan_cfg_is_peer_ext_stats_enabled(
  1314. soc->wlan_cfg_ctx)))
  1315. tx_desc->timestamp = qdf_ktime_to_ms(qdf_ktime_real_get());
  1316. dp_verbose_debug("length:%d , type = %d, dma_addr %llx, offset %d desc id %u",
  1317. tx_desc->length,
  1318. (tx_desc->flags & DP_TX_DESC_FLAG_FRAG),
  1319. (uint64_t)tx_desc->dma_addr, tx_desc->pkt_offset,
  1320. tx_desc->id);
  1321. hal_ring_hdl = dp_tx_get_hal_ring_hdl(soc, ring_id);
  1322. if (qdf_unlikely(dp_tx_hal_ring_access_start(soc, hal_ring_hdl))) {
  1323. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1324. "%s %d : HAL RING Access Failed -- %pK",
  1325. __func__, __LINE__, hal_ring_hdl);
  1326. DP_STATS_INC(soc, tx.tcl_ring_full[ring_id], 1);
  1327. DP_STATS_INC(vdev, tx_i.dropped.enqueue_fail, 1);
  1328. return status;
  1329. }
  1330. /* Sync cached descriptor with HW */
  1331. hal_tx_desc = hal_srng_src_get_next(soc->hal_soc, hal_ring_hdl);
  1332. if (qdf_unlikely(!hal_tx_desc)) {
  1333. dp_verbose_debug("TCL ring full ring_id:%d", ring_id);
  1334. DP_STATS_INC(soc, tx.tcl_ring_full[ring_id], 1);
  1335. DP_STATS_INC(vdev, tx_i.dropped.enqueue_fail, 1);
  1336. goto ring_access_fail;
  1337. }
  1338. tx_desc->flags |= DP_TX_DESC_FLAG_QUEUED_TX;
  1339. dp_vdev_peer_stats_update_protocol_cnt_tx(vdev, tx_desc->nbuf);
  1340. hal_tx_desc_sync(hal_tx_desc_cached, hal_tx_desc);
  1341. coalesce = dp_tx_attempt_coalescing(soc, vdev, tx_desc, tid);
  1342. DP_STATS_INC_PKT(vdev, tx_i.processed, 1, tx_desc->length);
  1343. dp_tx_update_stats(soc, tx_desc->nbuf);
  1344. status = QDF_STATUS_SUCCESS;
  1345. ring_access_fail:
  1346. dp_tx_ring_access_end_wrapper(soc, hal_ring_hdl, coalesce);
  1347. return status;
  1348. }
  1349. /**
  1350. * dp_cce_classify() - Classify the frame based on CCE rules
  1351. * @vdev: DP vdev handle
  1352. * @nbuf: skb
  1353. *
  1354. * Classify frames based on CCE rules
  1355. * Return: bool( true if classified,
  1356. * else false)
  1357. */
  1358. static bool dp_cce_classify(struct dp_vdev *vdev, qdf_nbuf_t nbuf)
  1359. {
  1360. qdf_ether_header_t *eh = NULL;
  1361. uint16_t ether_type;
  1362. qdf_llc_t *llcHdr;
  1363. qdf_nbuf_t nbuf_clone = NULL;
  1364. qdf_dot3_qosframe_t *qos_wh = NULL;
  1365. if (qdf_likely(vdev->skip_sw_tid_classification)) {
  1366. /*
  1367. * In case of mesh packets or hlos tid override enabled,
  1368. * don't do any classification
  1369. */
  1370. if (qdf_unlikely(vdev->skip_sw_tid_classification
  1371. & DP_TX_SKIP_CCE_CLASSIFY))
  1372. return false;
  1373. }
  1374. if (qdf_likely(vdev->tx_encap_type != htt_cmn_pkt_type_raw)) {
  1375. eh = (qdf_ether_header_t *)qdf_nbuf_data(nbuf);
  1376. ether_type = eh->ether_type;
  1377. llcHdr = (qdf_llc_t *)(nbuf->data +
  1378. sizeof(qdf_ether_header_t));
  1379. } else {
  1380. qos_wh = (qdf_dot3_qosframe_t *) nbuf->data;
  1381. /* For encrypted packets don't do any classification */
  1382. if (qdf_unlikely(qos_wh->i_fc[1] & IEEE80211_FC1_WEP))
  1383. return false;
  1384. if (qdf_unlikely(qos_wh->i_fc[0] & QDF_IEEE80211_FC0_SUBTYPE_QOS)) {
  1385. if (qdf_unlikely(
  1386. qos_wh->i_fc[1] & QDF_IEEE80211_FC1_TODS &&
  1387. qos_wh->i_fc[1] & QDF_IEEE80211_FC1_FROMDS)) {
  1388. ether_type = *(uint16_t *)(nbuf->data
  1389. + QDF_IEEE80211_4ADDR_HDR_LEN
  1390. + sizeof(qdf_llc_t)
  1391. - sizeof(ether_type));
  1392. llcHdr = (qdf_llc_t *)(nbuf->data +
  1393. QDF_IEEE80211_4ADDR_HDR_LEN);
  1394. } else {
  1395. ether_type = *(uint16_t *)(nbuf->data
  1396. + QDF_IEEE80211_3ADDR_HDR_LEN
  1397. + sizeof(qdf_llc_t)
  1398. - sizeof(ether_type));
  1399. llcHdr = (qdf_llc_t *)(nbuf->data +
  1400. QDF_IEEE80211_3ADDR_HDR_LEN);
  1401. }
  1402. if (qdf_unlikely(DP_FRAME_IS_SNAP(llcHdr)
  1403. && (ether_type ==
  1404. qdf_htons(QDF_NBUF_TRAC_EAPOL_ETH_TYPE)))) {
  1405. DP_STATS_INC(vdev, tx_i.cce_classified_raw, 1);
  1406. return true;
  1407. }
  1408. }
  1409. return false;
  1410. }
  1411. if (qdf_unlikely(DP_FRAME_IS_SNAP(llcHdr))) {
  1412. ether_type = *(uint16_t *)(nbuf->data + 2*QDF_MAC_ADDR_SIZE +
  1413. sizeof(*llcHdr));
  1414. nbuf_clone = qdf_nbuf_clone(nbuf);
  1415. if (qdf_unlikely(nbuf_clone)) {
  1416. qdf_nbuf_pull_head(nbuf_clone, sizeof(*llcHdr));
  1417. if (ether_type == htons(ETHERTYPE_VLAN)) {
  1418. qdf_nbuf_pull_head(nbuf_clone,
  1419. sizeof(qdf_net_vlanhdr_t));
  1420. }
  1421. }
  1422. } else {
  1423. if (ether_type == htons(ETHERTYPE_VLAN)) {
  1424. nbuf_clone = qdf_nbuf_clone(nbuf);
  1425. if (qdf_unlikely(nbuf_clone)) {
  1426. qdf_nbuf_pull_head(nbuf_clone,
  1427. sizeof(qdf_net_vlanhdr_t));
  1428. }
  1429. }
  1430. }
  1431. if (qdf_unlikely(nbuf_clone))
  1432. nbuf = nbuf_clone;
  1433. if (qdf_unlikely(qdf_nbuf_is_ipv4_eapol_pkt(nbuf)
  1434. || qdf_nbuf_is_ipv4_arp_pkt(nbuf)
  1435. || qdf_nbuf_is_ipv4_wapi_pkt(nbuf)
  1436. || qdf_nbuf_is_ipv4_tdls_pkt(nbuf)
  1437. || (qdf_nbuf_is_ipv4_pkt(nbuf)
  1438. && qdf_nbuf_is_ipv4_dhcp_pkt(nbuf))
  1439. || (qdf_nbuf_is_ipv6_pkt(nbuf) &&
  1440. qdf_nbuf_is_ipv6_dhcp_pkt(nbuf)))) {
  1441. if (qdf_unlikely(nbuf_clone))
  1442. qdf_nbuf_free(nbuf_clone);
  1443. return true;
  1444. }
  1445. if (qdf_unlikely(nbuf_clone))
  1446. qdf_nbuf_free(nbuf_clone);
  1447. return false;
  1448. }
  1449. /**
  1450. * dp_tx_get_tid() - Obtain TID to be used for this frame
  1451. * @vdev: DP vdev handle
  1452. * @nbuf: skb
  1453. *
  1454. * Extract the DSCP or PCP information from frame and map into TID value.
  1455. *
  1456. * Return: void
  1457. */
  1458. static void dp_tx_get_tid(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1459. struct dp_tx_msdu_info_s *msdu_info)
  1460. {
  1461. uint8_t tos = 0, dscp_tid_override = 0;
  1462. uint8_t *hdr_ptr, *L3datap;
  1463. uint8_t is_mcast = 0;
  1464. qdf_ether_header_t *eh = NULL;
  1465. qdf_ethervlan_header_t *evh = NULL;
  1466. uint16_t ether_type;
  1467. qdf_llc_t *llcHdr;
  1468. struct dp_pdev *pdev = (struct dp_pdev *)vdev->pdev;
  1469. DP_TX_TID_OVERRIDE(msdu_info, nbuf);
  1470. if (qdf_likely(vdev->tx_encap_type != htt_cmn_pkt_type_raw)) {
  1471. eh = (qdf_ether_header_t *)nbuf->data;
  1472. hdr_ptr = (uint8_t *)(eh->ether_dhost);
  1473. L3datap = hdr_ptr + sizeof(qdf_ether_header_t);
  1474. } else {
  1475. qdf_dot3_qosframe_t *qos_wh =
  1476. (qdf_dot3_qosframe_t *) nbuf->data;
  1477. msdu_info->tid = qos_wh->i_fc[0] & DP_FC0_SUBTYPE_QOS ?
  1478. qos_wh->i_qos[0] & DP_QOS_TID : 0;
  1479. return;
  1480. }
  1481. is_mcast = DP_FRAME_IS_MULTICAST(hdr_ptr);
  1482. ether_type = eh->ether_type;
  1483. llcHdr = (qdf_llc_t *)(nbuf->data + sizeof(qdf_ether_header_t));
  1484. /*
  1485. * Check if packet is dot3 or eth2 type.
  1486. */
  1487. if (DP_FRAME_IS_LLC(ether_type) && DP_FRAME_IS_SNAP(llcHdr)) {
  1488. ether_type = (uint16_t)*(nbuf->data + 2*QDF_MAC_ADDR_SIZE +
  1489. sizeof(*llcHdr));
  1490. if (ether_type == htons(ETHERTYPE_VLAN)) {
  1491. L3datap = hdr_ptr + sizeof(qdf_ethervlan_header_t) +
  1492. sizeof(*llcHdr);
  1493. ether_type = (uint16_t)*(nbuf->data + 2*QDF_MAC_ADDR_SIZE
  1494. + sizeof(*llcHdr) +
  1495. sizeof(qdf_net_vlanhdr_t));
  1496. } else {
  1497. L3datap = hdr_ptr + sizeof(qdf_ether_header_t) +
  1498. sizeof(*llcHdr);
  1499. }
  1500. } else {
  1501. if (ether_type == htons(ETHERTYPE_VLAN)) {
  1502. evh = (qdf_ethervlan_header_t *) eh;
  1503. ether_type = evh->ether_type;
  1504. L3datap = hdr_ptr + sizeof(qdf_ethervlan_header_t);
  1505. }
  1506. }
  1507. /*
  1508. * Find priority from IP TOS DSCP field
  1509. */
  1510. if (qdf_nbuf_is_ipv4_pkt(nbuf)) {
  1511. qdf_net_iphdr_t *ip = (qdf_net_iphdr_t *) L3datap;
  1512. if (qdf_nbuf_is_ipv4_dhcp_pkt(nbuf)) {
  1513. /* Only for unicast frames */
  1514. if (!is_mcast) {
  1515. /* send it on VO queue */
  1516. msdu_info->tid = DP_VO_TID;
  1517. }
  1518. } else {
  1519. /*
  1520. * IP frame: exclude ECN bits 0-1 and map DSCP bits 2-7
  1521. * from TOS byte.
  1522. */
  1523. tos = ip->ip_tos;
  1524. dscp_tid_override = 1;
  1525. }
  1526. } else if (qdf_nbuf_is_ipv6_pkt(nbuf)) {
  1527. /* TODO
  1528. * use flowlabel
  1529. *igmpmld cases to be handled in phase 2
  1530. */
  1531. unsigned long ver_pri_flowlabel;
  1532. unsigned long pri;
  1533. ver_pri_flowlabel = *(unsigned long *) L3datap;
  1534. pri = (ntohl(ver_pri_flowlabel) & IPV6_FLOWINFO_PRIORITY) >>
  1535. DP_IPV6_PRIORITY_SHIFT;
  1536. tos = pri;
  1537. dscp_tid_override = 1;
  1538. } else if (qdf_nbuf_is_ipv4_eapol_pkt(nbuf))
  1539. msdu_info->tid = DP_VO_TID;
  1540. else if (qdf_nbuf_is_ipv4_arp_pkt(nbuf)) {
  1541. /* Only for unicast frames */
  1542. if (!is_mcast) {
  1543. /* send ucast arp on VO queue */
  1544. msdu_info->tid = DP_VO_TID;
  1545. }
  1546. }
  1547. /*
  1548. * Assign all MCAST packets to BE
  1549. */
  1550. if (qdf_unlikely(vdev->tx_encap_type != htt_cmn_pkt_type_raw)) {
  1551. if (is_mcast) {
  1552. tos = 0;
  1553. dscp_tid_override = 1;
  1554. }
  1555. }
  1556. if (dscp_tid_override == 1) {
  1557. tos = (tos >> DP_IP_DSCP_SHIFT) & DP_IP_DSCP_MASK;
  1558. msdu_info->tid = pdev->dscp_tid_map[vdev->dscp_tid_map_id][tos];
  1559. }
  1560. if (msdu_info->tid >= CDP_MAX_DATA_TIDS)
  1561. msdu_info->tid = CDP_MAX_DATA_TIDS - 1;
  1562. return;
  1563. }
  1564. /**
  1565. * dp_tx_classify_tid() - Obtain TID to be used for this frame
  1566. * @vdev: DP vdev handle
  1567. * @nbuf: skb
  1568. *
  1569. * Software based TID classification is required when more than 2 DSCP-TID
  1570. * mapping tables are needed.
  1571. * Hardware supports 2 DSCP-TID mapping tables for HKv1 and 48 for HKv2.
  1572. *
  1573. * Return: void
  1574. */
  1575. static inline void dp_tx_classify_tid(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1576. struct dp_tx_msdu_info_s *msdu_info)
  1577. {
  1578. DP_TX_TID_OVERRIDE(msdu_info, nbuf);
  1579. /*
  1580. * skip_sw_tid_classification flag will set in below cases-
  1581. * 1. vdev->dscp_tid_map_id < pdev->soc->num_hw_dscp_tid_map
  1582. * 2. hlos_tid_override enabled for vdev
  1583. * 3. mesh mode enabled for vdev
  1584. */
  1585. if (qdf_likely(vdev->skip_sw_tid_classification)) {
  1586. /* Update tid in msdu_info from skb priority */
  1587. if (qdf_unlikely(vdev->skip_sw_tid_classification
  1588. & DP_TXRX_HLOS_TID_OVERRIDE_ENABLED)) {
  1589. msdu_info->tid = qdf_nbuf_get_priority(nbuf);
  1590. return;
  1591. }
  1592. return;
  1593. }
  1594. dp_tx_get_tid(vdev, nbuf, msdu_info);
  1595. }
  1596. #ifdef FEATURE_WLAN_TDLS
  1597. /**
  1598. * dp_tx_update_tdls_flags() - Update descriptor flags for TDLS frame
  1599. * @soc: datapath SOC
  1600. * @vdev: datapath vdev
  1601. * @tx_desc: TX descriptor
  1602. *
  1603. * Return: None
  1604. */
  1605. static void dp_tx_update_tdls_flags(struct dp_soc *soc,
  1606. struct dp_vdev *vdev,
  1607. struct dp_tx_desc_s *tx_desc)
  1608. {
  1609. if (vdev) {
  1610. if (vdev->is_tdls_frame) {
  1611. tx_desc->flags |= DP_TX_DESC_FLAG_TDLS_FRAME;
  1612. vdev->is_tdls_frame = false;
  1613. }
  1614. }
  1615. }
  1616. /**
  1617. * dp_non_std_tx_comp_free_buff() - Free the non std tx packet buffer
  1618. * @soc: dp_soc handle
  1619. * @tx_desc: TX descriptor
  1620. * @vdev: datapath vdev handle
  1621. *
  1622. * Return: None
  1623. */
  1624. static void dp_non_std_tx_comp_free_buff(struct dp_soc *soc,
  1625. struct dp_tx_desc_s *tx_desc)
  1626. {
  1627. struct hal_tx_completion_status ts = {0};
  1628. qdf_nbuf_t nbuf = tx_desc->nbuf;
  1629. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, tx_desc->vdev_id,
  1630. DP_MOD_ID_TDLS);
  1631. if (qdf_unlikely(!vdev)) {
  1632. dp_err_rl("vdev is null!");
  1633. goto error;
  1634. }
  1635. hal_tx_comp_get_status(&tx_desc->comp, &ts, vdev->pdev->soc->hal_soc);
  1636. if (vdev->tx_non_std_data_callback.func) {
  1637. qdf_nbuf_set_next(nbuf, NULL);
  1638. vdev->tx_non_std_data_callback.func(
  1639. vdev->tx_non_std_data_callback.ctxt,
  1640. nbuf, ts.status);
  1641. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_TDLS);
  1642. return;
  1643. } else {
  1644. dp_err_rl("callback func is null");
  1645. }
  1646. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_TDLS);
  1647. error:
  1648. qdf_nbuf_unmap_single(soc->osdev, nbuf, QDF_DMA_TO_DEVICE);
  1649. qdf_nbuf_free(nbuf);
  1650. }
  1651. /**
  1652. * dp_tx_msdu_single_map() - do nbuf map
  1653. * @vdev: DP vdev handle
  1654. * @tx_desc: DP TX descriptor pointer
  1655. * @nbuf: skb pointer
  1656. *
  1657. * For TDLS frame, use qdf_nbuf_map_single() to align with the unmap
  1658. * operation done in other component.
  1659. *
  1660. * Return: QDF_STATUS
  1661. */
  1662. static inline QDF_STATUS dp_tx_msdu_single_map(struct dp_vdev *vdev,
  1663. struct dp_tx_desc_s *tx_desc,
  1664. qdf_nbuf_t nbuf)
  1665. {
  1666. if (qdf_likely(!(tx_desc->flags & DP_TX_DESC_FLAG_TDLS_FRAME)))
  1667. return qdf_nbuf_map_nbytes_single(vdev->osdev,
  1668. nbuf,
  1669. QDF_DMA_TO_DEVICE,
  1670. nbuf->len);
  1671. else
  1672. return qdf_nbuf_map_single(vdev->osdev, nbuf,
  1673. QDF_DMA_TO_DEVICE);
  1674. }
  1675. #else
  1676. static inline void dp_tx_update_tdls_flags(struct dp_soc *soc,
  1677. struct dp_vdev *vdev,
  1678. struct dp_tx_desc_s *tx_desc)
  1679. {
  1680. }
  1681. static inline void dp_non_std_tx_comp_free_buff(struct dp_soc *soc,
  1682. struct dp_tx_desc_s *tx_desc)
  1683. {
  1684. }
  1685. static inline QDF_STATUS dp_tx_msdu_single_map(struct dp_vdev *vdev,
  1686. struct dp_tx_desc_s *tx_desc,
  1687. qdf_nbuf_t nbuf)
  1688. {
  1689. return qdf_nbuf_map_nbytes_single(vdev->osdev,
  1690. nbuf,
  1691. QDF_DMA_TO_DEVICE,
  1692. nbuf->len);
  1693. }
  1694. #endif
  1695. #ifdef MESH_MODE_SUPPORT
  1696. /**
  1697. * dp_tx_update_mesh_flags() - Update descriptor flags for mesh VAP
  1698. * @soc: datapath SOC
  1699. * @vdev: datapath vdev
  1700. * @tx_desc: TX descriptor
  1701. *
  1702. * Return: None
  1703. */
  1704. static inline void dp_tx_update_mesh_flags(struct dp_soc *soc,
  1705. struct dp_vdev *vdev,
  1706. struct dp_tx_desc_s *tx_desc)
  1707. {
  1708. if (qdf_unlikely(vdev->mesh_vdev))
  1709. tx_desc->flags |= DP_TX_DESC_FLAG_MESH_MODE;
  1710. }
  1711. /**
  1712. * dp_mesh_tx_comp_free_buff() - Free the mesh tx packet buffer
  1713. * @soc: dp_soc handle
  1714. * @tx_desc: TX descriptor
  1715. * @vdev: datapath vdev handle
  1716. *
  1717. * Return: None
  1718. */
  1719. static inline void dp_mesh_tx_comp_free_buff(struct dp_soc *soc,
  1720. struct dp_tx_desc_s *tx_desc)
  1721. {
  1722. qdf_nbuf_t nbuf = tx_desc->nbuf;
  1723. struct dp_vdev *vdev = NULL;
  1724. if (tx_desc->flags & DP_TX_DESC_FLAG_TO_FW) {
  1725. qdf_nbuf_free(nbuf);
  1726. DP_STATS_INC(vdev, tx_i.mesh.completion_fw, 1);
  1727. } else {
  1728. vdev = dp_vdev_get_ref_by_id(soc, tx_desc->vdev_id,
  1729. DP_MOD_ID_MESH);
  1730. if (vdev && vdev->osif_tx_free_ext)
  1731. vdev->osif_tx_free_ext((nbuf));
  1732. else
  1733. qdf_nbuf_free(nbuf);
  1734. if (vdev)
  1735. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_MESH);
  1736. }
  1737. }
  1738. #else
  1739. static inline void dp_tx_update_mesh_flags(struct dp_soc *soc,
  1740. struct dp_vdev *vdev,
  1741. struct dp_tx_desc_s *tx_desc)
  1742. {
  1743. }
  1744. static inline void dp_mesh_tx_comp_free_buff(struct dp_soc *soc,
  1745. struct dp_tx_desc_s *tx_desc)
  1746. {
  1747. }
  1748. #endif
  1749. /**
  1750. * dp_tx_frame_is_drop() - checks if the packet is loopback
  1751. * @vdev: DP vdev handle
  1752. * @nbuf: skb
  1753. *
  1754. * Return: 1 if frame needs to be dropped else 0
  1755. */
  1756. int dp_tx_frame_is_drop(struct dp_vdev *vdev, uint8_t *srcmac, uint8_t *dstmac)
  1757. {
  1758. struct dp_pdev *pdev = NULL;
  1759. struct dp_ast_entry *src_ast_entry = NULL;
  1760. struct dp_ast_entry *dst_ast_entry = NULL;
  1761. struct dp_soc *soc = NULL;
  1762. qdf_assert(vdev);
  1763. pdev = vdev->pdev;
  1764. qdf_assert(pdev);
  1765. soc = pdev->soc;
  1766. dst_ast_entry = dp_peer_ast_hash_find_by_pdevid
  1767. (soc, dstmac, vdev->pdev->pdev_id);
  1768. src_ast_entry = dp_peer_ast_hash_find_by_pdevid
  1769. (soc, srcmac, vdev->pdev->pdev_id);
  1770. if (dst_ast_entry && src_ast_entry) {
  1771. if (dst_ast_entry->peer_id ==
  1772. src_ast_entry->peer_id)
  1773. return 1;
  1774. }
  1775. return 0;
  1776. }
  1777. /**
  1778. * dp_tx_send_msdu_single() - Setup descriptor and enqueue single MSDU to TCL
  1779. * @vdev: DP vdev handle
  1780. * @nbuf: skb
  1781. * @tid: TID from HLOS for overriding default DSCP-TID mapping
  1782. * @meta_data: Metadata to the fw
  1783. * @tx_q: Tx queue to be used for this Tx frame
  1784. * @peer_id: peer_id of the peer in case of NAWDS frames
  1785. * @tx_exc_metadata: Handle that holds exception path metadata
  1786. *
  1787. * Return: NULL on success,
  1788. * nbuf when it fails to send
  1789. */
  1790. qdf_nbuf_t
  1791. dp_tx_send_msdu_single(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1792. struct dp_tx_msdu_info_s *msdu_info, uint16_t peer_id,
  1793. struct cdp_tx_exception_metadata *tx_exc_metadata)
  1794. {
  1795. struct dp_pdev *pdev = vdev->pdev;
  1796. struct dp_soc *soc = pdev->soc;
  1797. struct dp_tx_desc_s *tx_desc;
  1798. QDF_STATUS status;
  1799. struct dp_tx_queue *tx_q = &(msdu_info->tx_queue);
  1800. uint16_t htt_tcl_metadata = 0;
  1801. enum cdp_tx_sw_drop drop_code = TX_MAX_DROP;
  1802. uint8_t tid = msdu_info->tid;
  1803. struct cdp_tid_tx_stats *tid_stats = NULL;
  1804. /* Setup Tx descriptor for an MSDU, and MSDU extension descriptor */
  1805. tx_desc = dp_tx_prepare_desc_single(vdev, nbuf, tx_q->desc_pool_id,
  1806. msdu_info, tx_exc_metadata);
  1807. if (!tx_desc) {
  1808. dp_err_rl("Tx_desc prepare Fail vdev %pK queue %d",
  1809. vdev, tx_q->desc_pool_id);
  1810. drop_code = TX_DESC_ERR;
  1811. goto fail_return;
  1812. }
  1813. if (qdf_unlikely(soc->cce_disable)) {
  1814. if (dp_cce_classify(vdev, nbuf) == true) {
  1815. DP_STATS_INC(vdev, tx_i.cce_classified, 1);
  1816. tid = DP_VO_TID;
  1817. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  1818. }
  1819. }
  1820. dp_tx_update_tdls_flags(soc, vdev, tx_desc);
  1821. if (qdf_unlikely(peer_id == DP_INVALID_PEER)) {
  1822. htt_tcl_metadata = vdev->htt_tcl_metadata;
  1823. HTT_TX_TCL_METADATA_HOST_INSPECTED_SET(htt_tcl_metadata, 1);
  1824. } else if (qdf_unlikely(peer_id != HTT_INVALID_PEER)) {
  1825. HTT_TX_TCL_METADATA_TYPE_SET(htt_tcl_metadata,
  1826. HTT_TCL_METADATA_TYPE_PEER_BASED);
  1827. HTT_TX_TCL_METADATA_PEER_ID_SET(htt_tcl_metadata,
  1828. peer_id);
  1829. } else
  1830. htt_tcl_metadata = vdev->htt_tcl_metadata;
  1831. if (msdu_info->exception_fw)
  1832. HTT_TX_TCL_METADATA_VALID_HTT_SET(htt_tcl_metadata, 1);
  1833. dp_tx_desc_update_fast_comp_flag(soc, tx_desc,
  1834. !pdev->enhanced_stats_en);
  1835. dp_tx_update_mesh_flags(soc, vdev, tx_desc);
  1836. if (qdf_unlikely(QDF_STATUS_SUCCESS !=
  1837. dp_tx_msdu_single_map(vdev, tx_desc, nbuf))) {
  1838. /* Handle failure */
  1839. dp_err("qdf_nbuf_map failed");
  1840. DP_STATS_INC(vdev, tx_i.dropped.dma_error, 1);
  1841. drop_code = TX_DMA_MAP_ERR;
  1842. goto release_desc;
  1843. }
  1844. tx_desc->dma_addr = qdf_nbuf_mapped_paddr_get(tx_desc->nbuf);
  1845. /* Enqueue the Tx MSDU descriptor to HW for transmit */
  1846. status = dp_tx_hw_enqueue(soc, vdev, tx_desc, htt_tcl_metadata,
  1847. tx_exc_metadata, msdu_info);
  1848. if (status != QDF_STATUS_SUCCESS) {
  1849. dp_tx_err("Tx_hw_enqueue Fail tx_desc %pK queue %d",
  1850. tx_desc, tx_q->ring_id);
  1851. qdf_nbuf_unmap_nbytes_single(vdev->osdev, nbuf,
  1852. QDF_DMA_TO_DEVICE,
  1853. nbuf->len);
  1854. drop_code = TX_HW_ENQUEUE;
  1855. goto release_desc;
  1856. }
  1857. return NULL;
  1858. release_desc:
  1859. dp_tx_desc_release(tx_desc, tx_q->desc_pool_id);
  1860. fail_return:
  1861. dp_tx_get_tid(vdev, nbuf, msdu_info);
  1862. tid_stats = &pdev->stats.tid_stats.
  1863. tid_tx_stats[tx_q->ring_id][tid];
  1864. tid_stats->swdrop_cnt[drop_code]++;
  1865. return nbuf;
  1866. }
  1867. /**
  1868. * dp_tx_comp_free_buf() - Free nbuf associated with the Tx Descriptor
  1869. * @soc: Soc handle
  1870. * @desc: software Tx descriptor to be processed
  1871. *
  1872. * Return: none
  1873. */
  1874. static inline void dp_tx_comp_free_buf(struct dp_soc *soc,
  1875. struct dp_tx_desc_s *desc)
  1876. {
  1877. qdf_nbuf_t nbuf = desc->nbuf;
  1878. /* nbuf already freed in vdev detach path */
  1879. if (!nbuf)
  1880. return;
  1881. /* If it is TDLS mgmt, don't unmap or free the frame */
  1882. if (desc->flags & DP_TX_DESC_FLAG_TDLS_FRAME)
  1883. return dp_non_std_tx_comp_free_buff(soc, desc);
  1884. /* 0 : MSDU buffer, 1 : MLE */
  1885. if (desc->msdu_ext_desc) {
  1886. /* TSO free */
  1887. if (hal_tx_ext_desc_get_tso_enable(
  1888. desc->msdu_ext_desc->vaddr)) {
  1889. /* unmap eash TSO seg before free the nbuf */
  1890. dp_tx_tso_unmap_segment(soc, desc->tso_desc,
  1891. desc->tso_num_desc);
  1892. qdf_nbuf_free(nbuf);
  1893. return;
  1894. }
  1895. }
  1896. /* If it's ME frame, dont unmap the cloned nbuf's */
  1897. if ((desc->flags & DP_TX_DESC_FLAG_ME) && qdf_nbuf_is_cloned(nbuf))
  1898. goto nbuf_free;
  1899. dp_tx_unmap(soc, desc);
  1900. if (desc->flags & DP_TX_DESC_FLAG_MESH_MODE)
  1901. return dp_mesh_tx_comp_free_buff(soc, desc);
  1902. nbuf_free:
  1903. qdf_nbuf_free(nbuf);
  1904. }
  1905. /**
  1906. * dp_tx_send_msdu_multiple() - Enqueue multiple MSDUs
  1907. * @vdev: DP vdev handle
  1908. * @nbuf: skb
  1909. * @msdu_info: MSDU info to be setup in MSDU extension descriptor
  1910. *
  1911. * Prepare descriptors for multiple MSDUs (TSO segments) and enqueue to TCL
  1912. *
  1913. * Return: NULL on success,
  1914. * nbuf when it fails to send
  1915. */
  1916. #if QDF_LOCK_STATS
  1917. noinline
  1918. #else
  1919. #endif
  1920. qdf_nbuf_t dp_tx_send_msdu_multiple(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  1921. struct dp_tx_msdu_info_s *msdu_info)
  1922. {
  1923. uint32_t i;
  1924. struct dp_pdev *pdev = vdev->pdev;
  1925. struct dp_soc *soc = pdev->soc;
  1926. struct dp_tx_desc_s *tx_desc;
  1927. bool is_cce_classified = false;
  1928. QDF_STATUS status;
  1929. uint16_t htt_tcl_metadata = 0;
  1930. struct dp_tx_queue *tx_q = &msdu_info->tx_queue;
  1931. struct cdp_tid_tx_stats *tid_stats = NULL;
  1932. uint8_t prep_desc_fail = 0, hw_enq_fail = 0;
  1933. if (qdf_unlikely(soc->cce_disable)) {
  1934. is_cce_classified = dp_cce_classify(vdev, nbuf);
  1935. if (is_cce_classified) {
  1936. DP_STATS_INC(vdev, tx_i.cce_classified, 1);
  1937. msdu_info->tid = DP_VO_TID;
  1938. }
  1939. }
  1940. if (msdu_info->frm_type == dp_tx_frm_me)
  1941. nbuf = msdu_info->u.sg_info.curr_seg->nbuf;
  1942. i = 0;
  1943. /* Print statement to track i and num_seg */
  1944. /*
  1945. * For each segment (maps to 1 MSDU) , prepare software and hardware
  1946. * descriptors using information in msdu_info
  1947. */
  1948. while (i < msdu_info->num_seg) {
  1949. /*
  1950. * Setup Tx descriptor for an MSDU, and MSDU extension
  1951. * descriptor
  1952. */
  1953. tx_desc = dp_tx_prepare_desc(vdev, nbuf, msdu_info,
  1954. tx_q->desc_pool_id);
  1955. if (!tx_desc) {
  1956. if (msdu_info->frm_type == dp_tx_frm_me) {
  1957. prep_desc_fail++;
  1958. dp_tx_me_free_buf(pdev,
  1959. (void *)(msdu_info->u.sg_info
  1960. .curr_seg->frags[0].vaddr));
  1961. if (prep_desc_fail == msdu_info->num_seg) {
  1962. /*
  1963. * Unmap is needed only if descriptor
  1964. * preparation failed for all segments.
  1965. */
  1966. qdf_nbuf_unmap(soc->osdev,
  1967. msdu_info->u.sg_info.
  1968. curr_seg->nbuf,
  1969. QDF_DMA_TO_DEVICE);
  1970. }
  1971. /*
  1972. * Free the nbuf for the current segment
  1973. * and make it point to the next in the list.
  1974. * For me, there are as many segments as there
  1975. * are no of clients.
  1976. */
  1977. qdf_nbuf_free(msdu_info->u.sg_info
  1978. .curr_seg->nbuf);
  1979. if (msdu_info->u.sg_info.curr_seg->next) {
  1980. msdu_info->u.sg_info.curr_seg =
  1981. msdu_info->u.sg_info
  1982. .curr_seg->next;
  1983. nbuf = msdu_info->u.sg_info
  1984. .curr_seg->nbuf;
  1985. }
  1986. i++;
  1987. continue;
  1988. }
  1989. if (msdu_info->frm_type == dp_tx_frm_tso) {
  1990. dp_tx_tso_unmap_segment(soc,
  1991. msdu_info->u.tso_info.
  1992. curr_seg,
  1993. msdu_info->u.tso_info.
  1994. tso_num_seg_list);
  1995. if (msdu_info->u.tso_info.curr_seg->next) {
  1996. msdu_info->u.tso_info.curr_seg =
  1997. msdu_info->u.tso_info.curr_seg->next;
  1998. i++;
  1999. continue;
  2000. }
  2001. }
  2002. goto done;
  2003. }
  2004. if (msdu_info->frm_type == dp_tx_frm_me) {
  2005. tx_desc->me_buffer =
  2006. msdu_info->u.sg_info.curr_seg->frags[0].vaddr;
  2007. tx_desc->flags |= DP_TX_DESC_FLAG_ME;
  2008. }
  2009. if (is_cce_classified)
  2010. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  2011. htt_tcl_metadata = vdev->htt_tcl_metadata;
  2012. if (msdu_info->exception_fw) {
  2013. HTT_TX_TCL_METADATA_VALID_HTT_SET(htt_tcl_metadata, 1);
  2014. }
  2015. /*
  2016. * For frames with multiple segments (TSO, ME), jump to next
  2017. * segment.
  2018. */
  2019. if (msdu_info->frm_type == dp_tx_frm_tso) {
  2020. if (msdu_info->u.tso_info.curr_seg->next) {
  2021. msdu_info->u.tso_info.curr_seg =
  2022. msdu_info->u.tso_info.curr_seg->next;
  2023. /*
  2024. * If this is a jumbo nbuf, then increment the
  2025. * number of nbuf users for each additional
  2026. * segment of the msdu. This will ensure that
  2027. * the skb is freed only after receiving tx
  2028. * completion for all segments of an nbuf
  2029. */
  2030. qdf_nbuf_inc_users(nbuf);
  2031. /* Check with MCL if this is needed */
  2032. /* nbuf = msdu_info->u.tso_info.curr_seg->nbuf;
  2033. */
  2034. }
  2035. }
  2036. /*
  2037. * Enqueue the Tx MSDU descriptor to HW for transmit
  2038. */
  2039. status = dp_tx_hw_enqueue(soc, vdev, tx_desc, htt_tcl_metadata,
  2040. NULL, msdu_info);
  2041. if (status != QDF_STATUS_SUCCESS) {
  2042. dp_info("Tx_hw_enqueue Fail tx_desc %pK queue %d",
  2043. tx_desc, tx_q->ring_id);
  2044. dp_tx_get_tid(vdev, nbuf, msdu_info);
  2045. tid_stats = &pdev->stats.tid_stats.
  2046. tid_tx_stats[tx_q->ring_id][msdu_info->tid];
  2047. tid_stats->swdrop_cnt[TX_HW_ENQUEUE]++;
  2048. if (msdu_info->frm_type == dp_tx_frm_me) {
  2049. hw_enq_fail++;
  2050. if (hw_enq_fail == msdu_info->num_seg) {
  2051. /*
  2052. * Unmap is needed only if enqueue
  2053. * failed for all segments.
  2054. */
  2055. qdf_nbuf_unmap(soc->osdev,
  2056. msdu_info->u.sg_info.
  2057. curr_seg->nbuf,
  2058. QDF_DMA_TO_DEVICE);
  2059. }
  2060. /*
  2061. * Free the nbuf for the current segment
  2062. * and make it point to the next in the list.
  2063. * For me, there are as many segments as there
  2064. * are no of clients.
  2065. */
  2066. qdf_nbuf_free(msdu_info->u.sg_info
  2067. .curr_seg->nbuf);
  2068. if (msdu_info->u.sg_info.curr_seg->next) {
  2069. msdu_info->u.sg_info.curr_seg =
  2070. msdu_info->u.sg_info
  2071. .curr_seg->next;
  2072. nbuf = msdu_info->u.sg_info
  2073. .curr_seg->nbuf;
  2074. } else
  2075. break;
  2076. i++;
  2077. continue;
  2078. }
  2079. /*
  2080. * For TSO frames, the nbuf users increment done for
  2081. * the current segment has to be reverted, since the
  2082. * hw enqueue for this segment failed
  2083. */
  2084. if (msdu_info->frm_type == dp_tx_frm_tso &&
  2085. msdu_info->u.tso_info.curr_seg) {
  2086. /*
  2087. * unmap and free current,
  2088. * retransmit remaining segments
  2089. */
  2090. dp_tx_comp_free_buf(soc, tx_desc);
  2091. i++;
  2092. continue;
  2093. }
  2094. dp_tx_desc_release(tx_desc, tx_q->desc_pool_id);
  2095. goto done;
  2096. }
  2097. /*
  2098. * TODO
  2099. * if tso_info structure can be modified to have curr_seg
  2100. * as first element, following 2 blocks of code (for TSO and SG)
  2101. * can be combined into 1
  2102. */
  2103. /*
  2104. * For Multicast-Unicast converted packets,
  2105. * each converted frame (for a client) is represented as
  2106. * 1 segment
  2107. */
  2108. if ((msdu_info->frm_type == dp_tx_frm_sg) ||
  2109. (msdu_info->frm_type == dp_tx_frm_me)) {
  2110. if (msdu_info->u.sg_info.curr_seg->next) {
  2111. msdu_info->u.sg_info.curr_seg =
  2112. msdu_info->u.sg_info.curr_seg->next;
  2113. nbuf = msdu_info->u.sg_info.curr_seg->nbuf;
  2114. } else
  2115. break;
  2116. }
  2117. i++;
  2118. }
  2119. nbuf = NULL;
  2120. done:
  2121. return nbuf;
  2122. }
  2123. /**
  2124. * dp_tx_prepare_sg()- Extract SG info from NBUF and prepare msdu_info
  2125. * for SG frames
  2126. * @vdev: DP vdev handle
  2127. * @nbuf: skb
  2128. * @seg_info: Pointer to Segment info Descriptor to be prepared
  2129. * @msdu_info: MSDU info to be setup in MSDU descriptor and MSDU extension desc.
  2130. *
  2131. * Return: NULL on success,
  2132. * nbuf when it fails to send
  2133. */
  2134. static qdf_nbuf_t dp_tx_prepare_sg(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  2135. struct dp_tx_seg_info_s *seg_info, struct dp_tx_msdu_info_s *msdu_info)
  2136. {
  2137. uint32_t cur_frag, nr_frags, i;
  2138. qdf_dma_addr_t paddr;
  2139. struct dp_tx_sg_info_s *sg_info;
  2140. sg_info = &msdu_info->u.sg_info;
  2141. nr_frags = qdf_nbuf_get_nr_frags(nbuf);
  2142. if (QDF_STATUS_SUCCESS !=
  2143. qdf_nbuf_map_nbytes_single(vdev->osdev, nbuf,
  2144. QDF_DMA_TO_DEVICE,
  2145. qdf_nbuf_headlen(nbuf))) {
  2146. dp_tx_err("dma map error");
  2147. DP_STATS_INC(vdev, tx_i.sg.dma_map_error, 1);
  2148. qdf_nbuf_free(nbuf);
  2149. return NULL;
  2150. }
  2151. paddr = qdf_nbuf_mapped_paddr_get(nbuf);
  2152. seg_info->frags[0].paddr_lo = paddr;
  2153. seg_info->frags[0].paddr_hi = ((uint64_t) paddr) >> 32;
  2154. seg_info->frags[0].len = qdf_nbuf_headlen(nbuf);
  2155. seg_info->frags[0].vaddr = (void *) nbuf;
  2156. for (cur_frag = 0; cur_frag < nr_frags; cur_frag++) {
  2157. if (QDF_STATUS_E_FAILURE == qdf_nbuf_frag_map(vdev->osdev,
  2158. nbuf, 0, QDF_DMA_TO_DEVICE, cur_frag)) {
  2159. dp_tx_err("frag dma map error");
  2160. DP_STATS_INC(vdev, tx_i.sg.dma_map_error, 1);
  2161. goto map_err;
  2162. }
  2163. paddr = qdf_nbuf_get_tx_frag_paddr(nbuf);
  2164. seg_info->frags[cur_frag + 1].paddr_lo = paddr;
  2165. seg_info->frags[cur_frag + 1].paddr_hi =
  2166. ((uint64_t) paddr) >> 32;
  2167. seg_info->frags[cur_frag + 1].len =
  2168. qdf_nbuf_get_frag_size(nbuf, cur_frag);
  2169. }
  2170. seg_info->frag_cnt = (cur_frag + 1);
  2171. seg_info->total_len = qdf_nbuf_len(nbuf);
  2172. seg_info->next = NULL;
  2173. sg_info->curr_seg = seg_info;
  2174. msdu_info->frm_type = dp_tx_frm_sg;
  2175. msdu_info->num_seg = 1;
  2176. return nbuf;
  2177. map_err:
  2178. /* restore paddr into nbuf before calling unmap */
  2179. qdf_nbuf_mapped_paddr_set(nbuf,
  2180. (qdf_dma_addr_t)(seg_info->frags[0].paddr_lo |
  2181. ((uint64_t)
  2182. seg_info->frags[0].paddr_hi) << 32));
  2183. qdf_nbuf_unmap_nbytes_single(vdev->osdev, nbuf,
  2184. QDF_DMA_TO_DEVICE,
  2185. seg_info->frags[0].len);
  2186. for (i = 1; i <= cur_frag; i++) {
  2187. qdf_mem_unmap_page(vdev->osdev, (qdf_dma_addr_t)
  2188. (seg_info->frags[i].paddr_lo | ((uint64_t)
  2189. seg_info->frags[i].paddr_hi) << 32),
  2190. seg_info->frags[i].len,
  2191. QDF_DMA_TO_DEVICE);
  2192. }
  2193. qdf_nbuf_free(nbuf);
  2194. return NULL;
  2195. }
  2196. /**
  2197. * dp_tx_add_tx_sniffer_meta_data()- Add tx_sniffer meta hdr info
  2198. * @vdev: DP vdev handle
  2199. * @msdu_info: MSDU info to be setup in MSDU descriptor and MSDU extension desc.
  2200. * @ppdu_cookie: PPDU cookie that should be replayed in the ppdu completions
  2201. *
  2202. * Return: NULL on failure,
  2203. * nbuf when extracted successfully
  2204. */
  2205. static
  2206. void dp_tx_add_tx_sniffer_meta_data(struct dp_vdev *vdev,
  2207. struct dp_tx_msdu_info_s *msdu_info,
  2208. uint16_t ppdu_cookie)
  2209. {
  2210. struct htt_tx_msdu_desc_ext2_t *meta_data =
  2211. (struct htt_tx_msdu_desc_ext2_t *)&msdu_info->meta_data[0];
  2212. qdf_mem_zero(meta_data, sizeof(struct htt_tx_msdu_desc_ext2_t));
  2213. HTT_TX_MSDU_EXT2_DESC_FLAG_SEND_AS_STANDALONE_SET
  2214. (msdu_info->meta_data[5], 1);
  2215. HTT_TX_MSDU_EXT2_DESC_FLAG_HOST_OPAQUE_VALID_SET
  2216. (msdu_info->meta_data[5], 1);
  2217. HTT_TX_MSDU_EXT2_DESC_HOST_OPAQUE_COOKIE_SET
  2218. (msdu_info->meta_data[6], ppdu_cookie);
  2219. msdu_info->exception_fw = 1;
  2220. msdu_info->is_tx_sniffer = 1;
  2221. }
  2222. #ifdef MESH_MODE_SUPPORT
  2223. /**
  2224. * dp_tx_extract_mesh_meta_data()- Extract mesh meta hdr info from nbuf
  2225. and prepare msdu_info for mesh frames.
  2226. * @vdev: DP vdev handle
  2227. * @nbuf: skb
  2228. * @msdu_info: MSDU info to be setup in MSDU descriptor and MSDU extension desc.
  2229. *
  2230. * Return: NULL on failure,
  2231. * nbuf when extracted successfully
  2232. */
  2233. static
  2234. qdf_nbuf_t dp_tx_extract_mesh_meta_data(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  2235. struct dp_tx_msdu_info_s *msdu_info)
  2236. {
  2237. struct meta_hdr_s *mhdr;
  2238. struct htt_tx_msdu_desc_ext2_t *meta_data =
  2239. (struct htt_tx_msdu_desc_ext2_t *)&msdu_info->meta_data[0];
  2240. mhdr = (struct meta_hdr_s *)qdf_nbuf_data(nbuf);
  2241. if (CB_FTYPE_MESH_TX_INFO != qdf_nbuf_get_tx_ftype(nbuf)) {
  2242. msdu_info->exception_fw = 0;
  2243. goto remove_meta_hdr;
  2244. }
  2245. msdu_info->exception_fw = 1;
  2246. qdf_mem_zero(meta_data, sizeof(struct htt_tx_msdu_desc_ext2_t));
  2247. meta_data->host_tx_desc_pool = 1;
  2248. meta_data->update_peer_cache = 1;
  2249. meta_data->learning_frame = 1;
  2250. if (!(mhdr->flags & METAHDR_FLAG_AUTO_RATE)) {
  2251. meta_data->power = mhdr->power;
  2252. meta_data->mcs_mask = 1 << mhdr->rate_info[0].mcs;
  2253. meta_data->nss_mask = 1 << mhdr->rate_info[0].nss;
  2254. meta_data->pream_type = mhdr->rate_info[0].preamble_type;
  2255. meta_data->retry_limit = mhdr->rate_info[0].max_tries;
  2256. meta_data->dyn_bw = 1;
  2257. meta_data->valid_pwr = 1;
  2258. meta_data->valid_mcs_mask = 1;
  2259. meta_data->valid_nss_mask = 1;
  2260. meta_data->valid_preamble_type = 1;
  2261. meta_data->valid_retries = 1;
  2262. meta_data->valid_bw_info = 1;
  2263. }
  2264. if (mhdr->flags & METAHDR_FLAG_NOENCRYPT) {
  2265. meta_data->encrypt_type = 0;
  2266. meta_data->valid_encrypt_type = 1;
  2267. meta_data->learning_frame = 0;
  2268. }
  2269. meta_data->valid_key_flags = 1;
  2270. meta_data->key_flags = (mhdr->keyix & 0x3);
  2271. remove_meta_hdr:
  2272. if (qdf_nbuf_pull_head(nbuf, sizeof(struct meta_hdr_s)) == NULL) {
  2273. dp_tx_err("qdf_nbuf_pull_head failed");
  2274. qdf_nbuf_free(nbuf);
  2275. return NULL;
  2276. }
  2277. msdu_info->tid = qdf_nbuf_get_priority(nbuf);
  2278. dp_tx_info("Meta hdr %0x %0x %0x %0x %0x %0x"
  2279. " tid %d to_fw %d",
  2280. msdu_info->meta_data[0],
  2281. msdu_info->meta_data[1],
  2282. msdu_info->meta_data[2],
  2283. msdu_info->meta_data[3],
  2284. msdu_info->meta_data[4],
  2285. msdu_info->meta_data[5],
  2286. msdu_info->tid, msdu_info->exception_fw);
  2287. return nbuf;
  2288. }
  2289. #else
  2290. static
  2291. qdf_nbuf_t dp_tx_extract_mesh_meta_data(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  2292. struct dp_tx_msdu_info_s *msdu_info)
  2293. {
  2294. return nbuf;
  2295. }
  2296. #endif
  2297. /**
  2298. * dp_check_exc_metadata() - Checks if parameters are valid
  2299. * @tx_exc - holds all exception path parameters
  2300. *
  2301. * Returns true when all the parameters are valid else false
  2302. *
  2303. */
  2304. static bool dp_check_exc_metadata(struct cdp_tx_exception_metadata *tx_exc)
  2305. {
  2306. bool invalid_tid = (tx_exc->tid > DP_MAX_TIDS && tx_exc->tid !=
  2307. HTT_INVALID_TID);
  2308. bool invalid_encap_type =
  2309. (tx_exc->tx_encap_type > htt_cmn_pkt_num_types &&
  2310. tx_exc->tx_encap_type != CDP_INVALID_TX_ENCAP_TYPE);
  2311. bool invalid_sec_type = (tx_exc->sec_type > cdp_num_sec_types &&
  2312. tx_exc->sec_type != CDP_INVALID_SEC_TYPE);
  2313. bool invalid_cookie = (tx_exc->is_tx_sniffer == 1 &&
  2314. tx_exc->ppdu_cookie == 0);
  2315. if (invalid_tid || invalid_encap_type || invalid_sec_type ||
  2316. invalid_cookie) {
  2317. return false;
  2318. }
  2319. return true;
  2320. }
  2321. #ifdef ATH_SUPPORT_IQUE
  2322. /**
  2323. * dp_tx_mcast_enhance() - Multicast enhancement on TX
  2324. * @vdev: vdev handle
  2325. * @nbuf: skb
  2326. *
  2327. * Return: true on success,
  2328. * false on failure
  2329. */
  2330. static inline bool dp_tx_mcast_enhance(struct dp_vdev *vdev, qdf_nbuf_t nbuf)
  2331. {
  2332. qdf_ether_header_t *eh;
  2333. /* Mcast to Ucast Conversion*/
  2334. if (qdf_likely(!vdev->mcast_enhancement_en))
  2335. return true;
  2336. eh = (qdf_ether_header_t *)qdf_nbuf_data(nbuf);
  2337. if (DP_FRAME_IS_MULTICAST((eh)->ether_dhost) &&
  2338. !DP_FRAME_IS_BROADCAST((eh)->ether_dhost)) {
  2339. dp_verbose_debug("Mcast frm for ME %pK", vdev);
  2340. qdf_nbuf_set_next(nbuf, NULL);
  2341. DP_STATS_INC_PKT(vdev, tx_i.mcast_en.mcast_pkt, 1,
  2342. qdf_nbuf_len(nbuf));
  2343. if (dp_tx_prepare_send_me(vdev, nbuf) ==
  2344. QDF_STATUS_SUCCESS) {
  2345. return false;
  2346. }
  2347. if (qdf_unlikely(vdev->igmp_mcast_enhanc_en > 0)) {
  2348. if (dp_tx_prepare_send_igmp_me(vdev, nbuf) ==
  2349. QDF_STATUS_SUCCESS) {
  2350. return false;
  2351. }
  2352. }
  2353. }
  2354. return true;
  2355. }
  2356. #else
  2357. static inline bool dp_tx_mcast_enhance(struct dp_vdev *vdev, qdf_nbuf_t nbuf)
  2358. {
  2359. return true;
  2360. }
  2361. #endif
  2362. /**
  2363. * dp_tx_per_pkt_vdev_id_check() - vdev id check for frame
  2364. * @nbuf: qdf_nbuf_t
  2365. * @vdev: struct dp_vdev *
  2366. *
  2367. * Allow packet for processing only if it is for peer client which is
  2368. * connected with same vap. Drop packet if client is connected to
  2369. * different vap.
  2370. *
  2371. * Return: QDF_STATUS
  2372. */
  2373. static inline QDF_STATUS
  2374. dp_tx_per_pkt_vdev_id_check(qdf_nbuf_t nbuf, struct dp_vdev *vdev)
  2375. {
  2376. struct dp_ast_entry *dst_ast_entry = NULL;
  2377. qdf_ether_header_t *eh = (qdf_ether_header_t *)qdf_nbuf_data(nbuf);
  2378. if (DP_FRAME_IS_MULTICAST((eh)->ether_dhost) ||
  2379. DP_FRAME_IS_BROADCAST((eh)->ether_dhost))
  2380. return QDF_STATUS_SUCCESS;
  2381. qdf_spin_lock_bh(&vdev->pdev->soc->ast_lock);
  2382. dst_ast_entry = dp_peer_ast_hash_find_by_vdevid(vdev->pdev->soc,
  2383. eh->ether_dhost,
  2384. vdev->vdev_id);
  2385. /* If there is no ast entry, return failure */
  2386. if (qdf_unlikely(!dst_ast_entry)) {
  2387. qdf_spin_unlock_bh(&vdev->pdev->soc->ast_lock);
  2388. return QDF_STATUS_E_FAILURE;
  2389. }
  2390. qdf_spin_unlock_bh(&vdev->pdev->soc->ast_lock);
  2391. return QDF_STATUS_SUCCESS;
  2392. }
  2393. /**
  2394. * dp_tx_send_exception() - Transmit a frame on a given VAP in exception path
  2395. * @soc: DP soc handle
  2396. * @vdev_id: id of DP vdev handle
  2397. * @nbuf: skb
  2398. * @tx_exc_metadata: Handle that holds exception path meta data
  2399. *
  2400. * Entry point for Core Tx layer (DP_TX) invoked from
  2401. * hard_start_xmit in OSIF/HDD to transmit frames through fw
  2402. *
  2403. * Return: NULL on success,
  2404. * nbuf when it fails to send
  2405. */
  2406. qdf_nbuf_t
  2407. dp_tx_send_exception(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  2408. qdf_nbuf_t nbuf,
  2409. struct cdp_tx_exception_metadata *tx_exc_metadata)
  2410. {
  2411. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  2412. qdf_ether_header_t *eh = NULL;
  2413. struct dp_tx_msdu_info_s msdu_info;
  2414. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  2415. DP_MOD_ID_TX_EXCEPTION);
  2416. if (qdf_unlikely(!vdev))
  2417. goto fail;
  2418. qdf_mem_zero(&msdu_info, sizeof(msdu_info));
  2419. if (!tx_exc_metadata)
  2420. goto fail;
  2421. msdu_info.tid = tx_exc_metadata->tid;
  2422. eh = (qdf_ether_header_t *)qdf_nbuf_data(nbuf);
  2423. dp_verbose_debug("skb "QDF_MAC_ADDR_FMT,
  2424. QDF_MAC_ADDR_REF(nbuf->data));
  2425. DP_STATS_INC_PKT(vdev, tx_i.rcvd, 1, qdf_nbuf_len(nbuf));
  2426. if (qdf_unlikely(!dp_check_exc_metadata(tx_exc_metadata))) {
  2427. dp_tx_err("Invalid parameters in exception path");
  2428. goto fail;
  2429. }
  2430. /* Basic sanity checks for unsupported packets */
  2431. /* MESH mode */
  2432. if (qdf_unlikely(vdev->mesh_vdev)) {
  2433. dp_tx_err("Mesh mode is not supported in exception path");
  2434. goto fail;
  2435. }
  2436. /*
  2437. * Classify the frame and call corresponding
  2438. * "prepare" function which extracts the segment (TSO)
  2439. * and fragmentation information (for TSO , SG, ME, or Raw)
  2440. * into MSDU_INFO structure which is later used to fill
  2441. * SW and HW descriptors.
  2442. */
  2443. if (qdf_nbuf_is_tso(nbuf)) {
  2444. dp_verbose_debug("TSO frame %pK", vdev);
  2445. DP_STATS_INC_PKT(vdev->pdev, tso_stats.num_tso_pkts, 1,
  2446. qdf_nbuf_len(nbuf));
  2447. if (dp_tx_prepare_tso(vdev, nbuf, &msdu_info)) {
  2448. DP_STATS_INC_PKT(vdev->pdev, tso_stats.dropped_host, 1,
  2449. qdf_nbuf_len(nbuf));
  2450. goto fail;
  2451. }
  2452. goto send_multiple;
  2453. }
  2454. /* SG */
  2455. if (qdf_unlikely(qdf_nbuf_is_nonlinear(nbuf))) {
  2456. struct dp_tx_seg_info_s seg_info = {0};
  2457. nbuf = dp_tx_prepare_sg(vdev, nbuf, &seg_info, &msdu_info);
  2458. if (!nbuf)
  2459. goto fail;
  2460. dp_verbose_debug("non-TSO SG frame %pK", vdev);
  2461. DP_STATS_INC_PKT(vdev, tx_i.sg.sg_pkt, 1,
  2462. qdf_nbuf_len(nbuf));
  2463. goto send_multiple;
  2464. }
  2465. if (qdf_likely(tx_exc_metadata->is_tx_sniffer)) {
  2466. DP_STATS_INC_PKT(vdev, tx_i.sniffer_rcvd, 1,
  2467. qdf_nbuf_len(nbuf));
  2468. dp_tx_add_tx_sniffer_meta_data(vdev, &msdu_info,
  2469. tx_exc_metadata->ppdu_cookie);
  2470. }
  2471. /*
  2472. * Get HW Queue to use for this frame.
  2473. * TCL supports upto 4 DMA rings, out of which 3 rings are
  2474. * dedicated for data and 1 for command.
  2475. * "queue_id" maps to one hardware ring.
  2476. * With each ring, we also associate a unique Tx descriptor pool
  2477. * to minimize lock contention for these resources.
  2478. */
  2479. dp_tx_get_queue(vdev, nbuf, &msdu_info.tx_queue);
  2480. /*
  2481. * Check exception descriptors
  2482. */
  2483. if (dp_tx_exception_limit_check(vdev))
  2484. goto fail;
  2485. /* Single linear frame */
  2486. /*
  2487. * If nbuf is a simple linear frame, use send_single function to
  2488. * prepare direct-buffer type TCL descriptor and enqueue to TCL
  2489. * SRNG. There is no need to setup a MSDU extension descriptor.
  2490. */
  2491. nbuf = dp_tx_send_msdu_single(vdev, nbuf, &msdu_info,
  2492. tx_exc_metadata->peer_id, tx_exc_metadata);
  2493. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_TX_EXCEPTION);
  2494. return nbuf;
  2495. send_multiple:
  2496. nbuf = dp_tx_send_msdu_multiple(vdev, nbuf, &msdu_info);
  2497. fail:
  2498. if (vdev)
  2499. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_TX_EXCEPTION);
  2500. dp_verbose_debug("pkt send failed");
  2501. return nbuf;
  2502. }
  2503. /**
  2504. * dp_tx_send_exception_vdev_id_check() - Transmit a frame on a given VAP
  2505. * in exception path in special case to avoid regular exception path chk.
  2506. * @soc: DP soc handle
  2507. * @vdev_id: id of DP vdev handle
  2508. * @nbuf: skb
  2509. * @tx_exc_metadata: Handle that holds exception path meta data
  2510. *
  2511. * Entry point for Core Tx layer (DP_TX) invoked from
  2512. * hard_start_xmit in OSIF/HDD to transmit frames through fw
  2513. *
  2514. * Return: NULL on success,
  2515. * nbuf when it fails to send
  2516. */
  2517. qdf_nbuf_t
  2518. dp_tx_send_exception_vdev_id_check(struct cdp_soc_t *soc_hdl,
  2519. uint8_t vdev_id, qdf_nbuf_t nbuf,
  2520. struct cdp_tx_exception_metadata *tx_exc_metadata)
  2521. {
  2522. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  2523. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  2524. DP_MOD_ID_TX_EXCEPTION);
  2525. if (qdf_unlikely(!vdev))
  2526. goto fail;
  2527. if (qdf_unlikely(dp_tx_per_pkt_vdev_id_check(nbuf, vdev)
  2528. == QDF_STATUS_E_FAILURE)) {
  2529. DP_STATS_INC(vdev, tx_i.dropped.fail_per_pkt_vdev_id_check, 1);
  2530. goto fail;
  2531. }
  2532. /* Unref count as it will agin be taken inside dp_tx_exception */
  2533. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_TX_EXCEPTION);
  2534. return dp_tx_send_exception(soc_hdl, vdev_id, nbuf, tx_exc_metadata);
  2535. fail:
  2536. if (vdev)
  2537. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_TX_EXCEPTION);
  2538. dp_verbose_debug("pkt send failed");
  2539. return nbuf;
  2540. }
  2541. /**
  2542. * dp_tx_send_mesh() - Transmit mesh frame on a given VAP
  2543. * @soc: DP soc handle
  2544. * @vdev_id: DP vdev handle
  2545. * @nbuf: skb
  2546. *
  2547. * Entry point for Core Tx layer (DP_TX) invoked from
  2548. * hard_start_xmit in OSIF/HDD
  2549. *
  2550. * Return: NULL on success,
  2551. * nbuf when it fails to send
  2552. */
  2553. #ifdef MESH_MODE_SUPPORT
  2554. qdf_nbuf_t dp_tx_send_mesh(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  2555. qdf_nbuf_t nbuf)
  2556. {
  2557. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  2558. struct meta_hdr_s *mhdr;
  2559. qdf_nbuf_t nbuf_mesh = NULL;
  2560. qdf_nbuf_t nbuf_clone = NULL;
  2561. struct dp_vdev *vdev;
  2562. uint8_t no_enc_frame = 0;
  2563. nbuf_mesh = qdf_nbuf_unshare(nbuf);
  2564. if (!nbuf_mesh) {
  2565. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2566. "qdf_nbuf_unshare failed");
  2567. return nbuf;
  2568. }
  2569. vdev = dp_vdev_get_ref_by_id(soc, vdev_id, DP_MOD_ID_MESH);
  2570. if (!vdev) {
  2571. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2572. "vdev is NULL for vdev_id %d", vdev_id);
  2573. return nbuf;
  2574. }
  2575. nbuf = nbuf_mesh;
  2576. mhdr = (struct meta_hdr_s *)qdf_nbuf_data(nbuf);
  2577. if ((vdev->sec_type != cdp_sec_type_none) &&
  2578. (mhdr->flags & METAHDR_FLAG_NOENCRYPT))
  2579. no_enc_frame = 1;
  2580. if (mhdr->flags & METAHDR_FLAG_NOQOS)
  2581. qdf_nbuf_set_priority(nbuf, HTT_TX_EXT_TID_NON_QOS_MCAST_BCAST);
  2582. if ((mhdr->flags & METAHDR_FLAG_INFO_UPDATED) &&
  2583. !no_enc_frame) {
  2584. nbuf_clone = qdf_nbuf_clone(nbuf);
  2585. if (!nbuf_clone) {
  2586. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2587. "qdf_nbuf_clone failed");
  2588. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_MESH);
  2589. return nbuf;
  2590. }
  2591. qdf_nbuf_set_tx_ftype(nbuf_clone, CB_FTYPE_MESH_TX_INFO);
  2592. }
  2593. if (nbuf_clone) {
  2594. if (!dp_tx_send(soc_hdl, vdev_id, nbuf_clone)) {
  2595. DP_STATS_INC(vdev, tx_i.mesh.exception_fw, 1);
  2596. } else {
  2597. qdf_nbuf_free(nbuf_clone);
  2598. }
  2599. }
  2600. if (no_enc_frame)
  2601. qdf_nbuf_set_tx_ftype(nbuf, CB_FTYPE_MESH_TX_INFO);
  2602. else
  2603. qdf_nbuf_set_tx_ftype(nbuf, CB_FTYPE_INVALID);
  2604. nbuf = dp_tx_send(soc_hdl, vdev_id, nbuf);
  2605. if ((!nbuf) && no_enc_frame) {
  2606. DP_STATS_INC(vdev, tx_i.mesh.exception_fw, 1);
  2607. }
  2608. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_MESH);
  2609. return nbuf;
  2610. }
  2611. #else
  2612. qdf_nbuf_t dp_tx_send_mesh(struct cdp_soc_t *soc, uint8_t vdev_id,
  2613. qdf_nbuf_t nbuf)
  2614. {
  2615. return dp_tx_send(soc, vdev_id, nbuf);
  2616. }
  2617. #endif
  2618. /**
  2619. * dp_tx_nawds_handler() - NAWDS handler
  2620. *
  2621. * @soc: DP soc handle
  2622. * @vdev_id: id of DP vdev handle
  2623. * @msdu_info: msdu_info required to create HTT metadata
  2624. * @nbuf: skb
  2625. *
  2626. * This API transfers the multicast frames with the peer id
  2627. * on NAWDS enabled peer.
  2628. * Return: none
  2629. */
  2630. static inline
  2631. void dp_tx_nawds_handler(struct dp_soc *soc, struct dp_vdev *vdev,
  2632. struct dp_tx_msdu_info_s *msdu_info, qdf_nbuf_t nbuf)
  2633. {
  2634. struct dp_peer *peer = NULL;
  2635. qdf_nbuf_t nbuf_clone = NULL;
  2636. uint16_t peer_id = DP_INVALID_PEER;
  2637. uint16_t sa_peer_id = DP_INVALID_PEER;
  2638. struct dp_ast_entry *ast_entry = NULL;
  2639. qdf_ether_header_t *eh = (qdf_ether_header_t *)qdf_nbuf_data(nbuf);
  2640. qdf_spin_lock_bh(&soc->ast_lock);
  2641. ast_entry = dp_peer_ast_hash_find_by_pdevid
  2642. (soc,
  2643. (uint8_t *)(eh->ether_shost),
  2644. vdev->pdev->pdev_id);
  2645. if (ast_entry)
  2646. sa_peer_id = ast_entry->peer_id;
  2647. qdf_spin_unlock_bh(&soc->ast_lock);
  2648. qdf_spin_lock_bh(&vdev->peer_list_lock);
  2649. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  2650. if (!peer->bss_peer && peer->nawds_enabled) {
  2651. peer_id = peer->peer_id;
  2652. /* Multicast packets needs to be
  2653. * dropped in case of intra bss forwarding
  2654. */
  2655. if (sa_peer_id == peer->peer_id) {
  2656. dp_tx_debug("multicast packet");
  2657. DP_STATS_INC(peer, tx.nawds_mcast_drop, 1);
  2658. continue;
  2659. }
  2660. nbuf_clone = qdf_nbuf_clone(nbuf);
  2661. if (!nbuf_clone) {
  2662. QDF_TRACE(QDF_MODULE_ID_DP,
  2663. QDF_TRACE_LEVEL_ERROR,
  2664. FL("nbuf clone failed"));
  2665. break;
  2666. }
  2667. nbuf_clone = dp_tx_send_msdu_single(vdev, nbuf_clone,
  2668. msdu_info, peer_id,
  2669. NULL);
  2670. if (nbuf_clone) {
  2671. dp_tx_debug("pkt send failed");
  2672. qdf_nbuf_free(nbuf_clone);
  2673. } else {
  2674. if (peer_id != DP_INVALID_PEER)
  2675. DP_STATS_INC_PKT(peer, tx.nawds_mcast,
  2676. 1, qdf_nbuf_len(nbuf));
  2677. }
  2678. }
  2679. }
  2680. qdf_spin_unlock_bh(&vdev->peer_list_lock);
  2681. }
  2682. /**
  2683. * dp_tx_send() - Transmit a frame on a given VAP
  2684. * @soc: DP soc handle
  2685. * @vdev_id: id of DP vdev handle
  2686. * @nbuf: skb
  2687. *
  2688. * Entry point for Core Tx layer (DP_TX) invoked from
  2689. * hard_start_xmit in OSIF/HDD or from dp_rx_process for intravap forwarding
  2690. * cases
  2691. *
  2692. * Return: NULL on success,
  2693. * nbuf when it fails to send
  2694. */
  2695. qdf_nbuf_t dp_tx_send(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  2696. qdf_nbuf_t nbuf)
  2697. {
  2698. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  2699. uint16_t peer_id = HTT_INVALID_PEER;
  2700. /*
  2701. * doing a memzero is causing additional function call overhead
  2702. * so doing static stack clearing
  2703. */
  2704. struct dp_tx_msdu_info_s msdu_info = {0};
  2705. struct dp_vdev *vdev = NULL;
  2706. if (qdf_unlikely(vdev_id >= MAX_VDEV_CNT))
  2707. return nbuf;
  2708. /*
  2709. * dp_vdev_get_ref_by_id does does a atomic operation avoid using
  2710. * this in per packet path.
  2711. *
  2712. * As in this path vdev memory is already protected with netdev
  2713. * tx lock
  2714. */
  2715. vdev = soc->vdev_id_map[vdev_id];
  2716. if (qdf_unlikely(!vdev))
  2717. return nbuf;
  2718. dp_verbose_debug("skb "QDF_MAC_ADDR_FMT,
  2719. QDF_MAC_ADDR_REF(nbuf->data));
  2720. /*
  2721. * Set Default Host TID value to invalid TID
  2722. * (TID override disabled)
  2723. */
  2724. msdu_info.tid = HTT_TX_EXT_TID_INVALID;
  2725. DP_STATS_INC_PKT(vdev, tx_i.rcvd, 1, qdf_nbuf_len(nbuf));
  2726. if (qdf_unlikely(vdev->mesh_vdev)) {
  2727. qdf_nbuf_t nbuf_mesh = dp_tx_extract_mesh_meta_data(vdev, nbuf,
  2728. &msdu_info);
  2729. if (!nbuf_mesh) {
  2730. dp_verbose_debug("Extracting mesh metadata failed");
  2731. return nbuf;
  2732. }
  2733. nbuf = nbuf_mesh;
  2734. }
  2735. /*
  2736. * Get HW Queue to use for this frame.
  2737. * TCL supports upto 4 DMA rings, out of which 3 rings are
  2738. * dedicated for data and 1 for command.
  2739. * "queue_id" maps to one hardware ring.
  2740. * With each ring, we also associate a unique Tx descriptor pool
  2741. * to minimize lock contention for these resources.
  2742. */
  2743. dp_tx_get_queue(vdev, nbuf, &msdu_info.tx_queue);
  2744. /*
  2745. * TCL H/W supports 2 DSCP-TID mapping tables.
  2746. * Table 1 - Default DSCP-TID mapping table
  2747. * Table 2 - 1 DSCP-TID override table
  2748. *
  2749. * If we need a different DSCP-TID mapping for this vap,
  2750. * call tid_classify to extract DSCP/ToS from frame and
  2751. * map to a TID and store in msdu_info. This is later used
  2752. * to fill in TCL Input descriptor (per-packet TID override).
  2753. */
  2754. dp_tx_classify_tid(vdev, nbuf, &msdu_info);
  2755. /*
  2756. * Classify the frame and call corresponding
  2757. * "prepare" function which extracts the segment (TSO)
  2758. * and fragmentation information (for TSO , SG, ME, or Raw)
  2759. * into MSDU_INFO structure which is later used to fill
  2760. * SW and HW descriptors.
  2761. */
  2762. if (qdf_nbuf_is_tso(nbuf)) {
  2763. dp_verbose_debug("TSO frame %pK", vdev);
  2764. DP_STATS_INC_PKT(vdev->pdev, tso_stats.num_tso_pkts, 1,
  2765. qdf_nbuf_len(nbuf));
  2766. if (dp_tx_prepare_tso(vdev, nbuf, &msdu_info)) {
  2767. DP_STATS_INC_PKT(vdev->pdev, tso_stats.dropped_host, 1,
  2768. qdf_nbuf_len(nbuf));
  2769. return nbuf;
  2770. }
  2771. goto send_multiple;
  2772. }
  2773. /* SG */
  2774. if (qdf_unlikely(qdf_nbuf_is_nonlinear(nbuf))) {
  2775. struct dp_tx_seg_info_s seg_info = {0};
  2776. nbuf = dp_tx_prepare_sg(vdev, nbuf, &seg_info, &msdu_info);
  2777. if (!nbuf)
  2778. return NULL;
  2779. dp_verbose_debug("non-TSO SG frame %pK", vdev);
  2780. DP_STATS_INC_PKT(vdev, tx_i.sg.sg_pkt, 1,
  2781. qdf_nbuf_len(nbuf));
  2782. goto send_multiple;
  2783. }
  2784. if (qdf_unlikely(!dp_tx_mcast_enhance(vdev, nbuf)))
  2785. return NULL;
  2786. /* RAW */
  2787. if (qdf_unlikely(vdev->tx_encap_type == htt_cmn_pkt_type_raw)) {
  2788. struct dp_tx_seg_info_s seg_info = {0};
  2789. nbuf = dp_tx_prepare_raw(vdev, nbuf, &seg_info, &msdu_info);
  2790. if (!nbuf)
  2791. return NULL;
  2792. dp_verbose_debug("Raw frame %pK", vdev);
  2793. goto send_multiple;
  2794. }
  2795. if (qdf_unlikely(vdev->nawds_enabled)) {
  2796. qdf_ether_header_t *eh = (qdf_ether_header_t *)
  2797. qdf_nbuf_data(nbuf);
  2798. if (DP_FRAME_IS_MULTICAST((eh)->ether_dhost))
  2799. dp_tx_nawds_handler(soc, vdev, &msdu_info, nbuf);
  2800. peer_id = DP_INVALID_PEER;
  2801. DP_STATS_INC_PKT(vdev, tx_i.nawds_mcast,
  2802. 1, qdf_nbuf_len(nbuf));
  2803. }
  2804. /* Single linear frame */
  2805. /*
  2806. * If nbuf is a simple linear frame, use send_single function to
  2807. * prepare direct-buffer type TCL descriptor and enqueue to TCL
  2808. * SRNG. There is no need to setup a MSDU extension descriptor.
  2809. */
  2810. nbuf = dp_tx_send_msdu_single(vdev, nbuf, &msdu_info, peer_id, NULL);
  2811. return nbuf;
  2812. send_multiple:
  2813. nbuf = dp_tx_send_msdu_multiple(vdev, nbuf, &msdu_info);
  2814. if (qdf_unlikely(nbuf && msdu_info.frm_type == dp_tx_frm_raw))
  2815. dp_tx_raw_prepare_unset(vdev->pdev->soc, nbuf);
  2816. return nbuf;
  2817. }
  2818. /**
  2819. * dp_tx_send_vdev_id_check() - Transmit a frame on a given VAP in special
  2820. * case to vaoid check in perpkt path.
  2821. * @soc: DP soc handle
  2822. * @vdev_id: id of DP vdev handle
  2823. * @nbuf: skb
  2824. *
  2825. * Entry point for Core Tx layer (DP_TX) invoked from
  2826. * hard_start_xmit in OSIF/HDD to transmit packet through dp_tx_send
  2827. * with special condition to avoid per pkt check in dp_tx_send
  2828. *
  2829. * Return: NULL on success,
  2830. * nbuf when it fails to send
  2831. */
  2832. qdf_nbuf_t dp_tx_send_vdev_id_check(struct cdp_soc_t *soc_hdl,
  2833. uint8_t vdev_id, qdf_nbuf_t nbuf)
  2834. {
  2835. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  2836. struct dp_vdev *vdev = NULL;
  2837. if (qdf_unlikely(vdev_id >= MAX_VDEV_CNT))
  2838. return nbuf;
  2839. /*
  2840. * dp_vdev_get_ref_by_id does does a atomic operation avoid using
  2841. * this in per packet path.
  2842. *
  2843. * As in this path vdev memory is already protected with netdev
  2844. * tx lock
  2845. */
  2846. vdev = soc->vdev_id_map[vdev_id];
  2847. if (qdf_unlikely(!vdev))
  2848. return nbuf;
  2849. if (qdf_unlikely(dp_tx_per_pkt_vdev_id_check(nbuf, vdev)
  2850. == QDF_STATUS_E_FAILURE)) {
  2851. DP_STATS_INC(vdev, tx_i.dropped.fail_per_pkt_vdev_id_check, 1);
  2852. return nbuf;
  2853. }
  2854. return dp_tx_send(soc_hdl, vdev_id, nbuf);
  2855. }
  2856. #ifdef UMAC_SUPPORT_PROXY_ARP
  2857. /**
  2858. * dp_tx_proxy_arp() - Tx proxy arp handler
  2859. * @vdev: datapath vdev handle
  2860. * @buf: sk buffer
  2861. *
  2862. * Return: status
  2863. */
  2864. static inline
  2865. int dp_tx_proxy_arp(struct dp_vdev *vdev, qdf_nbuf_t nbuf)
  2866. {
  2867. if (vdev->osif_proxy_arp)
  2868. return vdev->osif_proxy_arp(vdev->osif_vdev, nbuf);
  2869. /*
  2870. * when UMAC_SUPPORT_PROXY_ARP is defined, we expect
  2871. * osif_proxy_arp has a valid function pointer assigned
  2872. * to it
  2873. */
  2874. dp_tx_err("valid function pointer for osif_proxy_arp is expected!!\n");
  2875. return QDF_STATUS_NOT_INITIALIZED;
  2876. }
  2877. #else
  2878. /**
  2879. * dp_tx_proxy_arp() - Tx proxy arp handler
  2880. * @vdev: datapath vdev handle
  2881. * @buf: sk buffer
  2882. *
  2883. * This function always return 0 when UMAC_SUPPORT_PROXY_ARP
  2884. * is not defined.
  2885. *
  2886. * Return: status
  2887. */
  2888. static inline
  2889. int dp_tx_proxy_arp(struct dp_vdev *vdev, qdf_nbuf_t nbuf)
  2890. {
  2891. return QDF_STATUS_SUCCESS;
  2892. }
  2893. #endif
  2894. /**
  2895. * dp_tx_reinject_handler() - Tx Reinject Handler
  2896. * @soc: datapath soc handle
  2897. * @vdev: datapath vdev handle
  2898. * @tx_desc: software descriptor head pointer
  2899. * @status : Tx completion status from HTT descriptor
  2900. *
  2901. * This function reinjects frames back to Target.
  2902. * Todo - Host queue needs to be added
  2903. *
  2904. * Return: none
  2905. */
  2906. static
  2907. void dp_tx_reinject_handler(struct dp_soc *soc,
  2908. struct dp_vdev *vdev,
  2909. struct dp_tx_desc_s *tx_desc,
  2910. uint8_t *status)
  2911. {
  2912. struct dp_peer *peer = NULL;
  2913. uint32_t peer_id = HTT_INVALID_PEER;
  2914. qdf_nbuf_t nbuf = tx_desc->nbuf;
  2915. qdf_nbuf_t nbuf_copy = NULL;
  2916. struct dp_tx_msdu_info_s msdu_info;
  2917. #ifdef WDS_VENDOR_EXTENSION
  2918. int is_mcast = 0, is_ucast = 0;
  2919. int num_peers_3addr = 0;
  2920. qdf_ether_header_t *eth_hdr = (qdf_ether_header_t *)(qdf_nbuf_data(nbuf));
  2921. struct ieee80211_frame_addr4 *wh = (struct ieee80211_frame_addr4 *)(qdf_nbuf_data(nbuf));
  2922. #endif
  2923. qdf_assert(vdev);
  2924. qdf_mem_zero(&msdu_info, sizeof(msdu_info));
  2925. dp_tx_get_queue(vdev, nbuf, &msdu_info.tx_queue);
  2926. dp_tx_debug("Tx reinject path");
  2927. DP_STATS_INC_PKT(vdev, tx_i.reinject_pkts, 1,
  2928. qdf_nbuf_len(tx_desc->nbuf));
  2929. #ifdef WDS_VENDOR_EXTENSION
  2930. if (qdf_unlikely(vdev->tx_encap_type != htt_cmn_pkt_type_raw)) {
  2931. is_mcast = (IS_MULTICAST(wh->i_addr1)) ? 1 : 0;
  2932. } else {
  2933. is_mcast = (IS_MULTICAST(eth_hdr->ether_dhost)) ? 1 : 0;
  2934. }
  2935. is_ucast = !is_mcast;
  2936. qdf_spin_lock_bh(&vdev->peer_list_lock);
  2937. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  2938. if (peer->bss_peer)
  2939. continue;
  2940. /* Detect wds peers that use 3-addr framing for mcast.
  2941. * if there are any, the bss_peer is used to send the
  2942. * the mcast frame using 3-addr format. all wds enabled
  2943. * peers that use 4-addr framing for mcast frames will
  2944. * be duplicated and sent as 4-addr frames below.
  2945. */
  2946. if (!peer->wds_enabled || !peer->wds_ecm.wds_tx_mcast_4addr) {
  2947. num_peers_3addr = 1;
  2948. break;
  2949. }
  2950. }
  2951. qdf_spin_unlock_bh(&vdev->peer_list_lock);
  2952. #endif
  2953. if (qdf_unlikely(vdev->mesh_vdev)) {
  2954. DP_TX_FREE_SINGLE_BUF(vdev->pdev->soc, tx_desc->nbuf);
  2955. } else {
  2956. qdf_spin_lock_bh(&vdev->peer_list_lock);
  2957. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  2958. if ((peer->peer_id != HTT_INVALID_PEER) &&
  2959. #ifdef WDS_VENDOR_EXTENSION
  2960. /*
  2961. * . if 3-addr STA, then send on BSS Peer
  2962. * . if Peer WDS enabled and accept 4-addr mcast,
  2963. * send mcast on that peer only
  2964. * . if Peer WDS enabled and accept 4-addr ucast,
  2965. * send ucast on that peer only
  2966. */
  2967. ((peer->bss_peer && num_peers_3addr && is_mcast) ||
  2968. (peer->wds_enabled &&
  2969. ((is_mcast && peer->wds_ecm.wds_tx_mcast_4addr) ||
  2970. (is_ucast && peer->wds_ecm.wds_tx_ucast_4addr))))) {
  2971. #else
  2972. (peer->bss_peer &&
  2973. (dp_tx_proxy_arp(vdev, nbuf) == QDF_STATUS_SUCCESS))) {
  2974. #endif
  2975. peer_id = DP_INVALID_PEER;
  2976. nbuf_copy = qdf_nbuf_copy(nbuf);
  2977. if (!nbuf_copy) {
  2978. dp_tx_debug("nbuf copy failed");
  2979. break;
  2980. }
  2981. nbuf_copy = dp_tx_send_msdu_single(vdev,
  2982. nbuf_copy,
  2983. &msdu_info,
  2984. peer_id,
  2985. NULL);
  2986. if (nbuf_copy) {
  2987. dp_tx_debug("pkt send failed");
  2988. qdf_nbuf_free(nbuf_copy);
  2989. }
  2990. }
  2991. }
  2992. qdf_spin_unlock_bh(&vdev->peer_list_lock);
  2993. }
  2994. qdf_nbuf_free(nbuf);
  2995. dp_tx_desc_release(tx_desc, tx_desc->pool_id);
  2996. }
  2997. /**
  2998. * dp_tx_inspect_handler() - Tx Inspect Handler
  2999. * @soc: datapath soc handle
  3000. * @vdev: datapath vdev handle
  3001. * @tx_desc: software descriptor head pointer
  3002. * @status : Tx completion status from HTT descriptor
  3003. *
  3004. * Handles Tx frames sent back to Host for inspection
  3005. * (ProxyARP)
  3006. *
  3007. * Return: none
  3008. */
  3009. static void dp_tx_inspect_handler(struct dp_soc *soc,
  3010. struct dp_vdev *vdev,
  3011. struct dp_tx_desc_s *tx_desc,
  3012. uint8_t *status)
  3013. {
  3014. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  3015. "%s Tx inspect path",
  3016. __func__);
  3017. DP_STATS_INC_PKT(vdev, tx_i.inspect_pkts, 1,
  3018. qdf_nbuf_len(tx_desc->nbuf));
  3019. DP_TX_FREE_SINGLE_BUF(soc, tx_desc->nbuf);
  3020. dp_tx_desc_release(tx_desc, tx_desc->pool_id);
  3021. }
  3022. #ifdef MESH_MODE_SUPPORT
  3023. /**
  3024. * dp_tx_comp_fill_tx_completion_stats() - Fill per packet Tx completion stats
  3025. * in mesh meta header
  3026. * @tx_desc: software descriptor head pointer
  3027. * @ts: pointer to tx completion stats
  3028. * Return: none
  3029. */
  3030. static
  3031. void dp_tx_comp_fill_tx_completion_stats(struct dp_tx_desc_s *tx_desc,
  3032. struct hal_tx_completion_status *ts)
  3033. {
  3034. struct meta_hdr_s *mhdr;
  3035. qdf_nbuf_t netbuf = tx_desc->nbuf;
  3036. if (!tx_desc->msdu_ext_desc) {
  3037. if (qdf_nbuf_pull_head(netbuf, tx_desc->pkt_offset) == NULL) {
  3038. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3039. "netbuf %pK offset %d",
  3040. netbuf, tx_desc->pkt_offset);
  3041. return;
  3042. }
  3043. }
  3044. if (qdf_nbuf_push_head(netbuf, sizeof(struct meta_hdr_s)) == NULL) {
  3045. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3046. "netbuf %pK offset %zu", netbuf,
  3047. sizeof(struct meta_hdr_s));
  3048. return;
  3049. }
  3050. mhdr = (struct meta_hdr_s *)qdf_nbuf_data(netbuf);
  3051. mhdr->rssi = ts->ack_frame_rssi;
  3052. mhdr->band = tx_desc->pdev->operating_channel.band;
  3053. mhdr->channel = tx_desc->pdev->operating_channel.num;
  3054. }
  3055. #else
  3056. static
  3057. void dp_tx_comp_fill_tx_completion_stats(struct dp_tx_desc_s *tx_desc,
  3058. struct hal_tx_completion_status *ts)
  3059. {
  3060. }
  3061. #endif
  3062. #ifdef QCA_PEER_EXT_STATS
  3063. /*
  3064. * dp_tx_compute_tid_delay() - Compute per TID delay
  3065. * @stats: Per TID delay stats
  3066. * @tx_desc: Software Tx descriptor
  3067. *
  3068. * Compute the software enqueue and hw enqueue delays and
  3069. * update the respective histograms
  3070. *
  3071. * Return: void
  3072. */
  3073. static void dp_tx_compute_tid_delay(struct cdp_delay_tid_stats *stats,
  3074. struct dp_tx_desc_s *tx_desc)
  3075. {
  3076. struct cdp_delay_tx_stats *tx_delay = &stats->tx_delay;
  3077. int64_t current_timestamp, timestamp_ingress, timestamp_hw_enqueue;
  3078. uint32_t sw_enqueue_delay, fwhw_transmit_delay;
  3079. current_timestamp = qdf_ktime_to_ms(qdf_ktime_real_get());
  3080. timestamp_ingress = qdf_nbuf_get_timestamp(tx_desc->nbuf);
  3081. timestamp_hw_enqueue = tx_desc->timestamp;
  3082. sw_enqueue_delay = (uint32_t)(timestamp_hw_enqueue - timestamp_ingress);
  3083. fwhw_transmit_delay = (uint32_t)(current_timestamp -
  3084. timestamp_hw_enqueue);
  3085. /*
  3086. * Update the Tx software enqueue delay and HW enque-Completion delay.
  3087. */
  3088. dp_hist_update_stats(&tx_delay->tx_swq_delay, sw_enqueue_delay);
  3089. dp_hist_update_stats(&tx_delay->hwtx_delay, fwhw_transmit_delay);
  3090. }
  3091. /*
  3092. * dp_tx_update_peer_ext_stats() - Update the peer extended stats
  3093. * @peer: DP peer context
  3094. * @tx_desc: Tx software descriptor
  3095. * @tid: Transmission ID
  3096. * @ring_id: Rx CPU context ID/CPU_ID
  3097. *
  3098. * Update the peer extended stats. These are enhanced other
  3099. * delay stats per msdu level.
  3100. *
  3101. * Return: void
  3102. */
  3103. static void dp_tx_update_peer_ext_stats(struct dp_peer *peer,
  3104. struct dp_tx_desc_s *tx_desc,
  3105. uint8_t tid, uint8_t ring_id)
  3106. {
  3107. struct dp_pdev *pdev = peer->vdev->pdev;
  3108. struct dp_soc *soc = NULL;
  3109. struct cdp_peer_ext_stats *pext_stats = NULL;
  3110. soc = pdev->soc;
  3111. if (qdf_likely(!wlan_cfg_is_peer_ext_stats_enabled(soc->wlan_cfg_ctx)))
  3112. return;
  3113. pext_stats = peer->pext_stats;
  3114. qdf_assert(pext_stats);
  3115. qdf_assert(ring < CDP_MAX_TXRX_CTX);
  3116. /*
  3117. * For non-TID packets use the TID 9
  3118. */
  3119. if (qdf_unlikely(tid >= CDP_MAX_DATA_TIDS))
  3120. tid = CDP_MAX_DATA_TIDS - 1;
  3121. dp_tx_compute_tid_delay(&pext_stats->delay_stats[tid][ring_id],
  3122. tx_desc);
  3123. }
  3124. #else
  3125. static inline void dp_tx_update_peer_ext_stats(struct dp_peer *peer,
  3126. struct dp_tx_desc_s *tx_desc,
  3127. uint8_t tid, uint8_t ring_id)
  3128. {
  3129. }
  3130. #endif
  3131. /**
  3132. * dp_tx_compute_delay() - Compute and fill in all timestamps
  3133. * to pass in correct fields
  3134. *
  3135. * @vdev: pdev handle
  3136. * @tx_desc: tx descriptor
  3137. * @tid: tid value
  3138. * @ring_id: TCL or WBM ring number for transmit path
  3139. * Return: none
  3140. */
  3141. static void dp_tx_compute_delay(struct dp_vdev *vdev,
  3142. struct dp_tx_desc_s *tx_desc,
  3143. uint8_t tid, uint8_t ring_id)
  3144. {
  3145. int64_t current_timestamp, timestamp_ingress, timestamp_hw_enqueue;
  3146. uint32_t sw_enqueue_delay, fwhw_transmit_delay, interframe_delay;
  3147. if (qdf_likely(!vdev->pdev->delay_stats_flag))
  3148. return;
  3149. current_timestamp = qdf_ktime_to_ms(qdf_ktime_real_get());
  3150. timestamp_ingress = qdf_nbuf_get_timestamp(tx_desc->nbuf);
  3151. timestamp_hw_enqueue = tx_desc->timestamp;
  3152. sw_enqueue_delay = (uint32_t)(timestamp_hw_enqueue - timestamp_ingress);
  3153. fwhw_transmit_delay = (uint32_t)(current_timestamp -
  3154. timestamp_hw_enqueue);
  3155. interframe_delay = (uint32_t)(timestamp_ingress -
  3156. vdev->prev_tx_enq_tstamp);
  3157. /*
  3158. * Delay in software enqueue
  3159. */
  3160. dp_update_delay_stats(vdev->pdev, sw_enqueue_delay, tid,
  3161. CDP_DELAY_STATS_SW_ENQ, ring_id);
  3162. /*
  3163. * Delay between packet enqueued to HW and Tx completion
  3164. */
  3165. dp_update_delay_stats(vdev->pdev, fwhw_transmit_delay, tid,
  3166. CDP_DELAY_STATS_FW_HW_TRANSMIT, ring_id);
  3167. /*
  3168. * Update interframe delay stats calculated at hardstart receive point.
  3169. * Value of vdev->prev_tx_enq_tstamp will be 0 for 1st frame, so
  3170. * interframe delay will not be calculate correctly for 1st frame.
  3171. * On the other side, this will help in avoiding extra per packet check
  3172. * of !vdev->prev_tx_enq_tstamp.
  3173. */
  3174. dp_update_delay_stats(vdev->pdev, interframe_delay, tid,
  3175. CDP_DELAY_STATS_TX_INTERFRAME, ring_id);
  3176. vdev->prev_tx_enq_tstamp = timestamp_ingress;
  3177. }
  3178. #ifdef DISABLE_DP_STATS
  3179. static
  3180. inline void dp_update_no_ack_stats(qdf_nbuf_t nbuf, struct dp_peer *peer)
  3181. {
  3182. }
  3183. #else
  3184. static
  3185. inline void dp_update_no_ack_stats(qdf_nbuf_t nbuf, struct dp_peer *peer)
  3186. {
  3187. enum qdf_proto_subtype subtype = QDF_PROTO_INVALID;
  3188. DPTRACE(qdf_dp_track_noack_check(nbuf, &subtype));
  3189. if (subtype != QDF_PROTO_INVALID)
  3190. DP_STATS_INC(peer, tx.no_ack_count[subtype], 1);
  3191. }
  3192. #endif
  3193. /**
  3194. * dp_tx_update_peer_stats() - Update peer stats from Tx completion indications
  3195. * per wbm ring
  3196. *
  3197. * @tx_desc: software descriptor head pointer
  3198. * @ts: Tx completion status
  3199. * @peer: peer handle
  3200. * @ring_id: ring number
  3201. *
  3202. * Return: None
  3203. */
  3204. static inline void
  3205. dp_tx_update_peer_stats(struct dp_tx_desc_s *tx_desc,
  3206. struct hal_tx_completion_status *ts,
  3207. struct dp_peer *peer, uint8_t ring_id)
  3208. {
  3209. struct dp_pdev *pdev = peer->vdev->pdev;
  3210. struct dp_soc *soc = NULL;
  3211. uint8_t mcs, pkt_type;
  3212. uint8_t tid = ts->tid;
  3213. uint32_t length;
  3214. struct cdp_tid_tx_stats *tid_stats;
  3215. if (!pdev)
  3216. return;
  3217. if (qdf_unlikely(tid >= CDP_MAX_DATA_TIDS))
  3218. tid = CDP_MAX_DATA_TIDS - 1;
  3219. tid_stats = &pdev->stats.tid_stats.tid_tx_stats[ring_id][tid];
  3220. soc = pdev->soc;
  3221. mcs = ts->mcs;
  3222. pkt_type = ts->pkt_type;
  3223. if (ts->release_src != HAL_TX_COMP_RELEASE_SOURCE_TQM) {
  3224. dp_err("Release source is not from TQM");
  3225. return;
  3226. }
  3227. length = qdf_nbuf_len(tx_desc->nbuf);
  3228. DP_STATS_INC_PKT(peer, tx.comp_pkt, 1, length);
  3229. if (qdf_unlikely(pdev->delay_stats_flag))
  3230. dp_tx_compute_delay(peer->vdev, tx_desc, tid, ring_id);
  3231. DP_STATS_INCC(peer, tx.dropped.age_out, 1,
  3232. (ts->status == HAL_TX_TQM_RR_REM_CMD_AGED));
  3233. DP_STATS_INCC_PKT(peer, tx.dropped.fw_rem, 1, length,
  3234. (ts->status == HAL_TX_TQM_RR_REM_CMD_REM));
  3235. DP_STATS_INCC(peer, tx.dropped.fw_rem_notx, 1,
  3236. (ts->status == HAL_TX_TQM_RR_REM_CMD_NOTX));
  3237. DP_STATS_INCC(peer, tx.dropped.fw_rem_tx, 1,
  3238. (ts->status == HAL_TX_TQM_RR_REM_CMD_TX));
  3239. DP_STATS_INCC(peer, tx.dropped.fw_reason1, 1,
  3240. (ts->status == HAL_TX_TQM_RR_FW_REASON1));
  3241. DP_STATS_INCC(peer, tx.dropped.fw_reason2, 1,
  3242. (ts->status == HAL_TX_TQM_RR_FW_REASON2));
  3243. DP_STATS_INCC(peer, tx.dropped.fw_reason3, 1,
  3244. (ts->status == HAL_TX_TQM_RR_FW_REASON3));
  3245. /*
  3246. * tx_failed is ideally supposed to be updated from HTT ppdu completion
  3247. * stats. But in IPQ807X/IPQ6018 chipsets owing to hw limitation there
  3248. * are no completions for failed cases. Hence updating tx_failed from
  3249. * data path. Please note that if tx_failed is fixed to be from ppdu,
  3250. * then this has to be removed
  3251. */
  3252. peer->stats.tx.tx_failed = peer->stats.tx.dropped.fw_rem.num +
  3253. peer->stats.tx.dropped.fw_rem_notx +
  3254. peer->stats.tx.dropped.fw_rem_tx +
  3255. peer->stats.tx.dropped.age_out +
  3256. peer->stats.tx.dropped.fw_reason1 +
  3257. peer->stats.tx.dropped.fw_reason2 +
  3258. peer->stats.tx.dropped.fw_reason3;
  3259. if (ts->status < CDP_MAX_TX_TQM_STATUS) {
  3260. tid_stats->tqm_status_cnt[ts->status]++;
  3261. }
  3262. if (ts->status != HAL_TX_TQM_RR_FRAME_ACKED) {
  3263. dp_update_no_ack_stats(tx_desc->nbuf, peer);
  3264. return;
  3265. }
  3266. DP_STATS_INCC(peer, tx.ofdma, 1, ts->ofdma);
  3267. DP_STATS_INCC(peer, tx.amsdu_cnt, 1, ts->msdu_part_of_amsdu);
  3268. DP_STATS_INCC(peer, tx.non_amsdu_cnt, 1, !ts->msdu_part_of_amsdu);
  3269. /*
  3270. * Following Rate Statistics are updated from HTT PPDU events from FW.
  3271. * Return from here if HTT PPDU events are enabled.
  3272. */
  3273. if (!(soc->process_tx_status))
  3274. return;
  3275. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  3276. ((mcs >= MAX_MCS_11A) && (pkt_type == DOT11_A)));
  3277. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[mcs], 1,
  3278. ((mcs < (MAX_MCS_11A)) && (pkt_type == DOT11_A)));
  3279. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  3280. ((mcs >= MAX_MCS_11B) && (pkt_type == DOT11_B)));
  3281. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[mcs], 1,
  3282. ((mcs < MAX_MCS_11B) && (pkt_type == DOT11_B)));
  3283. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  3284. ((mcs >= MAX_MCS_11A) && (pkt_type == DOT11_N)));
  3285. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[mcs], 1,
  3286. ((mcs < MAX_MCS_11A) && (pkt_type == DOT11_N)));
  3287. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  3288. ((mcs >= MAX_MCS_11AC) && (pkt_type == DOT11_AC)));
  3289. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[mcs], 1,
  3290. ((mcs < MAX_MCS_11AC) && (pkt_type == DOT11_AC)));
  3291. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[MAX_MCS - 1], 1,
  3292. ((mcs >= (MAX_MCS - 1)) && (pkt_type == DOT11_AX)));
  3293. DP_STATS_INCC(peer, tx.pkt_type[pkt_type].mcs_count[mcs], 1,
  3294. ((mcs < (MAX_MCS - 1)) && (pkt_type == DOT11_AX)));
  3295. DP_STATS_INC(peer, tx.sgi_count[ts->sgi], 1);
  3296. DP_STATS_INC(peer, tx.bw[ts->bw], 1);
  3297. DP_STATS_UPD(peer, tx.last_ack_rssi, ts->ack_frame_rssi);
  3298. DP_STATS_INC(peer, tx.wme_ac_type[TID_TO_WME_AC(ts->tid)], 1);
  3299. DP_STATS_INCC(peer, tx.stbc, 1, ts->stbc);
  3300. DP_STATS_INCC(peer, tx.ldpc, 1, ts->ldpc);
  3301. DP_STATS_INCC(peer, tx.retries, 1, ts->transmit_cnt > 1);
  3302. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  3303. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, pdev->soc,
  3304. &peer->stats, ts->peer_id,
  3305. UPDATE_PEER_STATS, pdev->pdev_id);
  3306. #endif
  3307. }
  3308. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  3309. /**
  3310. * dp_tx_flow_pool_lock() - take flow pool lock
  3311. * @soc: core txrx main context
  3312. * @tx_desc: tx desc
  3313. *
  3314. * Return: None
  3315. */
  3316. static inline
  3317. void dp_tx_flow_pool_lock(struct dp_soc *soc,
  3318. struct dp_tx_desc_s *tx_desc)
  3319. {
  3320. struct dp_tx_desc_pool_s *pool;
  3321. uint8_t desc_pool_id;
  3322. desc_pool_id = tx_desc->pool_id;
  3323. pool = &soc->tx_desc[desc_pool_id];
  3324. qdf_spin_lock_bh(&pool->flow_pool_lock);
  3325. }
  3326. /**
  3327. * dp_tx_flow_pool_unlock() - release flow pool lock
  3328. * @soc: core txrx main context
  3329. * @tx_desc: tx desc
  3330. *
  3331. * Return: None
  3332. */
  3333. static inline
  3334. void dp_tx_flow_pool_unlock(struct dp_soc *soc,
  3335. struct dp_tx_desc_s *tx_desc)
  3336. {
  3337. struct dp_tx_desc_pool_s *pool;
  3338. uint8_t desc_pool_id;
  3339. desc_pool_id = tx_desc->pool_id;
  3340. pool = &soc->tx_desc[desc_pool_id];
  3341. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  3342. }
  3343. #else
  3344. static inline
  3345. void dp_tx_flow_pool_lock(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc)
  3346. {
  3347. }
  3348. static inline
  3349. void dp_tx_flow_pool_unlock(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc)
  3350. {
  3351. }
  3352. #endif
  3353. /**
  3354. * dp_tx_notify_completion() - Notify tx completion for this desc
  3355. * @soc: core txrx main context
  3356. * @vdev: datapath vdev handle
  3357. * @tx_desc: tx desc
  3358. * @netbuf: buffer
  3359. * @status: tx status
  3360. *
  3361. * Return: none
  3362. */
  3363. static inline void dp_tx_notify_completion(struct dp_soc *soc,
  3364. struct dp_vdev *vdev,
  3365. struct dp_tx_desc_s *tx_desc,
  3366. qdf_nbuf_t netbuf,
  3367. uint8_t status)
  3368. {
  3369. void *osif_dev;
  3370. ol_txrx_completion_fp tx_compl_cbk = NULL;
  3371. uint16_t flag = BIT(QDF_TX_RX_STATUS_DOWNLOAD_SUCC);
  3372. qdf_assert(tx_desc);
  3373. dp_tx_flow_pool_lock(soc, tx_desc);
  3374. if (!vdev ||
  3375. !vdev->osif_vdev) {
  3376. dp_tx_flow_pool_unlock(soc, tx_desc);
  3377. return;
  3378. }
  3379. osif_dev = vdev->osif_vdev;
  3380. tx_compl_cbk = vdev->tx_comp;
  3381. dp_tx_flow_pool_unlock(soc, tx_desc);
  3382. if (status == HAL_TX_TQM_RR_FRAME_ACKED)
  3383. flag |= BIT(QDF_TX_RX_STATUS_OK);
  3384. if (tx_compl_cbk)
  3385. tx_compl_cbk(netbuf, osif_dev, flag);
  3386. }
  3387. /** dp_tx_sojourn_stats_process() - Collect sojourn stats
  3388. * @pdev: pdev handle
  3389. * @tid: tid value
  3390. * @txdesc_ts: timestamp from txdesc
  3391. * @ppdu_id: ppdu id
  3392. *
  3393. * Return: none
  3394. */
  3395. #ifdef FEATURE_PERPKT_INFO
  3396. static inline void dp_tx_sojourn_stats_process(struct dp_pdev *pdev,
  3397. struct dp_peer *peer,
  3398. uint8_t tid,
  3399. uint64_t txdesc_ts,
  3400. uint32_t ppdu_id)
  3401. {
  3402. uint64_t delta_ms;
  3403. struct cdp_tx_sojourn_stats *sojourn_stats;
  3404. if (qdf_unlikely(pdev->enhanced_stats_en == 0))
  3405. return;
  3406. if (qdf_unlikely(tid == HTT_INVALID_TID ||
  3407. tid >= CDP_DATA_TID_MAX))
  3408. return;
  3409. if (qdf_unlikely(!pdev->sojourn_buf))
  3410. return;
  3411. sojourn_stats = (struct cdp_tx_sojourn_stats *)
  3412. qdf_nbuf_data(pdev->sojourn_buf);
  3413. sojourn_stats->cookie = (void *)peer->rdkstats_ctx;
  3414. delta_ms = qdf_ktime_to_ms(qdf_ktime_get()) -
  3415. txdesc_ts;
  3416. qdf_ewma_tx_lag_add(&peer->avg_sojourn_msdu[tid],
  3417. delta_ms);
  3418. sojourn_stats->sum_sojourn_msdu[tid] = delta_ms;
  3419. sojourn_stats->num_msdus[tid] = 1;
  3420. sojourn_stats->avg_sojourn_msdu[tid].internal =
  3421. peer->avg_sojourn_msdu[tid].internal;
  3422. dp_wdi_event_handler(WDI_EVENT_TX_SOJOURN_STAT, pdev->soc,
  3423. pdev->sojourn_buf, HTT_INVALID_PEER,
  3424. WDI_NO_VAL, pdev->pdev_id);
  3425. sojourn_stats->sum_sojourn_msdu[tid] = 0;
  3426. sojourn_stats->num_msdus[tid] = 0;
  3427. sojourn_stats->avg_sojourn_msdu[tid].internal = 0;
  3428. }
  3429. #else
  3430. static inline void dp_tx_sojourn_stats_process(struct dp_pdev *pdev,
  3431. struct dp_peer *peer,
  3432. uint8_t tid,
  3433. uint64_t txdesc_ts,
  3434. uint32_t ppdu_id)
  3435. {
  3436. }
  3437. #endif
  3438. #ifdef WLAN_FEATURE_PKT_CAPTURE_V2
  3439. /**
  3440. * dp_send_completion_to_pkt_capture() - send tx completion to packet capture
  3441. * @soc: dp_soc handle
  3442. * @desc: Tx Descriptor
  3443. * @ts: HAL Tx completion descriptor contents
  3444. *
  3445. * This function is used to send tx completion to packet capture
  3446. */
  3447. void dp_send_completion_to_pkt_capture(struct dp_soc *soc,
  3448. struct dp_tx_desc_s *desc,
  3449. struct hal_tx_completion_status *ts)
  3450. {
  3451. dp_wdi_event_handler(WDI_EVENT_PKT_CAPTURE_TX_DATA, soc,
  3452. desc, ts->peer_id,
  3453. WDI_NO_VAL, desc->pdev->pdev_id);
  3454. }
  3455. #endif
  3456. /**
  3457. * dp_tx_comp_process_desc() - Process tx descriptor and free associated nbuf
  3458. * @soc: DP Soc handle
  3459. * @tx_desc: software Tx descriptor
  3460. * @ts : Tx completion status from HAL/HTT descriptor
  3461. *
  3462. * Return: none
  3463. */
  3464. static inline void
  3465. dp_tx_comp_process_desc(struct dp_soc *soc,
  3466. struct dp_tx_desc_s *desc,
  3467. struct hal_tx_completion_status *ts,
  3468. struct dp_peer *peer)
  3469. {
  3470. uint64_t time_latency = 0;
  3471. /*
  3472. * m_copy/tx_capture modes are not supported for
  3473. * scatter gather packets
  3474. */
  3475. if (qdf_unlikely(!!desc->pdev->latency_capture_enable)) {
  3476. time_latency = (qdf_ktime_to_ms(qdf_ktime_real_get()) -
  3477. desc->timestamp);
  3478. }
  3479. dp_send_completion_to_pkt_capture(soc, desc, ts);
  3480. if (!(desc->msdu_ext_desc)) {
  3481. dp_tx_enh_unmap(soc, desc);
  3482. if (QDF_STATUS_SUCCESS ==
  3483. dp_tx_add_to_comp_queue(soc, desc, ts, peer)) {
  3484. return;
  3485. }
  3486. if (QDF_STATUS_SUCCESS ==
  3487. dp_get_completion_indication_for_stack(soc,
  3488. desc->pdev,
  3489. peer, ts,
  3490. desc->nbuf,
  3491. time_latency)) {
  3492. dp_send_completion_to_stack(soc,
  3493. desc->pdev,
  3494. ts->peer_id,
  3495. ts->ppdu_id,
  3496. desc->nbuf);
  3497. return;
  3498. }
  3499. }
  3500. dp_tx_comp_free_buf(soc, desc);
  3501. }
  3502. #ifdef DISABLE_DP_STATS
  3503. /**
  3504. * dp_tx_update_connectivity_stats() - update tx connectivity stats
  3505. * @soc: core txrx main context
  3506. * @tx_desc: tx desc
  3507. * @status: tx status
  3508. *
  3509. * Return: none
  3510. */
  3511. static inline
  3512. void dp_tx_update_connectivity_stats(struct dp_soc *soc,
  3513. struct dp_vdev *vdev,
  3514. struct dp_tx_desc_s *tx_desc,
  3515. uint8_t status)
  3516. {
  3517. }
  3518. #else
  3519. static inline
  3520. void dp_tx_update_connectivity_stats(struct dp_soc *soc,
  3521. struct dp_vdev *vdev,
  3522. struct dp_tx_desc_s *tx_desc,
  3523. uint8_t status)
  3524. {
  3525. void *osif_dev;
  3526. ol_txrx_stats_rx_fp stats_cbk;
  3527. uint8_t pkt_type;
  3528. qdf_assert(tx_desc);
  3529. if (!vdev ||
  3530. !vdev->osif_vdev ||
  3531. !vdev->stats_cb)
  3532. return;
  3533. osif_dev = vdev->osif_vdev;
  3534. stats_cbk = vdev->stats_cb;
  3535. stats_cbk(tx_desc->nbuf, osif_dev, PKT_TYPE_TX_HOST_FW_SENT, &pkt_type);
  3536. if (status == HAL_TX_TQM_RR_FRAME_ACKED)
  3537. stats_cbk(tx_desc->nbuf, osif_dev, PKT_TYPE_TX_ACK_CNT,
  3538. &pkt_type);
  3539. }
  3540. #endif
  3541. /**
  3542. * dp_tx_comp_process_tx_status() - Parse and Dump Tx completion status info
  3543. * @soc: DP soc handle
  3544. * @tx_desc: software descriptor head pointer
  3545. * @ts: Tx completion status
  3546. * @peer: peer handle
  3547. * @ring_id: ring number
  3548. *
  3549. * Return: none
  3550. */
  3551. static inline
  3552. void dp_tx_comp_process_tx_status(struct dp_soc *soc,
  3553. struct dp_tx_desc_s *tx_desc,
  3554. struct hal_tx_completion_status *ts,
  3555. struct dp_peer *peer, uint8_t ring_id)
  3556. {
  3557. uint32_t length;
  3558. qdf_ether_header_t *eh;
  3559. struct dp_vdev *vdev = NULL;
  3560. qdf_nbuf_t nbuf = tx_desc->nbuf;
  3561. enum qdf_dp_tx_rx_status dp_status;
  3562. if (!nbuf) {
  3563. dp_info_rl("invalid tx descriptor. nbuf NULL");
  3564. goto out;
  3565. }
  3566. eh = (qdf_ether_header_t *)qdf_nbuf_data(nbuf);
  3567. length = qdf_nbuf_len(nbuf);
  3568. dp_status = dp_tx_hw_to_qdf(ts->status);
  3569. DPTRACE(qdf_dp_trace_ptr(tx_desc->nbuf,
  3570. QDF_DP_TRACE_LI_DP_FREE_PACKET_PTR_RECORD,
  3571. QDF_TRACE_DEFAULT_PDEV_ID,
  3572. qdf_nbuf_data_addr(nbuf),
  3573. sizeof(qdf_nbuf_data(nbuf)),
  3574. tx_desc->id, ts->status, dp_status));
  3575. dp_tx_comp_debug("-------------------- \n"
  3576. "Tx Completion Stats: \n"
  3577. "-------------------- \n"
  3578. "ack_frame_rssi = %d \n"
  3579. "first_msdu = %d \n"
  3580. "last_msdu = %d \n"
  3581. "msdu_part_of_amsdu = %d \n"
  3582. "rate_stats valid = %d \n"
  3583. "bw = %d \n"
  3584. "pkt_type = %d \n"
  3585. "stbc = %d \n"
  3586. "ldpc = %d \n"
  3587. "sgi = %d \n"
  3588. "mcs = %d \n"
  3589. "ofdma = %d \n"
  3590. "tones_in_ru = %d \n"
  3591. "tsf = %d \n"
  3592. "ppdu_id = %d \n"
  3593. "transmit_cnt = %d \n"
  3594. "tid = %d \n"
  3595. "peer_id = %d\n",
  3596. ts->ack_frame_rssi, ts->first_msdu,
  3597. ts->last_msdu, ts->msdu_part_of_amsdu,
  3598. ts->valid, ts->bw, ts->pkt_type, ts->stbc,
  3599. ts->ldpc, ts->sgi, ts->mcs, ts->ofdma,
  3600. ts->tones_in_ru, ts->tsf, ts->ppdu_id,
  3601. ts->transmit_cnt, ts->tid, ts->peer_id);
  3602. /* Update SoC level stats */
  3603. DP_STATS_INCC(soc, tx.dropped_fw_removed, 1,
  3604. (ts->status == HAL_TX_TQM_RR_REM_CMD_REM));
  3605. if (!peer) {
  3606. dp_info_rl("peer is null or deletion in progress");
  3607. DP_STATS_INC_PKT(soc, tx.tx_invalid_peer, 1, length);
  3608. goto out;
  3609. }
  3610. vdev = peer->vdev;
  3611. dp_tx_update_connectivity_stats(soc, vdev, tx_desc, ts->status);
  3612. /* Update per-packet stats for mesh mode */
  3613. if (qdf_unlikely(vdev->mesh_vdev) &&
  3614. !(tx_desc->flags & DP_TX_DESC_FLAG_TO_FW))
  3615. dp_tx_comp_fill_tx_completion_stats(tx_desc, ts);
  3616. /* Update peer level stats */
  3617. if (qdf_unlikely(peer->bss_peer && vdev->opmode == wlan_op_mode_ap)) {
  3618. if (ts->status != HAL_TX_TQM_RR_REM_CMD_REM) {
  3619. DP_STATS_INC_PKT(peer, tx.mcast, 1, length);
  3620. if ((peer->vdev->tx_encap_type ==
  3621. htt_cmn_pkt_type_ethernet) &&
  3622. QDF_IS_ADDR_BROADCAST(eh->ether_dhost)) {
  3623. DP_STATS_INC_PKT(peer, tx.bcast, 1, length);
  3624. }
  3625. }
  3626. } else {
  3627. DP_STATS_INC_PKT(peer, tx.ucast, 1, length);
  3628. if (ts->status == HAL_TX_TQM_RR_FRAME_ACKED) {
  3629. DP_STATS_INC_PKT(peer, tx.tx_success, 1, length);
  3630. if (qdf_unlikely(peer->in_twt)) {
  3631. DP_STATS_INC_PKT(peer,
  3632. tx.tx_success_twt,
  3633. 1, length);
  3634. }
  3635. }
  3636. }
  3637. dp_tx_update_peer_stats(tx_desc, ts, peer, ring_id);
  3638. dp_tx_update_peer_ext_stats(peer, tx_desc, ts->tid, ring_id);
  3639. #ifdef QCA_SUPPORT_RDK_STATS
  3640. if (soc->rdkstats_enabled)
  3641. dp_tx_sojourn_stats_process(vdev->pdev, peer, ts->tid,
  3642. tx_desc->timestamp,
  3643. ts->ppdu_id);
  3644. #endif
  3645. out:
  3646. return;
  3647. }
  3648. /**
  3649. * dp_tx_comp_process_desc_list() - Tx complete software descriptor handler
  3650. * @soc: core txrx main context
  3651. * @comp_head: software descriptor head pointer
  3652. * @ring_id: ring number
  3653. *
  3654. * This function will process batch of descriptors reaped by dp_tx_comp_handler
  3655. * and release the software descriptors after processing is complete
  3656. *
  3657. * Return: none
  3658. */
  3659. static void
  3660. dp_tx_comp_process_desc_list(struct dp_soc *soc,
  3661. struct dp_tx_desc_s *comp_head, uint8_t ring_id)
  3662. {
  3663. struct dp_tx_desc_s *desc;
  3664. struct dp_tx_desc_s *next;
  3665. struct hal_tx_completion_status ts;
  3666. struct dp_peer *peer = NULL;
  3667. uint16_t peer_id = DP_INVALID_PEER;
  3668. qdf_nbuf_t netbuf;
  3669. desc = comp_head;
  3670. while (desc) {
  3671. if (peer_id != desc->peer_id) {
  3672. if (peer)
  3673. dp_peer_unref_delete(peer,
  3674. DP_MOD_ID_TX_COMP);
  3675. peer_id = desc->peer_id;
  3676. peer = dp_peer_get_ref_by_id(soc, peer_id,
  3677. DP_MOD_ID_TX_COMP);
  3678. }
  3679. if (qdf_likely(desc->flags & DP_TX_DESC_FLAG_SIMPLE)) {
  3680. struct dp_pdev *pdev = desc->pdev;
  3681. if (qdf_likely(peer)) {
  3682. /*
  3683. * Increment peer statistics
  3684. * Minimal statistics update done here
  3685. */
  3686. DP_STATS_INC_PKT(peer, tx.comp_pkt, 1,
  3687. desc->length);
  3688. if (desc->tx_status !=
  3689. HAL_TX_TQM_RR_FRAME_ACKED)
  3690. DP_STATS_INC(peer, tx.tx_failed, 1);
  3691. }
  3692. qdf_assert(pdev);
  3693. dp_tx_outstanding_dec(pdev);
  3694. /*
  3695. * Calling a QDF WRAPPER here is creating signifcant
  3696. * performance impact so avoided the wrapper call here
  3697. */
  3698. next = desc->next;
  3699. qdf_mem_unmap_nbytes_single(soc->osdev,
  3700. desc->dma_addr,
  3701. QDF_DMA_TO_DEVICE,
  3702. desc->length);
  3703. qdf_nbuf_free(desc->nbuf);
  3704. dp_tx_desc_free(soc, desc, desc->pool_id);
  3705. desc = next;
  3706. continue;
  3707. }
  3708. hal_tx_comp_get_status(&desc->comp, &ts, soc->hal_soc);
  3709. dp_tx_comp_process_tx_status(soc, desc, &ts, peer, ring_id);
  3710. netbuf = desc->nbuf;
  3711. /* check tx complete notification */
  3712. if (peer && qdf_nbuf_tx_notify_comp_get(netbuf))
  3713. dp_tx_notify_completion(soc, peer->vdev, desc,
  3714. netbuf, ts.status);
  3715. dp_tx_comp_process_desc(soc, desc, &ts, peer);
  3716. next = desc->next;
  3717. dp_tx_desc_release(desc, desc->pool_id);
  3718. desc = next;
  3719. }
  3720. if (peer)
  3721. dp_peer_unref_delete(peer, DP_MOD_ID_TX_COMP);
  3722. }
  3723. /**
  3724. * dp_tx_process_htt_completion() - Tx HTT Completion Indication Handler
  3725. * @soc: Handle to DP soc structure
  3726. * @tx_desc: software descriptor head pointer
  3727. * @status : Tx completion status from HTT descriptor
  3728. * @ring_id: ring number
  3729. *
  3730. * This function will process HTT Tx indication messages from Target
  3731. *
  3732. * Return: none
  3733. */
  3734. static
  3735. void dp_tx_process_htt_completion(struct dp_soc *soc,
  3736. struct dp_tx_desc_s *tx_desc, uint8_t *status,
  3737. uint8_t ring_id)
  3738. {
  3739. uint8_t tx_status;
  3740. struct dp_pdev *pdev;
  3741. struct dp_vdev *vdev;
  3742. struct hal_tx_completion_status ts = {0};
  3743. uint32_t *htt_desc = (uint32_t *)status;
  3744. struct dp_peer *peer;
  3745. struct cdp_tid_tx_stats *tid_stats = NULL;
  3746. struct htt_soc *htt_handle;
  3747. uint8_t vdev_id;
  3748. tx_status = HTT_TX_WBM_COMPLETION_V2_TX_STATUS_GET(htt_desc[0]);
  3749. htt_handle = (struct htt_soc *)soc->htt_handle;
  3750. htt_wbm_event_record(htt_handle->htt_logger_handle, tx_status, status);
  3751. /*
  3752. * There can be scenario where WBM consuming descriptor enqueued
  3753. * from TQM2WBM first and TQM completion can happen before MEC
  3754. * notification comes from FW2WBM. Avoid access any field of tx
  3755. * descriptor in case of MEC notify.
  3756. */
  3757. if (tx_status == HTT_TX_FW2WBM_TX_STATUS_MEC_NOTIFY) {
  3758. /*
  3759. * Get vdev id from HTT status word in case of MEC
  3760. * notification
  3761. */
  3762. vdev_id = HTT_TX_WBM_COMPLETION_V2_VDEV_ID_GET(htt_desc[3]);
  3763. if (qdf_unlikely(vdev_id >= MAX_VDEV_CNT))
  3764. return;
  3765. vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  3766. DP_MOD_ID_HTT_COMP);
  3767. if (!vdev)
  3768. return;
  3769. dp_tx_mec_handler(vdev, status);
  3770. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_HTT_COMP);
  3771. return;
  3772. }
  3773. /*
  3774. * If the descriptor is already freed in vdev_detach,
  3775. * continue to next descriptor
  3776. */
  3777. if ((tx_desc->vdev_id == DP_INVALID_VDEV_ID) && !tx_desc->flags) {
  3778. dp_tx_comp_info_rl("Descriptor freed in vdev_detach %d", tx_desc->id);
  3779. return;
  3780. }
  3781. pdev = tx_desc->pdev;
  3782. if (qdf_unlikely(tx_desc->pdev->is_pdev_down)) {
  3783. dp_tx_comp_info_rl("pdev in down state %d", tx_desc->id);
  3784. dp_tx_comp_free_buf(soc, tx_desc);
  3785. dp_tx_desc_release(tx_desc, tx_desc->pool_id);
  3786. return;
  3787. }
  3788. qdf_assert(tx_desc->pdev);
  3789. vdev_id = tx_desc->vdev_id;
  3790. vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  3791. DP_MOD_ID_HTT_COMP);
  3792. if (!vdev)
  3793. return;
  3794. switch (tx_status) {
  3795. case HTT_TX_FW2WBM_TX_STATUS_OK:
  3796. case HTT_TX_FW2WBM_TX_STATUS_DROP:
  3797. case HTT_TX_FW2WBM_TX_STATUS_TTL:
  3798. {
  3799. uint8_t tid;
  3800. if (HTT_TX_WBM_COMPLETION_V2_VALID_GET(htt_desc[2])) {
  3801. ts.peer_id =
  3802. HTT_TX_WBM_COMPLETION_V2_SW_PEER_ID_GET(
  3803. htt_desc[2]);
  3804. ts.tid =
  3805. HTT_TX_WBM_COMPLETION_V2_TID_NUM_GET(
  3806. htt_desc[2]);
  3807. } else {
  3808. ts.peer_id = HTT_INVALID_PEER;
  3809. ts.tid = HTT_INVALID_TID;
  3810. }
  3811. ts.ppdu_id =
  3812. HTT_TX_WBM_COMPLETION_V2_SCH_CMD_ID_GET(
  3813. htt_desc[1]);
  3814. ts.ack_frame_rssi =
  3815. HTT_TX_WBM_COMPLETION_V2_ACK_FRAME_RSSI_GET(
  3816. htt_desc[1]);
  3817. ts.tsf = htt_desc[3];
  3818. ts.first_msdu = 1;
  3819. ts.last_msdu = 1;
  3820. tid = ts.tid;
  3821. if (qdf_unlikely(tid >= CDP_MAX_DATA_TIDS))
  3822. tid = CDP_MAX_DATA_TIDS - 1;
  3823. tid_stats = &pdev->stats.tid_stats.tid_tx_stats[ring_id][tid];
  3824. if (qdf_unlikely(pdev->delay_stats_flag))
  3825. dp_tx_compute_delay(vdev, tx_desc, tid, ring_id);
  3826. if (tx_status < CDP_MAX_TX_HTT_STATUS) {
  3827. tid_stats->htt_status_cnt[tx_status]++;
  3828. }
  3829. peer = dp_peer_get_ref_by_id(soc, ts.peer_id,
  3830. DP_MOD_ID_HTT_COMP);
  3831. dp_tx_comp_process_tx_status(soc, tx_desc, &ts, peer, ring_id);
  3832. dp_tx_comp_process_desc(soc, tx_desc, &ts, peer);
  3833. dp_tx_desc_release(tx_desc, tx_desc->pool_id);
  3834. if (qdf_likely(peer))
  3835. dp_peer_unref_delete(peer, DP_MOD_ID_HTT_COMP);
  3836. break;
  3837. }
  3838. case HTT_TX_FW2WBM_TX_STATUS_REINJECT:
  3839. {
  3840. dp_tx_reinject_handler(soc, vdev, tx_desc, status);
  3841. break;
  3842. }
  3843. case HTT_TX_FW2WBM_TX_STATUS_INSPECT:
  3844. {
  3845. dp_tx_inspect_handler(soc, vdev, tx_desc, status);
  3846. break;
  3847. }
  3848. default:
  3849. dp_tx_comp_debug("Invalid HTT tx_status %d\n",
  3850. tx_status);
  3851. break;
  3852. }
  3853. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_HTT_COMP);
  3854. }
  3855. #ifdef WLAN_FEATURE_RX_SOFTIRQ_TIME_LIMIT
  3856. static inline
  3857. bool dp_tx_comp_loop_pkt_limit_hit(struct dp_soc *soc, int num_reaped)
  3858. {
  3859. bool limit_hit = false;
  3860. struct wlan_cfg_dp_soc_ctxt *cfg = soc->wlan_cfg_ctx;
  3861. limit_hit =
  3862. (num_reaped >= cfg->tx_comp_loop_pkt_limit) ? true : false;
  3863. if (limit_hit)
  3864. DP_STATS_INC(soc, tx.tx_comp_loop_pkt_limit_hit, 1);
  3865. return limit_hit;
  3866. }
  3867. static inline bool dp_tx_comp_enable_eol_data_check(struct dp_soc *soc)
  3868. {
  3869. return soc->wlan_cfg_ctx->tx_comp_enable_eol_data_check;
  3870. }
  3871. #else
  3872. static inline
  3873. bool dp_tx_comp_loop_pkt_limit_hit(struct dp_soc *soc, int num_reaped)
  3874. {
  3875. return false;
  3876. }
  3877. static inline bool dp_tx_comp_enable_eol_data_check(struct dp_soc *soc)
  3878. {
  3879. return false;
  3880. }
  3881. #endif
  3882. uint32_t dp_tx_comp_handler(struct dp_intr *int_ctx, struct dp_soc *soc,
  3883. hal_ring_handle_t hal_ring_hdl, uint8_t ring_id,
  3884. uint32_t quota)
  3885. {
  3886. void *tx_comp_hal_desc;
  3887. uint8_t buffer_src;
  3888. uint8_t pool_id;
  3889. uint32_t tx_desc_id;
  3890. struct dp_tx_desc_s *tx_desc = NULL;
  3891. struct dp_tx_desc_s *head_desc = NULL;
  3892. struct dp_tx_desc_s *tail_desc = NULL;
  3893. uint32_t num_processed = 0;
  3894. uint32_t count;
  3895. uint32_t num_avail_for_reap = 0;
  3896. bool force_break = false;
  3897. DP_HIST_INIT();
  3898. more_data:
  3899. /* Re-initialize local variables to be re-used */
  3900. head_desc = NULL;
  3901. tail_desc = NULL;
  3902. count = 0;
  3903. if (qdf_unlikely(dp_srng_access_start(int_ctx, soc, hal_ring_hdl))) {
  3904. dp_err("HAL RING Access Failed -- %pK", hal_ring_hdl);
  3905. return 0;
  3906. }
  3907. num_avail_for_reap = hal_srng_dst_num_valid(soc->hal_soc, hal_ring_hdl, 0);
  3908. if (num_avail_for_reap >= quota)
  3909. num_avail_for_reap = quota;
  3910. dp_srng_dst_inv_cached_descs(soc, hal_ring_hdl, num_avail_for_reap);
  3911. /* Find head descriptor from completion ring */
  3912. while (qdf_likely(num_avail_for_reap)) {
  3913. tx_comp_hal_desc = dp_srng_dst_get_next(soc, hal_ring_hdl);
  3914. if (qdf_unlikely(!tx_comp_hal_desc))
  3915. break;
  3916. buffer_src = hal_tx_comp_get_buffer_source(tx_comp_hal_desc);
  3917. /* If this buffer was not released by TQM or FW, then it is not
  3918. * Tx completion indication, assert */
  3919. if (qdf_unlikely(buffer_src !=
  3920. HAL_TX_COMP_RELEASE_SOURCE_TQM) &&
  3921. (qdf_unlikely(buffer_src !=
  3922. HAL_TX_COMP_RELEASE_SOURCE_FW))) {
  3923. uint8_t wbm_internal_error;
  3924. dp_err_rl(
  3925. "Tx comp release_src != TQM | FW but from %d",
  3926. buffer_src);
  3927. hal_dump_comp_desc(tx_comp_hal_desc);
  3928. DP_STATS_INC(soc, tx.invalid_release_source, 1);
  3929. /* When WBM sees NULL buffer_addr_info in any of
  3930. * ingress rings it sends an error indication,
  3931. * with wbm_internal_error=1, to a specific ring.
  3932. * The WBM2SW ring used to indicate these errors is
  3933. * fixed in HW, and that ring is being used as Tx
  3934. * completion ring. These errors are not related to
  3935. * Tx completions, and should just be ignored
  3936. */
  3937. wbm_internal_error = hal_get_wbm_internal_error(
  3938. soc->hal_soc,
  3939. tx_comp_hal_desc);
  3940. if (wbm_internal_error) {
  3941. dp_err_rl("Tx comp wbm_internal_error!!");
  3942. DP_STATS_INC(soc, tx.wbm_internal_error[WBM_INT_ERROR_ALL], 1);
  3943. if (HAL_TX_COMP_RELEASE_SOURCE_REO ==
  3944. buffer_src)
  3945. dp_handle_wbm_internal_error(
  3946. soc,
  3947. tx_comp_hal_desc,
  3948. hal_tx_comp_get_buffer_type(
  3949. tx_comp_hal_desc));
  3950. } else {
  3951. dp_err_rl("Tx comp wbm_internal_error false");
  3952. DP_STATS_INC(soc, tx.non_wbm_internal_err, 1);
  3953. }
  3954. continue;
  3955. }
  3956. /* Get descriptor id */
  3957. tx_desc_id = hal_tx_comp_get_desc_id(tx_comp_hal_desc);
  3958. pool_id = (tx_desc_id & DP_TX_DESC_ID_POOL_MASK) >>
  3959. DP_TX_DESC_ID_POOL_OS;
  3960. /* Find Tx descriptor */
  3961. tx_desc = dp_tx_desc_find(soc, pool_id,
  3962. (tx_desc_id & DP_TX_DESC_ID_PAGE_MASK) >>
  3963. DP_TX_DESC_ID_PAGE_OS,
  3964. (tx_desc_id & DP_TX_DESC_ID_OFFSET_MASK) >>
  3965. DP_TX_DESC_ID_OFFSET_OS);
  3966. /*
  3967. * If the release source is FW, process the HTT status
  3968. */
  3969. if (qdf_unlikely(buffer_src ==
  3970. HAL_TX_COMP_RELEASE_SOURCE_FW)) {
  3971. uint8_t htt_tx_status[HAL_TX_COMP_HTT_STATUS_LEN];
  3972. hal_tx_comp_get_htt_desc(tx_comp_hal_desc,
  3973. htt_tx_status);
  3974. dp_tx_process_htt_completion(soc, tx_desc,
  3975. htt_tx_status, ring_id);
  3976. } else {
  3977. tx_desc->peer_id =
  3978. hal_tx_comp_get_peer_id(tx_comp_hal_desc);
  3979. tx_desc->tx_status =
  3980. hal_tx_comp_get_tx_status(tx_comp_hal_desc);
  3981. /*
  3982. * If the fast completion mode is enabled extended
  3983. * metadata from descriptor is not copied
  3984. */
  3985. if (qdf_likely(tx_desc->flags &
  3986. DP_TX_DESC_FLAG_SIMPLE))
  3987. goto add_to_pool;
  3988. /*
  3989. * If the descriptor is already freed in vdev_detach,
  3990. * continue to next descriptor
  3991. */
  3992. if (qdf_unlikely
  3993. ((tx_desc->vdev_id == DP_INVALID_VDEV_ID) &&
  3994. !tx_desc->flags)) {
  3995. dp_tx_comp_info_rl("Descriptor freed in vdev_detach %d",
  3996. tx_desc_id);
  3997. continue;
  3998. }
  3999. if (qdf_unlikely(tx_desc->pdev->is_pdev_down)) {
  4000. dp_tx_comp_info_rl("pdev in down state %d",
  4001. tx_desc_id);
  4002. dp_tx_comp_free_buf(soc, tx_desc);
  4003. dp_tx_desc_release(tx_desc, tx_desc->pool_id);
  4004. goto next_desc;
  4005. }
  4006. /* Pool id is not matching. Error */
  4007. if (tx_desc->pool_id != pool_id) {
  4008. dp_tx_comp_alert("Tx Comp pool id %d not matched %d",
  4009. pool_id, tx_desc->pool_id);
  4010. qdf_assert_always(0);
  4011. }
  4012. if (!(tx_desc->flags & DP_TX_DESC_FLAG_ALLOCATED) ||
  4013. !(tx_desc->flags & DP_TX_DESC_FLAG_QUEUED_TX)) {
  4014. dp_tx_comp_alert("Txdesc invalid, flgs = %x,id = %d",
  4015. tx_desc->flags, tx_desc_id);
  4016. qdf_assert_always(0);
  4017. }
  4018. /* Collect hw completion contents */
  4019. hal_tx_comp_desc_sync(tx_comp_hal_desc,
  4020. &tx_desc->comp, 1);
  4021. add_to_pool:
  4022. DP_HIST_PACKET_COUNT_INC(tx_desc->pdev->pdev_id);
  4023. /* First ring descriptor on the cycle */
  4024. if (!head_desc) {
  4025. head_desc = tx_desc;
  4026. tail_desc = tx_desc;
  4027. }
  4028. tail_desc->next = tx_desc;
  4029. tx_desc->next = NULL;
  4030. tail_desc = tx_desc;
  4031. }
  4032. next_desc:
  4033. num_processed += !(count & DP_TX_NAPI_BUDGET_DIV_MASK);
  4034. /*
  4035. * Processed packet count is more than given quota
  4036. * stop to processing
  4037. */
  4038. count++;
  4039. if (dp_tx_comp_loop_pkt_limit_hit(soc, count))
  4040. break;
  4041. }
  4042. dp_srng_access_end(int_ctx, soc, hal_ring_hdl);
  4043. /* Process the reaped descriptors */
  4044. if (head_desc)
  4045. dp_tx_comp_process_desc_list(soc, head_desc, ring_id);
  4046. if (dp_tx_comp_enable_eol_data_check(soc)) {
  4047. if (num_processed >= quota)
  4048. force_break = true;
  4049. if (!force_break &&
  4050. hal_srng_dst_peek_sync_locked(soc->hal_soc,
  4051. hal_ring_hdl)) {
  4052. DP_STATS_INC(soc, tx.hp_oos2, 1);
  4053. if (!hif_exec_should_yield(soc->hif_handle,
  4054. int_ctx->dp_intr_id))
  4055. goto more_data;
  4056. }
  4057. }
  4058. DP_TX_HIST_STATS_PER_PDEV();
  4059. return num_processed;
  4060. }
  4061. #ifdef FEATURE_WLAN_TDLS
  4062. qdf_nbuf_t dp_tx_non_std(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  4063. enum ol_tx_spec tx_spec, qdf_nbuf_t msdu_list)
  4064. {
  4065. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  4066. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  4067. DP_MOD_ID_TDLS);
  4068. if (!vdev) {
  4069. dp_err("vdev handle for id %d is NULL", vdev_id);
  4070. return NULL;
  4071. }
  4072. if (tx_spec & OL_TX_SPEC_NO_FREE)
  4073. vdev->is_tdls_frame = true;
  4074. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_TDLS);
  4075. return dp_tx_send(soc_hdl, vdev_id, msdu_list);
  4076. }
  4077. #endif
  4078. static void dp_tx_vdev_update_feature_flags(struct dp_vdev *vdev)
  4079. {
  4080. struct wlan_cfg_dp_soc_ctxt *cfg;
  4081. struct dp_soc *soc;
  4082. soc = vdev->pdev->soc;
  4083. if (!soc)
  4084. return;
  4085. cfg = soc->wlan_cfg_ctx;
  4086. if (!cfg)
  4087. return;
  4088. if (vdev->opmode == wlan_op_mode_ndi)
  4089. vdev->csum_enabled = wlan_cfg_get_nan_checksum_offload(cfg);
  4090. else if ((vdev->subtype == wlan_op_subtype_p2p_device) ||
  4091. (vdev->subtype == wlan_op_subtype_p2p_cli) ||
  4092. (vdev->subtype == wlan_op_subtype_p2p_go))
  4093. vdev->csum_enabled = wlan_cfg_get_p2p_checksum_offload(cfg);
  4094. else
  4095. vdev->csum_enabled = wlan_cfg_get_checksum_offload(cfg);
  4096. }
  4097. /**
  4098. * dp_tx_vdev_attach() - attach vdev to dp tx
  4099. * @vdev: virtual device instance
  4100. *
  4101. * Return: QDF_STATUS_SUCCESS: success
  4102. * QDF_STATUS_E_RESOURCES: Error return
  4103. */
  4104. QDF_STATUS dp_tx_vdev_attach(struct dp_vdev *vdev)
  4105. {
  4106. int pdev_id;
  4107. /*
  4108. * Fill HTT TCL Metadata with Vdev ID and MAC ID
  4109. */
  4110. HTT_TX_TCL_METADATA_TYPE_SET(vdev->htt_tcl_metadata,
  4111. HTT_TCL_METADATA_TYPE_VDEV_BASED);
  4112. HTT_TX_TCL_METADATA_VDEV_ID_SET(vdev->htt_tcl_metadata,
  4113. vdev->vdev_id);
  4114. pdev_id =
  4115. dp_get_target_pdev_id_for_host_pdev_id(vdev->pdev->soc,
  4116. vdev->pdev->pdev_id);
  4117. HTT_TX_TCL_METADATA_PDEV_ID_SET(vdev->htt_tcl_metadata, pdev_id);
  4118. /*
  4119. * Set HTT Extension Valid bit to 0 by default
  4120. */
  4121. HTT_TX_TCL_METADATA_VALID_HTT_SET(vdev->htt_tcl_metadata, 0);
  4122. dp_tx_vdev_update_search_flags(vdev);
  4123. dp_tx_vdev_update_feature_flags(vdev);
  4124. return QDF_STATUS_SUCCESS;
  4125. }
  4126. #ifndef FEATURE_WDS
  4127. static inline bool dp_tx_da_search_override(struct dp_vdev *vdev)
  4128. {
  4129. return false;
  4130. }
  4131. #endif
  4132. /**
  4133. * dp_tx_vdev_update_search_flags() - Update vdev flags as per opmode
  4134. * @vdev: virtual device instance
  4135. *
  4136. * Return: void
  4137. *
  4138. */
  4139. void dp_tx_vdev_update_search_flags(struct dp_vdev *vdev)
  4140. {
  4141. struct dp_soc *soc = vdev->pdev->soc;
  4142. /*
  4143. * Enable both AddrY (SA based search) and AddrX (Da based search)
  4144. * for TDLS link
  4145. *
  4146. * Enable AddrY (SA based search) only for non-WDS STA and
  4147. * ProxySTA VAP (in HKv1) modes.
  4148. *
  4149. * In all other VAP modes, only DA based search should be
  4150. * enabled
  4151. */
  4152. if (vdev->opmode == wlan_op_mode_sta &&
  4153. vdev->tdls_link_connected)
  4154. vdev->hal_desc_addr_search_flags =
  4155. (HAL_TX_DESC_ADDRX_EN | HAL_TX_DESC_ADDRY_EN);
  4156. else if ((vdev->opmode == wlan_op_mode_sta) &&
  4157. !dp_tx_da_search_override(vdev))
  4158. vdev->hal_desc_addr_search_flags = HAL_TX_DESC_ADDRY_EN;
  4159. else
  4160. vdev->hal_desc_addr_search_flags = HAL_TX_DESC_ADDRX_EN;
  4161. /* Set search type only when peer map v2 messaging is enabled
  4162. * as we will have the search index (AST hash) only when v2 is
  4163. * enabled
  4164. */
  4165. if (soc->is_peer_map_unmap_v2 && vdev->opmode == wlan_op_mode_sta)
  4166. vdev->search_type = HAL_TX_ADDR_INDEX_SEARCH;
  4167. else
  4168. vdev->search_type = HAL_TX_ADDR_SEARCH_DEFAULT;
  4169. }
  4170. static inline bool
  4171. dp_is_tx_desc_flush_match(struct dp_pdev *pdev,
  4172. struct dp_vdev *vdev,
  4173. struct dp_tx_desc_s *tx_desc)
  4174. {
  4175. if (!(tx_desc && (tx_desc->flags & DP_TX_DESC_FLAG_ALLOCATED)))
  4176. return false;
  4177. /*
  4178. * if vdev is given, then only check whether desc
  4179. * vdev match. if vdev is NULL, then check whether
  4180. * desc pdev match.
  4181. */
  4182. return vdev ? (tx_desc->vdev_id == vdev->vdev_id) :
  4183. (tx_desc->pdev == pdev);
  4184. }
  4185. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  4186. /**
  4187. * dp_tx_desc_flush() - release resources associated
  4188. * to TX Desc
  4189. *
  4190. * @dp_pdev: Handle to DP pdev structure
  4191. * @vdev: virtual device instance
  4192. * NULL: no specific Vdev is required and check all allcated TX desc
  4193. * on this pdev.
  4194. * Non-NULL: only check the allocated TX Desc associated to this Vdev.
  4195. *
  4196. * @force_free:
  4197. * true: flush the TX desc.
  4198. * false: only reset the Vdev in each allocated TX desc
  4199. * that associated to current Vdev.
  4200. *
  4201. * This function will go through the TX desc pool to flush
  4202. * the outstanding TX data or reset Vdev to NULL in associated TX
  4203. * Desc.
  4204. */
  4205. void dp_tx_desc_flush(struct dp_pdev *pdev, struct dp_vdev *vdev,
  4206. bool force_free)
  4207. {
  4208. uint8_t i;
  4209. uint32_t j;
  4210. uint32_t num_desc, page_id, offset;
  4211. uint16_t num_desc_per_page;
  4212. struct dp_soc *soc = pdev->soc;
  4213. struct dp_tx_desc_s *tx_desc = NULL;
  4214. struct dp_tx_desc_pool_s *tx_desc_pool = NULL;
  4215. if (!vdev && !force_free) {
  4216. dp_err("Reset TX desc vdev, Vdev param is required!");
  4217. return;
  4218. }
  4219. for (i = 0; i < MAX_TXDESC_POOLS; i++) {
  4220. tx_desc_pool = &soc->tx_desc[i];
  4221. if (!(tx_desc_pool->pool_size) ||
  4222. IS_TX_DESC_POOL_STATUS_INACTIVE(tx_desc_pool) ||
  4223. !(tx_desc_pool->desc_pages.cacheable_pages))
  4224. continue;
  4225. /*
  4226. * Add flow pool lock protection in case pool is freed
  4227. * due to all tx_desc is recycled when handle TX completion.
  4228. * this is not necessary when do force flush as:
  4229. * a. double lock will happen if dp_tx_desc_release is
  4230. * also trying to acquire it.
  4231. * b. dp interrupt has been disabled before do force TX desc
  4232. * flush in dp_pdev_deinit().
  4233. */
  4234. if (!force_free)
  4235. qdf_spin_lock_bh(&tx_desc_pool->flow_pool_lock);
  4236. num_desc = tx_desc_pool->pool_size;
  4237. num_desc_per_page =
  4238. tx_desc_pool->desc_pages.num_element_per_page;
  4239. for (j = 0; j < num_desc; j++) {
  4240. page_id = j / num_desc_per_page;
  4241. offset = j % num_desc_per_page;
  4242. if (qdf_unlikely(!(tx_desc_pool->
  4243. desc_pages.cacheable_pages)))
  4244. break;
  4245. tx_desc = dp_tx_desc_find(soc, i, page_id, offset);
  4246. if (dp_is_tx_desc_flush_match(pdev, vdev, tx_desc)) {
  4247. /*
  4248. * Free TX desc if force free is
  4249. * required, otherwise only reset vdev
  4250. * in this TX desc.
  4251. */
  4252. if (force_free) {
  4253. dp_tx_comp_free_buf(soc, tx_desc);
  4254. dp_tx_desc_release(tx_desc, i);
  4255. } else {
  4256. tx_desc->vdev_id = DP_INVALID_VDEV_ID;
  4257. }
  4258. }
  4259. }
  4260. if (!force_free)
  4261. qdf_spin_unlock_bh(&tx_desc_pool->flow_pool_lock);
  4262. }
  4263. }
  4264. #else /* QCA_LL_TX_FLOW_CONTROL_V2! */
  4265. /**
  4266. * dp_tx_desc_reset_vdev() - reset vdev to NULL in TX Desc
  4267. *
  4268. * @soc: Handle to DP soc structure
  4269. * @tx_desc: pointer of one TX desc
  4270. * @desc_pool_id: TX Desc pool id
  4271. */
  4272. static inline void
  4273. dp_tx_desc_reset_vdev(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  4274. uint8_t desc_pool_id)
  4275. {
  4276. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  4277. tx_desc->vdev_id = DP_INVALID_VDEV_ID;
  4278. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  4279. }
  4280. void dp_tx_desc_flush(struct dp_pdev *pdev, struct dp_vdev *vdev,
  4281. bool force_free)
  4282. {
  4283. uint8_t i, num_pool;
  4284. uint32_t j;
  4285. uint32_t num_desc, page_id, offset;
  4286. uint16_t num_desc_per_page;
  4287. struct dp_soc *soc = pdev->soc;
  4288. struct dp_tx_desc_s *tx_desc = NULL;
  4289. struct dp_tx_desc_pool_s *tx_desc_pool = NULL;
  4290. if (!vdev && !force_free) {
  4291. dp_err("Reset TX desc vdev, Vdev param is required!");
  4292. return;
  4293. }
  4294. num_desc = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  4295. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  4296. for (i = 0; i < num_pool; i++) {
  4297. tx_desc_pool = &soc->tx_desc[i];
  4298. if (!tx_desc_pool->desc_pages.cacheable_pages)
  4299. continue;
  4300. num_desc_per_page =
  4301. tx_desc_pool->desc_pages.num_element_per_page;
  4302. for (j = 0; j < num_desc; j++) {
  4303. page_id = j / num_desc_per_page;
  4304. offset = j % num_desc_per_page;
  4305. tx_desc = dp_tx_desc_find(soc, i, page_id, offset);
  4306. if (dp_is_tx_desc_flush_match(pdev, vdev, tx_desc)) {
  4307. if (force_free) {
  4308. dp_tx_comp_free_buf(soc, tx_desc);
  4309. dp_tx_desc_release(tx_desc, i);
  4310. } else {
  4311. dp_tx_desc_reset_vdev(soc, tx_desc,
  4312. i);
  4313. }
  4314. }
  4315. }
  4316. }
  4317. }
  4318. #endif /* !QCA_LL_TX_FLOW_CONTROL_V2 */
  4319. /**
  4320. * dp_tx_vdev_detach() - detach vdev from dp tx
  4321. * @vdev: virtual device instance
  4322. *
  4323. * Return: QDF_STATUS_SUCCESS: success
  4324. * QDF_STATUS_E_RESOURCES: Error return
  4325. */
  4326. QDF_STATUS dp_tx_vdev_detach(struct dp_vdev *vdev)
  4327. {
  4328. struct dp_pdev *pdev = vdev->pdev;
  4329. /* Reset TX desc associated to this Vdev as NULL */
  4330. dp_tx_desc_flush(pdev, vdev, false);
  4331. return QDF_STATUS_SUCCESS;
  4332. }
  4333. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  4334. /* Pools will be allocated dynamically */
  4335. static QDF_STATUS dp_tx_alloc_static_pools(struct dp_soc *soc, int num_pool,
  4336. int num_desc)
  4337. {
  4338. uint8_t i;
  4339. for (i = 0; i < num_pool; i++) {
  4340. qdf_spinlock_create(&soc->tx_desc[i].flow_pool_lock);
  4341. soc->tx_desc[i].status = FLOW_POOL_INACTIVE;
  4342. }
  4343. return QDF_STATUS_SUCCESS;
  4344. }
  4345. static QDF_STATUS dp_tx_init_static_pools(struct dp_soc *soc, int num_pool,
  4346. int num_desc)
  4347. {
  4348. return QDF_STATUS_SUCCESS;
  4349. }
  4350. static void dp_tx_deinit_static_pools(struct dp_soc *soc, int num_pool)
  4351. {
  4352. }
  4353. static void dp_tx_delete_static_pools(struct dp_soc *soc, int num_pool)
  4354. {
  4355. uint8_t i;
  4356. for (i = 0; i < num_pool; i++)
  4357. qdf_spinlock_destroy(&soc->tx_desc[i].flow_pool_lock);
  4358. }
  4359. #else /* QCA_LL_TX_FLOW_CONTROL_V2! */
  4360. static QDF_STATUS dp_tx_alloc_static_pools(struct dp_soc *soc, int num_pool,
  4361. int num_desc)
  4362. {
  4363. uint8_t i, count;
  4364. /* Allocate software Tx descriptor pools */
  4365. for (i = 0; i < num_pool; i++) {
  4366. if (dp_tx_desc_pool_alloc(soc, i, num_desc)) {
  4367. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  4368. FL("Tx Desc Pool alloc %d failed %pK"),
  4369. i, soc);
  4370. goto fail;
  4371. }
  4372. }
  4373. return QDF_STATUS_SUCCESS;
  4374. fail:
  4375. for (count = 0; count < i; count++)
  4376. dp_tx_desc_pool_free(soc, count);
  4377. return QDF_STATUS_E_NOMEM;
  4378. }
  4379. static QDF_STATUS dp_tx_init_static_pools(struct dp_soc *soc, int num_pool,
  4380. int num_desc)
  4381. {
  4382. uint8_t i;
  4383. for (i = 0; i < num_pool; i++) {
  4384. if (dp_tx_desc_pool_init(soc, i, num_desc)) {
  4385. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  4386. FL("Tx Desc Pool init %d failed %pK"),
  4387. i, soc);
  4388. return QDF_STATUS_E_NOMEM;
  4389. }
  4390. }
  4391. return QDF_STATUS_SUCCESS;
  4392. }
  4393. static void dp_tx_deinit_static_pools(struct dp_soc *soc, int num_pool)
  4394. {
  4395. uint8_t i;
  4396. for (i = 0; i < num_pool; i++)
  4397. dp_tx_desc_pool_deinit(soc, i);
  4398. }
  4399. static void dp_tx_delete_static_pools(struct dp_soc *soc, int num_pool)
  4400. {
  4401. uint8_t i;
  4402. for (i = 0; i < num_pool; i++)
  4403. dp_tx_desc_pool_free(soc, i);
  4404. }
  4405. #endif /* !QCA_LL_TX_FLOW_CONTROL_V2 */
  4406. /**
  4407. * dp_tx_tso_cmn_desc_pool_deinit() - de-initialize TSO descriptors
  4408. * @soc: core txrx main context
  4409. * @num_pool: number of pools
  4410. *
  4411. */
  4412. void dp_tx_tso_cmn_desc_pool_deinit(struct dp_soc *soc, uint8_t num_pool)
  4413. {
  4414. dp_tx_tso_desc_pool_deinit(soc, num_pool);
  4415. dp_tx_tso_num_seg_pool_deinit(soc, num_pool);
  4416. }
  4417. /**
  4418. * dp_tx_tso_cmn_desc_pool_free() - free TSO descriptors
  4419. * @soc: core txrx main context
  4420. * @num_pool: number of pools
  4421. *
  4422. */
  4423. void dp_tx_tso_cmn_desc_pool_free(struct dp_soc *soc, uint8_t num_pool)
  4424. {
  4425. dp_tx_tso_desc_pool_free(soc, num_pool);
  4426. dp_tx_tso_num_seg_pool_free(soc, num_pool);
  4427. }
  4428. /**
  4429. * dp_soc_tx_desc_sw_pools_free() - free all TX descriptors
  4430. * @soc: core txrx main context
  4431. *
  4432. * This function frees all tx related descriptors as below
  4433. * 1. Regular TX descriptors (static pools)
  4434. * 2. extension TX descriptors (used for ME, RAW, TSO etc...)
  4435. * 3. TSO descriptors
  4436. *
  4437. */
  4438. void dp_soc_tx_desc_sw_pools_free(struct dp_soc *soc)
  4439. {
  4440. uint8_t num_pool;
  4441. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  4442. dp_tx_tso_cmn_desc_pool_free(soc, num_pool);
  4443. dp_tx_ext_desc_pool_free(soc, num_pool);
  4444. dp_tx_delete_static_pools(soc, num_pool);
  4445. }
  4446. /**
  4447. * dp_soc_tx_desc_sw_pools_deinit() - de-initialize all TX descriptors
  4448. * @soc: core txrx main context
  4449. *
  4450. * This function de-initializes all tx related descriptors as below
  4451. * 1. Regular TX descriptors (static pools)
  4452. * 2. extension TX descriptors (used for ME, RAW, TSO etc...)
  4453. * 3. TSO descriptors
  4454. *
  4455. */
  4456. void dp_soc_tx_desc_sw_pools_deinit(struct dp_soc *soc)
  4457. {
  4458. uint8_t num_pool;
  4459. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  4460. dp_tx_flow_control_deinit(soc);
  4461. dp_tx_tso_cmn_desc_pool_deinit(soc, num_pool);
  4462. dp_tx_ext_desc_pool_deinit(soc, num_pool);
  4463. dp_tx_deinit_static_pools(soc, num_pool);
  4464. }
  4465. /**
  4466. * dp_tso_attach() - TSO attach handler
  4467. * @txrx_soc: Opaque Dp handle
  4468. *
  4469. * Reserve TSO descriptor buffers
  4470. *
  4471. * Return: QDF_STATUS_E_FAILURE on failure or
  4472. * QDF_STATUS_SUCCESS on success
  4473. */
  4474. QDF_STATUS dp_tx_tso_cmn_desc_pool_alloc(struct dp_soc *soc,
  4475. uint8_t num_pool,
  4476. uint16_t num_desc)
  4477. {
  4478. if (dp_tx_tso_desc_pool_alloc(soc, num_pool, num_desc)) {
  4479. dp_err("TSO Desc Pool alloc %d failed %pK", num_pool, soc);
  4480. return QDF_STATUS_E_FAILURE;
  4481. }
  4482. if (dp_tx_tso_num_seg_pool_alloc(soc, num_pool, num_desc)) {
  4483. dp_err("TSO Num of seg Pool alloc %d failed %pK",
  4484. num_pool, soc);
  4485. return QDF_STATUS_E_FAILURE;
  4486. }
  4487. return QDF_STATUS_SUCCESS;
  4488. }
  4489. /**
  4490. * dp_tx_tso_cmn_desc_pool_init() - TSO cmn desc pool init
  4491. * @soc: DP soc handle
  4492. * @num_pool: Number of pools
  4493. * @num_desc: Number of descriptors
  4494. *
  4495. * Initialize TSO descriptor pools
  4496. *
  4497. * Return: QDF_STATUS_E_FAILURE on failure or
  4498. * QDF_STATUS_SUCCESS on success
  4499. */
  4500. QDF_STATUS dp_tx_tso_cmn_desc_pool_init(struct dp_soc *soc,
  4501. uint8_t num_pool,
  4502. uint16_t num_desc)
  4503. {
  4504. if (dp_tx_tso_desc_pool_init(soc, num_pool, num_desc)) {
  4505. dp_err("TSO Desc Pool alloc %d failed %pK", num_pool, soc);
  4506. return QDF_STATUS_E_FAILURE;
  4507. }
  4508. if (dp_tx_tso_num_seg_pool_init(soc, num_pool, num_desc)) {
  4509. dp_err("TSO Num of seg Pool alloc %d failed %pK",
  4510. num_pool, soc);
  4511. return QDF_STATUS_E_FAILURE;
  4512. }
  4513. return QDF_STATUS_SUCCESS;
  4514. }
  4515. /**
  4516. * dp_soc_tx_desc_sw_pools_alloc() - Allocate tx descriptor pool memory
  4517. * @soc: core txrx main context
  4518. *
  4519. * This function allocates memory for following descriptor pools
  4520. * 1. regular sw tx descriptor pools (static pools)
  4521. * 2. TX extension descriptor pools (ME, RAW, TSO etc...)
  4522. * 3. TSO descriptor pools
  4523. *
  4524. * Return: QDF_STATUS_SUCCESS: success
  4525. * QDF_STATUS_E_RESOURCES: Error return
  4526. */
  4527. QDF_STATUS dp_soc_tx_desc_sw_pools_alloc(struct dp_soc *soc)
  4528. {
  4529. uint8_t num_pool;
  4530. uint32_t num_desc;
  4531. uint32_t num_ext_desc;
  4532. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  4533. num_desc = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  4534. num_ext_desc = wlan_cfg_get_num_tx_ext_desc(soc->wlan_cfg_ctx);
  4535. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  4536. "%s Tx Desc Alloc num_pool = %d, descs = %d",
  4537. __func__, num_pool, num_desc);
  4538. if ((num_pool > MAX_TXDESC_POOLS) ||
  4539. (num_desc > WLAN_CFG_NUM_TX_DESC_MAX))
  4540. goto fail1;
  4541. if (dp_tx_alloc_static_pools(soc, num_pool, num_desc))
  4542. goto fail1;
  4543. if (dp_tx_ext_desc_pool_alloc(soc, num_pool, num_ext_desc))
  4544. goto fail2;
  4545. if (wlan_cfg_is_tso_desc_attach_defer(soc->wlan_cfg_ctx))
  4546. return QDF_STATUS_SUCCESS;
  4547. if (dp_tx_tso_cmn_desc_pool_alloc(soc, num_pool, num_ext_desc))
  4548. goto fail3;
  4549. return QDF_STATUS_SUCCESS;
  4550. fail3:
  4551. dp_tx_ext_desc_pool_free(soc, num_pool);
  4552. fail2:
  4553. dp_tx_delete_static_pools(soc, num_pool);
  4554. fail1:
  4555. return QDF_STATUS_E_RESOURCES;
  4556. }
  4557. /**
  4558. * dp_soc_tx_desc_sw_pools_init() - Initialise TX descriptor pools
  4559. * @soc: core txrx main context
  4560. *
  4561. * This function initializes the following TX descriptor pools
  4562. * 1. regular sw tx descriptor pools (static pools)
  4563. * 2. TX extension descriptor pools (ME, RAW, TSO etc...)
  4564. * 3. TSO descriptor pools
  4565. *
  4566. * Return: QDF_STATUS_SUCCESS: success
  4567. * QDF_STATUS_E_RESOURCES: Error return
  4568. */
  4569. QDF_STATUS dp_soc_tx_desc_sw_pools_init(struct dp_soc *soc)
  4570. {
  4571. uint8_t num_pool;
  4572. uint32_t num_desc;
  4573. uint32_t num_ext_desc;
  4574. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  4575. num_desc = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  4576. num_ext_desc = wlan_cfg_get_num_tx_ext_desc(soc->wlan_cfg_ctx);
  4577. if (dp_tx_init_static_pools(soc, num_pool, num_desc))
  4578. goto fail1;
  4579. if (dp_tx_ext_desc_pool_init(soc, num_pool, num_ext_desc))
  4580. goto fail2;
  4581. if (wlan_cfg_is_tso_desc_attach_defer(soc->wlan_cfg_ctx))
  4582. return QDF_STATUS_SUCCESS;
  4583. if (dp_tx_tso_cmn_desc_pool_init(soc, num_pool, num_ext_desc))
  4584. goto fail3;
  4585. dp_tx_flow_control_init(soc);
  4586. soc->process_tx_status = CONFIG_PROCESS_TX_STATUS;
  4587. return QDF_STATUS_SUCCESS;
  4588. fail3:
  4589. dp_tx_ext_desc_pool_deinit(soc, num_pool);
  4590. fail2:
  4591. dp_tx_deinit_static_pools(soc, num_pool);
  4592. fail1:
  4593. return QDF_STATUS_E_RESOURCES;
  4594. }
  4595. /**
  4596. * dp_tso_soc_attach() - Allocate and initialize TSO descriptors
  4597. * @txrx_soc: dp soc handle
  4598. *
  4599. * Return: QDF_STATUS - QDF_STATUS_SUCCESS
  4600. * QDF_STATUS_E_FAILURE
  4601. */
  4602. QDF_STATUS dp_tso_soc_attach(struct cdp_soc_t *txrx_soc)
  4603. {
  4604. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  4605. uint8_t num_pool;
  4606. uint32_t num_desc;
  4607. uint32_t num_ext_desc;
  4608. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  4609. num_desc = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  4610. num_ext_desc = wlan_cfg_get_num_tx_ext_desc(soc->wlan_cfg_ctx);
  4611. if (dp_tx_tso_cmn_desc_pool_alloc(soc, num_pool, num_ext_desc))
  4612. return QDF_STATUS_E_FAILURE;
  4613. if (dp_tx_tso_cmn_desc_pool_init(soc, num_pool, num_ext_desc))
  4614. return QDF_STATUS_E_FAILURE;
  4615. return QDF_STATUS_SUCCESS;
  4616. }
  4617. /**
  4618. * dp_tso_soc_detach() - de-initialize and free the TSO descriptors
  4619. * @txrx_soc: dp soc handle
  4620. *
  4621. * Return: QDF_STATUS - QDF_STATUS_SUCCESS
  4622. */
  4623. QDF_STATUS dp_tso_soc_detach(struct cdp_soc_t *txrx_soc)
  4624. {
  4625. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  4626. uint8_t num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  4627. dp_tx_tso_cmn_desc_pool_deinit(soc, num_pool);
  4628. dp_tx_tso_cmn_desc_pool_free(soc, num_pool);
  4629. return QDF_STATUS_SUCCESS;
  4630. }