dp_main.c 263 KB

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