dp_main.c 279 KB

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