dp_main.c 259 KB

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