dp_main.c 282 KB

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