dp_main.c 277 KB

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