dp_main.c 280 KB

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