dp_main.c 277 KB

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