dp_main.c 309 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651
  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 void *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: DP PDEV handle on success, NULL on failure
  3097. */
  3098. static struct cdp_pdev *dp_pdev_attach_wifi3(struct cdp_soc_t *txrx_soc,
  3099. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev, uint8_t pdev_id)
  3100. {
  3101. int ring_size;
  3102. int entries;
  3103. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx;
  3104. int nss_cfg;
  3105. void *sojourn_buf;
  3106. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  3107. struct dp_pdev *pdev = NULL;
  3108. if (dp_is_soc_reinit(soc)) {
  3109. pdev = soc->pdev_list[pdev_id];
  3110. } else {
  3111. pdev = qdf_mem_malloc(sizeof(*pdev));
  3112. qdf_minidump_log(pdev, sizeof(*pdev), "dp_pdev");
  3113. }
  3114. if (!pdev) {
  3115. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3116. FL("DP PDEV memory allocation failed"));
  3117. goto fail0;
  3118. }
  3119. /*
  3120. * Variable to prevent double pdev deinitialization during
  3121. * radio detach execution .i.e. in the absence of any vdev.
  3122. */
  3123. pdev->pdev_deinit = 0;
  3124. pdev->invalid_peer = qdf_mem_malloc(sizeof(struct dp_peer));
  3125. if (!pdev->invalid_peer) {
  3126. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3127. FL("Invalid peer memory allocation failed"));
  3128. qdf_mem_free(pdev);
  3129. goto fail0;
  3130. }
  3131. soc_cfg_ctx = soc->wlan_cfg_ctx;
  3132. pdev->wlan_cfg_ctx = wlan_cfg_pdev_attach(soc->ctrl_psoc);
  3133. if (!pdev->wlan_cfg_ctx) {
  3134. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3135. FL("pdev cfg_attach failed"));
  3136. qdf_mem_free(pdev->invalid_peer);
  3137. qdf_mem_free(pdev);
  3138. goto fail0;
  3139. }
  3140. /*
  3141. * set nss pdev config based on soc config
  3142. */
  3143. nss_cfg = wlan_cfg_get_dp_soc_nss_cfg(soc_cfg_ctx);
  3144. wlan_cfg_set_dp_pdev_nss_enabled(pdev->wlan_cfg_ctx,
  3145. (nss_cfg & (1 << pdev_id)));
  3146. pdev->soc = soc;
  3147. pdev->pdev_id = pdev_id;
  3148. soc->pdev_list[pdev_id] = pdev;
  3149. pdev->lmac_id = wlan_cfg_get_hw_mac_idx(soc->wlan_cfg_ctx, pdev_id);
  3150. soc->pdev_count++;
  3151. TAILQ_INIT(&pdev->vdev_list);
  3152. qdf_spinlock_create(&pdev->vdev_list_lock);
  3153. pdev->vdev_count = 0;
  3154. qdf_spinlock_create(&pdev->tx_mutex);
  3155. qdf_spinlock_create(&pdev->neighbour_peer_mutex);
  3156. TAILQ_INIT(&pdev->neighbour_peers_list);
  3157. pdev->neighbour_peers_added = false;
  3158. pdev->monitor_configured = false;
  3159. if (dp_soc_cmn_setup(soc)) {
  3160. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3161. FL("dp_soc_cmn_setup failed"));
  3162. goto fail1;
  3163. }
  3164. /* Setup per PDEV TCL rings if configured */
  3165. if (wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  3166. ring_size =
  3167. wlan_cfg_tx_ring_size(soc_cfg_ctx);
  3168. if (dp_srng_setup(soc, &soc->tcl_data_ring[pdev_id], TCL_DATA,
  3169. pdev_id, pdev_id, ring_size, 0)) {
  3170. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3171. FL("dp_srng_setup failed for tcl_data_ring"));
  3172. goto fail1;
  3173. }
  3174. ring_size =
  3175. wlan_cfg_tx_comp_ring_size(soc_cfg_ctx);
  3176. if (dp_srng_setup(soc, &soc->tx_comp_ring[pdev_id],
  3177. WBM2SW_RELEASE, pdev_id, pdev_id,
  3178. ring_size, 0)) {
  3179. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3180. FL("dp_srng_setup failed for tx_comp_ring"));
  3181. goto fail1;
  3182. }
  3183. soc->num_tcl_data_rings++;
  3184. }
  3185. /* Tx specific init */
  3186. if (dp_tx_pdev_attach(pdev)) {
  3187. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3188. FL("dp_tx_pdev_attach failed"));
  3189. goto fail1;
  3190. }
  3191. ring_size = wlan_cfg_get_reo_dst_ring_size(soc->wlan_cfg_ctx);
  3192. /* Setup per PDEV REO rings if configured */
  3193. if (wlan_cfg_per_pdev_rx_ring(soc_cfg_ctx)) {
  3194. if (dp_srng_setup(soc, &soc->reo_dest_ring[pdev_id], REO_DST,
  3195. pdev_id, pdev_id, ring_size, 0)) {
  3196. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3197. FL("dp_srng_setup failed for reo_dest_ringn"));
  3198. goto fail1;
  3199. }
  3200. soc->num_reo_dest_rings++;
  3201. }
  3202. ring_size =
  3203. wlan_cfg_get_dp_soc_rxdma_refill_ring_size(soc->wlan_cfg_ctx);
  3204. if (dp_srng_setup(soc, &soc->rx_refill_buf_ring[pdev->lmac_id],
  3205. RXDMA_BUF, 0, pdev->lmac_id, ring_size, 0)) {
  3206. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3207. FL("dp_srng_setup failed rx refill ring"));
  3208. goto fail1;
  3209. }
  3210. if (dp_rxdma_ring_setup(soc, pdev)) {
  3211. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3212. FL("RXDMA ring config failed"));
  3213. goto fail1;
  3214. }
  3215. if (dp_mon_rings_setup(soc, pdev)) {
  3216. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3217. FL("MONITOR rings setup failed"));
  3218. goto fail1;
  3219. }
  3220. entries = wlan_cfg_get_dp_soc_rxdma_err_dst_ring_size(soc_cfg_ctx);
  3221. if (wlan_cfg_per_pdev_lmac_ring(soc->wlan_cfg_ctx)) {
  3222. if (dp_srng_setup(soc,
  3223. &soc->rxdma_err_dst_ring[pdev->lmac_id],
  3224. RXDMA_DST,
  3225. 0, pdev->lmac_id, entries, 0)) {
  3226. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3227. FL(RNG_ERR "rxdma_err_dst_ring"));
  3228. goto fail1;
  3229. }
  3230. }
  3231. if (dp_setup_ipa_rx_refill_buf_ring(soc, pdev))
  3232. goto fail1;
  3233. if (dp_ipa_ring_resource_setup(soc, pdev))
  3234. goto fail1;
  3235. if (dp_ipa_uc_attach(soc, pdev) != QDF_STATUS_SUCCESS) {
  3236. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3237. FL("dp_ipa_uc_attach failed"));
  3238. goto fail1;
  3239. }
  3240. /* Rx specific init */
  3241. if (dp_rx_pdev_attach(pdev)) {
  3242. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  3243. FL("dp_rx_pdev_attach failed"));
  3244. goto fail2;
  3245. }
  3246. DP_STATS_INIT(pdev);
  3247. /* Monitor filter init */
  3248. pdev->mon_filter_mode = MON_FILTER_ALL;
  3249. pdev->fp_mgmt_filter = FILTER_MGMT_ALL;
  3250. pdev->fp_ctrl_filter = FILTER_CTRL_ALL;
  3251. pdev->fp_data_filter = FILTER_DATA_ALL;
  3252. pdev->mo_mgmt_filter = FILTER_MGMT_ALL;
  3253. pdev->mo_ctrl_filter = FILTER_CTRL_ALL;
  3254. pdev->mo_data_filter = FILTER_DATA_ALL;
  3255. dp_local_peer_id_pool_init(pdev);
  3256. dp_dscp_tid_map_setup(pdev);
  3257. dp_pcp_tid_map_setup(pdev);
  3258. /* Rx monitor mode specific init */
  3259. if (dp_rx_pdev_mon_attach(pdev)) {
  3260. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  3261. "dp_rx_pdev_mon_attach failed");
  3262. goto fail2;
  3263. }
  3264. if (dp_wdi_event_attach(pdev)) {
  3265. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  3266. "dp_wdi_evet_attach failed");
  3267. goto wdi_attach_fail;
  3268. }
  3269. /* set the reo destination during initialization */
  3270. pdev->reo_dest = pdev->pdev_id + 1;
  3271. /*
  3272. * initialize ppdu tlv list
  3273. */
  3274. TAILQ_INIT(&pdev->ppdu_info_list);
  3275. pdev->tlv_count = 0;
  3276. pdev->list_depth = 0;
  3277. qdf_mem_zero(&pdev->sojourn_stats, sizeof(struct cdp_tx_sojourn_stats));
  3278. pdev->sojourn_buf = qdf_nbuf_alloc(pdev->soc->osdev,
  3279. sizeof(struct cdp_tx_sojourn_stats), 0, 4,
  3280. TRUE);
  3281. if (pdev->sojourn_buf) {
  3282. sojourn_buf = qdf_nbuf_data(pdev->sojourn_buf);
  3283. qdf_mem_zero(sojourn_buf, sizeof(struct cdp_tx_sojourn_stats));
  3284. }
  3285. /* initlialize cal client timer */
  3286. dp_cal_client_attach(&pdev->cal_client_ctx,
  3287. dp_pdev_to_cdp_pdev(pdev),
  3288. pdev->soc->osdev,
  3289. &dp_iterate_update_peer_list);
  3290. qdf_event_create(&pdev->fw_peer_stats_event);
  3291. pdev->num_tx_allowed = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  3292. dp_init_tso_stats(pdev);
  3293. if (dp_htt_ppdu_stats_attach(pdev) != QDF_STATUS_SUCCESS)
  3294. goto fail1;
  3295. dp_tx_ppdu_stats_attach(pdev);
  3296. return (struct cdp_pdev *)pdev;
  3297. wdi_attach_fail:
  3298. /*
  3299. * dp_mon_link_desc_pool_cleanup is done in dp_pdev_detach
  3300. * and hence need not to be done here.
  3301. */
  3302. dp_rx_pdev_mon_detach(pdev);
  3303. fail2:
  3304. dp_rx_pdev_detach(pdev);
  3305. fail1:
  3306. if (pdev->invalid_peer)
  3307. qdf_mem_free(pdev->invalid_peer);
  3308. dp_pdev_detach((struct cdp_pdev *)pdev, 0);
  3309. fail0:
  3310. return NULL;
  3311. }
  3312. /*
  3313. * dp_rxdma_ring_cleanup() - configure the RX DMA rings
  3314. * @soc: data path SoC handle
  3315. * @pdev: Physical device handle
  3316. *
  3317. * Return: void
  3318. */
  3319. #ifdef QCA_HOST2FW_RXBUF_RING
  3320. static void dp_rxdma_ring_cleanup(struct dp_soc *soc,
  3321. struct dp_pdev *pdev)
  3322. {
  3323. int i;
  3324. for (i = 0; i < MAX_RX_MAC_RINGS; i++)
  3325. dp_srng_cleanup(soc, &pdev->rx_mac_buf_ring[i],
  3326. RXDMA_BUF, 1);
  3327. if (soc->reap_timer_init) {
  3328. qdf_timer_free(&soc->mon_reap_timer);
  3329. soc->reap_timer_init = 0;
  3330. }
  3331. }
  3332. #else
  3333. static void dp_rxdma_ring_cleanup(struct dp_soc *soc,
  3334. struct dp_pdev *pdev)
  3335. {
  3336. if (soc->lmac_timer_init) {
  3337. qdf_timer_stop(&soc->lmac_reap_timer);
  3338. qdf_timer_free(&soc->lmac_reap_timer);
  3339. soc->lmac_timer_init = 0;
  3340. }
  3341. }
  3342. #endif
  3343. /*
  3344. * dp_neighbour_peers_detach() - Detach neighbour peers(nac clients)
  3345. * @pdev: device object
  3346. *
  3347. * Return: void
  3348. */
  3349. static void dp_neighbour_peers_detach(struct dp_pdev *pdev)
  3350. {
  3351. struct dp_neighbour_peer *peer = NULL;
  3352. struct dp_neighbour_peer *temp_peer = NULL;
  3353. TAILQ_FOREACH_SAFE(peer, &pdev->neighbour_peers_list,
  3354. neighbour_peer_list_elem, temp_peer) {
  3355. /* delete this peer from the list */
  3356. TAILQ_REMOVE(&pdev->neighbour_peers_list,
  3357. peer, neighbour_peer_list_elem);
  3358. qdf_mem_free(peer);
  3359. }
  3360. qdf_spinlock_destroy(&pdev->neighbour_peer_mutex);
  3361. }
  3362. /**
  3363. * dp_htt_ppdu_stats_detach() - detach stats resources
  3364. * @pdev: Datapath PDEV handle
  3365. *
  3366. * Return: void
  3367. */
  3368. static void dp_htt_ppdu_stats_detach(struct dp_pdev *pdev)
  3369. {
  3370. struct ppdu_info *ppdu_info, *ppdu_info_next;
  3371. TAILQ_FOREACH_SAFE(ppdu_info, &pdev->ppdu_info_list,
  3372. ppdu_info_list_elem, ppdu_info_next) {
  3373. if (!ppdu_info)
  3374. break;
  3375. qdf_assert_always(ppdu_info->nbuf);
  3376. qdf_nbuf_free(ppdu_info->nbuf);
  3377. qdf_mem_free(ppdu_info);
  3378. }
  3379. if (pdev->ppdu_tlv_buf)
  3380. qdf_mem_free(pdev->ppdu_tlv_buf);
  3381. }
  3382. #if !defined(DISABLE_MON_CONFIG)
  3383. static
  3384. void dp_mon_ring_cleanup(struct dp_soc *soc, struct dp_pdev *pdev,
  3385. int mac_id)
  3386. {
  3387. if (soc->wlan_cfg_ctx->rxdma1_enable) {
  3388. dp_srng_cleanup(soc,
  3389. &soc->rxdma_mon_buf_ring[mac_id],
  3390. RXDMA_MONITOR_BUF, 0);
  3391. dp_srng_cleanup(soc,
  3392. &soc->rxdma_mon_dst_ring[mac_id],
  3393. RXDMA_MONITOR_DST, 0);
  3394. dp_srng_cleanup(soc,
  3395. &soc->rxdma_mon_status_ring[mac_id],
  3396. RXDMA_MONITOR_STATUS, 0);
  3397. dp_srng_cleanup(soc,
  3398. &soc->rxdma_mon_desc_ring[mac_id],
  3399. RXDMA_MONITOR_DESC, 0);
  3400. dp_srng_cleanup(soc,
  3401. &soc->rxdma_err_dst_ring[mac_id],
  3402. RXDMA_DST, 0);
  3403. } else {
  3404. dp_srng_cleanup(soc,
  3405. &soc->rxdma_mon_status_ring[mac_id],
  3406. RXDMA_MONITOR_STATUS, 0);
  3407. dp_srng_cleanup(soc,
  3408. &soc->rxdma_err_dst_ring[mac_id],
  3409. RXDMA_DST, 0);
  3410. }
  3411. }
  3412. #else
  3413. static void dp_mon_ring_cleanup(struct dp_soc *soc, struct dp_pdev *pdev,
  3414. int mac_id)
  3415. {
  3416. }
  3417. #endif
  3418. /**
  3419. * dp_mon_ring_deinit() - Placeholder to deinitialize Monitor rings
  3420. *
  3421. * @soc: soc handle
  3422. * @pdev: datapath physical dev handle
  3423. * @mac_id: mac number
  3424. *
  3425. * Return: None
  3426. */
  3427. static void dp_mon_ring_deinit(struct dp_soc *soc, struct dp_pdev *pdev,
  3428. int mac_id)
  3429. {
  3430. }
  3431. /**
  3432. * dp_pdev_mem_reset() - Reset txrx pdev memory
  3433. * @pdev: dp pdev handle
  3434. *
  3435. * Return: None
  3436. */
  3437. static void dp_pdev_mem_reset(struct dp_pdev *pdev)
  3438. {
  3439. uint16_t len = 0;
  3440. uint8_t *dp_pdev_offset = (uint8_t *)pdev;
  3441. len = sizeof(struct dp_pdev) -
  3442. offsetof(struct dp_pdev, pdev_deinit) -
  3443. sizeof(pdev->pdev_deinit);
  3444. dp_pdev_offset = dp_pdev_offset +
  3445. offsetof(struct dp_pdev, pdev_deinit) +
  3446. sizeof(pdev->pdev_deinit);
  3447. qdf_mem_zero(dp_pdev_offset, len);
  3448. }
  3449. #ifdef WLAN_DP_PENDING_MEM_FLUSH
  3450. /**
  3451. * dp_pdev_flush_pending_vdevs() - Flush all delete pending vdevs in pdev
  3452. * @pdev: Datapath PDEV handle
  3453. *
  3454. * This is the last chance to flush all pending dp vdevs/peers,
  3455. * some peer/vdev leak case like Non-SSR + peer unmap missing
  3456. * will be covered here.
  3457. *
  3458. * Return: None
  3459. */
  3460. static void dp_pdev_flush_pending_vdevs(struct dp_pdev *pdev)
  3461. {
  3462. struct dp_vdev *vdev = NULL;
  3463. while (true) {
  3464. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  3465. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  3466. if (vdev->delete.pending)
  3467. break;
  3468. }
  3469. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  3470. /*
  3471. * vdev will be freed when all peers get cleanup,
  3472. * dp_delete_pending_vdev will remove vdev from vdev_list
  3473. * in pdev.
  3474. */
  3475. if (vdev)
  3476. dp_vdev_flush_peers((struct cdp_vdev *)vdev, 0);
  3477. else
  3478. break;
  3479. }
  3480. }
  3481. #else
  3482. static void dp_pdev_flush_pending_vdevs(struct dp_pdev *pdev)
  3483. {
  3484. }
  3485. #endif
  3486. /**
  3487. * dp_pdev_deinit() - Deinit txrx pdev
  3488. * @txrx_pdev: Datapath PDEV handle
  3489. * @force: Force deinit
  3490. *
  3491. * Return: None
  3492. */
  3493. static void dp_pdev_deinit(struct cdp_pdev *txrx_pdev, int force)
  3494. {
  3495. struct dp_pdev *pdev = (struct dp_pdev *)txrx_pdev;
  3496. struct dp_soc *soc = pdev->soc;
  3497. qdf_nbuf_t curr_nbuf, next_nbuf;
  3498. int mac_id;
  3499. /*
  3500. * Prevent double pdev deinitialization during radio detach
  3501. * execution .i.e. in the absence of any vdev
  3502. */
  3503. if (pdev->pdev_deinit)
  3504. return;
  3505. pdev->pdev_deinit = 1;
  3506. dp_wdi_event_detach(pdev);
  3507. dp_pdev_flush_pending_vdevs(pdev);
  3508. dp_tx_pdev_detach(pdev);
  3509. if (wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  3510. dp_srng_deinit(soc, &soc->tcl_data_ring[pdev->pdev_id],
  3511. TCL_DATA, pdev->pdev_id);
  3512. dp_srng_deinit(soc, &soc->tx_comp_ring[pdev->pdev_id],
  3513. WBM2SW_RELEASE, pdev->pdev_id);
  3514. }
  3515. dp_pktlogmod_exit(pdev);
  3516. dp_rx_fst_detach(soc, pdev);
  3517. dp_rx_pdev_detach(pdev);
  3518. dp_rx_pdev_mon_detach(pdev);
  3519. dp_neighbour_peers_detach(pdev);
  3520. qdf_spinlock_destroy(&pdev->tx_mutex);
  3521. qdf_spinlock_destroy(&pdev->vdev_list_lock);
  3522. dp_ipa_uc_detach(soc, pdev);
  3523. dp_cleanup_ipa_rx_refill_buf_ring(soc, pdev);
  3524. /* Cleanup per PDEV REO rings if configured */
  3525. if (wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  3526. dp_srng_deinit(soc, &soc->reo_dest_ring[pdev->pdev_id],
  3527. REO_DST, pdev->pdev_id);
  3528. }
  3529. dp_srng_deinit(soc, &soc->rx_refill_buf_ring[pdev->lmac_id],
  3530. RXDMA_BUF, 0);
  3531. dp_rxdma_ring_cleanup(soc, pdev);
  3532. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  3533. int lmac_id =
  3534. dp_get_lmac_id_for_pdev_id(soc, pdev->pdev_id, mac_id);
  3535. dp_mon_ring_deinit(soc, pdev, lmac_id);
  3536. dp_srng_deinit(soc, &soc->rxdma_err_dst_ring[lmac_id],
  3537. RXDMA_DST, 0);
  3538. }
  3539. curr_nbuf = pdev->invalid_peer_head_msdu;
  3540. while (curr_nbuf) {
  3541. next_nbuf = qdf_nbuf_next(curr_nbuf);
  3542. qdf_nbuf_free(curr_nbuf);
  3543. curr_nbuf = next_nbuf;
  3544. }
  3545. pdev->invalid_peer_head_msdu = NULL;
  3546. pdev->invalid_peer_tail_msdu = NULL;
  3547. dp_htt_ppdu_stats_detach(pdev);
  3548. dp_tx_ppdu_stats_detach(pdev);
  3549. qdf_nbuf_free(pdev->sojourn_buf);
  3550. qdf_nbuf_queue_free(&pdev->rx_ppdu_buf_q);
  3551. dp_cal_client_detach(&pdev->cal_client_ctx);
  3552. soc->pdev_count--;
  3553. /* only do soc common cleanup when last pdev do detach */
  3554. if (!(soc->pdev_count))
  3555. dp_soc_cmn_cleanup(soc);
  3556. wlan_cfg_pdev_detach(pdev->wlan_cfg_ctx);
  3557. if (pdev->invalid_peer)
  3558. qdf_mem_free(pdev->invalid_peer);
  3559. qdf_mem_free(pdev->dp_txrx_handle);
  3560. dp_pdev_mem_reset(pdev);
  3561. }
  3562. /**
  3563. * dp_pdev_deinit_wifi3() - Deinit txrx pdev
  3564. * @psoc: Datapath psoc handle
  3565. * @pdev_id: Id of datapath PDEV handle
  3566. * @force: Force deinit
  3567. *
  3568. * Return: QDF_STATUS
  3569. */
  3570. static QDF_STATUS
  3571. dp_pdev_deinit_wifi3(struct cdp_soc_t *psoc, uint8_t pdev_id,
  3572. int force)
  3573. {
  3574. struct dp_soc *soc = (struct dp_soc *)psoc;
  3575. struct dp_pdev *txrx_pdev =
  3576. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)psoc,
  3577. pdev_id);
  3578. if (!txrx_pdev)
  3579. return QDF_STATUS_E_FAILURE;
  3580. soc->dp_soc_reinit = TRUE;
  3581. dp_pdev_deinit((struct cdp_pdev *)txrx_pdev, force);
  3582. return QDF_STATUS_SUCCESS;
  3583. }
  3584. /*
  3585. * dp_pdev_detach() - Complete rest of pdev detach
  3586. * @txrx_pdev: Datapath PDEV handle
  3587. * @force: Force deinit
  3588. *
  3589. * Return: None
  3590. */
  3591. static void dp_pdev_detach(struct cdp_pdev *txrx_pdev, int force)
  3592. {
  3593. struct dp_pdev *pdev = (struct dp_pdev *)txrx_pdev;
  3594. struct dp_soc *soc = pdev->soc;
  3595. struct rx_desc_pool *rx_desc_pool;
  3596. int mac_id, mac_for_pdev;
  3597. int lmac_id;
  3598. if (wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  3599. dp_srng_cleanup(soc, &soc->tcl_data_ring[pdev->pdev_id],
  3600. TCL_DATA, pdev->pdev_id);
  3601. dp_srng_cleanup(soc, &soc->tx_comp_ring[pdev->pdev_id],
  3602. WBM2SW_RELEASE, pdev->pdev_id);
  3603. }
  3604. dp_mon_link_free(pdev);
  3605. /* Cleanup per PDEV REO rings if configured */
  3606. if (wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  3607. dp_srng_cleanup(soc, &soc->reo_dest_ring[pdev->pdev_id],
  3608. REO_DST, pdev->pdev_id);
  3609. }
  3610. dp_rxdma_ring_cleanup(soc, pdev);
  3611. wlan_cfg_pdev_detach(pdev->wlan_cfg_ctx);
  3612. dp_srng_cleanup(soc, &soc->rx_refill_buf_ring[pdev->lmac_id],
  3613. RXDMA_BUF, 0);
  3614. dp_cleanup_ipa_rx_refill_buf_ring(soc, pdev);
  3615. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  3616. lmac_id =
  3617. dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev->pdev_id);
  3618. dp_mon_ring_cleanup(soc, pdev, lmac_id);
  3619. dp_srng_cleanup(soc, &soc->rxdma_err_dst_ring[lmac_id],
  3620. RXDMA_DST, 0);
  3621. if (dp_is_soc_reinit(soc)) {
  3622. mac_for_pdev =
  3623. dp_get_lmac_id_for_pdev_id(soc, mac_id,
  3624. pdev->pdev_id);
  3625. rx_desc_pool = &soc->rx_desc_status[mac_for_pdev];
  3626. dp_rx_desc_pool_free(soc, rx_desc_pool);
  3627. rx_desc_pool = &soc->rx_desc_mon[mac_for_pdev];
  3628. dp_rx_desc_pool_free(soc, rx_desc_pool);
  3629. }
  3630. }
  3631. if (dp_is_soc_reinit(soc)) {
  3632. rx_desc_pool = &soc->rx_desc_buf[pdev->pdev_id];
  3633. dp_rx_desc_pool_free(soc, rx_desc_pool);
  3634. }
  3635. soc->pdev_list[pdev->pdev_id] = NULL;
  3636. qdf_minidump_remove(pdev);
  3637. qdf_mem_free(pdev);
  3638. }
  3639. /*
  3640. * dp_pdev_detach_wifi3() - detach txrx pdev
  3641. * @psoc: Datapath soc handle
  3642. * @pdev_id: pdev id of pdev
  3643. * @force: Force detach
  3644. *
  3645. * Return: QDF_STATUS
  3646. */
  3647. static QDF_STATUS dp_pdev_detach_wifi3(struct cdp_soc_t *psoc, uint8_t pdev_id,
  3648. int force)
  3649. {
  3650. struct dp_soc *soc = (struct dp_soc *)psoc;
  3651. struct dp_pdev *txrx_pdev =
  3652. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)psoc,
  3653. pdev_id);
  3654. if (!txrx_pdev) {
  3655. dp_err("Couldn't find dp pdev");
  3656. return QDF_STATUS_E_FAILURE;
  3657. }
  3658. if (dp_is_soc_reinit(soc)) {
  3659. dp_pdev_detach((struct cdp_pdev *)txrx_pdev, force);
  3660. } else {
  3661. dp_pdev_deinit((struct cdp_pdev *)txrx_pdev, force);
  3662. dp_pdev_detach((struct cdp_pdev *)txrx_pdev, force);
  3663. }
  3664. return QDF_STATUS_SUCCESS;
  3665. }
  3666. /*
  3667. * dp_reo_desc_freelist_destroy() - Flush REO descriptors from deferred freelist
  3668. * @soc: DP SOC handle
  3669. */
  3670. static inline void dp_reo_desc_freelist_destroy(struct dp_soc *soc)
  3671. {
  3672. struct reo_desc_list_node *desc;
  3673. struct dp_rx_tid *rx_tid;
  3674. qdf_spin_lock_bh(&soc->reo_desc_freelist_lock);
  3675. while (qdf_list_remove_front(&soc->reo_desc_freelist,
  3676. (qdf_list_node_t **)&desc) == QDF_STATUS_SUCCESS) {
  3677. rx_tid = &desc->rx_tid;
  3678. qdf_mem_unmap_nbytes_single(soc->osdev,
  3679. rx_tid->hw_qdesc_paddr,
  3680. QDF_DMA_BIDIRECTIONAL,
  3681. rx_tid->hw_qdesc_alloc_size);
  3682. qdf_mem_free(rx_tid->hw_qdesc_vaddr_unaligned);
  3683. qdf_mem_free(desc);
  3684. }
  3685. qdf_spin_unlock_bh(&soc->reo_desc_freelist_lock);
  3686. qdf_list_destroy(&soc->reo_desc_freelist);
  3687. qdf_spinlock_destroy(&soc->reo_desc_freelist_lock);
  3688. }
  3689. /**
  3690. * dp_soc_mem_reset() - Reset Dp Soc memory
  3691. * @soc: DP handle
  3692. *
  3693. * Return: None
  3694. */
  3695. static void dp_soc_mem_reset(struct dp_soc *soc)
  3696. {
  3697. uint16_t len = 0;
  3698. uint8_t *dp_soc_offset = (uint8_t *)soc;
  3699. len = sizeof(struct dp_soc) -
  3700. offsetof(struct dp_soc, dp_soc_reinit) -
  3701. sizeof(soc->dp_soc_reinit);
  3702. dp_soc_offset = dp_soc_offset +
  3703. offsetof(struct dp_soc, dp_soc_reinit) +
  3704. sizeof(soc->dp_soc_reinit);
  3705. qdf_mem_zero(dp_soc_offset, len);
  3706. }
  3707. /**
  3708. * dp_soc_deinit() - Deinitialize txrx SOC
  3709. * @txrx_soc: Opaque DP SOC handle
  3710. *
  3711. * Return: None
  3712. */
  3713. static void dp_soc_deinit(void *txrx_soc)
  3714. {
  3715. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  3716. int i;
  3717. qdf_atomic_set(&soc->cmn_init_done, 0);
  3718. for (i = 0; i < MAX_PDEV_CNT; i++) {
  3719. if (soc->pdev_list[i])
  3720. dp_pdev_deinit((struct cdp_pdev *)
  3721. soc->pdev_list[i], 1);
  3722. }
  3723. qdf_flush_work(&soc->htt_stats.work);
  3724. qdf_disable_work(&soc->htt_stats.work);
  3725. /* Free pending htt stats messages */
  3726. qdf_nbuf_queue_free(&soc->htt_stats.msg);
  3727. dp_peer_find_detach(soc);
  3728. /* Free the ring memories */
  3729. /* Common rings */
  3730. dp_srng_deinit(soc, &soc->wbm_desc_rel_ring, SW2WBM_RELEASE, 0);
  3731. /* Tx data rings */
  3732. if (!wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  3733. for (i = 0; i < soc->num_tcl_data_rings; i++) {
  3734. dp_srng_deinit(soc, &soc->tcl_data_ring[i],
  3735. TCL_DATA, i);
  3736. dp_srng_deinit(soc, &soc->tx_comp_ring[i],
  3737. WBM2SW_RELEASE, i);
  3738. }
  3739. }
  3740. /* TCL command and status rings */
  3741. dp_srng_deinit(soc, &soc->tcl_cmd_ring, TCL_CMD, 0);
  3742. dp_srng_deinit(soc, &soc->tcl_status_ring, TCL_STATUS, 0);
  3743. /* Rx data rings */
  3744. if (!wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  3745. soc->num_reo_dest_rings =
  3746. wlan_cfg_num_reo_dest_rings(soc->wlan_cfg_ctx);
  3747. for (i = 0; i < soc->num_reo_dest_rings; i++) {
  3748. /* TODO: Get number of rings and ring sizes
  3749. * from wlan_cfg
  3750. */
  3751. dp_srng_deinit(soc, &soc->reo_dest_ring[i],
  3752. REO_DST, i);
  3753. }
  3754. }
  3755. /* REO reinjection ring */
  3756. dp_srng_deinit(soc, &soc->reo_reinject_ring, REO_REINJECT, 0);
  3757. /* Rx release ring */
  3758. dp_srng_deinit(soc, &soc->rx_rel_ring, WBM2SW_RELEASE, 0);
  3759. /* Rx exception ring */
  3760. /* TODO: Better to store ring_type and ring_num in
  3761. * dp_srng during setup
  3762. */
  3763. dp_srng_deinit(soc, &soc->reo_exception_ring, REO_EXCEPTION, 0);
  3764. /* REO command and status rings */
  3765. dp_srng_deinit(soc, &soc->reo_cmd_ring, REO_CMD, 0);
  3766. dp_srng_deinit(soc, &soc->reo_status_ring, REO_STATUS, 0);
  3767. dp_soc_wds_detach(soc);
  3768. qdf_spinlock_destroy(&soc->peer_ref_mutex);
  3769. qdf_spinlock_destroy(&soc->htt_stats.lock);
  3770. htt_soc_htc_dealloc(soc->htt_handle);
  3771. dp_reo_desc_freelist_destroy(soc);
  3772. qdf_spinlock_destroy(&soc->ast_lock);
  3773. dp_soc_mem_reset(soc);
  3774. }
  3775. /**
  3776. * dp_soc_deinit_wifi3() - Deinitialize txrx SOC
  3777. * @txrx_soc: Opaque DP SOC handle
  3778. *
  3779. * Return: None
  3780. */
  3781. static void dp_soc_deinit_wifi3(struct cdp_soc_t *txrx_soc)
  3782. {
  3783. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  3784. soc->dp_soc_reinit = 1;
  3785. dp_soc_deinit(txrx_soc);
  3786. }
  3787. /*
  3788. * dp_soc_detach() - Detach rest of txrx SOC
  3789. * @txrx_soc: DP SOC handle, struct cdp_soc_t is first element of struct dp_soc.
  3790. *
  3791. * Return: None
  3792. */
  3793. static void dp_soc_detach(struct cdp_soc_t *txrx_soc)
  3794. {
  3795. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  3796. int i;
  3797. qdf_atomic_set(&soc->cmn_init_done, 0);
  3798. /* TBD: Call Tx and Rx cleanup functions to free buffers and
  3799. * SW descriptors
  3800. */
  3801. for (i = 0; i < MAX_PDEV_CNT; i++) {
  3802. if (soc->pdev_list[i])
  3803. dp_pdev_detach((struct cdp_pdev *)
  3804. soc->pdev_list[i], 1);
  3805. }
  3806. /* Free the ring memories */
  3807. /* Common rings */
  3808. qdf_minidump_remove(soc->wbm_desc_rel_ring.base_vaddr_unaligned);
  3809. dp_srng_cleanup(soc, &soc->wbm_desc_rel_ring, SW2WBM_RELEASE, 0);
  3810. if (dp_is_soc_reinit(soc)) {
  3811. dp_tx_soc_detach(soc);
  3812. }
  3813. /* Tx data rings */
  3814. if (!wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  3815. for (i = 0; i < soc->num_tcl_data_rings; i++) {
  3816. dp_srng_cleanup(soc, &soc->tcl_data_ring[i],
  3817. TCL_DATA, i);
  3818. dp_srng_cleanup(soc, &soc->tx_comp_ring[i],
  3819. WBM2SW_RELEASE, i);
  3820. }
  3821. }
  3822. /* TCL command and status rings */
  3823. dp_srng_cleanup(soc, &soc->tcl_cmd_ring, TCL_CMD, 0);
  3824. dp_srng_cleanup(soc, &soc->tcl_status_ring, TCL_STATUS, 0);
  3825. /* Rx data rings */
  3826. if (!wlan_cfg_per_pdev_rx_ring(soc->wlan_cfg_ctx)) {
  3827. soc->num_reo_dest_rings =
  3828. wlan_cfg_num_reo_dest_rings(soc->wlan_cfg_ctx);
  3829. for (i = 0; i < soc->num_reo_dest_rings; i++) {
  3830. /* TODO: Get number of rings and ring sizes
  3831. * from wlan_cfg
  3832. */
  3833. dp_srng_cleanup(soc, &soc->reo_dest_ring[i],
  3834. REO_DST, i);
  3835. }
  3836. }
  3837. /* REO reinjection ring */
  3838. dp_srng_cleanup(soc, &soc->reo_reinject_ring, REO_REINJECT, 0);
  3839. /* Rx release ring */
  3840. dp_srng_cleanup(soc, &soc->rx_rel_ring, WBM2SW_RELEASE, 0);
  3841. dp_srng_cleanup(soc, &soc->rx_rel_ring, WBM2SW_RELEASE, 3);
  3842. /* Rx exception ring */
  3843. /* TODO: Better to store ring_type and ring_num in
  3844. * dp_srng during setup
  3845. */
  3846. dp_srng_cleanup(soc, &soc->reo_exception_ring, REO_EXCEPTION, 0);
  3847. /* REO command and status rings */
  3848. dp_srng_cleanup(soc, &soc->reo_cmd_ring, REO_CMD, 0);
  3849. dp_srng_cleanup(soc, &soc->reo_status_ring, REO_STATUS, 0);
  3850. dp_hw_link_desc_pool_cleanup(soc);
  3851. htt_soc_detach(soc->htt_handle);
  3852. soc->dp_soc_reinit = 0;
  3853. wlan_cfg_soc_detach(soc->wlan_cfg_ctx);
  3854. qdf_minidump_remove(soc);
  3855. qdf_mem_free(soc);
  3856. }
  3857. /*
  3858. * dp_soc_detach_wifi3() - Detach txrx SOC
  3859. * @txrx_soc: DP SOC handle, struct cdp_soc_t is first element of struct dp_soc.
  3860. *
  3861. * Return: None
  3862. */
  3863. static void dp_soc_detach_wifi3(struct cdp_soc_t *txrx_soc)
  3864. {
  3865. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  3866. if (dp_is_soc_reinit(soc)) {
  3867. dp_soc_detach(txrx_soc);
  3868. } else {
  3869. dp_soc_deinit(txrx_soc);
  3870. dp_soc_detach(txrx_soc);
  3871. }
  3872. }
  3873. #if !defined(DISABLE_MON_CONFIG)
  3874. /**
  3875. * dp_mon_htt_srng_setup() - Prepare HTT messages for Monitor rings
  3876. * @soc: soc handle
  3877. * @pdev: physical device handle
  3878. * @mac_id: ring number
  3879. * @mac_for_pdev: mac_id
  3880. *
  3881. * Return: non-zero for failure, zero for success
  3882. */
  3883. static QDF_STATUS dp_mon_htt_srng_setup(struct dp_soc *soc,
  3884. struct dp_pdev *pdev,
  3885. int mac_id,
  3886. int mac_for_pdev)
  3887. {
  3888. QDF_STATUS status = QDF_STATUS_SUCCESS;
  3889. if (soc->wlan_cfg_ctx->rxdma1_enable) {
  3890. status = htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3891. soc->rxdma_mon_buf_ring[mac_id]
  3892. .hal_srng,
  3893. RXDMA_MONITOR_BUF);
  3894. if (status != QDF_STATUS_SUCCESS) {
  3895. dp_err("Failed to send htt srng setup message for Rxdma mon buf ring");
  3896. return status;
  3897. }
  3898. status = htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3899. soc->rxdma_mon_dst_ring[mac_id]
  3900. .hal_srng,
  3901. RXDMA_MONITOR_DST);
  3902. if (status != QDF_STATUS_SUCCESS) {
  3903. dp_err("Failed to send htt srng setup message for Rxdma mon dst ring");
  3904. return status;
  3905. }
  3906. status = htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3907. soc->rxdma_mon_status_ring[mac_id]
  3908. .hal_srng,
  3909. RXDMA_MONITOR_STATUS);
  3910. if (status != QDF_STATUS_SUCCESS) {
  3911. dp_err("Failed to send htt srng setup message for Rxdma mon status ring");
  3912. return status;
  3913. }
  3914. status = htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3915. soc->rxdma_mon_desc_ring[mac_id]
  3916. .hal_srng,
  3917. RXDMA_MONITOR_DESC);
  3918. if (status != QDF_STATUS_SUCCESS) {
  3919. dp_err("Failed to send htt srng message for Rxdma mon desc ring");
  3920. return status;
  3921. }
  3922. } else {
  3923. status = htt_srng_setup(soc->htt_handle, mac_for_pdev,
  3924. soc->rxdma_mon_status_ring[mac_id]
  3925. .hal_srng,
  3926. RXDMA_MONITOR_STATUS);
  3927. if (status != QDF_STATUS_SUCCESS) {
  3928. dp_err("Failed to send htt srng setup message for Rxdma mon status ring");
  3929. return status;
  3930. }
  3931. }
  3932. return status;
  3933. }
  3934. #else
  3935. static QDF_STATUS dp_mon_htt_srng_setup(struct dp_soc *soc,
  3936. struct dp_pdev *pdev,
  3937. int mac_id,
  3938. int mac_for_pdev)
  3939. {
  3940. return QDF_STATUS_SUCCESS;
  3941. }
  3942. #endif
  3943. /*
  3944. * dp_rxdma_ring_config() - configure the RX DMA rings
  3945. *
  3946. * This function is used to configure the MAC rings.
  3947. * On MCL host provides buffers in Host2FW ring
  3948. * FW refills (copies) buffers to the ring and updates
  3949. * ring_idx in register
  3950. *
  3951. * @soc: data path SoC handle
  3952. *
  3953. * Return: zero on success, non-zero on failure
  3954. */
  3955. #ifdef QCA_HOST2FW_RXBUF_RING
  3956. static QDF_STATUS dp_rxdma_ring_config(struct dp_soc *soc)
  3957. {
  3958. int i;
  3959. QDF_STATUS status = QDF_STATUS_SUCCESS;
  3960. for (i = 0; i < MAX_PDEV_CNT; i++) {
  3961. struct dp_pdev *pdev = soc->pdev_list[i];
  3962. if (pdev) {
  3963. int mac_id;
  3964. bool dbs_enable = 0;
  3965. int max_mac_rings =
  3966. wlan_cfg_get_num_mac_rings
  3967. (pdev->wlan_cfg_ctx);
  3968. int lmac_id = dp_get_lmac_id_for_pdev_id(soc, 0, i);
  3969. htt_srng_setup(soc->htt_handle, 0,
  3970. soc->rx_refill_buf_ring[lmac_id]
  3971. .hal_srng,
  3972. RXDMA_BUF);
  3973. if (pdev->rx_refill_buf_ring2.hal_srng)
  3974. htt_srng_setup(soc->htt_handle, 0,
  3975. pdev->rx_refill_buf_ring2.hal_srng,
  3976. RXDMA_BUF);
  3977. if (soc->cdp_soc.ol_ops->
  3978. is_hw_dbs_2x2_capable) {
  3979. dbs_enable = soc->cdp_soc.ol_ops->
  3980. is_hw_dbs_2x2_capable(
  3981. (void *)soc->ctrl_psoc);
  3982. }
  3983. if (dbs_enable) {
  3984. QDF_TRACE(QDF_MODULE_ID_TXRX,
  3985. QDF_TRACE_LEVEL_ERROR,
  3986. FL("DBS enabled max_mac_rings %d"),
  3987. max_mac_rings);
  3988. } else {
  3989. max_mac_rings = 1;
  3990. QDF_TRACE(QDF_MODULE_ID_TXRX,
  3991. QDF_TRACE_LEVEL_ERROR,
  3992. FL("DBS disabled, max_mac_rings %d"),
  3993. max_mac_rings);
  3994. }
  3995. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  3996. FL("pdev_id %d max_mac_rings %d"),
  3997. pdev->pdev_id, max_mac_rings);
  3998. for (mac_id = 0; mac_id < max_mac_rings; mac_id++) {
  3999. int mac_for_pdev =
  4000. dp_get_mac_id_for_pdev(mac_id,
  4001. pdev->pdev_id);
  4002. /*
  4003. * Obtain lmac id from pdev to access the LMAC
  4004. * ring in soc context
  4005. */
  4006. lmac_id =
  4007. dp_get_lmac_id_for_pdev_id(soc,
  4008. mac_id,
  4009. pdev->pdev_id);
  4010. QDF_TRACE(QDF_MODULE_ID_TXRX,
  4011. QDF_TRACE_LEVEL_ERROR,
  4012. FL("mac_id %d"), mac_for_pdev);
  4013. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  4014. pdev->rx_mac_buf_ring[mac_id]
  4015. .hal_srng,
  4016. RXDMA_BUF);
  4017. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  4018. soc->rxdma_err_dst_ring[lmac_id]
  4019. .hal_srng,
  4020. RXDMA_DST);
  4021. /* Configure monitor mode rings */
  4022. status = dp_mon_htt_srng_setup(soc, pdev,
  4023. lmac_id,
  4024. mac_for_pdev);
  4025. if (status != QDF_STATUS_SUCCESS) {
  4026. dp_err("Failed to send htt monitor messages to target");
  4027. return status;
  4028. }
  4029. }
  4030. }
  4031. }
  4032. /*
  4033. * Timer to reap rxdma status rings.
  4034. * Needed until we enable ppdu end interrupts
  4035. */
  4036. qdf_timer_init(soc->osdev, &soc->mon_reap_timer,
  4037. dp_service_mon_rings, (void *)soc,
  4038. QDF_TIMER_TYPE_WAKE_APPS);
  4039. soc->reap_timer_init = 1;
  4040. return status;
  4041. }
  4042. #else
  4043. /* This is only for WIN */
  4044. static QDF_STATUS dp_rxdma_ring_config(struct dp_soc *soc)
  4045. {
  4046. int i;
  4047. QDF_STATUS status = QDF_STATUS_SUCCESS;
  4048. int mac_for_pdev;
  4049. int lmac_id;
  4050. for (i = 0; i < MAX_PDEV_CNT; i++) {
  4051. struct dp_pdev *pdev = soc->pdev_list[i];
  4052. if (!pdev)
  4053. continue;
  4054. mac_for_pdev = i;
  4055. lmac_id = dp_get_lmac_id_for_pdev_id(soc, 0, i);
  4056. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  4057. soc->rx_refill_buf_ring[lmac_id].
  4058. hal_srng, RXDMA_BUF);
  4059. #ifndef DISABLE_MON_CONFIG
  4060. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  4061. soc->rxdma_mon_buf_ring[lmac_id].hal_srng,
  4062. RXDMA_MONITOR_BUF);
  4063. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  4064. soc->rxdma_mon_dst_ring[lmac_id].hal_srng,
  4065. RXDMA_MONITOR_DST);
  4066. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  4067. soc->rxdma_mon_status_ring[lmac_id].hal_srng,
  4068. RXDMA_MONITOR_STATUS);
  4069. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  4070. soc->rxdma_mon_desc_ring[lmac_id].hal_srng,
  4071. RXDMA_MONITOR_DESC);
  4072. #endif
  4073. htt_srng_setup(soc->htt_handle, mac_for_pdev,
  4074. soc->rxdma_err_dst_ring[lmac_id].hal_srng,
  4075. RXDMA_DST);
  4076. }
  4077. /* Configure LMAC rings in Polled mode */
  4078. if (soc->lmac_polled_mode) {
  4079. /*
  4080. * Timer to reap lmac rings.
  4081. */
  4082. qdf_timer_init(soc->osdev, &soc->lmac_reap_timer,
  4083. dp_service_lmac_rings, (void *)soc,
  4084. QDF_TIMER_TYPE_WAKE_APPS);
  4085. soc->lmac_timer_init = 1;
  4086. qdf_timer_mod(&soc->lmac_reap_timer, DP_INTR_POLL_TIMER_MS);
  4087. }
  4088. return status;
  4089. }
  4090. #endif
  4091. #ifdef NO_RX_PKT_HDR_TLV
  4092. static QDF_STATUS
  4093. dp_rxdma_ring_sel_cfg(struct dp_soc *soc)
  4094. {
  4095. int i;
  4096. int mac_id;
  4097. struct htt_rx_ring_tlv_filter htt_tlv_filter = {0};
  4098. QDF_STATUS status = QDF_STATUS_SUCCESS;
  4099. htt_tlv_filter.mpdu_start = 1;
  4100. htt_tlv_filter.msdu_start = 1;
  4101. htt_tlv_filter.mpdu_end = 1;
  4102. htt_tlv_filter.msdu_end = 1;
  4103. htt_tlv_filter.attention = 1;
  4104. htt_tlv_filter.packet = 1;
  4105. htt_tlv_filter.packet_header = 0;
  4106. htt_tlv_filter.ppdu_start = 0;
  4107. htt_tlv_filter.ppdu_end = 0;
  4108. htt_tlv_filter.ppdu_end_user_stats = 0;
  4109. htt_tlv_filter.ppdu_end_user_stats_ext = 0;
  4110. htt_tlv_filter.ppdu_end_status_done = 0;
  4111. htt_tlv_filter.enable_fp = 1;
  4112. htt_tlv_filter.enable_md = 0;
  4113. htt_tlv_filter.enable_md = 0;
  4114. htt_tlv_filter.enable_mo = 0;
  4115. htt_tlv_filter.fp_mgmt_filter = 0;
  4116. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_BA_REQ;
  4117. htt_tlv_filter.fp_data_filter = (FILTER_DATA_UCAST |
  4118. FILTER_DATA_MCAST |
  4119. FILTER_DATA_DATA);
  4120. htt_tlv_filter.mo_mgmt_filter = 0;
  4121. htt_tlv_filter.mo_ctrl_filter = 0;
  4122. htt_tlv_filter.mo_data_filter = 0;
  4123. htt_tlv_filter.md_data_filter = 0;
  4124. htt_tlv_filter.offset_valid = true;
  4125. htt_tlv_filter.rx_packet_offset = RX_PKT_TLVS_LEN;
  4126. /*Not subscribing rx_pkt_header*/
  4127. htt_tlv_filter.rx_header_offset = 0;
  4128. htt_tlv_filter.rx_mpdu_start_offset =
  4129. HAL_RX_PKT_TLV_MPDU_START_OFFSET(soc->hal_soc);
  4130. htt_tlv_filter.rx_mpdu_end_offset =
  4131. HAL_RX_PKT_TLV_MPDU_END_OFFSET(soc->hal_soc);
  4132. htt_tlv_filter.rx_msdu_start_offset =
  4133. HAL_RX_PKT_TLV_MSDU_START_OFFSET(soc->hal_soc);
  4134. htt_tlv_filter.rx_msdu_end_offset =
  4135. HAL_RX_PKT_TLV_MSDU_END_OFFSET(soc->hal_soc);
  4136. htt_tlv_filter.rx_attn_offset =
  4137. HAL_RX_PKT_TLV_ATTN_OFFSET(soc->hal_soc);
  4138. for (i = 0; i < MAX_PDEV_CNT; i++) {
  4139. struct dp_pdev *pdev = soc->pdev_list[i];
  4140. if (!pdev)
  4141. continue;
  4142. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  4143. int mac_for_pdev =
  4144. dp_get_mac_id_for_pdev(mac_id, pdev->pdev_id);
  4145. /*
  4146. * Obtain lmac id from pdev to access the LMAC ring
  4147. * in soc context
  4148. */
  4149. int lmac_id =
  4150. dp_get_lmac_id_for_pdev_id(soc, mac_id,
  4151. pdev->pdev_id);
  4152. htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  4153. soc->rx_refill_buf_ring[lmac_id].
  4154. hal_srng,
  4155. RXDMA_BUF, RX_BUFFER_SIZE,
  4156. &htt_tlv_filter);
  4157. }
  4158. }
  4159. return status;
  4160. }
  4161. #else
  4162. static QDF_STATUS
  4163. dp_rxdma_ring_sel_cfg(struct dp_soc *soc)
  4164. {
  4165. return QDF_STATUS_SUCCESS;
  4166. }
  4167. #endif
  4168. /*
  4169. * dp_rx_target_fst_config() - configure the RXOLE Flow Search Engine
  4170. *
  4171. * This function is used to configure the FSE HW block in RX OLE on a
  4172. * per pdev basis. Here, we will be programming parameters related to
  4173. * the Flow Search Table.
  4174. *
  4175. * @soc: data path SoC handle
  4176. *
  4177. * Return: zero on success, non-zero on failure
  4178. */
  4179. #ifdef WLAN_SUPPORT_RX_FLOW_TAG
  4180. static QDF_STATUS
  4181. dp_rx_target_fst_config(struct dp_soc *soc)
  4182. {
  4183. int i;
  4184. QDF_STATUS status = QDF_STATUS_SUCCESS;
  4185. for (i = 0; i < MAX_PDEV_CNT; i++) {
  4186. struct dp_pdev *pdev = soc->pdev_list[i];
  4187. /* Flow search is not enabled if NSS offload is enabled */
  4188. if (pdev &&
  4189. !wlan_cfg_get_dp_pdev_nss_enabled(pdev->wlan_cfg_ctx)) {
  4190. status = dp_rx_flow_send_fst_fw_setup(pdev->soc, pdev);
  4191. if (status != QDF_STATUS_SUCCESS)
  4192. break;
  4193. }
  4194. }
  4195. return status;
  4196. }
  4197. #else
  4198. /**
  4199. * dp_rx_target_fst_config() - Configure RX OLE FSE engine in HW
  4200. * @soc: SoC handle
  4201. *
  4202. * Return: Success
  4203. */
  4204. static inline QDF_STATUS
  4205. dp_rx_target_fst_config(struct dp_soc *soc)
  4206. {
  4207. return QDF_STATUS_SUCCESS;
  4208. }
  4209. #endif /* WLAN_SUPPORT_RX_FLOW_TAG */
  4210. /*
  4211. * dp_soc_attach_target_wifi3() - SOC initialization in the target
  4212. * @cdp_soc: Opaque Datapath SOC handle
  4213. *
  4214. * Return: zero on success, non-zero on failure
  4215. */
  4216. static QDF_STATUS
  4217. dp_soc_attach_target_wifi3(struct cdp_soc_t *cdp_soc)
  4218. {
  4219. struct dp_soc *soc = (struct dp_soc *)cdp_soc;
  4220. QDF_STATUS status = QDF_STATUS_SUCCESS;
  4221. htt_soc_attach_target(soc->htt_handle);
  4222. status = dp_rxdma_ring_config(soc);
  4223. if (status != QDF_STATUS_SUCCESS) {
  4224. dp_err("Failed to send htt srng setup messages to target");
  4225. return status;
  4226. }
  4227. status = dp_rxdma_ring_sel_cfg(soc);
  4228. if (status != QDF_STATUS_SUCCESS) {
  4229. dp_err("Failed to send htt ring config message to target");
  4230. return status;
  4231. }
  4232. status = dp_rx_target_fst_config(soc);
  4233. if (status != QDF_STATUS_SUCCESS) {
  4234. dp_err("Failed to send htt fst setup config message to target");
  4235. return status;
  4236. }
  4237. DP_STATS_INIT(soc);
  4238. /* initialize work queue for stats processing */
  4239. qdf_create_work(0, &soc->htt_stats.work, htt_t2h_stats_handler, soc);
  4240. qdf_minidump_log(soc, sizeof(*soc), "dp_soc");
  4241. return QDF_STATUS_SUCCESS;
  4242. }
  4243. /*
  4244. * dp_vdev_attach_wifi3() - attach txrx vdev
  4245. * @txrx_pdev: Datapath PDEV handle
  4246. * @vdev_mac_addr: MAC address of the virtual interface
  4247. * @vdev_id: VDEV Id
  4248. * @wlan_op_mode: VDEV operating mode
  4249. * @subtype: VDEV operating subtype
  4250. *
  4251. * Return: DP VDEV handle on success, NULL on failure
  4252. */
  4253. static struct cdp_vdev *dp_vdev_attach_wifi3(struct cdp_soc_t *cdp_soc,
  4254. uint8_t pdev_id,
  4255. uint8_t *vdev_mac_addr,
  4256. uint8_t vdev_id,
  4257. enum wlan_op_mode op_mode,
  4258. enum wlan_op_subtype subtype)
  4259. {
  4260. struct dp_soc *soc = (struct dp_soc *)cdp_soc;
  4261. struct dp_pdev *pdev =
  4262. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  4263. pdev_id);
  4264. struct dp_vdev *vdev = qdf_mem_malloc(sizeof(*vdev));
  4265. if (!pdev) {
  4266. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  4267. FL("DP PDEV is Null for pdev id %d"), pdev_id);
  4268. qdf_mem_free(vdev);
  4269. goto fail0;
  4270. }
  4271. if (!vdev) {
  4272. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  4273. FL("DP VDEV memory allocation failed"));
  4274. goto fail0;
  4275. }
  4276. vdev->pdev = pdev;
  4277. vdev->vdev_id = vdev_id;
  4278. vdev->opmode = op_mode;
  4279. vdev->subtype = subtype;
  4280. vdev->osdev = soc->osdev;
  4281. vdev->osif_rx = NULL;
  4282. vdev->osif_rsim_rx_decap = NULL;
  4283. vdev->osif_get_key = NULL;
  4284. vdev->osif_rx_mon = NULL;
  4285. vdev->osif_tx_free_ext = NULL;
  4286. vdev->osif_vdev = NULL;
  4287. vdev->delete.pending = 0;
  4288. vdev->safemode = 0;
  4289. vdev->drop_unenc = 1;
  4290. vdev->sec_type = cdp_sec_type_none;
  4291. vdev->multipass_en = false;
  4292. #ifdef notyet
  4293. vdev->filters_num = 0;
  4294. #endif
  4295. qdf_mem_copy(
  4296. &vdev->mac_addr.raw[0], vdev_mac_addr, QDF_MAC_ADDR_SIZE);
  4297. /* TODO: Initialize default HTT meta data that will be used in
  4298. * TCL descriptors for packets transmitted from this VDEV
  4299. */
  4300. TAILQ_INIT(&vdev->peer_list);
  4301. dp_peer_multipass_list_init(vdev);
  4302. if ((soc->intr_mode == DP_INTR_POLL) &&
  4303. wlan_cfg_get_num_contexts(soc->wlan_cfg_ctx) != 0) {
  4304. if ((pdev->vdev_count == 0) ||
  4305. (wlan_op_mode_monitor == vdev->opmode))
  4306. qdf_timer_mod(&soc->int_timer, DP_INTR_POLL_TIMER_MS);
  4307. }
  4308. soc->vdev_id_map[vdev_id] = vdev;
  4309. if (wlan_op_mode_monitor == vdev->opmode) {
  4310. pdev->monitor_vdev = vdev;
  4311. return (struct cdp_vdev *)vdev;
  4312. }
  4313. vdev->tx_encap_type = wlan_cfg_pkt_type(soc->wlan_cfg_ctx);
  4314. vdev->rx_decap_type = wlan_cfg_pkt_type(soc->wlan_cfg_ctx);
  4315. vdev->dscp_tid_map_id = 0;
  4316. vdev->mcast_enhancement_en = 0;
  4317. vdev->raw_mode_war = wlan_cfg_get_raw_mode_war(soc->wlan_cfg_ctx);
  4318. vdev->prev_tx_enq_tstamp = 0;
  4319. vdev->prev_rx_deliver_tstamp = 0;
  4320. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  4321. /* add this vdev into the pdev's list */
  4322. TAILQ_INSERT_TAIL(&pdev->vdev_list, vdev, vdev_list_elem);
  4323. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  4324. pdev->vdev_count++;
  4325. if (wlan_op_mode_sta != vdev->opmode)
  4326. vdev->ap_bridge_enabled = true;
  4327. else
  4328. vdev->ap_bridge_enabled = false;
  4329. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  4330. "%s: wlan_cfg_ap_bridge_enabled %d",
  4331. __func__, vdev->ap_bridge_enabled);
  4332. dp_tx_vdev_attach(vdev);
  4333. if (pdev->vdev_count == 1)
  4334. dp_lro_hash_setup(soc, pdev);
  4335. dp_info("Created vdev %pK (%pM)", vdev, vdev->mac_addr.raw);
  4336. DP_STATS_INIT(vdev);
  4337. if (wlan_op_mode_sta == vdev->opmode)
  4338. dp_peer_create_wifi3((struct cdp_soc_t *)soc, vdev_id,
  4339. vdev->mac_addr.raw);
  4340. return (struct cdp_vdev *)vdev;
  4341. fail0:
  4342. return NULL;
  4343. }
  4344. /**
  4345. * dp_vdev_register_wifi3() - Register VDEV operations from osif layer
  4346. * @soc: Datapath soc handle
  4347. * @vdev_id: id of Datapath VDEV handle
  4348. * @osif_vdev: OSIF vdev handle
  4349. * @txrx_ops: Tx and Rx operations
  4350. *
  4351. * Return: DP VDEV handle on success, NULL on failure
  4352. */
  4353. static QDF_STATUS dp_vdev_register_wifi3(struct cdp_soc_t *soc,
  4354. uint8_t vdev_id,
  4355. ol_osif_vdev_handle osif_vdev,
  4356. struct ol_txrx_ops *txrx_ops)
  4357. {
  4358. struct dp_vdev *vdev =
  4359. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  4360. vdev_id);
  4361. if (!vdev)
  4362. return QDF_STATUS_E_FAILURE;
  4363. vdev->osif_vdev = osif_vdev;
  4364. vdev->osif_rx = txrx_ops->rx.rx;
  4365. vdev->osif_rx_stack = txrx_ops->rx.rx_stack;
  4366. vdev->osif_rx_flush = txrx_ops->rx.rx_flush;
  4367. vdev->osif_gro_flush = txrx_ops->rx.rx_gro_flush;
  4368. vdev->osif_rsim_rx_decap = txrx_ops->rx.rsim_rx_decap;
  4369. vdev->osif_get_key = txrx_ops->get_key;
  4370. vdev->osif_rx_mon = txrx_ops->rx.mon;
  4371. vdev->osif_tx_free_ext = txrx_ops->tx.tx_free_ext;
  4372. vdev->tx_comp = txrx_ops->tx.tx_comp;
  4373. #ifdef notyet
  4374. #if ATH_SUPPORT_WAPI
  4375. vdev->osif_check_wai = txrx_ops->rx.wai_check;
  4376. #endif
  4377. #endif
  4378. #ifdef UMAC_SUPPORT_PROXY_ARP
  4379. vdev->osif_proxy_arp = txrx_ops->proxy_arp;
  4380. #endif
  4381. vdev->me_convert = txrx_ops->me_convert;
  4382. /* TODO: Enable the following once Tx code is integrated */
  4383. if (vdev->mesh_vdev)
  4384. txrx_ops->tx.tx = dp_tx_send_mesh;
  4385. else
  4386. txrx_ops->tx.tx = dp_tx_send;
  4387. txrx_ops->tx.tx_exception = dp_tx_send_exception;
  4388. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_LOW,
  4389. "DP Vdev Register success");
  4390. return QDF_STATUS_SUCCESS;
  4391. }
  4392. /**
  4393. * dp_peer_flush_ast_entry() - Forcibily flush all AST entry of peer
  4394. * @soc: Datapath soc handle
  4395. * @peer: Datapath peer handle
  4396. * @peer_id: Peer ID
  4397. * @vdev_id: Vdev ID
  4398. *
  4399. * Return: void
  4400. */
  4401. static void dp_peer_flush_ast_entry(struct dp_soc *soc,
  4402. struct dp_peer *peer,
  4403. uint16_t peer_id,
  4404. uint8_t vdev_id)
  4405. {
  4406. struct dp_ast_entry *ase, *tmp_ase;
  4407. if (soc->is_peer_map_unmap_v2) {
  4408. DP_PEER_ITERATE_ASE_LIST(peer, ase, tmp_ase) {
  4409. dp_rx_peer_unmap_handler
  4410. (soc, peer_id,
  4411. vdev_id,
  4412. ase->mac_addr.raw,
  4413. 1);
  4414. }
  4415. }
  4416. }
  4417. /**
  4418. * dp_vdev_flush_peers() - Forcibily Flush peers of vdev
  4419. * @vdev: Datapath VDEV handle
  4420. * @unmap_only: Flag to indicate "only unmap"
  4421. *
  4422. * Return: void
  4423. */
  4424. static void dp_vdev_flush_peers(struct cdp_vdev *vdev_handle, bool unmap_only)
  4425. {
  4426. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  4427. struct dp_pdev *pdev = vdev->pdev;
  4428. struct dp_soc *soc = pdev->soc;
  4429. struct dp_peer *peer;
  4430. uint16_t *peer_ids;
  4431. struct dp_peer **peer_array = NULL;
  4432. uint8_t i = 0, j = 0;
  4433. uint8_t m = 0, n = 0;
  4434. peer_ids = qdf_mem_malloc(soc->max_peers * sizeof(peer_ids[0]));
  4435. if (!peer_ids) {
  4436. dp_err("DP alloc failure - unable to flush peers");
  4437. return;
  4438. }
  4439. if (!unmap_only) {
  4440. peer_array = qdf_mem_malloc(
  4441. soc->max_peers * sizeof(struct dp_peer *));
  4442. if (!peer_array) {
  4443. qdf_mem_free(peer_ids);
  4444. dp_err("DP alloc failure - unable to flush peers");
  4445. return;
  4446. }
  4447. }
  4448. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  4449. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  4450. if (!unmap_only && n < soc->max_peers)
  4451. peer_array[n++] = peer;
  4452. for (i = 0; i < MAX_NUM_PEER_ID_PER_PEER; i++)
  4453. if (peer->peer_ids[i] != HTT_INVALID_PEER)
  4454. if (j < soc->max_peers)
  4455. peer_ids[j++] = peer->peer_ids[i];
  4456. }
  4457. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  4458. /*
  4459. * If peer id is invalid, need to flush the peer if
  4460. * peer valid flag is true, this is needed for NAN + SSR case.
  4461. */
  4462. if (!unmap_only) {
  4463. for (m = 0; m < n ; m++) {
  4464. peer = peer_array[m];
  4465. dp_info("peer: %pM is getting deleted",
  4466. peer->mac_addr.raw);
  4467. /* only if peer valid is true */
  4468. if (peer->valid)
  4469. dp_peer_delete_wifi3((struct cdp_soc_t *)soc,
  4470. vdev->vdev_id,
  4471. peer->mac_addr.raw, 0);
  4472. }
  4473. qdf_mem_free(peer_array);
  4474. }
  4475. for (i = 0; i < j ; i++) {
  4476. peer = __dp_peer_find_by_id(soc, peer_ids[i]);
  4477. if (!peer)
  4478. continue;
  4479. dp_info("peer: %pM is getting unmap",
  4480. peer->mac_addr.raw);
  4481. /* free AST entries of peer */
  4482. dp_peer_flush_ast_entry(soc, peer,
  4483. peer_ids[i],
  4484. vdev->vdev_id);
  4485. dp_rx_peer_unmap_handler(soc, peer_ids[i],
  4486. vdev->vdev_id,
  4487. peer->mac_addr.raw, 0);
  4488. }
  4489. qdf_mem_free(peer_ids);
  4490. dp_info("Flushed peers for vdev object %pK ", vdev);
  4491. }
  4492. /*
  4493. * dp_vdev_detach_wifi3() - Detach txrx vdev
  4494. * @cdp_soc: Datapath soc handle
  4495. * @vdev_id: VDEV Id
  4496. * @callback: Callback OL_IF on completion of detach
  4497. * @cb_context: Callback context
  4498. *
  4499. */
  4500. static QDF_STATUS dp_vdev_detach_wifi3(struct cdp_soc_t *cdp_soc,
  4501. uint8_t vdev_id,
  4502. ol_txrx_vdev_delete_cb callback,
  4503. void *cb_context)
  4504. {
  4505. struct dp_soc *soc = (struct dp_soc *)cdp_soc;
  4506. struct dp_pdev *pdev;
  4507. struct dp_neighbour_peer *peer = NULL;
  4508. struct dp_neighbour_peer *temp_peer = NULL;
  4509. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  4510. if (!vdev)
  4511. return QDF_STATUS_E_FAILURE;
  4512. pdev = vdev->pdev;
  4513. soc->vdev_id_map[vdev->vdev_id] = NULL;
  4514. if (wlan_op_mode_sta == vdev->opmode)
  4515. dp_peer_delete_wifi3((struct cdp_soc_t *)soc, vdev->vdev_id,
  4516. vdev->vap_self_peer->mac_addr.raw, 0);
  4517. /*
  4518. * If Target is hung, flush all peers before detaching vdev
  4519. * this will free all references held due to missing
  4520. * unmap commands from Target
  4521. */
  4522. if (!hif_is_target_ready(HIF_GET_SOFTC(soc->hif_handle)))
  4523. dp_vdev_flush_peers((struct cdp_vdev *)vdev, false);
  4524. else if (hif_get_target_status(soc->hif_handle) == TARGET_STATUS_RESET)
  4525. dp_vdev_flush_peers((struct cdp_vdev *)vdev, true);
  4526. /*
  4527. * Use peer_ref_mutex while accessing peer_list, in case
  4528. * a peer is in the process of being removed from the list.
  4529. */
  4530. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  4531. /* check that the vdev has no peers allocated */
  4532. if (!TAILQ_EMPTY(&vdev->peer_list)) {
  4533. /* debug print - will be removed later */
  4534. dp_warn("not deleting vdev object %pK (%pM) until deletion finishes for all its peers",
  4535. vdev, vdev->mac_addr.raw);
  4536. if (vdev->vdev_dp_ext_handle) {
  4537. qdf_mem_free(vdev->vdev_dp_ext_handle);
  4538. vdev->vdev_dp_ext_handle = NULL;
  4539. }
  4540. /* indicate that the vdev needs to be deleted */
  4541. vdev->delete.pending = 1;
  4542. vdev->delete.callback = callback;
  4543. vdev->delete.context = cb_context;
  4544. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  4545. return QDF_STATUS_E_FAILURE;
  4546. }
  4547. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  4548. if (wlan_op_mode_monitor == vdev->opmode)
  4549. goto free_vdev;
  4550. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  4551. if (!soc->hw_nac_monitor_support) {
  4552. TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
  4553. neighbour_peer_list_elem) {
  4554. QDF_ASSERT(peer->vdev != vdev);
  4555. }
  4556. } else {
  4557. TAILQ_FOREACH_SAFE(peer, &pdev->neighbour_peers_list,
  4558. neighbour_peer_list_elem, temp_peer) {
  4559. if (peer->vdev == vdev) {
  4560. TAILQ_REMOVE(&pdev->neighbour_peers_list, peer,
  4561. neighbour_peer_list_elem);
  4562. qdf_mem_free(peer);
  4563. }
  4564. }
  4565. }
  4566. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  4567. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  4568. /* remove the vdev from its parent pdev's list */
  4569. TAILQ_REMOVE(&pdev->vdev_list, vdev, vdev_list_elem);
  4570. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  4571. dp_tx_vdev_detach(vdev);
  4572. dp_rx_vdev_detach(vdev);
  4573. free_vdev:
  4574. if (wlan_op_mode_monitor == vdev->opmode)
  4575. pdev->monitor_vdev = NULL;
  4576. if (vdev->vdev_dp_ext_handle) {
  4577. qdf_mem_free(vdev->vdev_dp_ext_handle);
  4578. vdev->vdev_dp_ext_handle = NULL;
  4579. }
  4580. dp_info("deleting vdev object %pK (%pM)", vdev, vdev->mac_addr.raw);
  4581. qdf_mem_free(vdev);
  4582. if (callback)
  4583. callback(cb_context);
  4584. return QDF_STATUS_SUCCESS;
  4585. }
  4586. #ifdef FEATURE_AST
  4587. /*
  4588. * dp_peer_delete_ast_entries(): Delete all AST entries for a peer
  4589. * @soc - datapath soc handle
  4590. * @peer - datapath peer handle
  4591. *
  4592. * Delete the AST entries belonging to a peer
  4593. */
  4594. static inline void dp_peer_delete_ast_entries(struct dp_soc *soc,
  4595. struct dp_peer *peer)
  4596. {
  4597. struct dp_ast_entry *ast_entry, *temp_ast_entry;
  4598. DP_PEER_ITERATE_ASE_LIST(peer, ast_entry, temp_ast_entry)
  4599. dp_peer_del_ast(soc, ast_entry);
  4600. peer->self_ast_entry = NULL;
  4601. }
  4602. #else
  4603. static inline void dp_peer_delete_ast_entries(struct dp_soc *soc,
  4604. struct dp_peer *peer)
  4605. {
  4606. }
  4607. #endif
  4608. #if ATH_SUPPORT_WRAP
  4609. static inline struct dp_peer *dp_peer_can_reuse(struct dp_vdev *vdev,
  4610. uint8_t *peer_mac_addr)
  4611. {
  4612. struct dp_peer *peer;
  4613. peer = dp_peer_find_hash_find(vdev->pdev->soc, peer_mac_addr,
  4614. 0, vdev->vdev_id);
  4615. if (!peer)
  4616. return NULL;
  4617. if (peer->bss_peer)
  4618. return peer;
  4619. dp_peer_unref_delete(peer);
  4620. return NULL;
  4621. }
  4622. #else
  4623. static inline struct dp_peer *dp_peer_can_reuse(struct dp_vdev *vdev,
  4624. uint8_t *peer_mac_addr)
  4625. {
  4626. struct dp_peer *peer;
  4627. peer = dp_peer_find_hash_find(vdev->pdev->soc, peer_mac_addr,
  4628. 0, vdev->vdev_id);
  4629. if (!peer)
  4630. return NULL;
  4631. if (peer->bss_peer && (peer->vdev->vdev_id == vdev->vdev_id))
  4632. return peer;
  4633. dp_peer_unref_delete(peer);
  4634. return NULL;
  4635. }
  4636. #endif
  4637. #ifdef FEATURE_AST
  4638. static inline void dp_peer_ast_handle_roam_del(struct dp_soc *soc,
  4639. struct dp_pdev *pdev,
  4640. uint8_t *peer_mac_addr)
  4641. {
  4642. struct dp_ast_entry *ast_entry;
  4643. qdf_spin_lock_bh(&soc->ast_lock);
  4644. if (soc->ast_override_support)
  4645. ast_entry = dp_peer_ast_hash_find_by_pdevid(soc, peer_mac_addr,
  4646. pdev->pdev_id);
  4647. else
  4648. ast_entry = dp_peer_ast_hash_find_soc(soc, peer_mac_addr);
  4649. if (ast_entry && ast_entry->next_hop && !ast_entry->delete_in_progress)
  4650. dp_peer_del_ast(soc, ast_entry);
  4651. qdf_spin_unlock_bh(&soc->ast_lock);
  4652. }
  4653. #endif
  4654. #ifdef PEER_CACHE_RX_PKTS
  4655. static inline void dp_peer_rx_bufq_resources_init(struct dp_peer *peer)
  4656. {
  4657. qdf_spinlock_create(&peer->bufq_info.bufq_lock);
  4658. peer->bufq_info.thresh = DP_RX_CACHED_BUFQ_THRESH;
  4659. qdf_list_create(&peer->bufq_info.cached_bufq, DP_RX_CACHED_BUFQ_THRESH);
  4660. }
  4661. #else
  4662. static inline void dp_peer_rx_bufq_resources_init(struct dp_peer *peer)
  4663. {
  4664. }
  4665. #endif
  4666. #ifdef WLAN_FEATURE_STATS_EXT
  4667. /*
  4668. * dp_set_ignore_reo_status_cb() - set ignore reo status cb flag
  4669. * @soc: dp soc handle
  4670. * @flag: flag to set or reset
  4671. *
  4672. * Return: None
  4673. */
  4674. static inline void dp_set_ignore_reo_status_cb(struct dp_soc *soc,
  4675. bool flag)
  4676. {
  4677. soc->ignore_reo_status_cb = flag;
  4678. }
  4679. #else
  4680. static inline void dp_set_ignore_reo_status_cb(struct dp_soc *soc,
  4681. bool flag)
  4682. {
  4683. }
  4684. #endif
  4685. /*
  4686. * dp_peer_create_wifi3() - attach txrx peer
  4687. * @soc_hdl: Datapath soc handle
  4688. * @vdev_id: id of vdev
  4689. * @peer_mac_addr: Peer MAC address
  4690. *
  4691. * Return: DP peeer handle on success, NULL on failure
  4692. */
  4693. static void *dp_peer_create_wifi3(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  4694. uint8_t *peer_mac_addr)
  4695. {
  4696. struct dp_peer *peer;
  4697. int i;
  4698. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  4699. struct dp_pdev *pdev;
  4700. struct cdp_peer_cookie peer_cookie;
  4701. enum cdp_txrx_ast_entry_type ast_type = CDP_TXRX_AST_TYPE_STATIC;
  4702. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  4703. if (!vdev || !peer_mac_addr)
  4704. return NULL;
  4705. pdev = vdev->pdev;
  4706. soc = pdev->soc;
  4707. /*
  4708. * If a peer entry with given MAC address already exists,
  4709. * reuse the peer and reset the state of peer.
  4710. */
  4711. peer = dp_peer_can_reuse(vdev, peer_mac_addr);
  4712. if (peer) {
  4713. qdf_atomic_init(&peer->is_default_route_set);
  4714. dp_peer_cleanup(vdev, peer, true);
  4715. qdf_spin_lock_bh(&soc->ast_lock);
  4716. dp_peer_delete_ast_entries(soc, peer);
  4717. peer->delete_in_progress = false;
  4718. qdf_spin_unlock_bh(&soc->ast_lock);
  4719. if ((vdev->opmode == wlan_op_mode_sta) &&
  4720. !qdf_mem_cmp(peer_mac_addr, &vdev->mac_addr.raw[0],
  4721. QDF_MAC_ADDR_SIZE)) {
  4722. ast_type = CDP_TXRX_AST_TYPE_SELF;
  4723. }
  4724. dp_peer_add_ast(soc, peer, peer_mac_addr, ast_type, 0);
  4725. /*
  4726. * Control path maintains a node count which is incremented
  4727. * for every new peer create command. Since new peer is not being
  4728. * created and earlier reference is reused here,
  4729. * peer_unref_delete event is sent to control path to
  4730. * increment the count back.
  4731. */
  4732. if (soc->cdp_soc.ol_ops->peer_unref_delete) {
  4733. soc->cdp_soc.ol_ops->peer_unref_delete(
  4734. soc->ctrl_psoc,
  4735. pdev->pdev_id,
  4736. peer->mac_addr.raw, vdev->mac_addr.raw,
  4737. vdev->opmode);
  4738. }
  4739. dp_local_peer_id_alloc(pdev, peer);
  4740. qdf_spinlock_create(&peer->peer_info_lock);
  4741. dp_peer_rx_bufq_resources_init(peer);
  4742. DP_STATS_INIT(peer);
  4743. DP_STATS_UPD(peer, rx.avg_rssi, INVALID_RSSI);
  4744. return (void *)peer;
  4745. } else {
  4746. /*
  4747. * When a STA roams from RPTR AP to ROOT AP and vice versa, we
  4748. * need to remove the AST entry which was earlier added as a WDS
  4749. * entry.
  4750. * If an AST entry exists, but no peer entry exists with a given
  4751. * MAC addresses, we could deduce it as a WDS entry
  4752. */
  4753. dp_peer_ast_handle_roam_del(soc, pdev, peer_mac_addr);
  4754. }
  4755. #ifdef notyet
  4756. peer = (struct dp_peer *)qdf_mempool_alloc(soc->osdev,
  4757. soc->mempool_ol_ath_peer);
  4758. #else
  4759. peer = (struct dp_peer *)qdf_mem_malloc(sizeof(*peer));
  4760. #endif
  4761. if (!peer)
  4762. return NULL; /* failure */
  4763. qdf_mem_zero(peer, sizeof(struct dp_peer));
  4764. TAILQ_INIT(&peer->ast_entry_list);
  4765. /* store provided params */
  4766. peer->vdev = vdev;
  4767. if ((vdev->opmode == wlan_op_mode_sta) &&
  4768. !qdf_mem_cmp(peer_mac_addr, &vdev->mac_addr.raw[0],
  4769. QDF_MAC_ADDR_SIZE)) {
  4770. ast_type = CDP_TXRX_AST_TYPE_SELF;
  4771. }
  4772. dp_peer_add_ast(soc, peer, peer_mac_addr, ast_type, 0);
  4773. qdf_spinlock_create(&peer->peer_info_lock);
  4774. dp_peer_rx_bufq_resources_init(peer);
  4775. qdf_mem_copy(
  4776. &peer->mac_addr.raw[0], peer_mac_addr, QDF_MAC_ADDR_SIZE);
  4777. /* initialize the peer_id */
  4778. for (i = 0; i < MAX_NUM_PEER_ID_PER_PEER; i++)
  4779. peer->peer_ids[i] = HTT_INVALID_PEER;
  4780. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  4781. qdf_atomic_init(&peer->ref_cnt);
  4782. /* keep one reference for attach */
  4783. qdf_atomic_inc(&peer->ref_cnt);
  4784. /* add this peer into the vdev's list */
  4785. if (wlan_op_mode_sta == vdev->opmode)
  4786. TAILQ_INSERT_HEAD(&vdev->peer_list, peer, peer_list_elem);
  4787. else
  4788. TAILQ_INSERT_TAIL(&vdev->peer_list, peer, peer_list_elem);
  4789. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  4790. /* TODO: See if hash based search is required */
  4791. dp_peer_find_hash_add(soc, peer);
  4792. /* Initialize the peer state */
  4793. peer->state = OL_TXRX_PEER_STATE_DISC;
  4794. dp_info("vdev %pK created peer %pK (%pM) ref_cnt: %d",
  4795. vdev, peer, peer->mac_addr.raw,
  4796. qdf_atomic_read(&peer->ref_cnt));
  4797. /*
  4798. * For every peer MAp message search and set if bss_peer
  4799. */
  4800. if (qdf_mem_cmp(peer->mac_addr.raw, vdev->mac_addr.raw,
  4801. QDF_MAC_ADDR_SIZE) == 0 &&
  4802. (wlan_op_mode_sta != vdev->opmode)) {
  4803. dp_info("vdev bss_peer!!");
  4804. peer->bss_peer = 1;
  4805. vdev->vap_bss_peer = peer;
  4806. }
  4807. if (wlan_op_mode_sta == vdev->opmode &&
  4808. qdf_mem_cmp(peer->mac_addr.raw, vdev->mac_addr.raw,
  4809. QDF_MAC_ADDR_SIZE) == 0) {
  4810. vdev->vap_self_peer = peer;
  4811. }
  4812. if (wlan_op_mode_sta == vdev->opmode &&
  4813. qdf_mem_cmp(peer->mac_addr.raw, vdev->mac_addr.raw,
  4814. QDF_MAC_ADDR_SIZE) != 0) {
  4815. dp_set_ignore_reo_status_cb(soc, false);
  4816. }
  4817. for (i = 0; i < DP_MAX_TIDS; i++)
  4818. qdf_spinlock_create(&peer->rx_tid[i].tid_lock);
  4819. peer->valid = 1;
  4820. dp_local_peer_id_alloc(pdev, peer);
  4821. DP_STATS_INIT(peer);
  4822. DP_STATS_UPD(peer, rx.avg_rssi, INVALID_RSSI);
  4823. qdf_mem_copy(peer_cookie.mac_addr, peer->mac_addr.raw,
  4824. QDF_MAC_ADDR_SIZE);
  4825. peer_cookie.ctx = NULL;
  4826. peer_cookie.pdev_id = pdev->pdev_id;
  4827. peer_cookie.cookie = pdev->next_peer_cookie++;
  4828. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  4829. dp_wdi_event_handler(WDI_EVENT_PEER_CREATE, pdev->soc,
  4830. (void *)&peer_cookie,
  4831. peer->peer_ids[0], WDI_NO_VAL, pdev->pdev_id);
  4832. #endif
  4833. if (soc->wlanstats_enabled) {
  4834. if (!peer_cookie.ctx) {
  4835. pdev->next_peer_cookie--;
  4836. qdf_err("Failed to initialize peer rate stats");
  4837. } else {
  4838. peer->wlanstats_ctx = (struct cdp_peer_rate_stats_ctx *)
  4839. peer_cookie.ctx;
  4840. }
  4841. }
  4842. return (void *)peer;
  4843. }
  4844. /*
  4845. * dp_vdev_get_default_reo_hash() - get reo dest ring and hash values for a vdev
  4846. * @vdev: Datapath VDEV handle
  4847. * @reo_dest: pointer to default reo_dest ring for vdev to be populated
  4848. * @hash_based: pointer to hash value (enabled/disabled) to be populated
  4849. *
  4850. * Return: None
  4851. */
  4852. static
  4853. void dp_vdev_get_default_reo_hash(struct dp_vdev *vdev,
  4854. enum cdp_host_reo_dest_ring *reo_dest,
  4855. bool *hash_based)
  4856. {
  4857. struct dp_soc *soc;
  4858. struct dp_pdev *pdev;
  4859. pdev = vdev->pdev;
  4860. soc = pdev->soc;
  4861. /*
  4862. * hash based steering is disabled for Radios which are offloaded
  4863. * to NSS
  4864. */
  4865. if (!wlan_cfg_get_dp_pdev_nss_enabled(pdev->wlan_cfg_ctx))
  4866. *hash_based = wlan_cfg_is_rx_hash_enabled(soc->wlan_cfg_ctx);
  4867. /*
  4868. * Below line of code will ensure the proper reo_dest ring is chosen
  4869. * for cases where toeplitz hash cannot be generated (ex: non TCP/UDP)
  4870. */
  4871. *reo_dest = pdev->reo_dest;
  4872. }
  4873. #ifdef IPA_OFFLOAD
  4874. /**
  4875. * dp_is_vdev_subtype_p2p() - Check if the subtype for vdev is P2P
  4876. * @vdev: Virtual device
  4877. *
  4878. * Return: true if the vdev is of subtype P2P
  4879. * false if the vdev is of any other subtype
  4880. */
  4881. static inline bool dp_is_vdev_subtype_p2p(struct dp_vdev *vdev)
  4882. {
  4883. if (vdev->subtype == wlan_op_subtype_p2p_device ||
  4884. vdev->subtype == wlan_op_subtype_p2p_cli ||
  4885. vdev->subtype == wlan_op_subtype_p2p_go)
  4886. return true;
  4887. return false;
  4888. }
  4889. /*
  4890. * dp_peer_setup_get_reo_hash() - get reo dest ring and hash values for a peer
  4891. * @vdev: Datapath VDEV handle
  4892. * @reo_dest: pointer to default reo_dest ring for vdev to be populated
  4893. * @hash_based: pointer to hash value (enabled/disabled) to be populated
  4894. *
  4895. * If IPA is enabled in ini, for SAP mode, disable hash based
  4896. * steering, use default reo_dst ring for RX. Use config values for other modes.
  4897. * Return: None
  4898. */
  4899. static void dp_peer_setup_get_reo_hash(struct dp_vdev *vdev,
  4900. enum cdp_host_reo_dest_ring *reo_dest,
  4901. bool *hash_based)
  4902. {
  4903. struct dp_soc *soc;
  4904. struct dp_pdev *pdev;
  4905. pdev = vdev->pdev;
  4906. soc = pdev->soc;
  4907. dp_vdev_get_default_reo_hash(vdev, reo_dest, hash_based);
  4908. /* For P2P-GO interfaces we do not need to change the REO
  4909. * configuration even if IPA config is enabled
  4910. */
  4911. if (dp_is_vdev_subtype_p2p(vdev))
  4912. return;
  4913. /*
  4914. * If IPA is enabled, disable hash-based flow steering and set
  4915. * reo_dest_ring_4 as the REO ring to receive packets on.
  4916. * IPA is configured to reap reo_dest_ring_4.
  4917. *
  4918. * Note - REO DST indexes are from 0 - 3, while cdp_host_reo_dest_ring
  4919. * value enum value is from 1 - 4.
  4920. * Hence, *reo_dest = IPA_REO_DEST_RING_IDX + 1
  4921. */
  4922. if (wlan_cfg_is_ipa_enabled(soc->wlan_cfg_ctx)) {
  4923. if (vdev->opmode == wlan_op_mode_ap) {
  4924. *reo_dest = IPA_REO_DEST_RING_IDX + 1;
  4925. *hash_based = 0;
  4926. } else if (vdev->opmode == wlan_op_mode_sta &&
  4927. dp_ipa_is_mdm_platform()) {
  4928. *reo_dest = IPA_REO_DEST_RING_IDX + 1;
  4929. }
  4930. }
  4931. }
  4932. #else
  4933. /*
  4934. * dp_peer_setup_get_reo_hash() - get reo dest ring and hash values for a peer
  4935. * @vdev: Datapath VDEV handle
  4936. * @reo_dest: pointer to default reo_dest ring for vdev to be populated
  4937. * @hash_based: pointer to hash value (enabled/disabled) to be populated
  4938. *
  4939. * Use system config values for hash based steering.
  4940. * Return: None
  4941. */
  4942. static void dp_peer_setup_get_reo_hash(struct dp_vdev *vdev,
  4943. enum cdp_host_reo_dest_ring *reo_dest,
  4944. bool *hash_based)
  4945. {
  4946. dp_vdev_get_default_reo_hash(vdev, reo_dest, hash_based);
  4947. }
  4948. #endif /* IPA_OFFLOAD */
  4949. /*
  4950. * dp_peer_setup_wifi3() - initialize the peer
  4951. * @soc_hdl: soc handle object
  4952. * @vdev_id : vdev_id of vdev object
  4953. * @peer_mac: Peer's mac address
  4954. *
  4955. * Return: QDF_STATUS
  4956. */
  4957. static QDF_STATUS
  4958. dp_peer_setup_wifi3(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  4959. uint8_t *peer_mac)
  4960. {
  4961. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  4962. struct dp_pdev *pdev;
  4963. bool hash_based = 0;
  4964. enum cdp_host_reo_dest_ring reo_dest;
  4965. QDF_STATUS status = QDF_STATUS_SUCCESS;
  4966. struct dp_vdev *vdev =
  4967. dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  4968. struct dp_peer *peer =
  4969. dp_peer_find_hash_find(soc, peer_mac, 0, vdev_id);
  4970. if (!vdev || !peer || peer->delete_in_progress) {
  4971. status = QDF_STATUS_E_FAILURE;
  4972. goto fail;
  4973. }
  4974. pdev = vdev->pdev;
  4975. dp_peer_setup_get_reo_hash(vdev, &reo_dest, &hash_based);
  4976. dp_info("pdev: %d vdev :%d opmode:%u hash-based-steering:%d default-reo_dest:%u",
  4977. pdev->pdev_id, vdev->vdev_id,
  4978. vdev->opmode, hash_based, reo_dest);
  4979. /*
  4980. * There are corner cases where the AD1 = AD2 = "VAPs address"
  4981. * i.e both the devices have same MAC address. In these
  4982. * cases we want such pkts to be processed in NULL Q handler
  4983. * which is REO2TCL ring. for this reason we should
  4984. * not setup reo_queues and default route for bss_peer.
  4985. */
  4986. if (peer->bss_peer && vdev->opmode == wlan_op_mode_ap) {
  4987. status = QDF_STATUS_E_FAILURE;
  4988. goto fail;
  4989. }
  4990. if (soc->cdp_soc.ol_ops->peer_set_default_routing) {
  4991. /* TODO: Check the destination ring number to be passed to FW */
  4992. soc->cdp_soc.ol_ops->peer_set_default_routing(
  4993. soc->ctrl_psoc,
  4994. peer->vdev->pdev->pdev_id,
  4995. peer->mac_addr.raw,
  4996. peer->vdev->vdev_id, hash_based, reo_dest);
  4997. }
  4998. qdf_atomic_set(&peer->is_default_route_set, 1);
  4999. dp_peer_rx_init(pdev, peer);
  5000. dp_peer_tx_init(pdev, peer);
  5001. dp_peer_ppdu_delayed_ba_init(peer);
  5002. fail:
  5003. if (peer)
  5004. dp_peer_unref_delete(peer);
  5005. return status;
  5006. }
  5007. /*
  5008. * dp_cp_peer_del_resp_handler - Handle the peer delete response
  5009. * @soc_hdl: Datapath SOC handle
  5010. * @vdev_id: id of virtual device object
  5011. * @mac_addr: Mac address of the peer
  5012. *
  5013. * Return: QDF_STATUS
  5014. */
  5015. static QDF_STATUS dp_cp_peer_del_resp_handler(struct cdp_soc_t *soc_hdl,
  5016. uint8_t vdev_id,
  5017. uint8_t *mac_addr)
  5018. {
  5019. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  5020. struct dp_ast_entry *ast_entry = NULL;
  5021. txrx_ast_free_cb cb = NULL;
  5022. void *cookie;
  5023. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  5024. if (!vdev)
  5025. return QDF_STATUS_E_FAILURE;
  5026. qdf_spin_lock_bh(&soc->ast_lock);
  5027. if (soc->ast_override_support)
  5028. ast_entry =
  5029. dp_peer_ast_hash_find_by_pdevid(soc, mac_addr,
  5030. vdev->pdev->pdev_id);
  5031. else
  5032. ast_entry = dp_peer_ast_hash_find_soc(soc, mac_addr);
  5033. /* in case of qwrap we have multiple BSS peers
  5034. * with same mac address
  5035. *
  5036. * AST entry for this mac address will be created
  5037. * only for one peer hence it will be NULL here
  5038. */
  5039. if (!ast_entry || ast_entry->peer || !ast_entry->delete_in_progress) {
  5040. qdf_spin_unlock_bh(&soc->ast_lock);
  5041. return QDF_STATUS_E_FAILURE;
  5042. }
  5043. if (ast_entry->is_mapped)
  5044. soc->ast_table[ast_entry->ast_idx] = NULL;
  5045. DP_STATS_INC(soc, ast.deleted, 1);
  5046. dp_peer_ast_hash_remove(soc, ast_entry);
  5047. cb = ast_entry->callback;
  5048. cookie = ast_entry->cookie;
  5049. ast_entry->callback = NULL;
  5050. ast_entry->cookie = NULL;
  5051. soc->num_ast_entries--;
  5052. qdf_spin_unlock_bh(&soc->ast_lock);
  5053. if (cb) {
  5054. cb(soc->ctrl_psoc,
  5055. dp_soc_to_cdp_soc(soc),
  5056. cookie,
  5057. CDP_TXRX_AST_DELETED);
  5058. }
  5059. qdf_mem_free(ast_entry);
  5060. return QDF_STATUS_SUCCESS;
  5061. }
  5062. /*
  5063. * dp_set_ba_aging_timeout() - set ba aging timeout per AC
  5064. * @txrx_soc: cdp soc handle
  5065. * @ac: Access category
  5066. * @value: timeout value in millisec
  5067. *
  5068. * Return: void
  5069. */
  5070. static void dp_set_ba_aging_timeout(struct cdp_soc_t *txrx_soc,
  5071. uint8_t ac, uint32_t value)
  5072. {
  5073. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  5074. hal_set_ba_aging_timeout(soc->hal_soc, ac, value);
  5075. }
  5076. /*
  5077. * dp_get_ba_aging_timeout() - get ba aging timeout per AC
  5078. * @txrx_soc: cdp soc handle
  5079. * @ac: access category
  5080. * @value: timeout value in millisec
  5081. *
  5082. * Return: void
  5083. */
  5084. static void dp_get_ba_aging_timeout(struct cdp_soc_t *txrx_soc,
  5085. uint8_t ac, uint32_t *value)
  5086. {
  5087. struct dp_soc *soc = (struct dp_soc *)txrx_soc;
  5088. hal_get_ba_aging_timeout(soc->hal_soc, ac, value);
  5089. }
  5090. /*
  5091. * dp_set_pdev_reo_dest() - set the reo destination ring for this pdev
  5092. * @txrx_soc: cdp soc handle
  5093. * @pdev_id: id of physical device object
  5094. * @val: reo destination ring index (1 - 4)
  5095. *
  5096. * Return: QDF_STATUS
  5097. */
  5098. static QDF_STATUS
  5099. dp_set_pdev_reo_dest(struct cdp_soc_t *txrx_soc, uint8_t pdev_id,
  5100. enum cdp_host_reo_dest_ring val)
  5101. {
  5102. struct dp_pdev *pdev =
  5103. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)txrx_soc,
  5104. pdev_id);
  5105. if (pdev) {
  5106. pdev->reo_dest = val;
  5107. return QDF_STATUS_SUCCESS;
  5108. }
  5109. return QDF_STATUS_E_FAILURE;
  5110. }
  5111. /*
  5112. * dp_get_pdev_reo_dest() - get the reo destination for this pdev
  5113. * @txrx_soc: cdp soc handle
  5114. * @pdev_id: id of physical device object
  5115. *
  5116. * Return: reo destination ring index
  5117. */
  5118. static enum cdp_host_reo_dest_ring
  5119. dp_get_pdev_reo_dest(struct cdp_soc_t *txrx_soc, uint8_t pdev_id)
  5120. {
  5121. struct dp_pdev *pdev =
  5122. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)txrx_soc,
  5123. pdev_id);
  5124. if (pdev)
  5125. return pdev->reo_dest;
  5126. else
  5127. return cdp_host_reo_dest_ring_unknown;
  5128. }
  5129. /*
  5130. * dp_set_filter_neigh_peers() - set filter neighbour peers for smart mesh
  5131. * @pdev_handle: device object
  5132. * @val: value to be set
  5133. *
  5134. * Return: void
  5135. */
  5136. static int dp_set_filter_neigh_peers(struct dp_pdev *pdev,
  5137. bool val)
  5138. {
  5139. /* Enable/Disable smart mesh filtering. This flag will be checked
  5140. * during rx processing to check if packets are from NAC clients.
  5141. */
  5142. pdev->filter_neighbour_peers = val;
  5143. return 0;
  5144. }
  5145. /*
  5146. * dp_update_filter_neighbour_peers() - set neighbour peers(nac clients)
  5147. * address for smart mesh filtering
  5148. * @txrx_soc: cdp soc handle
  5149. * @vdev_id: id of virtual device object
  5150. * @cmd: Add/Del command
  5151. * @macaddr: nac client mac address
  5152. *
  5153. * Return: success/failure
  5154. */
  5155. static int dp_update_filter_neighbour_peers(struct cdp_soc_t *soc,
  5156. uint8_t vdev_id,
  5157. uint32_t cmd, uint8_t *macaddr)
  5158. {
  5159. struct dp_pdev *pdev;
  5160. struct dp_neighbour_peer *peer = NULL;
  5161. struct dp_vdev *vdev =
  5162. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  5163. vdev_id);
  5164. if (!vdev || !macaddr)
  5165. goto fail0;
  5166. pdev = vdev->pdev;
  5167. if (!pdev)
  5168. goto fail0;
  5169. /* Store address of NAC (neighbour peer) which will be checked
  5170. * against TA of received packets.
  5171. */
  5172. if (cmd == DP_NAC_PARAM_ADD) {
  5173. peer = (struct dp_neighbour_peer *) qdf_mem_malloc(
  5174. sizeof(*peer));
  5175. if (!peer) {
  5176. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  5177. FL("DP neighbour peer node memory allocation failed"));
  5178. goto fail0;
  5179. }
  5180. qdf_mem_copy(&peer->neighbour_peers_macaddr.raw[0],
  5181. macaddr, QDF_MAC_ADDR_SIZE);
  5182. peer->vdev = vdev;
  5183. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  5184. /* add this neighbour peer into the list */
  5185. TAILQ_INSERT_TAIL(&pdev->neighbour_peers_list, peer,
  5186. neighbour_peer_list_elem);
  5187. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  5188. /* first neighbour */
  5189. if (!pdev->neighbour_peers_added) {
  5190. pdev->neighbour_peers_added = true;
  5191. dp_ppdu_ring_cfg(pdev);
  5192. }
  5193. return 1;
  5194. } else if (cmd == DP_NAC_PARAM_DEL) {
  5195. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  5196. TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
  5197. neighbour_peer_list_elem) {
  5198. if (!qdf_mem_cmp(&peer->neighbour_peers_macaddr.raw[0],
  5199. macaddr, QDF_MAC_ADDR_SIZE)) {
  5200. /* delete this peer from the list */
  5201. TAILQ_REMOVE(&pdev->neighbour_peers_list,
  5202. peer, neighbour_peer_list_elem);
  5203. qdf_mem_free(peer);
  5204. break;
  5205. }
  5206. }
  5207. /* last neighbour deleted */
  5208. if (TAILQ_EMPTY(&pdev->neighbour_peers_list)) {
  5209. pdev->neighbour_peers_added = false;
  5210. dp_ppdu_ring_cfg(pdev);
  5211. }
  5212. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  5213. if (!pdev->mcopy_mode && !pdev->neighbour_peers_added &&
  5214. !pdev->enhanced_stats_en)
  5215. dp_ppdu_ring_reset(pdev);
  5216. return 1;
  5217. }
  5218. fail0:
  5219. return 0;
  5220. }
  5221. /*
  5222. * dp_get_sec_type() - Get the security type
  5223. * @soc: soc handle
  5224. * @vdev_id: id of dp handle
  5225. * @peer_mac: mac of datapath PEER handle
  5226. * @sec_idx: Security id (mcast, ucast)
  5227. *
  5228. * return sec_type: Security type
  5229. */
  5230. static int dp_get_sec_type(struct cdp_soc_t *soc, uint8_t vdev_id,
  5231. uint8_t *peer_mac, uint8_t sec_idx)
  5232. {
  5233. int sec_type = 0;
  5234. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)soc,
  5235. peer_mac, 0, vdev_id);
  5236. if (!peer || peer->delete_in_progress) {
  5237. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  5238. "%s: Peer is NULL!\n", __func__);
  5239. goto fail;
  5240. }
  5241. sec_type = peer->security[sec_idx].sec_type;
  5242. fail:
  5243. if (peer)
  5244. dp_peer_unref_delete(peer);
  5245. return sec_type;
  5246. }
  5247. /*
  5248. * dp_peer_authorize() - authorize txrx peer
  5249. * @soc: soc handle
  5250. * @vdev_id: id of dp handle
  5251. * @peer_mac: mac of datapath PEER handle
  5252. * @authorize
  5253. *
  5254. */
  5255. static QDF_STATUS
  5256. dp_peer_authorize(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  5257. uint8_t *peer_mac, uint32_t authorize)
  5258. {
  5259. QDF_STATUS status = QDF_STATUS_SUCCESS;
  5260. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  5261. struct dp_peer *peer = dp_peer_find_hash_find(soc,
  5262. peer_mac,
  5263. 0, vdev_id);
  5264. if (!peer || peer->delete_in_progress) {
  5265. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  5266. "%s: Peer is NULL!\n", __func__);
  5267. status = QDF_STATUS_E_FAILURE;
  5268. } else {
  5269. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  5270. peer->authorize = authorize ? 1 : 0;
  5271. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  5272. }
  5273. if (peer)
  5274. dp_peer_unref_delete(peer);
  5275. return status;
  5276. }
  5277. /*
  5278. * dp_vdev_reset_peer() - Update peer related member in vdev
  5279. as peer is going to free
  5280. * @vdev: datapath vdev handle
  5281. * @peer: dataptah peer handle
  5282. *
  5283. * Return: None
  5284. */
  5285. static void dp_vdev_reset_peer(struct dp_vdev *vdev,
  5286. struct dp_peer *peer)
  5287. {
  5288. struct dp_peer *bss_peer = NULL;
  5289. if (!vdev) {
  5290. dp_err("vdev is NULL");
  5291. } else {
  5292. if (vdev->vap_bss_peer == peer)
  5293. vdev->vap_bss_peer = NULL;
  5294. if (vdev && vdev->vap_bss_peer) {
  5295. bss_peer = vdev->vap_bss_peer;
  5296. DP_UPDATE_STATS(vdev, peer);
  5297. }
  5298. }
  5299. }
  5300. /*
  5301. * dp_peer_release_mem() - free dp peer handle memory
  5302. * @soc: dataptah soc handle
  5303. * @pdev: datapath pdev handle
  5304. * @peer: datapath peer handle
  5305. * @vdev_opmode: Vdev operation mode
  5306. * @vdev_mac_addr: Vdev Mac address
  5307. *
  5308. * Return: None
  5309. */
  5310. static void dp_peer_release_mem(struct dp_soc *soc,
  5311. struct dp_pdev *pdev,
  5312. struct dp_peer *peer,
  5313. enum wlan_op_mode vdev_opmode,
  5314. uint8_t *vdev_mac_addr)
  5315. {
  5316. if (soc->cdp_soc.ol_ops->peer_unref_delete)
  5317. soc->cdp_soc.ol_ops->peer_unref_delete(
  5318. soc->ctrl_psoc,
  5319. pdev->pdev_id,
  5320. peer->mac_addr.raw, vdev_mac_addr,
  5321. vdev_opmode);
  5322. /*
  5323. * Peer AST list hast to be empty here
  5324. */
  5325. DP_AST_ASSERT(TAILQ_EMPTY(&peer->ast_entry_list));
  5326. qdf_mem_free(peer);
  5327. }
  5328. /**
  5329. * dp_delete_pending_vdev() - check and process vdev delete
  5330. * @pdev: DP specific pdev pointer
  5331. * @vdev: DP specific vdev pointer
  5332. * @vdev_id: vdev id corresponding to vdev
  5333. *
  5334. * This API does following:
  5335. * 1) It releases tx flow pools buffers as vdev is
  5336. * going down and no peers are associated.
  5337. * 2) It also detaches vdev before cleaning vdev (struct dp_vdev) memory
  5338. */
  5339. static void dp_delete_pending_vdev(struct dp_pdev *pdev, struct dp_vdev *vdev,
  5340. uint8_t vdev_id)
  5341. {
  5342. ol_txrx_vdev_delete_cb vdev_delete_cb = NULL;
  5343. void *vdev_delete_context = NULL;
  5344. vdev_delete_cb = vdev->delete.callback;
  5345. vdev_delete_context = vdev->delete.context;
  5346. dp_info("deleting vdev object %pK (%pM)- its last peer is done",
  5347. vdev, vdev->mac_addr.raw);
  5348. /* all peers are gone, go ahead and delete it */
  5349. dp_tx_flow_pool_unmap_handler(pdev, vdev_id,
  5350. FLOW_TYPE_VDEV, vdev_id);
  5351. dp_tx_vdev_detach(vdev);
  5352. pdev->soc->vdev_id_map[vdev_id] = NULL;
  5353. if (wlan_op_mode_monitor == vdev->opmode) {
  5354. pdev->monitor_vdev = NULL;
  5355. } else {
  5356. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  5357. TAILQ_REMOVE(&pdev->vdev_list, vdev, vdev_list_elem);
  5358. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  5359. }
  5360. dp_info("deleting vdev object %pK (%pM)",
  5361. vdev, vdev->mac_addr.raw);
  5362. qdf_mem_free(vdev);
  5363. vdev = NULL;
  5364. if (vdev_delete_cb)
  5365. vdev_delete_cb(vdev_delete_context);
  5366. }
  5367. /*
  5368. * dp_peer_unref_delete() - unref and delete peer
  5369. * @peer_handle: Datapath peer handle
  5370. *
  5371. */
  5372. void dp_peer_unref_delete(struct dp_peer *peer)
  5373. {
  5374. struct dp_vdev *vdev = peer->vdev;
  5375. struct dp_pdev *pdev = vdev->pdev;
  5376. struct dp_soc *soc = pdev->soc;
  5377. struct dp_peer *tmppeer;
  5378. int found = 0;
  5379. uint16_t peer_id;
  5380. uint16_t vdev_id;
  5381. bool vdev_delete = false;
  5382. struct cdp_peer_cookie peer_cookie;
  5383. enum wlan_op_mode vdev_opmode;
  5384. uint8_t vdev_mac_addr[QDF_MAC_ADDR_SIZE];
  5385. /*
  5386. * Hold the lock all the way from checking if the peer ref count
  5387. * is zero until the peer references are removed from the hash
  5388. * table and vdev list (if the peer ref count is zero).
  5389. * This protects against a new HL tx operation starting to use the
  5390. * peer object just after this function concludes it's done being used.
  5391. * Furthermore, the lock needs to be held while checking whether the
  5392. * vdev's list of peers is empty, to make sure that list is not modified
  5393. * concurrently with the empty check.
  5394. */
  5395. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  5396. if (qdf_atomic_dec_and_test(&peer->ref_cnt)) {
  5397. peer_id = peer->peer_ids[0];
  5398. vdev_id = vdev->vdev_id;
  5399. /*
  5400. * Make sure that the reference to the peer in
  5401. * peer object map is removed
  5402. */
  5403. if (peer_id != HTT_INVALID_PEER)
  5404. soc->peer_id_to_obj_map[peer_id] = NULL;
  5405. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  5406. "Deleting peer %pK (%pM)", peer, peer->mac_addr.raw);
  5407. /* remove the reference to the peer from the hash table */
  5408. dp_peer_find_hash_remove(soc, peer);
  5409. qdf_spin_lock_bh(&soc->ast_lock);
  5410. if (peer->self_ast_entry) {
  5411. dp_peer_del_ast(soc, peer->self_ast_entry);
  5412. peer->self_ast_entry = NULL;
  5413. }
  5414. qdf_spin_unlock_bh(&soc->ast_lock);
  5415. TAILQ_FOREACH(tmppeer, &peer->vdev->peer_list, peer_list_elem) {
  5416. if (tmppeer == peer) {
  5417. found = 1;
  5418. break;
  5419. }
  5420. }
  5421. if (found) {
  5422. TAILQ_REMOVE(&peer->vdev->peer_list, peer,
  5423. peer_list_elem);
  5424. } else {
  5425. /*Ignoring the remove operation as peer not found*/
  5426. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  5427. "peer:%pK not found in vdev:%pK peerlist:%pK",
  5428. peer, vdev, &peer->vdev->peer_list);
  5429. }
  5430. /* send peer destroy event to upper layer */
  5431. qdf_mem_copy(peer_cookie.mac_addr, peer->mac_addr.raw,
  5432. QDF_MAC_ADDR_SIZE);
  5433. peer_cookie.ctx = NULL;
  5434. peer_cookie.ctx = (struct cdp_stats_cookie *)
  5435. peer->wlanstats_ctx;
  5436. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  5437. dp_wdi_event_handler(WDI_EVENT_PEER_DESTROY,
  5438. pdev->soc,
  5439. (void *)&peer_cookie,
  5440. peer->peer_ids[0],
  5441. WDI_NO_VAL,
  5442. pdev->pdev_id);
  5443. #endif
  5444. peer->wlanstats_ctx = NULL;
  5445. /* cleanup the peer data */
  5446. dp_peer_cleanup(vdev, peer, false);
  5447. /* reset this peer related info in vdev */
  5448. dp_vdev_reset_peer(vdev, peer);
  5449. /* save vdev related member in case vdev freed */
  5450. vdev_opmode = vdev->opmode;
  5451. qdf_mem_copy(vdev_mac_addr, vdev->mac_addr.raw,
  5452. QDF_MAC_ADDR_SIZE);
  5453. /*
  5454. * check whether the parent vdev is pending for deleting
  5455. * and no peers left.
  5456. */
  5457. if (vdev->delete.pending && TAILQ_EMPTY(&vdev->peer_list))
  5458. vdev_delete = true;
  5459. /*
  5460. * Now that there are no references to the peer, we can
  5461. * release the peer reference lock.
  5462. */
  5463. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  5464. /*
  5465. * Invoke soc.ol_ops->peer_unref_delete out of
  5466. * peer_ref_mutex in case deadlock issue.
  5467. */
  5468. dp_peer_release_mem(soc, pdev, peer,
  5469. vdev_opmode,
  5470. vdev_mac_addr);
  5471. /*
  5472. * Delete the vdev if it's waiting all peer deleted
  5473. * and it's chance now.
  5474. */
  5475. if (vdev_delete)
  5476. dp_delete_pending_vdev(pdev, vdev, vdev_id);
  5477. } else {
  5478. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  5479. }
  5480. }
  5481. #ifdef PEER_CACHE_RX_PKTS
  5482. static inline void dp_peer_rx_bufq_resources_deinit(struct dp_peer *peer)
  5483. {
  5484. dp_rx_flush_rx_cached(peer, true);
  5485. qdf_list_destroy(&peer->bufq_info.cached_bufq);
  5486. qdf_spinlock_destroy(&peer->bufq_info.bufq_lock);
  5487. }
  5488. #else
  5489. static inline void dp_peer_rx_bufq_resources_deinit(struct dp_peer *peer)
  5490. {
  5491. }
  5492. #endif
  5493. /*
  5494. * dp_peer_detach_wifi3() – Detach txrx peer
  5495. * @soc: soc handle
  5496. * @vdev_id: id of dp handle
  5497. * @peer_mac: mac of datapath PEER handle
  5498. * @bitmap: bitmap indicating special handling of request.
  5499. *
  5500. */
  5501. static QDF_STATUS dp_peer_delete_wifi3(struct cdp_soc_t *soc, uint8_t vdev_id,
  5502. uint8_t *peer_mac, uint32_t bitmap)
  5503. {
  5504. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)soc,
  5505. peer_mac, 0, vdev_id);
  5506. /* Peer can be null for monitor vap mac address */
  5507. if (!peer) {
  5508. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  5509. "%s: Invalid peer\n", __func__);
  5510. return QDF_STATUS_E_FAILURE;
  5511. }
  5512. peer->valid = 0;
  5513. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO_HIGH,
  5514. FL("peer %pK (%pM)"), peer, peer->mac_addr.raw);
  5515. dp_local_peer_id_free(peer->vdev->pdev, peer);
  5516. dp_peer_rx_bufq_resources_deinit(peer);
  5517. qdf_spinlock_destroy(&peer->peer_info_lock);
  5518. dp_peer_multipass_list_remove(peer);
  5519. if (wlan_op_mode_sta == peer->vdev->opmode &&
  5520. qdf_mem_cmp(peer->mac_addr.raw, peer->vdev->mac_addr.raw,
  5521. QDF_MAC_ADDR_SIZE) != 0) {
  5522. dp_set_ignore_reo_status_cb(peer->vdev->pdev->soc, true);
  5523. }
  5524. /*
  5525. * Remove the reference added during peer_attach.
  5526. * The peer will still be left allocated until the
  5527. * PEER_UNMAP message arrives to remove the other
  5528. * reference, added by the PEER_MAP message.
  5529. */
  5530. dp_peer_unref_delete(peer);
  5531. /*
  5532. * Remove the reference taken above
  5533. */
  5534. dp_peer_unref_delete(peer);
  5535. return QDF_STATUS_SUCCESS;
  5536. }
  5537. /*
  5538. * dp_get_vdev_mac_addr_wifi3() – Detach txrx peer
  5539. * @soc_hdl: Datapath soc handle
  5540. * @vdev_id: virtual interface id
  5541. *
  5542. * Return: MAC address on success, NULL on failure.
  5543. *
  5544. */
  5545. static uint8 *dp_get_vdev_mac_addr_wifi3(struct cdp_soc_t *soc_hdl,
  5546. uint8_t vdev_id)
  5547. {
  5548. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  5549. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  5550. if (!vdev)
  5551. return NULL;
  5552. return vdev->mac_addr.raw;
  5553. }
  5554. /*
  5555. * dp_vdev_set_wds() - Enable per packet stats
  5556. * @soc: DP soc handle
  5557. * @vdev_id: id of DP VDEV handle
  5558. * @val: value
  5559. *
  5560. * Return: none
  5561. */
  5562. static int dp_vdev_set_wds(struct cdp_soc_t *soc, uint8_t vdev_id, uint32_t val)
  5563. {
  5564. struct dp_vdev *vdev =
  5565. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  5566. vdev_id);
  5567. if (!vdev)
  5568. return QDF_STATUS_E_FAILURE;
  5569. vdev->wds_enabled = val;
  5570. return QDF_STATUS_SUCCESS;
  5571. }
  5572. /*
  5573. * dp_get_mon_vdev_from_pdev_wifi3() - Get vdev id of monitor mode
  5574. * @soc_hdl: datapath soc handle
  5575. * @pdev_id: physical device instance id
  5576. *
  5577. * Return: virtual interface id
  5578. */
  5579. static uint8_t dp_get_mon_vdev_from_pdev_wifi3(struct cdp_soc_t *soc_hdl,
  5580. uint8_t pdev_id)
  5581. {
  5582. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  5583. struct dp_pdev *pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  5584. if (qdf_unlikely(!pdev))
  5585. return -EINVAL;
  5586. return pdev->monitor_vdev->vdev_id;
  5587. }
  5588. static int dp_get_opmode(struct cdp_soc_t *soc_hdl, uint8_t vdev_id)
  5589. {
  5590. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  5591. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  5592. if (!vdev) {
  5593. dp_err("vdev for id %d is NULL", vdev_id);
  5594. return -EINVAL;
  5595. }
  5596. return vdev->opmode;
  5597. }
  5598. /**
  5599. * dp_get_os_rx_handles_from_vdev_wifi3() - Get os rx handles for a vdev
  5600. * @soc_hdl: ol_txrx_soc_handle handle
  5601. * @vdev_id: vdev id for which os rx handles are needed
  5602. * @stack_fn_p: pointer to stack function pointer
  5603. * @osif_handle_p: pointer to ol_osif_vdev_handle
  5604. *
  5605. * Return: void
  5606. */
  5607. static
  5608. void dp_get_os_rx_handles_from_vdev_wifi3(struct cdp_soc_t *soc_hdl,
  5609. uint8_t vdev_id,
  5610. ol_txrx_rx_fp *stack_fn_p,
  5611. ol_osif_vdev_handle *osif_vdev_p)
  5612. {
  5613. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  5614. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  5615. if (!vdev)
  5616. return;
  5617. *stack_fn_p = vdev->osif_rx_stack;
  5618. *osif_vdev_p = vdev->osif_vdev;
  5619. }
  5620. /**
  5621. * dp_get_ctrl_pdev_from_vdev() - Get control pdev of vdev
  5622. * @soc_hdl: datapath soc handle
  5623. * @vdev_id: virtual device/interface id
  5624. *
  5625. * Return: Handle to control pdev
  5626. */
  5627. static struct cdp_cfg *dp_get_ctrl_pdev_from_vdev_wifi3(
  5628. struct cdp_soc_t *soc_hdl,
  5629. uint8_t vdev_id)
  5630. {
  5631. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  5632. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  5633. struct dp_pdev *pdev;
  5634. if (!vdev || !vdev->pdev)
  5635. return NULL;
  5636. pdev = vdev->pdev;
  5637. return (struct cdp_cfg *)pdev->wlan_cfg_ctx;
  5638. }
  5639. /**
  5640. * dp_monitor_mode_ring_config() - Send the tlv config to fw for monitor buffer
  5641. * ring based on target
  5642. * @soc: soc handle
  5643. * @mac_for_pdev: WIN- pdev_id, MCL- mac id
  5644. * @pdev: physical device handle
  5645. * @ring_num: mac id
  5646. * @htt_tlv_filter: tlv filter
  5647. *
  5648. * Return: zero on success, non-zero on failure
  5649. */
  5650. static inline
  5651. QDF_STATUS dp_monitor_mode_ring_config(struct dp_soc *soc, uint8_t mac_for_pdev,
  5652. struct dp_pdev *pdev, uint8_t ring_num,
  5653. struct htt_rx_ring_tlv_filter htt_tlv_filter)
  5654. {
  5655. QDF_STATUS status;
  5656. if (soc->wlan_cfg_ctx->rxdma1_enable)
  5657. status = htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  5658. soc->rxdma_mon_buf_ring[ring_num]
  5659. .hal_srng,
  5660. RXDMA_MONITOR_BUF, RX_BUFFER_SIZE,
  5661. &htt_tlv_filter);
  5662. else
  5663. status = htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  5664. pdev->rx_mac_buf_ring[ring_num]
  5665. .hal_srng,
  5666. RXDMA_BUF, RX_BUFFER_SIZE,
  5667. &htt_tlv_filter);
  5668. return status;
  5669. }
  5670. static inline void
  5671. dp_pdev_disable_mcopy_code(struct dp_pdev *pdev)
  5672. {
  5673. pdev->mcopy_mode = 0;
  5674. qdf_nbuf_queue_free(&pdev->rx_ppdu_buf_q);
  5675. }
  5676. /**
  5677. * dp_reset_monitor_mode() - Disable monitor mode
  5678. * @soc_hdl: Datapath soc handle
  5679. * @pdev_id: id of datapath PDEV handle
  5680. *
  5681. * Return: QDF_STATUS
  5682. */
  5683. QDF_STATUS dp_reset_monitor_mode(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  5684. {
  5685. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  5686. struct htt_rx_ring_tlv_filter htt_tlv_filter;
  5687. int mac_id;
  5688. QDF_STATUS status = QDF_STATUS_SUCCESS;
  5689. struct dp_pdev *pdev =
  5690. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  5691. pdev_id);
  5692. if (!pdev)
  5693. return QDF_STATUS_E_FAILURE;
  5694. qdf_spin_lock_bh(&pdev->mon_lock);
  5695. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  5696. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  5697. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  5698. /*
  5699. * Obtain lmac id from pdev to access the ring in soc
  5700. * context
  5701. */
  5702. int lmac_id = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  5703. status = dp_monitor_mode_ring_config(soc, mac_for_pdev,
  5704. pdev, lmac_id,
  5705. htt_tlv_filter);
  5706. if (status != QDF_STATUS_SUCCESS) {
  5707. dp_err("Failed to send tlv filter for monitor mode rings");
  5708. qdf_spin_unlock_bh(&pdev->mon_lock);
  5709. return status;
  5710. }
  5711. htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  5712. soc->rxdma_mon_status_ring[lmac_id]
  5713. .hal_srng,
  5714. RXDMA_MONITOR_STATUS, RX_BUFFER_SIZE,
  5715. &htt_tlv_filter);
  5716. }
  5717. pdev->monitor_vdev = NULL;
  5718. if (pdev->mcopy_mode)
  5719. dp_pdev_disable_mcopy_code(pdev);
  5720. pdev->monitor_configured = false;
  5721. qdf_spin_unlock_bh(&pdev->mon_lock);
  5722. return QDF_STATUS_SUCCESS;
  5723. }
  5724. /**
  5725. * dp_get_tx_pending() - read pending tx
  5726. * @pdev_handle: Datapath PDEV handle
  5727. *
  5728. * Return: outstanding tx
  5729. */
  5730. static uint32_t dp_get_tx_pending(struct cdp_pdev *pdev_handle)
  5731. {
  5732. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  5733. return qdf_atomic_read(&pdev->num_tx_outstanding);
  5734. }
  5735. /**
  5736. * dp_get_peer_mac_from_peer_id() - get peer mac
  5737. * @pdev_handle: Datapath PDEV handle
  5738. * @peer_id: Peer ID
  5739. * @peer_mac: MAC addr of PEER
  5740. *
  5741. * Return: QDF_STATUS
  5742. */
  5743. static QDF_STATUS dp_get_peer_mac_from_peer_id(struct cdp_soc_t *soc,
  5744. uint32_t peer_id,
  5745. uint8_t *peer_mac)
  5746. {
  5747. struct dp_peer *peer;
  5748. if (soc && peer_mac) {
  5749. peer = dp_peer_find_by_id((struct dp_soc *)soc,
  5750. (uint16_t)peer_id);
  5751. if (peer) {
  5752. qdf_mem_copy(peer_mac, peer->mac_addr.raw,
  5753. QDF_MAC_ADDR_SIZE);
  5754. dp_peer_unref_del_find_by_id(peer);
  5755. return QDF_STATUS_SUCCESS;
  5756. }
  5757. }
  5758. return QDF_STATUS_E_FAILURE;
  5759. }
  5760. /**
  5761. * dp_pdev_configure_monitor_rings() - configure monitor rings
  5762. * @vdev_handle: Datapath VDEV handle
  5763. *
  5764. * Return: QDF_STATUS
  5765. */
  5766. QDF_STATUS dp_pdev_configure_monitor_rings(struct dp_pdev *pdev)
  5767. {
  5768. struct htt_rx_ring_tlv_filter htt_tlv_filter;
  5769. struct dp_soc *soc;
  5770. uint8_t pdev_id;
  5771. int mac_id;
  5772. QDF_STATUS status = QDF_STATUS_SUCCESS;
  5773. pdev_id = pdev->pdev_id;
  5774. soc = pdev->soc;
  5775. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  5776. "MODE[%x] FP[%02x|%02x|%02x] MO[%02x|%02x|%02x]",
  5777. pdev->mon_filter_mode, pdev->fp_mgmt_filter,
  5778. pdev->fp_ctrl_filter, pdev->fp_data_filter,
  5779. pdev->mo_mgmt_filter, pdev->mo_ctrl_filter,
  5780. pdev->mo_data_filter);
  5781. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  5782. htt_tlv_filter.mpdu_start = 1;
  5783. htt_tlv_filter.msdu_start = 1;
  5784. htt_tlv_filter.packet = 1;
  5785. htt_tlv_filter.msdu_end = 1;
  5786. htt_tlv_filter.mpdu_end = 1;
  5787. htt_tlv_filter.packet_header = 1;
  5788. htt_tlv_filter.attention = 1;
  5789. htt_tlv_filter.ppdu_start = 0;
  5790. htt_tlv_filter.ppdu_end = 0;
  5791. htt_tlv_filter.ppdu_end_user_stats = 0;
  5792. htt_tlv_filter.ppdu_end_user_stats_ext = 0;
  5793. htt_tlv_filter.ppdu_end_status_done = 0;
  5794. htt_tlv_filter.header_per_msdu = 1;
  5795. htt_tlv_filter.enable_fp =
  5796. (pdev->mon_filter_mode & MON_FILTER_PASS) ? 1 : 0;
  5797. htt_tlv_filter.enable_md = 0;
  5798. htt_tlv_filter.enable_mo =
  5799. (pdev->mon_filter_mode & MON_FILTER_OTHER) ? 1 : 0;
  5800. htt_tlv_filter.fp_mgmt_filter = pdev->fp_mgmt_filter;
  5801. htt_tlv_filter.fp_ctrl_filter = pdev->fp_ctrl_filter;
  5802. if (pdev->mcopy_mode) {
  5803. htt_tlv_filter.fp_data_filter = 0;
  5804. htt_tlv_filter.mo_data_filter = 0;
  5805. } else {
  5806. htt_tlv_filter.fp_data_filter = pdev->fp_data_filter;
  5807. htt_tlv_filter.mo_data_filter = pdev->mo_data_filter;
  5808. }
  5809. htt_tlv_filter.mo_mgmt_filter = pdev->mo_mgmt_filter;
  5810. htt_tlv_filter.mo_ctrl_filter = pdev->mo_ctrl_filter;
  5811. htt_tlv_filter.offset_valid = false;
  5812. if ((pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU) ||
  5813. (pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU_MSDU)) {
  5814. htt_tlv_filter.fp_mgmt_filter = 0;
  5815. htt_tlv_filter.fp_ctrl_filter = 0;
  5816. htt_tlv_filter.fp_data_filter = 0;
  5817. htt_tlv_filter.mo_mgmt_filter = 0;
  5818. htt_tlv_filter.mo_ctrl_filter = 0;
  5819. htt_tlv_filter.mo_data_filter = 0;
  5820. }
  5821. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  5822. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  5823. /*
  5824. * Obtain lmac id from pdev to access the LMAC ring in soc
  5825. * context
  5826. */
  5827. int lmac_id = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  5828. status = dp_monitor_mode_ring_config(soc, mac_for_pdev,
  5829. pdev, lmac_id,
  5830. htt_tlv_filter);
  5831. if (status != QDF_STATUS_SUCCESS) {
  5832. dp_err("Failed to send tlv filter for monitor mode rings");
  5833. return status;
  5834. }
  5835. }
  5836. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  5837. htt_tlv_filter.mpdu_start = 1;
  5838. htt_tlv_filter.msdu_start = 0;
  5839. htt_tlv_filter.packet = 0;
  5840. htt_tlv_filter.msdu_end = 0;
  5841. htt_tlv_filter.mpdu_end = 0;
  5842. if ((pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU) ||
  5843. (pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU_MSDU)) {
  5844. htt_tlv_filter.mpdu_end = 1;
  5845. }
  5846. htt_tlv_filter.attention = 0;
  5847. htt_tlv_filter.ppdu_start = 1;
  5848. htt_tlv_filter.ppdu_end = 1;
  5849. htt_tlv_filter.ppdu_end_user_stats = 1;
  5850. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  5851. htt_tlv_filter.ppdu_end_status_done = 1;
  5852. htt_tlv_filter.enable_fp = 1;
  5853. htt_tlv_filter.enable_md = 0;
  5854. htt_tlv_filter.enable_mo = 1;
  5855. if (pdev->mcopy_mode ||
  5856. (pdev->rx_enh_capture_mode != CDP_RX_ENH_CAPTURE_DISABLED)) {
  5857. htt_tlv_filter.packet_header = 1;
  5858. if (pdev->rx_enh_capture_mode == CDP_RX_ENH_CAPTURE_MPDU) {
  5859. htt_tlv_filter.header_per_msdu = 0;
  5860. htt_tlv_filter.enable_mo = 0;
  5861. } else if (pdev->rx_enh_capture_mode ==
  5862. CDP_RX_ENH_CAPTURE_MPDU_MSDU) {
  5863. bool is_rx_mon_proto_flow_tag_enabled =
  5864. wlan_cfg_is_rx_mon_protocol_flow_tag_enabled(
  5865. soc->wlan_cfg_ctx);
  5866. htt_tlv_filter.header_per_msdu = 1;
  5867. htt_tlv_filter.enable_mo = 0;
  5868. if (pdev->is_rx_enh_capture_trailer_enabled ||
  5869. is_rx_mon_proto_flow_tag_enabled)
  5870. htt_tlv_filter.msdu_end = 1;
  5871. }
  5872. }
  5873. htt_tlv_filter.fp_mgmt_filter = FILTER_MGMT_ALL;
  5874. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_ALL;
  5875. htt_tlv_filter.fp_data_filter = FILTER_DATA_ALL;
  5876. htt_tlv_filter.mo_mgmt_filter = FILTER_MGMT_ALL;
  5877. htt_tlv_filter.mo_ctrl_filter = FILTER_CTRL_ALL;
  5878. htt_tlv_filter.mo_data_filter = FILTER_DATA_ALL;
  5879. htt_tlv_filter.offset_valid = false;
  5880. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  5881. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  5882. /*
  5883. * Obtain lmac id from pdev to access the LMAC ring in soc
  5884. * context
  5885. */
  5886. int lmac_id = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  5887. /*
  5888. * If two back to back HTT msg sending happened in
  5889. * short time, the second HTT msg source SRNG HP
  5890. * writing has chance to fail, this has been confirmed
  5891. * by HST HW.
  5892. * for monitor mode, here is the last HTT msg for sending.
  5893. * if the 2nd HTT msg for monitor status ring sending failed,
  5894. * HW won't provide anything into 2nd monitor status ring.
  5895. * as a WAR, add some delay before 2nd HTT msg start sending,
  5896. * > 2us is required per HST HW, delay 100 us for safe.
  5897. */
  5898. if (mac_id)
  5899. qdf_udelay(100);
  5900. htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  5901. soc->rxdma_mon_status_ring[lmac_id]
  5902. .hal_srng,
  5903. RXDMA_MONITOR_STATUS,
  5904. RX_BUFFER_SIZE, &htt_tlv_filter);
  5905. }
  5906. return status;
  5907. }
  5908. /**
  5909. * dp_vdev_set_monitor_mode() - Set DP VDEV to monitor mode
  5910. * @vdev_handle: Datapath VDEV handle
  5911. * @smart_monitor: Flag to denote if its smart monitor mode
  5912. *
  5913. * Return: 0 on success, not 0 on failure
  5914. */
  5915. static QDF_STATUS dp_vdev_set_monitor_mode(struct cdp_soc_t *soc,
  5916. uint8_t vdev_id,
  5917. uint8_t special_monitor)
  5918. {
  5919. struct dp_pdev *pdev;
  5920. struct dp_vdev *vdev =
  5921. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  5922. vdev_id);
  5923. if (!vdev)
  5924. return QDF_STATUS_E_FAILURE;
  5925. pdev = vdev->pdev;
  5926. pdev->monitor_vdev = vdev;
  5927. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
  5928. "pdev=%pK, pdev_id=%d, soc=%pK vdev=%pK\n",
  5929. pdev, pdev->pdev_id, pdev->soc, vdev);
  5930. /*
  5931. * do not configure monitor buf ring and filter for smart and
  5932. * lite monitor
  5933. * for smart monitor filters are added along with first NAC
  5934. * for lite monitor required configuration done through
  5935. * dp_set_pdev_param
  5936. */
  5937. if (special_monitor)
  5938. return QDF_STATUS_SUCCESS;
  5939. /*Check if current pdev's monitor_vdev exists */
  5940. if (pdev->monitor_configured) {
  5941. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  5942. "monitor vap already created vdev=%pK\n", vdev);
  5943. return QDF_STATUS_E_RESOURCES;
  5944. }
  5945. pdev->monitor_configured = true;
  5946. dp_mon_buf_delayed_replenish(pdev);
  5947. return dp_pdev_configure_monitor_rings(pdev);
  5948. }
  5949. /**
  5950. * dp_pdev_set_advance_monitor_filter() - Set DP PDEV monitor filter
  5951. * @soc: soc handle
  5952. * @pdev_id: id of Datapath PDEV handle
  5953. * @filter_val: Flag to select Filter for monitor mode
  5954. * Return: 0 on success, not 0 on failure
  5955. */
  5956. static QDF_STATUS
  5957. dp_pdev_set_advance_monitor_filter(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  5958. struct cdp_monitor_filter *filter_val)
  5959. {
  5960. /* Many monitor VAPs can exists in a system but only one can be up at
  5961. * anytime
  5962. */
  5963. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  5964. struct dp_vdev *vdev;
  5965. struct htt_rx_ring_tlv_filter htt_tlv_filter;
  5966. int mac_id;
  5967. QDF_STATUS status = QDF_STATUS_SUCCESS;
  5968. struct dp_pdev *pdev =
  5969. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  5970. pdev_id);
  5971. if (!pdev)
  5972. return QDF_STATUS_E_FAILURE;
  5973. vdev = pdev->monitor_vdev;
  5974. if (!vdev)
  5975. return QDF_STATUS_E_FAILURE;
  5976. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
  5977. "pdev=%pK, pdev_id=%d, soc=%pK vdev=%pK",
  5978. pdev, pdev_id, soc, vdev);
  5979. /*Check if current pdev's monitor_vdev exists */
  5980. if (!pdev->monitor_vdev) {
  5981. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  5982. "vdev=%pK", vdev);
  5983. qdf_assert(vdev);
  5984. }
  5985. /* update filter mode, type in pdev structure */
  5986. pdev->mon_filter_mode = filter_val->mode;
  5987. pdev->fp_mgmt_filter = filter_val->fp_mgmt;
  5988. pdev->fp_ctrl_filter = filter_val->fp_ctrl;
  5989. pdev->fp_data_filter = filter_val->fp_data;
  5990. pdev->mo_mgmt_filter = filter_val->mo_mgmt;
  5991. pdev->mo_ctrl_filter = filter_val->mo_ctrl;
  5992. pdev->mo_data_filter = filter_val->mo_data;
  5993. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  5994. "MODE[%x] FP[%02x|%02x|%02x] MO[%02x|%02x|%02x]",
  5995. pdev->mon_filter_mode, pdev->fp_mgmt_filter,
  5996. pdev->fp_ctrl_filter, pdev->fp_data_filter,
  5997. pdev->mo_mgmt_filter, pdev->mo_ctrl_filter,
  5998. pdev->mo_data_filter);
  5999. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  6000. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  6001. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  6002. /*
  6003. * Obtain lmac id from pdev to access the LMAC ring in soc
  6004. * context
  6005. */
  6006. int lmac_id = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  6007. status = dp_monitor_mode_ring_config(soc, mac_for_pdev,
  6008. pdev, lmac_id,
  6009. htt_tlv_filter);
  6010. if (status != QDF_STATUS_SUCCESS) {
  6011. dp_err("Failed to send tlv filter for monitor mode rings");
  6012. return status;
  6013. }
  6014. htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  6015. soc->rxdma_mon_status_ring[lmac_id].hal_srng,
  6016. RXDMA_MONITOR_STATUS, RX_BUFFER_SIZE, &htt_tlv_filter);
  6017. }
  6018. htt_tlv_filter.mpdu_start = 1;
  6019. htt_tlv_filter.msdu_start = 1;
  6020. htt_tlv_filter.packet = 1;
  6021. htt_tlv_filter.msdu_end = 1;
  6022. htt_tlv_filter.mpdu_end = 1;
  6023. htt_tlv_filter.packet_header = 1;
  6024. htt_tlv_filter.attention = 1;
  6025. htt_tlv_filter.ppdu_start = 0;
  6026. htt_tlv_filter.ppdu_end = 0;
  6027. htt_tlv_filter.ppdu_end_user_stats = 0;
  6028. htt_tlv_filter.ppdu_end_user_stats_ext = 0;
  6029. htt_tlv_filter.ppdu_end_status_done = 0;
  6030. htt_tlv_filter.header_per_msdu = 1;
  6031. htt_tlv_filter.enable_fp =
  6032. (pdev->mon_filter_mode & MON_FILTER_PASS) ? 1 : 0;
  6033. htt_tlv_filter.enable_md = 0;
  6034. htt_tlv_filter.enable_mo =
  6035. (pdev->mon_filter_mode & MON_FILTER_OTHER) ? 1 : 0;
  6036. htt_tlv_filter.fp_mgmt_filter = pdev->fp_mgmt_filter;
  6037. htt_tlv_filter.fp_ctrl_filter = pdev->fp_ctrl_filter;
  6038. if (pdev->mcopy_mode)
  6039. htt_tlv_filter.fp_data_filter = 0;
  6040. else
  6041. htt_tlv_filter.fp_data_filter = pdev->fp_data_filter;
  6042. htt_tlv_filter.mo_mgmt_filter = pdev->mo_mgmt_filter;
  6043. htt_tlv_filter.mo_ctrl_filter = pdev->mo_ctrl_filter;
  6044. htt_tlv_filter.mo_data_filter = pdev->mo_data_filter;
  6045. htt_tlv_filter.offset_valid = false;
  6046. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  6047. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  6048. /*
  6049. * Obtain lmac id from pdev to access the LMAC ring in soc
  6050. * context
  6051. */
  6052. int lmac_id = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  6053. status = dp_monitor_mode_ring_config(soc, mac_for_pdev,
  6054. pdev, lmac_id,
  6055. htt_tlv_filter);
  6056. if (status != QDF_STATUS_SUCCESS) {
  6057. dp_err("Failed to send tlv filter for monitor mode rings");
  6058. return status;
  6059. }
  6060. }
  6061. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  6062. htt_tlv_filter.mpdu_start = 1;
  6063. htt_tlv_filter.msdu_start = 0;
  6064. htt_tlv_filter.packet = 0;
  6065. htt_tlv_filter.msdu_end = 0;
  6066. htt_tlv_filter.mpdu_end = 0;
  6067. htt_tlv_filter.attention = 0;
  6068. htt_tlv_filter.ppdu_start = 1;
  6069. htt_tlv_filter.ppdu_end = 1;
  6070. htt_tlv_filter.ppdu_end_user_stats = 1;
  6071. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  6072. htt_tlv_filter.ppdu_end_status_done = 1;
  6073. htt_tlv_filter.enable_fp = 1;
  6074. htt_tlv_filter.enable_md = 0;
  6075. htt_tlv_filter.enable_mo = 1;
  6076. if (pdev->mcopy_mode) {
  6077. htt_tlv_filter.packet_header = 1;
  6078. }
  6079. htt_tlv_filter.fp_mgmt_filter = FILTER_MGMT_ALL;
  6080. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_ALL;
  6081. htt_tlv_filter.fp_data_filter = FILTER_DATA_ALL;
  6082. htt_tlv_filter.mo_mgmt_filter = FILTER_MGMT_ALL;
  6083. htt_tlv_filter.mo_ctrl_filter = FILTER_CTRL_ALL;
  6084. htt_tlv_filter.mo_data_filter = FILTER_DATA_ALL;
  6085. htt_tlv_filter.offset_valid = false;
  6086. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  6087. int mac_for_pdev =
  6088. dp_get_mac_id_for_pdev(mac_id,
  6089. pdev->pdev_id);
  6090. /*
  6091. * Obtain lmac id from pdev to access the LMAC ring in soc
  6092. * context
  6093. */
  6094. int lmac_id =
  6095. dp_get_lmac_id_for_pdev_id(soc,
  6096. mac_id, pdev->pdev_id);
  6097. htt_h2t_rx_ring_cfg(soc->htt_handle, mac_for_pdev,
  6098. soc->rxdma_mon_status_ring[lmac_id].hal_srng,
  6099. RXDMA_MONITOR_STATUS, RX_BUFFER_SIZE, &htt_tlv_filter);
  6100. }
  6101. return QDF_STATUS_SUCCESS;
  6102. }
  6103. /**
  6104. * dp_deliver_tx_mgmt() - Deliver mgmt frame for tx capture
  6105. * @cdp_soc : data path soc handle
  6106. * @pdev_id : pdev_id
  6107. * @nbuf: Management frame buffer
  6108. */
  6109. static QDF_STATUS
  6110. dp_deliver_tx_mgmt(struct cdp_soc_t *cdp_soc, uint8_t pdev_id, qdf_nbuf_t nbuf)
  6111. {
  6112. struct dp_pdev *pdev =
  6113. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)cdp_soc,
  6114. pdev_id);
  6115. if (!pdev)
  6116. return QDF_STATUS_E_FAILURE;
  6117. dp_deliver_mgmt_frm(pdev, nbuf);
  6118. return QDF_STATUS_SUCCESS;
  6119. }
  6120. /**
  6121. * dp_set_bsscolor() - sets bsscolor for tx capture
  6122. * @pdev: Datapath PDEV handle
  6123. * @bsscolor: new bsscolor
  6124. */
  6125. static void
  6126. dp_mon_set_bsscolor(struct dp_pdev *pdev, uint8_t bsscolor)
  6127. {
  6128. pdev->rx_mon_recv_status.bsscolor = bsscolor;
  6129. }
  6130. /**
  6131. * dp_pdev_get_filter_ucast_data() - get DP PDEV monitor ucast filter
  6132. * @soc : data path soc handle
  6133. * @pdev_id : pdev_id
  6134. * Return: true on ucast filter flag set
  6135. */
  6136. static bool dp_pdev_get_filter_ucast_data(struct cdp_pdev *pdev_handle)
  6137. {
  6138. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6139. if ((pdev->fp_data_filter & FILTER_DATA_UCAST) ||
  6140. (pdev->mo_data_filter & FILTER_DATA_UCAST))
  6141. return true;
  6142. return false;
  6143. }
  6144. /**
  6145. * dp_pdev_get_filter_mcast_data() - get DP PDEV monitor mcast filter
  6146. * @pdev_handle: Datapath PDEV handle
  6147. * Return: true on mcast filter flag set
  6148. */
  6149. static bool dp_pdev_get_filter_mcast_data(struct cdp_pdev *pdev_handle)
  6150. {
  6151. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6152. if ((pdev->fp_data_filter & FILTER_DATA_MCAST) ||
  6153. (pdev->mo_data_filter & FILTER_DATA_MCAST))
  6154. return true;
  6155. return false;
  6156. }
  6157. /**
  6158. * dp_pdev_get_filter_non_data() - get DP PDEV monitor non_data filter
  6159. * @pdev_handle: Datapath PDEV handle
  6160. * Return: true on non data filter flag set
  6161. */
  6162. static bool dp_pdev_get_filter_non_data(struct cdp_pdev *pdev_handle)
  6163. {
  6164. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6165. if ((pdev->fp_mgmt_filter & FILTER_MGMT_ALL) ||
  6166. (pdev->mo_mgmt_filter & FILTER_MGMT_ALL)) {
  6167. if ((pdev->fp_ctrl_filter & FILTER_CTRL_ALL) ||
  6168. (pdev->mo_ctrl_filter & FILTER_CTRL_ALL)) {
  6169. return true;
  6170. }
  6171. }
  6172. return false;
  6173. }
  6174. #ifdef MESH_MODE_SUPPORT
  6175. void dp_peer_set_mesh_mode(struct cdp_vdev *vdev_hdl, uint32_t val)
  6176. {
  6177. struct dp_vdev *vdev = (struct dp_vdev *)vdev_hdl;
  6178. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  6179. FL("val %d"), val);
  6180. vdev->mesh_vdev = val;
  6181. }
  6182. /*
  6183. * dp_peer_set_mesh_rx_filter() - to set the mesh rx filter
  6184. * @vdev_hdl: virtual device object
  6185. * @val: value to be set
  6186. *
  6187. * Return: void
  6188. */
  6189. void dp_peer_set_mesh_rx_filter(struct cdp_vdev *vdev_hdl, uint32_t val)
  6190. {
  6191. struct dp_vdev *vdev = (struct dp_vdev *)vdev_hdl;
  6192. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  6193. FL("val %d"), val);
  6194. vdev->mesh_rx_filter = val;
  6195. }
  6196. #endif
  6197. bool dp_check_pdev_exists(struct dp_soc *soc, struct dp_pdev *data)
  6198. {
  6199. uint8_t pdev_count;
  6200. for (pdev_count = 0; pdev_count < MAX_PDEV_CNT; pdev_count++) {
  6201. if (soc->pdev_list[pdev_count] &&
  6202. soc->pdev_list[pdev_count] == data)
  6203. return true;
  6204. }
  6205. return false;
  6206. }
  6207. /**
  6208. * dp_rx_bar_stats_cb(): BAR received stats callback
  6209. * @soc: SOC handle
  6210. * @cb_ctxt: Call back context
  6211. * @reo_status: Reo status
  6212. *
  6213. * return: void
  6214. */
  6215. void dp_rx_bar_stats_cb(struct dp_soc *soc, void *cb_ctxt,
  6216. union hal_reo_status *reo_status)
  6217. {
  6218. struct dp_pdev *pdev = (struct dp_pdev *)cb_ctxt;
  6219. struct hal_reo_queue_status *queue_status = &(reo_status->queue_status);
  6220. if (!dp_check_pdev_exists(soc, pdev)) {
  6221. dp_err_rl("pdev doesn't exist");
  6222. return;
  6223. }
  6224. if (!qdf_atomic_read(&soc->cmn_init_done))
  6225. return;
  6226. if (queue_status->header.status != HAL_REO_CMD_SUCCESS) {
  6227. DP_PRINT_STATS("REO stats failure %d",
  6228. queue_status->header.status);
  6229. qdf_atomic_set(&(pdev->stats_cmd_complete), 1);
  6230. return;
  6231. }
  6232. pdev->stats.rx.bar_recv_cnt += queue_status->bar_rcvd_cnt;
  6233. qdf_atomic_set(&(pdev->stats_cmd_complete), 1);
  6234. }
  6235. /**
  6236. * dp_aggregate_vdev_stats(): Consolidate stats at VDEV level
  6237. * @vdev: DP VDEV handle
  6238. *
  6239. * return: void
  6240. */
  6241. void dp_aggregate_vdev_stats(struct dp_vdev *vdev,
  6242. struct cdp_vdev_stats *vdev_stats)
  6243. {
  6244. struct dp_peer *peer = NULL;
  6245. struct dp_soc *soc = NULL;
  6246. if (!vdev || !vdev->pdev)
  6247. return;
  6248. soc = vdev->pdev->soc;
  6249. qdf_mem_copy(vdev_stats, &vdev->stats, sizeof(vdev->stats));
  6250. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem)
  6251. dp_update_vdev_stats(vdev_stats, peer);
  6252. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  6253. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, vdev->pdev->soc,
  6254. vdev_stats, vdev->vdev_id,
  6255. UPDATE_VDEV_STATS, vdev->pdev->pdev_id);
  6256. #endif
  6257. }
  6258. void dp_aggregate_pdev_stats(struct dp_pdev *pdev)
  6259. {
  6260. struct dp_vdev *vdev = NULL;
  6261. struct dp_soc *soc;
  6262. struct cdp_vdev_stats *vdev_stats =
  6263. qdf_mem_malloc(sizeof(struct cdp_vdev_stats));
  6264. if (!vdev_stats) {
  6265. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  6266. "DP alloc failure - unable to get alloc vdev stats");
  6267. return;
  6268. }
  6269. qdf_mem_zero(&pdev->stats.tx, sizeof(pdev->stats.tx));
  6270. qdf_mem_zero(&pdev->stats.rx, sizeof(pdev->stats.rx));
  6271. qdf_mem_zero(&pdev->stats.tx_i, sizeof(pdev->stats.tx_i));
  6272. if (pdev->mcopy_mode)
  6273. DP_UPDATE_STATS(pdev, pdev->invalid_peer);
  6274. soc = pdev->soc;
  6275. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  6276. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  6277. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  6278. dp_aggregate_vdev_stats(vdev, vdev_stats);
  6279. dp_update_pdev_stats(pdev, vdev_stats);
  6280. dp_update_pdev_ingress_stats(pdev, vdev);
  6281. }
  6282. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  6283. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  6284. qdf_mem_free(vdev_stats);
  6285. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  6286. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, pdev->soc, &pdev->stats,
  6287. pdev->pdev_id, UPDATE_PDEV_STATS, pdev->pdev_id);
  6288. #endif
  6289. }
  6290. /**
  6291. * dp_vdev_getstats() - get vdev packet level stats
  6292. * @vdev_handle: Datapath VDEV handle
  6293. * @stats: cdp network device stats structure
  6294. *
  6295. * Return: QDF_STATUS
  6296. */
  6297. static QDF_STATUS dp_vdev_getstats(struct cdp_vdev *vdev_handle,
  6298. struct cdp_dev_stats *stats)
  6299. {
  6300. struct dp_vdev *vdev = (struct dp_vdev *)vdev_handle;
  6301. struct dp_pdev *pdev;
  6302. struct dp_soc *soc;
  6303. struct cdp_vdev_stats *vdev_stats;
  6304. if (!vdev)
  6305. return QDF_STATUS_E_FAILURE;
  6306. pdev = vdev->pdev;
  6307. if (!pdev)
  6308. return QDF_STATUS_E_FAILURE;
  6309. soc = pdev->soc;
  6310. vdev_stats = qdf_mem_malloc(sizeof(struct cdp_vdev_stats));
  6311. if (!vdev_stats) {
  6312. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  6313. "DP alloc failure - unable to get alloc vdev stats");
  6314. return QDF_STATUS_E_FAILURE;
  6315. }
  6316. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  6317. dp_aggregate_vdev_stats(vdev, vdev_stats);
  6318. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  6319. stats->tx_packets = vdev_stats->tx_i.rcvd.num;
  6320. stats->tx_bytes = vdev_stats->tx_i.rcvd.bytes;
  6321. stats->tx_errors = vdev_stats->tx.tx_failed +
  6322. vdev_stats->tx_i.dropped.dropped_pkt.num;
  6323. stats->tx_dropped = stats->tx_errors;
  6324. stats->rx_packets = vdev_stats->rx.unicast.num +
  6325. vdev_stats->rx.multicast.num +
  6326. vdev_stats->rx.bcast.num;
  6327. stats->rx_bytes = vdev_stats->rx.unicast.bytes +
  6328. vdev_stats->rx.multicast.bytes +
  6329. vdev_stats->rx.bcast.bytes;
  6330. qdf_mem_free(vdev_stats);
  6331. return QDF_STATUS_SUCCESS;
  6332. }
  6333. /**
  6334. * dp_pdev_getstats() - get pdev packet level stats
  6335. * @pdev_handle: Datapath PDEV handle
  6336. * @stats: cdp network device stats structure
  6337. *
  6338. * Return: QDF_STATUS
  6339. */
  6340. static void dp_pdev_getstats(struct cdp_pdev *pdev_handle,
  6341. struct cdp_dev_stats *stats)
  6342. {
  6343. struct dp_pdev *pdev = (struct dp_pdev *)pdev_handle;
  6344. dp_aggregate_pdev_stats(pdev);
  6345. stats->tx_packets = pdev->stats.tx_i.rcvd.num;
  6346. stats->tx_bytes = pdev->stats.tx_i.rcvd.bytes;
  6347. stats->tx_errors = pdev->stats.tx.tx_failed +
  6348. pdev->stats.tx_i.dropped.dropped_pkt.num;
  6349. stats->tx_dropped = stats->tx_errors;
  6350. stats->rx_packets = pdev->stats.rx.unicast.num +
  6351. pdev->stats.rx.multicast.num +
  6352. pdev->stats.rx.bcast.num;
  6353. stats->rx_bytes = pdev->stats.rx.unicast.bytes +
  6354. pdev->stats.rx.multicast.bytes +
  6355. pdev->stats.rx.bcast.bytes;
  6356. stats->rx_errors = pdev->stats.err.desc_alloc_fail +
  6357. pdev->stats.err.ip_csum_err +
  6358. pdev->stats.err.tcp_udp_csum_err +
  6359. pdev->stats.rx.err.mic_err +
  6360. pdev->stats.rx.err.decrypt_err +
  6361. pdev->stats.err.rxdma_error +
  6362. pdev->stats.err.reo_error;
  6363. stats->rx_dropped = pdev->stats.dropped.msdu_not_done +
  6364. pdev->stats.dropped.mec +
  6365. pdev->stats.dropped.mesh_filter +
  6366. pdev->stats.dropped.wifi_parse +
  6367. pdev->stats.dropped.mon_rx_drop +
  6368. pdev->stats.dropped.mon_radiotap_update_err;
  6369. }
  6370. /**
  6371. * dp_get_device_stats() - get interface level packet stats
  6372. * @soc: soc handle
  6373. * @id : vdev_id or pdev_id based on type
  6374. * @stats: cdp network device stats structure
  6375. * @type: device type pdev/vdev
  6376. *
  6377. * Return: QDF_STATUS
  6378. */
  6379. static QDF_STATUS dp_get_device_stats(struct cdp_soc_t *soc, uint8_t id,
  6380. struct cdp_dev_stats *stats,
  6381. uint8_t type)
  6382. {
  6383. switch (type) {
  6384. case UPDATE_VDEV_STATS:
  6385. return dp_vdev_getstats(
  6386. (struct cdp_vdev *)dp_get_vdev_from_soc_vdev_id_wifi3(
  6387. (struct dp_soc *)soc, id), stats);
  6388. case UPDATE_PDEV_STATS:
  6389. {
  6390. struct dp_pdev *pdev =
  6391. dp_get_pdev_from_soc_pdev_id_wifi3(
  6392. (struct dp_soc *)soc,
  6393. id);
  6394. if (pdev) {
  6395. dp_pdev_getstats((struct cdp_pdev *)pdev,
  6396. stats);
  6397. return QDF_STATUS_SUCCESS;
  6398. }
  6399. }
  6400. break;
  6401. default:
  6402. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  6403. "apstats cannot be updated for this input "
  6404. "type %d", type);
  6405. break;
  6406. }
  6407. return QDF_STATUS_E_FAILURE;
  6408. }
  6409. const
  6410. char *dp_srng_get_str_from_hal_ring_type(enum hal_ring_type ring_type)
  6411. {
  6412. switch (ring_type) {
  6413. case REO_DST:
  6414. return "Reo_dst";
  6415. case REO_EXCEPTION:
  6416. return "Reo_exception";
  6417. case REO_CMD:
  6418. return "Reo_cmd";
  6419. case REO_REINJECT:
  6420. return "Reo_reinject";
  6421. case REO_STATUS:
  6422. return "Reo_status";
  6423. case WBM2SW_RELEASE:
  6424. return "wbm2sw_release";
  6425. case TCL_DATA:
  6426. return "tcl_data";
  6427. case TCL_CMD:
  6428. return "tcl_cmd";
  6429. case TCL_STATUS:
  6430. return "tcl_status";
  6431. case SW2WBM_RELEASE:
  6432. return "sw2wbm_release";
  6433. case RXDMA_BUF:
  6434. return "Rxdma_buf";
  6435. case RXDMA_DST:
  6436. return "Rxdma_dst";
  6437. case RXDMA_MONITOR_BUF:
  6438. return "Rxdma_monitor_buf";
  6439. case RXDMA_MONITOR_DESC:
  6440. return "Rxdma_monitor_desc";
  6441. case RXDMA_MONITOR_STATUS:
  6442. return "Rxdma_monitor_status";
  6443. default:
  6444. dp_err("Invalid ring type");
  6445. break;
  6446. }
  6447. return "Invalid";
  6448. }
  6449. /*
  6450. * dp_print_napi_stats(): NAPI stats
  6451. * @soc - soc handle
  6452. */
  6453. void dp_print_napi_stats(struct dp_soc *soc)
  6454. {
  6455. hif_print_napi_stats(soc->hif_handle);
  6456. }
  6457. /**
  6458. * dp_txrx_host_stats_clr(): Reinitialize the txrx stats
  6459. * @vdev: DP_VDEV handle
  6460. *
  6461. * Return: QDF_STATUS
  6462. */
  6463. static inline QDF_STATUS
  6464. dp_txrx_host_stats_clr(struct dp_vdev *vdev)
  6465. {
  6466. struct dp_peer *peer = NULL;
  6467. if (!vdev || !vdev->pdev)
  6468. return QDF_STATUS_E_FAILURE;
  6469. DP_STATS_CLR(vdev->pdev);
  6470. DP_STATS_CLR(vdev->pdev->soc);
  6471. DP_STATS_CLR(vdev);
  6472. hif_clear_napi_stats(vdev->pdev->soc->hif_handle);
  6473. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  6474. if (!peer)
  6475. return QDF_STATUS_E_FAILURE;
  6476. DP_STATS_CLR(peer);
  6477. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  6478. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, vdev->pdev->soc,
  6479. &peer->stats, peer->peer_ids[0],
  6480. UPDATE_PEER_STATS, vdev->pdev->pdev_id);
  6481. #endif
  6482. }
  6483. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  6484. dp_wdi_event_handler(WDI_EVENT_UPDATE_DP_STATS, vdev->pdev->soc,
  6485. &vdev->stats, vdev->vdev_id,
  6486. UPDATE_VDEV_STATS, vdev->pdev->pdev_id);
  6487. #endif
  6488. return QDF_STATUS_SUCCESS;
  6489. }
  6490. /*
  6491. * dp_get_host_peer_stats()- function to print peer stats
  6492. * @soc: dp_soc handle
  6493. * @mac_addr: mac address of the peer
  6494. *
  6495. * Return: QDF_STATUS
  6496. */
  6497. static QDF_STATUS
  6498. dp_get_host_peer_stats(struct cdp_soc_t *soc, uint8_t *mac_addr)
  6499. {
  6500. QDF_STATUS status = QDF_STATUS_SUCCESS;
  6501. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)soc,
  6502. mac_addr, 0,
  6503. DP_VDEV_ALL);
  6504. if (!peer || peer->delete_in_progress) {
  6505. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  6506. "%s: Invalid peer\n", __func__);
  6507. status = QDF_STATUS_E_FAILURE;
  6508. goto fail;
  6509. }
  6510. dp_print_peer_stats(peer);
  6511. dp_peer_rxtid_stats(peer, dp_rx_tid_stats_cb, NULL);
  6512. fail:
  6513. if (peer)
  6514. dp_peer_unref_delete(peer);
  6515. return status;
  6516. }
  6517. /**
  6518. * dp_txrx_stats_help() - Helper function for Txrx_Stats
  6519. *
  6520. * Return: None
  6521. */
  6522. static void dp_txrx_stats_help(void)
  6523. {
  6524. dp_info("Command: iwpriv wlan0 txrx_stats <stats_option> <mac_id>");
  6525. dp_info("stats_option:");
  6526. dp_info(" 1 -- HTT Tx Statistics");
  6527. dp_info(" 2 -- HTT Rx Statistics");
  6528. dp_info(" 3 -- HTT Tx HW Queue Statistics");
  6529. dp_info(" 4 -- HTT Tx HW Sched Statistics");
  6530. dp_info(" 5 -- HTT Error Statistics");
  6531. dp_info(" 6 -- HTT TQM Statistics");
  6532. dp_info(" 7 -- HTT TQM CMDQ Statistics");
  6533. dp_info(" 8 -- HTT TX_DE_CMN Statistics");
  6534. dp_info(" 9 -- HTT Tx Rate Statistics");
  6535. dp_info(" 10 -- HTT Rx Rate Statistics");
  6536. dp_info(" 11 -- HTT Peer Statistics");
  6537. dp_info(" 12 -- HTT Tx SelfGen Statistics");
  6538. dp_info(" 13 -- HTT Tx MU HWQ Statistics");
  6539. dp_info(" 14 -- HTT RING_IF_INFO Statistics");
  6540. dp_info(" 15 -- HTT SRNG Statistics");
  6541. dp_info(" 16 -- HTT SFM Info Statistics");
  6542. dp_info(" 17 -- HTT PDEV_TX_MU_MIMO_SCHED INFO Statistics");
  6543. dp_info(" 18 -- HTT Peer List Details");
  6544. dp_info(" 20 -- Clear Host Statistics");
  6545. dp_info(" 21 -- Host Rx Rate Statistics");
  6546. dp_info(" 22 -- Host Tx Rate Statistics");
  6547. dp_info(" 23 -- Host Tx Statistics");
  6548. dp_info(" 24 -- Host Rx Statistics");
  6549. dp_info(" 25 -- Host AST Statistics");
  6550. dp_info(" 26 -- Host SRNG PTR Statistics");
  6551. dp_info(" 27 -- Host Mon Statistics");
  6552. dp_info(" 28 -- Host REO Queue Statistics");
  6553. dp_info(" 29 -- Host Soc cfg param Statistics");
  6554. dp_info(" 30 -- Host pdev cfg param Statistics");
  6555. }
  6556. /**
  6557. * dp_print_host_stats()- Function to print the stats aggregated at host
  6558. * @vdev_handle: DP_VDEV handle
  6559. * @type: host stats type
  6560. *
  6561. * Return: 0 on success, print error message in case of failure
  6562. */
  6563. static int
  6564. dp_print_host_stats(struct dp_vdev *vdev,
  6565. struct cdp_txrx_stats_req *req)
  6566. {
  6567. struct dp_pdev *pdev = (struct dp_pdev *)vdev->pdev;
  6568. enum cdp_host_txrx_stats type =
  6569. dp_stats_mapping_table[req->stats][STATS_HOST];
  6570. dp_aggregate_pdev_stats(pdev);
  6571. switch (type) {
  6572. case TXRX_CLEAR_STATS:
  6573. dp_txrx_host_stats_clr(vdev);
  6574. break;
  6575. case TXRX_RX_RATE_STATS:
  6576. dp_print_rx_rates(vdev);
  6577. break;
  6578. case TXRX_TX_RATE_STATS:
  6579. dp_print_tx_rates(vdev);
  6580. break;
  6581. case TXRX_TX_HOST_STATS:
  6582. dp_print_pdev_tx_stats(pdev);
  6583. dp_print_soc_tx_stats(pdev->soc);
  6584. break;
  6585. case TXRX_RX_HOST_STATS:
  6586. dp_print_pdev_rx_stats(pdev);
  6587. dp_print_soc_rx_stats(pdev->soc);
  6588. break;
  6589. case TXRX_AST_STATS:
  6590. dp_print_ast_stats(pdev->soc);
  6591. dp_print_peer_table(vdev);
  6592. break;
  6593. case TXRX_SRNG_PTR_STATS:
  6594. dp_print_ring_stats(pdev);
  6595. break;
  6596. case TXRX_RX_MON_STATS:
  6597. dp_print_pdev_rx_mon_stats(pdev);
  6598. break;
  6599. case TXRX_REO_QUEUE_STATS:
  6600. dp_get_host_peer_stats((struct cdp_soc_t *)pdev->soc,
  6601. req->peer_addr);
  6602. break;
  6603. case TXRX_SOC_CFG_PARAMS:
  6604. dp_print_soc_cfg_params(pdev->soc);
  6605. break;
  6606. case TXRX_PDEV_CFG_PARAMS:
  6607. dp_print_pdev_cfg_params(pdev);
  6608. break;
  6609. case TXRX_NAPI_STATS:
  6610. dp_print_napi_stats(pdev->soc);
  6611. case TXRX_SOC_INTERRUPT_STATS:
  6612. dp_print_soc_interrupt_stats(pdev->soc);
  6613. break;
  6614. default:
  6615. dp_info("Wrong Input For TxRx Host Stats");
  6616. dp_txrx_stats_help();
  6617. break;
  6618. }
  6619. return 0;
  6620. }
  6621. /*
  6622. * dp_ppdu_ring_reset()- Reset PPDU Stats ring
  6623. * @pdev: DP_PDEV handle
  6624. *
  6625. * Return: void
  6626. */
  6627. static void
  6628. dp_ppdu_ring_reset(struct dp_pdev *pdev)
  6629. {
  6630. struct htt_rx_ring_tlv_filter htt_tlv_filter;
  6631. int mac_id;
  6632. qdf_mem_zero(&(htt_tlv_filter), sizeof(htt_tlv_filter));
  6633. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  6634. int mac_for_pdev =
  6635. dp_get_mac_id_for_pdev(mac_id, pdev->pdev_id);
  6636. /*
  6637. * Obtain lmac id from pdev to access the LMAC ring in soc
  6638. * context
  6639. */
  6640. int lmac_id =
  6641. dp_get_lmac_id_for_pdev_id(pdev->soc,
  6642. mac_id, pdev->pdev_id);
  6643. htt_h2t_rx_ring_cfg(pdev->soc->htt_handle, mac_for_pdev,
  6644. pdev->soc->rxdma_mon_status_ring[lmac_id].hal_srng,
  6645. RXDMA_MONITOR_STATUS, RX_BUFFER_SIZE, &htt_tlv_filter);
  6646. }
  6647. }
  6648. /*
  6649. * dp_ppdu_ring_cfg()- Configure PPDU Stats ring
  6650. * @pdev: DP_PDEV handle
  6651. *
  6652. * Return: void
  6653. */
  6654. static void
  6655. dp_ppdu_ring_cfg(struct dp_pdev *pdev)
  6656. {
  6657. struct htt_rx_ring_tlv_filter htt_tlv_filter = {0};
  6658. int mac_id;
  6659. htt_tlv_filter.mpdu_start = 1;
  6660. htt_tlv_filter.msdu_start = 0;
  6661. htt_tlv_filter.packet = 0;
  6662. htt_tlv_filter.msdu_end = 0;
  6663. htt_tlv_filter.mpdu_end = 0;
  6664. htt_tlv_filter.attention = 0;
  6665. htt_tlv_filter.ppdu_start = 1;
  6666. htt_tlv_filter.ppdu_end = 1;
  6667. htt_tlv_filter.ppdu_end_user_stats = 1;
  6668. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  6669. htt_tlv_filter.ppdu_end_status_done = 1;
  6670. htt_tlv_filter.enable_fp = 1;
  6671. htt_tlv_filter.enable_md = 0;
  6672. if (pdev->neighbour_peers_added &&
  6673. pdev->soc->hw_nac_monitor_support) {
  6674. htt_tlv_filter.enable_md = 1;
  6675. htt_tlv_filter.packet_header = 1;
  6676. }
  6677. if (pdev->mcopy_mode) {
  6678. htt_tlv_filter.packet_header = 1;
  6679. htt_tlv_filter.enable_mo = 1;
  6680. }
  6681. htt_tlv_filter.fp_mgmt_filter = FILTER_MGMT_ALL;
  6682. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_ALL;
  6683. htt_tlv_filter.fp_data_filter = FILTER_DATA_ALL;
  6684. htt_tlv_filter.mo_mgmt_filter = FILTER_MGMT_ALL;
  6685. htt_tlv_filter.mo_ctrl_filter = FILTER_CTRL_ALL;
  6686. htt_tlv_filter.mo_data_filter = FILTER_DATA_ALL;
  6687. if (pdev->neighbour_peers_added &&
  6688. pdev->soc->hw_nac_monitor_support)
  6689. htt_tlv_filter.md_data_filter = FILTER_DATA_ALL;
  6690. htt_tlv_filter.offset_valid = false;
  6691. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  6692. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id,
  6693. pdev->pdev_id);
  6694. /*
  6695. * Obtain lmac id from pdev to access the LMAC ring in soc
  6696. * context
  6697. */
  6698. int lmac_id =
  6699. dp_get_lmac_id_for_pdev_id(pdev->soc,
  6700. mac_id, pdev->pdev_id);
  6701. htt_h2t_rx_ring_cfg(pdev->soc->htt_handle, mac_for_pdev,
  6702. pdev->soc->rxdma_mon_status_ring[lmac_id].hal_srng,
  6703. RXDMA_MONITOR_STATUS, RX_BUFFER_SIZE, &htt_tlv_filter);
  6704. }
  6705. }
  6706. /*
  6707. * is_ppdu_txrx_capture_enabled() - API to check both pktlog and debug_sniffer
  6708. * modes are enabled or not.
  6709. * @dp_pdev: dp pdev handle.
  6710. *
  6711. * Return: bool
  6712. */
  6713. static inline bool is_ppdu_txrx_capture_enabled(struct dp_pdev *pdev)
  6714. {
  6715. if (!pdev->pktlog_ppdu_stats && !pdev->tx_sniffer_enable &&
  6716. !pdev->mcopy_mode)
  6717. return true;
  6718. else
  6719. return false;
  6720. }
  6721. /*
  6722. *dp_set_bpr_enable() - API to enable/disable bpr feature
  6723. *@pdev_handle: DP_PDEV handle.
  6724. *@val: Provided value.
  6725. *
  6726. *Return: 0 for success. nonzero for failure.
  6727. */
  6728. static QDF_STATUS
  6729. dp_set_bpr_enable(struct dp_pdev *pdev, int val)
  6730. {
  6731. switch (val) {
  6732. case CDP_BPR_DISABLE:
  6733. pdev->bpr_enable = CDP_BPR_DISABLE;
  6734. if (!pdev->pktlog_ppdu_stats && !pdev->enhanced_stats_en &&
  6735. !pdev->tx_sniffer_enable && !pdev->mcopy_mode) {
  6736. dp_h2t_cfg_stats_msg_send(pdev, 0, pdev->pdev_id);
  6737. } else if (pdev->enhanced_stats_en &&
  6738. !pdev->tx_sniffer_enable && !pdev->mcopy_mode &&
  6739. !pdev->pktlog_ppdu_stats) {
  6740. dp_h2t_cfg_stats_msg_send(pdev,
  6741. DP_PPDU_STATS_CFG_ENH_STATS,
  6742. pdev->pdev_id);
  6743. }
  6744. break;
  6745. case CDP_BPR_ENABLE:
  6746. pdev->bpr_enable = CDP_BPR_ENABLE;
  6747. if (!pdev->enhanced_stats_en && !pdev->tx_sniffer_enable &&
  6748. !pdev->mcopy_mode && !pdev->pktlog_ppdu_stats) {
  6749. dp_h2t_cfg_stats_msg_send(pdev,
  6750. DP_PPDU_STATS_CFG_BPR,
  6751. pdev->pdev_id);
  6752. } else if (pdev->enhanced_stats_en &&
  6753. !pdev->tx_sniffer_enable && !pdev->mcopy_mode &&
  6754. !pdev->pktlog_ppdu_stats) {
  6755. dp_h2t_cfg_stats_msg_send(pdev,
  6756. DP_PPDU_STATS_CFG_BPR_ENH,
  6757. pdev->pdev_id);
  6758. } else if (pdev->pktlog_ppdu_stats) {
  6759. dp_h2t_cfg_stats_msg_send(pdev,
  6760. DP_PPDU_STATS_CFG_BPR_PKTLOG,
  6761. pdev->pdev_id);
  6762. }
  6763. break;
  6764. default:
  6765. break;
  6766. }
  6767. return QDF_STATUS_SUCCESS;
  6768. }
  6769. /*
  6770. * dp_pdev_tid_stats_ingress_inc
  6771. * @pdev: pdev handle
  6772. * @val: increase in value
  6773. *
  6774. * Return: void
  6775. */
  6776. static void
  6777. dp_pdev_tid_stats_ingress_inc(struct dp_pdev *pdev, uint32_t val)
  6778. {
  6779. pdev->stats.tid_stats.ingress_stack += val;
  6780. }
  6781. /*
  6782. * dp_pdev_tid_stats_osif_drop
  6783. * @pdev: pdev handle
  6784. * @val: increase in value
  6785. *
  6786. * Return: void
  6787. */
  6788. static void
  6789. dp_pdev_tid_stats_osif_drop(struct dp_pdev *pdev, uint32_t val)
  6790. {
  6791. pdev->stats.tid_stats.osif_drop += val;
  6792. }
  6793. /*
  6794. * dp_config_debug_sniffer()- API to enable/disable debug sniffer
  6795. * @pdev: DP_PDEV handle
  6796. * @val: user provided value
  6797. *
  6798. * Return: 0 for success. nonzero for failure.
  6799. */
  6800. static QDF_STATUS
  6801. dp_config_debug_sniffer(struct dp_pdev *pdev, int val)
  6802. {
  6803. QDF_STATUS status = QDF_STATUS_SUCCESS;
  6804. if (pdev->mcopy_mode)
  6805. dp_reset_monitor_mode((struct cdp_soc_t *)(pdev->soc),
  6806. pdev->pdev_id);
  6807. switch (val) {
  6808. case 0:
  6809. pdev->tx_sniffer_enable = 0;
  6810. pdev->monitor_configured = false;
  6811. if (!pdev->pktlog_ppdu_stats && !pdev->enhanced_stats_en &&
  6812. !pdev->bpr_enable) {
  6813. dp_h2t_cfg_stats_msg_send(pdev, 0, pdev->pdev_id);
  6814. dp_ppdu_ring_reset(pdev);
  6815. } else if (pdev->enhanced_stats_en && !pdev->bpr_enable) {
  6816. dp_h2t_cfg_stats_msg_send(pdev,
  6817. DP_PPDU_STATS_CFG_ENH_STATS, pdev->pdev_id);
  6818. } else if (!pdev->enhanced_stats_en && pdev->bpr_enable) {
  6819. dp_h2t_cfg_stats_msg_send(pdev,
  6820. DP_PPDU_STATS_CFG_BPR_ENH,
  6821. pdev->pdev_id);
  6822. } else {
  6823. dp_h2t_cfg_stats_msg_send(pdev,
  6824. DP_PPDU_STATS_CFG_BPR,
  6825. pdev->pdev_id);
  6826. }
  6827. break;
  6828. case 1:
  6829. pdev->tx_sniffer_enable = 1;
  6830. pdev->monitor_configured = false;
  6831. if (!pdev->pktlog_ppdu_stats)
  6832. dp_h2t_cfg_stats_msg_send(pdev,
  6833. DP_PPDU_STATS_CFG_SNIFFER, pdev->pdev_id);
  6834. break;
  6835. case 2:
  6836. if (pdev->monitor_vdev) {
  6837. status = QDF_STATUS_E_RESOURCES;
  6838. break;
  6839. }
  6840. pdev->mcopy_mode = 1;
  6841. dp_pdev_configure_monitor_rings(pdev);
  6842. pdev->monitor_configured = true;
  6843. pdev->tx_sniffer_enable = 0;
  6844. if (!pdev->pktlog_ppdu_stats)
  6845. dp_h2t_cfg_stats_msg_send(pdev,
  6846. DP_PPDU_STATS_CFG_SNIFFER, pdev->pdev_id);
  6847. break;
  6848. default:
  6849. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  6850. "Invalid value");
  6851. break;
  6852. }
  6853. return status;
  6854. }
  6855. /*
  6856. * dp_enable_enhanced_stats()- API to enable enhanced statistcs
  6857. * @soc_handle: DP_SOC handle
  6858. * @pdev_id: id of DP_PDEV handle
  6859. *
  6860. * Return: QDF_STATUS
  6861. */
  6862. static QDF_STATUS
  6863. dp_enable_enhanced_stats(struct cdp_soc_t *soc, uint8_t pdev_id)
  6864. {
  6865. struct dp_pdev *pdev =
  6866. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  6867. pdev_id);
  6868. if (!pdev)
  6869. return QDF_STATUS_E_FAILURE;
  6870. if (pdev->enhanced_stats_en == 0)
  6871. dp_cal_client_timer_start(pdev->cal_client_ctx);
  6872. pdev->enhanced_stats_en = 1;
  6873. if (!pdev->mcopy_mode && !pdev->neighbour_peers_added &&
  6874. !pdev->monitor_vdev)
  6875. dp_ppdu_ring_cfg(pdev);
  6876. if (is_ppdu_txrx_capture_enabled(pdev) && !pdev->bpr_enable) {
  6877. dp_h2t_cfg_stats_msg_send(pdev, DP_PPDU_STATS_CFG_ENH_STATS, pdev->pdev_id);
  6878. } else if (is_ppdu_txrx_capture_enabled(pdev) && pdev->bpr_enable) {
  6879. dp_h2t_cfg_stats_msg_send(pdev,
  6880. DP_PPDU_STATS_CFG_BPR_ENH,
  6881. pdev->pdev_id);
  6882. }
  6883. return QDF_STATUS_SUCCESS;
  6884. }
  6885. /*
  6886. * dp_disable_enhanced_stats()- API to disable enhanced statistcs
  6887. *
  6888. * @param soc - the soc handle
  6889. * @param pdev_id - pdev_id of pdev
  6890. * @return - QDF_STATUS
  6891. */
  6892. static QDF_STATUS
  6893. dp_disable_enhanced_stats(struct cdp_soc_t *soc, uint8_t pdev_id)
  6894. {
  6895. struct dp_pdev *pdev =
  6896. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  6897. pdev_id);
  6898. if (!pdev)
  6899. return QDF_STATUS_E_FAILURE;
  6900. if (pdev->enhanced_stats_en == 1)
  6901. dp_cal_client_timer_stop(pdev->cal_client_ctx);
  6902. pdev->enhanced_stats_en = 0;
  6903. if (is_ppdu_txrx_capture_enabled(pdev) && !pdev->bpr_enable) {
  6904. dp_h2t_cfg_stats_msg_send(pdev, 0, pdev->pdev_id);
  6905. } else if (is_ppdu_txrx_capture_enabled(pdev) && pdev->bpr_enable) {
  6906. dp_h2t_cfg_stats_msg_send(pdev,
  6907. DP_PPDU_STATS_CFG_BPR,
  6908. pdev->pdev_id);
  6909. }
  6910. if (!pdev->mcopy_mode && !pdev->neighbour_peers_added &&
  6911. !pdev->monitor_vdev)
  6912. dp_ppdu_ring_reset(pdev);
  6913. return QDF_STATUS_SUCCESS;
  6914. }
  6915. /*
  6916. * dp_get_fw_peer_stats()- function to print peer stats
  6917. * @soc: soc handle
  6918. * @pdev_id : id of the pdev handle
  6919. * @mac_addr: mac address of the peer
  6920. * @cap: Type of htt stats requested
  6921. * @is_wait: if set, wait on completion from firmware response
  6922. *
  6923. * Currently Supporting only MAC ID based requests Only
  6924. * 1: HTT_PEER_STATS_REQ_MODE_NO_QUERY
  6925. * 2: HTT_PEER_STATS_REQ_MODE_QUERY_TQM
  6926. * 3: HTT_PEER_STATS_REQ_MODE_FLUSH_TQM
  6927. *
  6928. * Return: QDF_STATUS
  6929. */
  6930. static QDF_STATUS
  6931. dp_get_fw_peer_stats(struct cdp_soc_t *soc, uint8_t pdev_id,
  6932. uint8_t *mac_addr,
  6933. uint32_t cap, uint32_t is_wait)
  6934. {
  6935. int i;
  6936. uint32_t config_param0 = 0;
  6937. uint32_t config_param1 = 0;
  6938. uint32_t config_param2 = 0;
  6939. uint32_t config_param3 = 0;
  6940. struct dp_pdev *pdev =
  6941. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  6942. pdev_id);
  6943. if (!pdev)
  6944. return QDF_STATUS_E_FAILURE;
  6945. HTT_DBG_EXT_STATS_PEER_INFO_IS_MAC_ADDR_SET(config_param0, 1);
  6946. config_param0 |= (1 << (cap + 1));
  6947. for (i = 0; i < HTT_PEER_STATS_MAX_TLV; i++) {
  6948. config_param1 |= (1 << i);
  6949. }
  6950. config_param2 |= (mac_addr[0] & 0x000000ff);
  6951. config_param2 |= ((mac_addr[1] << 8) & 0x0000ff00);
  6952. config_param2 |= ((mac_addr[2] << 16) & 0x00ff0000);
  6953. config_param2 |= ((mac_addr[3] << 24) & 0xff000000);
  6954. config_param3 |= (mac_addr[4] & 0x000000ff);
  6955. config_param3 |= ((mac_addr[5] << 8) & 0x0000ff00);
  6956. if (is_wait) {
  6957. qdf_event_reset(&pdev->fw_peer_stats_event);
  6958. dp_h2t_ext_stats_msg_send(pdev, HTT_DBG_EXT_STATS_PEER_INFO,
  6959. config_param0, config_param1,
  6960. config_param2, config_param3,
  6961. 0, 1, 0);
  6962. qdf_wait_single_event(&pdev->fw_peer_stats_event,
  6963. DP_FW_PEER_STATS_CMP_TIMEOUT_MSEC);
  6964. } else {
  6965. dp_h2t_ext_stats_msg_send(pdev, HTT_DBG_EXT_STATS_PEER_INFO,
  6966. config_param0, config_param1,
  6967. config_param2, config_param3,
  6968. 0, 0, 0);
  6969. }
  6970. return QDF_STATUS_SUCCESS;
  6971. }
  6972. /* This struct definition will be removed from here
  6973. * once it get added in FW headers*/
  6974. struct httstats_cmd_req {
  6975. uint32_t config_param0;
  6976. uint32_t config_param1;
  6977. uint32_t config_param2;
  6978. uint32_t config_param3;
  6979. int cookie;
  6980. u_int8_t stats_id;
  6981. };
  6982. /*
  6983. * dp_get_htt_stats: function to process the httstas request
  6984. * @soc: DP soc handle
  6985. * @pdev_id: id of pdev handle
  6986. * @data: pointer to request data
  6987. * @data_len: length for request data
  6988. *
  6989. * return: QDF_STATUS
  6990. */
  6991. static QDF_STATUS
  6992. dp_get_htt_stats(struct cdp_soc_t *soc, uint8_t pdev_id, void *data,
  6993. uint32_t data_len)
  6994. {
  6995. struct httstats_cmd_req *req = (struct httstats_cmd_req *)data;
  6996. struct dp_pdev *pdev =
  6997. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  6998. pdev_id);
  6999. if (!pdev)
  7000. return QDF_STATUS_E_FAILURE;
  7001. QDF_ASSERT(data_len == sizeof(struct httstats_cmd_req));
  7002. dp_h2t_ext_stats_msg_send(pdev, req->stats_id,
  7003. req->config_param0, req->config_param1,
  7004. req->config_param2, req->config_param3,
  7005. req->cookie, 0, 0);
  7006. return QDF_STATUS_SUCCESS;
  7007. }
  7008. /**
  7009. * dp_set_pdev_tidmap_prty_wifi3(): update tidmap priority in pdev
  7010. * @pdev: DP_PDEV handle
  7011. * @prio: tidmap priority value passed by the user
  7012. *
  7013. * Return: QDF_STATUS_SUCCESS on success
  7014. */
  7015. static QDF_STATUS dp_set_pdev_tidmap_prty_wifi3(struct dp_pdev *pdev,
  7016. uint8_t prio)
  7017. {
  7018. struct dp_soc *soc = pdev->soc;
  7019. soc->tidmap_prty = prio;
  7020. hal_tx_set_tidmap_prty(soc->hal_soc, prio);
  7021. return QDF_STATUS_SUCCESS;
  7022. }
  7023. /*
  7024. * dp_get_peer_param: function to get parameters in peer
  7025. * @cdp_soc: DP soc handle
  7026. * @vdev_id: id of vdev handle
  7027. * @peer_mac: peer mac address
  7028. * @param: parameter type to be set
  7029. * @val : address of buffer
  7030. *
  7031. * Return: val
  7032. */
  7033. static QDF_STATUS dp_get_peer_param(struct cdp_soc_t *cdp_soc, uint8_t vdev_id,
  7034. uint8_t *peer_mac,
  7035. enum cdp_peer_param_type param,
  7036. cdp_config_param_type *val)
  7037. {
  7038. return QDF_STATUS_SUCCESS;
  7039. }
  7040. /*
  7041. * dp_set_peer_param: function to set parameters in peer
  7042. * @cdp_soc: DP soc handle
  7043. * @vdev_id: id of vdev handle
  7044. * @peer_mac: peer mac address
  7045. * @param: parameter type to be set
  7046. * @val: value of parameter to be set
  7047. *
  7048. * Return: 0 for success. nonzero for failure.
  7049. */
  7050. static QDF_STATUS dp_set_peer_param(struct cdp_soc_t *cdp_soc, uint8_t vdev_id,
  7051. uint8_t *peer_mac,
  7052. enum cdp_peer_param_type param,
  7053. cdp_config_param_type val)
  7054. {
  7055. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)cdp_soc,
  7056. peer_mac, 0, vdev_id);
  7057. if (!peer || peer->delete_in_progress)
  7058. goto fail;
  7059. switch (param) {
  7060. case CDP_CONFIG_NAWDS:
  7061. peer->nawds_enabled = val.cdp_peer_param_nawds;
  7062. break;
  7063. case CDP_CONFIG_NAC:
  7064. peer->nac = !!(val.cdp_peer_param_nac);
  7065. break;
  7066. default:
  7067. break;
  7068. }
  7069. fail:
  7070. if (peer)
  7071. dp_peer_unref_delete(peer);
  7072. return QDF_STATUS_SUCCESS;
  7073. }
  7074. /*
  7075. * dp_get_pdev_param: function to get parameters from pdev
  7076. * @cdp_soc: DP soc handle
  7077. * @pdev_id: id of pdev handle
  7078. * @param: parameter type to be get
  7079. * @value : buffer for value
  7080. *
  7081. * Return: status
  7082. */
  7083. static QDF_STATUS dp_get_pdev_param(struct cdp_soc_t *cdp_soc, uint8_t pdev_id,
  7084. enum cdp_pdev_param_type param,
  7085. cdp_config_param_type *val)
  7086. {
  7087. struct cdp_pdev *pdev = (struct cdp_pdev *)
  7088. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)cdp_soc,
  7089. pdev_id);
  7090. if (!pdev)
  7091. return QDF_STATUS_E_FAILURE;
  7092. switch (param) {
  7093. case CDP_CONFIG_VOW:
  7094. val->cdp_pdev_param_cfg_vow =
  7095. ((struct dp_pdev *)pdev)->delay_stats_flag;
  7096. break;
  7097. case CDP_TX_PENDING:
  7098. val->cdp_pdev_param_tx_pending = dp_get_tx_pending(pdev);
  7099. break;
  7100. case CDP_FILTER_MCAST_DATA:
  7101. val->cdp_pdev_param_fltr_mcast =
  7102. dp_pdev_get_filter_mcast_data(pdev);
  7103. break;
  7104. case CDP_FILTER_NO_DATA:
  7105. val->cdp_pdev_param_fltr_none =
  7106. dp_pdev_get_filter_non_data(pdev);
  7107. break;
  7108. case CDP_FILTER_UCAST_DATA:
  7109. val->cdp_pdev_param_fltr_ucast =
  7110. dp_pdev_get_filter_ucast_data(pdev);
  7111. break;
  7112. default:
  7113. return QDF_STATUS_E_FAILURE;
  7114. }
  7115. return QDF_STATUS_SUCCESS;
  7116. }
  7117. /*
  7118. * dp_set_pdev_param: function to set parameters in pdev
  7119. * @cdp_soc: DP soc handle
  7120. * @pdev_id: id of pdev handle
  7121. * @param: parameter type to be set
  7122. * @val: value of parameter to be set
  7123. *
  7124. * Return: 0 for success. nonzero for failure.
  7125. */
  7126. static QDF_STATUS dp_set_pdev_param(struct cdp_soc_t *cdp_soc, uint8_t pdev_id,
  7127. enum cdp_pdev_param_type param,
  7128. cdp_config_param_type val)
  7129. {
  7130. struct dp_pdev *pdev =
  7131. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)cdp_soc,
  7132. pdev_id);
  7133. if (!pdev)
  7134. return QDF_STATUS_E_FAILURE;
  7135. switch (param) {
  7136. case CDP_CONFIG_TX_CAPTURE:
  7137. return dp_config_debug_sniffer(pdev,
  7138. val.cdp_pdev_param_tx_capture);
  7139. case CDP_CONFIG_DEBUG_SNIFFER:
  7140. return dp_config_debug_sniffer(pdev,
  7141. val.cdp_pdev_param_dbg_snf);
  7142. case CDP_CONFIG_BPR_ENABLE:
  7143. return dp_set_bpr_enable(pdev, val.cdp_pdev_param_bpr_enable);
  7144. case CDP_CONFIG_PRIMARY_RADIO:
  7145. pdev->is_primary = val.cdp_pdev_param_primary_radio;
  7146. break;
  7147. case CDP_CONFIG_CAPTURE_LATENCY:
  7148. pdev->latency_capture_enable = val.cdp_pdev_param_cptr_latcy;
  7149. break;
  7150. case CDP_INGRESS_STATS:
  7151. dp_pdev_tid_stats_ingress_inc(pdev,
  7152. val.cdp_pdev_param_ingrs_stats);
  7153. break;
  7154. case CDP_OSIF_DROP:
  7155. dp_pdev_tid_stats_osif_drop(pdev,
  7156. val.cdp_pdev_param_osif_drop);
  7157. break;
  7158. case CDP_CONFIG_ENH_RX_CAPTURE:
  7159. return dp_config_enh_rx_capture(pdev,
  7160. val.cdp_pdev_param_en_rx_cap);
  7161. case CDP_CONFIG_ENH_TX_CAPTURE:
  7162. return dp_config_enh_tx_capture(pdev,
  7163. val.cdp_pdev_param_en_tx_cap);
  7164. case CDP_CONFIG_HMMC_TID_OVERRIDE:
  7165. pdev->hmmc_tid_override_en = val.cdp_pdev_param_hmmc_tid_ovrd;
  7166. break;
  7167. case CDP_CONFIG_HMMC_TID_VALUE:
  7168. pdev->hmmc_tid = val.cdp_pdev_param_hmmc_tid;
  7169. break;
  7170. case CDP_CHAN_NOISE_FLOOR:
  7171. pdev->chan_noise_floor = val.cdp_pdev_param_chn_noise_flr;
  7172. break;
  7173. case CDP_TIDMAP_PRTY:
  7174. dp_set_pdev_tidmap_prty_wifi3(pdev,
  7175. val.cdp_pdev_param_tidmap_prty);
  7176. break;
  7177. case CDP_FILTER_NEIGH_PEERS:
  7178. dp_set_filter_neigh_peers(pdev,
  7179. val.cdp_pdev_param_fltr_neigh_peers);
  7180. break;
  7181. case CDP_MONITOR_CHANNEL:
  7182. pdev->mon_chan_num = val.cdp_pdev_param_monitor_chan;
  7183. break;
  7184. case CDP_MONITOR_FREQUENCY:
  7185. pdev->mon_chan_freq = val.cdp_pdev_param_mon_freq;
  7186. break;
  7187. case CDP_CONFIG_BSS_COLOR:
  7188. dp_mon_set_bsscolor(pdev, val.cdp_pdev_param_bss_color);
  7189. break;
  7190. default:
  7191. return QDF_STATUS_E_INVAL;
  7192. }
  7193. return QDF_STATUS_SUCCESS;
  7194. }
  7195. /*
  7196. * dp_calculate_delay_stats: function to get rx delay stats
  7197. * @cdp_soc: DP soc handle
  7198. * @vdev_id: id of DP vdev handle
  7199. * @nbuf: skb
  7200. *
  7201. * Return: QDF_STATUS
  7202. */
  7203. static QDF_STATUS
  7204. dp_calculate_delay_stats(struct cdp_soc_t *cdp_soc, uint8_t vdev_id,
  7205. qdf_nbuf_t nbuf)
  7206. {
  7207. struct dp_vdev *vdev =
  7208. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)cdp_soc,
  7209. vdev_id);
  7210. if (vdev) {
  7211. dp_rx_compute_delay(vdev, nbuf);
  7212. return QDF_STATUS_E_FAILURE;
  7213. }
  7214. return QDF_STATUS_SUCCESS;
  7215. }
  7216. /*
  7217. * dp_get_vdev_param: function to get parameters from vdev
  7218. * @cdp_soc : DP soc handle
  7219. * @vdev_id: id of DP vdev handle
  7220. * @param: parameter type to get value
  7221. * @val: buffer address
  7222. *
  7223. * return: status
  7224. */
  7225. static QDF_STATUS dp_get_vdev_param(struct cdp_soc_t *cdp_soc, uint8_t vdev_id,
  7226. enum cdp_vdev_param_type param,
  7227. cdp_config_param_type *val)
  7228. {
  7229. struct dp_vdev *vdev =
  7230. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)cdp_soc,
  7231. vdev_id);
  7232. if (!vdev)
  7233. return QDF_STATUS_E_FAILURE;
  7234. switch (param) {
  7235. case CDP_ENABLE_WDS:
  7236. val->cdp_vdev_param_wds = vdev->wds_enabled;
  7237. break;
  7238. case CDP_ENABLE_MEC:
  7239. val->cdp_vdev_param_mec = vdev->mec_enabled;
  7240. break;
  7241. case CDP_ENABLE_DA_WAR:
  7242. val->cdp_vdev_param_da_war = vdev->pdev->soc->da_war_enabled;
  7243. break;
  7244. default:
  7245. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7246. "param value %d is wrong\n",
  7247. param);
  7248. return QDF_STATUS_E_FAILURE;
  7249. }
  7250. return QDF_STATUS_SUCCESS;
  7251. }
  7252. /*
  7253. * dp_set_vdev_param: function to set parameters in vdev
  7254. * @cdp_soc : DP soc handle
  7255. * @vdev_id: id of DP vdev handle
  7256. * @param: parameter type to get value
  7257. * @val: value
  7258. *
  7259. * return: QDF_STATUS
  7260. */
  7261. static QDF_STATUS
  7262. dp_set_vdev_param(struct cdp_soc_t *cdp_soc, uint8_t vdev_id,
  7263. enum cdp_vdev_param_type param, cdp_config_param_type val)
  7264. {
  7265. struct dp_soc *dsoc = (struct dp_soc *)cdp_soc;
  7266. struct dp_vdev *vdev =
  7267. dp_get_vdev_from_soc_vdev_id_wifi3(dsoc, vdev_id);
  7268. uint32_t var = 0;
  7269. if (!vdev)
  7270. return QDF_STATUS_E_FAILURE;
  7271. switch (param) {
  7272. case CDP_ENABLE_WDS:
  7273. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7274. "wds_enable %d for vdev(%pK) id(%d)\n",
  7275. val.cdp_vdev_param_wds, vdev, vdev->vdev_id);
  7276. vdev->wds_enabled = val.cdp_vdev_param_wds;
  7277. break;
  7278. case CDP_ENABLE_MEC:
  7279. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7280. "mec_enable %d for vdev(%pK) id(%d)\n",
  7281. val.cdp_vdev_param_mec, vdev, vdev->vdev_id);
  7282. vdev->mec_enabled = val.cdp_vdev_param_mec;
  7283. break;
  7284. case CDP_ENABLE_DA_WAR:
  7285. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7286. "da_war_enable %d for vdev(%pK) id(%d)\n",
  7287. val.cdp_vdev_param_da_war, vdev, vdev->vdev_id);
  7288. vdev->pdev->soc->da_war_enabled = val.cdp_vdev_param_da_war;
  7289. dp_wds_flush_ast_table_wifi3(((struct cdp_soc_t *)
  7290. vdev->pdev->soc));
  7291. break;
  7292. case CDP_ENABLE_NAWDS:
  7293. vdev->nawds_enabled = val.cdp_vdev_param_nawds;
  7294. break;
  7295. case CDP_ENABLE_MCAST_EN:
  7296. vdev->mcast_enhancement_en = val.cdp_vdev_param_mcast_en;
  7297. break;
  7298. case CDP_ENABLE_PROXYSTA:
  7299. vdev->proxysta_vdev = val.cdp_vdev_param_proxysta;
  7300. break;
  7301. case CDP_UPDATE_TDLS_FLAGS:
  7302. vdev->tdls_link_connected = val.cdp_vdev_param_tdls_flags;
  7303. break;
  7304. case CDP_CFG_WDS_AGING_TIMER:
  7305. var = val.cdp_vdev_param_aging_tmr;
  7306. if (!var)
  7307. qdf_timer_stop(&vdev->pdev->soc->ast_aging_timer);
  7308. else if (var != vdev->wds_aging_timer_val)
  7309. qdf_timer_mod(&vdev->pdev->soc->ast_aging_timer, var);
  7310. vdev->wds_aging_timer_val = var;
  7311. break;
  7312. case CDP_ENABLE_AP_BRIDGE:
  7313. if (wlan_op_mode_sta != vdev->opmode)
  7314. vdev->ap_bridge_enabled = val.cdp_vdev_param_ap_brdg_en;
  7315. else
  7316. vdev->ap_bridge_enabled = false;
  7317. break;
  7318. case CDP_ENABLE_CIPHER:
  7319. vdev->sec_type = val.cdp_vdev_param_cipher_en;
  7320. break;
  7321. case CDP_ENABLE_QWRAP_ISOLATION:
  7322. vdev->isolation_vdev = val.cdp_vdev_param_qwrap_isolation;
  7323. break;
  7324. case CDP_UPDATE_MULTIPASS:
  7325. vdev->multipass_en = val.cdp_vdev_param_update_multipass;
  7326. break;
  7327. case CDP_TX_ENCAP_TYPE:
  7328. vdev->tx_encap_type = val.cdp_vdev_param_tx_encap;
  7329. break;
  7330. case CDP_RX_DECAP_TYPE:
  7331. vdev->rx_decap_type = val.cdp_vdev_param_rx_decap;
  7332. break;
  7333. case CDP_TID_VDEV_PRTY:
  7334. vdev->tidmap_prty = val.cdp_vdev_param_tidmap_prty;
  7335. break;
  7336. case CDP_TIDMAP_TBL_ID:
  7337. vdev->tidmap_tbl_id = val.cdp_vdev_param_tidmap_tbl_id;
  7338. break;
  7339. #ifdef MESH_MODE_SUPPORT
  7340. case CDP_MESH_RX_FILTER:
  7341. dp_peer_set_mesh_rx_filter((struct cdp_vdev *)vdev,
  7342. val.cdp_vdev_param_mesh_rx_filter);
  7343. break;
  7344. case CDP_MESH_MODE:
  7345. dp_peer_set_mesh_mode((struct cdp_vdev *)vdev,
  7346. val.cdp_vdev_param_mesh_mode);
  7347. break;
  7348. #endif
  7349. default:
  7350. break;
  7351. }
  7352. dp_tx_vdev_update_search_flags((struct dp_vdev *)vdev);
  7353. return QDF_STATUS_SUCCESS;
  7354. }
  7355. /*
  7356. * dp_set_psoc_param: function to set parameters in psoc
  7357. * @cdp_soc : DP soc handle
  7358. * @param: parameter type to be set
  7359. * @val: value of parameter to be set
  7360. *
  7361. * return: QDF_STATUS
  7362. */
  7363. static QDF_STATUS
  7364. dp_set_psoc_param(struct cdp_soc_t *cdp_soc,
  7365. enum cdp_psoc_param_type param, cdp_config_param_type val)
  7366. {
  7367. struct dp_soc *soc = (struct dp_soc *)cdp_soc;
  7368. struct wlan_cfg_dp_soc_ctxt *wlan_cfg_ctx = soc->wlan_cfg_ctx;
  7369. switch (param) {
  7370. case CDP_ENABLE_RATE_STATS:
  7371. soc->wlanstats_enabled = val.cdp_psoc_param_en_rate_stats;
  7372. break;
  7373. case CDP_SET_NSS_CFG:
  7374. wlan_cfg_set_dp_soc_nss_cfg(wlan_cfg_ctx,
  7375. val.cdp_psoc_param_en_nss_cfg);
  7376. /*
  7377. * TODO: masked out based on the per offloaded radio
  7378. */
  7379. switch (val.cdp_psoc_param_en_nss_cfg) {
  7380. case dp_nss_cfg_default:
  7381. break;
  7382. case dp_nss_cfg_first_radio:
  7383. /*
  7384. * This configuration is valid for single band radio which
  7385. * is also NSS offload.
  7386. */
  7387. case dp_nss_cfg_dbdc:
  7388. case dp_nss_cfg_dbtc:
  7389. wlan_cfg_set_num_tx_desc_pool(wlan_cfg_ctx, 0);
  7390. wlan_cfg_set_num_tx_ext_desc_pool(wlan_cfg_ctx, 0);
  7391. wlan_cfg_set_num_tx_desc(wlan_cfg_ctx, 0);
  7392. wlan_cfg_set_num_tx_ext_desc(wlan_cfg_ctx, 0);
  7393. break;
  7394. default:
  7395. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7396. "Invalid offload config %d",
  7397. val.cdp_psoc_param_en_nss_cfg);
  7398. }
  7399. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  7400. FL("nss-wifi<0> nss config is enabled"));
  7401. break;
  7402. default:
  7403. break;
  7404. }
  7405. return QDF_STATUS_SUCCESS;
  7406. }
  7407. /*
  7408. * dp_get_psoc_param: function to get parameters in soc
  7409. * @cdp_soc : DP soc handle
  7410. * @param: parameter type to be set
  7411. * @val: address of buffer
  7412. *
  7413. * return: status
  7414. */
  7415. static QDF_STATUS dp_get_psoc_param(struct cdp_soc_t *cdp_soc,
  7416. enum cdp_psoc_param_type param,
  7417. cdp_config_param_type *val)
  7418. {
  7419. return QDF_STATUS_SUCCESS;
  7420. }
  7421. /**
  7422. * dp_peer_update_pkt_capture_params: Set Rx & Tx Capture flags for a peer
  7423. * @soc: DP_SOC handle
  7424. * @pdev_id: id of DP_PDEV handle
  7425. * @is_rx_pkt_cap_enable: enable/disable Rx packet capture in monitor mode
  7426. * @is_tx_pkt_cap_enable: enable/disable Tx packet capture in monitor mode
  7427. * @peer_mac: MAC address for which the above need to be enabled/disabled
  7428. *
  7429. * Return: Success if Rx & Tx capture is enabled for peer, false otherwise
  7430. */
  7431. QDF_STATUS
  7432. dp_peer_update_pkt_capture_params(ol_txrx_soc_handle soc,
  7433. uint8_t pdev_id,
  7434. bool is_rx_pkt_cap_enable,
  7435. bool is_tx_pkt_cap_enable,
  7436. uint8_t *peer_mac)
  7437. {
  7438. struct dp_peer *peer;
  7439. struct dp_pdev *pdev =
  7440. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  7441. pdev_id);
  7442. if (!pdev)
  7443. return QDF_STATUS_E_FAILURE;
  7444. peer = (struct dp_peer *)dp_find_peer_by_addr((struct cdp_pdev *)pdev,
  7445. peer_mac);
  7446. if (!peer) {
  7447. dp_err("Invalid Peer");
  7448. return QDF_STATUS_E_FAILURE;
  7449. }
  7450. dp_peer_set_rx_capture_enabled(peer, is_rx_pkt_cap_enable);
  7451. dp_peer_set_tx_capture_enabled(peer, is_tx_pkt_cap_enable);
  7452. return QDF_STATUS_SUCCESS;
  7453. }
  7454. /*
  7455. * dp_set_vdev_dscp_tid_map_wifi3(): Update Map ID selected for particular vdev
  7456. * @soc: DP_SOC handle
  7457. * @vdev_id: id of DP_VDEV handle
  7458. * @map_id:ID of map that needs to be updated
  7459. *
  7460. * Return: QDF_STATUS
  7461. */
  7462. static QDF_STATUS dp_set_vdev_dscp_tid_map_wifi3(ol_txrx_soc_handle soc,
  7463. uint8_t vdev_id,
  7464. uint8_t map_id)
  7465. {
  7466. struct dp_vdev *vdev =
  7467. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  7468. vdev_id);
  7469. if (vdev) {
  7470. vdev->dscp_tid_map_id = map_id;
  7471. return QDF_STATUS_SUCCESS;
  7472. }
  7473. return QDF_STATUS_E_FAILURE;
  7474. }
  7475. #ifdef DP_RATETABLE_SUPPORT
  7476. static int dp_txrx_get_ratekbps(int preamb, int mcs,
  7477. int htflag, int gintval)
  7478. {
  7479. uint32_t rix;
  7480. uint16_t ratecode;
  7481. return dp_getrateindex((uint32_t)gintval, (uint16_t)mcs, 1,
  7482. (uint8_t)preamb, 1, &rix, &ratecode);
  7483. }
  7484. #else
  7485. static int dp_txrx_get_ratekbps(int preamb, int mcs,
  7486. int htflag, int gintval)
  7487. {
  7488. return 0;
  7489. }
  7490. #endif
  7491. /* dp_txrx_get_pdev_stats - Returns cdp_pdev_stats
  7492. * @soc: DP soc handle
  7493. * @pdev_id: id of DP pdev handle
  7494. * @pdev_stats: buffer to copy to
  7495. *
  7496. * return : status success/failure
  7497. */
  7498. static QDF_STATUS
  7499. dp_txrx_get_pdev_stats(struct cdp_soc_t *soc, uint8_t pdev_id,
  7500. struct cdp_pdev_stats *pdev_stats)
  7501. {
  7502. struct dp_pdev *pdev =
  7503. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  7504. pdev_id);
  7505. if (!pdev)
  7506. return QDF_STATUS_E_FAILURE;
  7507. dp_aggregate_pdev_stats(pdev);
  7508. qdf_mem_copy(pdev_stats, &pdev->stats, sizeof(struct cdp_pdev_stats));
  7509. return QDF_STATUS_SUCCESS;
  7510. }
  7511. /* dp_txrx_update_vdev_me_stats(): Update vdev ME stats sent from CDP
  7512. * @vdev: DP vdev handle
  7513. * @buf: buffer containing specific stats structure
  7514. *
  7515. * Returns: void
  7516. */
  7517. static void dp_txrx_update_vdev_me_stats(struct dp_vdev *vdev,
  7518. void *buf)
  7519. {
  7520. struct cdp_tx_ingress_stats *host_stats = NULL;
  7521. if (!buf) {
  7522. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7523. "Invalid host stats buf");
  7524. return;
  7525. }
  7526. host_stats = (struct cdp_tx_ingress_stats *)buf;
  7527. DP_STATS_INC_PKT(vdev, tx_i.mcast_en.mcast_pkt,
  7528. host_stats->mcast_en.mcast_pkt.num,
  7529. host_stats->mcast_en.mcast_pkt.bytes);
  7530. DP_STATS_INC(vdev, tx_i.mcast_en.dropped_map_error,
  7531. host_stats->mcast_en.dropped_map_error);
  7532. DP_STATS_INC(vdev, tx_i.mcast_en.dropped_self_mac,
  7533. host_stats->mcast_en.dropped_self_mac);
  7534. DP_STATS_INC(vdev, tx_i.mcast_en.dropped_send_fail,
  7535. host_stats->mcast_en.dropped_send_fail);
  7536. DP_STATS_INC(vdev, tx_i.mcast_en.ucast,
  7537. host_stats->mcast_en.ucast);
  7538. DP_STATS_INC(vdev, tx_i.mcast_en.fail_seg_alloc,
  7539. host_stats->mcast_en.fail_seg_alloc);
  7540. DP_STATS_INC(vdev, tx_i.mcast_en.clone_fail,
  7541. host_stats->mcast_en.clone_fail);
  7542. }
  7543. /* dp_txrx_update_vdev_host_stats(): Update stats sent through CDP
  7544. * @soc: DP soc handle
  7545. * @vdev_id: id of DP vdev handle
  7546. * @buf: buffer containing specific stats structure
  7547. * @stats_id: stats type
  7548. *
  7549. * Returns: QDF_STATUS
  7550. */
  7551. static QDF_STATUS dp_txrx_update_vdev_host_stats(struct cdp_soc_t *soc,
  7552. uint8_t vdev_id,
  7553. void *buf,
  7554. uint16_t stats_id)
  7555. {
  7556. struct dp_vdev *vdev =
  7557. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  7558. vdev_id);
  7559. if (!vdev) {
  7560. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7561. "Invalid vdev handle");
  7562. return QDF_STATUS_E_FAILURE;
  7563. }
  7564. switch (stats_id) {
  7565. case DP_VDEV_STATS_PKT_CNT_ONLY:
  7566. break;
  7567. case DP_VDEV_STATS_TX_ME:
  7568. dp_txrx_update_vdev_me_stats(vdev, buf);
  7569. break;
  7570. default:
  7571. qdf_info("Invalid stats_id %d", stats_id);
  7572. break;
  7573. }
  7574. return QDF_STATUS_SUCCESS;
  7575. }
  7576. /* dp_txrx_get_peer_stats - will return cdp_peer_stats
  7577. * @soc: soc handle
  7578. * @vdev_id: id of vdev handle
  7579. * @peer_mac: mac of DP_PEER handle
  7580. * @peer_stats: buffer to copy to
  7581. * return : status success/failure
  7582. */
  7583. static QDF_STATUS
  7584. dp_txrx_get_peer_stats(struct cdp_soc_t *soc, uint8_t vdev_id,
  7585. uint8_t *peer_mac, struct cdp_peer_stats *peer_stats)
  7586. {
  7587. QDF_STATUS status = QDF_STATUS_SUCCESS;
  7588. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)soc,
  7589. peer_mac, 0, vdev_id);
  7590. if (!peer || peer->delete_in_progress) {
  7591. status = QDF_STATUS_E_FAILURE;
  7592. } else
  7593. qdf_mem_copy(peer_stats, &peer->stats,
  7594. sizeof(struct cdp_peer_stats));
  7595. if (peer)
  7596. dp_peer_unref_delete(peer);
  7597. return status;
  7598. }
  7599. /* dp_txrx_get_peer_stats_param - will return specified cdp_peer_stats
  7600. * @param soc - soc handle
  7601. * @param vdev_id - vdev_id of vdev object
  7602. * @param peer_mac - mac address of the peer
  7603. * @param type - enum of required stats
  7604. * @param buf - buffer to hold the value
  7605. * return : status success/failure
  7606. */
  7607. static QDF_STATUS
  7608. dp_txrx_get_peer_stats_param(struct cdp_soc_t *soc, uint8_t vdev_id,
  7609. uint8_t *peer_mac, enum cdp_peer_stats_type type,
  7610. cdp_peer_stats_param_t *buf)
  7611. {
  7612. QDF_STATUS ret = QDF_STATUS_SUCCESS;
  7613. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)soc,
  7614. peer_mac, 0, vdev_id);
  7615. if (!peer || peer->delete_in_progress) {
  7616. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7617. "Invalid Peer for Mac %pM", peer_mac);
  7618. ret = QDF_STATUS_E_FAILURE;
  7619. } else if (type < cdp_peer_stats_max) {
  7620. switch (type) {
  7621. case cdp_peer_tx_ucast:
  7622. buf->tx_ucast = peer->stats.tx.ucast;
  7623. break;
  7624. case cdp_peer_tx_mcast:
  7625. buf->tx_mcast = peer->stats.tx.mcast;
  7626. break;
  7627. case cdp_peer_tx_rate:
  7628. buf->tx_rate = peer->stats.tx.tx_rate;
  7629. break;
  7630. case cdp_peer_tx_last_tx_rate:
  7631. buf->last_tx_rate = peer->stats.tx.last_tx_rate;
  7632. break;
  7633. case cdp_peer_tx_inactive_time:
  7634. buf->tx_inactive_time = peer->stats.tx.inactive_time;
  7635. break;
  7636. case cdp_peer_tx_ratecode:
  7637. buf->tx_ratecode = peer->stats.tx.tx_ratecode;
  7638. break;
  7639. case cdp_peer_tx_flags:
  7640. buf->tx_flags = peer->stats.tx.tx_flags;
  7641. break;
  7642. case cdp_peer_tx_power:
  7643. buf->tx_power = peer->stats.tx.tx_power;
  7644. break;
  7645. case cdp_peer_rx_rate:
  7646. buf->rx_rate = peer->stats.rx.rx_rate;
  7647. break;
  7648. case cdp_peer_rx_last_rx_rate:
  7649. buf->last_rx_rate = peer->stats.rx.last_rx_rate;
  7650. break;
  7651. case cdp_peer_rx_ratecode:
  7652. buf->rx_ratecode = peer->stats.rx.rx_ratecode;
  7653. break;
  7654. case cdp_peer_rx_ucast:
  7655. buf->rx_ucast = peer->stats.rx.unicast;
  7656. break;
  7657. case cdp_peer_rx_flags:
  7658. buf->rx_flags = peer->stats.rx.rx_flags;
  7659. break;
  7660. case cdp_peer_rx_avg_rssi:
  7661. buf->rx_avg_rssi = peer->stats.rx.avg_rssi;
  7662. break;
  7663. default:
  7664. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7665. "Invalid value");
  7666. ret = QDF_STATUS_E_FAILURE;
  7667. break;
  7668. }
  7669. } else {
  7670. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7671. "Invalid value");
  7672. ret = QDF_STATUS_E_FAILURE;
  7673. }
  7674. if (peer)
  7675. dp_peer_unref_delete(peer);
  7676. return ret;
  7677. }
  7678. /* dp_txrx_reset_peer_stats - reset cdp_peer_stats for particular peer
  7679. * @soc: soc handle
  7680. * @vdev_id: id of vdev handle
  7681. * @peer_mac: mac of DP_PEER handle
  7682. *
  7683. * return : QDF_STATUS
  7684. */
  7685. static QDF_STATUS
  7686. dp_txrx_reset_peer_stats(struct cdp_soc_t *soc, uint8_t vdev_id,
  7687. uint8_t *peer_mac)
  7688. {
  7689. QDF_STATUS status = QDF_STATUS_SUCCESS;
  7690. struct dp_peer *peer = dp_peer_find_hash_find((struct dp_soc *)soc,
  7691. peer_mac, 0, vdev_id);
  7692. if (!peer || peer->delete_in_progress) {
  7693. status = QDF_STATUS_E_FAILURE;
  7694. goto fail;
  7695. }
  7696. qdf_mem_zero(&peer->stats, sizeof(peer->stats));
  7697. fail:
  7698. if (peer)
  7699. dp_peer_unref_delete(peer);
  7700. return status;
  7701. }
  7702. /* dp_txrx_get_vdev_stats - Update buffer with cdp_vdev_stats
  7703. * @vdev_handle: DP_VDEV handle
  7704. * @buf: buffer for vdev stats
  7705. *
  7706. * return : int
  7707. */
  7708. static int dp_txrx_get_vdev_stats(struct cdp_soc_t *soc, uint8_t vdev_id,
  7709. void *buf, bool is_aggregate)
  7710. {
  7711. struct cdp_vdev_stats *vdev_stats;
  7712. struct dp_pdev *pdev;
  7713. struct dp_vdev *vdev =
  7714. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  7715. vdev_id);
  7716. if (!vdev)
  7717. return 1;
  7718. pdev = vdev->pdev;
  7719. if (!pdev)
  7720. return 1;
  7721. vdev_stats = (struct cdp_vdev_stats *)buf;
  7722. if (is_aggregate) {
  7723. qdf_spin_lock_bh(&((struct dp_soc *)soc)->peer_ref_mutex);
  7724. dp_aggregate_vdev_stats(vdev, buf);
  7725. qdf_spin_unlock_bh(&((struct dp_soc *)soc)->peer_ref_mutex);
  7726. } else {
  7727. qdf_mem_copy(vdev_stats, &vdev->stats, sizeof(vdev->stats));
  7728. }
  7729. return 0;
  7730. }
  7731. /*
  7732. * dp_get_total_per(): get total per
  7733. * @soc: DP soc handle
  7734. * @pdev_id: id of DP_PDEV handle
  7735. *
  7736. * Return: % error rate using retries per packet and success packets
  7737. */
  7738. static int dp_get_total_per(struct cdp_soc_t *soc, uint8_t pdev_id)
  7739. {
  7740. struct dp_pdev *pdev =
  7741. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  7742. pdev_id);
  7743. if (!pdev)
  7744. return 0;
  7745. dp_aggregate_pdev_stats(pdev);
  7746. if ((pdev->stats.tx.tx_success.num + pdev->stats.tx.retries) == 0)
  7747. return 0;
  7748. return ((pdev->stats.tx.retries * 100) /
  7749. ((pdev->stats.tx.tx_success.num) + (pdev->stats.tx.retries)));
  7750. }
  7751. /*
  7752. * dp_txrx_stats_publish(): publish pdev stats into a buffer
  7753. * @soc: DP soc handle
  7754. * @pdev_id: id of DP_PDEV handle
  7755. * @buf: to hold pdev_stats
  7756. *
  7757. * Return: int
  7758. */
  7759. static int
  7760. dp_txrx_stats_publish(struct cdp_soc_t *soc, uint8_t pdev_id,
  7761. struct cdp_stats_extd *buf)
  7762. {
  7763. struct cdp_txrx_stats_req req = {0,};
  7764. struct dp_pdev *pdev =
  7765. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  7766. pdev_id);
  7767. if (!pdev)
  7768. return TXRX_STATS_LEVEL_OFF;
  7769. dp_aggregate_pdev_stats(pdev);
  7770. req.stats = (enum cdp_stats)HTT_DBG_EXT_STATS_PDEV_TX;
  7771. req.cookie_val = 1;
  7772. dp_h2t_ext_stats_msg_send(pdev, req.stats, req.param0,
  7773. req.param1, req.param2, req.param3, 0,
  7774. req.cookie_val, 0);
  7775. msleep(DP_MAX_SLEEP_TIME);
  7776. req.stats = (enum cdp_stats)HTT_DBG_EXT_STATS_PDEV_RX;
  7777. req.cookie_val = 1;
  7778. dp_h2t_ext_stats_msg_send(pdev, req.stats, req.param0,
  7779. req.param1, req.param2, req.param3, 0,
  7780. req.cookie_val, 0);
  7781. msleep(DP_MAX_SLEEP_TIME);
  7782. qdf_mem_copy(buf, &pdev->stats, sizeof(struct cdp_stats_extd));
  7783. return TXRX_STATS_LEVEL;
  7784. }
  7785. /**
  7786. * dp_set_pdev_dscp_tid_map_wifi3(): update dscp tid map in pdev
  7787. * @soc: soc handle
  7788. * @pdev_id: id of DP_PDEV handle
  7789. * @map_id: ID of map that needs to be updated
  7790. * @tos: index value in map
  7791. * @tid: tid value passed by the user
  7792. *
  7793. * Return: QDF_STATUS
  7794. */
  7795. static QDF_STATUS
  7796. dp_set_pdev_dscp_tid_map_wifi3(struct cdp_soc_t *soc_handle,
  7797. uint8_t pdev_id,
  7798. uint8_t map_id,
  7799. uint8_t tos, uint8_t tid)
  7800. {
  7801. uint8_t dscp;
  7802. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  7803. struct dp_pdev *pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  7804. if (!pdev)
  7805. return QDF_STATUS_E_FAILURE;
  7806. dscp = (tos >> DP_IP_DSCP_SHIFT) & DP_IP_DSCP_MASK;
  7807. pdev->dscp_tid_map[map_id][dscp] = tid;
  7808. if (map_id < soc->num_hw_dscp_tid_map)
  7809. hal_tx_update_dscp_tid(soc->hal_soc, tid,
  7810. map_id, dscp);
  7811. else
  7812. return QDF_STATUS_E_FAILURE;
  7813. return QDF_STATUS_SUCCESS;
  7814. }
  7815. /**
  7816. * dp_fw_stats_process(): Process TxRX FW stats request
  7817. * @vdev_handle: DP VDEV handle
  7818. * @req: stats request
  7819. *
  7820. * return: int
  7821. */
  7822. static int dp_fw_stats_process(struct dp_vdev *vdev,
  7823. struct cdp_txrx_stats_req *req)
  7824. {
  7825. struct dp_pdev *pdev = NULL;
  7826. uint32_t stats = req->stats;
  7827. uint8_t mac_id = req->mac_id;
  7828. if (!vdev) {
  7829. DP_TRACE(NONE, "VDEV not found");
  7830. return 1;
  7831. }
  7832. pdev = vdev->pdev;
  7833. /*
  7834. * For HTT_DBG_EXT_STATS_RESET command, FW need to config
  7835. * from param0 to param3 according to below rule:
  7836. *
  7837. * PARAM:
  7838. * - config_param0 : start_offset (stats type)
  7839. * - config_param1 : stats bmask from start offset
  7840. * - config_param2 : stats bmask from start offset + 32
  7841. * - config_param3 : stats bmask from start offset + 64
  7842. */
  7843. if (req->stats == CDP_TXRX_STATS_0) {
  7844. req->param0 = HTT_DBG_EXT_STATS_PDEV_TX;
  7845. req->param1 = 0xFFFFFFFF;
  7846. req->param2 = 0xFFFFFFFF;
  7847. req->param3 = 0xFFFFFFFF;
  7848. } else if (req->stats == (uint8_t)HTT_DBG_EXT_STATS_PDEV_TX_MU) {
  7849. req->param0 = HTT_DBG_EXT_STATS_SET_VDEV_MASK(vdev->vdev_id);
  7850. }
  7851. return dp_h2t_ext_stats_msg_send(pdev, stats, req->param0,
  7852. req->param1, req->param2, req->param3,
  7853. 0, 0, mac_id);
  7854. }
  7855. /**
  7856. * dp_txrx_stats_request - function to map to firmware and host stats
  7857. * @soc: soc handle
  7858. * @vdev_id: virtual device ID
  7859. * @req: stats request
  7860. *
  7861. * Return: QDF_STATUS
  7862. */
  7863. static
  7864. QDF_STATUS dp_txrx_stats_request(struct cdp_soc_t *soc_handle,
  7865. uint8_t vdev_id,
  7866. struct cdp_txrx_stats_req *req)
  7867. {
  7868. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_handle);
  7869. int host_stats;
  7870. int fw_stats;
  7871. enum cdp_stats stats;
  7872. int num_stats;
  7873. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc,
  7874. vdev_id);
  7875. if (!vdev || !req) {
  7876. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7877. "Invalid vdev/req instance");
  7878. return QDF_STATUS_E_INVAL;
  7879. }
  7880. if (req->mac_id >= WLAN_CFG_MAC_PER_TARGET) {
  7881. dp_err("Invalid mac id request");
  7882. return QDF_STATUS_E_INVAL;
  7883. }
  7884. stats = req->stats;
  7885. if (stats >= CDP_TXRX_MAX_STATS)
  7886. return QDF_STATUS_E_INVAL;
  7887. /*
  7888. * DP_CURR_FW_STATS_AVAIL: no of FW stats currently available
  7889. * has to be updated if new FW HTT stats added
  7890. */
  7891. if (stats > CDP_TXRX_STATS_HTT_MAX)
  7892. stats = stats + DP_CURR_FW_STATS_AVAIL - DP_HTT_DBG_EXT_STATS_MAX;
  7893. num_stats = QDF_ARRAY_SIZE(dp_stats_mapping_table);
  7894. if (stats >= num_stats) {
  7895. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7896. "%s: Invalid stats option: %d", __func__, stats);
  7897. return QDF_STATUS_E_INVAL;
  7898. }
  7899. req->stats = stats;
  7900. fw_stats = dp_stats_mapping_table[stats][STATS_FW];
  7901. host_stats = dp_stats_mapping_table[stats][STATS_HOST];
  7902. dp_info("stats: %u fw_stats_type: %d host_stats: %d",
  7903. stats, fw_stats, host_stats);
  7904. if (fw_stats != TXRX_FW_STATS_INVALID) {
  7905. /* update request with FW stats type */
  7906. req->stats = fw_stats;
  7907. return dp_fw_stats_process(vdev, req);
  7908. }
  7909. if ((host_stats != TXRX_HOST_STATS_INVALID) &&
  7910. (host_stats <= TXRX_HOST_STATS_MAX))
  7911. return dp_print_host_stats(vdev, req);
  7912. else
  7913. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  7914. "Wrong Input for TxRx Stats");
  7915. return QDF_STATUS_SUCCESS;
  7916. }
  7917. /*
  7918. * dp_txrx_dump_stats() - Dump statistics
  7919. * @value - Statistics option
  7920. */
  7921. static QDF_STATUS dp_txrx_dump_stats(struct cdp_soc_t *psoc, uint16_t value,
  7922. enum qdf_stats_verbosity_level level)
  7923. {
  7924. struct dp_soc *soc =
  7925. (struct dp_soc *)psoc;
  7926. QDF_STATUS status = QDF_STATUS_SUCCESS;
  7927. if (!soc) {
  7928. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  7929. "%s: soc is NULL", __func__);
  7930. return QDF_STATUS_E_INVAL;
  7931. }
  7932. switch (value) {
  7933. case CDP_TXRX_PATH_STATS:
  7934. dp_txrx_path_stats(soc);
  7935. dp_print_soc_interrupt_stats(soc);
  7936. break;
  7937. case CDP_RX_RING_STATS:
  7938. dp_print_per_ring_stats(soc);
  7939. break;
  7940. case CDP_TXRX_TSO_STATS:
  7941. dp_print_tso_stats(soc, level);
  7942. break;
  7943. case CDP_DUMP_TX_FLOW_POOL_INFO:
  7944. if (level == QDF_STATS_VERBOSITY_LEVEL_HIGH)
  7945. cdp_dump_flow_pool_info((struct cdp_soc_t *)soc);
  7946. break;
  7947. case CDP_DP_NAPI_STATS:
  7948. dp_print_napi_stats(soc);
  7949. break;
  7950. case CDP_TXRX_DESC_STATS:
  7951. /* TODO: NOT IMPLEMENTED */
  7952. break;
  7953. default:
  7954. status = QDF_STATUS_E_INVAL;
  7955. break;
  7956. }
  7957. return status;
  7958. }
  7959. /**
  7960. * dp_txrx_clear_dump_stats() - clear dumpStats
  7961. * @soc- soc handle
  7962. * @value - stats option
  7963. *
  7964. * Return: 0 - Success, non-zero - failure
  7965. */
  7966. static
  7967. QDF_STATUS dp_txrx_clear_dump_stats(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  7968. uint8_t value)
  7969. {
  7970. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  7971. QDF_STATUS status = QDF_STATUS_SUCCESS;
  7972. if (!soc) {
  7973. dp_err("%s: soc is NULL", __func__);
  7974. return QDF_STATUS_E_INVAL;
  7975. }
  7976. switch (value) {
  7977. case CDP_TXRX_TSO_STATS:
  7978. dp_txrx_clear_tso_stats(soc);
  7979. break;
  7980. default:
  7981. status = QDF_STATUS_E_INVAL;
  7982. break;
  7983. }
  7984. return status;
  7985. }
  7986. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  7987. /**
  7988. * dp_update_flow_control_parameters() - API to store datapath
  7989. * config parameters
  7990. * @soc: soc handle
  7991. * @cfg: ini parameter handle
  7992. *
  7993. * Return: void
  7994. */
  7995. static inline
  7996. void dp_update_flow_control_parameters(struct dp_soc *soc,
  7997. struct cdp_config_params *params)
  7998. {
  7999. soc->wlan_cfg_ctx->tx_flow_stop_queue_threshold =
  8000. params->tx_flow_stop_queue_threshold;
  8001. soc->wlan_cfg_ctx->tx_flow_start_queue_offset =
  8002. params->tx_flow_start_queue_offset;
  8003. }
  8004. #else
  8005. static inline
  8006. void dp_update_flow_control_parameters(struct dp_soc *soc,
  8007. struct cdp_config_params *params)
  8008. {
  8009. }
  8010. #endif
  8011. #ifdef WLAN_FEATURE_RX_SOFTIRQ_TIME_LIMIT
  8012. /* Max packet limit for TX Comp packet loop (dp_tx_comp_handler) */
  8013. #define DP_TX_COMP_LOOP_PKT_LIMIT_MAX 1024
  8014. /* Max packet limit for RX REAP Loop (dp_rx_process) */
  8015. #define DP_RX_REAP_LOOP_PKT_LIMIT_MAX 1024
  8016. static
  8017. void dp_update_rx_soft_irq_limit_params(struct dp_soc *soc,
  8018. struct cdp_config_params *params)
  8019. {
  8020. soc->wlan_cfg_ctx->tx_comp_loop_pkt_limit =
  8021. params->tx_comp_loop_pkt_limit;
  8022. if (params->tx_comp_loop_pkt_limit < DP_TX_COMP_LOOP_PKT_LIMIT_MAX)
  8023. soc->wlan_cfg_ctx->tx_comp_enable_eol_data_check = true;
  8024. else
  8025. soc->wlan_cfg_ctx->tx_comp_enable_eol_data_check = false;
  8026. soc->wlan_cfg_ctx->rx_reap_loop_pkt_limit =
  8027. params->rx_reap_loop_pkt_limit;
  8028. if (params->rx_reap_loop_pkt_limit < DP_RX_REAP_LOOP_PKT_LIMIT_MAX)
  8029. soc->wlan_cfg_ctx->rx_enable_eol_data_check = true;
  8030. else
  8031. soc->wlan_cfg_ctx->rx_enable_eol_data_check = false;
  8032. soc->wlan_cfg_ctx->rx_hp_oos_update_limit =
  8033. params->rx_hp_oos_update_limit;
  8034. 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",
  8035. soc->wlan_cfg_ctx->tx_comp_loop_pkt_limit,
  8036. soc->wlan_cfg_ctx->tx_comp_enable_eol_data_check,
  8037. soc->wlan_cfg_ctx->rx_reap_loop_pkt_limit,
  8038. soc->wlan_cfg_ctx->rx_enable_eol_data_check,
  8039. soc->wlan_cfg_ctx->rx_hp_oos_update_limit);
  8040. }
  8041. #else
  8042. static inline
  8043. void dp_update_rx_soft_irq_limit_params(struct dp_soc *soc,
  8044. struct cdp_config_params *params)
  8045. { }
  8046. #endif /* WLAN_FEATURE_RX_SOFTIRQ_TIME_LIMIT */
  8047. /**
  8048. * dp_update_config_parameters() - API to store datapath
  8049. * config parameters
  8050. * @soc: soc handle
  8051. * @cfg: ini parameter handle
  8052. *
  8053. * Return: status
  8054. */
  8055. static
  8056. QDF_STATUS dp_update_config_parameters(struct cdp_soc *psoc,
  8057. struct cdp_config_params *params)
  8058. {
  8059. struct dp_soc *soc = (struct dp_soc *)psoc;
  8060. if (!(soc)) {
  8061. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  8062. "%s: Invalid handle", __func__);
  8063. return QDF_STATUS_E_INVAL;
  8064. }
  8065. soc->wlan_cfg_ctx->tso_enabled = params->tso_enable;
  8066. soc->wlan_cfg_ctx->lro_enabled = params->lro_enable;
  8067. soc->wlan_cfg_ctx->rx_hash = params->flow_steering_enable;
  8068. soc->wlan_cfg_ctx->tcp_udp_checksumoffload =
  8069. params->tcp_udp_checksumoffload;
  8070. soc->wlan_cfg_ctx->napi_enabled = params->napi_enable;
  8071. soc->wlan_cfg_ctx->ipa_enabled = params->ipa_enable;
  8072. soc->wlan_cfg_ctx->gro_enabled = params->gro_enable;
  8073. dp_update_rx_soft_irq_limit_params(soc, params);
  8074. dp_update_flow_control_parameters(soc, params);
  8075. return QDF_STATUS_SUCCESS;
  8076. }
  8077. static struct cdp_wds_ops dp_ops_wds = {
  8078. .vdev_set_wds = dp_vdev_set_wds,
  8079. #ifdef WDS_VENDOR_EXTENSION
  8080. .txrx_set_wds_rx_policy = dp_txrx_set_wds_rx_policy,
  8081. .txrx_wds_peer_tx_policy_update = dp_txrx_peer_wds_tx_policy_update,
  8082. #endif
  8083. };
  8084. /*
  8085. * dp_txrx_data_tx_cb_set(): set the callback for non standard tx
  8086. * @soc_hdl - datapath soc handle
  8087. * @vdev_id - virtual interface id
  8088. * @callback - callback function
  8089. * @ctxt: callback context
  8090. *
  8091. */
  8092. static void
  8093. dp_txrx_data_tx_cb_set(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  8094. ol_txrx_data_tx_cb callback, void *ctxt)
  8095. {
  8096. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  8097. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  8098. if (!vdev)
  8099. return;
  8100. vdev->tx_non_std_data_callback.func = callback;
  8101. vdev->tx_non_std_data_callback.ctxt = ctxt;
  8102. }
  8103. /**
  8104. * dp_pdev_get_dp_txrx_handle() - get dp handle from pdev
  8105. * @soc: datapath soc handle
  8106. * @pdev_id: id of datapath pdev handle
  8107. *
  8108. * Return: opaque pointer to dp txrx handle
  8109. */
  8110. static void *dp_pdev_get_dp_txrx_handle(struct cdp_soc_t *soc, uint8_t pdev_id)
  8111. {
  8112. struct dp_pdev *pdev =
  8113. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  8114. pdev_id);
  8115. if (qdf_unlikely(!pdev))
  8116. return NULL;
  8117. return pdev->dp_txrx_handle;
  8118. }
  8119. /**
  8120. * dp_pdev_set_dp_txrx_handle() - set dp handle in pdev
  8121. * @soc: datapath soc handle
  8122. * @pdev_id: id of datapath pdev handle
  8123. * @dp_txrx_hdl: opaque pointer for dp_txrx_handle
  8124. *
  8125. * Return: void
  8126. */
  8127. static void
  8128. dp_pdev_set_dp_txrx_handle(struct cdp_soc_t *soc, uint8_t pdev_id,
  8129. void *dp_txrx_hdl)
  8130. {
  8131. struct dp_pdev *pdev =
  8132. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  8133. pdev_id);
  8134. if (!pdev)
  8135. return;
  8136. pdev->dp_txrx_handle = dp_txrx_hdl;
  8137. }
  8138. /**
  8139. * dp_vdev_get_dp_ext_handle() - get dp handle from vdev
  8140. * @soc: datapath soc handle
  8141. * @vdev_id: vdev id
  8142. *
  8143. * Return: opaque pointer to dp txrx handle
  8144. */
  8145. static void *dp_vdev_get_dp_ext_handle(ol_txrx_soc_handle soc, uint8_t vdev_id)
  8146. {
  8147. struct dp_vdev *vdev =
  8148. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  8149. vdev_id);
  8150. if (!vdev)
  8151. return NULL;
  8152. return vdev->vdev_dp_ext_handle;
  8153. }
  8154. /**
  8155. * dp_vdev_set_dp_ext_handle() - set dp handle in vdev
  8156. * @soc: datapath soc handle
  8157. * @vdev_id: vdev id
  8158. * @size: size of advance dp handle
  8159. *
  8160. * Return: QDF_STATUS
  8161. */
  8162. static QDF_STATUS
  8163. dp_vdev_set_dp_ext_handle(ol_txrx_soc_handle soc, uint8_t vdev_id,
  8164. uint16_t size)
  8165. {
  8166. struct dp_vdev *vdev =
  8167. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  8168. vdev_id);
  8169. void *dp_ext_handle;
  8170. if (!vdev)
  8171. return QDF_STATUS_E_FAILURE;
  8172. dp_ext_handle = qdf_mem_malloc(size);
  8173. if (!dp_ext_handle)
  8174. return QDF_STATUS_E_FAILURE;
  8175. vdev->vdev_dp_ext_handle = dp_ext_handle;
  8176. return QDF_STATUS_SUCCESS;
  8177. }
  8178. /**
  8179. * dp_soc_get_dp_txrx_handle() - get context for external-dp from dp soc
  8180. * @soc_handle: datapath soc handle
  8181. *
  8182. * Return: opaque pointer to external dp (non-core DP)
  8183. */
  8184. static void *dp_soc_get_dp_txrx_handle(struct cdp_soc *soc_handle)
  8185. {
  8186. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  8187. return soc->external_txrx_handle;
  8188. }
  8189. /**
  8190. * dp_soc_set_dp_txrx_handle() - set external dp handle in soc
  8191. * @soc_handle: datapath soc handle
  8192. * @txrx_handle: opaque pointer to external dp (non-core DP)
  8193. *
  8194. * Return: void
  8195. */
  8196. static void
  8197. dp_soc_set_dp_txrx_handle(struct cdp_soc *soc_handle, void *txrx_handle)
  8198. {
  8199. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  8200. soc->external_txrx_handle = txrx_handle;
  8201. }
  8202. /**
  8203. * dp_soc_map_pdev_to_lmac() - Save pdev_id to lmac_id mapping
  8204. * @soc_hdl: datapath soc handle
  8205. * @pdev_id: id of the datapath pdev handle
  8206. * @lmac_id: lmac id
  8207. *
  8208. * Return: QDF_STATUS
  8209. */
  8210. static QDF_STATUS
  8211. dp_soc_map_pdev_to_lmac
  8212. (struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  8213. uint32_t lmac_id)
  8214. {
  8215. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  8216. wlan_cfg_set_hw_mac_idx(soc->wlan_cfg_ctx,
  8217. pdev_id,
  8218. lmac_id);
  8219. /*Set host PDEV ID for lmac_id*/
  8220. wlan_cfg_set_pdev_idx(soc->wlan_cfg_ctx,
  8221. pdev_id,
  8222. lmac_id);
  8223. return QDF_STATUS_SUCCESS;
  8224. }
  8225. /**
  8226. * dp_soc_handle_pdev_mode_change() - Update pdev to lmac mapping
  8227. * @soc_hdl: datapath soc handle
  8228. * @pdev_id: id of the datapath pdev handle
  8229. * @lmac_id: lmac id
  8230. *
  8231. * In the event of a dynamic mode change, update the pdev to lmac mapping
  8232. *
  8233. * Return: QDF_STATUS
  8234. */
  8235. static QDF_STATUS
  8236. dp_soc_handle_pdev_mode_change
  8237. (struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  8238. uint32_t lmac_id)
  8239. {
  8240. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  8241. struct dp_vdev *vdev = NULL;
  8242. uint8_t hw_pdev_id, mac_id;
  8243. struct dp_pdev *pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc,
  8244. pdev_id);
  8245. int nss_config = wlan_cfg_get_dp_soc_nss_cfg(soc->wlan_cfg_ctx);
  8246. if (qdf_unlikely(!pdev))
  8247. return QDF_STATUS_E_FAILURE;
  8248. pdev->lmac_id = lmac_id;
  8249. dp_info(" mode change %d %d\n", pdev->pdev_id, pdev->lmac_id);
  8250. /*Set host PDEV ID for lmac_id*/
  8251. wlan_cfg_set_pdev_idx(soc->wlan_cfg_ctx,
  8252. pdev->pdev_id,
  8253. lmac_id);
  8254. hw_pdev_id =
  8255. dp_get_target_pdev_id_for_host_pdev_id(soc,
  8256. pdev->pdev_id);
  8257. /*
  8258. * When NSS offload is enabled, send pdev_id->lmac_id
  8259. * and pdev_id to hw_pdev_id to NSS FW
  8260. */
  8261. if (nss_config) {
  8262. mac_id = pdev->lmac_id;
  8263. if (soc->cdp_soc.ol_ops->pdev_update_lmac_n_target_pdev_id)
  8264. soc->cdp_soc.ol_ops->
  8265. pdev_update_lmac_n_target_pdev_id(
  8266. soc->ctrl_psoc,
  8267. &pdev_id, &mac_id, &hw_pdev_id);
  8268. }
  8269. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  8270. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  8271. HTT_TX_TCL_METADATA_PDEV_ID_SET(vdev->htt_tcl_metadata,
  8272. hw_pdev_id);
  8273. }
  8274. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  8275. return QDF_STATUS_SUCCESS;
  8276. }
  8277. /**
  8278. * dp_soc_set_pdev_status_down() - set pdev down/up status
  8279. * @soc: datapath soc handle
  8280. * @pdev_id: id of datapath pdev handle
  8281. * @is_pdev_down: pdev down/up status
  8282. *
  8283. * Return: QDF_STATUS
  8284. */
  8285. static QDF_STATUS
  8286. dp_soc_set_pdev_status_down(struct cdp_soc_t *soc, uint8_t pdev_id,
  8287. bool is_pdev_down)
  8288. {
  8289. struct dp_pdev *pdev =
  8290. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  8291. pdev_id);
  8292. if (!pdev)
  8293. return QDF_STATUS_E_FAILURE;
  8294. pdev->is_pdev_down = is_pdev_down;
  8295. return QDF_STATUS_SUCCESS;
  8296. }
  8297. /**
  8298. * dp_get_cfg_capabilities() - get dp capabilities
  8299. * @soc_handle: datapath soc handle
  8300. * @dp_caps: enum for dp capabilities
  8301. *
  8302. * Return: bool to determine if dp caps is enabled
  8303. */
  8304. static bool
  8305. dp_get_cfg_capabilities(struct cdp_soc_t *soc_handle,
  8306. enum cdp_capabilities dp_caps)
  8307. {
  8308. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  8309. return wlan_cfg_get_dp_caps(soc->wlan_cfg_ctx, dp_caps);
  8310. }
  8311. #ifdef FEATURE_AST
  8312. static QDF_STATUS
  8313. dp_peer_teardown_wifi3(struct cdp_soc_t *soc_hdl, uint8_t vdev_id,
  8314. uint8_t *peer_mac)
  8315. {
  8316. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  8317. QDF_STATUS status = QDF_STATUS_SUCCESS;
  8318. struct dp_peer *peer =
  8319. dp_peer_find_hash_find(soc, peer_mac, 0, vdev_id);
  8320. /* Peer can be null for monitor vap mac address */
  8321. if (!peer) {
  8322. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  8323. "%s: Invalid peer\n", __func__);
  8324. return QDF_STATUS_E_FAILURE;
  8325. }
  8326. /*
  8327. * For BSS peer, new peer is not created on alloc_node if the
  8328. * peer with same address already exists , instead refcnt is
  8329. * increased for existing peer. Correspondingly in delete path,
  8330. * only refcnt is decreased; and peer is only deleted , when all
  8331. * references are deleted. So delete_in_progress should not be set
  8332. * for bss_peer, unless only 3 reference remains (peer map reference,
  8333. * peer hash table reference and above local reference).
  8334. */
  8335. if (peer->bss_peer && (qdf_atomic_read(&peer->ref_cnt) > 3)) {
  8336. status = QDF_STATUS_E_FAILURE;
  8337. goto fail;
  8338. }
  8339. qdf_spin_lock_bh(&soc->ast_lock);
  8340. peer->delete_in_progress = true;
  8341. dp_peer_delete_ast_entries(soc, peer);
  8342. qdf_spin_unlock_bh(&soc->ast_lock);
  8343. fail:
  8344. if (peer)
  8345. dp_peer_unref_delete(peer);
  8346. return status;
  8347. }
  8348. #endif
  8349. #ifdef ATH_SUPPORT_NAC_RSSI
  8350. /**
  8351. * dp_vdev_get_neighbour_rssi(): Store RSSI for configured NAC
  8352. * @soc_hdl: DP soc handle
  8353. * @vdev_id: id of DP vdev handle
  8354. * @mac_addr: neighbour mac
  8355. * @rssi: rssi value
  8356. *
  8357. * Return: 0 for success. nonzero for failure.
  8358. */
  8359. static QDF_STATUS dp_vdev_get_neighbour_rssi(struct cdp_soc_t *soc,
  8360. uint8_t vdev_id,
  8361. char *mac_addr,
  8362. uint8_t *rssi)
  8363. {
  8364. struct dp_vdev *vdev =
  8365. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  8366. vdev_id);
  8367. struct dp_pdev *pdev;
  8368. struct dp_neighbour_peer *peer = NULL;
  8369. QDF_STATUS status = QDF_STATUS_E_FAILURE;
  8370. if (!vdev)
  8371. return status;
  8372. pdev = vdev->pdev;
  8373. *rssi = 0;
  8374. qdf_spin_lock_bh(&pdev->neighbour_peer_mutex);
  8375. TAILQ_FOREACH(peer, &pdev->neighbour_peers_list,
  8376. neighbour_peer_list_elem) {
  8377. if (qdf_mem_cmp(&peer->neighbour_peers_macaddr.raw[0],
  8378. mac_addr, QDF_MAC_ADDR_SIZE) == 0) {
  8379. *rssi = peer->rssi;
  8380. status = QDF_STATUS_SUCCESS;
  8381. break;
  8382. }
  8383. }
  8384. qdf_spin_unlock_bh(&pdev->neighbour_peer_mutex);
  8385. return status;
  8386. }
  8387. static QDF_STATUS
  8388. dp_config_for_nac_rssi(struct cdp_soc_t *cdp_soc,
  8389. uint8_t vdev_id,
  8390. enum cdp_nac_param_cmd cmd, char *bssid,
  8391. char *client_macaddr,
  8392. uint8_t chan_num)
  8393. {
  8394. struct dp_soc *soc = (struct dp_soc *)cdp_soc;
  8395. struct dp_vdev *vdev =
  8396. dp_get_vdev_from_soc_vdev_id_wifi3(soc,
  8397. vdev_id);
  8398. struct dp_pdev *pdev;
  8399. if (!vdev)
  8400. return QDF_STATUS_E_FAILURE;
  8401. pdev = (struct dp_pdev *)vdev->pdev;
  8402. pdev->nac_rssi_filtering = 1;
  8403. /* Store address of NAC (neighbour peer) which will be checked
  8404. * against TA of received packets.
  8405. */
  8406. if (cmd == CDP_NAC_PARAM_ADD) {
  8407. dp_update_filter_neighbour_peers(cdp_soc, vdev->vdev_id,
  8408. DP_NAC_PARAM_ADD,
  8409. (uint8_t *)client_macaddr);
  8410. } else if (cmd == CDP_NAC_PARAM_DEL) {
  8411. dp_update_filter_neighbour_peers(cdp_soc, vdev->vdev_id,
  8412. DP_NAC_PARAM_DEL,
  8413. (uint8_t *)client_macaddr);
  8414. }
  8415. if (soc->cdp_soc.ol_ops->config_bssid_in_fw_for_nac_rssi)
  8416. soc->cdp_soc.ol_ops->config_bssid_in_fw_for_nac_rssi
  8417. (soc->ctrl_psoc, pdev->pdev_id,
  8418. vdev->vdev_id, cmd, bssid, client_macaddr);
  8419. return QDF_STATUS_SUCCESS;
  8420. }
  8421. #endif
  8422. /**
  8423. * dp_enable_peer_based_pktlog() - Set Flag for peer based filtering
  8424. * for pktlog
  8425. * @soc: cdp_soc handle
  8426. * @pdev_id: id of dp pdev handle
  8427. * @mac_addr: Peer mac address
  8428. * @enb_dsb: Enable or disable peer based filtering
  8429. *
  8430. * Return: QDF_STATUS
  8431. */
  8432. static int
  8433. dp_enable_peer_based_pktlog(struct cdp_soc_t *soc, uint8_t pdev_id,
  8434. uint8_t *mac_addr, uint8_t enb_dsb)
  8435. {
  8436. struct dp_peer *peer;
  8437. struct dp_pdev *pdev =
  8438. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  8439. pdev_id);
  8440. if (!pdev) {
  8441. dp_err("Invalid Pdev for pdev_id %d", pdev_id);
  8442. return QDF_STATUS_E_FAILURE;
  8443. }
  8444. peer = (struct dp_peer *)dp_find_peer_by_addr((struct cdp_pdev *)pdev,
  8445. mac_addr);
  8446. if (!peer) {
  8447. dp_err("Invalid Peer");
  8448. return QDF_STATUS_E_FAILURE;
  8449. }
  8450. peer->peer_based_pktlog_filter = enb_dsb;
  8451. pdev->dp_peer_based_pktlog = enb_dsb;
  8452. return QDF_STATUS_SUCCESS;
  8453. }
  8454. #ifndef WLAN_SUPPORT_RX_TAG_STATISTICS
  8455. /**
  8456. * dp_dump_pdev_rx_protocol_tag_stats - dump the number of packets tagged for
  8457. * given protocol type (RX_PROTOCOL_TAG_ALL indicates for all protocol)
  8458. * @soc: cdp_soc handle
  8459. * @pdev_id: id of cdp_pdev handle
  8460. * @protocol_type: protocol type for which stats should be displayed
  8461. *
  8462. * Return: none
  8463. */
  8464. static inline void
  8465. dp_dump_pdev_rx_protocol_tag_stats(struct cdp_soc_t *soc, uint8_t pdev_id,
  8466. uint16_t protocol_type)
  8467. {
  8468. }
  8469. #endif /* WLAN_SUPPORT_RX_TAG_STATISTICS */
  8470. #ifndef WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG
  8471. /**
  8472. * dp_update_pdev_rx_protocol_tag - Add/remove a protocol tag that should be
  8473. * applied to the desired protocol type packets
  8474. * @soc: soc handle
  8475. * @pdev_id: id of cdp_pdev handle
  8476. * @enable_rx_protocol_tag - bitmask that indicates what protocol types
  8477. * are enabled for tagging. zero indicates disable feature, non-zero indicates
  8478. * enable feature
  8479. * @protocol_type: new protocol type for which the tag is being added
  8480. * @tag: user configured tag for the new protocol
  8481. *
  8482. * Return: Success
  8483. */
  8484. static inline QDF_STATUS
  8485. dp_update_pdev_rx_protocol_tag(struct cdp_soc_t *soc, uint8_t pdev_id,
  8486. uint32_t enable_rx_protocol_tag,
  8487. uint16_t protocol_type,
  8488. uint16_t tag)
  8489. {
  8490. return QDF_STATUS_SUCCESS;
  8491. }
  8492. #endif /* WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG */
  8493. #ifndef WLAN_SUPPORT_RX_FLOW_TAG
  8494. /**
  8495. * dp_set_rx_flow_tag - add/delete a flow
  8496. * @soc: soc handle
  8497. * @pdev_id: id of cdp_pdev handle
  8498. * @flow_info: flow tuple that is to be added to/deleted from flow search table
  8499. *
  8500. * Return: Success
  8501. */
  8502. static inline QDF_STATUS
  8503. dp_set_rx_flow_tag(struct cdp_soc_t *cdp_soc, uint8_t pdev_id,
  8504. struct cdp_rx_flow_info *flow_info)
  8505. {
  8506. return QDF_STATUS_SUCCESS;
  8507. }
  8508. /**
  8509. * dp_dump_rx_flow_tag_stats - dump the number of packets tagged for
  8510. * given flow 5-tuple
  8511. * @cdp_soc: soc handle
  8512. * @pdev_id: id of cdp_pdev handle
  8513. * @flow_info: flow 5-tuple for which stats should be displayed
  8514. *
  8515. * Return: Success
  8516. */
  8517. static inline QDF_STATUS
  8518. dp_dump_rx_flow_tag_stats(struct cdp_soc_t *cdp_soc, uint8_t pdev_id,
  8519. struct cdp_rx_flow_info *flow_info)
  8520. {
  8521. return QDF_STATUS_SUCCESS;
  8522. }
  8523. #endif /* WLAN_SUPPORT_RX_FLOW_TAG */
  8524. static QDF_STATUS dp_peer_map_attach_wifi3(struct cdp_soc_t *soc_hdl,
  8525. uint32_t max_peers,
  8526. uint32_t max_ast_index,
  8527. bool peer_map_unmap_v2)
  8528. {
  8529. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  8530. soc->max_peers = max_peers;
  8531. qdf_print ("%s max_peers %u, max_ast_index: %u\n",
  8532. __func__, max_peers, max_ast_index);
  8533. wlan_cfg_set_max_ast_idx(soc->wlan_cfg_ctx, max_ast_index);
  8534. if (dp_peer_find_attach(soc))
  8535. return QDF_STATUS_E_FAILURE;
  8536. soc->is_peer_map_unmap_v2 = peer_map_unmap_v2;
  8537. return QDF_STATUS_SUCCESS;
  8538. }
  8539. static void dp_soc_set_rate_stats_ctx(struct cdp_soc_t *soc_handle,
  8540. void *stats_ctx)
  8541. {
  8542. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  8543. soc->rate_stats_ctx = (struct cdp_soc_rate_stats_ctx *)stats_ctx;
  8544. }
  8545. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  8546. static QDF_STATUS dp_flush_rate_stats_req(struct cdp_soc_t *soc_hdl,
  8547. uint8_t pdev_id)
  8548. {
  8549. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  8550. struct dp_vdev *vdev = NULL;
  8551. struct dp_peer *peer = NULL;
  8552. struct dp_pdev *pdev =
  8553. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  8554. pdev_id);
  8555. if (!pdev)
  8556. return QDF_STATUS_E_FAILURE;
  8557. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  8558. qdf_spin_lock_bh(&pdev->vdev_list_lock);
  8559. TAILQ_FOREACH(vdev, &pdev->vdev_list, vdev_list_elem) {
  8560. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  8561. if (peer && !peer->bss_peer)
  8562. dp_wdi_event_handler(
  8563. WDI_EVENT_FLUSH_RATE_STATS_REQ,
  8564. soc, peer->wlanstats_ctx,
  8565. peer->peer_ids[0],
  8566. WDI_NO_VAL, pdev_id);
  8567. }
  8568. }
  8569. qdf_spin_unlock_bh(&pdev->vdev_list_lock);
  8570. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  8571. return QDF_STATUS_SUCCESS;
  8572. }
  8573. #else
  8574. static inline QDF_STATUS
  8575. dp_flush_rate_stats_req(struct cdp_soc_t *soc_hdl,
  8576. uint8_t pdev_id)
  8577. {
  8578. return QDF_STATUS_SUCCESS;
  8579. }
  8580. #endif
  8581. #if defined(FEATURE_PERPKT_INFO) && WDI_EVENT_ENABLE
  8582. static QDF_STATUS dp_peer_flush_rate_stats(struct cdp_soc_t *soc,
  8583. uint8_t pdev_id,
  8584. void *buf)
  8585. {
  8586. dp_wdi_event_handler(WDI_EVENT_PEER_FLUSH_RATE_STATS,
  8587. (struct dp_soc *)soc, buf, HTT_INVALID_PEER,
  8588. WDI_NO_VAL, pdev_id);
  8589. return QDF_STATUS_SUCCESS;
  8590. }
  8591. #else
  8592. static inline QDF_STATUS
  8593. dp_peer_flush_rate_stats(struct cdp_soc_t *soc,
  8594. uint8_t pdev_id,
  8595. void *buf)
  8596. {
  8597. return QDF_STATUS_SUCCESS;
  8598. }
  8599. #endif
  8600. static void *dp_soc_get_rate_stats_ctx(struct cdp_soc_t *soc_handle)
  8601. {
  8602. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  8603. return soc->rate_stats_ctx;
  8604. }
  8605. /*
  8606. * dp_get_cfg() - get dp cfg
  8607. * @soc: cdp soc handle
  8608. * @cfg: cfg enum
  8609. *
  8610. * Return: cfg value
  8611. */
  8612. static uint32_t dp_get_cfg(struct cdp_soc_t *soc, enum cdp_dp_cfg cfg)
  8613. {
  8614. struct dp_soc *dpsoc = (struct dp_soc *)soc;
  8615. uint32_t value = 0;
  8616. switch (cfg) {
  8617. case cfg_dp_enable_data_stall:
  8618. value = dpsoc->wlan_cfg_ctx->enable_data_stall_detection;
  8619. break;
  8620. case cfg_dp_enable_ip_tcp_udp_checksum_offload:
  8621. value = dpsoc->wlan_cfg_ctx->tcp_udp_checksumoffload;
  8622. break;
  8623. case cfg_dp_tso_enable:
  8624. value = dpsoc->wlan_cfg_ctx->tso_enabled;
  8625. break;
  8626. case cfg_dp_lro_enable:
  8627. value = dpsoc->wlan_cfg_ctx->lro_enabled;
  8628. break;
  8629. case cfg_dp_gro_enable:
  8630. value = dpsoc->wlan_cfg_ctx->gro_enabled;
  8631. break;
  8632. case cfg_dp_tx_flow_start_queue_offset:
  8633. value = dpsoc->wlan_cfg_ctx->tx_flow_start_queue_offset;
  8634. break;
  8635. case cfg_dp_tx_flow_stop_queue_threshold:
  8636. value = dpsoc->wlan_cfg_ctx->tx_flow_stop_queue_threshold;
  8637. break;
  8638. case cfg_dp_disable_intra_bss_fwd:
  8639. value = dpsoc->wlan_cfg_ctx->disable_intra_bss_fwd;
  8640. break;
  8641. default:
  8642. value = 0;
  8643. }
  8644. return value;
  8645. }
  8646. #ifdef PEER_FLOW_CONTROL
  8647. /**
  8648. * dp_tx_flow_ctrl_configure_pdev() - Configure flow control params
  8649. * @soc_handle: datapath soc handle
  8650. * @pdev_id: id of datapath pdev handle
  8651. * @param: ol ath params
  8652. * @value: value of the flag
  8653. * @buff: Buffer to be passed
  8654. *
  8655. * Implemented this function same as legacy function. In legacy code, single
  8656. * function is used to display stats and update pdev params.
  8657. *
  8658. * Return: 0 for success. nonzero for failure.
  8659. */
  8660. static uint32_t dp_tx_flow_ctrl_configure_pdev(struct cdp_soc_t *soc_handle,
  8661. uint8_t pdev_id,
  8662. enum _ol_ath_param_t param,
  8663. uint32_t value, void *buff)
  8664. {
  8665. struct dp_soc *soc = (struct dp_soc *)soc_handle;
  8666. struct dp_pdev *pdev =
  8667. dp_get_pdev_from_soc_pdev_id_wifi3((struct dp_soc *)soc,
  8668. pdev_id);
  8669. if (qdf_unlikely(!pdev))
  8670. return 1;
  8671. soc = pdev->soc;
  8672. if (!soc)
  8673. return 1;
  8674. switch (param) {
  8675. #ifdef QCA_ENH_V3_STATS_SUPPORT
  8676. case OL_ATH_PARAM_VIDEO_DELAY_STATS_FC:
  8677. if (value)
  8678. pdev->delay_stats_flag = true;
  8679. else
  8680. pdev->delay_stats_flag = false;
  8681. break;
  8682. case OL_ATH_PARAM_VIDEO_STATS_FC:
  8683. qdf_print("------- TID Stats ------\n");
  8684. dp_pdev_print_tid_stats(pdev);
  8685. qdf_print("------ Delay Stats ------\n");
  8686. dp_pdev_print_delay_stats(pdev);
  8687. break;
  8688. #endif
  8689. case OL_ATH_PARAM_TOTAL_Q_SIZE:
  8690. {
  8691. uint32_t tx_min, tx_max;
  8692. tx_min = wlan_cfg_get_min_tx_desc(soc->wlan_cfg_ctx);
  8693. tx_max = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  8694. if (!buff) {
  8695. if ((value >= tx_min) && (value <= tx_max)) {
  8696. pdev->num_tx_allowed = value;
  8697. } else {
  8698. QDF_TRACE(QDF_MODULE_ID_DP,
  8699. QDF_TRACE_LEVEL_INFO,
  8700. "Failed to update num_tx_allowed, Q_min = %d Q_max = %d",
  8701. tx_min, tx_max);
  8702. break;
  8703. }
  8704. } else {
  8705. *(int *)buff = pdev->num_tx_allowed;
  8706. }
  8707. }
  8708. break;
  8709. default:
  8710. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  8711. "%s: not handled param %d ", __func__, param);
  8712. break;
  8713. }
  8714. return 0;
  8715. }
  8716. #endif
  8717. /**
  8718. * dp_set_pdev_pcp_tid_map_wifi3(): update pcp tid map in pdev
  8719. * @psoc: dp soc handle
  8720. * @pdev_id: id of DP_PDEV handle
  8721. * @pcp: pcp value
  8722. * @tid: tid value passed by the user
  8723. *
  8724. * Return: QDF_STATUS_SUCCESS on success
  8725. */
  8726. static QDF_STATUS dp_set_pdev_pcp_tid_map_wifi3(ol_txrx_soc_handle psoc,
  8727. uint8_t pdev_id,
  8728. uint8_t pcp, uint8_t tid)
  8729. {
  8730. struct dp_soc *soc = (struct dp_soc *)psoc;
  8731. soc->pcp_tid_map[pcp] = tid;
  8732. hal_tx_update_pcp_tid_map(soc->hal_soc, pcp, tid);
  8733. return QDF_STATUS_SUCCESS;
  8734. }
  8735. /**
  8736. * dp_set_vdev_pcp_tid_map_wifi3(): update pcp tid map in vdev
  8737. * @soc: DP soc handle
  8738. * @vdev_id: id of DP_VDEV handle
  8739. * @pcp: pcp value
  8740. * @tid: tid value passed by the user
  8741. *
  8742. * Return: QDF_STATUS_SUCCESS on success
  8743. */
  8744. static QDF_STATUS dp_set_vdev_pcp_tid_map_wifi3(struct cdp_soc_t *soc,
  8745. uint8_t vdev_id,
  8746. uint8_t pcp, uint8_t tid)
  8747. {
  8748. struct dp_vdev *vdev =
  8749. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  8750. vdev_id);
  8751. if (!vdev)
  8752. return QDF_STATUS_E_FAILURE;
  8753. vdev->pcp_tid_map[pcp] = tid;
  8754. return QDF_STATUS_SUCCESS;
  8755. }
  8756. static struct cdp_cmn_ops dp_ops_cmn = {
  8757. .txrx_soc_attach_target = dp_soc_attach_target_wifi3,
  8758. .txrx_vdev_attach = dp_vdev_attach_wifi3,
  8759. .txrx_vdev_detach = dp_vdev_detach_wifi3,
  8760. .txrx_pdev_attach = dp_pdev_attach_wifi3,
  8761. .txrx_pdev_detach = dp_pdev_detach_wifi3,
  8762. .txrx_pdev_deinit = dp_pdev_deinit_wifi3,
  8763. .txrx_peer_create = dp_peer_create_wifi3,
  8764. .txrx_peer_setup = dp_peer_setup_wifi3,
  8765. #ifdef FEATURE_AST
  8766. .txrx_peer_teardown = dp_peer_teardown_wifi3,
  8767. #else
  8768. .txrx_peer_teardown = NULL,
  8769. #endif
  8770. .txrx_peer_add_ast = dp_peer_add_ast_wifi3,
  8771. .txrx_peer_update_ast = dp_peer_update_ast_wifi3,
  8772. .txrx_peer_get_ast_info_by_soc = dp_peer_get_ast_info_by_soc_wifi3,
  8773. .txrx_peer_get_ast_info_by_pdev =
  8774. dp_peer_get_ast_info_by_pdevid_wifi3,
  8775. .txrx_peer_ast_delete_by_soc =
  8776. dp_peer_ast_entry_del_by_soc,
  8777. .txrx_peer_ast_delete_by_pdev =
  8778. dp_peer_ast_entry_del_by_pdev,
  8779. .txrx_peer_delete = dp_peer_delete_wifi3,
  8780. .txrx_vdev_register = dp_vdev_register_wifi3,
  8781. .txrx_soc_detach = dp_soc_detach_wifi3,
  8782. .txrx_soc_deinit = dp_soc_deinit_wifi3,
  8783. .txrx_soc_init = dp_soc_init_wifi3,
  8784. .txrx_tso_soc_attach = dp_tso_soc_attach,
  8785. .txrx_tso_soc_detach = dp_tso_soc_detach,
  8786. .txrx_get_vdev_mac_addr = dp_get_vdev_mac_addr_wifi3,
  8787. .txrx_get_mon_vdev_from_pdev = dp_get_mon_vdev_from_pdev_wifi3,
  8788. .txrx_get_ctrl_pdev_from_vdev = dp_get_ctrl_pdev_from_vdev_wifi3,
  8789. .txrx_ath_getstats = dp_get_device_stats,
  8790. .addba_requestprocess = dp_addba_requestprocess_wifi3,
  8791. .addba_responsesetup = dp_addba_responsesetup_wifi3,
  8792. .addba_resp_tx_completion = dp_addba_resp_tx_completion_wifi3,
  8793. .delba_process = dp_delba_process_wifi3,
  8794. .set_addba_response = dp_set_addba_response,
  8795. .flush_cache_rx_queue = NULL,
  8796. /* TODO: get API's for dscp-tid need to be added*/
  8797. .set_vdev_dscp_tid_map = dp_set_vdev_dscp_tid_map_wifi3,
  8798. .set_pdev_dscp_tid_map = dp_set_pdev_dscp_tid_map_wifi3,
  8799. .txrx_get_total_per = dp_get_total_per,
  8800. .txrx_stats_request = dp_txrx_stats_request,
  8801. .txrx_set_monitor_mode = dp_vdev_set_monitor_mode,
  8802. .txrx_get_peer_mac_from_peer_id = dp_get_peer_mac_from_peer_id,
  8803. .display_stats = dp_txrx_dump_stats,
  8804. .txrx_intr_attach = dp_soc_interrupt_attach_wrapper,
  8805. .txrx_intr_detach = dp_soc_interrupt_detach,
  8806. .set_pn_check = dp_set_pn_check_wifi3,
  8807. .update_config_parameters = dp_update_config_parameters,
  8808. /* TODO: Add other functions */
  8809. .txrx_data_tx_cb_set = dp_txrx_data_tx_cb_set,
  8810. .get_dp_txrx_handle = dp_pdev_get_dp_txrx_handle,
  8811. .set_dp_txrx_handle = dp_pdev_set_dp_txrx_handle,
  8812. .get_vdev_dp_ext_txrx_handle = dp_vdev_get_dp_ext_handle,
  8813. .set_vdev_dp_ext_txrx_handle = dp_vdev_set_dp_ext_handle,
  8814. .get_soc_dp_txrx_handle = dp_soc_get_dp_txrx_handle,
  8815. .set_soc_dp_txrx_handle = dp_soc_set_dp_txrx_handle,
  8816. .map_pdev_to_lmac = dp_soc_map_pdev_to_lmac,
  8817. .handle_mode_change = dp_soc_handle_pdev_mode_change,
  8818. .set_pdev_status_down = dp_soc_set_pdev_status_down,
  8819. .txrx_set_ba_aging_timeout = dp_set_ba_aging_timeout,
  8820. .txrx_get_ba_aging_timeout = dp_get_ba_aging_timeout,
  8821. .tx_send = dp_tx_send,
  8822. .txrx_peer_reset_ast = dp_wds_reset_ast_wifi3,
  8823. .txrx_peer_reset_ast_table = dp_wds_reset_ast_table_wifi3,
  8824. .txrx_peer_flush_ast_table = dp_wds_flush_ast_table_wifi3,
  8825. .txrx_peer_map_attach = dp_peer_map_attach_wifi3,
  8826. .txrx_get_os_rx_handles_from_vdev =
  8827. dp_get_os_rx_handles_from_vdev_wifi3,
  8828. .delba_tx_completion = dp_delba_tx_completion_wifi3,
  8829. .get_dp_capabilities = dp_get_cfg_capabilities,
  8830. .txrx_get_cfg = dp_get_cfg,
  8831. .set_rate_stats_ctx = dp_soc_set_rate_stats_ctx,
  8832. .get_rate_stats_ctx = dp_soc_get_rate_stats_ctx,
  8833. .txrx_peer_flush_rate_stats = dp_peer_flush_rate_stats,
  8834. .txrx_flush_rate_stats_request = dp_flush_rate_stats_req,
  8835. .set_pdev_pcp_tid_map = dp_set_pdev_pcp_tid_map_wifi3,
  8836. .set_vdev_pcp_tid_map = dp_set_vdev_pcp_tid_map_wifi3,
  8837. .txrx_cp_peer_del_response = dp_cp_peer_del_resp_handler,
  8838. #ifdef QCA_MULTIPASS_SUPPORT
  8839. .set_vlan_groupkey = dp_set_vlan_groupkey,
  8840. #endif
  8841. .get_peer_mac_list = dp_get_peer_mac_list,
  8842. .tx_send_exc = dp_tx_send_exception,
  8843. };
  8844. static struct cdp_ctrl_ops dp_ops_ctrl = {
  8845. .txrx_peer_authorize = dp_peer_authorize,
  8846. .txrx_set_vdev_param = dp_set_vdev_param,
  8847. .txrx_set_psoc_param = dp_set_psoc_param,
  8848. .txrx_get_psoc_param = dp_get_psoc_param,
  8849. .txrx_set_pdev_reo_dest = dp_set_pdev_reo_dest,
  8850. .txrx_get_pdev_reo_dest = dp_get_pdev_reo_dest,
  8851. .txrx_update_filter_neighbour_peers =
  8852. dp_update_filter_neighbour_peers,
  8853. .txrx_get_sec_type = dp_get_sec_type,
  8854. .txrx_wdi_event_sub = dp_wdi_event_sub,
  8855. .txrx_wdi_event_unsub = dp_wdi_event_unsub,
  8856. #ifdef WDI_EVENT_ENABLE
  8857. .txrx_get_pldev = dp_get_pldev,
  8858. #endif
  8859. .txrx_set_pdev_param = dp_set_pdev_param,
  8860. .txrx_get_pdev_param = dp_get_pdev_param,
  8861. .txrx_set_peer_param = dp_set_peer_param,
  8862. .txrx_get_peer_param = dp_get_peer_param,
  8863. #ifdef ATH_SUPPORT_NAC_RSSI
  8864. .txrx_vdev_config_for_nac_rssi = dp_config_for_nac_rssi,
  8865. .txrx_vdev_get_neighbour_rssi = dp_vdev_get_neighbour_rssi,
  8866. #endif
  8867. .set_key = dp_set_michael_key,
  8868. .txrx_get_vdev_param = dp_get_vdev_param,
  8869. .enable_peer_based_pktlog = dp_enable_peer_based_pktlog,
  8870. .calculate_delay_stats = dp_calculate_delay_stats,
  8871. #ifdef WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG
  8872. .txrx_update_pdev_rx_protocol_tag = dp_update_pdev_rx_protocol_tag,
  8873. #ifdef WLAN_SUPPORT_RX_TAG_STATISTICS
  8874. .txrx_dump_pdev_rx_protocol_tag_stats =
  8875. dp_dump_pdev_rx_protocol_tag_stats,
  8876. #endif /* WLAN_SUPPORT_RX_TAG_STATISTICS */
  8877. #endif /* WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG */
  8878. #ifdef WLAN_SUPPORT_RX_FLOW_TAG
  8879. .txrx_set_rx_flow_tag = dp_set_rx_flow_tag,
  8880. .txrx_dump_rx_flow_tag_stats = dp_dump_rx_flow_tag_stats,
  8881. #endif /* WLAN_SUPPORT_RX_FLOW_TAG */
  8882. #ifdef QCA_MULTIPASS_SUPPORT
  8883. .txrx_peer_set_vlan_id = dp_peer_set_vlan_id,
  8884. #endif /*QCA_MULTIPASS_SUPPORT*/
  8885. #if defined(WLAN_TX_PKT_CAPTURE_ENH) || defined(WLAN_RX_PKT_CAPTURE_ENH)
  8886. .txrx_update_peer_pkt_capture_params =
  8887. dp_peer_update_pkt_capture_params,
  8888. #endif /* WLAN_TX_PKT_CAPTURE_ENH || WLAN_RX_PKT_CAPTURE_ENH */
  8889. };
  8890. static struct cdp_me_ops dp_ops_me = {
  8891. #ifdef ATH_SUPPORT_IQUE
  8892. .tx_me_alloc_descriptor = dp_tx_me_alloc_descriptor,
  8893. .tx_me_free_descriptor = dp_tx_me_free_descriptor,
  8894. .tx_me_convert_ucast = dp_tx_me_send_convert_ucast,
  8895. #endif
  8896. };
  8897. static struct cdp_mon_ops dp_ops_mon = {
  8898. .txrx_reset_monitor_mode = dp_reset_monitor_mode,
  8899. /* Added support for HK advance filter */
  8900. .txrx_set_advance_monitor_filter = dp_pdev_set_advance_monitor_filter,
  8901. .txrx_deliver_tx_mgmt = dp_deliver_tx_mgmt,
  8902. };
  8903. static struct cdp_host_stats_ops dp_ops_host_stats = {
  8904. .txrx_per_peer_stats = dp_get_host_peer_stats,
  8905. .get_fw_peer_stats = dp_get_fw_peer_stats,
  8906. .get_htt_stats = dp_get_htt_stats,
  8907. .txrx_enable_enhanced_stats = dp_enable_enhanced_stats,
  8908. .txrx_disable_enhanced_stats = dp_disable_enhanced_stats,
  8909. .txrx_stats_publish = dp_txrx_stats_publish,
  8910. .txrx_get_vdev_stats = dp_txrx_get_vdev_stats,
  8911. .txrx_get_peer_stats = dp_txrx_get_peer_stats,
  8912. .txrx_get_peer_stats_param = dp_txrx_get_peer_stats_param,
  8913. .txrx_reset_peer_stats = dp_txrx_reset_peer_stats,
  8914. .txrx_get_pdev_stats = dp_txrx_get_pdev_stats,
  8915. .txrx_get_ratekbps = dp_txrx_get_ratekbps,
  8916. .txrx_update_vdev_stats = dp_txrx_update_vdev_host_stats,
  8917. /* TODO */
  8918. };
  8919. static struct cdp_raw_ops dp_ops_raw = {
  8920. /* TODO */
  8921. };
  8922. #ifdef PEER_FLOW_CONTROL
  8923. static struct cdp_pflow_ops dp_ops_pflow = {
  8924. dp_tx_flow_ctrl_configure_pdev,
  8925. };
  8926. #endif /* CONFIG_WIN */
  8927. #if defined(WLAN_CFR_ENABLE) && defined(WLAN_ENH_CFR_ENABLE)
  8928. static struct cdp_cfr_ops dp_ops_cfr = {
  8929. .txrx_cfr_filter = dp_cfr_filter,
  8930. .txrx_get_cfr_rcc = dp_get_cfr_rcc,
  8931. .txrx_set_cfr_rcc = dp_set_cfr_rcc,
  8932. };
  8933. #endif
  8934. #ifdef FEATURE_RUNTIME_PM
  8935. /**
  8936. * dp_runtime_suspend() - ensure DP is ready to runtime suspend
  8937. * @soc_hdl: Datapath soc handle
  8938. * @pdev_id: id of data path pdev handle
  8939. *
  8940. * DP is ready to runtime suspend if there are no pending TX packets.
  8941. *
  8942. * Return: QDF_STATUS
  8943. */
  8944. static QDF_STATUS dp_runtime_suspend(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  8945. {
  8946. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  8947. struct dp_pdev *pdev;
  8948. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  8949. if (!pdev) {
  8950. dp_err("pdev is NULL");
  8951. return QDF_STATUS_E_INVAL;
  8952. }
  8953. /* Abort if there are any pending TX packets */
  8954. if (dp_get_tx_pending(dp_pdev_to_cdp_pdev(pdev)) > 0) {
  8955. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  8956. FL("Abort suspend due to pending TX packets"));
  8957. return QDF_STATUS_E_AGAIN;
  8958. }
  8959. if (soc->intr_mode == DP_INTR_POLL)
  8960. qdf_timer_stop(&soc->int_timer);
  8961. return QDF_STATUS_SUCCESS;
  8962. }
  8963. /**
  8964. * dp_flush_ring_hptp() - Update ring shadow
  8965. * register HP/TP address when runtime
  8966. * resume
  8967. * @opaque_soc: DP soc context
  8968. *
  8969. * Return: None
  8970. */
  8971. static
  8972. void dp_flush_ring_hptp(struct dp_soc *soc, hal_ring_handle_t hal_srng)
  8973. {
  8974. if (hal_srng && hal_srng_get_clear_event(hal_srng,
  8975. HAL_SRNG_FLUSH_EVENT)) {
  8976. /* Acquire the lock */
  8977. hal_srng_access_start(soc->hal_soc, hal_srng);
  8978. hal_srng_access_end(soc->hal_soc, hal_srng);
  8979. hal_srng_set_flush_last_ts(hal_srng);
  8980. }
  8981. }
  8982. /**
  8983. * dp_runtime_resume() - ensure DP is ready to runtime resume
  8984. * @soc_hdl: Datapath soc handle
  8985. * @pdev_id: id of data path pdev handle
  8986. *
  8987. * Resume DP for runtime PM.
  8988. *
  8989. * Return: QDF_STATUS
  8990. */
  8991. static QDF_STATUS dp_runtime_resume(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  8992. {
  8993. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  8994. int i;
  8995. if (soc->intr_mode == DP_INTR_POLL)
  8996. qdf_timer_mod(&soc->int_timer, DP_INTR_POLL_TIMER_MS);
  8997. for (i = 0; i < MAX_TCL_DATA_RINGS; i++) {
  8998. dp_flush_ring_hptp(soc, soc->tcl_data_ring[i].hal_srng);
  8999. }
  9000. dp_flush_ring_hptp(soc, soc->reo_cmd_ring.hal_srng);
  9001. return QDF_STATUS_SUCCESS;
  9002. }
  9003. #endif /* FEATURE_RUNTIME_PM */
  9004. /**
  9005. * dp_tx_get_success_ack_stats() - get tx success completion count
  9006. * @soc_hdl: Datapath soc handle
  9007. * @vdevid: vdev identifier
  9008. *
  9009. * Return: tx success ack count
  9010. */
  9011. static uint32_t dp_tx_get_success_ack_stats(struct cdp_soc_t *soc_hdl,
  9012. uint8_t vdev_id)
  9013. {
  9014. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9015. struct cdp_vdev_stats *vdev_stats = NULL;
  9016. uint32_t tx_success;
  9017. struct dp_vdev *vdev =
  9018. (struct dp_vdev *)dp_get_vdev_from_soc_vdev_id_wifi3(soc,
  9019. vdev_id);
  9020. if (!vdev) {
  9021. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  9022. FL("Invalid vdev id %d"), vdev_id);
  9023. return 0;
  9024. }
  9025. vdev_stats = qdf_mem_malloc_atomic(sizeof(struct cdp_vdev_stats));
  9026. if (!vdev_stats) {
  9027. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  9028. "DP alloc failure - unable to get alloc vdev stats");
  9029. return 0;
  9030. }
  9031. qdf_spin_lock_bh(&soc->peer_ref_mutex);
  9032. dp_aggregate_vdev_stats(vdev, vdev_stats);
  9033. qdf_spin_unlock_bh(&soc->peer_ref_mutex);
  9034. tx_success = vdev_stats->tx.tx_success.num;
  9035. qdf_mem_free(vdev_stats);
  9036. return tx_success;
  9037. }
  9038. #ifdef WLAN_SUPPORT_DATA_STALL
  9039. /**
  9040. * dp_register_data_stall_detect_cb() - register data stall callback
  9041. * @soc_hdl: Datapath soc handle
  9042. * @pdev_id: id of data path pdev handle
  9043. * @data_stall_detect_callback: data stall callback function
  9044. *
  9045. * Return: QDF_STATUS Enumeration
  9046. */
  9047. static
  9048. QDF_STATUS dp_register_data_stall_detect_cb(
  9049. struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  9050. data_stall_detect_cb data_stall_detect_callback)
  9051. {
  9052. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9053. struct dp_pdev *pdev;
  9054. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  9055. if (!pdev) {
  9056. dp_err("pdev NULL!");
  9057. return QDF_STATUS_E_INVAL;
  9058. }
  9059. pdev->data_stall_detect_callback = data_stall_detect_callback;
  9060. return QDF_STATUS_SUCCESS;
  9061. }
  9062. /**
  9063. * dp_deregister_data_stall_detect_cb() - de-register data stall callback
  9064. * @soc_hdl: Datapath soc handle
  9065. * @pdev_id: id of data path pdev handle
  9066. * @data_stall_detect_callback: data stall callback function
  9067. *
  9068. * Return: QDF_STATUS Enumeration
  9069. */
  9070. static
  9071. QDF_STATUS dp_deregister_data_stall_detect_cb(
  9072. struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  9073. data_stall_detect_cb data_stall_detect_callback)
  9074. {
  9075. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9076. struct dp_pdev *pdev;
  9077. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  9078. if (!pdev) {
  9079. dp_err("pdev NULL!");
  9080. return QDF_STATUS_E_INVAL;
  9081. }
  9082. pdev->data_stall_detect_callback = NULL;
  9083. return QDF_STATUS_SUCCESS;
  9084. }
  9085. /**
  9086. * dp_txrx_post_data_stall_event() - post data stall event
  9087. * @soc_hdl: Datapath soc handle
  9088. * @indicator: Module triggering data stall
  9089. * @data_stall_type: data stall event type
  9090. * @pdev_id: pdev id
  9091. * @vdev_id_bitmap: vdev id bitmap
  9092. * @recovery_type: data stall recovery type
  9093. *
  9094. * Return: None
  9095. */
  9096. static void
  9097. dp_txrx_post_data_stall_event(struct cdp_soc_t *soc_hdl,
  9098. enum data_stall_log_event_indicator indicator,
  9099. enum data_stall_log_event_type data_stall_type,
  9100. uint32_t pdev_id, uint32_t vdev_id_bitmap,
  9101. enum data_stall_log_recovery_type recovery_type)
  9102. {
  9103. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9104. struct data_stall_event_info data_stall_info;
  9105. struct dp_pdev *pdev;
  9106. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  9107. if (!pdev) {
  9108. dp_err("pdev NULL!");
  9109. return;
  9110. }
  9111. if (!pdev->data_stall_detect_callback) {
  9112. dp_err("data stall cb not registered!");
  9113. return;
  9114. }
  9115. dp_info("data_stall_type: %x pdev_id: %d",
  9116. data_stall_type, pdev_id);
  9117. data_stall_info.indicator = indicator;
  9118. data_stall_info.data_stall_type = data_stall_type;
  9119. data_stall_info.vdev_id_bitmap = vdev_id_bitmap;
  9120. data_stall_info.pdev_id = pdev_id;
  9121. data_stall_info.recovery_type = recovery_type;
  9122. pdev->data_stall_detect_callback(&data_stall_info);
  9123. }
  9124. #endif /* WLAN_SUPPORT_DATA_STALL */
  9125. #ifdef WLAN_FEATURE_STATS_EXT
  9126. /* rx hw stats event wait timeout in ms */
  9127. #define DP_REO_STATUS_STATS_TIMEOUT 1000
  9128. /**
  9129. * dp_txrx_ext_stats_request - request dp txrx extended stats request
  9130. * @soc_hdl: soc handle
  9131. * @pdev_id: pdev id
  9132. * @req: stats request
  9133. *
  9134. * Return: QDF_STATUS
  9135. */
  9136. static QDF_STATUS
  9137. dp_txrx_ext_stats_request(struct cdp_soc_t *soc_hdl, uint8_t pdev_id,
  9138. struct cdp_txrx_ext_stats *req)
  9139. {
  9140. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  9141. struct dp_pdev *pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  9142. if (!pdev) {
  9143. dp_err("pdev is null");
  9144. return QDF_STATUS_E_INVAL;
  9145. }
  9146. dp_aggregate_pdev_stats(pdev);
  9147. req->tx_msdu_enqueue = pdev->stats.tx_i.processed.num;
  9148. req->tx_msdu_overflow = pdev->stats.tx_i.dropped.ring_full;
  9149. req->rx_mpdu_received = soc->ext_stats.rx_mpdu_received;
  9150. req->rx_mpdu_delivered = soc->ext_stats.rx_mpdu_received;
  9151. req->rx_mpdu_missed = soc->ext_stats.rx_mpdu_missed;
  9152. req->rx_mpdu_error = soc->stats.rx.err_ring_pkts -
  9153. soc->stats.rx.rx_frags;
  9154. return QDF_STATUS_SUCCESS;
  9155. }
  9156. /**
  9157. * dp_rx_hw_stats_cb - request rx hw stats response callback
  9158. * @soc: soc handle
  9159. * @cb_ctxt: callback context
  9160. * @reo_status: reo command response status
  9161. *
  9162. * Return: None
  9163. */
  9164. static void dp_rx_hw_stats_cb(struct dp_soc *soc, void *cb_ctxt,
  9165. union hal_reo_status *reo_status)
  9166. {
  9167. struct dp_rx_tid *rx_tid = (struct dp_rx_tid *)cb_ctxt;
  9168. struct hal_reo_queue_status *queue_status = &reo_status->queue_status;
  9169. if (soc->ignore_reo_status_cb) {
  9170. qdf_event_set(&soc->rx_hw_stats_event);
  9171. return;
  9172. }
  9173. if (queue_status->header.status != HAL_REO_CMD_SUCCESS) {
  9174. dp_info("REO stats failure %d for TID %d",
  9175. queue_status->header.status, rx_tid->tid);
  9176. return;
  9177. }
  9178. soc->ext_stats.rx_mpdu_received += queue_status->mpdu_frms_cnt;
  9179. soc->ext_stats.rx_mpdu_missed += queue_status->late_recv_mpdu_cnt;
  9180. if (rx_tid->tid == (DP_MAX_TIDS - 1))
  9181. qdf_event_set(&soc->rx_hw_stats_event);
  9182. }
  9183. /**
  9184. * dp_request_rx_hw_stats - request rx hardware stats
  9185. * @soc_hdl: soc handle
  9186. * @vdev_id: vdev id
  9187. *
  9188. * Return: None
  9189. */
  9190. static void
  9191. dp_request_rx_hw_stats(struct cdp_soc_t *soc_hdl, uint8_t vdev_id)
  9192. {
  9193. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  9194. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc, vdev_id);
  9195. struct dp_peer *peer;
  9196. if (!vdev) {
  9197. dp_err("vdev is null");
  9198. qdf_event_set(&soc->rx_hw_stats_event);
  9199. return;
  9200. }
  9201. peer = vdev->vap_bss_peer;
  9202. if (!peer || peer->delete_in_progress) {
  9203. dp_err("Peer deletion in progress");
  9204. qdf_event_set(&soc->rx_hw_stats_event);
  9205. return;
  9206. }
  9207. qdf_event_reset(&soc->rx_hw_stats_event);
  9208. dp_peer_rxtid_stats(peer, dp_rx_hw_stats_cb, NULL);
  9209. }
  9210. /**
  9211. * dp_wait_for_ext_rx_stats - wait for rx reo status for rx stats
  9212. * @soc_hdl: cdp opaque soc handle
  9213. *
  9214. * Return: status
  9215. */
  9216. static QDF_STATUS
  9217. dp_wait_for_ext_rx_stats(struct cdp_soc_t *soc_hdl)
  9218. {
  9219. struct dp_soc *soc = (struct dp_soc *)soc_hdl;
  9220. QDF_STATUS status;
  9221. status = qdf_wait_single_event(&soc->rx_hw_stats_event,
  9222. DP_REO_STATUS_STATS_TIMEOUT);
  9223. return status;
  9224. }
  9225. #endif /* WLAN_FEATURE_STATS_EXT */
  9226. #ifdef DP_PEER_EXTENDED_API
  9227. static struct cdp_misc_ops dp_ops_misc = {
  9228. #ifdef FEATURE_WLAN_TDLS
  9229. .tx_non_std = dp_tx_non_std,
  9230. #endif /* FEATURE_WLAN_TDLS */
  9231. .get_opmode = dp_get_opmode,
  9232. #ifdef FEATURE_RUNTIME_PM
  9233. .runtime_suspend = dp_runtime_suspend,
  9234. .runtime_resume = dp_runtime_resume,
  9235. #endif /* FEATURE_RUNTIME_PM */
  9236. .pkt_log_init = dp_pkt_log_init,
  9237. .pkt_log_con_service = dp_pkt_log_con_service,
  9238. .get_num_rx_contexts = dp_get_num_rx_contexts,
  9239. .get_tx_ack_stats = dp_tx_get_success_ack_stats,
  9240. #ifdef WLAN_SUPPORT_DATA_STALL
  9241. .txrx_data_stall_cb_register = dp_register_data_stall_detect_cb,
  9242. .txrx_data_stall_cb_deregister = dp_deregister_data_stall_detect_cb,
  9243. .txrx_post_data_stall_event = dp_txrx_post_data_stall_event,
  9244. #endif
  9245. #ifdef WLAN_FEATURE_STATS_EXT
  9246. .txrx_ext_stats_request = dp_txrx_ext_stats_request,
  9247. .request_rx_hw_stats = dp_request_rx_hw_stats,
  9248. .wait_for_ext_rx_stats = dp_wait_for_ext_rx_stats,
  9249. #endif
  9250. };
  9251. #endif
  9252. #ifdef DP_FLOW_CTL
  9253. static struct cdp_flowctl_ops dp_ops_flowctl = {
  9254. /* WIFI 3.0 DP implement as required. */
  9255. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  9256. .flow_pool_map_handler = dp_tx_flow_pool_map,
  9257. .flow_pool_unmap_handler = dp_tx_flow_pool_unmap,
  9258. .register_pause_cb = dp_txrx_register_pause_cb,
  9259. .dump_flow_pool_info = dp_tx_dump_flow_pool_info,
  9260. .tx_desc_thresh_reached = dp_tx_desc_thresh_reached,
  9261. #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */
  9262. };
  9263. static struct cdp_lflowctl_ops dp_ops_l_flowctl = {
  9264. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  9265. };
  9266. #endif
  9267. #ifdef IPA_OFFLOAD
  9268. static struct cdp_ipa_ops dp_ops_ipa = {
  9269. .ipa_get_resource = dp_ipa_get_resource,
  9270. .ipa_set_doorbell_paddr = dp_ipa_set_doorbell_paddr,
  9271. .ipa_op_response = dp_ipa_op_response,
  9272. .ipa_register_op_cb = dp_ipa_register_op_cb,
  9273. .ipa_get_stat = dp_ipa_get_stat,
  9274. .ipa_tx_data_frame = dp_tx_send_ipa_data_frame,
  9275. .ipa_enable_autonomy = dp_ipa_enable_autonomy,
  9276. .ipa_disable_autonomy = dp_ipa_disable_autonomy,
  9277. .ipa_setup = dp_ipa_setup,
  9278. .ipa_cleanup = dp_ipa_cleanup,
  9279. .ipa_setup_iface = dp_ipa_setup_iface,
  9280. .ipa_cleanup_iface = dp_ipa_cleanup_iface,
  9281. .ipa_enable_pipes = dp_ipa_enable_pipes,
  9282. .ipa_disable_pipes = dp_ipa_disable_pipes,
  9283. .ipa_set_perf_level = dp_ipa_set_perf_level,
  9284. .ipa_rx_intrabss_fwd = dp_ipa_rx_intrabss_fwd
  9285. };
  9286. #endif
  9287. #ifdef DP_POWER_SAVE
  9288. static QDF_STATUS dp_bus_suspend(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  9289. {
  9290. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9291. struct cdp_pdev *pdev = (struct cdp_pdev *)
  9292. dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  9293. int timeout = SUSPEND_DRAIN_WAIT;
  9294. int drain_wait_delay = 50; /* 50 ms */
  9295. if (qdf_unlikely(!pdev)) {
  9296. dp_err("pdev is NULL");
  9297. return QDF_STATUS_E_INVAL;
  9298. }
  9299. /* Abort if there are any pending TX packets */
  9300. while (dp_get_tx_pending(pdev) > 0) {
  9301. qdf_sleep(drain_wait_delay);
  9302. if (timeout <= 0) {
  9303. dp_err("TX frames are pending, abort suspend");
  9304. return QDF_STATUS_E_TIMEOUT;
  9305. }
  9306. timeout = timeout - drain_wait_delay;
  9307. }
  9308. if (soc->intr_mode == DP_INTR_POLL)
  9309. qdf_timer_stop(&soc->int_timer);
  9310. return QDF_STATUS_SUCCESS;
  9311. }
  9312. static QDF_STATUS dp_bus_resume(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  9313. {
  9314. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9315. if (soc->intr_mode == DP_INTR_POLL)
  9316. qdf_timer_mod(&soc->int_timer, DP_INTR_POLL_TIMER_MS);
  9317. return QDF_STATUS_SUCCESS;
  9318. }
  9319. static struct cdp_bus_ops dp_ops_bus = {
  9320. .bus_suspend = dp_bus_suspend,
  9321. .bus_resume = dp_bus_resume
  9322. };
  9323. #endif
  9324. #ifdef DP_FLOW_CTL
  9325. static struct cdp_throttle_ops dp_ops_throttle = {
  9326. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  9327. };
  9328. static struct cdp_cfg_ops dp_ops_cfg = {
  9329. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  9330. };
  9331. #endif
  9332. #ifdef DP_PEER_EXTENDED_API
  9333. static struct cdp_ocb_ops dp_ops_ocb = {
  9334. /* WIFI 3.0 DP NOT IMPLEMENTED YET */
  9335. };
  9336. static struct cdp_mob_stats_ops dp_ops_mob_stats = {
  9337. .clear_stats = dp_txrx_clear_dump_stats,
  9338. };
  9339. static struct cdp_peer_ops dp_ops_peer = {
  9340. .register_peer = dp_register_peer,
  9341. .clear_peer = dp_clear_peer,
  9342. .find_peer_exist = dp_find_peer_exist,
  9343. .find_peer_exist_on_vdev = dp_find_peer_exist_on_vdev,
  9344. .find_peer_exist_on_other_vdev = dp_find_peer_exist_on_other_vdev,
  9345. .peer_state_update = dp_peer_state_update,
  9346. .get_vdevid = dp_get_vdevid,
  9347. .get_vdev_by_peer_addr = dp_get_vdev_by_peer_addr,
  9348. .peer_get_peer_mac_addr = dp_peer_get_peer_mac_addr,
  9349. .get_peer_state = dp_get_peer_state,
  9350. };
  9351. #endif
  9352. static struct cdp_ops dp_txrx_ops = {
  9353. .cmn_drv_ops = &dp_ops_cmn,
  9354. .ctrl_ops = &dp_ops_ctrl,
  9355. .me_ops = &dp_ops_me,
  9356. .mon_ops = &dp_ops_mon,
  9357. .host_stats_ops = &dp_ops_host_stats,
  9358. .wds_ops = &dp_ops_wds,
  9359. .raw_ops = &dp_ops_raw,
  9360. #ifdef PEER_FLOW_CONTROL
  9361. .pflow_ops = &dp_ops_pflow,
  9362. #endif /* PEER_FLOW_CONTROL */
  9363. #ifdef DP_PEER_EXTENDED_API
  9364. .misc_ops = &dp_ops_misc,
  9365. .ocb_ops = &dp_ops_ocb,
  9366. .peer_ops = &dp_ops_peer,
  9367. .mob_stats_ops = &dp_ops_mob_stats,
  9368. #endif
  9369. #ifdef DP_FLOW_CTL
  9370. .cfg_ops = &dp_ops_cfg,
  9371. .flowctl_ops = &dp_ops_flowctl,
  9372. .l_flowctl_ops = &dp_ops_l_flowctl,
  9373. .throttle_ops = &dp_ops_throttle,
  9374. #endif
  9375. #ifdef IPA_OFFLOAD
  9376. .ipa_ops = &dp_ops_ipa,
  9377. #endif
  9378. #ifdef DP_POWER_SAVE
  9379. .bus_ops = &dp_ops_bus,
  9380. #endif
  9381. #if defined(WLAN_CFR_ENABLE) && defined(WLAN_ENH_CFR_ENABLE)
  9382. .cfr_ops = &dp_ops_cfr,
  9383. #endif
  9384. };
  9385. /*
  9386. * dp_soc_set_txrx_ring_map()
  9387. * @dp_soc: DP handler for soc
  9388. *
  9389. * Return: Void
  9390. */
  9391. void dp_soc_set_txrx_ring_map(struct dp_soc *soc)
  9392. {
  9393. uint32_t i;
  9394. for (i = 0; i < WLAN_CFG_INT_NUM_CONTEXTS; i++) {
  9395. soc->tx_ring_map[i] = dp_cpu_ring_map[DP_NSS_DEFAULT_MAP][i];
  9396. }
  9397. }
  9398. #if defined(QCA_WIFI_QCA8074) || defined(QCA_WIFI_QCA6018)
  9399. #ifndef QCA_MEM_ATTACH_ON_WIFI3
  9400. /**
  9401. * dp_soc_attach_wifi3() - Attach txrx SOC
  9402. * @ctrl_psoc: Opaque SOC handle from control plane
  9403. * @htc_handle: Opaque HTC handle
  9404. * @hif_handle: Opaque HIF handle
  9405. * @qdf_osdev: QDF device
  9406. * @ol_ops: Offload Operations
  9407. * @device_id: Device ID
  9408. *
  9409. * Return: DP SOC handle on success, NULL on failure
  9410. */
  9411. struct cdp_soc_t *
  9412. dp_soc_attach_wifi3(struct cdp_ctrl_objmgr_psoc *ctrl_psoc,
  9413. struct hif_opaque_softc *hif_handle,
  9414. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev,
  9415. struct ol_if_ops *ol_ops, uint16_t device_id)
  9416. {
  9417. struct dp_soc *dp_soc = NULL;
  9418. dp_soc = dp_soc_attach(ctrl_psoc, htc_handle, qdf_osdev,
  9419. ol_ops, device_id);
  9420. if (!dp_soc)
  9421. return NULL;
  9422. if (!dp_soc_init(dp_soc, htc_handle, hif_handle))
  9423. return NULL;
  9424. return dp_soc_to_cdp_soc_t(dp_soc);
  9425. }
  9426. #else
  9427. /**
  9428. * dp_soc_attach_wifi3() - Attach txrx SOC
  9429. * @ctrl_psoc: Opaque SOC handle from control plane
  9430. * @htc_handle: Opaque HTC handle
  9431. * @hif_handle: Opaque HIF handle
  9432. * @qdf_osdev: QDF device
  9433. * @ol_ops: Offload Operations
  9434. * @device_id: Device ID
  9435. *
  9436. * Return: DP SOC handle on success, NULL on failure
  9437. */
  9438. struct cdp_soc_t *
  9439. dp_soc_attach_wifi3(struct cdp_ctrl_objmgr_psoc *ctrl_psoc,
  9440. struct hif_opaque_softc *hif_handle,
  9441. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev,
  9442. struct ol_if_ops *ol_ops, uint16_t device_id)
  9443. {
  9444. struct dp_soc *dp_soc = NULL;
  9445. dp_soc = dp_soc_attach(ctrl_psoc, htc_handle, qdf_osdev,
  9446. ol_ops, device_id);
  9447. return dp_soc_to_cdp_soc_t(dp_soc);
  9448. }
  9449. #endif
  9450. /**
  9451. * dp_soc_attach() - Attach txrx SOC
  9452. * @ctrl_psoc: Opaque SOC handle from control plane
  9453. * @htc_handle: Opaque HTC handle
  9454. * @qdf_osdev: QDF device
  9455. * @ol_ops: Offload Operations
  9456. * @device_id: Device ID
  9457. *
  9458. * Return: DP SOC handle on success, NULL on failure
  9459. */
  9460. static struct dp_soc *
  9461. dp_soc_attach(struct cdp_ctrl_objmgr_psoc *ctrl_psoc,
  9462. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev,
  9463. struct ol_if_ops *ol_ops, uint16_t device_id)
  9464. {
  9465. int int_ctx;
  9466. struct dp_soc *soc = NULL;
  9467. struct htt_soc *htt_soc;
  9468. soc = qdf_mem_malloc(sizeof(*soc));
  9469. if (!soc) {
  9470. dp_err("DP SOC memory allocation failed");
  9471. goto fail0;
  9472. }
  9473. int_ctx = 0;
  9474. soc->device_id = device_id;
  9475. soc->cdp_soc.ops = &dp_txrx_ops;
  9476. soc->cdp_soc.ol_ops = ol_ops;
  9477. soc->ctrl_psoc = ctrl_psoc;
  9478. soc->osdev = qdf_osdev;
  9479. soc->num_hw_dscp_tid_map = HAL_MAX_HW_DSCP_TID_MAPS;
  9480. wlan_set_srng_cfg(&soc->wlan_srng_cfg);
  9481. qdf_mem_zero(&soc->vdev_id_map, sizeof(soc->vdev_id_map));
  9482. soc->wlan_cfg_ctx = wlan_cfg_soc_attach(soc->ctrl_psoc);
  9483. if (!soc->wlan_cfg_ctx) {
  9484. dp_err("wlan_cfg_ctx failed\n");
  9485. goto fail1;
  9486. }
  9487. dp_soc_set_interrupt_mode(soc);
  9488. htt_soc = htt_soc_attach(soc, htc_handle);
  9489. if (!htt_soc)
  9490. goto fail1;
  9491. soc->htt_handle = htt_soc;
  9492. if (htt_soc_htc_prealloc(htt_soc) != QDF_STATUS_SUCCESS)
  9493. goto fail2;
  9494. return soc;
  9495. fail2:
  9496. htt_soc_detach(htt_soc);
  9497. fail1:
  9498. qdf_mem_free(soc);
  9499. fail0:
  9500. return NULL;
  9501. }
  9502. /**
  9503. * dp_soc_init() - Initialize txrx SOC
  9504. * @dp_soc: Opaque DP SOC handle
  9505. * @htc_handle: Opaque HTC handle
  9506. * @hif_handle: Opaque HIF handle
  9507. *
  9508. * Return: DP SOC handle on success, NULL on failure
  9509. */
  9510. void *dp_soc_init(struct dp_soc *soc, HTC_HANDLE htc_handle,
  9511. struct hif_opaque_softc *hif_handle)
  9512. {
  9513. int target_type;
  9514. struct htt_soc *htt_soc = (struct htt_soc *)soc->htt_handle;
  9515. bool is_monitor_mode = false;
  9516. htt_set_htc_handle(htt_soc, htc_handle);
  9517. soc->hif_handle = hif_handle;
  9518. soc->hal_soc = hif_get_hal_handle(soc->hif_handle);
  9519. if (!soc->hal_soc)
  9520. return NULL;
  9521. htt_soc_initialize(soc->htt_handle, soc->ctrl_psoc,
  9522. htt_get_htc_handle(htt_soc),
  9523. soc->hal_soc, soc->osdev);
  9524. target_type = hal_get_target_type(soc->hal_soc);
  9525. switch (target_type) {
  9526. case TARGET_TYPE_QCA6290:
  9527. wlan_cfg_set_reo_dst_ring_size(soc->wlan_cfg_ctx,
  9528. REO_DST_RING_SIZE_QCA6290);
  9529. soc->ast_override_support = 1;
  9530. soc->da_war_enabled = false;
  9531. break;
  9532. #if defined(QCA_WIFI_QCA6390) || defined(QCA_WIFI_QCA6490) || \
  9533. defined(QCA_WIFI_QCA6750)
  9534. case TARGET_TYPE_QCA6390:
  9535. case TARGET_TYPE_QCA6490:
  9536. case TARGET_TYPE_QCA6750:
  9537. wlan_cfg_set_reo_dst_ring_size(soc->wlan_cfg_ctx,
  9538. REO_DST_RING_SIZE_QCA6290);
  9539. wlan_cfg_set_raw_mode_war(soc->wlan_cfg_ctx, true);
  9540. soc->ast_override_support = 1;
  9541. if (soc->cdp_soc.ol_ops->get_con_mode &&
  9542. soc->cdp_soc.ol_ops->get_con_mode() ==
  9543. QDF_GLOBAL_MONITOR_MODE) {
  9544. int int_ctx;
  9545. for (int_ctx = 0; int_ctx < WLAN_CFG_INT_NUM_CONTEXTS; int_ctx++) {
  9546. soc->wlan_cfg_ctx->int_rx_ring_mask[int_ctx] = 0;
  9547. soc->wlan_cfg_ctx->int_rxdma2host_ring_mask[int_ctx] = 0;
  9548. }
  9549. }
  9550. soc->wlan_cfg_ctx->rxdma1_enable = 0;
  9551. break;
  9552. #endif /* QCA_WIFI_QCA6390 || QCA_WIFI_QCA6490 || QCA_WIFI_QCA6750 */
  9553. case TARGET_TYPE_QCA8074:
  9554. wlan_cfg_set_reo_dst_ring_size(soc->wlan_cfg_ctx,
  9555. REO_DST_RING_SIZE_QCA8074);
  9556. wlan_cfg_set_raw_mode_war(soc->wlan_cfg_ctx, true);
  9557. soc->da_war_enabled = true;
  9558. soc->is_rx_fse_full_cache_invalidate_war_enabled = true;
  9559. break;
  9560. case TARGET_TYPE_QCA8074V2:
  9561. case TARGET_TYPE_QCA6018:
  9562. wlan_cfg_set_reo_dst_ring_size(soc->wlan_cfg_ctx,
  9563. REO_DST_RING_SIZE_QCA8074);
  9564. wlan_cfg_set_raw_mode_war(soc->wlan_cfg_ctx, false);
  9565. soc->hw_nac_monitor_support = 1;
  9566. soc->ast_override_support = 1;
  9567. soc->per_tid_basize_max_tid = 8;
  9568. soc->num_hw_dscp_tid_map = HAL_MAX_HW_DSCP_TID_V2_MAPS;
  9569. soc->da_war_enabled = false;
  9570. soc->is_rx_fse_full_cache_invalidate_war_enabled = true;
  9571. break;
  9572. case TARGET_TYPE_QCN9000:
  9573. wlan_cfg_set_reo_dst_ring_size(soc->wlan_cfg_ctx,
  9574. REO_DST_RING_SIZE_QCN9000);
  9575. soc->ast_override_support = 1;
  9576. soc->da_war_enabled = false;
  9577. wlan_cfg_set_raw_mode_war(soc->wlan_cfg_ctx, false);
  9578. soc->hw_nac_monitor_support = 1;
  9579. soc->per_tid_basize_max_tid = 8;
  9580. soc->num_hw_dscp_tid_map = HAL_MAX_HW_DSCP_TID_V2_MAPS;
  9581. soc->lmac_polled_mode = 1;
  9582. break;
  9583. default:
  9584. qdf_print("%s: Unknown tgt type %d\n", __func__, target_type);
  9585. qdf_assert_always(0);
  9586. break;
  9587. }
  9588. dp_soc_set_interrupt_mode(soc);
  9589. if (soc->cdp_soc.ol_ops->get_con_mode &&
  9590. soc->cdp_soc.ol_ops->get_con_mode() ==
  9591. QDF_GLOBAL_MONITOR_MODE)
  9592. is_monitor_mode = true;
  9593. wlan_cfg_fill_interrupt_mask(soc->wlan_cfg_ctx, soc->intr_mode,
  9594. is_monitor_mode);
  9595. wlan_cfg_set_rx_hash(soc->wlan_cfg_ctx,
  9596. cfg_get(soc->ctrl_psoc, CFG_DP_RX_HASH));
  9597. soc->cce_disable = false;
  9598. qdf_atomic_init(&soc->num_tx_outstanding);
  9599. soc->num_tx_allowed =
  9600. wlan_cfg_get_dp_soc_tx_device_limit(soc->wlan_cfg_ctx);
  9601. if (soc->cdp_soc.ol_ops->get_dp_cfg_param) {
  9602. int ret = soc->cdp_soc.ol_ops->get_dp_cfg_param(soc->ctrl_psoc,
  9603. CDP_CFG_MAX_PEER_ID);
  9604. if (ret != -EINVAL) {
  9605. wlan_cfg_set_max_peer_id(soc->wlan_cfg_ctx, ret);
  9606. }
  9607. ret = soc->cdp_soc.ol_ops->get_dp_cfg_param(soc->ctrl_psoc,
  9608. CDP_CFG_CCE_DISABLE);
  9609. if (ret == 1)
  9610. soc->cce_disable = true;
  9611. }
  9612. qdf_spinlock_create(&soc->peer_ref_mutex);
  9613. qdf_spinlock_create(&soc->ast_lock);
  9614. qdf_spinlock_create(&soc->reo_desc_freelist_lock);
  9615. qdf_list_create(&soc->reo_desc_freelist, REO_DESC_FREELIST_SIZE);
  9616. /* fill the tx/rx cpu ring map*/
  9617. dp_soc_set_txrx_ring_map(soc);
  9618. qdf_spinlock_create(&soc->htt_stats.lock);
  9619. /* initialize work queue for stats processing */
  9620. qdf_create_work(0, &soc->htt_stats.work, htt_t2h_stats_handler, soc);
  9621. return soc;
  9622. }
  9623. /**
  9624. * dp_soc_init_wifi3() - Initialize txrx SOC
  9625. * @soc: Opaque DP SOC handle
  9626. * @ctrl_psoc: Opaque SOC handle from control plane(Unused)
  9627. * @hif_handle: Opaque HIF handle
  9628. * @htc_handle: Opaque HTC handle
  9629. * @qdf_osdev: QDF device (Unused)
  9630. * @ol_ops: Offload Operations (Unused)
  9631. * @device_id: Device ID (Unused)
  9632. *
  9633. * Return: DP SOC handle on success, NULL on failure
  9634. */
  9635. void *dp_soc_init_wifi3(struct cdp_soc_t *soc,
  9636. struct cdp_ctrl_objmgr_psoc *ctrl_psoc,
  9637. struct hif_opaque_softc *hif_handle,
  9638. HTC_HANDLE htc_handle, qdf_device_t qdf_osdev,
  9639. struct ol_if_ops *ol_ops, uint16_t device_id)
  9640. {
  9641. return dp_soc_init((struct dp_soc *)soc, htc_handle, hif_handle);
  9642. }
  9643. #endif
  9644. /*
  9645. * dp_get_pdev_for_mac_id() - Return pdev for mac_id
  9646. *
  9647. * @soc: handle to DP soc
  9648. * @mac_id: MAC id
  9649. *
  9650. * Return: Return pdev corresponding to MAC
  9651. */
  9652. void *dp_get_pdev_for_mac_id(struct dp_soc *soc, uint32_t mac_id)
  9653. {
  9654. if (wlan_cfg_per_pdev_lmac_ring(soc->wlan_cfg_ctx))
  9655. return soc->pdev_list[mac_id];
  9656. /* Typically for MCL as there only 1 PDEV*/
  9657. return soc->pdev_list[0];
  9658. }
  9659. /*
  9660. * dp_is_hw_dbs_enable() - Procedure to check if DBS is supported
  9661. * @soc: DP SoC context
  9662. * @max_mac_rings: No of MAC rings
  9663. *
  9664. * Return: None
  9665. */
  9666. static
  9667. void dp_is_hw_dbs_enable(struct dp_soc *soc,
  9668. int *max_mac_rings)
  9669. {
  9670. bool dbs_enable = false;
  9671. if (soc->cdp_soc.ol_ops->is_hw_dbs_2x2_capable)
  9672. dbs_enable = soc->cdp_soc.ol_ops->
  9673. is_hw_dbs_2x2_capable((void *)soc->ctrl_psoc);
  9674. *max_mac_rings = (dbs_enable)?(*max_mac_rings):1;
  9675. }
  9676. #if defined(WLAN_CFR_ENABLE) && defined(WLAN_ENH_CFR_ENABLE)
  9677. /*
  9678. * dp_cfr_filter() - Configure HOST RX monitor status ring for CFR
  9679. * @soc_hdl: Datapath soc handle
  9680. * @pdev_id: id of data path pdev handle
  9681. * @enable: Enable/Disable CFR
  9682. * @filter_val: Flag to select Filter for monitor mode
  9683. */
  9684. static void dp_cfr_filter(struct cdp_soc_t *soc_hdl,
  9685. uint8_t pdev_id,
  9686. bool enable,
  9687. struct cdp_monitor_filter *filter_val)
  9688. {
  9689. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9690. struct dp_pdev *pdev = NULL;
  9691. struct htt_rx_ring_tlv_filter htt_tlv_filter = {0};
  9692. int max_mac_rings;
  9693. uint8_t mac_id = 0;
  9694. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  9695. if (!pdev) {
  9696. dp_err("pdev is NULL");
  9697. return;
  9698. }
  9699. if (pdev->monitor_vdev) {
  9700. dp_info("No action is needed since monitor mode is enabled\n");
  9701. return;
  9702. }
  9703. soc = pdev->soc;
  9704. pdev->cfr_rcc_mode = false;
  9705. max_mac_rings = wlan_cfg_get_num_mac_rings(pdev->wlan_cfg_ctx);
  9706. dp_is_hw_dbs_enable(soc, &max_mac_rings);
  9707. dp_debug("Max_mac_rings %d", max_mac_rings);
  9708. dp_info("enable : %d, mode: 0x%x", enable, filter_val->mode);
  9709. if (enable) {
  9710. pdev->cfr_rcc_mode = true;
  9711. htt_tlv_filter.ppdu_start = 1;
  9712. htt_tlv_filter.ppdu_end = 1;
  9713. htt_tlv_filter.ppdu_end_user_stats = 1;
  9714. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  9715. htt_tlv_filter.ppdu_end_status_done = 1;
  9716. htt_tlv_filter.mpdu_start = 1;
  9717. htt_tlv_filter.offset_valid = false;
  9718. htt_tlv_filter.enable_fp =
  9719. (filter_val->mode & MON_FILTER_PASS) ? 1 : 0;
  9720. htt_tlv_filter.enable_md = 0;
  9721. htt_tlv_filter.enable_mo =
  9722. (filter_val->mode & MON_FILTER_OTHER) ? 1 : 0;
  9723. htt_tlv_filter.fp_mgmt_filter = filter_val->fp_mgmt;
  9724. htt_tlv_filter.fp_ctrl_filter = filter_val->fp_ctrl;
  9725. htt_tlv_filter.fp_data_filter = filter_val->fp_data;
  9726. htt_tlv_filter.mo_mgmt_filter = filter_val->mo_mgmt;
  9727. htt_tlv_filter.mo_ctrl_filter = filter_val->mo_ctrl;
  9728. htt_tlv_filter.mo_data_filter = filter_val->mo_data;
  9729. }
  9730. for (mac_id = 0; mac_id < max_mac_rings; mac_id++) {
  9731. int mac_for_pdev =
  9732. dp_get_mac_id_for_pdev(mac_id,
  9733. pdev->pdev_id);
  9734. htt_h2t_rx_ring_cfg(soc->htt_handle,
  9735. mac_for_pdev,
  9736. soc->rxdma_mon_status_ring[mac_id]
  9737. .hal_srng,
  9738. RXDMA_MONITOR_STATUS,
  9739. RX_BUFFER_SIZE,
  9740. &htt_tlv_filter);
  9741. }
  9742. }
  9743. /**
  9744. * dp_get_cfr_rcc() - get cfr rcc config
  9745. * @soc_hdl: Datapath soc handle
  9746. * @pdev_id: id of objmgr pdev
  9747. *
  9748. * Return: true/false based on cfr mode setting
  9749. */
  9750. static
  9751. bool dp_get_cfr_rcc(struct cdp_soc_t *soc_hdl, uint8_t pdev_id)
  9752. {
  9753. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  9754. struct dp_pdev *pdev = NULL;
  9755. pdev = dp_get_pdev_from_soc_pdev_id_wifi3(soc, pdev_id);
  9756. if (!pdev) {
  9757. dp_err("pdev is NULL");
  9758. return false;
  9759. }
  9760. return pdev->cfr_rcc_mode;
  9761. }
  9762. /**
  9763. * dp_set_cfr_rcc() - enable/disable cfr rcc config
  9764. * @soc_hdl: Datapath soc handle
  9765. * @pdev_id: id of objmgr pdev
  9766. * @enable: Enable/Disable cfr rcc mode
  9767. *
  9768. * Return: none
  9769. */
  9770. static
  9771. void dp_set_cfr_rcc(struct cdp_soc_t *soc_hdl, uint8_t pdev_id, bool enable)
  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;
  9779. }
  9780. pdev->cfr_rcc_mode = enable;
  9781. }
  9782. #endif
  9783. /*
  9784. * dp_is_soc_reinit() - Check if soc reinit is true
  9785. * @soc: DP SoC context
  9786. *
  9787. * Return: true or false
  9788. */
  9789. bool dp_is_soc_reinit(struct dp_soc *soc)
  9790. {
  9791. return soc->dp_soc_reinit;
  9792. }
  9793. /*
  9794. * dp_set_pktlog_wifi3() - attach txrx vdev
  9795. * @pdev: Datapath PDEV handle
  9796. * @event: which event's notifications are being subscribed to
  9797. * @enable: WDI event subscribe or not. (True or False)
  9798. *
  9799. * Return: Success, NULL on failure
  9800. */
  9801. #ifdef WDI_EVENT_ENABLE
  9802. int dp_set_pktlog_wifi3(struct dp_pdev *pdev, uint32_t event,
  9803. bool enable)
  9804. {
  9805. struct dp_soc *soc = NULL;
  9806. struct htt_rx_ring_tlv_filter htt_tlv_filter = {0};
  9807. int max_mac_rings = wlan_cfg_get_num_mac_rings
  9808. (pdev->wlan_cfg_ctx);
  9809. uint8_t mac_id = 0;
  9810. soc = pdev->soc;
  9811. dp_is_hw_dbs_enable(soc, &max_mac_rings);
  9812. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_DEBUG,
  9813. FL("Max_mac_rings %d "),
  9814. max_mac_rings);
  9815. if (enable) {
  9816. switch (event) {
  9817. case WDI_EVENT_RX_DESC:
  9818. if (pdev->monitor_vdev) {
  9819. /* Nothing needs to be done if monitor mode is
  9820. * enabled
  9821. */
  9822. return 0;
  9823. }
  9824. if (pdev->rx_pktlog_mode != DP_RX_PKTLOG_FULL) {
  9825. pdev->rx_pktlog_mode = DP_RX_PKTLOG_FULL;
  9826. htt_tlv_filter.mpdu_start = 1;
  9827. htt_tlv_filter.msdu_start = 1;
  9828. htt_tlv_filter.msdu_end = 1;
  9829. htt_tlv_filter.mpdu_end = 1;
  9830. htt_tlv_filter.packet_header = 1;
  9831. htt_tlv_filter.attention = 1;
  9832. htt_tlv_filter.ppdu_start = 1;
  9833. htt_tlv_filter.ppdu_end = 1;
  9834. htt_tlv_filter.ppdu_end_user_stats = 1;
  9835. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  9836. htt_tlv_filter.ppdu_end_status_done = 1;
  9837. htt_tlv_filter.enable_fp = 1;
  9838. htt_tlv_filter.fp_mgmt_filter = FILTER_MGMT_ALL;
  9839. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_ALL;
  9840. htt_tlv_filter.fp_data_filter = FILTER_DATA_ALL;
  9841. htt_tlv_filter.mo_mgmt_filter = FILTER_MGMT_ALL;
  9842. htt_tlv_filter.mo_ctrl_filter = FILTER_CTRL_ALL;
  9843. htt_tlv_filter.mo_data_filter = FILTER_DATA_ALL;
  9844. htt_tlv_filter.offset_valid = false;
  9845. for (mac_id = 0; mac_id < max_mac_rings;
  9846. mac_id++) {
  9847. int pdev_id = pdev->pdev_id;
  9848. int mac_for_pdev =
  9849. dp_get_mac_id_for_pdev(mac_id,
  9850. pdev_id);
  9851. /*
  9852. * Obtain LMAC id from pdev for
  9853. * accessing LMAC ring from SOC
  9854. */
  9855. int lmac_id =
  9856. dp_get_lmac_id_for_pdev_id(soc,
  9857. mac_id,
  9858. pdev_id);
  9859. htt_h2t_rx_ring_cfg(soc->htt_handle,
  9860. mac_for_pdev,
  9861. soc->rxdma_mon_status_ring[lmac_id]
  9862. .hal_srng,
  9863. RXDMA_MONITOR_STATUS,
  9864. RX_BUFFER_SIZE,
  9865. &htt_tlv_filter);
  9866. }
  9867. if (soc->reap_timer_init)
  9868. qdf_timer_mod(&soc->mon_reap_timer,
  9869. DP_INTR_POLL_TIMER_MS);
  9870. }
  9871. break;
  9872. case WDI_EVENT_LITE_RX:
  9873. if (pdev->monitor_vdev) {
  9874. /* Nothing needs to be done if monitor mode is
  9875. * enabled
  9876. */
  9877. return 0;
  9878. }
  9879. if (pdev->rx_pktlog_mode != DP_RX_PKTLOG_LITE) {
  9880. pdev->rx_pktlog_mode = DP_RX_PKTLOG_LITE;
  9881. htt_tlv_filter.ppdu_start = 1;
  9882. htt_tlv_filter.ppdu_end = 1;
  9883. htt_tlv_filter.ppdu_end_user_stats = 1;
  9884. htt_tlv_filter.ppdu_end_user_stats_ext = 1;
  9885. htt_tlv_filter.ppdu_end_status_done = 1;
  9886. htt_tlv_filter.mpdu_start = 1;
  9887. htt_tlv_filter.enable_fp = 1;
  9888. htt_tlv_filter.fp_mgmt_filter = FILTER_MGMT_ALL;
  9889. htt_tlv_filter.fp_ctrl_filter = FILTER_CTRL_ALL;
  9890. htt_tlv_filter.fp_data_filter = FILTER_DATA_ALL;
  9891. htt_tlv_filter.mo_mgmt_filter = FILTER_MGMT_ALL;
  9892. htt_tlv_filter.mo_ctrl_filter = FILTER_CTRL_ALL;
  9893. htt_tlv_filter.mo_data_filter = FILTER_DATA_ALL;
  9894. htt_tlv_filter.offset_valid = false;
  9895. for (mac_id = 0; mac_id < max_mac_rings;
  9896. mac_id++) {
  9897. int pdev_id = pdev->pdev_id;
  9898. int mac_for_pdev =
  9899. dp_get_mac_id_for_pdev(mac_id,
  9900. pdev_id);
  9901. /*
  9902. * Obtain lmac id from pdev to access
  9903. * the LMAC ring in soc context
  9904. */
  9905. int lmac_id =
  9906. dp_get_lmac_id_for_pdev_id(soc,
  9907. mac_id,
  9908. pdev_id);
  9909. htt_h2t_rx_ring_cfg(soc->htt_handle,
  9910. mac_for_pdev,
  9911. soc->rxdma_mon_status_ring[lmac_id]
  9912. .hal_srng,
  9913. RXDMA_MONITOR_STATUS,
  9914. RX_BUFFER_SIZE_PKTLOG_LITE,
  9915. &htt_tlv_filter);
  9916. }
  9917. if (soc->reap_timer_init)
  9918. qdf_timer_mod(&soc->mon_reap_timer,
  9919. DP_INTR_POLL_TIMER_MS);
  9920. }
  9921. break;
  9922. case WDI_EVENT_LITE_T2H:
  9923. if (pdev->monitor_vdev) {
  9924. /* Nothing needs to be done if monitor mode is
  9925. * enabled
  9926. */
  9927. return 0;
  9928. }
  9929. for (mac_id = 0; mac_id < max_mac_rings; mac_id++) {
  9930. int mac_for_pdev = dp_get_mac_id_for_pdev(
  9931. mac_id, pdev->pdev_id);
  9932. pdev->pktlog_ppdu_stats = true;
  9933. dp_h2t_cfg_stats_msg_send(pdev,
  9934. DP_PPDU_TXLITE_STATS_BITMASK_CFG,
  9935. mac_for_pdev);
  9936. }
  9937. break;
  9938. default:
  9939. /* Nothing needs to be done for other pktlog types */
  9940. break;
  9941. }
  9942. } else {
  9943. switch (event) {
  9944. case WDI_EVENT_RX_DESC:
  9945. case WDI_EVENT_LITE_RX:
  9946. if (pdev->monitor_vdev) {
  9947. /* Nothing needs to be done if monitor mode is
  9948. * enabled
  9949. */
  9950. return 0;
  9951. }
  9952. if (pdev->rx_pktlog_mode != DP_RX_PKTLOG_DISABLED) {
  9953. pdev->rx_pktlog_mode = DP_RX_PKTLOG_DISABLED;
  9954. for (mac_id = 0; mac_id < max_mac_rings;
  9955. mac_id++) {
  9956. int pdev_id = pdev->pdev_id;
  9957. int mac_for_pdev =
  9958. dp_get_mac_id_for_pdev(mac_id,
  9959. pdev_id);
  9960. /*
  9961. * Obtain lmac id from pdev to access
  9962. * the LMAC ring in soc context
  9963. */
  9964. int lmac_id =
  9965. dp_get_lmac_id_for_pdev_id(soc,
  9966. mac_id,
  9967. pdev_id);
  9968. htt_h2t_rx_ring_cfg(soc->htt_handle,
  9969. mac_for_pdev,
  9970. soc->rxdma_mon_status_ring[lmac_id]
  9971. .hal_srng,
  9972. RXDMA_MONITOR_STATUS,
  9973. RX_BUFFER_SIZE,
  9974. &htt_tlv_filter);
  9975. }
  9976. if (soc->reap_timer_init)
  9977. qdf_timer_stop(&soc->mon_reap_timer);
  9978. }
  9979. break;
  9980. case WDI_EVENT_LITE_T2H:
  9981. if (pdev->monitor_vdev) {
  9982. /* Nothing needs to be done if monitor mode is
  9983. * enabled
  9984. */
  9985. return 0;
  9986. }
  9987. /* To disable HTT_H2T_MSG_TYPE_PPDU_STATS_CFG in FW
  9988. * passing value 0. Once these macros will define in htt
  9989. * header file will use proper macros
  9990. */
  9991. for (mac_id = 0; mac_id < max_mac_rings; mac_id++) {
  9992. int mac_for_pdev =
  9993. dp_get_mac_id_for_pdev(mac_id,
  9994. pdev->pdev_id);
  9995. pdev->pktlog_ppdu_stats = false;
  9996. if (!pdev->enhanced_stats_en && !pdev->tx_sniffer_enable && !pdev->mcopy_mode) {
  9997. dp_h2t_cfg_stats_msg_send(pdev, 0,
  9998. mac_for_pdev);
  9999. } else if (pdev->tx_sniffer_enable || pdev->mcopy_mode) {
  10000. dp_h2t_cfg_stats_msg_send(pdev, DP_PPDU_STATS_CFG_SNIFFER,
  10001. mac_for_pdev);
  10002. } else if (pdev->enhanced_stats_en) {
  10003. dp_h2t_cfg_stats_msg_send(pdev, DP_PPDU_STATS_CFG_ENH_STATS,
  10004. mac_for_pdev);
  10005. }
  10006. }
  10007. break;
  10008. default:
  10009. /* Nothing needs to be done for other pktlog types */
  10010. break;
  10011. }
  10012. }
  10013. return 0;
  10014. }
  10015. #endif
  10016. /**
  10017. * dp_bucket_index() - Return index from array
  10018. *
  10019. * @delay: delay measured
  10020. * @array: array used to index corresponding delay
  10021. *
  10022. * Return: index
  10023. */
  10024. static uint8_t dp_bucket_index(uint32_t delay, uint16_t *array)
  10025. {
  10026. uint8_t i = CDP_DELAY_BUCKET_0;
  10027. for (; i < CDP_DELAY_BUCKET_MAX; i++) {
  10028. if (delay >= array[i] && delay <= array[i + 1])
  10029. return i;
  10030. }
  10031. return (CDP_DELAY_BUCKET_MAX - 1);
  10032. }
  10033. /**
  10034. * dp_fill_delay_buckets() - Fill delay statistics bucket for each
  10035. * type of delay
  10036. *
  10037. * @pdev: pdev handle
  10038. * @delay: delay in ms
  10039. * @tid: tid value
  10040. * @mode: type of tx delay mode
  10041. * @ring_id: ring number
  10042. * Return: pointer to cdp_delay_stats structure
  10043. */
  10044. static struct cdp_delay_stats *
  10045. dp_fill_delay_buckets(struct dp_pdev *pdev, uint32_t delay,
  10046. uint8_t tid, uint8_t mode, uint8_t ring_id)
  10047. {
  10048. uint8_t delay_index = 0;
  10049. struct cdp_tid_tx_stats *tstats =
  10050. &pdev->stats.tid_stats.tid_tx_stats[ring_id][tid];
  10051. struct cdp_tid_rx_stats *rstats =
  10052. &pdev->stats.tid_stats.tid_rx_stats[ring_id][tid];
  10053. /*
  10054. * cdp_fw_to_hw_delay_range
  10055. * Fw to hw delay ranges in milliseconds
  10056. */
  10057. uint16_t cdp_fw_to_hw_delay[CDP_DELAY_BUCKET_MAX] = {
  10058. 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 250, 500};
  10059. /*
  10060. * cdp_sw_enq_delay_range
  10061. * Software enqueue delay ranges in milliseconds
  10062. */
  10063. uint16_t cdp_sw_enq_delay[CDP_DELAY_BUCKET_MAX] = {
  10064. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
  10065. /*
  10066. * cdp_intfrm_delay_range
  10067. * Interframe delay ranges in milliseconds
  10068. */
  10069. uint16_t cdp_intfrm_delay[CDP_DELAY_BUCKET_MAX] = {
  10070. 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60};
  10071. /*
  10072. * Update delay stats in proper bucket
  10073. */
  10074. switch (mode) {
  10075. /* Software Enqueue delay ranges */
  10076. case CDP_DELAY_STATS_SW_ENQ:
  10077. delay_index = dp_bucket_index(delay, cdp_sw_enq_delay);
  10078. tstats->swq_delay.delay_bucket[delay_index]++;
  10079. return &tstats->swq_delay;
  10080. /* Tx Completion delay ranges */
  10081. case CDP_DELAY_STATS_FW_HW_TRANSMIT:
  10082. delay_index = dp_bucket_index(delay, cdp_fw_to_hw_delay);
  10083. tstats->hwtx_delay.delay_bucket[delay_index]++;
  10084. return &tstats->hwtx_delay;
  10085. /* Interframe tx delay ranges */
  10086. case CDP_DELAY_STATS_TX_INTERFRAME:
  10087. delay_index = dp_bucket_index(delay, cdp_intfrm_delay);
  10088. tstats->intfrm_delay.delay_bucket[delay_index]++;
  10089. return &tstats->intfrm_delay;
  10090. /* Interframe rx delay ranges */
  10091. case CDP_DELAY_STATS_RX_INTERFRAME:
  10092. delay_index = dp_bucket_index(delay, cdp_intfrm_delay);
  10093. rstats->intfrm_delay.delay_bucket[delay_index]++;
  10094. return &rstats->intfrm_delay;
  10095. /* Ring reap to indication to network stack */
  10096. case CDP_DELAY_STATS_REAP_STACK:
  10097. delay_index = dp_bucket_index(delay, cdp_intfrm_delay);
  10098. rstats->to_stack_delay.delay_bucket[delay_index]++;
  10099. return &rstats->to_stack_delay;
  10100. default:
  10101. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  10102. "%s Incorrect delay mode: %d", __func__, mode);
  10103. }
  10104. return NULL;
  10105. }
  10106. /**
  10107. * dp_update_delay_stats() - Update delay statistics in structure
  10108. * and fill min, max and avg delay
  10109. *
  10110. * @pdev: pdev handle
  10111. * @delay: delay in ms
  10112. * @tid: tid value
  10113. * @mode: type of tx delay mode
  10114. * @ring id: ring number
  10115. * Return: none
  10116. */
  10117. void dp_update_delay_stats(struct dp_pdev *pdev, uint32_t delay,
  10118. uint8_t tid, uint8_t mode, uint8_t ring_id)
  10119. {
  10120. struct cdp_delay_stats *dstats = NULL;
  10121. /*
  10122. * Delay ranges are different for different delay modes
  10123. * Get the correct index to update delay bucket
  10124. */
  10125. dstats = dp_fill_delay_buckets(pdev, delay, tid, mode, ring_id);
  10126. if (qdf_unlikely(!dstats))
  10127. return;
  10128. if (delay != 0) {
  10129. /*
  10130. * Compute minimum,average and maximum
  10131. * delay
  10132. */
  10133. if (delay < dstats->min_delay)
  10134. dstats->min_delay = delay;
  10135. if (delay > dstats->max_delay)
  10136. dstats->max_delay = delay;
  10137. /*
  10138. * Average over delay measured till now
  10139. */
  10140. if (!dstats->avg_delay)
  10141. dstats->avg_delay = delay;
  10142. else
  10143. dstats->avg_delay = ((delay + dstats->avg_delay) / 2);
  10144. }
  10145. }
  10146. /**
  10147. * dp_get_peer_mac_list(): function to get peer mac list of vdev
  10148. * @soc: Datapath soc handle
  10149. * @vdev_id: vdev id
  10150. * @newmac: Table of the clients mac
  10151. * @mac_cnt: No. of MACs required
  10152. *
  10153. * return: no of clients
  10154. */
  10155. uint16_t dp_get_peer_mac_list(ol_txrx_soc_handle soc, uint8_t vdev_id,
  10156. u_int8_t newmac[][QDF_MAC_ADDR_SIZE],
  10157. u_int16_t mac_cnt)
  10158. {
  10159. struct dp_vdev *vdev =
  10160. dp_get_vdev_from_soc_vdev_id_wifi3((struct dp_soc *)soc,
  10161. vdev_id);
  10162. struct dp_soc *dp_soc = (struct dp_soc *)soc;
  10163. struct dp_peer *peer;
  10164. uint16_t new_mac_cnt = 0;
  10165. if (!vdev)
  10166. return new_mac_cnt;
  10167. qdf_spin_lock_bh(&dp_soc->peer_ref_mutex);
  10168. TAILQ_FOREACH(peer, &vdev->peer_list, peer_list_elem) {
  10169. if (peer->bss_peer)
  10170. continue;
  10171. if (new_mac_cnt < mac_cnt) {
  10172. WLAN_ADDR_COPY(newmac[new_mac_cnt], peer->mac_addr.raw);
  10173. new_mac_cnt++;
  10174. }
  10175. }
  10176. qdf_spin_unlock_bh(&dp_soc->peer_ref_mutex);
  10177. return new_mac_cnt;
  10178. }