dp_main.c 281 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579
  1. /*
  2. * Copyright (c) 2016-2019 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include <qdf_types.h>
  19. #include <qdf_lock.h>
  20. #include <qdf_net_types.h>
  21. #include <qdf_lro.h>
  22. #include <qdf_module.h>
  23. #include <hal_hw_headers.h>
  24. #include <hal_api.h>
  25. #include <hif.h>
  26. #include <htt.h>
  27. #include <wdi_event.h>
  28. #include <queue.h>
  29. #include "dp_types.h"
  30. #include "dp_internal.h"
  31. #include "dp_tx.h"
  32. #include "dp_tx_desc.h"
  33. #include "dp_rx.h"
  34. #include "dp_rx_mon.h"
  35. #ifdef DP_RATETABLE_SUPPORT
  36. #include "dp_ratetable.h"
  37. #endif
  38. #include <cdp_txrx_handle.h>
  39. #include <wlan_cfg.h>
  40. #include "cdp_txrx_cmn_struct.h"
  41. #include "cdp_txrx_stats_struct.h"
  42. #include "cdp_txrx_cmn_reg.h"
  43. #include <qdf_util.h>
  44. #include "dp_peer.h"
  45. #include "dp_rx_mon.h"
  46. #include "htt_stats.h"
  47. #include "dp_htt.h"
  48. #include "htt_ppdu_stats.h"
  49. #include "qdf_mem.h" /* qdf_mem_malloc,free */
  50. #include "cfg_ucfg_api.h"
  51. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  52. #include "cdp_txrx_flow_ctrl_v2.h"
  53. #else
  54. static inline void
  55. cdp_dump_flow_pool_info(struct cdp_soc_t *soc)
  56. {
  57. return;
  58. }
  59. #endif
  60. #include "dp_ipa.h"
  61. #include "dp_cal_client_api.h"
  62. #ifdef FEATURE_WDS
  63. #include "dp_txrx_wds.h"
  64. #endif
  65. #ifdef ATH_SUPPORT_IQUE
  66. #include "dp_txrx_me.h"
  67. #endif
  68. #if defined(DP_CON_MON)
  69. #ifndef REMOVE_PKT_LOG
  70. #include <pktlog_ac_api.h>
  71. #include <pktlog_ac.h>
  72. #endif
  73. #endif
  74. #ifdef WLAN_FEATURE_DP_EVENT_HISTORY
  75. /*
  76. * If WLAN_CFG_INT_NUM_CONTEXTS is changed, HIF_NUM_INT_CONTEXTS
  77. * also should be updated accordingly
  78. */
  79. QDF_COMPILE_TIME_ASSERT(num_intr_grps,
  80. HIF_NUM_INT_CONTEXTS == WLAN_CFG_INT_NUM_CONTEXTS);
  81. /*
  82. * HIF_EVENT_HIST_MAX should always be power of 2
  83. */
  84. QDF_COMPILE_TIME_ASSERT(hif_event_history_size,
  85. (HIF_EVENT_HIST_MAX & (HIF_EVENT_HIST_MAX - 1)) == 0);
  86. #endif /* WLAN_FEATURE_DP_EVENT_HISTORY */
  87. /*
  88. * If WLAN_CFG_INT_NUM_CONTEXTS is changed,
  89. * WLAN_CFG_INT_NUM_CONTEXTS_MAX should also be updated
  90. */
  91. QDF_COMPILE_TIME_ASSERT(wlan_cfg_num_int_ctxs,
  92. WLAN_CFG_INT_NUM_CONTEXTS_MAX >=
  93. WLAN_CFG_INT_NUM_CONTEXTS);
  94. #ifdef WLAN_RX_PKT_CAPTURE_ENH
  95. #include "dp_rx_mon_feature.h"
  96. #else
  97. /*
  98. * dp_config_enh_rx_capture()- API to enable/disable enhanced rx capture
  99. * @pdev_handle: DP_PDEV handle
  100. * @val: user provided value
  101. *
  102. * Return: QDF_STATUS
  103. */
  104. static QDF_STATUS
  105. dp_config_enh_rx_capture(struct cdp_pdev *pdev_handle, uint8_t val)
  106. {
  107. return QDF_STATUS_E_INVAL;
  108. }
  109. #endif /* WLAN_RX_PKT_CAPTURE_ENH */
  110. #ifdef WLAN_TX_PKT_CAPTURE_ENH
  111. #include "dp_tx_capture.h"
  112. #else
  113. /*
  114. * dp_config_enh_tx_capture()- API to enable/disable enhanced tx capture
  115. * @pdev_handle: DP_PDEV handle
  116. * @val: user provided value
  117. *
  118. * Return: QDF_STATUS
  119. */
  120. static QDF_STATUS
  121. dp_config_enh_tx_capture(struct cdp_pdev *pdev_handle, uint8_t val)
  122. {
  123. return QDF_STATUS_E_INVAL;
  124. }
  125. #endif
  126. void *dp_soc_init(void *dpsoc, HTC_HANDLE htc_handle,
  127. struct hif_opaque_softc *hif_handle);
  128. static void dp_pdev_detach(struct cdp_pdev *txrx_pdev, int force);
  129. static struct dp_soc *
  130. dp_soc_attach(struct cdp_ctrl_objmgr_psoc *ctrl_psoc, HTC_HANDLE htc_handle,
  131. qdf_device_t qdf_osdev,
  132. struct ol_if_ops *ol_ops, uint16_t device_id);
  133. static void dp_pktlogmod_exit(struct dp_pdev *handle);
  134. static void *dp_peer_create_wifi3(struct cdp_vdev *vdev_handle,
  135. uint8_t *peer_mac_addr,
  136. struct cdp_ctrl_objmgr_peer *ctrl_peer);
  137. static void dp_peer_delete_wifi3(void *peer_handle, uint32_t bitmap);
  138. static void dp_ppdu_ring_reset(struct dp_pdev *pdev);
  139. static void dp_ppdu_ring_cfg(struct dp_pdev *pdev);
  140. static void dp_vdev_flush_peers(struct cdp_vdev *vdev_handle,
  141. bool unmap_only);
  142. #ifdef ENABLE_VERBOSE_DEBUG
  143. bool is_dp_verbose_debug_enabled;
  144. #endif
  145. static uint8_t dp_soc_ring_if_nss_offloaded(struct dp_soc *soc,
  146. enum hal_ring_type ring_type,
  147. int ring_num);
  148. #define DP_INTR_POLL_TIMER_MS 10
  149. /* Generic AST entry aging timer value */
  150. #define DP_AST_AGING_TIMER_DEFAULT_MS 1000
  151. #define DP_MCS_LENGTH (6*MAX_MCS)
  152. #define DP_CURR_FW_STATS_AVAIL 19
  153. #define DP_HTT_DBG_EXT_STATS_MAX 256
  154. #define DP_MAX_SLEEP_TIME 100
  155. #ifndef QCA_WIFI_3_0_EMU
  156. #define SUSPEND_DRAIN_WAIT 500
  157. #else
  158. #define SUSPEND_DRAIN_WAIT 3000
  159. #endif
  160. #ifdef IPA_OFFLOAD
  161. /* Exclude IPA rings from the interrupt context */
  162. #define TX_RING_MASK_VAL 0xb
  163. #define RX_RING_MASK_VAL 0x7
  164. #else
  165. #define TX_RING_MASK_VAL 0xF
  166. #define RX_RING_MASK_VAL 0xF
  167. #endif
  168. #define STR_MAXLEN 64
  169. #define RNG_ERR "SRNG setup failed for"
  170. /* Threshold for peer's cached buf queue beyond which frames are dropped */
  171. #define DP_RX_CACHED_BUFQ_THRESH 64
  172. /**
  173. * default_dscp_tid_map - Default DSCP-TID mapping
  174. *
  175. * DSCP TID
  176. * 000000 0
  177. * 001000 1
  178. * 010000 2
  179. * 011000 3
  180. * 100000 4
  181. * 101000 5
  182. * 110000 6
  183. * 111000 7
  184. */
  185. static uint8_t default_dscp_tid_map[DSCP_TID_MAP_MAX] = {
  186. 0, 0, 0, 0, 0, 0, 0, 0,
  187. 1, 1, 1, 1, 1, 1, 1, 1,
  188. 2, 2, 2, 2, 2, 2, 2, 2,
  189. 3, 3, 3, 3, 3, 3, 3, 3,
  190. 4, 4, 4, 4, 4, 4, 4, 4,
  191. 5, 5, 5, 5, 5, 5, 5, 5,
  192. 6, 6, 6, 6, 6, 6, 6, 6,
  193. 7, 7, 7, 7, 7, 7, 7, 7,
  194. };
  195. /**
  196. * default_pcp_tid_map - Default PCP-TID mapping
  197. *
  198. * PCP TID
  199. * 000 0
  200. * 001 1
  201. * 010 2
  202. * 011 3
  203. * 100 4
  204. * 101 5
  205. * 110 6
  206. * 111 7
  207. */
  208. static uint8_t default_pcp_tid_map[PCP_TID_MAP_MAX] = {
  209. 0, 1, 2, 3, 4, 5, 6, 7,
  210. };
  211. /**
  212. * @brief Cpu to tx ring map
  213. */
  214. uint8_t
  215. dp_cpu_ring_map[DP_NSS_CPU_RING_MAP_MAX][WLAN_CFG_INT_NUM_CONTEXTS_MAX] = {
  216. {0x0, 0x1, 0x2, 0x0, 0x0, 0x1, 0x2, 0x0, 0x0, 0x1, 0x2},
  217. {0x1, 0x2, 0x1, 0x2, 0x1, 0x2, 0x1, 0x2, 0x1, 0x2, 0x1},
  218. {0x0, 0x2, 0x0, 0x2, 0x0, 0x2, 0x0, 0x2, 0x0, 0x2, 0x0},
  219. {0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2},
  220. {0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3},
  221. #ifdef WLAN_TX_PKT_CAPTURE_ENH
  222. {0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1}
  223. #endif
  224. };
  225. /**
  226. * @brief Select the type of statistics
  227. */
  228. enum dp_stats_type {
  229. STATS_FW = 0,
  230. STATS_HOST = 1,
  231. STATS_TYPE_MAX = 2,
  232. };
  233. /**
  234. * @brief General Firmware statistics options
  235. *
  236. */
  237. enum dp_fw_stats {
  238. TXRX_FW_STATS_INVALID = -1,
  239. };
  240. /**
  241. * dp_stats_mapping_table - Firmware and Host statistics
  242. * currently supported
  243. */
  244. const int dp_stats_mapping_table[][STATS_TYPE_MAX] = {
  245. {HTT_DBG_EXT_STATS_RESET, TXRX_HOST_STATS_INVALID},
  246. {HTT_DBG_EXT_STATS_PDEV_TX, TXRX_HOST_STATS_INVALID},
  247. {HTT_DBG_EXT_STATS_PDEV_RX, TXRX_HOST_STATS_INVALID},
  248. {HTT_DBG_EXT_STATS_PDEV_TX_HWQ, TXRX_HOST_STATS_INVALID},
  249. {HTT_DBG_EXT_STATS_PDEV_TX_SCHED, TXRX_HOST_STATS_INVALID},
  250. {HTT_DBG_EXT_STATS_PDEV_ERROR, TXRX_HOST_STATS_INVALID},
  251. {HTT_DBG_EXT_STATS_PDEV_TQM, TXRX_HOST_STATS_INVALID},
  252. {HTT_DBG_EXT_STATS_TQM_CMDQ, TXRX_HOST_STATS_INVALID},
  253. {HTT_DBG_EXT_STATS_TX_DE_INFO, TXRX_HOST_STATS_INVALID},
  254. {HTT_DBG_EXT_STATS_PDEV_TX_RATE, TXRX_HOST_STATS_INVALID},
  255. {HTT_DBG_EXT_STATS_PDEV_RX_RATE, TXRX_HOST_STATS_INVALID},
  256. {TXRX_FW_STATS_INVALID, TXRX_HOST_STATS_INVALID},
  257. {HTT_DBG_EXT_STATS_TX_SELFGEN_INFO, TXRX_HOST_STATS_INVALID},
  258. {HTT_DBG_EXT_STATS_TX_MU_HWQ, TXRX_HOST_STATS_INVALID},
  259. {HTT_DBG_EXT_STATS_RING_IF_INFO, TXRX_HOST_STATS_INVALID},
  260. {HTT_DBG_EXT_STATS_SRNG_INFO, TXRX_HOST_STATS_INVALID},
  261. {HTT_DBG_EXT_STATS_SFM_INFO, TXRX_HOST_STATS_INVALID},
  262. {HTT_DBG_EXT_STATS_PDEV_TX_MU, TXRX_HOST_STATS_INVALID},
  263. {HTT_DBG_EXT_STATS_ACTIVE_PEERS_LIST, TXRX_HOST_STATS_INVALID},
  264. /* Last ENUM for HTT FW STATS */
  265. {DP_HTT_DBG_EXT_STATS_MAX, TXRX_HOST_STATS_INVALID},
  266. {TXRX_FW_STATS_INVALID, TXRX_CLEAR_STATS},
  267. {TXRX_FW_STATS_INVALID, TXRX_RX_RATE_STATS},
  268. {TXRX_FW_STATS_INVALID, TXRX_TX_RATE_STATS},
  269. {TXRX_FW_STATS_INVALID, TXRX_TX_HOST_STATS},
  270. {TXRX_FW_STATS_INVALID, TXRX_RX_HOST_STATS},
  271. {TXRX_FW_STATS_INVALID, TXRX_AST_STATS},
  272. {TXRX_FW_STATS_INVALID, TXRX_SRNG_PTR_STATS},
  273. {TXRX_FW_STATS_INVALID, TXRX_RX_MON_STATS},
  274. {TXRX_FW_STATS_INVALID, TXRX_REO_QUEUE_STATS},
  275. {TXRX_FW_STATS_INVALID, TXRX_SOC_CFG_PARAMS},
  276. {TXRX_FW_STATS_INVALID, TXRX_PDEV_CFG_PARAMS},
  277. {TXRX_FW_STATS_INVALID, TXRX_SOC_INTERRUPT_STATS},
  278. };
  279. /* MCL specific functions */
  280. #if defined(DP_CON_MON)
  281. /**
  282. * dp_soc_get_mon_mask_for_interrupt_mode() - get mon mode mask for intr mode
  283. * @soc: pointer to dp_soc handle
  284. * @intr_ctx_num: interrupt context number for which mon mask is needed
  285. *
  286. * For MCL, monitor mode rings are being processed in timer contexts (polled).
  287. * This function is returning 0, since in interrupt mode(softirq based RX),
  288. * we donot want to process monitor mode rings in a softirq.
  289. *
  290. * So, in case packet log is enabled for SAP/STA/P2P modes,
  291. * regular interrupt processing will not process monitor mode rings. It would be
  292. * done in a separate timer context.
  293. *
  294. * Return: 0
  295. */
  296. static inline
  297. uint32_t dp_soc_get_mon_mask_for_interrupt_mode(struct dp_soc *soc, int intr_ctx_num)
  298. {
  299. return 0;
  300. }
  301. /*
  302. * dp_service_mon_rings()- timer to reap monitor rings
  303. * reqd as we are not getting ppdu end interrupts
  304. * @arg: SoC Handle
  305. *
  306. * Return:
  307. *
  308. */
  309. static void dp_service_mon_rings(void *arg)
  310. {
  311. struct dp_soc *soc = (struct dp_soc *)arg;
  312. int ring = 0, work_done, mac_id;
  313. struct dp_pdev *pdev = NULL;
  314. for (ring = 0 ; ring < MAX_PDEV_CNT; ring++) {
  315. pdev = soc->pdev_list[ring];
  316. if (!pdev)
  317. continue;
  318. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  319. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id,
  320. pdev->pdev_id);
  321. work_done = dp_mon_process(soc, mac_for_pdev,
  322. QCA_NAPI_BUDGET);
  323. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  324. FL("Reaped %d descs from Monitor rings"),
  325. work_done);
  326. }
  327. }
  328. qdf_timer_mod(&soc->mon_reap_timer, DP_INTR_POLL_TIMER_MS);
  329. }
  330. #ifndef REMOVE_PKT_LOG
  331. /**
  332. * dp_pkt_log_init() - API to initialize packet log
  333. * @soc_hdl: Datapath soc handle
  334. * @pdev_id: id of data path pdev handle
  335. * @scn: HIF context
  336. *
  337. * Return: none
  338. */
  339. void dp_pkt_log_init(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, void *scn)
  340. {
  341. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  342. struct dp_pdev *handle =
  343. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  344. if (!handle) {
  345. dp_err("pdev handle is NULL");
  346. return;
  347. }
  348. if (handle->pkt_log_init) {
  349. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  350. "%s: Packet log not initialized", __func__);
  351. return;
  352. }
  353. pktlog_sethandle(&handle->pl_dev, scn);
  354. pktlog_set_callback_regtype(PKTLOG_DEFAULT_CALLBACK_REGISTRATION);
  355. if (pktlogmod_init(scn)) {
  356. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  357. "%s: pktlogmod_init failed", __func__);
  358. handle->pkt_log_init = false;
  359. } else {
  360. handle->pkt_log_init = true;
  361. }
  362. }
  363. /**
  364. * dp_pkt_log_con_service() - connect packet log service
  365. * @soc_hdl: Datapath soc handle
  366. * @pdev_id: id of data path pdev handle
  367. * @scn: device context
  368. *
  369. * Return: none
  370. */
  371. static void dp_pkt_log_con_service(struct cdp_soc_t *soc_hdl,
  372. uint8_t pdev_id, void *scn)
  373. {
  374. dp_pkt_log_init(soc_hdl, pdev_id, scn);
  375. pktlog_htc_attach();
  376. }
  377. /**
  378. * dp_get_num_rx_contexts() - get number of RX contexts
  379. * @soc_hdl: cdp opaque soc handle
  380. *
  381. * Return: number of RX contexts
  382. */
  383. static int dp_get_num_rx_contexts(struct cdp_soc_t *soc_hdl)
  384. {
  385. int i;
  386. int num_rx_contexts = 0;
  387. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  388. for (i = 0; i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++)
  389. if (wlan_cfg_get_rx_ring_mask(soc->wlan_cfg_ctx, i))
  390. num_rx_contexts++;
  391. return num_rx_contexts;
  392. }
  393. /**
  394. * dp_pktlogmod_exit() - API to cleanup pktlog info
  395. * @handle: Pdev handle
  396. *
  397. * Return: none
  398. */
  399. static void dp_pktlogmod_exit(struct dp_pdev *handle)
  400. {
  401. struct hif_opaque_softc *scn = (void *)handle->soc->hif_handle;
  402. if (!scn) {
  403. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  404. "%s: Invalid hif(scn) handle", __func__);
  405. return;
  406. }
  407. pktlogmod_exit(scn);
  408. handle->pkt_log_init = false;
  409. }
  410. #endif
  411. #else
  412. static void dp_pktlogmod_exit(struct dp_pdev *handle) { }
  413. /**
  414. * dp_soc_get_mon_mask_for_interrupt_mode() - get mon mode mask for intr mode
  415. * @soc: pointer to dp_soc handle
  416. * @intr_ctx_num: interrupt context number for which mon mask is needed
  417. *
  418. * Return: mon mask value
  419. */
  420. static inline
  421. uint32_t dp_soc_get_mon_mask_for_interrupt_mode(struct dp_soc *soc, int intr_ctx_num)
  422. {
  423. return wlan_cfg_get_rx_mon_ring_mask(soc->wlan_cfg_ctx, intr_ctx_num);
  424. }
  425. #endif
  426. /**
  427. * dp_get_dp_vdev_from_cdp_vdev() - get dp_vdev from cdp_vdev by type-casting
  428. * @cdp_opaque_vdev: pointer to cdp_vdev
  429. *
  430. * Return: pointer to dp_vdev
  431. */
  432. static
  433. struct dp_vdev *dp_get_dp_vdev_from_cdp_vdev(struct cdp_vdev *cdp_opaque_vdev)
  434. {
  435. return (struct dp_vdev *)cdp_opaque_vdev;
  436. }
  437. static int dp_peer_add_ast_wifi3(struct cdp_soc_t *soc_hdl,
  438. struct cdp_peer *peer_hdl,
  439. uint8_t *mac_addr,
  440. enum cdp_txrx_ast_entry_type type,
  441. uint32_t flags)
  442. {
  443. return dp_peer_add_ast((struct dp_soc *)soc_hdl,
  444. (struct dp_peer *)peer_hdl,
  445. mac_addr,
  446. type,
  447. flags);
  448. }
  449. static int dp_peer_update_ast_wifi3(struct cdp_soc_t *soc_hdl,
  450. struct cdp_peer *peer_hdl,
  451. uint8_t *wds_macaddr,
  452. uint32_t flags)
  453. {
  454. int status = -1;
  455. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  456. struct dp_ast_entry *ast_entry = NULL;
  457. struct dp_peer *peer = (struct dp_peer *)peer_hdl;
  458. qdf_spin_lock_bh(&soc->ast_lock);
  459. ast_entry = dp_peer_ast_hash_find_by_pdevid(soc, wds_macaddr,
  460. peer->vdev->pdev->pdev_id);
  461. if (ast_entry) {
  462. status = dp_peer_update_ast(soc,
  463. peer,
  464. ast_entry, flags);
  465. }
  466. qdf_spin_unlock_bh(&soc->ast_lock);
  467. return status;
  468. }
  469. /*
  470. * dp_wds_reset_ast_wifi3() - Reset the is_active param for ast entry
  471. * @soc_handle: Datapath SOC handle
  472. * @wds_macaddr: WDS entry MAC Address
  473. * Return: None
  474. */
  475. static void dp_wds_reset_ast_wifi3(struct cdp_soc_t *soc_hdl,
  476. uint8_t *wds_macaddr,
  477. uint8_t *peer_mac_addr,
  478. void *vdev_handle)
  479. {
  480. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  481. struct dp_ast_entry *ast_entry = NULL;
  482. struct dp_ast_entry *tmp_ast_entry;
  483. struct dp_peer *peer;
  484. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  485. struct dp_pdev *pdev;
  486. if (!vdev)
  487. return;
  488. pdev = vdev->pdev;
  489. if (peer_mac_addr) {
  490. peer = dp_peer_find_hash_find(soc, peer_mac_addr,
  491. 0, vdev->vdev_id);
  492. if (!peer)
  493. return;
  494. qdf_spin_lock_bh(&soc->ast_lock);
  495. DP_PEER_ITERATE_ASE_LIST(peer, ast_entry, tmp_ast_entry) {
  496. if ((ast_entry->type == CDP_TXRX_AST_TYPE_WDS_HM) ||
  497. (ast_entry->type == CDP_TXRX_AST_TYPE_WDS_HM_SEC))
  498. dp_peer_del_ast(soc, ast_entry);
  499. }
  500. qdf_spin_unlock_bh(&soc->ast_lock);
  501. dp_peer_unref_delete(peer);
  502. } else if (wds_macaddr) {
  503. qdf_spin_lock_bh(&soc->ast_lock);
  504. ast_entry = dp_peer_ast_hash_find_by_pdevid(soc, wds_macaddr,
  505. pdev->pdev_id);
  506. if (ast_entry) {
  507. if ((ast_entry->type == CDP_TXRX_AST_TYPE_WDS_HM) ||
  508. (ast_entry->type == CDP_TXRX_AST_TYPE_WDS_HM_SEC))
  509. dp_peer_del_ast(soc, ast_entry);
  510. }
  511. qdf_spin_unlock_bh(&soc->ast_lock);
  512. }
  513. }
  514. /*
  515. * dp_wds_reset_ast_table_wifi3() - Reset the is_active param for all ast entry
  516. * @soc: Datapath SOC handle
  517. *
  518. * Return: None
  519. */
  520. static void dp_wds_reset_ast_table_wifi3(struct cdp_soc_t *soc_hdl,
  521. void *vdev_hdl)
  522. {
  523. struct dp_soc *soc = (struct dp_soc *) soc_hdl;
  524. struct dp_pdev *pdev;
  525. struct dp_vdev *vdev;
  526. struct dp_peer *peer;
  527. struct dp_ast_entry *ase, *temp_ase;
  528. int i;
  529. qdf_spin_lock_bh(&soc->ast_lock);
  530. for (i = 0; i < MAX_PDEV_CNT && soc->pdev_list[i]; i++) {
  531. pdev = soc->pdev_list[i];
  532. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  533. DP_PDEV_ITERATE_VDEV_LIST(pdev, vdev) {
  534. DP_VDEV_ITERATE_PEER_LIST(vdev, peer) {
  535. DP_PEER_ITERATE_ASE_LIST(peer, ase, temp_ase) {
  536. if ((ase->type ==
  537. CDP_TXRX_AST_TYPE_WDS_HM) ||
  538. (ase->type ==
  539. CDP_TXRX_AST_TYPE_WDS_HM_SEC))
  540. dp_peer_del_ast(soc, ase);
  541. }
  542. }
  543. }
  544. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  545. }
  546. qdf_spin_unlock_bh(&soc->ast_lock);
  547. }
  548. /*
  549. * dp_wds_flush_ast_table_wifi3() - Delete all wds and hmwds ast entry
  550. * @soc: Datapath SOC handle
  551. *
  552. * Return: None
  553. */
  554. static void dp_wds_flush_ast_table_wifi3(struct cdp_soc_t *soc_hdl)
  555. {
  556. struct dp_soc *soc = (struct dp_soc *) soc_hdl;
  557. struct dp_pdev *pdev;
  558. struct dp_vdev *vdev;
  559. struct dp_peer *peer;
  560. struct dp_ast_entry *ase, *temp_ase;
  561. int i;
  562. qdf_spin_lock_bh(&soc->ast_lock);
  563. for (i = 0; i < MAX_PDEV_CNT && soc->pdev_list[i]; i++) {
  564. pdev = soc->pdev_list[i];
  565. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  566. DP_PDEV_ITERATE_VDEV_LIST(pdev, vdev) {
  567. DP_VDEV_ITERATE_PEER_LIST(vdev, peer) {
  568. DP_PEER_ITERATE_ASE_LIST(peer, ase, temp_ase) {
  569. if ((ase->type ==
  570. CDP_TXRX_AST_TYPE_STATIC) ||
  571. (ase->type ==
  572. CDP_TXRX_AST_TYPE_SELF) ||
  573. (ase->type ==
  574. CDP_TXRX_AST_TYPE_STA_BSS))
  575. continue;
  576. dp_peer_del_ast(soc, ase);
  577. }
  578. }
  579. }
  580. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  581. }
  582. qdf_spin_unlock_bh(&soc->ast_lock);
  583. }
  584. /**
  585. * dp_peer_get_ast_info_by_soc_wifi3() - search the soc AST hash table
  586. * and return ast entry information
  587. * of first ast entry found in the
  588. * table with given mac address
  589. *
  590. * @soc : data path soc handle
  591. * @ast_mac_addr : AST entry mac address
  592. * @ast_entry_info : ast entry information
  593. *
  594. * return : true if ast entry found with ast_mac_addr
  595. * false if ast entry not found
  596. */
  597. static bool dp_peer_get_ast_info_by_soc_wifi3
  598. (struct cdp_soc_t *soc_hdl,
  599. uint8_t *ast_mac_addr,
  600. struct cdp_ast_entry_info *ast_entry_info)
  601. {
  602. struct dp_ast_entry *ast_entry = NULL;
  603. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  604. qdf_spin_lock_bh(&soc->ast_lock);
  605. ast_entry = dp_peer_ast_hash_find_soc(soc, ast_mac_addr);
  606. if (!ast_entry || !ast_entry->peer) {
  607. qdf_spin_unlock_bh(&soc->ast_lock);
  608. return false;
  609. }
  610. if (ast_entry->delete_in_progress && !ast_entry->callback) {
  611. qdf_spin_unlock_bh(&soc->ast_lock);
  612. return false;
  613. }
  614. ast_entry_info->type = ast_entry->type;
  615. ast_entry_info->pdev_id = ast_entry->pdev_id;
  616. ast_entry_info->vdev_id = ast_entry->peer->vdev->vdev_id;
  617. ast_entry_info->peer_id = ast_entry->peer->peer_ids[0];
  618. qdf_mem_copy(&ast_entry_info->peer_mac_addr[0],
  619. &ast_entry->peer->mac_addr.raw[0],
  620. QDF_MAC_ADDR_SIZE);
  621. qdf_spin_unlock_bh(&soc->ast_lock);
  622. return true;
  623. }
  624. /**
  625. * dp_peer_get_ast_info_by_pdevid_wifi3() - search the soc AST hash table
  626. * and return ast entry information
  627. * if mac address and pdev_id matches
  628. *
  629. * @soc : data path soc handle
  630. * @ast_mac_addr : AST entry mac address
  631. * @pdev_id : pdev_id
  632. * @ast_entry_info : ast entry information
  633. *
  634. * return : true if ast entry found with ast_mac_addr
  635. * false if ast entry not found
  636. */
  637. static bool dp_peer_get_ast_info_by_pdevid_wifi3
  638. (struct cdp_soc_t *soc_hdl,
  639. uint8_t *ast_mac_addr,
  640. uint8_t pdev_id,
  641. struct cdp_ast_entry_info *ast_entry_info)
  642. {
  643. struct dp_ast_entry *ast_entry;
  644. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  645. qdf_spin_lock_bh(&soc->ast_lock);
  646. ast_entry = dp_peer_ast_hash_find_by_pdevid(soc, ast_mac_addr, pdev_id);
  647. if (!ast_entry || !ast_entry->peer) {
  648. qdf_spin_unlock_bh(&soc->ast_lock);
  649. return false;
  650. }
  651. if (ast_entry->delete_in_progress && !ast_entry->callback) {
  652. qdf_spin_unlock_bh(&soc->ast_lock);
  653. return false;
  654. }
  655. ast_entry_info->type = ast_entry->type;
  656. ast_entry_info->pdev_id = ast_entry->pdev_id;
  657. ast_entry_info->vdev_id = ast_entry->peer->vdev->vdev_id;
  658. ast_entry_info->peer_id = ast_entry->peer->peer_ids[0];
  659. qdf_mem_copy(&ast_entry_info->peer_mac_addr[0],
  660. &ast_entry->peer->mac_addr.raw[0],
  661. QDF_MAC_ADDR_SIZE);
  662. qdf_spin_unlock_bh(&soc->ast_lock);
  663. return true;
  664. }
  665. /**
  666. * dp_peer_ast_entry_del_by_soc() - delete the ast entry from soc AST hash table
  667. * with given mac address
  668. *
  669. * @soc : data path soc handle
  670. * @ast_mac_addr : AST entry mac address
  671. * @callback : callback function to called on ast delete response from FW
  672. * @cookie : argument to be passed to callback
  673. *
  674. * return : QDF_STATUS_SUCCESS if ast entry found with ast_mac_addr and delete
  675. * is sent
  676. * QDF_STATUS_E_INVAL false if ast entry not found
  677. */
  678. static QDF_STATUS dp_peer_ast_entry_del_by_soc(struct cdp_soc_t *soc_handle,
  679. uint8_t *mac_addr,
  680. txrx_ast_free_cb callback,
  681. void *cookie)
  682. {
  683. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  684. struct dp_ast_entry *ast_entry = NULL;
  685. txrx_ast_free_cb cb = NULL;
  686. void *arg = NULL;
  687. qdf_spin_lock_bh(&soc->ast_lock);
  688. ast_entry = dp_peer_ast_hash_find_soc(soc, mac_addr);
  689. if (!ast_entry) {
  690. qdf_spin_unlock_bh(&soc->ast_lock);
  691. return -QDF_STATUS_E_INVAL;
  692. }
  693. if (ast_entry->callback) {
  694. cb = ast_entry->callback;
  695. arg = ast_entry->cookie;
  696. }
  697. ast_entry->callback = callback;
  698. ast_entry->cookie = cookie;
  699. /*
  700. * if delete_in_progress is set AST delete is sent to target
  701. * and host is waiting for response should not send delete
  702. * again
  703. */
  704. if (!ast_entry->delete_in_progress)
  705. dp_peer_del_ast(soc, ast_entry);
  706. qdf_spin_unlock_bh(&soc->ast_lock);
  707. if (cb) {
  708. cb(soc->ctrl_psoc,
  709. dp_soc_to_cdp_soc(soc),
  710. arg,
  711. CDP_TXRX_AST_DELETE_IN_PROGRESS);
  712. }
  713. return QDF_STATUS_SUCCESS;
  714. }
  715. /**
  716. * dp_peer_ast_entry_del_by_pdev() - delete the ast entry from soc AST hash
  717. * table if mac address and pdev_id matches
  718. *
  719. * @soc : data path soc handle
  720. * @ast_mac_addr : AST entry mac address
  721. * @pdev_id : pdev id
  722. * @callback : callback function to called on ast delete response from FW
  723. * @cookie : argument to be passed to callback
  724. *
  725. * return : QDF_STATUS_SUCCESS if ast entry found with ast_mac_addr and delete
  726. * is sent
  727. * QDF_STATUS_E_INVAL false if ast entry not found
  728. */
  729. static QDF_STATUS dp_peer_ast_entry_del_by_pdev(struct cdp_soc_t *soc_handle,
  730. uint8_t *mac_addr,
  731. uint8_t pdev_id,
  732. txrx_ast_free_cb callback,
  733. void *cookie)
  734. {
  735. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  736. struct dp_ast_entry *ast_entry;
  737. txrx_ast_free_cb cb = NULL;
  738. void *arg = NULL;
  739. qdf_spin_lock_bh(&soc->ast_lock);
  740. ast_entry = dp_peer_ast_hash_find_by_pdevid(soc, mac_addr, pdev_id);
  741. if (!ast_entry) {
  742. qdf_spin_unlock_bh(&soc->ast_lock);
  743. return -QDF_STATUS_E_INVAL;
  744. }
  745. if (ast_entry->callback) {
  746. cb = ast_entry->callback;
  747. arg = ast_entry->cookie;
  748. }
  749. ast_entry->callback = callback;
  750. ast_entry->cookie = cookie;
  751. /*
  752. * if delete_in_progress is set AST delete is sent to target
  753. * and host is waiting for response should not sent delete
  754. * again
  755. */
  756. if (!ast_entry->delete_in_progress)
  757. dp_peer_del_ast(soc, ast_entry);
  758. qdf_spin_unlock_bh(&soc->ast_lock);
  759. if (cb) {
  760. cb(soc->ctrl_psoc,
  761. dp_soc_to_cdp_soc(soc),
  762. arg,
  763. CDP_TXRX_AST_DELETE_IN_PROGRESS);
  764. }
  765. return QDF_STATUS_SUCCESS;
  766. }
  767. /**
  768. * dp_srng_find_ring_in_mask() - find which ext_group a ring belongs
  769. * @ring_num: ring num of the ring being queried
  770. * @grp_mask: the grp_mask array for the ring type in question.
  771. *
  772. * The grp_mask array is indexed by group number and the bit fields correspond
  773. * to ring numbers. We are finding which interrupt group a ring belongs to.
  774. *
  775. * Return: the index in the grp_mask array with the ring number.
  776. * -QDF_STATUS_E_NOENT if no entry is found
  777. */
  778. static int dp_srng_find_ring_in_mask(int ring_num, int *grp_mask)
  779. {
  780. int ext_group_num;
  781. int mask = 1 << ring_num;
  782. for (ext_group_num = 0; ext_group_num < WLAN_CFG_INT_NUM_CONTEXTS;
  783. ext_group_num++) {
  784. if (mask & grp_mask[ext_group_num])
  785. return ext_group_num;
  786. }
  787. return -QDF_STATUS_E_NOENT;
  788. }
  789. static int dp_srng_calculate_msi_group(struct dp_soc *soc,
  790. enum hal_ring_type ring_type,
  791. int ring_num)
  792. {
  793. int *grp_mask;
  794. switch (ring_type) {
  795. case WBM2SW_RELEASE:
  796. /* dp_tx_comp_handler - soc->tx_comp_ring */
  797. if (ring_num < 3)
  798. grp_mask = &soc->wlan_cfg_ctx->int_tx_ring_mask[0];
  799. /* dp_rx_wbm_err_process - soc->rx_rel_ring */
  800. else if (ring_num == 3) {
  801. /* sw treats this as a separate ring type */
  802. grp_mask = &soc->wlan_cfg_ctx->
  803. int_rx_wbm_rel_ring_mask[0];
  804. ring_num = 0;
  805. } else {
  806. qdf_assert(0);
  807. return -QDF_STATUS_E_NOENT;
  808. }
  809. break;
  810. case REO_EXCEPTION:
  811. /* dp_rx_err_process - &soc->reo_exception_ring */
  812. grp_mask = &soc->wlan_cfg_ctx->int_rx_err_ring_mask[0];
  813. break;
  814. case REO_DST:
  815. /* dp_rx_process - soc->reo_dest_ring */
  816. grp_mask = &soc->wlan_cfg_ctx->int_rx_ring_mask[0];
  817. break;
  818. case REO_STATUS:
  819. /* dp_reo_status_ring_handler - soc->reo_status_ring */
  820. grp_mask = &soc->wlan_cfg_ctx->int_reo_status_ring_mask[0];
  821. break;
  822. /* dp_rx_mon_status_srng_process - pdev->rxdma_mon_status_ring*/
  823. case RXDMA_MONITOR_STATUS:
  824. /* dp_rx_mon_dest_process - pdev->rxdma_mon_dst_ring */
  825. case RXDMA_MONITOR_DST:
  826. /* dp_mon_process */
  827. grp_mask = &soc->wlan_cfg_ctx->int_rx_mon_ring_mask[0];
  828. break;
  829. case RXDMA_DST:
  830. /* dp_rxdma_err_process */
  831. grp_mask = &soc->wlan_cfg_ctx->int_rxdma2host_ring_mask[0];
  832. break;
  833. case RXDMA_BUF:
  834. grp_mask = &soc->wlan_cfg_ctx->int_host2rxdma_ring_mask[0];
  835. break;
  836. case RXDMA_MONITOR_BUF:
  837. /* TODO: support low_thresh interrupt */
  838. return -QDF_STATUS_E_NOENT;
  839. break;
  840. case TCL_DATA:
  841. case TCL_CMD:
  842. case REO_CMD:
  843. case SW2WBM_RELEASE:
  844. case WBM_IDLE_LINK:
  845. /* normally empty SW_TO_HW rings */
  846. return -QDF_STATUS_E_NOENT;
  847. break;
  848. case TCL_STATUS:
  849. case REO_REINJECT:
  850. /* misc unused rings */
  851. return -QDF_STATUS_E_NOENT;
  852. break;
  853. case CE_SRC:
  854. case CE_DST:
  855. case CE_DST_STATUS:
  856. /* CE_rings - currently handled by hif */
  857. default:
  858. return -QDF_STATUS_E_NOENT;
  859. break;
  860. }
  861. return dp_srng_find_ring_in_mask(ring_num, grp_mask);
  862. }
  863. static void dp_srng_msi_setup(struct dp_soc *soc, struct hal_srng_params
  864. *ring_params, int ring_type, int ring_num)
  865. {
  866. int msi_group_number;
  867. int msi_data_count;
  868. int ret;
  869. uint32_t msi_data_start, msi_irq_start, addr_low, addr_high;
  870. ret = pld_get_user_msi_assignment(soc->osdev->dev, "DP",
  871. &msi_data_count, &msi_data_start,
  872. &msi_irq_start);
  873. if (ret)
  874. return;
  875. msi_group_number = dp_srng_calculate_msi_group(soc, ring_type,
  876. ring_num);
  877. if (msi_group_number < 0) {
  878. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
  879. FL("ring not part of an ext_group; ring_type: %d,ring_num %d"),
  880. ring_type, ring_num);
  881. ring_params->msi_addr = 0;
  882. ring_params->msi_data = 0;
  883. return;
  884. }
  885. if (msi_group_number > msi_data_count) {
  886. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_WARN,
  887. FL("2 msi_groups will share an msi; msi_group_num %d"),
  888. msi_group_number);
  889. QDF_ASSERT(0);
  890. }
  891. pld_get_msi_address(soc->osdev->dev, &addr_low, &addr_high);
  892. ring_params->msi_addr = addr_low;
  893. ring_params->msi_addr |= (qdf_dma_addr_t)(((uint64_t)addr_high) << 32);
  894. ring_params->msi_data = (msi_group_number % msi_data_count)
  895. + msi_data_start;
  896. ring_params->flags |= HAL_SRNG_MSI_INTR;
  897. }
  898. /**
  899. * dp_print_ast_stats() - Dump AST table contents
  900. * @soc: Datapath soc handle
  901. *
  902. * return void
  903. */
  904. #ifdef FEATURE_AST
  905. void dp_print_ast_stats(struct dp_soc *soc)
  906. {
  907. uint8_t i;
  908. uint8_t num_entries = 0;
  909. struct dp_vdev *vdev;
  910. struct dp_pdev *pdev;
  911. struct dp_peer *peer;
  912. struct dp_ast_entry *ase, *tmp_ase;
  913. char type[CDP_TXRX_AST_TYPE_MAX][10] = {
  914. "NONE", "STATIC", "SELF", "WDS", "MEC", "HMWDS", "BSS",
  915. "DA", "HMWDS_SEC"};
  916. DP_PRINT_STATS("AST Stats:");
  917. DP_PRINT_STATS(" Entries Added = %d", soc->stats.ast.added);
  918. DP_PRINT_STATS(" Entries Deleted = %d", soc->stats.ast.deleted);
  919. DP_PRINT_STATS(" Entries Agedout = %d", soc->stats.ast.aged_out);
  920. DP_PRINT_STATS(" Entries MAP ERR = %d", soc->stats.ast.map_err);
  921. DP_PRINT_STATS("AST Table:");
  922. qdf_spin_lock_bh(&soc->ast_lock);
  923. for (i = 0; i < MAX_PDEV_CNT && soc->pdev_list[i]; i++) {
  924. pdev = soc->pdev_list[i];
  925. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  926. DP_PDEV_ITERATE_VDEV_LIST(pdev, vdev) {
  927. DP_VDEV_ITERATE_PEER_LIST(vdev, peer) {
  928. DP_PEER_ITERATE_ASE_LIST(peer, ase, tmp_ase) {
  929. DP_PRINT_STATS("%6d mac_addr = %pM"
  930. " peer_mac_addr = %pM"
  931. " peer_id = %u"
  932. " type = %s"
  933. " next_hop = %d"
  934. " is_active = %d"
  935. " ast_idx = %d"
  936. " ast_hash = %d"
  937. " delete_in_progress = %d"
  938. " pdev_id = %d"
  939. " vdev_id = %d",
  940. ++num_entries,
  941. ase->mac_addr.raw,
  942. ase->peer->mac_addr.raw,
  943. ase->peer->peer_ids[0],
  944. type[ase->type],
  945. ase->next_hop,
  946. ase->is_active,
  947. ase->ast_idx,
  948. ase->ast_hash_value,
  949. ase->delete_in_progress,
  950. ase->pdev_id,
  951. vdev->vdev_id);
  952. }
  953. }
  954. }
  955. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  956. }
  957. qdf_spin_unlock_bh(&soc->ast_lock);
  958. }
  959. #else
  960. void dp_print_ast_stats(struct dp_soc *soc)
  961. {
  962. DP_PRINT_STATS("AST Stats not available.Enable FEATURE_AST");
  963. return;
  964. }
  965. #endif
  966. /**
  967. * dp_print_peer_table() - Dump all Peer stats
  968. * @vdev: Datapath Vdev handle
  969. *
  970. * return void
  971. */
  972. static void dp_print_peer_table(struct dp_vdev *vdev)
  973. {
  974. struct dp_peer *peer = NULL;
  975. DP_PRINT_STATS("Dumping Peer Table Stats:");
  976. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  977. if (!peer) {
  978. DP_PRINT_STATS("Invalid Peer");
  979. return;
  980. }
  981. DP_PRINT_STATS(" peer_mac_addr = %pM"
  982. " nawds_enabled = %d"
  983. " bss_peer = %d"
  984. " wds_enabled = %d"
  985. " tx_cap_enabled = %d"
  986. " rx_cap_enabled = %d"
  987. " delete in progress = %d"
  988. " peer id = %d",
  989. peer->mac_addr.raw,
  990. peer->nawds_enabled,
  991. peer->bss_peer,
  992. peer->wds_enabled,
  993. peer->tx_cap_enabled,
  994. peer->rx_cap_enabled,
  995. peer->delete_in_progress,
  996. peer->peer_ids[0]);
  997. }
  998. }
  999. #ifdef WLAN_DP_PER_RING_TYPE_CONFIG
  1000. /**
  1001. * dp_srng_configure_interrupt_thresholds() - Retrieve interrupt
  1002. * threshold values from the wlan_srng_cfg table for each ring type
  1003. * @soc: device handle
  1004. * @ring_params: per ring specific parameters
  1005. * @ring_type: Ring type
  1006. * @ring_num: Ring number for a given ring type
  1007. *
  1008. * Fill the ring params with the interrupt threshold
  1009. * configuration parameters available in the per ring type wlan_srng_cfg
  1010. * table.
  1011. *
  1012. * Return: None
  1013. */
  1014. static void
  1015. dp_srng_configure_interrupt_thresholds(struct dp_soc *soc,
  1016. struct hal_srng_params *ring_params,
  1017. int ring_type, int ring_num,
  1018. int num_entries)
  1019. {
  1020. if (ring_type == WBM2SW_RELEASE && (ring_num == 3)) {
  1021. ring_params->intr_timer_thres_us =
  1022. wlan_cfg_get_int_timer_threshold_other(soc->wlan_cfg_ctx);
  1023. ring_params->intr_batch_cntr_thres_entries =
  1024. wlan_cfg_get_int_batch_threshold_other(soc->wlan_cfg_ctx);
  1025. } else {
  1026. ring_params->intr_timer_thres_us =
  1027. soc->wlan_srng_cfg[ring_type].timer_threshold;
  1028. ring_params->intr_batch_cntr_thres_entries =
  1029. soc->wlan_srng_cfg[ring_type].batch_count_threshold;
  1030. }
  1031. ring_params->low_threshold =
  1032. soc->wlan_srng_cfg[ring_type].low_threshold;
  1033. if (ring_params->low_threshold)
  1034. ring_params->flags |= HAL_SRNG_LOW_THRES_INTR_ENABLE;
  1035. }
  1036. #else
  1037. static void
  1038. dp_srng_configure_interrupt_thresholds(struct dp_soc *soc,
  1039. struct hal_srng_params *ring_params,
  1040. int ring_type, int ring_num,
  1041. int num_entries)
  1042. {
  1043. if (ring_type == REO_DST) {
  1044. ring_params->intr_timer_thres_us =
  1045. wlan_cfg_get_int_timer_threshold_rx(soc->wlan_cfg_ctx);
  1046. ring_params->intr_batch_cntr_thres_entries =
  1047. wlan_cfg_get_int_batch_threshold_rx(soc->wlan_cfg_ctx);
  1048. } else if (ring_type == WBM2SW_RELEASE && (ring_num < 3)) {
  1049. ring_params->intr_timer_thres_us =
  1050. wlan_cfg_get_int_timer_threshold_tx(soc->wlan_cfg_ctx);
  1051. ring_params->intr_batch_cntr_thres_entries =
  1052. wlan_cfg_get_int_batch_threshold_tx(soc->wlan_cfg_ctx);
  1053. } else {
  1054. ring_params->intr_timer_thres_us =
  1055. wlan_cfg_get_int_timer_threshold_other(soc->wlan_cfg_ctx);
  1056. ring_params->intr_batch_cntr_thres_entries =
  1057. wlan_cfg_get_int_batch_threshold_other(soc->wlan_cfg_ctx);
  1058. }
  1059. /* Enable low threshold interrupts for rx buffer rings (regular and
  1060. * monitor buffer rings.
  1061. * TODO: See if this is required for any other ring
  1062. */
  1063. if ((ring_type == RXDMA_BUF) || (ring_type == RXDMA_MONITOR_BUF) ||
  1064. (ring_type == RXDMA_MONITOR_STATUS)) {
  1065. /* TODO: Setting low threshold to 1/8th of ring size
  1066. * see if this needs to be configurable
  1067. */
  1068. ring_params->low_threshold = num_entries >> 3;
  1069. ring_params->intr_timer_thres_us =
  1070. wlan_cfg_get_int_timer_threshold_rx(soc->wlan_cfg_ctx);
  1071. ring_params->flags |= HAL_SRNG_LOW_THRES_INTR_ENABLE;
  1072. ring_params->intr_batch_cntr_thres_entries = 0;
  1073. }
  1074. }
  1075. #endif
  1076. /**
  1077. * dp_srng_setup() - Internal function to setup SRNG rings used by data path
  1078. * @soc: datapath soc handle
  1079. * @srng: srng handle
  1080. * @ring_type: ring that needs to be configured
  1081. * @mac_id: mac number
  1082. * @num_entries: Total number of entries for a given ring
  1083. *
  1084. * Return: non-zero - failure/zero - success
  1085. */
  1086. static int dp_srng_setup(struct dp_soc *soc, struct dp_srng *srng,
  1087. int ring_type, int ring_num, int mac_id,
  1088. uint32_t num_entries, bool cached)
  1089. {
  1090. hal_soc_handle_t hal_soc = soc->hal_soc;
  1091. uint32_t entry_size = hal_srng_get_entrysize(hal_soc, ring_type);
  1092. /* TODO: See if we should get align size from hal */
  1093. uint32_t ring_base_align = 8;
  1094. struct hal_srng_params ring_params;
  1095. uint32_t max_entries = hal_srng_max_entries(hal_soc, ring_type);
  1096. /* TODO: Currently hal layer takes care of endianness related settings.
  1097. * See if these settings need to passed from DP layer
  1098. */
  1099. ring_params.flags = 0;
  1100. num_entries = (num_entries > max_entries) ? max_entries : num_entries;
  1101. srng->hal_srng = NULL;
  1102. srng->alloc_size = num_entries * entry_size;
  1103. srng->num_entries = num_entries;
  1104. if (!dp_is_soc_reinit(soc)) {
  1105. if (!cached) {
  1106. ring_params.ring_base_vaddr =
  1107. qdf_aligned_mem_alloc_consistent(
  1108. soc->osdev, &srng->alloc_size,
  1109. &srng->base_vaddr_unaligned,
  1110. &srng->base_paddr_unaligned,
  1111. &ring_params.ring_base_paddr,
  1112. ring_base_align);
  1113. } else {
  1114. ring_params.ring_base_vaddr = qdf_aligned_malloc(
  1115. &srng->alloc_size,
  1116. &srng->base_vaddr_unaligned,
  1117. &srng->base_paddr_unaligned,
  1118. &ring_params.ring_base_paddr,
  1119. ring_base_align);
  1120. }
  1121. if (!ring_params.ring_base_vaddr) {
  1122. dp_err("alloc failed - ring_type: %d, ring_num %d",
  1123. ring_type, ring_num);
  1124. return QDF_STATUS_E_NOMEM;
  1125. }
  1126. }
  1127. ring_params.ring_base_paddr = (qdf_dma_addr_t)qdf_align(
  1128. (unsigned long)(srng->base_paddr_unaligned),
  1129. ring_base_align);
  1130. ring_params.ring_base_vaddr = (void *)(
  1131. (unsigned long)(srng->base_vaddr_unaligned) +
  1132. ((unsigned long)(ring_params.ring_base_paddr) -
  1133. (unsigned long)(srng->base_paddr_unaligned)));
  1134. qdf_assert_always(ring_params.ring_base_vaddr);
  1135. ring_params.num_entries = num_entries;
  1136. dp_verbose_debug("Ring type: %d, num:%d vaddr %pK paddr %pK entries %u",
  1137. ring_type, ring_num,
  1138. (void *)ring_params.ring_base_vaddr,
  1139. (void *)ring_params.ring_base_paddr,
  1140. ring_params.num_entries);
  1141. if (soc->intr_mode == DP_INTR_MSI) {
  1142. dp_srng_msi_setup(soc, &ring_params, ring_type, ring_num);
  1143. dp_verbose_debug("Using MSI for ring_type: %d, ring_num %d",
  1144. ring_type, ring_num);
  1145. } else {
  1146. ring_params.msi_data = 0;
  1147. ring_params.msi_addr = 0;
  1148. dp_verbose_debug("Skipping MSI for ring_type: %d, ring_num %d",
  1149. ring_type, ring_num);
  1150. }
  1151. dp_srng_configure_interrupt_thresholds(soc, &ring_params,
  1152. ring_type, ring_num,
  1153. num_entries);
  1154. if (cached) {
  1155. ring_params.flags |= HAL_SRNG_CACHED_DESC;
  1156. srng->cached = 1;
  1157. }
  1158. srng->hal_srng = hal_srng_setup(hal_soc, ring_type, ring_num,
  1159. mac_id, &ring_params);
  1160. if (!srng->hal_srng) {
  1161. if (cached) {
  1162. qdf_mem_free(srng->base_vaddr_unaligned);
  1163. } else {
  1164. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  1165. srng->alloc_size,
  1166. srng->base_vaddr_unaligned,
  1167. srng->base_paddr_unaligned, 0);
  1168. }
  1169. }
  1170. return 0;
  1171. }
  1172. /*
  1173. * dp_srng_deinit() - Internal function to deinit SRNG rings used by data path
  1174. * @soc: DP SOC handle
  1175. * @srng: source ring structure
  1176. * @ring_type: type of ring
  1177. * @ring_num: ring number
  1178. *
  1179. * Return: None
  1180. */
  1181. static void dp_srng_deinit(struct dp_soc *soc, struct dp_srng *srng,
  1182. int ring_type, int ring_num)
  1183. {
  1184. if (!srng->hal_srng) {
  1185. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1186. FL("Ring type: %d, num:%d not setup"),
  1187. ring_type, ring_num);
  1188. return;
  1189. }
  1190. hal_srng_cleanup(soc->hal_soc, srng->hal_srng);
  1191. srng->hal_srng = NULL;
  1192. }
  1193. /**
  1194. * dp_srng_cleanup - Internal function to cleanup SRNG rings used by data path
  1195. * Any buffers allocated and attached to ring entries are expected to be freed
  1196. * before calling this function.
  1197. */
  1198. static void dp_srng_cleanup(struct dp_soc *soc, struct dp_srng *srng,
  1199. int ring_type, int ring_num)
  1200. {
  1201. if (!dp_is_soc_reinit(soc)) {
  1202. if (!srng->hal_srng && (srng->alloc_size == 0)) {
  1203. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1204. FL("Ring type: %d, num:%d not setup"),
  1205. ring_type, ring_num);
  1206. return;
  1207. }
  1208. if (srng->hal_srng) {
  1209. hal_srng_cleanup(soc->hal_soc, srng->hal_srng);
  1210. srng->hal_srng = NULL;
  1211. }
  1212. }
  1213. if (srng->alloc_size && srng->base_vaddr_unaligned) {
  1214. if (!srng->cached) {
  1215. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  1216. srng->alloc_size,
  1217. srng->base_vaddr_unaligned,
  1218. srng->base_paddr_unaligned, 0);
  1219. } else {
  1220. qdf_mem_free(srng->base_vaddr_unaligned);
  1221. }
  1222. srng->alloc_size = 0;
  1223. srng->base_vaddr_unaligned = NULL;
  1224. }
  1225. srng->hal_srng = NULL;
  1226. }
  1227. /* TODO: Need this interface from HIF */
  1228. void *hif_get_hal_handle(struct hif_opaque_softc *hif_handle);
  1229. #ifdef WLAN_FEATURE_DP_EVENT_HISTORY
  1230. int dp_srng_access_start(struct dp_intr *int_ctx, struct dp_soc *dp_soc,
  1231. hal_ring_handle_t hal_ring_hdl)
  1232. {
  1233. hal_soc_handle_t hal_soc = dp_soc->hal_soc;
  1234. uint32_t hp, tp;
  1235. uint8_t ring_id;
  1236. hal_get_sw_hptp(hal_soc, hal_ring_hdl, &tp, &hp);
  1237. ring_id = hal_srng_ring_id_get(hal_ring_hdl);
  1238. hif_record_event(dp_soc->hif_handle, int_ctx->dp_intr_id,
  1239. ring_id, hp, tp, HIF_EVENT_SRNG_ACCESS_START);
  1240. return hal_srng_access_start(hal_soc, hal_ring_hdl);
  1241. }
  1242. void dp_srng_access_end(struct dp_intr *int_ctx, struct dp_soc *dp_soc,
  1243. hal_ring_handle_t hal_ring_hdl)
  1244. {
  1245. hal_soc_handle_t hal_soc = dp_soc->hal_soc;
  1246. uint32_t hp, tp;
  1247. uint8_t ring_id;
  1248. hal_get_sw_hptp(hal_soc, hal_ring_hdl, &tp, &hp);
  1249. ring_id = hal_srng_ring_id_get(hal_ring_hdl);
  1250. hif_record_event(dp_soc->hif_handle, int_ctx->dp_intr_id,
  1251. ring_id, hp, tp, HIF_EVENT_SRNG_ACCESS_END);
  1252. return hal_srng_access_end(hal_soc, hal_ring_hdl);
  1253. }
  1254. #endif /* WLAN_FEATURE_DP_EVENT_HISTORY */
  1255. /*
  1256. * dp_service_srngs() - Top level interrupt handler for DP Ring interrupts
  1257. * @dp_ctx: DP SOC handle
  1258. * @budget: Number of frames/descriptors that can be processed in one shot
  1259. *
  1260. * Return: remaining budget/quota for the soc device
  1261. */
  1262. static uint32_t dp_service_srngs(void *dp_ctx, uint32_t dp_budget)
  1263. {
  1264. struct dp_intr *int_ctx = (struct dp_intr *)dp_ctx;
  1265. struct dp_intr_stats *intr_stats = &int_ctx->intr_stats;
  1266. struct dp_soc *soc = int_ctx->soc;
  1267. int ring = 0;
  1268. uint32_t work_done = 0;
  1269. int budget = dp_budget;
  1270. uint8_t tx_mask = int_ctx->tx_ring_mask;
  1271. uint8_t rx_mask = int_ctx->rx_ring_mask;
  1272. uint8_t rx_err_mask = int_ctx->rx_err_ring_mask;
  1273. uint8_t rx_wbm_rel_mask = int_ctx->rx_wbm_rel_ring_mask;
  1274. uint8_t reo_status_mask = int_ctx->reo_status_ring_mask;
  1275. uint32_t remaining_quota = dp_budget;
  1276. struct dp_pdev *pdev = NULL;
  1277. int mac_id;
  1278. dp_verbose_debug("tx %x rx %x rx_err %x rx_wbm_rel %x reo_status %x rx_mon_ring %x host2rxdma %x rxdma2host %x\n",
  1279. tx_mask, rx_mask, rx_err_mask, rx_wbm_rel_mask,
  1280. reo_status_mask,
  1281. int_ctx->rx_mon_ring_mask,
  1282. int_ctx->host2rxdma_ring_mask,
  1283. int_ctx->rxdma2host_ring_mask);
  1284. /* Process Tx completion interrupts first to return back buffers */
  1285. while (tx_mask) {
  1286. if (tx_mask & 0x1) {
  1287. work_done = dp_tx_comp_handler(int_ctx,
  1288. soc,
  1289. soc->tx_comp_ring[ring].hal_srng,
  1290. ring, remaining_quota);
  1291. if (work_done) {
  1292. intr_stats->num_tx_ring_masks[ring]++;
  1293. dp_verbose_debug("tx mask 0x%x ring %d, budget %d, work_done %d",
  1294. tx_mask, ring, budget,
  1295. work_done);
  1296. }
  1297. budget -= work_done;
  1298. if (budget <= 0)
  1299. goto budget_done;
  1300. remaining_quota = budget;
  1301. }
  1302. tx_mask = tx_mask >> 1;
  1303. ring++;
  1304. }
  1305. /* Process REO Exception ring interrupt */
  1306. if (rx_err_mask) {
  1307. work_done = dp_rx_err_process(int_ctx, soc,
  1308. soc->reo_exception_ring.hal_srng,
  1309. remaining_quota);
  1310. if (work_done) {
  1311. intr_stats->num_rx_err_ring_masks++;
  1312. dp_verbose_debug("REO Exception Ring: work_done %d budget %d",
  1313. work_done, budget);
  1314. }
  1315. budget -= work_done;
  1316. if (budget <= 0) {
  1317. goto budget_done;
  1318. }
  1319. remaining_quota = budget;
  1320. }
  1321. /* Process Rx WBM release ring interrupt */
  1322. if (rx_wbm_rel_mask) {
  1323. work_done = dp_rx_wbm_err_process(int_ctx, soc,
  1324. soc->rx_rel_ring.hal_srng,
  1325. remaining_quota);
  1326. if (work_done) {
  1327. intr_stats->num_rx_wbm_rel_ring_masks++;
  1328. dp_verbose_debug("WBM Release Ring: work_done %d budget %d",
  1329. work_done, budget);
  1330. }
  1331. budget -= work_done;
  1332. if (budget <= 0) {
  1333. goto budget_done;
  1334. }
  1335. remaining_quota = budget;
  1336. }
  1337. /* Process Rx interrupts */
  1338. if (rx_mask) {
  1339. for (ring = 0; ring < soc->num_reo_dest_rings; ring++) {
  1340. if (!(rx_mask & (1 << ring)))
  1341. continue;
  1342. work_done = dp_rx_process(int_ctx,
  1343. soc->reo_dest_ring[ring].hal_srng,
  1344. ring,
  1345. remaining_quota);
  1346. if (work_done) {
  1347. intr_stats->num_rx_ring_masks[ring]++;
  1348. dp_verbose_debug("rx mask 0x%x ring %d, work_done %d budget %d",
  1349. rx_mask, ring,
  1350. work_done, budget);
  1351. budget -= work_done;
  1352. if (budget <= 0)
  1353. goto budget_done;
  1354. remaining_quota = budget;
  1355. }
  1356. }
  1357. }
  1358. if (reo_status_mask) {
  1359. if (dp_reo_status_ring_handler(int_ctx, soc))
  1360. int_ctx->intr_stats.num_reo_status_ring_masks++;
  1361. }
  1362. /* Process LMAC interrupts */
  1363. for (ring = 0 ; ring < MAX_PDEV_CNT; ring++) {
  1364. pdev = soc->pdev_list[ring];
  1365. if (!pdev)
  1366. continue;
  1367. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  1368. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id,
  1369. pdev->pdev_id);
  1370. if (int_ctx->rx_mon_ring_mask & (1 << mac_for_pdev)) {
  1371. work_done = dp_mon_process(soc, mac_for_pdev,
  1372. remaining_quota);
  1373. if (work_done)
  1374. intr_stats->num_rx_mon_ring_masks++;
  1375. budget -= work_done;
  1376. if (budget <= 0)
  1377. goto budget_done;
  1378. remaining_quota = budget;
  1379. }
  1380. if (int_ctx->rxdma2host_ring_mask &
  1381. (1 << mac_for_pdev)) {
  1382. work_done = dp_rxdma_err_process(int_ctx, soc,
  1383. mac_for_pdev,
  1384. remaining_quota);
  1385. if (work_done)
  1386. intr_stats->num_rxdma2host_ring_masks++;
  1387. budget -= work_done;
  1388. if (budget <= 0)
  1389. goto budget_done;
  1390. remaining_quota = budget;
  1391. }
  1392. if (int_ctx->host2rxdma_ring_mask &
  1393. (1 << mac_for_pdev)) {
  1394. union dp_rx_desc_list_elem_t *desc_list = NULL;
  1395. union dp_rx_desc_list_elem_t *tail = NULL;
  1396. struct dp_srng *rx_refill_buf_ring =
  1397. &pdev->rx_refill_buf_ring;
  1398. intr_stats->num_host2rxdma_ring_masks++;
  1399. DP_STATS_INC(pdev, replenish.low_thresh_intrs,
  1400. 1);
  1401. dp_rx_buffers_replenish(soc, mac_for_pdev,
  1402. rx_refill_buf_ring,
  1403. &soc->rx_desc_buf[mac_for_pdev],
  1404. 0, &desc_list, &tail);
  1405. }
  1406. }
  1407. }
  1408. qdf_lro_flush(int_ctx->lro_ctx);
  1409. intr_stats->num_masks++;
  1410. budget_done:
  1411. return dp_budget - budget;
  1412. }
  1413. /* dp_interrupt_timer()- timer poll for interrupts
  1414. *
  1415. * @arg: SoC Handle
  1416. *
  1417. * Return:
  1418. *
  1419. */
  1420. static void dp_interrupt_timer(void *arg)
  1421. {
  1422. struct dp_soc *soc = (struct dp_soc *) arg;
  1423. int i;
  1424. if (qdf_atomic_read(&soc->cmn_init_done)) {
  1425. for (i = 0;
  1426. i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++)
  1427. dp_service_srngs(&soc->intr_ctx[i], 0xffff);
  1428. qdf_timer_mod(&soc->int_timer, DP_INTR_POLL_TIMER_MS);
  1429. }
  1430. }
  1431. /*
  1432. * dp_soc_attach_poll() - Register handlers for DP interrupts
  1433. * @txrx_soc: DP SOC handle
  1434. *
  1435. * Host driver will register for “DP_NUM_INTERRUPT_CONTEXTS” number of NAPI
  1436. * contexts. Each NAPI context will have a tx_ring_mask , rx_ring_mask ,and
  1437. * rx_monitor_ring mask to indicate the rings that are processed by the handler.
  1438. *
  1439. * Return: 0 for success, nonzero for failure.
  1440. */
  1441. static QDF_STATUS dp_soc_attach_poll(void *txrx_soc)
  1442. {
  1443. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  1444. int i;
  1445. soc->intr_mode = DP_INTR_POLL;
  1446. for (i = 0; i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++) {
  1447. soc->intr_ctx[i].dp_intr_id = i;
  1448. soc->intr_ctx[i].tx_ring_mask =
  1449. wlan_cfg_get_tx_ring_mask(soc->wlan_cfg_ctx, i);
  1450. soc->intr_ctx[i].rx_ring_mask =
  1451. wlan_cfg_get_rx_ring_mask(soc->wlan_cfg_ctx, i);
  1452. soc->intr_ctx[i].rx_mon_ring_mask =
  1453. wlan_cfg_get_rx_mon_ring_mask(soc->wlan_cfg_ctx, i);
  1454. soc->intr_ctx[i].rx_err_ring_mask =
  1455. wlan_cfg_get_rx_err_ring_mask(soc->wlan_cfg_ctx, i);
  1456. soc->intr_ctx[i].rx_wbm_rel_ring_mask =
  1457. wlan_cfg_get_rx_wbm_rel_ring_mask(soc->wlan_cfg_ctx, i);
  1458. soc->intr_ctx[i].reo_status_ring_mask =
  1459. wlan_cfg_get_reo_status_ring_mask(soc->wlan_cfg_ctx, i);
  1460. soc->intr_ctx[i].rxdma2host_ring_mask =
  1461. wlan_cfg_get_rxdma2host_ring_mask(soc->wlan_cfg_ctx, i);
  1462. soc->intr_ctx[i].soc = soc;
  1463. soc->intr_ctx[i].lro_ctx = qdf_lro_init();
  1464. }
  1465. qdf_timer_init(soc->osdev, &soc->int_timer,
  1466. dp_interrupt_timer, (void *)soc,
  1467. QDF_TIMER_TYPE_WAKE_APPS);
  1468. return QDF_STATUS_SUCCESS;
  1469. }
  1470. /**
  1471. * dp_soc_set_interrupt_mode() - Set the interrupt mode in soc
  1472. * soc: DP soc handle
  1473. *
  1474. * Set the appropriate interrupt mode flag in the soc
  1475. */
  1476. static void dp_soc_set_interrupt_mode(struct dp_soc *soc)
  1477. {
  1478. uint32_t msi_base_data, msi_vector_start;
  1479. int msi_vector_count, ret;
  1480. soc->intr_mode = DP_INTR_LEGACY;
  1481. if (!(soc->wlan_cfg_ctx->napi_enabled) ||
  1482. (soc->cdp_soc.ol_ops->get_con_mode &&
  1483. soc->cdp_soc.ol_ops->get_con_mode() == QDF_GLOBAL_MONITOR_MODE)) {
  1484. soc->intr_mode = DP_INTR_POLL;
  1485. } else {
  1486. ret = pld_get_user_msi_assignment(soc->osdev->dev, "DP",
  1487. &msi_vector_count,
  1488. &msi_base_data,
  1489. &msi_vector_start);
  1490. if (ret)
  1491. return;
  1492. soc->intr_mode = DP_INTR_MSI;
  1493. }
  1494. }
  1495. static QDF_STATUS dp_soc_interrupt_attach(void *txrx_soc);
  1496. #if defined(DP_INTR_POLL_BOTH)
  1497. /*
  1498. * dp_soc_interrupt_attach_wrapper() - Register handlers for DP interrupts
  1499. * @txrx_soc: DP SOC handle
  1500. *
  1501. * Call the appropriate attach function based on the mode of operation.
  1502. * This is a WAR for enabling monitor mode.
  1503. *
  1504. * Return: 0 for success. nonzero for failure.
  1505. */
  1506. static QDF_STATUS dp_soc_interrupt_attach_wrapper(void *txrx_soc)
  1507. {
  1508. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  1509. if (!(soc->wlan_cfg_ctx->napi_enabled) ||
  1510. (soc->cdp_soc.ol_ops->get_con_mode &&
  1511. soc->cdp_soc.ol_ops->get_con_mode() ==
  1512. QDF_GLOBAL_MONITOR_MODE)) {
  1513. dp_info("Poll mode");
  1514. return dp_soc_attach_poll(txrx_soc);
  1515. } else {
  1516. dp_info("Interrupt mode");
  1517. return dp_soc_interrupt_attach(txrx_soc);
  1518. }
  1519. }
  1520. #else
  1521. #if defined(DP_INTR_POLL_BASED) && DP_INTR_POLL_BASED
  1522. static QDF_STATUS dp_soc_interrupt_attach_wrapper(void *txrx_soc)
  1523. {
  1524. return dp_soc_attach_poll(txrx_soc);
  1525. }
  1526. #else
  1527. static QDF_STATUS dp_soc_interrupt_attach_wrapper(void *txrx_soc)
  1528. {
  1529. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  1530. if (hif_is_polled_mode_enabled(soc->hif_handle))
  1531. return dp_soc_attach_poll(txrx_soc);
  1532. else
  1533. return dp_soc_interrupt_attach(txrx_soc);
  1534. }
  1535. #endif
  1536. #endif
  1537. static void dp_soc_interrupt_map_calculate_integrated(struct dp_soc *soc,
  1538. int intr_ctx_num, int *irq_id_map, int *num_irq_r)
  1539. {
  1540. int j;
  1541. int num_irq = 0;
  1542. int tx_mask =
  1543. wlan_cfg_get_tx_ring_mask(soc->wlan_cfg_ctx, intr_ctx_num);
  1544. int rx_mask =
  1545. wlan_cfg_get_rx_ring_mask(soc->wlan_cfg_ctx, intr_ctx_num);
  1546. int rx_mon_mask =
  1547. wlan_cfg_get_rx_mon_ring_mask(soc->wlan_cfg_ctx, intr_ctx_num);
  1548. int rx_err_ring_mask = wlan_cfg_get_rx_err_ring_mask(
  1549. soc->wlan_cfg_ctx, intr_ctx_num);
  1550. int rx_wbm_rel_ring_mask = wlan_cfg_get_rx_wbm_rel_ring_mask(
  1551. soc->wlan_cfg_ctx, intr_ctx_num);
  1552. int reo_status_ring_mask = wlan_cfg_get_reo_status_ring_mask(
  1553. soc->wlan_cfg_ctx, intr_ctx_num);
  1554. int rxdma2host_ring_mask = wlan_cfg_get_rxdma2host_ring_mask(
  1555. soc->wlan_cfg_ctx, intr_ctx_num);
  1556. int host2rxdma_ring_mask = wlan_cfg_get_host2rxdma_ring_mask(
  1557. soc->wlan_cfg_ctx, intr_ctx_num);
  1558. int host2rxdma_mon_ring_mask = wlan_cfg_get_host2rxdma_mon_ring_mask(
  1559. soc->wlan_cfg_ctx, intr_ctx_num);
  1560. soc->intr_mode = DP_INTR_LEGACY;
  1561. for (j = 0; j < HIF_MAX_GRP_IRQ; j++) {
  1562. if (tx_mask & (1 << j)) {
  1563. irq_id_map[num_irq++] =
  1564. (wbm2host_tx_completions_ring1 - j);
  1565. }
  1566. if (rx_mask & (1 << j)) {
  1567. irq_id_map[num_irq++] =
  1568. (reo2host_destination_ring1 - j);
  1569. }
  1570. if (rxdma2host_ring_mask & (1 << j)) {
  1571. irq_id_map[num_irq++] =
  1572. rxdma2host_destination_ring_mac1 -
  1573. wlan_cfg_get_hw_mac_idx(soc->wlan_cfg_ctx, j);
  1574. }
  1575. if (host2rxdma_ring_mask & (1 << j)) {
  1576. irq_id_map[num_irq++] =
  1577. host2rxdma_host_buf_ring_mac1 -
  1578. wlan_cfg_get_hw_mac_idx(soc->wlan_cfg_ctx, j);
  1579. }
  1580. if (host2rxdma_mon_ring_mask & (1 << j)) {
  1581. irq_id_map[num_irq++] =
  1582. host2rxdma_monitor_ring1 -
  1583. wlan_cfg_get_hw_mac_idx(soc->wlan_cfg_ctx, j);
  1584. }
  1585. if (rx_mon_mask & (1 << j)) {
  1586. irq_id_map[num_irq++] =
  1587. ppdu_end_interrupts_mac1 -
  1588. wlan_cfg_get_hw_mac_idx(soc->wlan_cfg_ctx, j);
  1589. irq_id_map[num_irq++] =
  1590. rxdma2host_monitor_status_ring_mac1 -
  1591. wlan_cfg_get_hw_mac_idx(soc->wlan_cfg_ctx, j);
  1592. }
  1593. if (rx_wbm_rel_ring_mask & (1 << j))
  1594. irq_id_map[num_irq++] = wbm2host_rx_release;
  1595. if (rx_err_ring_mask & (1 << j))
  1596. irq_id_map[num_irq++] = reo2host_exception;
  1597. if (reo_status_ring_mask & (1 << j))
  1598. irq_id_map[num_irq++] = reo2host_status;
  1599. }
  1600. *num_irq_r = num_irq;
  1601. }
  1602. static void dp_soc_interrupt_map_calculate_msi(struct dp_soc *soc,
  1603. int intr_ctx_num, int *irq_id_map, int *num_irq_r,
  1604. int msi_vector_count, int msi_vector_start)
  1605. {
  1606. int tx_mask = wlan_cfg_get_tx_ring_mask(
  1607. soc->wlan_cfg_ctx, intr_ctx_num);
  1608. int rx_mask = wlan_cfg_get_rx_ring_mask(
  1609. soc->wlan_cfg_ctx, intr_ctx_num);
  1610. int rx_mon_mask = wlan_cfg_get_rx_mon_ring_mask(
  1611. soc->wlan_cfg_ctx, intr_ctx_num);
  1612. int rx_err_ring_mask = wlan_cfg_get_rx_err_ring_mask(
  1613. soc->wlan_cfg_ctx, intr_ctx_num);
  1614. int rx_wbm_rel_ring_mask = wlan_cfg_get_rx_wbm_rel_ring_mask(
  1615. soc->wlan_cfg_ctx, intr_ctx_num);
  1616. int reo_status_ring_mask = wlan_cfg_get_reo_status_ring_mask(
  1617. soc->wlan_cfg_ctx, intr_ctx_num);
  1618. int rxdma2host_ring_mask = wlan_cfg_get_rxdma2host_ring_mask(
  1619. soc->wlan_cfg_ctx, intr_ctx_num);
  1620. unsigned int vector =
  1621. (intr_ctx_num % msi_vector_count) + msi_vector_start;
  1622. int num_irq = 0;
  1623. soc->intr_mode = DP_INTR_MSI;
  1624. if (tx_mask | rx_mask | rx_mon_mask | rx_err_ring_mask |
  1625. rx_wbm_rel_ring_mask | reo_status_ring_mask | rxdma2host_ring_mask)
  1626. irq_id_map[num_irq++] =
  1627. pld_get_msi_irq(soc->osdev->dev, vector);
  1628. *num_irq_r = num_irq;
  1629. }
  1630. static void dp_soc_interrupt_map_calculate(struct dp_soc *soc, int intr_ctx_num,
  1631. int *irq_id_map, int *num_irq)
  1632. {
  1633. int msi_vector_count, ret;
  1634. uint32_t msi_base_data, msi_vector_start;
  1635. ret = pld_get_user_msi_assignment(soc->osdev->dev, "DP",
  1636. &msi_vector_count,
  1637. &msi_base_data,
  1638. &msi_vector_start);
  1639. if (ret)
  1640. return dp_soc_interrupt_map_calculate_integrated(soc,
  1641. intr_ctx_num, irq_id_map, num_irq);
  1642. else
  1643. dp_soc_interrupt_map_calculate_msi(soc,
  1644. intr_ctx_num, irq_id_map, num_irq,
  1645. msi_vector_count, msi_vector_start);
  1646. }
  1647. /*
  1648. * dp_soc_interrupt_attach() - Register handlers for DP interrupts
  1649. * @txrx_soc: DP SOC handle
  1650. *
  1651. * Host driver will register for “DP_NUM_INTERRUPT_CONTEXTS” number of NAPI
  1652. * contexts. Each NAPI context will have a tx_ring_mask , rx_ring_mask ,and
  1653. * rx_monitor_ring mask to indicate the rings that are processed by the handler.
  1654. *
  1655. * Return: 0 for success. nonzero for failure.
  1656. */
  1657. static QDF_STATUS dp_soc_interrupt_attach(void *txrx_soc)
  1658. {
  1659. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  1660. int i = 0;
  1661. int num_irq = 0;
  1662. for (i = 0; i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++) {
  1663. int ret = 0;
  1664. /* Map of IRQ ids registered with one interrupt context */
  1665. int irq_id_map[HIF_MAX_GRP_IRQ];
  1666. int tx_mask =
  1667. wlan_cfg_get_tx_ring_mask(soc->wlan_cfg_ctx, i);
  1668. int rx_mask =
  1669. wlan_cfg_get_rx_ring_mask(soc->wlan_cfg_ctx, i);
  1670. int rx_mon_mask =
  1671. dp_soc_get_mon_mask_for_interrupt_mode(soc, i);
  1672. int rx_err_ring_mask =
  1673. wlan_cfg_get_rx_err_ring_mask(soc->wlan_cfg_ctx, i);
  1674. int rx_wbm_rel_ring_mask =
  1675. wlan_cfg_get_rx_wbm_rel_ring_mask(soc->wlan_cfg_ctx, i);
  1676. int reo_status_ring_mask =
  1677. wlan_cfg_get_reo_status_ring_mask(soc->wlan_cfg_ctx, i);
  1678. int rxdma2host_ring_mask =
  1679. wlan_cfg_get_rxdma2host_ring_mask(soc->wlan_cfg_ctx, i);
  1680. int host2rxdma_ring_mask =
  1681. wlan_cfg_get_host2rxdma_ring_mask(soc->wlan_cfg_ctx, i);
  1682. int host2rxdma_mon_ring_mask =
  1683. wlan_cfg_get_host2rxdma_mon_ring_mask(
  1684. soc->wlan_cfg_ctx, i);
  1685. soc->intr_ctx[i].dp_intr_id = i;
  1686. soc->intr_ctx[i].tx_ring_mask = tx_mask;
  1687. soc->intr_ctx[i].rx_ring_mask = rx_mask;
  1688. soc->intr_ctx[i].rx_mon_ring_mask = rx_mon_mask;
  1689. soc->intr_ctx[i].rx_err_ring_mask = rx_err_ring_mask;
  1690. soc->intr_ctx[i].rxdma2host_ring_mask = rxdma2host_ring_mask;
  1691. soc->intr_ctx[i].host2rxdma_ring_mask = host2rxdma_ring_mask;
  1692. soc->intr_ctx[i].rx_wbm_rel_ring_mask = rx_wbm_rel_ring_mask;
  1693. soc->intr_ctx[i].reo_status_ring_mask = reo_status_ring_mask;
  1694. soc->intr_ctx[i].host2rxdma_mon_ring_mask =
  1695. host2rxdma_mon_ring_mask;
  1696. soc->intr_ctx[i].soc = soc;
  1697. num_irq = 0;
  1698. dp_soc_interrupt_map_calculate(soc, i, &irq_id_map[0],
  1699. &num_irq);
  1700. ret = hif_register_ext_group(soc->hif_handle,
  1701. num_irq, irq_id_map, dp_service_srngs,
  1702. &soc->intr_ctx[i], "dp_intr",
  1703. HIF_EXEC_NAPI_TYPE, QCA_NAPI_DEF_SCALE_BIN_SHIFT);
  1704. if (ret) {
  1705. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1706. FL("failed, ret = %d"), ret);
  1707. return QDF_STATUS_E_FAILURE;
  1708. }
  1709. soc->intr_ctx[i].lro_ctx = qdf_lro_init();
  1710. }
  1711. hif_configure_ext_group_interrupts(soc->hif_handle);
  1712. return QDF_STATUS_SUCCESS;
  1713. }
  1714. /*
  1715. * dp_soc_interrupt_detach() - Deregister any allocations done for interrupts
  1716. * @txrx_soc: DP SOC handle
  1717. *
  1718. * Return: void
  1719. */
  1720. static void dp_soc_interrupt_detach(void *txrx_soc)
  1721. {
  1722. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  1723. int i;
  1724. if (soc->intr_mode == DP_INTR_POLL) {
  1725. qdf_timer_stop(&soc->int_timer);
  1726. qdf_timer_free(&soc->int_timer);
  1727. } else {
  1728. hif_deregister_exec_group(soc->hif_handle, "dp_intr");
  1729. }
  1730. for (i = 0; i < wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx); i++) {
  1731. soc->intr_ctx[i].tx_ring_mask = 0;
  1732. soc->intr_ctx[i].rx_ring_mask = 0;
  1733. soc->intr_ctx[i].rx_mon_ring_mask = 0;
  1734. soc->intr_ctx[i].rx_err_ring_mask = 0;
  1735. soc->intr_ctx[i].rx_wbm_rel_ring_mask = 0;
  1736. soc->intr_ctx[i].reo_status_ring_mask = 0;
  1737. soc->intr_ctx[i].rxdma2host_ring_mask = 0;
  1738. soc->intr_ctx[i].host2rxdma_ring_mask = 0;
  1739. soc->intr_ctx[i].host2rxdma_mon_ring_mask = 0;
  1740. qdf_lro_deinit(soc->intr_ctx[i].lro_ctx);
  1741. }
  1742. }
  1743. #define AVG_MAX_MPDUS_PER_TID 128
  1744. #define AVG_TIDS_PER_CLIENT 2
  1745. #define AVG_FLOWS_PER_TID 2
  1746. #define AVG_MSDUS_PER_FLOW 128
  1747. #define AVG_MSDUS_PER_MPDU 4
  1748. /*
  1749. * Allocate and setup link descriptor pool that will be used by HW for
  1750. * various link and queue descriptors and managed by WBM
  1751. */
  1752. static int dp_hw_link_desc_pool_setup(struct dp_soc *soc)
  1753. {
  1754. int link_desc_size = hal_get_link_desc_size(soc->hal_soc);
  1755. int link_desc_align = hal_get_link_desc_align(soc->hal_soc);
  1756. uint32_t max_clients = wlan_cfg_get_max_clients(soc->wlan_cfg_ctx);
  1757. uint32_t num_mpdus_per_link_desc =
  1758. hal_num_mpdus_per_link_desc(soc->hal_soc);
  1759. uint32_t num_msdus_per_link_desc =
  1760. hal_num_msdus_per_link_desc(soc->hal_soc);
  1761. uint32_t num_mpdu_links_per_queue_desc =
  1762. hal_num_mpdu_links_per_queue_desc(soc->hal_soc);
  1763. uint32_t max_alloc_size = wlan_cfg_max_alloc_size(soc->wlan_cfg_ctx);
  1764. uint32_t total_link_descs, total_mem_size;
  1765. uint32_t num_mpdu_link_descs, num_mpdu_queue_descs;
  1766. uint32_t num_tx_msdu_link_descs, num_rx_msdu_link_descs;
  1767. uint32_t num_link_desc_banks;
  1768. uint32_t last_bank_size = 0;
  1769. uint32_t entry_size, num_entries;
  1770. int i;
  1771. uint32_t desc_id = 0;
  1772. qdf_dma_addr_t *baseaddr = NULL;
  1773. /* Only Tx queue descriptors are allocated from common link descriptor
  1774. * pool Rx queue descriptors are not included in this because (REO queue
  1775. * extension descriptors) they are expected to be allocated contiguously
  1776. * with REO queue descriptors
  1777. */
  1778. num_mpdu_link_descs = (max_clients * AVG_TIDS_PER_CLIENT *
  1779. AVG_MAX_MPDUS_PER_TID) / num_mpdus_per_link_desc;
  1780. num_mpdu_queue_descs = num_mpdu_link_descs /
  1781. num_mpdu_links_per_queue_desc;
  1782. num_tx_msdu_link_descs = (max_clients * AVG_TIDS_PER_CLIENT *
  1783. AVG_FLOWS_PER_TID * AVG_MSDUS_PER_FLOW) /
  1784. num_msdus_per_link_desc;
  1785. num_rx_msdu_link_descs = (max_clients * AVG_TIDS_PER_CLIENT *
  1786. AVG_MAX_MPDUS_PER_TID * AVG_MSDUS_PER_MPDU) / 6;
  1787. num_entries = num_mpdu_link_descs + num_mpdu_queue_descs +
  1788. num_tx_msdu_link_descs + num_rx_msdu_link_descs;
  1789. /* Round up to power of 2 */
  1790. total_link_descs = 1;
  1791. while (total_link_descs < num_entries)
  1792. total_link_descs <<= 1;
  1793. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  1794. FL("total_link_descs: %u, link_desc_size: %d"),
  1795. total_link_descs, link_desc_size);
  1796. total_mem_size = total_link_descs * link_desc_size;
  1797. total_mem_size += link_desc_align;
  1798. if (total_mem_size <= max_alloc_size) {
  1799. num_link_desc_banks = 0;
  1800. last_bank_size = total_mem_size;
  1801. } else {
  1802. num_link_desc_banks = (total_mem_size) /
  1803. (max_alloc_size - link_desc_align);
  1804. last_bank_size = total_mem_size %
  1805. (max_alloc_size - link_desc_align);
  1806. }
  1807. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  1808. FL("total_mem_size: %d, num_link_desc_banks: %u"),
  1809. total_mem_size, num_link_desc_banks);
  1810. for (i = 0; i < num_link_desc_banks; i++) {
  1811. if (!dp_is_soc_reinit(soc)) {
  1812. baseaddr = &soc->link_desc_banks[i].
  1813. base_paddr_unaligned;
  1814. soc->link_desc_banks[i].base_vaddr_unaligned =
  1815. qdf_mem_alloc_consistent(soc->osdev,
  1816. soc->osdev->dev,
  1817. max_alloc_size,
  1818. baseaddr);
  1819. }
  1820. soc->link_desc_banks[i].size = max_alloc_size;
  1821. soc->link_desc_banks[i].base_vaddr = (void *)((unsigned long)(
  1822. soc->link_desc_banks[i].base_vaddr_unaligned) +
  1823. ((unsigned long)(
  1824. soc->link_desc_banks[i].base_vaddr_unaligned) %
  1825. link_desc_align));
  1826. soc->link_desc_banks[i].base_paddr = (unsigned long)(
  1827. soc->link_desc_banks[i].base_paddr_unaligned) +
  1828. ((unsigned long)(soc->link_desc_banks[i].base_vaddr) -
  1829. (unsigned long)(
  1830. soc->link_desc_banks[i].base_vaddr_unaligned));
  1831. if (!soc->link_desc_banks[i].base_vaddr_unaligned) {
  1832. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1833. FL("Link descriptor memory alloc failed"));
  1834. goto fail;
  1835. }
  1836. if (!dp_is_soc_reinit(soc)) {
  1837. qdf_minidump_log(soc->link_desc_banks[i].base_vaddr,
  1838. soc->link_desc_banks[i].size,
  1839. "link_desc_bank");
  1840. }
  1841. qdf_minidump_log((soc->link_desc_banks[i].base_vaddr),
  1842. soc->link_desc_banks[i].size,
  1843. "link_desc_bank");
  1844. }
  1845. if (last_bank_size) {
  1846. /* Allocate last bank in case total memory required is not exact
  1847. * multiple of max_alloc_size
  1848. */
  1849. if (!dp_is_soc_reinit(soc)) {
  1850. baseaddr = &soc->link_desc_banks[i].
  1851. base_paddr_unaligned;
  1852. soc->link_desc_banks[i].base_vaddr_unaligned =
  1853. qdf_mem_alloc_consistent(soc->osdev,
  1854. soc->osdev->dev,
  1855. last_bank_size,
  1856. baseaddr);
  1857. }
  1858. soc->link_desc_banks[i].size = last_bank_size;
  1859. soc->link_desc_banks[i].base_vaddr = (void *)((unsigned long)
  1860. (soc->link_desc_banks[i].base_vaddr_unaligned) +
  1861. ((unsigned long)(
  1862. soc->link_desc_banks[i].base_vaddr_unaligned) %
  1863. link_desc_align));
  1864. soc->link_desc_banks[i].base_paddr =
  1865. (unsigned long)(
  1866. soc->link_desc_banks[i].base_paddr_unaligned) +
  1867. ((unsigned long)(soc->link_desc_banks[i].base_vaddr) -
  1868. (unsigned long)(
  1869. soc->link_desc_banks[i].base_vaddr_unaligned));
  1870. if (!dp_is_soc_reinit(soc)) {
  1871. qdf_minidump_log(soc->link_desc_banks[i].base_vaddr,
  1872. soc->link_desc_banks[i].size,
  1873. "link_desc_bank");
  1874. }
  1875. qdf_minidump_log((soc->link_desc_banks[i].base_vaddr),
  1876. soc->link_desc_banks[i].size,
  1877. "link_desc_bank");
  1878. }
  1879. /* Allocate and setup link descriptor idle list for HW internal use */
  1880. entry_size = hal_srng_get_entrysize(soc->hal_soc, WBM_IDLE_LINK);
  1881. total_mem_size = entry_size * total_link_descs;
  1882. if (total_mem_size <= max_alloc_size) {
  1883. void *desc;
  1884. if (dp_srng_setup(soc, &soc->wbm_idle_link_ring,
  1885. WBM_IDLE_LINK, 0, 0, total_link_descs, 0)) {
  1886. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1887. FL("Link desc idle ring setup failed"));
  1888. goto fail;
  1889. }
  1890. qdf_minidump_log(soc->wbm_idle_link_ring.base_vaddr_unaligned,
  1891. soc->wbm_idle_link_ring.alloc_size,
  1892. "wbm_idle_link_ring");
  1893. hal_srng_access_start_unlocked(soc->hal_soc,
  1894. soc->wbm_idle_link_ring.hal_srng);
  1895. for (i = 0; i < MAX_LINK_DESC_BANKS &&
  1896. soc->link_desc_banks[i].base_paddr; i++) {
  1897. uint32_t num_entries = (soc->link_desc_banks[i].size -
  1898. ((unsigned long)(
  1899. soc->link_desc_banks[i].base_vaddr) -
  1900. (unsigned long)(
  1901. soc->link_desc_banks[i].base_vaddr_unaligned)))
  1902. / link_desc_size;
  1903. unsigned long paddr = (unsigned long)(
  1904. soc->link_desc_banks[i].base_paddr);
  1905. while (num_entries && (desc = hal_srng_src_get_next(
  1906. soc->hal_soc,
  1907. soc->wbm_idle_link_ring.hal_srng))) {
  1908. hal_set_link_desc_addr(desc,
  1909. LINK_DESC_COOKIE(desc_id, i), paddr);
  1910. num_entries--;
  1911. desc_id++;
  1912. paddr += link_desc_size;
  1913. }
  1914. }
  1915. hal_srng_access_end_unlocked(soc->hal_soc,
  1916. soc->wbm_idle_link_ring.hal_srng);
  1917. } else {
  1918. uint32_t num_scatter_bufs;
  1919. uint32_t num_entries_per_buf;
  1920. uint32_t rem_entries;
  1921. uint8_t *scatter_buf_ptr;
  1922. uint16_t scatter_buf_num;
  1923. uint32_t buf_size = 0;
  1924. soc->wbm_idle_scatter_buf_size =
  1925. hal_idle_list_scatter_buf_size(soc->hal_soc);
  1926. num_entries_per_buf = hal_idle_scatter_buf_num_entries(
  1927. soc->hal_soc, soc->wbm_idle_scatter_buf_size);
  1928. num_scatter_bufs = hal_idle_list_num_scatter_bufs(
  1929. soc->hal_soc, total_mem_size,
  1930. soc->wbm_idle_scatter_buf_size);
  1931. if (num_scatter_bufs > MAX_IDLE_SCATTER_BUFS) {
  1932. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1933. FL("scatter bufs size out of bounds"));
  1934. goto fail;
  1935. }
  1936. for (i = 0; i < num_scatter_bufs; i++) {
  1937. baseaddr = &soc->wbm_idle_scatter_buf_base_paddr[i];
  1938. if (!dp_is_soc_reinit(soc)) {
  1939. buf_size = soc->wbm_idle_scatter_buf_size;
  1940. soc->wbm_idle_scatter_buf_base_vaddr[i] =
  1941. qdf_mem_alloc_consistent(soc->osdev,
  1942. soc->osdev->
  1943. dev,
  1944. buf_size,
  1945. baseaddr);
  1946. }
  1947. if (!soc->wbm_idle_scatter_buf_base_vaddr[i]) {
  1948. QDF_TRACE(QDF_MODULE_ID_DP,
  1949. QDF_TRACE_LEVEL_ERROR,
  1950. FL("Scatter lst memory alloc fail"));
  1951. goto fail;
  1952. }
  1953. }
  1954. /* Populate idle list scatter buffers with link descriptor
  1955. * pointers
  1956. */
  1957. scatter_buf_num = 0;
  1958. scatter_buf_ptr = (uint8_t *)(
  1959. soc->wbm_idle_scatter_buf_base_vaddr[scatter_buf_num]);
  1960. rem_entries = num_entries_per_buf;
  1961. for (i = 0; i < MAX_LINK_DESC_BANKS &&
  1962. soc->link_desc_banks[i].base_paddr; i++) {
  1963. uint32_t num_link_descs =
  1964. (soc->link_desc_banks[i].size -
  1965. ((unsigned long)(
  1966. soc->link_desc_banks[i].base_vaddr) -
  1967. (unsigned long)(
  1968. soc->link_desc_banks[i].base_vaddr_unaligned)))
  1969. / link_desc_size;
  1970. unsigned long paddr = (unsigned long)(
  1971. soc->link_desc_banks[i].base_paddr);
  1972. while (num_link_descs) {
  1973. hal_set_link_desc_addr((void *)scatter_buf_ptr,
  1974. LINK_DESC_COOKIE(desc_id, i), paddr);
  1975. num_link_descs--;
  1976. desc_id++;
  1977. paddr += link_desc_size;
  1978. rem_entries--;
  1979. if (rem_entries) {
  1980. scatter_buf_ptr += entry_size;
  1981. } else {
  1982. rem_entries = num_entries_per_buf;
  1983. scatter_buf_num++;
  1984. if (scatter_buf_num >= num_scatter_bufs)
  1985. break;
  1986. scatter_buf_ptr = (uint8_t *)(
  1987. soc->wbm_idle_scatter_buf_base_vaddr[
  1988. scatter_buf_num]);
  1989. }
  1990. }
  1991. }
  1992. /* Setup link descriptor idle list in HW */
  1993. hal_setup_link_idle_list(soc->hal_soc,
  1994. soc->wbm_idle_scatter_buf_base_paddr,
  1995. soc->wbm_idle_scatter_buf_base_vaddr,
  1996. num_scatter_bufs, soc->wbm_idle_scatter_buf_size,
  1997. (uint32_t)(scatter_buf_ptr -
  1998. (uint8_t *)(soc->wbm_idle_scatter_buf_base_vaddr[
  1999. scatter_buf_num-1])), total_link_descs);
  2000. }
  2001. return 0;
  2002. fail:
  2003. if (soc->wbm_idle_link_ring.hal_srng) {
  2004. dp_srng_cleanup(soc, &soc->wbm_idle_link_ring,
  2005. WBM_IDLE_LINK, 0);
  2006. }
  2007. for (i = 0; i < MAX_IDLE_SCATTER_BUFS; i++) {
  2008. if (soc->wbm_idle_scatter_buf_base_vaddr[i]) {
  2009. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  2010. soc->wbm_idle_scatter_buf_size,
  2011. soc->wbm_idle_scatter_buf_base_vaddr[i],
  2012. soc->wbm_idle_scatter_buf_base_paddr[i], 0);
  2013. soc->wbm_idle_scatter_buf_base_vaddr[i] = NULL;
  2014. }
  2015. }
  2016. for (i = 0; i < MAX_LINK_DESC_BANKS; i++) {
  2017. if (soc->link_desc_banks[i].base_vaddr_unaligned) {
  2018. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  2019. soc->link_desc_banks[i].size,
  2020. soc->link_desc_banks[i].base_vaddr_unaligned,
  2021. soc->link_desc_banks[i].base_paddr_unaligned,
  2022. 0);
  2023. soc->link_desc_banks[i].base_vaddr_unaligned = NULL;
  2024. }
  2025. }
  2026. return QDF_STATUS_E_FAILURE;
  2027. }
  2028. /*
  2029. * Free link descriptor pool that was setup HW
  2030. */
  2031. static void dp_hw_link_desc_pool_cleanup(struct dp_soc *soc)
  2032. {
  2033. int i;
  2034. if (soc->wbm_idle_link_ring.hal_srng) {
  2035. qdf_minidump_remove(
  2036. soc->wbm_idle_link_ring.base_vaddr_unaligned);
  2037. dp_srng_cleanup(soc, &soc->wbm_idle_link_ring,
  2038. WBM_IDLE_LINK, 0);
  2039. }
  2040. for (i = 0; i < MAX_IDLE_SCATTER_BUFS; i++) {
  2041. if (soc->wbm_idle_scatter_buf_base_vaddr[i]) {
  2042. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  2043. soc->wbm_idle_scatter_buf_size,
  2044. soc->wbm_idle_scatter_buf_base_vaddr[i],
  2045. soc->wbm_idle_scatter_buf_base_paddr[i], 0);
  2046. soc->wbm_idle_scatter_buf_base_vaddr[i] = NULL;
  2047. }
  2048. }
  2049. for (i = 0; i < MAX_LINK_DESC_BANKS; i++) {
  2050. if (soc->link_desc_banks[i].base_vaddr_unaligned) {
  2051. qdf_minidump_remove(soc->link_desc_banks[i].base_vaddr);
  2052. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  2053. soc->link_desc_banks[i].size,
  2054. soc->link_desc_banks[i].base_vaddr_unaligned,
  2055. soc->link_desc_banks[i].base_paddr_unaligned,
  2056. 0);
  2057. soc->link_desc_banks[i].base_vaddr_unaligned = NULL;
  2058. }
  2059. }
  2060. }
  2061. #ifdef IPA_OFFLOAD
  2062. #define REO_DST_RING_SIZE_QCA6290 1023
  2063. #ifndef QCA_WIFI_QCA8074_VP
  2064. #define REO_DST_RING_SIZE_QCA8074 1023
  2065. #define REO_DST_RING_SIZE_QCN9000 2048
  2066. #else
  2067. #define REO_DST_RING_SIZE_QCA8074 8
  2068. #define REO_DST_RING_SIZE_QCN9000 8
  2069. #endif /* QCA_WIFI_QCA8074_VP */
  2070. #else
  2071. #define REO_DST_RING_SIZE_QCA6290 1024
  2072. #ifndef QCA_WIFI_QCA8074_VP
  2073. #define REO_DST_RING_SIZE_QCA8074 2048
  2074. #define REO_DST_RING_SIZE_QCN9000 2048
  2075. #else
  2076. #define REO_DST_RING_SIZE_QCA8074 8
  2077. #define REO_DST_RING_SIZE_QCN9000 8
  2078. #endif /* QCA_WIFI_QCA8074_VP */
  2079. #endif /* IPA_OFFLOAD */
  2080. #ifndef FEATURE_WDS
  2081. static void dp_soc_wds_attach(struct dp_soc *soc)
  2082. {
  2083. }
  2084. static void dp_soc_wds_detach(struct dp_soc *soc)
  2085. {
  2086. }
  2087. #endif
  2088. /*
  2089. * dp_soc_reset_ring_map() - Reset cpu ring map
  2090. * @soc: Datapath soc handler
  2091. *
  2092. * This api resets the default cpu ring map
  2093. */
  2094. static void dp_soc_reset_cpu_ring_map(struct dp_soc *soc)
  2095. {
  2096. uint8_t i;
  2097. int nss_config = wlan_cfg_get_dp_soc_nss_cfg(soc->wlan_cfg_ctx);
  2098. for (i = 0; i < WLAN_CFG_INT_NUM_CONTEXTS; i++) {
  2099. switch (nss_config) {
  2100. case dp_nss_cfg_first_radio:
  2101. /*
  2102. * Setting Tx ring map for one nss offloaded radio
  2103. */
  2104. soc->tx_ring_map[i] = dp_cpu_ring_map[DP_NSS_FIRST_RADIO_OFFLOADED_MAP][i];
  2105. break;
  2106. case dp_nss_cfg_second_radio:
  2107. /*
  2108. * Setting Tx ring for two nss offloaded radios
  2109. */
  2110. soc->tx_ring_map[i] = dp_cpu_ring_map[DP_NSS_SECOND_RADIO_OFFLOADED_MAP][i];
  2111. break;
  2112. case dp_nss_cfg_dbdc:
  2113. /*
  2114. * Setting Tx ring map for 2 nss offloaded radios
  2115. */
  2116. soc->tx_ring_map[i] =
  2117. dp_cpu_ring_map[DP_NSS_DBDC_OFFLOADED_MAP][i];
  2118. break;
  2119. case dp_nss_cfg_dbtc:
  2120. /*
  2121. * Setting Tx ring map for 3 nss offloaded radios
  2122. */
  2123. soc->tx_ring_map[i] =
  2124. dp_cpu_ring_map[DP_NSS_DBTC_OFFLOADED_MAP][i];
  2125. break;
  2126. default:
  2127. dp_err("tx_ring_map failed due to invalid nss cfg");
  2128. break;
  2129. }
  2130. }
  2131. }
  2132. /*
  2133. * dp_soc_ring_if_nss_offloaded() - find if ring is offloaded to NSS
  2134. * @dp_soc - DP soc handle
  2135. * @ring_type - ring type
  2136. * @ring_num - ring_num
  2137. *
  2138. * return 0 or 1
  2139. */
  2140. static uint8_t dp_soc_ring_if_nss_offloaded(struct dp_soc *soc, enum hal_ring_type ring_type, int ring_num)
  2141. {
  2142. uint8_t nss_config = wlan_cfg_get_dp_soc_nss_cfg(soc->wlan_cfg_ctx);
  2143. uint8_t status = 0;
  2144. switch (ring_type) {
  2145. case WBM2SW_RELEASE:
  2146. case REO_DST:
  2147. case RXDMA_BUF:
  2148. status = ((nss_config) & (1 << ring_num));
  2149. break;
  2150. default:
  2151. break;
  2152. }
  2153. return status;
  2154. }
  2155. /*
  2156. * dp_soc_disable_mac2_intr_mask() - reset interrupt mask for WMAC2 hw rings
  2157. * @dp_soc - DP Soc handle
  2158. *
  2159. * Return: Return void
  2160. */
  2161. static void dp_soc_disable_mac2_intr_mask(struct dp_soc *soc)
  2162. {
  2163. int *grp_mask = NULL;
  2164. int group_number;
  2165. grp_mask = &soc->wlan_cfg_ctx->int_host2rxdma_ring_mask[0];
  2166. group_number = dp_srng_find_ring_in_mask(0x2, grp_mask);
  2167. wlan_cfg_set_host2rxdma_ring_mask(soc->wlan_cfg_ctx,
  2168. group_number, 0x0);
  2169. grp_mask = &soc->wlan_cfg_ctx->int_rx_mon_ring_mask[0];
  2170. group_number = dp_srng_find_ring_in_mask(0x2, grp_mask);
  2171. wlan_cfg_set_rx_mon_ring_mask(soc->wlan_cfg_ctx,
  2172. group_number, 0x0);
  2173. grp_mask = &soc->wlan_cfg_ctx->int_rxdma2host_ring_mask[0];
  2174. group_number = dp_srng_find_ring_in_mask(0x2, grp_mask);
  2175. wlan_cfg_set_rxdma2host_ring_mask(soc->wlan_cfg_ctx,
  2176. group_number, 0x0);
  2177. grp_mask = &soc->wlan_cfg_ctx->int_host2rxdma_mon_ring_mask[0];
  2178. group_number = dp_srng_find_ring_in_mask(0x2, grp_mask);
  2179. wlan_cfg_set_host2rxdma_mon_ring_mask(soc->wlan_cfg_ctx,
  2180. group_number, 0x0);
  2181. }
  2182. /*
  2183. * dp_soc_reset_intr_mask() - reset interrupt mask
  2184. * @dp_soc - DP Soc handle
  2185. *
  2186. * Return: Return void
  2187. */
  2188. static void dp_soc_reset_intr_mask(struct dp_soc *soc)
  2189. {
  2190. uint8_t j;
  2191. int *grp_mask = NULL;
  2192. int group_number, mask, num_ring;
  2193. /* number of tx ring */
  2194. num_ring = wlan_cfg_num_tcl_data_rings(soc->wlan_cfg_ctx);
  2195. /*
  2196. * group mask for tx completion ring.
  2197. */
  2198. grp_mask = &soc->wlan_cfg_ctx->int_tx_ring_mask[0];
  2199. /* loop and reset the mask for only offloaded ring */
  2200. for (j = 0; j < num_ring; j++) {
  2201. if (!dp_soc_ring_if_nss_offloaded(soc, WBM2SW_RELEASE, j)) {
  2202. continue;
  2203. }
  2204. /*
  2205. * Group number corresponding to tx offloaded ring.
  2206. */
  2207. group_number = dp_srng_find_ring_in_mask(j, grp_mask);
  2208. if (group_number < 0) {
  2209. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2210. FL("ring not part of any group; ring_type: %d,ring_num %d"),
  2211. WBM2SW_RELEASE, j);
  2212. return;
  2213. }
  2214. /* reset the tx mask for offloaded ring */
  2215. mask = wlan_cfg_get_tx_ring_mask(soc->wlan_cfg_ctx, group_number);
  2216. mask &= (~(1 << j));
  2217. /*
  2218. * reset the interrupt mask for offloaded ring.
  2219. */
  2220. wlan_cfg_set_tx_ring_mask(soc->wlan_cfg_ctx, group_number, mask);
  2221. }
  2222. /* number of rx rings */
  2223. num_ring = wlan_cfg_num_reo_dest_rings(soc->wlan_cfg_ctx);
  2224. /*
  2225. * group mask for reo destination ring.
  2226. */
  2227. grp_mask = &soc->wlan_cfg_ctx->int_rx_ring_mask[0];
  2228. /* loop and reset the mask for only offloaded ring */
  2229. for (j = 0; j < num_ring; j++) {
  2230. if (!dp_soc_ring_if_nss_offloaded(soc, REO_DST, j)) {
  2231. continue;
  2232. }
  2233. /*
  2234. * Group number corresponding to rx offloaded ring.
  2235. */
  2236. group_number = dp_srng_find_ring_in_mask(j, grp_mask);
  2237. if (group_number < 0) {
  2238. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2239. FL("ring not part of any group; ring_type: %d,ring_num %d"),
  2240. REO_DST, j);
  2241. return;
  2242. }
  2243. /* set the interrupt mask for offloaded ring */
  2244. mask = wlan_cfg_get_rx_ring_mask(soc->wlan_cfg_ctx, group_number);
  2245. mask &= (~(1 << j));
  2246. /*
  2247. * set the interrupt mask to zero for rx offloaded radio.
  2248. */
  2249. wlan_cfg_set_rx_ring_mask(soc->wlan_cfg_ctx, group_number, mask);
  2250. }
  2251. /*
  2252. * group mask for Rx buffer refill ring
  2253. */
  2254. grp_mask = &soc->wlan_cfg_ctx->int_host2rxdma_ring_mask[0];
  2255. /* loop and reset the mask for only offloaded ring */
  2256. for (j = 0; j < MAX_PDEV_CNT; j++) {
  2257. if (!dp_soc_ring_if_nss_offloaded(soc, RXDMA_BUF, j)) {
  2258. continue;
  2259. }
  2260. /*
  2261. * Group number corresponding to rx offloaded ring.
  2262. */
  2263. group_number = dp_srng_find_ring_in_mask(j, grp_mask);
  2264. if (group_number < 0) {
  2265. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  2266. FL("ring not part of any group; ring_type: %d,ring_num %d"),
  2267. REO_DST, j);
  2268. return;
  2269. }
  2270. /* set the interrupt mask for offloaded ring */
  2271. mask = wlan_cfg_get_host2rxdma_ring_mask(soc->wlan_cfg_ctx,
  2272. group_number);
  2273. mask &= (~(1 << j));
  2274. /*
  2275. * set the interrupt mask to zero for rx offloaded radio.
  2276. */
  2277. wlan_cfg_set_host2rxdma_ring_mask(soc->wlan_cfg_ctx,
  2278. group_number, mask);
  2279. }
  2280. }
  2281. #ifdef IPA_OFFLOAD
  2282. /**
  2283. * dp_reo_remap_config() - configure reo remap register value based
  2284. * nss configuration.
  2285. * based on offload_radio value below remap configuration
  2286. * get applied.
  2287. * 0 - both Radios handled by host (remap rings 1, 2, 3 & 4)
  2288. * 1 - 1st Radio handled by NSS (remap rings 2, 3 & 4)
  2289. * 2 - 2nd Radio handled by NSS (remap rings 1, 2 & 4)
  2290. * 3 - both Radios handled by NSS (remap not required)
  2291. * 4 - IPA OFFLOAD enabled (remap rings 1,2 & 3)
  2292. *
  2293. * @remap1: output parameter indicates reo remap 1 register value
  2294. * @remap2: output parameter indicates reo remap 2 register value
  2295. * Return: bool type, true if remap is configured else false.
  2296. */
  2297. bool dp_reo_remap_config(struct dp_soc *soc, uint32_t *remap1, uint32_t *remap2)
  2298. {
  2299. *remap1 = HAL_REO_REMAP_IX2(REO_REMAP_SW1, 16) |
  2300. HAL_REO_REMAP_IX2(REO_REMAP_SW2, 17) |
  2301. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 18) |
  2302. HAL_REO_REMAP_IX2(REO_REMAP_SW1, 19) |
  2303. HAL_REO_REMAP_IX2(REO_REMAP_SW2, 20) |
  2304. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 21) |
  2305. HAL_REO_REMAP_IX2(REO_REMAP_SW1, 22) |
  2306. HAL_REO_REMAP_IX2(REO_REMAP_SW2, 23);
  2307. *remap2 = HAL_REO_REMAP_IX3(REO_REMAP_SW3, 24) |
  2308. HAL_REO_REMAP_IX3(REO_REMAP_SW1, 25) |
  2309. HAL_REO_REMAP_IX3(REO_REMAP_SW2, 26) |
  2310. HAL_REO_REMAP_IX3(REO_REMAP_SW3, 27) |
  2311. HAL_REO_REMAP_IX3(REO_REMAP_SW1, 28) |
  2312. HAL_REO_REMAP_IX3(REO_REMAP_SW2, 29) |
  2313. HAL_REO_REMAP_IX3(REO_REMAP_SW3, 30) |
  2314. HAL_REO_REMAP_IX3(REO_REMAP_SW1, 31);
  2315. dp_debug("remap1 %x remap2 %x", *remap1, *remap2);
  2316. return true;
  2317. }
  2318. #else
  2319. static bool dp_reo_remap_config(struct dp_soc *soc,
  2320. uint32_t *remap1,
  2321. uint32_t *remap2)
  2322. {
  2323. uint8_t offload_radio = wlan_cfg_get_dp_soc_nss_cfg(soc->wlan_cfg_ctx);
  2324. uint8_t target_type;
  2325. target_type = hal_get_target_type(soc->hal_soc);
  2326. switch (offload_radio) {
  2327. case dp_nss_cfg_default:
  2328. *remap1 = HAL_REO_REMAP_IX2(REO_REMAP_SW1, 16) |
  2329. HAL_REO_REMAP_IX2(REO_REMAP_SW2, 17) |
  2330. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 18) |
  2331. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 19) |
  2332. HAL_REO_REMAP_IX2(REO_REMAP_SW1, 20) |
  2333. HAL_REO_REMAP_IX2(REO_REMAP_SW2, 21) |
  2334. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 22) |
  2335. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 23);
  2336. *remap2 = HAL_REO_REMAP_IX3(REO_REMAP_SW1, 24) |
  2337. HAL_REO_REMAP_IX3(REO_REMAP_SW2, 25) |
  2338. HAL_REO_REMAP_IX3(REO_REMAP_SW3, 26) |
  2339. HAL_REO_REMAP_IX3(REO_REMAP_SW4, 27) |
  2340. HAL_REO_REMAP_IX3(REO_REMAP_SW1, 28) |
  2341. HAL_REO_REMAP_IX3(REO_REMAP_SW2, 29) |
  2342. HAL_REO_REMAP_IX3(REO_REMAP_SW3, 30) |
  2343. HAL_REO_REMAP_IX3(REO_REMAP_SW4, 31);
  2344. break;
  2345. case dp_nss_cfg_first_radio:
  2346. *remap1 = HAL_REO_REMAP_IX2(REO_REMAP_SW2, 16) |
  2347. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 17) |
  2348. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 18) |
  2349. HAL_REO_REMAP_IX2(REO_REMAP_SW2, 19) |
  2350. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 20) |
  2351. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 21) |
  2352. HAL_REO_REMAP_IX2(REO_REMAP_SW2, 22) |
  2353. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 23);
  2354. *remap2 = HAL_REO_REMAP_IX3(REO_REMAP_SW4, 24) |
  2355. HAL_REO_REMAP_IX3(REO_REMAP_SW2, 25) |
  2356. HAL_REO_REMAP_IX3(REO_REMAP_SW3, 26) |
  2357. HAL_REO_REMAP_IX3(REO_REMAP_SW4, 27) |
  2358. HAL_REO_REMAP_IX3(REO_REMAP_SW2, 28) |
  2359. HAL_REO_REMAP_IX3(REO_REMAP_SW3, 29) |
  2360. HAL_REO_REMAP_IX3(REO_REMAP_SW4, 30) |
  2361. HAL_REO_REMAP_IX3(REO_REMAP_SW2, 31);
  2362. break;
  2363. case dp_nss_cfg_second_radio:
  2364. *remap1 = HAL_REO_REMAP_IX2(REO_REMAP_SW1, 16) |
  2365. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 17) |
  2366. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 18) |
  2367. HAL_REO_REMAP_IX2(REO_REMAP_SW1, 19) |
  2368. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 20) |
  2369. HAL_REO_REMAP_IX2(REO_REMAP_SW4, 21) |
  2370. HAL_REO_REMAP_IX2(REO_REMAP_SW1, 22) |
  2371. HAL_REO_REMAP_IX2(REO_REMAP_SW3, 23);
  2372. *remap2 = HAL_REO_REMAP_IX3(REO_REMAP_SW4, 24) |
  2373. HAL_REO_REMAP_IX3(REO_REMAP_SW1, 25) |
  2374. HAL_REO_REMAP_IX3(REO_REMAP_SW3, 26) |
  2375. HAL_REO_REMAP_IX3(REO_REMAP_SW4, 27) |
  2376. HAL_REO_REMAP_IX3(REO_REMAP_SW1, 28) |
  2377. HAL_REO_REMAP_IX3(REO_REMAP_SW3, 29) |
  2378. HAL_REO_REMAP_IX3(REO_REMAP_SW4, 30) |
  2379. HAL_REO_REMAP_IX3(REO_REMAP_SW1, 31);
  2380. break;
  2381. case dp_nss_cfg_dbdc:
  2382. case dp_nss_cfg_dbtc:
  2383. /* return false if both or all are offloaded to NSS */
  2384. return false;
  2385. }
  2386. dp_debug("remap1 %x remap2 %x offload_radio %u",
  2387. *remap1, *remap2, offload_radio);
  2388. return true;
  2389. }
  2390. #endif /* IPA_OFFLOAD */
  2391. /*
  2392. * dp_reo_frag_dst_set() - configure reo register to set the
  2393. * fragment destination ring
  2394. * @soc : Datapath soc
  2395. * @frag_dst_ring : output parameter to set fragment destination ring
  2396. *
  2397. * Based on offload_radio below fragment destination rings is selected
  2398. * 0 - TCL
  2399. * 1 - SW1
  2400. * 2 - SW2
  2401. * 3 - SW3
  2402. * 4 - SW4
  2403. * 5 - Release
  2404. * 6 - FW
  2405. * 7 - alternate select
  2406. *
  2407. * return: void
  2408. */
  2409. static void dp_reo_frag_dst_set(struct dp_soc *soc, uint8_t *frag_dst_ring)
  2410. {
  2411. uint8_t offload_radio = wlan_cfg_get_dp_soc_nss_cfg(soc->wlan_cfg_ctx);
  2412. switch (offload_radio) {
  2413. case dp_nss_cfg_default:
  2414. *frag_dst_ring = HAL_SRNG_REO_EXCEPTION;
  2415. break;
  2416. case dp_nss_cfg_first_radio:
  2417. /*
  2418. * This configuration is valid for single band radio which
  2419. * is also NSS offload.
  2420. */
  2421. case dp_nss_cfg_dbdc:
  2422. case dp_nss_cfg_dbtc:
  2423. *frag_dst_ring = HAL_SRNG_REO_ALTERNATE_SELECT;
  2424. break;
  2425. default:
  2426. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2427. FL("dp_reo_frag_dst_set invalid offload radio config"));
  2428. break;
  2429. }
  2430. }
  2431. #ifdef ENABLE_VERBOSE_DEBUG
  2432. static void dp_enable_verbose_debug(struct dp_soc *soc)
  2433. {
  2434. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx;
  2435. soc_cfg_ctx = soc->wlan_cfg_ctx;
  2436. if (soc_cfg_ctx->per_pkt_trace & dp_verbose_debug_mask)
  2437. is_dp_verbose_debug_enabled = true;
  2438. if (soc_cfg_ctx->per_pkt_trace & hal_verbose_debug_mask)
  2439. hal_set_verbose_debug(true);
  2440. else
  2441. hal_set_verbose_debug(false);
  2442. }
  2443. #else
  2444. static void dp_enable_verbose_debug(struct dp_soc *soc)
  2445. {
  2446. }
  2447. #endif
  2448. /*
  2449. * dp_soc_cmn_setup() - Common SoC level initializion
  2450. * @soc: Datapath SOC handle
  2451. *
  2452. * This is an internal function used to setup common SOC data structures,
  2453. * to be called from PDEV attach after receiving HW mode capabilities from FW
  2454. */
  2455. static int dp_soc_cmn_setup(struct dp_soc *soc)
  2456. {
  2457. int i, cached;
  2458. struct hal_reo_params reo_params;
  2459. int tx_ring_size;
  2460. int tx_comp_ring_size;
  2461. int reo_dst_ring_size;
  2462. uint32_t entries;
  2463. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx;
  2464. if (qdf_atomic_read(&soc->cmn_init_done))
  2465. return 0;
  2466. if (dp_hw_link_desc_pool_setup(soc))
  2467. goto fail1;
  2468. soc_cfg_ctx = soc->wlan_cfg_ctx;
  2469. dp_enable_verbose_debug(soc);
  2470. /* Setup SRNG rings */
  2471. /* Common rings */
  2472. entries = wlan_cfg_get_dp_soc_wbm_release_ring_size(soc_cfg_ctx);
  2473. if (dp_srng_setup(soc, &soc->wbm_desc_rel_ring, SW2WBM_RELEASE, 0, 0,
  2474. entries, 0)) {
  2475. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2476. FL("dp_srng_setup failed for wbm_desc_rel_ring"));
  2477. goto fail1;
  2478. }
  2479. qdf_minidump_log(soc->wbm_desc_rel_ring.base_vaddr_unaligned,
  2480. soc->wbm_desc_rel_ring.alloc_size,
  2481. "wbm_desc_rel_ring");
  2482. soc->num_tcl_data_rings = 0;
  2483. /* Tx data rings */
  2484. if (!wlan_cfg_per_pdev_tx_ring(soc_cfg_ctx)) {
  2485. soc->num_tcl_data_rings =
  2486. wlan_cfg_num_tcl_data_rings(soc_cfg_ctx);
  2487. tx_comp_ring_size =
  2488. wlan_cfg_tx_comp_ring_size(soc_cfg_ctx);
  2489. tx_ring_size =
  2490. wlan_cfg_tx_ring_size(soc_cfg_ctx);
  2491. for (i = 0; i < soc->num_tcl_data_rings; i++) {
  2492. if (dp_srng_setup(soc, &soc->tcl_data_ring[i],
  2493. TCL_DATA, i, 0, tx_ring_size, 0)) {
  2494. QDF_TRACE(QDF_MODULE_ID_DP,
  2495. QDF_TRACE_LEVEL_ERROR,
  2496. FL("dp_srng_setup failed for tcl_data_ring[%d]"), i);
  2497. goto fail1;
  2498. }
  2499. /* Disable cached desc if NSS offload is enabled */
  2500. cached = WLAN_CFG_DST_RING_CACHED_DESC;
  2501. if (wlan_cfg_get_dp_soc_nss_cfg(soc_cfg_ctx))
  2502. cached = 0;
  2503. /*
  2504. * TBD: Set IPA WBM ring size with ini IPA UC tx buffer
  2505. * count
  2506. */
  2507. if (dp_srng_setup(soc, &soc->tx_comp_ring[i],
  2508. WBM2SW_RELEASE, i, 0,
  2509. tx_comp_ring_size,
  2510. cached)) {
  2511. QDF_TRACE(QDF_MODULE_ID_DP,
  2512. QDF_TRACE_LEVEL_ERROR,
  2513. FL("dp_srng_setup failed for tx_comp_ring[%d]"), i);
  2514. goto fail1;
  2515. }
  2516. }
  2517. } else {
  2518. /* This will be incremented during per pdev ring setup */
  2519. soc->num_tcl_data_rings = 0;
  2520. }
  2521. if (dp_tx_soc_attach(soc)) {
  2522. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2523. FL("dp_tx_soc_attach failed"));
  2524. goto fail1;
  2525. }
  2526. entries = wlan_cfg_get_dp_soc_tcl_cmd_ring_size(soc_cfg_ctx);
  2527. /* TCL command and status rings */
  2528. if (dp_srng_setup(soc, &soc->tcl_cmd_ring, TCL_CMD, 0, 0,
  2529. entries, 0)) {
  2530. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2531. FL("dp_srng_setup failed for tcl_cmd_ring"));
  2532. goto fail2;
  2533. }
  2534. entries = wlan_cfg_get_dp_soc_tcl_status_ring_size(soc_cfg_ctx);
  2535. if (dp_srng_setup(soc, &soc->tcl_status_ring, TCL_STATUS, 0, 0,
  2536. entries, 0)) {
  2537. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2538. FL("dp_srng_setup failed for tcl_status_ring"));
  2539. goto fail2;
  2540. }
  2541. reo_dst_ring_size = wlan_cfg_get_reo_dst_ring_size(soc->wlan_cfg_ctx);
  2542. /* TBD: call dp_tx_init to setup Tx SW descriptors and MSDU extension
  2543. * descriptors
  2544. */
  2545. /* Rx data rings */
  2546. if (!wlan_cfg_per_pdev_rx_ring(soc_cfg_ctx)) {
  2547. soc->num_reo_dest_rings =
  2548. wlan_cfg_num_reo_dest_rings(soc_cfg_ctx);
  2549. QDF_TRACE(QDF_MODULE_ID_DP,
  2550. QDF_TRACE_LEVEL_INFO,
  2551. FL("num_reo_dest_rings %d"), soc->num_reo_dest_rings);
  2552. /* Disable cached desc if NSS offload is enabled */
  2553. cached = WLAN_CFG_DST_RING_CACHED_DESC;
  2554. if (wlan_cfg_get_dp_soc_nss_cfg(soc_cfg_ctx))
  2555. cached = 0;
  2556. for (i = 0; i < soc->num_reo_dest_rings; i++) {
  2557. if (dp_srng_setup(soc, &soc->reo_dest_ring[i], REO_DST,
  2558. i, 0, reo_dst_ring_size, cached)) {
  2559. QDF_TRACE(QDF_MODULE_ID_DP,
  2560. QDF_TRACE_LEVEL_ERROR,
  2561. FL(RNG_ERR "reo_dest_ring [%d]"), i);
  2562. goto fail2;
  2563. }
  2564. }
  2565. } else {
  2566. /* This will be incremented during per pdev ring setup */
  2567. soc->num_reo_dest_rings = 0;
  2568. }
  2569. entries = wlan_cfg_get_dp_soc_rxdma_err_dst_ring_size(soc_cfg_ctx);
  2570. /* LMAC RxDMA to SW Rings configuration */
  2571. if (!wlan_cfg_per_pdev_lmac_ring(soc_cfg_ctx)) {
  2572. /* Only valid for MCL */
  2573. struct dp_pdev *pdev = soc->pdev_list[0];
  2574. for (i = 0; i < MAX_RX_MAC_RINGS; i++) {
  2575. if (dp_srng_setup(soc, &pdev->rxdma_err_dst_ring[i],
  2576. RXDMA_DST, 0, i, entries, 0)) {
  2577. QDF_TRACE(QDF_MODULE_ID_DP,
  2578. QDF_TRACE_LEVEL_ERROR,
  2579. FL(RNG_ERR "rxdma_err_dst_ring"));
  2580. goto fail2;
  2581. }
  2582. }
  2583. }
  2584. /* TBD: call dp_rx_init to setup Rx SW descriptors */
  2585. /* REO reinjection ring */
  2586. entries = wlan_cfg_get_dp_soc_reo_reinject_ring_size(soc_cfg_ctx);
  2587. if (dp_srng_setup(soc, &soc->reo_reinject_ring, REO_REINJECT, 0, 0,
  2588. entries, 0)) {
  2589. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2590. FL("dp_srng_setup failed for reo_reinject_ring"));
  2591. goto fail2;
  2592. }
  2593. /* Rx release ring */
  2594. if (dp_srng_setup(soc, &soc->rx_rel_ring, WBM2SW_RELEASE, 3, 0,
  2595. wlan_cfg_get_dp_soc_rx_release_ring_size(soc_cfg_ctx),
  2596. 0)) {
  2597. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2598. FL("dp_srng_setup failed for rx_rel_ring"));
  2599. goto fail2;
  2600. }
  2601. /* Rx exception ring */
  2602. entries = wlan_cfg_get_dp_soc_reo_exception_ring_size(soc_cfg_ctx);
  2603. if (dp_srng_setup(soc, &soc->reo_exception_ring,
  2604. REO_EXCEPTION, 0, MAX_REO_DEST_RINGS, entries, 0)) {
  2605. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2606. FL("dp_srng_setup failed for reo_exception_ring"));
  2607. goto fail2;
  2608. }
  2609. /* REO command and status rings */
  2610. if (dp_srng_setup(soc, &soc->reo_cmd_ring, REO_CMD, 0, 0,
  2611. wlan_cfg_get_dp_soc_reo_cmd_ring_size(soc_cfg_ctx),
  2612. 0)) {
  2613. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2614. FL("dp_srng_setup failed for reo_cmd_ring"));
  2615. goto fail2;
  2616. }
  2617. hal_reo_init_cmd_ring(soc->hal_soc, soc->reo_cmd_ring.hal_srng);
  2618. TAILQ_INIT(&soc->rx.reo_cmd_list);
  2619. qdf_spinlock_create(&soc->rx.reo_cmd_lock);
  2620. if (dp_srng_setup(soc, &soc->reo_status_ring, REO_STATUS, 0, 0,
  2621. wlan_cfg_get_dp_soc_reo_status_ring_size(soc_cfg_ctx),
  2622. 0)) {
  2623. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2624. FL("dp_srng_setup failed for reo_status_ring"));
  2625. goto fail2;
  2626. }
  2627. /*
  2628. * Skip registering hw ring interrupts for WMAC2 on IPQ6018
  2629. * WMAC2 is not there in IPQ6018 platform.
  2630. */
  2631. if (hal_get_target_type(soc->hal_soc) == TARGET_TYPE_QCA6018) {
  2632. dp_soc_disable_mac2_intr_mask(soc);
  2633. }
  2634. /* Reset the cpu ring map if radio is NSS offloaded */
  2635. if (wlan_cfg_get_dp_soc_nss_cfg(soc_cfg_ctx)) {
  2636. dp_soc_reset_cpu_ring_map(soc);
  2637. dp_soc_reset_intr_mask(soc);
  2638. }
  2639. /* Setup HW REO */
  2640. qdf_mem_zero(&reo_params, sizeof(reo_params));
  2641. if (wlan_cfg_is_rx_hash_enabled(soc_cfg_ctx)) {
  2642. /*
  2643. * Reo ring remap is not required if both radios
  2644. * are offloaded to NSS
  2645. */
  2646. if (!dp_reo_remap_config(soc,
  2647. &reo_params.remap1,
  2648. &reo_params.remap2))
  2649. goto out;
  2650. reo_params.rx_hash_enabled = true;
  2651. }
  2652. /* setup the global rx defrag waitlist */
  2653. TAILQ_INIT(&soc->rx.defrag.waitlist);
  2654. soc->rx.defrag.timeout_ms =
  2655. wlan_cfg_get_rx_defrag_min_timeout(soc_cfg_ctx);
  2656. soc->rx.defrag.next_flush_ms = 0;
  2657. soc->rx.flags.defrag_timeout_check =
  2658. wlan_cfg_get_defrag_timeout_check(soc_cfg_ctx);
  2659. qdf_spinlock_create(&soc->rx.defrag.defrag_lock);
  2660. out:
  2661. /*
  2662. * set the fragment destination ring
  2663. */
  2664. dp_reo_frag_dst_set(soc, &reo_params.frag_dst_ring);
  2665. hal_reo_setup(soc->hal_soc, &reo_params);
  2666. qdf_atomic_set(&soc->cmn_init_done, 1);
  2667. dp_soc_wds_attach(soc);
  2668. qdf_nbuf_queue_init(&soc->htt_stats.msg);
  2669. return 0;
  2670. fail2:
  2671. dp_tx_soc_detach(soc);
  2672. fail1:
  2673. /*
  2674. * Cleanup will be done as part of soc_detach, which will
  2675. * be called on pdev attach failure
  2676. */
  2677. return QDF_STATUS_E_FAILURE;
  2678. }
  2679. /*
  2680. * dp_soc_cmn_cleanup() - Common SoC level De-initializion
  2681. *
  2682. * @soc: Datapath SOC handle
  2683. *
  2684. * This function is responsible for cleaning up DP resource of Soc
  2685. * initialled in dp_pdev_attach_wifi3-->dp_soc_cmn_setup, since
  2686. * dp_soc_detach_wifi3 could not identify some of them
  2687. * whether they have done initialized or not accurately.
  2688. *
  2689. */
  2690. static void dp_soc_cmn_cleanup(struct dp_soc *soc)
  2691. {
  2692. dp_tx_soc_detach(soc);
  2693. qdf_spinlock_destroy(&soc->rx.defrag.defrag_lock);
  2694. dp_reo_cmdlist_destroy(soc);
  2695. qdf_spinlock_destroy(&soc->rx.reo_cmd_lock);
  2696. }
  2697. static void dp_pdev_detach_wifi3(struct cdp_pdev *txrx_pdev, int force);
  2698. static QDF_STATUS dp_lro_hash_setup(struct dp_soc *soc, struct dp_pdev *pdev)
  2699. {
  2700. struct cdp_lro_hash_config lro_hash;
  2701. QDF_STATUS status;
  2702. if (!wlan_cfg_is_lro_enabled(soc->wlan_cfg_ctx) &&
  2703. !wlan_cfg_is_gro_enabled(soc->wlan_cfg_ctx) &&
  2704. !wlan_cfg_is_rx_hash_enabled(soc->wlan_cfg_ctx)) {
  2705. dp_err("LRO, GRO and RX hash disabled");
  2706. return QDF_STATUS_E_FAILURE;
  2707. }
  2708. qdf_mem_zero(&lro_hash, sizeof(lro_hash));
  2709. if (wlan_cfg_is_lro_enabled(soc->wlan_cfg_ctx) ||
  2710. wlan_cfg_is_gro_enabled(soc->wlan_cfg_ctx)) {
  2711. lro_hash.lro_enable = 1;
  2712. lro_hash.tcp_flag = QDF_TCPHDR_ACK;
  2713. lro_hash.tcp_flag_mask = QDF_TCPHDR_FIN | QDF_TCPHDR_SYN |
  2714. QDF_TCPHDR_RST | QDF_TCPHDR_ACK | QDF_TCPHDR_URG |
  2715. QDF_TCPHDR_ECE | QDF_TCPHDR_CWR;
  2716. }
  2717. qdf_get_random_bytes(lro_hash.toeplitz_hash_ipv4,
  2718. (sizeof(lro_hash.toeplitz_hash_ipv4[0]) *
  2719. LRO_IPV4_SEED_ARR_SZ));
  2720. qdf_get_random_bytes(lro_hash.toeplitz_hash_ipv6,
  2721. (sizeof(lro_hash.toeplitz_hash_ipv6[0]) *
  2722. LRO_IPV6_SEED_ARR_SZ));
  2723. qdf_assert(soc->cdp_soc.ol_ops->lro_hash_config);
  2724. if (!soc->cdp_soc.ol_ops->lro_hash_config) {
  2725. QDF_BUG(0);
  2726. dp_err("lro_hash_config not configured");
  2727. return QDF_STATUS_E_FAILURE;
  2728. }
  2729. status = soc->cdp_soc.ol_ops->lro_hash_config(pdev->ctrl_pdev,
  2730. &lro_hash);
  2731. if (!QDF_IS_STATUS_SUCCESS(status)) {
  2732. dp_err("failed to send lro_hash_config to FW %u", status);
  2733. return status;
  2734. }
  2735. dp_info("LRO CMD config: lro_enable: 0x%x tcp_flag 0x%x tcp_flag_mask 0x%x",
  2736. lro_hash.lro_enable, lro_hash.tcp_flag,
  2737. lro_hash.tcp_flag_mask);
  2738. dp_info("toeplitz_hash_ipv4:");
  2739. qdf_trace_hex_dump(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2740. lro_hash.toeplitz_hash_ipv4,
  2741. (sizeof(lro_hash.toeplitz_hash_ipv4[0]) *
  2742. LRO_IPV4_SEED_ARR_SZ));
  2743. dp_info("toeplitz_hash_ipv6:");
  2744. qdf_trace_hex_dump(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  2745. lro_hash.toeplitz_hash_ipv6,
  2746. (sizeof(lro_hash.toeplitz_hash_ipv6[0]) *
  2747. LRO_IPV6_SEED_ARR_SZ));
  2748. return status;
  2749. }
  2750. /*
  2751. * dp_rxdma_ring_setup() - configure the RX DMA rings
  2752. * @soc: data path SoC handle
  2753. * @pdev: Physical device handle
  2754. *
  2755. * Return: 0 - success, > 0 - failure
  2756. */
  2757. #ifdef QCA_HOST2FW_RXBUF_RING
  2758. static int dp_rxdma_ring_setup(struct dp_soc *soc,
  2759. struct dp_pdev *pdev)
  2760. {
  2761. struct wlan_cfg_dp_pdev_ctxt *pdev_cfg_ctx;
  2762. int max_mac_rings;
  2763. int i;
  2764. int ring_size;
  2765. pdev_cfg_ctx = pdev->wlan_cfg_ctx;
  2766. max_mac_rings = wlan_cfg_get_num_mac_rings(pdev_cfg_ctx);
  2767. ring_size = wlan_cfg_get_rx_dma_buf_ring_size(pdev_cfg_ctx);
  2768. for (i = 0; i < max_mac_rings; i++) {
  2769. dp_verbose_debug("pdev_id %d mac_id %d", pdev->pdev_id, i);
  2770. if (dp_srng_setup(soc, &pdev->rx_mac_buf_ring[i],
  2771. RXDMA_BUF, 1, i, ring_size, 0)) {
  2772. QDF_TRACE(QDF_MODULE_ID_DP,
  2773. QDF_TRACE_LEVEL_ERROR,
  2774. FL("failed rx mac ring setup"));
  2775. return QDF_STATUS_E_FAILURE;
  2776. }
  2777. }
  2778. return QDF_STATUS_SUCCESS;
  2779. }
  2780. #else
  2781. static int dp_rxdma_ring_setup(struct dp_soc *soc,
  2782. struct dp_pdev *pdev)
  2783. {
  2784. return QDF_STATUS_SUCCESS;
  2785. }
  2786. #endif
  2787. /**
  2788. * dp_dscp_tid_map_setup(): Initialize the dscp-tid maps
  2789. * @pdev - DP_PDEV handle
  2790. *
  2791. * Return: void
  2792. */
  2793. static inline void
  2794. dp_dscp_tid_map_setup(struct dp_pdev *pdev)
  2795. {
  2796. uint8_t map_id;
  2797. struct dp_soc *soc = pdev->soc;
  2798. if (!soc)
  2799. return;
  2800. for (map_id = 0; map_id < DP_MAX_TID_MAPS; map_id++) {
  2801. qdf_mem_copy(pdev->dscp_tid_map[map_id],
  2802. default_dscp_tid_map,
  2803. sizeof(default_dscp_tid_map));
  2804. }
  2805. for (map_id = 0; map_id < soc->num_hw_dscp_tid_map; map_id++) {
  2806. hal_tx_set_dscp_tid_map(soc->hal_soc,
  2807. default_dscp_tid_map,
  2808. map_id);
  2809. }
  2810. }
  2811. /**
  2812. * dp_pcp_tid_map_setup(): Initialize the pcp-tid maps
  2813. * @pdev - DP_PDEV handle
  2814. *
  2815. * Return: void
  2816. */
  2817. static inline void
  2818. dp_pcp_tid_map_setup(struct dp_pdev *pdev)
  2819. {
  2820. struct dp_soc *soc = pdev->soc;
  2821. if (!soc)
  2822. return;
  2823. qdf_mem_copy(soc->pcp_tid_map, default_pcp_tid_map,
  2824. sizeof(default_pcp_tid_map));
  2825. hal_tx_set_pcp_tid_map_default(soc->hal_soc, default_pcp_tid_map);
  2826. }
  2827. #ifdef IPA_OFFLOAD
  2828. /**
  2829. * dp_setup_ipa_rx_refill_buf_ring - Setup second Rx refill buffer ring
  2830. * @soc: data path instance
  2831. * @pdev: core txrx pdev context
  2832. *
  2833. * Return: QDF_STATUS_SUCCESS: success
  2834. * QDF_STATUS_E_RESOURCES: Error return
  2835. */
  2836. static int dp_setup_ipa_rx_refill_buf_ring(struct dp_soc *soc,
  2837. struct dp_pdev *pdev)
  2838. {
  2839. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx;
  2840. int entries;
  2841. soc_cfg_ctx = soc->wlan_cfg_ctx;
  2842. entries = wlan_cfg_get_dp_soc_rxdma_refill_ring_size(soc_cfg_ctx);
  2843. /* Setup second Rx refill buffer ring */
  2844. if (dp_srng_setup(soc, &pdev->rx_refill_buf_ring2, RXDMA_BUF,
  2845. IPA_RX_REFILL_BUF_RING_IDX, pdev->pdev_id, entries, 0)
  2846. ) {
  2847. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  2848. FL("dp_srng_setup failed second rx refill ring"));
  2849. return QDF_STATUS_E_FAILURE;
  2850. }
  2851. return QDF_STATUS_SUCCESS;
  2852. }
  2853. /**
  2854. * dp_cleanup_ipa_rx_refill_buf_ring - Cleanup second Rx refill buffer ring
  2855. * @soc: data path instance
  2856. * @pdev: core txrx pdev context
  2857. *
  2858. * Return: void
  2859. */
  2860. static void dp_cleanup_ipa_rx_refill_buf_ring(struct dp_soc *soc,
  2861. struct dp_pdev *pdev)
  2862. {
  2863. dp_srng_cleanup(soc, &pdev->rx_refill_buf_ring2, RXDMA_BUF,
  2864. IPA_RX_REFILL_BUF_RING_IDX);
  2865. }
  2866. #else
  2867. static int dp_setup_ipa_rx_refill_buf_ring(struct dp_soc *soc,
  2868. struct dp_pdev *pdev)
  2869. {
  2870. return QDF_STATUS_SUCCESS;
  2871. }
  2872. static void dp_cleanup_ipa_rx_refill_buf_ring(struct dp_soc *soc,
  2873. struct dp_pdev *pdev)
  2874. {
  2875. }
  2876. #endif
  2877. #if !defined(DISABLE_MON_CONFIG)
  2878. /**
  2879. * dp_mon_rings_setup() - Initialize Monitor rings based on target
  2880. * @soc: soc handle
  2881. * @pdev: physical device handle
  2882. *
  2883. * Return: nonzero on failure and zero on success
  2884. */
  2885. static
  2886. QDF_STATUS dp_mon_rings_setup(struct dp_soc *soc, struct dp_pdev *pdev)
  2887. {
  2888. int mac_id = 0;
  2889. int pdev_id = pdev->pdev_id;
  2890. int entries;
  2891. struct wlan_cfg_dp_pdev_ctxt *pdev_cfg_ctx;
  2892. pdev_cfg_ctx = pdev->wlan_cfg_ctx;
  2893. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  2894. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  2895. if (soc->wlan_cfg_ctx->rxdma1_enable) {
  2896. entries =
  2897. wlan_cfg_get_dma_mon_buf_ring_size(pdev_cfg_ctx);
  2898. if (dp_srng_setup(soc,
  2899. &pdev->rxdma_mon_buf_ring[mac_id],
  2900. RXDMA_MONITOR_BUF, 0, mac_for_pdev,
  2901. entries, 0)) {
  2902. QDF_TRACE(QDF_MODULE_ID_DP,
  2903. QDF_TRACE_LEVEL_ERROR,
  2904. FL(RNG_ERR "rxdma_mon_buf_ring "));
  2905. return QDF_STATUS_E_NOMEM;
  2906. }
  2907. entries =
  2908. wlan_cfg_get_dma_mon_dest_ring_size(pdev_cfg_ctx);
  2909. if (dp_srng_setup(soc,
  2910. &pdev->rxdma_mon_dst_ring[mac_id],
  2911. RXDMA_MONITOR_DST, 0, mac_for_pdev,
  2912. entries, 0)) {
  2913. QDF_TRACE(QDF_MODULE_ID_DP,
  2914. QDF_TRACE_LEVEL_ERROR,
  2915. FL(RNG_ERR "rxdma_mon_dst_ring"));
  2916. return QDF_STATUS_E_NOMEM;
  2917. }
  2918. entries =
  2919. wlan_cfg_get_dma_mon_stat_ring_size(pdev_cfg_ctx);
  2920. if (dp_srng_setup(soc,
  2921. &pdev->rxdma_mon_status_ring[mac_id],
  2922. RXDMA_MONITOR_STATUS, 0, mac_for_pdev,
  2923. entries, 0)) {
  2924. QDF_TRACE(QDF_MODULE_ID_DP,
  2925. QDF_TRACE_LEVEL_ERROR,
  2926. FL(RNG_ERR "rxdma_mon_status_ring"));
  2927. return QDF_STATUS_E_NOMEM;
  2928. }
  2929. entries =
  2930. wlan_cfg_get_dma_mon_desc_ring_size(pdev_cfg_ctx);
  2931. if (dp_srng_setup(soc,
  2932. &pdev->rxdma_mon_desc_ring[mac_id],
  2933. RXDMA_MONITOR_DESC, 0, mac_for_pdev,
  2934. entries, 0)) {
  2935. QDF_TRACE(QDF_MODULE_ID_DP,
  2936. QDF_TRACE_LEVEL_ERROR,
  2937. FL(RNG_ERR "rxdma_mon_desc_ring"));
  2938. return QDF_STATUS_E_NOMEM;
  2939. }
  2940. } else {
  2941. entries =
  2942. wlan_cfg_get_dma_mon_stat_ring_size(pdev_cfg_ctx);
  2943. if (dp_srng_setup(soc,
  2944. &pdev->rxdma_mon_status_ring[mac_id],
  2945. RXDMA_MONITOR_STATUS, 0, mac_for_pdev,
  2946. entries, 0)) {
  2947. QDF_TRACE(QDF_MODULE_ID_DP,
  2948. QDF_TRACE_LEVEL_ERROR,
  2949. FL(RNG_ERR "rxdma_mon_status_ring"));
  2950. return QDF_STATUS_E_NOMEM;
  2951. }
  2952. }
  2953. }
  2954. return QDF_STATUS_SUCCESS;
  2955. }
  2956. #else
  2957. static
  2958. QDF_STATUS dp_mon_rings_setup(struct dp_soc *soc, struct dp_pdev *pdev)
  2959. {
  2960. return QDF_STATUS_SUCCESS;
  2961. }
  2962. #endif
  2963. /*dp_iterate_update_peer_list - update peer stats on cal client timer
  2964. * @pdev_hdl: pdev handle
  2965. */
  2966. #ifdef ATH_SUPPORT_EXT_STAT
  2967. void dp_iterate_update_peer_list(struct cdp_pdev *pdev_hdl)
  2968. {
  2969. struct dp_pdev *pdev = (struct dp_pdev *)pdev_hdl;
  2970. struct dp_soc *soc = pdev->soc;
  2971. struct dp_vdev *vdev = NULL;
  2972. struct dp_peer *peer = NULL;
  2973. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  2974. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  2975. DP_PDEV_ITERATE_VDEV_LIST(pdev, vdev) {
  2976. DP_VDEV_ITERATE_PEER_LIST(vdev, peer) {
  2977. dp_cal_client_update_peer_stats(&peer->stats);
  2978. }
  2979. }
  2980. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  2981. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  2982. }
  2983. #else
  2984. void dp_iterate_update_peer_list(struct cdp_pdev *pdev_hdl)
  2985. {
  2986. }
  2987. #endif
  2988. /*
  2989. * dp_htt_ppdu_stats_attach() - attach resources for HTT PPDU stats processing
  2990. * @pdev: Datapath PDEV handle
  2991. *
  2992. * Return: QDF_STATUS_SUCCESS: Success
  2993. * QDF_STATUS_E_NOMEM: Error
  2994. */
  2995. static QDF_STATUS dp_htt_ppdu_stats_attach(struct dp_pdev *pdev)
  2996. {
  2997. pdev->ppdu_tlv_buf = qdf_mem_malloc(HTT_T2H_MAX_MSG_SIZE);
  2998. if (!pdev->ppdu_tlv_buf) {
  2999. QDF_TRACE_ERROR(QDF_MODULE_ID_DP, "ppdu_tlv_buf alloc fail");
  3000. return QDF_STATUS_E_NOMEM;
  3001. }
  3002. return QDF_STATUS_SUCCESS;
  3003. }
  3004. /*
  3005. * dp_pdev_attach_wifi3() - attach txrx pdev
  3006. * @ctrl_pdev: Opaque PDEV object
  3007. * @txrx_soc: Datapath SOC handle
  3008. * @htc_handle: HTC handle for host-target interface
  3009. * @qdf_osdev: QDF OS device
  3010. * @pdev_id: PDEV ID
  3011. *
  3012. * Return: DP PDEV handle on success, NULL on failure
  3013. */
  3014. static struct cdp_pdev *dp_pdev_attach_wifi3(struct cdp_soc_t *txrx_soc,
  3015. struct cdp_ctrl_objmgr_pdev *ctrl_pdev,
  3016. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev, uint8_t pdev_id)
  3017. {
  3018. int ring_size;
  3019. int entries;
  3020. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx;
  3021. int nss_cfg;
  3022. void *sojourn_buf;
  3023. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  3024. struct dp_pdev *pdev = NULL;
  3025. if (dp_is_soc_reinit(soc)) {
  3026. pdev = soc->pdev_list[pdev_id];
  3027. } else {
  3028. pdev = qdf_mem_malloc(sizeof(*pdev));
  3029. qdf_minidump_log(pdev, sizeof(*pdev), "dp_pdev");
  3030. }
  3031. if (!pdev) {
  3032. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3033. FL("DP PDEV memory allocation failed"));
  3034. goto fail0;
  3035. }
  3036. /*
  3037. * Variable to prevent double pdev deinitialization during
  3038. * radio detach execution .i.e. in the absence of any vdev.
  3039. */
  3040. pdev->pdev_deinit = 0;
  3041. pdev->invalid_peer = qdf_mem_malloc(sizeof(struct dp_peer));
  3042. if (!pdev->invalid_peer) {
  3043. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3044. FL("Invalid peer memory allocation failed"));
  3045. qdf_mem_free(pdev);
  3046. goto fail0;
  3047. }
  3048. soc_cfg_ctx = soc->wlan_cfg_ctx;
  3049. pdev->wlan_cfg_ctx = wlan_cfg_pdev_attach(soc->ctrl_psoc);
  3050. if (!pdev->wlan_cfg_ctx) {
  3051. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3052. FL("pdev cfg_attach failed"));
  3053. qdf_mem_free(pdev->invalid_peer);
  3054. qdf_mem_free(pdev);
  3055. goto fail0;
  3056. }
  3057. /*
  3058. * set nss pdev config based on soc config
  3059. */
  3060. nss_cfg = wlan_cfg_get_dp_soc_nss_cfg(soc_cfg_ctx);
  3061. wlan_cfg_set_dp_pdev_nss_enabled(pdev->wlan_cfg_ctx,
  3062. (nss_cfg & (1 << pdev_id)));
  3063. pdev->soc = soc;
  3064. pdev->ctrl_pdev = ctrl_pdev;
  3065. pdev->pdev_id = pdev_id;
  3066. soc->pdev_list[pdev_id] = pdev;
  3067. pdev->lmac_id = wlan_cfg_get_hw_mac_idx(soc->wlan_cfg_ctx, pdev_id);
  3068. soc->pdev_count++;
  3069. TAILQ_INIT(&pdev->vdev_list);
  3070. qdf_spinlock_create(&pdev->vdev_list_lock);
  3071. pdev->vdev_count = 0;
  3072. qdf_spinlock_create(&pdev->tx_mutex);
  3073. qdf_spinlock_create(&pdev->neighbour_peer_mutex);
  3074. TAILQ_INIT(&pdev->neighbour_peers_list);
  3075. pdev->neighbour_peers_added = false;
  3076. pdev->monitor_configured = false;
  3077. if (dp_soc_cmn_setup(soc)) {
  3078. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3079. FL("dp_soc_cmn_setup failed"));
  3080. goto fail1;
  3081. }
  3082. /* Setup per PDEV TCL rings if configured */
  3083. if (wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  3084. ring_size =
  3085. wlan_cfg_tx_ring_size(soc_cfg_ctx);
  3086. if (dp_srng_setup(soc, &soc->tcl_data_ring[pdev_id], TCL_DATA,
  3087. pdev_id, pdev_id, ring_size, 0)) {
  3088. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3089. FL("dp_srng_setup failed for tcl_data_ring"));
  3090. goto fail1;
  3091. }
  3092. ring_size =
  3093. wlan_cfg_tx_comp_ring_size(soc_cfg_ctx);
  3094. if (dp_srng_setup(soc, &soc->tx_comp_ring[pdev_id],
  3095. WBM2SW_RELEASE, pdev_id, pdev_id,
  3096. ring_size, 0)) {
  3097. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3098. FL("dp_srng_setup failed for tx_comp_ring"));
  3099. goto fail1;
  3100. }
  3101. soc->num_tcl_data_rings++;
  3102. }
  3103. /* Tx specific init */
  3104. if (dp_tx_pdev_attach(pdev)) {
  3105. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3106. FL("dp_tx_pdev_attach failed"));
  3107. goto fail1;
  3108. }
  3109. ring_size = wlan_cfg_get_reo_dst_ring_size(soc->wlan_cfg_ctx);
  3110. /* Setup per PDEV REO rings if configured */
  3111. if (wlan_cfg_per_pdev_rx_ring(soc_cfg_ctx)) {
  3112. if (dp_srng_setup(soc, &soc->reo_dest_ring[pdev_id], REO_DST,
  3113. pdev_id, pdev_id, ring_size, 0)) {
  3114. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3115. FL("dp_srng_setup failed for reo_dest_ringn"));
  3116. goto fail1;
  3117. }
  3118. soc->num_reo_dest_rings++;
  3119. }
  3120. ring_size =
  3121. wlan_cfg_get_dp_soc_rxdma_refill_ring_size(soc->wlan_cfg_ctx);
  3122. if (dp_srng_setup(soc, &pdev->rx_refill_buf_ring, RXDMA_BUF, 0, pdev_id,
  3123. ring_size, 0)) {
  3124. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3125. FL("dp_srng_setup failed rx refill ring"));
  3126. goto fail1;
  3127. }
  3128. if (dp_rxdma_ring_setup(soc, pdev)) {
  3129. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3130. FL("RXDMA ring config failed"));
  3131. goto fail1;
  3132. }
  3133. if (dp_mon_rings_setup(soc, pdev)) {
  3134. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3135. FL("MONITOR rings setup failed"));
  3136. goto fail1;
  3137. }
  3138. entries = wlan_cfg_get_dp_soc_rxdma_err_dst_ring_size(soc_cfg_ctx);
  3139. if (wlan_cfg_per_pdev_lmac_ring(soc->wlan_cfg_ctx)) {
  3140. if (dp_srng_setup(soc, &pdev->rxdma_err_dst_ring[0], RXDMA_DST,
  3141. 0, pdev_id, entries, 0)) {
  3142. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3143. FL(RNG_ERR "rxdma_err_dst_ring"));
  3144. goto fail1;
  3145. }
  3146. }
  3147. if (dp_setup_ipa_rx_refill_buf_ring(soc, pdev))
  3148. goto fail1;
  3149. if (dp_ipa_ring_resource_setup(soc, pdev))
  3150. goto fail1;
  3151. if (dp_ipa_uc_attach(soc, pdev) != QDF_STATUS_SUCCESS) {
  3152. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3153. FL("dp_ipa_uc_attach failed"));
  3154. goto fail1;
  3155. }
  3156. /* Rx specific init */
  3157. if (dp_rx_pdev_attach(pdev)) {
  3158. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3159. FL("dp_rx_pdev_attach failed"));
  3160. goto fail2;
  3161. }
  3162. DP_STATS_INIT(pdev);
  3163. /* Monitor filter init */
  3164. pdev->mon_filter_mode = MON_FILTER_ALL;
  3165. pdev->fp_mgmt_filter = FILTER_MGMT_ALL;
  3166. pdev->fp_ctrl_filter = FILTER_CTRL_ALL;
  3167. pdev->fp_data_filter = FILTER_DATA_ALL;
  3168. pdev->mo_mgmt_filter = FILTER_MGMT_ALL;
  3169. pdev->mo_ctrl_filter = FILTER_CTRL_ALL;
  3170. pdev->mo_data_filter = FILTER_DATA_ALL;
  3171. dp_local_peer_id_pool_init(pdev);
  3172. dp_dscp_tid_map_setup(pdev);
  3173. dp_pcp_tid_map_setup(pdev);
  3174. /* Rx monitor mode specific init */
  3175. if (dp_rx_pdev_mon_attach(pdev)) {
  3176. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  3177. "dp_rx_pdev_mon_attach failed");
  3178. goto fail2;
  3179. }
  3180. if (dp_wdi_event_attach(pdev)) {
  3181. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  3182. "dp_wdi_evet_attach failed");
  3183. goto wdi_attach_fail;
  3184. }
  3185. /* set the reo destination during initialization */
  3186. pdev->reo_dest = pdev->pdev_id + 1;
  3187. /*
  3188. * initialize ppdu tlv list
  3189. */
  3190. TAILQ_INIT(&pdev->ppdu_info_list);
  3191. pdev->tlv_count = 0;
  3192. pdev->list_depth = 0;
  3193. qdf_mem_zero(&pdev->sojourn_stats, sizeof(struct cdp_tx_sojourn_stats));
  3194. pdev->sojourn_buf = qdf_nbuf_alloc(pdev->soc->osdev,
  3195. sizeof(struct cdp_tx_sojourn_stats), 0, 4,
  3196. TRUE);
  3197. if (pdev->sojourn_buf) {
  3198. sojourn_buf = qdf_nbuf_data(pdev->sojourn_buf);
  3199. qdf_mem_zero(sojourn_buf, sizeof(struct cdp_tx_sojourn_stats));
  3200. }
  3201. /* initlialize cal client timer */
  3202. dp_cal_client_attach(&pdev->cal_client_ctx,
  3203. dp_pdev_to_cdp_pdev(pdev),
  3204. pdev->soc->osdev,
  3205. &dp_iterate_update_peer_list);
  3206. qdf_event_create(&pdev->fw_peer_stats_event);
  3207. pdev->num_tx_allowed = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  3208. dp_init_tso_stats(pdev);
  3209. if (dp_htt_ppdu_stats_attach(pdev) != QDF_STATUS_SUCCESS)
  3210. goto fail1;
  3211. dp_tx_ppdu_stats_attach(pdev);
  3212. return (struct cdp_pdev *)pdev;
  3213. wdi_attach_fail:
  3214. /*
  3215. * dp_mon_link_desc_pool_cleanup is done in dp_pdev_detach
  3216. * and hence need not to be done here.
  3217. */
  3218. dp_rx_pdev_mon_detach(pdev);
  3219. fail2:
  3220. dp_rx_pdev_detach(pdev);
  3221. fail1:
  3222. if (pdev->invalid_peer)
  3223. qdf_mem_free(pdev->invalid_peer);
  3224. dp_pdev_detach((struct cdp_pdev *)pdev, 0);
  3225. fail0:
  3226. return NULL;
  3227. }
  3228. /*
  3229. * dp_rxdma_ring_cleanup() - configure the RX DMA rings
  3230. * @soc: data path SoC handle
  3231. * @pdev: Physical device handle
  3232. *
  3233. * Return: void
  3234. */
  3235. #ifdef QCA_HOST2FW_RXBUF_RING
  3236. static void dp_rxdma_ring_cleanup(struct dp_soc *soc,
  3237. struct dp_pdev *pdev)
  3238. {
  3239. int i;
  3240. for (i = 0; i < MAX_RX_MAC_RINGS; i++)
  3241. dp_srng_cleanup(soc, &pdev->rx_mac_buf_ring[i],
  3242. RXDMA_BUF, 1);
  3243. qdf_timer_free(&soc->mon_reap_timer);
  3244. }
  3245. #else
  3246. static void dp_rxdma_ring_cleanup(struct dp_soc *soc,
  3247. struct dp_pdev *pdev)
  3248. {
  3249. }
  3250. #endif
  3251. /*
  3252. * dp_neighbour_peers_detach() - Detach neighbour peers(nac clients)
  3253. * @pdev: device object
  3254. *
  3255. * Return: void
  3256. */
  3257. static void dp_neighbour_peers_detach(struct dp_pdev *pdev)
  3258. {
  3259. struct dp_neighbour_peer *peer = NULL;
  3260. struct dp_neighbour_peer *temp_peer = NULL;
  3261. TAILQ_FOREACH_SAFE(peer, &pdev->neighbour_peers_list,
  3262. neighbour_peer_list_elem, temp_peer) {
  3263. /* delete this peer from the list */
  3264. TAILQ_REMOVE(&pdev->neighbour_peers_list,
  3265. peer, neighbour_peer_list_elem);
  3266. qdf_mem_free(peer);
  3267. }
  3268. qdf_spinlock_destroy(&pdev->neighbour_peer_mutex);
  3269. }
  3270. /**
  3271. * dp_htt_ppdu_stats_detach() - detach stats resources
  3272. * @pdev: Datapath PDEV handle
  3273. *
  3274. * Return: void
  3275. */
  3276. static void dp_htt_ppdu_stats_detach(struct dp_pdev *pdev)
  3277. {
  3278. struct ppdu_info *ppdu_info, *ppdu_info_next;
  3279. TAILQ_FOREACH_SAFE(ppdu_info, &pdev->ppdu_info_list,
  3280. ppdu_info_list_elem, ppdu_info_next) {
  3281. if (!ppdu_info)
  3282. break;
  3283. qdf_assert_always(ppdu_info->nbuf);
  3284. qdf_nbuf_free(ppdu_info->nbuf);
  3285. qdf_mem_free(ppdu_info);
  3286. }
  3287. if (pdev->ppdu_tlv_buf)
  3288. qdf_mem_free(pdev->ppdu_tlv_buf);
  3289. }
  3290. #if !defined(DISABLE_MON_CONFIG)
  3291. static
  3292. void dp_mon_ring_cleanup(struct dp_soc *soc, struct dp_pdev *pdev,
  3293. int mac_id)
  3294. {
  3295. if (soc->wlan_cfg_ctx->rxdma1_enable) {
  3296. dp_srng_cleanup(soc,
  3297. &pdev->rxdma_mon_buf_ring[mac_id],
  3298. RXDMA_MONITOR_BUF, 0);
  3299. dp_srng_cleanup(soc,
  3300. &pdev->rxdma_mon_dst_ring[mac_id],
  3301. RXDMA_MONITOR_DST, 0);
  3302. dp_srng_cleanup(soc,
  3303. &pdev->rxdma_mon_status_ring[mac_id],
  3304. RXDMA_MONITOR_STATUS, 0);
  3305. dp_srng_cleanup(soc,
  3306. &pdev->rxdma_mon_desc_ring[mac_id],
  3307. RXDMA_MONITOR_DESC, 0);
  3308. dp_srng_cleanup(soc,
  3309. &pdev->rxdma_err_dst_ring[mac_id],
  3310. RXDMA_DST, 0);
  3311. } else {
  3312. dp_srng_cleanup(soc,
  3313. &pdev->rxdma_mon_status_ring[mac_id],
  3314. RXDMA_MONITOR_STATUS, 0);
  3315. dp_srng_cleanup(soc,
  3316. &pdev->rxdma_err_dst_ring[mac_id],
  3317. RXDMA_DST, 0);
  3318. }
  3319. }
  3320. #else
  3321. static void dp_mon_ring_cleanup(struct dp_soc *soc, struct dp_pdev *pdev,
  3322. int mac_id)
  3323. {
  3324. }
  3325. #endif
  3326. /**
  3327. * dp_mon_ring_deinit() - Placeholder to deinitialize Monitor rings
  3328. *
  3329. * @soc: soc handle
  3330. * @pdev: datapath physical dev handle
  3331. * @mac_id: mac number
  3332. *
  3333. * Return: None
  3334. */
  3335. static void dp_mon_ring_deinit(struct dp_soc *soc, struct dp_pdev *pdev,
  3336. int mac_id)
  3337. {
  3338. }
  3339. /**
  3340. * dp_pdev_mem_reset() - Reset txrx pdev memory
  3341. * @pdev: dp pdev handle
  3342. *
  3343. * Return: None
  3344. */
  3345. static void dp_pdev_mem_reset(struct dp_pdev *pdev)
  3346. {
  3347. uint16_t len = 0;
  3348. uint8_t *dp_pdev_offset = (uint8_t *)pdev;
  3349. len = sizeof(struct dp_pdev) -
  3350. offsetof(struct dp_pdev, pdev_deinit) -
  3351. sizeof(pdev->pdev_deinit);
  3352. dp_pdev_offset = dp_pdev_offset +
  3353. offsetof(struct dp_pdev, pdev_deinit) +
  3354. sizeof(pdev->pdev_deinit);
  3355. qdf_mem_zero(dp_pdev_offset, len);
  3356. }
  3357. #ifdef WLAN_DP_PENDING_MEM_FLUSH
  3358. /**
  3359. * dp_pdev_flush_pending_vdevs() - Flush all delete pending vdevs in pdev
  3360. * @pdev: Datapath PDEV handle
  3361. *
  3362. * This is the last chance to flush all pending dp vdevs/peers,
  3363. * some peer/vdev leak case like Non-SSR + peer unmap missing
  3364. * will be covered here.
  3365. *
  3366. * Return: None
  3367. */
  3368. static void dp_pdev_flush_pending_vdevs(struct dp_pdev *pdev)
  3369. {
  3370. struct dp_vdev *vdev = NULL;
  3371. while (true) {
  3372. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  3373. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  3374. if (vdev->delete.pending)
  3375. break;
  3376. }
  3377. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  3378. /*
  3379. * vdev will be freed when all peers get cleanup,
  3380. * dp_delete_pending_vdev will remove vdev from vdev_list
  3381. * in pdev.
  3382. */
  3383. if (vdev)
  3384. dp_vdev_flush_peers((struct cdp_vdev *)vdev, 0);
  3385. else
  3386. break;
  3387. }
  3388. }
  3389. #else
  3390. static void dp_pdev_flush_pending_vdevs(struct dp_pdev *pdev)
  3391. {
  3392. }
  3393. #endif
  3394. /**
  3395. * dp_pdev_deinit() - Deinit txrx pdev
  3396. * @txrx_pdev: Datapath PDEV handle
  3397. * @force: Force deinit
  3398. *
  3399. * Return: None
  3400. */
  3401. static void dp_pdev_deinit(struct cdp_pdev *txrx_pdev, int force)
  3402. {
  3403. struct dp_pdev *pdev = (struct dp_pdev *)txrx_pdev;
  3404. struct dp_soc *soc = pdev->soc;
  3405. qdf_nbuf_t curr_nbuf, next_nbuf;
  3406. int mac_id;
  3407. /*
  3408. * Prevent double pdev deinitialization during radio detach
  3409. * execution .i.e. in the absence of any vdev
  3410. */
  3411. if (pdev->pdev_deinit)
  3412. return;
  3413. pdev->pdev_deinit = 1;
  3414. dp_wdi_event_detach(pdev);
  3415. dp_pdev_flush_pending_vdevs(pdev);
  3416. dp_tx_pdev_detach(pdev);
  3417. if (wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  3418. dp_srng_deinit(soc, &soc->tcl_data_ring[pdev->pdev_id],
  3419. TCL_DATA, pdev->pdev_id);
  3420. dp_srng_deinit(soc, &soc->tx_comp_ring[pdev->pdev_id],
  3421. WBM2SW_RELEASE, pdev->pdev_id);
  3422. }
  3423. dp_pktlogmod_exit(pdev);
  3424. dp_rx_fst_detach(soc, pdev);
  3425. dp_rx_pdev_detach(pdev);
  3426. dp_rx_pdev_mon_detach(pdev);
  3427. dp_neighbour_peers_detach(pdev);
  3428. qdf_spinlock_destroy(&pdev->tx_mutex);
  3429. qdf_spinlock_destroy(&pdev->vdev_list_lock);
  3430. dp_ipa_uc_detach(soc, pdev);
  3431. dp_cleanup_ipa_rx_refill_buf_ring(soc, pdev);
  3432. /* Cleanup per PDEV REO rings if configured */
  3433. if (wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  3434. dp_srng_deinit(soc, &soc->reo_dest_ring[pdev->pdev_id],
  3435. REO_DST, pdev->pdev_id);
  3436. }
  3437. dp_srng_deinit(soc, &pdev->rx_refill_buf_ring, RXDMA_BUF, 0);
  3438. dp_rxdma_ring_cleanup(soc, pdev);
  3439. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  3440. dp_mon_ring_deinit(soc, pdev, mac_id);
  3441. dp_srng_deinit(soc, &pdev->rxdma_err_dst_ring[mac_id],
  3442. RXDMA_DST, 0);
  3443. }
  3444. curr_nbuf = pdev->invalid_peer_head_msdu;
  3445. while (curr_nbuf) {
  3446. next_nbuf = qdf_nbuf_next(curr_nbuf);
  3447. qdf_nbuf_free(curr_nbuf);
  3448. curr_nbuf = next_nbuf;
  3449. }
  3450. pdev->invalid_peer_head_msdu = NULL;
  3451. pdev->invalid_peer_tail_msdu = NULL;
  3452. dp_htt_ppdu_stats_detach(pdev);
  3453. dp_tx_ppdu_stats_detach(pdev);
  3454. qdf_nbuf_free(pdev->sojourn_buf);
  3455. qdf_nbuf_queue_free(&pdev->rx_ppdu_buf_q);
  3456. dp_cal_client_detach(&pdev->cal_client_ctx);
  3457. soc->pdev_count--;
  3458. /* only do soc common cleanup when last pdev do detach */
  3459. if (!(soc->pdev_count))
  3460. dp_soc_cmn_cleanup(soc);
  3461. wlan_cfg_pdev_detach(pdev->wlan_cfg_ctx);
  3462. if (pdev->invalid_peer)
  3463. qdf_mem_free(pdev->invalid_peer);
  3464. qdf_mem_free(pdev->dp_txrx_handle);
  3465. dp_pdev_mem_reset(pdev);
  3466. }
  3467. /**
  3468. * dp_pdev_deinit_wifi3() - Deinit txrx pdev
  3469. * @txrx_pdev: Datapath PDEV handle
  3470. * @force: Force deinit
  3471. *
  3472. * Return: None
  3473. */
  3474. static void dp_pdev_deinit_wifi3(struct cdp_pdev *txrx_pdev, int force)
  3475. {
  3476. struct dp_pdev *pdev = (struct dp_pdev *)txrx_pdev;
  3477. struct dp_soc *soc = pdev->soc;
  3478. soc->dp_soc_reinit = TRUE;
  3479. dp_pdev_deinit(txrx_pdev, force);
  3480. }
  3481. /*
  3482. * dp_pdev_detach() - Complete rest of pdev detach
  3483. * @txrx_pdev: Datapath PDEV handle
  3484. * @force: Force deinit
  3485. *
  3486. * Return: None
  3487. */
  3488. static void dp_pdev_detach(struct cdp_pdev *txrx_pdev, int force)
  3489. {
  3490. struct dp_pdev *pdev = (struct dp_pdev *)txrx_pdev;
  3491. struct dp_soc *soc = pdev->soc;
  3492. struct rx_desc_pool *rx_desc_pool;
  3493. int mac_id, mac_for_pdev;
  3494. if (wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  3495. dp_srng_cleanup(soc, &soc->tcl_data_ring[pdev->pdev_id],
  3496. TCL_DATA, pdev->pdev_id);
  3497. dp_srng_cleanup(soc, &soc->tx_comp_ring[pdev->pdev_id],
  3498. WBM2SW_RELEASE, pdev->pdev_id);
  3499. }
  3500. dp_mon_link_free(pdev);
  3501. /* Cleanup per PDEV REO rings if configured */
  3502. if (wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  3503. dp_srng_cleanup(soc, &soc->reo_dest_ring[pdev->pdev_id],
  3504. REO_DST, pdev->pdev_id);
  3505. }
  3506. dp_rxdma_ring_cleanup(soc, pdev);
  3507. wlan_cfg_pdev_detach(pdev->wlan_cfg_ctx);
  3508. dp_srng_cleanup(soc, &pdev->rx_refill_buf_ring, RXDMA_BUF, 0);
  3509. dp_cleanup_ipa_rx_refill_buf_ring(soc, pdev);
  3510. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  3511. dp_mon_ring_cleanup(soc, pdev, mac_id);
  3512. dp_srng_cleanup(soc, &pdev->rxdma_err_dst_ring[mac_id],
  3513. RXDMA_DST, 0);
  3514. if (dp_is_soc_reinit(soc)) {
  3515. mac_for_pdev = dp_get_mac_id_for_pdev(mac_id,
  3516. pdev->pdev_id);
  3517. rx_desc_pool = &soc->rx_desc_status[mac_for_pdev];
  3518. dp_rx_desc_pool_free(soc, rx_desc_pool);
  3519. rx_desc_pool = &soc->rx_desc_mon[mac_for_pdev];
  3520. dp_rx_desc_pool_free(soc, rx_desc_pool);
  3521. }
  3522. }
  3523. if (dp_is_soc_reinit(soc)) {
  3524. rx_desc_pool = &soc->rx_desc_buf[pdev->pdev_id];
  3525. dp_rx_desc_pool_free(soc, rx_desc_pool);
  3526. }
  3527. soc->pdev_list[pdev->pdev_id] = NULL;
  3528. qdf_minidump_remove(pdev);
  3529. qdf_mem_free(pdev);
  3530. }
  3531. /*
  3532. * dp_pdev_detach_wifi3() - detach txrx pdev
  3533. * @txrx_pdev: Datapath PDEV handle
  3534. * @force: Force detach
  3535. *
  3536. * Return: None
  3537. */
  3538. static void dp_pdev_detach_wifi3(struct cdp_pdev *txrx_pdev, int force)
  3539. {
  3540. struct dp_pdev *pdev = (struct dp_pdev *)txrx_pdev;
  3541. struct dp_soc *soc = pdev->soc;
  3542. if (dp_is_soc_reinit(soc)) {
  3543. dp_pdev_detach(txrx_pdev, force);
  3544. } else {
  3545. dp_pdev_deinit(txrx_pdev, force);
  3546. dp_pdev_detach(txrx_pdev, force);
  3547. }
  3548. }
  3549. /*
  3550. * dp_reo_desc_freelist_destroy() - Flush REO descriptors from deferred freelist
  3551. * @soc: DP SOC handle
  3552. */
  3553. static inline void dp_reo_desc_freelist_destroy(struct dp_soc *soc)
  3554. {
  3555. struct reo_desc_list_node *desc;
  3556. struct dp_rx_tid *rx_tid;
  3557. qdf_spin_lock_bh(&soc->reo_desc_freelist_lock);
  3558. while (qdf_list_remove_front(&soc->reo_desc_freelist,
  3559. (qdf_list_node_t **)&desc) == QDF_STATUS_SUCCESS) {
  3560. rx_tid = &desc->rx_tid;
  3561. qdf_mem_unmap_nbytes_single(soc->osdev,
  3562. rx_tid->hw_qdesc_paddr,
  3563. QDF_DMA_BIDIRECTIONAL,
  3564. rx_tid->hw_qdesc_alloc_size);
  3565. qdf_mem_free(rx_tid->hw_qdesc_vaddr_unaligned);
  3566. qdf_mem_free(desc);
  3567. }
  3568. qdf_spin_unlock_bh(&soc->reo_desc_freelist_lock);
  3569. qdf_list_destroy(&soc->reo_desc_freelist);
  3570. qdf_spinlock_destroy(&soc->reo_desc_freelist_lock);
  3571. }
  3572. /**
  3573. * dp_soc_mem_reset() - Reset Dp Soc memory
  3574. * @soc: DP handle
  3575. *
  3576. * Return: None
  3577. */
  3578. static void dp_soc_mem_reset(struct dp_soc *soc)
  3579. {
  3580. uint16_t len = 0;
  3581. uint8_t *dp_soc_offset = (uint8_t *)soc;
  3582. len = sizeof(struct dp_soc) -
  3583. offsetof(struct dp_soc, dp_soc_reinit) -
  3584. sizeof(soc->dp_soc_reinit);
  3585. dp_soc_offset = dp_soc_offset +
  3586. offsetof(struct dp_soc, dp_soc_reinit) +
  3587. sizeof(soc->dp_soc_reinit);
  3588. qdf_mem_zero(dp_soc_offset, len);
  3589. }
  3590. /**
  3591. * dp_soc_deinit() - Deinitialize txrx SOC
  3592. * @txrx_soc: Opaque DP SOC handle
  3593. *
  3594. * Return: None
  3595. */
  3596. static void dp_soc_deinit(void *txrx_soc)
  3597. {
  3598. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  3599. int i;
  3600. qdf_atomic_set(&soc->cmn_init_done, 0);
  3601. for (i = 0; i < MAX_PDEV_CNT; i++) {
  3602. if (soc->pdev_list[i])
  3603. dp_pdev_deinit((struct cdp_pdev *)
  3604. soc->pdev_list[i], 1);
  3605. }
  3606. qdf_flush_work(&soc->htt_stats.work);
  3607. qdf_disable_work(&soc->htt_stats.work);
  3608. /* Free pending htt stats messages */
  3609. qdf_nbuf_queue_free(&soc->htt_stats.msg);
  3610. dp_peer_find_detach(soc);
  3611. /* Free the ring memories */
  3612. /* Common rings */
  3613. dp_srng_deinit(soc, &soc->wbm_desc_rel_ring, SW2WBM_RELEASE, 0);
  3614. /* Tx data rings */
  3615. if (!wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  3616. for (i = 0; i < soc->num_tcl_data_rings; i++) {
  3617. dp_srng_deinit(soc, &soc->tcl_data_ring[i],
  3618. TCL_DATA, i);
  3619. dp_srng_deinit(soc, &soc->tx_comp_ring[i],
  3620. WBM2SW_RELEASE, i);
  3621. }
  3622. }
  3623. /* TCL command and status rings */
  3624. dp_srng_deinit(soc, &soc->tcl_cmd_ring, TCL_CMD, 0);
  3625. dp_srng_deinit(soc, &soc->tcl_status_ring, TCL_STATUS, 0);
  3626. /* Rx data rings */
  3627. if (!wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  3628. soc->num_reo_dest_rings =
  3629. wlan_cfg_num_reo_dest_rings(soc->wlan_cfg_ctx);
  3630. for (i = 0; i < soc->num_reo_dest_rings; i++) {
  3631. /* TODO: Get number of rings and ring sizes
  3632. * from wlan_cfg
  3633. */
  3634. dp_srng_deinit(soc, &soc->reo_dest_ring[i],
  3635. REO_DST, i);
  3636. }
  3637. }
  3638. /* REO reinjection ring */
  3639. dp_srng_deinit(soc, &soc->reo_reinject_ring, REO_REINJECT, 0);
  3640. /* Rx release ring */
  3641. dp_srng_deinit(soc, &soc->rx_rel_ring, WBM2SW_RELEASE, 0);
  3642. /* Rx exception ring */
  3643. /* TODO: Better to store ring_type and ring_num in
  3644. * dp_srng during setup
  3645. */
  3646. dp_srng_deinit(soc, &soc->reo_exception_ring, REO_EXCEPTION, 0);
  3647. /* REO command and status rings */
  3648. dp_srng_deinit(soc, &soc->reo_cmd_ring, REO_CMD, 0);
  3649. dp_srng_deinit(soc, &soc->reo_status_ring, REO_STATUS, 0);
  3650. dp_soc_wds_detach(soc);
  3651. qdf_spinlock_destroy(&soc->peer_ref_mutex);
  3652. qdf_spinlock_destroy(&soc->htt_stats.lock);
  3653. htt_soc_htc_dealloc(soc->htt_handle);
  3654. dp_reo_desc_freelist_destroy(soc);
  3655. qdf_spinlock_destroy(&soc->ast_lock);
  3656. dp_soc_mem_reset(soc);
  3657. }
  3658. /**
  3659. * dp_soc_deinit_wifi3() - Deinitialize txrx SOC
  3660. * @txrx_soc: Opaque DP SOC handle
  3661. *
  3662. * Return: None
  3663. */
  3664. static void dp_soc_deinit_wifi3(void *txrx_soc)
  3665. {
  3666. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  3667. soc->dp_soc_reinit = 1;
  3668. dp_soc_deinit(txrx_soc);
  3669. }
  3670. /*
  3671. * dp_soc_detach() - Detach rest of txrx SOC
  3672. * @txrx_soc: DP SOC handle, struct cdp_soc_t is first element of struct dp_soc.
  3673. *
  3674. * Return: None
  3675. */
  3676. static void dp_soc_detach(void *txrx_soc)
  3677. {
  3678. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  3679. int i;
  3680. qdf_atomic_set(&soc->cmn_init_done, 0);
  3681. /* TBD: Call Tx and Rx cleanup functions to free buffers and
  3682. * SW descriptors
  3683. */
  3684. for (i = 0; i < MAX_PDEV_CNT; i++) {
  3685. if (soc->pdev_list[i])
  3686. dp_pdev_detach((struct cdp_pdev *)
  3687. soc->pdev_list[i], 1);
  3688. }
  3689. /* Free the ring memories */
  3690. /* Common rings */
  3691. qdf_minidump_remove(soc->wbm_desc_rel_ring.base_vaddr_unaligned);
  3692. dp_srng_cleanup(soc, &soc->wbm_desc_rel_ring, SW2WBM_RELEASE, 0);
  3693. /* Tx data rings */
  3694. if (!wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  3695. for (i = 0; i < soc->num_tcl_data_rings; i++) {
  3696. dp_srng_cleanup(soc, &soc->tcl_data_ring[i],
  3697. TCL_DATA, i);
  3698. dp_srng_cleanup(soc, &soc->tx_comp_ring[i],
  3699. WBM2SW_RELEASE, i);
  3700. }
  3701. }
  3702. /* TCL command and status rings */
  3703. dp_srng_cleanup(soc, &soc->tcl_cmd_ring, TCL_CMD, 0);
  3704. dp_srng_cleanup(soc, &soc->tcl_status_ring, TCL_STATUS, 0);
  3705. /* Rx data rings */
  3706. if (!wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  3707. soc->num_reo_dest_rings =
  3708. wlan_cfg_num_reo_dest_rings(soc->wlan_cfg_ctx);
  3709. for (i = 0; i < soc->num_reo_dest_rings; i++) {
  3710. /* TODO: Get number of rings and ring sizes
  3711. * from wlan_cfg
  3712. */
  3713. dp_srng_cleanup(soc, &soc->reo_dest_ring[i],
  3714. REO_DST, i);
  3715. }
  3716. }
  3717. /* REO reinjection ring */
  3718. dp_srng_cleanup(soc, &soc->reo_reinject_ring, REO_REINJECT, 0);
  3719. /* Rx release ring */
  3720. dp_srng_cleanup(soc, &soc->rx_rel_ring, WBM2SW_RELEASE, 0);
  3721. dp_srng_cleanup(soc, &soc->rx_rel_ring, WBM2SW_RELEASE, 3);
  3722. /* Rx exception ring */
  3723. /* TODO: Better to store ring_type and ring_num in
  3724. * dp_srng during setup
  3725. */
  3726. dp_srng_cleanup(soc, &soc->reo_exception_ring, REO_EXCEPTION, 0);
  3727. /* REO command and status rings */
  3728. dp_srng_cleanup(soc, &soc->reo_cmd_ring, REO_CMD, 0);
  3729. dp_srng_cleanup(soc, &soc->reo_status_ring, REO_STATUS, 0);
  3730. dp_hw_link_desc_pool_cleanup(soc);
  3731. htt_soc_detach(soc->htt_handle);
  3732. soc->dp_soc_reinit = 0;
  3733. wlan_cfg_soc_detach(soc->wlan_cfg_ctx);
  3734. qdf_minidump_remove(soc);
  3735. qdf_mem_free(soc);
  3736. }
  3737. /*
  3738. * dp_soc_detach_wifi3() - Detach txrx SOC
  3739. * @txrx_soc: DP SOC handle, struct cdp_soc_t is first element of struct dp_soc.
  3740. *
  3741. * Return: None
  3742. */
  3743. static void dp_soc_detach_wifi3(void *txrx_soc)
  3744. {
  3745. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  3746. if (dp_is_soc_reinit(soc)) {
  3747. dp_soc_detach(txrx_soc);
  3748. } else {
  3749. dp_soc_deinit(txrx_soc);
  3750. dp_soc_detach(txrx_soc);
  3751. }
  3752. }
  3753. #if !defined(DISABLE_MON_CONFIG)
  3754. /**
  3755. * dp_mon_htt_srng_setup() - Prepare HTT messages for Monitor rings
  3756. * @soc: soc handle
  3757. * @pdev: physical device handle
  3758. * @mac_id: ring number
  3759. * @mac_for_pdev: mac_id
  3760. *
  3761. * Return: non-zero for failure, zero for success
  3762. */
  3763. static QDF_STATUS dp_mon_htt_srng_setup(struct dp_soc *soc,
  3764. struct dp_pdev *pdev,
  3765. int mac_id,
  3766. int mac_for_pdev)
  3767. {
  3768. QDF_STATUS status = QDF_STATUS_SUCCESS;
  3769. if (soc->wlan_cfg_ctx->rxdma1_enable) {
  3770. status = htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3771. pdev->rxdma_mon_buf_ring[mac_id]
  3772. .hal_srng,
  3773. RXDMA_MONITOR_BUF);
  3774. if (status != QDF_STATUS_SUCCESS) {
  3775. dp_err("Failed to send htt srng setup message for Rxdma mon buf ring");
  3776. return status;
  3777. }
  3778. status = htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3779. pdev->rxdma_mon_dst_ring[mac_id]
  3780. .hal_srng,
  3781. RXDMA_MONITOR_DST);
  3782. if (status != QDF_STATUS_SUCCESS) {
  3783. dp_err("Failed to send htt srng setup message for Rxdma mon dst ring");
  3784. return status;
  3785. }
  3786. status = htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3787. pdev->rxdma_mon_status_ring[mac_id]
  3788. .hal_srng,
  3789. RXDMA_MONITOR_STATUS);
  3790. if (status != QDF_STATUS_SUCCESS) {
  3791. dp_err("Failed to send htt srng setup message for Rxdma mon status ring");
  3792. return status;
  3793. }
  3794. status = htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3795. pdev->rxdma_mon_desc_ring[mac_id]
  3796. .hal_srng,
  3797. RXDMA_MONITOR_DESC);
  3798. if (status != QDF_STATUS_SUCCESS) {
  3799. dp_err("Failed to send htt srng message for Rxdma mon desc ring");
  3800. return status;
  3801. }
  3802. } else {
  3803. status = htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3804. pdev->rxdma_mon_status_ring[mac_id]
  3805. .hal_srng,
  3806. RXDMA_MONITOR_STATUS);
  3807. if (status != QDF_STATUS_SUCCESS) {
  3808. dp_err("Failed to send htt srng setup message for Rxdma mon status ring");
  3809. return status;
  3810. }
  3811. }
  3812. return status;
  3813. }
  3814. #else
  3815. static QDF_STATUS dp_mon_htt_srng_setup(struct dp_soc *soc,
  3816. struct dp_pdev *pdev,
  3817. int mac_id,
  3818. int mac_for_pdev)
  3819. {
  3820. return QDF_STATUS_SUCCESS;
  3821. }
  3822. #endif
  3823. /*
  3824. * dp_rxdma_ring_config() - configure the RX DMA rings
  3825. *
  3826. * This function is used to configure the MAC rings.
  3827. * On MCL host provides buffers in Host2FW ring
  3828. * FW refills (copies) buffers to the ring and updates
  3829. * ring_idx in register
  3830. *
  3831. * @soc: data path SoC handle
  3832. *
  3833. * Return: zero on success, non-zero on failure
  3834. */
  3835. #ifdef QCA_HOST2FW_RXBUF_RING
  3836. static QDF_STATUS dp_rxdma_ring_config(struct dp_soc *soc)
  3837. {
  3838. int i;
  3839. QDF_STATUS status = QDF_STATUS_SUCCESS;
  3840. for (i = 0; i < MAX_PDEV_CNT; i++) {
  3841. struct dp_pdev *pdev = soc->pdev_list[i];
  3842. if (pdev) {
  3843. int mac_id;
  3844. bool dbs_enable = 0;
  3845. int max_mac_rings =
  3846. wlan_cfg_get_num_mac_rings
  3847. (pdev->wlan_cfg_ctx);
  3848. htt_srng_setup(soc->htt_handle, 0,
  3849. pdev->rx_refill_buf_ring.hal_srng,
  3850. RXDMA_BUF);
  3851. if (pdev->rx_refill_buf_ring2.hal_srng)
  3852. htt_srng_setup(soc->htt_handle, 0,
  3853. pdev->rx_refill_buf_ring2.hal_srng,
  3854. RXDMA_BUF);
  3855. if (soc->cdp_soc.ol_ops->
  3856. is_hw_dbs_2x2_capable) {
  3857. dbs_enable = soc->cdp_soc.ol_ops->
  3858. is_hw_dbs_2x2_capable(
  3859. (void *)soc->ctrl_psoc);
  3860. }
  3861. if (dbs_enable) {
  3862. QDF_TRACE(QDF_MODULE_ID_TXRX,
  3863. QDF_TRACE_LEVEL_ERROR,
  3864. FL("DBS enabled max_mac_rings %d"),
  3865. max_mac_rings);
  3866. } else {
  3867. max_mac_rings = 1;
  3868. QDF_TRACE(QDF_MODULE_ID_TXRX,
  3869. QDF_TRACE_LEVEL_ERROR,
  3870. FL("DBS disabled, max_mac_rings %d"),
  3871. max_mac_rings);
  3872. }
  3873. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  3874. FL("pdev_id %d max_mac_rings %d"),
  3875. pdev->pdev_id, max_mac_rings);
  3876. for (mac_id = 0; mac_id < max_mac_rings; mac_id++) {
  3877. int mac_for_pdev = dp_get_mac_id_for_pdev(
  3878. mac_id, pdev->pdev_id);
  3879. QDF_TRACE(QDF_MODULE_ID_TXRX,
  3880. QDF_TRACE_LEVEL_ERROR,
  3881. FL("mac_id %d"), mac_for_pdev);
  3882. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3883. pdev->rx_mac_buf_ring[mac_id]
  3884. .hal_srng,
  3885. RXDMA_BUF);
  3886. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3887. pdev->rxdma_err_dst_ring[mac_id]
  3888. .hal_srng,
  3889. RXDMA_DST);
  3890. /* Configure monitor mode rings */
  3891. status = dp_mon_htt_srng_setup(soc, pdev,
  3892. mac_id,
  3893. mac_for_pdev);
  3894. if (status != QDF_STATUS_SUCCESS) {
  3895. dp_err("Failed to send htt monitor messages to target");
  3896. return status;
  3897. }
  3898. }
  3899. }
  3900. }
  3901. /*
  3902. * Timer to reap rxdma status rings.
  3903. * Needed until we enable ppdu end interrupts
  3904. */
  3905. qdf_timer_init(soc->osdev, &soc->mon_reap_timer,
  3906. dp_service_mon_rings, (void *)soc,
  3907. QDF_TIMER_TYPE_WAKE_APPS);
  3908. soc->reap_timer_init = 1;
  3909. return status;
  3910. }
  3911. #else
  3912. /* This is only for WIN */
  3913. static QDF_STATUS dp_rxdma_ring_config(struct dp_soc *soc)
  3914. {
  3915. int i;
  3916. int mac_id;
  3917. QDF_STATUS status = QDF_STATUS_SUCCESS;
  3918. for (i = 0; i < MAX_PDEV_CNT; i++) {
  3919. struct dp_pdev *pdev = soc->pdev_list[i];
  3920. if (!pdev)
  3921. continue;
  3922. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  3923. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, i);
  3924. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3925. pdev->rx_refill_buf_ring.hal_srng, RXDMA_BUF);
  3926. #ifndef DISABLE_MON_CONFIG
  3927. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3928. pdev->rxdma_mon_buf_ring[mac_id].hal_srng,
  3929. RXDMA_MONITOR_BUF);
  3930. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3931. pdev->rxdma_mon_dst_ring[mac_id].hal_srng,
  3932. RXDMA_MONITOR_DST);
  3933. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3934. pdev->rxdma_mon_status_ring[mac_id].hal_srng,
  3935. RXDMA_MONITOR_STATUS);
  3936. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3937. pdev->rxdma_mon_desc_ring[mac_id].hal_srng,
  3938. RXDMA_MONITOR_DESC);
  3939. #endif
  3940. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3941. pdev->rxdma_err_dst_ring[mac_id].hal_srng,
  3942. RXDMA_DST);
  3943. }
  3944. }
  3945. return status;
  3946. }
  3947. #endif
  3948. #ifdef NO_RX_PKT_HDR_TLV
  3949. static QDF_STATUS
  3950. dp_rxdma_ring_sel_cfg(struct dp_soc *soc)
  3951. {
  3952. int i;
  3953. int mac_id;
  3954. struct htt_rx_ring_tlv_filter htt_tlv_filter = {0};
  3955. QDF_STATUS status = QDF_STATUS_SUCCESS;
  3956. htt_tlv_filter.mpdu_start = 1;
  3957. htt_tlv_filter.msdu_start = 1;
  3958. htt_tlv_filter.mpdu_end = 1;
  3959. htt_tlv_filter.msdu_end = 1;
  3960. htt_tlv_filter.attention = 1;
  3961. htt_tlv_filter.packet = 1;
  3962. htt_tlv_filter.packet_header = 0;
  3963. htt_tlv_filter.ppdu_start = 0;
  3964. htt_tlv_filter.ppdu_end = 0;
  3965. htt_tlv_filter.ppdu_end_user_stats = 0;
  3966. htt_tlv_filter.ppdu_end_user_stats_ext = 0;
  3967. htt_tlv_filter.ppdu_end_status_done = 0;
  3968. htt_tlv_filter.enable_fp = 1;
  3969. htt_tlv_filter.enable_md = 0;
  3970. htt_tlv_filter.enable_md = 0;
  3971. htt_tlv_filter.enable_mo = 0;
  3972. htt_tlv_filter.fp_mgmt_filter = 0;
  3973. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_BA_REQ;
  3974. htt_tlv_filter.fp_data_filter = (FILTER_DATA_UCAST |
  3975. FILTER_DATA_MCAST |
  3976. FILTER_DATA_DATA);
  3977. htt_tlv_filter.mo_mgmt_filter = 0;
  3978. htt_tlv_filter.mo_ctrl_filter = 0;
  3979. htt_tlv_filter.mo_data_filter = 0;
  3980. htt_tlv_filter.md_data_filter = 0;
  3981. htt_tlv_filter.offset_valid = true;
  3982. htt_tlv_filter.rx_packet_offset = RX_PKT_TLVS_LEN;
  3983. /*Not subscribing rx_pkt_header*/
  3984. htt_tlv_filter.rx_header_offset = 0;
  3985. htt_tlv_filter.rx_mpdu_start_offset =
  3986. HAL_RX_PKT_TLV_MPDU_START_OFFSET(soc->hal_soc);
  3987. htt_tlv_filter.rx_mpdu_end_offset =
  3988. HAL_RX_PKT_TLV_MPDU_END_OFFSET(soc->hal_soc);
  3989. htt_tlv_filter.rx_msdu_start_offset =
  3990. HAL_RX_PKT_TLV_MSDU_START_OFFSET(soc->hal_soc);
  3991. htt_tlv_filter.rx_msdu_end_offset =
  3992. HAL_RX_PKT_TLV_MSDU_END_OFFSET(soc->hal_soc);
  3993. htt_tlv_filter.rx_attn_offset =
  3994. HAL_RX_PKT_TLV_ATTN_OFFSET(soc->hal_soc);
  3995. for (i = 0; i < MAX_PDEV_CNT; i++) {
  3996. struct dp_pdev *pdev = soc->pdev_list[i];
  3997. if (!pdev)
  3998. continue;
  3999. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  4000. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id,
  4001. pdev->pdev_id);
  4002. htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  4003. pdev->rx_refill_buf_ring.hal_srng,
  4004. RXDMA_BUF, RX_BUFFER_SIZE,
  4005. &htt_tlv_filter);
  4006. }
  4007. }
  4008. return status;
  4009. }
  4010. #else
  4011. static QDF_STATUS
  4012. dp_rxdma_ring_sel_cfg(struct dp_soc *soc)
  4013. {
  4014. return QDF_STATUS_SUCCESS;
  4015. }
  4016. #endif
  4017. /*
  4018. * dp_rx_target_fst_config() - configure the RXOLE Flow Search Engine
  4019. *
  4020. * This function is used to configure the FSE HW block in RX OLE on a
  4021. * per pdev basis. Here, we will be programming parameters related to
  4022. * the Flow Search Table.
  4023. *
  4024. * @soc: data path SoC handle
  4025. *
  4026. * Return: zero on success, non-zero on failure
  4027. */
  4028. #ifdef WLAN_SUPPORT_RX_FLOW_TAG
  4029. static QDF_STATUS
  4030. dp_rx_target_fst_config(struct dp_soc *soc)
  4031. {
  4032. int i;
  4033. QDF_STATUS status = QDF_STATUS_SUCCESS;
  4034. for (i = 0; i < MAX_PDEV_CNT; i++) {
  4035. struct dp_pdev *pdev = soc->pdev_list[i];
  4036. /* Flow search is not enabled if NSS offload is enabled */
  4037. if (pdev &&
  4038. !wlan_cfg_get_dp_pdev_nss_enabled(pdev->wlan_cfg_ctx)) {
  4039. status = dp_rx_flow_send_fst_fw_setup(pdev->soc, pdev);
  4040. if (status != QDF_STATUS_SUCCESS)
  4041. break;
  4042. }
  4043. }
  4044. return status;
  4045. }
  4046. #else
  4047. /**
  4048. * dp_rx_target_fst_config() - Configure RX OLE FSE engine in HW
  4049. * @soc: SoC handle
  4050. *
  4051. * Return: Success
  4052. */
  4053. static inline QDF_STATUS
  4054. dp_rx_target_fst_config(struct dp_soc *soc)
  4055. {
  4056. return QDF_STATUS_SUCCESS;
  4057. }
  4058. #endif /* WLAN_SUPPORT_RX_FLOW_TAG */
  4059. /*
  4060. * dp_soc_attach_target_wifi3() - SOC initialization in the target
  4061. * @cdp_soc: Opaque Datapath SOC handle
  4062. *
  4063. * Return: zero on success, non-zero on failure
  4064. */
  4065. static QDF_STATUS
  4066. dp_soc_attach_target_wifi3(struct cdp_soc_t *cdp_soc)
  4067. {
  4068. struct dp_soc *soc = (struct dp_soc *)cdp_soc;
  4069. QDF_STATUS status = QDF_STATUS_SUCCESS;
  4070. htt_soc_attach_target(soc->htt_handle);
  4071. status = dp_rxdma_ring_config(soc);
  4072. if (status != QDF_STATUS_SUCCESS) {
  4073. dp_err("Failed to send htt srng setup messages to target");
  4074. return status;
  4075. }
  4076. status = dp_rxdma_ring_sel_cfg(soc);
  4077. if (status != QDF_STATUS_SUCCESS) {
  4078. dp_err("Failed to send htt ring config message to target");
  4079. return status;
  4080. }
  4081. status = dp_rx_target_fst_config(soc);
  4082. if (status != QDF_STATUS_SUCCESS) {
  4083. dp_err("Failed to send htt fst setup config message to target");
  4084. return status;
  4085. }
  4086. DP_STATS_INIT(soc);
  4087. /* initialize work queue for stats processing */
  4088. qdf_create_work(0, &soc->htt_stats.work, htt_t2h_stats_handler, soc);
  4089. qdf_minidump_log(soc, sizeof(*soc), "dp_soc");
  4090. return QDF_STATUS_SUCCESS;
  4091. }
  4092. /*
  4093. * dp_soc_get_nss_cfg_wifi3() - SOC get nss config
  4094. * @txrx_soc: Datapath SOC handle
  4095. */
  4096. static int dp_soc_get_nss_cfg_wifi3(struct cdp_soc_t *cdp_soc)
  4097. {
  4098. struct dp_soc *dsoc = (struct dp_soc *)cdp_soc;
  4099. return wlan_cfg_get_dp_soc_nss_cfg(dsoc->wlan_cfg_ctx);
  4100. }
  4101. /*
  4102. * dp_soc_set_nss_cfg_wifi3() - SOC set nss config
  4103. * @txrx_soc: Datapath SOC handle
  4104. * @nss_cfg: nss config
  4105. */
  4106. static void dp_soc_set_nss_cfg_wifi3(struct cdp_soc_t *cdp_soc, int config)
  4107. {
  4108. struct dp_soc *dsoc = (struct dp_soc *)cdp_soc;
  4109. struct wlan_cfg_dp_soc_ctxt *wlan_cfg_ctx = dsoc->wlan_cfg_ctx;
  4110. wlan_cfg_set_dp_soc_nss_cfg(wlan_cfg_ctx, config);
  4111. /*
  4112. * TODO: masked out based on the per offloaded radio
  4113. */
  4114. switch (config) {
  4115. case dp_nss_cfg_default:
  4116. break;
  4117. case dp_nss_cfg_first_radio:
  4118. /*
  4119. * This configuration is valid for single band radio which
  4120. * is also NSS offload.
  4121. */
  4122. case dp_nss_cfg_dbdc:
  4123. case dp_nss_cfg_dbtc:
  4124. wlan_cfg_set_num_tx_desc_pool(wlan_cfg_ctx, 0);
  4125. wlan_cfg_set_num_tx_ext_desc_pool(wlan_cfg_ctx, 0);
  4126. wlan_cfg_set_num_tx_desc(wlan_cfg_ctx, 0);
  4127. wlan_cfg_set_num_tx_ext_desc(wlan_cfg_ctx, 0);
  4128. break;
  4129. default:
  4130. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  4131. "Invalid offload config %d", config);
  4132. }
  4133. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  4134. FL("nss-wifi<0> nss config is enabled"));
  4135. }
  4136. /*
  4137. * dp_vdev_attach_wifi3() - attach txrx vdev
  4138. * @txrx_pdev: Datapath PDEV handle
  4139. * @vdev_mac_addr: MAC address of the virtual interface
  4140. * @vdev_id: VDEV Id
  4141. * @wlan_op_mode: VDEV operating mode
  4142. * @subtype: VDEV operating subtype
  4143. *
  4144. * Return: DP VDEV handle on success, NULL on failure
  4145. */
  4146. static struct cdp_vdev *dp_vdev_attach_wifi3(struct cdp_pdev *txrx_pdev,
  4147. uint8_t *vdev_mac_addr, uint8_t vdev_id, enum wlan_op_mode op_mode,
  4148. enum wlan_op_subtype subtype)
  4149. {
  4150. struct dp_pdev *pdev = (struct dp_pdev *)txrx_pdev;
  4151. struct dp_soc *soc = pdev->soc;
  4152. struct dp_vdev *vdev = qdf_mem_malloc(sizeof(*vdev));
  4153. if (!vdev) {
  4154. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  4155. FL("DP VDEV memory allocation failed"));
  4156. goto fail0;
  4157. }
  4158. vdev->pdev = pdev;
  4159. vdev->vdev_id = vdev_id;
  4160. vdev->opmode = op_mode;
  4161. vdev->subtype = subtype;
  4162. vdev->osdev = soc->osdev;
  4163. vdev->osif_rx = NULL;
  4164. vdev->osif_rsim_rx_decap = NULL;
  4165. vdev->osif_get_key = NULL;
  4166. vdev->osif_rx_mon = NULL;
  4167. vdev->osif_tx_free_ext = NULL;
  4168. vdev->osif_vdev = NULL;
  4169. vdev->delete.pending = 0;
  4170. vdev->safemode = 0;
  4171. vdev->drop_unenc = 1;
  4172. vdev->sec_type = cdp_sec_type_none;
  4173. #ifdef notyet
  4174. vdev->filters_num = 0;
  4175. #endif
  4176. qdf_mem_copy(
  4177. &vdev->mac_addr.raw[0], vdev_mac_addr, QDF_MAC_ADDR_SIZE);
  4178. /* TODO: Initialize default HTT meta data that will be used in
  4179. * TCL descriptors for packets transmitted from this VDEV
  4180. */
  4181. TAILQ_INIT(&vdev->peer_list);
  4182. dp_peer_multipass_list_init(vdev);
  4183. if ((soc->intr_mode == DP_INTR_POLL) &&
  4184. wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx) != 0) {
  4185. if ((pdev->vdev_count == 0) ||
  4186. (wlan_op_mode_monitor == vdev->opmode))
  4187. qdf_timer_mod(&soc->int_timer, DP_INTR_POLL_TIMER_MS);
  4188. }
  4189. soc->vdev_id_map[vdev_id] = vdev;
  4190. if (wlan_op_mode_monitor == vdev->opmode) {
  4191. pdev->monitor_vdev = vdev;
  4192. return (struct cdp_vdev *)vdev;
  4193. }
  4194. vdev->tx_encap_type = wlan_cfg_pkt_type(soc->wlan_cfg_ctx);
  4195. vdev->rx_decap_type = wlan_cfg_pkt_type(soc->wlan_cfg_ctx);
  4196. vdev->dscp_tid_map_id = 0;
  4197. vdev->mcast_enhancement_en = 0;
  4198. vdev->raw_mode_war = wlan_cfg_get_raw_mode_war(soc->wlan_cfg_ctx);
  4199. vdev->prev_tx_enq_tstamp = 0;
  4200. vdev->prev_rx_deliver_tstamp = 0;
  4201. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  4202. /* add this vdev into the pdev's list */
  4203. TAILQ_INSERT_TAIL(&pdev->vdev_list, vdev, vdev_list_elem);
  4204. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  4205. pdev->vdev_count++;
  4206. if (wlan_op_mode_sta != vdev->opmode)
  4207. vdev->ap_bridge_enabled = true;
  4208. else
  4209. vdev->ap_bridge_enabled = false;
  4210. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  4211. "%s: wlan_cfg_ap_bridge_enabled %d",
  4212. __func__, vdev->ap_bridge_enabled);
  4213. dp_tx_vdev_attach(vdev);
  4214. if (pdev->vdev_count == 1)
  4215. dp_lro_hash_setup(soc, pdev);
  4216. dp_info("Created vdev %pK (%pM)", vdev, vdev->mac_addr.raw);
  4217. DP_STATS_INIT(vdev);
  4218. if (wlan_op_mode_sta == vdev->opmode)
  4219. dp_peer_create_wifi3((struct cdp_vdev *)vdev,
  4220. vdev->mac_addr.raw,
  4221. NULL);
  4222. return (struct cdp_vdev *)vdev;
  4223. fail0:
  4224. return NULL;
  4225. }
  4226. /**
  4227. * dp_vdev_register_wifi3() - Register VDEV operations from osif layer
  4228. * @vdev: Datapath VDEV handle
  4229. * @osif_vdev: OSIF vdev handle
  4230. * @ctrl_vdev: UMAC vdev handle
  4231. * @txrx_ops: Tx and Rx operations
  4232. *
  4233. * Return: DP VDEV handle on success, NULL on failure
  4234. */
  4235. static void dp_vdev_register_wifi3(struct cdp_vdev *vdev_handle,
  4236. void *osif_vdev, struct cdp_ctrl_objmgr_vdev *ctrl_vdev,
  4237. struct ol_txrx_ops *txrx_ops)
  4238. {
  4239. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  4240. vdev->osif_vdev = osif_vdev;
  4241. vdev->ctrl_vdev = ctrl_vdev;
  4242. vdev->osif_rx = txrx_ops->rx.rx;
  4243. vdev->osif_rx_stack = txrx_ops->rx.rx_stack;
  4244. vdev->osif_rx_flush = txrx_ops->rx.rx_flush;
  4245. vdev->osif_gro_flush = txrx_ops->rx.rx_gro_flush;
  4246. vdev->osif_rsim_rx_decap = txrx_ops->rx.rsim_rx_decap;
  4247. vdev->osif_get_key = txrx_ops->get_key;
  4248. vdev->osif_rx_mon = txrx_ops->rx.mon;
  4249. vdev->osif_tx_free_ext = txrx_ops->tx.tx_free_ext;
  4250. vdev->tx_comp = txrx_ops->tx.tx_comp;
  4251. #ifdef notyet
  4252. #if ATH_SUPPORT_WAPI
  4253. vdev->osif_check_wai = txrx_ops->rx.wai_check;
  4254. #endif
  4255. #endif
  4256. #ifdef UMAC_SUPPORT_PROXY_ARP
  4257. vdev->osif_proxy_arp = txrx_ops->proxy_arp;
  4258. #endif
  4259. vdev->me_convert = txrx_ops->me_convert;
  4260. /* TODO: Enable the following once Tx code is integrated */
  4261. if (vdev->mesh_vdev)
  4262. txrx_ops->tx.tx = dp_tx_send_mesh;
  4263. else
  4264. txrx_ops->tx.tx = dp_tx_send;
  4265. txrx_ops->tx.tx_exception = dp_tx_send_exception;
  4266. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
  4267. "DP Vdev Register success");
  4268. }
  4269. /**
  4270. * dp_peer_flush_ast_entry() - Forcibily flush all AST entry of peer
  4271. * @soc: Datapath soc handle
  4272. * @peer: Datapath peer handle
  4273. * @peer_id: Peer ID
  4274. * @vdev_id: Vdev ID
  4275. *
  4276. * Return: void
  4277. */
  4278. static void dp_peer_flush_ast_entry(struct dp_soc *soc,
  4279. struct dp_peer *peer,
  4280. uint16_t peer_id,
  4281. uint8_t vdev_id)
  4282. {
  4283. struct dp_ast_entry *ase, *tmp_ase;
  4284. if (soc->is_peer_map_unmap_v2) {
  4285. DP_PEER_ITERATE_ASE_LIST(peer, ase, tmp_ase) {
  4286. dp_rx_peer_unmap_handler
  4287. (soc, peer_id,
  4288. vdev_id,
  4289. ase->mac_addr.raw,
  4290. 1);
  4291. }
  4292. }
  4293. }
  4294. /**
  4295. * dp_vdev_flush_peers() - Forcibily Flush peers of vdev
  4296. * @vdev: Datapath VDEV handle
  4297. * @unmap_only: Flag to indicate "only unmap"
  4298. *
  4299. * Return: void
  4300. */
  4301. static void dp_vdev_flush_peers(struct cdp_vdev *vdev_handle, bool unmap_only)
  4302. {
  4303. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  4304. struct dp_pdev *pdev = vdev->pdev;
  4305. struct dp_soc *soc = pdev->soc;
  4306. struct dp_peer *peer;
  4307. uint16_t *peer_ids;
  4308. struct dp_peer **peer_array = NULL;
  4309. uint8_t i = 0, j = 0;
  4310. uint8_t m = 0, n = 0;
  4311. peer_ids = qdf_mem_malloc(soc->max_peers * sizeof(peer_ids[0]));
  4312. if (!peer_ids) {
  4313. dp_err("DP alloc failure - unable to flush peers");
  4314. return;
  4315. }
  4316. if (!unmap_only) {
  4317. peer_array = qdf_mem_malloc(
  4318. soc->max_peers * sizeof(struct dp_peer *));
  4319. if (!peer_array) {
  4320. qdf_mem_free(peer_ids);
  4321. dp_err("DP alloc failure - unable to flush peers");
  4322. return;
  4323. }
  4324. }
  4325. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  4326. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  4327. if (!unmap_only && n < soc->max_peers)
  4328. peer_array[n++] = peer;
  4329. for (i = 0; i < MAX_NUM_PEER_ID_PER_PEER; i++)
  4330. if (peer->peer_ids[i] != HTT_INVALID_PEER)
  4331. if (j < soc->max_peers)
  4332. peer_ids[j++] = peer->peer_ids[i];
  4333. }
  4334. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  4335. /*
  4336. * If peer id is invalid, need to flush the peer if
  4337. * peer valid flag is true, this is needed for NAN + SSR case.
  4338. */
  4339. if (!unmap_only) {
  4340. for (m = 0; m < n ; m++) {
  4341. peer = peer_array[m];
  4342. dp_info("peer: %pM is getting deleted",
  4343. peer->mac_addr.raw);
  4344. /* only if peer valid is true */
  4345. if (peer->valid)
  4346. dp_peer_delete_wifi3(peer, 0);
  4347. }
  4348. qdf_mem_free(peer_array);
  4349. }
  4350. for (i = 0; i < j ; i++) {
  4351. peer = __dp_peer_find_by_id(soc, peer_ids[i]);
  4352. if (!peer)
  4353. continue;
  4354. dp_info("peer: %pM is getting unmap",
  4355. peer->mac_addr.raw);
  4356. /* free AST entries of peer */
  4357. dp_peer_flush_ast_entry(soc, peer,
  4358. peer_ids[i],
  4359. vdev->vdev_id);
  4360. dp_rx_peer_unmap_handler(soc, peer_ids[i],
  4361. vdev->vdev_id,
  4362. peer->mac_addr.raw, 0);
  4363. }
  4364. qdf_mem_free(peer_ids);
  4365. dp_info("Flushed peers for vdev object %pK ", vdev);
  4366. }
  4367. /*
  4368. * dp_vdev_detach_wifi3() - Detach txrx vdev
  4369. * @txrx_vdev: Datapath VDEV handle
  4370. * @callback: Callback OL_IF on completion of detach
  4371. * @cb_context: Callback context
  4372. *
  4373. */
  4374. static void dp_vdev_detach_wifi3(struct cdp_vdev *vdev_handle,
  4375. ol_txrx_vdev_delete_cb callback, void *cb_context)
  4376. {
  4377. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  4378. struct dp_pdev *pdev;
  4379. struct dp_soc *soc;
  4380. struct dp_neighbour_peer *peer = NULL;
  4381. struct dp_neighbour_peer *temp_peer = NULL;
  4382. /* preconditions */
  4383. qdf_assert_always(vdev);
  4384. pdev = vdev->pdev;
  4385. soc = pdev->soc;
  4386. soc->vdev_id_map[vdev->vdev_id] = NULL;
  4387. if (wlan_op_mode_monitor == vdev->opmode)
  4388. goto free_vdev;
  4389. if (wlan_op_mode_sta == vdev->opmode)
  4390. dp_peer_delete_wifi3(vdev->vap_self_peer, 0);
  4391. /*
  4392. * If Target is hung, flush all peers before detaching vdev
  4393. * this will free all references held due to missing
  4394. * unmap commands from Target
  4395. */
  4396. if (!hif_is_target_ready(HIF_GET_SOFTC(soc->hif_handle)))
  4397. dp_vdev_flush_peers((struct cdp_vdev *)vdev, false);
  4398. /*
  4399. * Use peer_ref_mutex while accessing peer_list, in case
  4400. * a peer is in the process of being removed from the list.
  4401. */
  4402. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  4403. /* check that the vdev has no peers allocated */
  4404. if (!TAILQ_EMPTY(&vdev->peer_list)) {
  4405. /* debug print - will be removed later */
  4406. dp_warn("not deleting vdev object %pK (%pM) until deletion finishes for all its peers",
  4407. vdev, vdev->mac_addr.raw);
  4408. /* indicate that the vdev needs to be deleted */
  4409. vdev->delete.pending = 1;
  4410. vdev->delete.callback = callback;
  4411. vdev->delete.context = cb_context;
  4412. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  4413. return;
  4414. }
  4415. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  4416. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  4417. if (!soc->hw_nac_monitor_support) {
  4418. TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
  4419. neighbour_peer_list_elem) {
  4420. QDF_ASSERT(peer->vdev != vdev);
  4421. }
  4422. } else {
  4423. TAILQ_FOREACH_SAFE(peer, &pdev->neighbour_peers_list,
  4424. neighbour_peer_list_elem, temp_peer) {
  4425. if (peer->vdev == vdev) {
  4426. TAILQ_REMOVE(&pdev->neighbour_peers_list, peer,
  4427. neighbour_peer_list_elem);
  4428. qdf_mem_free(peer);
  4429. }
  4430. }
  4431. }
  4432. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  4433. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  4434. dp_tx_vdev_detach(vdev);
  4435. dp_rx_vdev_detach(vdev);
  4436. /* remove the vdev from its parent pdev's list */
  4437. TAILQ_REMOVE(&pdev->vdev_list, vdev, vdev_list_elem);
  4438. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  4439. FL("deleting vdev object %pK (%pM)"), vdev, vdev->mac_addr.raw);
  4440. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  4441. free_vdev:
  4442. if (wlan_op_mode_monitor == vdev->opmode)
  4443. pdev->monitor_vdev = NULL;
  4444. qdf_mem_free(vdev);
  4445. if (callback)
  4446. callback(cb_context);
  4447. }
  4448. #ifdef FEATURE_AST
  4449. /*
  4450. * dp_peer_delete_ast_entries(): Delete all AST entries for a peer
  4451. * @soc - datapath soc handle
  4452. * @peer - datapath peer handle
  4453. *
  4454. * Delete the AST entries belonging to a peer
  4455. */
  4456. static inline void dp_peer_delete_ast_entries(struct dp_soc *soc,
  4457. struct dp_peer *peer)
  4458. {
  4459. struct dp_ast_entry *ast_entry, *temp_ast_entry;
  4460. DP_PEER_ITERATE_ASE_LIST(peer, ast_entry, temp_ast_entry)
  4461. dp_peer_del_ast(soc, ast_entry);
  4462. peer->self_ast_entry = NULL;
  4463. }
  4464. #else
  4465. static inline void dp_peer_delete_ast_entries(struct dp_soc *soc,
  4466. struct dp_peer *peer)
  4467. {
  4468. }
  4469. #endif
  4470. #if ATH_SUPPORT_WRAP
  4471. static inline struct dp_peer *dp_peer_can_reuse(struct dp_vdev *vdev,
  4472. uint8_t *peer_mac_addr)
  4473. {
  4474. struct dp_peer *peer;
  4475. peer = dp_peer_find_hash_find(vdev->pdev->soc, peer_mac_addr,
  4476. 0, vdev->vdev_id);
  4477. if (!peer)
  4478. return NULL;
  4479. if (peer->bss_peer)
  4480. return peer;
  4481. dp_peer_unref_delete(peer);
  4482. return NULL;
  4483. }
  4484. #else
  4485. static inline struct dp_peer *dp_peer_can_reuse(struct dp_vdev *vdev,
  4486. uint8_t *peer_mac_addr)
  4487. {
  4488. struct dp_peer *peer;
  4489. peer = dp_peer_find_hash_find(vdev->pdev->soc, peer_mac_addr,
  4490. 0, vdev->vdev_id);
  4491. if (!peer)
  4492. return NULL;
  4493. if (peer->bss_peer && (peer->vdev->vdev_id == vdev->vdev_id))
  4494. return peer;
  4495. dp_peer_unref_delete(peer);
  4496. return NULL;
  4497. }
  4498. #endif
  4499. #ifdef FEATURE_AST
  4500. static inline void dp_peer_ast_handle_roam_del(struct dp_soc *soc,
  4501. struct dp_pdev *pdev,
  4502. uint8_t *peer_mac_addr)
  4503. {
  4504. struct dp_ast_entry *ast_entry;
  4505. qdf_spin_lock_bh(&soc->ast_lock);
  4506. if (soc->ast_override_support)
  4507. ast_entry = dp_peer_ast_hash_find_by_pdevid(soc, peer_mac_addr,
  4508. pdev->pdev_id);
  4509. else
  4510. ast_entry = dp_peer_ast_hash_find_soc(soc, peer_mac_addr);
  4511. if (ast_entry && ast_entry->next_hop && !ast_entry->delete_in_progress)
  4512. dp_peer_del_ast(soc, ast_entry);
  4513. qdf_spin_unlock_bh(&soc->ast_lock);
  4514. }
  4515. #endif
  4516. #ifdef PEER_CACHE_RX_PKTS
  4517. static inline void dp_peer_rx_bufq_resources_init(struct dp_peer *peer)
  4518. {
  4519. qdf_spinlock_create(&peer->bufq_info.bufq_lock);
  4520. peer->bufq_info.thresh = DP_RX_CACHED_BUFQ_THRESH;
  4521. qdf_list_create(&peer->bufq_info.cached_bufq, DP_RX_CACHED_BUFQ_THRESH);
  4522. }
  4523. #else
  4524. static inline void dp_peer_rx_bufq_resources_init(struct dp_peer *peer)
  4525. {
  4526. }
  4527. #endif
  4528. /*
  4529. * dp_peer_create_wifi3() - attach txrx peer
  4530. * @txrx_vdev: Datapath VDEV handle
  4531. * @peer_mac_addr: Peer MAC address
  4532. *
  4533. * Return: DP peeer handle on success, NULL on failure
  4534. */
  4535. static void *dp_peer_create_wifi3(struct cdp_vdev *vdev_handle,
  4536. uint8_t *peer_mac_addr, struct cdp_ctrl_objmgr_peer *ctrl_peer)
  4537. {
  4538. struct dp_peer *peer;
  4539. int i;
  4540. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  4541. struct dp_pdev *pdev;
  4542. struct dp_soc *soc;
  4543. struct cdp_peer_cookie peer_cookie;
  4544. enum cdp_txrx_ast_entry_type ast_type = CDP_TXRX_AST_TYPE_STATIC;
  4545. /* preconditions */
  4546. qdf_assert(vdev);
  4547. qdf_assert(peer_mac_addr);
  4548. pdev = vdev->pdev;
  4549. soc = pdev->soc;
  4550. /*
  4551. * If a peer entry with given MAC address already exists,
  4552. * reuse the peer and reset the state of peer.
  4553. */
  4554. peer = dp_peer_can_reuse(vdev, peer_mac_addr);
  4555. if (peer) {
  4556. qdf_atomic_init(&peer->is_default_route_set);
  4557. dp_peer_cleanup(vdev, peer, true);
  4558. qdf_spin_lock_bh(&soc->ast_lock);
  4559. dp_peer_delete_ast_entries(soc, peer);
  4560. peer->delete_in_progress = false;
  4561. qdf_spin_unlock_bh(&soc->ast_lock);
  4562. if ((vdev->opmode == wlan_op_mode_sta) &&
  4563. !qdf_mem_cmp(peer_mac_addr, &vdev->mac_addr.raw[0],
  4564. QDF_MAC_ADDR_SIZE)) {
  4565. ast_type = CDP_TXRX_AST_TYPE_SELF;
  4566. }
  4567. dp_peer_add_ast(soc, peer, peer_mac_addr, ast_type, 0);
  4568. /*
  4569. * Control path maintains a node count which is incremented
  4570. * for every new peer create command. Since new peer is not being
  4571. * created and earlier reference is reused here,
  4572. * peer_unref_delete event is sent to control path to
  4573. * increment the count back.
  4574. */
  4575. if (soc->cdp_soc.ol_ops->peer_unref_delete) {
  4576. soc->cdp_soc.ol_ops->peer_unref_delete(pdev->ctrl_pdev,
  4577. peer->mac_addr.raw, vdev->mac_addr.raw,
  4578. vdev->opmode, peer->ctrl_peer, ctrl_peer);
  4579. }
  4580. peer->ctrl_peer = ctrl_peer;
  4581. dp_local_peer_id_alloc(pdev, peer);
  4582. qdf_spinlock_create(&peer->peer_info_lock);
  4583. dp_peer_rx_bufq_resources_init(peer);
  4584. DP_STATS_INIT(peer);
  4585. DP_STATS_UPD(peer, rx.avg_rssi, INVALID_RSSI);
  4586. return (void *)peer;
  4587. } else {
  4588. /*
  4589. * When a STA roams from RPTR AP to ROOT AP and vice versa, we
  4590. * need to remove the AST entry which was earlier added as a WDS
  4591. * entry.
  4592. * If an AST entry exists, but no peer entry exists with a given
  4593. * MAC addresses, we could deduce it as a WDS entry
  4594. */
  4595. dp_peer_ast_handle_roam_del(soc, pdev, peer_mac_addr);
  4596. }
  4597. #ifdef notyet
  4598. peer = (struct dp_peer *)qdf_mempool_alloc(soc->osdev,
  4599. soc->mempool_ol_ath_peer);
  4600. #else
  4601. peer = (struct dp_peer *)qdf_mem_malloc(sizeof(*peer));
  4602. #endif
  4603. if (!peer)
  4604. return NULL; /* failure */
  4605. qdf_mem_zero(peer, sizeof(struct dp_peer));
  4606. TAILQ_INIT(&peer->ast_entry_list);
  4607. /* store provided params */
  4608. peer->vdev = vdev;
  4609. peer->ctrl_peer = ctrl_peer;
  4610. if ((vdev->opmode == wlan_op_mode_sta) &&
  4611. !qdf_mem_cmp(peer_mac_addr, &vdev->mac_addr.raw[0],
  4612. QDF_MAC_ADDR_SIZE)) {
  4613. ast_type = CDP_TXRX_AST_TYPE_SELF;
  4614. }
  4615. dp_peer_add_ast(soc, peer, peer_mac_addr, ast_type, 0);
  4616. qdf_spinlock_create(&peer->peer_info_lock);
  4617. dp_peer_rx_bufq_resources_init(peer);
  4618. qdf_mem_copy(
  4619. &peer->mac_addr.raw[0], peer_mac_addr, QDF_MAC_ADDR_SIZE);
  4620. /* initialize the peer_id */
  4621. for (i = 0; i < MAX_NUM_PEER_ID_PER_PEER; i++)
  4622. peer->peer_ids[i] = HTT_INVALID_PEER;
  4623. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  4624. qdf_atomic_init(&peer->ref_cnt);
  4625. /* keep one reference for attach */
  4626. qdf_atomic_inc(&peer->ref_cnt);
  4627. /* add this peer into the vdev's list */
  4628. if (wlan_op_mode_sta == vdev->opmode)
  4629. TAILQ_INSERT_HEAD(&vdev->peer_list, peer, peer_list_elem);
  4630. else
  4631. TAILQ_INSERT_TAIL(&vdev->peer_list, peer, peer_list_elem);
  4632. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  4633. /* TODO: See if hash based search is required */
  4634. dp_peer_find_hash_add(soc, peer);
  4635. /* Initialize the peer state */
  4636. peer->state = OL_TXRX_PEER_STATE_DISC;
  4637. dp_info("vdev %pK created peer %pK (%pM) ref_cnt: %d",
  4638. vdev, peer, peer->mac_addr.raw,
  4639. qdf_atomic_read(&peer->ref_cnt));
  4640. /*
  4641. * For every peer MAp message search and set if bss_peer
  4642. */
  4643. if (qdf_mem_cmp(peer->mac_addr.raw, vdev->mac_addr.raw,
  4644. QDF_MAC_ADDR_SIZE) == 0 &&
  4645. (wlan_op_mode_sta != vdev->opmode)) {
  4646. dp_info("vdev bss_peer!!");
  4647. peer->bss_peer = 1;
  4648. vdev->vap_bss_peer = peer;
  4649. }
  4650. if (wlan_op_mode_sta == vdev->opmode &&
  4651. qdf_mem_cmp(peer->mac_addr.raw, vdev->mac_addr.raw,
  4652. QDF_MAC_ADDR_SIZE) == 0) {
  4653. vdev->vap_self_peer = peer;
  4654. }
  4655. for (i = 0; i < DP_MAX_TIDS; i++)
  4656. qdf_spinlock_create(&peer->rx_tid[i].tid_lock);
  4657. peer->valid = 1;
  4658. dp_local_peer_id_alloc(pdev, peer);
  4659. DP_STATS_INIT(peer);
  4660. DP_STATS_UPD(peer, rx.avg_rssi, INVALID_RSSI);
  4661. qdf_mem_copy(peer_cookie.mac_addr, peer->mac_addr.raw,
  4662. QDF_MAC_ADDR_SIZE);
  4663. peer_cookie.ctx = NULL;
  4664. peer_cookie.cookie = pdev->next_peer_cookie++;
  4665. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  4666. dp_wdi_event_handler(WDI_EVENT_PEER_CREATE, pdev->soc,
  4667. (void *)&peer_cookie,
  4668. peer->peer_ids[0], WDI_NO_VAL, pdev->pdev_id);
  4669. #endif
  4670. if (soc->wlanstats_enabled) {
  4671. if (!peer_cookie.ctx) {
  4672. pdev->next_peer_cookie--;
  4673. qdf_err("Failed to initialize peer rate stats");
  4674. } else {
  4675. peer->wlanstats_ctx = (struct cdp_peer_rate_stats_ctx *)
  4676. peer_cookie.ctx;
  4677. }
  4678. }
  4679. return (void *)peer;
  4680. }
  4681. /*
  4682. * dp_vdev_get_default_reo_hash() - get reo dest ring and hash values for a vdev
  4683. * @vdev: Datapath VDEV handle
  4684. * @reo_dest: pointer to default reo_dest ring for vdev to be populated
  4685. * @hash_based: pointer to hash value (enabled/disabled) to be populated
  4686. *
  4687. * Return: None
  4688. */
  4689. static
  4690. void dp_vdev_get_default_reo_hash(struct dp_vdev *vdev,
  4691. enum cdp_host_reo_dest_ring *reo_dest,
  4692. bool *hash_based)
  4693. {
  4694. struct dp_soc *soc;
  4695. struct dp_pdev *pdev;
  4696. pdev = vdev->pdev;
  4697. soc = pdev->soc;
  4698. /*
  4699. * hash based steering is disabled for Radios which are offloaded
  4700. * to NSS
  4701. */
  4702. if (!wlan_cfg_get_dp_pdev_nss_enabled(pdev->wlan_cfg_ctx))
  4703. *hash_based = wlan_cfg_is_rx_hash_enabled(soc->wlan_cfg_ctx);
  4704. /*
  4705. * Below line of code will ensure the proper reo_dest ring is chosen
  4706. * for cases where toeplitz hash cannot be generated (ex: non TCP/UDP)
  4707. */
  4708. *reo_dest = pdev->reo_dest;
  4709. }
  4710. #ifdef IPA_OFFLOAD
  4711. /**
  4712. * dp_is_vdev_subtype_p2p() - Check if the subtype for vdev is P2P
  4713. * @vdev: Virtual device
  4714. *
  4715. * Return: true if the vdev is of subtype P2P
  4716. * false if the vdev is of any other subtype
  4717. */
  4718. static inline bool dp_is_vdev_subtype_p2p(struct dp_vdev *vdev)
  4719. {
  4720. if (vdev->subtype == wlan_op_subtype_p2p_device ||
  4721. vdev->subtype == wlan_op_subtype_p2p_cli ||
  4722. vdev->subtype == wlan_op_subtype_p2p_go)
  4723. return true;
  4724. return false;
  4725. }
  4726. /*
  4727. * dp_peer_setup_get_reo_hash() - get reo dest ring and hash values for a peer
  4728. * @vdev: Datapath VDEV handle
  4729. * @reo_dest: pointer to default reo_dest ring for vdev to be populated
  4730. * @hash_based: pointer to hash value (enabled/disabled) to be populated
  4731. *
  4732. * If IPA is enabled in ini, for SAP mode, disable hash based
  4733. * steering, use default reo_dst ring for RX. Use config values for other modes.
  4734. * Return: None
  4735. */
  4736. static void dp_peer_setup_get_reo_hash(struct dp_vdev *vdev,
  4737. enum cdp_host_reo_dest_ring *reo_dest,
  4738. bool *hash_based)
  4739. {
  4740. struct dp_soc *soc;
  4741. struct dp_pdev *pdev;
  4742. pdev = vdev->pdev;
  4743. soc = pdev->soc;
  4744. dp_vdev_get_default_reo_hash(vdev, reo_dest, hash_based);
  4745. /* For P2P-GO interfaces we do not need to change the REO
  4746. * configuration even if IPA config is enabled
  4747. */
  4748. if (dp_is_vdev_subtype_p2p(vdev))
  4749. return;
  4750. /*
  4751. * If IPA is enabled, disable hash-based flow steering and set
  4752. * reo_dest_ring_4 as the REO ring to receive packets on.
  4753. * IPA is configured to reap reo_dest_ring_4.
  4754. *
  4755. * Note - REO DST indexes are from 0 - 3, while cdp_host_reo_dest_ring
  4756. * value enum value is from 1 - 4.
  4757. * Hence, *reo_dest = IPA_REO_DEST_RING_IDX + 1
  4758. */
  4759. if (wlan_cfg_is_ipa_enabled(soc->wlan_cfg_ctx)) {
  4760. if (vdev->opmode == wlan_op_mode_ap) {
  4761. *reo_dest = IPA_REO_DEST_RING_IDX + 1;
  4762. *hash_based = 0;
  4763. } else if (vdev->opmode == wlan_op_mode_sta &&
  4764. dp_ipa_is_mdm_platform()) {
  4765. *reo_dest = IPA_REO_DEST_RING_IDX + 1;
  4766. }
  4767. }
  4768. }
  4769. #else
  4770. /*
  4771. * dp_peer_setup_get_reo_hash() - get reo dest ring and hash values for a peer
  4772. * @vdev: Datapath VDEV handle
  4773. * @reo_dest: pointer to default reo_dest ring for vdev to be populated
  4774. * @hash_based: pointer to hash value (enabled/disabled) to be populated
  4775. *
  4776. * Use system config values for hash based steering.
  4777. * Return: None
  4778. */
  4779. static void dp_peer_setup_get_reo_hash(struct dp_vdev *vdev,
  4780. enum cdp_host_reo_dest_ring *reo_dest,
  4781. bool *hash_based)
  4782. {
  4783. dp_vdev_get_default_reo_hash(vdev, reo_dest, hash_based);
  4784. }
  4785. #endif /* IPA_OFFLOAD */
  4786. /*
  4787. * dp_peer_setup_wifi3() - initialize the peer
  4788. * @vdev_hdl: virtual device object
  4789. * @peer: Peer object
  4790. *
  4791. * Return: void
  4792. */
  4793. static void dp_peer_setup_wifi3(struct cdp_vdev *vdev_hdl, void *peer_hdl)
  4794. {
  4795. struct dp_peer *peer = (struct dp_peer *)peer_hdl;
  4796. struct dp_vdev *vdev = (struct dp_vdev *)vdev_hdl;
  4797. struct dp_pdev *pdev;
  4798. struct dp_soc *soc;
  4799. bool hash_based = 0;
  4800. enum cdp_host_reo_dest_ring reo_dest;
  4801. /* preconditions */
  4802. qdf_assert(vdev);
  4803. qdf_assert(peer);
  4804. pdev = vdev->pdev;
  4805. soc = pdev->soc;
  4806. dp_peer_setup_get_reo_hash(vdev, &reo_dest, &hash_based);
  4807. dp_info("pdev: %d vdev :%d opmode:%u hash-based-steering:%d default-reo_dest:%u",
  4808. pdev->pdev_id, vdev->vdev_id,
  4809. vdev->opmode, hash_based, reo_dest);
  4810. /*
  4811. * There are corner cases where the AD1 = AD2 = "VAPs address"
  4812. * i.e both the devices have same MAC address. In these
  4813. * cases we want such pkts to be processed in NULL Q handler
  4814. * which is REO2TCL ring. for this reason we should
  4815. * not setup reo_queues and default route for bss_peer.
  4816. */
  4817. if (peer->bss_peer && vdev->opmode == wlan_op_mode_ap)
  4818. return;
  4819. if (soc->cdp_soc.ol_ops->peer_set_default_routing) {
  4820. /* TODO: Check the destination ring number to be passed to FW */
  4821. soc->cdp_soc.ol_ops->peer_set_default_routing(
  4822. pdev->ctrl_pdev, peer->mac_addr.raw,
  4823. peer->vdev->vdev_id, hash_based, reo_dest);
  4824. }
  4825. qdf_atomic_set(&peer->is_default_route_set, 1);
  4826. dp_peer_rx_init(pdev, peer);
  4827. dp_peer_tx_init(pdev, peer);
  4828. dp_peer_ppdu_delayed_ba_init(peer);
  4829. return;
  4830. }
  4831. /*
  4832. * dp_cp_peer_del_resp_handler - Handle the peer delete response
  4833. * @soc_hdl: Datapath SOC handle
  4834. * @vdev_hdl: virtual device object
  4835. * @mac_addr: Mac address of the peer
  4836. *
  4837. * Return: void
  4838. */
  4839. static void dp_cp_peer_del_resp_handler(struct cdp_soc_t *soc_hdl,
  4840. struct cdp_vdev *vdev_hdl,
  4841. uint8_t *mac_addr)
  4842. {
  4843. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  4844. struct dp_ast_entry *ast_entry = NULL;
  4845. struct dp_vdev *vdev = (struct dp_vdev *)vdev_hdl;
  4846. txrx_ast_free_cb cb = NULL;
  4847. void *cookie;
  4848. qdf_spin_lock_bh(&soc->ast_lock);
  4849. if (soc->ast_override_support)
  4850. ast_entry =
  4851. dp_peer_ast_hash_find_by_pdevid(soc, mac_addr,
  4852. vdev->pdev->pdev_id);
  4853. else
  4854. ast_entry = dp_peer_ast_hash_find_soc(soc, mac_addr);
  4855. /* in case of qwrap we have multiple BSS peers
  4856. * with same mac address
  4857. *
  4858. * AST entry for this mac address will be created
  4859. * only for one peer hence it will be NULL here
  4860. */
  4861. if (!ast_entry || ast_entry->peer || !ast_entry->delete_in_progress) {
  4862. qdf_spin_unlock_bh(&soc->ast_lock);
  4863. return;
  4864. }
  4865. if (ast_entry->is_mapped)
  4866. soc->ast_table[ast_entry->ast_idx] = NULL;
  4867. DP_STATS_INC(soc, ast.deleted, 1);
  4868. dp_peer_ast_hash_remove(soc, ast_entry);
  4869. cb = ast_entry->callback;
  4870. cookie = ast_entry->cookie;
  4871. ast_entry->callback = NULL;
  4872. ast_entry->cookie = NULL;
  4873. soc->num_ast_entries--;
  4874. qdf_spin_unlock_bh(&soc->ast_lock);
  4875. if (cb) {
  4876. cb(soc->ctrl_psoc,
  4877. dp_soc_to_cdp_soc(soc),
  4878. cookie,
  4879. CDP_TXRX_AST_DELETED);
  4880. }
  4881. qdf_mem_free(ast_entry);
  4882. }
  4883. /*
  4884. * dp_set_vdev_tx_encap_type() - set the encap type of the vdev
  4885. * @vdev_handle: virtual device object
  4886. * @htt_pkt_type: type of pkt
  4887. *
  4888. * Return: void
  4889. */
  4890. static void dp_set_vdev_tx_encap_type(struct cdp_vdev *vdev_handle,
  4891. enum htt_cmn_pkt_type val)
  4892. {
  4893. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  4894. vdev->tx_encap_type = val;
  4895. }
  4896. /*
  4897. * dp_set_vdev_rx_decap_type() - set the decap type of the vdev
  4898. * @vdev_handle: virtual device object
  4899. * @htt_pkt_type: type of pkt
  4900. *
  4901. * Return: void
  4902. */
  4903. static void dp_set_vdev_rx_decap_type(struct cdp_vdev *vdev_handle,
  4904. enum htt_cmn_pkt_type val)
  4905. {
  4906. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  4907. vdev->rx_decap_type = val;
  4908. }
  4909. /*
  4910. * dp_set_ba_aging_timeout() - set ba aging timeout per AC
  4911. * @txrx_soc: cdp soc handle
  4912. * @ac: Access category
  4913. * @value: timeout value in millisec
  4914. *
  4915. * Return: void
  4916. */
  4917. static void dp_set_ba_aging_timeout(struct cdp_soc_t *txrx_soc,
  4918. uint8_t ac, uint32_t value)
  4919. {
  4920. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  4921. hal_set_ba_aging_timeout(soc->hal_soc, ac, value);
  4922. }
  4923. /*
  4924. * dp_get_ba_aging_timeout() - get ba aging timeout per AC
  4925. * @txrx_soc: cdp soc handle
  4926. * @ac: access category
  4927. * @value: timeout value in millisec
  4928. *
  4929. * Return: void
  4930. */
  4931. static void dp_get_ba_aging_timeout(struct cdp_soc_t *txrx_soc,
  4932. uint8_t ac, uint32_t *value)
  4933. {
  4934. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  4935. hal_get_ba_aging_timeout(soc->hal_soc, ac, value);
  4936. }
  4937. /*
  4938. * dp_set_pdev_reo_dest() - set the reo destination ring for this pdev
  4939. * @pdev_handle: physical device object
  4940. * @val: reo destination ring index (1 - 4)
  4941. *
  4942. * Return: void
  4943. */
  4944. static void dp_set_pdev_reo_dest(struct cdp_pdev *pdev_handle,
  4945. enum cdp_host_reo_dest_ring val)
  4946. {
  4947. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  4948. if (pdev)
  4949. pdev->reo_dest = val;
  4950. }
  4951. /*
  4952. * dp_get_pdev_reo_dest() - get the reo destination for this pdev
  4953. * @pdev_handle: physical device object
  4954. *
  4955. * Return: reo destination ring index
  4956. */
  4957. static enum cdp_host_reo_dest_ring
  4958. dp_get_pdev_reo_dest(struct cdp_pdev *pdev_handle)
  4959. {
  4960. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  4961. if (pdev)
  4962. return pdev->reo_dest;
  4963. else
  4964. return cdp_host_reo_dest_ring_unknown;
  4965. }
  4966. /*
  4967. * dp_set_filter_neighbour_peers() - set filter neighbour peers for smart mesh
  4968. * @pdev_handle: device object
  4969. * @val: value to be set
  4970. *
  4971. * Return: void
  4972. */
  4973. static int dp_set_filter_neighbour_peers(struct cdp_pdev *pdev_handle,
  4974. uint32_t val)
  4975. {
  4976. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  4977. /* Enable/Disable smart mesh filtering. This flag will be checked
  4978. * during rx processing to check if packets are from NAC clients.
  4979. */
  4980. pdev->filter_neighbour_peers = val;
  4981. return 0;
  4982. }
  4983. /*
  4984. * dp_update_filter_neighbour_peers() - set neighbour peers(nac clients)
  4985. * address for smart mesh filtering
  4986. * @vdev_handle: virtual device object
  4987. * @cmd: Add/Del command
  4988. * @macaddr: nac client mac address
  4989. *
  4990. * Return: void
  4991. */
  4992. static int dp_update_filter_neighbour_peers(struct cdp_vdev *vdev_handle,
  4993. uint32_t cmd, uint8_t *macaddr)
  4994. {
  4995. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  4996. struct dp_pdev *pdev = vdev->pdev;
  4997. struct dp_neighbour_peer *peer = NULL;
  4998. if (!macaddr)
  4999. goto fail0;
  5000. /* Store address of NAC (neighbour peer) which will be checked
  5001. * against TA of received packets.
  5002. */
  5003. if (cmd == DP_NAC_PARAM_ADD) {
  5004. peer = (struct dp_neighbour_peer *) qdf_mem_malloc(
  5005. sizeof(*peer));
  5006. if (!peer) {
  5007. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  5008. FL("DP neighbour peer node memory allocation failed"));
  5009. goto fail0;
  5010. }
  5011. qdf_mem_copy(&peer->neighbour_peers_macaddr.raw[0],
  5012. macaddr, QDF_MAC_ADDR_SIZE);
  5013. peer->vdev = vdev;
  5014. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  5015. /* add this neighbour peer into the list */
  5016. TAILQ_INSERT_TAIL(&pdev->neighbour_peers_list, peer,
  5017. neighbour_peer_list_elem);
  5018. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  5019. /* first neighbour */
  5020. if (!pdev->neighbour_peers_added) {
  5021. pdev->neighbour_peers_added = true;
  5022. dp_ppdu_ring_cfg(pdev);
  5023. }
  5024. return 1;
  5025. } else if (cmd == DP_NAC_PARAM_DEL) {
  5026. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  5027. TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
  5028. neighbour_peer_list_elem) {
  5029. if (!qdf_mem_cmp(&peer->neighbour_peers_macaddr.raw[0],
  5030. macaddr, QDF_MAC_ADDR_SIZE)) {
  5031. /* delete this peer from the list */
  5032. TAILQ_REMOVE(&pdev->neighbour_peers_list,
  5033. peer, neighbour_peer_list_elem);
  5034. qdf_mem_free(peer);
  5035. break;
  5036. }
  5037. }
  5038. /* last neighbour deleted */
  5039. if (TAILQ_EMPTY(&pdev->neighbour_peers_list)) {
  5040. pdev->neighbour_peers_added = false;
  5041. dp_ppdu_ring_cfg(pdev);
  5042. }
  5043. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  5044. if (!pdev->mcopy_mode && !pdev->neighbour_peers_added &&
  5045. !pdev->enhanced_stats_en)
  5046. dp_ppdu_ring_reset(pdev);
  5047. return 1;
  5048. }
  5049. fail0:
  5050. return 0;
  5051. }
  5052. /*
  5053. * dp_get_sec_type() - Get the security type
  5054. * @peer: Datapath peer handle
  5055. * @sec_idx: Security id (mcast, ucast)
  5056. *
  5057. * return sec_type: Security type
  5058. */
  5059. static int dp_get_sec_type(struct cdp_peer *peer, uint8_t sec_idx)
  5060. {
  5061. struct dp_peer *dpeer = (struct dp_peer *)peer;
  5062. return dpeer->security[sec_idx].sec_type;
  5063. }
  5064. /*
  5065. * dp_peer_authorize() - authorize txrx peer
  5066. * @peer_handle: Datapath peer handle
  5067. * @authorize
  5068. *
  5069. */
  5070. static void dp_peer_authorize(struct cdp_peer *peer_handle, uint32_t authorize)
  5071. {
  5072. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  5073. struct dp_soc *soc;
  5074. if (peer) {
  5075. soc = peer->vdev->pdev->soc;
  5076. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  5077. peer->authorize = authorize ? 1 : 0;
  5078. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  5079. }
  5080. }
  5081. /*
  5082. * dp_vdev_reset_peer() - Update peer related member in vdev
  5083. as peer is going to free
  5084. * @vdev: datapath vdev handle
  5085. * @peer: dataptah peer handle
  5086. *
  5087. * Return: None
  5088. */
  5089. static void dp_vdev_reset_peer(struct dp_vdev *vdev,
  5090. struct dp_peer *peer)
  5091. {
  5092. struct dp_peer *bss_peer = NULL;
  5093. if (!vdev) {
  5094. dp_err("vdev is NULL");
  5095. } else {
  5096. if (vdev->vap_bss_peer == peer)
  5097. vdev->vap_bss_peer = NULL;
  5098. if (vdev && vdev->vap_bss_peer) {
  5099. bss_peer = vdev->vap_bss_peer;
  5100. DP_UPDATE_STATS(vdev, peer);
  5101. }
  5102. }
  5103. }
  5104. /*
  5105. * dp_peer_release_mem() - free dp peer handle memory
  5106. * @soc: dataptah soc handle
  5107. * @pdev: datapath pdev handle
  5108. * @peer: datapath peer handle
  5109. * @vdev_opmode: Vdev operation mode
  5110. * @vdev_mac_addr: Vdev Mac address
  5111. *
  5112. * Return: None
  5113. */
  5114. static void dp_peer_release_mem(struct dp_soc *soc,
  5115. struct dp_pdev *pdev,
  5116. struct dp_peer *peer,
  5117. enum wlan_op_mode vdev_opmode,
  5118. uint8_t *vdev_mac_addr)
  5119. {
  5120. if (soc->cdp_soc.ol_ops->peer_unref_delete)
  5121. soc->cdp_soc.ol_ops->peer_unref_delete(
  5122. pdev->ctrl_pdev,
  5123. peer->mac_addr.raw, vdev_mac_addr,
  5124. vdev_opmode, peer->ctrl_peer,
  5125. NULL);
  5126. /*
  5127. * Peer AST list hast to be empty here
  5128. */
  5129. DP_AST_ASSERT(TAILQ_EMPTY(&peer->ast_entry_list));
  5130. qdf_mem_free(peer);
  5131. }
  5132. /**
  5133. * dp_delete_pending_vdev() - check and process vdev delete
  5134. * @pdev: DP specific pdev pointer
  5135. * @vdev: DP specific vdev pointer
  5136. * @vdev_id: vdev id corresponding to vdev
  5137. *
  5138. * This API does following:
  5139. * 1) It releases tx flow pools buffers as vdev is
  5140. * going down and no peers are associated.
  5141. * 2) It also detaches vdev before cleaning vdev (struct dp_vdev) memory
  5142. */
  5143. static void dp_delete_pending_vdev(struct dp_pdev *pdev, struct dp_vdev *vdev,
  5144. uint8_t vdev_id)
  5145. {
  5146. ol_txrx_vdev_delete_cb vdev_delete_cb = NULL;
  5147. void *vdev_delete_context = NULL;
  5148. vdev_delete_cb = vdev->delete.callback;
  5149. vdev_delete_context = vdev->delete.context;
  5150. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  5151. FL("deleting vdev object %pK (%pM)- its last peer is done"),
  5152. vdev, vdev->mac_addr.raw);
  5153. /* all peers are gone, go ahead and delete it */
  5154. dp_tx_flow_pool_unmap_handler(pdev, vdev_id,
  5155. FLOW_TYPE_VDEV, vdev_id);
  5156. dp_tx_vdev_detach(vdev);
  5157. pdev->soc->vdev_id_map[vdev_id] = NULL;
  5158. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  5159. TAILQ_REMOVE(&pdev->vdev_list, vdev, vdev_list_elem);
  5160. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  5161. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  5162. FL("deleting vdev object %pK (%pM)"),
  5163. vdev, vdev->mac_addr.raw);
  5164. qdf_mem_free(vdev);
  5165. vdev = NULL;
  5166. if (vdev_delete_cb)
  5167. vdev_delete_cb(vdev_delete_context);
  5168. }
  5169. /*
  5170. * dp_peer_unref_delete() - unref and delete peer
  5171. * @peer_handle: Datapath peer handle
  5172. *
  5173. */
  5174. void dp_peer_unref_delete(struct dp_peer *peer)
  5175. {
  5176. struct dp_vdev *vdev = peer->vdev;
  5177. struct dp_pdev *pdev = vdev->pdev;
  5178. struct dp_soc *soc = pdev->soc;
  5179. struct dp_peer *tmppeer;
  5180. int found = 0;
  5181. uint16_t peer_id;
  5182. uint16_t vdev_id;
  5183. bool vdev_delete = false;
  5184. struct cdp_peer_cookie peer_cookie;
  5185. enum wlan_op_mode vdev_opmode;
  5186. uint8_t vdev_mac_addr[QDF_MAC_ADDR_SIZE];
  5187. /*
  5188. * Hold the lock all the way from checking if the peer ref count
  5189. * is zero until the peer references are removed from the hash
  5190. * table and vdev list (if the peer ref count is zero).
  5191. * This protects against a new HL tx operation starting to use the
  5192. * peer object just after this function concludes it's done being used.
  5193. * Furthermore, the lock needs to be held while checking whether the
  5194. * vdev's list of peers is empty, to make sure that list is not modified
  5195. * concurrently with the empty check.
  5196. */
  5197. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  5198. if (qdf_atomic_dec_and_test(&peer->ref_cnt)) {
  5199. peer_id = peer->peer_ids[0];
  5200. vdev_id = vdev->vdev_id;
  5201. /*
  5202. * Make sure that the reference to the peer in
  5203. * peer object map is removed
  5204. */
  5205. if (peer_id != HTT_INVALID_PEER)
  5206. soc->peer_id_to_obj_map[peer_id] = NULL;
  5207. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  5208. "Deleting peer %pK (%pM)", peer, peer->mac_addr.raw);
  5209. /* remove the reference to the peer from the hash table */
  5210. dp_peer_find_hash_remove(soc, peer);
  5211. qdf_spin_lock_bh(&soc->ast_lock);
  5212. if (peer->self_ast_entry) {
  5213. dp_peer_del_ast(soc, peer->self_ast_entry);
  5214. peer->self_ast_entry = NULL;
  5215. }
  5216. qdf_spin_unlock_bh(&soc->ast_lock);
  5217. TAILQ_FOREACH(tmppeer, &peer->vdev->peer_list, peer_list_elem) {
  5218. if (tmppeer == peer) {
  5219. found = 1;
  5220. break;
  5221. }
  5222. }
  5223. if (found) {
  5224. TAILQ_REMOVE(&peer->vdev->peer_list, peer,
  5225. peer_list_elem);
  5226. } else {
  5227. /*Ignoring the remove operation as peer not found*/
  5228. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  5229. "peer:%pK not found in vdev:%pK peerlist:%pK",
  5230. peer, vdev, &peer->vdev->peer_list);
  5231. }
  5232. /* send peer destroy event to upper layer */
  5233. qdf_mem_copy(peer_cookie.mac_addr, peer->mac_addr.raw,
  5234. QDF_MAC_ADDR_SIZE);
  5235. peer_cookie.ctx = NULL;
  5236. peer_cookie.ctx = (struct cdp_stats_cookie *)
  5237. peer->wlanstats_ctx;
  5238. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  5239. dp_wdi_event_handler(WDI_EVENT_PEER_DESTROY,
  5240. pdev->soc,
  5241. (void *)&peer_cookie,
  5242. peer->peer_ids[0],
  5243. WDI_NO_VAL,
  5244. pdev->pdev_id);
  5245. #endif
  5246. peer->wlanstats_ctx = NULL;
  5247. /* cleanup the peer data */
  5248. dp_peer_cleanup(vdev, peer, false);
  5249. /* reset this peer related info in vdev */
  5250. dp_vdev_reset_peer(vdev, peer);
  5251. /* save vdev related member in case vdev freed */
  5252. vdev_opmode = vdev->opmode;
  5253. qdf_mem_copy(vdev_mac_addr, vdev->mac_addr.raw,
  5254. QDF_MAC_ADDR_SIZE);
  5255. /*
  5256. * check whether the parent vdev is pending for deleting
  5257. * and no peers left.
  5258. */
  5259. if (vdev->delete.pending && TAILQ_EMPTY(&vdev->peer_list))
  5260. vdev_delete = true;
  5261. /*
  5262. * Now that there are no references to the peer, we can
  5263. * release the peer reference lock.
  5264. */
  5265. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  5266. /*
  5267. * Invoke soc.ol_ops->peer_unref_delete out of
  5268. * peer_ref_mutex in case deadlock issue.
  5269. */
  5270. dp_peer_release_mem(soc, pdev, peer,
  5271. vdev_opmode,
  5272. vdev_mac_addr);
  5273. /*
  5274. * Delete the vdev if it's waiting all peer deleted
  5275. * and it's chance now.
  5276. */
  5277. if (vdev_delete)
  5278. dp_delete_pending_vdev(pdev, vdev, vdev_id);
  5279. } else {
  5280. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  5281. }
  5282. }
  5283. #ifdef PEER_CACHE_RX_PKTS
  5284. static inline void dp_peer_rx_bufq_resources_deinit(struct dp_peer *peer)
  5285. {
  5286. dp_rx_flush_rx_cached(peer, true);
  5287. qdf_list_destroy(&peer->bufq_info.cached_bufq);
  5288. qdf_spinlock_destroy(&peer->bufq_info.bufq_lock);
  5289. }
  5290. #else
  5291. static inline void dp_peer_rx_bufq_resources_deinit(struct dp_peer *peer)
  5292. {
  5293. }
  5294. #endif
  5295. /*
  5296. * dp_peer_detach_wifi3() – Detach txrx peer
  5297. * @peer_handle: Datapath peer handle
  5298. * @bitmap: bitmap indicating special handling of request.
  5299. *
  5300. */
  5301. static void dp_peer_delete_wifi3(void *peer_handle, uint32_t bitmap)
  5302. {
  5303. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  5304. /* redirect the peer's rx delivery function to point to a
  5305. * discard func
  5306. */
  5307. /* Do not make ctrl_peer to NULL for connected sta peers.
  5308. * We need ctrl_peer to release the reference during dp
  5309. * peer free. This reference was held for
  5310. * obj_mgr peer during the creation of dp peer.
  5311. */
  5312. if (!(peer->vdev && (peer->vdev->opmode != wlan_op_mode_sta) &&
  5313. !peer->bss_peer))
  5314. peer->ctrl_peer = NULL;
  5315. peer->valid = 0;
  5316. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  5317. FL("peer %pK (%pM)"), peer, peer->mac_addr.raw);
  5318. dp_local_peer_id_free(peer->vdev->pdev, peer);
  5319. dp_peer_rx_bufq_resources_deinit(peer);
  5320. qdf_spinlock_destroy(&peer->peer_info_lock);
  5321. dp_peer_multipass_list_remove(peer);
  5322. /*
  5323. * Remove the reference added during peer_attach.
  5324. * The peer will still be left allocated until the
  5325. * PEER_UNMAP message arrives to remove the other
  5326. * reference, added by the PEER_MAP message.
  5327. */
  5328. dp_peer_unref_delete(peer_handle);
  5329. }
  5330. /*
  5331. * dp_get_vdev_mac_addr_wifi3() – Detach txrx peer
  5332. * @peer_handle: Datapath peer handle
  5333. *
  5334. */
  5335. static uint8 *dp_get_vdev_mac_addr_wifi3(struct cdp_vdev *pvdev)
  5336. {
  5337. struct dp_vdev *vdev = (struct dp_vdev *)pvdev;
  5338. return vdev->mac_addr.raw;
  5339. }
  5340. /*
  5341. * dp_vdev_set_wds() - Enable per packet stats
  5342. * @vdev_handle: DP VDEV handle
  5343. * @val: value
  5344. *
  5345. * Return: none
  5346. */
  5347. static int dp_vdev_set_wds(void *vdev_handle, uint32_t val)
  5348. {
  5349. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  5350. vdev->wds_enabled = val;
  5351. return 0;
  5352. }
  5353. /*
  5354. * dp_get_vdev_from_vdev_id_wifi3() – Detach txrx peer
  5355. * @peer_handle: Datapath peer handle
  5356. *
  5357. */
  5358. static struct cdp_vdev *dp_get_vdev_from_vdev_id_wifi3(struct cdp_pdev *dev,
  5359. uint8_t vdev_id)
  5360. {
  5361. struct dp_pdev *pdev = (struct dp_pdev *)dev;
  5362. struct dp_vdev *vdev = NULL;
  5363. if (qdf_unlikely(!pdev))
  5364. return NULL;
  5365. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  5366. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  5367. if (vdev->delete.pending)
  5368. continue;
  5369. if (vdev->vdev_id == vdev_id)
  5370. break;
  5371. }
  5372. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  5373. return (struct cdp_vdev *)vdev;
  5374. }
  5375. /*
  5376. * dp_get_mon_vdev_from_pdev_wifi3() - Get vdev handle of monitor mode
  5377. * @dev: PDEV handle
  5378. *
  5379. * Return: VDEV handle of monitor mode
  5380. */
  5381. static struct cdp_vdev *dp_get_mon_vdev_from_pdev_wifi3(struct cdp_pdev *dev)
  5382. {
  5383. struct dp_pdev *pdev = (struct dp_pdev *)dev;
  5384. if (qdf_unlikely(!pdev))
  5385. return NULL;
  5386. return (struct cdp_vdev *)pdev->monitor_vdev;
  5387. }
  5388. static int dp_get_opmode(struct cdp_soc_t *soc_hdl, uint8_t vdev_id)
  5389. {
  5390. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  5391. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  5392. if (!vdev) {
  5393. dp_err("vdev for id %d is NULL", vdev_id);
  5394. return -EINVAL;
  5395. }
  5396. return vdev->opmode;
  5397. }
  5398. static
  5399. void dp_get_os_rx_handles_from_vdev_wifi3(struct cdp_vdev *pvdev,
  5400. ol_txrx_rx_fp *stack_fn_p,
  5401. ol_osif_vdev_handle *osif_vdev_p)
  5402. {
  5403. struct dp_vdev *vdev = dp_get_dp_vdev_from_cdp_vdev(pvdev);
  5404. qdf_assert(vdev);
  5405. *stack_fn_p = vdev->osif_rx_stack;
  5406. *osif_vdev_p = vdev->osif_vdev;
  5407. }
  5408. static struct cdp_cfg *dp_get_ctrl_pdev_from_vdev_wifi3(struct cdp_vdev *pvdev)
  5409. {
  5410. struct dp_vdev *vdev = (struct dp_vdev *)pvdev;
  5411. struct dp_pdev *pdev = vdev->pdev;
  5412. return (struct cdp_cfg *)pdev->wlan_cfg_ctx;
  5413. }
  5414. /**
  5415. * dp_monitor_mode_ring_config() - Send the tlv config to fw for monitor buffer
  5416. * ring based on target
  5417. * @soc: soc handle
  5418. * @mac_for_pdev: pdev_id
  5419. * @pdev: physical device handle
  5420. * @ring_num: mac id
  5421. * @htt_tlv_filter: tlv filter
  5422. *
  5423. * Return: zero on success, non-zero on failure
  5424. */
  5425. static inline
  5426. QDF_STATUS dp_monitor_mode_ring_config(struct dp_soc *soc, uint8_t mac_for_pdev,
  5427. struct dp_pdev *pdev, uint8_t ring_num,
  5428. struct htt_rx_ring_tlv_filter htt_tlv_filter)
  5429. {
  5430. QDF_STATUS status;
  5431. if (soc->wlan_cfg_ctx->rxdma1_enable)
  5432. status = htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  5433. pdev->rxdma_mon_buf_ring[ring_num]
  5434. .hal_srng,
  5435. RXDMA_MONITOR_BUF, RX_BUFFER_SIZE,
  5436. &htt_tlv_filter);
  5437. else
  5438. status = htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  5439. pdev->rx_mac_buf_ring[ring_num]
  5440. .hal_srng,
  5441. RXDMA_BUF, RX_BUFFER_SIZE,
  5442. &htt_tlv_filter);
  5443. return status;
  5444. }
  5445. static inline void
  5446. dp_pdev_disable_mcopy_code(struct dp_pdev *pdev)
  5447. {
  5448. pdev->mcopy_mode = 0;
  5449. qdf_nbuf_queue_free(&pdev->rx_ppdu_buf_q);
  5450. }
  5451. /**
  5452. * dp_reset_monitor_mode() - Disable monitor mode
  5453. * @pdev_handle: Datapath PDEV handle
  5454. *
  5455. * Return: QDF_STATUS
  5456. */
  5457. QDF_STATUS dp_reset_monitor_mode(struct cdp_pdev *pdev_handle)
  5458. {
  5459. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  5460. struct htt_rx_ring_tlv_filter htt_tlv_filter;
  5461. struct dp_soc *soc = pdev->soc;
  5462. uint8_t pdev_id;
  5463. int mac_id;
  5464. QDF_STATUS status = QDF_STATUS_SUCCESS;
  5465. pdev_id = pdev->pdev_id;
  5466. soc = pdev->soc;
  5467. qdf_spin_lock_bh(&pdev->mon_lock);
  5468. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  5469. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  5470. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  5471. status = dp_monitor_mode_ring_config(soc, mac_for_pdev,
  5472. pdev, mac_id,
  5473. htt_tlv_filter);
  5474. if (status != QDF_STATUS_SUCCESS) {
  5475. dp_err("Failed to send tlv filter for monitor mode rings");
  5476. qdf_spin_unlock_bh(&pdev->mon_lock);
  5477. return status;
  5478. }
  5479. htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  5480. pdev->rxdma_mon_status_ring[mac_id].hal_srng,
  5481. RXDMA_MONITOR_STATUS, RX_BUFFER_SIZE,
  5482. &htt_tlv_filter);
  5483. }
  5484. pdev->monitor_vdev = NULL;
  5485. if (pdev->mcopy_mode)
  5486. dp_pdev_disable_mcopy_code(pdev);
  5487. pdev->monitor_configured = false;
  5488. qdf_spin_unlock_bh(&pdev->mon_lock);
  5489. return QDF_STATUS_SUCCESS;
  5490. }
  5491. /**
  5492. * dp_set_nac() - set peer_nac
  5493. * @peer_handle: Datapath PEER handle
  5494. *
  5495. * Return: void
  5496. */
  5497. static void dp_set_nac(struct cdp_peer *peer_handle)
  5498. {
  5499. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  5500. peer->nac = 1;
  5501. }
  5502. /**
  5503. * dp_get_tx_pending() - read pending tx
  5504. * @pdev_handle: Datapath PDEV handle
  5505. *
  5506. * Return: outstanding tx
  5507. */
  5508. static int dp_get_tx_pending(struct cdp_pdev *pdev_handle)
  5509. {
  5510. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  5511. return qdf_atomic_read(&pdev->num_tx_outstanding);
  5512. }
  5513. /**
  5514. * dp_get_peer_mac_from_peer_id() - get peer mac
  5515. * @pdev_handle: Datapath PDEV handle
  5516. * @peer_id: Peer ID
  5517. * @peer_mac: MAC addr of PEER
  5518. *
  5519. * Return: void
  5520. */
  5521. static void dp_get_peer_mac_from_peer_id(struct cdp_pdev *pdev_handle,
  5522. uint32_t peer_id, uint8_t *peer_mac)
  5523. {
  5524. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  5525. struct dp_peer *peer;
  5526. if (pdev && peer_mac) {
  5527. peer = dp_peer_find_by_id(pdev->soc, (uint16_t)peer_id);
  5528. if (peer) {
  5529. qdf_mem_copy(peer_mac, peer->mac_addr.raw,
  5530. QDF_MAC_ADDR_SIZE);
  5531. dp_peer_unref_del_find_by_id(peer);
  5532. }
  5533. }
  5534. }
  5535. /**
  5536. * dp_pdev_configure_monitor_rings() - configure monitor rings
  5537. * @vdev_handle: Datapath VDEV handle
  5538. *
  5539. * Return: QDF_STATUS
  5540. */
  5541. QDF_STATUS dp_pdev_configure_monitor_rings(struct dp_pdev *pdev)
  5542. {
  5543. struct htt_rx_ring_tlv_filter htt_tlv_filter;
  5544. struct dp_soc *soc;
  5545. uint8_t pdev_id;
  5546. int mac_id;
  5547. QDF_STATUS status = QDF_STATUS_SUCCESS;
  5548. pdev_id = pdev->pdev_id;
  5549. soc = pdev->soc;
  5550. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  5551. "MODE[%x] FP[%02x|%02x|%02x] MO[%02x|%02x|%02x]",
  5552. pdev->mon_filter_mode, pdev->fp_mgmt_filter,
  5553. pdev->fp_ctrl_filter, pdev->fp_data_filter,
  5554. pdev->mo_mgmt_filter, pdev->mo_ctrl_filter,
  5555. pdev->mo_data_filter);
  5556. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  5557. htt_tlv_filter.mpdu_start = 1;
  5558. htt_tlv_filter.msdu_start = 1;
  5559. htt_tlv_filter.packet = 1;
  5560. htt_tlv_filter.msdu_end = 1;
  5561. htt_tlv_filter.mpdu_end = 1;
  5562. htt_tlv_filter.packet_header = 1;
  5563. htt_tlv_filter.attention = 1;
  5564. htt_tlv_filter.ppdu_start = 0;
  5565. htt_tlv_filter.ppdu_end = 0;
  5566. htt_tlv_filter.ppdu_end_user_stats = 0;
  5567. htt_tlv_filter.ppdu_end_user_stats_ext = 0;
  5568. htt_tlv_filter.ppdu_end_status_done = 0;
  5569. htt_tlv_filter.header_per_msdu = 1;
  5570. htt_tlv_filter.enable_fp =
  5571. (pdev->mon_filter_mode & MON_FILTER_PASS) ? 1 : 0;
  5572. htt_tlv_filter.enable_md = 0;
  5573. htt_tlv_filter.enable_mo =
  5574. (pdev->mon_filter_mode & MON_FILTER_OTHER) ? 1 : 0;
  5575. htt_tlv_filter.fp_mgmt_filter = pdev->fp_mgmt_filter;
  5576. htt_tlv_filter.fp_ctrl_filter = pdev->fp_ctrl_filter;
  5577. if (pdev->mcopy_mode) {
  5578. htt_tlv_filter.fp_data_filter = 0;
  5579. htt_tlv_filter.mo_data_filter = 0;
  5580. } else {
  5581. htt_tlv_filter.fp_data_filter = pdev->fp_data_filter;
  5582. htt_tlv_filter.mo_data_filter = pdev->mo_data_filter;
  5583. }
  5584. htt_tlv_filter.mo_mgmt_filter = pdev->mo_mgmt_filter;
  5585. htt_tlv_filter.mo_ctrl_filter = pdev->mo_ctrl_filter;
  5586. htt_tlv_filter.offset_valid = false;
  5587. if ((pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU) ||
  5588. (pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU_MSDU)) {
  5589. htt_tlv_filter.fp_mgmt_filter = 0;
  5590. htt_tlv_filter.fp_ctrl_filter = 0;
  5591. htt_tlv_filter.fp_data_filter = 0;
  5592. htt_tlv_filter.mo_mgmt_filter = 0;
  5593. htt_tlv_filter.mo_ctrl_filter = 0;
  5594. htt_tlv_filter.mo_data_filter = 0;
  5595. }
  5596. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  5597. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  5598. status = dp_monitor_mode_ring_config(soc, mac_for_pdev,
  5599. pdev, mac_id,
  5600. htt_tlv_filter);
  5601. if (status != QDF_STATUS_SUCCESS) {
  5602. dp_err("Failed to send tlv filter for monitor mode rings");
  5603. return status;
  5604. }
  5605. }
  5606. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  5607. htt_tlv_filter.mpdu_start = 1;
  5608. htt_tlv_filter.msdu_start = 0;
  5609. htt_tlv_filter.packet = 0;
  5610. htt_tlv_filter.msdu_end = 0;
  5611. htt_tlv_filter.mpdu_end = 0;
  5612. if ((pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU) ||
  5613. (pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU_MSDU)) {
  5614. htt_tlv_filter.mpdu_end = 1;
  5615. }
  5616. htt_tlv_filter.attention = 0;
  5617. htt_tlv_filter.ppdu_start = 1;
  5618. htt_tlv_filter.ppdu_end = 1;
  5619. htt_tlv_filter.ppdu_end_user_stats = 1;
  5620. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  5621. htt_tlv_filter.ppdu_end_status_done = 1;
  5622. htt_tlv_filter.enable_fp = 1;
  5623. htt_tlv_filter.enable_md = 0;
  5624. htt_tlv_filter.enable_mo = 1;
  5625. if (pdev->mcopy_mode ||
  5626. (pdev->rx_enh_capture_mode != CDP_RX_ENH_CAPTURE_DISABLED)) {
  5627. htt_tlv_filter.packet_header = 1;
  5628. if (pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU) {
  5629. htt_tlv_filter.header_per_msdu = 0;
  5630. htt_tlv_filter.enable_mo = 0;
  5631. } else if (pdev->rx_enh_capture_mode ==
  5632. CDP_RX_ENH_CAPTURE_MPDU_MSDU) {
  5633. bool is_rx_mon_proto_flow_tag_enabled =
  5634. wlan_cfg_is_rx_mon_protocol_flow_tag_enabled(
  5635. soc->wlan_cfg_ctx);
  5636. htt_tlv_filter.header_per_msdu = 1;
  5637. htt_tlv_filter.enable_mo = 0;
  5638. if (pdev->is_rx_enh_capture_trailer_enabled ||
  5639. is_rx_mon_proto_flow_tag_enabled)
  5640. htt_tlv_filter.msdu_end = 1;
  5641. }
  5642. }
  5643. htt_tlv_filter.fp_mgmt_filter = FILTER_MGMT_ALL;
  5644. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_ALL;
  5645. htt_tlv_filter.fp_data_filter = FILTER_DATA_ALL;
  5646. htt_tlv_filter.mo_mgmt_filter = FILTER_MGMT_ALL;
  5647. htt_tlv_filter.mo_ctrl_filter = FILTER_CTRL_ALL;
  5648. htt_tlv_filter.mo_data_filter = FILTER_DATA_ALL;
  5649. htt_tlv_filter.offset_valid = false;
  5650. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  5651. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id,
  5652. pdev->pdev_id);
  5653. htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  5654. pdev->rxdma_mon_status_ring[mac_id].hal_srng,
  5655. RXDMA_MONITOR_STATUS, RX_BUFFER_SIZE, &htt_tlv_filter);
  5656. }
  5657. return status;
  5658. }
  5659. /**
  5660. * dp_vdev_set_monitor_mode() - Set DP VDEV to monitor mode
  5661. * @vdev_handle: Datapath VDEV handle
  5662. * @smart_monitor: Flag to denote if its smart monitor mode
  5663. *
  5664. * Return: 0 on success, not 0 on failure
  5665. */
  5666. static QDF_STATUS dp_vdev_set_monitor_mode(struct cdp_vdev *vdev_handle,
  5667. uint8_t special_monitor)
  5668. {
  5669. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  5670. struct dp_pdev *pdev;
  5671. qdf_assert(vdev);
  5672. pdev = vdev->pdev;
  5673. pdev->monitor_vdev = vdev;
  5674. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
  5675. "pdev=%pK, pdev_id=%d, soc=%pK vdev=%pK\n",
  5676. pdev, pdev->pdev_id, pdev->soc, vdev);
  5677. /*
  5678. * do not configure monitor buf ring and filter for smart and
  5679. * lite monitor
  5680. * for smart monitor filters are added along with first NAC
  5681. * for lite monitor required configuration done through
  5682. * dp_set_pdev_param
  5683. */
  5684. if (special_monitor)
  5685. return QDF_STATUS_SUCCESS;
  5686. /*Check if current pdev's monitor_vdev exists */
  5687. if (pdev->monitor_configured) {
  5688. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  5689. "monitor vap already created vdev=%pK\n", vdev);
  5690. return QDF_STATUS_E_RESOURCES;
  5691. }
  5692. pdev->monitor_configured = true;
  5693. dp_mon_buf_delayed_replenish(pdev);
  5694. return dp_pdev_configure_monitor_rings(pdev);
  5695. }
  5696. /**
  5697. * dp_pdev_set_advance_monitor_filter() - Set DP PDEV monitor filter
  5698. * @pdev_handle: Datapath PDEV handle
  5699. * @filter_val: Flag to select Filter for monitor mode
  5700. * Return: 0 on success, not 0 on failure
  5701. */
  5702. static QDF_STATUS
  5703. dp_pdev_set_advance_monitor_filter(struct cdp_pdev *pdev_handle,
  5704. struct cdp_monitor_filter *filter_val)
  5705. {
  5706. /* Many monitor VAPs can exists in a system but only one can be up at
  5707. * anytime
  5708. */
  5709. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  5710. struct dp_vdev *vdev = pdev->monitor_vdev;
  5711. struct htt_rx_ring_tlv_filter htt_tlv_filter;
  5712. struct dp_soc *soc;
  5713. uint8_t pdev_id;
  5714. int mac_id;
  5715. QDF_STATUS status = QDF_STATUS_SUCCESS;
  5716. pdev_id = pdev->pdev_id;
  5717. soc = pdev->soc;
  5718. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
  5719. "pdev=%pK, pdev_id=%d, soc=%pK vdev=%pK",
  5720. pdev, pdev_id, soc, vdev);
  5721. /*Check if current pdev's monitor_vdev exists */
  5722. if (!pdev->monitor_vdev) {
  5723. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  5724. "vdev=%pK", vdev);
  5725. qdf_assert(vdev);
  5726. }
  5727. /* update filter mode, type in pdev structure */
  5728. pdev->mon_filter_mode = filter_val->mode;
  5729. pdev->fp_mgmt_filter = filter_val->fp_mgmt;
  5730. pdev->fp_ctrl_filter = filter_val->fp_ctrl;
  5731. pdev->fp_data_filter = filter_val->fp_data;
  5732. pdev->mo_mgmt_filter = filter_val->mo_mgmt;
  5733. pdev->mo_ctrl_filter = filter_val->mo_ctrl;
  5734. pdev->mo_data_filter = filter_val->mo_data;
  5735. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  5736. "MODE[%x] FP[%02x|%02x|%02x] MO[%02x|%02x|%02x]",
  5737. pdev->mon_filter_mode, pdev->fp_mgmt_filter,
  5738. pdev->fp_ctrl_filter, pdev->fp_data_filter,
  5739. pdev->mo_mgmt_filter, pdev->mo_ctrl_filter,
  5740. pdev->mo_data_filter);
  5741. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  5742. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  5743. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  5744. status = dp_monitor_mode_ring_config(soc, mac_for_pdev,
  5745. pdev, mac_id,
  5746. htt_tlv_filter);
  5747. if (status != QDF_STATUS_SUCCESS) {
  5748. dp_err("Failed to send tlv filter for monitor mode rings");
  5749. return status;
  5750. }
  5751. htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  5752. pdev->rxdma_mon_status_ring[mac_id].hal_srng,
  5753. RXDMA_MONITOR_STATUS, RX_BUFFER_SIZE, &htt_tlv_filter);
  5754. }
  5755. htt_tlv_filter.mpdu_start = 1;
  5756. htt_tlv_filter.msdu_start = 1;
  5757. htt_tlv_filter.packet = 1;
  5758. htt_tlv_filter.msdu_end = 1;
  5759. htt_tlv_filter.mpdu_end = 1;
  5760. htt_tlv_filter.packet_header = 1;
  5761. htt_tlv_filter.attention = 1;
  5762. htt_tlv_filter.ppdu_start = 0;
  5763. htt_tlv_filter.ppdu_end = 0;
  5764. htt_tlv_filter.ppdu_end_user_stats = 0;
  5765. htt_tlv_filter.ppdu_end_user_stats_ext = 0;
  5766. htt_tlv_filter.ppdu_end_status_done = 0;
  5767. htt_tlv_filter.header_per_msdu = 1;
  5768. htt_tlv_filter.enable_fp =
  5769. (pdev->mon_filter_mode & MON_FILTER_PASS) ? 1 : 0;
  5770. htt_tlv_filter.enable_md = 0;
  5771. htt_tlv_filter.enable_mo =
  5772. (pdev->mon_filter_mode & MON_FILTER_OTHER) ? 1 : 0;
  5773. htt_tlv_filter.fp_mgmt_filter = pdev->fp_mgmt_filter;
  5774. htt_tlv_filter.fp_ctrl_filter = pdev->fp_ctrl_filter;
  5775. if (pdev->mcopy_mode)
  5776. htt_tlv_filter.fp_data_filter = 0;
  5777. else
  5778. htt_tlv_filter.fp_data_filter = pdev->fp_data_filter;
  5779. htt_tlv_filter.mo_mgmt_filter = pdev->mo_mgmt_filter;
  5780. htt_tlv_filter.mo_ctrl_filter = pdev->mo_ctrl_filter;
  5781. htt_tlv_filter.mo_data_filter = pdev->mo_data_filter;
  5782. htt_tlv_filter.offset_valid = false;
  5783. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  5784. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  5785. status = dp_monitor_mode_ring_config(soc, mac_for_pdev,
  5786. pdev, mac_id,
  5787. htt_tlv_filter);
  5788. if (status != QDF_STATUS_SUCCESS) {
  5789. dp_err("Failed to send tlv filter for monitor mode rings");
  5790. return status;
  5791. }
  5792. }
  5793. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  5794. htt_tlv_filter.mpdu_start = 1;
  5795. htt_tlv_filter.msdu_start = 0;
  5796. htt_tlv_filter.packet = 0;
  5797. htt_tlv_filter.msdu_end = 0;
  5798. htt_tlv_filter.mpdu_end = 0;
  5799. htt_tlv_filter.attention = 0;
  5800. htt_tlv_filter.ppdu_start = 1;
  5801. htt_tlv_filter.ppdu_end = 1;
  5802. htt_tlv_filter.ppdu_end_user_stats = 1;
  5803. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  5804. htt_tlv_filter.ppdu_end_status_done = 1;
  5805. htt_tlv_filter.enable_fp = 1;
  5806. htt_tlv_filter.enable_md = 0;
  5807. htt_tlv_filter.enable_mo = 1;
  5808. if (pdev->mcopy_mode) {
  5809. htt_tlv_filter.packet_header = 1;
  5810. }
  5811. htt_tlv_filter.fp_mgmt_filter = FILTER_MGMT_ALL;
  5812. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_ALL;
  5813. htt_tlv_filter.fp_data_filter = FILTER_DATA_ALL;
  5814. htt_tlv_filter.mo_mgmt_filter = FILTER_MGMT_ALL;
  5815. htt_tlv_filter.mo_ctrl_filter = FILTER_CTRL_ALL;
  5816. htt_tlv_filter.mo_data_filter = FILTER_DATA_ALL;
  5817. htt_tlv_filter.offset_valid = false;
  5818. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  5819. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id,
  5820. pdev->pdev_id);
  5821. htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  5822. pdev->rxdma_mon_status_ring[mac_id].hal_srng,
  5823. RXDMA_MONITOR_STATUS, RX_BUFFER_SIZE, &htt_tlv_filter);
  5824. }
  5825. return QDF_STATUS_SUCCESS;
  5826. }
  5827. /**
  5828. * dp_pdev_set_monitor_channel() - set monitor channel num in pdev
  5829. * @pdev_handle: Datapath PDEV handle
  5830. *
  5831. * Return: None
  5832. */
  5833. static
  5834. void dp_pdev_set_monitor_channel(struct cdp_pdev *pdev_handle, int chan_num)
  5835. {
  5836. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  5837. pdev->mon_chan_num = chan_num;
  5838. }
  5839. /**
  5840. * dp_deliver_tx_mgmt() - Deliver mgmt frame for tx capture
  5841. * @pdev_handle: Datapath PDEV handle
  5842. * @nbuf: Management frame buffer
  5843. */
  5844. static void
  5845. dp_deliver_tx_mgmt(struct cdp_pdev *pdev_handle, qdf_nbuf_t nbuf)
  5846. {
  5847. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  5848. dp_deliver_mgmt_frm(pdev, nbuf);
  5849. }
  5850. /**
  5851. * dp_get_pdev_id_frm_pdev() - get pdev_id
  5852. * @pdev_handle: Datapath PDEV handle
  5853. *
  5854. * Return: pdev_id
  5855. */
  5856. static
  5857. uint8_t dp_get_pdev_id_frm_pdev(struct cdp_pdev *pdev_handle)
  5858. {
  5859. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  5860. return pdev->pdev_id;
  5861. }
  5862. /**
  5863. * dp_get_delay_stats_flag() - get delay stats flag
  5864. * @pdev_handle: Datapath PDEV handle
  5865. *
  5866. * Return: 0 if flag is disabled else 1
  5867. */
  5868. static
  5869. bool dp_get_delay_stats_flag(struct cdp_pdev *pdev_handle)
  5870. {
  5871. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  5872. return pdev->delay_stats_flag;
  5873. }
  5874. /**
  5875. * dp_pdev_set_chan_noise_floor() - set channel noise floor
  5876. * @pdev_handle: Datapath PDEV handle
  5877. * @chan_noise_floor: Channel Noise Floor
  5878. *
  5879. * Return: void
  5880. */
  5881. static
  5882. void dp_pdev_set_chan_noise_floor(struct cdp_pdev *pdev_handle,
  5883. int16_t chan_noise_floor)
  5884. {
  5885. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  5886. pdev->chan_noise_floor = chan_noise_floor;
  5887. }
  5888. /**
  5889. * dp_vdev_get_filter_ucast_data() - get DP VDEV monitor ucast filter
  5890. * @vdev_handle: Datapath VDEV handle
  5891. * Return: true on ucast filter flag set
  5892. */
  5893. static bool dp_vdev_get_filter_ucast_data(struct cdp_vdev *vdev_handle)
  5894. {
  5895. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  5896. struct dp_pdev *pdev;
  5897. pdev = vdev->pdev;
  5898. if ((pdev->fp_data_filter & FILTER_DATA_UCAST) ||
  5899. (pdev->mo_data_filter & FILTER_DATA_UCAST))
  5900. return true;
  5901. return false;
  5902. }
  5903. /**
  5904. * dp_vdev_get_filter_mcast_data() - get DP VDEV monitor mcast filter
  5905. * @vdev_handle: Datapath VDEV handle
  5906. * Return: true on mcast filter flag set
  5907. */
  5908. static bool dp_vdev_get_filter_mcast_data(struct cdp_vdev *vdev_handle)
  5909. {
  5910. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  5911. struct dp_pdev *pdev;
  5912. pdev = vdev->pdev;
  5913. if ((pdev->fp_data_filter & FILTER_DATA_MCAST) ||
  5914. (pdev->mo_data_filter & FILTER_DATA_MCAST))
  5915. return true;
  5916. return false;
  5917. }
  5918. /**
  5919. * dp_vdev_get_filter_non_data() - get DP VDEV monitor non_data filter
  5920. * @vdev_handle: Datapath VDEV handle
  5921. * Return: true on non data filter flag set
  5922. */
  5923. static bool dp_vdev_get_filter_non_data(struct cdp_vdev *vdev_handle)
  5924. {
  5925. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  5926. struct dp_pdev *pdev;
  5927. pdev = vdev->pdev;
  5928. if ((pdev->fp_mgmt_filter & FILTER_MGMT_ALL) ||
  5929. (pdev->mo_mgmt_filter & FILTER_MGMT_ALL)) {
  5930. if ((pdev->fp_ctrl_filter & FILTER_CTRL_ALL) ||
  5931. (pdev->mo_ctrl_filter & FILTER_CTRL_ALL)) {
  5932. return true;
  5933. }
  5934. }
  5935. return false;
  5936. }
  5937. #ifdef MESH_MODE_SUPPORT
  5938. void dp_peer_set_mesh_mode(struct cdp_vdev *vdev_hdl, uint32_t val)
  5939. {
  5940. struct dp_vdev *vdev = (struct dp_vdev *)vdev_hdl;
  5941. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  5942. FL("val %d"), val);
  5943. vdev->mesh_vdev = val;
  5944. }
  5945. /*
  5946. * dp_peer_set_mesh_rx_filter() - to set the mesh rx filter
  5947. * @vdev_hdl: virtual device object
  5948. * @val: value to be set
  5949. *
  5950. * Return: void
  5951. */
  5952. void dp_peer_set_mesh_rx_filter(struct cdp_vdev *vdev_hdl, uint32_t val)
  5953. {
  5954. struct dp_vdev *vdev = (struct dp_vdev *)vdev_hdl;
  5955. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  5956. FL("val %d"), val);
  5957. vdev->mesh_rx_filter = val;
  5958. }
  5959. #endif
  5960. bool dp_check_pdev_exists(struct dp_soc *soc, struct dp_pdev *data)
  5961. {
  5962. uint8_t pdev_count;
  5963. for (pdev_count = 0; pdev_count < MAX_PDEV_CNT; pdev_count++) {
  5964. if (soc->pdev_list[pdev_count] &&
  5965. soc->pdev_list[pdev_count] == data)
  5966. return true;
  5967. }
  5968. return false;
  5969. }
  5970. /**
  5971. * dp_rx_bar_stats_cb(): BAR received stats callback
  5972. * @soc: SOC handle
  5973. * @cb_ctxt: Call back context
  5974. * @reo_status: Reo status
  5975. *
  5976. * return: void
  5977. */
  5978. void dp_rx_bar_stats_cb(struct dp_soc *soc, void *cb_ctxt,
  5979. union hal_reo_status *reo_status)
  5980. {
  5981. struct dp_pdev *pdev = (struct dp_pdev *)cb_ctxt;
  5982. struct hal_reo_queue_status *queue_status = &(reo_status->queue_status);
  5983. if (!dp_check_pdev_exists(soc, pdev)) {
  5984. dp_err_rl("pdev doesn't exist");
  5985. return;
  5986. }
  5987. if (!qdf_atomic_read(&soc->cmn_init_done))
  5988. return;
  5989. if (queue_status->header.status != HAL_REO_CMD_SUCCESS) {
  5990. DP_PRINT_STATS("REO stats failure %d",
  5991. queue_status->header.status);
  5992. qdf_atomic_set(&(pdev->stats_cmd_complete), 1);
  5993. return;
  5994. }
  5995. pdev->stats.rx.bar_recv_cnt += queue_status->bar_rcvd_cnt;
  5996. qdf_atomic_set(&(pdev->stats_cmd_complete), 1);
  5997. }
  5998. /**
  5999. * dp_aggregate_vdev_stats(): Consolidate stats at VDEV level
  6000. * @vdev: DP VDEV handle
  6001. *
  6002. * return: void
  6003. */
  6004. void dp_aggregate_vdev_stats(struct dp_vdev *vdev,
  6005. struct cdp_vdev_stats *vdev_stats)
  6006. {
  6007. struct dp_peer *peer = NULL;
  6008. struct dp_soc *soc = NULL;
  6009. if (!vdev || !vdev->pdev)
  6010. return;
  6011. soc = vdev->pdev->soc;
  6012. qdf_mem_copy(vdev_stats, &vdev->stats, sizeof(vdev->stats));
  6013. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem)
  6014. dp_update_vdev_stats(vdev_stats, peer);
  6015. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  6016. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, vdev->pdev->soc,
  6017. vdev_stats, vdev->vdev_id,
  6018. UPDATE_VDEV_STATS, vdev->pdev->pdev_id);
  6019. #endif
  6020. }
  6021. void dp_aggregate_pdev_stats(struct dp_pdev *pdev)
  6022. {
  6023. struct dp_vdev *vdev = NULL;
  6024. struct dp_soc *soc;
  6025. struct cdp_vdev_stats *vdev_stats =
  6026. qdf_mem_malloc(sizeof(struct cdp_vdev_stats));
  6027. if (!vdev_stats) {
  6028. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  6029. "DP alloc failure - unable to get alloc vdev stats");
  6030. return;
  6031. }
  6032. qdf_mem_zero(&pdev->stats.tx, sizeof(pdev->stats.tx));
  6033. qdf_mem_zero(&pdev->stats.rx, sizeof(pdev->stats.rx));
  6034. qdf_mem_zero(&pdev->stats.tx_i, sizeof(pdev->stats.tx_i));
  6035. if (pdev->mcopy_mode)
  6036. DP_UPDATE_STATS(pdev, pdev->invalid_peer);
  6037. soc = pdev->soc;
  6038. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  6039. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  6040. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  6041. dp_aggregate_vdev_stats(vdev, vdev_stats);
  6042. dp_update_pdev_stats(pdev, vdev_stats);
  6043. dp_update_pdev_ingress_stats(pdev, vdev);
  6044. }
  6045. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  6046. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  6047. qdf_mem_free(vdev_stats);
  6048. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  6049. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, pdev->soc, &pdev->stats,
  6050. pdev->pdev_id, UPDATE_PDEV_STATS, pdev->pdev_id);
  6051. #endif
  6052. }
  6053. /**
  6054. * dp_vdev_getstats() - get vdev packet level stats
  6055. * @vdev_handle: Datapath VDEV handle
  6056. * @stats: cdp network device stats structure
  6057. *
  6058. * Return: void
  6059. */
  6060. static void dp_vdev_getstats(void *vdev_handle,
  6061. struct cdp_dev_stats *stats)
  6062. {
  6063. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  6064. struct dp_pdev *pdev;
  6065. struct dp_soc *soc;
  6066. struct cdp_vdev_stats *vdev_stats;
  6067. if (!vdev)
  6068. return;
  6069. pdev = vdev->pdev;
  6070. if (!pdev)
  6071. return;
  6072. soc = pdev->soc;
  6073. vdev_stats = qdf_mem_malloc(sizeof(struct cdp_vdev_stats));
  6074. if (!vdev_stats) {
  6075. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  6076. "DP alloc failure - unable to get alloc vdev stats");
  6077. return;
  6078. }
  6079. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  6080. dp_aggregate_vdev_stats(vdev, vdev_stats);
  6081. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  6082. stats->tx_packets = vdev_stats->tx_i.rcvd.num;
  6083. stats->tx_bytes = vdev_stats->tx_i.rcvd.bytes;
  6084. stats->tx_errors = vdev_stats->tx.tx_failed +
  6085. vdev_stats->tx_i.dropped.dropped_pkt.num;
  6086. stats->tx_dropped = stats->tx_errors;
  6087. stats->rx_packets = vdev_stats->rx.unicast.num +
  6088. vdev_stats->rx.multicast.num +
  6089. vdev_stats->rx.bcast.num;
  6090. stats->rx_bytes = vdev_stats->rx.unicast.bytes +
  6091. vdev_stats->rx.multicast.bytes +
  6092. vdev_stats->rx.bcast.bytes;
  6093. qdf_mem_free(vdev_stats);
  6094. }
  6095. /**
  6096. * dp_pdev_getstats() - get pdev packet level stats
  6097. * @pdev_handle: Datapath PDEV handle
  6098. * @stats: cdp network device stats structure
  6099. *
  6100. * Return: void
  6101. */
  6102. static void dp_pdev_getstats(void *pdev_handle,
  6103. struct cdp_dev_stats *stats)
  6104. {
  6105. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6106. dp_aggregate_pdev_stats(pdev);
  6107. stats->tx_packets = pdev->stats.tx_i.rcvd.num;
  6108. stats->tx_bytes = pdev->stats.tx_i.rcvd.bytes;
  6109. stats->tx_errors = pdev->stats.tx.tx_failed +
  6110. pdev->stats.tx_i.dropped.dropped_pkt.num;
  6111. stats->tx_dropped = stats->tx_errors;
  6112. stats->rx_packets = pdev->stats.rx.unicast.num +
  6113. pdev->stats.rx.multicast.num +
  6114. pdev->stats.rx.bcast.num;
  6115. stats->rx_bytes = pdev->stats.rx.unicast.bytes +
  6116. pdev->stats.rx.multicast.bytes +
  6117. pdev->stats.rx.bcast.bytes;
  6118. stats->rx_errors = pdev->stats.err.desc_alloc_fail +
  6119. pdev->stats.err.ip_csum_err +
  6120. pdev->stats.err.tcp_udp_csum_err +
  6121. pdev->stats.rx.err.mic_err +
  6122. pdev->stats.rx.err.decrypt_err +
  6123. pdev->stats.err.rxdma_error +
  6124. pdev->stats.err.reo_error;
  6125. stats->rx_dropped = pdev->stats.dropped.msdu_not_done +
  6126. pdev->stats.dropped.mec +
  6127. pdev->stats.dropped.mesh_filter +
  6128. pdev->stats.dropped.wifi_parse +
  6129. pdev->stats.dropped.mon_rx_drop +
  6130. pdev->stats.dropped.mon_radiotap_update_err;
  6131. }
  6132. /**
  6133. * dp_get_device_stats() - get interface level packet stats
  6134. * @handle: device handle
  6135. * @stats: cdp network device stats structure
  6136. * @type: device type pdev/vdev
  6137. *
  6138. * Return: void
  6139. */
  6140. static void dp_get_device_stats(void *handle,
  6141. struct cdp_dev_stats *stats, uint8_t type)
  6142. {
  6143. switch (type) {
  6144. case UPDATE_VDEV_STATS:
  6145. dp_vdev_getstats(handle, stats);
  6146. break;
  6147. case UPDATE_PDEV_STATS:
  6148. dp_pdev_getstats(handle, stats);
  6149. break;
  6150. default:
  6151. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  6152. "apstats cannot be updated for this input "
  6153. "type %d", type);
  6154. break;
  6155. }
  6156. }
  6157. const
  6158. char *dp_srng_get_str_from_hal_ring_type(enum hal_ring_type ring_type)
  6159. {
  6160. switch (ring_type) {
  6161. case REO_DST:
  6162. return "Reo_dst";
  6163. case REO_EXCEPTION:
  6164. return "Reo_exception";
  6165. case REO_CMD:
  6166. return "Reo_cmd";
  6167. case REO_REINJECT:
  6168. return "Reo_reinject";
  6169. case REO_STATUS:
  6170. return "Reo_status";
  6171. case WBM2SW_RELEASE:
  6172. return "wbm2sw_release";
  6173. case TCL_DATA:
  6174. return "tcl_data";
  6175. case TCL_CMD:
  6176. return "tcl_cmd";
  6177. case TCL_STATUS:
  6178. return "tcl_status";
  6179. case SW2WBM_RELEASE:
  6180. return "sw2wbm_release";
  6181. case RXDMA_BUF:
  6182. return "Rxdma_buf";
  6183. case RXDMA_DST:
  6184. return "Rxdma_dst";
  6185. case RXDMA_MONITOR_BUF:
  6186. return "Rxdma_monitor_buf";
  6187. case RXDMA_MONITOR_DESC:
  6188. return "Rxdma_monitor_desc";
  6189. case RXDMA_MONITOR_STATUS:
  6190. return "Rxdma_monitor_status";
  6191. default:
  6192. dp_err("Invalid ring type");
  6193. break;
  6194. }
  6195. return "Invalid";
  6196. }
  6197. /*
  6198. * dp_print_napi_stats(): NAPI stats
  6199. * @soc - soc handle
  6200. */
  6201. void dp_print_napi_stats(struct dp_soc *soc)
  6202. {
  6203. hif_print_napi_stats(soc->hif_handle);
  6204. }
  6205. /**
  6206. * dp_txrx_host_stats_clr(): Reinitialize the txrx stats
  6207. * @vdev: DP_VDEV handle
  6208. *
  6209. * Return:void
  6210. */
  6211. static inline void
  6212. dp_txrx_host_stats_clr(struct dp_vdev *vdev)
  6213. {
  6214. struct dp_peer *peer = NULL;
  6215. if (!vdev || !vdev->pdev)
  6216. return;
  6217. DP_STATS_CLR(vdev->pdev);
  6218. DP_STATS_CLR(vdev->pdev->soc);
  6219. DP_STATS_CLR(vdev);
  6220. hif_clear_napi_stats(vdev->pdev->soc->hif_handle);
  6221. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  6222. if (!peer)
  6223. return;
  6224. DP_STATS_CLR(peer);
  6225. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  6226. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, vdev->pdev->soc,
  6227. &peer->stats, peer->peer_ids[0],
  6228. UPDATE_PEER_STATS, vdev->pdev->pdev_id);
  6229. #endif
  6230. }
  6231. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  6232. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, vdev->pdev->soc,
  6233. &vdev->stats, vdev->vdev_id,
  6234. UPDATE_VDEV_STATS, vdev->pdev->pdev_id);
  6235. #endif
  6236. }
  6237. /*
  6238. * dp_get_host_peer_stats()- function to print peer stats
  6239. * @pdev_handle: DP_PDEV handle
  6240. * @mac_addr: mac address of the peer
  6241. *
  6242. * Return: void
  6243. */
  6244. static void
  6245. dp_get_host_peer_stats(struct cdp_pdev *pdev_handle, char *mac_addr)
  6246. {
  6247. struct dp_peer *peer;
  6248. uint8_t local_id;
  6249. if (!mac_addr) {
  6250. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  6251. "Invalid MAC address\n");
  6252. return;
  6253. }
  6254. peer = (struct dp_peer *)dp_find_peer_by_addr(pdev_handle, mac_addr,
  6255. &local_id);
  6256. if (!peer) {
  6257. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  6258. "%s: Invalid peer\n", __func__);
  6259. return;
  6260. }
  6261. /* Making sure the peer is for the specific pdev */
  6262. if ((struct dp_pdev *)pdev_handle != peer->vdev->pdev) {
  6263. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  6264. "%s: Peer is not for this pdev\n", __func__);
  6265. return;
  6266. }
  6267. dp_print_peer_stats(peer);
  6268. dp_peer_rxtid_stats(peer, dp_rx_tid_stats_cb, NULL);
  6269. }
  6270. /**
  6271. * dp_txrx_stats_help() - Helper function for Txrx_Stats
  6272. *
  6273. * Return: None
  6274. */
  6275. static void dp_txrx_stats_help(void)
  6276. {
  6277. dp_info("Command: iwpriv wlan0 txrx_stats <stats_option> <mac_id>");
  6278. dp_info("stats_option:");
  6279. dp_info(" 1 -- HTT Tx Statistics");
  6280. dp_info(" 2 -- HTT Rx Statistics");
  6281. dp_info(" 3 -- HTT Tx HW Queue Statistics");
  6282. dp_info(" 4 -- HTT Tx HW Sched Statistics");
  6283. dp_info(" 5 -- HTT Error Statistics");
  6284. dp_info(" 6 -- HTT TQM Statistics");
  6285. dp_info(" 7 -- HTT TQM CMDQ Statistics");
  6286. dp_info(" 8 -- HTT TX_DE_CMN Statistics");
  6287. dp_info(" 9 -- HTT Tx Rate Statistics");
  6288. dp_info(" 10 -- HTT Rx Rate Statistics");
  6289. dp_info(" 11 -- HTT Peer Statistics");
  6290. dp_info(" 12 -- HTT Tx SelfGen Statistics");
  6291. dp_info(" 13 -- HTT Tx MU HWQ Statistics");
  6292. dp_info(" 14 -- HTT RING_IF_INFO Statistics");
  6293. dp_info(" 15 -- HTT SRNG Statistics");
  6294. dp_info(" 16 -- HTT SFM Info Statistics");
  6295. dp_info(" 17 -- HTT PDEV_TX_MU_MIMO_SCHED INFO Statistics");
  6296. dp_info(" 18 -- HTT Peer List Details");
  6297. dp_info(" 20 -- Clear Host Statistics");
  6298. dp_info(" 21 -- Host Rx Rate Statistics");
  6299. dp_info(" 22 -- Host Tx Rate Statistics");
  6300. dp_info(" 23 -- Host Tx Statistics");
  6301. dp_info(" 24 -- Host Rx Statistics");
  6302. dp_info(" 25 -- Host AST Statistics");
  6303. dp_info(" 26 -- Host SRNG PTR Statistics");
  6304. dp_info(" 27 -- Host Mon Statistics");
  6305. dp_info(" 28 -- Host REO Queue Statistics");
  6306. dp_info(" 29 -- Host Soc cfg param Statistics");
  6307. dp_info(" 30 -- Host pdev cfg param Statistics");
  6308. }
  6309. /**
  6310. * dp_print_host_stats()- Function to print the stats aggregated at host
  6311. * @vdev_handle: DP_VDEV handle
  6312. * @type: host stats type
  6313. *
  6314. * Return: 0 on success, print error message in case of failure
  6315. */
  6316. static int
  6317. dp_print_host_stats(struct cdp_vdev *vdev_handle,
  6318. struct cdp_txrx_stats_req *req)
  6319. {
  6320. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  6321. struct dp_pdev *pdev = (struct dp_pdev *)vdev->pdev;
  6322. enum cdp_host_txrx_stats type =
  6323. dp_stats_mapping_table[req->stats][STATS_HOST];
  6324. dp_aggregate_pdev_stats(pdev);
  6325. switch (type) {
  6326. case TXRX_CLEAR_STATS:
  6327. dp_txrx_host_stats_clr(vdev);
  6328. break;
  6329. case TXRX_RX_RATE_STATS:
  6330. dp_print_rx_rates(vdev);
  6331. break;
  6332. case TXRX_TX_RATE_STATS:
  6333. dp_print_tx_rates(vdev);
  6334. break;
  6335. case TXRX_TX_HOST_STATS:
  6336. dp_print_pdev_tx_stats(pdev);
  6337. dp_print_soc_tx_stats(pdev->soc);
  6338. break;
  6339. case TXRX_RX_HOST_STATS:
  6340. dp_print_pdev_rx_stats(pdev);
  6341. dp_print_soc_rx_stats(pdev->soc);
  6342. break;
  6343. case TXRX_AST_STATS:
  6344. dp_print_ast_stats(pdev->soc);
  6345. dp_print_peer_table(vdev);
  6346. break;
  6347. case TXRX_SRNG_PTR_STATS:
  6348. dp_print_ring_stats(pdev);
  6349. break;
  6350. case TXRX_RX_MON_STATS:
  6351. dp_print_pdev_rx_mon_stats(pdev);
  6352. break;
  6353. case TXRX_REO_QUEUE_STATS:
  6354. dp_get_host_peer_stats((struct cdp_pdev *)pdev, req->peer_addr);
  6355. break;
  6356. case TXRX_SOC_CFG_PARAMS:
  6357. dp_print_soc_cfg_params(pdev->soc);
  6358. break;
  6359. case TXRX_PDEV_CFG_PARAMS:
  6360. dp_print_pdev_cfg_params(pdev);
  6361. break;
  6362. case TXRX_NAPI_STATS:
  6363. dp_print_napi_stats(pdev->soc);
  6364. case TXRX_SOC_INTERRUPT_STATS:
  6365. dp_print_soc_interrupt_stats(pdev->soc);
  6366. break;
  6367. default:
  6368. dp_info("Wrong Input For TxRx Host Stats");
  6369. dp_txrx_stats_help();
  6370. break;
  6371. }
  6372. return 0;
  6373. }
  6374. /*
  6375. * dp_ppdu_ring_reset()- Reset PPDU Stats ring
  6376. * @pdev: DP_PDEV handle
  6377. *
  6378. * Return: void
  6379. */
  6380. static void
  6381. dp_ppdu_ring_reset(struct dp_pdev *pdev)
  6382. {
  6383. struct htt_rx_ring_tlv_filter htt_tlv_filter;
  6384. int mac_id;
  6385. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  6386. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  6387. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id,
  6388. pdev->pdev_id);
  6389. htt_h2t_rx_ring_cfg(pdev->soc->htt_handle, mac_for_pdev,
  6390. pdev->rxdma_mon_status_ring[mac_id].hal_srng,
  6391. RXDMA_MONITOR_STATUS, RX_BUFFER_SIZE, &htt_tlv_filter);
  6392. }
  6393. }
  6394. /*
  6395. * dp_ppdu_ring_cfg()- Configure PPDU Stats ring
  6396. * @pdev: DP_PDEV handle
  6397. *
  6398. * Return: void
  6399. */
  6400. static void
  6401. dp_ppdu_ring_cfg(struct dp_pdev *pdev)
  6402. {
  6403. struct htt_rx_ring_tlv_filter htt_tlv_filter = {0};
  6404. int mac_id;
  6405. htt_tlv_filter.mpdu_start = 1;
  6406. htt_tlv_filter.msdu_start = 0;
  6407. htt_tlv_filter.packet = 0;
  6408. htt_tlv_filter.msdu_end = 0;
  6409. htt_tlv_filter.mpdu_end = 0;
  6410. htt_tlv_filter.attention = 0;
  6411. htt_tlv_filter.ppdu_start = 1;
  6412. htt_tlv_filter.ppdu_end = 1;
  6413. htt_tlv_filter.ppdu_end_user_stats = 1;
  6414. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  6415. htt_tlv_filter.ppdu_end_status_done = 1;
  6416. htt_tlv_filter.enable_fp = 1;
  6417. htt_tlv_filter.enable_md = 0;
  6418. if (pdev->neighbour_peers_added &&
  6419. pdev->soc->hw_nac_monitor_support) {
  6420. htt_tlv_filter.enable_md = 1;
  6421. htt_tlv_filter.packet_header = 1;
  6422. }
  6423. if (pdev->mcopy_mode) {
  6424. htt_tlv_filter.packet_header = 1;
  6425. htt_tlv_filter.enable_mo = 1;
  6426. }
  6427. htt_tlv_filter.fp_mgmt_filter = FILTER_MGMT_ALL;
  6428. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_ALL;
  6429. htt_tlv_filter.fp_data_filter = FILTER_DATA_ALL;
  6430. htt_tlv_filter.mo_mgmt_filter = FILTER_MGMT_ALL;
  6431. htt_tlv_filter.mo_ctrl_filter = FILTER_CTRL_ALL;
  6432. htt_tlv_filter.mo_data_filter = FILTER_DATA_ALL;
  6433. if (pdev->neighbour_peers_added &&
  6434. pdev->soc->hw_nac_monitor_support)
  6435. htt_tlv_filter.md_data_filter = FILTER_DATA_ALL;
  6436. htt_tlv_filter.offset_valid = false;
  6437. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  6438. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id,
  6439. pdev->pdev_id);
  6440. htt_h2t_rx_ring_cfg(pdev->soc->htt_handle, mac_for_pdev,
  6441. pdev->rxdma_mon_status_ring[mac_id].hal_srng,
  6442. RXDMA_MONITOR_STATUS, RX_BUFFER_SIZE, &htt_tlv_filter);
  6443. }
  6444. }
  6445. /*
  6446. * is_ppdu_txrx_capture_enabled() - API to check both pktlog and debug_sniffer
  6447. * modes are enabled or not.
  6448. * @dp_pdev: dp pdev handle.
  6449. *
  6450. * Return: bool
  6451. */
  6452. static inline bool is_ppdu_txrx_capture_enabled(struct dp_pdev *pdev)
  6453. {
  6454. if (!pdev->pktlog_ppdu_stats && !pdev->tx_sniffer_enable &&
  6455. !pdev->mcopy_mode)
  6456. return true;
  6457. else
  6458. return false;
  6459. }
  6460. /*
  6461. *dp_set_bpr_enable() - API to enable/disable bpr feature
  6462. *@pdev_handle: DP_PDEV handle.
  6463. *@val: Provided value.
  6464. *
  6465. *Return: 0 for success. nonzero for failure.
  6466. */
  6467. static QDF_STATUS
  6468. dp_set_bpr_enable(struct cdp_pdev *pdev_handle, int val)
  6469. {
  6470. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6471. switch (val) {
  6472. case CDP_BPR_DISABLE:
  6473. pdev->bpr_enable = CDP_BPR_DISABLE;
  6474. if (!pdev->pktlog_ppdu_stats && !pdev->enhanced_stats_en &&
  6475. !pdev->tx_sniffer_enable && !pdev->mcopy_mode) {
  6476. dp_h2t_cfg_stats_msg_send(pdev, 0, pdev->pdev_id);
  6477. } else if (pdev->enhanced_stats_en &&
  6478. !pdev->tx_sniffer_enable && !pdev->mcopy_mode &&
  6479. !pdev->pktlog_ppdu_stats) {
  6480. dp_h2t_cfg_stats_msg_send(pdev,
  6481. DP_PPDU_STATS_CFG_ENH_STATS,
  6482. pdev->pdev_id);
  6483. }
  6484. break;
  6485. case CDP_BPR_ENABLE:
  6486. pdev->bpr_enable = CDP_BPR_ENABLE;
  6487. if (!pdev->enhanced_stats_en && !pdev->tx_sniffer_enable &&
  6488. !pdev->mcopy_mode && !pdev->pktlog_ppdu_stats) {
  6489. dp_h2t_cfg_stats_msg_send(pdev,
  6490. DP_PPDU_STATS_CFG_BPR,
  6491. pdev->pdev_id);
  6492. } else if (pdev->enhanced_stats_en &&
  6493. !pdev->tx_sniffer_enable && !pdev->mcopy_mode &&
  6494. !pdev->pktlog_ppdu_stats) {
  6495. dp_h2t_cfg_stats_msg_send(pdev,
  6496. DP_PPDU_STATS_CFG_BPR_ENH,
  6497. pdev->pdev_id);
  6498. } else if (pdev->pktlog_ppdu_stats) {
  6499. dp_h2t_cfg_stats_msg_send(pdev,
  6500. DP_PPDU_STATS_CFG_BPR_PKTLOG,
  6501. pdev->pdev_id);
  6502. }
  6503. break;
  6504. default:
  6505. break;
  6506. }
  6507. return QDF_STATUS_SUCCESS;
  6508. }
  6509. /*
  6510. * dp_pdev_tid_stats_ingress_inc
  6511. * @pdev: pdev handle
  6512. * @val: increase in value
  6513. *
  6514. * Return: void
  6515. */
  6516. static void
  6517. dp_pdev_tid_stats_ingress_inc(struct cdp_pdev *pdev, uint32_t val)
  6518. {
  6519. struct dp_pdev *dp_pdev = (struct dp_pdev *)pdev;
  6520. dp_pdev->stats.tid_stats.ingress_stack += val;
  6521. }
  6522. /*
  6523. * dp_pdev_tid_stats_osif_drop
  6524. * @pdev: pdev handle
  6525. * @val: increase in value
  6526. *
  6527. * Return: void
  6528. */
  6529. static void
  6530. dp_pdev_tid_stats_osif_drop(struct cdp_pdev *pdev, uint32_t val)
  6531. {
  6532. struct dp_pdev *dp_pdev = (struct dp_pdev *)pdev;
  6533. dp_pdev->stats.tid_stats.osif_drop += val;
  6534. }
  6535. /*
  6536. * dp_config_debug_sniffer()- API to enable/disable debug sniffer
  6537. * @pdev_handle: DP_PDEV handle
  6538. * @val: user provided value
  6539. *
  6540. * Return: 0 for success. nonzero for failure.
  6541. */
  6542. static QDF_STATUS
  6543. dp_config_debug_sniffer(struct cdp_pdev *pdev_handle, int val)
  6544. {
  6545. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6546. QDF_STATUS status = QDF_STATUS_SUCCESS;
  6547. if (pdev->mcopy_mode)
  6548. dp_reset_monitor_mode(pdev_handle);
  6549. switch (val) {
  6550. case 0:
  6551. pdev->tx_sniffer_enable = 0;
  6552. pdev->monitor_configured = false;
  6553. if (!pdev->pktlog_ppdu_stats && !pdev->enhanced_stats_en &&
  6554. !pdev->bpr_enable) {
  6555. dp_h2t_cfg_stats_msg_send(pdev, 0, pdev->pdev_id);
  6556. dp_ppdu_ring_reset(pdev);
  6557. } else if (pdev->enhanced_stats_en && !pdev->bpr_enable) {
  6558. dp_h2t_cfg_stats_msg_send(pdev,
  6559. DP_PPDU_STATS_CFG_ENH_STATS, pdev->pdev_id);
  6560. } else if (!pdev->enhanced_stats_en && pdev->bpr_enable) {
  6561. dp_h2t_cfg_stats_msg_send(pdev,
  6562. DP_PPDU_STATS_CFG_BPR_ENH,
  6563. pdev->pdev_id);
  6564. } else {
  6565. dp_h2t_cfg_stats_msg_send(pdev,
  6566. DP_PPDU_STATS_CFG_BPR,
  6567. pdev->pdev_id);
  6568. }
  6569. break;
  6570. case 1:
  6571. pdev->tx_sniffer_enable = 1;
  6572. pdev->monitor_configured = false;
  6573. if (!pdev->pktlog_ppdu_stats)
  6574. dp_h2t_cfg_stats_msg_send(pdev,
  6575. DP_PPDU_STATS_CFG_SNIFFER, pdev->pdev_id);
  6576. break;
  6577. case 2:
  6578. if (pdev->monitor_vdev) {
  6579. status = QDF_STATUS_E_RESOURCES;
  6580. break;
  6581. }
  6582. pdev->mcopy_mode = 1;
  6583. dp_pdev_configure_monitor_rings(pdev);
  6584. pdev->monitor_configured = true;
  6585. pdev->tx_sniffer_enable = 0;
  6586. if (!pdev->pktlog_ppdu_stats)
  6587. dp_h2t_cfg_stats_msg_send(pdev,
  6588. DP_PPDU_STATS_CFG_SNIFFER, pdev->pdev_id);
  6589. break;
  6590. default:
  6591. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  6592. "Invalid value");
  6593. break;
  6594. }
  6595. return status;
  6596. }
  6597. /*
  6598. * dp_enable_enhanced_stats()- API to enable enhanced statistcs
  6599. * @pdev_handle: DP_PDEV handle
  6600. *
  6601. * Return: void
  6602. */
  6603. static void
  6604. dp_enable_enhanced_stats(struct cdp_pdev *pdev_handle)
  6605. {
  6606. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6607. if (pdev->enhanced_stats_en == 0)
  6608. dp_cal_client_timer_start(pdev->cal_client_ctx);
  6609. pdev->enhanced_stats_en = 1;
  6610. if (!pdev->mcopy_mode && !pdev->neighbour_peers_added &&
  6611. !pdev->monitor_vdev)
  6612. dp_ppdu_ring_cfg(pdev);
  6613. if (is_ppdu_txrx_capture_enabled(pdev) && !pdev->bpr_enable) {
  6614. dp_h2t_cfg_stats_msg_send(pdev, DP_PPDU_STATS_CFG_ENH_STATS, pdev->pdev_id);
  6615. } else if (is_ppdu_txrx_capture_enabled(pdev) && pdev->bpr_enable) {
  6616. dp_h2t_cfg_stats_msg_send(pdev,
  6617. DP_PPDU_STATS_CFG_BPR_ENH,
  6618. pdev->pdev_id);
  6619. }
  6620. }
  6621. /*
  6622. * dp_disable_enhanced_stats()- API to disable enhanced statistcs
  6623. * @pdev_handle: DP_PDEV handle
  6624. *
  6625. * Return: void
  6626. */
  6627. static void
  6628. dp_disable_enhanced_stats(struct cdp_pdev *pdev_handle)
  6629. {
  6630. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6631. if (pdev->enhanced_stats_en == 1)
  6632. dp_cal_client_timer_stop(pdev->cal_client_ctx);
  6633. pdev->enhanced_stats_en = 0;
  6634. if (is_ppdu_txrx_capture_enabled(pdev) && !pdev->bpr_enable) {
  6635. dp_h2t_cfg_stats_msg_send(pdev, 0, pdev->pdev_id);
  6636. } else if (is_ppdu_txrx_capture_enabled(pdev) && pdev->bpr_enable) {
  6637. dp_h2t_cfg_stats_msg_send(pdev,
  6638. DP_PPDU_STATS_CFG_BPR,
  6639. pdev->pdev_id);
  6640. }
  6641. if (!pdev->mcopy_mode && !pdev->neighbour_peers_added &&
  6642. !pdev->monitor_vdev)
  6643. dp_ppdu_ring_reset(pdev);
  6644. }
  6645. /*
  6646. * dp_get_fw_peer_stats()- function to print peer stats
  6647. * @pdev_handle: DP_PDEV handle
  6648. * @mac_addr: mac address of the peer
  6649. * @cap: Type of htt stats requested
  6650. * @is_wait: if set, wait on completion from firmware response
  6651. *
  6652. * Currently Supporting only MAC ID based requests Only
  6653. * 1: HTT_PEER_STATS_REQ_MODE_NO_QUERY
  6654. * 2: HTT_PEER_STATS_REQ_MODE_QUERY_TQM
  6655. * 3: HTT_PEER_STATS_REQ_MODE_FLUSH_TQM
  6656. *
  6657. * Return: void
  6658. */
  6659. static void
  6660. dp_get_fw_peer_stats(struct cdp_pdev *pdev_handle, uint8_t *mac_addr,
  6661. uint32_t cap, uint32_t is_wait)
  6662. {
  6663. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6664. int i;
  6665. uint32_t config_param0 = 0;
  6666. uint32_t config_param1 = 0;
  6667. uint32_t config_param2 = 0;
  6668. uint32_t config_param3 = 0;
  6669. HTT_DBG_EXT_STATS_PEER_INFO_IS_MAC_ADDR_SET(config_param0, 1);
  6670. config_param0 |= (1 << (cap + 1));
  6671. for (i = 0; i < HTT_PEER_STATS_MAX_TLV; i++) {
  6672. config_param1 |= (1 << i);
  6673. }
  6674. config_param2 |= (mac_addr[0] & 0x000000ff);
  6675. config_param2 |= ((mac_addr[1] << 8) & 0x0000ff00);
  6676. config_param2 |= ((mac_addr[2] << 16) & 0x00ff0000);
  6677. config_param2 |= ((mac_addr[3] << 24) & 0xff000000);
  6678. config_param3 |= (mac_addr[4] & 0x000000ff);
  6679. config_param3 |= ((mac_addr[5] << 8) & 0x0000ff00);
  6680. if (is_wait) {
  6681. qdf_event_reset(&pdev->fw_peer_stats_event);
  6682. dp_h2t_ext_stats_msg_send(pdev, HTT_DBG_EXT_STATS_PEER_INFO,
  6683. config_param0, config_param1,
  6684. config_param2, config_param3,
  6685. 0, 1, 0);
  6686. qdf_wait_single_event(&pdev->fw_peer_stats_event,
  6687. DP_FW_PEER_STATS_CMP_TIMEOUT_MSEC);
  6688. } else {
  6689. dp_h2t_ext_stats_msg_send(pdev, HTT_DBG_EXT_STATS_PEER_INFO,
  6690. config_param0, config_param1,
  6691. config_param2, config_param3,
  6692. 0, 0, 0);
  6693. }
  6694. }
  6695. /* This struct definition will be removed from here
  6696. * once it get added in FW headers*/
  6697. struct httstats_cmd_req {
  6698. uint32_t config_param0;
  6699. uint32_t config_param1;
  6700. uint32_t config_param2;
  6701. uint32_t config_param3;
  6702. int cookie;
  6703. u_int8_t stats_id;
  6704. };
  6705. /*
  6706. * dp_get_htt_stats: function to process the httstas request
  6707. * @pdev_handle: DP pdev handle
  6708. * @data: pointer to request data
  6709. * @data_len: length for request data
  6710. *
  6711. * return: void
  6712. */
  6713. static void
  6714. dp_get_htt_stats(struct cdp_pdev *pdev_handle, void *data, uint32_t data_len)
  6715. {
  6716. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6717. struct httstats_cmd_req *req = (struct httstats_cmd_req *)data;
  6718. QDF_ASSERT(data_len == sizeof(struct httstats_cmd_req));
  6719. dp_h2t_ext_stats_msg_send(pdev, req->stats_id,
  6720. req->config_param0, req->config_param1,
  6721. req->config_param2, req->config_param3,
  6722. req->cookie, 0, 0);
  6723. }
  6724. /*
  6725. * dp_set_pdev_param: function to set parameters in pdev
  6726. * @pdev_handle: DP pdev handle
  6727. * @param: parameter type to be set
  6728. * @val: value of parameter to be set
  6729. *
  6730. * Return: 0 for success. nonzero for failure.
  6731. */
  6732. static QDF_STATUS dp_set_pdev_param(struct cdp_pdev *pdev_handle,
  6733. enum cdp_pdev_param_type param,
  6734. uint32_t val)
  6735. {
  6736. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6737. switch (param) {
  6738. case CDP_CONFIG_DEBUG_SNIFFER:
  6739. return dp_config_debug_sniffer(pdev_handle, val);
  6740. case CDP_CONFIG_BPR_ENABLE:
  6741. return dp_set_bpr_enable(pdev_handle, val);
  6742. case CDP_CONFIG_PRIMARY_RADIO:
  6743. pdev->is_primary = val;
  6744. break;
  6745. case CDP_CONFIG_CAPTURE_LATENCY:
  6746. if (val == 1)
  6747. pdev->latency_capture_enable = true;
  6748. else
  6749. pdev->latency_capture_enable = false;
  6750. break;
  6751. case CDP_INGRESS_STATS:
  6752. dp_pdev_tid_stats_ingress_inc(pdev_handle, val);
  6753. break;
  6754. case CDP_OSIF_DROP:
  6755. dp_pdev_tid_stats_osif_drop(pdev_handle, val);
  6756. break;
  6757. case CDP_CONFIG_ENH_RX_CAPTURE:
  6758. return dp_config_enh_rx_capture(pdev_handle, val);
  6759. case CDP_CONFIG_TX_CAPTURE:
  6760. return dp_config_enh_tx_capture(pdev_handle, val);
  6761. default:
  6762. return QDF_STATUS_E_INVAL;
  6763. }
  6764. return QDF_STATUS_SUCCESS;
  6765. }
  6766. /*
  6767. * dp_calculate_delay_stats: function to get rx delay stats
  6768. * @vdev_handle: DP vdev handle
  6769. * @nbuf: skb
  6770. *
  6771. * Return: void
  6772. */
  6773. static void dp_calculate_delay_stats(struct cdp_vdev *vdev_handle,
  6774. qdf_nbuf_t nbuf)
  6775. {
  6776. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  6777. dp_rx_compute_delay(vdev, nbuf);
  6778. }
  6779. /*
  6780. * dp_get_vdev_param: function to get parameters from vdev
  6781. * @param: parameter type to get value
  6782. *
  6783. * return: void
  6784. */
  6785. static uint32_t dp_get_vdev_param(struct cdp_vdev *vdev_handle,
  6786. enum cdp_vdev_param_type param)
  6787. {
  6788. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  6789. uint32_t val;
  6790. switch (param) {
  6791. case CDP_ENABLE_WDS:
  6792. val = vdev->wds_enabled;
  6793. break;
  6794. case CDP_ENABLE_MEC:
  6795. val = vdev->mec_enabled;
  6796. break;
  6797. case CDP_ENABLE_DA_WAR:
  6798. val = vdev->pdev->soc->da_war_enabled;
  6799. break;
  6800. default:
  6801. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  6802. "param value %d is wrong\n",
  6803. param);
  6804. val = -1;
  6805. break;
  6806. }
  6807. return val;
  6808. }
  6809. /*
  6810. * dp_set_vdev_param: function to set parameters in vdev
  6811. * @param: parameter type to be set
  6812. * @val: value of parameter to be set
  6813. *
  6814. * return: void
  6815. */
  6816. static void dp_set_vdev_param(struct cdp_vdev *vdev_handle,
  6817. enum cdp_vdev_param_type param, uint32_t val)
  6818. {
  6819. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  6820. switch (param) {
  6821. case CDP_ENABLE_WDS:
  6822. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  6823. "wds_enable %d for vdev(%pK) id(%d)\n",
  6824. val, vdev, vdev->vdev_id);
  6825. vdev->wds_enabled = val;
  6826. break;
  6827. case CDP_ENABLE_MEC:
  6828. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  6829. "mec_enable %d for vdev(%pK) id(%d)\n",
  6830. val, vdev, vdev->vdev_id);
  6831. vdev->mec_enabled = val;
  6832. break;
  6833. case CDP_ENABLE_DA_WAR:
  6834. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  6835. "da_war_enable %d for vdev(%pK) id(%d)\n",
  6836. val, vdev, vdev->vdev_id);
  6837. vdev->pdev->soc->da_war_enabled = val;
  6838. dp_wds_flush_ast_table_wifi3(((struct cdp_soc_t *)
  6839. vdev->pdev->soc));
  6840. break;
  6841. case CDP_ENABLE_NAWDS:
  6842. vdev->nawds_enabled = val;
  6843. break;
  6844. case CDP_ENABLE_MCAST_EN:
  6845. vdev->mcast_enhancement_en = val;
  6846. break;
  6847. case CDP_ENABLE_PROXYSTA:
  6848. vdev->proxysta_vdev = val;
  6849. break;
  6850. case CDP_UPDATE_TDLS_FLAGS:
  6851. vdev->tdls_link_connected = val;
  6852. break;
  6853. case CDP_CFG_WDS_AGING_TIMER:
  6854. if (val == 0)
  6855. qdf_timer_stop(&vdev->pdev->soc->ast_aging_timer);
  6856. else if (val != vdev->wds_aging_timer_val)
  6857. qdf_timer_mod(&vdev->pdev->soc->ast_aging_timer, val);
  6858. vdev->wds_aging_timer_val = val;
  6859. break;
  6860. case CDP_ENABLE_AP_BRIDGE:
  6861. if (wlan_op_mode_sta != vdev->opmode)
  6862. vdev->ap_bridge_enabled = val;
  6863. else
  6864. vdev->ap_bridge_enabled = false;
  6865. break;
  6866. case CDP_ENABLE_CIPHER:
  6867. vdev->sec_type = val;
  6868. break;
  6869. case CDP_ENABLE_QWRAP_ISOLATION:
  6870. vdev->isolation_vdev = val;
  6871. break;
  6872. case CDP_UPDATE_MULTIPASS:
  6873. vdev->multipass_en = val;
  6874. break;
  6875. default:
  6876. break;
  6877. }
  6878. dp_tx_vdev_update_search_flags(vdev);
  6879. }
  6880. /**
  6881. * dp_peer_set_nawds: set nawds bit in peer
  6882. * @peer_handle: pointer to peer
  6883. * @value: enable/disable nawds
  6884. *
  6885. * return: void
  6886. */
  6887. static void dp_peer_set_nawds(struct cdp_peer *peer_handle, uint8_t value)
  6888. {
  6889. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  6890. peer->nawds_enabled = value;
  6891. }
  6892. /**
  6893. * dp_peer_set_tx_capture_enabled: Set tx_cap_enabled bit in peer
  6894. * @peer_handle: Peer handle
  6895. * @value: Enable/disable setting for tx_cap_enabled
  6896. *
  6897. * Return: None
  6898. */
  6899. static void
  6900. dp_peer_set_tx_capture_enabled(struct cdp_peer *peer_handle, bool value)
  6901. {
  6902. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  6903. peer->tx_cap_enabled = value;
  6904. }
  6905. /**
  6906. * dp_peer_set_rx_capture_enabled: Set rx_cap_enabled bit in peer
  6907. * @peer_handle: Peer handle
  6908. * @value: Enable/disable setting for rx_cap_enabled
  6909. *
  6910. * Return: None
  6911. */
  6912. static void
  6913. dp_peer_set_rx_capture_enabled(struct cdp_peer *peer_handle, bool value)
  6914. {
  6915. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  6916. peer->rx_cap_enabled = value;
  6917. }
  6918. /**
  6919. * dp_peer_update_pkt_capture_params: Set Rx & Tx Capture flags for a peer
  6920. * @is_rx_pkt_cap_enable: enable/disable Rx packet capture in monitor mode
  6921. * @is_tx_pkt_cap_enable: enable/disable Tx packet capture in monitor mode
  6922. * @peer_mac: MAC address for which the above need to be enabled/disabled
  6923. *
  6924. * Return: Success if Rx & Tx capture is enabled for peer, false otherwise
  6925. */
  6926. QDF_STATUS
  6927. dp_peer_update_pkt_capture_params(struct cdp_pdev *pdev,
  6928. bool is_rx_pkt_cap_enable,
  6929. bool is_tx_pkt_cap_enable,
  6930. uint8_t *peer_mac)
  6931. {
  6932. struct dp_peer *peer;
  6933. uint8_t local_id;
  6934. peer = (struct dp_peer *)dp_find_peer_by_addr(pdev,
  6935. peer_mac, &local_id);
  6936. if (!peer) {
  6937. dp_err("Invalid Peer");
  6938. return QDF_STATUS_E_FAILURE;
  6939. }
  6940. dp_peer_set_rx_capture_enabled((struct cdp_peer *)peer,
  6941. is_rx_pkt_cap_enable);
  6942. dp_peer_set_tx_capture_enabled((struct cdp_peer *)peer,
  6943. is_tx_pkt_cap_enable);
  6944. return QDF_STATUS_SUCCESS;
  6945. }
  6946. /*
  6947. * dp_set_vdev_dscp_tid_map_wifi3(): Update Map ID selected for particular vdev
  6948. * @vdev_handle: DP_VDEV handle
  6949. * @map_id:ID of map that needs to be updated
  6950. *
  6951. * Return: void
  6952. */
  6953. static void dp_set_vdev_dscp_tid_map_wifi3(struct cdp_vdev *vdev_handle,
  6954. uint8_t map_id)
  6955. {
  6956. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  6957. vdev->dscp_tid_map_id = map_id;
  6958. return;
  6959. }
  6960. #ifdef DP_RATETABLE_SUPPORT
  6961. static int dp_txrx_get_ratekbps(int preamb, int mcs,
  6962. int htflag, int gintval)
  6963. {
  6964. uint32_t rix;
  6965. uint16_t ratecode;
  6966. return dp_getrateindex((uint32_t)gintval, (uint16_t)mcs, 1,
  6967. (uint8_t)preamb, 1, &rix, &ratecode);
  6968. }
  6969. #else
  6970. static int dp_txrx_get_ratekbps(int preamb, int mcs,
  6971. int htflag, int gintval)
  6972. {
  6973. return 0;
  6974. }
  6975. #endif
  6976. /* dp_txrx_get_pdev_stats - Returns cdp_pdev_stats
  6977. * @peer_handle: DP pdev handle
  6978. *
  6979. * return : cdp_pdev_stats pointer
  6980. */
  6981. static struct cdp_pdev_stats*
  6982. dp_txrx_get_pdev_stats(struct cdp_pdev *pdev_handle)
  6983. {
  6984. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6985. dp_aggregate_pdev_stats(pdev);
  6986. return &pdev->stats;
  6987. }
  6988. /* dp_txrx_update_vdev_me_stats(): Update vdev ME stats sent from CDP
  6989. * @vdev_handle: DP vdev handle
  6990. * @buf: buffer containing specific stats structure
  6991. *
  6992. * Returns: void
  6993. */
  6994. static void dp_txrx_update_vdev_me_stats(struct cdp_vdev *vdev_handle,
  6995. void *buf)
  6996. {
  6997. struct dp_vdev *vdev = NULL;
  6998. struct cdp_tx_ingress_stats *host_stats = NULL;
  6999. if (!vdev_handle) {
  7000. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7001. "Invalid vdev handle");
  7002. return;
  7003. }
  7004. vdev = (struct dp_vdev *)vdev_handle;
  7005. if (!buf) {
  7006. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7007. "Invalid host stats buf");
  7008. return;
  7009. }
  7010. host_stats = (struct cdp_tx_ingress_stats *)buf;
  7011. DP_STATS_INC_PKT(vdev, tx_i.mcast_en.mcast_pkt,
  7012. host_stats->mcast_en.mcast_pkt.num,
  7013. host_stats->mcast_en.mcast_pkt.bytes);
  7014. DP_STATS_INC(vdev, tx_i.mcast_en.dropped_map_error,
  7015. host_stats->mcast_en.dropped_map_error);
  7016. DP_STATS_INC(vdev, tx_i.mcast_en.dropped_self_mac,
  7017. host_stats->mcast_en.dropped_self_mac);
  7018. DP_STATS_INC(vdev, tx_i.mcast_en.dropped_send_fail,
  7019. host_stats->mcast_en.dropped_send_fail);
  7020. DP_STATS_INC(vdev, tx_i.mcast_en.ucast,
  7021. host_stats->mcast_en.ucast);
  7022. DP_STATS_INC(vdev, tx_i.mcast_en.fail_seg_alloc,
  7023. host_stats->mcast_en.fail_seg_alloc);
  7024. DP_STATS_INC(vdev, tx_i.mcast_en.clone_fail,
  7025. host_stats->mcast_en.clone_fail);
  7026. }
  7027. /* dp_txrx_update_vdev_host_stats(): Update stats sent through CDP
  7028. * @vdev_handle: DP vdev handle
  7029. * @buf: buffer containing specific stats structure
  7030. * @stats_id: stats type
  7031. *
  7032. * Returns: void
  7033. */
  7034. static void dp_txrx_update_vdev_host_stats(struct cdp_vdev *vdev_handle,
  7035. void *buf,
  7036. uint16_t stats_id)
  7037. {
  7038. switch (stats_id) {
  7039. case DP_VDEV_STATS_PKT_CNT_ONLY:
  7040. break;
  7041. case DP_VDEV_STATS_TX_ME:
  7042. dp_txrx_update_vdev_me_stats(vdev_handle, buf);
  7043. break;
  7044. default:
  7045. qdf_info("Invalid stats_id %d", stats_id);
  7046. break;
  7047. }
  7048. }
  7049. /* dp_txrx_get_peer_stats - will return cdp_peer_stats
  7050. * @peer_handle: DP_PEER handle
  7051. *
  7052. * return : cdp_peer_stats pointer
  7053. */
  7054. static struct cdp_peer_stats*
  7055. dp_txrx_get_peer_stats(struct cdp_peer *peer_handle)
  7056. {
  7057. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  7058. qdf_assert(peer);
  7059. return &peer->stats;
  7060. }
  7061. /* dp_txrx_reset_peer_stats - reset cdp_peer_stats for particular peer
  7062. * @peer_handle: DP_PEER handle
  7063. *
  7064. * return : void
  7065. */
  7066. static void dp_txrx_reset_peer_stats(struct cdp_peer *peer_handle)
  7067. {
  7068. struct dp_peer *peer = (struct dp_peer *)peer_handle;
  7069. qdf_assert(peer);
  7070. qdf_mem_zero(&peer->stats, sizeof(peer->stats));
  7071. }
  7072. /* dp_txrx_get_vdev_stats - Update buffer with cdp_vdev_stats
  7073. * @vdev_handle: DP_VDEV handle
  7074. * @buf: buffer for vdev stats
  7075. *
  7076. * return : int
  7077. */
  7078. static int dp_txrx_get_vdev_stats(struct cdp_vdev *vdev_handle, void *buf,
  7079. bool is_aggregate)
  7080. {
  7081. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  7082. struct cdp_vdev_stats *vdev_stats;
  7083. struct dp_pdev *pdev;
  7084. struct dp_soc *soc;
  7085. if (!vdev)
  7086. return 1;
  7087. pdev = vdev->pdev;
  7088. if (!pdev)
  7089. return 1;
  7090. soc = pdev->soc;
  7091. vdev_stats = (struct cdp_vdev_stats *)buf;
  7092. if (is_aggregate) {
  7093. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  7094. dp_aggregate_vdev_stats(vdev, buf);
  7095. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  7096. } else {
  7097. qdf_mem_copy(vdev_stats, &vdev->stats, sizeof(vdev->stats));
  7098. }
  7099. return 0;
  7100. }
  7101. /*
  7102. * dp_get_total_per(): get total per
  7103. * @pdev_handle: DP_PDEV handle
  7104. *
  7105. * Return: % error rate using retries per packet and success packets
  7106. */
  7107. static int dp_get_total_per(struct cdp_pdev *pdev_handle)
  7108. {
  7109. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  7110. dp_aggregate_pdev_stats(pdev);
  7111. if ((pdev->stats.tx.tx_success.num + pdev->stats.tx.retries) == 0)
  7112. return 0;
  7113. return ((pdev->stats.tx.retries * 100) /
  7114. ((pdev->stats.tx.tx_success.num) + (pdev->stats.tx.retries)));
  7115. }
  7116. /*
  7117. * dp_txrx_stats_publish(): publish pdev stats into a buffer
  7118. * @pdev_handle: DP_PDEV handle
  7119. * @buf: to hold pdev_stats
  7120. *
  7121. * Return: int
  7122. */
  7123. static int
  7124. dp_txrx_stats_publish(struct cdp_pdev *pdev_handle, struct cdp_stats_extd *buf)
  7125. {
  7126. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  7127. struct cdp_pdev_stats *buffer = (struct cdp_pdev_stats *) buf;
  7128. struct cdp_txrx_stats_req req = {0,};
  7129. dp_aggregate_pdev_stats(pdev);
  7130. req.stats = (enum cdp_stats)HTT_DBG_EXT_STATS_PDEV_TX;
  7131. req.cookie_val = 1;
  7132. dp_h2t_ext_stats_msg_send(pdev, req.stats, req.param0,
  7133. req.param1, req.param2, req.param3, 0,
  7134. req.cookie_val, 0);
  7135. msleep(DP_MAX_SLEEP_TIME);
  7136. req.stats = (enum cdp_stats)HTT_DBG_EXT_STATS_PDEV_RX;
  7137. req.cookie_val = 1;
  7138. dp_h2t_ext_stats_msg_send(pdev, req.stats, req.param0,
  7139. req.param1, req.param2, req.param3, 0,
  7140. req.cookie_val, 0);
  7141. msleep(DP_MAX_SLEEP_TIME);
  7142. qdf_mem_copy(buffer, &pdev->stats, sizeof(pdev->stats));
  7143. return TXRX_STATS_LEVEL;
  7144. }
  7145. /**
  7146. * dp_set_pdev_dscp_tid_map_wifi3(): update dscp tid map in pdev
  7147. * @pdev: DP_PDEV handle
  7148. * @map_id: ID of map that needs to be updated
  7149. * @tos: index value in map
  7150. * @tid: tid value passed by the user
  7151. *
  7152. * Return: void
  7153. */
  7154. static void dp_set_pdev_dscp_tid_map_wifi3(struct cdp_pdev *pdev_handle,
  7155. uint8_t map_id, uint8_t tos, uint8_t tid)
  7156. {
  7157. uint8_t dscp;
  7158. struct dp_pdev *pdev = (struct dp_pdev *) pdev_handle;
  7159. struct dp_soc *soc = pdev->soc;
  7160. if (!soc)
  7161. return;
  7162. dscp = (tos >> DP_IP_DSCP_SHIFT) & DP_IP_DSCP_MASK;
  7163. pdev->dscp_tid_map[map_id][dscp] = tid;
  7164. if (map_id < soc->num_hw_dscp_tid_map)
  7165. hal_tx_update_dscp_tid(soc->hal_soc, tid,
  7166. map_id, dscp);
  7167. return;
  7168. }
  7169. /**
  7170. * dp_hmmc_tid_override_en_wifi3(): Function to enable hmmc tid override.
  7171. * @pdev_handle: pdev handle
  7172. * @val: hmmc-dscp flag value
  7173. *
  7174. * Return: void
  7175. */
  7176. static void dp_hmmc_tid_override_en_wifi3(struct cdp_pdev *pdev_handle,
  7177. bool val)
  7178. {
  7179. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  7180. pdev->hmmc_tid_override_en = val;
  7181. }
  7182. /**
  7183. * dp_set_hmmc_tid_val_wifi3(): Function to set hmmc tid value.
  7184. * @pdev_handle: pdev handle
  7185. * @tid: tid value
  7186. *
  7187. * Return: void
  7188. */
  7189. static void dp_set_hmmc_tid_val_wifi3(struct cdp_pdev *pdev_handle,
  7190. uint8_t tid)
  7191. {
  7192. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  7193. pdev->hmmc_tid = tid;
  7194. }
  7195. /**
  7196. * dp_fw_stats_process(): Process TxRX FW stats request
  7197. * @vdev_handle: DP VDEV handle
  7198. * @req: stats request
  7199. *
  7200. * return: int
  7201. */
  7202. static int dp_fw_stats_process(struct cdp_vdev *vdev_handle,
  7203. struct cdp_txrx_stats_req *req)
  7204. {
  7205. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  7206. struct dp_pdev *pdev = NULL;
  7207. uint32_t stats = req->stats;
  7208. uint8_t mac_id = req->mac_id;
  7209. if (!vdev) {
  7210. DP_TRACE(NONE, "VDEV not found");
  7211. return 1;
  7212. }
  7213. pdev = vdev->pdev;
  7214. /*
  7215. * For HTT_DBG_EXT_STATS_RESET command, FW need to config
  7216. * from param0 to param3 according to below rule:
  7217. *
  7218. * PARAM:
  7219. * - config_param0 : start_offset (stats type)
  7220. * - config_param1 : stats bmask from start offset
  7221. * - config_param2 : stats bmask from start offset + 32
  7222. * - config_param3 : stats bmask from start offset + 64
  7223. */
  7224. if (req->stats == CDP_TXRX_STATS_0) {
  7225. req->param0 = HTT_DBG_EXT_STATS_PDEV_TX;
  7226. req->param1 = 0xFFFFFFFF;
  7227. req->param2 = 0xFFFFFFFF;
  7228. req->param3 = 0xFFFFFFFF;
  7229. } else if (req->stats == (uint8_t)HTT_DBG_EXT_STATS_PDEV_TX_MU) {
  7230. req->param0 = HTT_DBG_EXT_STATS_SET_VDEV_MASK(vdev->vdev_id);
  7231. }
  7232. return dp_h2t_ext_stats_msg_send(pdev, stats, req->param0,
  7233. req->param1, req->param2, req->param3,
  7234. 0, 0, mac_id);
  7235. }
  7236. /**
  7237. * dp_txrx_stats_request - function to map to firmware and host stats
  7238. * @soc: soc handle
  7239. * @vdev_id: virtual device ID
  7240. * @req: stats request
  7241. *
  7242. * Return: QDF_STATUS
  7243. */
  7244. static
  7245. QDF_STATUS dp_txrx_stats_request(struct cdp_soc_t *soc_handle,
  7246. uint8_t vdev_id,
  7247. struct cdp_txrx_stats_req *req)
  7248. {
  7249. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_handle);
  7250. struct cdp_vdev *vdev;
  7251. int host_stats;
  7252. int fw_stats;
  7253. enum cdp_stats stats;
  7254. int num_stats;
  7255. vdev = dp_vdev_to_cdp_vdev(dp_get_vdev_from_soc_vdev_id_wifi3(soc,
  7256. vdev_id));
  7257. if (!vdev || !req) {
  7258. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7259. "Invalid vdev/req instance");
  7260. return QDF_STATUS_E_INVAL;
  7261. }
  7262. if (req->mac_id >= WLAN_CFG_MAC_PER_TARGET) {
  7263. dp_err("Invalid mac id request");
  7264. return QDF_STATUS_E_INVAL;
  7265. }
  7266. stats = req->stats;
  7267. if (stats >= CDP_TXRX_MAX_STATS)
  7268. return QDF_STATUS_E_INVAL;
  7269. /*
  7270. * DP_CURR_FW_STATS_AVAIL: no of FW stats currently available
  7271. * has to be updated if new FW HTT stats added
  7272. */
  7273. if (stats > CDP_TXRX_STATS_HTT_MAX)
  7274. stats = stats + DP_CURR_FW_STATS_AVAIL - DP_HTT_DBG_EXT_STATS_MAX;
  7275. num_stats = QDF_ARRAY_SIZE(dp_stats_mapping_table);
  7276. if (stats >= num_stats) {
  7277. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7278. "%s: Invalid stats option: %d", __func__, stats);
  7279. return QDF_STATUS_E_INVAL;
  7280. }
  7281. req->stats = stats;
  7282. fw_stats = dp_stats_mapping_table[stats][STATS_FW];
  7283. host_stats = dp_stats_mapping_table[stats][STATS_HOST];
  7284. dp_info("stats: %u fw_stats_type: %d host_stats: %d",
  7285. stats, fw_stats, host_stats);
  7286. if (fw_stats != TXRX_FW_STATS_INVALID) {
  7287. /* update request with FW stats type */
  7288. req->stats = fw_stats;
  7289. return dp_fw_stats_process(vdev, req);
  7290. }
  7291. if ((host_stats != TXRX_HOST_STATS_INVALID) &&
  7292. (host_stats <= TXRX_HOST_STATS_MAX))
  7293. return dp_print_host_stats(vdev, req);
  7294. else
  7295. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  7296. "Wrong Input for TxRx Stats");
  7297. return QDF_STATUS_SUCCESS;
  7298. }
  7299. /*
  7300. * dp_txrx_dump_stats() - Dump statistics
  7301. * @value - Statistics option
  7302. */
  7303. static QDF_STATUS dp_txrx_dump_stats(void *psoc, uint16_t value,
  7304. enum qdf_stats_verbosity_level level)
  7305. {
  7306. struct dp_soc *soc =
  7307. (struct dp_soc *)psoc;
  7308. QDF_STATUS status = QDF_STATUS_SUCCESS;
  7309. if (!soc) {
  7310. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7311. "%s: soc is NULL", __func__);
  7312. return QDF_STATUS_E_INVAL;
  7313. }
  7314. switch (value) {
  7315. case CDP_TXRX_PATH_STATS:
  7316. dp_txrx_path_stats(soc);
  7317. dp_print_soc_interrupt_stats(soc);
  7318. break;
  7319. case CDP_RX_RING_STATS:
  7320. dp_print_per_ring_stats(soc);
  7321. break;
  7322. case CDP_TXRX_TSO_STATS:
  7323. dp_print_tso_stats(soc, level);
  7324. break;
  7325. case CDP_DUMP_TX_FLOW_POOL_INFO:
  7326. if (level == QDF_STATS_VERBOSITY_LEVEL_HIGH)
  7327. cdp_dump_flow_pool_info((struct cdp_soc_t *)soc);
  7328. break;
  7329. case CDP_DP_NAPI_STATS:
  7330. dp_print_napi_stats(soc);
  7331. break;
  7332. case CDP_TXRX_DESC_STATS:
  7333. /* TODO: NOT IMPLEMENTED */
  7334. break;
  7335. default:
  7336. status = QDF_STATUS_E_INVAL;
  7337. break;
  7338. }
  7339. return status;
  7340. }
  7341. /**
  7342. * dp_txrx_clear_dump_stats() - clear dumpStats
  7343. * @soc- soc handle
  7344. * @value - stats option
  7345. *
  7346. * Return: 0 - Success, non-zero - failure
  7347. */
  7348. static
  7349. QDF_STATUS dp_txrx_clear_dump_stats(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  7350. uint8_t value)
  7351. {
  7352. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  7353. QDF_STATUS status = QDF_STATUS_SUCCESS;
  7354. if (!soc) {
  7355. dp_err("%s: soc is NULL", __func__);
  7356. return QDF_STATUS_E_INVAL;
  7357. }
  7358. switch (value) {
  7359. case CDP_TXRX_TSO_STATS:
  7360. dp_txrx_clear_tso_stats(soc);
  7361. break;
  7362. default:
  7363. status = QDF_STATUS_E_INVAL;
  7364. break;
  7365. }
  7366. return status;
  7367. }
  7368. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  7369. /**
  7370. * dp_update_flow_control_parameters() - API to store datapath
  7371. * config parameters
  7372. * @soc: soc handle
  7373. * @cfg: ini parameter handle
  7374. *
  7375. * Return: void
  7376. */
  7377. static inline
  7378. void dp_update_flow_control_parameters(struct dp_soc *soc,
  7379. struct cdp_config_params *params)
  7380. {
  7381. soc->wlan_cfg_ctx->tx_flow_stop_queue_threshold =
  7382. params->tx_flow_stop_queue_threshold;
  7383. soc->wlan_cfg_ctx->tx_flow_start_queue_offset =
  7384. params->tx_flow_start_queue_offset;
  7385. }
  7386. #else
  7387. static inline
  7388. void dp_update_flow_control_parameters(struct dp_soc *soc,
  7389. struct cdp_config_params *params)
  7390. {
  7391. }
  7392. #endif
  7393. #ifdef WLAN_FEATURE_RX_SOFTIRQ_TIME_LIMIT
  7394. /* Max packet limit for TX Comp packet loop (dp_tx_comp_handler) */
  7395. #define DP_TX_COMP_LOOP_PKT_LIMIT_MAX 1024
  7396. /* Max packet limit for RX REAP Loop (dp_rx_process) */
  7397. #define DP_RX_REAP_LOOP_PKT_LIMIT_MAX 1024
  7398. static
  7399. void dp_update_rx_soft_irq_limit_params(struct dp_soc *soc,
  7400. struct cdp_config_params *params)
  7401. {
  7402. soc->wlan_cfg_ctx->tx_comp_loop_pkt_limit =
  7403. params->tx_comp_loop_pkt_limit;
  7404. if (params->tx_comp_loop_pkt_limit < DP_TX_COMP_LOOP_PKT_LIMIT_MAX)
  7405. soc->wlan_cfg_ctx->tx_comp_enable_eol_data_check = true;
  7406. else
  7407. soc->wlan_cfg_ctx->tx_comp_enable_eol_data_check = false;
  7408. soc->wlan_cfg_ctx->rx_reap_loop_pkt_limit =
  7409. params->rx_reap_loop_pkt_limit;
  7410. if (params->rx_reap_loop_pkt_limit < DP_RX_REAP_LOOP_PKT_LIMIT_MAX)
  7411. soc->wlan_cfg_ctx->rx_enable_eol_data_check = true;
  7412. else
  7413. soc->wlan_cfg_ctx->rx_enable_eol_data_check = false;
  7414. soc->wlan_cfg_ctx->rx_hp_oos_update_limit =
  7415. params->rx_hp_oos_update_limit;
  7416. dp_info("tx_comp_loop_pkt_limit %u tx_comp_enable_eol_data_check %u rx_reap_loop_pkt_limit %u rx_enable_eol_data_check %u rx_hp_oos_update_limit %u",
  7417. soc->wlan_cfg_ctx->tx_comp_loop_pkt_limit,
  7418. soc->wlan_cfg_ctx->tx_comp_enable_eol_data_check,
  7419. soc->wlan_cfg_ctx->rx_reap_loop_pkt_limit,
  7420. soc->wlan_cfg_ctx->rx_enable_eol_data_check,
  7421. soc->wlan_cfg_ctx->rx_hp_oos_update_limit);
  7422. }
  7423. #else
  7424. static inline
  7425. void dp_update_rx_soft_irq_limit_params(struct dp_soc *soc,
  7426. struct cdp_config_params *params)
  7427. { }
  7428. #endif /* WLAN_FEATURE_RX_SOFTIRQ_TIME_LIMIT */
  7429. /**
  7430. * dp_update_config_parameters() - API to store datapath
  7431. * config parameters
  7432. * @soc: soc handle
  7433. * @cfg: ini parameter handle
  7434. *
  7435. * Return: status
  7436. */
  7437. static
  7438. QDF_STATUS dp_update_config_parameters(struct cdp_soc *psoc,
  7439. struct cdp_config_params *params)
  7440. {
  7441. struct dp_soc *soc = (struct dp_soc *)psoc;
  7442. if (!(soc)) {
  7443. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7444. "%s: Invalid handle", __func__);
  7445. return QDF_STATUS_E_INVAL;
  7446. }
  7447. soc->wlan_cfg_ctx->tso_enabled = params->tso_enable;
  7448. soc->wlan_cfg_ctx->lro_enabled = params->lro_enable;
  7449. soc->wlan_cfg_ctx->rx_hash = params->flow_steering_enable;
  7450. soc->wlan_cfg_ctx->tcp_udp_checksumoffload =
  7451. params->tcp_udp_checksumoffload;
  7452. soc->wlan_cfg_ctx->napi_enabled = params->napi_enable;
  7453. soc->wlan_cfg_ctx->ipa_enabled = params->ipa_enable;
  7454. soc->wlan_cfg_ctx->gro_enabled = params->gro_enable;
  7455. dp_update_rx_soft_irq_limit_params(soc, params);
  7456. dp_update_flow_control_parameters(soc, params);
  7457. return QDF_STATUS_SUCCESS;
  7458. }
  7459. static struct cdp_wds_ops dp_ops_wds = {
  7460. .vdev_set_wds = dp_vdev_set_wds,
  7461. #ifdef WDS_VENDOR_EXTENSION
  7462. .txrx_set_wds_rx_policy = dp_txrx_set_wds_rx_policy,
  7463. .txrx_wds_peer_tx_policy_update = dp_txrx_peer_wds_tx_policy_update,
  7464. #endif
  7465. };
  7466. /*
  7467. * dp_txrx_data_tx_cb_set(): set the callback for non standard tx
  7468. * @vdev_handle - datapath vdev handle
  7469. * @callback - callback function
  7470. * @ctxt: callback context
  7471. *
  7472. */
  7473. static void
  7474. dp_txrx_data_tx_cb_set(struct cdp_vdev *vdev_handle,
  7475. ol_txrx_data_tx_cb callback, void *ctxt)
  7476. {
  7477. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  7478. vdev->tx_non_std_data_callback.func = callback;
  7479. vdev->tx_non_std_data_callback.ctxt = ctxt;
  7480. }
  7481. /**
  7482. * dp_pdev_get_dp_txrx_handle() - get dp handle from pdev
  7483. * @pdev_hdl: datapath pdev handle
  7484. *
  7485. * Return: opaque pointer to dp txrx handle
  7486. */
  7487. static void *dp_pdev_get_dp_txrx_handle(struct cdp_pdev *pdev_hdl)
  7488. {
  7489. struct dp_pdev *pdev = (struct dp_pdev *)pdev_hdl;
  7490. return pdev->dp_txrx_handle;
  7491. }
  7492. /**
  7493. * dp_pdev_set_dp_txrx_handle() - set dp handle in pdev
  7494. * @pdev_hdl: datapath pdev handle
  7495. * @dp_txrx_hdl: opaque pointer for dp_txrx_handle
  7496. *
  7497. * Return: void
  7498. */
  7499. static void
  7500. dp_pdev_set_dp_txrx_handle(struct cdp_pdev *pdev_hdl, void *dp_txrx_hdl)
  7501. {
  7502. struct dp_pdev *pdev = (struct dp_pdev *)pdev_hdl;
  7503. pdev->dp_txrx_handle = dp_txrx_hdl;
  7504. }
  7505. /**
  7506. * dp_soc_get_dp_txrx_handle() - get context for external-dp from dp soc
  7507. * @soc_handle: datapath soc handle
  7508. *
  7509. * Return: opaque pointer to external dp (non-core DP)
  7510. */
  7511. static void *dp_soc_get_dp_txrx_handle(struct cdp_soc *soc_handle)
  7512. {
  7513. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  7514. return soc->external_txrx_handle;
  7515. }
  7516. /**
  7517. * dp_soc_set_dp_txrx_handle() - set external dp handle in soc
  7518. * @soc_handle: datapath soc handle
  7519. * @txrx_handle: opaque pointer to external dp (non-core DP)
  7520. *
  7521. * Return: void
  7522. */
  7523. static void
  7524. dp_soc_set_dp_txrx_handle(struct cdp_soc *soc_handle, void *txrx_handle)
  7525. {
  7526. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  7527. soc->external_txrx_handle = txrx_handle;
  7528. }
  7529. /**
  7530. * dp_soc_map_pdev_to_lmac() - Save pdev_id to lmac_id mapping
  7531. * @pdev_hdl: datapath pdev handle
  7532. * @lmac_id: lmac id
  7533. *
  7534. * Return: void
  7535. */
  7536. static void
  7537. dp_soc_map_pdev_to_lmac(struct cdp_pdev *pdev_hdl, uint32_t lmac_id)
  7538. {
  7539. struct dp_pdev *pdev = (struct dp_pdev *)pdev_hdl;
  7540. struct dp_soc *soc = pdev->soc;
  7541. pdev->lmac_id = lmac_id;
  7542. wlan_cfg_set_hw_macid(soc->wlan_cfg_ctx,
  7543. pdev->pdev_id,
  7544. (lmac_id + 1));
  7545. }
  7546. /**
  7547. * dp_soc_set_pdev_status_down() - set pdev down/up status
  7548. * @pdev_hdl: datapath pdev handle
  7549. * @is_pdev_down: pdev down/up status
  7550. *
  7551. * Return: void
  7552. */
  7553. static void
  7554. dp_soc_set_pdev_status_down(struct cdp_pdev *pdev_hdl, bool is_pdev_down)
  7555. {
  7556. struct dp_pdev *pdev = (struct dp_pdev *)pdev_hdl;
  7557. pdev->is_pdev_down = is_pdev_down;
  7558. }
  7559. /**
  7560. * dp_get_cfg_capabilities() - get dp capabilities
  7561. * @soc_handle: datapath soc handle
  7562. * @dp_caps: enum for dp capabilities
  7563. *
  7564. * Return: bool to determine if dp caps is enabled
  7565. */
  7566. static bool
  7567. dp_get_cfg_capabilities(struct cdp_soc_t *soc_handle,
  7568. enum cdp_capabilities dp_caps)
  7569. {
  7570. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  7571. return wlan_cfg_get_dp_caps(soc->wlan_cfg_ctx, dp_caps);
  7572. }
  7573. #ifdef FEATURE_AST
  7574. static void dp_peer_teardown_wifi3(struct cdp_vdev *vdev_hdl, void *peer_hdl)
  7575. {
  7576. struct dp_vdev *vdev = (struct dp_vdev *)vdev_hdl;
  7577. struct dp_peer *peer = (struct dp_peer *)peer_hdl;
  7578. struct dp_soc *soc = (struct dp_soc *)vdev->pdev->soc;
  7579. /*
  7580. * For BSS peer, new peer is not created on alloc_node if the
  7581. * peer with same address already exists , instead refcnt is
  7582. * increased for existing peer. Correspondingly in delete path,
  7583. * only refcnt is decreased; and peer is only deleted , when all
  7584. * references are deleted. So delete_in_progress should not be set
  7585. * for bss_peer, unless only 2 reference remains (peer map reference
  7586. * and peer hash table reference).
  7587. */
  7588. if (peer->bss_peer && (qdf_atomic_read(&peer->ref_cnt) > 2))
  7589. return;
  7590. qdf_spin_lock_bh(&soc->ast_lock);
  7591. peer->delete_in_progress = true;
  7592. dp_peer_delete_ast_entries(soc, peer);
  7593. qdf_spin_unlock_bh(&soc->ast_lock);
  7594. }
  7595. #endif
  7596. #ifdef ATH_SUPPORT_NAC_RSSI
  7597. /**
  7598. * dp_vdev_get_neighbour_rssi(): Store RSSI for configured NAC
  7599. * @vdev_hdl: DP vdev handle
  7600. * @rssi: rssi value
  7601. *
  7602. * Return: 0 for success. nonzero for failure.
  7603. */
  7604. static QDF_STATUS dp_vdev_get_neighbour_rssi(struct cdp_vdev *vdev_hdl,
  7605. char *mac_addr,
  7606. uint8_t *rssi)
  7607. {
  7608. struct dp_vdev *vdev = (struct dp_vdev *)vdev_hdl;
  7609. struct dp_pdev *pdev = vdev->pdev;
  7610. struct dp_neighbour_peer *peer = NULL;
  7611. QDF_STATUS status = QDF_STATUS_E_FAILURE;
  7612. *rssi = 0;
  7613. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  7614. TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
  7615. neighbour_peer_list_elem) {
  7616. if (qdf_mem_cmp(&peer->neighbour_peers_macaddr.raw[0],
  7617. mac_addr, QDF_MAC_ADDR_SIZE) == 0) {
  7618. *rssi = peer->rssi;
  7619. status = QDF_STATUS_SUCCESS;
  7620. break;
  7621. }
  7622. }
  7623. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  7624. return status;
  7625. }
  7626. static QDF_STATUS dp_config_for_nac_rssi(struct cdp_vdev *vdev_handle,
  7627. enum cdp_nac_param_cmd cmd, char *bssid, char *client_macaddr,
  7628. uint8_t chan_num)
  7629. {
  7630. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  7631. struct dp_pdev *pdev = (struct dp_pdev *)vdev->pdev;
  7632. struct dp_soc *soc = (struct dp_soc *) vdev->pdev->soc;
  7633. pdev->nac_rssi_filtering = 1;
  7634. /* Store address of NAC (neighbour peer) which will be checked
  7635. * against TA of received packets.
  7636. */
  7637. if (cmd == CDP_NAC_PARAM_ADD) {
  7638. dp_update_filter_neighbour_peers(vdev_handle, DP_NAC_PARAM_ADD,
  7639. client_macaddr);
  7640. } else if (cmd == CDP_NAC_PARAM_DEL) {
  7641. dp_update_filter_neighbour_peers(vdev_handle,
  7642. DP_NAC_PARAM_DEL,
  7643. client_macaddr);
  7644. }
  7645. if (soc->cdp_soc.ol_ops->config_bssid_in_fw_for_nac_rssi)
  7646. soc->cdp_soc.ol_ops->config_bssid_in_fw_for_nac_rssi
  7647. ((void *)vdev->pdev->ctrl_pdev,
  7648. vdev->vdev_id, cmd, bssid, client_macaddr);
  7649. return QDF_STATUS_SUCCESS;
  7650. }
  7651. #endif
  7652. /**
  7653. * dp_enable_peer_based_pktlog() - Set Flag for peer based filtering
  7654. * for pktlog
  7655. * @txrx_pdev_handle: cdp_pdev handle
  7656. * @enb_dsb: Enable or disable peer based filtering
  7657. *
  7658. * Return: QDF_STATUS
  7659. */
  7660. static int
  7661. dp_enable_peer_based_pktlog(
  7662. struct cdp_pdev *txrx_pdev_handle,
  7663. char *mac_addr, uint8_t enb_dsb)
  7664. {
  7665. struct dp_peer *peer;
  7666. uint8_t local_id;
  7667. struct dp_pdev *pdev = (struct dp_pdev *)txrx_pdev_handle;
  7668. peer = (struct dp_peer *)dp_find_peer_by_addr(txrx_pdev_handle,
  7669. mac_addr, &local_id);
  7670. if (!peer) {
  7671. dp_err("Invalid Peer");
  7672. return QDF_STATUS_E_FAILURE;
  7673. }
  7674. peer->peer_based_pktlog_filter = enb_dsb;
  7675. pdev->dp_peer_based_pktlog = enb_dsb;
  7676. return QDF_STATUS_SUCCESS;
  7677. }
  7678. #ifndef WLAN_SUPPORT_RX_TAG_STATISTICS
  7679. /**
  7680. * dp_dump_pdev_rx_protocol_tag_stats - dump the number of packets tagged for
  7681. * given protocol type (RX_PROTOCOL_TAG_ALL indicates for all protocol)
  7682. * @pdev_handle: cdp_pdev handle
  7683. * @protocol_type: protocol type for which stats should be displayed
  7684. *
  7685. * Return: none
  7686. */
  7687. static inline void
  7688. dp_dump_pdev_rx_protocol_tag_stats(struct cdp_pdev *pdev_handle,
  7689. uint16_t protocol_type)
  7690. {
  7691. }
  7692. #endif /* WLAN_SUPPORT_RX_TAG_STATISTICS */
  7693. #ifndef WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG
  7694. /**
  7695. * dp_update_pdev_rx_protocol_tag - Add/remove a protocol tag that should be
  7696. * applied to the desired protocol type packets
  7697. * @txrx_pdev_handle: cdp_pdev handle
  7698. * @enable_rx_protocol_tag - bitmask that indicates what protocol types
  7699. * are enabled for tagging. zero indicates disable feature, non-zero indicates
  7700. * enable feature
  7701. * @protocol_type: new protocol type for which the tag is being added
  7702. * @tag: user configured tag for the new protocol
  7703. *
  7704. * Return: Success
  7705. */
  7706. static inline QDF_STATUS
  7707. dp_update_pdev_rx_protocol_tag(struct cdp_pdev *pdev_handle,
  7708. uint32_t enable_rx_protocol_tag,
  7709. uint16_t protocol_type,
  7710. uint16_t tag)
  7711. {
  7712. return QDF_STATUS_SUCCESS;
  7713. }
  7714. #endif /* WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG */
  7715. #ifndef WLAN_SUPPORT_RX_FLOW_TAG
  7716. /**
  7717. * dp_set_rx_flow_tag - add/delete a flow
  7718. * @pdev_handle: cdp_pdev handle
  7719. * @flow_info: flow tuple that is to be added to/deleted from flow search table
  7720. *
  7721. * Return: Success
  7722. */
  7723. static inline QDF_STATUS
  7724. dp_set_rx_flow_tag(struct cdp_pdev *pdev_handle,
  7725. struct cdp_rx_flow_info *flow_info)
  7726. {
  7727. return QDF_STATUS_SUCCESS;
  7728. }
  7729. /**
  7730. * dp_dump_rx_flow_tag_stats - dump the number of packets tagged for
  7731. * given flow 5-tuple
  7732. * @pdev_handle: cdp_pdev handle
  7733. * @flow_info: flow 5-tuple for which stats should be displayed
  7734. *
  7735. * Return: Success
  7736. */
  7737. static inline QDF_STATUS
  7738. dp_dump_rx_flow_tag_stats(struct cdp_pdev *pdev_handle,
  7739. struct cdp_rx_flow_info *flow_info)
  7740. {
  7741. return QDF_STATUS_SUCCESS;
  7742. }
  7743. #endif /* WLAN_SUPPORT_RX_FLOW_TAG */
  7744. static QDF_STATUS dp_peer_map_attach_wifi3(struct cdp_soc_t *soc_hdl,
  7745. uint32_t max_peers,
  7746. uint32_t max_ast_index,
  7747. bool peer_map_unmap_v2)
  7748. {
  7749. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  7750. soc->max_peers = max_peers;
  7751. qdf_print ("%s max_peers %u, max_ast_index: %u\n",
  7752. __func__, max_peers, max_ast_index);
  7753. wlan_cfg_set_max_ast_idx(soc->wlan_cfg_ctx, max_ast_index);
  7754. if (dp_peer_find_attach(soc))
  7755. return QDF_STATUS_E_FAILURE;
  7756. soc->is_peer_map_unmap_v2 = peer_map_unmap_v2;
  7757. return QDF_STATUS_SUCCESS;
  7758. }
  7759. /**
  7760. * dp_pdev_set_ctrl_pdev() - set ctrl pdev handle in dp pdev
  7761. * @dp_pdev: dp pdev handle
  7762. * @ctrl_pdev: UMAC ctrl pdev handle
  7763. *
  7764. * Return: void
  7765. */
  7766. static void dp_pdev_set_ctrl_pdev(struct cdp_pdev *dp_pdev,
  7767. struct cdp_ctrl_objmgr_pdev *ctrl_pdev)
  7768. {
  7769. struct dp_pdev *pdev = (struct dp_pdev *)dp_pdev;
  7770. pdev->ctrl_pdev = ctrl_pdev;
  7771. }
  7772. static void dp_set_rate_stats_cap(struct cdp_soc_t *soc_hdl,
  7773. uint8_t val)
  7774. {
  7775. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  7776. soc->wlanstats_enabled = val;
  7777. }
  7778. static void dp_soc_set_rate_stats_ctx(struct cdp_soc_t *soc_handle,
  7779. void *stats_ctx)
  7780. {
  7781. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  7782. soc->rate_stats_ctx = stats_ctx;
  7783. }
  7784. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  7785. static void dp_flush_rate_stats_req(struct cdp_soc_t *soc_hdl,
  7786. struct cdp_pdev *pdev_hdl)
  7787. {
  7788. struct dp_pdev *pdev = (struct dp_pdev *)pdev_hdl;
  7789. struct dp_soc *soc = (struct dp_soc *)pdev->soc;
  7790. struct dp_vdev *vdev = NULL;
  7791. struct dp_peer *peer = NULL;
  7792. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  7793. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  7794. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  7795. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  7796. if (peer && !peer->bss_peer)
  7797. dp_wdi_event_handler(
  7798. WDI_EVENT_FLUSH_RATE_STATS_REQ,
  7799. pdev->soc, peer->wlanstats_ctx,
  7800. peer->peer_ids[0],
  7801. WDI_NO_VAL, pdev->pdev_id);
  7802. }
  7803. }
  7804. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  7805. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  7806. }
  7807. #else
  7808. static inline void
  7809. dp_flush_rate_stats_req(struct cdp_soc_t *soc_hdl,
  7810. struct cdp_pdev *pdev_hdl)
  7811. {
  7812. }
  7813. #endif
  7814. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  7815. static void dp_peer_flush_rate_stats(struct cdp_soc_t *soc,
  7816. struct cdp_pdev *pdev_handle,
  7817. void *buf)
  7818. {
  7819. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  7820. dp_wdi_event_handler(WDI_EVENT_PEER_FLUSH_RATE_STATS,
  7821. pdev->soc, buf, HTT_INVALID_PEER,
  7822. WDI_NO_VAL, pdev->pdev_id);
  7823. }
  7824. #else
  7825. static inline void
  7826. dp_peer_flush_rate_stats(struct cdp_soc_t *soc,
  7827. struct cdp_pdev *pdev_handle,
  7828. void *buf)
  7829. {
  7830. }
  7831. #endif
  7832. static void *dp_soc_get_rate_stats_ctx(struct cdp_soc_t *soc_handle)
  7833. {
  7834. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  7835. return soc->rate_stats_ctx;
  7836. }
  7837. /*
  7838. * dp_get_cfg() - get dp cfg
  7839. * @soc: cdp soc handle
  7840. * @cfg: cfg enum
  7841. *
  7842. * Return: cfg value
  7843. */
  7844. static uint32_t dp_get_cfg(void *soc, enum cdp_dp_cfg cfg)
  7845. {
  7846. struct dp_soc *dpsoc = (struct dp_soc *)soc;
  7847. uint32_t value = 0;
  7848. switch (cfg) {
  7849. case cfg_dp_enable_data_stall:
  7850. value = dpsoc->wlan_cfg_ctx->enable_data_stall_detection;
  7851. break;
  7852. case cfg_dp_enable_ip_tcp_udp_checksum_offload:
  7853. value = dpsoc->wlan_cfg_ctx->tcp_udp_checksumoffload;
  7854. break;
  7855. case cfg_dp_tso_enable:
  7856. value = dpsoc->wlan_cfg_ctx->tso_enabled;
  7857. break;
  7858. case cfg_dp_lro_enable:
  7859. value = dpsoc->wlan_cfg_ctx->lro_enabled;
  7860. break;
  7861. case cfg_dp_gro_enable:
  7862. value = dpsoc->wlan_cfg_ctx->gro_enabled;
  7863. break;
  7864. case cfg_dp_tx_flow_start_queue_offset:
  7865. value = dpsoc->wlan_cfg_ctx->tx_flow_start_queue_offset;
  7866. break;
  7867. case cfg_dp_tx_flow_stop_queue_threshold:
  7868. value = dpsoc->wlan_cfg_ctx->tx_flow_stop_queue_threshold;
  7869. break;
  7870. case cfg_dp_disable_intra_bss_fwd:
  7871. value = dpsoc->wlan_cfg_ctx->disable_intra_bss_fwd;
  7872. break;
  7873. default:
  7874. value = 0;
  7875. }
  7876. return value;
  7877. }
  7878. #ifdef PEER_FLOW_CONTROL
  7879. /**
  7880. * dp_tx_flow_ctrl_configure_pdev() - Configure flow control params
  7881. * @pdev_hdl: datapath pdev handle
  7882. * @param: ol ath params
  7883. * @value: value of the flag
  7884. * @buff: Buffer to be passed
  7885. *
  7886. * Implemented this function same as legacy function. In legacy code, single
  7887. * function is used to display stats and update pdev params.
  7888. *
  7889. * Return: 0 for success. nonzero for failure.
  7890. */
  7891. static uint32_t dp_tx_flow_ctrl_configure_pdev(void *pdev_handle,
  7892. enum _ol_ath_param_t param,
  7893. uint32_t value, void *buff)
  7894. {
  7895. struct dp_soc *soc = NULL;
  7896. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  7897. if (qdf_unlikely(!pdev))
  7898. return 1;
  7899. soc = pdev->soc;
  7900. if (!soc)
  7901. return 1;
  7902. switch (param) {
  7903. #ifdef QCA_ENH_V3_STATS_SUPPORT
  7904. case OL_ATH_PARAM_VIDEO_DELAY_STATS_FC:
  7905. if (value)
  7906. pdev->delay_stats_flag = true;
  7907. else
  7908. pdev->delay_stats_flag = false;
  7909. break;
  7910. case OL_ATH_PARAM_VIDEO_STATS_FC:
  7911. qdf_print("------- TID Stats ------\n");
  7912. dp_pdev_print_tid_stats(pdev);
  7913. qdf_print("------ Delay Stats ------\n");
  7914. dp_pdev_print_delay_stats(pdev);
  7915. break;
  7916. #endif
  7917. case OL_ATH_PARAM_TOTAL_Q_SIZE:
  7918. {
  7919. uint32_t tx_min, tx_max;
  7920. tx_min = wlan_cfg_get_min_tx_desc(soc->wlan_cfg_ctx);
  7921. tx_max = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  7922. if (!buff) {
  7923. if ((value >= tx_min) && (value <= tx_max)) {
  7924. pdev->num_tx_allowed = value;
  7925. } else {
  7926. QDF_TRACE(QDF_MODULE_ID_DP,
  7927. QDF_TRACE_LEVEL_INFO,
  7928. "Failed to update num_tx_allowed, Q_min = %d Q_max = %d",
  7929. tx_min, tx_max);
  7930. break;
  7931. }
  7932. } else {
  7933. *(int *)buff = pdev->num_tx_allowed;
  7934. }
  7935. }
  7936. break;
  7937. default:
  7938. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  7939. "%s: not handled param %d ", __func__, param);
  7940. break;
  7941. }
  7942. return 0;
  7943. }
  7944. #endif
  7945. /**
  7946. * dp_set_pdev_pcp_tid_map_wifi3(): update pcp tid map in pdev
  7947. * @vdev: DP_PDEV handle
  7948. * @pcp: pcp value
  7949. * @tid: tid value passed by the user
  7950. *
  7951. * Return: QDF_STATUS_SUCCESS on success
  7952. */
  7953. static QDF_STATUS dp_set_pdev_pcp_tid_map_wifi3(struct cdp_pdev *pdev_handle,
  7954. uint8_t pcp, uint8_t tid)
  7955. {
  7956. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  7957. struct dp_soc *soc = pdev->soc;
  7958. soc->pcp_tid_map[pcp] = tid;
  7959. hal_tx_update_pcp_tid_map(soc->hal_soc, pcp, tid);
  7960. return QDF_STATUS_SUCCESS;
  7961. }
  7962. /**
  7963. * dp_set_pdev_tidmap_prty_wifi3(): update tidmap priority in pdev
  7964. * @vdev: DP_PDEV handle
  7965. * @prio: tidmap priority value passed by the user
  7966. *
  7967. * Return: QDF_STATUS_SUCCESS on success
  7968. */
  7969. static QDF_STATUS dp_set_pdev_tidmap_prty_wifi3(struct cdp_pdev *pdev_handle,
  7970. uint8_t prio)
  7971. {
  7972. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  7973. struct dp_soc *soc = pdev->soc;
  7974. soc->tidmap_prty = prio;
  7975. hal_tx_set_tidmap_prty(soc->hal_soc, prio);
  7976. return QDF_STATUS_SUCCESS;
  7977. }
  7978. /**
  7979. * dp_set_vdev_pcp_tid_map_wifi3(): update pcp tid map in vdev
  7980. * @vdev: DP_VDEV handle
  7981. * @pcp: pcp value
  7982. * @tid: tid value passed by the user
  7983. *
  7984. * Return: QDF_STATUS_SUCCESS on success
  7985. */
  7986. static QDF_STATUS dp_set_vdev_pcp_tid_map_wifi3(struct cdp_vdev *vdev_handle,
  7987. uint8_t pcp, uint8_t tid)
  7988. {
  7989. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  7990. vdev->pcp_tid_map[pcp] = tid;
  7991. return QDF_STATUS_SUCCESS;
  7992. }
  7993. /**
  7994. * dp_set_vdev_tidmap_tbl_id_wifi3(): update tidmapi tbl id in vdev
  7995. * @vdev: DP_VDEV handle
  7996. * @mapid: map_id value passed by the user
  7997. *
  7998. * Return: QDF_STATUS_SUCCESS on success
  7999. */
  8000. static QDF_STATUS dp_set_vdev_tidmap_tbl_id_wifi3(struct cdp_vdev *vdev_handle,
  8001. uint8_t mapid)
  8002. {
  8003. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  8004. vdev->tidmap_tbl_id = mapid;
  8005. return QDF_STATUS_SUCCESS;
  8006. }
  8007. /**
  8008. * dp_set_vdev_tidmap_prty_wifi3(): update tidmap priority in vdev
  8009. * @vdev: DP_VDEV handle
  8010. * @prio: tidmap priority value passed by the user
  8011. *
  8012. * Return: QDF_STATUS_SUCCESS on success
  8013. */
  8014. static QDF_STATUS dp_set_vdev_tidmap_prty_wifi3(struct cdp_vdev *vdev_handle,
  8015. uint8_t prio)
  8016. {
  8017. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  8018. vdev->tidmap_prty = prio;
  8019. return QDF_STATUS_SUCCESS;
  8020. }
  8021. static struct cdp_cmn_ops dp_ops_cmn = {
  8022. .txrx_soc_attach_target = dp_soc_attach_target_wifi3,
  8023. .txrx_vdev_attach = dp_vdev_attach_wifi3,
  8024. .txrx_vdev_detach = dp_vdev_detach_wifi3,
  8025. .txrx_pdev_attach = dp_pdev_attach_wifi3,
  8026. .txrx_pdev_detach = dp_pdev_detach_wifi3,
  8027. .txrx_pdev_deinit = dp_pdev_deinit_wifi3,
  8028. .txrx_peer_create = dp_peer_create_wifi3,
  8029. .txrx_peer_setup = dp_peer_setup_wifi3,
  8030. #ifdef FEATURE_AST
  8031. .txrx_peer_teardown = dp_peer_teardown_wifi3,
  8032. #else
  8033. .txrx_peer_teardown = NULL,
  8034. #endif
  8035. .txrx_peer_add_ast = dp_peer_add_ast_wifi3,
  8036. .txrx_peer_update_ast = dp_peer_update_ast_wifi3,
  8037. .txrx_peer_get_ast_info_by_soc = dp_peer_get_ast_info_by_soc_wifi3,
  8038. .txrx_peer_get_ast_info_by_pdev =
  8039. dp_peer_get_ast_info_by_pdevid_wifi3,
  8040. .txrx_peer_ast_delete_by_soc =
  8041. dp_peer_ast_entry_del_by_soc,
  8042. .txrx_peer_ast_delete_by_pdev =
  8043. dp_peer_ast_entry_del_by_pdev,
  8044. .txrx_peer_delete = dp_peer_delete_wifi3,
  8045. .txrx_vdev_register = dp_vdev_register_wifi3,
  8046. .txrx_vdev_flush_peers = dp_vdev_flush_peers,
  8047. .txrx_soc_detach = dp_soc_detach_wifi3,
  8048. .txrx_soc_deinit = dp_soc_deinit_wifi3,
  8049. .txrx_soc_init = dp_soc_init_wifi3,
  8050. .txrx_tso_soc_attach = dp_tso_soc_attach,
  8051. .txrx_tso_soc_detach = dp_tso_soc_detach,
  8052. .txrx_get_vdev_mac_addr = dp_get_vdev_mac_addr_wifi3,
  8053. .txrx_get_vdev_from_vdev_id = dp_get_vdev_from_vdev_id_wifi3,
  8054. .txrx_get_mon_vdev_from_pdev = dp_get_mon_vdev_from_pdev_wifi3,
  8055. .txrx_get_ctrl_pdev_from_vdev = dp_get_ctrl_pdev_from_vdev_wifi3,
  8056. .txrx_ath_getstats = dp_get_device_stats,
  8057. .addba_requestprocess = dp_addba_requestprocess_wifi3,
  8058. .addba_responsesetup = dp_addba_responsesetup_wifi3,
  8059. .addba_resp_tx_completion = dp_addba_resp_tx_completion_wifi3,
  8060. .delba_process = dp_delba_process_wifi3,
  8061. .set_addba_response = dp_set_addba_response,
  8062. .get_peer_mac_addr_frm_id = dp_get_peer_mac_addr_frm_id,
  8063. .flush_cache_rx_queue = NULL,
  8064. /* TODO: get API's for dscp-tid need to be added*/
  8065. .set_vdev_dscp_tid_map = dp_set_vdev_dscp_tid_map_wifi3,
  8066. .set_pdev_dscp_tid_map = dp_set_pdev_dscp_tid_map_wifi3,
  8067. .hmmc_tid_override_en = dp_hmmc_tid_override_en_wifi3,
  8068. .set_hmmc_tid_val = dp_set_hmmc_tid_val_wifi3,
  8069. .txrx_get_total_per = dp_get_total_per,
  8070. .txrx_stats_request = dp_txrx_stats_request,
  8071. .txrx_set_monitor_mode = dp_vdev_set_monitor_mode,
  8072. .txrx_get_pdev_id_frm_pdev = dp_get_pdev_id_frm_pdev,
  8073. .txrx_get_vow_config_frm_pdev = dp_get_delay_stats_flag,
  8074. .txrx_pdev_set_chan_noise_floor = dp_pdev_set_chan_noise_floor,
  8075. .txrx_set_nac = dp_set_nac,
  8076. .txrx_get_tx_pending = dp_get_tx_pending,
  8077. .txrx_set_pdev_tx_capture = dp_config_debug_sniffer,
  8078. .txrx_get_peer_mac_from_peer_id = dp_get_peer_mac_from_peer_id,
  8079. .display_stats = dp_txrx_dump_stats,
  8080. .txrx_soc_set_nss_cfg = dp_soc_set_nss_cfg_wifi3,
  8081. .txrx_soc_get_nss_cfg = dp_soc_get_nss_cfg_wifi3,
  8082. .txrx_intr_attach = dp_soc_interrupt_attach_wrapper,
  8083. .txrx_intr_detach = dp_soc_interrupt_detach,
  8084. .set_pn_check = dp_set_pn_check_wifi3,
  8085. .update_config_parameters = dp_update_config_parameters,
  8086. /* TODO: Add other functions */
  8087. .txrx_data_tx_cb_set = dp_txrx_data_tx_cb_set,
  8088. .get_dp_txrx_handle = dp_pdev_get_dp_txrx_handle,
  8089. .set_dp_txrx_handle = dp_pdev_set_dp_txrx_handle,
  8090. .get_soc_dp_txrx_handle = dp_soc_get_dp_txrx_handle,
  8091. .set_soc_dp_txrx_handle = dp_soc_set_dp_txrx_handle,
  8092. .map_pdev_to_lmac = dp_soc_map_pdev_to_lmac,
  8093. .set_pdev_status_down = dp_soc_set_pdev_status_down,
  8094. .txrx_set_ba_aging_timeout = dp_set_ba_aging_timeout,
  8095. .txrx_get_ba_aging_timeout = dp_get_ba_aging_timeout,
  8096. .tx_send = dp_tx_send,
  8097. .txrx_peer_reset_ast = dp_wds_reset_ast_wifi3,
  8098. .txrx_peer_reset_ast_table = dp_wds_reset_ast_table_wifi3,
  8099. .txrx_peer_flush_ast_table = dp_wds_flush_ast_table_wifi3,
  8100. .txrx_peer_map_attach = dp_peer_map_attach_wifi3,
  8101. .txrx_pdev_set_ctrl_pdev = dp_pdev_set_ctrl_pdev,
  8102. .txrx_get_os_rx_handles_from_vdev =
  8103. dp_get_os_rx_handles_from_vdev_wifi3,
  8104. .delba_tx_completion = dp_delba_tx_completion_wifi3,
  8105. .get_dp_capabilities = dp_get_cfg_capabilities,
  8106. .txrx_get_cfg = dp_get_cfg,
  8107. .set_rate_stats_ctx = dp_soc_set_rate_stats_ctx,
  8108. .get_rate_stats_ctx = dp_soc_get_rate_stats_ctx,
  8109. .txrx_peer_flush_rate_stats = dp_peer_flush_rate_stats,
  8110. .txrx_flush_rate_stats_request = dp_flush_rate_stats_req,
  8111. .set_pdev_pcp_tid_map = dp_set_pdev_pcp_tid_map_wifi3,
  8112. .set_pdev_tidmap_prty = dp_set_pdev_tidmap_prty_wifi3,
  8113. .set_vdev_pcp_tid_map = dp_set_vdev_pcp_tid_map_wifi3,
  8114. .set_vdev_tidmap_prty = dp_set_vdev_tidmap_prty_wifi3,
  8115. .set_vdev_tidmap_tbl_id = dp_set_vdev_tidmap_tbl_id_wifi3,
  8116. .txrx_cp_peer_del_response = dp_cp_peer_del_resp_handler,
  8117. #ifdef QCA_MULTIPASS_SUPPORT
  8118. .set_vlan_groupkey = dp_set_vlan_groupkey,
  8119. #endif
  8120. };
  8121. static struct cdp_ctrl_ops dp_ops_ctrl = {
  8122. .txrx_peer_authorize = dp_peer_authorize,
  8123. .txrx_set_vdev_rx_decap_type = dp_set_vdev_rx_decap_type,
  8124. .txrx_set_tx_encap_type = dp_set_vdev_tx_encap_type,
  8125. #ifdef MESH_MODE_SUPPORT
  8126. .txrx_set_mesh_mode = dp_peer_set_mesh_mode,
  8127. .txrx_set_mesh_rx_filter = dp_peer_set_mesh_rx_filter,
  8128. #endif
  8129. .txrx_set_vdev_param = dp_set_vdev_param,
  8130. .txrx_peer_set_nawds = dp_peer_set_nawds,
  8131. .txrx_set_pdev_reo_dest = dp_set_pdev_reo_dest,
  8132. .txrx_get_pdev_reo_dest = dp_get_pdev_reo_dest,
  8133. .txrx_set_filter_neighbour_peers = dp_set_filter_neighbour_peers,
  8134. .txrx_update_filter_neighbour_peers =
  8135. dp_update_filter_neighbour_peers,
  8136. .txrx_get_sec_type = dp_get_sec_type,
  8137. /* TODO: Add other functions */
  8138. .txrx_wdi_event_sub = dp_wdi_event_sub,
  8139. .txrx_wdi_event_unsub = dp_wdi_event_unsub,
  8140. #ifdef WDI_EVENT_ENABLE
  8141. .txrx_get_pldev = dp_get_pldev,
  8142. #endif
  8143. .txrx_set_pdev_param = dp_set_pdev_param,
  8144. #ifdef ATH_SUPPORT_NAC_RSSI
  8145. .txrx_vdev_config_for_nac_rssi = dp_config_for_nac_rssi,
  8146. .txrx_vdev_get_neighbour_rssi = dp_vdev_get_neighbour_rssi,
  8147. #endif
  8148. .set_key = dp_set_michael_key,
  8149. .txrx_get_vdev_param = dp_get_vdev_param,
  8150. .enable_peer_based_pktlog = dp_enable_peer_based_pktlog,
  8151. .calculate_delay_stats = dp_calculate_delay_stats,
  8152. #ifdef WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG
  8153. .txrx_update_pdev_rx_protocol_tag = dp_update_pdev_rx_protocol_tag,
  8154. #ifdef WLAN_SUPPORT_RX_TAG_STATISTICS
  8155. .txrx_dump_pdev_rx_protocol_tag_stats =
  8156. dp_dump_pdev_rx_protocol_tag_stats,
  8157. #endif /* WLAN_SUPPORT_RX_TAG_STATISTICS */
  8158. #endif /* WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG */
  8159. #ifdef WLAN_SUPPORT_RX_FLOW_TAG
  8160. .txrx_set_rx_flow_tag = dp_set_rx_flow_tag,
  8161. .txrx_dump_rx_flow_tag_stats = dp_dump_rx_flow_tag_stats,
  8162. #endif /* WLAN_SUPPORT_RX_FLOW_TAG */
  8163. #ifdef QCA_MULTIPASS_SUPPORT
  8164. .txrx_peer_set_vlan_id = dp_peer_set_vlan_id,
  8165. #endif /*QCA_MULTIPASS_SUPPORT*/
  8166. #if defined(WLAN_TX_PKT_CAPTURE_ENH) || defined(WLAN_RX_PKT_CAPTURE_ENH)
  8167. .txrx_update_peer_pkt_capture_params =
  8168. dp_peer_update_pkt_capture_params,
  8169. #endif /* WLAN_TX_PKT_CAPTURE_ENH || WLAN_RX_PKT_CAPTURE_ENH */
  8170. };
  8171. static struct cdp_me_ops dp_ops_me = {
  8172. #ifdef ATH_SUPPORT_IQUE
  8173. .tx_me_alloc_descriptor = dp_tx_me_alloc_descriptor,
  8174. .tx_me_free_descriptor = dp_tx_me_free_descriptor,
  8175. .tx_me_convert_ucast = dp_tx_me_send_convert_ucast,
  8176. #endif
  8177. };
  8178. static struct cdp_mon_ops dp_ops_mon = {
  8179. .txrx_monitor_set_filter_ucast_data = NULL,
  8180. .txrx_monitor_set_filter_mcast_data = NULL,
  8181. .txrx_monitor_set_filter_non_data = NULL,
  8182. .txrx_monitor_get_filter_ucast_data = dp_vdev_get_filter_ucast_data,
  8183. .txrx_monitor_get_filter_mcast_data = dp_vdev_get_filter_mcast_data,
  8184. .txrx_monitor_get_filter_non_data = dp_vdev_get_filter_non_data,
  8185. .txrx_reset_monitor_mode = dp_reset_monitor_mode,
  8186. /* Added support for HK advance filter */
  8187. .txrx_set_advance_monitor_filter = dp_pdev_set_advance_monitor_filter,
  8188. .txrx_monitor_record_channel = dp_pdev_set_monitor_channel,
  8189. .txrx_deliver_tx_mgmt = dp_deliver_tx_mgmt,
  8190. };
  8191. static struct cdp_host_stats_ops dp_ops_host_stats = {
  8192. .txrx_per_peer_stats = dp_get_host_peer_stats,
  8193. .get_fw_peer_stats = dp_get_fw_peer_stats,
  8194. .get_htt_stats = dp_get_htt_stats,
  8195. .txrx_enable_enhanced_stats = dp_enable_enhanced_stats,
  8196. .txrx_disable_enhanced_stats = dp_disable_enhanced_stats,
  8197. .txrx_stats_publish = dp_txrx_stats_publish,
  8198. .txrx_get_vdev_stats = dp_txrx_get_vdev_stats,
  8199. .txrx_get_peer_stats = dp_txrx_get_peer_stats,
  8200. .txrx_reset_peer_stats = dp_txrx_reset_peer_stats,
  8201. .txrx_get_pdev_stats = dp_txrx_get_pdev_stats,
  8202. .txrx_get_ratekbps = dp_txrx_get_ratekbps,
  8203. .configure_rate_stats = dp_set_rate_stats_cap,
  8204. .txrx_update_vdev_stats = dp_txrx_update_vdev_host_stats,
  8205. /* TODO */
  8206. };
  8207. static struct cdp_raw_ops dp_ops_raw = {
  8208. /* TODO */
  8209. };
  8210. #ifdef PEER_FLOW_CONTROL
  8211. static struct cdp_pflow_ops dp_ops_pflow = {
  8212. dp_tx_flow_ctrl_configure_pdev,
  8213. };
  8214. #endif /* CONFIG_WIN */
  8215. #ifdef FEATURE_RUNTIME_PM
  8216. /**
  8217. * dp_runtime_suspend() - ensure DP is ready to runtime suspend
  8218. * @soc_hdl: Datapath soc handle
  8219. * @pdev_id: id of data path pdev handle
  8220. *
  8221. * DP is ready to runtime suspend if there are no pending TX packets.
  8222. *
  8223. * Return: QDF_STATUS
  8224. */
  8225. static QDF_STATUS dp_runtime_suspend(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  8226. {
  8227. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  8228. struct dp_pdev *pdev;
  8229. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  8230. if (!pdev) {
  8231. dp_err("pdev is NULL");
  8232. return QDF_STATUS_E_INVAL;
  8233. }
  8234. /* Abort if there are any pending TX packets */
  8235. if (dp_get_tx_pending(dp_pdev_to_cdp_pdev(pdev)) > 0) {
  8236. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  8237. FL("Abort suspend due to pending TX packets"));
  8238. return QDF_STATUS_E_AGAIN;
  8239. }
  8240. if (soc->intr_mode == DP_INTR_POLL)
  8241. qdf_timer_stop(&soc->int_timer);
  8242. return QDF_STATUS_SUCCESS;
  8243. }
  8244. /**
  8245. * dp_flush_ring_hptp() - Update ring shadow
  8246. * register HP/TP address when runtime
  8247. * resume
  8248. * @opaque_soc: DP soc context
  8249. *
  8250. * Return: None
  8251. */
  8252. static
  8253. void dp_flush_ring_hptp(struct dp_soc *soc, hal_ring_handle_t hal_srng)
  8254. {
  8255. if (hal_srng && hal_srng_get_clear_event(hal_srng,
  8256. HAL_SRNG_FLUSH_EVENT)) {
  8257. /* Acquire the lock */
  8258. hal_srng_access_start(soc->hal_soc, hal_srng);
  8259. hal_srng_access_end(soc->hal_soc, hal_srng);
  8260. hal_srng_set_flush_last_ts(hal_srng);
  8261. }
  8262. }
  8263. /**
  8264. * dp_runtime_resume() - ensure DP is ready to runtime resume
  8265. * @soc_hdl: Datapath soc handle
  8266. * @pdev_id: id of data path pdev handle
  8267. *
  8268. * Resume DP for runtime PM.
  8269. *
  8270. * Return: QDF_STATUS
  8271. */
  8272. static QDF_STATUS dp_runtime_resume(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  8273. {
  8274. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  8275. int i;
  8276. if (soc->intr_mode == DP_INTR_POLL)
  8277. qdf_timer_mod(&soc->int_timer, DP_INTR_POLL_TIMER_MS);
  8278. for (i = 0; i < MAX_TCL_DATA_RINGS; i++) {
  8279. dp_flush_ring_hptp(soc, soc->tcl_data_ring[i].hal_srng);
  8280. }
  8281. dp_flush_ring_hptp(soc, soc->reo_cmd_ring.hal_srng);
  8282. return QDF_STATUS_SUCCESS;
  8283. }
  8284. #endif /* FEATURE_RUNTIME_PM */
  8285. /**
  8286. * dp_tx_get_success_ack_stats() - get tx success completion count
  8287. * @soc_hdl: Datapath soc handle
  8288. * @vdevid: vdev identifier
  8289. *
  8290. * Return: tx success ack count
  8291. */
  8292. static uint32_t dp_tx_get_success_ack_stats(struct cdp_soc_t *soc_hdl,
  8293. uint8_t vdev_id)
  8294. {
  8295. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  8296. struct dp_vdev *vdev =
  8297. (struct dp_vdev *)dp_get_vdev_from_soc_vdev_id_wifi3(soc,
  8298. vdev_id);
  8299. struct cdp_vdev_stats *vdev_stats = NULL;
  8300. uint32_t tx_success;
  8301. if (!vdev) {
  8302. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  8303. FL("Invalid vdev id %d"), vdev_id);
  8304. return 0;
  8305. }
  8306. vdev_stats = qdf_mem_malloc_atomic(sizeof(struct cdp_vdev_stats));
  8307. if (!vdev_stats) {
  8308. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  8309. "DP alloc failure - unable to get alloc vdev stats");
  8310. return 0;
  8311. }
  8312. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  8313. dp_aggregate_vdev_stats(vdev, vdev_stats);
  8314. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  8315. tx_success = vdev_stats->tx.tx_success.num;
  8316. qdf_mem_free(vdev_stats);
  8317. return tx_success;
  8318. }
  8319. #ifdef WLAN_SUPPORT_DATA_STALL
  8320. /**
  8321. * dp_register_data_stall_detect_cb() - register data stall callback
  8322. * @soc_hdl: Datapath soc handle
  8323. * @pdev_id: id of data path pdev handle
  8324. * @data_stall_detect_callback: data stall callback function
  8325. *
  8326. * Return: QDF_STATUS Enumeration
  8327. */
  8328. static
  8329. QDF_STATUS dp_register_data_stall_detect_cb(
  8330. struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  8331. data_stall_detect_cb data_stall_detect_callback)
  8332. {
  8333. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  8334. struct dp_pdev *pdev;
  8335. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  8336. if (!pdev) {
  8337. dp_err("pdev NULL!");
  8338. return QDF_STATUS_E_INVAL;
  8339. }
  8340. pdev->data_stall_detect_callback = data_stall_detect_callback;
  8341. return QDF_STATUS_SUCCESS;
  8342. }
  8343. /**
  8344. * dp_deregister_data_stall_detect_cb() - de-register data stall callback
  8345. * @soc_hdl: Datapath soc handle
  8346. * @pdev_id: id of data path pdev handle
  8347. * @data_stall_detect_callback: data stall callback function
  8348. *
  8349. * Return: QDF_STATUS Enumeration
  8350. */
  8351. static
  8352. QDF_STATUS dp_deregister_data_stall_detect_cb(
  8353. struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  8354. data_stall_detect_cb data_stall_detect_callback)
  8355. {
  8356. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  8357. struct dp_pdev *pdev;
  8358. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  8359. if (!pdev) {
  8360. dp_err("pdev NULL!");
  8361. return QDF_STATUS_E_INVAL;
  8362. }
  8363. pdev->data_stall_detect_callback = NULL;
  8364. return QDF_STATUS_SUCCESS;
  8365. }
  8366. /**
  8367. * dp_txrx_post_data_stall_event() - post data stall event
  8368. * @soc_hdl: Datapath soc handle
  8369. * @indicator: Module triggering data stall
  8370. * @data_stall_type: data stall event type
  8371. * @pdev_id: pdev id
  8372. * @vdev_id_bitmap: vdev id bitmap
  8373. * @recovery_type: data stall recovery type
  8374. *
  8375. * Return: None
  8376. */
  8377. static void
  8378. dp_txrx_post_data_stall_event(struct cdp_soc_t *soc_hdl,
  8379. enum data_stall_log_event_indicator indicator,
  8380. enum data_stall_log_event_type data_stall_type,
  8381. uint32_t pdev_id, uint32_t vdev_id_bitmap,
  8382. enum data_stall_log_recovery_type recovery_type)
  8383. {
  8384. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  8385. struct data_stall_event_info data_stall_info;
  8386. struct dp_pdev *pdev;
  8387. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  8388. if (!pdev) {
  8389. dp_err("pdev NULL!");
  8390. return;
  8391. }
  8392. if (!pdev->data_stall_detect_callback) {
  8393. dp_err("data stall cb not registered!");
  8394. return;
  8395. }
  8396. dp_info("data_stall_type: %x pdev_id: %d",
  8397. data_stall_type, pdev_id);
  8398. data_stall_info.indicator = indicator;
  8399. data_stall_info.data_stall_type = data_stall_type;
  8400. data_stall_info.vdev_id_bitmap = vdev_id_bitmap;
  8401. data_stall_info.pdev_id = pdev_id;
  8402. data_stall_info.recovery_type = recovery_type;
  8403. pdev->data_stall_detect_callback(&data_stall_info);
  8404. }
  8405. #endif /* WLAN_SUPPORT_DATA_STALL */
  8406. #ifdef DP_PEER_EXTENDED_API
  8407. static struct cdp_misc_ops dp_ops_misc = {
  8408. #ifdef FEATURE_WLAN_TDLS
  8409. .tx_non_std = dp_tx_non_std,
  8410. #endif /* FEATURE_WLAN_TDLS */
  8411. .get_opmode = dp_get_opmode,
  8412. #ifdef FEATURE_RUNTIME_PM
  8413. .runtime_suspend = dp_runtime_suspend,
  8414. .runtime_resume = dp_runtime_resume,
  8415. #endif /* FEATURE_RUNTIME_PM */
  8416. .pkt_log_init = dp_pkt_log_init,
  8417. .pkt_log_con_service = dp_pkt_log_con_service,
  8418. .get_num_rx_contexts = dp_get_num_rx_contexts,
  8419. .get_tx_ack_stats = dp_tx_get_success_ack_stats,
  8420. #ifdef WLAN_SUPPORT_DATA_STALL
  8421. .txrx_data_stall_cb_register = dp_register_data_stall_detect_cb,
  8422. .txrx_data_stall_cb_deregister = dp_deregister_data_stall_detect_cb,
  8423. .txrx_post_data_stall_event = dp_txrx_post_data_stall_event,
  8424. #endif
  8425. };
  8426. #endif
  8427. #ifdef DP_FLOW_CTL
  8428. static struct cdp_flowctl_ops dp_ops_flowctl = {
  8429. /* WIFI 3.0 DP implement as required. */
  8430. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  8431. .flow_pool_map_handler = dp_tx_flow_pool_map,
  8432. .flow_pool_unmap_handler = dp_tx_flow_pool_unmap,
  8433. .register_pause_cb = dp_txrx_register_pause_cb,
  8434. .dump_flow_pool_info = dp_tx_dump_flow_pool_info,
  8435. .tx_desc_thresh_reached = dp_tx_desc_thresh_reached,
  8436. #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */
  8437. };
  8438. static struct cdp_lflowctl_ops dp_ops_l_flowctl = {
  8439. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  8440. };
  8441. #endif
  8442. #ifdef IPA_OFFLOAD
  8443. static struct cdp_ipa_ops dp_ops_ipa = {
  8444. .ipa_get_resource = dp_ipa_get_resource,
  8445. .ipa_set_doorbell_paddr = dp_ipa_set_doorbell_paddr,
  8446. .ipa_op_response = dp_ipa_op_response,
  8447. .ipa_register_op_cb = dp_ipa_register_op_cb,
  8448. .ipa_get_stat = dp_ipa_get_stat,
  8449. .ipa_tx_data_frame = dp_tx_send_ipa_data_frame,
  8450. .ipa_enable_autonomy = dp_ipa_enable_autonomy,
  8451. .ipa_disable_autonomy = dp_ipa_disable_autonomy,
  8452. .ipa_setup = dp_ipa_setup,
  8453. .ipa_cleanup = dp_ipa_cleanup,
  8454. .ipa_setup_iface = dp_ipa_setup_iface,
  8455. .ipa_cleanup_iface = dp_ipa_cleanup_iface,
  8456. .ipa_enable_pipes = dp_ipa_enable_pipes,
  8457. .ipa_disable_pipes = dp_ipa_disable_pipes,
  8458. .ipa_set_perf_level = dp_ipa_set_perf_level,
  8459. .ipa_rx_intrabss_fwd = dp_ipa_rx_intrabss_fwd
  8460. };
  8461. #endif
  8462. #ifdef DP_POWER_SAVE
  8463. static QDF_STATUS dp_bus_suspend(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  8464. {
  8465. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  8466. struct cdp_pdev *pdev = (struct cdp_pdev *)
  8467. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  8468. int timeout = SUSPEND_DRAIN_WAIT;
  8469. int drain_wait_delay = 50; /* 50 ms */
  8470. if (qdf_unlikely(!pdev)) {
  8471. dp_err("pdev is NULL");
  8472. return QDF_STATUS_E_INVAL;
  8473. }
  8474. /* Abort if there are any pending TX packets */
  8475. while (dp_get_tx_pending(pdev) > 0) {
  8476. qdf_sleep(drain_wait_delay);
  8477. if (timeout <= 0) {
  8478. dp_err("TX frames are pending, abort suspend");
  8479. return QDF_STATUS_E_TIMEOUT;
  8480. }
  8481. timeout = timeout - drain_wait_delay;
  8482. }
  8483. if (soc->intr_mode == DP_INTR_POLL)
  8484. qdf_timer_stop(&soc->int_timer);
  8485. return QDF_STATUS_SUCCESS;
  8486. }
  8487. static QDF_STATUS dp_bus_resume(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  8488. {
  8489. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  8490. if (soc->intr_mode == DP_INTR_POLL)
  8491. qdf_timer_mod(&soc->int_timer, DP_INTR_POLL_TIMER_MS);
  8492. return QDF_STATUS_SUCCESS;
  8493. }
  8494. static struct cdp_bus_ops dp_ops_bus = {
  8495. .bus_suspend = dp_bus_suspend,
  8496. .bus_resume = dp_bus_resume
  8497. };
  8498. #endif
  8499. #ifdef DP_FLOW_CTL
  8500. static struct cdp_throttle_ops dp_ops_throttle = {
  8501. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  8502. };
  8503. static struct cdp_cfg_ops dp_ops_cfg = {
  8504. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  8505. };
  8506. #endif
  8507. #ifdef DP_PEER_EXTENDED_API
  8508. static struct cdp_ocb_ops dp_ops_ocb = {
  8509. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  8510. };
  8511. static struct cdp_mob_stats_ops dp_ops_mob_stats = {
  8512. .clear_stats = dp_txrx_clear_dump_stats,
  8513. };
  8514. /*
  8515. * dp_peer_get_ref_find_by_addr - get peer with addr by ref count inc
  8516. * @dev: physical device instance
  8517. * @peer_mac_addr: peer mac address
  8518. * @local_id: local id for the peer
  8519. * @debug_id: to track enum peer access
  8520. *
  8521. * Return: peer instance pointer
  8522. */
  8523. static inline void *
  8524. dp_peer_get_ref_find_by_addr(struct cdp_pdev *dev, uint8_t *peer_mac_addr,
  8525. uint8_t *local_id,
  8526. enum peer_debug_id_type debug_id)
  8527. {
  8528. struct dp_pdev *pdev = (struct dp_pdev *)dev;
  8529. struct dp_peer *peer;
  8530. peer = dp_peer_find_hash_find(pdev->soc, peer_mac_addr, 0, DP_VDEV_ALL);
  8531. if (!peer)
  8532. return NULL;
  8533. *local_id = peer->local_id;
  8534. DP_TRACE(INFO, "%s: peer %pK id %d", __func__, peer, *local_id);
  8535. return peer;
  8536. }
  8537. /*
  8538. * dp_peer_release_ref - release peer ref count
  8539. * @peer: peer handle
  8540. * @debug_id: to track enum peer access
  8541. *
  8542. * Return: None
  8543. */
  8544. static inline
  8545. void dp_peer_release_ref(void *peer, enum peer_debug_id_type debug_id)
  8546. {
  8547. dp_peer_unref_delete(peer);
  8548. }
  8549. static struct cdp_peer_ops dp_ops_peer = {
  8550. .register_peer = dp_register_peer,
  8551. .clear_peer = dp_clear_peer,
  8552. .find_peer_by_addr = dp_find_peer_by_addr,
  8553. .find_peer_by_addr_and_vdev = dp_find_peer_by_addr_and_vdev,
  8554. .peer_get_ref_by_addr = dp_peer_get_ref_find_by_addr,
  8555. .peer_release_ref = dp_peer_release_ref,
  8556. .local_peer_id = dp_local_peer_id,
  8557. .peer_find_by_local_id = dp_peer_find_by_local_id,
  8558. .peer_state_update = dp_peer_state_update,
  8559. .get_vdevid = dp_get_vdevid,
  8560. .get_vdev_by_peer_addr = dp_get_vdev_by_peer_addr,
  8561. .peer_get_peer_mac_addr = dp_peer_get_peer_mac_addr,
  8562. .get_vdev_for_peer = dp_get_vdev_for_peer,
  8563. .get_peer_state = dp_get_peer_state,
  8564. };
  8565. #endif
  8566. static struct cdp_ops dp_txrx_ops = {
  8567. .cmn_drv_ops = &dp_ops_cmn,
  8568. .ctrl_ops = &dp_ops_ctrl,
  8569. .me_ops = &dp_ops_me,
  8570. .mon_ops = &dp_ops_mon,
  8571. .host_stats_ops = &dp_ops_host_stats,
  8572. .wds_ops = &dp_ops_wds,
  8573. .raw_ops = &dp_ops_raw,
  8574. #ifdef PEER_FLOW_CONTROL
  8575. .pflow_ops = &dp_ops_pflow,
  8576. #endif /* PEER_FLOW_CONTROL */
  8577. #ifdef DP_PEER_EXTENDED_API
  8578. .misc_ops = &dp_ops_misc,
  8579. .ocb_ops = &dp_ops_ocb,
  8580. .peer_ops = &dp_ops_peer,
  8581. .mob_stats_ops = &dp_ops_mob_stats,
  8582. #endif
  8583. #ifdef DP_FLOW_CTL
  8584. .cfg_ops = &dp_ops_cfg,
  8585. .flowctl_ops = &dp_ops_flowctl,
  8586. .l_flowctl_ops = &dp_ops_l_flowctl,
  8587. .throttle_ops = &dp_ops_throttle,
  8588. #endif
  8589. #ifdef IPA_OFFLOAD
  8590. .ipa_ops = &dp_ops_ipa,
  8591. #endif
  8592. #ifdef DP_POWER_SAVE
  8593. .bus_ops = &dp_ops_bus,
  8594. #endif
  8595. };
  8596. /*
  8597. * dp_soc_set_txrx_ring_map()
  8598. * @dp_soc: DP handler for soc
  8599. *
  8600. * Return: Void
  8601. */
  8602. void dp_soc_set_txrx_ring_map(struct dp_soc *soc)
  8603. {
  8604. uint32_t i;
  8605. for (i = 0; i < WLAN_CFG_INT_NUM_CONTEXTS; i++) {
  8606. soc->tx_ring_map[i] = dp_cpu_ring_map[DP_NSS_DEFAULT_MAP][i];
  8607. }
  8608. }
  8609. #if defined(QCA_WIFI_QCA8074) || defined(QCA_WIFI_QCA6018)
  8610. #ifndef QCA_MEM_ATTACH_ON_WIFI3
  8611. /**
  8612. * dp_soc_attach_wifi3() - Attach txrx SOC
  8613. * @ctrl_psoc: Opaque SOC handle from control plane
  8614. * @htc_handle: Opaque HTC handle
  8615. * @hif_handle: Opaque HIF handle
  8616. * @qdf_osdev: QDF device
  8617. * @ol_ops: Offload Operations
  8618. * @device_id: Device ID
  8619. *
  8620. * Return: DP SOC handle on success, NULL on failure
  8621. */
  8622. struct cdp_soc_t *
  8623. dp_soc_attach_wifi3(struct cdp_ctrl_objmgr_psoc *ctrl_psoc,
  8624. struct hif_opaque_softc *hif_handle,
  8625. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev,
  8626. struct ol_if_ops *ol_ops, uint16_t device_id)
  8627. {
  8628. struct dp_soc *dp_soc = NULL;
  8629. dp_soc = dp_soc_attach(ctrl_psoc, htc_handle, qdf_osdev,
  8630. ol_ops, device_id);
  8631. if (!dp_soc)
  8632. return NULL;
  8633. if (!dp_soc_init(dp_soc, htc_handle, hif_handle))
  8634. return NULL;
  8635. return dp_soc_to_cdp_soc_t(dp_soc);
  8636. }
  8637. #else
  8638. /**
  8639. * dp_soc_attach_wifi3() - Attach txrx SOC
  8640. * @ctrl_psoc: Opaque SOC handle from control plane
  8641. * @htc_handle: Opaque HTC handle
  8642. * @hif_handle: Opaque HIF handle
  8643. * @qdf_osdev: QDF device
  8644. * @ol_ops: Offload Operations
  8645. * @device_id: Device ID
  8646. *
  8647. * Return: DP SOC handle on success, NULL on failure
  8648. */
  8649. struct cdp_soc_t *
  8650. dp_soc_attach_wifi3(struct cdp_ctrl_objmgr_psoc *ctrl_psoc,
  8651. struct hif_opaque_softc *hif_handle,
  8652. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev,
  8653. struct ol_if_ops *ol_ops, uint16_t device_id)
  8654. {
  8655. struct dp_soc *dp_soc = NULL;
  8656. dp_soc = dp_soc_attach(ctrl_psoc, htc_handle, qdf_osdev,
  8657. ol_ops, device_id);
  8658. return dp_soc_to_cdp_soc_t(dp_soc);
  8659. }
  8660. #endif
  8661. /**
  8662. * dp_soc_attach() - Attach txrx SOC
  8663. * @ctrl_psoc: Opaque SOC handle from control plane
  8664. * @htc_handle: Opaque HTC handle
  8665. * @qdf_osdev: QDF device
  8666. * @ol_ops: Offload Operations
  8667. * @device_id: Device ID
  8668. *
  8669. * Return: DP SOC handle on success, NULL on failure
  8670. */
  8671. static struct dp_soc *
  8672. dp_soc_attach(struct cdp_ctrl_objmgr_psoc *ctrl_psoc, HTC_HANDLE htc_handle,
  8673. qdf_device_t qdf_osdev,
  8674. struct ol_if_ops *ol_ops, uint16_t device_id)
  8675. {
  8676. int int_ctx;
  8677. struct dp_soc *soc = NULL;
  8678. struct htt_soc *htt_soc;
  8679. soc = qdf_mem_malloc(sizeof(*soc));
  8680. if (!soc) {
  8681. dp_err("DP SOC memory allocation failed");
  8682. goto fail0;
  8683. }
  8684. int_ctx = 0;
  8685. soc->device_id = device_id;
  8686. soc->cdp_soc.ops = &dp_txrx_ops;
  8687. soc->cdp_soc.ol_ops = ol_ops;
  8688. soc->ctrl_psoc = ctrl_psoc;
  8689. soc->osdev = qdf_osdev;
  8690. soc->num_hw_dscp_tid_map = HAL_MAX_HW_DSCP_TID_MAPS;
  8691. wlan_set_srng_cfg(&soc->wlan_srng_cfg);
  8692. qdf_mem_zero(&soc->vdev_id_map, sizeof(soc->vdev_id_map));
  8693. soc->wlan_cfg_ctx = wlan_cfg_soc_attach(soc->ctrl_psoc);
  8694. if (!soc->wlan_cfg_ctx) {
  8695. dp_err("wlan_cfg_ctx failed\n");
  8696. goto fail1;
  8697. }
  8698. dp_soc_set_interrupt_mode(soc);
  8699. htt_soc = htt_soc_attach(soc, htc_handle);
  8700. if (!htt_soc)
  8701. goto fail1;
  8702. soc->htt_handle = htt_soc;
  8703. if (htt_soc_htc_prealloc(htt_soc) != QDF_STATUS_SUCCESS)
  8704. goto fail2;
  8705. return soc;
  8706. fail2:
  8707. htt_soc_detach(htt_soc);
  8708. fail1:
  8709. qdf_mem_free(soc);
  8710. fail0:
  8711. return NULL;
  8712. }
  8713. /**
  8714. * dp_soc_init() - Initialize txrx SOC
  8715. * @dp_soc: Opaque DP SOC handle
  8716. * @htc_handle: Opaque HTC handle
  8717. * @hif_handle: Opaque HIF handle
  8718. *
  8719. * Return: DP SOC handle on success, NULL on failure
  8720. */
  8721. void *dp_soc_init(void *dpsoc, HTC_HANDLE htc_handle,
  8722. struct hif_opaque_softc *hif_handle)
  8723. {
  8724. int target_type;
  8725. struct dp_soc *soc = (struct dp_soc *)dpsoc;
  8726. struct htt_soc *htt_soc = soc->htt_handle;
  8727. htt_set_htc_handle(htt_soc, htc_handle);
  8728. soc->hif_handle = hif_handle;
  8729. soc->hal_soc = hif_get_hal_handle(soc->hif_handle);
  8730. if (!soc->hal_soc)
  8731. return NULL;
  8732. htt_soc_initialize(soc->htt_handle, soc->ctrl_psoc,
  8733. htt_get_htc_handle(htt_soc),
  8734. soc->hal_soc, soc->osdev);
  8735. target_type = hal_get_target_type(soc->hal_soc);
  8736. switch (target_type) {
  8737. case TARGET_TYPE_QCA6290:
  8738. wlan_cfg_set_reo_dst_ring_size(soc->wlan_cfg_ctx,
  8739. REO_DST_RING_SIZE_QCA6290);
  8740. soc->ast_override_support = 1;
  8741. soc->da_war_enabled = false;
  8742. break;
  8743. #if defined(QCA_WIFI_QCA6390) || defined(QCA_WIFI_QCA6490)
  8744. case TARGET_TYPE_QCA6390:
  8745. case TARGET_TYPE_QCA6490:
  8746. wlan_cfg_set_reo_dst_ring_size(soc->wlan_cfg_ctx,
  8747. REO_DST_RING_SIZE_QCA6290);
  8748. wlan_cfg_set_raw_mode_war(soc->wlan_cfg_ctx, true);
  8749. soc->ast_override_support = 1;
  8750. if (soc->cdp_soc.ol_ops->get_con_mode &&
  8751. soc->cdp_soc.ol_ops->get_con_mode() ==
  8752. QDF_GLOBAL_MONITOR_MODE) {
  8753. int int_ctx;
  8754. for (int_ctx = 0; int_ctx < WLAN_CFG_INT_NUM_CONTEXTS; int_ctx++) {
  8755. soc->wlan_cfg_ctx->int_rx_ring_mask[int_ctx] = 0;
  8756. soc->wlan_cfg_ctx->int_rxdma2host_ring_mask[int_ctx] = 0;
  8757. }
  8758. }
  8759. soc->wlan_cfg_ctx->rxdma1_enable = 0;
  8760. break;
  8761. #endif /* QCA_WIFI_QCA6390 || QCA_WIFI_QCA6490 */
  8762. case TARGET_TYPE_QCA8074:
  8763. wlan_cfg_set_reo_dst_ring_size(soc->wlan_cfg_ctx,
  8764. REO_DST_RING_SIZE_QCA8074);
  8765. wlan_cfg_set_raw_mode_war(soc->wlan_cfg_ctx, true);
  8766. soc->da_war_enabled = true;
  8767. soc->is_rx_fse_full_cache_invalidate_war_enabled = true;
  8768. break;
  8769. case TARGET_TYPE_QCA8074V2:
  8770. case TARGET_TYPE_QCA6018:
  8771. wlan_cfg_set_reo_dst_ring_size(soc->wlan_cfg_ctx,
  8772. REO_DST_RING_SIZE_QCA8074);
  8773. wlan_cfg_set_raw_mode_war(soc->wlan_cfg_ctx, false);
  8774. soc->hw_nac_monitor_support = 1;
  8775. soc->ast_override_support = 1;
  8776. soc->per_tid_basize_max_tid = 8;
  8777. soc->num_hw_dscp_tid_map = HAL_MAX_HW_DSCP_TID_V2_MAPS;
  8778. soc->da_war_enabled = false;
  8779. soc->is_rx_fse_full_cache_invalidate_war_enabled = true;
  8780. break;
  8781. case TARGET_TYPE_QCN9000:
  8782. wlan_cfg_set_reo_dst_ring_size(soc->wlan_cfg_ctx,
  8783. REO_DST_RING_SIZE_QCN9000);
  8784. soc->ast_override_support = 1;
  8785. soc->da_war_enabled = false;
  8786. wlan_cfg_set_raw_mode_war(soc->wlan_cfg_ctx, false);
  8787. soc->hw_nac_monitor_support = 1;
  8788. soc->per_tid_basize_max_tid = 8;
  8789. soc->num_hw_dscp_tid_map = HAL_MAX_HW_DSCP_TID_V2_MAPS;
  8790. break;
  8791. default:
  8792. qdf_print("%s: Unknown tgt type %d\n", __func__, target_type);
  8793. qdf_assert_always(0);
  8794. break;
  8795. }
  8796. wlan_cfg_set_rx_hash(soc->wlan_cfg_ctx,
  8797. cfg_get(soc->ctrl_psoc, CFG_DP_RX_HASH));
  8798. soc->cce_disable = false;
  8799. qdf_atomic_init(&soc->num_tx_outstanding);
  8800. soc->num_tx_allowed =
  8801. wlan_cfg_get_dp_soc_tx_device_limit(soc->wlan_cfg_ctx);
  8802. if (soc->cdp_soc.ol_ops->get_dp_cfg_param) {
  8803. int ret = soc->cdp_soc.ol_ops->get_dp_cfg_param(soc->ctrl_psoc,
  8804. CDP_CFG_MAX_PEER_ID);
  8805. if (ret != -EINVAL) {
  8806. wlan_cfg_set_max_peer_id(soc->wlan_cfg_ctx, ret);
  8807. }
  8808. ret = soc->cdp_soc.ol_ops->get_dp_cfg_param(soc->ctrl_psoc,
  8809. CDP_CFG_CCE_DISABLE);
  8810. if (ret == 1)
  8811. soc->cce_disable = true;
  8812. }
  8813. qdf_spinlock_create(&soc->peer_ref_mutex);
  8814. qdf_spinlock_create(&soc->ast_lock);
  8815. qdf_spinlock_create(&soc->reo_desc_freelist_lock);
  8816. qdf_list_create(&soc->reo_desc_freelist, REO_DESC_FREELIST_SIZE);
  8817. /* fill the tx/rx cpu ring map*/
  8818. dp_soc_set_txrx_ring_map(soc);
  8819. qdf_spinlock_create(&soc->htt_stats.lock);
  8820. /* initialize work queue for stats processing */
  8821. qdf_create_work(0, &soc->htt_stats.work, htt_t2h_stats_handler, soc);
  8822. return soc;
  8823. }
  8824. /**
  8825. * dp_soc_init_wifi3() - Initialize txrx SOC
  8826. * @dp_soc: Opaque DP SOC handle
  8827. * @ctrl_psoc: Opaque SOC handle from control plane(Unused)
  8828. * @hif_handle: Opaque HIF handle
  8829. * @htc_handle: Opaque HTC handle
  8830. * @qdf_osdev: QDF device (Unused)
  8831. * @ol_ops: Offload Operations (Unused)
  8832. * @device_id: Device ID (Unused)
  8833. *
  8834. * Return: DP SOC handle on success, NULL on failure
  8835. */
  8836. void *dp_soc_init_wifi3(void *dpsoc, struct cdp_ctrl_objmgr_psoc *ctrl_psoc,
  8837. struct hif_opaque_softc *hif_handle,
  8838. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev,
  8839. struct ol_if_ops *ol_ops, uint16_t device_id)
  8840. {
  8841. return dp_soc_init(dpsoc, htc_handle, hif_handle);
  8842. }
  8843. #endif
  8844. /*
  8845. * dp_get_pdev_for_mac_id() - Return pdev for mac_id
  8846. *
  8847. * @soc: handle to DP soc
  8848. * @mac_id: MAC id
  8849. *
  8850. * Return: Return pdev corresponding to MAC
  8851. */
  8852. void *dp_get_pdev_for_mac_id(struct dp_soc *soc, uint32_t mac_id)
  8853. {
  8854. if (wlan_cfg_per_pdev_lmac_ring(soc->wlan_cfg_ctx))
  8855. return soc->pdev_list[mac_id];
  8856. /* Typically for MCL as there only 1 PDEV*/
  8857. return soc->pdev_list[0];
  8858. }
  8859. /*
  8860. * dp_is_hw_dbs_enable() - Procedure to check if DBS is supported
  8861. * @soc: DP SoC context
  8862. * @max_mac_rings: No of MAC rings
  8863. *
  8864. * Return: None
  8865. */
  8866. static
  8867. void dp_is_hw_dbs_enable(struct dp_soc *soc,
  8868. int *max_mac_rings)
  8869. {
  8870. bool dbs_enable = false;
  8871. if (soc->cdp_soc.ol_ops->is_hw_dbs_2x2_capable)
  8872. dbs_enable = soc->cdp_soc.ol_ops->
  8873. is_hw_dbs_2x2_capable((void *)soc->ctrl_psoc);
  8874. *max_mac_rings = (dbs_enable)?(*max_mac_rings):1;
  8875. }
  8876. /*
  8877. * dp_is_soc_reinit() - Check if soc reinit is true
  8878. * @soc: DP SoC context
  8879. *
  8880. * Return: true or false
  8881. */
  8882. bool dp_is_soc_reinit(struct dp_soc *soc)
  8883. {
  8884. return soc->dp_soc_reinit;
  8885. }
  8886. /*
  8887. * dp_set_pktlog_wifi3() - attach txrx vdev
  8888. * @pdev: Datapath PDEV handle
  8889. * @event: which event's notifications are being subscribed to
  8890. * @enable: WDI event subscribe or not. (True or False)
  8891. *
  8892. * Return: Success, NULL on failure
  8893. */
  8894. #ifdef WDI_EVENT_ENABLE
  8895. int dp_set_pktlog_wifi3(struct dp_pdev *pdev, uint32_t event,
  8896. bool enable)
  8897. {
  8898. struct dp_soc *soc = NULL;
  8899. struct htt_rx_ring_tlv_filter htt_tlv_filter = {0};
  8900. int max_mac_rings = wlan_cfg_get_num_mac_rings
  8901. (pdev->wlan_cfg_ctx);
  8902. uint8_t mac_id = 0;
  8903. soc = pdev->soc;
  8904. dp_is_hw_dbs_enable(soc, &max_mac_rings);
  8905. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  8906. FL("Max_mac_rings %d "),
  8907. max_mac_rings);
  8908. if (enable) {
  8909. switch (event) {
  8910. case WDI_EVENT_RX_DESC:
  8911. if (pdev->monitor_vdev) {
  8912. /* Nothing needs to be done if monitor mode is
  8913. * enabled
  8914. */
  8915. return 0;
  8916. }
  8917. if (pdev->rx_pktlog_mode != DP_RX_PKTLOG_FULL) {
  8918. pdev->rx_pktlog_mode = DP_RX_PKTLOG_FULL;
  8919. htt_tlv_filter.mpdu_start = 1;
  8920. htt_tlv_filter.msdu_start = 1;
  8921. htt_tlv_filter.msdu_end = 1;
  8922. htt_tlv_filter.mpdu_end = 1;
  8923. htt_tlv_filter.packet_header = 1;
  8924. htt_tlv_filter.attention = 1;
  8925. htt_tlv_filter.ppdu_start = 1;
  8926. htt_tlv_filter.ppdu_end = 1;
  8927. htt_tlv_filter.ppdu_end_user_stats = 1;
  8928. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  8929. htt_tlv_filter.ppdu_end_status_done = 1;
  8930. htt_tlv_filter.enable_fp = 1;
  8931. htt_tlv_filter.fp_mgmt_filter = FILTER_MGMT_ALL;
  8932. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_ALL;
  8933. htt_tlv_filter.fp_data_filter = FILTER_DATA_ALL;
  8934. htt_tlv_filter.mo_mgmt_filter = FILTER_MGMT_ALL;
  8935. htt_tlv_filter.mo_ctrl_filter = FILTER_CTRL_ALL;
  8936. htt_tlv_filter.mo_data_filter = FILTER_DATA_ALL;
  8937. htt_tlv_filter.offset_valid = false;
  8938. for (mac_id = 0; mac_id < max_mac_rings;
  8939. mac_id++) {
  8940. int mac_for_pdev =
  8941. dp_get_mac_id_for_pdev(mac_id,
  8942. pdev->pdev_id);
  8943. htt_h2t_rx_ring_cfg(soc->htt_handle,
  8944. mac_for_pdev,
  8945. pdev->rxdma_mon_status_ring[mac_id]
  8946. .hal_srng,
  8947. RXDMA_MONITOR_STATUS,
  8948. RX_BUFFER_SIZE,
  8949. &htt_tlv_filter);
  8950. }
  8951. if (soc->reap_timer_init)
  8952. qdf_timer_mod(&soc->mon_reap_timer,
  8953. DP_INTR_POLL_TIMER_MS);
  8954. }
  8955. break;
  8956. case WDI_EVENT_LITE_RX:
  8957. if (pdev->monitor_vdev) {
  8958. /* Nothing needs to be done if monitor mode is
  8959. * enabled
  8960. */
  8961. return 0;
  8962. }
  8963. if (pdev->rx_pktlog_mode != DP_RX_PKTLOG_LITE) {
  8964. pdev->rx_pktlog_mode = DP_RX_PKTLOG_LITE;
  8965. htt_tlv_filter.ppdu_start = 1;
  8966. htt_tlv_filter.ppdu_end = 1;
  8967. htt_tlv_filter.ppdu_end_user_stats = 1;
  8968. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  8969. htt_tlv_filter.ppdu_end_status_done = 1;
  8970. htt_tlv_filter.mpdu_start = 1;
  8971. htt_tlv_filter.enable_fp = 1;
  8972. htt_tlv_filter.fp_mgmt_filter = FILTER_MGMT_ALL;
  8973. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_ALL;
  8974. htt_tlv_filter.fp_data_filter = FILTER_DATA_ALL;
  8975. htt_tlv_filter.mo_mgmt_filter = FILTER_MGMT_ALL;
  8976. htt_tlv_filter.mo_ctrl_filter = FILTER_CTRL_ALL;
  8977. htt_tlv_filter.mo_data_filter = FILTER_DATA_ALL;
  8978. htt_tlv_filter.offset_valid = false;
  8979. for (mac_id = 0; mac_id < max_mac_rings;
  8980. mac_id++) {
  8981. int mac_for_pdev =
  8982. dp_get_mac_id_for_pdev(mac_id,
  8983. pdev->pdev_id);
  8984. htt_h2t_rx_ring_cfg(soc->htt_handle,
  8985. mac_for_pdev,
  8986. pdev->rxdma_mon_status_ring[mac_id]
  8987. .hal_srng,
  8988. RXDMA_MONITOR_STATUS,
  8989. RX_BUFFER_SIZE_PKTLOG_LITE,
  8990. &htt_tlv_filter);
  8991. }
  8992. if (soc->reap_timer_init)
  8993. qdf_timer_mod(&soc->mon_reap_timer,
  8994. DP_INTR_POLL_TIMER_MS);
  8995. }
  8996. break;
  8997. case WDI_EVENT_LITE_T2H:
  8998. if (pdev->monitor_vdev) {
  8999. /* Nothing needs to be done if monitor mode is
  9000. * enabled
  9001. */
  9002. return 0;
  9003. }
  9004. for (mac_id = 0; mac_id < max_mac_rings; mac_id++) {
  9005. int mac_for_pdev = dp_get_mac_id_for_pdev(
  9006. mac_id, pdev->pdev_id);
  9007. pdev->pktlog_ppdu_stats = true;
  9008. dp_h2t_cfg_stats_msg_send(pdev,
  9009. DP_PPDU_TXLITE_STATS_BITMASK_CFG,
  9010. mac_for_pdev);
  9011. }
  9012. break;
  9013. default:
  9014. /* Nothing needs to be done for other pktlog types */
  9015. break;
  9016. }
  9017. } else {
  9018. switch (event) {
  9019. case WDI_EVENT_RX_DESC:
  9020. case WDI_EVENT_LITE_RX:
  9021. if (pdev->monitor_vdev) {
  9022. /* Nothing needs to be done if monitor mode is
  9023. * enabled
  9024. */
  9025. return 0;
  9026. }
  9027. if (pdev->rx_pktlog_mode != DP_RX_PKTLOG_DISABLED) {
  9028. pdev->rx_pktlog_mode = DP_RX_PKTLOG_DISABLED;
  9029. for (mac_id = 0; mac_id < max_mac_rings;
  9030. mac_id++) {
  9031. int mac_for_pdev =
  9032. dp_get_mac_id_for_pdev(mac_id,
  9033. pdev->pdev_id);
  9034. htt_h2t_rx_ring_cfg(soc->htt_handle,
  9035. mac_for_pdev,
  9036. pdev->rxdma_mon_status_ring[mac_id]
  9037. .hal_srng,
  9038. RXDMA_MONITOR_STATUS,
  9039. RX_BUFFER_SIZE,
  9040. &htt_tlv_filter);
  9041. }
  9042. if (soc->reap_timer_init)
  9043. qdf_timer_stop(&soc->mon_reap_timer);
  9044. }
  9045. break;
  9046. case WDI_EVENT_LITE_T2H:
  9047. if (pdev->monitor_vdev) {
  9048. /* Nothing needs to be done if monitor mode is
  9049. * enabled
  9050. */
  9051. return 0;
  9052. }
  9053. /* To disable HTT_H2T_MSG_TYPE_PPDU_STATS_CFG in FW
  9054. * passing value 0. Once these macros will define in htt
  9055. * header file will use proper macros
  9056. */
  9057. for (mac_id = 0; mac_id < max_mac_rings; mac_id++) {
  9058. int mac_for_pdev =
  9059. dp_get_mac_id_for_pdev(mac_id,
  9060. pdev->pdev_id);
  9061. pdev->pktlog_ppdu_stats = false;
  9062. if (!pdev->enhanced_stats_en && !pdev->tx_sniffer_enable && !pdev->mcopy_mode) {
  9063. dp_h2t_cfg_stats_msg_send(pdev, 0,
  9064. mac_for_pdev);
  9065. } else if (pdev->tx_sniffer_enable || pdev->mcopy_mode) {
  9066. dp_h2t_cfg_stats_msg_send(pdev, DP_PPDU_STATS_CFG_SNIFFER,
  9067. mac_for_pdev);
  9068. } else if (pdev->enhanced_stats_en) {
  9069. dp_h2t_cfg_stats_msg_send(pdev, DP_PPDU_STATS_CFG_ENH_STATS,
  9070. mac_for_pdev);
  9071. }
  9072. }
  9073. break;
  9074. default:
  9075. /* Nothing needs to be done for other pktlog types */
  9076. break;
  9077. }
  9078. }
  9079. return 0;
  9080. }
  9081. #endif
  9082. /**
  9083. * dp_bucket_index() - Return index from array
  9084. *
  9085. * @delay: delay measured
  9086. * @array: array used to index corresponding delay
  9087. *
  9088. * Return: index
  9089. */
  9090. static uint8_t dp_bucket_index(uint32_t delay, uint16_t *array)
  9091. {
  9092. uint8_t i = CDP_DELAY_BUCKET_0;
  9093. for (; i < CDP_DELAY_BUCKET_MAX; i++) {
  9094. if (delay >= array[i] && delay <= array[i + 1])
  9095. return i;
  9096. }
  9097. return (CDP_DELAY_BUCKET_MAX - 1);
  9098. }
  9099. /**
  9100. * dp_fill_delay_buckets() - Fill delay statistics bucket for each
  9101. * type of delay
  9102. *
  9103. * @pdev: pdev handle
  9104. * @delay: delay in ms
  9105. * @tid: tid value
  9106. * @mode: type of tx delay mode
  9107. * @ring_id: ring number
  9108. * Return: pointer to cdp_delay_stats structure
  9109. */
  9110. static struct cdp_delay_stats *
  9111. dp_fill_delay_buckets(struct dp_pdev *pdev, uint32_t delay,
  9112. uint8_t tid, uint8_t mode, uint8_t ring_id)
  9113. {
  9114. uint8_t delay_index = 0;
  9115. struct cdp_tid_tx_stats *tstats =
  9116. &pdev->stats.tid_stats.tid_tx_stats[ring_id][tid];
  9117. struct cdp_tid_rx_stats *rstats =
  9118. &pdev->stats.tid_stats.tid_rx_stats[ring_id][tid];
  9119. /*
  9120. * cdp_fw_to_hw_delay_range
  9121. * Fw to hw delay ranges in milliseconds
  9122. */
  9123. uint16_t cdp_fw_to_hw_delay[CDP_DELAY_BUCKET_MAX] = {
  9124. 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 250, 500};
  9125. /*
  9126. * cdp_sw_enq_delay_range
  9127. * Software enqueue delay ranges in milliseconds
  9128. */
  9129. uint16_t cdp_sw_enq_delay[CDP_DELAY_BUCKET_MAX] = {
  9130. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
  9131. /*
  9132. * cdp_intfrm_delay_range
  9133. * Interframe delay ranges in milliseconds
  9134. */
  9135. uint16_t cdp_intfrm_delay[CDP_DELAY_BUCKET_MAX] = {
  9136. 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60};
  9137. /*
  9138. * Update delay stats in proper bucket
  9139. */
  9140. switch (mode) {
  9141. /* Software Enqueue delay ranges */
  9142. case CDP_DELAY_STATS_SW_ENQ:
  9143. delay_index = dp_bucket_index(delay, cdp_sw_enq_delay);
  9144. tstats->swq_delay.delay_bucket[delay_index]++;
  9145. return &tstats->swq_delay;
  9146. /* Tx Completion delay ranges */
  9147. case CDP_DELAY_STATS_FW_HW_TRANSMIT:
  9148. delay_index = dp_bucket_index(delay, cdp_fw_to_hw_delay);
  9149. tstats->hwtx_delay.delay_bucket[delay_index]++;
  9150. return &tstats->hwtx_delay;
  9151. /* Interframe tx delay ranges */
  9152. case CDP_DELAY_STATS_TX_INTERFRAME:
  9153. delay_index = dp_bucket_index(delay, cdp_intfrm_delay);
  9154. tstats->intfrm_delay.delay_bucket[delay_index]++;
  9155. return &tstats->intfrm_delay;
  9156. /* Interframe rx delay ranges */
  9157. case CDP_DELAY_STATS_RX_INTERFRAME:
  9158. delay_index = dp_bucket_index(delay, cdp_intfrm_delay);
  9159. rstats->intfrm_delay.delay_bucket[delay_index]++;
  9160. return &rstats->intfrm_delay;
  9161. /* Ring reap to indication to network stack */
  9162. case CDP_DELAY_STATS_REAP_STACK:
  9163. delay_index = dp_bucket_index(delay, cdp_intfrm_delay);
  9164. rstats->to_stack_delay.delay_bucket[delay_index]++;
  9165. return &rstats->to_stack_delay;
  9166. default:
  9167. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  9168. "%s Incorrect delay mode: %d", __func__, mode);
  9169. }
  9170. return NULL;
  9171. }
  9172. /**
  9173. * dp_update_delay_stats() - Update delay statistics in structure
  9174. * and fill min, max and avg delay
  9175. *
  9176. * @pdev: pdev handle
  9177. * @delay: delay in ms
  9178. * @tid: tid value
  9179. * @mode: type of tx delay mode
  9180. * @ring id: ring number
  9181. * Return: none
  9182. */
  9183. void dp_update_delay_stats(struct dp_pdev *pdev, uint32_t delay,
  9184. uint8_t tid, uint8_t mode, uint8_t ring_id)
  9185. {
  9186. struct cdp_delay_stats *dstats = NULL;
  9187. /*
  9188. * Delay ranges are different for different delay modes
  9189. * Get the correct index to update delay bucket
  9190. */
  9191. dstats = dp_fill_delay_buckets(pdev, delay, tid, mode, ring_id);
  9192. if (qdf_unlikely(!dstats))
  9193. return;
  9194. if (delay != 0) {
  9195. /*
  9196. * Compute minimum,average and maximum
  9197. * delay
  9198. */
  9199. if (delay < dstats->min_delay)
  9200. dstats->min_delay = delay;
  9201. if (delay > dstats->max_delay)
  9202. dstats->max_delay = delay;
  9203. /*
  9204. * Average over delay measured till now
  9205. */
  9206. if (!dstats->avg_delay)
  9207. dstats->avg_delay = delay;
  9208. else
  9209. dstats->avg_delay = ((delay + dstats->avg_delay) / 2);
  9210. }
  9211. }