dp_main.c 312 KB

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