dp_main.c 263 KB

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