pci.c 204 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/completion.h>
  7. #include <linux/io.h>
  8. #include <linux/irq.h>
  9. #include <linux/memblock.h>
  10. #include <linux/module.h>
  11. #include <linux/msi.h>
  12. #include <linux/of.h>
  13. #include <linux/of_gpio.h>
  14. #include <linux/pm_runtime.h>
  15. #include <linux/suspend.h>
  16. #include <linux/version.h>
  17. #include <linux/sched.h>
  18. #include "main.h"
  19. #include "bus.h"
  20. #include "debug.h"
  21. #include "pci.h"
  22. #include "pci_platform.h"
  23. #include "reg.h"
  24. #define PCI_LINK_UP 1
  25. #define PCI_LINK_DOWN 0
  26. #define SAVE_PCI_CONFIG_SPACE 1
  27. #define RESTORE_PCI_CONFIG_SPACE 0
  28. #define PCI_BAR_NUM 0
  29. #define PCI_INVALID_READ(val) ((val) == U32_MAX)
  30. #define PCI_DMA_MASK_32_BIT DMA_BIT_MASK(32)
  31. #define PCI_DMA_MASK_36_BIT DMA_BIT_MASK(36)
  32. #define PCI_DMA_MASK_64_BIT DMA_BIT_MASK(64)
  33. #define MHI_NODE_NAME "qcom,mhi"
  34. #define MHI_MSI_NAME "MHI"
  35. #define QCA6390_PATH_PREFIX "qca6390/"
  36. #define QCA6490_PATH_PREFIX "qca6490/"
  37. #define QCN7605_PATH_PREFIX "qcn7605/"
  38. #define KIWI_PATH_PREFIX "kiwi/"
  39. #define MANGO_PATH_PREFIX "mango/"
  40. #define PEACH_PATH_PREFIX "peach/"
  41. #define DEFAULT_PHY_M3_FILE_NAME "m3.bin"
  42. #define DEFAULT_AUX_FILE_NAME "aux_ucode.elf"
  43. #define DEFAULT_PHY_UCODE_FILE_NAME "phy_ucode.elf"
  44. #define TME_PATCH_FILE_NAME_1_0 "tmel_peach_10.elf"
  45. #define TME_PATCH_FILE_NAME_2_0 "tmel_peach_20.elf"
  46. #define PHY_UCODE_V2_FILE_NAME "phy_ucode20.elf"
  47. #define DEFAULT_FW_FILE_NAME "amss.bin"
  48. #define FW_V2_FILE_NAME "amss20.bin"
  49. #define DEVICE_MAJOR_VERSION_MASK 0xF
  50. #define WAKE_MSI_NAME "WAKE"
  51. #define DEV_RDDM_TIMEOUT 5000
  52. #define WAKE_EVENT_TIMEOUT 5000
  53. #ifdef CONFIG_CNSS_EMULATION
  54. #define EMULATION_HW 1
  55. #else
  56. #define EMULATION_HW 0
  57. #endif
  58. #define RAMDUMP_SIZE_DEFAULT 0x420000
  59. #define CNSS_256KB_SIZE 0x40000
  60. #define DEVICE_RDDM_COOKIE 0xCAFECACE
  61. static bool cnss_driver_registered;
  62. static DEFINE_SPINLOCK(pci_link_down_lock);
  63. static DEFINE_SPINLOCK(pci_reg_window_lock);
  64. static DEFINE_SPINLOCK(time_sync_lock);
  65. #define MHI_TIMEOUT_OVERWRITE_MS (plat_priv->ctrl_params.mhi_timeout)
  66. #define MHI_M2_TIMEOUT_MS (plat_priv->ctrl_params.mhi_m2_timeout)
  67. #define WLAON_PWR_CTRL_SHUTDOWN_DELAY_MIN_US 1000
  68. #define WLAON_PWR_CTRL_SHUTDOWN_DELAY_MAX_US 2000
  69. #define RDDM_LINK_RECOVERY_RETRY 20
  70. #define RDDM_LINK_RECOVERY_RETRY_DELAY_MS 20
  71. #define FORCE_WAKE_DELAY_MIN_US 4000
  72. #define FORCE_WAKE_DELAY_MAX_US 6000
  73. #define FORCE_WAKE_DELAY_TIMEOUT_US 60000
  74. #define REG_RETRY_MAX_TIMES 3
  75. #define MHI_SUSPEND_RETRY_MAX_TIMES 3
  76. #define MHI_SUSPEND_RETRY_DELAY_US 5000
  77. #define BOOT_DEBUG_TIMEOUT_MS 7000
  78. #define HANG_DATA_LENGTH 384
  79. #define HST_HANG_DATA_OFFSET ((3 * 1024 * 1024) - HANG_DATA_LENGTH)
  80. #define HSP_HANG_DATA_OFFSET ((2 * 1024 * 1024) - HANG_DATA_LENGTH)
  81. #define GNO_HANG_DATA_OFFSET (0x7d000 - HANG_DATA_LENGTH)
  82. #define AFC_SLOT_SIZE 0x1000
  83. #define AFC_MAX_SLOT 2
  84. #define AFC_MEM_SIZE (AFC_SLOT_SIZE * AFC_MAX_SLOT)
  85. #define AFC_AUTH_STATUS_OFFSET 1
  86. #define AFC_AUTH_SUCCESS 1
  87. #define AFC_AUTH_ERROR 0
  88. static const struct mhi_channel_config cnss_mhi_channels[] = {
  89. {
  90. .num = 0,
  91. .name = "LOOPBACK",
  92. .num_elements = 32,
  93. .event_ring = 1,
  94. .dir = DMA_TO_DEVICE,
  95. .ee_mask = 0x4,
  96. .pollcfg = 0,
  97. .doorbell = MHI_DB_BRST_DISABLE,
  98. .lpm_notify = false,
  99. .offload_channel = false,
  100. .doorbell_mode_switch = false,
  101. .auto_queue = false,
  102. },
  103. {
  104. .num = 1,
  105. .name = "LOOPBACK",
  106. .num_elements = 32,
  107. .event_ring = 1,
  108. .dir = DMA_FROM_DEVICE,
  109. .ee_mask = 0x4,
  110. .pollcfg = 0,
  111. .doorbell = MHI_DB_BRST_DISABLE,
  112. .lpm_notify = false,
  113. .offload_channel = false,
  114. .doorbell_mode_switch = false,
  115. .auto_queue = false,
  116. },
  117. {
  118. .num = 4,
  119. .name = "DIAG",
  120. .num_elements = 64,
  121. .event_ring = 1,
  122. .dir = DMA_TO_DEVICE,
  123. .ee_mask = 0x4,
  124. .pollcfg = 0,
  125. .doorbell = MHI_DB_BRST_DISABLE,
  126. .lpm_notify = false,
  127. .offload_channel = false,
  128. .doorbell_mode_switch = false,
  129. .auto_queue = false,
  130. },
  131. {
  132. .num = 5,
  133. .name = "DIAG",
  134. .num_elements = 64,
  135. .event_ring = 1,
  136. .dir = DMA_FROM_DEVICE,
  137. .ee_mask = 0x4,
  138. .pollcfg = 0,
  139. .doorbell = MHI_DB_BRST_DISABLE,
  140. .lpm_notify = false,
  141. .offload_channel = false,
  142. .doorbell_mode_switch = false,
  143. .auto_queue = false,
  144. },
  145. {
  146. .num = 20,
  147. .name = "IPCR",
  148. .num_elements = 64,
  149. .event_ring = 1,
  150. .dir = DMA_TO_DEVICE,
  151. .ee_mask = 0x4,
  152. .pollcfg = 0,
  153. .doorbell = MHI_DB_BRST_DISABLE,
  154. .lpm_notify = false,
  155. .offload_channel = false,
  156. .doorbell_mode_switch = false,
  157. .auto_queue = false,
  158. },
  159. {
  160. .num = 21,
  161. .name = "IPCR",
  162. .num_elements = 64,
  163. .event_ring = 1,
  164. .dir = DMA_FROM_DEVICE,
  165. .ee_mask = 0x4,
  166. .pollcfg = 0,
  167. .doorbell = MHI_DB_BRST_DISABLE,
  168. .lpm_notify = false,
  169. .offload_channel = false,
  170. .doorbell_mode_switch = false,
  171. .auto_queue = true,
  172. },
  173. /* All MHI satellite config to be at the end of data struct */
  174. #if IS_ENABLED(CONFIG_MHI_SATELLITE)
  175. {
  176. .num = 50,
  177. .name = "ADSP_0",
  178. .num_elements = 64,
  179. .event_ring = 3,
  180. .dir = DMA_BIDIRECTIONAL,
  181. .ee_mask = 0x4,
  182. .pollcfg = 0,
  183. .doorbell = MHI_DB_BRST_DISABLE,
  184. .lpm_notify = false,
  185. .offload_channel = true,
  186. .doorbell_mode_switch = false,
  187. .auto_queue = false,
  188. },
  189. {
  190. .num = 51,
  191. .name = "ADSP_1",
  192. .num_elements = 64,
  193. .event_ring = 3,
  194. .dir = DMA_BIDIRECTIONAL,
  195. .ee_mask = 0x4,
  196. .pollcfg = 0,
  197. .doorbell = MHI_DB_BRST_DISABLE,
  198. .lpm_notify = false,
  199. .offload_channel = true,
  200. .doorbell_mode_switch = false,
  201. .auto_queue = false,
  202. },
  203. {
  204. .num = 70,
  205. .name = "ADSP_2",
  206. .num_elements = 64,
  207. .event_ring = 3,
  208. .dir = DMA_BIDIRECTIONAL,
  209. .ee_mask = 0x4,
  210. .pollcfg = 0,
  211. .doorbell = MHI_DB_BRST_DISABLE,
  212. .lpm_notify = false,
  213. .offload_channel = true,
  214. .doorbell_mode_switch = false,
  215. .auto_queue = false,
  216. },
  217. {
  218. .num = 71,
  219. .name = "ADSP_3",
  220. .num_elements = 64,
  221. .event_ring = 3,
  222. .dir = DMA_BIDIRECTIONAL,
  223. .ee_mask = 0x4,
  224. .pollcfg = 0,
  225. .doorbell = MHI_DB_BRST_DISABLE,
  226. .lpm_notify = false,
  227. .offload_channel = true,
  228. .doorbell_mode_switch = false,
  229. .auto_queue = false,
  230. },
  231. #endif
  232. };
  233. static const struct mhi_channel_config cnss_mhi_channels_no_diag[] = {
  234. {
  235. .num = 0,
  236. .name = "LOOPBACK",
  237. .num_elements = 32,
  238. .event_ring = 1,
  239. .dir = DMA_TO_DEVICE,
  240. .ee_mask = 0x4,
  241. .pollcfg = 0,
  242. .doorbell = MHI_DB_BRST_DISABLE,
  243. .lpm_notify = false,
  244. .offload_channel = false,
  245. .doorbell_mode_switch = false,
  246. .auto_queue = false,
  247. },
  248. {
  249. .num = 1,
  250. .name = "LOOPBACK",
  251. .num_elements = 32,
  252. .event_ring = 1,
  253. .dir = DMA_FROM_DEVICE,
  254. .ee_mask = 0x4,
  255. .pollcfg = 0,
  256. .doorbell = MHI_DB_BRST_DISABLE,
  257. .lpm_notify = false,
  258. .offload_channel = false,
  259. .doorbell_mode_switch = false,
  260. .auto_queue = false,
  261. },
  262. {
  263. .num = 20,
  264. .name = "IPCR",
  265. .num_elements = 64,
  266. .event_ring = 1,
  267. .dir = DMA_TO_DEVICE,
  268. .ee_mask = 0x4,
  269. .pollcfg = 0,
  270. .doorbell = MHI_DB_BRST_DISABLE,
  271. .lpm_notify = false,
  272. .offload_channel = false,
  273. .doorbell_mode_switch = false,
  274. .auto_queue = false,
  275. },
  276. {
  277. .num = 21,
  278. .name = "IPCR",
  279. .num_elements = 64,
  280. .event_ring = 1,
  281. .dir = DMA_FROM_DEVICE,
  282. .ee_mask = 0x4,
  283. .pollcfg = 0,
  284. .doorbell = MHI_DB_BRST_DISABLE,
  285. .lpm_notify = false,
  286. .offload_channel = false,
  287. .doorbell_mode_switch = false,
  288. .auto_queue = true,
  289. },
  290. /* All MHI satellite config to be at the end of data struct */
  291. #if IS_ENABLED(CONFIG_MHI_SATELLITE)
  292. {
  293. .num = 50,
  294. .name = "ADSP_0",
  295. .num_elements = 64,
  296. .event_ring = 3,
  297. .dir = DMA_BIDIRECTIONAL,
  298. .ee_mask = 0x4,
  299. .pollcfg = 0,
  300. .doorbell = MHI_DB_BRST_DISABLE,
  301. .lpm_notify = false,
  302. .offload_channel = true,
  303. .doorbell_mode_switch = false,
  304. .auto_queue = false,
  305. },
  306. {
  307. .num = 51,
  308. .name = "ADSP_1",
  309. .num_elements = 64,
  310. .event_ring = 3,
  311. .dir = DMA_BIDIRECTIONAL,
  312. .ee_mask = 0x4,
  313. .pollcfg = 0,
  314. .doorbell = MHI_DB_BRST_DISABLE,
  315. .lpm_notify = false,
  316. .offload_channel = true,
  317. .doorbell_mode_switch = false,
  318. .auto_queue = false,
  319. },
  320. {
  321. .num = 70,
  322. .name = "ADSP_2",
  323. .num_elements = 64,
  324. .event_ring = 3,
  325. .dir = DMA_BIDIRECTIONAL,
  326. .ee_mask = 0x4,
  327. .pollcfg = 0,
  328. .doorbell = MHI_DB_BRST_DISABLE,
  329. .lpm_notify = false,
  330. .offload_channel = true,
  331. .doorbell_mode_switch = false,
  332. .auto_queue = false,
  333. },
  334. {
  335. .num = 71,
  336. .name = "ADSP_3",
  337. .num_elements = 64,
  338. .event_ring = 3,
  339. .dir = DMA_BIDIRECTIONAL,
  340. .ee_mask = 0x4,
  341. .pollcfg = 0,
  342. .doorbell = MHI_DB_BRST_DISABLE,
  343. .lpm_notify = false,
  344. .offload_channel = true,
  345. .doorbell_mode_switch = false,
  346. .auto_queue = false,
  347. },
  348. #endif
  349. };
  350. static const struct mhi_channel_config cnss_mhi_channels_genoa[] = {
  351. {
  352. .num = 0,
  353. .name = "LOOPBACK",
  354. .num_elements = 32,
  355. .event_ring = 1,
  356. .dir = DMA_TO_DEVICE,
  357. .ee_mask = 0x4,
  358. .pollcfg = 0,
  359. .doorbell = MHI_DB_BRST_DISABLE,
  360. .lpm_notify = false,
  361. .offload_channel = false,
  362. .doorbell_mode_switch = false,
  363. .auto_queue = false,
  364. },
  365. {
  366. .num = 1,
  367. .name = "LOOPBACK",
  368. .num_elements = 32,
  369. .event_ring = 1,
  370. .dir = DMA_FROM_DEVICE,
  371. .ee_mask = 0x4,
  372. .pollcfg = 0,
  373. .doorbell = MHI_DB_BRST_DISABLE,
  374. .lpm_notify = false,
  375. .offload_channel = false,
  376. .doorbell_mode_switch = false,
  377. .auto_queue = false,
  378. },
  379. {
  380. .num = 4,
  381. .name = "DIAG",
  382. .num_elements = 64,
  383. .event_ring = 1,
  384. .dir = DMA_TO_DEVICE,
  385. .ee_mask = 0x4,
  386. .pollcfg = 0,
  387. .doorbell = MHI_DB_BRST_DISABLE,
  388. .lpm_notify = false,
  389. .offload_channel = false,
  390. .doorbell_mode_switch = false,
  391. .auto_queue = false,
  392. },
  393. {
  394. .num = 5,
  395. .name = "DIAG",
  396. .num_elements = 64,
  397. .event_ring = 1,
  398. .dir = DMA_FROM_DEVICE,
  399. .ee_mask = 0x4,
  400. .pollcfg = 0,
  401. .doorbell = MHI_DB_BRST_DISABLE,
  402. .lpm_notify = false,
  403. .offload_channel = false,
  404. .doorbell_mode_switch = false,
  405. .auto_queue = false,
  406. },
  407. {
  408. .num = 16,
  409. .name = "IPCR",
  410. .num_elements = 64,
  411. .event_ring = 1,
  412. .dir = DMA_TO_DEVICE,
  413. .ee_mask = 0x4,
  414. .pollcfg = 0,
  415. .doorbell = MHI_DB_BRST_DISABLE,
  416. .lpm_notify = false,
  417. .offload_channel = false,
  418. .doorbell_mode_switch = false,
  419. .auto_queue = false,
  420. },
  421. {
  422. .num = 17,
  423. .name = "IPCR",
  424. .num_elements = 64,
  425. .event_ring = 1,
  426. .dir = DMA_FROM_DEVICE,
  427. .ee_mask = 0x4,
  428. .pollcfg = 0,
  429. .doorbell = MHI_DB_BRST_DISABLE,
  430. .lpm_notify = false,
  431. .offload_channel = false,
  432. .doorbell_mode_switch = false,
  433. .auto_queue = true,
  434. },
  435. };
  436. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
  437. static struct mhi_event_config cnss_mhi_events[] = {
  438. #else
  439. static const struct mhi_event_config cnss_mhi_events[] = {
  440. #endif
  441. {
  442. .num_elements = 32,
  443. .irq_moderation_ms = 0,
  444. .irq = 1,
  445. .mode = MHI_DB_BRST_DISABLE,
  446. .data_type = MHI_ER_CTRL,
  447. .priority = 0,
  448. .hardware_event = false,
  449. .client_managed = false,
  450. .offload_channel = false,
  451. },
  452. {
  453. .num_elements = 256,
  454. .irq_moderation_ms = 0,
  455. .irq = 2,
  456. .mode = MHI_DB_BRST_DISABLE,
  457. .priority = 1,
  458. .hardware_event = false,
  459. .client_managed = false,
  460. .offload_channel = false,
  461. },
  462. #if IS_ENABLED(CONFIG_MHI_BUS_MISC)
  463. {
  464. .num_elements = 32,
  465. .irq_moderation_ms = 0,
  466. .irq = 1,
  467. .mode = MHI_DB_BRST_DISABLE,
  468. .data_type = MHI_ER_BW_SCALE,
  469. .priority = 2,
  470. .hardware_event = false,
  471. .client_managed = false,
  472. .offload_channel = false,
  473. },
  474. #endif
  475. #if IS_ENABLED(CONFIG_MHI_SATELLITE)
  476. {
  477. .num_elements = 256,
  478. .irq_moderation_ms = 0,
  479. .irq = 2,
  480. .mode = MHI_DB_BRST_DISABLE,
  481. .data_type = MHI_ER_DATA,
  482. .priority = 1,
  483. .hardware_event = false,
  484. .client_managed = true,
  485. .offload_channel = true,
  486. },
  487. #endif
  488. };
  489. #if IS_ENABLED(CONFIG_MHI_SATELLITE)
  490. #define CNSS_MHI_SATELLITE_CH_CFG_COUNT 4
  491. #define CNSS_MHI_SATELLITE_EVT_COUNT 1
  492. #else
  493. #define CNSS_MHI_SATELLITE_CH_CFG_COUNT 0
  494. #define CNSS_MHI_SATELLITE_EVT_COUNT 0
  495. #endif
  496. static const struct mhi_controller_config cnss_mhi_config_no_diag = {
  497. #if IS_ENABLED(CONFIG_MHI_SATELLITE)
  498. .max_channels = 72,
  499. #else
  500. .max_channels = 32,
  501. #endif
  502. .timeout_ms = 10000,
  503. .use_bounce_buf = false,
  504. .buf_len = 0x8000,
  505. .num_channels = ARRAY_SIZE(cnss_mhi_channels_no_diag),
  506. .ch_cfg = cnss_mhi_channels_no_diag,
  507. .num_events = ARRAY_SIZE(cnss_mhi_events),
  508. .event_cfg = cnss_mhi_events,
  509. .m2_no_db = true,
  510. };
  511. static const struct mhi_controller_config cnss_mhi_config_default = {
  512. #if IS_ENABLED(CONFIG_MHI_SATELLITE)
  513. .max_channels = 72,
  514. #else
  515. .max_channels = 32,
  516. #endif
  517. .timeout_ms = 10000,
  518. .use_bounce_buf = false,
  519. .buf_len = 0x8000,
  520. .num_channels = ARRAY_SIZE(cnss_mhi_channels),
  521. .ch_cfg = cnss_mhi_channels,
  522. .num_events = ARRAY_SIZE(cnss_mhi_events),
  523. .event_cfg = cnss_mhi_events,
  524. .m2_no_db = true,
  525. };
  526. static const struct mhi_controller_config cnss_mhi_config_genoa = {
  527. .max_channels = 32,
  528. .timeout_ms = 10000,
  529. .use_bounce_buf = false,
  530. .buf_len = 0x8000,
  531. .num_channels = ARRAY_SIZE(cnss_mhi_channels_genoa),
  532. .ch_cfg = cnss_mhi_channels_genoa,
  533. .num_events = ARRAY_SIZE(cnss_mhi_events) -
  534. CNSS_MHI_SATELLITE_EVT_COUNT,
  535. .event_cfg = cnss_mhi_events,
  536. .m2_no_db = true,
  537. #if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0))
  538. .bhie_offset = 0x0324,
  539. #endif
  540. };
  541. static const struct mhi_controller_config cnss_mhi_config_no_satellite = {
  542. .max_channels = 32,
  543. .timeout_ms = 10000,
  544. .use_bounce_buf = false,
  545. .buf_len = 0x8000,
  546. .num_channels = ARRAY_SIZE(cnss_mhi_channels) -
  547. CNSS_MHI_SATELLITE_CH_CFG_COUNT,
  548. .ch_cfg = cnss_mhi_channels,
  549. .num_events = ARRAY_SIZE(cnss_mhi_events) -
  550. CNSS_MHI_SATELLITE_EVT_COUNT,
  551. .event_cfg = cnss_mhi_events,
  552. .m2_no_db = true,
  553. };
  554. static struct cnss_pci_reg ce_src[] = {
  555. { "SRC_RING_BASE_LSB", CE_SRC_RING_BASE_LSB_OFFSET },
  556. { "SRC_RING_BASE_MSB", CE_SRC_RING_BASE_MSB_OFFSET },
  557. { "SRC_RING_ID", CE_SRC_RING_ID_OFFSET },
  558. { "SRC_RING_MISC", CE_SRC_RING_MISC_OFFSET },
  559. { "SRC_CTRL", CE_SRC_CTRL_OFFSET },
  560. { "SRC_R0_CE_CH_SRC_IS", CE_SRC_R0_CE_CH_SRC_IS_OFFSET },
  561. { "SRC_RING_HP", CE_SRC_RING_HP_OFFSET },
  562. { "SRC_RING_TP", CE_SRC_RING_TP_OFFSET },
  563. { NULL },
  564. };
  565. static struct cnss_pci_reg ce_dst[] = {
  566. { "DEST_RING_BASE_LSB", CE_DEST_RING_BASE_LSB_OFFSET },
  567. { "DEST_RING_BASE_MSB", CE_DEST_RING_BASE_MSB_OFFSET },
  568. { "DEST_RING_ID", CE_DEST_RING_ID_OFFSET },
  569. { "DEST_RING_MISC", CE_DEST_RING_MISC_OFFSET },
  570. { "DEST_CTRL", CE_DEST_CTRL_OFFSET },
  571. { "CE_CH_DST_IS", CE_CH_DST_IS_OFFSET },
  572. { "CE_CH_DEST_CTRL2", CE_CH_DEST_CTRL2_OFFSET },
  573. { "DEST_RING_HP", CE_DEST_RING_HP_OFFSET },
  574. { "DEST_RING_TP", CE_DEST_RING_TP_OFFSET },
  575. { "STATUS_RING_BASE_LSB", CE_STATUS_RING_BASE_LSB_OFFSET },
  576. { "STATUS_RING_BASE_MSB", CE_STATUS_RING_BASE_MSB_OFFSET },
  577. { "STATUS_RING_ID", CE_STATUS_RING_ID_OFFSET },
  578. { "STATUS_RING_MISC", CE_STATUS_RING_MISC_OFFSET },
  579. { "STATUS_RING_HP", CE_STATUS_RING_HP_OFFSET },
  580. { "STATUS_RING_TP", CE_STATUS_RING_TP_OFFSET },
  581. { NULL },
  582. };
  583. static struct cnss_pci_reg ce_cmn[] = {
  584. { "GXI_ERR_INTS", CE_COMMON_GXI_ERR_INTS },
  585. { "GXI_ERR_STATS", CE_COMMON_GXI_ERR_STATS },
  586. { "GXI_WDOG_STATUS", CE_COMMON_GXI_WDOG_STATUS },
  587. { "TARGET_IE_0", CE_COMMON_TARGET_IE_0 },
  588. { "TARGET_IE_1", CE_COMMON_TARGET_IE_1 },
  589. { NULL },
  590. };
  591. static struct cnss_pci_reg qdss_csr[] = {
  592. { "QDSSCSR_ETRIRQCTRL", QDSS_APB_DEC_CSR_ETRIRQCTRL_OFFSET },
  593. { "QDSSCSR_PRESERVEETF", QDSS_APB_DEC_CSR_PRESERVEETF_OFFSET },
  594. { "QDSSCSR_PRESERVEETR0", QDSS_APB_DEC_CSR_PRESERVEETR0_OFFSET },
  595. { "QDSSCSR_PRESERVEETR1", QDSS_APB_DEC_CSR_PRESERVEETR1_OFFSET },
  596. { NULL },
  597. };
  598. static struct cnss_pci_reg pci_scratch[] = {
  599. { "PCIE_SCRATCH_0", PCIE_SCRATCH_0_SOC_PCIE_REG },
  600. { "PCIE_SCRATCH_1", PCIE_SCRATCH_1_SOC_PCIE_REG },
  601. { "PCIE_SCRATCH_2", PCIE_SCRATCH_2_SOC_PCIE_REG },
  602. { NULL },
  603. };
  604. static struct cnss_pci_reg pci_bhi_debug[] = {
  605. { "PCIE_BHIE_DEBUG_0", PCIE_PCIE_BHIE_DEBUG_0 },
  606. { "PCIE_BHIE_DEBUG_1", PCIE_PCIE_BHIE_DEBUG_1 },
  607. { "PCIE_BHIE_DEBUG_2", PCIE_PCIE_BHIE_DEBUG_2 },
  608. { "PCIE_BHIE_DEBUG_3", PCIE_PCIE_BHIE_DEBUG_3 },
  609. { "PCIE_BHIE_DEBUG_4", PCIE_PCIE_BHIE_DEBUG_4 },
  610. { "PCIE_BHIE_DEBUG_5", PCIE_PCIE_BHIE_DEBUG_5 },
  611. { "PCIE_BHIE_DEBUG_6", PCIE_PCIE_BHIE_DEBUG_6 },
  612. { "PCIE_BHIE_DEBUG_7", PCIE_PCIE_BHIE_DEBUG_7 },
  613. { "PCIE_BHIE_DEBUG_8", PCIE_PCIE_BHIE_DEBUG_8 },
  614. { "PCIE_BHIE_DEBUG_9", PCIE_PCIE_BHIE_DEBUG_9 },
  615. { "PCIE_BHIE_DEBUG_10", PCIE_PCIE_BHIE_DEBUG_10 },
  616. { NULL },
  617. };
  618. /* First field of the structure is the device bit mask. Use
  619. * enum cnss_pci_reg_mask as reference for the value.
  620. */
  621. static struct cnss_misc_reg wcss_reg_access_seq[] = {
  622. {1, 0, QCA6390_GCC_DEBUG_CLK_CTL, 0},
  623. {1, 1, QCA6390_GCC_DEBUG_CLK_CTL, 0x802},
  624. {1, 0, QCA6390_GCC_DEBUG_CLK_CTL, 0},
  625. {1, 0, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_PLL_MODE, 0},
  626. {1, 1, QCA6390_GCC_DEBUG_CLK_CTL, 0x805},
  627. {1, 0, QCA6390_GCC_DEBUG_CLK_CTL, 0},
  628. {1, 0, QCA6390_WCSS_WFSS_PMM_WFSS_PMM_R0_PMM_CTRL, 0},
  629. {1, 0, QCA6390_WCSS_PMM_TOP_PMU_CX_CSR, 0},
  630. {1, 0, QCA6390_WCSS_PMM_TOP_AON_INT_RAW_STAT, 0},
  631. {1, 0, QCA6390_WCSS_PMM_TOP_AON_INT_EN, 0},
  632. {1, 0, QCA6390_WCSS_PMM_TOP_PMU_TESTBUS_STS, 0},
  633. {1, 1, QCA6390_WCSS_PMM_TOP_PMU_TESTBUS_CTL, 0xD},
  634. {1, 0, QCA6390_WCSS_PMM_TOP_TESTBUS_STS, 0},
  635. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_SAW2_CFG, 0},
  636. {1, 1, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_SAW2_CFG, 0},
  637. {1, 1, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_CTL, 0x8},
  638. {1, 0, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_VALUE, 0},
  639. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_SAW2_SPM_STS, 0},
  640. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_SAW2_SPM_CTL, 0},
  641. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_SAW2_SPM_SLP_SEQ_ENTRY_0, 0},
  642. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_SAW2_SPM_SLP_SEQ_ENTRY_9, 0},
  643. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_STATUS0, 0},
  644. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_STATUS1, 0},
  645. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_STATUS2, 0},
  646. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_STATUS3, 0},
  647. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_STATUS4, 0},
  648. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_STATUS5, 0},
  649. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_STATUS6, 0},
  650. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_ENABLE0, 0},
  651. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_ENABLE1, 0},
  652. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_ENABLE2, 0},
  653. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_ENABLE3, 0},
  654. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_ENABLE4, 0},
  655. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_ENABLE5, 0},
  656. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_ENABLE6, 0},
  657. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_PENDING0, 0},
  658. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_PENDING1, 0},
  659. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_PENDING2, 0},
  660. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_PENDING3, 0},
  661. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_PENDING4, 0},
  662. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_PENDING5, 0},
  663. {1, 0, QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_L2VIC_INT_PENDING6, 0},
  664. {1, 1, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_CTL, 0x30040},
  665. {1, 0, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_CTL, 0},
  666. {1, 0, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_VALUE, 0},
  667. {1, 0, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_VALUE, 0},
  668. {1, 0, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_VALUE, 0},
  669. {1, 1, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_CTL, 0x30105},
  670. {1, 0, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_CTL, 0},
  671. {1, 0, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_VALUE, 0},
  672. {1, 0, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_VALUE, 0},
  673. {1, 0, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_VALUE, 0},
  674. {1, 0, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_VALUE, 0},
  675. {1, 0, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_VALUE, 0},
  676. {1, 0, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_VALUE, 0},
  677. {1, 0, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_VALUE, 0},
  678. {1, 0, QCA6390_WCSS_Q6SS_PUBCSR_QDSP6SS_TEST_BUS_CTL, 0},
  679. {1, 0, QCA6390_WCSS_CC_WCSS_UMAC_NOC_CBCR, 0},
  680. {1, 0, QCA6390_WCSS_CC_WCSS_UMAC_AHB_CBCR, 0},
  681. {1, 0, QCA6390_WCSS_CC_WCSS_UMAC_GDSCR, 0},
  682. {1, 0, QCA6390_WCSS_CC_WCSS_WLAN1_GDSCR, 0},
  683. {1, 0, QCA6390_WCSS_CC_WCSS_WLAN2_GDSCR, 0},
  684. {1, 0, QCA6390_WCSS_PMM_TOP_PMM_INT_CLR, 0},
  685. {1, 0, QCA6390_WCSS_PMM_TOP_AON_INT_STICKY_EN, 0},
  686. };
  687. static struct cnss_misc_reg pcie_reg_access_seq[] = {
  688. {1, 0, QCA6390_PCIE_PCIE_WCSS_STATUS_FOR_DEBUG_LOW_PCIE_LOCAL_REG, 0},
  689. {1, 0, QCA6390_PCIE_SOC_PCIE_WRAP_INTR_MASK_SOC_PCIE_REG, 0},
  690. {1, 1, QCA6390_PCIE_SOC_PCIE_WRAP_INTR_MASK_SOC_PCIE_REG, 0x18},
  691. {1, 0, QCA6390_PCIE_SOC_PCIE_WRAP_INTR_MASK_SOC_PCIE_REG, 0},
  692. {1, 0, QCA6390_PCIE_SOC_PCIE_WRAP_INTR_MASK_SOC_PCIE_REG, 0},
  693. {1, 0, QCA6390_PCIE_SOC_PCIE_WRAP_INTR_STATUS_SOC_PCIE_REG, 0},
  694. {1, 0, QCA6390_PCIE_SOC_COMMIT_REPLAY_SOC_PCIE_REG, 0},
  695. {1, 0, QCA6390_TLMM_GPIO_IN_OUT57, 0},
  696. {1, 0, QCA6390_TLMM_GPIO_INTR_CFG57, 0},
  697. {1, 0, QCA6390_TLMM_GPIO_INTR_STATUS57, 0},
  698. {1, 0, QCA6390_TLMM_GPIO_IN_OUT59, 0},
  699. {1, 0, QCA6390_TLMM_GPIO_INTR_CFG59, 0},
  700. {1, 0, QCA6390_TLMM_GPIO_INTR_STATUS59, 0},
  701. {1, 0, QCA6390_PCIE_PCIE_PARF_LTSSM, 0},
  702. {1, 0, QCA6390_PCIE_PCIE_PARF_PM_STTS, 0},
  703. {1, 0, QCA6390_PCIE_PCIE_PARF_PM_STTS_1, 0},
  704. {1, 0, QCA6390_PCIE_PCIE_PARF_INT_STATUS, 0},
  705. {1, 0, QCA6390_PCIE_PCIE_INT_ALL_STATUS, 0},
  706. {1, 0, QCA6390_PCIE_PCIE_INT_ALL_MASK, 0},
  707. {1, 0, QCA6390_PCIE_PCIE_PARF_BDF_TO_SID_CFG, 0},
  708. {1, 0, QCA6390_PCIE_PCIE_PARF_L1SS_SLEEP_NO_MHI_ACCESS_HANDLER_RD_4, 0},
  709. {1, 0, QCA6390_PCIE_PCIE_PARF_L1SS_SLEEP_NO_MHI_ACCESS_HANDLER_RD_3, 0},
  710. {1, 0, QCA6390_PCIE_PCIE_PARF_MHI_CLOCK_RESET_CTRL, 0},
  711. {1, 0, QCA6390_PCIE_PCIE_PARF_MHI_BASE_ADDR_LOWER, 0},
  712. {1, 0, QCA6390_PCIE_PCIE_PARF_L1SS_SLEEP_MODE_HANDLER_STATUS, 0},
  713. {1, 0, QCA6390_PCIE_PCIE_PARF_L1SS_SLEEP_MODE_HANDLER_CFG, 0},
  714. {1, 0, QCA6390_PCIE_PCIE_PARF_DEBUG_CNT_AUX_CLK_IN_L1SUB_L2, 0},
  715. {1, 0, QCA6390_PCIE_PCIE_PARF_DEBUG_CNT_PM_LINKST_IN_L1SUB, 0},
  716. {1, 0, QCA6390_PCIE_PCIE_CORE_CONFIG, 0},
  717. {1, 0, QCA6390_PCIE_PCIE_PARF_L1SS_SLEEP_NO_MHI_ACCESS_HANDLER_RD_4, 0},
  718. {1, 0, QCA6390_PCIE_PCIE_PARF_DEBUG_CNT_PM_LINKST_IN_L2, 0},
  719. {1, 0, QCA6390_PCIE_PCIE_PARF_DEBUG_CNT_PM_LINKST_IN_L1, 0},
  720. {1, 0, QCA6390_PCIE_PCIE_PARF_DEBUG_CNT_AUX_CLK_IN_L1SUB_L1, 0},
  721. {1, 0, QCA6390_PCIE_PCIE_PARF_DEBUG_CNT_AUX_CLK_IN_L1SUB_L2, 0},
  722. {1, 0, QCA6390_PCIE_PCIE_LOCAL_REG_WCSSAON_PCIE_SR_STATUS_HIGH, 0},
  723. {1, 0, QCA6390_PCIE_PCIE_LOCAL_REG_WCSSAON_PCIE_SR_STATUS_LOW, 0},
  724. {1, 0, QCA6390_PCIE_PCIE_LOCAL_REG_WCSS_STATUS_FOR_DEBUG_HIGH, 0},
  725. {1, 0, QCA6390_PCIE_PCIE_LOCAL_REG_WCSS_STATUS_FOR_DEBUG_LOW, 0},
  726. {1, 0, QCA6390_WFSS_PMM_WFSS_PMM_R0_WLAN1_STATUS_REG2, 0},
  727. {1, 0, QCA6390_WFSS_PMM_WFSS_PMM_R0_WLAN2_STATUS_REG2, 0},
  728. {1, 0, QCA6390_WFSS_PMM_WFSS_PMM_R0_PMM_WLAN2_CFG_REG1, 0},
  729. {1, 0, QCA6390_WFSS_PMM_WFSS_PMM_R0_PMM_WLAN1_CFG_REG1, 0},
  730. {1, 0, QCA6390_WFSS_PMM_WFSS_PMM_R0_WLAN2_APS_STATUS_REG1, 0},
  731. {1, 0, QCA6390_WFSS_PMM_WFSS_PMM_R0_WLAN1_APS_STATUS_REG1, 0},
  732. {1, 0, QCA6390_PCIE_PCIE_BHI_EXECENV_REG, 0},
  733. };
  734. static struct cnss_misc_reg wlaon_reg_access_seq[] = {
  735. {3, 0, WLAON_SOC_POWER_CTRL, 0},
  736. {3, 0, WLAON_SOC_PWR_WDG_BARK_THRSHD, 0},
  737. {3, 0, WLAON_SOC_PWR_WDG_BITE_THRSHD, 0},
  738. {3, 0, WLAON_SW_COLD_RESET, 0},
  739. {3, 0, WLAON_RFA_MEM_SLP_NRET_N_OVERRIDE, 0},
  740. {3, 0, WLAON_GDSC_DELAY_SETTING, 0},
  741. {3, 0, WLAON_GDSC_DELAY_SETTING2, 0},
  742. {3, 0, WLAON_WL_PWR_STATUS_REG, 0},
  743. {3, 0, WLAON_WL_AON_DBG_CFG_REG, 0},
  744. {2, 0, WLAON_WL_AON_DBG_ENABLE_GRP0_REG, 0},
  745. {2, 0, WLAON_WL_AON_DBG_ENABLE_GRP1_REG, 0},
  746. {2, 0, WLAON_WL_AON_APM_CFG_CTRL0, 0},
  747. {2, 0, WLAON_WL_AON_APM_CFG_CTRL1, 0},
  748. {2, 0, WLAON_WL_AON_APM_CFG_CTRL2, 0},
  749. {2, 0, WLAON_WL_AON_APM_CFG_CTRL3, 0},
  750. {2, 0, WLAON_WL_AON_APM_CFG_CTRL4, 0},
  751. {2, 0, WLAON_WL_AON_APM_CFG_CTRL5, 0},
  752. {2, 0, WLAON_WL_AON_APM_CFG_CTRL5_1, 0},
  753. {2, 0, WLAON_WL_AON_APM_CFG_CTRL6, 0},
  754. {2, 0, WLAON_WL_AON_APM_CFG_CTRL6_1, 0},
  755. {2, 0, WLAON_WL_AON_APM_CFG_CTRL7, 0},
  756. {2, 0, WLAON_WL_AON_APM_CFG_CTRL8, 0},
  757. {2, 0, WLAON_WL_AON_APM_CFG_CTRL8_1, 0},
  758. {2, 0, WLAON_WL_AON_APM_CFG_CTRL9, 0},
  759. {2, 0, WLAON_WL_AON_APM_CFG_CTRL9_1, 0},
  760. {2, 0, WLAON_WL_AON_APM_CFG_CTRL10, 0},
  761. {2, 0, WLAON_WL_AON_APM_CFG_CTRL11, 0},
  762. {2, 0, WLAON_WL_AON_APM_CFG_CTRL12, 0},
  763. {2, 0, WLAON_WL_AON_APM_OVERRIDE_REG, 0},
  764. {2, 0, WLAON_WL_AON_CXPC_REG, 0},
  765. {2, 0, WLAON_WL_AON_APM_STATUS0, 0},
  766. {2, 0, WLAON_WL_AON_APM_STATUS1, 0},
  767. {2, 0, WLAON_WL_AON_APM_STATUS2, 0},
  768. {2, 0, WLAON_WL_AON_APM_STATUS3, 0},
  769. {2, 0, WLAON_WL_AON_APM_STATUS4, 0},
  770. {2, 0, WLAON_WL_AON_APM_STATUS5, 0},
  771. {2, 0, WLAON_WL_AON_APM_STATUS6, 0},
  772. {3, 0, WLAON_GLOBAL_COUNTER_CTRL1, 0},
  773. {3, 0, WLAON_GLOBAL_COUNTER_CTRL6, 0},
  774. {3, 0, WLAON_GLOBAL_COUNTER_CTRL7, 0},
  775. {3, 0, WLAON_GLOBAL_COUNTER_CTRL3, 0},
  776. {3, 0, WLAON_GLOBAL_COUNTER_CTRL4, 0},
  777. {3, 0, WLAON_GLOBAL_COUNTER_CTRL5, 0},
  778. {3, 0, WLAON_GLOBAL_COUNTER_CTRL8, 0},
  779. {3, 0, WLAON_GLOBAL_COUNTER_CTRL2, 0},
  780. {3, 0, WLAON_GLOBAL_COUNTER_CTRL9, 0},
  781. {3, 0, WLAON_RTC_CLK_CAL_CTRL1, 0},
  782. {3, 0, WLAON_RTC_CLK_CAL_CTRL2, 0},
  783. {3, 0, WLAON_RTC_CLK_CAL_CTRL3, 0},
  784. {3, 0, WLAON_RTC_CLK_CAL_CTRL4, 0},
  785. {3, 0, WLAON_RTC_CLK_CAL_CTRL5, 0},
  786. {3, 0, WLAON_RTC_CLK_CAL_CTRL6, 0},
  787. {3, 0, WLAON_RTC_CLK_CAL_CTRL7, 0},
  788. {3, 0, WLAON_RTC_CLK_CAL_CTRL8, 0},
  789. {3, 0, WLAON_RTC_CLK_CAL_CTRL9, 0},
  790. {3, 0, WLAON_WCSSAON_CONFIG_REG, 0},
  791. {3, 0, WLAON_WLAN_OEM_DEBUG_REG, 0},
  792. {3, 0, WLAON_WLAN_RAM_DUMP_REG, 0},
  793. {3, 0, WLAON_QDSS_WCSS_REG, 0},
  794. {3, 0, WLAON_QDSS_WCSS_ACK, 0},
  795. {3, 0, WLAON_WL_CLK_CNTL_KDF_REG, 0},
  796. {3, 0, WLAON_WL_CLK_CNTL_PMU_HFRC_REG, 0},
  797. {3, 0, WLAON_QFPROM_PWR_CTRL_REG, 0},
  798. {3, 0, WLAON_DLY_CONFIG, 0},
  799. {3, 0, WLAON_WLAON_Q6_IRQ_REG, 0},
  800. {3, 0, WLAON_PCIE_INTF_SW_CFG_REG, 0},
  801. {3, 0, WLAON_PCIE_INTF_STICKY_SW_CFG_REG, 0},
  802. {3, 0, WLAON_PCIE_INTF_PHY_SW_CFG_REG, 0},
  803. {3, 0, WLAON_PCIE_INTF_PHY_NOCSR_SW_CFG_REG, 0},
  804. {3, 0, WLAON_Q6_COOKIE_BIT, 0},
  805. {3, 0, WLAON_WARM_SW_ENTRY, 0},
  806. {3, 0, WLAON_RESET_DBG_SW_ENTRY, 0},
  807. {3, 0, WLAON_WL_PMUNOC_CFG_REG, 0},
  808. {3, 0, WLAON_RESET_CAUSE_CFG_REG, 0},
  809. {3, 0, WLAON_SOC_WCSSAON_WAKEUP_IRQ_7_EN_REG, 0},
  810. {3, 0, WLAON_DEBUG, 0},
  811. {3, 0, WLAON_SOC_PARAMETERS, 0},
  812. {3, 0, WLAON_WLPM_SIGNAL, 0},
  813. {3, 0, WLAON_SOC_RESET_CAUSE_REG, 0},
  814. {3, 0, WLAON_WAKEUP_PCIE_SOC_REG, 0},
  815. {3, 0, WLAON_PBL_STACK_CANARY, 0},
  816. {3, 0, WLAON_MEM_TOT_NUM_GRP_REG, 0},
  817. {3, 0, WLAON_MEM_TOT_BANKS_IN_GRP0_REG, 0},
  818. {3, 0, WLAON_MEM_TOT_BANKS_IN_GRP1_REG, 0},
  819. {3, 0, WLAON_MEM_TOT_BANKS_IN_GRP2_REG, 0},
  820. {3, 0, WLAON_MEM_TOT_BANKS_IN_GRP3_REG, 0},
  821. {3, 0, WLAON_MEM_TOT_SIZE_IN_GRP0_REG, 0},
  822. {3, 0, WLAON_MEM_TOT_SIZE_IN_GRP1_REG, 0},
  823. {3, 0, WLAON_MEM_TOT_SIZE_IN_GRP2_REG, 0},
  824. {3, 0, WLAON_MEM_TOT_SIZE_IN_GRP3_REG, 0},
  825. {3, 0, WLAON_MEM_SLP_NRET_OVERRIDE_GRP0_REG, 0},
  826. {3, 0, WLAON_MEM_SLP_NRET_OVERRIDE_GRP1_REG, 0},
  827. {3, 0, WLAON_MEM_SLP_NRET_OVERRIDE_GRP2_REG, 0},
  828. {3, 0, WLAON_MEM_SLP_NRET_OVERRIDE_GRP3_REG, 0},
  829. {3, 0, WLAON_MEM_SLP_RET_OVERRIDE_GRP0_REG, 0},
  830. {3, 0, WLAON_MEM_SLP_RET_OVERRIDE_GRP1_REG, 0},
  831. {3, 0, WLAON_MEM_SLP_RET_OVERRIDE_GRP2_REG, 0},
  832. {3, 0, WLAON_MEM_SLP_RET_OVERRIDE_GRP3_REG, 0},
  833. {3, 0, WLAON_MEM_CNT_SEL_REG, 0},
  834. {3, 0, WLAON_MEM_NO_EXTBHS_REG, 0},
  835. {3, 0, WLAON_MEM_DEBUG_REG, 0},
  836. {3, 0, WLAON_MEM_DEBUG_BUS_REG, 0},
  837. {3, 0, WLAON_MEM_REDUN_CFG_REG, 0},
  838. {3, 0, WLAON_WL_AON_SPARE2, 0},
  839. {3, 0, WLAON_VSEL_CFG_FOR_WL_RET_DISABLE_REG, 0},
  840. {3, 0, WLAON_BTFM_WLAN_IPC_STATUS_REG, 0},
  841. {3, 0, WLAON_MPM_COUNTER_CHICKEN_BITS, 0},
  842. {3, 0, WLAON_WLPM_CHICKEN_BITS, 0},
  843. {3, 0, WLAON_PCIE_PHY_PWR_REG, 0},
  844. {3, 0, WLAON_WL_CLK_CNTL_PMU_LPO2M_REG, 0},
  845. {3, 0, WLAON_WL_SS_ROOT_CLK_SWITCH_REG, 0},
  846. {3, 0, WLAON_POWERCTRL_PMU_REG, 0},
  847. {3, 0, WLAON_POWERCTRL_MEM_REG, 0},
  848. {3, 0, WLAON_PCIE_PWR_CTRL_REG, 0},
  849. {3, 0, WLAON_SOC_PWR_PROFILE_REG, 0},
  850. {3, 0, WLAON_WCSSAON_PCIE_SR_STATUS_HI_REG, 0},
  851. {3, 0, WLAON_WCSSAON_PCIE_SR_STATUS_LO_REG, 0},
  852. {3, 0, WLAON_WCSS_TCSR_PMM_SR_STATUS_HI_REG, 0},
  853. {3, 0, WLAON_WCSS_TCSR_PMM_SR_STATUS_LO_REG, 0},
  854. {3, 0, WLAON_MEM_SVS_CFG_REG, 0},
  855. {3, 0, WLAON_CMN_AON_MISC_REG, 0},
  856. {3, 0, WLAON_INTR_STATUS, 0},
  857. {2, 0, WLAON_INTR_ENABLE, 0},
  858. {2, 0, WLAON_NOC_DBG_BUS_SEL_REG, 0},
  859. {2, 0, WLAON_NOC_DBG_BUS_REG, 0},
  860. {2, 0, WLAON_WL_CTRL_MISC_REG, 0},
  861. {2, 0, WLAON_DBG_STATUS0, 0},
  862. {2, 0, WLAON_DBG_STATUS1, 0},
  863. {2, 0, WLAON_TIMERSYNC_OFFSET_L, 0},
  864. {2, 0, WLAON_TIMERSYNC_OFFSET_H, 0},
  865. {2, 0, WLAON_PMU_LDO_SETTLE_REG, 0},
  866. };
  867. static struct cnss_misc_reg syspm_reg_access_seq[] = {
  868. {1, 0, QCA6390_SYSPM_SYSPM_PWR_STATUS, 0},
  869. {1, 0, QCA6390_SYSPM_DBG_BTFM_AON_REG, 0},
  870. {1, 0, QCA6390_SYSPM_DBG_BUS_SEL_REG, 0},
  871. {1, 0, QCA6390_SYSPM_WCSSAON_SR_STATUS, 0},
  872. {1, 0, QCA6390_SYSPM_WCSSAON_SR_STATUS, 0},
  873. {1, 0, QCA6390_SYSPM_WCSSAON_SR_STATUS, 0},
  874. {1, 0, QCA6390_SYSPM_WCSSAON_SR_STATUS, 0},
  875. {1, 0, QCA6390_SYSPM_WCSSAON_SR_STATUS, 0},
  876. {1, 0, QCA6390_SYSPM_WCSSAON_SR_STATUS, 0},
  877. {1, 0, QCA6390_SYSPM_WCSSAON_SR_STATUS, 0},
  878. {1, 0, QCA6390_SYSPM_WCSSAON_SR_STATUS, 0},
  879. {1, 0, QCA6390_SYSPM_WCSSAON_SR_STATUS, 0},
  880. {1, 0, QCA6390_SYSPM_WCSSAON_SR_STATUS, 0},
  881. };
  882. static struct cnss_print_optimize print_optimize;
  883. #define WCSS_REG_SIZE ARRAY_SIZE(wcss_reg_access_seq)
  884. #define PCIE_REG_SIZE ARRAY_SIZE(pcie_reg_access_seq)
  885. #define WLAON_REG_SIZE ARRAY_SIZE(wlaon_reg_access_seq)
  886. #define SYSPM_REG_SIZE ARRAY_SIZE(syspm_reg_access_seq)
  887. static int cnss_pci_update_fw_name(struct cnss_pci_data *pci_priv);
  888. static void cnss_pci_suspend_pwroff(struct pci_dev *pci_dev);
  889. static bool cnss_should_suspend_pwroff(struct pci_dev *pci_dev);
  890. static void cnss_pci_update_link_event(struct cnss_pci_data *pci_priv,
  891. enum cnss_bus_event_type type,
  892. void *data);
  893. #if IS_ENABLED(CONFIG_MHI_BUS_MISC)
  894. static void cnss_mhi_debug_reg_dump(struct cnss_pci_data *pci_priv)
  895. {
  896. mhi_debug_reg_dump(pci_priv->mhi_ctrl);
  897. }
  898. static void cnss_mhi_dump_sfr(struct cnss_pci_data *pci_priv)
  899. {
  900. mhi_dump_sfr(pci_priv->mhi_ctrl);
  901. }
  902. static bool cnss_mhi_scan_rddm_cookie(struct cnss_pci_data *pci_priv,
  903. u32 cookie)
  904. {
  905. return mhi_scan_rddm_cookie(pci_priv->mhi_ctrl, cookie);
  906. }
  907. static int cnss_mhi_pm_fast_suspend(struct cnss_pci_data *pci_priv,
  908. bool notify_clients)
  909. {
  910. return mhi_pm_fast_suspend(pci_priv->mhi_ctrl, notify_clients);
  911. }
  912. static int cnss_mhi_pm_fast_resume(struct cnss_pci_data *pci_priv,
  913. bool notify_clients)
  914. {
  915. return mhi_pm_fast_resume(pci_priv->mhi_ctrl, notify_clients);
  916. }
  917. static void cnss_mhi_set_m2_timeout_ms(struct cnss_pci_data *pci_priv,
  918. u32 timeout)
  919. {
  920. return mhi_set_m2_timeout_ms(pci_priv->mhi_ctrl, timeout);
  921. }
  922. static int cnss_mhi_device_get_sync_atomic(struct cnss_pci_data *pci_priv,
  923. int timeout_us, bool in_panic)
  924. {
  925. return mhi_device_get_sync_atomic(pci_priv->mhi_ctrl->mhi_dev,
  926. timeout_us, in_panic);
  927. }
  928. #ifdef CONFIG_CNSS2_SMMU_DB_SUPPORT
  929. static int cnss_mhi_host_notify_db_disable_trace(struct cnss_pci_data *pci_priv)
  930. {
  931. return mhi_host_notify_db_disable_trace(pci_priv->mhi_ctrl);
  932. }
  933. #endif
  934. static void
  935. cnss_mhi_controller_set_bw_scale_cb(struct cnss_pci_data *pci_priv,
  936. int (*cb)(struct mhi_controller *mhi_ctrl,
  937. struct mhi_link_info *link_info))
  938. {
  939. mhi_controller_set_bw_scale_cb(pci_priv->mhi_ctrl, cb);
  940. }
  941. static int cnss_mhi_force_reset(struct cnss_pci_data *pci_priv)
  942. {
  943. return mhi_force_reset(pci_priv->mhi_ctrl);
  944. }
  945. void cnss_mhi_controller_set_base(struct cnss_pci_data *pci_priv,
  946. phys_addr_t base)
  947. {
  948. return mhi_controller_set_base(pci_priv->mhi_ctrl, base);
  949. }
  950. #else
  951. static void cnss_mhi_debug_reg_dump(struct cnss_pci_data *pci_priv)
  952. {
  953. }
  954. static void cnss_mhi_dump_sfr(struct cnss_pci_data *pci_priv)
  955. {
  956. }
  957. static bool cnss_mhi_scan_rddm_cookie(struct cnss_pci_data *pci_priv,
  958. u32 cookie)
  959. {
  960. return false;
  961. }
  962. static int cnss_mhi_pm_fast_suspend(struct cnss_pci_data *pci_priv,
  963. bool notify_clients)
  964. {
  965. return -EOPNOTSUPP;
  966. }
  967. static int cnss_mhi_pm_fast_resume(struct cnss_pci_data *pci_priv,
  968. bool notify_clients)
  969. {
  970. return -EOPNOTSUPP;
  971. }
  972. static void cnss_mhi_set_m2_timeout_ms(struct cnss_pci_data *pci_priv,
  973. u32 timeout)
  974. {
  975. }
  976. static int cnss_mhi_device_get_sync_atomic(struct cnss_pci_data *pci_priv,
  977. int timeout_us, bool in_panic)
  978. {
  979. return -EOPNOTSUPP;
  980. }
  981. #ifdef CONFIG_CNSS2_SMMU_DB_SUPPORT
  982. static int cnss_mhi_host_notify_db_disable_trace(struct cnss_pci_data *pci_priv)
  983. {
  984. return -EOPNOTSUPP;
  985. }
  986. #endif
  987. static void
  988. cnss_mhi_controller_set_bw_scale_cb(struct cnss_pci_data *pci_priv,
  989. int (*cb)(struct mhi_controller *mhi_ctrl,
  990. struct mhi_link_info *link_info))
  991. {
  992. }
  993. static int cnss_mhi_force_reset(struct cnss_pci_data *pci_priv)
  994. {
  995. return -EOPNOTSUPP;
  996. }
  997. void cnss_mhi_controller_set_base(struct cnss_pci_data *pci_priv,
  998. phys_addr_t base)
  999. {
  1000. }
  1001. #endif /* CONFIG_MHI_BUS_MISC */
  1002. #ifdef CONFIG_CNSS2_SMMU_DB_SUPPORT
  1003. #define CNSS_MHI_WAKE_TIMEOUT 500000
  1004. static void cnss_record_smmu_fault_timestamp(struct cnss_pci_data *pci_priv,
  1005. enum cnss_smmu_fault_time id)
  1006. {
  1007. if (id >= SMMU_CB_MAX)
  1008. return;
  1009. pci_priv->smmu_fault_timestamp[id] = sched_clock();
  1010. }
  1011. static void cnss_pci_smmu_fault_handler_irq(struct iommu_domain *domain,
  1012. void *handler_token)
  1013. {
  1014. struct cnss_pci_data *pci_priv = handler_token;
  1015. int ret = 0;
  1016. cnss_record_smmu_fault_timestamp(pci_priv, SMMU_CB_ENTRY);
  1017. ret = cnss_mhi_device_get_sync_atomic(pci_priv,
  1018. CNSS_MHI_WAKE_TIMEOUT, true);
  1019. if (ret < 0) {
  1020. cnss_pr_err("Failed to bring mhi in M0 state, ret %d\n", ret);
  1021. return;
  1022. }
  1023. cnss_record_smmu_fault_timestamp(pci_priv, SMMU_CB_DOORBELL_RING);
  1024. ret = cnss_mhi_host_notify_db_disable_trace(pci_priv);
  1025. if (ret < 0)
  1026. cnss_pr_err("Fail to notify wlan fw to stop trace collection, ret %d\n", ret);
  1027. cnss_record_smmu_fault_timestamp(pci_priv, SMMU_CB_EXIT);
  1028. }
  1029. void cnss_register_iommu_fault_handler_irq(struct cnss_pci_data *pci_priv)
  1030. {
  1031. qcom_iommu_set_fault_handler_irq(pci_priv->iommu_domain,
  1032. cnss_pci_smmu_fault_handler_irq, pci_priv);
  1033. }
  1034. #else
  1035. void cnss_register_iommu_fault_handler_irq(struct cnss_pci_data *pci_priv)
  1036. {
  1037. }
  1038. #endif
  1039. int cnss_pci_check_link_status(struct cnss_pci_data *pci_priv)
  1040. {
  1041. u16 device_id;
  1042. if (pci_priv->pci_link_state == PCI_LINK_DOWN) {
  1043. cnss_pr_dbg("%ps: PCIe link is in suspend state\n",
  1044. (void *)_RET_IP_);
  1045. return -EACCES;
  1046. }
  1047. if (pci_priv->pci_link_down_ind) {
  1048. cnss_pr_err("%ps: PCIe link is down\n", (void *)_RET_IP_);
  1049. return -EIO;
  1050. }
  1051. pci_read_config_word(pci_priv->pci_dev, PCI_DEVICE_ID, &device_id);
  1052. if (device_id != pci_priv->device_id) {
  1053. cnss_fatal_err("%ps: PCI device ID mismatch, link possibly down, current read ID: 0x%x, record ID: 0x%x\n",
  1054. (void *)_RET_IP_, device_id,
  1055. pci_priv->device_id);
  1056. return -EIO;
  1057. }
  1058. return 0;
  1059. }
  1060. static void cnss_pci_select_window(struct cnss_pci_data *pci_priv, u32 offset)
  1061. {
  1062. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  1063. u32 window = (offset >> WINDOW_SHIFT) & WINDOW_VALUE_MASK;
  1064. u32 window_enable = WINDOW_ENABLE_BIT | window;
  1065. u32 val;
  1066. if (plat_priv->device_id == QCN7605_DEVICE_ID)
  1067. window_enable = QCN7605_WINDOW_ENABLE_BIT | window;
  1068. if (plat_priv->device_id == PEACH_DEVICE_ID) {
  1069. writel_relaxed(window_enable, pci_priv->bar +
  1070. PEACH_PCIE_REMAP_BAR_CTRL_OFFSET);
  1071. } else {
  1072. writel_relaxed(window_enable, pci_priv->bar +
  1073. QCA6390_PCIE_REMAP_BAR_CTRL_OFFSET);
  1074. }
  1075. if (window != pci_priv->remap_window) {
  1076. pci_priv->remap_window = window;
  1077. cnss_pr_dbg("Config PCIe remap window register to 0x%x\n",
  1078. window_enable);
  1079. }
  1080. /* Read it back to make sure the write has taken effect */
  1081. if (plat_priv->device_id == PEACH_DEVICE_ID) {
  1082. val = readl_relaxed(pci_priv->bar +
  1083. PEACH_PCIE_REMAP_BAR_CTRL_OFFSET);
  1084. } else {
  1085. val = readl_relaxed(pci_priv->bar +
  1086. QCA6390_PCIE_REMAP_BAR_CTRL_OFFSET);
  1087. }
  1088. if (val != window_enable) {
  1089. cnss_pr_err("Failed to config window register to 0x%x, current value: 0x%x\n",
  1090. window_enable, val);
  1091. if (!cnss_pci_check_link_status(pci_priv) &&
  1092. !test_bit(CNSS_IN_PANIC, &plat_priv->driver_state))
  1093. CNSS_ASSERT(0);
  1094. }
  1095. }
  1096. static int cnss_pci_reg_read(struct cnss_pci_data *pci_priv,
  1097. u32 offset, u32 *val)
  1098. {
  1099. int ret;
  1100. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  1101. if (!in_interrupt() && !irqs_disabled()) {
  1102. ret = cnss_pci_check_link_status(pci_priv);
  1103. if (ret)
  1104. return ret;
  1105. }
  1106. if (pci_priv->pci_dev->device == QCA6174_DEVICE_ID ||
  1107. offset < MAX_UNWINDOWED_ADDRESS) {
  1108. *val = readl_relaxed(pci_priv->bar + offset);
  1109. return 0;
  1110. }
  1111. /* If in panic, assumption is kernel panic handler will hold all threads
  1112. * and interrupts. Further pci_reg_window_lock could be held before
  1113. * panic. So only lock during normal operation.
  1114. */
  1115. if (test_bit(CNSS_IN_PANIC, &plat_priv->driver_state)) {
  1116. cnss_pci_select_window(pci_priv, offset);
  1117. *val = readl_relaxed(pci_priv->bar + WINDOW_START +
  1118. (offset & WINDOW_RANGE_MASK));
  1119. } else {
  1120. spin_lock_bh(&pci_reg_window_lock);
  1121. cnss_pci_select_window(pci_priv, offset);
  1122. *val = readl_relaxed(pci_priv->bar + WINDOW_START +
  1123. (offset & WINDOW_RANGE_MASK));
  1124. spin_unlock_bh(&pci_reg_window_lock);
  1125. }
  1126. return 0;
  1127. }
  1128. static int cnss_pci_reg_write(struct cnss_pci_data *pci_priv, u32 offset,
  1129. u32 val)
  1130. {
  1131. int ret;
  1132. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  1133. if (!in_interrupt() && !irqs_disabled()) {
  1134. ret = cnss_pci_check_link_status(pci_priv);
  1135. if (ret)
  1136. return ret;
  1137. }
  1138. if (pci_priv->pci_dev->device == QCA6174_DEVICE_ID ||
  1139. offset < MAX_UNWINDOWED_ADDRESS) {
  1140. writel_relaxed(val, pci_priv->bar + offset);
  1141. return 0;
  1142. }
  1143. /* Same constraint as PCI register read in panic */
  1144. if (test_bit(CNSS_IN_PANIC, &plat_priv->driver_state)) {
  1145. cnss_pci_select_window(pci_priv, offset);
  1146. writel_relaxed(val, pci_priv->bar + WINDOW_START +
  1147. (offset & WINDOW_RANGE_MASK));
  1148. } else {
  1149. spin_lock_bh(&pci_reg_window_lock);
  1150. cnss_pci_select_window(pci_priv, offset);
  1151. writel_relaxed(val, pci_priv->bar + WINDOW_START +
  1152. (offset & WINDOW_RANGE_MASK));
  1153. spin_unlock_bh(&pci_reg_window_lock);
  1154. }
  1155. return 0;
  1156. }
  1157. static int cnss_pci_force_wake_get(struct cnss_pci_data *pci_priv)
  1158. {
  1159. struct device *dev = &pci_priv->pci_dev->dev;
  1160. int ret;
  1161. ret = cnss_pci_force_wake_request_sync(dev,
  1162. FORCE_WAKE_DELAY_TIMEOUT_US);
  1163. if (ret) {
  1164. if (ret != -EAGAIN)
  1165. cnss_pr_err("Failed to request force wake\n");
  1166. return ret;
  1167. }
  1168. /* If device's M1 state-change event races here, it can be ignored,
  1169. * as the device is expected to immediately move from M2 to M0
  1170. * without entering low power state.
  1171. */
  1172. if (cnss_pci_is_device_awake(dev) != true)
  1173. cnss_pr_warn("MHI not in M0, while reg still accessible\n");
  1174. return 0;
  1175. }
  1176. static int cnss_pci_force_wake_put(struct cnss_pci_data *pci_priv)
  1177. {
  1178. struct device *dev = &pci_priv->pci_dev->dev;
  1179. int ret;
  1180. ret = cnss_pci_force_wake_release(dev);
  1181. if (ret && ret != -EAGAIN)
  1182. cnss_pr_err("Failed to release force wake\n");
  1183. return ret;
  1184. }
  1185. #if IS_ENABLED(CONFIG_INTERCONNECT)
  1186. /**
  1187. * cnss_setup_bus_bandwidth() - Setup interconnect vote for given bandwidth
  1188. * @plat_priv: Platform private data struct
  1189. * @bw: bandwidth
  1190. * @save: toggle flag to save bandwidth to current_bw_vote
  1191. *
  1192. * Setup bandwidth votes for configured interconnect paths
  1193. *
  1194. * Return: 0 for success
  1195. */
  1196. static int cnss_setup_bus_bandwidth(struct cnss_plat_data *plat_priv,
  1197. u32 bw, bool save)
  1198. {
  1199. int ret = 0;
  1200. struct cnss_bus_bw_info *bus_bw_info;
  1201. if (!plat_priv->icc.path_count)
  1202. return -EOPNOTSUPP;
  1203. if (bw >= plat_priv->icc.bus_bw_cfg_count) {
  1204. cnss_pr_err("Invalid bus bandwidth Type: %d", bw);
  1205. return -EINVAL;
  1206. }
  1207. cnss_pr_buf("Bandwidth vote to %d, save %d\n", bw, save);
  1208. list_for_each_entry(bus_bw_info, &plat_priv->icc.list_head, list) {
  1209. ret = icc_set_bw(bus_bw_info->icc_path,
  1210. bus_bw_info->cfg_table[bw].avg_bw,
  1211. bus_bw_info->cfg_table[bw].peak_bw);
  1212. if (ret) {
  1213. cnss_pr_err("Could not set BW Cfg: %d, err = %d ICC Path: %s Val: %d %d\n",
  1214. bw, ret, bus_bw_info->icc_name,
  1215. bus_bw_info->cfg_table[bw].avg_bw,
  1216. bus_bw_info->cfg_table[bw].peak_bw);
  1217. break;
  1218. }
  1219. }
  1220. if (ret == 0 && save)
  1221. plat_priv->icc.current_bw_vote = bw;
  1222. return ret;
  1223. }
  1224. int cnss_request_bus_bandwidth(struct device *dev, int bandwidth)
  1225. {
  1226. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  1227. if (!plat_priv)
  1228. return -ENODEV;
  1229. if (bandwidth < 0)
  1230. return -EINVAL;
  1231. return cnss_setup_bus_bandwidth(plat_priv, (u32)bandwidth, true);
  1232. }
  1233. #else
  1234. static int cnss_setup_bus_bandwidth(struct cnss_plat_data *plat_priv,
  1235. u32 bw, bool save)
  1236. {
  1237. return 0;
  1238. }
  1239. int cnss_request_bus_bandwidth(struct device *dev, int bandwidth)
  1240. {
  1241. return 0;
  1242. }
  1243. #endif
  1244. EXPORT_SYMBOL(cnss_request_bus_bandwidth);
  1245. int cnss_pci_debug_reg_read(struct cnss_pci_data *pci_priv, u32 offset,
  1246. u32 *val, bool raw_access)
  1247. {
  1248. int ret = 0;
  1249. bool do_force_wake_put = true;
  1250. if (raw_access) {
  1251. ret = cnss_pci_reg_read(pci_priv, offset, val);
  1252. goto out;
  1253. }
  1254. ret = cnss_pci_is_device_down(&pci_priv->pci_dev->dev);
  1255. if (ret)
  1256. goto out;
  1257. ret = cnss_pci_pm_runtime_get_sync(pci_priv, RTPM_ID_CNSS);
  1258. if (ret < 0)
  1259. goto runtime_pm_put;
  1260. ret = cnss_pci_force_wake_get(pci_priv);
  1261. if (ret)
  1262. do_force_wake_put = false;
  1263. ret = cnss_pci_reg_read(pci_priv, offset, val);
  1264. if (ret) {
  1265. cnss_pr_err("Failed to read register offset 0x%x, err = %d\n",
  1266. offset, ret);
  1267. goto force_wake_put;
  1268. }
  1269. force_wake_put:
  1270. if (do_force_wake_put)
  1271. cnss_pci_force_wake_put(pci_priv);
  1272. runtime_pm_put:
  1273. cnss_pci_pm_runtime_mark_last_busy(pci_priv);
  1274. cnss_pci_pm_runtime_put_autosuspend(pci_priv, RTPM_ID_CNSS);
  1275. out:
  1276. return ret;
  1277. }
  1278. int cnss_pci_debug_reg_write(struct cnss_pci_data *pci_priv, u32 offset,
  1279. u32 val, bool raw_access)
  1280. {
  1281. int ret = 0;
  1282. bool do_force_wake_put = true;
  1283. if (raw_access) {
  1284. ret = cnss_pci_reg_write(pci_priv, offset, val);
  1285. goto out;
  1286. }
  1287. ret = cnss_pci_is_device_down(&pci_priv->pci_dev->dev);
  1288. if (ret)
  1289. goto out;
  1290. ret = cnss_pci_pm_runtime_get_sync(pci_priv, RTPM_ID_CNSS);
  1291. if (ret < 0)
  1292. goto runtime_pm_put;
  1293. ret = cnss_pci_force_wake_get(pci_priv);
  1294. if (ret)
  1295. do_force_wake_put = false;
  1296. ret = cnss_pci_reg_write(pci_priv, offset, val);
  1297. if (ret) {
  1298. cnss_pr_err("Failed to write 0x%x to register offset 0x%x, err = %d\n",
  1299. val, offset, ret);
  1300. goto force_wake_put;
  1301. }
  1302. force_wake_put:
  1303. if (do_force_wake_put)
  1304. cnss_pci_force_wake_put(pci_priv);
  1305. runtime_pm_put:
  1306. cnss_pci_pm_runtime_mark_last_busy(pci_priv);
  1307. cnss_pci_pm_runtime_put_autosuspend(pci_priv, RTPM_ID_CNSS);
  1308. out:
  1309. return ret;
  1310. }
  1311. static int cnss_set_pci_config_space(struct cnss_pci_data *pci_priv, bool save)
  1312. {
  1313. struct pci_dev *pci_dev = pci_priv->pci_dev;
  1314. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  1315. bool link_down_or_recovery;
  1316. if (!plat_priv)
  1317. return -ENODEV;
  1318. link_down_or_recovery = pci_priv->pci_link_down_ind ||
  1319. (test_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state));
  1320. if (save) {
  1321. if (link_down_or_recovery) {
  1322. pci_priv->saved_state = NULL;
  1323. } else {
  1324. pci_save_state(pci_dev);
  1325. pci_priv->saved_state = pci_store_saved_state(pci_dev);
  1326. }
  1327. } else {
  1328. if (link_down_or_recovery) {
  1329. pci_load_saved_state(pci_dev, pci_priv->default_state);
  1330. pci_restore_state(pci_dev);
  1331. } else if (pci_priv->saved_state) {
  1332. pci_load_and_free_saved_state(pci_dev,
  1333. &pci_priv->saved_state);
  1334. pci_restore_state(pci_dev);
  1335. }
  1336. }
  1337. return 0;
  1338. }
  1339. static int cnss_update_supported_link_info(struct cnss_pci_data *pci_priv)
  1340. {
  1341. int ret = 0;
  1342. struct pci_dev *root_port;
  1343. struct device_node *root_of_node;
  1344. struct cnss_plat_data *plat_priv;
  1345. if (!pci_priv)
  1346. return -EINVAL;
  1347. if (pci_priv->device_id != KIWI_DEVICE_ID)
  1348. return ret;
  1349. plat_priv = pci_priv->plat_priv;
  1350. root_port = pcie_find_root_port(pci_priv->pci_dev);
  1351. if (!root_port) {
  1352. cnss_pr_err("PCIe root port is null\n");
  1353. return -EINVAL;
  1354. }
  1355. root_of_node = root_port->dev.of_node;
  1356. if (root_of_node && root_of_node->parent) {
  1357. ret = of_property_read_u32(root_of_node->parent,
  1358. "qcom,target-link-speed",
  1359. &plat_priv->supported_link_speed);
  1360. if (!ret)
  1361. cnss_pr_dbg("Supported PCIe Link Speed: %d\n",
  1362. plat_priv->supported_link_speed);
  1363. else
  1364. plat_priv->supported_link_speed = 0;
  1365. }
  1366. return ret;
  1367. }
  1368. static int cnss_pci_get_link_status(struct cnss_pci_data *pci_priv)
  1369. {
  1370. u16 link_status;
  1371. int ret;
  1372. ret = pcie_capability_read_word(pci_priv->pci_dev, PCI_EXP_LNKSTA,
  1373. &link_status);
  1374. if (ret)
  1375. return ret;
  1376. cnss_pr_dbg("Get PCI link status register: %u\n", link_status);
  1377. pci_priv->def_link_speed = link_status & PCI_EXP_LNKSTA_CLS;
  1378. pci_priv->def_link_width =
  1379. (link_status & PCI_EXP_LNKSTA_NLW) >> PCI_EXP_LNKSTA_NLW_SHIFT;
  1380. pci_priv->cur_link_speed = pci_priv->def_link_speed;
  1381. cnss_pr_dbg("Default PCI link speed is 0x%x, link width is 0x%x\n",
  1382. pci_priv->def_link_speed, pci_priv->def_link_width);
  1383. return 0;
  1384. }
  1385. static void cnss_pci_soc_scratch_reg_dump(struct cnss_pci_data *pci_priv)
  1386. {
  1387. u32 reg_offset, val;
  1388. int i;
  1389. switch (pci_priv->device_id) {
  1390. case QCA6390_DEVICE_ID:
  1391. case QCA6490_DEVICE_ID:
  1392. case KIWI_DEVICE_ID:
  1393. case MANGO_DEVICE_ID:
  1394. case PEACH_DEVICE_ID:
  1395. break;
  1396. default:
  1397. return;
  1398. }
  1399. if (in_interrupt() || irqs_disabled())
  1400. return;
  1401. if (cnss_pci_check_link_status(pci_priv))
  1402. return;
  1403. cnss_pr_dbg("Start to dump SOC Scratch registers\n");
  1404. for (i = 0; pci_scratch[i].name; i++) {
  1405. reg_offset = pci_scratch[i].offset;
  1406. if (cnss_pci_reg_read(pci_priv, reg_offset, &val))
  1407. return;
  1408. cnss_pr_dbg("PCIE_SOC_REG_%s = 0x%x\n",
  1409. pci_scratch[i].name, val);
  1410. }
  1411. }
  1412. static void cnss_pci_soc_reset_cause_reg_dump(struct cnss_pci_data *pci_priv)
  1413. {
  1414. u32 val;
  1415. switch (pci_priv->device_id) {
  1416. case PEACH_DEVICE_ID:
  1417. break;
  1418. default:
  1419. return;
  1420. }
  1421. if (in_interrupt() || irqs_disabled())
  1422. return;
  1423. if (cnss_pci_check_link_status(pci_priv))
  1424. return;
  1425. cnss_pr_dbg("Start to dump SOC Reset Cause registers\n");
  1426. if (cnss_pci_reg_read(pci_priv, WLAON_SOC_RESET_CAUSE_SHADOW_REG,
  1427. &val))
  1428. return;
  1429. cnss_pr_dbg("WLAON_SOC_RESET_CAUSE_SHADOW_REG = 0x%x\n",
  1430. val);
  1431. }
  1432. static void cnss_pci_bhi_debug_reg_dump(struct cnss_pci_data *pci_priv)
  1433. {
  1434. u32 reg_offset, val;
  1435. int i;
  1436. switch (pci_priv->device_id) {
  1437. case PEACH_DEVICE_ID:
  1438. break;
  1439. default:
  1440. return;
  1441. }
  1442. if (cnss_pci_check_link_status(pci_priv))
  1443. return;
  1444. cnss_pr_dbg("Start to dump PCIE BHIE DEBUG registers\n");
  1445. for (i = 0; pci_bhi_debug[i].name; i++) {
  1446. reg_offset = pci_bhi_debug[i].offset;
  1447. if (cnss_pci_reg_read(pci_priv, reg_offset, &val))
  1448. return;
  1449. cnss_pr_dbg("PCIE__%s = 0x%x\n",
  1450. pci_bhi_debug[i].name, val);
  1451. }
  1452. }
  1453. int cnss_suspend_pci_link(struct cnss_pci_data *pci_priv)
  1454. {
  1455. int ret = 0;
  1456. if (!pci_priv)
  1457. return -ENODEV;
  1458. if (pci_priv->pci_link_state == PCI_LINK_DOWN) {
  1459. cnss_pr_info("PCI link is already suspended\n");
  1460. goto out;
  1461. }
  1462. pci_clear_master(pci_priv->pci_dev);
  1463. ret = cnss_set_pci_config_space(pci_priv, SAVE_PCI_CONFIG_SPACE);
  1464. if (ret)
  1465. goto out;
  1466. pci_disable_device(pci_priv->pci_dev);
  1467. if (pci_priv->pci_dev->device != QCA6174_DEVICE_ID) {
  1468. ret = pci_set_power_state(pci_priv->pci_dev, PCI_D3hot);
  1469. if (ret)
  1470. cnss_pr_err("Failed to set D3Hot, err = %d\n", ret);
  1471. }
  1472. /* Always do PCIe L2 suspend during power off/PCIe link recovery */
  1473. pci_priv->drv_connected_last = 0;
  1474. ret = cnss_set_pci_link(pci_priv, PCI_LINK_DOWN);
  1475. if (ret)
  1476. goto out;
  1477. pci_priv->pci_link_state = PCI_LINK_DOWN;
  1478. return 0;
  1479. out:
  1480. return ret;
  1481. }
  1482. int cnss_resume_pci_link(struct cnss_pci_data *pci_priv)
  1483. {
  1484. int ret = 0;
  1485. if (!pci_priv)
  1486. return -ENODEV;
  1487. if (pci_priv->pci_link_state == PCI_LINK_UP) {
  1488. cnss_pr_info("PCI link is already resumed\n");
  1489. goto out;
  1490. }
  1491. ret = cnss_set_pci_link(pci_priv, PCI_LINK_UP);
  1492. if (ret) {
  1493. ret = -EAGAIN;
  1494. cnss_pci_update_link_event(pci_priv,
  1495. BUS_EVENT_PCI_LINK_RESUME_FAIL, NULL);
  1496. goto out;
  1497. }
  1498. pci_priv->pci_link_state = PCI_LINK_UP;
  1499. if (pci_priv->pci_dev->device != QCA6174_DEVICE_ID) {
  1500. ret = pci_set_power_state(pci_priv->pci_dev, PCI_D0);
  1501. if (ret) {
  1502. cnss_pr_err("Failed to set D0, err = %d\n", ret);
  1503. goto out;
  1504. }
  1505. }
  1506. ret = cnss_set_pci_config_space(pci_priv, RESTORE_PCI_CONFIG_SPACE);
  1507. if (ret)
  1508. goto out;
  1509. ret = pci_enable_device(pci_priv->pci_dev);
  1510. if (ret) {
  1511. cnss_pr_err("Failed to enable PCI device, err = %d\n", ret);
  1512. goto out;
  1513. }
  1514. pci_set_master(pci_priv->pci_dev);
  1515. if (pci_priv->pci_link_down_ind)
  1516. pci_priv->pci_link_down_ind = false;
  1517. return 0;
  1518. out:
  1519. return ret;
  1520. }
  1521. static void cnss_pci_update_link_event(struct cnss_pci_data *pci_priv,
  1522. enum cnss_bus_event_type type,
  1523. void *data)
  1524. {
  1525. struct cnss_bus_event bus_event;
  1526. bus_event.etype = type;
  1527. bus_event.event_data = data;
  1528. cnss_pci_call_driver_uevent(pci_priv, CNSS_BUS_EVENT, &bus_event);
  1529. }
  1530. void cnss_pci_handle_linkdown(struct cnss_pci_data *pci_priv)
  1531. {
  1532. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  1533. struct pci_dev *pci_dev = pci_priv->pci_dev;
  1534. unsigned long flags;
  1535. if (test_bit(ENABLE_PCI_LINK_DOWN_PANIC,
  1536. &plat_priv->ctrl_params.quirks))
  1537. panic("cnss: PCI link is down\n");
  1538. spin_lock_irqsave(&pci_link_down_lock, flags);
  1539. if (pci_priv->pci_link_down_ind) {
  1540. cnss_pr_dbg("PCI link down recovery is in progress, ignore\n");
  1541. spin_unlock_irqrestore(&pci_link_down_lock, flags);
  1542. return;
  1543. }
  1544. pci_priv->pci_link_down_ind = true;
  1545. spin_unlock_irqrestore(&pci_link_down_lock, flags);
  1546. if (pci_priv->mhi_ctrl) {
  1547. /* Notify MHI about link down*/
  1548. mhi_report_error(pci_priv->mhi_ctrl);
  1549. }
  1550. if (pci_dev->device == QCA6174_DEVICE_ID)
  1551. disable_irq_nosync(pci_dev->irq);
  1552. /* Notify bus related event. Now for all supported chips.
  1553. * Here PCIe LINK_DOWN notification taken care.
  1554. * uevent buffer can be extended later, to cover more bus info.
  1555. */
  1556. cnss_pci_update_link_event(pci_priv, BUS_EVENT_PCI_LINK_DOWN, NULL);
  1557. cnss_fatal_err("PCI link down, schedule recovery\n");
  1558. reinit_completion(&pci_priv->wake_event_complete);
  1559. cnss_schedule_recovery(&pci_dev->dev, CNSS_REASON_LINK_DOWN);
  1560. }
  1561. int cnss_pci_link_down(struct device *dev)
  1562. {
  1563. struct pci_dev *pci_dev = to_pci_dev(dev);
  1564. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  1565. struct cnss_plat_data *plat_priv = NULL;
  1566. int ret;
  1567. if (!pci_priv) {
  1568. cnss_pr_err("pci_priv is NULL\n");
  1569. return -EINVAL;
  1570. }
  1571. plat_priv = pci_priv->plat_priv;
  1572. if (!plat_priv) {
  1573. cnss_pr_err("plat_priv is NULL\n");
  1574. return -ENODEV;
  1575. }
  1576. if (pci_priv->pci_link_down_ind) {
  1577. cnss_pr_dbg("PCI link down recovery is already in progress\n");
  1578. return -EBUSY;
  1579. }
  1580. if (pci_priv->drv_connected_last &&
  1581. of_property_read_bool(plat_priv->plat_dev->dev.of_node,
  1582. "cnss-enable-self-recovery"))
  1583. plat_priv->ctrl_params.quirks |= BIT(LINK_DOWN_SELF_RECOVERY);
  1584. cnss_pr_err("PCI link down is detected by drivers\n");
  1585. ret = cnss_pci_assert_perst(pci_priv);
  1586. if (ret)
  1587. cnss_pci_handle_linkdown(pci_priv);
  1588. return ret;
  1589. }
  1590. EXPORT_SYMBOL(cnss_pci_link_down);
  1591. int cnss_pci_get_reg_dump(struct device *dev, uint8_t *buffer, uint32_t len)
  1592. {
  1593. struct pci_dev *pci_dev = to_pci_dev(dev);
  1594. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  1595. if (!pci_priv) {
  1596. cnss_pr_err("pci_priv is NULL\n");
  1597. return -ENODEV;
  1598. }
  1599. if (pci_priv->pci_link_state == PCI_LINK_DOWN) {
  1600. cnss_pr_dbg("No PCIe reg dump since PCIe is suspended(D3)\n");
  1601. return -EACCES;
  1602. }
  1603. cnss_pr_dbg("Start to get PCIe reg dump\n");
  1604. return _cnss_pci_get_reg_dump(pci_priv, buffer, len);
  1605. }
  1606. EXPORT_SYMBOL(cnss_pci_get_reg_dump);
  1607. int cnss_pcie_is_device_down(struct cnss_pci_data *pci_priv)
  1608. {
  1609. struct cnss_plat_data *plat_priv;
  1610. if (!pci_priv) {
  1611. cnss_pr_err("pci_priv is NULL\n");
  1612. return -ENODEV;
  1613. }
  1614. plat_priv = pci_priv->plat_priv;
  1615. if (!plat_priv) {
  1616. cnss_pr_err("plat_priv is NULL\n");
  1617. return -ENODEV;
  1618. }
  1619. return test_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state) |
  1620. pci_priv->pci_link_down_ind;
  1621. }
  1622. int cnss_pci_is_device_down(struct device *dev)
  1623. {
  1624. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(to_pci_dev(dev));
  1625. return cnss_pcie_is_device_down(pci_priv);
  1626. }
  1627. EXPORT_SYMBOL(cnss_pci_is_device_down);
  1628. int cnss_pci_shutdown_cleanup(struct cnss_pci_data *pci_priv)
  1629. {
  1630. int ret;
  1631. if (!pci_priv) {
  1632. cnss_pr_err("pci_priv is NULL\n");
  1633. return -ENODEV;
  1634. }
  1635. ret = del_timer(&pci_priv->dev_rddm_timer);
  1636. cnss_pr_dbg("%s RDDM timer deleted", ret ? "Active" : "Inactive");
  1637. return ret;
  1638. }
  1639. void cnss_pci_lock_reg_window(struct device *dev, unsigned long *flags)
  1640. {
  1641. spin_lock_bh(&pci_reg_window_lock);
  1642. }
  1643. EXPORT_SYMBOL(cnss_pci_lock_reg_window);
  1644. void cnss_pci_unlock_reg_window(struct device *dev, unsigned long *flags)
  1645. {
  1646. spin_unlock_bh(&pci_reg_window_lock);
  1647. }
  1648. EXPORT_SYMBOL(cnss_pci_unlock_reg_window);
  1649. int cnss_get_pci_slot(struct device *dev)
  1650. {
  1651. struct pci_dev *pci_dev = to_pci_dev(dev);
  1652. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  1653. struct cnss_plat_data *plat_priv = NULL;
  1654. if (!pci_priv) {
  1655. cnss_pr_err("pci_priv is NULL\n");
  1656. return -EINVAL;
  1657. }
  1658. plat_priv = pci_priv->plat_priv;
  1659. if (!plat_priv) {
  1660. cnss_pr_err("plat_priv is NULL\n");
  1661. return -ENODEV;
  1662. }
  1663. return plat_priv->rc_num;
  1664. }
  1665. EXPORT_SYMBOL(cnss_get_pci_slot);
  1666. /**
  1667. * cnss_pci_dump_bl_sram_mem - Dump WLAN device bootloader debug log
  1668. * @pci_priv: driver PCI bus context pointer
  1669. *
  1670. * Dump primary and secondary bootloader debug log data. For SBL check the
  1671. * log struct address and size for validity.
  1672. *
  1673. * Return: None
  1674. */
  1675. static void cnss_pci_dump_bl_sram_mem(struct cnss_pci_data *pci_priv)
  1676. {
  1677. enum mhi_ee_type ee;
  1678. u32 mem_addr, val, pbl_log_max_size, sbl_log_max_size;
  1679. u32 pbl_log_sram_start;
  1680. u32 pbl_stage, sbl_log_start, sbl_log_size;
  1681. u32 pbl_wlan_boot_cfg, pbl_bootstrap_status;
  1682. u32 pbl_bootstrap_status_reg = PBL_BOOTSTRAP_STATUS;
  1683. u32 sbl_log_def_start = SRAM_START;
  1684. u32 sbl_log_def_end = SRAM_END;
  1685. int i;
  1686. cnss_pci_soc_reset_cause_reg_dump(pci_priv);
  1687. switch (pci_priv->device_id) {
  1688. case QCA6390_DEVICE_ID:
  1689. pbl_log_sram_start = QCA6390_DEBUG_PBL_LOG_SRAM_START;
  1690. pbl_log_max_size = QCA6390_DEBUG_PBL_LOG_SRAM_MAX_SIZE;
  1691. sbl_log_max_size = QCA6390_DEBUG_SBL_LOG_SRAM_MAX_SIZE;
  1692. break;
  1693. case QCA6490_DEVICE_ID:
  1694. pbl_log_sram_start = QCA6490_DEBUG_PBL_LOG_SRAM_START;
  1695. pbl_log_max_size = QCA6490_DEBUG_PBL_LOG_SRAM_MAX_SIZE;
  1696. sbl_log_max_size = QCA6490_DEBUG_SBL_LOG_SRAM_MAX_SIZE;
  1697. break;
  1698. case KIWI_DEVICE_ID:
  1699. pbl_bootstrap_status_reg = KIWI_PBL_BOOTSTRAP_STATUS;
  1700. pbl_log_sram_start = KIWI_DEBUG_PBL_LOG_SRAM_START;
  1701. pbl_log_max_size = KIWI_DEBUG_PBL_LOG_SRAM_MAX_SIZE;
  1702. sbl_log_max_size = KIWI_DEBUG_SBL_LOG_SRAM_MAX_SIZE;
  1703. break;
  1704. case MANGO_DEVICE_ID:
  1705. pbl_bootstrap_status_reg = MANGO_PBL_BOOTSTRAP_STATUS;
  1706. pbl_log_sram_start = MANGO_DEBUG_PBL_LOG_SRAM_START;
  1707. pbl_log_max_size = MANGO_DEBUG_PBL_LOG_SRAM_MAX_SIZE;
  1708. sbl_log_max_size = MANGO_DEBUG_SBL_LOG_SRAM_MAX_SIZE;
  1709. break;
  1710. case PEACH_DEVICE_ID:
  1711. pbl_bootstrap_status_reg = PEACH_PBL_BOOTSTRAP_STATUS;
  1712. pbl_log_sram_start = PEACH_DEBUG_PBL_LOG_SRAM_START;
  1713. pbl_log_max_size = PEACH_DEBUG_PBL_LOG_SRAM_MAX_SIZE;
  1714. sbl_log_max_size = PEACH_DEBUG_SBL_LOG_SRAM_MAX_SIZE;
  1715. break;
  1716. default:
  1717. return;
  1718. }
  1719. if (cnss_pci_check_link_status(pci_priv))
  1720. return;
  1721. cnss_pci_reg_read(pci_priv, TCSR_PBL_LOGGING_REG, &pbl_stage);
  1722. cnss_pci_reg_read(pci_priv, PCIE_BHI_ERRDBG2_REG, &sbl_log_start);
  1723. cnss_pci_reg_read(pci_priv, PCIE_BHI_ERRDBG3_REG, &sbl_log_size);
  1724. cnss_pci_reg_read(pci_priv, PBL_WLAN_BOOT_CFG, &pbl_wlan_boot_cfg);
  1725. cnss_pci_reg_read(pci_priv, pbl_bootstrap_status_reg,
  1726. &pbl_bootstrap_status);
  1727. cnss_pr_dbg("TCSR_PBL_LOGGING: 0x%08x PCIE_BHI_ERRDBG: Start: 0x%08x Size:0x%08x\n",
  1728. pbl_stage, sbl_log_start, sbl_log_size);
  1729. cnss_pr_dbg("PBL_WLAN_BOOT_CFG: 0x%08x PBL_BOOTSTRAP_STATUS: 0x%08x\n",
  1730. pbl_wlan_boot_cfg, pbl_bootstrap_status);
  1731. ee = mhi_get_exec_env(pci_priv->mhi_ctrl);
  1732. if (CNSS_MHI_IN_MISSION_MODE(ee)) {
  1733. cnss_pr_err("Avoid Dumping PBL log data in Mission mode\n");
  1734. return;
  1735. }
  1736. cnss_pr_dbg("Dumping PBL log data\n");
  1737. for (i = 0; i < pbl_log_max_size; i += sizeof(val)) {
  1738. mem_addr = pbl_log_sram_start + i;
  1739. if (cnss_pci_reg_read(pci_priv, mem_addr, &val))
  1740. break;
  1741. cnss_pr_dbg("SRAM[0x%x] = 0x%x\n", mem_addr, val);
  1742. }
  1743. sbl_log_size = (sbl_log_size > sbl_log_max_size ?
  1744. sbl_log_max_size : sbl_log_size);
  1745. if (sbl_log_start < sbl_log_def_start ||
  1746. sbl_log_start > sbl_log_def_end ||
  1747. (sbl_log_start + sbl_log_size) > sbl_log_def_end) {
  1748. cnss_pr_err("Invalid SBL log data\n");
  1749. return;
  1750. }
  1751. ee = mhi_get_exec_env(pci_priv->mhi_ctrl);
  1752. if (CNSS_MHI_IN_MISSION_MODE(ee)) {
  1753. cnss_pr_err("Avoid Dumping SBL log data in Mission mode\n");
  1754. return;
  1755. }
  1756. cnss_pr_dbg("Dumping SBL log data\n");
  1757. for (i = 0; i < sbl_log_size; i += sizeof(val)) {
  1758. mem_addr = sbl_log_start + i;
  1759. if (cnss_pci_reg_read(pci_priv, mem_addr, &val))
  1760. break;
  1761. cnss_pr_dbg("SRAM[0x%x] = 0x%x\n", mem_addr, val);
  1762. }
  1763. }
  1764. #ifdef CONFIG_DISABLE_CNSS_SRAM_DUMP
  1765. static void cnss_pci_dump_sram(struct cnss_pci_data *pci_priv)
  1766. {
  1767. }
  1768. #else
  1769. static void cnss_pci_dump_sram(struct cnss_pci_data *pci_priv)
  1770. {
  1771. struct cnss_plat_data *plat_priv;
  1772. u32 i, mem_addr;
  1773. u32 *dump_ptr;
  1774. plat_priv = pci_priv->plat_priv;
  1775. if (plat_priv->device_id != QCA6490_DEVICE_ID ||
  1776. cnss_get_host_build_type() != QMI_HOST_BUILD_TYPE_PRIMARY_V01)
  1777. return;
  1778. if (!plat_priv->sram_dump) {
  1779. cnss_pr_err("SRAM dump memory is not allocated\n");
  1780. return;
  1781. }
  1782. if (cnss_pci_check_link_status(pci_priv))
  1783. return;
  1784. cnss_pr_dbg("Dumping SRAM at 0x%lx\n", plat_priv->sram_dump);
  1785. for (i = 0; i < SRAM_DUMP_SIZE; i += sizeof(u32)) {
  1786. mem_addr = SRAM_START + i;
  1787. dump_ptr = (u32 *)(plat_priv->sram_dump + i);
  1788. if (cnss_pci_reg_read(pci_priv, mem_addr, dump_ptr)) {
  1789. cnss_pr_err("SRAM Dump failed at 0x%x\n", mem_addr);
  1790. break;
  1791. }
  1792. /* Relinquish CPU after dumping 256KB chunks*/
  1793. if (!(i % CNSS_256KB_SIZE))
  1794. cond_resched();
  1795. }
  1796. }
  1797. #endif
  1798. static int cnss_pci_handle_mhi_poweron_timeout(struct cnss_pci_data *pci_priv)
  1799. {
  1800. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  1801. cnss_fatal_err("MHI power up returns timeout\n");
  1802. if (cnss_mhi_scan_rddm_cookie(pci_priv, DEVICE_RDDM_COOKIE) ||
  1803. cnss_get_dev_sol_value(plat_priv) > 0) {
  1804. /* Wait for RDDM if RDDM cookie is set or device SOL GPIO is
  1805. * high. If RDDM times out, PBL/SBL error region may have been
  1806. * erased so no need to dump them either.
  1807. */
  1808. if (!test_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state) &&
  1809. !pci_priv->pci_link_down_ind) {
  1810. mod_timer(&pci_priv->dev_rddm_timer,
  1811. jiffies + msecs_to_jiffies(DEV_RDDM_TIMEOUT));
  1812. }
  1813. } else {
  1814. cnss_pr_dbg("RDDM cookie is not set and device SOL is low\n");
  1815. cnss_mhi_debug_reg_dump(pci_priv);
  1816. cnss_pci_bhi_debug_reg_dump(pci_priv);
  1817. cnss_pci_soc_scratch_reg_dump(pci_priv);
  1818. /* Dump PBL/SBL error log if RDDM cookie is not set */
  1819. cnss_pci_dump_bl_sram_mem(pci_priv);
  1820. cnss_pci_dump_sram(pci_priv);
  1821. return -ETIMEDOUT;
  1822. }
  1823. return 0;
  1824. }
  1825. static char *cnss_mhi_state_to_str(enum cnss_mhi_state mhi_state)
  1826. {
  1827. switch (mhi_state) {
  1828. case CNSS_MHI_INIT:
  1829. return "INIT";
  1830. case CNSS_MHI_DEINIT:
  1831. return "DEINIT";
  1832. case CNSS_MHI_POWER_ON:
  1833. return "POWER_ON";
  1834. case CNSS_MHI_POWERING_OFF:
  1835. return "POWERING_OFF";
  1836. case CNSS_MHI_POWER_OFF:
  1837. return "POWER_OFF";
  1838. case CNSS_MHI_FORCE_POWER_OFF:
  1839. return "FORCE_POWER_OFF";
  1840. case CNSS_MHI_SUSPEND:
  1841. return "SUSPEND";
  1842. case CNSS_MHI_RESUME:
  1843. return "RESUME";
  1844. case CNSS_MHI_TRIGGER_RDDM:
  1845. return "TRIGGER_RDDM";
  1846. case CNSS_MHI_RDDM_DONE:
  1847. return "RDDM_DONE";
  1848. default:
  1849. return "UNKNOWN";
  1850. }
  1851. };
  1852. static int cnss_pci_check_mhi_state_bit(struct cnss_pci_data *pci_priv,
  1853. enum cnss_mhi_state mhi_state)
  1854. {
  1855. switch (mhi_state) {
  1856. case CNSS_MHI_INIT:
  1857. if (!test_bit(CNSS_MHI_INIT, &pci_priv->mhi_state))
  1858. return 0;
  1859. break;
  1860. case CNSS_MHI_DEINIT:
  1861. case CNSS_MHI_POWER_ON:
  1862. if (test_bit(CNSS_MHI_INIT, &pci_priv->mhi_state) &&
  1863. !test_bit(CNSS_MHI_POWER_ON, &pci_priv->mhi_state))
  1864. return 0;
  1865. break;
  1866. case CNSS_MHI_FORCE_POWER_OFF:
  1867. if (test_bit(CNSS_MHI_POWER_ON, &pci_priv->mhi_state))
  1868. return 0;
  1869. break;
  1870. case CNSS_MHI_POWER_OFF:
  1871. case CNSS_MHI_SUSPEND:
  1872. if (test_bit(CNSS_MHI_POWER_ON, &pci_priv->mhi_state) &&
  1873. !test_bit(CNSS_MHI_SUSPEND, &pci_priv->mhi_state))
  1874. return 0;
  1875. break;
  1876. case CNSS_MHI_RESUME:
  1877. if (test_bit(CNSS_MHI_SUSPEND, &pci_priv->mhi_state))
  1878. return 0;
  1879. break;
  1880. case CNSS_MHI_TRIGGER_RDDM:
  1881. if (test_bit(CNSS_MHI_POWER_ON, &pci_priv->mhi_state) &&
  1882. !test_bit(CNSS_MHI_TRIGGER_RDDM, &pci_priv->mhi_state))
  1883. return 0;
  1884. break;
  1885. case CNSS_MHI_RDDM_DONE:
  1886. return 0;
  1887. default:
  1888. cnss_pr_err("Unhandled MHI state: %s(%d)\n",
  1889. cnss_mhi_state_to_str(mhi_state), mhi_state);
  1890. }
  1891. cnss_pr_err("Cannot set MHI state %s(%d) in current MHI state (0x%lx)\n",
  1892. cnss_mhi_state_to_str(mhi_state), mhi_state,
  1893. pci_priv->mhi_state);
  1894. if (mhi_state != CNSS_MHI_TRIGGER_RDDM)
  1895. CNSS_ASSERT(0);
  1896. return -EINVAL;
  1897. }
  1898. static int cnss_rddm_trigger_debug(struct cnss_pci_data *pci_priv)
  1899. {
  1900. int read_val, ret;
  1901. if (!pci_priv || pci_priv->device_id != QCA6490_DEVICE_ID)
  1902. return -EOPNOTSUPP;
  1903. if (cnss_pci_check_link_status(pci_priv))
  1904. return -EINVAL;
  1905. cnss_pr_err("Write GCC Spare with ACE55 Pattern");
  1906. cnss_pci_reg_write(pci_priv, GCC_GCC_SPARE_REG_1, 0xACE55);
  1907. ret = cnss_pci_reg_read(pci_priv, GCC_GCC_SPARE_REG_1, &read_val);
  1908. cnss_pr_err("Read back GCC Spare: 0x%x, ret: %d", read_val, ret);
  1909. ret = cnss_pci_reg_read(pci_priv, GCC_PRE_ARES_DEBUG_TIMER_VAL,
  1910. &read_val);
  1911. cnss_pr_err("Warm reset allowed check: 0x%x, ret: %d", read_val, ret);
  1912. return ret;
  1913. }
  1914. static int cnss_rddm_trigger_check(struct cnss_pci_data *pci_priv)
  1915. {
  1916. int read_val, ret;
  1917. u32 pbl_stage, sbl_log_start, sbl_log_size, pbl_wlan_boot_cfg;
  1918. if (!pci_priv || pci_priv->device_id != QCA6490_DEVICE_ID)
  1919. return -EOPNOTSUPP;
  1920. if (cnss_pci_check_link_status(pci_priv))
  1921. return -EINVAL;
  1922. ret = cnss_pci_reg_read(pci_priv, GCC_GCC_SPARE_REG_1, &read_val);
  1923. cnss_pr_err("Read GCC spare to check reset status: 0x%x, ret: %d",
  1924. read_val, ret);
  1925. cnss_pci_reg_read(pci_priv, TCSR_PBL_LOGGING_REG, &pbl_stage);
  1926. cnss_pci_reg_read(pci_priv, PCIE_BHI_ERRDBG2_REG, &sbl_log_start);
  1927. cnss_pci_reg_read(pci_priv, PCIE_BHI_ERRDBG3_REG, &sbl_log_size);
  1928. cnss_pci_reg_read(pci_priv, PBL_WLAN_BOOT_CFG, &pbl_wlan_boot_cfg);
  1929. cnss_pr_dbg("TCSR_PBL_LOGGING: 0x%08x PCIE_BHI_ERRDBG: Start: 0x%08x Size:0x%08x \n",
  1930. pbl_stage, sbl_log_start, sbl_log_size);
  1931. cnss_pr_dbg("PBL_WLAN_BOOT_CFG: 0x%08x\n", pbl_wlan_boot_cfg);
  1932. return ret;
  1933. }
  1934. static void cnss_pci_set_mhi_state_bit(struct cnss_pci_data *pci_priv,
  1935. enum cnss_mhi_state mhi_state)
  1936. {
  1937. switch (mhi_state) {
  1938. case CNSS_MHI_INIT:
  1939. set_bit(CNSS_MHI_INIT, &pci_priv->mhi_state);
  1940. break;
  1941. case CNSS_MHI_DEINIT:
  1942. clear_bit(CNSS_MHI_INIT, &pci_priv->mhi_state);
  1943. break;
  1944. case CNSS_MHI_POWER_ON:
  1945. set_bit(CNSS_MHI_POWER_ON, &pci_priv->mhi_state);
  1946. break;
  1947. case CNSS_MHI_POWERING_OFF:
  1948. set_bit(CNSS_MHI_POWERING_OFF, &pci_priv->mhi_state);
  1949. break;
  1950. case CNSS_MHI_POWER_OFF:
  1951. case CNSS_MHI_FORCE_POWER_OFF:
  1952. clear_bit(CNSS_MHI_POWER_ON, &pci_priv->mhi_state);
  1953. clear_bit(CNSS_MHI_POWERING_OFF, &pci_priv->mhi_state);
  1954. clear_bit(CNSS_MHI_TRIGGER_RDDM, &pci_priv->mhi_state);
  1955. clear_bit(CNSS_MHI_RDDM_DONE, &pci_priv->mhi_state);
  1956. break;
  1957. case CNSS_MHI_SUSPEND:
  1958. set_bit(CNSS_MHI_SUSPEND, &pci_priv->mhi_state);
  1959. break;
  1960. case CNSS_MHI_RESUME:
  1961. clear_bit(CNSS_MHI_SUSPEND, &pci_priv->mhi_state);
  1962. break;
  1963. case CNSS_MHI_TRIGGER_RDDM:
  1964. set_bit(CNSS_MHI_TRIGGER_RDDM, &pci_priv->mhi_state);
  1965. break;
  1966. case CNSS_MHI_RDDM_DONE:
  1967. set_bit(CNSS_MHI_RDDM_DONE, &pci_priv->mhi_state);
  1968. break;
  1969. default:
  1970. cnss_pr_err("Unhandled MHI state (%d)\n", mhi_state);
  1971. }
  1972. }
  1973. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0))
  1974. static int cnss_mhi_pm_force_resume(struct cnss_pci_data *pci_priv)
  1975. {
  1976. return mhi_pm_resume_force(pci_priv->mhi_ctrl);
  1977. }
  1978. #else
  1979. static int cnss_mhi_pm_force_resume(struct cnss_pci_data *pci_priv)
  1980. {
  1981. return mhi_pm_resume(pci_priv->mhi_ctrl);
  1982. }
  1983. #endif
  1984. static int cnss_pci_set_mhi_state(struct cnss_pci_data *pci_priv,
  1985. enum cnss_mhi_state mhi_state)
  1986. {
  1987. int ret = 0, retry = 0;
  1988. if (pci_priv->device_id == QCA6174_DEVICE_ID)
  1989. return 0;
  1990. if (mhi_state < 0) {
  1991. cnss_pr_err("Invalid MHI state (%d)\n", mhi_state);
  1992. return -EINVAL;
  1993. }
  1994. ret = cnss_pci_check_mhi_state_bit(pci_priv, mhi_state);
  1995. if (ret)
  1996. goto out;
  1997. cnss_pr_vdbg("Setting MHI state: %s(%d)\n",
  1998. cnss_mhi_state_to_str(mhi_state), mhi_state);
  1999. switch (mhi_state) {
  2000. case CNSS_MHI_INIT:
  2001. ret = mhi_prepare_for_power_up(pci_priv->mhi_ctrl);
  2002. break;
  2003. case CNSS_MHI_DEINIT:
  2004. mhi_unprepare_after_power_down(pci_priv->mhi_ctrl);
  2005. ret = 0;
  2006. break;
  2007. case CNSS_MHI_POWER_ON:
  2008. ret = mhi_sync_power_up(pci_priv->mhi_ctrl);
  2009. #if IS_ENABLED(CONFIG_MHI_BUS_MISC)
  2010. /* Only set img_pre_alloc when power up succeeds */
  2011. if (!ret && !pci_priv->mhi_ctrl->img_pre_alloc) {
  2012. cnss_pr_dbg("Notify MHI to use already allocated images\n");
  2013. pci_priv->mhi_ctrl->img_pre_alloc = true;
  2014. }
  2015. #endif
  2016. break;
  2017. case CNSS_MHI_POWER_OFF:
  2018. mhi_power_down(pci_priv->mhi_ctrl, true);
  2019. ret = 0;
  2020. break;
  2021. case CNSS_MHI_FORCE_POWER_OFF:
  2022. mhi_power_down(pci_priv->mhi_ctrl, false);
  2023. ret = 0;
  2024. break;
  2025. case CNSS_MHI_SUSPEND:
  2026. retry_mhi_suspend:
  2027. mutex_lock(&pci_priv->mhi_ctrl->pm_mutex);
  2028. if (pci_priv->drv_connected_last)
  2029. ret = cnss_mhi_pm_fast_suspend(pci_priv, true);
  2030. else
  2031. ret = mhi_pm_suspend(pci_priv->mhi_ctrl);
  2032. mutex_unlock(&pci_priv->mhi_ctrl->pm_mutex);
  2033. if (ret == -EBUSY && retry++ < MHI_SUSPEND_RETRY_MAX_TIMES) {
  2034. cnss_pr_vdbg("Retry MHI suspend #%d\n", retry);
  2035. usleep_range(MHI_SUSPEND_RETRY_DELAY_US,
  2036. MHI_SUSPEND_RETRY_DELAY_US + 1000);
  2037. goto retry_mhi_suspend;
  2038. }
  2039. break;
  2040. case CNSS_MHI_RESUME:
  2041. mutex_lock(&pci_priv->mhi_ctrl->pm_mutex);
  2042. if (pci_priv->drv_connected_last) {
  2043. ret = cnss_pci_prevent_l1(&pci_priv->pci_dev->dev);
  2044. if (ret) {
  2045. mutex_unlock(&pci_priv->mhi_ctrl->pm_mutex);
  2046. break;
  2047. }
  2048. ret = cnss_mhi_pm_fast_resume(pci_priv, true);
  2049. cnss_pci_allow_l1(&pci_priv->pci_dev->dev);
  2050. } else {
  2051. if (pci_priv->device_id == QCA6390_DEVICE_ID)
  2052. ret = cnss_mhi_pm_force_resume(pci_priv);
  2053. else
  2054. ret = mhi_pm_resume(pci_priv->mhi_ctrl);
  2055. }
  2056. mutex_unlock(&pci_priv->mhi_ctrl->pm_mutex);
  2057. break;
  2058. case CNSS_MHI_TRIGGER_RDDM:
  2059. cnss_rddm_trigger_debug(pci_priv);
  2060. ret = mhi_force_rddm_mode(pci_priv->mhi_ctrl);
  2061. if (ret) {
  2062. cnss_pr_err("Failed to trigger RDDM, err = %d\n", ret);
  2063. cnss_rddm_trigger_check(pci_priv);
  2064. }
  2065. break;
  2066. case CNSS_MHI_RDDM_DONE:
  2067. break;
  2068. default:
  2069. cnss_pr_err("Unhandled MHI state (%d)\n", mhi_state);
  2070. ret = -EINVAL;
  2071. }
  2072. if (ret)
  2073. goto out;
  2074. cnss_pci_set_mhi_state_bit(pci_priv, mhi_state);
  2075. return 0;
  2076. out:
  2077. cnss_pr_err("Failed to set MHI state: %s(%d), err = %d\n",
  2078. cnss_mhi_state_to_str(mhi_state), mhi_state, ret);
  2079. return ret;
  2080. }
  2081. static int cnss_pci_config_msi_addr(struct cnss_pci_data *pci_priv)
  2082. {
  2083. int ret = 0;
  2084. struct pci_dev *pci_dev = pci_priv->pci_dev;
  2085. struct cnss_plat_data *plat_priv;
  2086. if (!pci_dev)
  2087. return -ENODEV;
  2088. if (!pci_dev->msix_enabled)
  2089. return ret;
  2090. plat_priv = pci_priv->plat_priv;
  2091. if (!plat_priv) {
  2092. cnss_pr_err("plat_priv is NULL\n");
  2093. return -ENODEV;
  2094. }
  2095. ret = of_property_read_u32(plat_priv->plat_dev->dev.of_node,
  2096. "msix-match-addr",
  2097. &pci_priv->msix_addr);
  2098. cnss_pr_dbg("MSI-X Match address is 0x%X\n",
  2099. pci_priv->msix_addr);
  2100. return ret;
  2101. }
  2102. static int cnss_pci_config_msi_data(struct cnss_pci_data *pci_priv)
  2103. {
  2104. struct msi_desc *msi_desc;
  2105. struct cnss_msi_config *msi_config;
  2106. struct pci_dev *pci_dev = pci_priv->pci_dev;
  2107. msi_config = pci_priv->msi_config;
  2108. if (pci_dev->msix_enabled) {
  2109. pci_priv->msi_ep_base_data = msi_config->users[0].base_vector;
  2110. cnss_pr_dbg("MSI-X base data is %d\n",
  2111. pci_priv->msi_ep_base_data);
  2112. return 0;
  2113. }
  2114. msi_desc = irq_get_msi_desc(pci_dev->irq);
  2115. if (!msi_desc) {
  2116. cnss_pr_err("msi_desc is NULL!\n");
  2117. return -EINVAL;
  2118. }
  2119. pci_priv->msi_ep_base_data = msi_desc->msg.data;
  2120. cnss_pr_dbg("MSI base data is %d\n", pci_priv->msi_ep_base_data);
  2121. return 0;
  2122. }
  2123. #ifdef CONFIG_CNSS_SUPPORT_DUAL_DEV
  2124. #define PLC_PCIE_NAME_LEN 14
  2125. static struct cnss_plat_data *
  2126. cnss_get_plat_priv_by_driver_ops(struct cnss_wlan_driver *driver_ops)
  2127. {
  2128. int plat_env_count = cnss_get_plat_env_count();
  2129. struct cnss_plat_data *plat_env;
  2130. struct cnss_pci_data *pci_priv;
  2131. int i = 0;
  2132. if (!driver_ops) {
  2133. cnss_pr_err("No cnss driver\n");
  2134. return NULL;
  2135. }
  2136. for (i = 0; i < plat_env_count; i++) {
  2137. plat_env = cnss_get_plat_env(i);
  2138. if (!plat_env)
  2139. continue;
  2140. if (driver_ops->name && plat_env->pld_bus_ops_name) {
  2141. /* driver_ops->name = PLD_PCIE_OPS_NAME
  2142. * #ifdef MULTI_IF_NAME
  2143. * #define PLD_PCIE_OPS_NAME "pld_pcie_" MULTI_IF_NAME
  2144. * #else
  2145. * #define PLD_PCIE_OPS_NAME "pld_pcie"
  2146. * #endif
  2147. */
  2148. if (memcmp(driver_ops->name,
  2149. plat_env->pld_bus_ops_name,
  2150. PLC_PCIE_NAME_LEN) == 0)
  2151. return plat_env;
  2152. }
  2153. }
  2154. cnss_pr_vdbg("Invalid cnss driver name from ko %s\n", driver_ops->name);
  2155. /* in the dual wlan card case, the pld_bus_ops_name from dts
  2156. * and driver_ops-> name from ko should match, otherwise
  2157. * wlanhost driver don't know which plat_env it can use;
  2158. * if doesn't find the match one, then get first available
  2159. * instance insteadly.
  2160. */
  2161. for (i = 0; i < plat_env_count; i++) {
  2162. plat_env = cnss_get_plat_env(i);
  2163. if (!plat_env)
  2164. continue;
  2165. pci_priv = plat_env->bus_priv;
  2166. if (!pci_priv) {
  2167. cnss_pr_err("pci_priv is NULL\n");
  2168. continue;
  2169. }
  2170. if (driver_ops == pci_priv->driver_ops)
  2171. return plat_env;
  2172. }
  2173. /* Doesn't find the existing instance,
  2174. * so return the fist empty instance
  2175. */
  2176. for (i = 0; i < plat_env_count; i++) {
  2177. plat_env = cnss_get_plat_env(i);
  2178. if (!plat_env)
  2179. continue;
  2180. pci_priv = plat_env->bus_priv;
  2181. if (!pci_priv) {
  2182. cnss_pr_err("pci_priv is NULL\n");
  2183. continue;
  2184. }
  2185. if (!pci_priv->driver_ops)
  2186. return plat_env;
  2187. }
  2188. return NULL;
  2189. }
  2190. static int cnss_pci_store_qrtr_node_id(struct cnss_pci_data *pci_priv)
  2191. {
  2192. int ret = 0;
  2193. u32 scratch = QCA6390_PCIE_SOC_PCIE_REG_PCIE_SCRATCH_2_SOC_PCIE_REG;
  2194. struct cnss_plat_data *plat_priv;
  2195. if (!pci_priv) {
  2196. cnss_pr_err("pci_priv is NULL\n");
  2197. return -ENODEV;
  2198. }
  2199. plat_priv = pci_priv->plat_priv;
  2200. /**
  2201. * in the single wlan chipset case, plat_priv->qrtr_node_id always is 0,
  2202. * wlan fw will use the hardcode 7 as the qrtr node id.
  2203. * in the dual Hastings case, we will read qrtr node id
  2204. * from device tree and pass to get plat_priv->qrtr_node_id,
  2205. * which always is not zero. And then store this new value
  2206. * to pcie register, wlan fw will read out this qrtr node id
  2207. * from this register and overwrite to the hardcode one
  2208. * while do initialization for ipc router.
  2209. * without this change, two Hastings will use the same
  2210. * qrtr node instance id, which will mess up qmi message
  2211. * exchange. According to qrtr spec, every node should
  2212. * have unique qrtr node id
  2213. */
  2214. if (plat_priv->device_id == QCA6390_DEVICE_ID &&
  2215. plat_priv->qrtr_node_id) {
  2216. u32 val;
  2217. cnss_pr_dbg("write 0x%x to SCRATCH REG\n",
  2218. plat_priv->qrtr_node_id);
  2219. ret = cnss_pci_reg_write(pci_priv, scratch,
  2220. plat_priv->qrtr_node_id);
  2221. if (ret) {
  2222. cnss_pr_err("Failed to write register offset 0x%x, err = %d\n",
  2223. scratch, ret);
  2224. goto out;
  2225. }
  2226. ret = cnss_pci_reg_read(pci_priv, scratch, &val);
  2227. if (ret) {
  2228. cnss_pr_err("Failed to read SCRATCH REG");
  2229. goto out;
  2230. }
  2231. if (val != plat_priv->qrtr_node_id) {
  2232. cnss_pr_err("qrtr node id write to register doesn't match with readout value");
  2233. return -ERANGE;
  2234. }
  2235. }
  2236. out:
  2237. return ret;
  2238. }
  2239. #else
  2240. static struct cnss_plat_data *
  2241. cnss_get_plat_priv_by_driver_ops(struct cnss_wlan_driver *driver_ops)
  2242. {
  2243. return cnss_bus_dev_to_plat_priv(NULL);
  2244. }
  2245. static int cnss_pci_store_qrtr_node_id(struct cnss_pci_data *pci_priv)
  2246. {
  2247. return 0;
  2248. }
  2249. #endif
  2250. int cnss_pci_start_mhi(struct cnss_pci_data *pci_priv)
  2251. {
  2252. int ret = 0;
  2253. struct cnss_plat_data *plat_priv;
  2254. unsigned int timeout = 0;
  2255. int retry = 0;
  2256. if (!pci_priv) {
  2257. cnss_pr_err("pci_priv is NULL\n");
  2258. return -ENODEV;
  2259. }
  2260. plat_priv = pci_priv->plat_priv;
  2261. if (test_bit(FBC_BYPASS, &plat_priv->ctrl_params.quirks))
  2262. return 0;
  2263. if (MHI_TIMEOUT_OVERWRITE_MS)
  2264. pci_priv->mhi_ctrl->timeout_ms = MHI_TIMEOUT_OVERWRITE_MS;
  2265. cnss_mhi_set_m2_timeout_ms(pci_priv, MHI_M2_TIMEOUT_MS);
  2266. ret = cnss_pci_set_mhi_state(pci_priv, CNSS_MHI_INIT);
  2267. if (ret)
  2268. return ret;
  2269. timeout = pci_priv->mhi_ctrl->timeout_ms;
  2270. /* For non-perf builds the timeout is 10 (default) * 6 seconds */
  2271. if (cnss_get_host_build_type() == QMI_HOST_BUILD_TYPE_PRIMARY_V01)
  2272. pci_priv->mhi_ctrl->timeout_ms *= 6;
  2273. else /* For perf builds the timeout is 10 (default) * 3 seconds */
  2274. pci_priv->mhi_ctrl->timeout_ms *= 3;
  2275. retry:
  2276. ret = cnss_pci_store_qrtr_node_id(pci_priv);
  2277. if (ret) {
  2278. if (retry++ < REG_RETRY_MAX_TIMES)
  2279. goto retry;
  2280. else
  2281. return ret;
  2282. }
  2283. /* Start the timer to dump MHI/PBL/SBL debug data periodically */
  2284. mod_timer(&pci_priv->boot_debug_timer,
  2285. jiffies + msecs_to_jiffies(BOOT_DEBUG_TIMEOUT_MS));
  2286. ret = cnss_pci_set_mhi_state(pci_priv, CNSS_MHI_POWER_ON);
  2287. del_timer_sync(&pci_priv->boot_debug_timer);
  2288. if (ret == 0)
  2289. cnss_wlan_adsp_pc_enable(pci_priv, false);
  2290. pci_priv->mhi_ctrl->timeout_ms = timeout;
  2291. if (ret == -ETIMEDOUT) {
  2292. /* This is a special case needs to be handled that if MHI
  2293. * power on returns -ETIMEDOUT, controller needs to take care
  2294. * the cleanup by calling MHI power down. Force to set the bit
  2295. * for driver internal MHI state to make sure it can be handled
  2296. * properly later.
  2297. */
  2298. set_bit(CNSS_MHI_POWER_ON, &pci_priv->mhi_state);
  2299. ret = cnss_pci_handle_mhi_poweron_timeout(pci_priv);
  2300. } else if (!ret) {
  2301. /* kernel may allocate a dummy vector before request_irq and
  2302. * then allocate a real vector when request_irq is called.
  2303. * So get msi_data here again to avoid spurious interrupt
  2304. * as msi_data will configured to srngs.
  2305. */
  2306. if (cnss_pci_is_one_msi(pci_priv))
  2307. ret = cnss_pci_config_msi_data(pci_priv);
  2308. }
  2309. return ret;
  2310. }
  2311. static void cnss_pci_power_off_mhi(struct cnss_pci_data *pci_priv)
  2312. {
  2313. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  2314. if (test_bit(FBC_BYPASS, &plat_priv->ctrl_params.quirks))
  2315. return;
  2316. if (!test_bit(CNSS_MHI_POWER_ON, &pci_priv->mhi_state)) {
  2317. cnss_pr_dbg("MHI is already powered off\n");
  2318. return;
  2319. }
  2320. cnss_wlan_adsp_pc_enable(pci_priv, true);
  2321. cnss_pci_set_mhi_state_bit(pci_priv, CNSS_MHI_RESUME);
  2322. cnss_pci_set_mhi_state_bit(pci_priv, CNSS_MHI_POWERING_OFF);
  2323. if (!pci_priv->pci_link_down_ind)
  2324. cnss_pci_set_mhi_state(pci_priv, CNSS_MHI_POWER_OFF);
  2325. else
  2326. cnss_pci_set_mhi_state(pci_priv, CNSS_MHI_FORCE_POWER_OFF);
  2327. }
  2328. static void cnss_pci_deinit_mhi(struct cnss_pci_data *pci_priv)
  2329. {
  2330. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  2331. if (test_bit(FBC_BYPASS, &plat_priv->ctrl_params.quirks))
  2332. return;
  2333. if (!test_bit(CNSS_MHI_INIT, &pci_priv->mhi_state)) {
  2334. cnss_pr_dbg("MHI is already deinited\n");
  2335. return;
  2336. }
  2337. cnss_pci_set_mhi_state(pci_priv, CNSS_MHI_DEINIT);
  2338. }
  2339. static void cnss_pci_set_wlaon_pwr_ctrl(struct cnss_pci_data *pci_priv,
  2340. bool set_vddd4blow, bool set_shutdown,
  2341. bool do_force_wake)
  2342. {
  2343. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  2344. int ret;
  2345. u32 val;
  2346. if (!plat_priv->set_wlaon_pwr_ctrl)
  2347. return;
  2348. if (pci_priv->pci_link_state == PCI_LINK_DOWN ||
  2349. pci_priv->pci_link_down_ind)
  2350. return;
  2351. if (do_force_wake)
  2352. if (cnss_pci_force_wake_get(pci_priv))
  2353. return;
  2354. ret = cnss_pci_reg_read(pci_priv, WLAON_QFPROM_PWR_CTRL_REG, &val);
  2355. if (ret) {
  2356. cnss_pr_err("Failed to read register offset 0x%x, err = %d\n",
  2357. WLAON_QFPROM_PWR_CTRL_REG, ret);
  2358. goto force_wake_put;
  2359. }
  2360. cnss_pr_dbg("Read register offset 0x%x, val = 0x%x\n",
  2361. WLAON_QFPROM_PWR_CTRL_REG, val);
  2362. if (set_vddd4blow)
  2363. val |= QFPROM_PWR_CTRL_VDD4BLOW_SW_EN_MASK;
  2364. else
  2365. val &= ~QFPROM_PWR_CTRL_VDD4BLOW_SW_EN_MASK;
  2366. if (set_shutdown)
  2367. val |= QFPROM_PWR_CTRL_SHUTDOWN_EN_MASK;
  2368. else
  2369. val &= ~QFPROM_PWR_CTRL_SHUTDOWN_EN_MASK;
  2370. ret = cnss_pci_reg_write(pci_priv, WLAON_QFPROM_PWR_CTRL_REG, val);
  2371. if (ret) {
  2372. cnss_pr_err("Failed to write register offset 0x%x, err = %d\n",
  2373. WLAON_QFPROM_PWR_CTRL_REG, ret);
  2374. goto force_wake_put;
  2375. }
  2376. cnss_pr_dbg("Write val 0x%x to register offset 0x%x\n", val,
  2377. WLAON_QFPROM_PWR_CTRL_REG);
  2378. if (set_shutdown)
  2379. usleep_range(WLAON_PWR_CTRL_SHUTDOWN_DELAY_MIN_US,
  2380. WLAON_PWR_CTRL_SHUTDOWN_DELAY_MAX_US);
  2381. force_wake_put:
  2382. if (do_force_wake)
  2383. cnss_pci_force_wake_put(pci_priv);
  2384. }
  2385. static int cnss_pci_get_device_timestamp(struct cnss_pci_data *pci_priv,
  2386. u64 *time_us)
  2387. {
  2388. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  2389. u32 low, high;
  2390. u64 device_ticks;
  2391. if (!plat_priv->device_freq_hz) {
  2392. cnss_pr_err("Device time clock frequency is not valid\n");
  2393. return -EINVAL;
  2394. }
  2395. switch (pci_priv->device_id) {
  2396. case KIWI_DEVICE_ID:
  2397. case MANGO_DEVICE_ID:
  2398. case PEACH_DEVICE_ID:
  2399. cnss_pci_reg_read(pci_priv, PCIE_MHI_TIME_LOW, &low);
  2400. cnss_pci_reg_read(pci_priv, PCIE_MHI_TIME_HIGH, &high);
  2401. break;
  2402. default:
  2403. cnss_pci_reg_read(pci_priv, WLAON_GLOBAL_COUNTER_CTRL3, &low);
  2404. cnss_pci_reg_read(pci_priv, WLAON_GLOBAL_COUNTER_CTRL4, &high);
  2405. break;
  2406. }
  2407. device_ticks = (u64)high << 32 | low;
  2408. do_div(device_ticks, plat_priv->device_freq_hz / 100000);
  2409. *time_us = device_ticks * 10;
  2410. return 0;
  2411. }
  2412. static void cnss_pci_enable_time_sync_counter(struct cnss_pci_data *pci_priv)
  2413. {
  2414. switch (pci_priv->device_id) {
  2415. case KIWI_DEVICE_ID:
  2416. case MANGO_DEVICE_ID:
  2417. case PEACH_DEVICE_ID:
  2418. return;
  2419. default:
  2420. break;
  2421. }
  2422. cnss_pci_reg_write(pci_priv, WLAON_GLOBAL_COUNTER_CTRL5,
  2423. TIME_SYNC_ENABLE);
  2424. }
  2425. static void cnss_pci_clear_time_sync_counter(struct cnss_pci_data *pci_priv)
  2426. {
  2427. switch (pci_priv->device_id) {
  2428. case KIWI_DEVICE_ID:
  2429. case MANGO_DEVICE_ID:
  2430. case PEACH_DEVICE_ID:
  2431. return;
  2432. default:
  2433. break;
  2434. }
  2435. cnss_pci_reg_write(pci_priv, WLAON_GLOBAL_COUNTER_CTRL5,
  2436. TIME_SYNC_CLEAR);
  2437. }
  2438. static void cnss_pci_time_sync_reg_update(struct cnss_pci_data *pci_priv,
  2439. u32 low, u32 high)
  2440. {
  2441. u32 time_reg_low;
  2442. u32 time_reg_high;
  2443. switch (pci_priv->device_id) {
  2444. case KIWI_DEVICE_ID:
  2445. case MANGO_DEVICE_ID:
  2446. case PEACH_DEVICE_ID:
  2447. /* Use the next two shadow registers after host's usage */
  2448. time_reg_low = PCIE_SHADOW_REG_VALUE_0 +
  2449. (pci_priv->plat_priv->num_shadow_regs_v3 *
  2450. SHADOW_REG_LEN_BYTES);
  2451. time_reg_high = time_reg_low + SHADOW_REG_LEN_BYTES;
  2452. break;
  2453. default:
  2454. time_reg_low = PCIE_SHADOW_REG_VALUE_34;
  2455. time_reg_high = PCIE_SHADOW_REG_VALUE_35;
  2456. break;
  2457. }
  2458. cnss_pci_reg_write(pci_priv, time_reg_low, low);
  2459. cnss_pci_reg_write(pci_priv, time_reg_high, high);
  2460. cnss_pci_reg_read(pci_priv, time_reg_low, &low);
  2461. cnss_pci_reg_read(pci_priv, time_reg_high, &high);
  2462. cnss_pr_dbg("Updated time sync regs [0x%x] = 0x%x, [0x%x] = 0x%x\n",
  2463. time_reg_low, low, time_reg_high, high);
  2464. }
  2465. static int cnss_pci_update_timestamp(struct cnss_pci_data *pci_priv)
  2466. {
  2467. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  2468. struct device *dev = &pci_priv->pci_dev->dev;
  2469. unsigned long flags = 0;
  2470. u64 host_time_us, device_time_us, offset;
  2471. u32 low, high;
  2472. int ret;
  2473. ret = cnss_pci_prevent_l1(dev);
  2474. if (ret)
  2475. goto out;
  2476. ret = cnss_pci_force_wake_get(pci_priv);
  2477. if (ret)
  2478. goto allow_l1;
  2479. spin_lock_irqsave(&time_sync_lock, flags);
  2480. cnss_pci_clear_time_sync_counter(pci_priv);
  2481. cnss_pci_enable_time_sync_counter(pci_priv);
  2482. host_time_us = cnss_get_host_timestamp(plat_priv);
  2483. ret = cnss_pci_get_device_timestamp(pci_priv, &device_time_us);
  2484. cnss_pci_clear_time_sync_counter(pci_priv);
  2485. spin_unlock_irqrestore(&time_sync_lock, flags);
  2486. if (ret)
  2487. goto force_wake_put;
  2488. if (host_time_us < device_time_us) {
  2489. cnss_pr_err("Host time (%llu us) is smaller than device time (%llu us), stop\n",
  2490. host_time_us, device_time_us);
  2491. ret = -EINVAL;
  2492. goto force_wake_put;
  2493. }
  2494. offset = host_time_us - device_time_us;
  2495. cnss_pr_dbg("Host time = %llu us, device time = %llu us, offset = %llu us\n",
  2496. host_time_us, device_time_us, offset);
  2497. low = offset & 0xFFFFFFFF;
  2498. high = offset >> 32;
  2499. cnss_pci_time_sync_reg_update(pci_priv, low, high);
  2500. force_wake_put:
  2501. cnss_pci_force_wake_put(pci_priv);
  2502. allow_l1:
  2503. cnss_pci_allow_l1(dev);
  2504. out:
  2505. return ret;
  2506. }
  2507. static void cnss_pci_time_sync_work_hdlr(struct work_struct *work)
  2508. {
  2509. struct cnss_pci_data *pci_priv =
  2510. container_of(work, struct cnss_pci_data, time_sync_work.work);
  2511. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  2512. unsigned int time_sync_period_ms =
  2513. plat_priv->ctrl_params.time_sync_period;
  2514. if (test_bit(DISABLE_TIME_SYNC, &plat_priv->ctrl_params.quirks)) {
  2515. cnss_pr_dbg("Time sync is disabled\n");
  2516. return;
  2517. }
  2518. if (!time_sync_period_ms) {
  2519. cnss_pr_dbg("Skip time sync as time period is 0\n");
  2520. return;
  2521. }
  2522. if (cnss_pci_is_device_down(&pci_priv->pci_dev->dev))
  2523. return;
  2524. if (cnss_pci_pm_runtime_get_sync(pci_priv, RTPM_ID_CNSS) < 0)
  2525. goto runtime_pm_put;
  2526. mutex_lock(&pci_priv->bus_lock);
  2527. cnss_pci_update_timestamp(pci_priv);
  2528. mutex_unlock(&pci_priv->bus_lock);
  2529. schedule_delayed_work(&pci_priv->time_sync_work,
  2530. msecs_to_jiffies(time_sync_period_ms));
  2531. runtime_pm_put:
  2532. cnss_pci_pm_runtime_mark_last_busy(pci_priv);
  2533. cnss_pci_pm_runtime_put_autosuspend(pci_priv, RTPM_ID_CNSS);
  2534. }
  2535. static int cnss_pci_start_time_sync_update(struct cnss_pci_data *pci_priv)
  2536. {
  2537. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  2538. switch (pci_priv->device_id) {
  2539. case QCA6390_DEVICE_ID:
  2540. case QCA6490_DEVICE_ID:
  2541. case KIWI_DEVICE_ID:
  2542. case MANGO_DEVICE_ID:
  2543. case PEACH_DEVICE_ID:
  2544. break;
  2545. default:
  2546. return -EOPNOTSUPP;
  2547. }
  2548. if (!plat_priv->device_freq_hz) {
  2549. cnss_pr_dbg("Device time clock frequency is not valid, skip time sync\n");
  2550. return -EINVAL;
  2551. }
  2552. cnss_pci_time_sync_work_hdlr(&pci_priv->time_sync_work.work);
  2553. return 0;
  2554. }
  2555. static void cnss_pci_stop_time_sync_update(struct cnss_pci_data *pci_priv)
  2556. {
  2557. switch (pci_priv->device_id) {
  2558. case QCA6390_DEVICE_ID:
  2559. case QCA6490_DEVICE_ID:
  2560. case KIWI_DEVICE_ID:
  2561. case MANGO_DEVICE_ID:
  2562. case PEACH_DEVICE_ID:
  2563. break;
  2564. default:
  2565. return;
  2566. }
  2567. cancel_delayed_work_sync(&pci_priv->time_sync_work);
  2568. }
  2569. int cnss_pci_set_therm_cdev_state(struct cnss_pci_data *pci_priv,
  2570. unsigned long thermal_state,
  2571. int tcdev_id)
  2572. {
  2573. if (!pci_priv) {
  2574. cnss_pr_err("pci_priv is NULL!\n");
  2575. return -ENODEV;
  2576. }
  2577. if (!pci_priv->driver_ops || !pci_priv->driver_ops->set_therm_cdev_state) {
  2578. cnss_pr_err("driver_ops or set_therm_cdev_state is NULL\n");
  2579. return -EINVAL;
  2580. }
  2581. return pci_priv->driver_ops->set_therm_cdev_state(pci_priv->pci_dev,
  2582. thermal_state,
  2583. tcdev_id);
  2584. }
  2585. int cnss_pci_update_time_sync_period(struct cnss_pci_data *pci_priv,
  2586. unsigned int time_sync_period)
  2587. {
  2588. struct cnss_plat_data *plat_priv;
  2589. if (!pci_priv)
  2590. return -ENODEV;
  2591. plat_priv = pci_priv->plat_priv;
  2592. cnss_pci_stop_time_sync_update(pci_priv);
  2593. plat_priv->ctrl_params.time_sync_period = time_sync_period;
  2594. cnss_pci_start_time_sync_update(pci_priv);
  2595. cnss_pr_dbg("WLAN time sync period %u ms\n",
  2596. plat_priv->ctrl_params.time_sync_period);
  2597. return 0;
  2598. }
  2599. int cnss_pci_call_driver_probe(struct cnss_pci_data *pci_priv)
  2600. {
  2601. int ret = 0;
  2602. struct cnss_plat_data *plat_priv;
  2603. if (!pci_priv)
  2604. return -ENODEV;
  2605. plat_priv = pci_priv->plat_priv;
  2606. if (test_bit(CNSS_IN_REBOOT, &plat_priv->driver_state)) {
  2607. cnss_pr_err("Reboot is in progress, skip driver probe\n");
  2608. return -EINVAL;
  2609. }
  2610. if (test_bit(CNSS_DRIVER_DEBUG, &plat_priv->driver_state)) {
  2611. clear_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state);
  2612. cnss_pr_dbg("Skip driver probe\n");
  2613. goto out;
  2614. }
  2615. if (!pci_priv->driver_ops) {
  2616. cnss_pr_err("driver_ops is NULL\n");
  2617. ret = -EINVAL;
  2618. goto out;
  2619. }
  2620. if (test_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state) &&
  2621. test_bit(CNSS_DRIVER_PROBED, &plat_priv->driver_state)) {
  2622. ret = pci_priv->driver_ops->reinit(pci_priv->pci_dev,
  2623. pci_priv->pci_device_id);
  2624. if (ret) {
  2625. cnss_pr_err("Failed to reinit host driver, err = %d\n",
  2626. ret);
  2627. goto out;
  2628. }
  2629. complete(&plat_priv->recovery_complete);
  2630. } else if (test_bit(CNSS_DRIVER_LOADING, &plat_priv->driver_state)) {
  2631. ret = pci_priv->driver_ops->probe(pci_priv->pci_dev,
  2632. pci_priv->pci_device_id);
  2633. if (ret) {
  2634. cnss_pr_err("Failed to probe host driver, err = %d\n",
  2635. ret);
  2636. complete_all(&plat_priv->power_up_complete);
  2637. goto out;
  2638. }
  2639. clear_bit(CNSS_DRIVER_LOADING, &plat_priv->driver_state);
  2640. set_bit(CNSS_DRIVER_PROBED, &plat_priv->driver_state);
  2641. cnss_pci_free_blob_mem(pci_priv);
  2642. complete_all(&plat_priv->power_up_complete);
  2643. } else if (test_bit(CNSS_DRIVER_IDLE_RESTART,
  2644. &plat_priv->driver_state)) {
  2645. ret = pci_priv->driver_ops->idle_restart(pci_priv->pci_dev,
  2646. pci_priv->pci_device_id);
  2647. if (ret) {
  2648. cnss_pr_err("Failed to idle restart host driver, err = %d\n",
  2649. ret);
  2650. plat_priv->power_up_error = ret;
  2651. complete_all(&plat_priv->power_up_complete);
  2652. goto out;
  2653. }
  2654. clear_bit(CNSS_DRIVER_IDLE_RESTART, &plat_priv->driver_state);
  2655. complete_all(&plat_priv->power_up_complete);
  2656. } else {
  2657. complete(&plat_priv->power_up_complete);
  2658. }
  2659. if (test_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state)) {
  2660. clear_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state);
  2661. __pm_relax(plat_priv->recovery_ws);
  2662. }
  2663. cnss_pci_start_time_sync_update(pci_priv);
  2664. return 0;
  2665. out:
  2666. return ret;
  2667. }
  2668. int cnss_pci_call_driver_remove(struct cnss_pci_data *pci_priv)
  2669. {
  2670. struct cnss_plat_data *plat_priv;
  2671. int ret;
  2672. if (!pci_priv)
  2673. return -ENODEV;
  2674. plat_priv = pci_priv->plat_priv;
  2675. if (test_bit(CNSS_IN_COLD_BOOT_CAL, &plat_priv->driver_state) ||
  2676. test_bit(CNSS_FW_BOOT_RECOVERY, &plat_priv->driver_state) ||
  2677. test_bit(CNSS_DRIVER_DEBUG, &plat_priv->driver_state)) {
  2678. cnss_pr_dbg("Skip driver remove\n");
  2679. return 0;
  2680. }
  2681. if (!pci_priv->driver_ops) {
  2682. cnss_pr_err("driver_ops is NULL\n");
  2683. return -EINVAL;
  2684. }
  2685. cnss_pci_stop_time_sync_update(pci_priv);
  2686. if (test_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state) &&
  2687. test_bit(CNSS_DRIVER_PROBED, &plat_priv->driver_state)) {
  2688. complete(&plat_priv->rddm_complete);
  2689. pci_priv->driver_ops->shutdown(pci_priv->pci_dev);
  2690. } else if (test_bit(CNSS_DRIVER_UNLOADING, &plat_priv->driver_state)) {
  2691. pci_priv->driver_ops->remove(pci_priv->pci_dev);
  2692. clear_bit(CNSS_DRIVER_PROBED, &plat_priv->driver_state);
  2693. } else if (test_bit(CNSS_DRIVER_IDLE_SHUTDOWN,
  2694. &plat_priv->driver_state)) {
  2695. ret = pci_priv->driver_ops->idle_shutdown(pci_priv->pci_dev);
  2696. if (ret == -EAGAIN) {
  2697. clear_bit(CNSS_DRIVER_IDLE_SHUTDOWN,
  2698. &plat_priv->driver_state);
  2699. return ret;
  2700. }
  2701. }
  2702. plat_priv->get_info_cb_ctx = NULL;
  2703. plat_priv->get_info_cb = NULL;
  2704. return 0;
  2705. }
  2706. int cnss_pci_call_driver_modem_status(struct cnss_pci_data *pci_priv,
  2707. int modem_current_status)
  2708. {
  2709. struct cnss_wlan_driver *driver_ops;
  2710. if (!pci_priv)
  2711. return -ENODEV;
  2712. driver_ops = pci_priv->driver_ops;
  2713. if (!driver_ops || !driver_ops->modem_status)
  2714. return -EINVAL;
  2715. driver_ops->modem_status(pci_priv->pci_dev, modem_current_status);
  2716. return 0;
  2717. }
  2718. int cnss_pci_update_status(struct cnss_pci_data *pci_priv,
  2719. enum cnss_driver_status status)
  2720. {
  2721. struct cnss_wlan_driver *driver_ops;
  2722. if (!pci_priv)
  2723. return -ENODEV;
  2724. driver_ops = pci_priv->driver_ops;
  2725. if (!driver_ops || !driver_ops->update_status)
  2726. return -EINVAL;
  2727. cnss_pr_dbg("Update driver status: %d\n", status);
  2728. driver_ops->update_status(pci_priv->pci_dev, status);
  2729. return 0;
  2730. }
  2731. static void cnss_pci_misc_reg_dump(struct cnss_pci_data *pci_priv,
  2732. struct cnss_misc_reg *misc_reg,
  2733. u32 misc_reg_size,
  2734. char *reg_name)
  2735. {
  2736. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  2737. bool do_force_wake_put = true;
  2738. int i;
  2739. if (!misc_reg)
  2740. return;
  2741. if (in_interrupt() || irqs_disabled())
  2742. return;
  2743. if (cnss_pci_check_link_status(pci_priv))
  2744. return;
  2745. if (cnss_pci_force_wake_get(pci_priv)) {
  2746. /* Continue to dump when device has entered RDDM already */
  2747. if (!test_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state))
  2748. return;
  2749. do_force_wake_put = false;
  2750. }
  2751. cnss_pr_dbg("Start to dump %s registers\n", reg_name);
  2752. for (i = 0; i < misc_reg_size; i++) {
  2753. if (!test_bit(pci_priv->misc_reg_dev_mask,
  2754. &misc_reg[i].dev_mask))
  2755. continue;
  2756. if (misc_reg[i].wr) {
  2757. if (misc_reg[i].offset ==
  2758. QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_SAW2_CFG &&
  2759. i >= 1)
  2760. misc_reg[i].val =
  2761. QCA6390_WCSS_Q6SS_PRIVCSR_QDSP6SS_SAW2_CFG_MSK |
  2762. misc_reg[i - 1].val;
  2763. if (cnss_pci_reg_write(pci_priv,
  2764. misc_reg[i].offset,
  2765. misc_reg[i].val))
  2766. goto force_wake_put;
  2767. cnss_pr_vdbg("Write 0x%X to 0x%X\n",
  2768. misc_reg[i].val,
  2769. misc_reg[i].offset);
  2770. } else {
  2771. if (cnss_pci_reg_read(pci_priv,
  2772. misc_reg[i].offset,
  2773. &misc_reg[i].val))
  2774. goto force_wake_put;
  2775. }
  2776. }
  2777. force_wake_put:
  2778. if (do_force_wake_put)
  2779. cnss_pci_force_wake_put(pci_priv);
  2780. }
  2781. static void cnss_pci_dump_misc_reg(struct cnss_pci_data *pci_priv)
  2782. {
  2783. if (in_interrupt() || irqs_disabled())
  2784. return;
  2785. if (cnss_pci_check_link_status(pci_priv))
  2786. return;
  2787. cnss_pci_misc_reg_dump(pci_priv, pci_priv->wcss_reg,
  2788. WCSS_REG_SIZE, "wcss");
  2789. cnss_pci_misc_reg_dump(pci_priv, pci_priv->pcie_reg,
  2790. PCIE_REG_SIZE, "pcie");
  2791. cnss_pci_misc_reg_dump(pci_priv, pci_priv->wlaon_reg,
  2792. WLAON_REG_SIZE, "wlaon");
  2793. cnss_pci_misc_reg_dump(pci_priv, pci_priv->syspm_reg,
  2794. SYSPM_REG_SIZE, "syspm");
  2795. }
  2796. static void cnss_pci_dump_shadow_reg(struct cnss_pci_data *pci_priv)
  2797. {
  2798. int i, j = 0, array_size = SHADOW_REG_COUNT + SHADOW_REG_INTER_COUNT;
  2799. u32 reg_offset;
  2800. bool do_force_wake_put = true;
  2801. if (in_interrupt() || irqs_disabled())
  2802. return;
  2803. if (cnss_pci_check_link_status(pci_priv))
  2804. return;
  2805. if (!pci_priv->debug_reg) {
  2806. pci_priv->debug_reg = devm_kzalloc(&pci_priv->pci_dev->dev,
  2807. sizeof(*pci_priv->debug_reg)
  2808. * array_size, GFP_KERNEL);
  2809. if (!pci_priv->debug_reg)
  2810. return;
  2811. }
  2812. if (cnss_pci_force_wake_get(pci_priv))
  2813. do_force_wake_put = false;
  2814. cnss_pr_dbg("Start to dump shadow registers\n");
  2815. for (i = 0; i < SHADOW_REG_COUNT; i++, j++) {
  2816. reg_offset = PCIE_SHADOW_REG_VALUE_0 + i * 4;
  2817. pci_priv->debug_reg[j].offset = reg_offset;
  2818. if (cnss_pci_reg_read(pci_priv, reg_offset,
  2819. &pci_priv->debug_reg[j].val))
  2820. goto force_wake_put;
  2821. }
  2822. for (i = 0; i < SHADOW_REG_INTER_COUNT; i++, j++) {
  2823. reg_offset = PCIE_SHADOW_REG_INTER_0 + i * 4;
  2824. pci_priv->debug_reg[j].offset = reg_offset;
  2825. if (cnss_pci_reg_read(pci_priv, reg_offset,
  2826. &pci_priv->debug_reg[j].val))
  2827. goto force_wake_put;
  2828. }
  2829. force_wake_put:
  2830. if (do_force_wake_put)
  2831. cnss_pci_force_wake_put(pci_priv);
  2832. }
  2833. static int cnss_qca6174_powerup(struct cnss_pci_data *pci_priv)
  2834. {
  2835. int ret = 0;
  2836. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  2837. ret = cnss_power_on_device(plat_priv, false);
  2838. if (ret) {
  2839. cnss_pr_err("Failed to power on device, err = %d\n", ret);
  2840. goto out;
  2841. }
  2842. ret = cnss_resume_pci_link(pci_priv);
  2843. if (ret) {
  2844. cnss_pr_err("Failed to resume PCI link, err = %d\n", ret);
  2845. goto power_off;
  2846. }
  2847. ret = cnss_pci_call_driver_probe(pci_priv);
  2848. if (ret)
  2849. goto suspend_link;
  2850. return 0;
  2851. suspend_link:
  2852. cnss_suspend_pci_link(pci_priv);
  2853. power_off:
  2854. cnss_power_off_device(plat_priv);
  2855. out:
  2856. return ret;
  2857. }
  2858. static int cnss_qca6174_shutdown(struct cnss_pci_data *pci_priv)
  2859. {
  2860. int ret = 0;
  2861. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  2862. cnss_pci_pm_runtime_resume(pci_priv);
  2863. ret = cnss_pci_call_driver_remove(pci_priv);
  2864. if (ret == -EAGAIN)
  2865. goto out;
  2866. cnss_request_bus_bandwidth(&plat_priv->plat_dev->dev,
  2867. CNSS_BUS_WIDTH_NONE);
  2868. cnss_pci_set_monitor_wake_intr(pci_priv, false);
  2869. cnss_pci_set_auto_suspended(pci_priv, 0);
  2870. ret = cnss_suspend_pci_link(pci_priv);
  2871. if (ret)
  2872. cnss_pr_err("Failed to suspend PCI link, err = %d\n", ret);
  2873. cnss_power_off_device(plat_priv);
  2874. clear_bit(CNSS_DRIVER_UNLOADING, &plat_priv->driver_state);
  2875. clear_bit(CNSS_DRIVER_IDLE_SHUTDOWN, &plat_priv->driver_state);
  2876. out:
  2877. return ret;
  2878. }
  2879. static void cnss_qca6174_crash_shutdown(struct cnss_pci_data *pci_priv)
  2880. {
  2881. if (pci_priv->driver_ops && pci_priv->driver_ops->crash_shutdown)
  2882. pci_priv->driver_ops->crash_shutdown(pci_priv->pci_dev);
  2883. }
  2884. static int cnss_qca6174_ramdump(struct cnss_pci_data *pci_priv)
  2885. {
  2886. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  2887. struct cnss_ramdump_info *ramdump_info;
  2888. ramdump_info = &plat_priv->ramdump_info;
  2889. if (!ramdump_info->ramdump_size)
  2890. return -EINVAL;
  2891. return cnss_do_ramdump(plat_priv);
  2892. }
  2893. static int cnss_qca6290_powerup(struct cnss_pci_data *pci_priv)
  2894. {
  2895. int ret = 0;
  2896. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  2897. unsigned int timeout;
  2898. int retry = 0, bt_en_gpio = plat_priv->pinctrl_info.bt_en_gpio;
  2899. int sw_ctrl_gpio = plat_priv->pinctrl_info.sw_ctrl_gpio;
  2900. if (plat_priv->ramdump_info_v2.dump_data_valid) {
  2901. cnss_pci_clear_dump_info(pci_priv);
  2902. cnss_pci_power_off_mhi(pci_priv);
  2903. cnss_suspend_pci_link(pci_priv);
  2904. cnss_pci_deinit_mhi(pci_priv);
  2905. cnss_power_off_device(plat_priv);
  2906. }
  2907. /* Clear QMI send usage count during every power up */
  2908. pci_priv->qmi_send_usage_count = 0;
  2909. plat_priv->power_up_error = 0;
  2910. retry:
  2911. ret = cnss_power_on_device(plat_priv, false);
  2912. if (ret) {
  2913. cnss_pr_err("Failed to power on device, err = %d\n", ret);
  2914. goto out;
  2915. }
  2916. ret = cnss_resume_pci_link(pci_priv);
  2917. if (ret) {
  2918. cnss_pr_err("Failed to resume PCI link, err = %d\n", ret);
  2919. cnss_pr_dbg("Value of SW_CTRL GPIO: %d\n",
  2920. cnss_get_input_gpio_value(plat_priv, sw_ctrl_gpio));
  2921. if (test_bit(IGNORE_PCI_LINK_FAILURE,
  2922. &plat_priv->ctrl_params.quirks)) {
  2923. cnss_pr_dbg("Ignore PCI link resume failure\n");
  2924. ret = 0;
  2925. goto out;
  2926. }
  2927. if (ret == -EAGAIN && retry++ < POWER_ON_RETRY_MAX_TIMES) {
  2928. cnss_power_off_device(plat_priv);
  2929. /* Force toggle BT_EN GPIO low */
  2930. if (retry == POWER_ON_RETRY_MAX_TIMES) {
  2931. cnss_pr_dbg("Retry #%d. Set BT_EN GPIO(%u) low\n",
  2932. retry, bt_en_gpio);
  2933. if (bt_en_gpio >= 0)
  2934. gpio_direction_output(bt_en_gpio, 0);
  2935. cnss_pr_dbg("BT_EN GPIO val: %d\n",
  2936. gpio_get_value(bt_en_gpio));
  2937. }
  2938. cnss_pr_dbg("Retry to resume PCI link #%d\n", retry);
  2939. cnss_pr_dbg("Value of SW_CTRL GPIO: %d\n",
  2940. cnss_get_input_gpio_value(plat_priv,
  2941. sw_ctrl_gpio));
  2942. msleep(POWER_ON_RETRY_DELAY_MS * retry);
  2943. goto retry;
  2944. }
  2945. /* Assert when it reaches maximum retries */
  2946. CNSS_ASSERT(0);
  2947. goto power_off;
  2948. }
  2949. cnss_pci_set_wlaon_pwr_ctrl(pci_priv, false, false, false);
  2950. timeout = cnss_get_timeout(plat_priv, CNSS_TIMEOUT_QMI);
  2951. ret = cnss_pci_start_mhi(pci_priv);
  2952. if (ret) {
  2953. cnss_fatal_err("Failed to start MHI, err = %d\n", ret);
  2954. if (!test_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state) &&
  2955. !pci_priv->pci_link_down_ind && timeout) {
  2956. /* Start recovery directly for MHI start failures */
  2957. cnss_schedule_recovery(&pci_priv->pci_dev->dev,
  2958. CNSS_REASON_DEFAULT);
  2959. }
  2960. return 0;
  2961. }
  2962. if (test_bit(USE_CORE_ONLY_FW, &plat_priv->ctrl_params.quirks)) {
  2963. clear_bit(CNSS_FW_BOOT_RECOVERY, &plat_priv->driver_state);
  2964. clear_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state);
  2965. return 0;
  2966. }
  2967. cnss_set_pin_connect_status(plat_priv);
  2968. if (test_bit(QMI_BYPASS, &plat_priv->ctrl_params.quirks)) {
  2969. ret = cnss_pci_call_driver_probe(pci_priv);
  2970. if (ret)
  2971. goto stop_mhi;
  2972. } else if (timeout) {
  2973. if (test_bit(CNSS_IN_COLD_BOOT_CAL, &plat_priv->driver_state))
  2974. timeout += WLAN_COLD_BOOT_CAL_TIMEOUT;
  2975. else
  2976. timeout += WLAN_MISSION_MODE_TIMEOUT;
  2977. mod_timer(&plat_priv->fw_boot_timer,
  2978. jiffies + msecs_to_jiffies(timeout));
  2979. }
  2980. return 0;
  2981. stop_mhi:
  2982. cnss_pci_set_wlaon_pwr_ctrl(pci_priv, false, true, true);
  2983. cnss_pci_power_off_mhi(pci_priv);
  2984. cnss_suspend_pci_link(pci_priv);
  2985. cnss_pci_deinit_mhi(pci_priv);
  2986. power_off:
  2987. cnss_power_off_device(plat_priv);
  2988. out:
  2989. return ret;
  2990. }
  2991. static int cnss_qca6290_shutdown(struct cnss_pci_data *pci_priv)
  2992. {
  2993. int ret = 0;
  2994. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  2995. int do_force_wake = true;
  2996. cnss_pci_pm_runtime_resume(pci_priv);
  2997. ret = cnss_pci_call_driver_remove(pci_priv);
  2998. if (ret == -EAGAIN)
  2999. goto out;
  3000. cnss_request_bus_bandwidth(&plat_priv->plat_dev->dev,
  3001. CNSS_BUS_WIDTH_NONE);
  3002. cnss_pci_set_monitor_wake_intr(pci_priv, false);
  3003. cnss_pci_set_auto_suspended(pci_priv, 0);
  3004. if ((test_bit(CNSS_DRIVER_LOADING, &plat_priv->driver_state) ||
  3005. test_bit(CNSS_DRIVER_UNLOADING, &plat_priv->driver_state) ||
  3006. test_bit(CNSS_DRIVER_IDLE_RESTART, &plat_priv->driver_state) ||
  3007. test_bit(CNSS_DRIVER_IDLE_SHUTDOWN, &plat_priv->driver_state) ||
  3008. test_bit(CNSS_IN_COLD_BOOT_CAL, &plat_priv->driver_state)) &&
  3009. test_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state)) {
  3010. del_timer(&pci_priv->dev_rddm_timer);
  3011. cnss_pci_collect_dump_info(pci_priv, false);
  3012. if (!plat_priv->recovery_enabled)
  3013. CNSS_ASSERT(0);
  3014. }
  3015. if (!cnss_is_device_powered_on(plat_priv)) {
  3016. cnss_pr_dbg("Device is already powered off, ignore\n");
  3017. goto skip_power_off;
  3018. }
  3019. if (test_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state))
  3020. do_force_wake = false;
  3021. cnss_pci_set_wlaon_pwr_ctrl(pci_priv, false, true, do_force_wake);
  3022. /* FBC image will be freed after powering off MHI, so skip
  3023. * if RAM dump data is still valid.
  3024. */
  3025. if (plat_priv->ramdump_info_v2.dump_data_valid)
  3026. goto skip_power_off;
  3027. cnss_pci_power_off_mhi(pci_priv);
  3028. ret = cnss_suspend_pci_link(pci_priv);
  3029. if (ret)
  3030. cnss_pr_err("Failed to suspend PCI link, err = %d\n", ret);
  3031. cnss_pci_deinit_mhi(pci_priv);
  3032. cnss_power_off_device(plat_priv);
  3033. skip_power_off:
  3034. pci_priv->remap_window = 0;
  3035. clear_bit(CNSS_FW_READY, &plat_priv->driver_state);
  3036. clear_bit(CNSS_FW_MEM_READY, &plat_priv->driver_state);
  3037. if (test_bit(CNSS_DRIVER_UNLOADING, &plat_priv->driver_state) ||
  3038. test_bit(CNSS_DRIVER_IDLE_SHUTDOWN, &plat_priv->driver_state)) {
  3039. clear_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state);
  3040. pci_priv->pci_link_down_ind = false;
  3041. }
  3042. clear_bit(CNSS_DRIVER_UNLOADING, &plat_priv->driver_state);
  3043. clear_bit(CNSS_DRIVER_IDLE_SHUTDOWN, &plat_priv->driver_state);
  3044. memset(&print_optimize, 0, sizeof(print_optimize));
  3045. out:
  3046. return ret;
  3047. }
  3048. static void cnss_qca6290_crash_shutdown(struct cnss_pci_data *pci_priv)
  3049. {
  3050. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  3051. set_bit(CNSS_IN_PANIC, &plat_priv->driver_state);
  3052. cnss_pr_dbg("Crash shutdown with driver_state 0x%lx\n",
  3053. plat_priv->driver_state);
  3054. cnss_pci_collect_dump_info(pci_priv, true);
  3055. clear_bit(CNSS_IN_PANIC, &plat_priv->driver_state);
  3056. }
  3057. static int cnss_qca6290_ramdump(struct cnss_pci_data *pci_priv)
  3058. {
  3059. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  3060. struct cnss_ramdump_info_v2 *info_v2 = &plat_priv->ramdump_info_v2;
  3061. struct cnss_dump_data *dump_data = &info_v2->dump_data;
  3062. struct cnss_dump_seg *dump_seg = info_v2->dump_data_vaddr;
  3063. int ret = 0;
  3064. if (!info_v2->dump_data_valid || !dump_seg ||
  3065. dump_data->nentries == 0)
  3066. return 0;
  3067. ret = cnss_do_elf_ramdump(plat_priv);
  3068. cnss_pci_clear_dump_info(pci_priv);
  3069. cnss_pci_power_off_mhi(pci_priv);
  3070. cnss_suspend_pci_link(pci_priv);
  3071. cnss_pci_deinit_mhi(pci_priv);
  3072. cnss_power_off_device(plat_priv);
  3073. return ret;
  3074. }
  3075. int cnss_pci_dev_powerup(struct cnss_pci_data *pci_priv)
  3076. {
  3077. int ret = 0;
  3078. if (!pci_priv) {
  3079. cnss_pr_err("pci_priv is NULL\n");
  3080. return -ENODEV;
  3081. }
  3082. switch (pci_priv->device_id) {
  3083. case QCA6174_DEVICE_ID:
  3084. ret = cnss_qca6174_powerup(pci_priv);
  3085. break;
  3086. case QCA6290_DEVICE_ID:
  3087. case QCA6390_DEVICE_ID:
  3088. case QCN7605_DEVICE_ID:
  3089. case QCA6490_DEVICE_ID:
  3090. case KIWI_DEVICE_ID:
  3091. case MANGO_DEVICE_ID:
  3092. case PEACH_DEVICE_ID:
  3093. ret = cnss_qca6290_powerup(pci_priv);
  3094. break;
  3095. default:
  3096. cnss_pr_err("Unknown device_id found: 0x%x\n",
  3097. pci_priv->device_id);
  3098. ret = -ENODEV;
  3099. }
  3100. return ret;
  3101. }
  3102. int cnss_pci_dev_shutdown(struct cnss_pci_data *pci_priv)
  3103. {
  3104. int ret = 0;
  3105. if (!pci_priv) {
  3106. cnss_pr_err("pci_priv is NULL\n");
  3107. return -ENODEV;
  3108. }
  3109. switch (pci_priv->device_id) {
  3110. case QCA6174_DEVICE_ID:
  3111. ret = cnss_qca6174_shutdown(pci_priv);
  3112. break;
  3113. case QCA6290_DEVICE_ID:
  3114. case QCA6390_DEVICE_ID:
  3115. case QCN7605_DEVICE_ID:
  3116. case QCA6490_DEVICE_ID:
  3117. case KIWI_DEVICE_ID:
  3118. case MANGO_DEVICE_ID:
  3119. case PEACH_DEVICE_ID:
  3120. ret = cnss_qca6290_shutdown(pci_priv);
  3121. break;
  3122. default:
  3123. cnss_pr_err("Unknown device_id found: 0x%x\n",
  3124. pci_priv->device_id);
  3125. ret = -ENODEV;
  3126. }
  3127. return ret;
  3128. }
  3129. int cnss_pci_dev_crash_shutdown(struct cnss_pci_data *pci_priv)
  3130. {
  3131. int ret = 0;
  3132. if (!pci_priv) {
  3133. cnss_pr_err("pci_priv is NULL\n");
  3134. return -ENODEV;
  3135. }
  3136. switch (pci_priv->device_id) {
  3137. case QCA6174_DEVICE_ID:
  3138. cnss_qca6174_crash_shutdown(pci_priv);
  3139. break;
  3140. case QCA6290_DEVICE_ID:
  3141. case QCA6390_DEVICE_ID:
  3142. case QCN7605_DEVICE_ID:
  3143. case QCA6490_DEVICE_ID:
  3144. case KIWI_DEVICE_ID:
  3145. case MANGO_DEVICE_ID:
  3146. case PEACH_DEVICE_ID:
  3147. cnss_qca6290_crash_shutdown(pci_priv);
  3148. break;
  3149. default:
  3150. cnss_pr_err("Unknown device_id found: 0x%x\n",
  3151. pci_priv->device_id);
  3152. ret = -ENODEV;
  3153. }
  3154. return ret;
  3155. }
  3156. int cnss_pci_dev_ramdump(struct cnss_pci_data *pci_priv)
  3157. {
  3158. int ret = 0;
  3159. if (!pci_priv) {
  3160. cnss_pr_err("pci_priv is NULL\n");
  3161. return -ENODEV;
  3162. }
  3163. switch (pci_priv->device_id) {
  3164. case QCA6174_DEVICE_ID:
  3165. ret = cnss_qca6174_ramdump(pci_priv);
  3166. break;
  3167. case QCA6290_DEVICE_ID:
  3168. case QCA6390_DEVICE_ID:
  3169. case QCN7605_DEVICE_ID:
  3170. case QCA6490_DEVICE_ID:
  3171. case KIWI_DEVICE_ID:
  3172. case MANGO_DEVICE_ID:
  3173. case PEACH_DEVICE_ID:
  3174. ret = cnss_qca6290_ramdump(pci_priv);
  3175. break;
  3176. default:
  3177. cnss_pr_err("Unknown device_id found: 0x%x\n",
  3178. pci_priv->device_id);
  3179. ret = -ENODEV;
  3180. }
  3181. return ret;
  3182. }
  3183. int cnss_pci_is_drv_connected(struct device *dev)
  3184. {
  3185. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(to_pci_dev(dev));
  3186. if (!pci_priv)
  3187. return -ENODEV;
  3188. return pci_priv->drv_connected_last;
  3189. }
  3190. EXPORT_SYMBOL(cnss_pci_is_drv_connected);
  3191. static void cnss_wlan_reg_driver_work(struct work_struct *work)
  3192. {
  3193. struct cnss_plat_data *plat_priv =
  3194. container_of(work, struct cnss_plat_data, wlan_reg_driver_work.work);
  3195. struct cnss_pci_data *pci_priv = plat_priv->bus_priv;
  3196. struct cnss_cal_info *cal_info;
  3197. unsigned int timeout;
  3198. if (test_bit(CNSS_WLAN_HW_DISABLED, &plat_priv->driver_state))
  3199. return;
  3200. if (test_bit(CNSS_COLD_BOOT_CAL_DONE, &plat_priv->driver_state)) {
  3201. goto reg_driver;
  3202. } else {
  3203. if (plat_priv->charger_mode) {
  3204. cnss_pr_err("Ignore calibration timeout in charger mode\n");
  3205. return;
  3206. }
  3207. if (!test_bit(CNSS_IN_COLD_BOOT_CAL,
  3208. &plat_priv->driver_state)) {
  3209. timeout = cnss_get_timeout(plat_priv,
  3210. CNSS_TIMEOUT_CALIBRATION);
  3211. cnss_pr_dbg("File system not ready to start calibration. Wait for %ds..\n",
  3212. timeout / 1000);
  3213. schedule_delayed_work(&plat_priv->wlan_reg_driver_work,
  3214. msecs_to_jiffies(timeout));
  3215. return;
  3216. }
  3217. del_timer(&plat_priv->fw_boot_timer);
  3218. if (test_bit(CNSS_IN_COLD_BOOT_CAL, &plat_priv->driver_state) &&
  3219. !test_bit(CNSS_IN_REBOOT, &plat_priv->driver_state)) {
  3220. cnss_pr_err("Timeout waiting for calibration to complete\n");
  3221. CNSS_ASSERT(0);
  3222. }
  3223. cal_info = kzalloc(sizeof(*cal_info), GFP_KERNEL);
  3224. if (!cal_info)
  3225. return;
  3226. cal_info->cal_status = CNSS_CAL_TIMEOUT;
  3227. cnss_driver_event_post(plat_priv,
  3228. CNSS_DRIVER_EVENT_COLD_BOOT_CAL_DONE,
  3229. 0, cal_info);
  3230. }
  3231. reg_driver:
  3232. if (test_bit(CNSS_IN_REBOOT, &plat_priv->driver_state)) {
  3233. cnss_pr_dbg("Reboot/Shutdown is in progress, ignore register driver\n");
  3234. return;
  3235. }
  3236. reinit_completion(&plat_priv->power_up_complete);
  3237. cnss_driver_event_post(plat_priv,
  3238. CNSS_DRIVER_EVENT_REGISTER_DRIVER,
  3239. CNSS_EVENT_SYNC_UNKILLABLE,
  3240. pci_priv->driver_ops);
  3241. }
  3242. int cnss_wlan_register_driver(struct cnss_wlan_driver *driver_ops)
  3243. {
  3244. int ret = 0;
  3245. struct cnss_plat_data *plat_priv;
  3246. struct cnss_pci_data *pci_priv;
  3247. const struct pci_device_id *id_table = driver_ops->id_table;
  3248. unsigned int timeout;
  3249. if (!cnss_check_driver_loading_allowed()) {
  3250. cnss_pr_info("No cnss2 dtsi entry present");
  3251. return -ENODEV;
  3252. }
  3253. plat_priv = cnss_get_plat_priv_by_driver_ops(driver_ops);
  3254. if (!plat_priv) {
  3255. cnss_pr_buf("plat_priv is not ready for register driver\n");
  3256. return -EAGAIN;
  3257. }
  3258. pci_priv = plat_priv->bus_priv;
  3259. if (test_bit(CNSS_WLAN_HW_DISABLED, &plat_priv->driver_state)) {
  3260. while (id_table && id_table->device) {
  3261. if (plat_priv->device_id == id_table->device) {
  3262. if (plat_priv->device_id == KIWI_DEVICE_ID &&
  3263. driver_ops->chip_version != 2) {
  3264. cnss_pr_err("WLAN HW disabled. kiwi_v2 only supported\n");
  3265. return -ENODEV;
  3266. }
  3267. cnss_pr_info("WLAN register driver deferred for device ID: 0x%x due to HW disable\n",
  3268. id_table->device);
  3269. plat_priv->driver_ops = driver_ops;
  3270. return 0;
  3271. }
  3272. id_table++;
  3273. }
  3274. return -ENODEV;
  3275. }
  3276. if (!test_bit(CNSS_PCI_PROBE_DONE, &plat_priv->driver_state)) {
  3277. cnss_pr_info("pci probe not yet done for register driver\n");
  3278. return -EAGAIN;
  3279. }
  3280. if (test_bit(CNSS_DRIVER_REGISTERED, &plat_priv->driver_state)) {
  3281. cnss_pr_err("Driver has already registered\n");
  3282. return -EEXIST;
  3283. }
  3284. if (test_bit(CNSS_IN_REBOOT, &plat_priv->driver_state)) {
  3285. cnss_pr_dbg("Reboot/Shutdown is in progress, ignore register driver\n");
  3286. return -EINVAL;
  3287. }
  3288. if (!id_table || !pci_dev_present(id_table)) {
  3289. /* id_table pointer will move from pci_dev_present(),
  3290. * so check again using local pointer.
  3291. */
  3292. id_table = driver_ops->id_table;
  3293. while (id_table && id_table->vendor) {
  3294. cnss_pr_info("Host driver is built for PCIe device ID 0x%x\n",
  3295. id_table->device);
  3296. id_table++;
  3297. }
  3298. cnss_pr_err("Enumerated PCIe device id is 0x%x, reject unsupported driver\n",
  3299. pci_priv->device_id);
  3300. return -ENODEV;
  3301. }
  3302. if (driver_ops->chip_version != CNSS_CHIP_VER_ANY &&
  3303. driver_ops->chip_version != plat_priv->device_version.major_version) {
  3304. cnss_pr_err("Driver built for chip ver 0x%x, enumerated ver 0x%x, reject unsupported driver\n",
  3305. driver_ops->chip_version,
  3306. plat_priv->device_version.major_version);
  3307. return -ENODEV;
  3308. }
  3309. set_bit(CNSS_DRIVER_REGISTER, &plat_priv->driver_state);
  3310. if (!plat_priv->cbc_enabled ||
  3311. test_bit(CNSS_COLD_BOOT_CAL_DONE, &plat_priv->driver_state))
  3312. goto register_driver;
  3313. pci_priv->driver_ops = driver_ops;
  3314. /* If Cold Boot Calibration is enabled, it is the 1st step in init
  3315. * sequence.CBC is done on file system_ready trigger. Qcacld will be
  3316. * loaded from vendor_modprobe.sh at early boot and must be deferred
  3317. * until CBC is complete
  3318. */
  3319. timeout = cnss_get_timeout(plat_priv, CNSS_TIMEOUT_CALIBRATION);
  3320. INIT_DELAYED_WORK(&plat_priv->wlan_reg_driver_work,
  3321. cnss_wlan_reg_driver_work);
  3322. schedule_delayed_work(&plat_priv->wlan_reg_driver_work,
  3323. msecs_to_jiffies(timeout));
  3324. cnss_pr_info("WLAN register driver deferred for Calibration\n");
  3325. return 0;
  3326. register_driver:
  3327. reinit_completion(&plat_priv->power_up_complete);
  3328. ret = cnss_driver_event_post(plat_priv,
  3329. CNSS_DRIVER_EVENT_REGISTER_DRIVER,
  3330. CNSS_EVENT_SYNC_UNKILLABLE,
  3331. driver_ops);
  3332. return ret;
  3333. }
  3334. EXPORT_SYMBOL(cnss_wlan_register_driver);
  3335. void cnss_wlan_unregister_driver(struct cnss_wlan_driver *driver_ops)
  3336. {
  3337. struct cnss_plat_data *plat_priv;
  3338. int ret = 0;
  3339. unsigned int timeout;
  3340. plat_priv = cnss_get_plat_priv_by_driver_ops(driver_ops);
  3341. if (!plat_priv) {
  3342. cnss_pr_err("plat_priv is NULL\n");
  3343. return;
  3344. }
  3345. mutex_lock(&plat_priv->driver_ops_lock);
  3346. if (plat_priv->device_id == QCA6174_DEVICE_ID)
  3347. goto skip_wait_power_up;
  3348. timeout = cnss_get_timeout(plat_priv, CNSS_TIMEOUT_WLAN_WATCHDOG);
  3349. ret = wait_for_completion_timeout(&plat_priv->power_up_complete,
  3350. msecs_to_jiffies(timeout));
  3351. if (!ret) {
  3352. cnss_pr_err("Timeout (%ums) waiting for driver power up to complete\n",
  3353. timeout);
  3354. CNSS_ASSERT(0);
  3355. }
  3356. skip_wait_power_up:
  3357. if (!test_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state) &&
  3358. !test_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state))
  3359. goto skip_wait_recovery;
  3360. reinit_completion(&plat_priv->recovery_complete);
  3361. timeout = cnss_get_timeout(plat_priv, CNSS_TIMEOUT_RECOVERY);
  3362. ret = wait_for_completion_timeout(&plat_priv->recovery_complete,
  3363. msecs_to_jiffies(timeout));
  3364. if (!ret) {
  3365. cnss_pr_err("Timeout (%ums) waiting for recovery to complete\n",
  3366. timeout);
  3367. CNSS_ASSERT(0);
  3368. }
  3369. skip_wait_recovery:
  3370. cnss_driver_event_post(plat_priv,
  3371. CNSS_DRIVER_EVENT_UNREGISTER_DRIVER,
  3372. CNSS_EVENT_SYNC_UNKILLABLE, NULL);
  3373. mutex_unlock(&plat_priv->driver_ops_lock);
  3374. }
  3375. EXPORT_SYMBOL(cnss_wlan_unregister_driver);
  3376. int cnss_pci_register_driver_hdlr(struct cnss_pci_data *pci_priv,
  3377. void *data)
  3378. {
  3379. int ret = 0;
  3380. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  3381. if (test_bit(CNSS_IN_REBOOT, &plat_priv->driver_state)) {
  3382. cnss_pr_dbg("Reboot or shutdown is in progress, ignore register driver\n");
  3383. return -EINVAL;
  3384. }
  3385. set_bit(CNSS_DRIVER_LOADING, &plat_priv->driver_state);
  3386. pci_priv->driver_ops = data;
  3387. ret = cnss_pci_dev_powerup(pci_priv);
  3388. if (ret) {
  3389. clear_bit(CNSS_DRIVER_LOADING, &plat_priv->driver_state);
  3390. pci_priv->driver_ops = NULL;
  3391. } else {
  3392. set_bit(CNSS_DRIVER_REGISTERED, &plat_priv->driver_state);
  3393. }
  3394. return ret;
  3395. }
  3396. int cnss_pci_unregister_driver_hdlr(struct cnss_pci_data *pci_priv)
  3397. {
  3398. struct cnss_plat_data *plat_priv;
  3399. if (!pci_priv)
  3400. return -EINVAL;
  3401. plat_priv = pci_priv->plat_priv;
  3402. set_bit(CNSS_DRIVER_UNLOADING, &plat_priv->driver_state);
  3403. cnss_pci_dev_shutdown(pci_priv);
  3404. pci_priv->driver_ops = NULL;
  3405. clear_bit(CNSS_DRIVER_REGISTERED, &plat_priv->driver_state);
  3406. return 0;
  3407. }
  3408. static int cnss_pci_suspend_driver(struct cnss_pci_data *pci_priv)
  3409. {
  3410. struct pci_dev *pci_dev = pci_priv->pci_dev;
  3411. struct cnss_wlan_driver *driver_ops = pci_priv->driver_ops;
  3412. int ret = 0;
  3413. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  3414. pm_message_t state = { .event = PM_EVENT_SUSPEND };
  3415. if (test_bit(CNSS_DRIVER_REGISTERED, &plat_priv->driver_state) &&
  3416. driver_ops && driver_ops->suspend) {
  3417. ret = driver_ops->suspend(pci_dev, state);
  3418. if (ret) {
  3419. cnss_pr_err("Failed to suspend host driver, err = %d\n",
  3420. ret);
  3421. ret = -EAGAIN;
  3422. }
  3423. }
  3424. return ret;
  3425. }
  3426. static int cnss_pci_resume_driver(struct cnss_pci_data *pci_priv)
  3427. {
  3428. struct pci_dev *pci_dev = pci_priv->pci_dev;
  3429. struct cnss_wlan_driver *driver_ops = pci_priv->driver_ops;
  3430. int ret = 0;
  3431. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  3432. if (test_bit(CNSS_DRIVER_REGISTERED, &plat_priv->driver_state) &&
  3433. driver_ops && driver_ops->resume) {
  3434. ret = driver_ops->resume(pci_dev);
  3435. if (ret)
  3436. cnss_pr_err("Failed to resume host driver, err = %d\n",
  3437. ret);
  3438. }
  3439. return ret;
  3440. }
  3441. int cnss_pci_suspend_bus(struct cnss_pci_data *pci_priv)
  3442. {
  3443. struct pci_dev *pci_dev = pci_priv->pci_dev;
  3444. int ret = 0;
  3445. if (pci_priv->pci_link_state == PCI_LINK_DOWN)
  3446. goto out;
  3447. if (cnss_pci_set_mhi_state(pci_priv, CNSS_MHI_SUSPEND)) {
  3448. ret = -EAGAIN;
  3449. goto out;
  3450. }
  3451. if (pci_priv->drv_connected_last)
  3452. goto skip_disable_pci;
  3453. pci_clear_master(pci_dev);
  3454. cnss_set_pci_config_space(pci_priv, SAVE_PCI_CONFIG_SPACE);
  3455. pci_disable_device(pci_dev);
  3456. ret = pci_set_power_state(pci_dev, PCI_D3hot);
  3457. if (ret)
  3458. cnss_pr_err("Failed to set D3Hot, err = %d\n", ret);
  3459. skip_disable_pci:
  3460. if (cnss_set_pci_link(pci_priv, PCI_LINK_DOWN)) {
  3461. ret = -EAGAIN;
  3462. goto resume_mhi;
  3463. }
  3464. pci_priv->pci_link_state = PCI_LINK_DOWN;
  3465. return 0;
  3466. resume_mhi:
  3467. if (!pci_is_enabled(pci_dev))
  3468. if (pci_enable_device(pci_dev))
  3469. cnss_pr_err("Failed to enable PCI device\n");
  3470. if (pci_priv->saved_state)
  3471. cnss_set_pci_config_space(pci_priv, RESTORE_PCI_CONFIG_SPACE);
  3472. pci_set_master(pci_dev);
  3473. cnss_pci_set_mhi_state(pci_priv, CNSS_MHI_RESUME);
  3474. out:
  3475. return ret;
  3476. }
  3477. int cnss_pci_resume_bus(struct cnss_pci_data *pci_priv)
  3478. {
  3479. struct pci_dev *pci_dev = pci_priv->pci_dev;
  3480. int ret = 0;
  3481. if (pci_priv->pci_link_state == PCI_LINK_UP)
  3482. goto out;
  3483. if (cnss_set_pci_link(pci_priv, PCI_LINK_UP)) {
  3484. cnss_fatal_err("Failed to resume PCI link from suspend\n");
  3485. cnss_pci_link_down(&pci_dev->dev);
  3486. ret = -EAGAIN;
  3487. goto out;
  3488. }
  3489. pci_priv->pci_link_state = PCI_LINK_UP;
  3490. if (pci_priv->drv_connected_last)
  3491. goto skip_enable_pci;
  3492. ret = pci_enable_device(pci_dev);
  3493. if (ret) {
  3494. cnss_pr_err("Failed to enable PCI device, err = %d\n",
  3495. ret);
  3496. goto out;
  3497. }
  3498. if (pci_priv->saved_state)
  3499. cnss_set_pci_config_space(pci_priv,
  3500. RESTORE_PCI_CONFIG_SPACE);
  3501. pci_set_master(pci_dev);
  3502. skip_enable_pci:
  3503. cnss_pci_set_mhi_state(pci_priv, CNSS_MHI_RESUME);
  3504. out:
  3505. return ret;
  3506. }
  3507. static int cnss_pci_suspend(struct device *dev)
  3508. {
  3509. int ret = 0;
  3510. struct pci_dev *pci_dev = to_pci_dev(dev);
  3511. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  3512. struct cnss_plat_data *plat_priv;
  3513. if (!pci_priv)
  3514. goto out;
  3515. plat_priv = pci_priv->plat_priv;
  3516. if (!plat_priv)
  3517. goto out;
  3518. if (!cnss_is_device_powered_on(plat_priv))
  3519. goto out;
  3520. /* No mhi state bit set if only finish pcie enumeration,
  3521. * so test_bit is not applicable to check if it is INIT state.
  3522. */
  3523. if (pci_priv->mhi_state == CNSS_MHI_INIT) {
  3524. bool suspend = cnss_should_suspend_pwroff(pci_dev);
  3525. /* Do PCI link suspend and power off in the LPM case
  3526. * if chipset didn't do that after pcie enumeration.
  3527. */
  3528. if (!suspend) {
  3529. ret = cnss_suspend_pci_link(pci_priv);
  3530. if (ret)
  3531. cnss_pr_err("Failed to suspend PCI link, err = %d\n",
  3532. ret);
  3533. cnss_power_off_device(plat_priv);
  3534. goto out;
  3535. }
  3536. }
  3537. if (!test_bit(DISABLE_DRV, &plat_priv->ctrl_params.quirks) &&
  3538. pci_priv->drv_supported) {
  3539. pci_priv->drv_connected_last =
  3540. cnss_pci_get_drv_connected(pci_priv);
  3541. if (!pci_priv->drv_connected_last) {
  3542. cnss_pr_dbg("Firmware does not support non-DRV suspend, reject\n");
  3543. ret = -EAGAIN;
  3544. goto out;
  3545. }
  3546. }
  3547. set_bit(CNSS_IN_SUSPEND_RESUME, &plat_priv->driver_state);
  3548. ret = cnss_pci_suspend_driver(pci_priv);
  3549. if (ret)
  3550. goto clear_flag;
  3551. if (!pci_priv->disable_pc) {
  3552. mutex_lock(&pci_priv->bus_lock);
  3553. ret = cnss_pci_suspend_bus(pci_priv);
  3554. mutex_unlock(&pci_priv->bus_lock);
  3555. if (ret)
  3556. goto resume_driver;
  3557. }
  3558. cnss_pci_set_monitor_wake_intr(pci_priv, false);
  3559. return 0;
  3560. resume_driver:
  3561. cnss_pci_resume_driver(pci_priv);
  3562. clear_flag:
  3563. pci_priv->drv_connected_last = 0;
  3564. clear_bit(CNSS_IN_SUSPEND_RESUME, &plat_priv->driver_state);
  3565. out:
  3566. return ret;
  3567. }
  3568. static int cnss_pci_resume(struct device *dev)
  3569. {
  3570. int ret = 0;
  3571. struct pci_dev *pci_dev = to_pci_dev(dev);
  3572. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  3573. struct cnss_plat_data *plat_priv;
  3574. if (!pci_priv)
  3575. goto out;
  3576. plat_priv = pci_priv->plat_priv;
  3577. if (!plat_priv)
  3578. goto out;
  3579. if (pci_priv->pci_link_down_ind)
  3580. goto out;
  3581. if (!cnss_is_device_powered_on(pci_priv->plat_priv))
  3582. goto out;
  3583. if (!pci_priv->disable_pc) {
  3584. mutex_lock(&pci_priv->bus_lock);
  3585. ret = cnss_pci_resume_bus(pci_priv);
  3586. mutex_unlock(&pci_priv->bus_lock);
  3587. if (ret)
  3588. goto out;
  3589. }
  3590. ret = cnss_pci_resume_driver(pci_priv);
  3591. pci_priv->drv_connected_last = 0;
  3592. clear_bit(CNSS_IN_SUSPEND_RESUME, &plat_priv->driver_state);
  3593. out:
  3594. return ret;
  3595. }
  3596. static int cnss_pci_suspend_noirq(struct device *dev)
  3597. {
  3598. int ret = 0;
  3599. struct pci_dev *pci_dev = to_pci_dev(dev);
  3600. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  3601. struct cnss_wlan_driver *driver_ops;
  3602. struct cnss_plat_data *plat_priv;
  3603. if (!pci_priv)
  3604. goto out;
  3605. if (!cnss_is_device_powered_on(pci_priv->plat_priv))
  3606. goto out;
  3607. driver_ops = pci_priv->driver_ops;
  3608. plat_priv = pci_priv->plat_priv;
  3609. if (test_bit(CNSS_DRIVER_REGISTERED, &plat_priv->driver_state) &&
  3610. driver_ops && driver_ops->suspend_noirq)
  3611. ret = driver_ops->suspend_noirq(pci_dev);
  3612. if (pci_priv->disable_pc && !pci_dev->state_saved &&
  3613. !pci_priv->plat_priv->use_pm_domain)
  3614. pci_save_state(pci_dev);
  3615. out:
  3616. return ret;
  3617. }
  3618. static int cnss_pci_resume_noirq(struct device *dev)
  3619. {
  3620. int ret = 0;
  3621. struct pci_dev *pci_dev = to_pci_dev(dev);
  3622. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  3623. struct cnss_wlan_driver *driver_ops;
  3624. struct cnss_plat_data *plat_priv;
  3625. if (!pci_priv)
  3626. goto out;
  3627. if (!cnss_is_device_powered_on(pci_priv->plat_priv))
  3628. goto out;
  3629. plat_priv = pci_priv->plat_priv;
  3630. driver_ops = pci_priv->driver_ops;
  3631. if (test_bit(CNSS_DRIVER_REGISTERED, &plat_priv->driver_state) &&
  3632. driver_ops && driver_ops->resume_noirq &&
  3633. !pci_priv->pci_link_down_ind)
  3634. ret = driver_ops->resume_noirq(pci_dev);
  3635. out:
  3636. return ret;
  3637. }
  3638. static int cnss_pci_runtime_suspend(struct device *dev)
  3639. {
  3640. int ret = 0;
  3641. struct pci_dev *pci_dev = to_pci_dev(dev);
  3642. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  3643. struct cnss_plat_data *plat_priv;
  3644. struct cnss_wlan_driver *driver_ops;
  3645. if (!pci_priv)
  3646. return -EAGAIN;
  3647. plat_priv = pci_priv->plat_priv;
  3648. if (!plat_priv)
  3649. return -EAGAIN;
  3650. if (!cnss_is_device_powered_on(pci_priv->plat_priv))
  3651. return -EAGAIN;
  3652. if (pci_priv->pci_link_down_ind) {
  3653. cnss_pr_dbg("PCI link down recovery is in progress!\n");
  3654. return -EAGAIN;
  3655. }
  3656. if (!test_bit(DISABLE_DRV, &plat_priv->ctrl_params.quirks) &&
  3657. pci_priv->drv_supported) {
  3658. pci_priv->drv_connected_last =
  3659. cnss_pci_get_drv_connected(pci_priv);
  3660. if (!pci_priv->drv_connected_last) {
  3661. cnss_pr_dbg("Firmware does not support non-DRV suspend, reject\n");
  3662. return -EAGAIN;
  3663. }
  3664. }
  3665. cnss_pr_vdbg("Runtime suspend start\n");
  3666. driver_ops = pci_priv->driver_ops;
  3667. if (driver_ops && driver_ops->runtime_ops &&
  3668. driver_ops->runtime_ops->runtime_suspend)
  3669. ret = driver_ops->runtime_ops->runtime_suspend(pci_dev);
  3670. else
  3671. ret = cnss_auto_suspend(dev);
  3672. if (ret)
  3673. pci_priv->drv_connected_last = 0;
  3674. cnss_pr_vdbg("Runtime suspend status: %d\n", ret);
  3675. return ret;
  3676. }
  3677. static int cnss_pci_runtime_resume(struct device *dev)
  3678. {
  3679. int ret = 0;
  3680. struct pci_dev *pci_dev = to_pci_dev(dev);
  3681. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  3682. struct cnss_wlan_driver *driver_ops;
  3683. if (!pci_priv)
  3684. return -EAGAIN;
  3685. if (!cnss_is_device_powered_on(pci_priv->plat_priv))
  3686. return -EAGAIN;
  3687. if (pci_priv->pci_link_down_ind) {
  3688. cnss_pr_dbg("PCI link down recovery is in progress!\n");
  3689. return -EAGAIN;
  3690. }
  3691. cnss_pr_vdbg("Runtime resume start\n");
  3692. driver_ops = pci_priv->driver_ops;
  3693. if (driver_ops && driver_ops->runtime_ops &&
  3694. driver_ops->runtime_ops->runtime_resume)
  3695. ret = driver_ops->runtime_ops->runtime_resume(pci_dev);
  3696. else
  3697. ret = cnss_auto_resume(dev);
  3698. cnss_pr_vdbg("Runtime resume status: %d\n", ret);
  3699. return ret;
  3700. }
  3701. static int cnss_pci_runtime_idle(struct device *dev)
  3702. {
  3703. cnss_pr_vdbg("Runtime idle\n");
  3704. pm_request_autosuspend(dev);
  3705. return -EBUSY;
  3706. }
  3707. int cnss_wlan_pm_control(struct device *dev, bool vote)
  3708. {
  3709. struct pci_dev *pci_dev = to_pci_dev(dev);
  3710. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  3711. int ret = 0;
  3712. if (!pci_priv)
  3713. return -ENODEV;
  3714. ret = cnss_pci_disable_pc(pci_priv, vote);
  3715. if (ret)
  3716. return ret;
  3717. pci_priv->disable_pc = vote;
  3718. cnss_pr_dbg("%s PCIe power collapse\n", vote ? "disable" : "enable");
  3719. return 0;
  3720. }
  3721. EXPORT_SYMBOL(cnss_wlan_pm_control);
  3722. static void cnss_pci_pm_runtime_get_record(struct cnss_pci_data *pci_priv,
  3723. enum cnss_rtpm_id id)
  3724. {
  3725. if (id >= RTPM_ID_MAX)
  3726. return;
  3727. atomic_inc(&pci_priv->pm_stats.runtime_get);
  3728. atomic_inc(&pci_priv->pm_stats.runtime_get_id[id]);
  3729. pci_priv->pm_stats.runtime_get_timestamp_id[id] =
  3730. cnss_get_host_timestamp(pci_priv->plat_priv);
  3731. }
  3732. static void cnss_pci_pm_runtime_put_record(struct cnss_pci_data *pci_priv,
  3733. enum cnss_rtpm_id id)
  3734. {
  3735. if (id >= RTPM_ID_MAX)
  3736. return;
  3737. atomic_inc(&pci_priv->pm_stats.runtime_put);
  3738. atomic_inc(&pci_priv->pm_stats.runtime_put_id[id]);
  3739. pci_priv->pm_stats.runtime_put_timestamp_id[id] =
  3740. cnss_get_host_timestamp(pci_priv->plat_priv);
  3741. }
  3742. void cnss_pci_pm_runtime_show_usage_count(struct cnss_pci_data *pci_priv)
  3743. {
  3744. struct device *dev;
  3745. if (!pci_priv)
  3746. return;
  3747. dev = &pci_priv->pci_dev->dev;
  3748. cnss_pr_dbg("Runtime PM usage count: %d\n",
  3749. atomic_read(&dev->power.usage_count));
  3750. }
  3751. int cnss_pci_pm_request_resume(struct cnss_pci_data *pci_priv)
  3752. {
  3753. struct device *dev;
  3754. enum rpm_status status;
  3755. if (!pci_priv)
  3756. return -ENODEV;
  3757. dev = &pci_priv->pci_dev->dev;
  3758. status = dev->power.runtime_status;
  3759. if (status == RPM_SUSPENDING || status == RPM_SUSPENDED)
  3760. cnss_pr_vdbg("Runtime PM resume is requested by %ps\n",
  3761. (void *)_RET_IP_);
  3762. return pm_request_resume(dev);
  3763. }
  3764. int cnss_pci_pm_runtime_resume(struct cnss_pci_data *pci_priv)
  3765. {
  3766. struct device *dev;
  3767. enum rpm_status status;
  3768. if (!pci_priv)
  3769. return -ENODEV;
  3770. dev = &pci_priv->pci_dev->dev;
  3771. status = dev->power.runtime_status;
  3772. if (status == RPM_SUSPENDING || status == RPM_SUSPENDED)
  3773. cnss_pr_vdbg("Runtime PM resume is requested by %ps\n",
  3774. (void *)_RET_IP_);
  3775. return pm_runtime_resume(dev);
  3776. }
  3777. int cnss_pci_pm_runtime_get(struct cnss_pci_data *pci_priv,
  3778. enum cnss_rtpm_id id)
  3779. {
  3780. struct device *dev;
  3781. enum rpm_status status;
  3782. if (!pci_priv)
  3783. return -ENODEV;
  3784. dev = &pci_priv->pci_dev->dev;
  3785. status = dev->power.runtime_status;
  3786. if (status == RPM_SUSPENDING || status == RPM_SUSPENDED)
  3787. cnss_pr_vdbg("Runtime PM resume is requested by %ps\n",
  3788. (void *)_RET_IP_);
  3789. cnss_pci_pm_runtime_get_record(pci_priv, id);
  3790. return pm_runtime_get(dev);
  3791. }
  3792. int cnss_pci_pm_runtime_get_sync(struct cnss_pci_data *pci_priv,
  3793. enum cnss_rtpm_id id)
  3794. {
  3795. struct device *dev;
  3796. enum rpm_status status;
  3797. if (!pci_priv)
  3798. return -ENODEV;
  3799. dev = &pci_priv->pci_dev->dev;
  3800. status = dev->power.runtime_status;
  3801. if (status == RPM_SUSPENDING || status == RPM_SUSPENDED)
  3802. cnss_pr_vdbg("Runtime PM resume is requested by %ps\n",
  3803. (void *)_RET_IP_);
  3804. cnss_pci_pm_runtime_get_record(pci_priv, id);
  3805. return pm_runtime_get_sync(dev);
  3806. }
  3807. void cnss_pci_pm_runtime_get_noresume(struct cnss_pci_data *pci_priv,
  3808. enum cnss_rtpm_id id)
  3809. {
  3810. if (!pci_priv)
  3811. return;
  3812. cnss_pci_pm_runtime_get_record(pci_priv, id);
  3813. pm_runtime_get_noresume(&pci_priv->pci_dev->dev);
  3814. }
  3815. int cnss_pci_pm_runtime_put_autosuspend(struct cnss_pci_data *pci_priv,
  3816. enum cnss_rtpm_id id)
  3817. {
  3818. struct device *dev;
  3819. if (!pci_priv)
  3820. return -ENODEV;
  3821. dev = &pci_priv->pci_dev->dev;
  3822. if (atomic_read(&dev->power.usage_count) == 0) {
  3823. cnss_pr_dbg("Ignore excessive runtime PM put operation\n");
  3824. return -EINVAL;
  3825. }
  3826. cnss_pci_pm_runtime_put_record(pci_priv, id);
  3827. return pm_runtime_put_autosuspend(&pci_priv->pci_dev->dev);
  3828. }
  3829. void cnss_pci_pm_runtime_put_noidle(struct cnss_pci_data *pci_priv,
  3830. enum cnss_rtpm_id id)
  3831. {
  3832. struct device *dev;
  3833. if (!pci_priv)
  3834. return;
  3835. dev = &pci_priv->pci_dev->dev;
  3836. if (atomic_read(&dev->power.usage_count) == 0) {
  3837. cnss_pr_dbg("Ignore excessive runtime PM put operation\n");
  3838. return;
  3839. }
  3840. cnss_pci_pm_runtime_put_record(pci_priv, id);
  3841. pm_runtime_put_noidle(&pci_priv->pci_dev->dev);
  3842. }
  3843. void cnss_pci_pm_runtime_mark_last_busy(struct cnss_pci_data *pci_priv)
  3844. {
  3845. if (!pci_priv)
  3846. return;
  3847. pm_runtime_mark_last_busy(&pci_priv->pci_dev->dev);
  3848. }
  3849. int cnss_auto_suspend(struct device *dev)
  3850. {
  3851. int ret = 0;
  3852. struct pci_dev *pci_dev = to_pci_dev(dev);
  3853. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  3854. struct cnss_plat_data *plat_priv;
  3855. if (!pci_priv)
  3856. return -ENODEV;
  3857. plat_priv = pci_priv->plat_priv;
  3858. if (!plat_priv)
  3859. return -ENODEV;
  3860. mutex_lock(&pci_priv->bus_lock);
  3861. if (!pci_priv->qmi_send_usage_count) {
  3862. ret = cnss_pci_suspend_bus(pci_priv);
  3863. if (ret) {
  3864. mutex_unlock(&pci_priv->bus_lock);
  3865. return ret;
  3866. }
  3867. }
  3868. cnss_pci_set_auto_suspended(pci_priv, 1);
  3869. mutex_unlock(&pci_priv->bus_lock);
  3870. cnss_pci_set_monitor_wake_intr(pci_priv, true);
  3871. /* For suspend temporarily set bandwidth vote to NONE and dont save in
  3872. * current_bw_vote as in resume path we should vote for last used
  3873. * bandwidth vote. Also ignore error if bw voting is not setup.
  3874. */
  3875. cnss_setup_bus_bandwidth(plat_priv, CNSS_BUS_WIDTH_NONE, false);
  3876. return 0;
  3877. }
  3878. EXPORT_SYMBOL(cnss_auto_suspend);
  3879. int cnss_auto_resume(struct device *dev)
  3880. {
  3881. int ret = 0;
  3882. struct pci_dev *pci_dev = to_pci_dev(dev);
  3883. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  3884. struct cnss_plat_data *plat_priv;
  3885. if (!pci_priv)
  3886. return -ENODEV;
  3887. plat_priv = pci_priv->plat_priv;
  3888. if (!plat_priv)
  3889. return -ENODEV;
  3890. mutex_lock(&pci_priv->bus_lock);
  3891. ret = cnss_pci_resume_bus(pci_priv);
  3892. if (ret) {
  3893. mutex_unlock(&pci_priv->bus_lock);
  3894. return ret;
  3895. }
  3896. cnss_pci_set_auto_suspended(pci_priv, 0);
  3897. mutex_unlock(&pci_priv->bus_lock);
  3898. cnss_request_bus_bandwidth(dev, plat_priv->icc.current_bw_vote);
  3899. pci_priv->drv_connected_last = 0;
  3900. return 0;
  3901. }
  3902. EXPORT_SYMBOL(cnss_auto_resume);
  3903. int cnss_pci_force_wake_request_sync(struct device *dev, int timeout_us)
  3904. {
  3905. struct pci_dev *pci_dev = to_pci_dev(dev);
  3906. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  3907. struct cnss_plat_data *plat_priv;
  3908. struct mhi_controller *mhi_ctrl;
  3909. if (!pci_priv)
  3910. return -ENODEV;
  3911. switch (pci_priv->device_id) {
  3912. case QCA6390_DEVICE_ID:
  3913. case QCA6490_DEVICE_ID:
  3914. case KIWI_DEVICE_ID:
  3915. case MANGO_DEVICE_ID:
  3916. case PEACH_DEVICE_ID:
  3917. break;
  3918. default:
  3919. return 0;
  3920. }
  3921. mhi_ctrl = pci_priv->mhi_ctrl;
  3922. if (!mhi_ctrl)
  3923. return -EINVAL;
  3924. plat_priv = pci_priv->plat_priv;
  3925. if (!plat_priv)
  3926. return -ENODEV;
  3927. if (test_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state))
  3928. return -EAGAIN;
  3929. if (timeout_us) {
  3930. /* Busy wait for timeout_us */
  3931. return cnss_mhi_device_get_sync_atomic(pci_priv,
  3932. timeout_us, false);
  3933. } else {
  3934. /* Sleep wait for mhi_ctrl->timeout_ms */
  3935. return mhi_device_get_sync(mhi_ctrl->mhi_dev);
  3936. }
  3937. }
  3938. EXPORT_SYMBOL(cnss_pci_force_wake_request_sync);
  3939. int cnss_pci_force_wake_request(struct device *dev)
  3940. {
  3941. struct pci_dev *pci_dev = to_pci_dev(dev);
  3942. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  3943. struct cnss_plat_data *plat_priv;
  3944. struct mhi_controller *mhi_ctrl;
  3945. if (!pci_priv)
  3946. return -ENODEV;
  3947. switch (pci_priv->device_id) {
  3948. case QCA6390_DEVICE_ID:
  3949. case QCA6490_DEVICE_ID:
  3950. case KIWI_DEVICE_ID:
  3951. case MANGO_DEVICE_ID:
  3952. case PEACH_DEVICE_ID:
  3953. break;
  3954. default:
  3955. return 0;
  3956. }
  3957. mhi_ctrl = pci_priv->mhi_ctrl;
  3958. if (!mhi_ctrl)
  3959. return -EINVAL;
  3960. plat_priv = pci_priv->plat_priv;
  3961. if (!plat_priv)
  3962. return -ENODEV;
  3963. if (test_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state))
  3964. return -EAGAIN;
  3965. mhi_device_get(mhi_ctrl->mhi_dev);
  3966. return 0;
  3967. }
  3968. EXPORT_SYMBOL(cnss_pci_force_wake_request);
  3969. int cnss_pci_is_device_awake(struct device *dev)
  3970. {
  3971. struct pci_dev *pci_dev = to_pci_dev(dev);
  3972. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  3973. struct mhi_controller *mhi_ctrl;
  3974. if (!pci_priv)
  3975. return -ENODEV;
  3976. switch (pci_priv->device_id) {
  3977. case QCA6390_DEVICE_ID:
  3978. case QCA6490_DEVICE_ID:
  3979. case KIWI_DEVICE_ID:
  3980. case MANGO_DEVICE_ID:
  3981. case PEACH_DEVICE_ID:
  3982. break;
  3983. default:
  3984. return 0;
  3985. }
  3986. mhi_ctrl = pci_priv->mhi_ctrl;
  3987. if (!mhi_ctrl)
  3988. return -EINVAL;
  3989. return (mhi_ctrl->dev_state == MHI_STATE_M0);
  3990. }
  3991. EXPORT_SYMBOL(cnss_pci_is_device_awake);
  3992. int cnss_pci_force_wake_release(struct device *dev)
  3993. {
  3994. struct pci_dev *pci_dev = to_pci_dev(dev);
  3995. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  3996. struct cnss_plat_data *plat_priv;
  3997. struct mhi_controller *mhi_ctrl;
  3998. if (!pci_priv)
  3999. return -ENODEV;
  4000. switch (pci_priv->device_id) {
  4001. case QCA6390_DEVICE_ID:
  4002. case QCA6490_DEVICE_ID:
  4003. case KIWI_DEVICE_ID:
  4004. case MANGO_DEVICE_ID:
  4005. case PEACH_DEVICE_ID:
  4006. break;
  4007. default:
  4008. return 0;
  4009. }
  4010. mhi_ctrl = pci_priv->mhi_ctrl;
  4011. if (!mhi_ctrl)
  4012. return -EINVAL;
  4013. plat_priv = pci_priv->plat_priv;
  4014. if (!plat_priv)
  4015. return -ENODEV;
  4016. if (test_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state))
  4017. return -EAGAIN;
  4018. mhi_device_put(mhi_ctrl->mhi_dev);
  4019. return 0;
  4020. }
  4021. EXPORT_SYMBOL(cnss_pci_force_wake_release);
  4022. int cnss_pci_qmi_send_get(struct cnss_pci_data *pci_priv)
  4023. {
  4024. int ret = 0;
  4025. if (!pci_priv)
  4026. return -ENODEV;
  4027. mutex_lock(&pci_priv->bus_lock);
  4028. if (cnss_pci_get_auto_suspended(pci_priv) &&
  4029. !pci_priv->qmi_send_usage_count)
  4030. ret = cnss_pci_resume_bus(pci_priv);
  4031. pci_priv->qmi_send_usage_count++;
  4032. cnss_pr_buf("Increased QMI send usage count to %d\n",
  4033. pci_priv->qmi_send_usage_count);
  4034. mutex_unlock(&pci_priv->bus_lock);
  4035. return ret;
  4036. }
  4037. int cnss_pci_qmi_send_put(struct cnss_pci_data *pci_priv)
  4038. {
  4039. int ret = 0;
  4040. if (!pci_priv)
  4041. return -ENODEV;
  4042. mutex_lock(&pci_priv->bus_lock);
  4043. if (pci_priv->qmi_send_usage_count)
  4044. pci_priv->qmi_send_usage_count--;
  4045. cnss_pr_buf("Decreased QMI send usage count to %d\n",
  4046. pci_priv->qmi_send_usage_count);
  4047. if (cnss_pci_get_auto_suspended(pci_priv) &&
  4048. !pci_priv->qmi_send_usage_count &&
  4049. !cnss_pcie_is_device_down(pci_priv))
  4050. ret = cnss_pci_suspend_bus(pci_priv);
  4051. mutex_unlock(&pci_priv->bus_lock);
  4052. return ret;
  4053. }
  4054. int cnss_send_buffer_to_afcmem(struct device *dev, const uint8_t *afcdb,
  4055. uint32_t len, uint8_t slotid)
  4056. {
  4057. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  4058. struct cnss_fw_mem *fw_mem;
  4059. void *mem = NULL;
  4060. int i, ret;
  4061. u32 *status;
  4062. if (!plat_priv)
  4063. return -EINVAL;
  4064. fw_mem = plat_priv->fw_mem;
  4065. if (slotid >= AFC_MAX_SLOT) {
  4066. cnss_pr_err("Invalid slot id %d\n", slotid);
  4067. ret = -EINVAL;
  4068. goto err;
  4069. }
  4070. if (len > AFC_SLOT_SIZE) {
  4071. cnss_pr_err("len %d greater than slot size", len);
  4072. ret = -EINVAL;
  4073. goto err;
  4074. }
  4075. for (i = 0; i < plat_priv->fw_mem_seg_len; i++) {
  4076. if (fw_mem[i].type == QMI_WLFW_AFC_MEM_V01) {
  4077. mem = fw_mem[i].va;
  4078. status = mem + (slotid * AFC_SLOT_SIZE);
  4079. break;
  4080. }
  4081. }
  4082. if (!mem) {
  4083. cnss_pr_err("AFC mem is not available\n");
  4084. ret = -ENOMEM;
  4085. goto err;
  4086. }
  4087. memcpy(mem + (slotid * AFC_SLOT_SIZE), afcdb, len);
  4088. if (len < AFC_SLOT_SIZE)
  4089. memset(mem + (slotid * AFC_SLOT_SIZE) + len,
  4090. 0, AFC_SLOT_SIZE - len);
  4091. status[AFC_AUTH_STATUS_OFFSET] = cpu_to_le32(AFC_AUTH_SUCCESS);
  4092. return 0;
  4093. err:
  4094. return ret;
  4095. }
  4096. EXPORT_SYMBOL(cnss_send_buffer_to_afcmem);
  4097. int cnss_reset_afcmem(struct device *dev, uint8_t slotid)
  4098. {
  4099. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  4100. struct cnss_fw_mem *fw_mem;
  4101. void *mem = NULL;
  4102. int i, ret;
  4103. if (!plat_priv)
  4104. return -EINVAL;
  4105. fw_mem = plat_priv->fw_mem;
  4106. if (slotid >= AFC_MAX_SLOT) {
  4107. cnss_pr_err("Invalid slot id %d\n", slotid);
  4108. ret = -EINVAL;
  4109. goto err;
  4110. }
  4111. for (i = 0; i < plat_priv->fw_mem_seg_len; i++) {
  4112. if (fw_mem[i].type == QMI_WLFW_AFC_MEM_V01) {
  4113. mem = fw_mem[i].va;
  4114. break;
  4115. }
  4116. }
  4117. if (!mem) {
  4118. cnss_pr_err("AFC mem is not available\n");
  4119. ret = -ENOMEM;
  4120. goto err;
  4121. }
  4122. memset(mem + (slotid * AFC_SLOT_SIZE), 0, AFC_SLOT_SIZE);
  4123. return 0;
  4124. err:
  4125. return ret;
  4126. }
  4127. EXPORT_SYMBOL(cnss_reset_afcmem);
  4128. int cnss_pci_alloc_fw_mem(struct cnss_pci_data *pci_priv)
  4129. {
  4130. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  4131. struct cnss_fw_mem *fw_mem = plat_priv->fw_mem;
  4132. struct device *dev = &pci_priv->pci_dev->dev;
  4133. int i;
  4134. for (i = 0; i < plat_priv->fw_mem_seg_len; i++) {
  4135. if (!fw_mem[i].va && fw_mem[i].size) {
  4136. retry:
  4137. fw_mem[i].va =
  4138. dma_alloc_attrs(dev, fw_mem[i].size,
  4139. &fw_mem[i].pa, GFP_KERNEL,
  4140. fw_mem[i].attrs);
  4141. if (!fw_mem[i].va) {
  4142. if ((fw_mem[i].attrs &
  4143. DMA_ATTR_FORCE_CONTIGUOUS)) {
  4144. fw_mem[i].attrs &=
  4145. ~DMA_ATTR_FORCE_CONTIGUOUS;
  4146. cnss_pr_dbg("Fallback to non-contiguous memory for FW, Mem type: %u\n",
  4147. fw_mem[i].type);
  4148. goto retry;
  4149. }
  4150. cnss_pr_err("Failed to allocate memory for FW, size: 0x%zx, type: %u\n",
  4151. fw_mem[i].size, fw_mem[i].type);
  4152. CNSS_ASSERT(0);
  4153. return -ENOMEM;
  4154. }
  4155. }
  4156. }
  4157. return 0;
  4158. }
  4159. static void cnss_pci_free_fw_mem(struct cnss_pci_data *pci_priv)
  4160. {
  4161. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  4162. struct cnss_fw_mem *fw_mem = plat_priv->fw_mem;
  4163. struct device *dev = &pci_priv->pci_dev->dev;
  4164. int i;
  4165. for (i = 0; i < plat_priv->fw_mem_seg_len; i++) {
  4166. if (fw_mem[i].va && fw_mem[i].size) {
  4167. cnss_pr_dbg("Freeing memory for FW, va: 0x%pK, pa: %pa, size: 0x%zx, type: %u\n",
  4168. fw_mem[i].va, &fw_mem[i].pa,
  4169. fw_mem[i].size, fw_mem[i].type);
  4170. dma_free_attrs(dev, fw_mem[i].size,
  4171. fw_mem[i].va, fw_mem[i].pa,
  4172. fw_mem[i].attrs);
  4173. fw_mem[i].va = NULL;
  4174. fw_mem[i].pa = 0;
  4175. fw_mem[i].size = 0;
  4176. fw_mem[i].type = 0;
  4177. }
  4178. }
  4179. plat_priv->fw_mem_seg_len = 0;
  4180. }
  4181. int cnss_pci_alloc_qdss_mem(struct cnss_pci_data *pci_priv)
  4182. {
  4183. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  4184. struct cnss_fw_mem *qdss_mem = plat_priv->qdss_mem;
  4185. int i, j;
  4186. for (i = 0; i < plat_priv->qdss_mem_seg_len; i++) {
  4187. if (!qdss_mem[i].va && qdss_mem[i].size) {
  4188. qdss_mem[i].va =
  4189. dma_alloc_coherent(&pci_priv->pci_dev->dev,
  4190. qdss_mem[i].size,
  4191. &qdss_mem[i].pa,
  4192. GFP_KERNEL);
  4193. if (!qdss_mem[i].va) {
  4194. cnss_pr_err("Failed to allocate QDSS memory for FW, size: 0x%zx, type: %u, chuck-ID: %d\n",
  4195. qdss_mem[i].size,
  4196. qdss_mem[i].type, i);
  4197. break;
  4198. }
  4199. }
  4200. }
  4201. /* Best-effort allocation for QDSS trace */
  4202. if (i < plat_priv->qdss_mem_seg_len) {
  4203. for (j = i; j < plat_priv->qdss_mem_seg_len; j++) {
  4204. qdss_mem[j].type = 0;
  4205. qdss_mem[j].size = 0;
  4206. }
  4207. plat_priv->qdss_mem_seg_len = i;
  4208. }
  4209. return 0;
  4210. }
  4211. void cnss_pci_free_qdss_mem(struct cnss_pci_data *pci_priv)
  4212. {
  4213. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  4214. struct cnss_fw_mem *qdss_mem = plat_priv->qdss_mem;
  4215. int i;
  4216. for (i = 0; i < plat_priv->qdss_mem_seg_len; i++) {
  4217. if (qdss_mem[i].va && qdss_mem[i].size) {
  4218. cnss_pr_dbg("Freeing memory for QDSS: pa: %pa, size: 0x%zx, type: %u\n",
  4219. &qdss_mem[i].pa, qdss_mem[i].size,
  4220. qdss_mem[i].type);
  4221. dma_free_coherent(&pci_priv->pci_dev->dev,
  4222. qdss_mem[i].size, qdss_mem[i].va,
  4223. qdss_mem[i].pa);
  4224. qdss_mem[i].va = NULL;
  4225. qdss_mem[i].pa = 0;
  4226. qdss_mem[i].size = 0;
  4227. qdss_mem[i].type = 0;
  4228. }
  4229. }
  4230. plat_priv->qdss_mem_seg_len = 0;
  4231. }
  4232. int cnss_pci_load_tme_patch(struct cnss_pci_data *pci_priv)
  4233. {
  4234. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  4235. struct cnss_fw_mem *tme_lite_mem = &plat_priv->tme_lite_mem;
  4236. char filename[MAX_FIRMWARE_NAME_LEN];
  4237. char *tme_patch_filename = NULL;
  4238. const struct firmware *fw_entry;
  4239. int ret = 0;
  4240. switch (pci_priv->device_id) {
  4241. case PEACH_DEVICE_ID:
  4242. if (plat_priv->device_version.major_version == FW_V1_NUMBER)
  4243. tme_patch_filename = TME_PATCH_FILE_NAME_1_0;
  4244. else if (plat_priv->device_version.major_version == FW_V2_NUMBER)
  4245. tme_patch_filename = TME_PATCH_FILE_NAME_2_0;
  4246. break;
  4247. case QCA6174_DEVICE_ID:
  4248. case QCA6290_DEVICE_ID:
  4249. case QCA6390_DEVICE_ID:
  4250. case QCA6490_DEVICE_ID:
  4251. case KIWI_DEVICE_ID:
  4252. case MANGO_DEVICE_ID:
  4253. default:
  4254. cnss_pr_dbg("TME-L not supported for device ID: (0x%x)\n",
  4255. pci_priv->device_id);
  4256. return 0;
  4257. }
  4258. if (!tme_lite_mem->va && !tme_lite_mem->size) {
  4259. scnprintf(filename, MAX_FIRMWARE_NAME_LEN, "%s", tme_patch_filename);
  4260. ret = firmware_request_nowarn(&fw_entry, filename,
  4261. &pci_priv->pci_dev->dev);
  4262. if (ret) {
  4263. cnss_pr_err("Failed to load TME-L patch: %s, ret: %d\n",
  4264. filename, ret);
  4265. return ret;
  4266. }
  4267. tme_lite_mem->va = dma_alloc_coherent(&pci_priv->pci_dev->dev,
  4268. fw_entry->size, &tme_lite_mem->pa,
  4269. GFP_KERNEL);
  4270. if (!tme_lite_mem->va) {
  4271. cnss_pr_err("Failed to allocate memory for M3, size: 0x%zx\n",
  4272. fw_entry->size);
  4273. release_firmware(fw_entry);
  4274. return -ENOMEM;
  4275. }
  4276. memcpy(tme_lite_mem->va, fw_entry->data, fw_entry->size);
  4277. tme_lite_mem->size = fw_entry->size;
  4278. release_firmware(fw_entry);
  4279. }
  4280. return 0;
  4281. }
  4282. static void cnss_pci_free_tme_lite_mem(struct cnss_pci_data *pci_priv)
  4283. {
  4284. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  4285. struct cnss_fw_mem *tme_lite_mem = &plat_priv->tme_lite_mem;
  4286. if (tme_lite_mem->va && tme_lite_mem->size) {
  4287. cnss_pr_dbg("Freeing memory for TME patch, va: 0x%pK, pa: %pa, size: 0x%zx\n",
  4288. tme_lite_mem->va, &tme_lite_mem->pa, tme_lite_mem->size);
  4289. dma_free_coherent(&pci_priv->pci_dev->dev, tme_lite_mem->size,
  4290. tme_lite_mem->va, tme_lite_mem->pa);
  4291. }
  4292. tme_lite_mem->va = NULL;
  4293. tme_lite_mem->pa = 0;
  4294. tme_lite_mem->size = 0;
  4295. }
  4296. int cnss_pci_load_tme_opt_file(struct cnss_pci_data *pci_priv,
  4297. enum wlfw_tme_lite_file_type_v01 file)
  4298. {
  4299. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  4300. struct cnss_fw_mem *tme_lite_mem = NULL;
  4301. char filename[MAX_FIRMWARE_NAME_LEN];
  4302. char *tme_opt_filename = NULL;
  4303. const struct firmware *fw_entry;
  4304. int ret = 0;
  4305. switch (pci_priv->device_id) {
  4306. case PEACH_DEVICE_ID:
  4307. if (file == WLFW_TME_LITE_OEM_FUSE_FILE_V01) {
  4308. tme_opt_filename = TME_OEM_FUSE_FILE_NAME;
  4309. tme_lite_mem = &plat_priv->tme_opt_file_mem[0];
  4310. } else if (file == WLFW_TME_LITE_RPR_FILE_V01) {
  4311. tme_opt_filename = TME_RPR_FILE_NAME;
  4312. tme_lite_mem = &plat_priv->tme_opt_file_mem[1];
  4313. } else if (file == WLFW_TME_LITE_DPR_FILE_V01) {
  4314. tme_opt_filename = TME_DPR_FILE_NAME;
  4315. tme_lite_mem = &plat_priv->tme_opt_file_mem[2];
  4316. }
  4317. break;
  4318. case QCA6174_DEVICE_ID:
  4319. case QCA6290_DEVICE_ID:
  4320. case QCA6390_DEVICE_ID:
  4321. case QCA6490_DEVICE_ID:
  4322. case KIWI_DEVICE_ID:
  4323. case MANGO_DEVICE_ID:
  4324. default:
  4325. cnss_pr_dbg("TME-L opt file: %s not supported for device ID: (0x%x)\n",
  4326. tme_opt_filename, pci_priv->device_id);
  4327. return 0;
  4328. }
  4329. if (!tme_lite_mem)
  4330. return 0;
  4331. if (!tme_lite_mem->va && !tme_lite_mem->size) {
  4332. cnss_pci_add_fw_prefix_name(pci_priv, filename,
  4333. tme_opt_filename);
  4334. ret = firmware_request_nowarn(&fw_entry, filename,
  4335. &pci_priv->pci_dev->dev);
  4336. if (ret) {
  4337. cnss_pr_err("Failed to load TME-L opt file: %s, ret: %d\n",
  4338. filename, ret);
  4339. return ret;
  4340. }
  4341. tme_lite_mem->va = dma_alloc_coherent(&pci_priv->pci_dev->dev,
  4342. fw_entry->size, &tme_lite_mem->pa,
  4343. GFP_KERNEL);
  4344. if (!tme_lite_mem->va) {
  4345. cnss_pr_err("Failed to allocate memory for TME-L opt file %s,size: 0x%zx\n",
  4346. filename, fw_entry->size);
  4347. release_firmware(fw_entry);
  4348. return -ENOMEM;
  4349. }
  4350. memcpy(tme_lite_mem->va, fw_entry->data, fw_entry->size);
  4351. tme_lite_mem->size = fw_entry->size;
  4352. release_firmware(fw_entry);
  4353. }
  4354. return 0;
  4355. }
  4356. static void cnss_pci_free_tme_opt_file_mem(struct cnss_pci_data *pci_priv)
  4357. {
  4358. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  4359. struct cnss_fw_mem *tme_opt_file_mem = plat_priv->tme_opt_file_mem;
  4360. int i = 0;
  4361. for (i = 0; i < QMI_WLFW_MAX_TME_OPT_FILE_NUM; i++) {
  4362. if (tme_opt_file_mem[i].va && tme_opt_file_mem[i].size) {
  4363. cnss_pr_dbg("Free memory for TME opt file,va:0x%pK, pa:%pa, size:0x%zx\n",
  4364. tme_opt_file_mem[i].va, &tme_opt_file_mem[i].pa,
  4365. tme_opt_file_mem[i].size);
  4366. dma_free_coherent(&pci_priv->pci_dev->dev, tme_opt_file_mem[i].size,
  4367. tme_opt_file_mem[i].va, tme_opt_file_mem[i].pa);
  4368. }
  4369. tme_opt_file_mem[i].va = NULL;
  4370. tme_opt_file_mem[i].pa = 0;
  4371. tme_opt_file_mem[i].size = 0;
  4372. }
  4373. }
  4374. int cnss_pci_load_m3(struct cnss_pci_data *pci_priv)
  4375. {
  4376. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  4377. struct cnss_fw_mem *m3_mem = &plat_priv->m3_mem;
  4378. char filename[MAX_FIRMWARE_NAME_LEN];
  4379. char *phy_filename = DEFAULT_PHY_UCODE_FILE_NAME;
  4380. const struct firmware *fw_entry;
  4381. int ret = 0;
  4382. /* Use forward compatibility here since for any recent device
  4383. * it should use DEFAULT_PHY_UCODE_FILE_NAME.
  4384. */
  4385. switch (pci_priv->device_id) {
  4386. case QCA6174_DEVICE_ID:
  4387. cnss_pr_err("Invalid device ID (0x%x) to load phy image\n",
  4388. pci_priv->device_id);
  4389. return -EINVAL;
  4390. case QCA6290_DEVICE_ID:
  4391. case QCA6390_DEVICE_ID:
  4392. case QCA6490_DEVICE_ID:
  4393. phy_filename = DEFAULT_PHY_M3_FILE_NAME;
  4394. break;
  4395. case KIWI_DEVICE_ID:
  4396. case MANGO_DEVICE_ID:
  4397. case PEACH_DEVICE_ID:
  4398. switch (plat_priv->device_version.major_version) {
  4399. case FW_V2_NUMBER:
  4400. phy_filename = PHY_UCODE_V2_FILE_NAME;
  4401. break;
  4402. default:
  4403. break;
  4404. }
  4405. break;
  4406. default:
  4407. break;
  4408. }
  4409. if (!m3_mem->va && !m3_mem->size) {
  4410. cnss_pci_add_fw_prefix_name(pci_priv, filename,
  4411. phy_filename);
  4412. ret = firmware_request_nowarn(&fw_entry, filename,
  4413. &pci_priv->pci_dev->dev);
  4414. if (ret) {
  4415. cnss_pr_err("Failed to load M3 image: %s\n", filename);
  4416. return ret;
  4417. }
  4418. m3_mem->va = dma_alloc_coherent(&pci_priv->pci_dev->dev,
  4419. fw_entry->size, &m3_mem->pa,
  4420. GFP_KERNEL);
  4421. if (!m3_mem->va) {
  4422. cnss_pr_err("Failed to allocate memory for M3, size: 0x%zx\n",
  4423. fw_entry->size);
  4424. release_firmware(fw_entry);
  4425. return -ENOMEM;
  4426. }
  4427. memcpy(m3_mem->va, fw_entry->data, fw_entry->size);
  4428. m3_mem->size = fw_entry->size;
  4429. release_firmware(fw_entry);
  4430. }
  4431. return 0;
  4432. }
  4433. static void cnss_pci_free_m3_mem(struct cnss_pci_data *pci_priv)
  4434. {
  4435. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  4436. struct cnss_fw_mem *m3_mem = &plat_priv->m3_mem;
  4437. if (m3_mem->va && m3_mem->size) {
  4438. cnss_pr_dbg("Freeing memory for M3, va: 0x%pK, pa: %pa, size: 0x%zx\n",
  4439. m3_mem->va, &m3_mem->pa, m3_mem->size);
  4440. dma_free_coherent(&pci_priv->pci_dev->dev, m3_mem->size,
  4441. m3_mem->va, m3_mem->pa);
  4442. }
  4443. m3_mem->va = NULL;
  4444. m3_mem->pa = 0;
  4445. m3_mem->size = 0;
  4446. }
  4447. #ifdef CONFIG_FREE_M3_BLOB_MEM
  4448. void cnss_pci_free_blob_mem(struct cnss_pci_data *pci_priv)
  4449. {
  4450. cnss_pci_free_m3_mem(pci_priv);
  4451. }
  4452. #else
  4453. void cnss_pci_free_blob_mem(struct cnss_pci_data *pci_priv)
  4454. {
  4455. }
  4456. #endif
  4457. int cnss_pci_load_aux(struct cnss_pci_data *pci_priv)
  4458. {
  4459. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  4460. struct cnss_fw_mem *aux_mem = &plat_priv->aux_mem;
  4461. char filename[MAX_FIRMWARE_NAME_LEN];
  4462. char *aux_filename = DEFAULT_AUX_FILE_NAME;
  4463. const struct firmware *fw_entry;
  4464. int ret = 0;
  4465. if (!aux_mem->va && !aux_mem->size) {
  4466. cnss_pci_add_fw_prefix_name(pci_priv, filename,
  4467. aux_filename);
  4468. ret = firmware_request_nowarn(&fw_entry, filename,
  4469. &pci_priv->pci_dev->dev);
  4470. if (ret) {
  4471. cnss_pr_err("Failed to load AUX image: %s\n", filename);
  4472. return ret;
  4473. }
  4474. aux_mem->va = dma_alloc_coherent(&pci_priv->pci_dev->dev,
  4475. fw_entry->size, &aux_mem->pa,
  4476. GFP_KERNEL);
  4477. if (!aux_mem->va) {
  4478. cnss_pr_err("Failed to allocate memory for AUX, size: 0x%zx\n",
  4479. fw_entry->size);
  4480. release_firmware(fw_entry);
  4481. return -ENOMEM;
  4482. }
  4483. memcpy(aux_mem->va, fw_entry->data, fw_entry->size);
  4484. aux_mem->size = fw_entry->size;
  4485. release_firmware(fw_entry);
  4486. }
  4487. return 0;
  4488. }
  4489. static void cnss_pci_free_aux_mem(struct cnss_pci_data *pci_priv)
  4490. {
  4491. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  4492. struct cnss_fw_mem *aux_mem = &plat_priv->aux_mem;
  4493. if (aux_mem->va && aux_mem->size) {
  4494. cnss_pr_dbg("Freeing memory for AUX, va: 0x%pK, pa: %pa, size: 0x%zx\n",
  4495. aux_mem->va, &aux_mem->pa, aux_mem->size);
  4496. dma_free_coherent(&pci_priv->pci_dev->dev, aux_mem->size,
  4497. aux_mem->va, aux_mem->pa);
  4498. }
  4499. aux_mem->va = NULL;
  4500. aux_mem->pa = 0;
  4501. aux_mem->size = 0;
  4502. }
  4503. void cnss_pci_fw_boot_timeout_hdlr(struct cnss_pci_data *pci_priv)
  4504. {
  4505. struct cnss_plat_data *plat_priv;
  4506. if (!pci_priv)
  4507. return;
  4508. cnss_fatal_err("Timeout waiting for FW ready indication\n");
  4509. plat_priv = pci_priv->plat_priv;
  4510. if (!plat_priv)
  4511. return;
  4512. if (test_bit(CNSS_IN_COLD_BOOT_CAL, &plat_priv->driver_state)) {
  4513. cnss_pr_dbg("Ignore FW ready timeout for calibration mode\n");
  4514. return;
  4515. }
  4516. cnss_schedule_recovery(&pci_priv->pci_dev->dev,
  4517. CNSS_REASON_TIMEOUT);
  4518. }
  4519. static void cnss_pci_deinit_smmu(struct cnss_pci_data *pci_priv)
  4520. {
  4521. pci_priv->iommu_domain = NULL;
  4522. }
  4523. int cnss_pci_get_iova(struct cnss_pci_data *pci_priv, u64 *addr, u64 *size)
  4524. {
  4525. if (!pci_priv)
  4526. return -ENODEV;
  4527. if (!pci_priv->smmu_iova_len)
  4528. return -EINVAL;
  4529. *addr = pci_priv->smmu_iova_start;
  4530. *size = pci_priv->smmu_iova_len;
  4531. return 0;
  4532. }
  4533. int cnss_pci_get_iova_ipa(struct cnss_pci_data *pci_priv, u64 *addr, u64 *size)
  4534. {
  4535. if (!pci_priv)
  4536. return -ENODEV;
  4537. if (!pci_priv->smmu_iova_ipa_len)
  4538. return -EINVAL;
  4539. *addr = pci_priv->smmu_iova_ipa_start;
  4540. *size = pci_priv->smmu_iova_ipa_len;
  4541. return 0;
  4542. }
  4543. bool cnss_pci_is_smmu_s1_enabled(struct cnss_pci_data *pci_priv)
  4544. {
  4545. if (pci_priv)
  4546. return pci_priv->smmu_s1_enable;
  4547. return false;
  4548. }
  4549. struct iommu_domain *cnss_smmu_get_domain(struct device *dev)
  4550. {
  4551. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(to_pci_dev(dev));
  4552. if (!pci_priv)
  4553. return NULL;
  4554. return pci_priv->iommu_domain;
  4555. }
  4556. EXPORT_SYMBOL(cnss_smmu_get_domain);
  4557. int cnss_smmu_map(struct device *dev,
  4558. phys_addr_t paddr, uint32_t *iova_addr, size_t size)
  4559. {
  4560. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(to_pci_dev(dev));
  4561. struct cnss_plat_data *plat_priv;
  4562. unsigned long iova;
  4563. size_t len;
  4564. int ret = 0;
  4565. int flag = IOMMU_READ | IOMMU_WRITE;
  4566. struct pci_dev *root_port;
  4567. struct device_node *root_of_node;
  4568. bool dma_coherent = false;
  4569. if (!pci_priv)
  4570. return -ENODEV;
  4571. if (!iova_addr) {
  4572. cnss_pr_err("iova_addr is NULL, paddr %pa, size %zu\n",
  4573. &paddr, size);
  4574. return -EINVAL;
  4575. }
  4576. plat_priv = pci_priv->plat_priv;
  4577. len = roundup(size + paddr - rounddown(paddr, PAGE_SIZE), PAGE_SIZE);
  4578. iova = roundup(pci_priv->smmu_iova_ipa_current, PAGE_SIZE);
  4579. if (pci_priv->iommu_geometry &&
  4580. iova >= pci_priv->smmu_iova_ipa_start +
  4581. pci_priv->smmu_iova_ipa_len) {
  4582. cnss_pr_err("No IOVA space to map, iova %lx, smmu_iova_ipa_start %pad, smmu_iova_ipa_len %zu\n",
  4583. iova,
  4584. &pci_priv->smmu_iova_ipa_start,
  4585. pci_priv->smmu_iova_ipa_len);
  4586. return -ENOMEM;
  4587. }
  4588. if (!test_bit(DISABLE_IO_COHERENCY,
  4589. &plat_priv->ctrl_params.quirks)) {
  4590. root_port = pcie_find_root_port(pci_priv->pci_dev);
  4591. if (!root_port) {
  4592. cnss_pr_err("Root port is null, so dma_coherent is disabled\n");
  4593. } else {
  4594. root_of_node = root_port->dev.of_node;
  4595. if (root_of_node && root_of_node->parent) {
  4596. dma_coherent =
  4597. of_property_read_bool(root_of_node->parent,
  4598. "dma-coherent");
  4599. cnss_pr_dbg("dma-coherent is %s\n",
  4600. dma_coherent ? "enabled" : "disabled");
  4601. if (dma_coherent)
  4602. flag |= IOMMU_CACHE;
  4603. }
  4604. }
  4605. }
  4606. cnss_pr_dbg("IOMMU map: iova %lx, len %zu\n", iova, len);
  4607. ret = cnss_iommu_map(pci_priv->iommu_domain, iova,
  4608. rounddown(paddr, PAGE_SIZE), len, flag);
  4609. if (ret) {
  4610. cnss_pr_err("PA to IOVA mapping failed, ret %d\n", ret);
  4611. return ret;
  4612. }
  4613. pci_priv->smmu_iova_ipa_current = iova + len;
  4614. *iova_addr = (uint32_t)(iova + paddr - rounddown(paddr, PAGE_SIZE));
  4615. cnss_pr_dbg("IOMMU map: iova_addr %lx\n", *iova_addr);
  4616. return 0;
  4617. }
  4618. EXPORT_SYMBOL(cnss_smmu_map);
  4619. int cnss_smmu_unmap(struct device *dev, uint32_t iova_addr, size_t size)
  4620. {
  4621. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(to_pci_dev(dev));
  4622. unsigned long iova;
  4623. size_t unmapped;
  4624. size_t len;
  4625. if (!pci_priv)
  4626. return -ENODEV;
  4627. iova = rounddown(iova_addr, PAGE_SIZE);
  4628. len = roundup(size + iova_addr - iova, PAGE_SIZE);
  4629. if (iova >= pci_priv->smmu_iova_ipa_start +
  4630. pci_priv->smmu_iova_ipa_len) {
  4631. cnss_pr_err("Out of IOVA space to unmap, iova %lx, smmu_iova_ipa_start %pad, smmu_iova_ipa_len %zu\n",
  4632. iova,
  4633. &pci_priv->smmu_iova_ipa_start,
  4634. pci_priv->smmu_iova_ipa_len);
  4635. return -ENOMEM;
  4636. }
  4637. cnss_pr_dbg("IOMMU unmap: iova %lx, len %zu\n", iova, len);
  4638. unmapped = iommu_unmap(pci_priv->iommu_domain, iova, len);
  4639. if (unmapped != len) {
  4640. cnss_pr_err("IOMMU unmap failed, unmapped = %zu, requested = %zu\n",
  4641. unmapped, len);
  4642. return -EINVAL;
  4643. }
  4644. pci_priv->smmu_iova_ipa_current = iova;
  4645. return 0;
  4646. }
  4647. EXPORT_SYMBOL(cnss_smmu_unmap);
  4648. int cnss_get_soc_info(struct device *dev, struct cnss_soc_info *info)
  4649. {
  4650. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(to_pci_dev(dev));
  4651. struct cnss_plat_data *plat_priv;
  4652. if (!pci_priv)
  4653. return -ENODEV;
  4654. plat_priv = pci_priv->plat_priv;
  4655. if (!plat_priv)
  4656. return -ENODEV;
  4657. info->va = pci_priv->bar;
  4658. info->pa = pci_resource_start(pci_priv->pci_dev, PCI_BAR_NUM);
  4659. info->chip_id = plat_priv->chip_info.chip_id;
  4660. info->chip_family = plat_priv->chip_info.chip_family;
  4661. info->board_id = plat_priv->board_info.board_id;
  4662. info->soc_id = plat_priv->soc_info.soc_id;
  4663. info->fw_version = plat_priv->fw_version_info.fw_version;
  4664. strlcpy(info->fw_build_timestamp,
  4665. plat_priv->fw_version_info.fw_build_timestamp,
  4666. sizeof(info->fw_build_timestamp));
  4667. memcpy(&info->device_version, &plat_priv->device_version,
  4668. sizeof(info->device_version));
  4669. memcpy(&info->dev_mem_info, &plat_priv->dev_mem_info,
  4670. sizeof(info->dev_mem_info));
  4671. memcpy(&info->fw_build_id, &plat_priv->fw_build_id,
  4672. sizeof(info->fw_build_id));
  4673. return 0;
  4674. }
  4675. EXPORT_SYMBOL(cnss_get_soc_info);
  4676. int cnss_pci_get_user_msi_assignment(struct cnss_pci_data *pci_priv,
  4677. char *user_name,
  4678. int *num_vectors,
  4679. u32 *user_base_data,
  4680. u32 *base_vector)
  4681. {
  4682. return cnss_get_user_msi_assignment(&pci_priv->pci_dev->dev,
  4683. user_name,
  4684. num_vectors,
  4685. user_base_data,
  4686. base_vector);
  4687. }
  4688. static int cnss_pci_irq_set_affinity_hint(struct cnss_pci_data *pci_priv,
  4689. unsigned int vec,
  4690. const struct cpumask *cpumask)
  4691. {
  4692. int ret;
  4693. struct pci_dev *pci_dev = pci_priv->pci_dev;
  4694. ret = irq_set_affinity_hint(pci_irq_vector(pci_dev, vec),
  4695. cpumask);
  4696. return ret;
  4697. }
  4698. static int cnss_pci_enable_msi(struct cnss_pci_data *pci_priv)
  4699. {
  4700. int ret = 0;
  4701. struct pci_dev *pci_dev = pci_priv->pci_dev;
  4702. int num_vectors;
  4703. struct cnss_msi_config *msi_config;
  4704. if (pci_priv->device_id == QCA6174_DEVICE_ID)
  4705. return 0;
  4706. if (cnss_pci_is_force_one_msi(pci_priv)) {
  4707. ret = cnss_pci_get_one_msi_assignment(pci_priv);
  4708. cnss_pr_dbg("force one msi\n");
  4709. } else {
  4710. ret = cnss_pci_get_msi_assignment(pci_priv);
  4711. }
  4712. if (ret) {
  4713. cnss_pr_err("Failed to get MSI assignment, err = %d\n", ret);
  4714. goto out;
  4715. }
  4716. msi_config = pci_priv->msi_config;
  4717. if (!msi_config) {
  4718. cnss_pr_err("msi_config is NULL!\n");
  4719. ret = -EINVAL;
  4720. goto out;
  4721. }
  4722. num_vectors = pci_alloc_irq_vectors(pci_dev,
  4723. msi_config->total_vectors,
  4724. msi_config->total_vectors,
  4725. PCI_IRQ_MSI | PCI_IRQ_MSIX);
  4726. if ((num_vectors != msi_config->total_vectors) &&
  4727. !cnss_pci_fallback_one_msi(pci_priv, &num_vectors)) {
  4728. cnss_pr_err("Failed to get enough MSI vectors (%d), available vectors = %d",
  4729. msi_config->total_vectors, num_vectors);
  4730. if (num_vectors >= 0)
  4731. ret = -EINVAL;
  4732. goto reset_msi_config;
  4733. }
  4734. /* With VT-d disabled on x86 platform, only one pci irq vector is
  4735. * allocated. Once suspend the irq may be migrated to CPU0 if it was
  4736. * affine to other CPU with one new msi vector re-allocated.
  4737. * The observation cause the issue about no irq handler for vector
  4738. * once resume.
  4739. * The fix is to set irq vector affinity to CPU0 before calling
  4740. * request_irq to avoid the irq migration.
  4741. */
  4742. if (cnss_pci_is_one_msi(pci_priv)) {
  4743. ret = cnss_pci_irq_set_affinity_hint(pci_priv,
  4744. 0,
  4745. cpumask_of(0));
  4746. if (ret) {
  4747. cnss_pr_err("Failed to affinize irq vector to CPU0\n");
  4748. goto free_msi_vector;
  4749. }
  4750. }
  4751. if (cnss_pci_config_msi_addr(pci_priv)) {
  4752. ret = -EINVAL;
  4753. goto free_msi_vector;
  4754. }
  4755. if (cnss_pci_config_msi_data(pci_priv)) {
  4756. ret = -EINVAL;
  4757. goto free_msi_vector;
  4758. }
  4759. return 0;
  4760. free_msi_vector:
  4761. if (cnss_pci_is_one_msi(pci_priv))
  4762. cnss_pci_irq_set_affinity_hint(pci_priv, 0, NULL);
  4763. pci_free_irq_vectors(pci_priv->pci_dev);
  4764. reset_msi_config:
  4765. pci_priv->msi_config = NULL;
  4766. out:
  4767. return ret;
  4768. }
  4769. static void cnss_pci_disable_msi(struct cnss_pci_data *pci_priv)
  4770. {
  4771. if (pci_priv->device_id == QCA6174_DEVICE_ID)
  4772. return;
  4773. if (cnss_pci_is_one_msi(pci_priv))
  4774. cnss_pci_irq_set_affinity_hint(pci_priv, 0, NULL);
  4775. pci_free_irq_vectors(pci_priv->pci_dev);
  4776. }
  4777. int cnss_get_user_msi_assignment(struct device *dev, char *user_name,
  4778. int *num_vectors, u32 *user_base_data,
  4779. u32 *base_vector)
  4780. {
  4781. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(to_pci_dev(dev));
  4782. struct cnss_msi_config *msi_config;
  4783. int idx;
  4784. if (!pci_priv)
  4785. return -ENODEV;
  4786. msi_config = pci_priv->msi_config;
  4787. if (!msi_config) {
  4788. cnss_pr_err("MSI is not supported.\n");
  4789. return -EINVAL;
  4790. }
  4791. for (idx = 0; idx < msi_config->total_users; idx++) {
  4792. if (strcmp(user_name, msi_config->users[idx].name) == 0) {
  4793. *num_vectors = msi_config->users[idx].num_vectors;
  4794. *user_base_data = msi_config->users[idx].base_vector
  4795. + pci_priv->msi_ep_base_data;
  4796. *base_vector = msi_config->users[idx].base_vector;
  4797. /*Add only single print for each user*/
  4798. if (print_optimize.msi_log_chk[idx]++)
  4799. goto skip_print;
  4800. cnss_pr_dbg("Assign MSI to user: %s, num_vectors: %d, user_base_data: %u, base_vector: %u\n",
  4801. user_name, *num_vectors, *user_base_data,
  4802. *base_vector);
  4803. skip_print:
  4804. return 0;
  4805. }
  4806. }
  4807. cnss_pr_err("Failed to find MSI assignment for %s!\n", user_name);
  4808. return -EINVAL;
  4809. }
  4810. EXPORT_SYMBOL(cnss_get_user_msi_assignment);
  4811. int cnss_get_msi_irq(struct device *dev, unsigned int vector)
  4812. {
  4813. struct pci_dev *pci_dev = to_pci_dev(dev);
  4814. int irq_num;
  4815. irq_num = pci_irq_vector(pci_dev, vector);
  4816. cnss_pr_dbg("Get IRQ number %d for vector index %d\n", irq_num, vector);
  4817. return irq_num;
  4818. }
  4819. EXPORT_SYMBOL(cnss_get_msi_irq);
  4820. bool cnss_is_one_msi(struct device *dev)
  4821. {
  4822. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(to_pci_dev(dev));
  4823. if (!pci_priv)
  4824. return false;
  4825. return cnss_pci_is_one_msi(pci_priv);
  4826. }
  4827. EXPORT_SYMBOL(cnss_is_one_msi);
  4828. void cnss_get_msi_address(struct device *dev, u32 *msi_addr_low,
  4829. u32 *msi_addr_high)
  4830. {
  4831. struct pci_dev *pci_dev = to_pci_dev(dev);
  4832. struct cnss_pci_data *pci_priv;
  4833. u16 control;
  4834. if (!pci_dev)
  4835. return;
  4836. pci_priv = cnss_get_pci_priv(pci_dev);
  4837. if (!pci_priv)
  4838. return;
  4839. if (pci_dev->msix_enabled) {
  4840. *msi_addr_low = pci_priv->msix_addr;
  4841. *msi_addr_high = 0;
  4842. if (!print_optimize.msi_addr_chk++)
  4843. cnss_pr_dbg("Get MSI low addr = 0x%x, high addr = 0x%x\n",
  4844. *msi_addr_low, *msi_addr_high);
  4845. return;
  4846. }
  4847. pci_read_config_word(pci_dev, pci_dev->msi_cap + PCI_MSI_FLAGS,
  4848. &control);
  4849. pci_read_config_dword(pci_dev, pci_dev->msi_cap + PCI_MSI_ADDRESS_LO,
  4850. msi_addr_low);
  4851. /* Return MSI high address only when device supports 64-bit MSI */
  4852. if (control & PCI_MSI_FLAGS_64BIT)
  4853. pci_read_config_dword(pci_dev,
  4854. pci_dev->msi_cap + PCI_MSI_ADDRESS_HI,
  4855. msi_addr_high);
  4856. else
  4857. *msi_addr_high = 0;
  4858. /*Add only single print as the address is constant*/
  4859. if (!print_optimize.msi_addr_chk++)
  4860. cnss_pr_dbg("Get MSI low addr = 0x%x, high addr = 0x%x\n",
  4861. *msi_addr_low, *msi_addr_high);
  4862. }
  4863. EXPORT_SYMBOL(cnss_get_msi_address);
  4864. u32 cnss_pci_get_wake_msi(struct cnss_pci_data *pci_priv)
  4865. {
  4866. int ret, num_vectors;
  4867. u32 user_base_data, base_vector;
  4868. if (!pci_priv)
  4869. return -ENODEV;
  4870. ret = cnss_get_user_msi_assignment(&pci_priv->pci_dev->dev,
  4871. WAKE_MSI_NAME, &num_vectors,
  4872. &user_base_data, &base_vector);
  4873. if (ret) {
  4874. cnss_pr_err("WAKE MSI is not valid\n");
  4875. return 0;
  4876. }
  4877. return user_base_data;
  4878. }
  4879. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0))
  4880. static inline int cnss_pci_set_dma_mask(struct pci_dev *pci_dev, u64 mask)
  4881. {
  4882. return dma_set_mask(&pci_dev->dev, mask);
  4883. }
  4884. static inline int cnss_pci_set_coherent_dma_mask(struct pci_dev *pci_dev,
  4885. u64 mask)
  4886. {
  4887. return dma_set_coherent_mask(&pci_dev->dev, mask);
  4888. }
  4889. #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0)) */
  4890. static inline int cnss_pci_set_dma_mask(struct pci_dev *pci_dev, u64 mask)
  4891. {
  4892. return pci_set_dma_mask(pci_dev, mask);
  4893. }
  4894. static inline int cnss_pci_set_coherent_dma_mask(struct pci_dev *pci_dev,
  4895. u64 mask)
  4896. {
  4897. return pci_set_consistent_dma_mask(pci_dev, mask);
  4898. }
  4899. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0)) */
  4900. static int cnss_pci_enable_bus(struct cnss_pci_data *pci_priv)
  4901. {
  4902. int ret = 0;
  4903. struct pci_dev *pci_dev = pci_priv->pci_dev;
  4904. u16 device_id;
  4905. pci_read_config_word(pci_dev, PCI_DEVICE_ID, &device_id);
  4906. if (device_id != pci_priv->pci_device_id->device) {
  4907. cnss_pr_err("PCI device ID mismatch, config ID: 0x%x, probe ID: 0x%x\n",
  4908. device_id, pci_priv->pci_device_id->device);
  4909. ret = -EIO;
  4910. goto out;
  4911. }
  4912. ret = pci_assign_resource(pci_dev, PCI_BAR_NUM);
  4913. if (ret) {
  4914. pr_err("Failed to assign PCI resource, err = %d\n", ret);
  4915. goto out;
  4916. }
  4917. ret = pci_enable_device(pci_dev);
  4918. if (ret) {
  4919. cnss_pr_err("Failed to enable PCI device, err = %d\n", ret);
  4920. goto out;
  4921. }
  4922. ret = pci_request_region(pci_dev, PCI_BAR_NUM, "cnss");
  4923. if (ret) {
  4924. cnss_pr_err("Failed to request PCI region, err = %d\n", ret);
  4925. goto disable_device;
  4926. }
  4927. switch (device_id) {
  4928. case QCA6174_DEVICE_ID:
  4929. case QCN7605_DEVICE_ID:
  4930. pci_priv->dma_bit_mask = PCI_DMA_MASK_32_BIT;
  4931. break;
  4932. case QCA6390_DEVICE_ID:
  4933. case QCA6490_DEVICE_ID:
  4934. case KIWI_DEVICE_ID:
  4935. case MANGO_DEVICE_ID:
  4936. case PEACH_DEVICE_ID:
  4937. pci_priv->dma_bit_mask = PCI_DMA_MASK_36_BIT;
  4938. break;
  4939. default:
  4940. pci_priv->dma_bit_mask = PCI_DMA_MASK_32_BIT;
  4941. break;
  4942. }
  4943. cnss_pr_dbg("Set PCI DMA MASK (0x%llx)\n", pci_priv->dma_bit_mask);
  4944. ret = cnss_pci_set_dma_mask(pci_dev, pci_priv->dma_bit_mask);
  4945. if (ret) {
  4946. cnss_pr_err("Failed to set PCI DMA mask, err = %d\n", ret);
  4947. goto release_region;
  4948. }
  4949. ret = cnss_pci_set_coherent_dma_mask(pci_dev, pci_priv->dma_bit_mask);
  4950. if (ret) {
  4951. cnss_pr_err("Failed to set PCI coherent DMA mask, err = %d\n",
  4952. ret);
  4953. goto release_region;
  4954. }
  4955. pci_priv->bar = pci_iomap(pci_dev, PCI_BAR_NUM, 0);
  4956. if (!pci_priv->bar) {
  4957. cnss_pr_err("Failed to do PCI IO map!\n");
  4958. ret = -EIO;
  4959. goto release_region;
  4960. }
  4961. /* Save default config space without BME enabled */
  4962. pci_save_state(pci_dev);
  4963. pci_priv->default_state = pci_store_saved_state(pci_dev);
  4964. pci_set_master(pci_dev);
  4965. return 0;
  4966. release_region:
  4967. pci_release_region(pci_dev, PCI_BAR_NUM);
  4968. disable_device:
  4969. pci_disable_device(pci_dev);
  4970. out:
  4971. return ret;
  4972. }
  4973. static void cnss_pci_disable_bus(struct cnss_pci_data *pci_priv)
  4974. {
  4975. struct pci_dev *pci_dev = pci_priv->pci_dev;
  4976. pci_clear_master(pci_dev);
  4977. pci_load_and_free_saved_state(pci_dev, &pci_priv->saved_state);
  4978. pci_load_and_free_saved_state(pci_dev, &pci_priv->default_state);
  4979. if (pci_priv->bar) {
  4980. pci_iounmap(pci_dev, pci_priv->bar);
  4981. pci_priv->bar = NULL;
  4982. }
  4983. pci_release_region(pci_dev, PCI_BAR_NUM);
  4984. if (pci_is_enabled(pci_dev))
  4985. pci_disable_device(pci_dev);
  4986. }
  4987. static void cnss_pci_dump_qdss_reg(struct cnss_pci_data *pci_priv)
  4988. {
  4989. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  4990. int i, array_size = ARRAY_SIZE(qdss_csr) - 1;
  4991. gfp_t gfp = GFP_KERNEL;
  4992. u32 reg_offset;
  4993. if (in_interrupt() || irqs_disabled())
  4994. gfp = GFP_ATOMIC;
  4995. if (!plat_priv->qdss_reg) {
  4996. plat_priv->qdss_reg = devm_kzalloc(&pci_priv->pci_dev->dev,
  4997. sizeof(*plat_priv->qdss_reg)
  4998. * array_size, gfp);
  4999. if (!plat_priv->qdss_reg)
  5000. return;
  5001. }
  5002. cnss_pr_dbg("Start to dump qdss registers\n");
  5003. for (i = 0; qdss_csr[i].name; i++) {
  5004. reg_offset = QDSS_APB_DEC_CSR_BASE + qdss_csr[i].offset;
  5005. if (cnss_pci_reg_read(pci_priv, reg_offset,
  5006. &plat_priv->qdss_reg[i]))
  5007. return;
  5008. cnss_pr_dbg("%s[0x%x] = 0x%x\n", qdss_csr[i].name, reg_offset,
  5009. plat_priv->qdss_reg[i]);
  5010. }
  5011. }
  5012. static void cnss_pci_dump_ce_reg(struct cnss_pci_data *pci_priv,
  5013. enum cnss_ce_index ce)
  5014. {
  5015. int i;
  5016. u32 ce_base = ce * CE_REG_INTERVAL;
  5017. u32 reg_offset, src_ring_base, dst_ring_base, cmn_base, val;
  5018. switch (pci_priv->device_id) {
  5019. case QCA6390_DEVICE_ID:
  5020. src_ring_base = QCA6390_CE_SRC_RING_REG_BASE;
  5021. dst_ring_base = QCA6390_CE_DST_RING_REG_BASE;
  5022. cmn_base = QCA6390_CE_COMMON_REG_BASE;
  5023. break;
  5024. case QCA6490_DEVICE_ID:
  5025. src_ring_base = QCA6490_CE_SRC_RING_REG_BASE;
  5026. dst_ring_base = QCA6490_CE_DST_RING_REG_BASE;
  5027. cmn_base = QCA6490_CE_COMMON_REG_BASE;
  5028. break;
  5029. default:
  5030. return;
  5031. }
  5032. switch (ce) {
  5033. case CNSS_CE_09:
  5034. case CNSS_CE_10:
  5035. for (i = 0; ce_src[i].name; i++) {
  5036. reg_offset = src_ring_base + ce_base + ce_src[i].offset;
  5037. if (cnss_pci_reg_read(pci_priv, reg_offset, &val))
  5038. return;
  5039. cnss_pr_dbg("CE_%02d_%s[0x%x] = 0x%x\n",
  5040. ce, ce_src[i].name, reg_offset, val);
  5041. }
  5042. for (i = 0; ce_dst[i].name; i++) {
  5043. reg_offset = dst_ring_base + ce_base + ce_dst[i].offset;
  5044. if (cnss_pci_reg_read(pci_priv, reg_offset, &val))
  5045. return;
  5046. cnss_pr_dbg("CE_%02d_%s[0x%x] = 0x%x\n",
  5047. ce, ce_dst[i].name, reg_offset, val);
  5048. }
  5049. break;
  5050. case CNSS_CE_COMMON:
  5051. for (i = 0; ce_cmn[i].name; i++) {
  5052. reg_offset = cmn_base + ce_cmn[i].offset;
  5053. if (cnss_pci_reg_read(pci_priv, reg_offset, &val))
  5054. return;
  5055. cnss_pr_dbg("CE_COMMON_%s[0x%x] = 0x%x\n",
  5056. ce_cmn[i].name, reg_offset, val);
  5057. }
  5058. break;
  5059. default:
  5060. cnss_pr_err("Unsupported CE[%d] registers dump\n", ce);
  5061. }
  5062. }
  5063. static void cnss_pci_dump_debug_reg(struct cnss_pci_data *pci_priv)
  5064. {
  5065. if (cnss_pci_check_link_status(pci_priv))
  5066. return;
  5067. cnss_pr_dbg("Start to dump debug registers\n");
  5068. cnss_mhi_debug_reg_dump(pci_priv);
  5069. cnss_pci_bhi_debug_reg_dump(pci_priv);
  5070. cnss_pci_soc_scratch_reg_dump(pci_priv);
  5071. cnss_pci_dump_ce_reg(pci_priv, CNSS_CE_COMMON);
  5072. cnss_pci_dump_ce_reg(pci_priv, CNSS_CE_09);
  5073. cnss_pci_dump_ce_reg(pci_priv, CNSS_CE_10);
  5074. }
  5075. static int cnss_pci_assert_host_sol(struct cnss_pci_data *pci_priv)
  5076. {
  5077. int ret;
  5078. ret = cnss_get_host_sol_value(pci_priv->plat_priv);
  5079. if (ret) {
  5080. if (ret < 0) {
  5081. cnss_pr_dbg("Host SOL functionality is not enabled\n");
  5082. return ret;
  5083. } else {
  5084. cnss_pr_dbg("Host SOL is already high\n");
  5085. /*
  5086. * Return success if HOST SOL is already high.
  5087. * This will indicate caller that a HOST SOL is
  5088. * already asserted from some other thread and
  5089. * no further action required from the caller.
  5090. */
  5091. return 0;
  5092. }
  5093. }
  5094. cnss_pr_dbg("Assert host SOL GPIO to retry RDDM, expecting link down\n");
  5095. cnss_set_host_sol_value(pci_priv->plat_priv, 1);
  5096. return 0;
  5097. }
  5098. static void cnss_pci_mhi_reg_dump(struct cnss_pci_data *pci_priv)
  5099. {
  5100. if (!cnss_pci_check_link_status(pci_priv))
  5101. cnss_mhi_debug_reg_dump(pci_priv);
  5102. cnss_pci_bhi_debug_reg_dump(pci_priv);
  5103. cnss_pci_soc_scratch_reg_dump(pci_priv);
  5104. cnss_pci_dump_misc_reg(pci_priv);
  5105. cnss_pci_dump_shadow_reg(pci_priv);
  5106. }
  5107. int cnss_pci_recover_link_down(struct cnss_pci_data *pci_priv)
  5108. {
  5109. int ret;
  5110. int retry = 0;
  5111. enum mhi_ee_type mhi_ee;
  5112. switch (pci_priv->device_id) {
  5113. case QCA6390_DEVICE_ID:
  5114. case QCA6490_DEVICE_ID:
  5115. case KIWI_DEVICE_ID:
  5116. case MANGO_DEVICE_ID:
  5117. case PEACH_DEVICE_ID:
  5118. break;
  5119. default:
  5120. return -EOPNOTSUPP;
  5121. }
  5122. /* Always wait here to avoid missing WAKE assert for RDDM
  5123. * before link recovery
  5124. */
  5125. ret = wait_for_completion_timeout(&pci_priv->wake_event_complete,
  5126. msecs_to_jiffies(WAKE_EVENT_TIMEOUT));
  5127. if (!ret)
  5128. cnss_pr_err("Timeout waiting for wake event after link down\n");
  5129. ret = cnss_suspend_pci_link(pci_priv);
  5130. if (ret)
  5131. cnss_pr_err("Failed to suspend PCI link, err = %d\n", ret);
  5132. ret = cnss_resume_pci_link(pci_priv);
  5133. if (ret) {
  5134. cnss_pr_err("Failed to resume PCI link, err = %d\n", ret);
  5135. del_timer(&pci_priv->dev_rddm_timer);
  5136. return ret;
  5137. }
  5138. retry:
  5139. /*
  5140. * After PCIe link resumes, 20 to 400 ms delay is observerved
  5141. * before device moves to RDDM.
  5142. */
  5143. msleep(RDDM_LINK_RECOVERY_RETRY_DELAY_MS);
  5144. mhi_ee = mhi_get_exec_env(pci_priv->mhi_ctrl);
  5145. if (mhi_ee == MHI_EE_RDDM) {
  5146. del_timer(&pci_priv->dev_rddm_timer);
  5147. cnss_pr_info("Device in RDDM after link recovery, try to collect dump\n");
  5148. cnss_schedule_recovery(&pci_priv->pci_dev->dev,
  5149. CNSS_REASON_RDDM);
  5150. return 0;
  5151. } else if (retry++ < RDDM_LINK_RECOVERY_RETRY) {
  5152. cnss_pr_dbg("Wait for RDDM after link recovery, retry #%d, Device EE: %d\n",
  5153. retry, mhi_ee);
  5154. goto retry;
  5155. }
  5156. if (!cnss_pci_assert_host_sol(pci_priv))
  5157. return 0;
  5158. cnss_mhi_debug_reg_dump(pci_priv);
  5159. cnss_pci_bhi_debug_reg_dump(pci_priv);
  5160. cnss_pci_soc_scratch_reg_dump(pci_priv);
  5161. cnss_schedule_recovery(&pci_priv->pci_dev->dev,
  5162. CNSS_REASON_TIMEOUT);
  5163. return 0;
  5164. }
  5165. int cnss_pci_force_fw_assert_hdlr(struct cnss_pci_data *pci_priv)
  5166. {
  5167. int ret;
  5168. struct cnss_plat_data *plat_priv;
  5169. if (!pci_priv)
  5170. return -ENODEV;
  5171. plat_priv = pci_priv->plat_priv;
  5172. if (!plat_priv)
  5173. return -ENODEV;
  5174. if (!test_bit(CNSS_MHI_POWER_ON, &pci_priv->mhi_state) ||
  5175. test_bit(CNSS_MHI_POWERING_OFF, &pci_priv->mhi_state))
  5176. return -EINVAL;
  5177. /*
  5178. * Call pm_runtime_get_sync insteat of auto_resume to get
  5179. * reference and make sure runtime_suspend wont get called.
  5180. */
  5181. ret = cnss_pci_pm_runtime_get_sync(pci_priv, RTPM_ID_CNSS);
  5182. if (ret < 0)
  5183. goto runtime_pm_put;
  5184. /*
  5185. * In some scenarios, cnss_pci_pm_runtime_get_sync
  5186. * might not resume PCI bus. For those cases do auto resume.
  5187. */
  5188. cnss_auto_resume(&pci_priv->pci_dev->dev);
  5189. if (!pci_priv->is_smmu_fault)
  5190. cnss_pci_mhi_reg_dump(pci_priv);
  5191. /* If link is still down here, directly trigger link down recovery */
  5192. ret = cnss_pci_check_link_status(pci_priv);
  5193. if (ret) {
  5194. cnss_pci_link_down(&pci_priv->pci_dev->dev);
  5195. cnss_pci_pm_runtime_mark_last_busy(pci_priv);
  5196. cnss_pci_pm_runtime_put_autosuspend(pci_priv, RTPM_ID_CNSS);
  5197. return 0;
  5198. }
  5199. /*
  5200. * Fist try MHI SYS_ERR, if fails try HOST SOL and return.
  5201. * If SOL is not enabled try HOST Reset Rquest after MHI
  5202. * SYS_ERRR fails.
  5203. */
  5204. ret = cnss_pci_set_mhi_state(pci_priv, CNSS_MHI_TRIGGER_RDDM);
  5205. if (ret) {
  5206. if (pci_priv->is_smmu_fault) {
  5207. cnss_pci_mhi_reg_dump(pci_priv);
  5208. pci_priv->is_smmu_fault = false;
  5209. }
  5210. if (!test_bit(CNSS_MHI_POWER_ON, &pci_priv->mhi_state) ||
  5211. test_bit(CNSS_MHI_POWERING_OFF, &pci_priv->mhi_state)) {
  5212. cnss_pr_dbg("MHI is not powered on, ignore RDDM failure\n");
  5213. cnss_pci_pm_runtime_mark_last_busy(pci_priv);
  5214. cnss_pci_pm_runtime_put_autosuspend(pci_priv, RTPM_ID_CNSS);
  5215. return 0;
  5216. }
  5217. cnss_fatal_err("Failed to trigger RDDM, err = %d\n", ret);
  5218. if (!cnss_pci_assert_host_sol(pci_priv)) {
  5219. cnss_pci_pm_runtime_mark_last_busy(pci_priv);
  5220. cnss_pci_pm_runtime_put_autosuspend(pci_priv, RTPM_ID_CNSS);
  5221. return 0;
  5222. }
  5223. cnss_pr_dbg("Sending Host Reset Req\n");
  5224. if (!cnss_mhi_force_reset(pci_priv)) {
  5225. ret = 0;
  5226. goto mhi_reg_dump;
  5227. }
  5228. cnss_pci_dump_debug_reg(pci_priv);
  5229. cnss_schedule_recovery(&pci_priv->pci_dev->dev,
  5230. CNSS_REASON_DEFAULT);
  5231. ret = 0;
  5232. goto runtime_pm_put;
  5233. }
  5234. mhi_reg_dump:
  5235. if (pci_priv->is_smmu_fault) {
  5236. cnss_pci_mhi_reg_dump(pci_priv);
  5237. pci_priv->is_smmu_fault = false;
  5238. }
  5239. if (!test_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state)) {
  5240. mod_timer(&pci_priv->dev_rddm_timer,
  5241. jiffies + msecs_to_jiffies(DEV_RDDM_TIMEOUT));
  5242. }
  5243. runtime_pm_put:
  5244. cnss_pci_pm_runtime_mark_last_busy(pci_priv);
  5245. cnss_pci_pm_runtime_put_autosuspend(pci_priv, RTPM_ID_CNSS);
  5246. return ret;
  5247. }
  5248. static void cnss_pci_add_dump_seg(struct cnss_pci_data *pci_priv,
  5249. struct cnss_dump_seg *dump_seg,
  5250. enum cnss_fw_dump_type type, int seg_no,
  5251. void *va, dma_addr_t dma, size_t size)
  5252. {
  5253. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  5254. struct device *dev = &pci_priv->pci_dev->dev;
  5255. phys_addr_t pa;
  5256. dump_seg->address = dma;
  5257. dump_seg->v_address = va;
  5258. dump_seg->size = size;
  5259. dump_seg->type = type;
  5260. cnss_pr_dbg("Seg: %x, va: %pK, dma: %pa, size: 0x%zx\n",
  5261. seg_no, va, &dma, size);
  5262. if (type == CNSS_FW_CAL || cnss_va_to_pa(dev, size, va, dma, &pa, DMA_ATTR_FORCE_CONTIGUOUS))
  5263. return;
  5264. cnss_minidump_add_region(plat_priv, type, seg_no, va, pa, size);
  5265. }
  5266. static void cnss_pci_remove_dump_seg(struct cnss_pci_data *pci_priv,
  5267. struct cnss_dump_seg *dump_seg,
  5268. enum cnss_fw_dump_type type, int seg_no,
  5269. void *va, dma_addr_t dma, size_t size)
  5270. {
  5271. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  5272. struct device *dev = &pci_priv->pci_dev->dev;
  5273. phys_addr_t pa;
  5274. cnss_va_to_pa(dev, size, va, dma, &pa, DMA_ATTR_FORCE_CONTIGUOUS);
  5275. cnss_minidump_remove_region(plat_priv, type, seg_no, va, pa, size);
  5276. }
  5277. int cnss_pci_call_driver_uevent(struct cnss_pci_data *pci_priv,
  5278. enum cnss_driver_status status, void *data)
  5279. {
  5280. struct cnss_uevent_data uevent_data;
  5281. struct cnss_wlan_driver *driver_ops;
  5282. driver_ops = pci_priv->driver_ops;
  5283. if (!driver_ops || !driver_ops->update_event) {
  5284. cnss_pr_dbg("Hang event driver ops is NULL\n");
  5285. return -EINVAL;
  5286. }
  5287. cnss_pr_dbg("Calling driver uevent: %d\n", status);
  5288. uevent_data.status = status;
  5289. uevent_data.data = data;
  5290. return driver_ops->update_event(pci_priv->pci_dev, &uevent_data);
  5291. }
  5292. static void cnss_pci_send_hang_event(struct cnss_pci_data *pci_priv)
  5293. {
  5294. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  5295. struct cnss_fw_mem *fw_mem = plat_priv->fw_mem;
  5296. struct cnss_hang_event hang_event;
  5297. void *hang_data_va = NULL;
  5298. u64 offset = 0;
  5299. u16 length = 0;
  5300. int i = 0;
  5301. if (!fw_mem || !plat_priv->fw_mem_seg_len)
  5302. return;
  5303. memset(&hang_event, 0, sizeof(hang_event));
  5304. switch (pci_priv->device_id) {
  5305. case QCA6390_DEVICE_ID:
  5306. offset = HST_HANG_DATA_OFFSET;
  5307. length = HANG_DATA_LENGTH;
  5308. break;
  5309. case QCA6490_DEVICE_ID:
  5310. /* Fallback to hard-coded values if hang event params not
  5311. * present in QMI. Once all the firmware branches have the
  5312. * fix to send params over QMI, this can be removed.
  5313. */
  5314. if (plat_priv->hang_event_data_len) {
  5315. offset = plat_priv->hang_data_addr_offset;
  5316. length = plat_priv->hang_event_data_len;
  5317. } else {
  5318. offset = HSP_HANG_DATA_OFFSET;
  5319. length = HANG_DATA_LENGTH;
  5320. }
  5321. break;
  5322. case KIWI_DEVICE_ID:
  5323. case MANGO_DEVICE_ID:
  5324. case PEACH_DEVICE_ID:
  5325. offset = plat_priv->hang_data_addr_offset;
  5326. length = plat_priv->hang_event_data_len;
  5327. break;
  5328. case QCN7605_DEVICE_ID:
  5329. offset = GNO_HANG_DATA_OFFSET;
  5330. length = HANG_DATA_LENGTH;
  5331. break;
  5332. default:
  5333. cnss_pr_err("Skip Hang Event Data as unsupported Device ID received: %d\n",
  5334. pci_priv->device_id);
  5335. return;
  5336. }
  5337. for (i = 0; i < plat_priv->fw_mem_seg_len; i++) {
  5338. if (fw_mem[i].type == QMI_WLFW_MEM_TYPE_DDR_V01 &&
  5339. fw_mem[i].va) {
  5340. /* The offset must be < (fw_mem size- hangdata length) */
  5341. if (!(offset <= fw_mem[i].size - length))
  5342. goto exit;
  5343. hang_data_va = fw_mem[i].va + offset;
  5344. hang_event.hang_event_data = kmemdup(hang_data_va,
  5345. length,
  5346. GFP_ATOMIC);
  5347. if (!hang_event.hang_event_data) {
  5348. cnss_pr_dbg("Hang data memory alloc failed\n");
  5349. return;
  5350. }
  5351. hang_event.hang_event_data_len = length;
  5352. break;
  5353. }
  5354. }
  5355. cnss_pci_call_driver_uevent(pci_priv, CNSS_HANG_EVENT, &hang_event);
  5356. kfree(hang_event.hang_event_data);
  5357. hang_event.hang_event_data = NULL;
  5358. return;
  5359. exit:
  5360. cnss_pr_dbg("Invalid hang event params, offset:0x%x, length:0x%x\n",
  5361. plat_priv->hang_data_addr_offset,
  5362. plat_priv->hang_event_data_len);
  5363. }
  5364. #ifdef CONFIG_CNSS2_SSR_DRIVER_DUMP
  5365. void cnss_pci_collect_host_dump_info(struct cnss_pci_data *pci_priv)
  5366. {
  5367. struct cnss_ssr_driver_dump_entry *ssr_entry;
  5368. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  5369. size_t num_entries_loaded = 0;
  5370. int x;
  5371. int ret = -1;
  5372. ssr_entry = kmalloc(sizeof(*ssr_entry) * CNSS_HOST_DUMP_TYPE_MAX, GFP_KERNEL);
  5373. if (!ssr_entry) {
  5374. cnss_pr_err("ssr_entry malloc failed");
  5375. return;
  5376. }
  5377. if (pci_priv->driver_ops &&
  5378. pci_priv->driver_ops->collect_driver_dump) {
  5379. ret = pci_priv->driver_ops->collect_driver_dump(pci_priv->pci_dev,
  5380. ssr_entry,
  5381. &num_entries_loaded);
  5382. }
  5383. if (!ret) {
  5384. for (x = 0; x < num_entries_loaded; x++) {
  5385. cnss_pr_info("Idx:%d, ptr: %p, name: %s, size: %d\n",
  5386. x, ssr_entry[x].buffer_pointer,
  5387. ssr_entry[x].region_name,
  5388. ssr_entry[x].buffer_size);
  5389. }
  5390. cnss_do_host_ramdump(plat_priv, ssr_entry, num_entries_loaded);
  5391. } else {
  5392. cnss_pr_info("Host SSR elf dump collection feature disabled\n");
  5393. }
  5394. kfree(ssr_entry);
  5395. }
  5396. #endif
  5397. void cnss_pci_collect_dump_info(struct cnss_pci_data *pci_priv, bool in_panic)
  5398. {
  5399. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  5400. struct cnss_dump_data *dump_data =
  5401. &plat_priv->ramdump_info_v2.dump_data;
  5402. struct cnss_dump_seg *dump_seg =
  5403. plat_priv->ramdump_info_v2.dump_data_vaddr;
  5404. struct image_info *fw_image, *rddm_image;
  5405. struct cnss_fw_mem *fw_mem = plat_priv->fw_mem;
  5406. int ret, i, j;
  5407. if (test_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state) &&
  5408. !test_bit(CNSS_IN_PANIC, &plat_priv->driver_state))
  5409. cnss_pci_send_hang_event(pci_priv);
  5410. if (test_bit(CNSS_MHI_RDDM_DONE, &pci_priv->mhi_state)) {
  5411. cnss_pr_dbg("RAM dump is already collected, skip\n");
  5412. return;
  5413. }
  5414. if (!cnss_is_device_powered_on(plat_priv)) {
  5415. cnss_pr_dbg("Device is already powered off, skip\n");
  5416. return;
  5417. }
  5418. if (!in_panic) {
  5419. mutex_lock(&pci_priv->bus_lock);
  5420. ret = cnss_pci_check_link_status(pci_priv);
  5421. if (ret) {
  5422. if (ret != -EACCES) {
  5423. mutex_unlock(&pci_priv->bus_lock);
  5424. return;
  5425. }
  5426. if (cnss_pci_resume_bus(pci_priv)) {
  5427. mutex_unlock(&pci_priv->bus_lock);
  5428. return;
  5429. }
  5430. }
  5431. mutex_unlock(&pci_priv->bus_lock);
  5432. } else {
  5433. if (cnss_pci_check_link_status(pci_priv))
  5434. return;
  5435. /* Inside panic handler, reduce timeout for RDDM to avoid
  5436. * unnecessary hypervisor watchdog bite.
  5437. */
  5438. pci_priv->mhi_ctrl->timeout_ms /= 2;
  5439. }
  5440. cnss_mhi_debug_reg_dump(pci_priv);
  5441. cnss_pci_bhi_debug_reg_dump(pci_priv);
  5442. cnss_pci_soc_scratch_reg_dump(pci_priv);
  5443. cnss_pci_dump_misc_reg(pci_priv);
  5444. cnss_rddm_trigger_debug(pci_priv);
  5445. ret = mhi_download_rddm_image(pci_priv->mhi_ctrl, in_panic);
  5446. if (ret) {
  5447. cnss_fatal_err("Failed to download RDDM image, err = %d\n",
  5448. ret);
  5449. if (!cnss_pci_assert_host_sol(pci_priv))
  5450. return;
  5451. cnss_rddm_trigger_check(pci_priv);
  5452. cnss_pci_dump_debug_reg(pci_priv);
  5453. return;
  5454. }
  5455. cnss_rddm_trigger_check(pci_priv);
  5456. fw_image = pci_priv->mhi_ctrl->fbc_image;
  5457. rddm_image = pci_priv->mhi_ctrl->rddm_image;
  5458. dump_data->nentries = 0;
  5459. if (plat_priv->qdss_mem_seg_len)
  5460. cnss_pci_dump_qdss_reg(pci_priv);
  5461. cnss_mhi_dump_sfr(pci_priv);
  5462. if (!dump_seg) {
  5463. cnss_pr_warn("FW image dump collection not setup");
  5464. goto skip_dump;
  5465. }
  5466. cnss_pr_dbg("Collect FW image dump segment, nentries %d\n",
  5467. fw_image->entries);
  5468. for (i = 0; i < fw_image->entries; i++) {
  5469. cnss_pci_add_dump_seg(pci_priv, dump_seg, CNSS_FW_IMAGE, i,
  5470. fw_image->mhi_buf[i].buf,
  5471. fw_image->mhi_buf[i].dma_addr,
  5472. fw_image->mhi_buf[i].len);
  5473. dump_seg++;
  5474. }
  5475. dump_data->nentries += fw_image->entries;
  5476. cnss_pr_dbg("Collect RDDM image dump segment, nentries %d\n",
  5477. rddm_image->entries);
  5478. for (i = 0; i < rddm_image->entries; i++) {
  5479. cnss_pci_add_dump_seg(pci_priv, dump_seg, CNSS_FW_RDDM, i,
  5480. rddm_image->mhi_buf[i].buf,
  5481. rddm_image->mhi_buf[i].dma_addr,
  5482. rddm_image->mhi_buf[i].len);
  5483. dump_seg++;
  5484. }
  5485. dump_data->nentries += rddm_image->entries;
  5486. for (i = 0, j = 0; i < plat_priv->fw_mem_seg_len; i++) {
  5487. if (fw_mem[i].type == CNSS_MEM_TYPE_DDR) {
  5488. if (fw_mem[i].attrs & DMA_ATTR_FORCE_CONTIGUOUS) {
  5489. cnss_pr_dbg("Collect remote heap dump segment\n");
  5490. cnss_pci_add_dump_seg(pci_priv, dump_seg,
  5491. CNSS_FW_REMOTE_HEAP, j,
  5492. fw_mem[i].va,
  5493. fw_mem[i].pa,
  5494. fw_mem[i].size);
  5495. dump_seg++;
  5496. dump_data->nentries++;
  5497. j++;
  5498. } else {
  5499. cnss_pr_dbg("Skip remote heap dumps as it is non-contiguous\n");
  5500. }
  5501. } else if (fw_mem[i].type == CNSS_MEM_CAL_V01) {
  5502. cnss_pr_dbg("Collect CAL memory dump segment\n");
  5503. cnss_pci_add_dump_seg(pci_priv, dump_seg,
  5504. CNSS_FW_CAL, j,
  5505. fw_mem[i].va,
  5506. fw_mem[i].pa,
  5507. fw_mem[i].size);
  5508. dump_seg++;
  5509. dump_data->nentries++;
  5510. j++;
  5511. }
  5512. }
  5513. if (dump_data->nentries > 0)
  5514. plat_priv->ramdump_info_v2.dump_data_valid = true;
  5515. cnss_pci_set_mhi_state(pci_priv, CNSS_MHI_RDDM_DONE);
  5516. skip_dump:
  5517. complete(&plat_priv->rddm_complete);
  5518. }
  5519. void cnss_pci_clear_dump_info(struct cnss_pci_data *pci_priv)
  5520. {
  5521. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  5522. struct cnss_dump_seg *dump_seg =
  5523. plat_priv->ramdump_info_v2.dump_data_vaddr;
  5524. struct image_info *fw_image, *rddm_image;
  5525. struct cnss_fw_mem *fw_mem = plat_priv->fw_mem;
  5526. int i, j;
  5527. if (!dump_seg)
  5528. return;
  5529. fw_image = pci_priv->mhi_ctrl->fbc_image;
  5530. rddm_image = pci_priv->mhi_ctrl->rddm_image;
  5531. for (i = 0; i < fw_image->entries; i++) {
  5532. cnss_pci_remove_dump_seg(pci_priv, dump_seg, CNSS_FW_IMAGE, i,
  5533. fw_image->mhi_buf[i].buf,
  5534. fw_image->mhi_buf[i].dma_addr,
  5535. fw_image->mhi_buf[i].len);
  5536. dump_seg++;
  5537. }
  5538. for (i = 0; i < rddm_image->entries; i++) {
  5539. cnss_pci_remove_dump_seg(pci_priv, dump_seg, CNSS_FW_RDDM, i,
  5540. rddm_image->mhi_buf[i].buf,
  5541. rddm_image->mhi_buf[i].dma_addr,
  5542. rddm_image->mhi_buf[i].len);
  5543. dump_seg++;
  5544. }
  5545. for (i = 0, j = 0; i < plat_priv->fw_mem_seg_len; i++) {
  5546. if (fw_mem[i].type == CNSS_MEM_TYPE_DDR &&
  5547. (fw_mem[i].attrs & DMA_ATTR_FORCE_CONTIGUOUS)) {
  5548. cnss_pci_remove_dump_seg(pci_priv, dump_seg,
  5549. CNSS_FW_REMOTE_HEAP, j,
  5550. fw_mem[i].va, fw_mem[i].pa,
  5551. fw_mem[i].size);
  5552. dump_seg++;
  5553. j++;
  5554. } else if (fw_mem[i].type == CNSS_MEM_CAL_V01) {
  5555. cnss_pci_remove_dump_seg(pci_priv, dump_seg,
  5556. CNSS_FW_CAL, j,
  5557. fw_mem[i].va, fw_mem[i].pa,
  5558. fw_mem[i].size);
  5559. dump_seg++;
  5560. j++;
  5561. }
  5562. }
  5563. plat_priv->ramdump_info_v2.dump_data.nentries = 0;
  5564. plat_priv->ramdump_info_v2.dump_data_valid = false;
  5565. }
  5566. void cnss_pci_device_crashed(struct cnss_pci_data *pci_priv)
  5567. {
  5568. struct cnss_plat_data *plat_priv;
  5569. if (!pci_priv) {
  5570. cnss_pr_err("pci_priv is NULL\n");
  5571. return;
  5572. }
  5573. plat_priv = pci_priv->plat_priv;
  5574. if (!plat_priv) {
  5575. cnss_pr_err("plat_priv is NULL\n");
  5576. return;
  5577. }
  5578. if (plat_priv->recovery_enabled)
  5579. cnss_pci_collect_host_dump_info(pci_priv);
  5580. /* Call recovery handler in the DRIVER_RECOVERY event context
  5581. * instead of scheduling work. In that way complete recovery
  5582. * will be done as part of DRIVER_RECOVERY event and get
  5583. * serialized with other events.
  5584. */
  5585. cnss_recovery_handler(plat_priv);
  5586. }
  5587. static int cnss_mhi_pm_runtime_get(struct mhi_controller *mhi_ctrl)
  5588. {
  5589. struct cnss_pci_data *pci_priv = dev_get_drvdata(mhi_ctrl->cntrl_dev);
  5590. return cnss_pci_pm_runtime_get(pci_priv, RTPM_ID_MHI);
  5591. }
  5592. static void cnss_mhi_pm_runtime_put_noidle(struct mhi_controller *mhi_ctrl)
  5593. {
  5594. struct cnss_pci_data *pci_priv = dev_get_drvdata(mhi_ctrl->cntrl_dev);
  5595. cnss_pci_pm_runtime_put_noidle(pci_priv, RTPM_ID_MHI);
  5596. }
  5597. void cnss_pci_add_fw_prefix_name(struct cnss_pci_data *pci_priv,
  5598. char *prefix_name, char *name)
  5599. {
  5600. struct cnss_plat_data *plat_priv;
  5601. if (!pci_priv)
  5602. return;
  5603. plat_priv = pci_priv->plat_priv;
  5604. if (!plat_priv->use_fw_path_with_prefix) {
  5605. scnprintf(prefix_name, MAX_FIRMWARE_NAME_LEN, "%s", name);
  5606. return;
  5607. }
  5608. switch (pci_priv->device_id) {
  5609. case QCN7605_DEVICE_ID:
  5610. scnprintf(prefix_name, MAX_FIRMWARE_NAME_LEN,
  5611. QCN7605_PATH_PREFIX "%s", name);
  5612. break;
  5613. case QCA6390_DEVICE_ID:
  5614. scnprintf(prefix_name, MAX_FIRMWARE_NAME_LEN,
  5615. QCA6390_PATH_PREFIX "%s", name);
  5616. break;
  5617. case QCA6490_DEVICE_ID:
  5618. scnprintf(prefix_name, MAX_FIRMWARE_NAME_LEN,
  5619. QCA6490_PATH_PREFIX "%s", name);
  5620. break;
  5621. case KIWI_DEVICE_ID:
  5622. scnprintf(prefix_name, MAX_FIRMWARE_NAME_LEN,
  5623. KIWI_PATH_PREFIX "%s", name);
  5624. break;
  5625. case MANGO_DEVICE_ID:
  5626. scnprintf(prefix_name, MAX_FIRMWARE_NAME_LEN,
  5627. MANGO_PATH_PREFIX "%s", name);
  5628. break;
  5629. case PEACH_DEVICE_ID:
  5630. scnprintf(prefix_name, MAX_FIRMWARE_NAME_LEN,
  5631. PEACH_PATH_PREFIX "%s", name);
  5632. break;
  5633. default:
  5634. scnprintf(prefix_name, MAX_FIRMWARE_NAME_LEN, "%s", name);
  5635. break;
  5636. }
  5637. cnss_pr_dbg("FW name added with prefix: %s\n", prefix_name);
  5638. }
  5639. static int cnss_pci_update_fw_name(struct cnss_pci_data *pci_priv)
  5640. {
  5641. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  5642. switch (pci_priv->device_id) {
  5643. case QCA6390_DEVICE_ID:
  5644. if (plat_priv->device_version.major_version < FW_V2_NUMBER) {
  5645. cnss_pr_dbg("Device ID:version (0x%lx:%d) is not supported\n",
  5646. pci_priv->device_id,
  5647. plat_priv->device_version.major_version);
  5648. return -EINVAL;
  5649. }
  5650. cnss_pci_add_fw_prefix_name(pci_priv, plat_priv->firmware_name,
  5651. FW_V2_FILE_NAME);
  5652. snprintf(plat_priv->fw_fallback_name, MAX_FIRMWARE_NAME_LEN,
  5653. FW_V2_FILE_NAME);
  5654. break;
  5655. case QCA6490_DEVICE_ID:
  5656. case KIWI_DEVICE_ID:
  5657. case MANGO_DEVICE_ID:
  5658. case PEACH_DEVICE_ID:
  5659. switch (plat_priv->device_version.major_version) {
  5660. case FW_V2_NUMBER:
  5661. cnss_pci_add_fw_prefix_name(pci_priv,
  5662. plat_priv->firmware_name,
  5663. FW_V2_FILE_NAME);
  5664. snprintf(plat_priv->fw_fallback_name,
  5665. MAX_FIRMWARE_NAME_LEN,
  5666. FW_V2_FILE_NAME);
  5667. break;
  5668. default:
  5669. cnss_pci_add_fw_prefix_name(pci_priv,
  5670. plat_priv->firmware_name,
  5671. DEFAULT_FW_FILE_NAME);
  5672. snprintf(plat_priv->fw_fallback_name,
  5673. MAX_FIRMWARE_NAME_LEN,
  5674. DEFAULT_FW_FILE_NAME);
  5675. break;
  5676. }
  5677. break;
  5678. default:
  5679. cnss_pci_add_fw_prefix_name(pci_priv, plat_priv->firmware_name,
  5680. DEFAULT_FW_FILE_NAME);
  5681. snprintf(plat_priv->fw_fallback_name, MAX_FIRMWARE_NAME_LEN,
  5682. DEFAULT_FW_FILE_NAME);
  5683. break;
  5684. }
  5685. cnss_pr_dbg("FW name is %s, FW fallback name is %s\n",
  5686. plat_priv->firmware_name, plat_priv->fw_fallback_name);
  5687. return 0;
  5688. }
  5689. static char *cnss_mhi_notify_status_to_str(enum mhi_callback status)
  5690. {
  5691. switch (status) {
  5692. case MHI_CB_IDLE:
  5693. return "IDLE";
  5694. case MHI_CB_EE_RDDM:
  5695. return "RDDM";
  5696. case MHI_CB_SYS_ERROR:
  5697. return "SYS_ERROR";
  5698. case MHI_CB_FATAL_ERROR:
  5699. return "FATAL_ERROR";
  5700. case MHI_CB_EE_MISSION_MODE:
  5701. return "MISSION_MODE";
  5702. #if IS_ENABLED(CONFIG_MHI_BUS_MISC) && \
  5703. (LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0))
  5704. case MHI_CB_FALLBACK_IMG:
  5705. return "FW_FALLBACK";
  5706. #endif
  5707. default:
  5708. return "UNKNOWN";
  5709. }
  5710. };
  5711. static void cnss_dev_rddm_timeout_hdlr(struct timer_list *t)
  5712. {
  5713. struct cnss_pci_data *pci_priv =
  5714. from_timer(pci_priv, t, dev_rddm_timer);
  5715. enum mhi_ee_type mhi_ee;
  5716. if (!pci_priv)
  5717. return;
  5718. cnss_fatal_err("Timeout waiting for RDDM notification\n");
  5719. mhi_ee = mhi_get_exec_env(pci_priv->mhi_ctrl);
  5720. if (mhi_ee == MHI_EE_PBL)
  5721. cnss_pr_err("Device MHI EE is PBL, unable to collect dump\n");
  5722. if (mhi_ee == MHI_EE_RDDM) {
  5723. cnss_pr_info("Device MHI EE is RDDM, try to collect dump\n");
  5724. cnss_schedule_recovery(&pci_priv->pci_dev->dev,
  5725. CNSS_REASON_RDDM);
  5726. } else {
  5727. if (!cnss_pci_assert_host_sol(pci_priv))
  5728. return;
  5729. cnss_mhi_debug_reg_dump(pci_priv);
  5730. cnss_pci_bhi_debug_reg_dump(pci_priv);
  5731. cnss_pci_soc_scratch_reg_dump(pci_priv);
  5732. cnss_schedule_recovery(&pci_priv->pci_dev->dev,
  5733. CNSS_REASON_TIMEOUT);
  5734. }
  5735. }
  5736. static void cnss_boot_debug_timeout_hdlr(struct timer_list *t)
  5737. {
  5738. struct cnss_pci_data *pci_priv =
  5739. from_timer(pci_priv, t, boot_debug_timer);
  5740. if (!pci_priv)
  5741. return;
  5742. if (cnss_pci_check_link_status(pci_priv))
  5743. return;
  5744. if (cnss_pci_is_device_down(&pci_priv->pci_dev->dev))
  5745. return;
  5746. if (test_bit(CNSS_MHI_POWER_ON, &pci_priv->mhi_state))
  5747. return;
  5748. if (cnss_mhi_scan_rddm_cookie(pci_priv, DEVICE_RDDM_COOKIE))
  5749. return;
  5750. cnss_pr_dbg("Dump MHI/PBL/SBL debug data every %ds during MHI power on\n",
  5751. BOOT_DEBUG_TIMEOUT_MS / 1000);
  5752. cnss_mhi_debug_reg_dump(pci_priv);
  5753. cnss_pci_bhi_debug_reg_dump(pci_priv);
  5754. cnss_pci_soc_scratch_reg_dump(pci_priv);
  5755. cnss_pci_dump_bl_sram_mem(pci_priv);
  5756. mod_timer(&pci_priv->boot_debug_timer,
  5757. jiffies + msecs_to_jiffies(BOOT_DEBUG_TIMEOUT_MS));
  5758. }
  5759. static int cnss_pci_handle_mhi_sys_err(struct cnss_pci_data *pci_priv)
  5760. {
  5761. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  5762. cnss_ignore_qmi_failure(true);
  5763. set_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state);
  5764. del_timer(&plat_priv->fw_boot_timer);
  5765. reinit_completion(&pci_priv->wake_event_complete);
  5766. mod_timer(&pci_priv->dev_rddm_timer,
  5767. jiffies + msecs_to_jiffies(DEV_RDDM_TIMEOUT));
  5768. cnss_pci_update_status(pci_priv, CNSS_FW_DOWN);
  5769. return 0;
  5770. }
  5771. int cnss_pci_handle_dev_sol_irq(struct cnss_pci_data *pci_priv)
  5772. {
  5773. return cnss_pci_handle_mhi_sys_err(pci_priv);
  5774. }
  5775. static void cnss_mhi_notify_status(struct mhi_controller *mhi_ctrl,
  5776. enum mhi_callback reason)
  5777. {
  5778. struct cnss_pci_data *pci_priv = dev_get_drvdata(mhi_ctrl->cntrl_dev);
  5779. struct cnss_plat_data *plat_priv;
  5780. enum cnss_recovery_reason cnss_reason;
  5781. if (!pci_priv) {
  5782. cnss_pr_err("pci_priv is NULL");
  5783. return;
  5784. }
  5785. plat_priv = pci_priv->plat_priv;
  5786. if (reason != MHI_CB_IDLE)
  5787. cnss_pr_dbg("MHI status cb is called with reason %s(%d)\n",
  5788. cnss_mhi_notify_status_to_str(reason), reason);
  5789. switch (reason) {
  5790. case MHI_CB_IDLE:
  5791. case MHI_CB_EE_MISSION_MODE:
  5792. return;
  5793. case MHI_CB_FATAL_ERROR:
  5794. cnss_ignore_qmi_failure(true);
  5795. set_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state);
  5796. del_timer(&plat_priv->fw_boot_timer);
  5797. cnss_pci_update_status(pci_priv, CNSS_FW_DOWN);
  5798. cnss_reason = CNSS_REASON_DEFAULT;
  5799. break;
  5800. case MHI_CB_SYS_ERROR:
  5801. cnss_pci_handle_mhi_sys_err(pci_priv);
  5802. return;
  5803. case MHI_CB_EE_RDDM:
  5804. cnss_ignore_qmi_failure(true);
  5805. set_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state);
  5806. del_timer(&plat_priv->fw_boot_timer);
  5807. del_timer(&pci_priv->dev_rddm_timer);
  5808. cnss_pci_update_status(pci_priv, CNSS_FW_DOWN);
  5809. cnss_reason = CNSS_REASON_RDDM;
  5810. break;
  5811. #if IS_ENABLED(CONFIG_MHI_BUS_MISC) && \
  5812. (LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0))
  5813. case MHI_CB_FALLBACK_IMG:
  5814. plat_priv->use_fw_path_with_prefix = false;
  5815. cnss_pci_update_fw_name(pci_priv);
  5816. return;
  5817. #endif
  5818. default:
  5819. cnss_pr_err("Unsupported MHI status cb reason: %d\n", reason);
  5820. return;
  5821. }
  5822. cnss_schedule_recovery(&pci_priv->pci_dev->dev, cnss_reason);
  5823. }
  5824. static int cnss_pci_get_mhi_msi(struct cnss_pci_data *pci_priv)
  5825. {
  5826. int ret, num_vectors, i;
  5827. u32 user_base_data, base_vector;
  5828. int *irq;
  5829. unsigned int msi_data;
  5830. bool is_one_msi = false;
  5831. ret = cnss_get_user_msi_assignment(&pci_priv->pci_dev->dev,
  5832. MHI_MSI_NAME, &num_vectors,
  5833. &user_base_data, &base_vector);
  5834. if (ret)
  5835. return ret;
  5836. if (cnss_pci_is_one_msi(pci_priv)) {
  5837. is_one_msi = true;
  5838. num_vectors = cnss_pci_get_one_msi_mhi_irq_array_size(pci_priv);
  5839. }
  5840. cnss_pr_dbg("Number of assigned MSI for MHI is %d, base vector is %d\n",
  5841. num_vectors, base_vector);
  5842. irq = kcalloc(num_vectors, sizeof(int), GFP_KERNEL);
  5843. if (!irq)
  5844. return -ENOMEM;
  5845. for (i = 0; i < num_vectors; i++) {
  5846. msi_data = base_vector;
  5847. if (!is_one_msi)
  5848. msi_data += i;
  5849. irq[i] = cnss_get_msi_irq(&pci_priv->pci_dev->dev, msi_data);
  5850. }
  5851. pci_priv->mhi_ctrl->irq = irq;
  5852. pci_priv->mhi_ctrl->nr_irqs = num_vectors;
  5853. return 0;
  5854. }
  5855. static int cnss_mhi_bw_scale(struct mhi_controller *mhi_ctrl,
  5856. struct mhi_link_info *link_info)
  5857. {
  5858. struct cnss_pci_data *pci_priv = dev_get_drvdata(mhi_ctrl->cntrl_dev);
  5859. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  5860. int ret = 0;
  5861. cnss_pr_dbg("Setting link speed:0x%x, width:0x%x\n",
  5862. link_info->target_link_speed,
  5863. link_info->target_link_width);
  5864. /* It has to set target link speed here before setting link bandwidth
  5865. * when device requests link speed change. This can avoid setting link
  5866. * bandwidth getting rejected if requested link speed is higher than
  5867. * current one.
  5868. */
  5869. ret = cnss_pci_set_max_link_speed(pci_priv, plat_priv->rc_num,
  5870. link_info->target_link_speed);
  5871. if (ret)
  5872. cnss_pr_err("Failed to set target link speed to 0x%x, err = %d\n",
  5873. link_info->target_link_speed, ret);
  5874. ret = cnss_pci_set_link_bandwidth(pci_priv,
  5875. link_info->target_link_speed,
  5876. link_info->target_link_width);
  5877. if (ret) {
  5878. cnss_pr_err("Failed to set link bandwidth, err = %d\n", ret);
  5879. return ret;
  5880. }
  5881. pci_priv->def_link_speed = link_info->target_link_speed;
  5882. pci_priv->def_link_width = link_info->target_link_width;
  5883. return 0;
  5884. }
  5885. static int cnss_mhi_read_reg(struct mhi_controller *mhi_ctrl,
  5886. void __iomem *addr, u32 *out)
  5887. {
  5888. struct cnss_pci_data *pci_priv = dev_get_drvdata(mhi_ctrl->cntrl_dev);
  5889. u32 tmp = readl_relaxed(addr);
  5890. /* Unexpected value, query the link status */
  5891. if (PCI_INVALID_READ(tmp) &&
  5892. cnss_pci_check_link_status(pci_priv))
  5893. return -EIO;
  5894. *out = tmp;
  5895. return 0;
  5896. }
  5897. static void cnss_mhi_write_reg(struct mhi_controller *mhi_ctrl,
  5898. void __iomem *addr, u32 val)
  5899. {
  5900. writel_relaxed(val, addr);
  5901. }
  5902. static int cnss_get_mhi_soc_info(struct cnss_plat_data *plat_priv,
  5903. struct mhi_controller *mhi_ctrl)
  5904. {
  5905. int ret = 0;
  5906. ret = mhi_get_soc_info(mhi_ctrl);
  5907. if (ret)
  5908. goto exit;
  5909. plat_priv->device_version.family_number = mhi_ctrl->family_number;
  5910. plat_priv->device_version.device_number = mhi_ctrl->device_number;
  5911. plat_priv->device_version.major_version = mhi_ctrl->major_version;
  5912. plat_priv->device_version.minor_version = mhi_ctrl->minor_version;
  5913. cnss_pr_dbg("Get device version info, family number: 0x%x, device number: 0x%x, major version: 0x%x, minor version: 0x%x\n",
  5914. plat_priv->device_version.family_number,
  5915. plat_priv->device_version.device_number,
  5916. plat_priv->device_version.major_version,
  5917. plat_priv->device_version.minor_version);
  5918. /* Only keep lower 4 bits as real device major version */
  5919. plat_priv->device_version.major_version &= DEVICE_MAJOR_VERSION_MASK;
  5920. exit:
  5921. return ret;
  5922. }
  5923. static bool cnss_is_tme_supported(struct cnss_pci_data *pci_priv)
  5924. {
  5925. if (!pci_priv) {
  5926. cnss_pr_dbg("pci_priv is NULL");
  5927. return false;
  5928. }
  5929. switch (pci_priv->device_id) {
  5930. case PEACH_DEVICE_ID:
  5931. return true;
  5932. default:
  5933. return false;
  5934. }
  5935. }
  5936. static int cnss_pci_register_mhi(struct cnss_pci_data *pci_priv)
  5937. {
  5938. int ret = 0;
  5939. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  5940. struct pci_dev *pci_dev = pci_priv->pci_dev;
  5941. struct mhi_controller *mhi_ctrl;
  5942. phys_addr_t bar_start;
  5943. const struct mhi_controller_config *cnss_mhi_config =
  5944. &cnss_mhi_config_default;
  5945. ret = cnss_qmi_init(plat_priv);
  5946. if (ret)
  5947. return -EINVAL;
  5948. if (pci_priv->device_id == QCA6174_DEVICE_ID)
  5949. return 0;
  5950. mhi_ctrl = mhi_alloc_controller();
  5951. if (!mhi_ctrl) {
  5952. cnss_pr_err("Invalid MHI controller context\n");
  5953. return -EINVAL;
  5954. }
  5955. pci_priv->mhi_ctrl = mhi_ctrl;
  5956. mhi_ctrl->cntrl_dev = &pci_dev->dev;
  5957. mhi_ctrl->fw_image = plat_priv->firmware_name;
  5958. #if IS_ENABLED(CONFIG_MHI_BUS_MISC) && \
  5959. (LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0))
  5960. mhi_ctrl->fallback_fw_image = plat_priv->fw_fallback_name;
  5961. #endif
  5962. mhi_ctrl->regs = pci_priv->bar;
  5963. mhi_ctrl->reg_len = pci_resource_len(pci_priv->pci_dev, PCI_BAR_NUM);
  5964. bar_start = pci_resource_start(pci_priv->pci_dev, PCI_BAR_NUM);
  5965. cnss_pr_dbg("BAR starts at %pa, length is %x\n",
  5966. &bar_start, mhi_ctrl->reg_len);
  5967. ret = cnss_pci_get_mhi_msi(pci_priv);
  5968. if (ret) {
  5969. cnss_pr_err("Failed to get MSI for MHI, err = %d\n", ret);
  5970. goto free_mhi_ctrl;
  5971. }
  5972. if (cnss_pci_is_one_msi(pci_priv))
  5973. mhi_ctrl->irq_flags = IRQF_SHARED | IRQF_NOBALANCING;
  5974. if (pci_priv->smmu_s1_enable) {
  5975. mhi_ctrl->iova_start = pci_priv->smmu_iova_start;
  5976. mhi_ctrl->iova_stop = pci_priv->smmu_iova_start +
  5977. pci_priv->smmu_iova_len;
  5978. } else {
  5979. mhi_ctrl->iova_start = 0;
  5980. mhi_ctrl->iova_stop = pci_priv->dma_bit_mask;
  5981. }
  5982. mhi_ctrl->status_cb = cnss_mhi_notify_status;
  5983. mhi_ctrl->runtime_get = cnss_mhi_pm_runtime_get;
  5984. mhi_ctrl->runtime_put = cnss_mhi_pm_runtime_put_noidle;
  5985. mhi_ctrl->read_reg = cnss_mhi_read_reg;
  5986. mhi_ctrl->write_reg = cnss_mhi_write_reg;
  5987. mhi_ctrl->rddm_size = pci_priv->plat_priv->ramdump_info_v2.ramdump_size;
  5988. if (!mhi_ctrl->rddm_size)
  5989. mhi_ctrl->rddm_size = RAMDUMP_SIZE_DEFAULT;
  5990. if (plat_priv->device_id == QCN7605_DEVICE_ID)
  5991. mhi_ctrl->sbl_size = SZ_256K;
  5992. else
  5993. mhi_ctrl->sbl_size = SZ_512K;
  5994. mhi_ctrl->seg_len = SZ_512K;
  5995. mhi_ctrl->fbc_download = true;
  5996. ret = cnss_get_mhi_soc_info(plat_priv, mhi_ctrl);
  5997. if (ret)
  5998. goto free_mhi_irq;
  5999. /* Satellite config only supported on KIWI V2 and later chipset */
  6000. if (plat_priv->device_id <= QCA6490_DEVICE_ID ||
  6001. (plat_priv->device_id == KIWI_DEVICE_ID &&
  6002. plat_priv->device_version.major_version == 1)) {
  6003. if (plat_priv->device_id == QCN7605_DEVICE_ID)
  6004. cnss_mhi_config = &cnss_mhi_config_genoa;
  6005. else
  6006. cnss_mhi_config = &cnss_mhi_config_no_satellite;
  6007. }
  6008. /* DIAG no longer supported on PEACH and later chipset */
  6009. if (plat_priv->device_id >= PEACH_DEVICE_ID) {
  6010. cnss_mhi_config = &cnss_mhi_config_no_diag;
  6011. }
  6012. mhi_ctrl->tme_supported_image = cnss_is_tme_supported(pci_priv);
  6013. ret = mhi_register_controller(mhi_ctrl, cnss_mhi_config);
  6014. if (ret) {
  6015. cnss_pr_err("Failed to register to MHI bus, err = %d\n", ret);
  6016. goto free_mhi_irq;
  6017. }
  6018. /* MHI satellite driver only needs to connect when DRV is supported */
  6019. if (cnss_pci_get_drv_supported(pci_priv))
  6020. cnss_mhi_controller_set_base(pci_priv, bar_start);
  6021. cnss_get_bwscal_info(plat_priv);
  6022. cnss_pr_dbg("no_bwscale: %d\n", plat_priv->no_bwscale);
  6023. /* BW scale CB needs to be set after registering MHI per requirement */
  6024. if (!plat_priv->no_bwscale)
  6025. cnss_mhi_controller_set_bw_scale_cb(pci_priv,
  6026. cnss_mhi_bw_scale);
  6027. ret = cnss_pci_update_fw_name(pci_priv);
  6028. if (ret)
  6029. goto unreg_mhi;
  6030. return 0;
  6031. unreg_mhi:
  6032. mhi_unregister_controller(mhi_ctrl);
  6033. free_mhi_irq:
  6034. kfree(mhi_ctrl->irq);
  6035. free_mhi_ctrl:
  6036. mhi_free_controller(mhi_ctrl);
  6037. return ret;
  6038. }
  6039. static void cnss_pci_unregister_mhi(struct cnss_pci_data *pci_priv)
  6040. {
  6041. struct mhi_controller *mhi_ctrl = pci_priv->mhi_ctrl;
  6042. if (pci_priv->device_id == QCA6174_DEVICE_ID)
  6043. return;
  6044. mhi_unregister_controller(mhi_ctrl);
  6045. kfree(mhi_ctrl->irq);
  6046. mhi_ctrl->irq = NULL;
  6047. mhi_free_controller(mhi_ctrl);
  6048. pci_priv->mhi_ctrl = NULL;
  6049. }
  6050. static void cnss_pci_config_regs(struct cnss_pci_data *pci_priv)
  6051. {
  6052. switch (pci_priv->device_id) {
  6053. case QCA6390_DEVICE_ID:
  6054. pci_priv->misc_reg_dev_mask = REG_MASK_QCA6390;
  6055. pci_priv->wcss_reg = wcss_reg_access_seq;
  6056. pci_priv->pcie_reg = pcie_reg_access_seq;
  6057. pci_priv->wlaon_reg = wlaon_reg_access_seq;
  6058. pci_priv->syspm_reg = syspm_reg_access_seq;
  6059. /* Configure WDOG register with specific value so that we can
  6060. * know if HW is in the process of WDOG reset recovery or not
  6061. * when reading the registers.
  6062. */
  6063. cnss_pci_reg_write
  6064. (pci_priv,
  6065. QCA6390_PCIE_SOC_WDOG_DISC_BAD_DATA_LOW_CFG_SOC_PCIE_REG,
  6066. QCA6390_PCIE_SOC_WDOG_DISC_BAD_DATA_LOW_CFG_SOC_PCIE_REG_VAL);
  6067. break;
  6068. case QCA6490_DEVICE_ID:
  6069. pci_priv->misc_reg_dev_mask = REG_MASK_QCA6490;
  6070. pci_priv->wlaon_reg = wlaon_reg_access_seq;
  6071. break;
  6072. default:
  6073. return;
  6074. }
  6075. }
  6076. #if !IS_ENABLED(CONFIG_ARCH_QCOM)
  6077. static int cnss_pci_of_reserved_mem_device_init(struct cnss_pci_data *pci_priv)
  6078. {
  6079. return 0;
  6080. }
  6081. static irqreturn_t cnss_pci_wake_handler(int irq, void *data)
  6082. {
  6083. struct cnss_pci_data *pci_priv = data;
  6084. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  6085. enum rpm_status status;
  6086. struct device *dev;
  6087. pci_priv->wake_counter++;
  6088. cnss_pr_dbg("WLAN PCI wake IRQ (%u) is asserted #%u\n",
  6089. pci_priv->wake_irq, pci_priv->wake_counter);
  6090. /* Make sure abort current suspend */
  6091. cnss_pm_stay_awake(plat_priv);
  6092. cnss_pm_relax(plat_priv);
  6093. /* Above two pm* API calls will abort system suspend only when
  6094. * plat_dev->dev->ws is initiated by device_init_wakeup() API, and
  6095. * calling pm_system_wakeup() is just to guarantee system suspend
  6096. * can be aborted if it is not initiated in any case.
  6097. */
  6098. pm_system_wakeup();
  6099. dev = &pci_priv->pci_dev->dev;
  6100. status = dev->power.runtime_status;
  6101. if ((cnss_pci_get_monitor_wake_intr(pci_priv) &&
  6102. cnss_pci_get_auto_suspended(pci_priv)) ||
  6103. (status == RPM_SUSPENDING || status == RPM_SUSPENDED)) {
  6104. cnss_pci_set_monitor_wake_intr(pci_priv, false);
  6105. cnss_pci_pm_request_resume(pci_priv);
  6106. }
  6107. return IRQ_HANDLED;
  6108. }
  6109. /**
  6110. * cnss_pci_wake_gpio_init() - Setup PCI wake GPIO for WLAN
  6111. * @pci_priv: driver PCI bus context pointer
  6112. *
  6113. * This function initializes WLAN PCI wake GPIO and corresponding
  6114. * interrupt. It should be used in non-MSM platforms whose PCIe
  6115. * root complex driver doesn't handle the GPIO.
  6116. *
  6117. * Return: 0 for success or skip, negative value for error
  6118. */
  6119. static int cnss_pci_wake_gpio_init(struct cnss_pci_data *pci_priv)
  6120. {
  6121. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  6122. struct device *dev = &plat_priv->plat_dev->dev;
  6123. int ret = 0;
  6124. pci_priv->wake_gpio = of_get_named_gpio(dev->of_node,
  6125. "wlan-pci-wake-gpio", 0);
  6126. if (pci_priv->wake_gpio < 0)
  6127. goto out;
  6128. cnss_pr_dbg("Get PCI wake GPIO (%d) from device node\n",
  6129. pci_priv->wake_gpio);
  6130. ret = gpio_request(pci_priv->wake_gpio, "wlan_pci_wake_gpio");
  6131. if (ret) {
  6132. cnss_pr_err("Failed to request PCI wake GPIO, err = %d\n",
  6133. ret);
  6134. goto out;
  6135. }
  6136. gpio_direction_input(pci_priv->wake_gpio);
  6137. pci_priv->wake_irq = gpio_to_irq(pci_priv->wake_gpio);
  6138. ret = request_irq(pci_priv->wake_irq, cnss_pci_wake_handler,
  6139. IRQF_TRIGGER_FALLING, "wlan_pci_wake_irq", pci_priv);
  6140. if (ret) {
  6141. cnss_pr_err("Failed to request PCI wake IRQ, err = %d\n", ret);
  6142. goto free_gpio;
  6143. }
  6144. ret = enable_irq_wake(pci_priv->wake_irq);
  6145. if (ret) {
  6146. cnss_pr_err("Failed to enable PCI wake IRQ, err = %d\n", ret);
  6147. goto free_irq;
  6148. }
  6149. return 0;
  6150. free_irq:
  6151. free_irq(pci_priv->wake_irq, pci_priv);
  6152. free_gpio:
  6153. gpio_free(pci_priv->wake_gpio);
  6154. out:
  6155. return ret;
  6156. }
  6157. static void cnss_pci_wake_gpio_deinit(struct cnss_pci_data *pci_priv)
  6158. {
  6159. if (pci_priv->wake_gpio < 0)
  6160. return;
  6161. disable_irq_wake(pci_priv->wake_irq);
  6162. free_irq(pci_priv->wake_irq, pci_priv);
  6163. gpio_free(pci_priv->wake_gpio);
  6164. }
  6165. #endif
  6166. #ifdef CONFIG_CNSS_SUPPORT_DUAL_DEV
  6167. static int cnss_try_suspend(struct cnss_plat_data *plat_priv)
  6168. {
  6169. int ret = 0;
  6170. /* in the dual wlan card case, if call pci_register_driver after
  6171. * finishing the first pcie device enumeration, it will cause
  6172. * the cnss_pci_probe called in advance with the second wlan card,
  6173. * and the sequence like this:
  6174. * enter msm_pcie_enumerate -> pci_bus_add_devices -> cnss_pci_probe
  6175. * -> exit msm_pcie_enumerate.
  6176. * But the correct sequence we expected is like this:
  6177. * enter msm_pcie_enumerate -> pci_bus_add_devices ->
  6178. * exit msm_pcie_enumerate -> cnss_pci_probe.
  6179. * And this unexpected sequence will make the second wlan card do
  6180. * pcie link suspend while the pcie enumeration not finished.
  6181. * So need to add below logical to avoid doing pcie link suspend
  6182. * if the enumeration has not finish.
  6183. */
  6184. plat_priv->enumerate_done = true;
  6185. /* Now enumeration is finished, try to suspend PCIe link */
  6186. if (plat_priv->bus_priv) {
  6187. struct cnss_pci_data *pci_priv = plat_priv->bus_priv;
  6188. struct pci_dev *pci_dev = pci_priv->pci_dev;
  6189. switch (pci_dev->device) {
  6190. case QCA6390_DEVICE_ID:
  6191. cnss_pci_set_wlaon_pwr_ctrl(pci_priv,
  6192. false,
  6193. true,
  6194. false);
  6195. cnss_pci_suspend_pwroff(pci_dev);
  6196. break;
  6197. default:
  6198. cnss_pr_err("Unknown PCI device found: 0x%x\n",
  6199. pci_dev->device);
  6200. ret = -ENODEV;
  6201. }
  6202. }
  6203. return ret;
  6204. }
  6205. #else
  6206. static int cnss_try_suspend(struct cnss_plat_data *plat_priv)
  6207. {
  6208. return 0;
  6209. }
  6210. #endif
  6211. /* Setting to use this cnss_pm_domain ops will let PM framework override the
  6212. * ops from dev->bus->pm which is pci_dev_pm_ops from pci-driver.c. This ops
  6213. * has to take care everything device driver needed which is currently done
  6214. * from pci_dev_pm_ops.
  6215. */
  6216. static struct dev_pm_domain cnss_pm_domain = {
  6217. .ops = {
  6218. SET_SYSTEM_SLEEP_PM_OPS(cnss_pci_suspend, cnss_pci_resume)
  6219. SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(cnss_pci_suspend_noirq,
  6220. cnss_pci_resume_noirq)
  6221. SET_RUNTIME_PM_OPS(cnss_pci_runtime_suspend,
  6222. cnss_pci_runtime_resume,
  6223. cnss_pci_runtime_idle)
  6224. }
  6225. };
  6226. static int cnss_pci_get_dev_cfg_node(struct cnss_plat_data *plat_priv)
  6227. {
  6228. struct device_node *child;
  6229. u32 id, i;
  6230. int id_n, ret;
  6231. if (plat_priv->dt_type != CNSS_DTT_MULTIEXCHG)
  6232. return 0;
  6233. if (!plat_priv->device_id) {
  6234. cnss_pr_err("Invalid device id\n");
  6235. return -EINVAL;
  6236. }
  6237. for_each_available_child_of_node(plat_priv->plat_dev->dev.of_node,
  6238. child) {
  6239. if (strcmp(child->name, "chip_cfg"))
  6240. continue;
  6241. id_n = of_property_count_u32_elems(child, "supported-ids");
  6242. if (id_n <= 0) {
  6243. cnss_pr_err("Device id is NOT set\n");
  6244. return -EINVAL;
  6245. }
  6246. for (i = 0; i < id_n; i++) {
  6247. ret = of_property_read_u32_index(child,
  6248. "supported-ids",
  6249. i, &id);
  6250. if (ret) {
  6251. cnss_pr_err("Failed to read supported ids\n");
  6252. return -EINVAL;
  6253. }
  6254. if (id == plat_priv->device_id) {
  6255. plat_priv->dev_node = child;
  6256. cnss_pr_dbg("got node[%s@%d] for device[0x%x]\n",
  6257. child->name, i, id);
  6258. return 0;
  6259. }
  6260. }
  6261. }
  6262. return -EINVAL;
  6263. }
  6264. #ifdef CONFIG_CNSS2_CONDITIONAL_POWEROFF
  6265. static bool cnss_should_suspend_pwroff(struct pci_dev *pci_dev)
  6266. {
  6267. bool suspend_pwroff;
  6268. switch (pci_dev->device) {
  6269. case QCA6390_DEVICE_ID:
  6270. case QCA6490_DEVICE_ID:
  6271. suspend_pwroff = false;
  6272. break;
  6273. default:
  6274. suspend_pwroff = true;
  6275. }
  6276. return suspend_pwroff;
  6277. }
  6278. #else
  6279. static bool cnss_should_suspend_pwroff(struct pci_dev *pci_dev)
  6280. {
  6281. return true;
  6282. }
  6283. #endif
  6284. #ifdef CONFIG_CNSS2_ENUM_WITH_LOW_SPEED
  6285. static void
  6286. cnss_pci_downgrade_rc_speed(struct cnss_plat_data *plat_priv, u32 rc_num)
  6287. {
  6288. int ret;
  6289. ret = cnss_pci_set_max_link_speed(plat_priv->bus_priv, rc_num,
  6290. PCI_EXP_LNKSTA_CLS_2_5GB);
  6291. if (ret)
  6292. cnss_pr_err("Failed to set max PCIe RC%x link speed to Gen1, err = %d\n",
  6293. rc_num, ret);
  6294. }
  6295. static void
  6296. cnss_pci_restore_rc_speed(struct cnss_pci_data *pci_priv)
  6297. {
  6298. int ret;
  6299. struct cnss_plat_data *plat_priv = pci_priv->plat_priv;
  6300. /* if not Genoa, do not restore rc speed */
  6301. if (pci_priv->device_id != QCN7605_DEVICE_ID) {
  6302. /* The request 0 will reset maximum GEN speed to default */
  6303. ret = cnss_pci_set_max_link_speed(pci_priv, plat_priv->rc_num, 0);
  6304. if (ret)
  6305. cnss_pr_err("Failed to reset max PCIe RC%x link speed to default, err = %d\n",
  6306. plat_priv->rc_num, ret);
  6307. }
  6308. }
  6309. static void
  6310. cnss_pci_link_retrain_trigger(struct cnss_pci_data *pci_priv)
  6311. {
  6312. int ret;
  6313. /* suspend/resume will trigger retain to re-establish link speed */
  6314. ret = cnss_suspend_pci_link(pci_priv);
  6315. if (ret)
  6316. cnss_pr_err("Failed to suspend PCI link, err = %d\n", ret);
  6317. ret = cnss_resume_pci_link(pci_priv);
  6318. if (ret)
  6319. cnss_pr_err("Failed to resume PCI link, err = %d\n", ret);
  6320. cnss_pci_get_link_status(pci_priv);
  6321. }
  6322. #else
  6323. static void
  6324. cnss_pci_downgrade_rc_speed(struct cnss_plat_data *plat_priv, u32 rc_num)
  6325. {
  6326. }
  6327. static void
  6328. cnss_pci_restore_rc_speed(struct cnss_pci_data *pci_priv)
  6329. {
  6330. }
  6331. static void
  6332. cnss_pci_link_retrain_trigger(struct cnss_pci_data *pci_priv)
  6333. {
  6334. }
  6335. #endif
  6336. static void cnss_pci_suspend_pwroff(struct pci_dev *pci_dev)
  6337. {
  6338. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  6339. int rc_num = pci_dev->bus->domain_nr;
  6340. struct cnss_plat_data *plat_priv;
  6341. int ret = 0;
  6342. bool suspend_pwroff = cnss_should_suspend_pwroff(pci_dev);
  6343. plat_priv = cnss_get_plat_priv_by_rc_num(rc_num);
  6344. if (suspend_pwroff) {
  6345. ret = cnss_suspend_pci_link(pci_priv);
  6346. if (ret)
  6347. cnss_pr_err("Failed to suspend PCI link, err = %d\n",
  6348. ret);
  6349. cnss_power_off_device(plat_priv);
  6350. } else {
  6351. cnss_pr_dbg("bus suspend and dev power off disabled for device [0x%x]\n",
  6352. pci_dev->device);
  6353. cnss_pci_link_retrain_trigger(pci_priv);
  6354. }
  6355. }
  6356. static int cnss_pci_probe(struct pci_dev *pci_dev,
  6357. const struct pci_device_id *id)
  6358. {
  6359. int ret = 0;
  6360. struct cnss_pci_data *pci_priv;
  6361. struct device *dev = &pci_dev->dev;
  6362. int rc_num = pci_dev->bus->domain_nr;
  6363. struct cnss_plat_data *plat_priv = cnss_get_plat_priv_by_rc_num(rc_num);
  6364. cnss_pr_dbg("PCI is probing, vendor ID: 0x%x, device ID: 0x%x rc_num %d\n",
  6365. id->vendor, pci_dev->device, rc_num);
  6366. if (!plat_priv) {
  6367. cnss_pr_err("Find match plat_priv with rc number failure\n");
  6368. ret = -ENODEV;
  6369. goto out;
  6370. }
  6371. pci_priv = devm_kzalloc(dev, sizeof(*pci_priv), GFP_KERNEL);
  6372. if (!pci_priv) {
  6373. ret = -ENOMEM;
  6374. goto out;
  6375. }
  6376. pci_priv->pci_link_state = PCI_LINK_UP;
  6377. pci_priv->plat_priv = plat_priv;
  6378. pci_priv->pci_dev = pci_dev;
  6379. pci_priv->pci_device_id = id;
  6380. pci_priv->device_id = pci_dev->device;
  6381. cnss_set_pci_priv(pci_dev, pci_priv);
  6382. plat_priv->device_id = pci_dev->device;
  6383. plat_priv->bus_priv = pci_priv;
  6384. mutex_init(&pci_priv->bus_lock);
  6385. if (plat_priv->use_pm_domain)
  6386. dev->pm_domain = &cnss_pm_domain;
  6387. cnss_pci_restore_rc_speed(pci_priv);
  6388. ret = cnss_pci_get_dev_cfg_node(plat_priv);
  6389. if (ret) {
  6390. cnss_pr_err("Failed to get device cfg node, err = %d\n", ret);
  6391. goto reset_ctx;
  6392. }
  6393. cnss_get_sleep_clk_supported(plat_priv);
  6394. ret = cnss_dev_specific_power_on(plat_priv);
  6395. if (ret < 0)
  6396. goto reset_ctx;
  6397. cnss_pci_of_reserved_mem_device_init(pci_priv);
  6398. ret = cnss_register_subsys(plat_priv);
  6399. if (ret)
  6400. goto reset_ctx;
  6401. ret = cnss_register_ramdump(plat_priv);
  6402. if (ret)
  6403. goto unregister_subsys;
  6404. ret = cnss_pci_init_smmu(pci_priv);
  6405. if (ret)
  6406. goto unregister_ramdump;
  6407. /* update drv support flag */
  6408. cnss_pci_update_drv_supported(pci_priv);
  6409. cnss_update_supported_link_info(pci_priv);
  6410. init_completion(&pci_priv->wake_event_complete);
  6411. ret = cnss_reg_pci_event(pci_priv);
  6412. if (ret) {
  6413. cnss_pr_err("Failed to register PCI event, err = %d\n", ret);
  6414. goto deinit_smmu;
  6415. }
  6416. ret = cnss_pci_enable_bus(pci_priv);
  6417. if (ret)
  6418. goto dereg_pci_event;
  6419. ret = cnss_pci_enable_msi(pci_priv);
  6420. if (ret)
  6421. goto disable_bus;
  6422. ret = cnss_pci_register_mhi(pci_priv);
  6423. if (ret)
  6424. goto disable_msi;
  6425. switch (pci_dev->device) {
  6426. case QCA6174_DEVICE_ID:
  6427. pci_read_config_word(pci_dev, QCA6174_REV_ID_OFFSET,
  6428. &pci_priv->revision_id);
  6429. break;
  6430. case QCA6290_DEVICE_ID:
  6431. case QCA6390_DEVICE_ID:
  6432. case QCN7605_DEVICE_ID:
  6433. case QCA6490_DEVICE_ID:
  6434. case KIWI_DEVICE_ID:
  6435. case MANGO_DEVICE_ID:
  6436. case PEACH_DEVICE_ID:
  6437. if ((cnss_is_dual_wlan_enabled() &&
  6438. plat_priv->enumerate_done) || !cnss_is_dual_wlan_enabled())
  6439. cnss_pci_set_wlaon_pwr_ctrl(pci_priv, false, false,
  6440. false);
  6441. timer_setup(&pci_priv->dev_rddm_timer,
  6442. cnss_dev_rddm_timeout_hdlr, 0);
  6443. timer_setup(&pci_priv->boot_debug_timer,
  6444. cnss_boot_debug_timeout_hdlr, 0);
  6445. INIT_DELAYED_WORK(&pci_priv->time_sync_work,
  6446. cnss_pci_time_sync_work_hdlr);
  6447. cnss_pci_get_link_status(pci_priv);
  6448. cnss_pci_set_wlaon_pwr_ctrl(pci_priv, false, true, false);
  6449. cnss_pci_wake_gpio_init(pci_priv);
  6450. break;
  6451. default:
  6452. cnss_pr_err("Unknown PCI device found: 0x%x\n",
  6453. pci_dev->device);
  6454. ret = -ENODEV;
  6455. goto unreg_mhi;
  6456. }
  6457. cnss_pci_config_regs(pci_priv);
  6458. if (EMULATION_HW)
  6459. goto out;
  6460. if (cnss_is_dual_wlan_enabled() && !plat_priv->enumerate_done)
  6461. goto probe_done;
  6462. cnss_pci_suspend_pwroff(pci_dev);
  6463. probe_done:
  6464. set_bit(CNSS_PCI_PROBE_DONE, &plat_priv->driver_state);
  6465. return 0;
  6466. unreg_mhi:
  6467. cnss_pci_unregister_mhi(pci_priv);
  6468. disable_msi:
  6469. cnss_pci_disable_msi(pci_priv);
  6470. disable_bus:
  6471. cnss_pci_disable_bus(pci_priv);
  6472. dereg_pci_event:
  6473. cnss_dereg_pci_event(pci_priv);
  6474. deinit_smmu:
  6475. cnss_pci_deinit_smmu(pci_priv);
  6476. unregister_ramdump:
  6477. cnss_unregister_ramdump(plat_priv);
  6478. unregister_subsys:
  6479. cnss_unregister_subsys(plat_priv);
  6480. reset_ctx:
  6481. plat_priv->bus_priv = NULL;
  6482. out:
  6483. return ret;
  6484. }
  6485. static void cnss_pci_remove(struct pci_dev *pci_dev)
  6486. {
  6487. struct cnss_pci_data *pci_priv = cnss_get_pci_priv(pci_dev);
  6488. struct cnss_plat_data *plat_priv =
  6489. cnss_bus_dev_to_plat_priv(&pci_dev->dev);
  6490. clear_bit(CNSS_PCI_PROBE_DONE, &plat_priv->driver_state);
  6491. cnss_pci_unregister_driver_hdlr(pci_priv);
  6492. cnss_pci_free_aux_mem(pci_priv);
  6493. cnss_pci_free_tme_lite_mem(pci_priv);
  6494. cnss_pci_free_tme_opt_file_mem(pci_priv);
  6495. cnss_pci_free_m3_mem(pci_priv);
  6496. cnss_pci_free_fw_mem(pci_priv);
  6497. cnss_pci_free_qdss_mem(pci_priv);
  6498. switch (pci_dev->device) {
  6499. case QCA6290_DEVICE_ID:
  6500. case QCA6390_DEVICE_ID:
  6501. case QCN7605_DEVICE_ID:
  6502. case QCA6490_DEVICE_ID:
  6503. case KIWI_DEVICE_ID:
  6504. case MANGO_DEVICE_ID:
  6505. case PEACH_DEVICE_ID:
  6506. cnss_pci_wake_gpio_deinit(pci_priv);
  6507. del_timer(&pci_priv->boot_debug_timer);
  6508. del_timer(&pci_priv->dev_rddm_timer);
  6509. break;
  6510. default:
  6511. break;
  6512. }
  6513. cnss_pci_unregister_mhi(pci_priv);
  6514. cnss_pci_disable_msi(pci_priv);
  6515. cnss_pci_disable_bus(pci_priv);
  6516. cnss_dereg_pci_event(pci_priv);
  6517. cnss_pci_deinit_smmu(pci_priv);
  6518. if (plat_priv) {
  6519. cnss_unregister_ramdump(plat_priv);
  6520. cnss_unregister_subsys(plat_priv);
  6521. plat_priv->bus_priv = NULL;
  6522. } else {
  6523. cnss_pr_err("Plat_priv is null, Unable to unregister ramdump,subsys\n");
  6524. }
  6525. }
  6526. static const struct pci_device_id cnss_pci_id_table[] = {
  6527. { QCA6174_VENDOR_ID, QCA6174_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID },
  6528. { QCA6290_VENDOR_ID, QCA6290_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID },
  6529. { QCA6390_VENDOR_ID, QCA6390_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID },
  6530. { QCN7605_VENDOR_ID, QCN7605_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID },
  6531. { QCA6490_VENDOR_ID, QCA6490_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID },
  6532. { KIWI_VENDOR_ID, KIWI_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID },
  6533. { MANGO_VENDOR_ID, MANGO_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID },
  6534. { PEACH_VENDOR_ID, PEACH_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID },
  6535. { 0 }
  6536. };
  6537. MODULE_DEVICE_TABLE(pci, cnss_pci_id_table);
  6538. static const struct dev_pm_ops cnss_pm_ops = {
  6539. SET_SYSTEM_SLEEP_PM_OPS(cnss_pci_suspend, cnss_pci_resume)
  6540. SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(cnss_pci_suspend_noirq,
  6541. cnss_pci_resume_noirq)
  6542. SET_RUNTIME_PM_OPS(cnss_pci_runtime_suspend, cnss_pci_runtime_resume,
  6543. cnss_pci_runtime_idle)
  6544. };
  6545. static struct pci_driver cnss_pci_driver = {
  6546. .name = "cnss_pci",
  6547. .id_table = cnss_pci_id_table,
  6548. .probe = cnss_pci_probe,
  6549. .remove = cnss_pci_remove,
  6550. .driver = {
  6551. .pm = &cnss_pm_ops,
  6552. },
  6553. };
  6554. static int cnss_pci_enumerate(struct cnss_plat_data *plat_priv, u32 rc_num)
  6555. {
  6556. int ret, retry = 0;
  6557. /* Always set initial target PCIe link speed to Gen2 for QCA6490 device
  6558. * since there may be link issues if it boots up with Gen3 link speed.
  6559. * Device is able to change it later at any time. It will be rejected
  6560. * if requested speed is higher than the one specified in PCIe DT.
  6561. */
  6562. if (plat_priv->device_id == QCA6490_DEVICE_ID) {
  6563. ret = cnss_pci_set_max_link_speed(plat_priv->bus_priv, rc_num,
  6564. PCI_EXP_LNKSTA_CLS_5_0GB);
  6565. if (ret && ret != -EPROBE_DEFER)
  6566. cnss_pr_err("Failed to set max PCIe RC%x link speed to Gen2, err = %d\n",
  6567. rc_num, ret);
  6568. } else {
  6569. cnss_pci_downgrade_rc_speed(plat_priv, rc_num);
  6570. }
  6571. cnss_pr_dbg("Trying to enumerate with PCIe RC%x\n", rc_num);
  6572. retry:
  6573. ret = _cnss_pci_enumerate(plat_priv, rc_num);
  6574. if (ret) {
  6575. if (ret == -EPROBE_DEFER) {
  6576. cnss_pr_dbg("PCIe RC driver is not ready, defer probe\n");
  6577. goto out;
  6578. }
  6579. cnss_pr_err("Failed to enable PCIe RC%x, err = %d\n",
  6580. rc_num, ret);
  6581. if (retry++ < LINK_TRAINING_RETRY_MAX_TIMES) {
  6582. cnss_pr_dbg("Retry PCI link training #%d\n", retry);
  6583. goto retry;
  6584. } else {
  6585. goto out;
  6586. }
  6587. }
  6588. plat_priv->rc_num = rc_num;
  6589. out:
  6590. return ret;
  6591. }
  6592. int cnss_pci_init(struct cnss_plat_data *plat_priv)
  6593. {
  6594. struct device *dev = &plat_priv->plat_dev->dev;
  6595. const __be32 *prop;
  6596. int ret = 0, prop_len = 0, rc_count, i;
  6597. prop = of_get_property(dev->of_node, "qcom,wlan-rc-num", &prop_len);
  6598. if (!prop || !prop_len) {
  6599. cnss_pr_err("Failed to get PCIe RC number from DT\n");
  6600. goto out;
  6601. }
  6602. rc_count = prop_len / sizeof(__be32);
  6603. for (i = 0; i < rc_count; i++) {
  6604. ret = cnss_pci_enumerate(plat_priv, be32_to_cpup(&prop[i]));
  6605. if (!ret)
  6606. break;
  6607. else if (ret == -EPROBE_DEFER || (ret && i == rc_count - 1))
  6608. goto out;
  6609. }
  6610. ret = cnss_try_suspend(plat_priv);
  6611. if (ret) {
  6612. cnss_pr_err("Failed to suspend, ret: %d\n", ret);
  6613. goto out;
  6614. }
  6615. if (!cnss_driver_registered) {
  6616. ret = pci_register_driver(&cnss_pci_driver);
  6617. if (ret) {
  6618. cnss_pr_err("Failed to register to PCI framework, err = %d\n",
  6619. ret);
  6620. goto out;
  6621. }
  6622. if (!plat_priv->bus_priv) {
  6623. cnss_pr_err("Failed to probe PCI driver\n");
  6624. ret = -ENODEV;
  6625. goto unreg_pci;
  6626. }
  6627. cnss_driver_registered = true;
  6628. }
  6629. return 0;
  6630. unreg_pci:
  6631. pci_unregister_driver(&cnss_pci_driver);
  6632. out:
  6633. return ret;
  6634. }
  6635. void cnss_pci_deinit(struct cnss_plat_data *plat_priv)
  6636. {
  6637. if (cnss_driver_registered) {
  6638. pci_unregister_driver(&cnss_pci_driver);
  6639. cnss_driver_registered = false;
  6640. }
  6641. }