dp_tx.c 147 KB

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