dp_main.c 281 KB

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