dp_main.c 263 KB

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