dp_main.c 310 KB

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