dp_main.c 268 KB

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