dp_main.c 309 KB

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