dp_main.c 268 KB

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