dp_main.c 268 KB

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