dp_main.c 280 KB

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