ipa.c 220 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/clk.h>
  6. #include <linux/compat.h>
  7. #include <linux/device.h>
  8. #include <linux/dmapool.h>
  9. #include <linux/fs.h>
  10. #include <linux/genalloc.h>
  11. #include <linux/init.h>
  12. #include <linux/kernel.h>
  13. #include <linux/mm.h>
  14. #include <linux/module.h>
  15. #include <linux/of.h>
  16. #include <linux/of_platform.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/rbtree.h>
  19. #include <linux/uaccess.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/msm-bus.h>
  22. #include <linux/msm-bus-board.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/delay.h>
  25. #include <linux/msm_gsi.h>
  26. #include <linux/time.h>
  27. #include <linux/hashtable.h>
  28. #include <linux/jhash.h>
  29. #include <linux/pci.h>
  30. #include <soc/qcom/subsystem_restart.h>
  31. #include <linux/soc/qcom/smem.h>
  32. #include <soc/qcom/scm.h>
  33. #include <asm/cacheflush.h>
  34. #include <linux/soc/qcom/smem_state.h>
  35. #include <linux/of_irq.h>
  36. #ifdef CONFIG_ARM64
  37. /* Outer caches unsupported on ARM64 platforms */
  38. #define outer_flush_range(x, y)
  39. #define __cpuc_flush_dcache_area __flush_dcache_area
  40. #endif
  41. #define IPA_SUBSYSTEM_NAME "ipa_fws"
  42. #define IPA_UC_SUBSYSTEM_NAME "ipa_uc"
  43. #include "ipa_i.h"
  44. #include "../ipa_rm_i.h"
  45. #include "ipahal/ipahal.h"
  46. #include "ipahal/ipahal_fltrt.h"
  47. #define CREATE_TRACE_POINTS
  48. #include "ipa_trace.h"
  49. #include "ipa_odl.h"
  50. /*
  51. * The following for adding code (ie. for EMULATION) not found on x86.
  52. */
  53. #if defined(CONFIG_IPA_EMULATION)
  54. # include "ipa_emulation_stubs.h"
  55. #endif
  56. #ifdef CONFIG_COMPAT
  57. /**
  58. * struct ipa3_ioc_nat_alloc_mem32 - nat table memory allocation
  59. * properties
  60. * @dev_name: input parameter, the name of table
  61. * @size: input parameter, size of table in bytes
  62. * @offset: output parameter, offset into page in case of system memory
  63. */
  64. struct ipa3_ioc_nat_alloc_mem32 {
  65. char dev_name[IPA_RESOURCE_NAME_MAX];
  66. compat_size_t size;
  67. compat_off_t offset;
  68. };
  69. /**
  70. * struct ipa_ioc_nat_ipv6ct_table_alloc32 - table memory allocation
  71. * properties
  72. * @size: input parameter, size of table in bytes
  73. * @offset: output parameter, offset into page in case of system memory
  74. */
  75. struct ipa_ioc_nat_ipv6ct_table_alloc32 {
  76. compat_size_t size;
  77. compat_off_t offset;
  78. };
  79. #endif /* #ifdef CONFIG_COMPAT */
  80. #define IPA_TZ_UNLOCK_ATTRIBUTE 0x0C0311
  81. #define TZ_MEM_PROTECT_REGION_ID 0x10
  82. struct tz_smmu_ipa_protect_region_iovec_s {
  83. u64 input_addr;
  84. u64 output_addr;
  85. u64 size;
  86. u32 attr;
  87. } __packed;
  88. struct tz_smmu_ipa_protect_region_s {
  89. phys_addr_t iovec_buf;
  90. u32 size_bytes;
  91. } __packed;
  92. static void ipa3_start_tag_process(struct work_struct *work);
  93. static DECLARE_WORK(ipa3_tag_work, ipa3_start_tag_process);
  94. static void ipa3_transport_release_resource(struct work_struct *work);
  95. static DECLARE_DELAYED_WORK(ipa3_transport_release_resource_work,
  96. ipa3_transport_release_resource);
  97. static void ipa_gsi_notify_cb(struct gsi_per_notify *notify);
  98. static int ipa3_attach_to_smmu(void);
  99. static int ipa3_alloc_pkt_init(void);
  100. static void ipa3_load_ipa_fw(struct work_struct *work);
  101. static DECLARE_WORK(ipa3_fw_loading_work, ipa3_load_ipa_fw);
  102. static void ipa_dec_clients_disable_clks_on_wq(struct work_struct *work);
  103. static DECLARE_WORK(ipa_dec_clients_disable_clks_on_wq_work,
  104. ipa_dec_clients_disable_clks_on_wq);
  105. static int ipa3_ioctl_add_rt_rule_v2(unsigned long arg);
  106. static int ipa3_ioctl_add_rt_rule_ext_v2(unsigned long arg);
  107. static int ipa3_ioctl_add_rt_rule_after_v2(unsigned long arg);
  108. static int ipa3_ioctl_mdfy_rt_rule_v2(unsigned long arg);
  109. static int ipa3_ioctl_add_flt_rule_v2(unsigned long arg);
  110. static int ipa3_ioctl_add_flt_rule_after_v2(unsigned long arg);
  111. static int ipa3_ioctl_mdfy_flt_rule_v2(unsigned long arg);
  112. static int ipa3_ioctl_fnr_counter_alloc(unsigned long arg);
  113. static int ipa3_ioctl_fnr_counter_query(unsigned long arg);
  114. static struct ipa3_plat_drv_res ipa3_res = {0, };
  115. static struct clk *ipa3_clk;
  116. struct ipa3_context *ipa3_ctx;
  117. static struct {
  118. bool present[IPA_SMMU_CB_MAX];
  119. bool arm_smmu;
  120. bool use_64_bit_dma_mask;
  121. u32 ipa_base;
  122. u32 ipa_size;
  123. } smmu_info;
  124. static char *active_clients_table_buf;
  125. int ipa3_active_clients_log_print_buffer(char *buf, int size)
  126. {
  127. int i;
  128. int nbytes;
  129. int cnt = 0;
  130. int start_idx;
  131. int end_idx;
  132. unsigned long flags;
  133. spin_lock_irqsave(&ipa3_ctx->ipa3_active_clients_logging.lock, flags);
  134. start_idx = (ipa3_ctx->ipa3_active_clients_logging.log_tail + 1) %
  135. IPA3_ACTIVE_CLIENTS_LOG_BUFFER_SIZE_LINES;
  136. end_idx = ipa3_ctx->ipa3_active_clients_logging.log_head;
  137. for (i = start_idx; i != end_idx;
  138. i = (i + 1) % IPA3_ACTIVE_CLIENTS_LOG_BUFFER_SIZE_LINES) {
  139. nbytes = scnprintf(buf + cnt, size - cnt, "%s\n",
  140. ipa3_ctx->ipa3_active_clients_logging
  141. .log_buffer[i]);
  142. cnt += nbytes;
  143. }
  144. spin_unlock_irqrestore(&ipa3_ctx->ipa3_active_clients_logging.lock,
  145. flags);
  146. return cnt;
  147. }
  148. int ipa3_active_clients_log_print_table(char *buf, int size)
  149. {
  150. int i;
  151. struct ipa3_active_client_htable_entry *iterator;
  152. int cnt = 0;
  153. unsigned long flags;
  154. spin_lock_irqsave(&ipa3_ctx->ipa3_active_clients_logging.lock, flags);
  155. cnt = scnprintf(buf, size, "\n---- Active Clients Table ----\n");
  156. hash_for_each(ipa3_ctx->ipa3_active_clients_logging.htable, i,
  157. iterator, list) {
  158. switch (iterator->type) {
  159. case IPA3_ACTIVE_CLIENT_LOG_TYPE_EP:
  160. cnt += scnprintf(buf + cnt, size - cnt,
  161. "%-40s %-3d ENDPOINT\n",
  162. iterator->id_string, iterator->count);
  163. break;
  164. case IPA3_ACTIVE_CLIENT_LOG_TYPE_SIMPLE:
  165. cnt += scnprintf(buf + cnt, size - cnt,
  166. "%-40s %-3d SIMPLE\n",
  167. iterator->id_string, iterator->count);
  168. break;
  169. case IPA3_ACTIVE_CLIENT_LOG_TYPE_RESOURCE:
  170. cnt += scnprintf(buf + cnt, size - cnt,
  171. "%-40s %-3d RESOURCE\n",
  172. iterator->id_string, iterator->count);
  173. break;
  174. case IPA3_ACTIVE_CLIENT_LOG_TYPE_SPECIAL:
  175. cnt += scnprintf(buf + cnt, size - cnt,
  176. "%-40s %-3d SPECIAL\n",
  177. iterator->id_string, iterator->count);
  178. break;
  179. default:
  180. IPAERR("Trying to print illegal active_clients type");
  181. break;
  182. }
  183. }
  184. cnt += scnprintf(buf + cnt, size - cnt,
  185. "\nTotal active clients count: %d\n",
  186. atomic_read(&ipa3_ctx->ipa3_active_clients.cnt));
  187. if (ipa3_is_mhip_offload_enabled())
  188. cnt += ipa_mpm_panic_handler(buf + cnt, size - cnt);
  189. spin_unlock_irqrestore(&ipa3_ctx->ipa3_active_clients_logging.lock,
  190. flags);
  191. return cnt;
  192. }
  193. static int ipa3_clean_modem_rule(void)
  194. {
  195. struct ipa_install_fltr_rule_req_msg_v01 *req;
  196. struct ipa_install_fltr_rule_req_ex_msg_v01 *req_ex;
  197. int val = 0;
  198. if (ipa3_ctx->ipa_hw_type < IPA_HW_v3_0) {
  199. req = kzalloc(
  200. sizeof(struct ipa_install_fltr_rule_req_msg_v01),
  201. GFP_KERNEL);
  202. if (!req) {
  203. IPAERR("mem allocated failed!\n");
  204. return -ENOMEM;
  205. }
  206. req->filter_spec_list_valid = false;
  207. req->filter_spec_list_len = 0;
  208. req->source_pipe_index_valid = 0;
  209. val = ipa3_qmi_filter_request_send(req);
  210. kfree(req);
  211. } else {
  212. req_ex = kzalloc(
  213. sizeof(struct ipa_install_fltr_rule_req_ex_msg_v01),
  214. GFP_KERNEL);
  215. if (!req_ex) {
  216. IPAERR("mem allocated failed!\n");
  217. return -ENOMEM;
  218. }
  219. req_ex->filter_spec_ex_list_valid = false;
  220. req_ex->filter_spec_ex_list_len = 0;
  221. req_ex->source_pipe_index_valid = 0;
  222. val = ipa3_qmi_filter_request_ex_send(req_ex);
  223. kfree(req_ex);
  224. }
  225. return val;
  226. }
  227. static int ipa3_active_clients_panic_notifier(struct notifier_block *this,
  228. unsigned long event, void *ptr)
  229. {
  230. ipa3_active_clients_log_print_table(active_clients_table_buf,
  231. IPA3_ACTIVE_CLIENTS_TABLE_BUF_SIZE);
  232. IPAERR("%s\n", active_clients_table_buf);
  233. return NOTIFY_DONE;
  234. }
  235. static struct notifier_block ipa3_active_clients_panic_blk = {
  236. .notifier_call = ipa3_active_clients_panic_notifier,
  237. };
  238. #ifdef CONFIG_IPA_DEBUG
  239. static int ipa3_active_clients_log_insert(const char *string)
  240. {
  241. int head;
  242. int tail;
  243. if (!ipa3_ctx->ipa3_active_clients_logging.log_rdy)
  244. return -EPERM;
  245. head = ipa3_ctx->ipa3_active_clients_logging.log_head;
  246. tail = ipa3_ctx->ipa3_active_clients_logging.log_tail;
  247. memset(ipa3_ctx->ipa3_active_clients_logging.log_buffer[head], '_',
  248. IPA3_ACTIVE_CLIENTS_LOG_LINE_LEN);
  249. strlcpy(ipa3_ctx->ipa3_active_clients_logging.log_buffer[head], string,
  250. (size_t)IPA3_ACTIVE_CLIENTS_LOG_LINE_LEN);
  251. head = (head + 1) % IPA3_ACTIVE_CLIENTS_LOG_BUFFER_SIZE_LINES;
  252. if (tail == head)
  253. tail = (tail + 1) % IPA3_ACTIVE_CLIENTS_LOG_BUFFER_SIZE_LINES;
  254. ipa3_ctx->ipa3_active_clients_logging.log_tail = tail;
  255. ipa3_ctx->ipa3_active_clients_logging.log_head = head;
  256. return 0;
  257. }
  258. #endif
  259. static int ipa3_active_clients_log_init(void)
  260. {
  261. int i;
  262. spin_lock_init(&ipa3_ctx->ipa3_active_clients_logging.lock);
  263. ipa3_ctx->ipa3_active_clients_logging.log_buffer[0] = kcalloc(
  264. IPA3_ACTIVE_CLIENTS_LOG_BUFFER_SIZE_LINES,
  265. sizeof(char[IPA3_ACTIVE_CLIENTS_LOG_LINE_LEN]),
  266. GFP_KERNEL);
  267. active_clients_table_buf = kzalloc(sizeof(
  268. char[IPA3_ACTIVE_CLIENTS_TABLE_BUF_SIZE]), GFP_KERNEL);
  269. if (ipa3_ctx->ipa3_active_clients_logging.log_buffer == NULL) {
  270. pr_err("Active Clients Logging memory allocation failed\n");
  271. goto bail;
  272. }
  273. for (i = 0; i < IPA3_ACTIVE_CLIENTS_LOG_BUFFER_SIZE_LINES; i++) {
  274. ipa3_ctx->ipa3_active_clients_logging.log_buffer[i] =
  275. ipa3_ctx->ipa3_active_clients_logging.log_buffer[0] +
  276. (IPA3_ACTIVE_CLIENTS_LOG_LINE_LEN * i);
  277. }
  278. ipa3_ctx->ipa3_active_clients_logging.log_head = 0;
  279. ipa3_ctx->ipa3_active_clients_logging.log_tail =
  280. IPA3_ACTIVE_CLIENTS_LOG_BUFFER_SIZE_LINES - 1;
  281. hash_init(ipa3_ctx->ipa3_active_clients_logging.htable);
  282. atomic_notifier_chain_register(&panic_notifier_list,
  283. &ipa3_active_clients_panic_blk);
  284. ipa3_ctx->ipa3_active_clients_logging.log_rdy = true;
  285. return 0;
  286. bail:
  287. return -ENOMEM;
  288. }
  289. void ipa3_active_clients_log_clear(void)
  290. {
  291. unsigned long flags;
  292. spin_lock_irqsave(&ipa3_ctx->ipa3_active_clients_logging.lock, flags);
  293. ipa3_ctx->ipa3_active_clients_logging.log_head = 0;
  294. ipa3_ctx->ipa3_active_clients_logging.log_tail =
  295. IPA3_ACTIVE_CLIENTS_LOG_BUFFER_SIZE_LINES - 1;
  296. spin_unlock_irqrestore(&ipa3_ctx->ipa3_active_clients_logging.lock,
  297. flags);
  298. }
  299. static void ipa3_active_clients_log_destroy(void)
  300. {
  301. unsigned long flags;
  302. spin_lock_irqsave(&ipa3_ctx->ipa3_active_clients_logging.lock, flags);
  303. ipa3_ctx->ipa3_active_clients_logging.log_rdy = false;
  304. kfree(active_clients_table_buf);
  305. active_clients_table_buf = NULL;
  306. kfree(ipa3_ctx->ipa3_active_clients_logging.log_buffer[0]);
  307. ipa3_ctx->ipa3_active_clients_logging.log_head = 0;
  308. ipa3_ctx->ipa3_active_clients_logging.log_tail =
  309. IPA3_ACTIVE_CLIENTS_LOG_BUFFER_SIZE_LINES - 1;
  310. spin_unlock_irqrestore(&ipa3_ctx->ipa3_active_clients_logging.lock,
  311. flags);
  312. }
  313. static struct ipa_smmu_cb_ctx smmu_cb[IPA_SMMU_CB_MAX];
  314. struct iommu_domain *ipa3_get_smmu_domain_by_type(enum ipa_smmu_cb_type cb_type)
  315. {
  316. if (VALID_IPA_SMMU_CB_TYPE(cb_type) && smmu_cb[cb_type].valid)
  317. return smmu_cb[cb_type].iommu_domain;
  318. IPAERR("cb_type(%d) not valid\n", cb_type);
  319. return NULL;
  320. }
  321. struct iommu_domain *ipa3_get_smmu_domain(void)
  322. {
  323. return ipa3_get_smmu_domain_by_type(IPA_SMMU_CB_AP);
  324. }
  325. struct iommu_domain *ipa3_get_uc_smmu_domain(void)
  326. {
  327. return ipa3_get_smmu_domain_by_type(IPA_SMMU_CB_UC);
  328. }
  329. struct iommu_domain *ipa3_get_wlan_smmu_domain(void)
  330. {
  331. return ipa3_get_smmu_domain_by_type(IPA_SMMU_CB_WLAN);
  332. }
  333. struct iommu_domain *ipa3_get_11ad_smmu_domain(void)
  334. {
  335. return ipa3_get_smmu_domain_by_type(IPA_SMMU_CB_11AD);
  336. }
  337. struct device *ipa3_get_dma_dev(void)
  338. {
  339. return ipa3_ctx->pdev;
  340. }
  341. /**
  342. * ipa3_get_smmu_ctx()- Return smmu context for the given cb_type
  343. *
  344. * Return value: pointer to smmu context address
  345. */
  346. struct ipa_smmu_cb_ctx *ipa3_get_smmu_ctx(enum ipa_smmu_cb_type cb_type)
  347. {
  348. return &smmu_cb[cb_type];
  349. }
  350. static int ipa3_open(struct inode *inode, struct file *filp)
  351. {
  352. IPADBG_LOW("ENTER\n");
  353. filp->private_data = ipa3_ctx;
  354. return 0;
  355. }
  356. static void ipa3_wan_msg_free_cb(void *buff, u32 len, u32 type)
  357. {
  358. if (!buff) {
  359. IPAERR("Null buffer\n");
  360. return;
  361. }
  362. if (type != WAN_UPSTREAM_ROUTE_ADD &&
  363. type != WAN_UPSTREAM_ROUTE_DEL &&
  364. type != WAN_EMBMS_CONNECT) {
  365. IPAERR("Wrong type given. buff %pK type %d\n", buff, type);
  366. return;
  367. }
  368. kfree(buff);
  369. }
  370. static int ipa3_send_wan_msg(unsigned long usr_param,
  371. uint8_t msg_type, bool is_cache)
  372. {
  373. int retval;
  374. struct ipa_wan_msg *wan_msg;
  375. struct ipa_msg_meta msg_meta;
  376. struct ipa_wan_msg cache_wan_msg;
  377. wan_msg = kzalloc(sizeof(*wan_msg), GFP_KERNEL);
  378. if (!wan_msg)
  379. return -ENOMEM;
  380. if (copy_from_user(wan_msg, (const void __user *)usr_param,
  381. sizeof(struct ipa_wan_msg))) {
  382. kfree(wan_msg);
  383. return -EFAULT;
  384. }
  385. memcpy(&cache_wan_msg, wan_msg, sizeof(cache_wan_msg));
  386. memset(&msg_meta, 0, sizeof(struct ipa_msg_meta));
  387. msg_meta.msg_type = msg_type;
  388. msg_meta.msg_len = sizeof(struct ipa_wan_msg);
  389. retval = ipa3_send_msg(&msg_meta, wan_msg, ipa3_wan_msg_free_cb);
  390. if (retval) {
  391. IPAERR_RL("ipa3_send_msg failed: %d\n", retval);
  392. kfree(wan_msg);
  393. return retval;
  394. }
  395. if (is_cache) {
  396. mutex_lock(&ipa3_ctx->ipa_cne_evt_lock);
  397. /* cache the cne event */
  398. memcpy(&ipa3_ctx->ipa_cne_evt_req_cache[
  399. ipa3_ctx->num_ipa_cne_evt_req].wan_msg,
  400. &cache_wan_msg,
  401. sizeof(cache_wan_msg));
  402. memcpy(&ipa3_ctx->ipa_cne_evt_req_cache[
  403. ipa3_ctx->num_ipa_cne_evt_req].msg_meta,
  404. &msg_meta,
  405. sizeof(struct ipa_msg_meta));
  406. ipa3_ctx->num_ipa_cne_evt_req++;
  407. ipa3_ctx->num_ipa_cne_evt_req %= IPA_MAX_NUM_REQ_CACHE;
  408. mutex_unlock(&ipa3_ctx->ipa_cne_evt_lock);
  409. }
  410. return 0;
  411. }
  412. static void ipa3_vlan_l2tp_msg_free_cb(void *buff, u32 len, u32 type)
  413. {
  414. if (!buff) {
  415. IPAERR("Null buffer\n");
  416. return;
  417. }
  418. switch (type) {
  419. case ADD_VLAN_IFACE:
  420. case DEL_VLAN_IFACE:
  421. case ADD_L2TP_VLAN_MAPPING:
  422. case DEL_L2TP_VLAN_MAPPING:
  423. case ADD_BRIDGE_VLAN_MAPPING:
  424. case DEL_BRIDGE_VLAN_MAPPING:
  425. break;
  426. default:
  427. IPAERR("Wrong type given. buff %pK type %d\n", buff, type);
  428. return;
  429. }
  430. kfree(buff);
  431. }
  432. static int ipa3_send_vlan_l2tp_msg(unsigned long usr_param, uint8_t msg_type)
  433. {
  434. int retval;
  435. struct ipa_ioc_vlan_iface_info *vlan_info;
  436. struct ipa_ioc_l2tp_vlan_mapping_info *mapping_info;
  437. struct ipa_ioc_bridge_vlan_mapping_info *bridge_vlan_info;
  438. struct ipa_msg_meta msg_meta;
  439. void *buff;
  440. IPADBG("type %d\n", msg_type);
  441. memset(&msg_meta, 0, sizeof(msg_meta));
  442. msg_meta.msg_type = msg_type;
  443. if ((msg_type == ADD_VLAN_IFACE) ||
  444. (msg_type == DEL_VLAN_IFACE)) {
  445. vlan_info = kzalloc(sizeof(struct ipa_ioc_vlan_iface_info),
  446. GFP_KERNEL);
  447. if (!vlan_info)
  448. return -ENOMEM;
  449. if (copy_from_user((u8 *)vlan_info, (void __user *)usr_param,
  450. sizeof(struct ipa_ioc_vlan_iface_info))) {
  451. kfree(vlan_info);
  452. return -EFAULT;
  453. }
  454. msg_meta.msg_len = sizeof(struct ipa_ioc_vlan_iface_info);
  455. buff = vlan_info;
  456. } else if ((msg_type == ADD_L2TP_VLAN_MAPPING) ||
  457. (msg_type == DEL_L2TP_VLAN_MAPPING)) {
  458. mapping_info = kzalloc(sizeof(struct
  459. ipa_ioc_l2tp_vlan_mapping_info), GFP_KERNEL);
  460. if (!mapping_info)
  461. return -ENOMEM;
  462. if (copy_from_user((u8 *)mapping_info,
  463. (void __user *)usr_param,
  464. sizeof(struct ipa_ioc_l2tp_vlan_mapping_info))) {
  465. kfree(mapping_info);
  466. return -EFAULT;
  467. }
  468. msg_meta.msg_len = sizeof(struct
  469. ipa_ioc_l2tp_vlan_mapping_info);
  470. buff = mapping_info;
  471. } else if ((msg_type == ADD_BRIDGE_VLAN_MAPPING) ||
  472. (msg_type == DEL_BRIDGE_VLAN_MAPPING)) {
  473. bridge_vlan_info = kzalloc(
  474. sizeof(struct ipa_ioc_bridge_vlan_mapping_info),
  475. GFP_KERNEL);
  476. if (!bridge_vlan_info)
  477. return -ENOMEM;
  478. if (copy_from_user((u8 *)bridge_vlan_info,
  479. (void __user *)usr_param,
  480. sizeof(struct ipa_ioc_bridge_vlan_mapping_info))) {
  481. kfree(bridge_vlan_info);
  482. IPAERR("copy from user failed\n");
  483. return -EFAULT;
  484. }
  485. msg_meta.msg_len = sizeof(struct
  486. ipa_ioc_bridge_vlan_mapping_info);
  487. buff = bridge_vlan_info;
  488. } else {
  489. IPAERR("Unexpected event\n");
  490. return -EFAULT;
  491. }
  492. retval = ipa3_send_msg(&msg_meta, buff,
  493. ipa3_vlan_l2tp_msg_free_cb);
  494. if (retval) {
  495. IPAERR("ipa3_send_msg failed: %d, msg_type %d\n",
  496. retval,
  497. msg_type);
  498. kfree(buff);
  499. return retval;
  500. }
  501. IPADBG("exit\n");
  502. return 0;
  503. }
  504. static void ipa3_gsb_msg_free_cb(void *buff, u32 len, u32 type)
  505. {
  506. if (!buff) {
  507. IPAERR("Null buffer\n");
  508. return;
  509. }
  510. switch (type) {
  511. case IPA_GSB_CONNECT:
  512. case IPA_GSB_DISCONNECT:
  513. break;
  514. default:
  515. IPAERR("Wrong type given. buff %pK type %d\n", buff, type);
  516. return;
  517. }
  518. kfree(buff);
  519. }
  520. static int ipa3_send_gsb_msg(unsigned long usr_param, uint8_t msg_type)
  521. {
  522. int retval;
  523. struct ipa_ioc_gsb_info *gsb_info;
  524. struct ipa_msg_meta msg_meta;
  525. void *buff;
  526. IPADBG("type %d\n", msg_type);
  527. memset(&msg_meta, 0, sizeof(msg_meta));
  528. msg_meta.msg_type = msg_type;
  529. if ((msg_type == IPA_GSB_CONNECT) ||
  530. (msg_type == IPA_GSB_DISCONNECT)) {
  531. gsb_info = kzalloc(sizeof(struct ipa_ioc_gsb_info),
  532. GFP_KERNEL);
  533. if (!gsb_info) {
  534. IPAERR("no memory\n");
  535. return -ENOMEM;
  536. }
  537. if (copy_from_user((u8 *)gsb_info, (void __user *)usr_param,
  538. sizeof(struct ipa_ioc_gsb_info))) {
  539. kfree(gsb_info);
  540. return -EFAULT;
  541. }
  542. msg_meta.msg_len = sizeof(struct ipa_ioc_gsb_info);
  543. buff = gsb_info;
  544. } else {
  545. IPAERR("Unexpected event\n");
  546. return -EFAULT;
  547. }
  548. retval = ipa3_send_msg(&msg_meta, buff,
  549. ipa3_gsb_msg_free_cb);
  550. if (retval) {
  551. IPAERR("ipa3_send_msg failed: %d, msg_type %d\n",
  552. retval,
  553. msg_type);
  554. kfree(buff);
  555. return retval;
  556. }
  557. IPADBG("exit\n");
  558. return 0;
  559. }
  560. static int ipa3_ioctl_add_rt_rule_v2(unsigned long arg)
  561. {
  562. int retval = 0;
  563. int i;
  564. u8 header[128] = { 0 };
  565. int pre_entry;
  566. u32 usr_pyld_sz;
  567. u32 pyld_sz;
  568. u64 uptr = 0;
  569. u8 *param = NULL;
  570. u8 *kptr = NULL;
  571. if (copy_from_user(header, (const void __user *)arg,
  572. sizeof(struct ipa_ioc_add_rt_rule_v2))) {
  573. IPAERR_RL("copy_from_user fails\n");
  574. retval = -EFAULT;
  575. goto free_param_kptr;
  576. }
  577. pre_entry =
  578. ((struct ipa_ioc_add_rt_rule_v2 *)header)->num_rules;
  579. if (unlikely(((struct ipa_ioc_add_rt_rule_v2 *)
  580. header)->rule_add_size >
  581. sizeof(struct ipa_rt_rule_add_i))) {
  582. IPAERR_RL("unexpected rule_add_size %d\n",
  583. ((struct ipa_ioc_add_rt_rule_v2 *)
  584. header)->rule_add_size);
  585. retval = -EPERM;
  586. goto free_param_kptr;
  587. }
  588. /* user payload size */
  589. usr_pyld_sz = ((struct ipa_ioc_add_rt_rule_v2 *)
  590. header)->rule_add_size * pre_entry;
  591. /* actual payload structure size in kernel */
  592. pyld_sz = sizeof(struct ipa_rt_rule_add_i) * pre_entry;
  593. uptr = ((struct ipa_ioc_add_rt_rule_v2 *)
  594. header)->rules;
  595. if (unlikely(!uptr)) {
  596. IPAERR_RL("unexpected NULL rules\n");
  597. retval = -EPERM;
  598. goto free_param_kptr;
  599. }
  600. /* alloc param with same payload size as user payload */
  601. param = memdup_user((const void __user *)uptr,
  602. usr_pyld_sz);
  603. if (IS_ERR(param)) {
  604. retval = -EFAULT;
  605. goto free_param_kptr;
  606. }
  607. /* alloc kernel pointer with actual payload size */
  608. kptr = kzalloc(pyld_sz, GFP_KERNEL);
  609. if (!kptr) {
  610. retval = -ENOMEM;
  611. goto free_param_kptr;
  612. }
  613. for (i = 0; i < pre_entry; i++)
  614. memcpy(kptr + i * sizeof(struct ipa_rt_rule_add_i),
  615. (void *)param + i *
  616. ((struct ipa_ioc_add_rt_rule_v2 *)
  617. header)->rule_add_size,
  618. ((struct ipa_ioc_add_rt_rule_v2 *)
  619. header)->rule_add_size);
  620. /* modify the rule pointer to the kernel pointer */
  621. ((struct ipa_ioc_add_rt_rule_v2 *)header)->rules =
  622. (u64)kptr;
  623. if (ipa3_add_rt_rule_usr_v2(
  624. (struct ipa_ioc_add_rt_rule_v2 *)header, true)) {
  625. IPAERR_RL("ipa3_add_rt_rule_usr_v2 fails\n");
  626. retval = -EPERM;
  627. goto free_param_kptr;
  628. }
  629. for (i = 0; i < pre_entry; i++)
  630. memcpy((void *)param + i *
  631. ((struct ipa_ioc_add_rt_rule_v2 *)
  632. header)->rule_add_size,
  633. kptr + i * sizeof(struct ipa_rt_rule_add_i),
  634. ((struct ipa_ioc_add_rt_rule_v2 *)
  635. header)->rule_add_size);
  636. if (copy_to_user((void __user *)uptr, param,
  637. usr_pyld_sz)) {
  638. IPAERR_RL("copy_to_user fails\n");
  639. retval = -EFAULT;
  640. goto free_param_kptr;
  641. }
  642. free_param_kptr:
  643. if (!IS_ERR(param))
  644. kfree(param);
  645. kfree(kptr);
  646. return retval;
  647. }
  648. static int ipa3_ioctl_add_rt_rule_ext_v2(unsigned long arg)
  649. {
  650. int retval = 0;
  651. int i;
  652. u8 header[128] = { 0 };
  653. int pre_entry;
  654. u32 usr_pyld_sz;
  655. u32 pyld_sz;
  656. u64 uptr = 0;
  657. u8 *param = NULL;
  658. u8 *kptr = NULL;
  659. if (copy_from_user(header,
  660. (const void __user *)arg,
  661. sizeof(struct ipa_ioc_add_rt_rule_ext_v2))) {
  662. IPAERR_RL("copy_from_user fails\n");
  663. retval = -EFAULT;
  664. goto free_param_kptr;
  665. }
  666. pre_entry =
  667. ((struct ipa_ioc_add_rt_rule_ext_v2 *)
  668. header)->num_rules;
  669. if (unlikely(((struct ipa_ioc_add_rt_rule_ext_v2 *)
  670. header)->rule_add_ext_size >
  671. sizeof(struct ipa_rt_rule_add_ext_i))) {
  672. IPAERR_RL("unexpected rule_add_size %d\n",
  673. ((struct ipa_ioc_add_rt_rule_ext_v2 *)
  674. header)->rule_add_ext_size);
  675. retval = -EPERM;
  676. goto free_param_kptr;
  677. }
  678. /* user payload size */
  679. usr_pyld_sz = ((struct ipa_ioc_add_rt_rule_ext_v2 *)
  680. header)->rule_add_ext_size * pre_entry;
  681. /* actual payload structure size in kernel */
  682. pyld_sz = sizeof(struct ipa_rt_rule_add_ext_i)
  683. * pre_entry;
  684. uptr = ((struct ipa_ioc_add_rt_rule_ext_v2 *)
  685. header)->rules;
  686. if (unlikely(!uptr)) {
  687. IPAERR_RL("unexpected NULL rules\n");
  688. retval = -EPERM;
  689. goto free_param_kptr;
  690. }
  691. /* alloc param with same payload size as user payload */
  692. param = memdup_user((const void __user *)uptr,
  693. usr_pyld_sz);
  694. if (IS_ERR(param)) {
  695. retval = -EFAULT;
  696. goto free_param_kptr;
  697. }
  698. /* alloc kernel pointer with actual payload size */
  699. kptr = kzalloc(pyld_sz, GFP_KERNEL);
  700. if (!kptr) {
  701. retval = -ENOMEM;
  702. goto free_param_kptr;
  703. }
  704. for (i = 0; i < pre_entry; i++)
  705. memcpy(kptr + i *
  706. sizeof(struct ipa_rt_rule_add_ext_i),
  707. (void *)param + i *
  708. ((struct ipa_ioc_add_rt_rule_ext_v2 *)
  709. header)->rule_add_ext_size,
  710. ((struct ipa_ioc_add_rt_rule_ext_v2 *)
  711. header)->rule_add_ext_size);
  712. /* modify the rule pointer to the kernel pointer */
  713. ((struct ipa_ioc_add_rt_rule_ext_v2 *)header)->rules =
  714. (u64)kptr;
  715. if (ipa3_add_rt_rule_ext_v2(
  716. (struct ipa_ioc_add_rt_rule_ext_v2 *)header)) {
  717. IPAERR_RL("ipa3_add_rt_rule_ext_v2 fails\n");
  718. retval = -EPERM;
  719. goto free_param_kptr;
  720. }
  721. for (i = 0; i < pre_entry; i++)
  722. memcpy((void *)param + i *
  723. ((struct ipa_ioc_add_rt_rule_ext_v2 *)
  724. header)->rule_add_ext_size,
  725. kptr + i *
  726. sizeof(struct ipa_rt_rule_add_ext_i),
  727. ((struct ipa_ioc_add_rt_rule_ext_v2 *)
  728. header)->rule_add_ext_size);
  729. if (copy_to_user((void __user *)uptr, param,
  730. usr_pyld_sz)) {
  731. IPAERR_RL("copy_to_user fails\n");
  732. retval = -EFAULT;
  733. goto free_param_kptr;
  734. }
  735. free_param_kptr:
  736. if (!IS_ERR(param))
  737. kfree(param);
  738. kfree(kptr);
  739. return retval;
  740. }
  741. static int ipa3_ioctl_add_rt_rule_after_v2(unsigned long arg)
  742. {
  743. int retval = 0;
  744. int i;
  745. u8 header[128] = { 0 };
  746. int pre_entry;
  747. u32 usr_pyld_sz;
  748. u32 pyld_sz;
  749. u64 uptr = 0;
  750. u8 *param = NULL;
  751. u8 *kptr = NULL;
  752. if (copy_from_user(header, (const void __user *)arg,
  753. sizeof(struct ipa_ioc_add_rt_rule_after_v2))) {
  754. IPAERR_RL("copy_from_user fails\n");
  755. retval = -EFAULT;
  756. goto free_param_kptr;
  757. }
  758. pre_entry =
  759. ((struct ipa_ioc_add_rt_rule_after_v2 *)
  760. header)->num_rules;
  761. if (unlikely(((struct ipa_ioc_add_rt_rule_after_v2 *)
  762. header)->rule_add_size >
  763. sizeof(struct ipa_rt_rule_add_i))) {
  764. IPAERR_RL("unexpected rule_add_size %d\n",
  765. ((struct ipa_ioc_add_rt_rule_after_v2 *)
  766. header)->rule_add_size);
  767. retval = -EPERM;
  768. goto free_param_kptr;
  769. }
  770. /* user payload size */
  771. usr_pyld_sz = ((struct ipa_ioc_add_rt_rule_after_v2 *)
  772. header)->rule_add_size * pre_entry;
  773. /* actual payload structure size in kernel */
  774. pyld_sz = sizeof(struct ipa_rt_rule_add_i)
  775. * pre_entry;
  776. uptr = ((struct ipa_ioc_add_rt_rule_after_v2 *)
  777. header)->rules;
  778. if (unlikely(!uptr)) {
  779. IPAERR_RL("unexpected NULL rules\n");
  780. retval = -EPERM;
  781. goto free_param_kptr;
  782. }
  783. /* alloc param with same payload size as user payload */
  784. param = memdup_user((const void __user *)uptr,
  785. usr_pyld_sz);
  786. if (IS_ERR(param)) {
  787. retval = -EFAULT;
  788. goto free_param_kptr;
  789. }
  790. /* alloc kernel pointer with actual payload size */
  791. kptr = kzalloc(pyld_sz, GFP_KERNEL);
  792. if (!kptr) {
  793. retval = -ENOMEM;
  794. goto free_param_kptr;
  795. }
  796. for (i = 0; i < pre_entry; i++)
  797. memcpy(kptr + i * sizeof(struct ipa_rt_rule_add_i),
  798. (void *)param + i *
  799. ((struct ipa_ioc_add_rt_rule_after_v2 *)
  800. header)->rule_add_size,
  801. ((struct ipa_ioc_add_rt_rule_after_v2 *)
  802. header)->rule_add_size);
  803. /* modify the rule pointer to the kernel pointer */
  804. ((struct ipa_ioc_add_rt_rule_after_v2 *)header)->rules =
  805. (u64)kptr;
  806. if (ipa3_add_rt_rule_after_v2(
  807. (struct ipa_ioc_add_rt_rule_after_v2 *)header)) {
  808. IPAERR_RL("ipa3_add_rt_rule_after_v2 fails\n");
  809. retval = -EPERM;
  810. goto free_param_kptr;
  811. }
  812. for (i = 0; i < pre_entry; i++)
  813. memcpy((void *)param + i *
  814. ((struct ipa_ioc_add_rt_rule_after_v2 *)
  815. header)->rule_add_size,
  816. kptr + i * sizeof(struct ipa_rt_rule_add_i),
  817. ((struct ipa_ioc_add_rt_rule_after_v2 *)
  818. header)->rule_add_size);
  819. if (copy_to_user((void __user *)uptr, param,
  820. usr_pyld_sz)) {
  821. IPAERR_RL("copy_to_user fails\n");
  822. retval = -EFAULT;
  823. goto free_param_kptr;
  824. }
  825. free_param_kptr:
  826. if (!IS_ERR(param))
  827. kfree(param);
  828. kfree(kptr);
  829. return retval;
  830. }
  831. static int ipa3_ioctl_mdfy_rt_rule_v2(unsigned long arg)
  832. {
  833. int retval = 0;
  834. int i;
  835. u8 header[128] = { 0 };
  836. int pre_entry;
  837. u32 usr_pyld_sz;
  838. u32 pyld_sz;
  839. u64 uptr = 0;
  840. u8 *param = NULL;
  841. u8 *kptr = NULL;
  842. if (copy_from_user(header, (const void __user *)arg,
  843. sizeof(struct ipa_ioc_mdfy_rt_rule_v2))) {
  844. IPAERR_RL("copy_from_user fails\n");
  845. retval = -EFAULT;
  846. goto free_param_kptr;
  847. }
  848. pre_entry =
  849. ((struct ipa_ioc_mdfy_rt_rule_v2 *)
  850. header)->num_rules;
  851. if (unlikely(((struct ipa_ioc_mdfy_rt_rule_v2 *)
  852. header)->rule_mdfy_size >
  853. sizeof(struct ipa_rt_rule_mdfy_i))) {
  854. IPAERR_RL("unexpected rule_add_size %d\n",
  855. ((struct ipa_ioc_mdfy_rt_rule_v2 *)
  856. header)->rule_mdfy_size);
  857. retval = -EPERM;
  858. goto free_param_kptr;
  859. }
  860. /* user payload size */
  861. usr_pyld_sz = ((struct ipa_ioc_mdfy_rt_rule_v2 *)
  862. header)->rule_mdfy_size * pre_entry;
  863. /* actual payload structure size in kernel */
  864. pyld_sz = sizeof(struct ipa_rt_rule_mdfy_i)
  865. * pre_entry;
  866. uptr = ((struct ipa_ioc_mdfy_rt_rule_v2 *)
  867. header)->rules;
  868. if (unlikely(!uptr)) {
  869. IPAERR_RL("unexpected NULL rules\n");
  870. retval = -EPERM;
  871. goto free_param_kptr;
  872. }
  873. /* alloc param with same payload size as user payload */
  874. param = memdup_user((const void __user *)uptr,
  875. usr_pyld_sz);
  876. if (IS_ERR(param)) {
  877. retval = -EFAULT;
  878. goto free_param_kptr;
  879. }
  880. /* alloc kernel pointer with actual payload size */
  881. kptr = kzalloc(pyld_sz, GFP_KERNEL);
  882. if (!kptr) {
  883. retval = -ENOMEM;
  884. goto free_param_kptr;
  885. }
  886. for (i = 0; i < pre_entry; i++)
  887. memcpy(kptr + i * sizeof(struct ipa_rt_rule_mdfy_i),
  888. (void *)param + i *
  889. ((struct ipa_ioc_mdfy_rt_rule_v2 *)
  890. header)->rule_mdfy_size,
  891. ((struct ipa_ioc_mdfy_rt_rule_v2 *)
  892. header)->rule_mdfy_size);
  893. /* modify the rule pointer to the kernel pointer */
  894. ((struct ipa_ioc_mdfy_rt_rule_v2 *)header)->rules =
  895. (u64)kptr;
  896. if (ipa3_mdfy_rt_rule_v2((struct ipa_ioc_mdfy_rt_rule_v2 *)
  897. header)) {
  898. IPAERR_RL("ipa3_mdfy_rt_rule_v2 fails\n");
  899. retval = -EPERM;
  900. goto free_param_kptr;
  901. }
  902. for (i = 0; i < pre_entry; i++)
  903. memcpy((void *)param + i *
  904. ((struct ipa_ioc_mdfy_rt_rule_v2 *)
  905. header)->rule_mdfy_size,
  906. kptr + i * sizeof(struct ipa_rt_rule_mdfy_i),
  907. ((struct ipa_ioc_mdfy_rt_rule_v2 *)
  908. header)->rule_mdfy_size);
  909. if (copy_to_user((void __user *)uptr, param,
  910. usr_pyld_sz)) {
  911. IPAERR_RL("copy_to_user fails\n");
  912. retval = -EFAULT;
  913. goto free_param_kptr;
  914. }
  915. free_param_kptr:
  916. if (!IS_ERR(param))
  917. kfree(param);
  918. kfree(kptr);
  919. return retval;
  920. }
  921. static int ipa3_ioctl_add_flt_rule_v2(unsigned long arg)
  922. {
  923. int retval = 0;
  924. int i;
  925. u8 header[128] = { 0 };
  926. int pre_entry;
  927. u32 usr_pyld_sz;
  928. u32 pyld_sz;
  929. u64 uptr = 0;
  930. u8 *param = NULL;
  931. u8 *kptr = NULL;
  932. if (copy_from_user(header, (const void __user *)arg,
  933. sizeof(struct ipa_ioc_add_flt_rule_v2))) {
  934. IPAERR_RL("copy_from_user fails\n");
  935. retval = -EFAULT;
  936. goto free_param_kptr;
  937. }
  938. pre_entry =
  939. ((struct ipa_ioc_add_flt_rule_v2 *)header)->num_rules;
  940. if (unlikely(((struct ipa_ioc_add_flt_rule_v2 *)
  941. header)->flt_rule_size >
  942. sizeof(struct ipa_flt_rule_add_i))) {
  943. IPAERR_RL("unexpected rule_add_size %d\n",
  944. ((struct ipa_ioc_add_flt_rule_v2 *)
  945. header)->flt_rule_size);
  946. retval = -EPERM;
  947. goto free_param_kptr;
  948. }
  949. /* user payload size */
  950. usr_pyld_sz = ((struct ipa_ioc_add_flt_rule_v2 *)
  951. header)->flt_rule_size * pre_entry;
  952. /* actual payload structure size in kernel */
  953. pyld_sz = sizeof(struct ipa_flt_rule_add_i)
  954. * pre_entry;
  955. uptr = ((struct ipa_ioc_add_flt_rule_v2 *)
  956. header)->rules;
  957. if (unlikely(!uptr)) {
  958. IPAERR_RL("unexpected NULL rules\n");
  959. retval = -EPERM;
  960. goto free_param_kptr;
  961. }
  962. /* alloc param with same payload size as user payload */
  963. param = memdup_user((const void __user *)uptr,
  964. usr_pyld_sz);
  965. if (IS_ERR(param)) {
  966. retval = -EFAULT;
  967. goto free_param_kptr;
  968. }
  969. /* alloc kernel pointer with actual payload size */
  970. kptr = kzalloc(pyld_sz, GFP_KERNEL);
  971. if (!kptr) {
  972. retval = -ENOMEM;
  973. goto free_param_kptr;
  974. }
  975. for (i = 0; i < pre_entry; i++)
  976. memcpy(kptr + i * sizeof(struct ipa_flt_rule_add_i),
  977. (void *)param + i *
  978. ((struct ipa_ioc_add_flt_rule_v2 *)
  979. header)->flt_rule_size,
  980. ((struct ipa_ioc_add_flt_rule_v2 *)
  981. header)->flt_rule_size);
  982. /* modify the rule pointer to the kernel pointer */
  983. ((struct ipa_ioc_add_flt_rule_v2 *)header)->rules =
  984. (u64)kptr;
  985. if (ipa3_add_flt_rule_usr_v2((struct ipa_ioc_add_flt_rule_v2 *)
  986. header, true)) {
  987. IPAERR_RL("ipa3_add_flt_rule_usr_v2 fails\n");
  988. retval = -EPERM;
  989. goto free_param_kptr;
  990. }
  991. for (i = 0; i < pre_entry; i++)
  992. memcpy((void *)param + i *
  993. ((struct ipa_ioc_add_flt_rule_v2 *)
  994. header)->flt_rule_size,
  995. kptr + i * sizeof(struct ipa_flt_rule_add_i),
  996. ((struct ipa_ioc_add_flt_rule_v2 *)
  997. header)->flt_rule_size);
  998. if (copy_to_user((void __user *)uptr, param,
  999. usr_pyld_sz)) {
  1000. IPAERR_RL("copy_to_user fails\n");
  1001. retval = -EFAULT;
  1002. goto free_param_kptr;
  1003. }
  1004. free_param_kptr:
  1005. if (!IS_ERR(param))
  1006. kfree(param);
  1007. kfree(kptr);
  1008. return retval;
  1009. }
  1010. static int ipa3_ioctl_add_flt_rule_after_v2(unsigned long arg)
  1011. {
  1012. int retval = 0;
  1013. int i;
  1014. u8 header[128] = { 0 };
  1015. int pre_entry;
  1016. u32 usr_pyld_sz;
  1017. u32 pyld_sz;
  1018. u64 uptr = 0;
  1019. u8 *param = NULL;
  1020. u8 *kptr = NULL;
  1021. if (copy_from_user(header, (const void __user *)arg,
  1022. sizeof(struct ipa_ioc_add_flt_rule_after_v2))) {
  1023. IPAERR_RL("copy_from_user fails\n");
  1024. retval = -EFAULT;
  1025. goto free_param_kptr;
  1026. }
  1027. pre_entry =
  1028. ((struct ipa_ioc_add_flt_rule_after_v2 *)
  1029. header)->num_rules;
  1030. if (unlikely(((struct ipa_ioc_add_flt_rule_after_v2 *)
  1031. header)->flt_rule_size >
  1032. sizeof(struct ipa_flt_rule_add_i))) {
  1033. IPAERR_RL("unexpected rule_add_size %d\n",
  1034. ((struct ipa_ioc_add_flt_rule_after_v2 *)
  1035. header)->flt_rule_size);
  1036. retval = -EPERM;
  1037. goto free_param_kptr;
  1038. }
  1039. /* user payload size */
  1040. usr_pyld_sz = ((struct ipa_ioc_add_flt_rule_after_v2 *)
  1041. header)->flt_rule_size * pre_entry;
  1042. /* actual payload structure size in kernel */
  1043. pyld_sz = sizeof(struct ipa_flt_rule_add_i)
  1044. * pre_entry;
  1045. uptr = ((struct ipa_ioc_add_flt_rule_after_v2 *)
  1046. header)->rules;
  1047. if (unlikely(!uptr)) {
  1048. IPAERR_RL("unexpected NULL rules\n");
  1049. retval = -EPERM;
  1050. goto free_param_kptr;
  1051. }
  1052. /* alloc param with same payload size as user payload */
  1053. param = memdup_user((const void __user *)uptr,
  1054. usr_pyld_sz);
  1055. if (IS_ERR(param)) {
  1056. retval = -EFAULT;
  1057. goto free_param_kptr;
  1058. }
  1059. /* alloc kernel pointer with actual payload size */
  1060. kptr = kzalloc(pyld_sz, GFP_KERNEL);
  1061. if (!kptr) {
  1062. retval = -ENOMEM;
  1063. goto free_param_kptr;
  1064. }
  1065. for (i = 0; i < pre_entry; i++)
  1066. memcpy(kptr + i * sizeof(struct ipa_flt_rule_add_i),
  1067. (void *)param + i *
  1068. ((struct ipa_ioc_add_flt_rule_after_v2 *)
  1069. header)->flt_rule_size,
  1070. ((struct ipa_ioc_add_flt_rule_after_v2 *)
  1071. header)->flt_rule_size);
  1072. /* modify the rule pointer to the kernel pointer */
  1073. ((struct ipa_ioc_add_flt_rule_after_v2 *)header)->rules =
  1074. (u64)kptr;
  1075. if (ipa3_add_flt_rule_after_v2(
  1076. (struct ipa_ioc_add_flt_rule_after_v2 *)header)) {
  1077. IPAERR_RL("ipa3_add_flt_rule_after_v2 fails\n");
  1078. retval = -EPERM;
  1079. goto free_param_kptr;
  1080. }
  1081. for (i = 0; i < pre_entry; i++)
  1082. memcpy((void *)param + i *
  1083. ((struct ipa_ioc_add_flt_rule_after_v2 *)
  1084. header)->flt_rule_size,
  1085. kptr + i * sizeof(struct ipa_flt_rule_add_i),
  1086. ((struct ipa_ioc_add_flt_rule_after_v2 *)
  1087. header)->flt_rule_size);
  1088. if (copy_to_user((void __user *)uptr, param,
  1089. usr_pyld_sz)) {
  1090. IPAERR_RL("copy_to_user fails\n");
  1091. retval = -EFAULT;
  1092. goto free_param_kptr;
  1093. }
  1094. free_param_kptr:
  1095. if (!IS_ERR(param))
  1096. kfree(param);
  1097. kfree(kptr);
  1098. return retval;
  1099. }
  1100. static int ipa3_ioctl_mdfy_flt_rule_v2(unsigned long arg)
  1101. {
  1102. int retval = 0;
  1103. int i;
  1104. u8 header[128] = { 0 };
  1105. int pre_entry;
  1106. u32 usr_pyld_sz;
  1107. u32 pyld_sz;
  1108. u64 uptr = 0;
  1109. u8 *param = NULL;
  1110. u8 *kptr = NULL;
  1111. if (copy_from_user(header, (const void __user *)arg,
  1112. sizeof(struct ipa_ioc_mdfy_flt_rule_v2))) {
  1113. IPAERR_RL("copy_from_user fails\n");
  1114. retval = -EFAULT;
  1115. goto free_param_kptr;
  1116. }
  1117. pre_entry =
  1118. ((struct ipa_ioc_mdfy_flt_rule_v2 *)
  1119. header)->num_rules;
  1120. if (unlikely(((struct ipa_ioc_mdfy_flt_rule_v2 *)
  1121. header)->rule_mdfy_size >
  1122. sizeof(struct ipa_flt_rule_mdfy_i))) {
  1123. IPAERR_RL("unexpected rule_add_size %d\n",
  1124. ((struct ipa_ioc_mdfy_flt_rule_v2 *)
  1125. header)->rule_mdfy_size);
  1126. retval = -EPERM;
  1127. goto free_param_kptr;
  1128. }
  1129. /* user payload size */
  1130. usr_pyld_sz = ((struct ipa_ioc_mdfy_flt_rule_v2 *)
  1131. header)->rule_mdfy_size * pre_entry;
  1132. /* actual payload structure size in kernel */
  1133. pyld_sz = sizeof(struct ipa_flt_rule_mdfy_i)
  1134. * pre_entry;
  1135. uptr = ((struct ipa_ioc_mdfy_flt_rule_v2 *)
  1136. header)->rules;
  1137. if (unlikely(!uptr)) {
  1138. IPAERR_RL("unexpected NULL rules\n");
  1139. retval = -EPERM;
  1140. goto free_param_kptr;
  1141. }
  1142. /* alloc param with same payload size as user payload */
  1143. param = memdup_user((const void __user *)uptr,
  1144. usr_pyld_sz);
  1145. if (IS_ERR(param)) {
  1146. retval = -EFAULT;
  1147. goto free_param_kptr;
  1148. }
  1149. /* alloc kernel pointer with actual payload size */
  1150. kptr = kzalloc(pyld_sz, GFP_KERNEL);
  1151. if (!kptr) {
  1152. retval = -ENOMEM;
  1153. goto free_param_kptr;
  1154. }
  1155. for (i = 0; i < pre_entry; i++)
  1156. memcpy(kptr + i * sizeof(struct ipa_flt_rule_mdfy_i),
  1157. (void *)param + i *
  1158. ((struct ipa_ioc_mdfy_flt_rule_v2 *)
  1159. header)->rule_mdfy_size,
  1160. ((struct ipa_ioc_mdfy_flt_rule_v2 *)
  1161. header)->rule_mdfy_size);
  1162. /* modify the rule pointer to the kernel pointer */
  1163. ((struct ipa_ioc_add_flt_rule_after_v2 *)header)->rules =
  1164. (u64)kptr;
  1165. if (ipa3_mdfy_flt_rule_v2
  1166. ((struct ipa_ioc_mdfy_flt_rule_v2 *)header)) {
  1167. IPAERR_RL("ipa3_mdfy_flt_rule_v2 fails\n");
  1168. retval = -EPERM;
  1169. goto free_param_kptr;
  1170. }
  1171. for (i = 0; i < pre_entry; i++)
  1172. memcpy((void *)param + i *
  1173. ((struct ipa_ioc_mdfy_flt_rule_v2 *)
  1174. header)->rule_mdfy_size,
  1175. kptr + i * sizeof(struct ipa_flt_rule_mdfy_i),
  1176. ((struct ipa_ioc_mdfy_flt_rule_v2 *)
  1177. header)->rule_mdfy_size);
  1178. if (copy_to_user((void __user *)uptr, param,
  1179. usr_pyld_sz)) {
  1180. IPAERR_RL("copy_to_user fails\n");
  1181. retval = -EFAULT;
  1182. goto free_param_kptr;
  1183. }
  1184. free_param_kptr:
  1185. if (!IS_ERR(param))
  1186. kfree(param);
  1187. kfree(kptr);
  1188. return retval;
  1189. }
  1190. static int ipa3_ioctl_fnr_counter_alloc(unsigned long arg)
  1191. {
  1192. int retval = 0;
  1193. u8 header[128] = { 0 };
  1194. if (copy_from_user(header, (const void __user *)arg,
  1195. sizeof(struct ipa_ioc_flt_rt_counter_alloc))) {
  1196. IPAERR("copy_from_user fails\n");
  1197. return -EFAULT;
  1198. }
  1199. if (((struct ipa_ioc_flt_rt_counter_alloc *)
  1200. header)->hw_counter.num_counters >
  1201. IPA_FLT_RT_HW_COUNTER ||
  1202. ((struct ipa_ioc_flt_rt_counter_alloc *)
  1203. header)->sw_counter.num_counters >
  1204. IPA_FLT_RT_SW_COUNTER) {
  1205. IPAERR("failed: wrong sw/hw num_counters\n");
  1206. return -EPERM;
  1207. }
  1208. if (((struct ipa_ioc_flt_rt_counter_alloc *)
  1209. header)->hw_counter.num_counters == 0 &&
  1210. ((struct ipa_ioc_flt_rt_counter_alloc *)
  1211. header)->sw_counter.num_counters == 0) {
  1212. IPAERR("failed: both sw/hw num_counters 0\n");
  1213. return -EPERM;
  1214. }
  1215. retval = ipa3_alloc_counter_id
  1216. ((struct ipa_ioc_flt_rt_counter_alloc *)header);
  1217. if (retval < 0) {
  1218. IPAERR("ipa3_alloc_counter_id failed\n");
  1219. return retval;
  1220. }
  1221. if (copy_to_user((void __user *)arg, header,
  1222. sizeof(struct ipa_ioc_flt_rt_counter_alloc))) {
  1223. IPAERR("copy_to_user fails\n");
  1224. ipa3_counter_remove_hdl(
  1225. ((struct ipa_ioc_flt_rt_counter_alloc *)
  1226. header)->hdl);
  1227. return -EFAULT;
  1228. }
  1229. return 0;
  1230. }
  1231. static int ipa3_ioctl_fnr_counter_query(unsigned long arg)
  1232. {
  1233. int retval = 0;
  1234. int i;
  1235. u8 header[128] = { 0 };
  1236. int pre_entry;
  1237. u32 usr_pyld_sz;
  1238. u32 pyld_sz;
  1239. u64 uptr = 0;
  1240. u8 *param = NULL;
  1241. u8 *kptr = NULL;
  1242. if (copy_from_user(header, (const void __user *)arg,
  1243. sizeof(struct ipa_ioc_flt_rt_query))) {
  1244. IPAERR_RL("copy_from_user fails\n");
  1245. retval = -EFAULT;
  1246. goto free_param_kptr;
  1247. }
  1248. pre_entry =
  1249. ((struct ipa_ioc_flt_rt_query *)
  1250. header)->end_id - ((struct ipa_ioc_flt_rt_query *)
  1251. header)->start_id + 1;
  1252. if (pre_entry <= 0 || pre_entry > IPA_MAX_FLT_RT_CNT_INDEX) {
  1253. IPAERR("IPA_IOC_FNR_COUNTER_QUERY failed: num %d\n",
  1254. pre_entry);
  1255. retval = -EPERM;
  1256. goto free_param_kptr;
  1257. }
  1258. if (((struct ipa_ioc_flt_rt_query *)header)->stats_size
  1259. > sizeof(struct ipa_flt_rt_stats)) {
  1260. IPAERR_RL("unexpected stats_size %d\n",
  1261. ((struct ipa_ioc_flt_rt_query *)header)->stats_size);
  1262. retval = -EPERM;
  1263. goto free_param_kptr;
  1264. }
  1265. /* user payload size */
  1266. usr_pyld_sz = ((struct ipa_ioc_flt_rt_query *)
  1267. header)->stats_size * pre_entry;
  1268. /* actual payload structure size in kernel */
  1269. pyld_sz = sizeof(struct ipa_flt_rt_stats) * pre_entry;
  1270. uptr = ((struct ipa_ioc_flt_rt_query *)
  1271. header)->stats;
  1272. if (unlikely(!uptr)) {
  1273. IPAERR_RL("unexpected NULL rules\n");
  1274. retval = -EPERM;
  1275. goto free_param_kptr;
  1276. }
  1277. /* alloc param with same payload size as user payload */
  1278. param = memdup_user((const void __user *)uptr,
  1279. usr_pyld_sz);
  1280. if (IS_ERR(param)) {
  1281. retval = -EFAULT;
  1282. goto free_param_kptr;
  1283. }
  1284. /* alloc kernel pointer with actual payload size */
  1285. kptr = kzalloc(pyld_sz, GFP_KERNEL);
  1286. if (!kptr) {
  1287. retval = -ENOMEM;
  1288. goto free_param_kptr;
  1289. }
  1290. for (i = 0; i < pre_entry; i++)
  1291. memcpy(kptr + i * sizeof(struct ipa_flt_rt_stats),
  1292. (void *)param + i *
  1293. ((struct ipa_ioc_flt_rt_query *)
  1294. header)->stats_size,
  1295. ((struct ipa_ioc_flt_rt_query *)
  1296. header)->stats_size);
  1297. /* modify the rule pointer to the kernel pointer */
  1298. ((struct ipa_ioc_flt_rt_query *)
  1299. header)->stats = (u64)kptr;
  1300. retval = ipa_get_flt_rt_stats
  1301. ((struct ipa_ioc_flt_rt_query *)header);
  1302. if (retval < 0) {
  1303. IPAERR("ipa_get_flt_rt_stats failed\n");
  1304. retval = -EPERM;
  1305. goto free_param_kptr;
  1306. }
  1307. for (i = 0; i < pre_entry; i++)
  1308. memcpy((void *)param + i *
  1309. ((struct ipa_ioc_flt_rt_query *)
  1310. header)->stats_size,
  1311. kptr + i * sizeof(struct ipa_flt_rt_stats),
  1312. ((struct ipa_ioc_flt_rt_query *)
  1313. header)->stats_size);
  1314. if (copy_to_user((void __user *)uptr, param,
  1315. usr_pyld_sz)) {
  1316. IPAERR_RL("copy_to_user fails\n");
  1317. retval = -EFAULT;
  1318. goto free_param_kptr;
  1319. }
  1320. free_param_kptr:
  1321. if (!IS_ERR(param))
  1322. kfree(param);
  1323. kfree(kptr);
  1324. return retval;
  1325. }
  1326. static long ipa3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  1327. {
  1328. int retval = 0;
  1329. u32 pyld_sz;
  1330. u8 header[128] = { 0 };
  1331. u8 *param = NULL;
  1332. bool is_vlan_mode;
  1333. struct ipa_ioc_nat_alloc_mem nat_mem;
  1334. struct ipa_ioc_nat_ipv6ct_table_alloc table_alloc;
  1335. struct ipa_ioc_v4_nat_init nat_init;
  1336. struct ipa_ioc_ipv6ct_init ipv6ct_init;
  1337. struct ipa_ioc_v4_nat_del nat_del;
  1338. struct ipa_ioc_nat_ipv6ct_table_del table_del;
  1339. struct ipa_ioc_nat_pdn_entry mdfy_pdn;
  1340. struct ipa_ioc_nat_dma_cmd *table_dma_cmd;
  1341. struct ipa_ioc_get_vlan_mode vlan_mode;
  1342. struct ipa_ioc_wigig_fst_switch fst_switch;
  1343. size_t sz;
  1344. int pre_entry;
  1345. int hdl;
  1346. IPADBG("cmd=%x nr=%d\n", cmd, _IOC_NR(cmd));
  1347. if (_IOC_TYPE(cmd) != IPA_IOC_MAGIC)
  1348. return -ENOTTY;
  1349. if (!ipa3_is_ready()) {
  1350. IPAERR("IPA not ready, waiting for init completion\n");
  1351. wait_for_completion(&ipa3_ctx->init_completion_obj);
  1352. }
  1353. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  1354. switch (cmd) {
  1355. case IPA_IOC_ALLOC_NAT_MEM:
  1356. if (copy_from_user(&nat_mem, (const void __user *)arg,
  1357. sizeof(struct ipa_ioc_nat_alloc_mem))) {
  1358. retval = -EFAULT;
  1359. break;
  1360. }
  1361. /* null terminate the string */
  1362. nat_mem.dev_name[IPA_RESOURCE_NAME_MAX - 1] = '\0';
  1363. if (ipa3_allocate_nat_device(&nat_mem)) {
  1364. retval = -EFAULT;
  1365. break;
  1366. }
  1367. if (copy_to_user((void __user *)arg, &nat_mem,
  1368. sizeof(struct ipa_ioc_nat_alloc_mem))) {
  1369. retval = -EFAULT;
  1370. break;
  1371. }
  1372. break;
  1373. case IPA_IOC_ALLOC_NAT_TABLE:
  1374. if (copy_from_user(&table_alloc, (const void __user *)arg,
  1375. sizeof(struct ipa_ioc_nat_ipv6ct_table_alloc))) {
  1376. retval = -EFAULT;
  1377. break;
  1378. }
  1379. if (ipa3_allocate_nat_table(&table_alloc)) {
  1380. retval = -EFAULT;
  1381. break;
  1382. }
  1383. if (table_alloc.offset &&
  1384. copy_to_user((void __user *)arg, &table_alloc, sizeof(
  1385. struct ipa_ioc_nat_ipv6ct_table_alloc))) {
  1386. retval = -EFAULT;
  1387. break;
  1388. }
  1389. break;
  1390. case IPA_IOC_ALLOC_IPV6CT_TABLE:
  1391. if (copy_from_user(&table_alloc, (const void __user *)arg,
  1392. sizeof(struct ipa_ioc_nat_ipv6ct_table_alloc))) {
  1393. retval = -EFAULT;
  1394. break;
  1395. }
  1396. if (ipa3_allocate_ipv6ct_table(&table_alloc)) {
  1397. retval = -EFAULT;
  1398. break;
  1399. }
  1400. if (table_alloc.offset &&
  1401. copy_to_user((void __user *)arg, &table_alloc, sizeof(
  1402. struct ipa_ioc_nat_ipv6ct_table_alloc))) {
  1403. retval = -EFAULT;
  1404. break;
  1405. }
  1406. break;
  1407. case IPA_IOC_V4_INIT_NAT:
  1408. if (copy_from_user(&nat_init, (const void __user *)arg,
  1409. sizeof(struct ipa_ioc_v4_nat_init))) {
  1410. retval = -EFAULT;
  1411. break;
  1412. }
  1413. if (ipa3_nat_init_cmd(&nat_init)) {
  1414. retval = -EFAULT;
  1415. break;
  1416. }
  1417. break;
  1418. case IPA_IOC_INIT_IPV6CT_TABLE:
  1419. if (copy_from_user(&ipv6ct_init, (const void __user *)arg,
  1420. sizeof(struct ipa_ioc_ipv6ct_init))) {
  1421. retval = -EFAULT;
  1422. break;
  1423. }
  1424. if (ipa3_ipv6ct_init_cmd(&ipv6ct_init)) {
  1425. retval = -EFAULT;
  1426. break;
  1427. }
  1428. break;
  1429. case IPA_IOC_TABLE_DMA_CMD:
  1430. table_dma_cmd = (struct ipa_ioc_nat_dma_cmd *)header;
  1431. if (copy_from_user(header, (const void __user *)arg,
  1432. sizeof(struct ipa_ioc_nat_dma_cmd))) {
  1433. retval = -EFAULT;
  1434. break;
  1435. }
  1436. pre_entry = table_dma_cmd->entries;
  1437. pyld_sz = sizeof(struct ipa_ioc_nat_dma_cmd) +
  1438. pre_entry * sizeof(struct ipa_ioc_nat_dma_one);
  1439. param = memdup_user((const void __user *)arg, pyld_sz);
  1440. if (IS_ERR(param)) {
  1441. retval = PTR_ERR(param);
  1442. break;
  1443. }
  1444. table_dma_cmd = (struct ipa_ioc_nat_dma_cmd *)param;
  1445. /* add check in case user-space module compromised */
  1446. if (unlikely(table_dma_cmd->entries != pre_entry)) {
  1447. IPAERR_RL("current %d pre %d\n",
  1448. table_dma_cmd->entries, pre_entry);
  1449. retval = -EFAULT;
  1450. break;
  1451. }
  1452. if (ipa3_table_dma_cmd(table_dma_cmd)) {
  1453. retval = -EFAULT;
  1454. break;
  1455. }
  1456. break;
  1457. case IPA_IOC_V4_DEL_NAT:
  1458. if (copy_from_user(&nat_del, (const void __user *)arg,
  1459. sizeof(struct ipa_ioc_v4_nat_del))) {
  1460. retval = -EFAULT;
  1461. break;
  1462. }
  1463. if (ipa3_nat_del_cmd(&nat_del)) {
  1464. retval = -EFAULT;
  1465. break;
  1466. }
  1467. break;
  1468. case IPA_IOC_DEL_NAT_TABLE:
  1469. if (copy_from_user(&table_del, (const void __user *)arg,
  1470. sizeof(struct ipa_ioc_nat_ipv6ct_table_del))) {
  1471. retval = -EFAULT;
  1472. break;
  1473. }
  1474. if (ipa3_del_nat_table(&table_del)) {
  1475. retval = -EFAULT;
  1476. break;
  1477. }
  1478. break;
  1479. case IPA_IOC_DEL_IPV6CT_TABLE:
  1480. if (copy_from_user(&table_del, (const void __user *)arg,
  1481. sizeof(struct ipa_ioc_nat_ipv6ct_table_del))) {
  1482. retval = -EFAULT;
  1483. break;
  1484. }
  1485. if (ipa3_del_ipv6ct_table(&table_del)) {
  1486. retval = -EFAULT;
  1487. break;
  1488. }
  1489. break;
  1490. case IPA_IOC_NAT_MODIFY_PDN:
  1491. if (copy_from_user(&mdfy_pdn, (const void __user *)arg,
  1492. sizeof(struct ipa_ioc_nat_pdn_entry))) {
  1493. retval = -EFAULT;
  1494. break;
  1495. }
  1496. if (ipa3_nat_mdfy_pdn(&mdfy_pdn)) {
  1497. retval = -EFAULT;
  1498. break;
  1499. }
  1500. break;
  1501. case IPA_IOC_ADD_HDR:
  1502. if (copy_from_user(header, (const void __user *)arg,
  1503. sizeof(struct ipa_ioc_add_hdr))) {
  1504. retval = -EFAULT;
  1505. break;
  1506. }
  1507. pre_entry =
  1508. ((struct ipa_ioc_add_hdr *)header)->num_hdrs;
  1509. pyld_sz =
  1510. sizeof(struct ipa_ioc_add_hdr) +
  1511. pre_entry * sizeof(struct ipa_hdr_add);
  1512. param = memdup_user((const void __user *)arg, pyld_sz);
  1513. if (IS_ERR(param)) {
  1514. retval = PTR_ERR(param);
  1515. break;
  1516. }
  1517. /* add check in case user-space module compromised */
  1518. if (unlikely(((struct ipa_ioc_add_hdr *)param)->num_hdrs
  1519. != pre_entry)) {
  1520. IPAERR_RL("current %d pre %d\n",
  1521. ((struct ipa_ioc_add_hdr *)param)->num_hdrs,
  1522. pre_entry);
  1523. retval = -EFAULT;
  1524. break;
  1525. }
  1526. if (ipa3_add_hdr_usr((struct ipa_ioc_add_hdr *)param,
  1527. true)) {
  1528. retval = -EFAULT;
  1529. break;
  1530. }
  1531. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  1532. retval = -EFAULT;
  1533. break;
  1534. }
  1535. break;
  1536. case IPA_IOC_DEL_HDR:
  1537. if (copy_from_user(header, (const void __user *)arg,
  1538. sizeof(struct ipa_ioc_del_hdr))) {
  1539. retval = -EFAULT;
  1540. break;
  1541. }
  1542. pre_entry =
  1543. ((struct ipa_ioc_del_hdr *)header)->num_hdls;
  1544. pyld_sz =
  1545. sizeof(struct ipa_ioc_del_hdr) +
  1546. pre_entry * sizeof(struct ipa_hdr_del);
  1547. param = memdup_user((const void __user *)arg, pyld_sz);
  1548. if (IS_ERR(param)) {
  1549. retval = PTR_ERR(param);
  1550. break;
  1551. }
  1552. /* add check in case user-space module compromised */
  1553. if (unlikely(((struct ipa_ioc_del_hdr *)param)->num_hdls
  1554. != pre_entry)) {
  1555. IPAERR_RL("current %d pre %d\n",
  1556. ((struct ipa_ioc_del_hdr *)param)->num_hdls,
  1557. pre_entry);
  1558. retval = -EFAULT;
  1559. break;
  1560. }
  1561. if (ipa3_del_hdr_by_user((struct ipa_ioc_del_hdr *)param,
  1562. true)) {
  1563. retval = -EFAULT;
  1564. break;
  1565. }
  1566. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  1567. retval = -EFAULT;
  1568. break;
  1569. }
  1570. break;
  1571. case IPA_IOC_ADD_RT_RULE:
  1572. if (copy_from_user(header, (const void __user *)arg,
  1573. sizeof(struct ipa_ioc_add_rt_rule))) {
  1574. retval = -EFAULT;
  1575. break;
  1576. }
  1577. pre_entry =
  1578. ((struct ipa_ioc_add_rt_rule *)header)->num_rules;
  1579. pyld_sz =
  1580. sizeof(struct ipa_ioc_add_rt_rule) +
  1581. pre_entry * sizeof(struct ipa_rt_rule_add);
  1582. param = memdup_user((const void __user *)arg, pyld_sz);
  1583. if (IS_ERR(param)) {
  1584. retval = PTR_ERR(param);
  1585. break;
  1586. }
  1587. /* add check in case user-space module compromised */
  1588. if (unlikely(((struct ipa_ioc_add_rt_rule *)param)->num_rules
  1589. != pre_entry)) {
  1590. IPAERR_RL("current %d pre %d\n",
  1591. ((struct ipa_ioc_add_rt_rule *)param)->
  1592. num_rules,
  1593. pre_entry);
  1594. retval = -EFAULT;
  1595. break;
  1596. }
  1597. if (ipa3_add_rt_rule_usr((struct ipa_ioc_add_rt_rule *)param,
  1598. true)) {
  1599. retval = -EFAULT;
  1600. break;
  1601. }
  1602. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  1603. retval = -EFAULT;
  1604. break;
  1605. }
  1606. break;
  1607. case IPA_IOC_ADD_RT_RULE_EXT:
  1608. if (copy_from_user(header,
  1609. (const void __user *)arg,
  1610. sizeof(struct ipa_ioc_add_rt_rule_ext))) {
  1611. retval = -EFAULT;
  1612. break;
  1613. }
  1614. pre_entry =
  1615. ((struct ipa_ioc_add_rt_rule_ext *)header)->num_rules;
  1616. pyld_sz =
  1617. sizeof(struct ipa_ioc_add_rt_rule_ext) +
  1618. pre_entry * sizeof(struct ipa_rt_rule_add_ext);
  1619. param = memdup_user((const void __user *)arg, pyld_sz);
  1620. if (IS_ERR(param)) {
  1621. retval = PTR_ERR(param);
  1622. break;
  1623. }
  1624. /* add check in case user-space module compromised */
  1625. if (unlikely(
  1626. ((struct ipa_ioc_add_rt_rule_ext *)param)->num_rules
  1627. != pre_entry)) {
  1628. IPAERR(" prevent memory corruption(%d not match %d)\n",
  1629. ((struct ipa_ioc_add_rt_rule_ext *)param)->
  1630. num_rules,
  1631. pre_entry);
  1632. retval = -EINVAL;
  1633. break;
  1634. }
  1635. if (ipa3_add_rt_rule_ext(
  1636. (struct ipa_ioc_add_rt_rule_ext *)param)) {
  1637. retval = -EFAULT;
  1638. break;
  1639. }
  1640. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  1641. retval = -EFAULT;
  1642. break;
  1643. }
  1644. break;
  1645. case IPA_IOC_ADD_RT_RULE_AFTER:
  1646. if (copy_from_user(header, (const void __user *)arg,
  1647. sizeof(struct ipa_ioc_add_rt_rule_after))) {
  1648. retval = -EFAULT;
  1649. break;
  1650. }
  1651. pre_entry =
  1652. ((struct ipa_ioc_add_rt_rule_after *)header)->num_rules;
  1653. pyld_sz =
  1654. sizeof(struct ipa_ioc_add_rt_rule_after) +
  1655. pre_entry * sizeof(struct ipa_rt_rule_add);
  1656. param = memdup_user((const void __user *)arg, pyld_sz);
  1657. if (IS_ERR(param)) {
  1658. retval = PTR_ERR(param);
  1659. break;
  1660. }
  1661. /* add check in case user-space module compromised */
  1662. if (unlikely(((struct ipa_ioc_add_rt_rule_after *)param)->
  1663. num_rules != pre_entry)) {
  1664. IPAERR_RL("current %d pre %d\n",
  1665. ((struct ipa_ioc_add_rt_rule_after *)param)->
  1666. num_rules,
  1667. pre_entry);
  1668. retval = -EFAULT;
  1669. break;
  1670. }
  1671. if (ipa3_add_rt_rule_after(
  1672. (struct ipa_ioc_add_rt_rule_after *)param)) {
  1673. retval = -EFAULT;
  1674. break;
  1675. }
  1676. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  1677. retval = -EFAULT;
  1678. break;
  1679. }
  1680. break;
  1681. case IPA_IOC_MDFY_RT_RULE:
  1682. if (copy_from_user(header, (const void __user *)arg,
  1683. sizeof(struct ipa_ioc_mdfy_rt_rule))) {
  1684. retval = -EFAULT;
  1685. break;
  1686. }
  1687. pre_entry =
  1688. ((struct ipa_ioc_mdfy_rt_rule *)header)->num_rules;
  1689. pyld_sz =
  1690. sizeof(struct ipa_ioc_mdfy_rt_rule) +
  1691. pre_entry * sizeof(struct ipa_rt_rule_mdfy);
  1692. param = memdup_user((const void __user *)arg, pyld_sz);
  1693. if (IS_ERR(param)) {
  1694. retval = PTR_ERR(param);
  1695. break;
  1696. }
  1697. /* add check in case user-space module compromised */
  1698. if (unlikely(((struct ipa_ioc_mdfy_rt_rule *)param)->num_rules
  1699. != pre_entry)) {
  1700. IPAERR_RL("current %d pre %d\n",
  1701. ((struct ipa_ioc_mdfy_rt_rule *)param)->
  1702. num_rules,
  1703. pre_entry);
  1704. retval = -EFAULT;
  1705. break;
  1706. }
  1707. if (ipa3_mdfy_rt_rule((struct ipa_ioc_mdfy_rt_rule *)param)) {
  1708. retval = -EFAULT;
  1709. break;
  1710. }
  1711. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  1712. retval = -EFAULT;
  1713. break;
  1714. }
  1715. break;
  1716. case IPA_IOC_DEL_RT_RULE:
  1717. if (copy_from_user(header, (const void __user *)arg,
  1718. sizeof(struct ipa_ioc_del_rt_rule))) {
  1719. retval = -EFAULT;
  1720. break;
  1721. }
  1722. pre_entry =
  1723. ((struct ipa_ioc_del_rt_rule *)header)->num_hdls;
  1724. pyld_sz =
  1725. sizeof(struct ipa_ioc_del_rt_rule) +
  1726. pre_entry * sizeof(struct ipa_rt_rule_del);
  1727. param = memdup_user((const void __user *)arg, pyld_sz);
  1728. if (IS_ERR(param)) {
  1729. retval = PTR_ERR(param);
  1730. break;
  1731. }
  1732. /* add check in case user-space module compromised */
  1733. if (unlikely(((struct ipa_ioc_del_rt_rule *)param)->num_hdls
  1734. != pre_entry)) {
  1735. IPAERR_RL("current %d pre %d\n",
  1736. ((struct ipa_ioc_del_rt_rule *)param)->num_hdls,
  1737. pre_entry);
  1738. retval = -EFAULT;
  1739. break;
  1740. }
  1741. if (ipa3_del_rt_rule((struct ipa_ioc_del_rt_rule *)param)) {
  1742. retval = -EFAULT;
  1743. break;
  1744. }
  1745. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  1746. retval = -EFAULT;
  1747. break;
  1748. }
  1749. break;
  1750. case IPA_IOC_ADD_FLT_RULE:
  1751. if (copy_from_user(header, (const void __user *)arg,
  1752. sizeof(struct ipa_ioc_add_flt_rule))) {
  1753. retval = -EFAULT;
  1754. break;
  1755. }
  1756. pre_entry =
  1757. ((struct ipa_ioc_add_flt_rule *)header)->num_rules;
  1758. pyld_sz =
  1759. sizeof(struct ipa_ioc_add_flt_rule) +
  1760. pre_entry * sizeof(struct ipa_flt_rule_add);
  1761. param = memdup_user((const void __user *)arg, pyld_sz);
  1762. if (IS_ERR(param)) {
  1763. retval = PTR_ERR(param);
  1764. break;
  1765. }
  1766. /* add check in case user-space module compromised */
  1767. if (unlikely(((struct ipa_ioc_add_flt_rule *)param)->num_rules
  1768. != pre_entry)) {
  1769. IPAERR_RL("current %d pre %d\n",
  1770. ((struct ipa_ioc_add_flt_rule *)param)->
  1771. num_rules,
  1772. pre_entry);
  1773. retval = -EFAULT;
  1774. break;
  1775. }
  1776. if (ipa3_add_flt_rule_usr((struct ipa_ioc_add_flt_rule *)param,
  1777. true)) {
  1778. retval = -EFAULT;
  1779. break;
  1780. }
  1781. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  1782. retval = -EFAULT;
  1783. break;
  1784. }
  1785. break;
  1786. case IPA_IOC_ADD_FLT_RULE_AFTER:
  1787. if (copy_from_user(header, (const void __user *)arg,
  1788. sizeof(struct ipa_ioc_add_flt_rule_after))) {
  1789. retval = -EFAULT;
  1790. break;
  1791. }
  1792. pre_entry =
  1793. ((struct ipa_ioc_add_flt_rule_after *)header)->
  1794. num_rules;
  1795. pyld_sz =
  1796. sizeof(struct ipa_ioc_add_flt_rule_after) +
  1797. pre_entry * sizeof(struct ipa_flt_rule_add);
  1798. param = memdup_user((const void __user *)arg, pyld_sz);
  1799. if (IS_ERR(param)) {
  1800. retval = PTR_ERR(param);
  1801. break;
  1802. }
  1803. /* add check in case user-space module compromised */
  1804. if (unlikely(((struct ipa_ioc_add_flt_rule_after *)param)->
  1805. num_rules != pre_entry)) {
  1806. IPAERR_RL("current %d pre %d\n",
  1807. ((struct ipa_ioc_add_flt_rule_after *)param)->
  1808. num_rules,
  1809. pre_entry);
  1810. retval = -EFAULT;
  1811. break;
  1812. }
  1813. if (ipa3_add_flt_rule_after(
  1814. (struct ipa_ioc_add_flt_rule_after *)param)) {
  1815. retval = -EFAULT;
  1816. break;
  1817. }
  1818. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  1819. retval = -EFAULT;
  1820. break;
  1821. }
  1822. break;
  1823. case IPA_IOC_DEL_FLT_RULE:
  1824. if (copy_from_user(header, (const void __user *)arg,
  1825. sizeof(struct ipa_ioc_del_flt_rule))) {
  1826. retval = -EFAULT;
  1827. break;
  1828. }
  1829. pre_entry =
  1830. ((struct ipa_ioc_del_flt_rule *)header)->num_hdls;
  1831. pyld_sz =
  1832. sizeof(struct ipa_ioc_del_flt_rule) +
  1833. pre_entry * sizeof(struct ipa_flt_rule_del);
  1834. param = memdup_user((const void __user *)arg, pyld_sz);
  1835. if (IS_ERR(param)) {
  1836. retval = PTR_ERR(param);
  1837. break;
  1838. }
  1839. /* add check in case user-space module compromised */
  1840. if (unlikely(((struct ipa_ioc_del_flt_rule *)param)->num_hdls
  1841. != pre_entry)) {
  1842. IPAERR_RL("current %d pre %d\n",
  1843. ((struct ipa_ioc_del_flt_rule *)param)->
  1844. num_hdls,
  1845. pre_entry);
  1846. retval = -EFAULT;
  1847. break;
  1848. }
  1849. if (ipa3_del_flt_rule((struct ipa_ioc_del_flt_rule *)param)) {
  1850. retval = -EFAULT;
  1851. break;
  1852. }
  1853. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  1854. retval = -EFAULT;
  1855. break;
  1856. }
  1857. break;
  1858. case IPA_IOC_MDFY_FLT_RULE:
  1859. if (copy_from_user(header, (const void __user *)arg,
  1860. sizeof(struct ipa_ioc_mdfy_flt_rule))) {
  1861. retval = -EFAULT;
  1862. break;
  1863. }
  1864. pre_entry =
  1865. ((struct ipa_ioc_mdfy_flt_rule *)header)->num_rules;
  1866. pyld_sz =
  1867. sizeof(struct ipa_ioc_mdfy_flt_rule) +
  1868. pre_entry * sizeof(struct ipa_flt_rule_mdfy);
  1869. param = memdup_user((const void __user *)arg, pyld_sz);
  1870. if (IS_ERR(param)) {
  1871. retval = PTR_ERR(param);
  1872. break;
  1873. }
  1874. /* add check in case user-space module compromised */
  1875. if (unlikely(((struct ipa_ioc_mdfy_flt_rule *)param)->num_rules
  1876. != pre_entry)) {
  1877. IPAERR_RL("current %d pre %d\n",
  1878. ((struct ipa_ioc_mdfy_flt_rule *)param)->
  1879. num_rules,
  1880. pre_entry);
  1881. retval = -EFAULT;
  1882. break;
  1883. }
  1884. if (ipa3_mdfy_flt_rule((struct ipa_ioc_mdfy_flt_rule *)param)) {
  1885. retval = -EFAULT;
  1886. break;
  1887. }
  1888. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  1889. retval = -EFAULT;
  1890. break;
  1891. }
  1892. break;
  1893. case IPA_IOC_COMMIT_HDR:
  1894. retval = ipa3_commit_hdr();
  1895. break;
  1896. case IPA_IOC_RESET_HDR:
  1897. retval = ipa3_reset_hdr(false);
  1898. break;
  1899. case IPA_IOC_COMMIT_RT:
  1900. retval = ipa3_commit_rt(arg);
  1901. break;
  1902. case IPA_IOC_RESET_RT:
  1903. retval = ipa3_reset_rt(arg, false);
  1904. break;
  1905. case IPA_IOC_COMMIT_FLT:
  1906. retval = ipa3_commit_flt(arg);
  1907. break;
  1908. case IPA_IOC_RESET_FLT:
  1909. retval = ipa3_reset_flt(arg, false);
  1910. break;
  1911. case IPA_IOC_GET_RT_TBL:
  1912. if (copy_from_user(header, (const void __user *)arg,
  1913. sizeof(struct ipa_ioc_get_rt_tbl))) {
  1914. retval = -EFAULT;
  1915. break;
  1916. }
  1917. if (ipa3_get_rt_tbl((struct ipa_ioc_get_rt_tbl *)header)) {
  1918. retval = -EFAULT;
  1919. break;
  1920. }
  1921. if (copy_to_user((void __user *)arg, header,
  1922. sizeof(struct ipa_ioc_get_rt_tbl))) {
  1923. retval = -EFAULT;
  1924. break;
  1925. }
  1926. break;
  1927. case IPA_IOC_PUT_RT_TBL:
  1928. retval = ipa3_put_rt_tbl(arg);
  1929. break;
  1930. case IPA_IOC_GET_HDR:
  1931. if (copy_from_user(header, (const void __user *)arg,
  1932. sizeof(struct ipa_ioc_get_hdr))) {
  1933. retval = -EFAULT;
  1934. break;
  1935. }
  1936. if (ipa3_get_hdr((struct ipa_ioc_get_hdr *)header)) {
  1937. retval = -EFAULT;
  1938. break;
  1939. }
  1940. if (copy_to_user((void __user *)arg, header,
  1941. sizeof(struct ipa_ioc_get_hdr))) {
  1942. retval = -EFAULT;
  1943. break;
  1944. }
  1945. break;
  1946. case IPA_IOC_PUT_HDR:
  1947. retval = ipa3_put_hdr(arg);
  1948. break;
  1949. case IPA_IOC_SET_FLT:
  1950. retval = ipa3_cfg_filter(arg);
  1951. break;
  1952. case IPA_IOC_COPY_HDR:
  1953. if (copy_from_user(header, (const void __user *)arg,
  1954. sizeof(struct ipa_ioc_copy_hdr))) {
  1955. retval = -EFAULT;
  1956. break;
  1957. }
  1958. if (ipa3_copy_hdr((struct ipa_ioc_copy_hdr *)header)) {
  1959. retval = -EFAULT;
  1960. break;
  1961. }
  1962. if (copy_to_user((void __user *)arg, header,
  1963. sizeof(struct ipa_ioc_copy_hdr))) {
  1964. retval = -EFAULT;
  1965. break;
  1966. }
  1967. break;
  1968. case IPA_IOC_QUERY_INTF:
  1969. if (copy_from_user(header, (const void __user *)arg,
  1970. sizeof(struct ipa_ioc_query_intf))) {
  1971. retval = -EFAULT;
  1972. break;
  1973. }
  1974. if (ipa3_query_intf((struct ipa_ioc_query_intf *)header)) {
  1975. retval = -1;
  1976. break;
  1977. }
  1978. if (copy_to_user((void __user *)arg, header,
  1979. sizeof(struct ipa_ioc_query_intf))) {
  1980. retval = -EFAULT;
  1981. break;
  1982. }
  1983. break;
  1984. case IPA_IOC_QUERY_INTF_TX_PROPS:
  1985. sz = sizeof(struct ipa_ioc_query_intf_tx_props);
  1986. if (copy_from_user(header, (const void __user *)arg, sz)) {
  1987. retval = -EFAULT;
  1988. break;
  1989. }
  1990. if (((struct ipa_ioc_query_intf_tx_props *)header)->num_tx_props
  1991. > IPA_NUM_PROPS_MAX) {
  1992. retval = -EFAULT;
  1993. break;
  1994. }
  1995. pre_entry =
  1996. ((struct ipa_ioc_query_intf_tx_props *)
  1997. header)->num_tx_props;
  1998. pyld_sz = sz + pre_entry *
  1999. sizeof(struct ipa_ioc_tx_intf_prop);
  2000. param = memdup_user((const void __user *)arg, pyld_sz);
  2001. if (IS_ERR(param)) {
  2002. retval = PTR_ERR(param);
  2003. break;
  2004. }
  2005. /* add check in case user-space module compromised */
  2006. if (unlikely(((struct ipa_ioc_query_intf_tx_props *)
  2007. param)->num_tx_props
  2008. != pre_entry)) {
  2009. IPAERR_RL("current %d pre %d\n",
  2010. ((struct ipa_ioc_query_intf_tx_props *)
  2011. param)->num_tx_props, pre_entry);
  2012. retval = -EFAULT;
  2013. break;
  2014. }
  2015. if (ipa3_query_intf_tx_props(
  2016. (struct ipa_ioc_query_intf_tx_props *)param)) {
  2017. retval = -1;
  2018. break;
  2019. }
  2020. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  2021. retval = -EFAULT;
  2022. break;
  2023. }
  2024. break;
  2025. case IPA_IOC_QUERY_INTF_RX_PROPS:
  2026. sz = sizeof(struct ipa_ioc_query_intf_rx_props);
  2027. if (copy_from_user(header, (const void __user *)arg, sz)) {
  2028. retval = -EFAULT;
  2029. break;
  2030. }
  2031. if (((struct ipa_ioc_query_intf_rx_props *)header)->num_rx_props
  2032. > IPA_NUM_PROPS_MAX) {
  2033. retval = -EFAULT;
  2034. break;
  2035. }
  2036. pre_entry =
  2037. ((struct ipa_ioc_query_intf_rx_props *)
  2038. header)->num_rx_props;
  2039. pyld_sz = sz + pre_entry *
  2040. sizeof(struct ipa_ioc_rx_intf_prop);
  2041. param = memdup_user((const void __user *)arg, pyld_sz);
  2042. if (IS_ERR(param)) {
  2043. retval = PTR_ERR(param);
  2044. break;
  2045. }
  2046. /* add check in case user-space module compromised */
  2047. if (unlikely(((struct ipa_ioc_query_intf_rx_props *)
  2048. param)->num_rx_props != pre_entry)) {
  2049. IPAERR_RL("current %d pre %d\n",
  2050. ((struct ipa_ioc_query_intf_rx_props *)
  2051. param)->num_rx_props, pre_entry);
  2052. retval = -EFAULT;
  2053. break;
  2054. }
  2055. if (ipa3_query_intf_rx_props(
  2056. (struct ipa_ioc_query_intf_rx_props *)param)) {
  2057. retval = -1;
  2058. break;
  2059. }
  2060. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  2061. retval = -EFAULT;
  2062. break;
  2063. }
  2064. break;
  2065. case IPA_IOC_QUERY_INTF_EXT_PROPS:
  2066. sz = sizeof(struct ipa_ioc_query_intf_ext_props);
  2067. if (copy_from_user(header, (const void __user *)arg, sz)) {
  2068. retval = -EFAULT;
  2069. break;
  2070. }
  2071. if (((struct ipa_ioc_query_intf_ext_props *)
  2072. header)->num_ext_props > IPA_NUM_PROPS_MAX) {
  2073. retval = -EFAULT;
  2074. break;
  2075. }
  2076. pre_entry =
  2077. ((struct ipa_ioc_query_intf_ext_props *)
  2078. header)->num_ext_props;
  2079. pyld_sz = sz + pre_entry *
  2080. sizeof(struct ipa_ioc_ext_intf_prop);
  2081. param = memdup_user((const void __user *)arg, pyld_sz);
  2082. if (IS_ERR(param)) {
  2083. retval = PTR_ERR(param);
  2084. break;
  2085. }
  2086. /* add check in case user-space module compromised */
  2087. if (unlikely(((struct ipa_ioc_query_intf_ext_props *)
  2088. param)->num_ext_props != pre_entry)) {
  2089. IPAERR_RL("current %d pre %d\n",
  2090. ((struct ipa_ioc_query_intf_ext_props *)
  2091. param)->num_ext_props, pre_entry);
  2092. retval = -EFAULT;
  2093. break;
  2094. }
  2095. if (ipa3_query_intf_ext_props(
  2096. (struct ipa_ioc_query_intf_ext_props *)param)) {
  2097. retval = -1;
  2098. break;
  2099. }
  2100. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  2101. retval = -EFAULT;
  2102. break;
  2103. }
  2104. break;
  2105. case IPA_IOC_PULL_MSG:
  2106. if (copy_from_user(header, (const void __user *)arg,
  2107. sizeof(struct ipa_msg_meta))) {
  2108. retval = -EFAULT;
  2109. break;
  2110. }
  2111. pre_entry =
  2112. ((struct ipa_msg_meta *)header)->msg_len;
  2113. pyld_sz = sizeof(struct ipa_msg_meta) +
  2114. pre_entry;
  2115. param = memdup_user((const void __user *)arg, pyld_sz);
  2116. if (IS_ERR(param)) {
  2117. retval = PTR_ERR(param);
  2118. break;
  2119. }
  2120. /* add check in case user-space module compromised */
  2121. if (unlikely(((struct ipa_msg_meta *)param)->msg_len
  2122. != pre_entry)) {
  2123. IPAERR_RL("current %d pre %d\n",
  2124. ((struct ipa_msg_meta *)param)->msg_len,
  2125. pre_entry);
  2126. retval = -EFAULT;
  2127. break;
  2128. }
  2129. if (ipa3_pull_msg((struct ipa_msg_meta *)param,
  2130. (char *)param + sizeof(struct ipa_msg_meta),
  2131. ((struct ipa_msg_meta *)param)->msg_len) !=
  2132. ((struct ipa_msg_meta *)param)->msg_len) {
  2133. retval = -1;
  2134. break;
  2135. }
  2136. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  2137. retval = -EFAULT;
  2138. break;
  2139. }
  2140. break;
  2141. case IPA_IOC_RM_ADD_DEPENDENCY:
  2142. /* IPA RM is deprecate because IPA PM is used */
  2143. IPAERR("using obselete command: IPA_IOC_RM_ADD_DEPENDENCY");
  2144. return -EINVAL;
  2145. case IPA_IOC_RM_DEL_DEPENDENCY:
  2146. /* IPA RM is deprecate because IPA PM is used */
  2147. IPAERR("using obselete command: IPA_IOC_RM_DEL_DEPENDENCY");
  2148. return -EINVAL;
  2149. case IPA_IOC_GENERATE_FLT_EQ:
  2150. {
  2151. struct ipa_ioc_generate_flt_eq flt_eq;
  2152. if (copy_from_user(&flt_eq, (const void __user *)arg,
  2153. sizeof(struct ipa_ioc_generate_flt_eq))) {
  2154. retval = -EFAULT;
  2155. break;
  2156. }
  2157. if (ipahal_flt_generate_equation(flt_eq.ip,
  2158. &flt_eq.attrib, &flt_eq.eq_attrib)) {
  2159. retval = -EFAULT;
  2160. break;
  2161. }
  2162. if (copy_to_user((void __user *)arg, &flt_eq,
  2163. sizeof(struct ipa_ioc_generate_flt_eq))) {
  2164. retval = -EFAULT;
  2165. break;
  2166. }
  2167. break;
  2168. }
  2169. case IPA_IOC_QUERY_EP_MAPPING:
  2170. {
  2171. retval = ipa3_get_ep_mapping(arg);
  2172. break;
  2173. }
  2174. case IPA_IOC_QUERY_RT_TBL_INDEX:
  2175. if (copy_from_user(header, (const void __user *)arg,
  2176. sizeof(struct ipa_ioc_get_rt_tbl_indx))) {
  2177. retval = -EFAULT;
  2178. break;
  2179. }
  2180. if (ipa3_query_rt_index(
  2181. (struct ipa_ioc_get_rt_tbl_indx *)header)) {
  2182. retval = -EFAULT;
  2183. break;
  2184. }
  2185. if (copy_to_user((void __user *)arg, header,
  2186. sizeof(struct ipa_ioc_get_rt_tbl_indx))) {
  2187. retval = -EFAULT;
  2188. break;
  2189. }
  2190. break;
  2191. case IPA_IOC_WRITE_QMAPID:
  2192. if (copy_from_user(header, (const void __user *)arg,
  2193. sizeof(struct ipa_ioc_write_qmapid))) {
  2194. retval = -EFAULT;
  2195. break;
  2196. }
  2197. if (ipa3_write_qmap_id((struct ipa_ioc_write_qmapid *)header)) {
  2198. retval = -EFAULT;
  2199. break;
  2200. }
  2201. if (copy_to_user((void __user *)arg, header,
  2202. sizeof(struct ipa_ioc_write_qmapid))) {
  2203. retval = -EFAULT;
  2204. break;
  2205. }
  2206. break;
  2207. case IPA_IOC_NOTIFY_WAN_UPSTREAM_ROUTE_ADD:
  2208. retval = ipa3_send_wan_msg(arg, WAN_UPSTREAM_ROUTE_ADD, true);
  2209. if (retval) {
  2210. IPAERR("ipa3_send_wan_msg failed: %d\n", retval);
  2211. break;
  2212. }
  2213. break;
  2214. case IPA_IOC_NOTIFY_WAN_UPSTREAM_ROUTE_DEL:
  2215. retval = ipa3_send_wan_msg(arg, WAN_UPSTREAM_ROUTE_DEL, true);
  2216. if (retval) {
  2217. IPAERR("ipa3_send_wan_msg failed: %d\n", retval);
  2218. break;
  2219. }
  2220. break;
  2221. case IPA_IOC_NOTIFY_WAN_EMBMS_CONNECTED:
  2222. retval = ipa3_send_wan_msg(arg, WAN_EMBMS_CONNECT, false);
  2223. if (retval) {
  2224. IPAERR("ipa3_send_wan_msg failed: %d\n", retval);
  2225. break;
  2226. }
  2227. break;
  2228. case IPA_IOC_ADD_HDR_PROC_CTX:
  2229. if (copy_from_user(header, (const void __user *)arg,
  2230. sizeof(struct ipa_ioc_add_hdr_proc_ctx))) {
  2231. retval = -EFAULT;
  2232. break;
  2233. }
  2234. pre_entry =
  2235. ((struct ipa_ioc_add_hdr_proc_ctx *)
  2236. header)->num_proc_ctxs;
  2237. pyld_sz =
  2238. sizeof(struct ipa_ioc_add_hdr_proc_ctx) +
  2239. pre_entry * sizeof(struct ipa_hdr_proc_ctx_add);
  2240. param = memdup_user((const void __user *)arg, pyld_sz);
  2241. if (IS_ERR(param)) {
  2242. retval = PTR_ERR(param);
  2243. break;
  2244. }
  2245. /* add check in case user-space module compromised */
  2246. if (unlikely(((struct ipa_ioc_add_hdr_proc_ctx *)
  2247. param)->num_proc_ctxs != pre_entry)) {
  2248. IPAERR_RL("current %d pre %d\n",
  2249. ((struct ipa_ioc_add_hdr_proc_ctx *)
  2250. param)->num_proc_ctxs, pre_entry);
  2251. retval = -EFAULT;
  2252. break;
  2253. }
  2254. if (ipa3_add_hdr_proc_ctx(
  2255. (struct ipa_ioc_add_hdr_proc_ctx *)param, true)) {
  2256. retval = -EFAULT;
  2257. break;
  2258. }
  2259. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  2260. retval = -EFAULT;
  2261. break;
  2262. }
  2263. break;
  2264. case IPA_IOC_DEL_HDR_PROC_CTX:
  2265. if (copy_from_user(header, (const void __user *)arg,
  2266. sizeof(struct ipa_ioc_del_hdr_proc_ctx))) {
  2267. retval = -EFAULT;
  2268. break;
  2269. }
  2270. pre_entry =
  2271. ((struct ipa_ioc_del_hdr_proc_ctx *)header)->num_hdls;
  2272. pyld_sz =
  2273. sizeof(struct ipa_ioc_del_hdr_proc_ctx) +
  2274. pre_entry * sizeof(struct ipa_hdr_proc_ctx_del);
  2275. param = memdup_user((const void __user *)arg, pyld_sz);
  2276. if (IS_ERR(param)) {
  2277. retval = PTR_ERR(param);
  2278. break;
  2279. }
  2280. /* add check in case user-space module compromised */
  2281. if (unlikely(((struct ipa_ioc_del_hdr_proc_ctx *)
  2282. param)->num_hdls != pre_entry)) {
  2283. IPAERR_RL("current %d pre %d\n",
  2284. ((struct ipa_ioc_del_hdr_proc_ctx *)param)->
  2285. num_hdls,
  2286. pre_entry);
  2287. retval = -EFAULT;
  2288. break;
  2289. }
  2290. if (ipa3_del_hdr_proc_ctx_by_user(
  2291. (struct ipa_ioc_del_hdr_proc_ctx *)param, true)) {
  2292. retval = -EFAULT;
  2293. break;
  2294. }
  2295. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  2296. retval = -EFAULT;
  2297. break;
  2298. }
  2299. break;
  2300. case IPA_IOC_GET_HW_VERSION:
  2301. pyld_sz = sizeof(enum ipa_hw_type);
  2302. param = kmemdup(&ipa3_ctx->ipa_hw_type, pyld_sz, GFP_KERNEL);
  2303. if (!param) {
  2304. retval = -ENOMEM;
  2305. break;
  2306. }
  2307. if (copy_to_user((void __user *)arg, param, pyld_sz)) {
  2308. retval = -EFAULT;
  2309. break;
  2310. }
  2311. break;
  2312. case IPA_IOC_GET_VLAN_MODE:
  2313. if (copy_from_user(&vlan_mode, (const void __user *)arg,
  2314. sizeof(struct ipa_ioc_get_vlan_mode))) {
  2315. retval = -EFAULT;
  2316. break;
  2317. }
  2318. retval = ipa3_is_vlan_mode(
  2319. vlan_mode.iface,
  2320. &is_vlan_mode);
  2321. if (retval)
  2322. break;
  2323. vlan_mode.is_vlan_mode = is_vlan_mode;
  2324. if (copy_to_user((void __user *)arg,
  2325. &vlan_mode,
  2326. sizeof(struct ipa_ioc_get_vlan_mode))) {
  2327. retval = -EFAULT;
  2328. break;
  2329. }
  2330. break;
  2331. case IPA_IOC_ADD_VLAN_IFACE:
  2332. if (ipa3_send_vlan_l2tp_msg(arg, ADD_VLAN_IFACE)) {
  2333. retval = -EFAULT;
  2334. break;
  2335. }
  2336. break;
  2337. case IPA_IOC_DEL_VLAN_IFACE:
  2338. if (ipa3_send_vlan_l2tp_msg(arg, DEL_VLAN_IFACE)) {
  2339. retval = -EFAULT;
  2340. break;
  2341. }
  2342. break;
  2343. case IPA_IOC_ADD_BRIDGE_VLAN_MAPPING:
  2344. if (ipa3_send_vlan_l2tp_msg(arg, ADD_BRIDGE_VLAN_MAPPING)) {
  2345. retval = -EFAULT;
  2346. break;
  2347. }
  2348. break;
  2349. case IPA_IOC_DEL_BRIDGE_VLAN_MAPPING:
  2350. if (ipa3_send_vlan_l2tp_msg(arg, DEL_BRIDGE_VLAN_MAPPING)) {
  2351. retval = -EFAULT;
  2352. break;
  2353. }
  2354. break;
  2355. case IPA_IOC_ADD_L2TP_VLAN_MAPPING:
  2356. if (ipa3_send_vlan_l2tp_msg(arg, ADD_L2TP_VLAN_MAPPING)) {
  2357. retval = -EFAULT;
  2358. break;
  2359. }
  2360. break;
  2361. case IPA_IOC_DEL_L2TP_VLAN_MAPPING:
  2362. if (ipa3_send_vlan_l2tp_msg(arg, DEL_L2TP_VLAN_MAPPING)) {
  2363. retval = -EFAULT;
  2364. break;
  2365. }
  2366. break;
  2367. case IPA_IOC_CLEANUP:
  2368. /*Route and filter rules will also be clean*/
  2369. IPADBG("Got IPA_IOC_CLEANUP\n");
  2370. retval = ipa3_reset_hdr(true);
  2371. memset(&nat_del, 0, sizeof(nat_del));
  2372. nat_del.table_index = 0;
  2373. retval = ipa3_nat_del_cmd(&nat_del);
  2374. retval = ipa3_clean_modem_rule();
  2375. ipa3_counter_id_remove_all();
  2376. break;
  2377. case IPA_IOC_QUERY_WLAN_CLIENT:
  2378. IPADBG("Got IPA_IOC_QUERY_WLAN_CLIENT\n");
  2379. retval = ipa3_resend_wlan_msg();
  2380. break;
  2381. case IPA_IOC_GSB_CONNECT:
  2382. IPADBG("Got IPA_IOC_GSB_CONNECT\n");
  2383. if (ipa3_send_gsb_msg(arg, IPA_GSB_CONNECT)) {
  2384. retval = -EFAULT;
  2385. break;
  2386. }
  2387. break;
  2388. case IPA_IOC_GSB_DISCONNECT:
  2389. IPADBG("Got IPA_IOC_GSB_DISCONNECT\n");
  2390. if (ipa3_send_gsb_msg(arg, IPA_GSB_DISCONNECT)) {
  2391. retval = -EFAULT;
  2392. break;
  2393. }
  2394. break;
  2395. case IPA_IOC_ADD_RT_RULE_V2:
  2396. retval = ipa3_ioctl_add_rt_rule_v2(arg);
  2397. break;
  2398. case IPA_IOC_ADD_RT_RULE_EXT_V2:
  2399. retval = ipa3_ioctl_add_rt_rule_ext_v2(arg);
  2400. break;
  2401. case IPA_IOC_ADD_RT_RULE_AFTER_V2:
  2402. retval = ipa3_ioctl_add_rt_rule_after_v2(arg);
  2403. break;
  2404. case IPA_IOC_MDFY_RT_RULE_V2:
  2405. retval = ipa3_ioctl_mdfy_rt_rule_v2(arg);
  2406. break;
  2407. case IPA_IOC_ADD_FLT_RULE_V2:
  2408. retval = ipa3_ioctl_add_flt_rule_v2(arg);
  2409. break;
  2410. case IPA_IOC_ADD_FLT_RULE_AFTER_V2:
  2411. retval = ipa3_ioctl_add_flt_rule_after_v2(arg);
  2412. break;
  2413. case IPA_IOC_MDFY_FLT_RULE_V2:
  2414. retval = ipa3_ioctl_mdfy_flt_rule_v2(arg);
  2415. break;
  2416. case IPA_IOC_FNR_COUNTER_ALLOC:
  2417. retval = ipa3_ioctl_fnr_counter_alloc(arg);
  2418. break;
  2419. case IPA_IOC_FNR_COUNTER_DEALLOC:
  2420. hdl = (int)arg;
  2421. if (hdl < 0) {
  2422. IPAERR("IPA_FNR_COUNTER_DEALLOC failed: hdl %d\n",
  2423. hdl);
  2424. retval = -EPERM;
  2425. break;
  2426. }
  2427. ipa3_counter_remove_hdl(hdl);
  2428. break;
  2429. case IPA_IOC_FNR_COUNTER_QUERY:
  2430. retval = ipa3_ioctl_fnr_counter_query(arg);
  2431. break;
  2432. case IPA_IOC_WIGIG_FST_SWITCH:
  2433. IPADBG("Got IPA_IOCTL_WIGIG_FST_SWITCH\n");
  2434. if (copy_from_user(&fst_switch, (const void __user *)arg,
  2435. sizeof(struct ipa_ioc_wigig_fst_switch))) {
  2436. retval = -EFAULT;
  2437. break;
  2438. }
  2439. retval = ipa_wigig_send_msg(WIGIG_FST_SWITCH,
  2440. fst_switch.netdev_name,
  2441. fst_switch.client_mac_addr,
  2442. IPA_CLIENT_MAX,
  2443. fst_switch.to_wigig);
  2444. break;
  2445. default:
  2446. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  2447. return -ENOTTY;
  2448. }
  2449. if (!IS_ERR(param))
  2450. kfree(param);
  2451. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  2452. return retval;
  2453. }
  2454. /**
  2455. * ipa3_setup_dflt_rt_tables() - Setup default routing tables
  2456. *
  2457. * Return codes:
  2458. * 0: success
  2459. * -ENOMEM: failed to allocate memory
  2460. * -EPERM: failed to add the tables
  2461. */
  2462. int ipa3_setup_dflt_rt_tables(void)
  2463. {
  2464. struct ipa_ioc_add_rt_rule *rt_rule;
  2465. struct ipa_rt_rule_add *rt_rule_entry;
  2466. rt_rule =
  2467. kzalloc(sizeof(struct ipa_ioc_add_rt_rule) + 1 *
  2468. sizeof(struct ipa_rt_rule_add), GFP_KERNEL);
  2469. if (!rt_rule)
  2470. return -ENOMEM;
  2471. /* setup a default v4 route to point to Apps */
  2472. rt_rule->num_rules = 1;
  2473. rt_rule->commit = 1;
  2474. rt_rule->ip = IPA_IP_v4;
  2475. strlcpy(rt_rule->rt_tbl_name, IPA_DFLT_RT_TBL_NAME,
  2476. IPA_RESOURCE_NAME_MAX);
  2477. rt_rule_entry = &rt_rule->rules[0];
  2478. rt_rule_entry->at_rear = 1;
  2479. rt_rule_entry->rule.dst = IPA_CLIENT_APPS_LAN_CONS;
  2480. rt_rule_entry->rule.hdr_hdl = ipa3_ctx->excp_hdr_hdl;
  2481. rt_rule_entry->rule.retain_hdr = 1;
  2482. if (ipa3_add_rt_rule(rt_rule)) {
  2483. IPAERR("fail to add dflt v4 rule\n");
  2484. kfree(rt_rule);
  2485. return -EPERM;
  2486. }
  2487. IPADBG("dflt v4 rt rule hdl=%x\n", rt_rule_entry->rt_rule_hdl);
  2488. ipa3_ctx->dflt_v4_rt_rule_hdl = rt_rule_entry->rt_rule_hdl;
  2489. /* setup a default v6 route to point to A5 */
  2490. rt_rule->ip = IPA_IP_v6;
  2491. if (ipa3_add_rt_rule(rt_rule)) {
  2492. IPAERR("fail to add dflt v6 rule\n");
  2493. kfree(rt_rule);
  2494. return -EPERM;
  2495. }
  2496. IPADBG("dflt v6 rt rule hdl=%x\n", rt_rule_entry->rt_rule_hdl);
  2497. ipa3_ctx->dflt_v6_rt_rule_hdl = rt_rule_entry->rt_rule_hdl;
  2498. /*
  2499. * because these tables are the very first to be added, they will both
  2500. * have the same index (0) which is essential for programming the
  2501. * "route" end-point config
  2502. */
  2503. kfree(rt_rule);
  2504. return 0;
  2505. }
  2506. static int ipa3_setup_exception_path(void)
  2507. {
  2508. struct ipa_ioc_add_hdr *hdr;
  2509. struct ipa_hdr_add *hdr_entry;
  2510. struct ipahal_reg_route route = { 0 };
  2511. int ret;
  2512. /* install the basic exception header */
  2513. hdr = kzalloc(sizeof(struct ipa_ioc_add_hdr) + 1 *
  2514. sizeof(struct ipa_hdr_add), GFP_KERNEL);
  2515. if (!hdr)
  2516. return -ENOMEM;
  2517. hdr->num_hdrs = 1;
  2518. hdr->commit = 1;
  2519. hdr_entry = &hdr->hdr[0];
  2520. strlcpy(hdr_entry->name, IPA_LAN_RX_HDR_NAME, IPA_RESOURCE_NAME_MAX);
  2521. hdr_entry->hdr_len = IPA_LAN_RX_HEADER_LENGTH;
  2522. if (ipa3_add_hdr(hdr)) {
  2523. IPAERR("fail to add exception hdr\n");
  2524. ret = -EPERM;
  2525. goto bail;
  2526. }
  2527. if (hdr_entry->status) {
  2528. IPAERR("fail to add exception hdr\n");
  2529. ret = -EPERM;
  2530. goto bail;
  2531. }
  2532. ipa3_ctx->excp_hdr_hdl = hdr_entry->hdr_hdl;
  2533. /* set the route register to pass exception packets to Apps */
  2534. route.route_def_pipe = ipa3_get_ep_mapping(IPA_CLIENT_APPS_LAN_CONS);
  2535. route.route_frag_def_pipe = ipa3_get_ep_mapping(
  2536. IPA_CLIENT_APPS_LAN_CONS);
  2537. route.route_def_hdr_table = !ipa3_ctx->hdr_tbl_lcl;
  2538. route.route_def_retain_hdr = 1;
  2539. if (ipa3_cfg_route(&route)) {
  2540. IPAERR("fail to add exception hdr\n");
  2541. ret = -EPERM;
  2542. goto bail;
  2543. }
  2544. ret = 0;
  2545. bail:
  2546. kfree(hdr);
  2547. return ret;
  2548. }
  2549. static int ipa3_init_smem_region(int memory_region_size,
  2550. int memory_region_offset)
  2551. {
  2552. struct ipahal_imm_cmd_dma_shared_mem cmd;
  2553. struct ipahal_imm_cmd_pyld *cmd_pyld;
  2554. struct ipa3_desc desc;
  2555. struct ipa_mem_buffer mem;
  2556. int rc;
  2557. if (memory_region_size == 0)
  2558. return 0;
  2559. memset(&desc, 0, sizeof(desc));
  2560. memset(&cmd, 0, sizeof(cmd));
  2561. memset(&mem, 0, sizeof(mem));
  2562. mem.size = memory_region_size;
  2563. mem.base = dma_zalloc_coherent(ipa3_ctx->pdev, mem.size,
  2564. &mem.phys_base, GFP_KERNEL);
  2565. if (!mem.base) {
  2566. IPAERR("failed to alloc DMA buff of size %d\n", mem.size);
  2567. return -ENOMEM;
  2568. }
  2569. cmd.is_read = false;
  2570. cmd.skip_pipeline_clear = false;
  2571. cmd.pipeline_clear_options = IPAHAL_HPS_CLEAR;
  2572. cmd.size = mem.size;
  2573. cmd.system_addr = mem.phys_base;
  2574. cmd.local_addr = ipa3_ctx->smem_restricted_bytes +
  2575. memory_region_offset;
  2576. cmd_pyld = ipahal_construct_imm_cmd(
  2577. IPA_IMM_CMD_DMA_SHARED_MEM, &cmd, false);
  2578. if (!cmd_pyld) {
  2579. IPAERR("failed to construct dma_shared_mem imm cmd\n");
  2580. return -ENOMEM;
  2581. }
  2582. ipa3_init_imm_cmd_desc(&desc, cmd_pyld);
  2583. rc = ipa3_send_cmd(1, &desc);
  2584. if (rc) {
  2585. IPAERR("failed to send immediate command (error %d)\n", rc);
  2586. rc = -EFAULT;
  2587. }
  2588. ipahal_destroy_imm_cmd(cmd_pyld);
  2589. dma_free_coherent(ipa3_ctx->pdev, mem.size, mem.base,
  2590. mem.phys_base);
  2591. return rc;
  2592. }
  2593. /**
  2594. * ipa3_init_q6_smem() - Initialize Q6 general memory and
  2595. * header memory regions in IPA.
  2596. *
  2597. * Return codes:
  2598. * 0: success
  2599. * -ENOMEM: failed to allocate dma memory
  2600. * -EFAULT: failed to send IPA command to initialize the memory
  2601. */
  2602. int ipa3_init_q6_smem(void)
  2603. {
  2604. int rc;
  2605. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  2606. rc = ipa3_init_smem_region(IPA_MEM_PART(modem_size),
  2607. IPA_MEM_PART(modem_ofst));
  2608. if (rc) {
  2609. IPAERR("failed to initialize Modem RAM memory\n");
  2610. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  2611. return rc;
  2612. }
  2613. rc = ipa3_init_smem_region(IPA_MEM_PART(modem_hdr_size),
  2614. IPA_MEM_PART(modem_hdr_ofst));
  2615. if (rc) {
  2616. IPAERR("failed to initialize Modem HDRs RAM memory\n");
  2617. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  2618. return rc;
  2619. }
  2620. rc = ipa3_init_smem_region(IPA_MEM_PART(modem_hdr_proc_ctx_size),
  2621. IPA_MEM_PART(modem_hdr_proc_ctx_ofst));
  2622. if (rc) {
  2623. IPAERR("failed to initialize Modem proc ctx RAM memory\n");
  2624. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  2625. return rc;
  2626. }
  2627. rc = ipa3_init_smem_region(IPA_MEM_PART(modem_comp_decomp_size),
  2628. IPA_MEM_PART(modem_comp_decomp_ofst));
  2629. if (rc) {
  2630. IPAERR("failed to initialize Modem Comp/Decomp RAM memory\n");
  2631. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  2632. return rc;
  2633. }
  2634. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  2635. return rc;
  2636. }
  2637. static void ipa3_destroy_imm(void *user1, int user2)
  2638. {
  2639. ipahal_destroy_imm_cmd(user1);
  2640. }
  2641. static void ipa3_q6_pipe_delay(bool delay)
  2642. {
  2643. int client_idx;
  2644. int ep_idx;
  2645. struct ipa_ep_cfg_ctrl ep_ctrl;
  2646. memset(&ep_ctrl, 0, sizeof(struct ipa_ep_cfg_ctrl));
  2647. ep_ctrl.ipa_ep_delay = delay;
  2648. for (client_idx = 0; client_idx < IPA_CLIENT_MAX; client_idx++) {
  2649. if (IPA_CLIENT_IS_Q6_PROD(client_idx)) {
  2650. ep_idx = ipa3_get_ep_mapping(client_idx);
  2651. if (ep_idx == -1)
  2652. continue;
  2653. ipahal_write_reg_n_fields(IPA_ENDP_INIT_CTRL_n,
  2654. ep_idx, &ep_ctrl);
  2655. }
  2656. }
  2657. }
  2658. static void ipa3_q6_avoid_holb(void)
  2659. {
  2660. int ep_idx;
  2661. int client_idx;
  2662. struct ipa_ep_cfg_ctrl ep_suspend;
  2663. struct ipa_ep_cfg_holb ep_holb;
  2664. memset(&ep_suspend, 0, sizeof(ep_suspend));
  2665. memset(&ep_holb, 0, sizeof(ep_holb));
  2666. ep_suspend.ipa_ep_suspend = true;
  2667. ep_holb.tmr_val = 0;
  2668. ep_holb.en = 1;
  2669. if (ipa3_ctx->ipa_hw_type == IPA_HW_v4_2)
  2670. ipa3_cal_ep_holb_scale_base_val(ep_holb.tmr_val, &ep_holb);
  2671. for (client_idx = 0; client_idx < IPA_CLIENT_MAX; client_idx++) {
  2672. if (IPA_CLIENT_IS_Q6_CONS(client_idx)) {
  2673. ep_idx = ipa3_get_ep_mapping(client_idx);
  2674. if (ep_idx == -1)
  2675. continue;
  2676. /* from IPA 4.0 pipe suspend is not supported */
  2677. if (ipa3_ctx->ipa_hw_type < IPA_HW_v4_0)
  2678. ipahal_write_reg_n_fields(
  2679. IPA_ENDP_INIT_CTRL_n,
  2680. ep_idx, &ep_suspend);
  2681. /*
  2682. * ipa3_cfg_ep_holb is not used here because we are
  2683. * setting HOLB on Q6 pipes, and from APPS perspective
  2684. * they are not valid, therefore, the above function
  2685. * will fail.
  2686. */
  2687. ipahal_write_reg_n_fields(
  2688. IPA_ENDP_INIT_HOL_BLOCK_TIMER_n,
  2689. ep_idx, &ep_holb);
  2690. ipahal_write_reg_n_fields(
  2691. IPA_ENDP_INIT_HOL_BLOCK_EN_n,
  2692. ep_idx, &ep_holb);
  2693. /* IPA4.5 issue requires HOLB_EN to be written twice */
  2694. if (ipa3_ctx->ipa_hw_type >= IPA_HW_v4_5)
  2695. ipahal_write_reg_n_fields(
  2696. IPA_ENDP_INIT_HOL_BLOCK_EN_n,
  2697. ep_idx, &ep_holb);
  2698. }
  2699. }
  2700. }
  2701. static void ipa3_halt_q6_gsi_channels(bool prod)
  2702. {
  2703. int ep_idx;
  2704. int client_idx;
  2705. const struct ipa_gsi_ep_config *gsi_ep_cfg;
  2706. int i;
  2707. int ret;
  2708. int code = 0;
  2709. /* if prod flag is true, then we halt the producer channels also */
  2710. for (client_idx = 0; client_idx < IPA_CLIENT_MAX; client_idx++) {
  2711. if (IPA_CLIENT_IS_Q6_CONS(client_idx)
  2712. || (IPA_CLIENT_IS_Q6_PROD(client_idx) && prod)) {
  2713. ep_idx = ipa3_get_ep_mapping(client_idx);
  2714. if (ep_idx == -1)
  2715. continue;
  2716. gsi_ep_cfg = ipa3_get_gsi_ep_info(client_idx);
  2717. if (!gsi_ep_cfg) {
  2718. IPAERR("failed to get GSI config\n");
  2719. ipa_assert();
  2720. return;
  2721. }
  2722. ret = gsi_halt_channel_ee(
  2723. gsi_ep_cfg->ipa_gsi_chan_num, gsi_ep_cfg->ee,
  2724. &code);
  2725. for (i = 0; i < IPA_GSI_CHANNEL_STOP_MAX_RETRY &&
  2726. ret == -GSI_STATUS_AGAIN; i++) {
  2727. IPADBG(
  2728. "ch %d ee %d with code %d\n is busy try again",
  2729. gsi_ep_cfg->ipa_gsi_chan_num,
  2730. gsi_ep_cfg->ee,
  2731. code);
  2732. usleep_range(IPA_GSI_CHANNEL_HALT_MIN_SLEEP,
  2733. IPA_GSI_CHANNEL_HALT_MAX_SLEEP);
  2734. ret = gsi_halt_channel_ee(
  2735. gsi_ep_cfg->ipa_gsi_chan_num,
  2736. gsi_ep_cfg->ee, &code);
  2737. }
  2738. if (ret == GSI_STATUS_SUCCESS)
  2739. IPADBG("halted gsi ch %d ee %d with code %d\n",
  2740. gsi_ep_cfg->ipa_gsi_chan_num,
  2741. gsi_ep_cfg->ee,
  2742. code);
  2743. else
  2744. IPAERR("failed to halt ch %d ee %d code %d\n",
  2745. gsi_ep_cfg->ipa_gsi_chan_num,
  2746. gsi_ep_cfg->ee,
  2747. code);
  2748. }
  2749. }
  2750. }
  2751. static int ipa3_q6_clean_q6_flt_tbls(enum ipa_ip_type ip,
  2752. enum ipa_rule_type rlt)
  2753. {
  2754. struct ipa3_desc *desc;
  2755. struct ipahal_imm_cmd_dma_shared_mem cmd = {0};
  2756. struct ipahal_imm_cmd_pyld **cmd_pyld;
  2757. int retval = 0;
  2758. int pipe_idx;
  2759. int flt_idx = 0;
  2760. int num_cmds = 0;
  2761. int index;
  2762. u32 lcl_addr_mem_part;
  2763. u32 lcl_hdr_sz;
  2764. struct ipa_mem_buffer mem;
  2765. IPADBG("Entry\n");
  2766. if ((ip >= IPA_IP_MAX) || (rlt >= IPA_RULE_TYPE_MAX)) {
  2767. IPAERR("Input Err: ip=%d ; rlt=%d\n", ip, rlt);
  2768. return -EINVAL;
  2769. }
  2770. /*
  2771. * SRAM memory not allocated to hash tables. Cleaning the of hash table
  2772. * operation not supported.
  2773. */
  2774. if (rlt == IPA_RULE_HASHABLE && ipa3_ctx->ipa_fltrt_not_hashable) {
  2775. IPADBG("Clean hashable rules not supported\n");
  2776. return retval;
  2777. }
  2778. /* Up to filtering pipes we have filtering tables */
  2779. desc = kcalloc(ipa3_ctx->ep_flt_num, sizeof(struct ipa3_desc),
  2780. GFP_KERNEL);
  2781. if (!desc)
  2782. return -ENOMEM;
  2783. cmd_pyld = kcalloc(ipa3_ctx->ep_flt_num,
  2784. sizeof(struct ipahal_imm_cmd_pyld *), GFP_KERNEL);
  2785. if (!cmd_pyld) {
  2786. retval = -ENOMEM;
  2787. goto free_desc;
  2788. }
  2789. if (ip == IPA_IP_v4) {
  2790. if (rlt == IPA_RULE_HASHABLE) {
  2791. lcl_addr_mem_part = IPA_MEM_PART(v4_flt_hash_ofst);
  2792. lcl_hdr_sz = IPA_MEM_PART(v4_flt_hash_size);
  2793. } else {
  2794. lcl_addr_mem_part = IPA_MEM_PART(v4_flt_nhash_ofst);
  2795. lcl_hdr_sz = IPA_MEM_PART(v4_flt_nhash_size);
  2796. }
  2797. } else {
  2798. if (rlt == IPA_RULE_HASHABLE) {
  2799. lcl_addr_mem_part = IPA_MEM_PART(v6_flt_hash_ofst);
  2800. lcl_hdr_sz = IPA_MEM_PART(v6_flt_hash_size);
  2801. } else {
  2802. lcl_addr_mem_part = IPA_MEM_PART(v6_flt_nhash_ofst);
  2803. lcl_hdr_sz = IPA_MEM_PART(v6_flt_nhash_size);
  2804. }
  2805. }
  2806. retval = ipahal_flt_generate_empty_img(1, lcl_hdr_sz, lcl_hdr_sz,
  2807. 0, &mem, true);
  2808. if (retval) {
  2809. IPAERR("failed to generate flt single tbl empty img\n");
  2810. goto free_cmd_pyld;
  2811. }
  2812. for (pipe_idx = 0; pipe_idx < ipa3_ctx->ipa_num_pipes; pipe_idx++) {
  2813. if (!ipa_is_ep_support_flt(pipe_idx))
  2814. continue;
  2815. /*
  2816. * Iterating over all the filtering pipes which are either
  2817. * invalid but connected or connected but not configured by AP.
  2818. */
  2819. if (!ipa3_ctx->ep[pipe_idx].valid ||
  2820. ipa3_ctx->ep[pipe_idx].skip_ep_cfg) {
  2821. if (num_cmds >= ipa3_ctx->ep_flt_num) {
  2822. IPAERR("number of commands is out of range\n");
  2823. retval = -ENOBUFS;
  2824. goto free_empty_img;
  2825. }
  2826. cmd.is_read = false;
  2827. cmd.skip_pipeline_clear = false;
  2828. cmd.pipeline_clear_options = IPAHAL_HPS_CLEAR;
  2829. cmd.size = mem.size;
  2830. cmd.system_addr = mem.phys_base;
  2831. cmd.local_addr =
  2832. ipa3_ctx->smem_restricted_bytes +
  2833. lcl_addr_mem_part +
  2834. ipahal_get_hw_tbl_hdr_width() +
  2835. flt_idx * ipahal_get_hw_tbl_hdr_width();
  2836. cmd_pyld[num_cmds] = ipahal_construct_imm_cmd(
  2837. IPA_IMM_CMD_DMA_SHARED_MEM, &cmd, false);
  2838. if (!cmd_pyld[num_cmds]) {
  2839. IPAERR("fail construct dma_shared_mem cmd\n");
  2840. retval = -ENOMEM;
  2841. goto free_empty_img;
  2842. }
  2843. ipa3_init_imm_cmd_desc(&desc[num_cmds],
  2844. cmd_pyld[num_cmds]);
  2845. ++num_cmds;
  2846. }
  2847. ++flt_idx;
  2848. }
  2849. IPADBG("Sending %d descriptors for flt tbl clearing\n", num_cmds);
  2850. retval = ipa3_send_cmd(num_cmds, desc);
  2851. if (retval) {
  2852. IPAERR("failed to send immediate command (err %d)\n", retval);
  2853. retval = -EFAULT;
  2854. }
  2855. free_empty_img:
  2856. ipahal_free_dma_mem(&mem);
  2857. free_cmd_pyld:
  2858. for (index = 0; index < num_cmds; index++)
  2859. ipahal_destroy_imm_cmd(cmd_pyld[index]);
  2860. kfree(cmd_pyld);
  2861. free_desc:
  2862. kfree(desc);
  2863. return retval;
  2864. }
  2865. static int ipa3_q6_clean_q6_rt_tbls(enum ipa_ip_type ip,
  2866. enum ipa_rule_type rlt)
  2867. {
  2868. struct ipa3_desc *desc;
  2869. struct ipahal_imm_cmd_dma_shared_mem cmd = {0};
  2870. struct ipahal_imm_cmd_pyld *cmd_pyld = NULL;
  2871. int retval = 0;
  2872. u32 modem_rt_index_lo;
  2873. u32 modem_rt_index_hi;
  2874. u32 lcl_addr_mem_part;
  2875. u32 lcl_hdr_sz;
  2876. struct ipa_mem_buffer mem;
  2877. IPADBG("Entry\n");
  2878. if ((ip >= IPA_IP_MAX) || (rlt >= IPA_RULE_TYPE_MAX)) {
  2879. IPAERR("Input Err: ip=%d ; rlt=%d\n", ip, rlt);
  2880. return -EINVAL;
  2881. }
  2882. /*
  2883. * SRAM memory not allocated to hash tables. Cleaning the of hash table
  2884. * operation not supported.
  2885. */
  2886. if (rlt == IPA_RULE_HASHABLE && ipa3_ctx->ipa_fltrt_not_hashable) {
  2887. IPADBG("Clean hashable rules not supported\n");
  2888. return retval;
  2889. }
  2890. if (ip == IPA_IP_v4) {
  2891. modem_rt_index_lo = IPA_MEM_PART(v4_modem_rt_index_lo);
  2892. modem_rt_index_hi = IPA_MEM_PART(v4_modem_rt_index_hi);
  2893. if (rlt == IPA_RULE_HASHABLE) {
  2894. lcl_addr_mem_part = IPA_MEM_PART(v4_rt_hash_ofst);
  2895. lcl_hdr_sz = IPA_MEM_PART(v4_flt_hash_size);
  2896. } else {
  2897. lcl_addr_mem_part = IPA_MEM_PART(v4_rt_nhash_ofst);
  2898. lcl_hdr_sz = IPA_MEM_PART(v4_flt_nhash_size);
  2899. }
  2900. } else {
  2901. modem_rt_index_lo = IPA_MEM_PART(v6_modem_rt_index_lo);
  2902. modem_rt_index_hi = IPA_MEM_PART(v6_modem_rt_index_hi);
  2903. if (rlt == IPA_RULE_HASHABLE) {
  2904. lcl_addr_mem_part = IPA_MEM_PART(v6_rt_hash_ofst);
  2905. lcl_hdr_sz = IPA_MEM_PART(v6_flt_hash_size);
  2906. } else {
  2907. lcl_addr_mem_part = IPA_MEM_PART(v6_rt_nhash_ofst);
  2908. lcl_hdr_sz = IPA_MEM_PART(v6_flt_nhash_size);
  2909. }
  2910. }
  2911. retval = ipahal_rt_generate_empty_img(
  2912. modem_rt_index_hi - modem_rt_index_lo + 1,
  2913. lcl_hdr_sz, lcl_hdr_sz, &mem, true);
  2914. if (retval) {
  2915. IPAERR("fail generate empty rt img\n");
  2916. return -ENOMEM;
  2917. }
  2918. desc = kzalloc(sizeof(struct ipa3_desc), GFP_KERNEL);
  2919. if (!desc) {
  2920. IPAERR("failed to allocate memory\n");
  2921. goto free_empty_img;
  2922. }
  2923. cmd.is_read = false;
  2924. cmd.skip_pipeline_clear = false;
  2925. cmd.pipeline_clear_options = IPAHAL_HPS_CLEAR;
  2926. cmd.size = mem.size;
  2927. cmd.system_addr = mem.phys_base;
  2928. cmd.local_addr = ipa3_ctx->smem_restricted_bytes +
  2929. lcl_addr_mem_part +
  2930. modem_rt_index_lo * ipahal_get_hw_tbl_hdr_width();
  2931. cmd_pyld = ipahal_construct_imm_cmd(
  2932. IPA_IMM_CMD_DMA_SHARED_MEM, &cmd, false);
  2933. if (!cmd_pyld) {
  2934. IPAERR("failed to construct dma_shared_mem imm cmd\n");
  2935. retval = -ENOMEM;
  2936. goto free_desc;
  2937. }
  2938. ipa3_init_imm_cmd_desc(desc, cmd_pyld);
  2939. IPADBG("Sending 1 descriptor for rt tbl clearing\n");
  2940. retval = ipa3_send_cmd(1, desc);
  2941. if (retval) {
  2942. IPAERR("failed to send immediate command (err %d)\n", retval);
  2943. retval = -EFAULT;
  2944. }
  2945. ipahal_destroy_imm_cmd(cmd_pyld);
  2946. free_desc:
  2947. kfree(desc);
  2948. free_empty_img:
  2949. ipahal_free_dma_mem(&mem);
  2950. return retval;
  2951. }
  2952. static int ipa3_q6_clean_q6_tables(void)
  2953. {
  2954. struct ipa3_desc *desc;
  2955. struct ipahal_imm_cmd_pyld *cmd_pyld = NULL;
  2956. struct ipahal_imm_cmd_register_write reg_write_cmd = {0};
  2957. int retval = 0;
  2958. struct ipahal_reg_fltrt_hash_flush flush;
  2959. struct ipahal_reg_valmask valmask;
  2960. IPADBG("Entry\n");
  2961. if (ipa3_q6_clean_q6_flt_tbls(IPA_IP_v4, IPA_RULE_HASHABLE)) {
  2962. IPAERR("failed to clean q6 flt tbls (v4/hashable)\n");
  2963. return -EFAULT;
  2964. }
  2965. if (ipa3_q6_clean_q6_flt_tbls(IPA_IP_v6, IPA_RULE_HASHABLE)) {
  2966. IPAERR("failed to clean q6 flt tbls (v6/hashable)\n");
  2967. return -EFAULT;
  2968. }
  2969. if (ipa3_q6_clean_q6_flt_tbls(IPA_IP_v4, IPA_RULE_NON_HASHABLE)) {
  2970. IPAERR("failed to clean q6 flt tbls (v4/non-hashable)\n");
  2971. return -EFAULT;
  2972. }
  2973. if (ipa3_q6_clean_q6_flt_tbls(IPA_IP_v6, IPA_RULE_NON_HASHABLE)) {
  2974. IPAERR("failed to clean q6 flt tbls (v6/non-hashable)\n");
  2975. return -EFAULT;
  2976. }
  2977. if (ipa3_q6_clean_q6_rt_tbls(IPA_IP_v4, IPA_RULE_HASHABLE)) {
  2978. IPAERR("failed to clean q6 rt tbls (v4/hashable)\n");
  2979. return -EFAULT;
  2980. }
  2981. if (ipa3_q6_clean_q6_rt_tbls(IPA_IP_v6, IPA_RULE_HASHABLE)) {
  2982. IPAERR("failed to clean q6 rt tbls (v6/hashable)\n");
  2983. return -EFAULT;
  2984. }
  2985. if (ipa3_q6_clean_q6_rt_tbls(IPA_IP_v4, IPA_RULE_NON_HASHABLE)) {
  2986. IPAERR("failed to clean q6 rt tbls (v4/non-hashable)\n");
  2987. return -EFAULT;
  2988. }
  2989. if (ipa3_q6_clean_q6_rt_tbls(IPA_IP_v6, IPA_RULE_NON_HASHABLE)) {
  2990. IPAERR("failed to clean q6 rt tbls (v6/non-hashable)\n");
  2991. return -EFAULT;
  2992. }
  2993. /*
  2994. * SRAM memory not allocated to hash tables. Cleaning the of hash table
  2995. * operation not supported.
  2996. */
  2997. if (ipa3_ctx->ipa_fltrt_not_hashable)
  2998. return retval;
  2999. /* Flush rules cache */
  3000. desc = kzalloc(sizeof(struct ipa3_desc), GFP_KERNEL);
  3001. if (!desc)
  3002. return -ENOMEM;
  3003. flush.v4_flt = true;
  3004. flush.v4_rt = true;
  3005. flush.v6_flt = true;
  3006. flush.v6_rt = true;
  3007. ipahal_get_fltrt_hash_flush_valmask(&flush, &valmask);
  3008. reg_write_cmd.skip_pipeline_clear = false;
  3009. reg_write_cmd.pipeline_clear_options = IPAHAL_HPS_CLEAR;
  3010. reg_write_cmd.offset = ipahal_get_reg_ofst(IPA_FILT_ROUT_HASH_FLUSH);
  3011. reg_write_cmd.value = valmask.val;
  3012. reg_write_cmd.value_mask = valmask.mask;
  3013. cmd_pyld = ipahal_construct_imm_cmd(IPA_IMM_CMD_REGISTER_WRITE,
  3014. &reg_write_cmd, false);
  3015. if (!cmd_pyld) {
  3016. IPAERR("fail construct register_write imm cmd\n");
  3017. retval = -EFAULT;
  3018. goto bail_desc;
  3019. }
  3020. ipa3_init_imm_cmd_desc(desc, cmd_pyld);
  3021. IPADBG("Sending 1 descriptor for tbls flush\n");
  3022. retval = ipa3_send_cmd(1, desc);
  3023. if (retval) {
  3024. IPAERR("failed to send immediate command (err %d)\n", retval);
  3025. retval = -EFAULT;
  3026. }
  3027. ipahal_destroy_imm_cmd(cmd_pyld);
  3028. bail_desc:
  3029. kfree(desc);
  3030. IPADBG("Done - retval = %d\n", retval);
  3031. return retval;
  3032. }
  3033. static int ipa3_q6_set_ex_path_to_apps(void)
  3034. {
  3035. int ep_idx;
  3036. int client_idx;
  3037. struct ipa3_desc *desc;
  3038. int num_descs = 0;
  3039. int index;
  3040. struct ipahal_imm_cmd_register_write reg_write;
  3041. struct ipahal_imm_cmd_pyld *cmd_pyld;
  3042. int retval;
  3043. desc = kcalloc(ipa3_ctx->ipa_num_pipes, sizeof(struct ipa3_desc),
  3044. GFP_KERNEL);
  3045. if (!desc)
  3046. return -ENOMEM;
  3047. /* Set the exception path to AP */
  3048. for (client_idx = 0; client_idx < IPA_CLIENT_MAX; client_idx++) {
  3049. ep_idx = ipa3_get_ep_mapping(client_idx);
  3050. if (ep_idx == -1)
  3051. continue;
  3052. /* disable statuses for all modem controlled prod pipes */
  3053. if (!IPA_CLIENT_IS_TEST(client_idx) &&
  3054. (IPA_CLIENT_IS_Q6_PROD(client_idx) ||
  3055. (IPA_CLIENT_IS_PROD(client_idx) &&
  3056. ipa3_ctx->ep[ep_idx].valid &&
  3057. ipa3_ctx->ep[ep_idx].skip_ep_cfg) ||
  3058. (ipa3_ctx->ep[ep_idx].client == IPA_CLIENT_APPS_WAN_PROD
  3059. && ipa3_ctx->modem_cfg_emb_pipe_flt))) {
  3060. ipa_assert_on(num_descs >= ipa3_ctx->ipa_num_pipes);
  3061. ipa3_ctx->ep[ep_idx].status.status_en = false;
  3062. reg_write.skip_pipeline_clear = false;
  3063. reg_write.pipeline_clear_options =
  3064. IPAHAL_HPS_CLEAR;
  3065. reg_write.offset =
  3066. ipahal_get_reg_n_ofst(IPA_ENDP_STATUS_n,
  3067. ep_idx);
  3068. reg_write.value = 0;
  3069. reg_write.value_mask = ~0;
  3070. cmd_pyld = ipahal_construct_imm_cmd(
  3071. IPA_IMM_CMD_REGISTER_WRITE, &reg_write, false);
  3072. if (!cmd_pyld) {
  3073. IPAERR("fail construct register_write cmd\n");
  3074. ipa_assert();
  3075. return -ENOMEM;
  3076. }
  3077. ipa3_init_imm_cmd_desc(&desc[num_descs], cmd_pyld);
  3078. desc[num_descs].callback = ipa3_destroy_imm;
  3079. desc[num_descs].user1 = cmd_pyld;
  3080. ++num_descs;
  3081. }
  3082. }
  3083. /* Will wait 500msecs for IPA tag process completion */
  3084. retval = ipa3_tag_process(desc, num_descs,
  3085. msecs_to_jiffies(CLEANUP_TAG_PROCESS_TIMEOUT));
  3086. if (retval) {
  3087. IPAERR("TAG process failed! (error %d)\n", retval);
  3088. /* For timeout error ipa3_destroy_imm cb will destroy user1 */
  3089. if (retval != -ETIME) {
  3090. for (index = 0; index < num_descs; index++)
  3091. if (desc[index].callback)
  3092. desc[index].callback(desc[index].user1,
  3093. desc[index].user2);
  3094. retval = -EINVAL;
  3095. }
  3096. }
  3097. kfree(desc);
  3098. return retval;
  3099. }
  3100. /*
  3101. * ipa3_update_ssr_state() - updating current SSR state
  3102. * @is_ssr: [in] Current SSR state
  3103. */
  3104. void ipa3_update_ssr_state(bool is_ssr)
  3105. {
  3106. if (is_ssr)
  3107. atomic_set(&ipa3_ctx->is_ssr, 1);
  3108. else
  3109. atomic_set(&ipa3_ctx->is_ssr, 0);
  3110. }
  3111. /**
  3112. * ipa3_q6_pre_shutdown_cleanup() - A cleanup for all Q6 related configuration
  3113. * in IPA HW. This is performed in case of SSR.
  3114. *
  3115. * This is a mandatory procedure, in case one of the steps fails, the
  3116. * AP needs to restart.
  3117. */
  3118. void ipa3_q6_pre_shutdown_cleanup(void)
  3119. {
  3120. IPADBG_LOW("ENTER\n");
  3121. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  3122. ipa3_update_ssr_state(true);
  3123. if (!ipa3_ctx->ipa_endp_delay_wa)
  3124. ipa3_q6_pipe_delay(true);
  3125. ipa3_q6_avoid_holb();
  3126. if (ipa3_ctx->ipa_config_is_mhi)
  3127. ipa3_set_reset_client_cons_pipe_sus_holb(true,
  3128. IPA_CLIENT_MHI_CONS);
  3129. if (ipa3_q6_clean_q6_tables()) {
  3130. IPAERR("Failed to clean Q6 tables\n");
  3131. /*
  3132. * Indicates IPA hardware is stalled, unexpected
  3133. * hardware state.
  3134. */
  3135. ipa_assert();
  3136. }
  3137. if (ipa3_q6_set_ex_path_to_apps()) {
  3138. IPAERR("Failed to redirect exceptions to APPS\n");
  3139. /*
  3140. * Indicates IPA hardware is stalled, unexpected
  3141. * hardware state.
  3142. */
  3143. ipa_assert();
  3144. }
  3145. /* Remove delay from Q6 PRODs to avoid pending descriptors
  3146. * on pipe reset procedure
  3147. */
  3148. if (!ipa3_ctx->ipa_endp_delay_wa) {
  3149. ipa3_q6_pipe_delay(false);
  3150. ipa3_set_reset_client_prod_pipe_delay(true,
  3151. IPA_CLIENT_USB_PROD);
  3152. } else {
  3153. ipa3_start_stop_client_prod_gsi_chnl(IPA_CLIENT_USB_PROD,
  3154. false);
  3155. }
  3156. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  3157. IPADBG_LOW("Exit with success\n");
  3158. }
  3159. /*
  3160. * ipa3_q6_post_shutdown_cleanup() - As part of this cleanup
  3161. * check if GSI channel related to Q6 producer client is empty.
  3162. *
  3163. * Q6 GSI channel emptiness is needed to garantee no descriptors with invalid
  3164. * info are injected into IPA RX from IPA_IF, while modem is restarting.
  3165. */
  3166. void ipa3_q6_post_shutdown_cleanup(void)
  3167. {
  3168. int client_idx;
  3169. int ep_idx;
  3170. bool prod = false;
  3171. IPADBG_LOW("ENTER\n");
  3172. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  3173. /* Handle the issue where SUSPEND was removed for some reason */
  3174. ipa3_q6_avoid_holb();
  3175. /* halt both prod and cons channels starting at IPAv4 */
  3176. if (ipa3_ctx->ipa_hw_type >= IPA_HW_v4_0) {
  3177. prod = true;
  3178. ipa3_halt_q6_gsi_channels(prod);
  3179. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  3180. IPADBG("Exit without consumer check\n");
  3181. return;
  3182. }
  3183. ipa3_halt_q6_gsi_channels(prod);
  3184. if (!ipa3_ctx->uc_ctx.uc_loaded) {
  3185. IPAERR("uC is not loaded. Skipping\n");
  3186. return;
  3187. }
  3188. for (client_idx = 0; client_idx < IPA_CLIENT_MAX; client_idx++)
  3189. if (IPA_CLIENT_IS_Q6_PROD(client_idx)) {
  3190. ep_idx = ipa3_get_ep_mapping(client_idx);
  3191. if (ep_idx == -1)
  3192. continue;
  3193. if (ipa3_uc_is_gsi_channel_empty(client_idx)) {
  3194. IPAERR("fail to validate Q6 ch emptiness %d\n",
  3195. client_idx);
  3196. /*
  3197. * Indicates GSI hardware is stalled, unexpected
  3198. * hardware state.
  3199. * Remove bug for adb reboot issue.
  3200. */
  3201. }
  3202. }
  3203. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  3204. IPADBG_LOW("Exit with success\n");
  3205. }
  3206. /**
  3207. * ipa3_q6_pre_powerup_cleanup() - A cleanup routine for pheripheral
  3208. * configuration in IPA HW. This is performed in case of SSR.
  3209. *
  3210. * This is a mandatory procedure, in case one of the steps fails, the
  3211. * AP needs to restart.
  3212. */
  3213. void ipa3_q6_pre_powerup_cleanup(void)
  3214. {
  3215. IPADBG_LOW("ENTER\n");
  3216. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  3217. if (ipa3_ctx->ipa_config_is_mhi)
  3218. ipa3_set_reset_client_prod_pipe_delay(true,
  3219. IPA_CLIENT_MHI_PROD);
  3220. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  3221. IPADBG_LOW("Exit with success\n");
  3222. }
  3223. /*
  3224. * ipa3_client_prod_post_shutdown_cleanup () - As part of this function
  3225. * set end point delay client producer pipes and starting corresponding
  3226. * gsi channels
  3227. */
  3228. void ipa3_client_prod_post_shutdown_cleanup(void)
  3229. {
  3230. IPADBG_LOW("ENTER\n");
  3231. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  3232. ipa3_set_reset_client_prod_pipe_delay(true,
  3233. IPA_CLIENT_USB_PROD);
  3234. ipa3_start_stop_client_prod_gsi_chnl(IPA_CLIENT_USB_PROD, true);
  3235. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  3236. IPADBG_LOW("Exit with success\n");
  3237. }
  3238. static inline void ipa3_sram_set_canary(u32 *sram_mmio, int offset)
  3239. {
  3240. /* Set 4 bytes of CANARY before the offset */
  3241. sram_mmio[(offset - 4) / 4] = IPA_MEM_CANARY_VAL;
  3242. }
  3243. /**
  3244. * _ipa_init_sram_v3() - Initialize IPA local SRAM.
  3245. *
  3246. * Return codes: 0 for success, negative value for failure
  3247. */
  3248. int _ipa_init_sram_v3(void)
  3249. {
  3250. u32 *ipa_sram_mmio;
  3251. unsigned long phys_addr;
  3252. IPADBG(
  3253. "ipa_wrapper_base(0x%08X) ipa_reg_base_ofst(0x%08X) IPA_SW_AREA_RAM_DIRECT_ACCESS_n(0x%08X) smem_restricted_bytes(0x%08X) smem_sz(0x%08X)\n",
  3254. ipa3_ctx->ipa_wrapper_base,
  3255. ipa3_ctx->ctrl->ipa_reg_base_ofst,
  3256. ipahal_get_reg_n_ofst(
  3257. IPA_SW_AREA_RAM_DIRECT_ACCESS_n,
  3258. ipa3_ctx->smem_restricted_bytes / 4),
  3259. ipa3_ctx->smem_restricted_bytes,
  3260. ipa3_ctx->smem_sz);
  3261. phys_addr = ipa3_ctx->ipa_wrapper_base +
  3262. ipa3_ctx->ctrl->ipa_reg_base_ofst +
  3263. ipahal_get_reg_n_ofst(IPA_SW_AREA_RAM_DIRECT_ACCESS_n,
  3264. ipa3_ctx->smem_restricted_bytes / 4);
  3265. ipa_sram_mmio = ioremap(phys_addr, ipa3_ctx->smem_sz);
  3266. if (!ipa_sram_mmio) {
  3267. IPAERR("fail to ioremap IPA SRAM\n");
  3268. return -ENOMEM;
  3269. }
  3270. /* Consult with ipa_i.h on the location of the CANARY values */
  3271. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(v4_flt_hash_ofst) - 4);
  3272. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(v4_flt_hash_ofst));
  3273. ipa3_sram_set_canary(ipa_sram_mmio,
  3274. IPA_MEM_PART(v4_flt_nhash_ofst) - 4);
  3275. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(v4_flt_nhash_ofst));
  3276. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(v6_flt_hash_ofst) - 4);
  3277. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(v6_flt_hash_ofst));
  3278. ipa3_sram_set_canary(ipa_sram_mmio,
  3279. IPA_MEM_PART(v6_flt_nhash_ofst) - 4);
  3280. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(v6_flt_nhash_ofst));
  3281. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(v4_rt_hash_ofst) - 4);
  3282. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(v4_rt_hash_ofst));
  3283. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(v4_rt_nhash_ofst) - 4);
  3284. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(v4_rt_nhash_ofst));
  3285. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(v6_rt_hash_ofst) - 4);
  3286. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(v6_rt_hash_ofst));
  3287. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(v6_rt_nhash_ofst) - 4);
  3288. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(v6_rt_nhash_ofst));
  3289. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(modem_hdr_ofst) - 4);
  3290. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(modem_hdr_ofst));
  3291. ipa3_sram_set_canary(ipa_sram_mmio,
  3292. IPA_MEM_PART(modem_hdr_proc_ctx_ofst) - 4);
  3293. ipa3_sram_set_canary(ipa_sram_mmio,
  3294. IPA_MEM_PART(modem_hdr_proc_ctx_ofst));
  3295. if (ipa_get_hw_type() >= IPA_HW_v4_5) {
  3296. ipa3_sram_set_canary(ipa_sram_mmio,
  3297. IPA_MEM_PART(nat_tbl_ofst) - 12);
  3298. ipa3_sram_set_canary(ipa_sram_mmio,
  3299. IPA_MEM_PART(nat_tbl_ofst) - 8);
  3300. ipa3_sram_set_canary(ipa_sram_mmio,
  3301. IPA_MEM_PART(nat_tbl_ofst) - 4);
  3302. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(nat_tbl_ofst));
  3303. }
  3304. if (ipa_get_hw_type() >= IPA_HW_v4_0) {
  3305. ipa3_sram_set_canary(ipa_sram_mmio,
  3306. IPA_MEM_PART(pdn_config_ofst) - 4);
  3307. ipa3_sram_set_canary(ipa_sram_mmio,
  3308. IPA_MEM_PART(pdn_config_ofst));
  3309. ipa3_sram_set_canary(ipa_sram_mmio,
  3310. IPA_MEM_PART(stats_quota_ofst) - 4);
  3311. ipa3_sram_set_canary(ipa_sram_mmio,
  3312. IPA_MEM_PART(stats_quota_ofst));
  3313. }
  3314. if (ipa_get_hw_type() <= IPA_HW_v3_5 ||
  3315. ipa_get_hw_type() >= IPA_HW_v4_5) {
  3316. ipa3_sram_set_canary(ipa_sram_mmio,
  3317. IPA_MEM_PART(modem_ofst) - 4);
  3318. ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(modem_ofst));
  3319. }
  3320. ipa3_sram_set_canary(ipa_sram_mmio,
  3321. (ipa_get_hw_type() >= IPA_HW_v3_5) ?
  3322. IPA_MEM_PART(uc_descriptor_ram_ofst) :
  3323. IPA_MEM_PART(end_ofst));
  3324. iounmap(ipa_sram_mmio);
  3325. return 0;
  3326. }
  3327. /**
  3328. * _ipa_init_hdr_v3_0() - Initialize IPA header block.
  3329. *
  3330. * Return codes: 0 for success, negative value for failure
  3331. */
  3332. int _ipa_init_hdr_v3_0(void)
  3333. {
  3334. struct ipa3_desc desc;
  3335. struct ipa_mem_buffer mem;
  3336. struct ipahal_imm_cmd_hdr_init_local cmd = {0};
  3337. struct ipahal_imm_cmd_pyld *cmd_pyld;
  3338. struct ipahal_imm_cmd_dma_shared_mem dma_cmd = { 0 };
  3339. mem.size = IPA_MEM_PART(modem_hdr_size) + IPA_MEM_PART(apps_hdr_size);
  3340. mem.base = dma_zalloc_coherent(ipa3_ctx->pdev, mem.size, &mem.phys_base,
  3341. GFP_KERNEL);
  3342. if (!mem.base) {
  3343. IPAERR("fail to alloc DMA buff of size %d\n", mem.size);
  3344. return -ENOMEM;
  3345. }
  3346. cmd.hdr_table_addr = mem.phys_base;
  3347. cmd.size_hdr_table = mem.size;
  3348. cmd.hdr_addr = ipa3_ctx->smem_restricted_bytes +
  3349. IPA_MEM_PART(modem_hdr_ofst);
  3350. cmd_pyld = ipahal_construct_imm_cmd(
  3351. IPA_IMM_CMD_HDR_INIT_LOCAL, &cmd, false);
  3352. if (!cmd_pyld) {
  3353. IPAERR("fail to construct hdr_init_local imm cmd\n");
  3354. dma_free_coherent(ipa3_ctx->pdev,
  3355. mem.size, mem.base,
  3356. mem.phys_base);
  3357. return -EFAULT;
  3358. }
  3359. ipa3_init_imm_cmd_desc(&desc, cmd_pyld);
  3360. IPA_DUMP_BUFF(mem.base, mem.phys_base, mem.size);
  3361. if (ipa3_send_cmd(1, &desc)) {
  3362. IPAERR("fail to send immediate command\n");
  3363. ipahal_destroy_imm_cmd(cmd_pyld);
  3364. dma_free_coherent(ipa3_ctx->pdev,
  3365. mem.size, mem.base,
  3366. mem.phys_base);
  3367. return -EFAULT;
  3368. }
  3369. ipahal_destroy_imm_cmd(cmd_pyld);
  3370. dma_free_coherent(ipa3_ctx->pdev, mem.size, mem.base, mem.phys_base);
  3371. mem.size = IPA_MEM_PART(modem_hdr_proc_ctx_size) +
  3372. IPA_MEM_PART(apps_hdr_proc_ctx_size);
  3373. mem.base = dma_zalloc_coherent(ipa3_ctx->pdev, mem.size, &mem.phys_base,
  3374. GFP_KERNEL);
  3375. if (!mem.base) {
  3376. IPAERR("fail to alloc DMA buff of size %d\n", mem.size);
  3377. return -ENOMEM;
  3378. }
  3379. dma_cmd.is_read = false;
  3380. dma_cmd.skip_pipeline_clear = false;
  3381. dma_cmd.pipeline_clear_options = IPAHAL_HPS_CLEAR;
  3382. dma_cmd.system_addr = mem.phys_base;
  3383. dma_cmd.local_addr = ipa3_ctx->smem_restricted_bytes +
  3384. IPA_MEM_PART(modem_hdr_proc_ctx_ofst);
  3385. dma_cmd.size = mem.size;
  3386. cmd_pyld = ipahal_construct_imm_cmd(
  3387. IPA_IMM_CMD_DMA_SHARED_MEM, &dma_cmd, false);
  3388. if (!cmd_pyld) {
  3389. IPAERR("fail to construct dma_shared_mem imm\n");
  3390. dma_free_coherent(ipa3_ctx->pdev,
  3391. mem.size, mem.base,
  3392. mem.phys_base);
  3393. return -ENOMEM;
  3394. }
  3395. ipa3_init_imm_cmd_desc(&desc, cmd_pyld);
  3396. IPA_DUMP_BUFF(mem.base, mem.phys_base, mem.size);
  3397. if (ipa3_send_cmd(1, &desc)) {
  3398. IPAERR("fail to send immediate command\n");
  3399. ipahal_destroy_imm_cmd(cmd_pyld);
  3400. dma_free_coherent(ipa3_ctx->pdev,
  3401. mem.size,
  3402. mem.base,
  3403. mem.phys_base);
  3404. return -EBUSY;
  3405. }
  3406. ipahal_destroy_imm_cmd(cmd_pyld);
  3407. ipahal_write_reg(IPA_LOCAL_PKT_PROC_CNTXT_BASE, dma_cmd.local_addr);
  3408. dma_free_coherent(ipa3_ctx->pdev, mem.size, mem.base, mem.phys_base);
  3409. return 0;
  3410. }
  3411. /**
  3412. * _ipa_init_rt4_v3() - Initialize IPA routing block for IPv4.
  3413. *
  3414. * Return codes: 0 for success, negative value for failure
  3415. */
  3416. int _ipa_init_rt4_v3(void)
  3417. {
  3418. struct ipa3_desc desc;
  3419. struct ipa_mem_buffer mem;
  3420. struct ipahal_imm_cmd_ip_v4_routing_init v4_cmd;
  3421. struct ipahal_imm_cmd_pyld *cmd_pyld;
  3422. int i;
  3423. int rc = 0;
  3424. for (i = IPA_MEM_PART(v4_modem_rt_index_lo);
  3425. i <= IPA_MEM_PART(v4_modem_rt_index_hi);
  3426. i++)
  3427. ipa3_ctx->rt_idx_bitmap[IPA_IP_v4] |= (1 << i);
  3428. IPADBG("v4 rt bitmap 0x%lx\n", ipa3_ctx->rt_idx_bitmap[IPA_IP_v4]);
  3429. rc = ipahal_rt_generate_empty_img(IPA_MEM_PART(v4_rt_num_index),
  3430. IPA_MEM_PART(v4_rt_hash_size), IPA_MEM_PART(v4_rt_nhash_size),
  3431. &mem, false);
  3432. if (rc) {
  3433. IPAERR("fail generate empty v4 rt img\n");
  3434. return rc;
  3435. }
  3436. /*
  3437. * SRAM memory not allocated to hash tables. Initializing/Sending
  3438. * command to hash tables(filer/routing) operation not supported.
  3439. */
  3440. if (ipa3_ctx->ipa_fltrt_not_hashable) {
  3441. v4_cmd.hash_rules_addr = 0;
  3442. v4_cmd.hash_rules_size = 0;
  3443. v4_cmd.hash_local_addr = 0;
  3444. } else {
  3445. v4_cmd.hash_rules_addr = mem.phys_base;
  3446. v4_cmd.hash_rules_size = mem.size;
  3447. v4_cmd.hash_local_addr = ipa3_ctx->smem_restricted_bytes +
  3448. IPA_MEM_PART(v4_rt_hash_ofst);
  3449. }
  3450. v4_cmd.nhash_rules_addr = mem.phys_base;
  3451. v4_cmd.nhash_rules_size = mem.size;
  3452. v4_cmd.nhash_local_addr = ipa3_ctx->smem_restricted_bytes +
  3453. IPA_MEM_PART(v4_rt_nhash_ofst);
  3454. IPADBG("putting hashable routing IPv4 rules to phys 0x%x\n",
  3455. v4_cmd.hash_local_addr);
  3456. IPADBG("putting non-hashable routing IPv4 rules to phys 0x%x\n",
  3457. v4_cmd.nhash_local_addr);
  3458. cmd_pyld = ipahal_construct_imm_cmd(
  3459. IPA_IMM_CMD_IP_V4_ROUTING_INIT, &v4_cmd, false);
  3460. if (!cmd_pyld) {
  3461. IPAERR("fail construct ip_v4_rt_init imm cmd\n");
  3462. rc = -EPERM;
  3463. goto free_mem;
  3464. }
  3465. ipa3_init_imm_cmd_desc(&desc, cmd_pyld);
  3466. IPA_DUMP_BUFF(mem.base, mem.phys_base, mem.size);
  3467. if (ipa3_send_cmd(1, &desc)) {
  3468. IPAERR("fail to send immediate command\n");
  3469. rc = -EFAULT;
  3470. }
  3471. ipahal_destroy_imm_cmd(cmd_pyld);
  3472. free_mem:
  3473. ipahal_free_dma_mem(&mem);
  3474. return rc;
  3475. }
  3476. /**
  3477. * _ipa_init_rt6_v3() - Initialize IPA routing block for IPv6.
  3478. *
  3479. * Return codes: 0 for success, negative value for failure
  3480. */
  3481. int _ipa_init_rt6_v3(void)
  3482. {
  3483. struct ipa3_desc desc;
  3484. struct ipa_mem_buffer mem;
  3485. struct ipahal_imm_cmd_ip_v6_routing_init v6_cmd;
  3486. struct ipahal_imm_cmd_pyld *cmd_pyld;
  3487. int i;
  3488. int rc = 0;
  3489. for (i = IPA_MEM_PART(v6_modem_rt_index_lo);
  3490. i <= IPA_MEM_PART(v6_modem_rt_index_hi);
  3491. i++)
  3492. ipa3_ctx->rt_idx_bitmap[IPA_IP_v6] |= (1 << i);
  3493. IPADBG("v6 rt bitmap 0x%lx\n", ipa3_ctx->rt_idx_bitmap[IPA_IP_v6]);
  3494. rc = ipahal_rt_generate_empty_img(IPA_MEM_PART(v6_rt_num_index),
  3495. IPA_MEM_PART(v6_rt_hash_size), IPA_MEM_PART(v6_rt_nhash_size),
  3496. &mem, false);
  3497. if (rc) {
  3498. IPAERR("fail generate empty v6 rt img\n");
  3499. return rc;
  3500. }
  3501. /*
  3502. * SRAM memory not allocated to hash tables. Initializing/Sending
  3503. * command to hash tables(filer/routing) operation not supported.
  3504. */
  3505. if (ipa3_ctx->ipa_fltrt_not_hashable) {
  3506. v6_cmd.hash_rules_addr = 0;
  3507. v6_cmd.hash_rules_size = 0;
  3508. v6_cmd.hash_local_addr = 0;
  3509. } else {
  3510. v6_cmd.hash_rules_addr = mem.phys_base;
  3511. v6_cmd.hash_rules_size = mem.size;
  3512. v6_cmd.hash_local_addr = ipa3_ctx->smem_restricted_bytes +
  3513. IPA_MEM_PART(v6_rt_hash_ofst);
  3514. }
  3515. v6_cmd.nhash_rules_addr = mem.phys_base;
  3516. v6_cmd.nhash_rules_size = mem.size;
  3517. v6_cmd.nhash_local_addr = ipa3_ctx->smem_restricted_bytes +
  3518. IPA_MEM_PART(v6_rt_nhash_ofst);
  3519. IPADBG("putting hashable routing IPv6 rules to phys 0x%x\n",
  3520. v6_cmd.hash_local_addr);
  3521. IPADBG("putting non-hashable routing IPv6 rules to phys 0x%x\n",
  3522. v6_cmd.nhash_local_addr);
  3523. cmd_pyld = ipahal_construct_imm_cmd(
  3524. IPA_IMM_CMD_IP_V6_ROUTING_INIT, &v6_cmd, false);
  3525. if (!cmd_pyld) {
  3526. IPAERR("fail construct ip_v6_rt_init imm cmd\n");
  3527. rc = -EPERM;
  3528. goto free_mem;
  3529. }
  3530. ipa3_init_imm_cmd_desc(&desc, cmd_pyld);
  3531. IPA_DUMP_BUFF(mem.base, mem.phys_base, mem.size);
  3532. if (ipa3_send_cmd(1, &desc)) {
  3533. IPAERR("fail to send immediate command\n");
  3534. rc = -EFAULT;
  3535. }
  3536. ipahal_destroy_imm_cmd(cmd_pyld);
  3537. free_mem:
  3538. ipahal_free_dma_mem(&mem);
  3539. return rc;
  3540. }
  3541. /**
  3542. * _ipa_init_flt4_v3() - Initialize IPA filtering block for IPv4.
  3543. *
  3544. * Return codes: 0 for success, negative value for failure
  3545. */
  3546. int _ipa_init_flt4_v3(void)
  3547. {
  3548. struct ipa3_desc desc;
  3549. struct ipa_mem_buffer mem;
  3550. struct ipahal_imm_cmd_ip_v4_filter_init v4_cmd;
  3551. struct ipahal_imm_cmd_pyld *cmd_pyld;
  3552. int rc;
  3553. rc = ipahal_flt_generate_empty_img(ipa3_ctx->ep_flt_num,
  3554. IPA_MEM_PART(v4_flt_hash_size),
  3555. IPA_MEM_PART(v4_flt_nhash_size), ipa3_ctx->ep_flt_bitmap,
  3556. &mem, false);
  3557. if (rc) {
  3558. IPAERR("fail generate empty v4 flt img\n");
  3559. return rc;
  3560. }
  3561. /*
  3562. * SRAM memory not allocated to hash tables. Initializing/Sending
  3563. * command to hash tables(filer/routing) operation not supported.
  3564. */
  3565. if (ipa3_ctx->ipa_fltrt_not_hashable) {
  3566. v4_cmd.hash_rules_addr = 0;
  3567. v4_cmd.hash_rules_size = 0;
  3568. v4_cmd.hash_local_addr = 0;
  3569. } else {
  3570. v4_cmd.hash_rules_addr = mem.phys_base;
  3571. v4_cmd.hash_rules_size = mem.size;
  3572. v4_cmd.hash_local_addr = ipa3_ctx->smem_restricted_bytes +
  3573. IPA_MEM_PART(v4_flt_hash_ofst);
  3574. }
  3575. v4_cmd.nhash_rules_addr = mem.phys_base;
  3576. v4_cmd.nhash_rules_size = mem.size;
  3577. v4_cmd.nhash_local_addr = ipa3_ctx->smem_restricted_bytes +
  3578. IPA_MEM_PART(v4_flt_nhash_ofst);
  3579. IPADBG("putting hashable filtering IPv4 rules to phys 0x%x\n",
  3580. v4_cmd.hash_local_addr);
  3581. IPADBG("putting non-hashable filtering IPv4 rules to phys 0x%x\n",
  3582. v4_cmd.nhash_local_addr);
  3583. cmd_pyld = ipahal_construct_imm_cmd(
  3584. IPA_IMM_CMD_IP_V4_FILTER_INIT, &v4_cmd, false);
  3585. if (!cmd_pyld) {
  3586. IPAERR("fail construct ip_v4_flt_init imm cmd\n");
  3587. rc = -EPERM;
  3588. goto free_mem;
  3589. }
  3590. ipa3_init_imm_cmd_desc(&desc, cmd_pyld);
  3591. IPA_DUMP_BUFF(mem.base, mem.phys_base, mem.size);
  3592. if (ipa3_send_cmd(1, &desc)) {
  3593. IPAERR("fail to send immediate command\n");
  3594. rc = -EFAULT;
  3595. }
  3596. ipahal_destroy_imm_cmd(cmd_pyld);
  3597. free_mem:
  3598. ipahal_free_dma_mem(&mem);
  3599. return rc;
  3600. }
  3601. /**
  3602. * _ipa_init_flt6_v3() - Initialize IPA filtering block for IPv6.
  3603. *
  3604. * Return codes: 0 for success, negative value for failure
  3605. */
  3606. int _ipa_init_flt6_v3(void)
  3607. {
  3608. struct ipa3_desc desc;
  3609. struct ipa_mem_buffer mem;
  3610. struct ipahal_imm_cmd_ip_v6_filter_init v6_cmd;
  3611. struct ipahal_imm_cmd_pyld *cmd_pyld;
  3612. int rc;
  3613. rc = ipahal_flt_generate_empty_img(ipa3_ctx->ep_flt_num,
  3614. IPA_MEM_PART(v6_flt_hash_size),
  3615. IPA_MEM_PART(v6_flt_nhash_size), ipa3_ctx->ep_flt_bitmap,
  3616. &mem, false);
  3617. if (rc) {
  3618. IPAERR("fail generate empty v6 flt img\n");
  3619. return rc;
  3620. }
  3621. /*
  3622. * SRAM memory not allocated to hash tables. Initializing/Sending
  3623. * command to hash tables(filer/routing) operation not supported.
  3624. */
  3625. if (ipa3_ctx->ipa_fltrt_not_hashable) {
  3626. v6_cmd.hash_rules_addr = 0;
  3627. v6_cmd.hash_rules_size = 0;
  3628. v6_cmd.hash_local_addr = 0;
  3629. } else {
  3630. v6_cmd.hash_rules_addr = mem.phys_base;
  3631. v6_cmd.hash_rules_size = mem.size;
  3632. v6_cmd.hash_local_addr = ipa3_ctx->smem_restricted_bytes +
  3633. IPA_MEM_PART(v6_flt_hash_ofst);
  3634. }
  3635. v6_cmd.nhash_rules_addr = mem.phys_base;
  3636. v6_cmd.nhash_rules_size = mem.size;
  3637. v6_cmd.nhash_local_addr = ipa3_ctx->smem_restricted_bytes +
  3638. IPA_MEM_PART(v6_flt_nhash_ofst);
  3639. IPADBG("putting hashable filtering IPv6 rules to phys 0x%x\n",
  3640. v6_cmd.hash_local_addr);
  3641. IPADBG("putting non-hashable filtering IPv6 rules to phys 0x%x\n",
  3642. v6_cmd.nhash_local_addr);
  3643. cmd_pyld = ipahal_construct_imm_cmd(
  3644. IPA_IMM_CMD_IP_V6_FILTER_INIT, &v6_cmd, false);
  3645. if (!cmd_pyld) {
  3646. IPAERR("fail construct ip_v6_flt_init imm cmd\n");
  3647. rc = -EPERM;
  3648. goto free_mem;
  3649. }
  3650. ipa3_init_imm_cmd_desc(&desc, cmd_pyld);
  3651. IPA_DUMP_BUFF(mem.base, mem.phys_base, mem.size);
  3652. if (ipa3_send_cmd(1, &desc)) {
  3653. IPAERR("fail to send immediate command\n");
  3654. rc = -EFAULT;
  3655. }
  3656. ipahal_destroy_imm_cmd(cmd_pyld);
  3657. free_mem:
  3658. ipahal_free_dma_mem(&mem);
  3659. return rc;
  3660. }
  3661. static int ipa3_setup_flt_hash_tuple(void)
  3662. {
  3663. int pipe_idx;
  3664. struct ipahal_reg_hash_tuple tuple;
  3665. memset(&tuple, 0, sizeof(struct ipahal_reg_hash_tuple));
  3666. for (pipe_idx = 0; pipe_idx < ipa3_ctx->ipa_num_pipes ; pipe_idx++) {
  3667. if (!ipa_is_ep_support_flt(pipe_idx))
  3668. continue;
  3669. if (ipa_is_modem_pipe(pipe_idx))
  3670. continue;
  3671. if (ipa3_set_flt_tuple_mask(pipe_idx, &tuple)) {
  3672. IPAERR("failed to setup pipe %d flt tuple\n", pipe_idx);
  3673. return -EFAULT;
  3674. }
  3675. }
  3676. return 0;
  3677. }
  3678. static int ipa3_setup_rt_hash_tuple(void)
  3679. {
  3680. int tbl_idx;
  3681. struct ipahal_reg_hash_tuple tuple;
  3682. memset(&tuple, 0, sizeof(struct ipahal_reg_hash_tuple));
  3683. for (tbl_idx = 0;
  3684. tbl_idx < max(IPA_MEM_PART(v6_rt_num_index),
  3685. IPA_MEM_PART(v4_rt_num_index));
  3686. tbl_idx++) {
  3687. if (tbl_idx >= IPA_MEM_PART(v4_modem_rt_index_lo) &&
  3688. tbl_idx <= IPA_MEM_PART(v4_modem_rt_index_hi))
  3689. continue;
  3690. if (tbl_idx >= IPA_MEM_PART(v6_modem_rt_index_lo) &&
  3691. tbl_idx <= IPA_MEM_PART(v6_modem_rt_index_hi))
  3692. continue;
  3693. if (ipa3_set_rt_tuple_mask(tbl_idx, &tuple)) {
  3694. IPAERR("failed to setup tbl %d rt tuple\n", tbl_idx);
  3695. return -EFAULT;
  3696. }
  3697. }
  3698. return 0;
  3699. }
  3700. static int ipa3_setup_apps_pipes(void)
  3701. {
  3702. struct ipa_sys_connect_params sys_in;
  3703. int result = 0;
  3704. if (ipa3_ctx->gsi_ch20_wa) {
  3705. IPADBG("Allocating GSI physical channel 20\n");
  3706. result = ipa_gsi_ch20_wa();
  3707. if (result) {
  3708. IPAERR("ipa_gsi_ch20_wa failed %d\n", result);
  3709. goto fail_ch20_wa;
  3710. }
  3711. }
  3712. /* allocate the common PROD event ring */
  3713. if (ipa3_alloc_common_event_ring()) {
  3714. IPAERR("ipa3_alloc_common_event_ring failed.\n");
  3715. result = -EPERM;
  3716. goto fail_ch20_wa;
  3717. }
  3718. /* CMD OUT (AP->IPA) */
  3719. memset(&sys_in, 0, sizeof(struct ipa_sys_connect_params));
  3720. sys_in.client = IPA_CLIENT_APPS_CMD_PROD;
  3721. sys_in.desc_fifo_sz = IPA_SYS_DESC_FIFO_SZ;
  3722. sys_in.ipa_ep_cfg.mode.mode = IPA_DMA;
  3723. sys_in.ipa_ep_cfg.mode.dst = IPA_CLIENT_APPS_LAN_CONS;
  3724. if (ipa3_setup_sys_pipe(&sys_in, &ipa3_ctx->clnt_hdl_cmd)) {
  3725. IPAERR(":setup sys pipe (APPS_CMD_PROD) failed.\n");
  3726. result = -EPERM;
  3727. goto fail_ch20_wa;
  3728. }
  3729. IPADBG("Apps to IPA cmd pipe is connected\n");
  3730. IPADBG("Will initialize SRAM\n");
  3731. ipa3_ctx->ctrl->ipa_init_sram();
  3732. IPADBG("SRAM initialized\n");
  3733. IPADBG("Will initialize HDR\n");
  3734. ipa3_ctx->ctrl->ipa_init_hdr();
  3735. IPADBG("HDR initialized\n");
  3736. IPADBG("Will initialize V4 RT\n");
  3737. ipa3_ctx->ctrl->ipa_init_rt4();
  3738. IPADBG("V4 RT initialized\n");
  3739. IPADBG("Will initialize V6 RT\n");
  3740. ipa3_ctx->ctrl->ipa_init_rt6();
  3741. IPADBG("V6 RT initialized\n");
  3742. IPADBG("Will initialize V4 FLT\n");
  3743. ipa3_ctx->ctrl->ipa_init_flt4();
  3744. IPADBG("V4 FLT initialized\n");
  3745. IPADBG("Will initialize V6 FLT\n");
  3746. ipa3_ctx->ctrl->ipa_init_flt6();
  3747. IPADBG("V6 FLT initialized\n");
  3748. if (!ipa3_ctx->ipa_fltrt_not_hashable) {
  3749. if (ipa3_setup_flt_hash_tuple()) {
  3750. IPAERR(":fail to configure flt hash tuple\n");
  3751. result = -EPERM;
  3752. goto fail_flt_hash_tuple;
  3753. }
  3754. IPADBG("flt hash tuple is configured\n");
  3755. if (ipa3_setup_rt_hash_tuple()) {
  3756. IPAERR(":fail to configure rt hash tuple\n");
  3757. result = -EPERM;
  3758. goto fail_flt_hash_tuple;
  3759. }
  3760. IPADBG("rt hash tuple is configured\n");
  3761. }
  3762. if (ipa3_setup_exception_path()) {
  3763. IPAERR(":fail to setup excp path\n");
  3764. result = -EPERM;
  3765. goto fail_flt_hash_tuple;
  3766. }
  3767. IPADBG("Exception path was successfully set");
  3768. if (ipa3_setup_dflt_rt_tables()) {
  3769. IPAERR(":fail to setup dflt routes\n");
  3770. result = -EPERM;
  3771. goto fail_flt_hash_tuple;
  3772. }
  3773. IPADBG("default routing was set\n");
  3774. /* LAN IN (IPA->AP) */
  3775. memset(&sys_in, 0, sizeof(struct ipa_sys_connect_params));
  3776. sys_in.client = IPA_CLIENT_APPS_LAN_CONS;
  3777. sys_in.desc_fifo_sz = IPA_SYS_DESC_FIFO_SZ;
  3778. sys_in.notify = ipa3_lan_rx_cb;
  3779. sys_in.priv = NULL;
  3780. sys_in.ipa_ep_cfg.hdr.hdr_len = IPA_LAN_RX_HEADER_LENGTH;
  3781. sys_in.ipa_ep_cfg.hdr_ext.hdr_little_endian = false;
  3782. sys_in.ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad_valid = true;
  3783. sys_in.ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad = IPA_HDR_PAD;
  3784. sys_in.ipa_ep_cfg.hdr_ext.hdr_payload_len_inc_padding = false;
  3785. sys_in.ipa_ep_cfg.hdr_ext.hdr_total_len_or_pad_offset = 0;
  3786. sys_in.ipa_ep_cfg.hdr_ext.hdr_pad_to_alignment = 2;
  3787. sys_in.ipa_ep_cfg.cfg.cs_offload_en = IPA_DISABLE_CS_OFFLOAD;
  3788. /**
  3789. * ipa_lan_rx_cb() intended to notify the source EP about packet
  3790. * being received on the LAN_CONS via calling the source EP call-back.
  3791. * There could be a race condition with calling this call-back. Other
  3792. * thread may nullify it - e.g. on EP disconnect.
  3793. * This lock intended to protect the access to the source EP call-back
  3794. */
  3795. spin_lock_init(&ipa3_ctx->disconnect_lock);
  3796. if (ipa3_setup_sys_pipe(&sys_in, &ipa3_ctx->clnt_hdl_data_in)) {
  3797. IPAERR(":setup sys pipe (LAN_CONS) failed.\n");
  3798. result = -EPERM;
  3799. goto fail_flt_hash_tuple;
  3800. }
  3801. /* LAN OUT (AP->IPA) */
  3802. if (!ipa3_ctx->ipa_config_is_mhi) {
  3803. memset(&sys_in, 0, sizeof(struct ipa_sys_connect_params));
  3804. sys_in.client = IPA_CLIENT_APPS_LAN_PROD;
  3805. sys_in.desc_fifo_sz = IPA_SYS_TX_DATA_DESC_FIFO_SZ;
  3806. sys_in.ipa_ep_cfg.mode.mode = IPA_BASIC;
  3807. if (ipa3_setup_sys_pipe(&sys_in,
  3808. &ipa3_ctx->clnt_hdl_data_out)) {
  3809. IPAERR(":setup sys pipe (LAN_PROD) failed.\n");
  3810. result = -EPERM;
  3811. goto fail_lan_data_out;
  3812. }
  3813. }
  3814. return 0;
  3815. fail_lan_data_out:
  3816. ipa3_teardown_sys_pipe(ipa3_ctx->clnt_hdl_data_in);
  3817. fail_flt_hash_tuple:
  3818. if (ipa3_ctx->dflt_v6_rt_rule_hdl)
  3819. __ipa3_del_rt_rule(ipa3_ctx->dflt_v6_rt_rule_hdl);
  3820. if (ipa3_ctx->dflt_v4_rt_rule_hdl)
  3821. __ipa3_del_rt_rule(ipa3_ctx->dflt_v4_rt_rule_hdl);
  3822. if (ipa3_ctx->excp_hdr_hdl)
  3823. __ipa3_del_hdr(ipa3_ctx->excp_hdr_hdl, false);
  3824. ipa3_teardown_sys_pipe(ipa3_ctx->clnt_hdl_cmd);
  3825. fail_ch20_wa:
  3826. return result;
  3827. }
  3828. static void ipa3_teardown_apps_pipes(void)
  3829. {
  3830. if (!ipa3_ctx->ipa_config_is_mhi)
  3831. ipa3_teardown_sys_pipe(ipa3_ctx->clnt_hdl_data_out);
  3832. ipa3_teardown_sys_pipe(ipa3_ctx->clnt_hdl_data_in);
  3833. __ipa3_del_rt_rule(ipa3_ctx->dflt_v6_rt_rule_hdl);
  3834. __ipa3_del_rt_rule(ipa3_ctx->dflt_v4_rt_rule_hdl);
  3835. __ipa3_del_hdr(ipa3_ctx->excp_hdr_hdl, false);
  3836. ipa3_teardown_sys_pipe(ipa3_ctx->clnt_hdl_cmd);
  3837. }
  3838. #ifdef CONFIG_COMPAT
  3839. static long compat_ipa3_nat_ipv6ct_alloc_table(unsigned long arg,
  3840. int (alloc_func)(struct ipa_ioc_nat_ipv6ct_table_alloc *))
  3841. {
  3842. long retval;
  3843. struct ipa_ioc_nat_ipv6ct_table_alloc32 table_alloc32;
  3844. struct ipa_ioc_nat_ipv6ct_table_alloc table_alloc;
  3845. retval = copy_from_user(&table_alloc32, (const void __user *)arg,
  3846. sizeof(struct ipa_ioc_nat_ipv6ct_table_alloc32));
  3847. if (retval)
  3848. return retval;
  3849. table_alloc.size = (size_t)table_alloc32.size;
  3850. table_alloc.offset = (off_t)table_alloc32.offset;
  3851. retval = alloc_func(&table_alloc);
  3852. if (retval)
  3853. return retval;
  3854. if (table_alloc.offset) {
  3855. table_alloc32.offset = (compat_off_t)table_alloc.offset;
  3856. retval = copy_to_user((void __user *)arg, &table_alloc32,
  3857. sizeof(struct ipa_ioc_nat_ipv6ct_table_alloc32));
  3858. }
  3859. return retval;
  3860. }
  3861. long compat_ipa3_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  3862. {
  3863. long retval = 0;
  3864. struct ipa3_ioc_nat_alloc_mem32 nat_mem32;
  3865. struct ipa_ioc_nat_alloc_mem nat_mem;
  3866. switch (cmd) {
  3867. case IPA_IOC_ADD_HDR32:
  3868. cmd = IPA_IOC_ADD_HDR;
  3869. break;
  3870. case IPA_IOC_DEL_HDR32:
  3871. cmd = IPA_IOC_DEL_HDR;
  3872. break;
  3873. case IPA_IOC_ADD_RT_RULE32:
  3874. cmd = IPA_IOC_ADD_RT_RULE;
  3875. break;
  3876. case IPA_IOC_DEL_RT_RULE32:
  3877. cmd = IPA_IOC_DEL_RT_RULE;
  3878. break;
  3879. case IPA_IOC_ADD_FLT_RULE32:
  3880. cmd = IPA_IOC_ADD_FLT_RULE;
  3881. break;
  3882. case IPA_IOC_DEL_FLT_RULE32:
  3883. cmd = IPA_IOC_DEL_FLT_RULE;
  3884. break;
  3885. case IPA_IOC_GET_RT_TBL32:
  3886. cmd = IPA_IOC_GET_RT_TBL;
  3887. break;
  3888. case IPA_IOC_COPY_HDR32:
  3889. cmd = IPA_IOC_COPY_HDR;
  3890. break;
  3891. case IPA_IOC_QUERY_INTF32:
  3892. cmd = IPA_IOC_QUERY_INTF;
  3893. break;
  3894. case IPA_IOC_QUERY_INTF_TX_PROPS32:
  3895. cmd = IPA_IOC_QUERY_INTF_TX_PROPS;
  3896. break;
  3897. case IPA_IOC_QUERY_INTF_RX_PROPS32:
  3898. cmd = IPA_IOC_QUERY_INTF_RX_PROPS;
  3899. break;
  3900. case IPA_IOC_QUERY_INTF_EXT_PROPS32:
  3901. cmd = IPA_IOC_QUERY_INTF_EXT_PROPS;
  3902. break;
  3903. case IPA_IOC_GET_HDR32:
  3904. cmd = IPA_IOC_GET_HDR;
  3905. break;
  3906. case IPA_IOC_ALLOC_NAT_MEM32:
  3907. retval = copy_from_user(&nat_mem32, (const void __user *)arg,
  3908. sizeof(struct ipa3_ioc_nat_alloc_mem32));
  3909. if (retval)
  3910. return retval;
  3911. memcpy(nat_mem.dev_name, nat_mem32.dev_name,
  3912. IPA_RESOURCE_NAME_MAX);
  3913. nat_mem.size = (size_t)nat_mem32.size;
  3914. nat_mem.offset = (off_t)nat_mem32.offset;
  3915. /* null terminate the string */
  3916. nat_mem.dev_name[IPA_RESOURCE_NAME_MAX - 1] = '\0';
  3917. retval = ipa3_allocate_nat_device(&nat_mem);
  3918. if (retval)
  3919. return retval;
  3920. nat_mem32.offset = (compat_off_t)nat_mem.offset;
  3921. retval = copy_to_user((void __user *)arg, &nat_mem32,
  3922. sizeof(struct ipa3_ioc_nat_alloc_mem32));
  3923. return retval;
  3924. case IPA_IOC_ALLOC_NAT_TABLE32:
  3925. return compat_ipa3_nat_ipv6ct_alloc_table(arg,
  3926. ipa3_allocate_nat_table);
  3927. case IPA_IOC_ALLOC_IPV6CT_TABLE32:
  3928. return compat_ipa3_nat_ipv6ct_alloc_table(arg,
  3929. ipa3_allocate_ipv6ct_table);
  3930. case IPA_IOC_V4_INIT_NAT32:
  3931. cmd = IPA_IOC_V4_INIT_NAT;
  3932. break;
  3933. case IPA_IOC_INIT_IPV6CT_TABLE32:
  3934. cmd = IPA_IOC_INIT_IPV6CT_TABLE;
  3935. break;
  3936. case IPA_IOC_TABLE_DMA_CMD32:
  3937. cmd = IPA_IOC_TABLE_DMA_CMD;
  3938. break;
  3939. case IPA_IOC_V4_DEL_NAT32:
  3940. cmd = IPA_IOC_V4_DEL_NAT;
  3941. break;
  3942. case IPA_IOC_DEL_NAT_TABLE32:
  3943. cmd = IPA_IOC_DEL_NAT_TABLE;
  3944. break;
  3945. case IPA_IOC_DEL_IPV6CT_TABLE32:
  3946. cmd = IPA_IOC_DEL_IPV6CT_TABLE;
  3947. break;
  3948. case IPA_IOC_NAT_MODIFY_PDN32:
  3949. cmd = IPA_IOC_NAT_MODIFY_PDN;
  3950. break;
  3951. case IPA_IOC_GET_NAT_OFFSET32:
  3952. cmd = IPA_IOC_GET_NAT_OFFSET;
  3953. break;
  3954. case IPA_IOC_PULL_MSG32:
  3955. cmd = IPA_IOC_PULL_MSG;
  3956. break;
  3957. case IPA_IOC_RM_ADD_DEPENDENCY32:
  3958. cmd = IPA_IOC_RM_ADD_DEPENDENCY;
  3959. break;
  3960. case IPA_IOC_RM_DEL_DEPENDENCY32:
  3961. cmd = IPA_IOC_RM_DEL_DEPENDENCY;
  3962. break;
  3963. case IPA_IOC_GENERATE_FLT_EQ32:
  3964. cmd = IPA_IOC_GENERATE_FLT_EQ;
  3965. break;
  3966. case IPA_IOC_QUERY_RT_TBL_INDEX32:
  3967. cmd = IPA_IOC_QUERY_RT_TBL_INDEX;
  3968. break;
  3969. case IPA_IOC_WRITE_QMAPID32:
  3970. cmd = IPA_IOC_WRITE_QMAPID;
  3971. break;
  3972. case IPA_IOC_MDFY_FLT_RULE32:
  3973. cmd = IPA_IOC_MDFY_FLT_RULE;
  3974. break;
  3975. case IPA_IOC_NOTIFY_WAN_UPSTREAM_ROUTE_ADD32:
  3976. cmd = IPA_IOC_NOTIFY_WAN_UPSTREAM_ROUTE_ADD;
  3977. break;
  3978. case IPA_IOC_NOTIFY_WAN_UPSTREAM_ROUTE_DEL32:
  3979. cmd = IPA_IOC_NOTIFY_WAN_UPSTREAM_ROUTE_DEL;
  3980. break;
  3981. case IPA_IOC_NOTIFY_WAN_EMBMS_CONNECTED32:
  3982. cmd = IPA_IOC_NOTIFY_WAN_EMBMS_CONNECTED;
  3983. break;
  3984. case IPA_IOC_MDFY_RT_RULE32:
  3985. cmd = IPA_IOC_MDFY_RT_RULE;
  3986. break;
  3987. case IPA_IOC_COMMIT_HDR:
  3988. case IPA_IOC_RESET_HDR:
  3989. case IPA_IOC_COMMIT_RT:
  3990. case IPA_IOC_RESET_RT:
  3991. case IPA_IOC_COMMIT_FLT:
  3992. case IPA_IOC_RESET_FLT:
  3993. case IPA_IOC_DUMP:
  3994. case IPA_IOC_PUT_RT_TBL:
  3995. case IPA_IOC_PUT_HDR:
  3996. case IPA_IOC_SET_FLT:
  3997. case IPA_IOC_QUERY_EP_MAPPING:
  3998. break;
  3999. default:
  4000. return -ENOIOCTLCMD;
  4001. }
  4002. return ipa3_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
  4003. }
  4004. #endif
  4005. static ssize_t ipa3_write(struct file *file, const char __user *buf,
  4006. size_t count, loff_t *ppos);
  4007. static const struct file_operations ipa3_drv_fops = {
  4008. .owner = THIS_MODULE,
  4009. .open = ipa3_open,
  4010. .read = ipa3_read,
  4011. .write = ipa3_write,
  4012. .unlocked_ioctl = ipa3_ioctl,
  4013. #ifdef CONFIG_COMPAT
  4014. .compat_ioctl = compat_ipa3_ioctl,
  4015. #endif
  4016. };
  4017. static int ipa3_get_clks(struct device *dev)
  4018. {
  4019. if (ipa3_ctx->ipa3_hw_mode != IPA_HW_MODE_NORMAL) {
  4020. IPADBG("not supported in this HW mode\n");
  4021. ipa3_clk = NULL;
  4022. return 0;
  4023. }
  4024. if (ipa3_res.use_bw_vote) {
  4025. IPADBG("Vote IPA clock by bw voting via bus scaling driver\n");
  4026. ipa3_clk = NULL;
  4027. return 0;
  4028. }
  4029. ipa3_clk = clk_get(dev, "core_clk");
  4030. if (IS_ERR(ipa3_clk)) {
  4031. if (ipa3_clk != ERR_PTR(-EPROBE_DEFER))
  4032. IPAERR("fail to get ipa clk\n");
  4033. return PTR_ERR(ipa3_clk);
  4034. }
  4035. return 0;
  4036. }
  4037. /**
  4038. * _ipa_enable_clks_v3_0() - Enable IPA clocks.
  4039. */
  4040. void _ipa_enable_clks_v3_0(void)
  4041. {
  4042. IPADBG_LOW("curr_ipa_clk_rate=%d", ipa3_ctx->curr_ipa_clk_rate);
  4043. if (ipa3_clk) {
  4044. IPADBG_LOW("enabling gcc_ipa_clk\n");
  4045. clk_prepare(ipa3_clk);
  4046. clk_enable(ipa3_clk);
  4047. clk_set_rate(ipa3_clk, ipa3_ctx->curr_ipa_clk_rate);
  4048. }
  4049. ipa3_uc_notify_clk_state(true);
  4050. }
  4051. static unsigned int ipa3_get_bus_vote(void)
  4052. {
  4053. unsigned int idx = 1;
  4054. if (ipa3_ctx->curr_ipa_clk_rate == ipa3_ctx->ctrl->ipa_clk_rate_svs2) {
  4055. idx = 1;
  4056. } else if (ipa3_ctx->curr_ipa_clk_rate ==
  4057. ipa3_ctx->ctrl->ipa_clk_rate_svs) {
  4058. idx = 2;
  4059. } else if (ipa3_ctx->curr_ipa_clk_rate ==
  4060. ipa3_ctx->ctrl->ipa_clk_rate_nominal) {
  4061. idx = 3;
  4062. } else if (ipa3_ctx->curr_ipa_clk_rate ==
  4063. ipa3_ctx->ctrl->ipa_clk_rate_turbo) {
  4064. idx = ipa3_ctx->ctrl->msm_bus_data_ptr->num_usecases - 1;
  4065. } else {
  4066. WARN(1, "unexpected clock rate");
  4067. }
  4068. IPADBG_LOW("curr %d idx %d\n", ipa3_ctx->curr_ipa_clk_rate, idx);
  4069. return idx;
  4070. }
  4071. /**
  4072. * ipa3_enable_clks() - Turn on IPA clocks
  4073. *
  4074. * Return codes:
  4075. * None
  4076. */
  4077. void ipa3_enable_clks(void)
  4078. {
  4079. if (ipa3_ctx->ipa3_hw_mode != IPA_HW_MODE_NORMAL) {
  4080. IPAERR("not supported in this mode\n");
  4081. return;
  4082. }
  4083. IPADBG("enabling IPA clocks and bus voting\n");
  4084. if (msm_bus_scale_client_update_request(ipa3_ctx->ipa_bus_hdl,
  4085. ipa3_get_bus_vote()))
  4086. WARN(1, "bus scaling failed");
  4087. ipa3_ctx->ctrl->ipa3_enable_clks();
  4088. atomic_set(&ipa3_ctx->ipa_clk_vote, 1);
  4089. }
  4090. /**
  4091. * _ipa_disable_clks_v3_0() - Disable IPA clocks.
  4092. */
  4093. void _ipa_disable_clks_v3_0(void)
  4094. {
  4095. ipa3_uc_notify_clk_state(false);
  4096. if (ipa3_clk) {
  4097. IPADBG_LOW("disabling gcc_ipa_clk\n");
  4098. clk_disable_unprepare(ipa3_clk);
  4099. }
  4100. }
  4101. /**
  4102. * ipa3_disable_clks() - Turn off IPA clocks
  4103. *
  4104. * Return codes:
  4105. * None
  4106. */
  4107. void ipa3_disable_clks(void)
  4108. {
  4109. if (ipa3_ctx->ipa3_hw_mode != IPA_HW_MODE_NORMAL) {
  4110. IPAERR("not supported in this mode\n");
  4111. return;
  4112. }
  4113. IPADBG("disabling IPA clocks and bus voting\n");
  4114. ipa3_ctx->ctrl->ipa3_disable_clks();
  4115. ipa_pm_set_clock_index(0);
  4116. if (msm_bus_scale_client_update_request(ipa3_ctx->ipa_bus_hdl, 0))
  4117. WARN(1, "bus scaling failed");
  4118. atomic_set(&ipa3_ctx->ipa_clk_vote, 0);
  4119. }
  4120. /**
  4121. * ipa3_start_tag_process() - Send TAG packet and wait for it to come back
  4122. *
  4123. * This function is called prior to clock gating when active client counter
  4124. * is 1. TAG process ensures that there are no packets inside IPA HW that
  4125. * were not submitted to the IPA client via the transport. During TAG process
  4126. * all aggregation frames are (force) closed.
  4127. *
  4128. * Return codes:
  4129. * None
  4130. */
  4131. static void ipa3_start_tag_process(struct work_struct *work)
  4132. {
  4133. int res;
  4134. IPADBG("starting TAG process\n");
  4135. /* close aggregation frames on all pipes */
  4136. res = ipa3_tag_aggr_force_close(-1);
  4137. if (res)
  4138. IPAERR("ipa3_tag_aggr_force_close failed %d\n", res);
  4139. IPA_ACTIVE_CLIENTS_DEC_SPECIAL("TAG_PROCESS");
  4140. IPADBG("TAG process done\n");
  4141. }
  4142. /**
  4143. * ipa3_active_clients_log_mod() - Log a modification in the active clients
  4144. * reference count
  4145. *
  4146. * This method logs any modification in the active clients reference count:
  4147. * It logs the modification in the circular history buffer
  4148. * It logs the modification in the hash table - looking for an entry,
  4149. * creating one if needed and deleting one if needed.
  4150. *
  4151. * @id: ipa3_active client logging info struct to hold the log information
  4152. * @inc: a boolean variable to indicate whether the modification is an increase
  4153. * or decrease
  4154. * @int_ctx: a boolean variable to indicate whether this call is being made from
  4155. * an interrupt context and therefore should allocate GFP_ATOMIC memory
  4156. *
  4157. * Method process:
  4158. * - Hash the unique identifier string
  4159. * - Find the hash in the table
  4160. * 1)If found, increase or decrease the reference count
  4161. * 2)If not found, allocate a new hash table entry struct and initialize it
  4162. * - Remove and deallocate unneeded data structure
  4163. * - Log the call in the circular history buffer (unless it is a simple call)
  4164. */
  4165. #ifdef CONFIG_IPA_DEBUG
  4166. static void ipa3_active_clients_log_mod(
  4167. struct ipa_active_client_logging_info *id,
  4168. bool inc, bool int_ctx)
  4169. {
  4170. char temp_str[IPA3_ACTIVE_CLIENTS_LOG_LINE_LEN];
  4171. unsigned long long t;
  4172. unsigned long nanosec_rem;
  4173. struct ipa3_active_client_htable_entry *hentry;
  4174. struct ipa3_active_client_htable_entry *hfound;
  4175. u32 hkey;
  4176. char str_to_hash[IPA3_ACTIVE_CLIENTS_LOG_NAME_LEN];
  4177. unsigned long flags;
  4178. spin_lock_irqsave(&ipa3_ctx->ipa3_active_clients_logging.lock, flags);
  4179. int_ctx = true;
  4180. hfound = NULL;
  4181. memset(str_to_hash, 0, IPA3_ACTIVE_CLIENTS_LOG_NAME_LEN);
  4182. strlcpy(str_to_hash, id->id_string, IPA3_ACTIVE_CLIENTS_LOG_NAME_LEN);
  4183. hkey = jhash(str_to_hash, IPA3_ACTIVE_CLIENTS_LOG_NAME_LEN,
  4184. 0);
  4185. hash_for_each_possible(ipa3_ctx->ipa3_active_clients_logging.htable,
  4186. hentry, list, hkey) {
  4187. if (!strcmp(hentry->id_string, id->id_string)) {
  4188. hentry->count = hentry->count + (inc ? 1 : -1);
  4189. hfound = hentry;
  4190. }
  4191. }
  4192. if (hfound == NULL) {
  4193. hentry = NULL;
  4194. hentry = kzalloc(sizeof(
  4195. struct ipa3_active_client_htable_entry),
  4196. int_ctx ? GFP_ATOMIC : GFP_KERNEL);
  4197. if (hentry == NULL) {
  4198. spin_unlock_irqrestore(
  4199. &ipa3_ctx->ipa3_active_clients_logging.lock,
  4200. flags);
  4201. return;
  4202. }
  4203. hentry->type = id->type;
  4204. strlcpy(hentry->id_string, id->id_string,
  4205. IPA3_ACTIVE_CLIENTS_LOG_NAME_LEN);
  4206. INIT_HLIST_NODE(&hentry->list);
  4207. hentry->count = inc ? 1 : -1;
  4208. hash_add(ipa3_ctx->ipa3_active_clients_logging.htable,
  4209. &hentry->list, hkey);
  4210. } else if (hfound->count == 0) {
  4211. hash_del(&hfound->list);
  4212. kfree(hfound);
  4213. }
  4214. if (id->type != SIMPLE) {
  4215. t = local_clock();
  4216. nanosec_rem = do_div(t, 1000000000) / 1000;
  4217. snprintf(temp_str, IPA3_ACTIVE_CLIENTS_LOG_LINE_LEN,
  4218. inc ? "[%5lu.%06lu] ^ %s, %s: %d" :
  4219. "[%5lu.%06lu] v %s, %s: %d",
  4220. (unsigned long)t, nanosec_rem,
  4221. id->id_string, id->file, id->line);
  4222. ipa3_active_clients_log_insert(temp_str);
  4223. }
  4224. spin_unlock_irqrestore(&ipa3_ctx->ipa3_active_clients_logging.lock,
  4225. flags);
  4226. }
  4227. #else
  4228. static void ipa3_active_clients_log_mod(
  4229. struct ipa_active_client_logging_info *id,
  4230. bool inc, bool int_ctx)
  4231. {
  4232. }
  4233. #endif
  4234. void ipa3_active_clients_log_dec(struct ipa_active_client_logging_info *id,
  4235. bool int_ctx)
  4236. {
  4237. ipa3_active_clients_log_mod(id, false, int_ctx);
  4238. }
  4239. void ipa3_active_clients_log_inc(struct ipa_active_client_logging_info *id,
  4240. bool int_ctx)
  4241. {
  4242. ipa3_active_clients_log_mod(id, true, int_ctx);
  4243. }
  4244. /**
  4245. * ipa3_inc_client_enable_clks() - Increase active clients counter, and
  4246. * enable ipa clocks if necessary
  4247. *
  4248. * Return codes:
  4249. * None
  4250. */
  4251. void ipa3_inc_client_enable_clks(struct ipa_active_client_logging_info *id)
  4252. {
  4253. int ret;
  4254. ipa3_active_clients_log_inc(id, false);
  4255. ret = atomic_inc_not_zero(&ipa3_ctx->ipa3_active_clients.cnt);
  4256. if (ret) {
  4257. IPADBG_LOW("active clients = %d\n",
  4258. atomic_read(&ipa3_ctx->ipa3_active_clients.cnt));
  4259. return;
  4260. }
  4261. mutex_lock(&ipa3_ctx->ipa3_active_clients.mutex);
  4262. /* somebody might voted to clocks meanwhile */
  4263. ret = atomic_inc_not_zero(&ipa3_ctx->ipa3_active_clients.cnt);
  4264. if (ret) {
  4265. mutex_unlock(&ipa3_ctx->ipa3_active_clients.mutex);
  4266. IPADBG_LOW("active clients = %d\n",
  4267. atomic_read(&ipa3_ctx->ipa3_active_clients.cnt));
  4268. return;
  4269. }
  4270. ipa3_enable_clks();
  4271. ipa3_suspend_apps_pipes(false);
  4272. atomic_inc(&ipa3_ctx->ipa3_active_clients.cnt);
  4273. IPADBG_LOW("active clients = %d\n",
  4274. atomic_read(&ipa3_ctx->ipa3_active_clients.cnt));
  4275. mutex_unlock(&ipa3_ctx->ipa3_active_clients.mutex);
  4276. }
  4277. /**
  4278. * ipa3_active_clks_status() - update the current msm bus clock vote
  4279. * status
  4280. */
  4281. int ipa3_active_clks_status(void)
  4282. {
  4283. return atomic_read(&ipa3_ctx->ipa_clk_vote);
  4284. }
  4285. /**
  4286. * ipa3_inc_client_enable_clks_no_block() - Only increment the number of active
  4287. * clients if no asynchronous actions should be done. Asynchronous actions are
  4288. * locking a mutex and waking up IPA HW.
  4289. *
  4290. * Return codes: 0 for success
  4291. * -EPERM if an asynchronous action should have been done
  4292. */
  4293. int ipa3_inc_client_enable_clks_no_block(struct ipa_active_client_logging_info
  4294. *id)
  4295. {
  4296. int ret;
  4297. ret = atomic_inc_not_zero(&ipa3_ctx->ipa3_active_clients.cnt);
  4298. if (ret) {
  4299. ipa3_active_clients_log_inc(id, true);
  4300. IPADBG_LOW("active clients = %d\n",
  4301. atomic_read(&ipa3_ctx->ipa3_active_clients.cnt));
  4302. return 0;
  4303. }
  4304. return -EPERM;
  4305. }
  4306. static void __ipa3_dec_client_disable_clks(void)
  4307. {
  4308. int ret;
  4309. if (!atomic_read(&ipa3_ctx->ipa3_active_clients.cnt)) {
  4310. IPAERR("trying to disable clocks with refcnt is 0\n");
  4311. ipa_assert();
  4312. return;
  4313. }
  4314. ret = atomic_add_unless(&ipa3_ctx->ipa3_active_clients.cnt, -1, 1);
  4315. if (ret)
  4316. goto bail;
  4317. /* seems like this is the only client holding the clocks */
  4318. mutex_lock(&ipa3_ctx->ipa3_active_clients.mutex);
  4319. if (atomic_read(&ipa3_ctx->ipa3_active_clients.cnt) == 1 &&
  4320. ipa3_ctx->tag_process_before_gating) {
  4321. ipa3_ctx->tag_process_before_gating = false;
  4322. /*
  4323. * When TAG process ends, active clients will be
  4324. * decreased
  4325. */
  4326. queue_work(ipa3_ctx->power_mgmt_wq, &ipa3_tag_work);
  4327. goto unlock_mutex;
  4328. }
  4329. /* a different context might increase the clock reference meanwhile */
  4330. ret = atomic_sub_return(1, &ipa3_ctx->ipa3_active_clients.cnt);
  4331. if (ret > 0)
  4332. goto unlock_mutex;
  4333. ipa3_suspend_apps_pipes(true);
  4334. ipa3_disable_clks();
  4335. unlock_mutex:
  4336. mutex_unlock(&ipa3_ctx->ipa3_active_clients.mutex);
  4337. bail:
  4338. IPADBG_LOW("active clients = %d\n",
  4339. atomic_read(&ipa3_ctx->ipa3_active_clients.cnt));
  4340. }
  4341. /**
  4342. * ipa3_dec_client_disable_clks() - Decrease active clients counter
  4343. *
  4344. * In case that there are no active clients this function also starts
  4345. * TAG process. When TAG progress ends ipa clocks will be gated.
  4346. * start_tag_process_again flag is set during this function to signal TAG
  4347. * process to start again as there was another client that may send data to ipa
  4348. *
  4349. * Return codes:
  4350. * None
  4351. */
  4352. void ipa3_dec_client_disable_clks(struct ipa_active_client_logging_info *id)
  4353. {
  4354. ipa3_active_clients_log_dec(id, false);
  4355. __ipa3_dec_client_disable_clks();
  4356. }
  4357. static void ipa_dec_clients_disable_clks_on_wq(struct work_struct *work)
  4358. {
  4359. __ipa3_dec_client_disable_clks();
  4360. }
  4361. /**
  4362. * ipa3_dec_client_disable_clks_no_block() - Decrease active clients counter
  4363. * if possible without blocking. If this is the last client then the desrease
  4364. * will happen from work queue context.
  4365. *
  4366. * Return codes:
  4367. * None
  4368. */
  4369. void ipa3_dec_client_disable_clks_no_block(
  4370. struct ipa_active_client_logging_info *id)
  4371. {
  4372. int ret;
  4373. ipa3_active_clients_log_dec(id, true);
  4374. ret = atomic_add_unless(&ipa3_ctx->ipa3_active_clients.cnt, -1, 1);
  4375. if (ret) {
  4376. IPADBG_LOW("active clients = %d\n",
  4377. atomic_read(&ipa3_ctx->ipa3_active_clients.cnt));
  4378. return;
  4379. }
  4380. /* seems like this is the only client holding the clocks */
  4381. queue_work(ipa3_ctx->power_mgmt_wq,
  4382. &ipa_dec_clients_disable_clks_on_wq_work);
  4383. }
  4384. /**
  4385. * ipa3_inc_acquire_wakelock() - Increase active clients counter, and
  4386. * acquire wakelock if necessary
  4387. *
  4388. * Return codes:
  4389. * None
  4390. */
  4391. void ipa3_inc_acquire_wakelock(void)
  4392. {
  4393. unsigned long flags;
  4394. spin_lock_irqsave(&ipa3_ctx->wakelock_ref_cnt.spinlock, flags);
  4395. ipa3_ctx->wakelock_ref_cnt.cnt++;
  4396. if (ipa3_ctx->wakelock_ref_cnt.cnt == 1)
  4397. __pm_stay_awake(&ipa3_ctx->w_lock);
  4398. IPADBG_LOW("active wakelock ref cnt = %d\n",
  4399. ipa3_ctx->wakelock_ref_cnt.cnt);
  4400. spin_unlock_irqrestore(&ipa3_ctx->wakelock_ref_cnt.spinlock, flags);
  4401. }
  4402. /**
  4403. * ipa3_dec_release_wakelock() - Decrease active clients counter
  4404. *
  4405. * In case if the ref count is 0, release the wakelock.
  4406. *
  4407. * Return codes:
  4408. * None
  4409. */
  4410. void ipa3_dec_release_wakelock(void)
  4411. {
  4412. unsigned long flags;
  4413. spin_lock_irqsave(&ipa3_ctx->wakelock_ref_cnt.spinlock, flags);
  4414. ipa3_ctx->wakelock_ref_cnt.cnt--;
  4415. IPADBG_LOW("active wakelock ref cnt = %d\n",
  4416. ipa3_ctx->wakelock_ref_cnt.cnt);
  4417. if (ipa3_ctx->wakelock_ref_cnt.cnt == 0)
  4418. __pm_relax(&ipa3_ctx->w_lock);
  4419. spin_unlock_irqrestore(&ipa3_ctx->wakelock_ref_cnt.spinlock, flags);
  4420. }
  4421. int ipa3_set_clock_plan_from_pm(int idx)
  4422. {
  4423. u32 clk_rate;
  4424. IPADBG_LOW("idx = %d\n", idx);
  4425. if (!ipa3_ctx->enable_clock_scaling) {
  4426. ipa3_ctx->ipa3_active_clients.bus_vote_idx = idx;
  4427. return 0;
  4428. }
  4429. if (ipa3_ctx->ipa3_hw_mode != IPA_HW_MODE_NORMAL) {
  4430. IPAERR("not supported in this mode\n");
  4431. return 0;
  4432. }
  4433. if (idx <= 0 || idx >= ipa3_ctx->ctrl->msm_bus_data_ptr->num_usecases) {
  4434. IPAERR("bad voltage\n");
  4435. return -EINVAL;
  4436. }
  4437. if (idx == 1)
  4438. clk_rate = ipa3_ctx->ctrl->ipa_clk_rate_svs2;
  4439. else if (idx == 2)
  4440. clk_rate = ipa3_ctx->ctrl->ipa_clk_rate_svs;
  4441. else if (idx == 3)
  4442. clk_rate = ipa3_ctx->ctrl->ipa_clk_rate_nominal;
  4443. else if (idx == 4)
  4444. clk_rate = ipa3_ctx->ctrl->ipa_clk_rate_turbo;
  4445. else {
  4446. IPAERR("bad voltage\n");
  4447. WARN_ON(1);
  4448. return -EFAULT;
  4449. }
  4450. if (clk_rate == ipa3_ctx->curr_ipa_clk_rate) {
  4451. IPADBG_LOW("Same voltage\n");
  4452. return 0;
  4453. }
  4454. mutex_lock(&ipa3_ctx->ipa3_active_clients.mutex);
  4455. ipa3_ctx->curr_ipa_clk_rate = clk_rate;
  4456. ipa3_ctx->ipa3_active_clients.bus_vote_idx = idx;
  4457. IPADBG_LOW("setting clock rate to %u\n", ipa3_ctx->curr_ipa_clk_rate);
  4458. if (atomic_read(&ipa3_ctx->ipa3_active_clients.cnt) > 0) {
  4459. if (ipa3_clk)
  4460. clk_set_rate(ipa3_clk, ipa3_ctx->curr_ipa_clk_rate);
  4461. if (msm_bus_scale_client_update_request(ipa3_ctx->ipa_bus_hdl,
  4462. ipa3_get_bus_vote()))
  4463. WARN_ON(1);
  4464. } else {
  4465. IPADBG_LOW("clocks are gated, not setting rate\n");
  4466. }
  4467. mutex_unlock(&ipa3_ctx->ipa3_active_clients.mutex);
  4468. IPADBG_LOW("Done\n");
  4469. return 0;
  4470. }
  4471. int ipa3_set_required_perf_profile(enum ipa_voltage_level floor_voltage,
  4472. u32 bandwidth_mbps)
  4473. {
  4474. enum ipa_voltage_level needed_voltage;
  4475. u32 clk_rate;
  4476. if (ipa3_ctx->ipa3_hw_mode != IPA_HW_MODE_NORMAL) {
  4477. IPAERR("not supported in this mode\n");
  4478. return 0;
  4479. }
  4480. IPADBG_LOW("floor_voltage=%d, bandwidth_mbps=%u",
  4481. floor_voltage, bandwidth_mbps);
  4482. if (floor_voltage < IPA_VOLTAGE_UNSPECIFIED ||
  4483. floor_voltage >= IPA_VOLTAGE_MAX) {
  4484. IPAERR("bad voltage\n");
  4485. return -EINVAL;
  4486. }
  4487. if (ipa3_ctx->enable_clock_scaling) {
  4488. IPADBG_LOW("Clock scaling is enabled\n");
  4489. if (bandwidth_mbps >=
  4490. ipa3_ctx->ctrl->clock_scaling_bw_threshold_turbo)
  4491. needed_voltage = IPA_VOLTAGE_TURBO;
  4492. else if (bandwidth_mbps >=
  4493. ipa3_ctx->ctrl->clock_scaling_bw_threshold_nominal)
  4494. needed_voltage = IPA_VOLTAGE_NOMINAL;
  4495. else if (bandwidth_mbps >=
  4496. ipa3_ctx->ctrl->clock_scaling_bw_threshold_svs)
  4497. needed_voltage = IPA_VOLTAGE_SVS;
  4498. else
  4499. needed_voltage = IPA_VOLTAGE_SVS2;
  4500. } else {
  4501. IPADBG_LOW("Clock scaling is disabled\n");
  4502. needed_voltage = IPA_VOLTAGE_NOMINAL;
  4503. }
  4504. needed_voltage = max(needed_voltage, floor_voltage);
  4505. switch (needed_voltage) {
  4506. case IPA_VOLTAGE_SVS2:
  4507. clk_rate = ipa3_ctx->ctrl->ipa_clk_rate_svs2;
  4508. break;
  4509. case IPA_VOLTAGE_SVS:
  4510. clk_rate = ipa3_ctx->ctrl->ipa_clk_rate_svs;
  4511. break;
  4512. case IPA_VOLTAGE_NOMINAL:
  4513. clk_rate = ipa3_ctx->ctrl->ipa_clk_rate_nominal;
  4514. break;
  4515. case IPA_VOLTAGE_TURBO:
  4516. clk_rate = ipa3_ctx->ctrl->ipa_clk_rate_turbo;
  4517. break;
  4518. default:
  4519. IPAERR("bad voltage\n");
  4520. WARN_ON(1);
  4521. return -EFAULT;
  4522. }
  4523. if (clk_rate == ipa3_ctx->curr_ipa_clk_rate) {
  4524. IPADBG_LOW("Same voltage\n");
  4525. return 0;
  4526. }
  4527. /* Hold the mutex to avoid race conditions with ipa3_enable_clocks() */
  4528. mutex_lock(&ipa3_ctx->ipa3_active_clients.mutex);
  4529. ipa3_ctx->curr_ipa_clk_rate = clk_rate;
  4530. IPADBG_LOW("setting clock rate to %u\n", ipa3_ctx->curr_ipa_clk_rate);
  4531. if (atomic_read(&ipa3_ctx->ipa3_active_clients.cnt) > 0) {
  4532. if (ipa3_clk)
  4533. clk_set_rate(ipa3_clk, ipa3_ctx->curr_ipa_clk_rate);
  4534. if (msm_bus_scale_client_update_request(ipa3_ctx->ipa_bus_hdl,
  4535. ipa3_get_bus_vote()))
  4536. WARN_ON(1);
  4537. } else {
  4538. IPADBG_LOW("clocks are gated, not setting rate\n");
  4539. }
  4540. mutex_unlock(&ipa3_ctx->ipa3_active_clients.mutex);
  4541. IPADBG_LOW("Done\n");
  4542. return 0;
  4543. }
  4544. static void ipa3_process_irq_schedule_rel(void)
  4545. {
  4546. queue_delayed_work(ipa3_ctx->transport_power_mgmt_wq,
  4547. &ipa3_transport_release_resource_work,
  4548. msecs_to_jiffies(IPA_TRANSPORT_PROD_TIMEOUT_MSEC));
  4549. }
  4550. /**
  4551. * ipa3_suspend_handler() - Handles the suspend interrupt:
  4552. * wakes up the suspended peripheral by requesting its consumer
  4553. * @interrupt: Interrupt type
  4554. * @private_data: The client's private data
  4555. * @interrupt_data: Interrupt specific information data
  4556. */
  4557. void ipa3_suspend_handler(enum ipa_irq_type interrupt,
  4558. void *private_data,
  4559. void *interrupt_data)
  4560. {
  4561. u32 suspend_data =
  4562. ((struct ipa_tx_suspend_irq_data *)interrupt_data)->endpoints;
  4563. u32 bmsk = 1;
  4564. u32 i = 0;
  4565. int res;
  4566. struct ipa_ep_cfg_holb holb_cfg;
  4567. u32 pipe_bitmask = 0;
  4568. IPADBG("interrupt=%d, interrupt_data=%u\n",
  4569. interrupt, suspend_data);
  4570. memset(&holb_cfg, 0, sizeof(holb_cfg));
  4571. for (i = 0; i < ipa3_ctx->ipa_num_pipes; i++, bmsk = bmsk << 1) {
  4572. if ((suspend_data & bmsk) && (ipa3_ctx->ep[i].valid)) {
  4573. pipe_bitmask |= bmsk;
  4574. }
  4575. }
  4576. res = ipa_pm_handle_suspend(pipe_bitmask);
  4577. if (res) {
  4578. IPAERR("ipa_pm_handle_suspend failed %d\n", res);
  4579. return;
  4580. }
  4581. }
  4582. /**
  4583. * ipa3_restore_suspend_handler() - restores the original suspend IRQ handler
  4584. * as it was registered in the IPA init sequence.
  4585. * Return codes:
  4586. * 0: success
  4587. * -EPERM: failed to remove current handler or failed to add original handler
  4588. */
  4589. int ipa3_restore_suspend_handler(void)
  4590. {
  4591. int result = 0;
  4592. result = ipa3_remove_interrupt_handler(IPA_TX_SUSPEND_IRQ);
  4593. if (result) {
  4594. IPAERR("remove handler for suspend interrupt failed\n");
  4595. return -EPERM;
  4596. }
  4597. result = ipa3_add_interrupt_handler(IPA_TX_SUSPEND_IRQ,
  4598. ipa3_suspend_handler, false, NULL);
  4599. if (result) {
  4600. IPAERR("register handler for suspend interrupt failed\n");
  4601. result = -EPERM;
  4602. }
  4603. IPADBG("suspend handler successfully restored\n");
  4604. return result;
  4605. }
  4606. static int ipa3_apps_cons_release_resource(void)
  4607. {
  4608. return 0;
  4609. }
  4610. static int ipa3_apps_cons_request_resource(void)
  4611. {
  4612. return 0;
  4613. }
  4614. static void ipa3_transport_release_resource(struct work_struct *work)
  4615. {
  4616. mutex_lock(&ipa3_ctx->transport_pm.transport_pm_mutex);
  4617. /* check whether still need to decrease client usage */
  4618. if (atomic_read(&ipa3_ctx->transport_pm.dec_clients)) {
  4619. if (atomic_read(&ipa3_ctx->transport_pm.eot_activity)) {
  4620. IPADBG("EOT pending Re-scheduling\n");
  4621. ipa3_process_irq_schedule_rel();
  4622. } else {
  4623. atomic_set(&ipa3_ctx->transport_pm.dec_clients, 0);
  4624. ipa3_dec_release_wakelock();
  4625. IPA_ACTIVE_CLIENTS_DEC_SPECIAL("TRANSPORT_RESOURCE");
  4626. }
  4627. }
  4628. atomic_set(&ipa3_ctx->transport_pm.eot_activity, 0);
  4629. mutex_unlock(&ipa3_ctx->transport_pm.transport_pm_mutex);
  4630. }
  4631. int ipa3_create_apps_resource(void)
  4632. {
  4633. struct ipa_rm_create_params apps_cons_create_params;
  4634. struct ipa_rm_perf_profile profile;
  4635. int result = 0;
  4636. memset(&apps_cons_create_params, 0,
  4637. sizeof(apps_cons_create_params));
  4638. apps_cons_create_params.name = IPA_RM_RESOURCE_APPS_CONS;
  4639. apps_cons_create_params.request_resource =
  4640. ipa3_apps_cons_request_resource;
  4641. apps_cons_create_params.release_resource =
  4642. ipa3_apps_cons_release_resource;
  4643. result = ipa_rm_create_resource(&apps_cons_create_params);
  4644. if (result) {
  4645. IPAERR("ipa_rm_create_resource failed\n");
  4646. return result;
  4647. }
  4648. profile.max_supported_bandwidth_mbps = IPA_APPS_MAX_BW_IN_MBPS;
  4649. ipa_rm_set_perf_profile(IPA_RM_RESOURCE_APPS_CONS, &profile);
  4650. return result;
  4651. }
  4652. /**
  4653. * ipa3_init_interrupts() - Register to IPA IRQs
  4654. *
  4655. * Return codes: 0 in success, negative in failure
  4656. *
  4657. */
  4658. int ipa3_init_interrupts(void)
  4659. {
  4660. int result;
  4661. /*register IPA IRQ handler*/
  4662. result = ipa3_interrupts_init(ipa3_res.ipa_irq, 0,
  4663. &ipa3_ctx->master_pdev->dev);
  4664. if (result) {
  4665. IPAERR("ipa interrupts initialization failed\n");
  4666. return -ENODEV;
  4667. }
  4668. /*add handler for suspend interrupt*/
  4669. result = ipa3_add_interrupt_handler(IPA_TX_SUSPEND_IRQ,
  4670. ipa3_suspend_handler, false, NULL);
  4671. if (result) {
  4672. IPAERR("register handler for suspend interrupt failed\n");
  4673. result = -ENODEV;
  4674. goto fail_add_interrupt_handler;
  4675. }
  4676. return 0;
  4677. fail_add_interrupt_handler:
  4678. ipa3_interrupts_destroy(ipa3_res.ipa_irq, &ipa3_ctx->master_pdev->dev);
  4679. return result;
  4680. }
  4681. /**
  4682. * ipa3_destroy_flt_tbl_idrs() - destroy the idr structure for flt tables
  4683. * The idr strcuture per filtering table is intended for rule id generation
  4684. * per filtering rule.
  4685. */
  4686. static void ipa3_destroy_flt_tbl_idrs(void)
  4687. {
  4688. int i;
  4689. struct ipa3_flt_tbl *flt_tbl;
  4690. idr_destroy(&ipa3_ctx->flt_rule_ids[IPA_IP_v4]);
  4691. idr_destroy(&ipa3_ctx->flt_rule_ids[IPA_IP_v6]);
  4692. for (i = 0; i < ipa3_ctx->ipa_num_pipes; i++) {
  4693. if (!ipa_is_ep_support_flt(i))
  4694. continue;
  4695. flt_tbl = &ipa3_ctx->flt_tbl[i][IPA_IP_v4];
  4696. flt_tbl->rule_ids = NULL;
  4697. flt_tbl = &ipa3_ctx->flt_tbl[i][IPA_IP_v6];
  4698. flt_tbl->rule_ids = NULL;
  4699. }
  4700. }
  4701. static void ipa3_freeze_clock_vote_and_notify_modem(void)
  4702. {
  4703. int res;
  4704. struct ipa_active_client_logging_info log_info;
  4705. if (ipa3_ctx->platform_type == IPA_PLAT_TYPE_APQ) {
  4706. IPADBG("Ignore smp2p on APQ platform\n");
  4707. return;
  4708. }
  4709. if (ipa3_ctx->smp2p_info.res_sent)
  4710. return;
  4711. if (IS_ERR(ipa3_ctx->smp2p_info.smem_state)) {
  4712. IPAERR("fail to get smp2p clk resp bit %ld\n",
  4713. PTR_ERR(ipa3_ctx->smp2p_info.smem_state));
  4714. return;
  4715. }
  4716. IPA_ACTIVE_CLIENTS_PREP_SPECIAL(log_info, "FREEZE_VOTE");
  4717. res = ipa3_inc_client_enable_clks_no_block(&log_info);
  4718. if (res)
  4719. ipa3_ctx->smp2p_info.ipa_clk_on = false;
  4720. else
  4721. ipa3_ctx->smp2p_info.ipa_clk_on = true;
  4722. qcom_smem_state_update_bits(ipa3_ctx->smp2p_info.smem_state,
  4723. IPA_SMP2P_SMEM_STATE_MASK,
  4724. ((ipa3_ctx->smp2p_info.ipa_clk_on <<
  4725. IPA_SMP2P_OUT_CLK_VOTE_IDX) |
  4726. (1 << IPA_SMP2P_OUT_CLK_RSP_CMPLT_IDX)));
  4727. ipa3_ctx->smp2p_info.res_sent = true;
  4728. IPADBG("IPA clocks are %s\n",
  4729. ipa3_ctx->smp2p_info.ipa_clk_on ? "ON" : "OFF");
  4730. }
  4731. void ipa3_reset_freeze_vote(void)
  4732. {
  4733. if (!ipa3_ctx->smp2p_info.res_sent)
  4734. return;
  4735. if (ipa3_ctx->smp2p_info.ipa_clk_on)
  4736. IPA_ACTIVE_CLIENTS_DEC_SPECIAL("FREEZE_VOTE");
  4737. qcom_smem_state_update_bits(ipa3_ctx->smp2p_info.smem_state,
  4738. IPA_SMP2P_SMEM_STATE_MASK,
  4739. ((0 <<
  4740. IPA_SMP2P_OUT_CLK_VOTE_IDX) |
  4741. (0 << IPA_SMP2P_OUT_CLK_RSP_CMPLT_IDX)));
  4742. ipa3_ctx->smp2p_info.res_sent = false;
  4743. ipa3_ctx->smp2p_info.ipa_clk_on = false;
  4744. }
  4745. static int ipa3_panic_notifier(struct notifier_block *this,
  4746. unsigned long event, void *ptr)
  4747. {
  4748. int res;
  4749. ipa3_freeze_clock_vote_and_notify_modem();
  4750. IPADBG("Calling uC panic handler\n");
  4751. res = ipa3_uc_panic_notifier(this, event, ptr);
  4752. if (res)
  4753. IPAERR("uC panic handler failed %d\n", res);
  4754. if (atomic_read(&ipa3_ctx->ipa_clk_vote)) {
  4755. ipahal_print_all_regs(false);
  4756. ipa_save_registers();
  4757. ipa_wigig_save_regs();
  4758. }
  4759. return NOTIFY_DONE;
  4760. }
  4761. static struct notifier_block ipa3_panic_blk = {
  4762. .notifier_call = ipa3_panic_notifier,
  4763. /* IPA panic handler needs to run before modem shuts down */
  4764. .priority = INT_MAX,
  4765. };
  4766. static void ipa3_register_panic_hdlr(void)
  4767. {
  4768. atomic_notifier_chain_register(&panic_notifier_list,
  4769. &ipa3_panic_blk);
  4770. }
  4771. static void ipa3_trigger_ipa_ready_cbs(void)
  4772. {
  4773. struct ipa3_ready_cb_info *info;
  4774. mutex_lock(&ipa3_ctx->lock);
  4775. /* Call all the CBs */
  4776. list_for_each_entry(info, &ipa3_ctx->ipa_ready_cb_list, link)
  4777. if (info->ready_cb)
  4778. info->ready_cb(info->user_data);
  4779. mutex_unlock(&ipa3_ctx->lock);
  4780. }
  4781. static void ipa3_uc_is_loaded(void)
  4782. {
  4783. IPADBG("\n");
  4784. complete_all(&ipa3_ctx->uc_loaded_completion_obj);
  4785. }
  4786. static enum gsi_ver ipa3_get_gsi_ver(enum ipa_hw_type ipa_hw_type)
  4787. {
  4788. enum gsi_ver gsi_ver;
  4789. switch (ipa_hw_type) {
  4790. case IPA_HW_v3_0:
  4791. case IPA_HW_v3_1:
  4792. gsi_ver = GSI_VER_1_0;
  4793. break;
  4794. case IPA_HW_v3_5:
  4795. gsi_ver = GSI_VER_1_2;
  4796. break;
  4797. case IPA_HW_v3_5_1:
  4798. gsi_ver = GSI_VER_1_3;
  4799. break;
  4800. case IPA_HW_v4_0:
  4801. case IPA_HW_v4_1:
  4802. gsi_ver = GSI_VER_2_0;
  4803. break;
  4804. case IPA_HW_v4_2:
  4805. gsi_ver = GSI_VER_2_2;
  4806. break;
  4807. case IPA_HW_v4_5:
  4808. gsi_ver = GSI_VER_2_5;
  4809. break;
  4810. case IPA_HW_v4_7:
  4811. gsi_ver = GSI_VER_2_7;
  4812. break;
  4813. default:
  4814. IPAERR("No GSI version for ipa type %d\n", ipa_hw_type);
  4815. WARN_ON(1);
  4816. gsi_ver = GSI_VER_ERR;
  4817. }
  4818. IPADBG("GSI version %d\n", gsi_ver);
  4819. return gsi_ver;
  4820. }
  4821. static int ipa3_gsi_pre_fw_load_init(void)
  4822. {
  4823. int result;
  4824. result = gsi_configure_regs(
  4825. ipa3_res.ipa_mem_base,
  4826. ipa3_get_gsi_ver(ipa3_res.ipa_hw_type));
  4827. if (result) {
  4828. IPAERR("Failed to configure GSI registers\n");
  4829. return -EINVAL;
  4830. }
  4831. return 0;
  4832. }
  4833. static int ipa3_alloc_gsi_channel(void)
  4834. {
  4835. const struct ipa_gsi_ep_config *gsi_ep_cfg;
  4836. enum ipa_client_type type;
  4837. int code = 0;
  4838. int ret = 0;
  4839. int i;
  4840. for (i = 0; i < ipa3_ctx->ipa_num_pipes; i++) {
  4841. type = ipa3_get_client_by_pipe(i);
  4842. gsi_ep_cfg = ipa3_get_gsi_ep_info(type);
  4843. IPADBG("for ep %d client is %d\n", i, type);
  4844. if (!gsi_ep_cfg)
  4845. continue;
  4846. ret = gsi_alloc_channel_ee(gsi_ep_cfg->ipa_gsi_chan_num,
  4847. gsi_ep_cfg->ee, &code);
  4848. if (ret == GSI_STATUS_SUCCESS) {
  4849. IPADBG("alloc gsi ch %d ee %d with code %d\n",
  4850. gsi_ep_cfg->ipa_gsi_chan_num,
  4851. gsi_ep_cfg->ee,
  4852. code);
  4853. } else {
  4854. IPAERR("failed to alloc ch %d ee %d code %d\n",
  4855. gsi_ep_cfg->ipa_gsi_chan_num,
  4856. gsi_ep_cfg->ee,
  4857. code);
  4858. return ret;
  4859. }
  4860. }
  4861. return ret;
  4862. }
  4863. /**
  4864. * ipa3_post_init() - Initialize the IPA Driver (Part II).
  4865. * This part contains all initialization which requires interaction with
  4866. * IPA HW (via GSI).
  4867. *
  4868. * @resource_p: contain platform specific values from DST file
  4869. * @pdev: The platform device structure representing the IPA driver
  4870. *
  4871. * Function initialization process:
  4872. * - Initialize endpoints bitmaps
  4873. * - Initialize resource groups min and max values
  4874. * - Initialize filtering lists heads and idr
  4875. * - Initialize interrupts
  4876. * - Register GSI
  4877. * - Setup APPS pipes
  4878. * - Initialize tethering bridge
  4879. * - Initialize IPA debugfs
  4880. * - Initialize IPA uC interface
  4881. * - Initialize WDI interface
  4882. * - Initialize USB interface
  4883. * - Register for panic handler
  4884. * - Trigger IPA ready callbacks (to all subscribers)
  4885. * - Trigger IPA completion object (to all who wait on it)
  4886. */
  4887. static int ipa3_post_init(const struct ipa3_plat_drv_res *resource_p,
  4888. struct device *ipa_dev)
  4889. {
  4890. int result;
  4891. struct gsi_per_props gsi_props;
  4892. struct ipa3_uc_hdlrs uc_hdlrs = { 0 };
  4893. struct ipa3_flt_tbl *flt_tbl;
  4894. int i;
  4895. struct idr *idr;
  4896. if (ipa3_ctx == NULL) {
  4897. IPADBG("IPA driver haven't initialized\n");
  4898. return -ENXIO;
  4899. }
  4900. /* Prevent consequent calls from trying to load the FW again. */
  4901. if (ipa3_ctx->ipa_initialization_complete)
  4902. return 0;
  4903. IPADBG("active clients = %d\n",
  4904. atomic_read(&ipa3_ctx->ipa3_active_clients.cnt));
  4905. /* move proxy vote for modem on ipa3_post_init */
  4906. if (ipa3_ctx->ipa_hw_type != IPA_HW_v4_0)
  4907. ipa3_proxy_clk_vote();
  4908. /* The following will retrieve and save the gsi fw version */
  4909. ipa_save_gsi_ver();
  4910. if (ipahal_init(ipa3_ctx->ipa_hw_type, ipa3_ctx->mmio,
  4911. ipa3_ctx->pdev)) {
  4912. IPAERR("fail to init ipahal\n");
  4913. result = -EFAULT;
  4914. goto fail_ipahal;
  4915. }
  4916. result = ipa3_init_hw();
  4917. if (result) {
  4918. IPAERR(":error initializing HW\n");
  4919. result = -ENODEV;
  4920. goto fail_init_hw;
  4921. }
  4922. IPADBG("IPA HW initialization sequence completed");
  4923. ipa3_ctx->ipa_num_pipes = ipa3_get_num_pipes();
  4924. IPADBG("IPA Pipes num %u\n", ipa3_ctx->ipa_num_pipes);
  4925. if (ipa3_ctx->ipa_num_pipes > IPA3_MAX_NUM_PIPES) {
  4926. IPAERR("IPA has more pipes then supported has %d, max %d\n",
  4927. ipa3_ctx->ipa_num_pipes, IPA3_MAX_NUM_PIPES);
  4928. result = -ENODEV;
  4929. goto fail_init_hw;
  4930. }
  4931. ipa3_ctx->ctrl->ipa_sram_read_settings();
  4932. IPADBG("SRAM, size: 0x%x, restricted bytes: 0x%x\n",
  4933. ipa3_ctx->smem_sz, ipa3_ctx->smem_restricted_bytes);
  4934. IPADBG("hdr_lcl=%u ip4_rt_hash=%u ip4_rt_nonhash=%u\n",
  4935. ipa3_ctx->hdr_tbl_lcl, ipa3_ctx->ip4_rt_tbl_hash_lcl,
  4936. ipa3_ctx->ip4_rt_tbl_nhash_lcl);
  4937. IPADBG("ip6_rt_hash=%u ip6_rt_nonhash=%u\n",
  4938. ipa3_ctx->ip6_rt_tbl_hash_lcl, ipa3_ctx->ip6_rt_tbl_nhash_lcl);
  4939. IPADBG("ip4_flt_hash=%u ip4_flt_nonhash=%u\n",
  4940. ipa3_ctx->ip4_flt_tbl_hash_lcl,
  4941. ipa3_ctx->ip4_flt_tbl_nhash_lcl);
  4942. IPADBG("ip6_flt_hash=%u ip6_flt_nonhash=%u\n",
  4943. ipa3_ctx->ip6_flt_tbl_hash_lcl,
  4944. ipa3_ctx->ip6_flt_tbl_nhash_lcl);
  4945. if (ipa3_ctx->smem_reqd_sz > ipa3_ctx->smem_sz) {
  4946. IPAERR("SW expect more core memory, needed %d, avail %d\n",
  4947. ipa3_ctx->smem_reqd_sz, ipa3_ctx->smem_sz);
  4948. result = -ENOMEM;
  4949. goto fail_init_hw;
  4950. }
  4951. result = ipa3_allocate_dma_task_for_gsi();
  4952. if (result) {
  4953. IPAERR("failed to allocate dma task\n");
  4954. goto fail_dma_task;
  4955. }
  4956. if (ipa3_nat_ipv6ct_init_devices()) {
  4957. IPAERR("unable to init NAT and IPv6CT devices\n");
  4958. result = -ENODEV;
  4959. goto fail_nat_ipv6ct_init_dev;
  4960. }
  4961. result = ipa3_alloc_pkt_init();
  4962. if (result) {
  4963. IPAERR("Failed to alloc pkt_init payload\n");
  4964. result = -ENODEV;
  4965. goto fail_allok_pkt_init;
  4966. }
  4967. if (ipa3_ctx->ipa_hw_type >= IPA_HW_v3_5)
  4968. ipa3_enable_dcd();
  4969. /*
  4970. * indication whether working in MHI config or non MHI config is given
  4971. * in ipa3_write which is launched before ipa3_post_init. i.e. from
  4972. * this point it is safe to use ipa3_ep_mapping array and the correct
  4973. * entry will be returned from ipa3_get_hw_type_index()
  4974. */
  4975. ipa_init_ep_flt_bitmap();
  4976. IPADBG("EP with flt support bitmap 0x%x (%u pipes)\n",
  4977. ipa3_ctx->ep_flt_bitmap, ipa3_ctx->ep_flt_num);
  4978. /* Assign resource limitation to each group */
  4979. ipa3_set_resorce_groups_min_max_limits();
  4980. idr = &(ipa3_ctx->flt_rule_ids[IPA_IP_v4]);
  4981. idr_init(idr);
  4982. idr = &(ipa3_ctx->flt_rule_ids[IPA_IP_v6]);
  4983. idr_init(idr);
  4984. for (i = 0; i < ipa3_ctx->ipa_num_pipes; i++) {
  4985. if (!ipa_is_ep_support_flt(i))
  4986. continue;
  4987. flt_tbl = &ipa3_ctx->flt_tbl[i][IPA_IP_v4];
  4988. INIT_LIST_HEAD(&flt_tbl->head_flt_rule_list);
  4989. flt_tbl->in_sys[IPA_RULE_HASHABLE] =
  4990. !ipa3_ctx->ip4_flt_tbl_hash_lcl;
  4991. flt_tbl->in_sys[IPA_RULE_NON_HASHABLE] =
  4992. !ipa3_ctx->ip4_flt_tbl_nhash_lcl;
  4993. flt_tbl->rule_ids = &ipa3_ctx->flt_rule_ids[IPA_IP_v4];
  4994. flt_tbl = &ipa3_ctx->flt_tbl[i][IPA_IP_v6];
  4995. INIT_LIST_HEAD(&flt_tbl->head_flt_rule_list);
  4996. flt_tbl->in_sys[IPA_RULE_HASHABLE] =
  4997. !ipa3_ctx->ip6_flt_tbl_hash_lcl;
  4998. flt_tbl->in_sys[IPA_RULE_NON_HASHABLE] =
  4999. !ipa3_ctx->ip6_flt_tbl_nhash_lcl;
  5000. flt_tbl->rule_ids = &ipa3_ctx->flt_rule_ids[IPA_IP_v6];
  5001. }
  5002. result = ipa3_init_interrupts();
  5003. if (result) {
  5004. IPAERR("ipa initialization of interrupts failed\n");
  5005. result = -ENODEV;
  5006. goto fail_init_interrupts;
  5007. }
  5008. /*
  5009. * Disable prefetch for USB or MHI at IPAv3.5/IPA.3.5.1
  5010. * This is to allow MBIM to work.
  5011. */
  5012. if ((ipa3_ctx->ipa_hw_type >= IPA_HW_v3_5
  5013. && ipa3_ctx->ipa_hw_type < IPA_HW_v4_0) &&
  5014. (!ipa3_ctx->ipa_config_is_mhi))
  5015. ipa3_disable_prefetch(IPA_CLIENT_USB_CONS);
  5016. if ((ipa3_ctx->ipa_hw_type >= IPA_HW_v3_5
  5017. && ipa3_ctx->ipa_hw_type < IPA_HW_v4_0) &&
  5018. (ipa3_ctx->ipa_config_is_mhi))
  5019. ipa3_disable_prefetch(IPA_CLIENT_MHI_CONS);
  5020. memset(&gsi_props, 0, sizeof(gsi_props));
  5021. gsi_props.ver = ipa3_get_gsi_ver(resource_p->ipa_hw_type);
  5022. gsi_props.ee = resource_p->ee;
  5023. gsi_props.intr = GSI_INTR_IRQ;
  5024. gsi_props.phys_addr = resource_p->transport_mem_base;
  5025. gsi_props.size = resource_p->transport_mem_size;
  5026. if (ipa3_ctx->ipa3_hw_mode == IPA_HW_MODE_EMULATION) {
  5027. gsi_props.irq = resource_p->emulator_irq;
  5028. gsi_props.emulator_intcntrlr_client_isr = ipa3_get_isr();
  5029. gsi_props.emulator_intcntrlr_addr =
  5030. resource_p->emulator_intcntrlr_mem_base;
  5031. gsi_props.emulator_intcntrlr_size =
  5032. resource_p->emulator_intcntrlr_mem_size;
  5033. } else {
  5034. gsi_props.irq = resource_p->transport_irq;
  5035. }
  5036. gsi_props.notify_cb = ipa_gsi_notify_cb;
  5037. gsi_props.req_clk_cb = NULL;
  5038. gsi_props.rel_clk_cb = NULL;
  5039. gsi_props.clk_status_cb = ipa3_active_clks_status;
  5040. if (ipa3_ctx->ipa_config_is_mhi) {
  5041. gsi_props.mhi_er_id_limits_valid = true;
  5042. gsi_props.mhi_er_id_limits[0] = resource_p->mhi_evid_limits[0];
  5043. gsi_props.mhi_er_id_limits[1] = resource_p->mhi_evid_limits[1];
  5044. }
  5045. result = gsi_register_device(&gsi_props,
  5046. &ipa3_ctx->gsi_dev_hdl);
  5047. if (result != GSI_STATUS_SUCCESS) {
  5048. IPAERR(":gsi register error - %d\n", result);
  5049. result = -ENODEV;
  5050. goto fail_register_device;
  5051. }
  5052. IPADBG("IPA gsi is registered\n");
  5053. /* GSI 2.2 requires to allocate all EE GSI channel
  5054. * during device bootup.
  5055. */
  5056. if (ipa3_get_gsi_ver(resource_p->ipa_hw_type) == GSI_VER_2_2) {
  5057. result = ipa3_alloc_gsi_channel();
  5058. if (result) {
  5059. IPAERR("Failed to alloc the GSI channels\n");
  5060. result = -ENODEV;
  5061. goto fail_alloc_gsi_channel;
  5062. }
  5063. }
  5064. /* setup the AP-IPA pipes */
  5065. if (ipa3_setup_apps_pipes()) {
  5066. IPAERR(":failed to setup IPA-Apps pipes\n");
  5067. result = -ENODEV;
  5068. goto fail_setup_apps_pipes;
  5069. }
  5070. IPADBG("IPA GPI pipes were connected\n");
  5071. if (ipa3_ctx->use_ipa_teth_bridge) {
  5072. /* Initialize the tethering bridge driver */
  5073. result = ipa3_teth_bridge_driver_init();
  5074. if (result) {
  5075. IPAERR(":teth_bridge init failed (%d)\n", -result);
  5076. result = -ENODEV;
  5077. goto fail_teth_bridge_driver_init;
  5078. }
  5079. IPADBG("teth_bridge initialized");
  5080. }
  5081. result = ipa3_uc_interface_init();
  5082. if (result)
  5083. IPAERR(":ipa Uc interface init failed (%d)\n", -result);
  5084. else
  5085. IPADBG(":ipa Uc interface init ok\n");
  5086. uc_hdlrs.ipa_uc_loaded_hdlr = ipa3_uc_is_loaded;
  5087. ipa3_uc_register_handlers(IPA_HW_FEATURE_COMMON, &uc_hdlrs);
  5088. result = ipa3_wdi_init();
  5089. if (result)
  5090. IPAERR(":wdi init failed (%d)\n", -result);
  5091. else
  5092. IPADBG(":wdi init ok\n");
  5093. result = ipa3_wigig_init_i();
  5094. if (result)
  5095. IPAERR(":wigig init failed (%d)\n", -result);
  5096. else
  5097. IPADBG(":wigig init ok\n");
  5098. result = ipa3_ntn_init();
  5099. if (result)
  5100. IPAERR(":ntn init failed (%d)\n", -result);
  5101. else
  5102. IPADBG(":ntn init ok\n");
  5103. result = ipa_hw_stats_init();
  5104. if (result)
  5105. IPAERR("fail to init stats %d\n", result);
  5106. else
  5107. IPADBG(":stats init ok\n");
  5108. ipa3_register_panic_hdlr();
  5109. ipa3_debugfs_init();
  5110. mutex_lock(&ipa3_ctx->lock);
  5111. ipa3_ctx->ipa_initialization_complete = true;
  5112. mutex_unlock(&ipa3_ctx->lock);
  5113. ipa3_trigger_ipa_ready_cbs();
  5114. complete_all(&ipa3_ctx->init_completion_obj);
  5115. pr_info("IPA driver initialization was successful.\n");
  5116. return 0;
  5117. fail_teth_bridge_driver_init:
  5118. ipa3_teardown_apps_pipes();
  5119. fail_alloc_gsi_channel:
  5120. fail_setup_apps_pipes:
  5121. gsi_deregister_device(ipa3_ctx->gsi_dev_hdl, false);
  5122. fail_register_device:
  5123. ipa3_destroy_flt_tbl_idrs();
  5124. fail_init_interrupts:
  5125. ipa3_remove_interrupt_handler(IPA_TX_SUSPEND_IRQ);
  5126. ipa3_interrupts_destroy(ipa3_res.ipa_irq, &ipa3_ctx->master_pdev->dev);
  5127. fail_allok_pkt_init:
  5128. ipa3_nat_ipv6ct_destroy_devices();
  5129. fail_nat_ipv6ct_init_dev:
  5130. ipa3_free_dma_task_for_gsi();
  5131. fail_dma_task:
  5132. fail_init_hw:
  5133. ipahal_destroy();
  5134. fail_ipahal:
  5135. ipa3_proxy_clk_unvote();
  5136. return result;
  5137. }
  5138. static int ipa3_manual_load_ipa_fws(void)
  5139. {
  5140. int result;
  5141. const struct firmware *fw;
  5142. const char *path = IPA_FWS_PATH;
  5143. if (ipa3_ctx->ipa3_hw_mode == IPA_HW_MODE_EMULATION) {
  5144. switch (ipa3_get_emulation_type()) {
  5145. case IPA_HW_v3_5_1:
  5146. path = IPA_FWS_PATH_3_5_1;
  5147. break;
  5148. case IPA_HW_v4_0:
  5149. path = IPA_FWS_PATH_4_0;
  5150. break;
  5151. case IPA_HW_v4_5:
  5152. path = IPA_FWS_PATH_4_5;
  5153. break;
  5154. default:
  5155. break;
  5156. }
  5157. }
  5158. IPADBG("Manual FW loading (%s) process initiated\n", path);
  5159. result = request_firmware(&fw, path, ipa3_ctx->cdev.dev);
  5160. if (result < 0) {
  5161. IPAERR("request_firmware failed, error %d\n", result);
  5162. return result;
  5163. }
  5164. IPADBG("FWs are available for loading\n");
  5165. if (ipa3_ctx->ipa3_hw_mode == IPA_HW_MODE_EMULATION) {
  5166. result = emulator_load_fws(fw,
  5167. ipa3_res.transport_mem_base,
  5168. ipa3_res.transport_mem_size,
  5169. ipa3_get_gsi_ver(ipa3_res.ipa_hw_type));
  5170. } else {
  5171. result = ipa3_load_fws(fw, ipa3_res.transport_mem_base,
  5172. ipa3_get_gsi_ver(ipa3_res.ipa_hw_type));
  5173. }
  5174. if (result) {
  5175. IPAERR("Manual IPA FWs loading has failed\n");
  5176. release_firmware(fw);
  5177. return result;
  5178. }
  5179. result = gsi_enable_fw(ipa3_res.transport_mem_base,
  5180. ipa3_res.transport_mem_size,
  5181. ipa3_get_gsi_ver(ipa3_res.ipa_hw_type));
  5182. if (result) {
  5183. IPAERR("Failed to enable GSI FW\n");
  5184. release_firmware(fw);
  5185. return result;
  5186. }
  5187. release_firmware(fw);
  5188. IPADBG("Manual FW loading process is complete\n");
  5189. return 0;
  5190. }
  5191. static int ipa3_pil_load_ipa_fws(const char *sub_sys)
  5192. {
  5193. void *subsystem_get_retval = NULL;
  5194. IPADBG("PIL FW loading process initiated sub_sys=%s\n",
  5195. sub_sys);
  5196. subsystem_get_retval = subsystem_get(sub_sys);
  5197. if (IS_ERR_OR_NULL(subsystem_get_retval)) {
  5198. IPAERR("Unable to PIL load FW for sub_sys=%s\n", sub_sys);
  5199. return -EINVAL;
  5200. }
  5201. IPADBG("PIL FW loading process is complete sub_sys=%s\n", sub_sys);
  5202. return 0;
  5203. }
  5204. static void ipa3_load_ipa_fw(struct work_struct *work)
  5205. {
  5206. int result;
  5207. IPADBG("Entry\n");
  5208. IPA_ACTIVE_CLIENTS_INC_SIMPLE();
  5209. result = ipa3_attach_to_smmu();
  5210. if (result) {
  5211. IPAERR("IPA attach to smmu failed %d\n", result);
  5212. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  5213. return;
  5214. }
  5215. if (ipa3_ctx->ipa3_hw_mode != IPA_HW_MODE_EMULATION &&
  5216. ((ipa3_ctx->platform_type != IPA_PLAT_TYPE_MDM) ||
  5217. (ipa3_ctx->ipa_hw_type >= IPA_HW_v3_5)))
  5218. result = ipa3_pil_load_ipa_fws(IPA_SUBSYSTEM_NAME);
  5219. else
  5220. result = ipa3_manual_load_ipa_fws();
  5221. IPA_ACTIVE_CLIENTS_DEC_SIMPLE();
  5222. if (result) {
  5223. IPAERR("IPA FW loading process has failed result=%d\n",
  5224. result);
  5225. return;
  5226. }
  5227. pr_info("IPA FW loaded successfully\n");
  5228. result = ipa3_post_init(&ipa3_res, ipa3_ctx->cdev.dev);
  5229. if (result) {
  5230. IPAERR("IPA post init failed %d\n", result);
  5231. return;
  5232. }
  5233. if (ipa3_ctx->platform_type == IPA_PLAT_TYPE_APQ &&
  5234. ipa3_ctx->ipa3_hw_mode != IPA_HW_MODE_VIRTUAL &&
  5235. ipa3_ctx->ipa3_hw_mode != IPA_HW_MODE_EMULATION) {
  5236. IPADBG("Loading IPA uC via PIL\n");
  5237. /* Unvoting will happen when uC loaded event received. */
  5238. ipa3_proxy_clk_vote();
  5239. result = ipa3_pil_load_ipa_fws(IPA_UC_SUBSYSTEM_NAME);
  5240. if (result) {
  5241. IPAERR("IPA uC loading process has failed result=%d\n",
  5242. result);
  5243. return;
  5244. }
  5245. IPADBG("IPA uC PIL loading succeeded\n");
  5246. }
  5247. }
  5248. static ssize_t ipa3_write(struct file *file, const char __user *buf,
  5249. size_t count, loff_t *ppos)
  5250. {
  5251. unsigned long missing;
  5252. char dbg_buff[32] = { 0 };
  5253. if (count >= sizeof(dbg_buff))
  5254. return -EFAULT;
  5255. missing = copy_from_user(dbg_buff, buf, count);
  5256. if (missing) {
  5257. IPAERR("Unable to copy data from user\n");
  5258. return -EFAULT;
  5259. }
  5260. if (count > 0)
  5261. dbg_buff[count] = '\0';
  5262. IPADBG("user input string %s\n", dbg_buff);
  5263. /* Prevent consequent calls from trying to load the FW again. */
  5264. if (ipa3_is_ready())
  5265. return count;
  5266. /* Check MHI configuration on MDM devices */
  5267. if (ipa3_ctx->platform_type == IPA_PLAT_TYPE_MDM) {
  5268. if (strnstr(dbg_buff, "vlan", strlen(dbg_buff))) {
  5269. if (strnstr(dbg_buff, "eth", strlen(dbg_buff)))
  5270. ipa3_ctx->vlan_mode_iface[IPA_VLAN_IF_EMAC] =
  5271. true;
  5272. if (strnstr(dbg_buff, "rndis", strlen(dbg_buff)))
  5273. ipa3_ctx->vlan_mode_iface[IPA_VLAN_IF_RNDIS] =
  5274. true;
  5275. if (strnstr(dbg_buff, "ecm", strlen(dbg_buff)))
  5276. ipa3_ctx->vlan_mode_iface[IPA_VLAN_IF_ECM] =
  5277. true;
  5278. /*
  5279. * when vlan mode is passed to our dev we expect
  5280. * another write
  5281. */
  5282. return count;
  5283. }
  5284. /* trim ending newline character if any */
  5285. if (count && (dbg_buff[count - 1] == '\n'))
  5286. dbg_buff[count - 1] = '\0';
  5287. /*
  5288. * This logic enforeces MHI mode based on userspace input.
  5289. * Note that MHI mode could be already determined due
  5290. * to previous logic.
  5291. */
  5292. if (!strcasecmp(dbg_buff, "MHI")) {
  5293. ipa3_ctx->ipa_config_is_mhi = true;
  5294. } else if (strcmp(dbg_buff, "1")) {
  5295. IPAERR("got invalid string %s not loading FW\n",
  5296. dbg_buff);
  5297. return count;
  5298. }
  5299. pr_info("IPA is loading with %sMHI configuration\n",
  5300. ipa3_ctx->ipa_config_is_mhi ? "" : "non ");
  5301. }
  5302. /* Prevent multiple calls from trying to load the FW again. */
  5303. if (ipa3_ctx->fw_loaded) {
  5304. IPAERR("not load FW again\n");
  5305. return count;
  5306. }
  5307. /* Schedule WQ to load ipa-fws */
  5308. ipa3_ctx->fw_loaded = true;
  5309. queue_work(ipa3_ctx->transport_power_mgmt_wq,
  5310. &ipa3_fw_loading_work);
  5311. IPADBG("Scheduled a work to load IPA FW\n");
  5312. return count;
  5313. }
  5314. /**
  5315. * ipa3_tz_unlock_reg - Unlocks memory regions so that they become accessible
  5316. * from AP.
  5317. * @reg_info - Pointer to array of memory regions to unlock
  5318. * @num_regs - Number of elements in the array
  5319. *
  5320. * Converts the input array of regions to a struct that TZ understands and
  5321. * issues an SCM call.
  5322. * Also flushes the memory cache to DDR in order to make sure that TZ sees the
  5323. * correct data structure.
  5324. *
  5325. * Returns: 0 on success, negative on failure
  5326. */
  5327. int ipa3_tz_unlock_reg(struct ipa_tz_unlock_reg_info *reg_info, u16 num_regs)
  5328. {
  5329. int i, size, ret;
  5330. struct tz_smmu_ipa_protect_region_iovec_s *ipa_tz_unlock_vec;
  5331. struct tz_smmu_ipa_protect_region_s cmd_buf;
  5332. struct scm_desc desc = {0};
  5333. if (reg_info == NULL || num_regs == 0) {
  5334. IPAERR("Bad parameters\n");
  5335. return -EFAULT;
  5336. }
  5337. size = num_regs * sizeof(struct tz_smmu_ipa_protect_region_iovec_s);
  5338. ipa_tz_unlock_vec = kzalloc(PAGE_ALIGN(size), GFP_KERNEL);
  5339. if (ipa_tz_unlock_vec == NULL)
  5340. return -ENOMEM;
  5341. for (i = 0; i < num_regs; i++) {
  5342. ipa_tz_unlock_vec[i].input_addr = reg_info[i].reg_addr ^
  5343. (reg_info[i].reg_addr & 0xFFF);
  5344. ipa_tz_unlock_vec[i].output_addr = reg_info[i].reg_addr ^
  5345. (reg_info[i].reg_addr & 0xFFF);
  5346. ipa_tz_unlock_vec[i].size = reg_info[i].size;
  5347. ipa_tz_unlock_vec[i].attr = IPA_TZ_UNLOCK_ATTRIBUTE;
  5348. }
  5349. /* pass physical address of command buffer */
  5350. cmd_buf.iovec_buf = virt_to_phys((void *)ipa_tz_unlock_vec);
  5351. cmd_buf.size_bytes = size;
  5352. desc.args[0] = virt_to_phys((void *)ipa_tz_unlock_vec);
  5353. desc.args[1] = size;
  5354. desc.arginfo = SCM_ARGS(2);
  5355. ret = scm_call2(SCM_SIP_FNID(SCM_SVC_MP,
  5356. TZ_MEM_PROTECT_REGION_ID), &desc);
  5357. if (ret) {
  5358. IPAERR("scm call SCM_SVC_MP failed: %d\n", ret);
  5359. kfree(ipa_tz_unlock_vec);
  5360. return -EFAULT;
  5361. }
  5362. kfree(ipa_tz_unlock_vec);
  5363. return 0;
  5364. }
  5365. static int ipa3_alloc_pkt_init(void)
  5366. {
  5367. struct ipa_mem_buffer mem;
  5368. struct ipahal_imm_cmd_pyld *cmd_pyld;
  5369. struct ipahal_imm_cmd_ip_packet_init cmd = {0};
  5370. int i;
  5371. cmd_pyld = ipahal_construct_imm_cmd(IPA_IMM_CMD_IP_PACKET_INIT,
  5372. &cmd, false);
  5373. if (!cmd_pyld) {
  5374. IPAERR("failed to construct IMM cmd\n");
  5375. return -ENOMEM;
  5376. }
  5377. ipa3_ctx->pkt_init_imm_opcode = cmd_pyld->opcode;
  5378. mem.size = cmd_pyld->len * ipa3_ctx->ipa_num_pipes;
  5379. mem.base = dma_alloc_coherent(ipa3_ctx->pdev, mem.size,
  5380. &mem.phys_base, GFP_KERNEL);
  5381. if (!mem.base) {
  5382. IPAERR("failed to alloc DMA buff of size %d\n", mem.size);
  5383. ipahal_destroy_imm_cmd(cmd_pyld);
  5384. return -ENOMEM;
  5385. }
  5386. ipahal_destroy_imm_cmd(cmd_pyld);
  5387. memset(mem.base, 0, mem.size);
  5388. for (i = 0; i < ipa3_ctx->ipa_num_pipes; i++) {
  5389. cmd.destination_pipe_index = i;
  5390. cmd_pyld = ipahal_construct_imm_cmd(IPA_IMM_CMD_IP_PACKET_INIT,
  5391. &cmd, false);
  5392. if (!cmd_pyld) {
  5393. IPAERR("failed to construct IMM cmd\n");
  5394. dma_free_coherent(ipa3_ctx->pdev,
  5395. mem.size,
  5396. mem.base,
  5397. mem.phys_base);
  5398. return -ENOMEM;
  5399. }
  5400. memcpy(mem.base + i * cmd_pyld->len, cmd_pyld->data,
  5401. cmd_pyld->len);
  5402. ipa3_ctx->pkt_init_imm[i] = mem.phys_base + i * cmd_pyld->len;
  5403. ipahal_destroy_imm_cmd(cmd_pyld);
  5404. }
  5405. return 0;
  5406. }
  5407. /*
  5408. * SCM call to check if secure dump is allowed.
  5409. *
  5410. * Returns true in secure dump allowed.
  5411. * Return false when secure dump not allowed.
  5412. */
  5413. #define TZ_UTIL_GET_SEC_DUMP_STATE 0x10
  5414. static bool ipa_is_mem_dump_allowed(void)
  5415. {
  5416. struct scm_desc desc = {0};
  5417. int ret = 0;
  5418. desc.args[0] = 0;
  5419. desc.arginfo = 0;
  5420. ret = scm_call2(
  5421. SCM_SIP_FNID(SCM_SVC_UTIL, TZ_UTIL_GET_SEC_DUMP_STATE),
  5422. &desc);
  5423. if (ret) {
  5424. IPAERR("SCM DUMP_STATE call failed\n");
  5425. return false;
  5426. }
  5427. return (desc.ret[0] == 1);
  5428. }
  5429. /**
  5430. * ipa3_pre_init() - Initialize the IPA Driver.
  5431. * This part contains all initialization which doesn't require IPA HW, such
  5432. * as structure allocations and initializations, register writes, etc.
  5433. *
  5434. * @resource_p: contain platform specific values from DST file
  5435. * @pdev: The platform device structure representing the IPA driver
  5436. *
  5437. * Function initialization process:
  5438. * Allocate memory for the driver context data struct
  5439. * Initializing the ipa3_ctx with :
  5440. * 1)parsed values from the dts file
  5441. * 2)parameters passed to the module initialization
  5442. * 3)read HW values(such as core memory size)
  5443. * Map IPA core registers to CPU memory
  5444. * Restart IPA core(HW reset)
  5445. * Initialize the look-aside caches(kmem_cache/slab) for filter,
  5446. * routing and IPA-tree
  5447. * Create memory pool with 4 objects for DMA operations(each object
  5448. * is 512Bytes long), this object will be use for tx(A5->IPA)
  5449. * Initialize lists head(routing, hdr, system pipes)
  5450. * Initialize mutexes (for ipa_ctx and NAT memory mutexes)
  5451. * Initialize spinlocks (for list related to A5<->IPA pipes)
  5452. * Initialize 2 single-threaded work-queue named "ipa rx wq" and "ipa tx wq"
  5453. * Initialize Red-Black-Tree(s) for handles of header,routing rule,
  5454. * routing table ,filtering rule
  5455. * Initialize the filter block by committing IPV4 and IPV6 default rules
  5456. * Create empty routing table in system memory(no committing)
  5457. * Create a char-device for IPA
  5458. * Initialize IPA PM (power manager)
  5459. * Configure GSI registers (in GSI case)
  5460. */
  5461. static int ipa3_pre_init(const struct ipa3_plat_drv_res *resource_p,
  5462. struct platform_device *ipa_pdev)
  5463. {
  5464. int result = 0;
  5465. int i, j;
  5466. struct ipa3_rt_tbl_set *rset;
  5467. struct ipa_active_client_logging_info log_info;
  5468. struct cdev *cdev;
  5469. IPADBG("IPA Driver initialization started\n");
  5470. ipa3_ctx = kzalloc(sizeof(*ipa3_ctx), GFP_KERNEL);
  5471. if (!ipa3_ctx) {
  5472. result = -ENOMEM;
  5473. goto fail_mem_ctx;
  5474. }
  5475. ipa3_ctx->logbuf = ipc_log_context_create(IPA_IPC_LOG_PAGES, "ipa", 0);
  5476. if (ipa3_ctx->logbuf == NULL)
  5477. IPADBG("failed to create IPC log, continue...\n");
  5478. /* ipa3_ctx->pdev and ipa3_ctx->uc_pdev will be set in the smmu probes*/
  5479. ipa3_ctx->master_pdev = ipa_pdev;
  5480. for (i = 0; i < IPA_SMMU_CB_MAX; i++)
  5481. ipa3_ctx->s1_bypass_arr[i] = true;
  5482. /* initialize the gsi protocol info for uC debug stats */
  5483. for (i = 0; i < IPA_HW_PROTOCOL_MAX; i++) {
  5484. ipa3_ctx->gsi_info[i].protocol = i;
  5485. /* initialize all to be not started */
  5486. for (j = 0; j < MAX_CH_STATS_SUPPORTED; j++)
  5487. ipa3_ctx->gsi_info[i].ch_id_info[j].ch_id =
  5488. 0xFF;
  5489. }
  5490. ipa3_ctx->ipa_wrapper_base = resource_p->ipa_mem_base;
  5491. ipa3_ctx->ipa_wrapper_size = resource_p->ipa_mem_size;
  5492. ipa3_ctx->ipa_hw_type = resource_p->ipa_hw_type;
  5493. ipa3_ctx->ipa3_hw_mode = resource_p->ipa3_hw_mode;
  5494. ipa3_ctx->platform_type = resource_p->platform_type;
  5495. ipa3_ctx->use_ipa_teth_bridge = resource_p->use_ipa_teth_bridge;
  5496. ipa3_ctx->modem_cfg_emb_pipe_flt = resource_p->modem_cfg_emb_pipe_flt;
  5497. ipa3_ctx->ipa_wdi2 = resource_p->ipa_wdi2;
  5498. ipa3_ctx->ipa_wdi2_over_gsi = resource_p->ipa_wdi2_over_gsi;
  5499. ipa3_ctx->ipa_wdi3_over_gsi = resource_p->ipa_wdi3_over_gsi;
  5500. ipa3_ctx->ipa_fltrt_not_hashable = resource_p->ipa_fltrt_not_hashable;
  5501. ipa3_ctx->use_64_bit_dma_mask = resource_p->use_64_bit_dma_mask;
  5502. ipa3_ctx->wan_rx_ring_size = resource_p->wan_rx_ring_size;
  5503. ipa3_ctx->lan_rx_ring_size = resource_p->lan_rx_ring_size;
  5504. ipa3_ctx->skip_uc_pipe_reset = resource_p->skip_uc_pipe_reset;
  5505. ipa3_ctx->tethered_flow_control = resource_p->tethered_flow_control;
  5506. ipa3_ctx->ee = resource_p->ee;
  5507. ipa3_ctx->gsi_ch20_wa = resource_p->gsi_ch20_wa;
  5508. ipa3_ctx->wdi_over_pcie = resource_p->wdi_over_pcie;
  5509. ipa3_ctx->ipa3_active_clients_logging.log_rdy = false;
  5510. ipa3_ctx->ipa_config_is_mhi = resource_p->ipa_mhi_dynamic_config;
  5511. ipa3_ctx->mhi_evid_limits[0] = resource_p->mhi_evid_limits[0];
  5512. ipa3_ctx->mhi_evid_limits[1] = resource_p->mhi_evid_limits[1];
  5513. ipa3_ctx->entire_ipa_block_size = resource_p->entire_ipa_block_size;
  5514. ipa3_ctx->do_register_collection_on_crash =
  5515. resource_p->do_register_collection_on_crash;
  5516. ipa3_ctx->do_testbus_collection_on_crash =
  5517. resource_p->do_testbus_collection_on_crash;
  5518. ipa3_ctx->do_non_tn_collection_on_crash =
  5519. resource_p->do_non_tn_collection_on_crash;
  5520. ipa3_ctx->secure_debug_check_action =
  5521. resource_p->secure_debug_check_action;
  5522. ipa3_ctx->do_ram_collection_on_crash =
  5523. resource_p->do_ram_collection_on_crash;
  5524. if (ipa3_ctx->secure_debug_check_action == USE_SCM) {
  5525. if (ipa_is_mem_dump_allowed())
  5526. ipa3_ctx->sd_state = SD_ENABLED;
  5527. else
  5528. ipa3_ctx->sd_state = SD_DISABLED;
  5529. } else {
  5530. if (ipa3_ctx->secure_debug_check_action == OVERRIDE_SCM_TRUE)
  5531. ipa3_ctx->sd_state = SD_ENABLED;
  5532. else
  5533. /* secure_debug_check_action == OVERRIDE_SCM_FALSE */
  5534. ipa3_ctx->sd_state = SD_DISABLED;
  5535. }
  5536. if (ipa3_ctx->sd_state == SD_ENABLED) {
  5537. /* secure debug is enabled. */
  5538. IPADBG("secure debug enabled\n");
  5539. } else {
  5540. /* secure debug is disabled. */
  5541. IPADBG("secure debug disabled\n");
  5542. ipa3_ctx->do_testbus_collection_on_crash = false;
  5543. }
  5544. ipa3_ctx->ipa_endp_delay_wa = resource_p->ipa_endp_delay_wa;
  5545. WARN(ipa3_ctx->ipa3_hw_mode != IPA_HW_MODE_NORMAL,
  5546. "Non NORMAL IPA HW mode, is this emulation platform ?");
  5547. if (resource_p->ipa_tz_unlock_reg) {
  5548. ipa3_ctx->ipa_tz_unlock_reg_num =
  5549. resource_p->ipa_tz_unlock_reg_num;
  5550. ipa3_ctx->ipa_tz_unlock_reg = kcalloc(
  5551. ipa3_ctx->ipa_tz_unlock_reg_num,
  5552. sizeof(*ipa3_ctx->ipa_tz_unlock_reg),
  5553. GFP_KERNEL);
  5554. if (ipa3_ctx->ipa_tz_unlock_reg == NULL) {
  5555. result = -ENOMEM;
  5556. goto fail_tz_unlock_reg;
  5557. }
  5558. for (i = 0; i < ipa3_ctx->ipa_tz_unlock_reg_num; i++) {
  5559. ipa3_ctx->ipa_tz_unlock_reg[i].reg_addr =
  5560. resource_p->ipa_tz_unlock_reg[i].reg_addr;
  5561. ipa3_ctx->ipa_tz_unlock_reg[i].size =
  5562. resource_p->ipa_tz_unlock_reg[i].size;
  5563. }
  5564. /* unlock registers for uc */
  5565. result = ipa3_tz_unlock_reg(ipa3_ctx->ipa_tz_unlock_reg,
  5566. ipa3_ctx->ipa_tz_unlock_reg_num);
  5567. if (result)
  5568. IPAERR("Failed to unlock memory region using TZ\n");
  5569. }
  5570. /* default aggregation parameters */
  5571. ipa3_ctx->aggregation_type = IPA_MBIM_16;
  5572. ipa3_ctx->aggregation_byte_limit = 1;
  5573. ipa3_ctx->aggregation_time_limit = 0;
  5574. ipa3_ctx->ctrl = kzalloc(sizeof(*ipa3_ctx->ctrl), GFP_KERNEL);
  5575. if (!ipa3_ctx->ctrl) {
  5576. result = -ENOMEM;
  5577. goto fail_mem_ctrl;
  5578. }
  5579. result = ipa3_controller_static_bind(ipa3_ctx->ctrl,
  5580. ipa3_ctx->ipa_hw_type);
  5581. if (result) {
  5582. IPAERR("fail to static bind IPA ctrl\n");
  5583. result = -EFAULT;
  5584. goto fail_bind;
  5585. }
  5586. result = ipa3_init_mem_partition(ipa3_ctx->ipa_hw_type);
  5587. if (result) {
  5588. IPAERR(":ipa3_init_mem_partition failed\n");
  5589. result = -ENODEV;
  5590. goto fail_init_mem_partition;
  5591. }
  5592. if (ipa3_ctx->ipa3_hw_mode != IPA_HW_MODE_VIRTUAL &&
  5593. ipa3_ctx->ipa3_hw_mode != IPA_HW_MODE_EMULATION) {
  5594. ipa3_ctx->ctrl->msm_bus_data_ptr =
  5595. msm_bus_cl_get_pdata(ipa3_ctx->master_pdev);
  5596. if (ipa3_ctx->ctrl->msm_bus_data_ptr == NULL) {
  5597. IPAERR("failed to get bus scaling\n");
  5598. goto fail_bus_reg;
  5599. }
  5600. IPADBG("Use bus scaling info from device tree #usecases=%d\n",
  5601. ipa3_ctx->ctrl->msm_bus_data_ptr->num_usecases);
  5602. /* get BUS handle */
  5603. ipa3_ctx->ipa_bus_hdl =
  5604. msm_bus_scale_register_client(
  5605. ipa3_ctx->ctrl->msm_bus_data_ptr);
  5606. if (!ipa3_ctx->ipa_bus_hdl) {
  5607. IPAERR("fail to register with bus mgr!\n");
  5608. ipa3_ctx->ctrl->msm_bus_data_ptr = NULL;
  5609. result = -EPROBE_DEFER;
  5610. goto fail_bus_reg;
  5611. }
  5612. }
  5613. /* get IPA clocks */
  5614. result = ipa3_get_clks(&ipa3_ctx->master_pdev->dev);
  5615. if (result)
  5616. goto fail_clk;
  5617. /* init active_clients_log after getting ipa-clk */
  5618. result = ipa3_active_clients_log_init();
  5619. if (result)
  5620. goto fail_init_active_client;
  5621. /* Enable ipa3_ctx->enable_clock_scaling */
  5622. ipa3_ctx->enable_clock_scaling = 1;
  5623. /* vote for svs2 on bootup */
  5624. ipa3_ctx->curr_ipa_clk_rate = ipa3_ctx->ctrl->ipa_clk_rate_svs2;
  5625. /* Enable ipa3_ctx->enable_napi_chain */
  5626. ipa3_ctx->enable_napi_chain = 1;
  5627. /* enable IPA clocks explicitly to allow the initialization */
  5628. ipa3_enable_clks();
  5629. /* setup IPA register access */
  5630. IPADBG("Mapping 0x%x\n", resource_p->ipa_mem_base +
  5631. ipa3_ctx->ctrl->ipa_reg_base_ofst);
  5632. ipa3_ctx->mmio = ioremap(resource_p->ipa_mem_base +
  5633. ipa3_ctx->ctrl->ipa_reg_base_ofst,
  5634. resource_p->ipa_mem_size);
  5635. if (!ipa3_ctx->mmio) {
  5636. IPAERR(":ipa-base ioremap err\n");
  5637. result = -EFAULT;
  5638. goto fail_remap;
  5639. }
  5640. IPADBG(
  5641. "base(0x%x)+offset(0x%x)=(0x%x) mapped to (%pK) with len (0x%x)\n",
  5642. resource_p->ipa_mem_base,
  5643. ipa3_ctx->ctrl->ipa_reg_base_ofst,
  5644. resource_p->ipa_mem_base + ipa3_ctx->ctrl->ipa_reg_base_ofst,
  5645. ipa3_ctx->mmio,
  5646. resource_p->ipa_mem_size);
  5647. /*
  5648. * Setup access for register collection/dump on crash
  5649. */
  5650. if (ipa_reg_save_init(IPA_MEM_INIT_VAL) != 0) {
  5651. result = -EFAULT;
  5652. goto fail_gsi_map;
  5653. }
  5654. /*
  5655. * Since we now know where the transport's registers live,
  5656. * let's set up access to them. This is done since subseqent
  5657. * functions, that deal with the transport, require the
  5658. * access.
  5659. */
  5660. if (gsi_map_base(
  5661. ipa3_res.transport_mem_base,
  5662. ipa3_res.transport_mem_size) != 0) {
  5663. IPAERR("Allocation of gsi base failed\n");
  5664. result = -EFAULT;
  5665. goto fail_gsi_map;
  5666. }
  5667. mutex_init(&ipa3_ctx->ipa3_active_clients.mutex);
  5668. IPA_ACTIVE_CLIENTS_PREP_SPECIAL(log_info, "PROXY_CLK_VOTE");
  5669. ipa3_active_clients_log_inc(&log_info, false);
  5670. ipa3_ctx->q6_proxy_clk_vote_valid = true;
  5671. ipa3_ctx->q6_proxy_clk_vote_cnt = 1;
  5672. /*Updating the proxy vote cnt 1 */
  5673. atomic_set(&ipa3_ctx->ipa3_active_clients.cnt, 1);
  5674. /* Create workqueues for power management */
  5675. ipa3_ctx->power_mgmt_wq =
  5676. create_singlethread_workqueue("ipa_power_mgmt");
  5677. if (!ipa3_ctx->power_mgmt_wq) {
  5678. IPAERR("failed to create power mgmt wq\n");
  5679. result = -ENOMEM;
  5680. goto fail_init_hw;
  5681. }
  5682. ipa3_ctx->transport_power_mgmt_wq =
  5683. create_singlethread_workqueue("transport_power_mgmt");
  5684. if (!ipa3_ctx->transport_power_mgmt_wq) {
  5685. IPAERR("failed to create transport power mgmt wq\n");
  5686. result = -ENOMEM;
  5687. goto fail_create_transport_wq;
  5688. }
  5689. mutex_init(&ipa3_ctx->transport_pm.transport_pm_mutex);
  5690. /* init the lookaside cache */
  5691. ipa3_ctx->flt_rule_cache = kmem_cache_create("IPA_FLT",
  5692. sizeof(struct ipa3_flt_entry), 0, 0, NULL);
  5693. if (!ipa3_ctx->flt_rule_cache) {
  5694. IPAERR(":ipa flt cache create failed\n");
  5695. result = -ENOMEM;
  5696. goto fail_flt_rule_cache;
  5697. }
  5698. ipa3_ctx->rt_rule_cache = kmem_cache_create("IPA_RT",
  5699. sizeof(struct ipa3_rt_entry), 0, 0, NULL);
  5700. if (!ipa3_ctx->rt_rule_cache) {
  5701. IPAERR(":ipa rt cache create failed\n");
  5702. result = -ENOMEM;
  5703. goto fail_rt_rule_cache;
  5704. }
  5705. ipa3_ctx->hdr_cache = kmem_cache_create("IPA_HDR",
  5706. sizeof(struct ipa3_hdr_entry), 0, 0, NULL);
  5707. if (!ipa3_ctx->hdr_cache) {
  5708. IPAERR(":ipa hdr cache create failed\n");
  5709. result = -ENOMEM;
  5710. goto fail_hdr_cache;
  5711. }
  5712. ipa3_ctx->hdr_offset_cache =
  5713. kmem_cache_create("IPA_HDR_OFFSET",
  5714. sizeof(struct ipa_hdr_offset_entry), 0, 0, NULL);
  5715. if (!ipa3_ctx->hdr_offset_cache) {
  5716. IPAERR(":ipa hdr off cache create failed\n");
  5717. result = -ENOMEM;
  5718. goto fail_hdr_offset_cache;
  5719. }
  5720. ipa3_ctx->hdr_proc_ctx_cache = kmem_cache_create("IPA_HDR_PROC_CTX",
  5721. sizeof(struct ipa3_hdr_proc_ctx_entry), 0, 0, NULL);
  5722. if (!ipa3_ctx->hdr_proc_ctx_cache) {
  5723. IPAERR(":ipa hdr proc ctx cache create failed\n");
  5724. result = -ENOMEM;
  5725. goto fail_hdr_proc_ctx_cache;
  5726. }
  5727. ipa3_ctx->hdr_proc_ctx_offset_cache =
  5728. kmem_cache_create("IPA_HDR_PROC_CTX_OFFSET",
  5729. sizeof(struct ipa3_hdr_proc_ctx_offset_entry), 0, 0, NULL);
  5730. if (!ipa3_ctx->hdr_proc_ctx_offset_cache) {
  5731. IPAERR(":ipa hdr proc ctx off cache create failed\n");
  5732. result = -ENOMEM;
  5733. goto fail_hdr_proc_ctx_offset_cache;
  5734. }
  5735. ipa3_ctx->rt_tbl_cache = kmem_cache_create("IPA_RT_TBL",
  5736. sizeof(struct ipa3_rt_tbl), 0, 0, NULL);
  5737. if (!ipa3_ctx->rt_tbl_cache) {
  5738. IPAERR(":ipa rt tbl cache create failed\n");
  5739. result = -ENOMEM;
  5740. goto fail_rt_tbl_cache;
  5741. }
  5742. ipa3_ctx->tx_pkt_wrapper_cache =
  5743. kmem_cache_create("IPA_TX_PKT_WRAPPER",
  5744. sizeof(struct ipa3_tx_pkt_wrapper), 0, 0, NULL);
  5745. if (!ipa3_ctx->tx_pkt_wrapper_cache) {
  5746. IPAERR(":ipa tx pkt wrapper cache create failed\n");
  5747. result = -ENOMEM;
  5748. goto fail_tx_pkt_wrapper_cache;
  5749. }
  5750. ipa3_ctx->rx_pkt_wrapper_cache =
  5751. kmem_cache_create("IPA_RX_PKT_WRAPPER",
  5752. sizeof(struct ipa3_rx_pkt_wrapper), 0, 0, NULL);
  5753. if (!ipa3_ctx->rx_pkt_wrapper_cache) {
  5754. IPAERR(":ipa rx pkt wrapper cache create failed\n");
  5755. result = -ENOMEM;
  5756. goto fail_rx_pkt_wrapper_cache;
  5757. }
  5758. /* init the various list heads */
  5759. INIT_LIST_HEAD(&ipa3_ctx->hdr_tbl.head_hdr_entry_list);
  5760. for (i = 0; i < IPA_HDR_BIN_MAX; i++) {
  5761. INIT_LIST_HEAD(&ipa3_ctx->hdr_tbl.head_offset_list[i]);
  5762. INIT_LIST_HEAD(&ipa3_ctx->hdr_tbl.head_free_offset_list[i]);
  5763. }
  5764. INIT_LIST_HEAD(&ipa3_ctx->hdr_proc_ctx_tbl.head_proc_ctx_entry_list);
  5765. for (i = 0; i < IPA_HDR_PROC_CTX_BIN_MAX; i++) {
  5766. INIT_LIST_HEAD(
  5767. &ipa3_ctx->hdr_proc_ctx_tbl.head_offset_list[i]);
  5768. INIT_LIST_HEAD(
  5769. &ipa3_ctx->hdr_proc_ctx_tbl.head_free_offset_list[i]);
  5770. }
  5771. INIT_LIST_HEAD(&ipa3_ctx->rt_tbl_set[IPA_IP_v4].head_rt_tbl_list);
  5772. idr_init(&ipa3_ctx->rt_tbl_set[IPA_IP_v4].rule_ids);
  5773. INIT_LIST_HEAD(&ipa3_ctx->rt_tbl_set[IPA_IP_v6].head_rt_tbl_list);
  5774. idr_init(&ipa3_ctx->rt_tbl_set[IPA_IP_v6].rule_ids);
  5775. rset = &ipa3_ctx->reap_rt_tbl_set[IPA_IP_v4];
  5776. INIT_LIST_HEAD(&rset->head_rt_tbl_list);
  5777. idr_init(&rset->rule_ids);
  5778. rset = &ipa3_ctx->reap_rt_tbl_set[IPA_IP_v6];
  5779. INIT_LIST_HEAD(&rset->head_rt_tbl_list);
  5780. idr_init(&rset->rule_ids);
  5781. idr_init(&ipa3_ctx->flt_rt_counters.hdl);
  5782. spin_lock_init(&ipa3_ctx->flt_rt_counters.hdl_lock);
  5783. memset(&ipa3_ctx->flt_rt_counters.used_hw, 0,
  5784. sizeof(ipa3_ctx->flt_rt_counters.used_hw));
  5785. memset(&ipa3_ctx->flt_rt_counters.used_sw, 0,
  5786. sizeof(ipa3_ctx->flt_rt_counters.used_sw));
  5787. INIT_LIST_HEAD(&ipa3_ctx->intf_list);
  5788. INIT_LIST_HEAD(&ipa3_ctx->msg_list);
  5789. INIT_LIST_HEAD(&ipa3_ctx->pull_msg_list);
  5790. init_waitqueue_head(&ipa3_ctx->msg_waitq);
  5791. mutex_init(&ipa3_ctx->msg_lock);
  5792. /* store wlan client-connect-msg-list */
  5793. INIT_LIST_HEAD(&ipa3_ctx->msg_wlan_client_list);
  5794. mutex_init(&ipa3_ctx->msg_wlan_client_lock);
  5795. mutex_init(&ipa3_ctx->lock);
  5796. mutex_init(&ipa3_ctx->q6_proxy_clk_vote_mutex);
  5797. mutex_init(&ipa3_ctx->ipa_cne_evt_lock);
  5798. idr_init(&ipa3_ctx->ipa_idr);
  5799. spin_lock_init(&ipa3_ctx->idr_lock);
  5800. /* wlan related member */
  5801. memset(&ipa3_ctx->wc_memb, 0, sizeof(ipa3_ctx->wc_memb));
  5802. spin_lock_init(&ipa3_ctx->wc_memb.wlan_spinlock);
  5803. spin_lock_init(&ipa3_ctx->wc_memb.ipa_tx_mul_spinlock);
  5804. INIT_LIST_HEAD(&ipa3_ctx->wc_memb.wlan_comm_desc_list);
  5805. ipa3_ctx->cdev.class = class_create(THIS_MODULE, DRV_NAME);
  5806. result = alloc_chrdev_region(&ipa3_ctx->cdev.dev_num, 0, 1, DRV_NAME);
  5807. if (result) {
  5808. IPAERR("alloc_chrdev_region err\n");
  5809. result = -ENODEV;
  5810. goto fail_alloc_chrdev_region;
  5811. }
  5812. ipa3_ctx->cdev.dev = device_create(ipa3_ctx->cdev.class, NULL,
  5813. ipa3_ctx->cdev.dev_num, ipa3_ctx, DRV_NAME);
  5814. if (IS_ERR(ipa3_ctx->cdev.dev)) {
  5815. IPAERR(":device_create err.\n");
  5816. result = -ENODEV;
  5817. goto fail_device_create;
  5818. }
  5819. /* Create a wakeup source. */
  5820. wakeup_source_init(&ipa3_ctx->w_lock, "IPA_WS");
  5821. spin_lock_init(&ipa3_ctx->wakelock_ref_cnt.spinlock);
  5822. /* Initialize Power Management framework */
  5823. result = ipa_pm_init(&ipa3_res.pm_init);
  5824. if (result) {
  5825. IPAERR("IPA PM initialization failed (%d)\n", -result);
  5826. result = -ENODEV;
  5827. goto fail_ipa_pm_init;
  5828. }
  5829. IPADBG("IPA power manager initialized\n");
  5830. INIT_LIST_HEAD(&ipa3_ctx->ipa_ready_cb_list);
  5831. init_completion(&ipa3_ctx->init_completion_obj);
  5832. init_completion(&ipa3_ctx->uc_loaded_completion_obj);
  5833. result = ipa3_dma_setup();
  5834. if (result) {
  5835. IPAERR("Failed to setup IPA DMA\n");
  5836. result = -ENODEV;
  5837. goto fail_ipa_dma_setup;
  5838. }
  5839. /*
  5840. * We can't register the GSI driver yet, as it expects
  5841. * the GSI FW to be up and running before the registration.
  5842. *
  5843. * For IPA3.0 and the emulation system, the GSI configuration
  5844. * is done by the GSI driver.
  5845. *
  5846. * For IPA3.1 (and on), the GSI configuration is done by TZ.
  5847. */
  5848. if (ipa3_ctx->ipa_hw_type == IPA_HW_v3_0 ||
  5849. ipa3_ctx->ipa3_hw_mode == IPA_HW_MODE_EMULATION) {
  5850. result = ipa3_gsi_pre_fw_load_init();
  5851. if (result) {
  5852. IPAERR("gsi pre FW loading config failed\n");
  5853. result = -ENODEV;
  5854. goto fail_gsi_pre_fw_load_init;
  5855. }
  5856. }
  5857. cdev = &ipa3_ctx->cdev.cdev;
  5858. cdev_init(cdev, &ipa3_drv_fops);
  5859. cdev->owner = THIS_MODULE;
  5860. cdev->ops = &ipa3_drv_fops; /* from LDD3 */
  5861. result = cdev_add(cdev, ipa3_ctx->cdev.dev_num, 1);
  5862. if (result) {
  5863. IPAERR(":cdev_add err=%d\n", -result);
  5864. result = -ENODEV;
  5865. goto fail_cdev_add;
  5866. }
  5867. IPADBG("ipa cdev added successful. major:%d minor:%d\n",
  5868. MAJOR(ipa3_ctx->cdev.dev_num),
  5869. MINOR(ipa3_ctx->cdev.dev_num));
  5870. if (ipa3_ctx->ipa_hw_type >= IPA_HW_v4_1) {
  5871. result = ipa_odl_init();
  5872. if (result) {
  5873. IPADBG("Error: ODL init fialed\n");
  5874. result = -ENODEV;
  5875. goto fail_cdev_add;
  5876. }
  5877. }
  5878. /*
  5879. * for IPA 4.0 offline charge is not needed and we need to prevent
  5880. * power collapse until IPA uC is loaded.
  5881. */
  5882. /* proxy vote for modem is added in ipa3_post_init() phase */
  5883. if (ipa3_ctx->ipa_hw_type != IPA_HW_v4_0)
  5884. ipa3_proxy_clk_unvote();
  5885. return 0;
  5886. fail_cdev_add:
  5887. fail_gsi_pre_fw_load_init:
  5888. ipa3_dma_shutdown();
  5889. fail_ipa_dma_setup:
  5890. ipa_pm_destroy();
  5891. fail_ipa_pm_init:
  5892. device_destroy(ipa3_ctx->cdev.class, ipa3_ctx->cdev.dev_num);
  5893. fail_device_create:
  5894. unregister_chrdev_region(ipa3_ctx->cdev.dev_num, 1);
  5895. fail_alloc_chrdev_region:
  5896. idr_destroy(&ipa3_ctx->ipa_idr);
  5897. rset = &ipa3_ctx->reap_rt_tbl_set[IPA_IP_v6];
  5898. idr_destroy(&rset->rule_ids);
  5899. rset = &ipa3_ctx->reap_rt_tbl_set[IPA_IP_v4];
  5900. idr_destroy(&rset->rule_ids);
  5901. idr_destroy(&ipa3_ctx->rt_tbl_set[IPA_IP_v6].rule_ids);
  5902. idr_destroy(&ipa3_ctx->rt_tbl_set[IPA_IP_v4].rule_ids);
  5903. kmem_cache_destroy(ipa3_ctx->rx_pkt_wrapper_cache);
  5904. fail_rx_pkt_wrapper_cache:
  5905. kmem_cache_destroy(ipa3_ctx->tx_pkt_wrapper_cache);
  5906. fail_tx_pkt_wrapper_cache:
  5907. kmem_cache_destroy(ipa3_ctx->rt_tbl_cache);
  5908. fail_rt_tbl_cache:
  5909. kmem_cache_destroy(ipa3_ctx->hdr_proc_ctx_offset_cache);
  5910. fail_hdr_proc_ctx_offset_cache:
  5911. kmem_cache_destroy(ipa3_ctx->hdr_proc_ctx_cache);
  5912. fail_hdr_proc_ctx_cache:
  5913. kmem_cache_destroy(ipa3_ctx->hdr_offset_cache);
  5914. fail_hdr_offset_cache:
  5915. kmem_cache_destroy(ipa3_ctx->hdr_cache);
  5916. fail_hdr_cache:
  5917. kmem_cache_destroy(ipa3_ctx->rt_rule_cache);
  5918. fail_rt_rule_cache:
  5919. kmem_cache_destroy(ipa3_ctx->flt_rule_cache);
  5920. fail_flt_rule_cache:
  5921. destroy_workqueue(ipa3_ctx->transport_power_mgmt_wq);
  5922. fail_create_transport_wq:
  5923. destroy_workqueue(ipa3_ctx->power_mgmt_wq);
  5924. fail_init_hw:
  5925. gsi_unmap_base();
  5926. fail_gsi_map:
  5927. if (ipa3_ctx->reg_collection_base)
  5928. iounmap(ipa3_ctx->reg_collection_base);
  5929. iounmap(ipa3_ctx->mmio);
  5930. fail_remap:
  5931. ipa3_disable_clks();
  5932. ipa3_active_clients_log_destroy();
  5933. fail_init_active_client:
  5934. if (ipa3_clk)
  5935. clk_put(ipa3_clk);
  5936. ipa3_clk = NULL;
  5937. fail_clk:
  5938. if (ipa3_ctx->ipa_bus_hdl)
  5939. msm_bus_scale_unregister_client(ipa3_ctx->ipa_bus_hdl);
  5940. fail_bus_reg:
  5941. if (ipa3_ctx->ctrl->msm_bus_data_ptr)
  5942. msm_bus_cl_clear_pdata(ipa3_ctx->ctrl->msm_bus_data_ptr);
  5943. fail_init_mem_partition:
  5944. fail_bind:
  5945. kfree(ipa3_ctx->ctrl);
  5946. fail_mem_ctrl:
  5947. kfree(ipa3_ctx->ipa_tz_unlock_reg);
  5948. fail_tz_unlock_reg:
  5949. if (ipa3_ctx->logbuf)
  5950. ipc_log_context_destroy(ipa3_ctx->logbuf);
  5951. kfree(ipa3_ctx);
  5952. ipa3_ctx = NULL;
  5953. fail_mem_ctx:
  5954. return result;
  5955. }
  5956. static int get_ipa_dts_pm_info(struct platform_device *pdev,
  5957. struct ipa3_plat_drv_res *ipa_drv_res)
  5958. {
  5959. int result;
  5960. int i, j;
  5961. result = of_property_read_u32(pdev->dev.of_node,
  5962. "qcom,msm-bus,num-cases",
  5963. &ipa_drv_res->pm_init.threshold_size);
  5964. /* No vote is ignored */
  5965. ipa_drv_res->pm_init.threshold_size -= 2;
  5966. if (result || ipa_drv_res->pm_init.threshold_size >
  5967. IPA_PM_THRESHOLD_MAX) {
  5968. IPAERR("invalid property qcom,msm-bus,num-cases %d\n",
  5969. ipa_drv_res->pm_init.threshold_size);
  5970. return -EFAULT;
  5971. }
  5972. result = of_property_read_u32_array(pdev->dev.of_node,
  5973. "qcom,throughput-threshold",
  5974. ipa_drv_res->pm_init.default_threshold,
  5975. ipa_drv_res->pm_init.threshold_size);
  5976. if (result) {
  5977. IPAERR("failed to read qcom,throughput-thresholds\n");
  5978. return -EFAULT;
  5979. }
  5980. result = of_property_count_strings(pdev->dev.of_node,
  5981. "qcom,scaling-exceptions");
  5982. if (result < 0) {
  5983. IPADBG("no exception list for ipa pm\n");
  5984. result = 0;
  5985. }
  5986. if (result % (ipa_drv_res->pm_init.threshold_size + 1)) {
  5987. IPAERR("failed to read qcom,scaling-exceptions\n");
  5988. return -EFAULT;
  5989. }
  5990. ipa_drv_res->pm_init.exception_size = result /
  5991. (ipa_drv_res->pm_init.threshold_size + 1);
  5992. if (ipa_drv_res->pm_init.exception_size >=
  5993. IPA_PM_EXCEPTION_MAX) {
  5994. IPAERR("exception list larger then max %d\n",
  5995. ipa_drv_res->pm_init.exception_size);
  5996. return -EFAULT;
  5997. }
  5998. for (i = 0; i < ipa_drv_res->pm_init.exception_size; i++) {
  5999. struct ipa_pm_exception *ex = ipa_drv_res->pm_init.exceptions;
  6000. result = of_property_read_string_index(pdev->dev.of_node,
  6001. "qcom,scaling-exceptions",
  6002. i * ipa_drv_res->pm_init.threshold_size,
  6003. &ex[i].usecase);
  6004. if (result) {
  6005. IPAERR("failed to read qcom,scaling-exceptions");
  6006. return -EFAULT;
  6007. }
  6008. for (j = 0; j < ipa_drv_res->pm_init.threshold_size; j++) {
  6009. const char *str;
  6010. result = of_property_read_string_index(
  6011. pdev->dev.of_node,
  6012. "qcom,scaling-exceptions",
  6013. i * ipa_drv_res->pm_init.threshold_size + j + 1,
  6014. &str);
  6015. if (result) {
  6016. IPAERR("failed to read qcom,scaling-exceptions"
  6017. );
  6018. return -EFAULT;
  6019. }
  6020. if (kstrtou32(str, 0, &ex[i].threshold[j])) {
  6021. IPAERR("error str=%s\n", str);
  6022. return -EFAULT;
  6023. }
  6024. }
  6025. }
  6026. return 0;
  6027. }
  6028. static int get_ipa_dts_configuration(struct platform_device *pdev,
  6029. struct ipa3_plat_drv_res *ipa_drv_res)
  6030. {
  6031. int i, result, pos;
  6032. struct resource *resource;
  6033. u32 *ipa_tz_unlock_reg;
  6034. int elem_num;
  6035. u32 mhi_evid_limits[2];
  6036. /* initialize ipa3_res */
  6037. ipa_drv_res->ipa_pipe_mem_start_ofst = IPA_PIPE_MEM_START_OFST;
  6038. ipa_drv_res->ipa_pipe_mem_size = IPA_PIPE_MEM_SIZE;
  6039. ipa_drv_res->ipa_hw_type = 0;
  6040. ipa_drv_res->ipa3_hw_mode = 0;
  6041. ipa_drv_res->platform_type = 0;
  6042. ipa_drv_res->modem_cfg_emb_pipe_flt = false;
  6043. ipa_drv_res->ipa_wdi2 = false;
  6044. ipa_drv_res->ipa_wdi2_over_gsi = false;
  6045. ipa_drv_res->ipa_wdi3_over_gsi = false;
  6046. ipa_drv_res->ipa_mhi_dynamic_config = false;
  6047. ipa_drv_res->use_64_bit_dma_mask = false;
  6048. ipa_drv_res->use_bw_vote = false;
  6049. ipa_drv_res->wan_rx_ring_size = IPA_GENERIC_RX_POOL_SZ;
  6050. ipa_drv_res->lan_rx_ring_size = IPA_GENERIC_RX_POOL_SZ;
  6051. ipa_drv_res->apply_rg10_wa = false;
  6052. ipa_drv_res->gsi_ch20_wa = false;
  6053. ipa_drv_res->ipa_tz_unlock_reg_num = 0;
  6054. ipa_drv_res->ipa_tz_unlock_reg = NULL;
  6055. ipa_drv_res->mhi_evid_limits[0] = IPA_MHI_GSI_EVENT_RING_ID_START;
  6056. ipa_drv_res->mhi_evid_limits[1] = IPA_MHI_GSI_EVENT_RING_ID_END;
  6057. ipa_drv_res->ipa_fltrt_not_hashable = false;
  6058. ipa_drv_res->ipa_endp_delay_wa = false;
  6059. /* Get IPA HW Version */
  6060. result = of_property_read_u32(pdev->dev.of_node, "qcom,ipa-hw-ver",
  6061. &ipa_drv_res->ipa_hw_type);
  6062. if ((result) || (ipa_drv_res->ipa_hw_type == 0)) {
  6063. IPAERR(":get resource failed for ipa-hw-ver\n");
  6064. return -ENODEV;
  6065. }
  6066. IPADBG(": ipa_hw_type = %d", ipa_drv_res->ipa_hw_type);
  6067. if (ipa_drv_res->ipa_hw_type < IPA_HW_v3_0) {
  6068. IPAERR(":IPA version below 3.0 not supported\n");
  6069. return -ENODEV;
  6070. }
  6071. if (ipa_drv_res->ipa_hw_type >= IPA_HW_MAX) {
  6072. IPAERR(":IPA version is greater than the MAX\n");
  6073. return -ENODEV;
  6074. }
  6075. /* Get IPA HW mode */
  6076. result = of_property_read_u32(pdev->dev.of_node, "qcom,ipa-hw-mode",
  6077. &ipa_drv_res->ipa3_hw_mode);
  6078. if (result)
  6079. IPADBG("using default (IPA_MODE_NORMAL) for ipa-hw-mode\n");
  6080. else
  6081. IPADBG(": found ipa_drv_res->ipa3_hw_mode = %d",
  6082. ipa_drv_res->ipa3_hw_mode);
  6083. /* Get Platform Type */
  6084. result = of_property_read_u32(pdev->dev.of_node, "qcom,platform-type",
  6085. &ipa_drv_res->platform_type);
  6086. if (result)
  6087. IPADBG("using default (IPA_PLAT_TYPE_MDM) for platform-type\n");
  6088. else
  6089. IPADBG(": found ipa_drv_res->platform_type = %d",
  6090. ipa_drv_res->platform_type);
  6091. /* Get IPA WAN / LAN RX pool size */
  6092. result = of_property_read_u32(pdev->dev.of_node,
  6093. "qcom,wan-rx-ring-size",
  6094. &ipa_drv_res->wan_rx_ring_size);
  6095. if (result)
  6096. IPADBG("using default for wan-rx-ring-size = %u\n",
  6097. ipa_drv_res->wan_rx_ring_size);
  6098. else
  6099. IPADBG(": found ipa_drv_res->wan-rx-ring-size = %u",
  6100. ipa_drv_res->wan_rx_ring_size);
  6101. result = of_property_read_u32(pdev->dev.of_node,
  6102. "qcom,lan-rx-ring-size",
  6103. &ipa_drv_res->lan_rx_ring_size);
  6104. if (result)
  6105. IPADBG("using default for lan-rx-ring-size = %u\n",
  6106. ipa_drv_res->lan_rx_ring_size);
  6107. else
  6108. IPADBG(": found ipa_drv_res->lan-rx-ring-size = %u",
  6109. ipa_drv_res->lan_rx_ring_size);
  6110. ipa_drv_res->use_ipa_teth_bridge =
  6111. of_property_read_bool(pdev->dev.of_node,
  6112. "qcom,use-ipa-tethering-bridge");
  6113. IPADBG(": using ipa teth bridge = %s",
  6114. ipa_drv_res->use_ipa_teth_bridge
  6115. ? "True" : "False");
  6116. ipa_drv_res->ipa_mhi_dynamic_config =
  6117. of_property_read_bool(pdev->dev.of_node,
  6118. "qcom,use-ipa-in-mhi-mode");
  6119. IPADBG(": ipa_mhi_dynamic_config (%s)\n",
  6120. ipa_drv_res->ipa_mhi_dynamic_config
  6121. ? "True" : "False");
  6122. ipa_drv_res->modem_cfg_emb_pipe_flt =
  6123. of_property_read_bool(pdev->dev.of_node,
  6124. "qcom,modem-cfg-emb-pipe-flt");
  6125. IPADBG(": modem configure embedded pipe filtering = %s\n",
  6126. ipa_drv_res->modem_cfg_emb_pipe_flt
  6127. ? "True" : "False");
  6128. ipa_drv_res->ipa_wdi2_over_gsi =
  6129. of_property_read_bool(pdev->dev.of_node,
  6130. "qcom,ipa-wdi2_over_gsi");
  6131. IPADBG(": WDI-2.0 over gsi= %s\n",
  6132. ipa_drv_res->ipa_wdi2_over_gsi
  6133. ? "True" : "False");
  6134. ipa_drv_res->ipa_endp_delay_wa =
  6135. of_property_read_bool(pdev->dev.of_node,
  6136. "qcom,ipa-endp-delay-wa");
  6137. IPADBG(": endppoint delay wa = %s\n",
  6138. ipa_drv_res->ipa_endp_delay_wa
  6139. ? "True" : "False");
  6140. ipa_drv_res->ipa_wdi3_over_gsi =
  6141. of_property_read_bool(pdev->dev.of_node,
  6142. "qcom,ipa-wdi3-over-gsi");
  6143. IPADBG(": WDI-3.0 over gsi= %s\n",
  6144. ipa_drv_res->ipa_wdi3_over_gsi
  6145. ? "True" : "False");
  6146. ipa_drv_res->ipa_wdi2 =
  6147. of_property_read_bool(pdev->dev.of_node,
  6148. "qcom,ipa-wdi2");
  6149. IPADBG(": WDI-2.0 = %s\n",
  6150. ipa_drv_res->ipa_wdi2
  6151. ? "True" : "False");
  6152. ipa_drv_res->ipa_fltrt_not_hashable =
  6153. of_property_read_bool(pdev->dev.of_node,
  6154. "qcom,ipa-fltrt-not-hashable");
  6155. IPADBG(": IPA filter/route rule hashable = %s\n",
  6156. ipa_drv_res->ipa_fltrt_not_hashable
  6157. ? "True" : "False");
  6158. ipa_drv_res->use_64_bit_dma_mask =
  6159. of_property_read_bool(pdev->dev.of_node,
  6160. "qcom,use-64-bit-dma-mask");
  6161. IPADBG(": use_64_bit_dma_mask = %s\n",
  6162. ipa_drv_res->use_64_bit_dma_mask
  6163. ? "True" : "False");
  6164. ipa_drv_res->use_bw_vote =
  6165. of_property_read_bool(pdev->dev.of_node,
  6166. "qcom,bandwidth-vote-for-ipa");
  6167. IPADBG(": use_bw_vote = %s\n",
  6168. ipa_drv_res->use_bw_vote
  6169. ? "True" : "False");
  6170. ipa_drv_res->skip_uc_pipe_reset =
  6171. of_property_read_bool(pdev->dev.of_node,
  6172. "qcom,skip-uc-pipe-reset");
  6173. IPADBG(": skip uC pipe reset = %s\n",
  6174. ipa_drv_res->skip_uc_pipe_reset
  6175. ? "True" : "False");
  6176. ipa_drv_res->tethered_flow_control =
  6177. of_property_read_bool(pdev->dev.of_node,
  6178. "qcom,tethered-flow-control");
  6179. IPADBG(": Use apps based flow control = %s\n",
  6180. ipa_drv_res->tethered_flow_control
  6181. ? "True" : "False");
  6182. /* Get IPA wrapper address */
  6183. resource = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  6184. "ipa-base");
  6185. if (!resource) {
  6186. IPAERR(":get resource failed for ipa-base!\n");
  6187. return -ENODEV;
  6188. }
  6189. ipa_drv_res->ipa_mem_base = resource->start;
  6190. ipa_drv_res->ipa_mem_size = resource_size(resource);
  6191. IPADBG(": ipa-base = 0x%x, size = 0x%x\n",
  6192. ipa_drv_res->ipa_mem_base,
  6193. ipa_drv_res->ipa_mem_size);
  6194. smmu_info.ipa_base = ipa_drv_res->ipa_mem_base;
  6195. smmu_info.ipa_size = ipa_drv_res->ipa_mem_size;
  6196. /* Get IPA GSI address */
  6197. resource = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  6198. "gsi-base");
  6199. if (!resource) {
  6200. IPAERR(":get resource failed for gsi-base\n");
  6201. return -ENODEV;
  6202. }
  6203. ipa_drv_res->transport_mem_base = resource->start;
  6204. ipa_drv_res->transport_mem_size = resource_size(resource);
  6205. IPADBG(": gsi-base = 0x%x, size = 0x%x\n",
  6206. ipa_drv_res->transport_mem_base,
  6207. ipa_drv_res->transport_mem_size);
  6208. /* Get IPA GSI IRQ number */
  6209. resource = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
  6210. "gsi-irq");
  6211. if (!resource) {
  6212. IPAERR(":get resource failed for gsi-irq\n");
  6213. return -ENODEV;
  6214. }
  6215. ipa_drv_res->transport_irq = resource->start;
  6216. IPADBG(": gsi-irq = %d\n", ipa_drv_res->transport_irq);
  6217. /* Get IPA pipe mem start ofst */
  6218. resource = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  6219. "ipa-pipe-mem");
  6220. if (!resource) {
  6221. IPADBG(":not using pipe memory - resource nonexisting\n");
  6222. } else {
  6223. ipa_drv_res->ipa_pipe_mem_start_ofst = resource->start;
  6224. ipa_drv_res->ipa_pipe_mem_size = resource_size(resource);
  6225. IPADBG(":using pipe memory - at 0x%x of size 0x%x\n",
  6226. ipa_drv_res->ipa_pipe_mem_start_ofst,
  6227. ipa_drv_res->ipa_pipe_mem_size);
  6228. }
  6229. /* Get IPA IRQ number */
  6230. resource = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
  6231. "ipa-irq");
  6232. if (!resource) {
  6233. IPAERR(":get resource failed for ipa-irq\n");
  6234. return -ENODEV;
  6235. }
  6236. ipa_drv_res->ipa_irq = resource->start;
  6237. IPADBG(":ipa-irq = %d\n", ipa_drv_res->ipa_irq);
  6238. result = of_property_read_u32(pdev->dev.of_node, "qcom,ee",
  6239. &ipa_drv_res->ee);
  6240. if (result)
  6241. ipa_drv_res->ee = 0;
  6242. IPADBG(":ee = %u\n", ipa_drv_res->ee);
  6243. ipa_drv_res->apply_rg10_wa =
  6244. of_property_read_bool(pdev->dev.of_node,
  6245. "qcom,use-rg10-limitation-mitigation");
  6246. IPADBG(": Use Register Group 10 limitation mitigation = %s\n",
  6247. ipa_drv_res->apply_rg10_wa
  6248. ? "True" : "False");
  6249. ipa_drv_res->gsi_ch20_wa =
  6250. of_property_read_bool(pdev->dev.of_node,
  6251. "qcom,do-not-use-ch-gsi-20");
  6252. IPADBG(": GSI CH 20 WA is = %s\n",
  6253. ipa_drv_res->gsi_ch20_wa
  6254. ? "Needed" : "Not needed");
  6255. elem_num = of_property_count_elems_of_size(pdev->dev.of_node,
  6256. "qcom,mhi-event-ring-id-limits", sizeof(u32));
  6257. if (elem_num == 2) {
  6258. if (of_property_read_u32_array(pdev->dev.of_node,
  6259. "qcom,mhi-event-ring-id-limits", mhi_evid_limits, 2)) {
  6260. IPAERR("failed to read mhi event ring id limits\n");
  6261. return -EFAULT;
  6262. }
  6263. if (mhi_evid_limits[0] > mhi_evid_limits[1]) {
  6264. IPAERR("mhi event ring id low limit > high limit\n");
  6265. return -EFAULT;
  6266. }
  6267. ipa_drv_res->mhi_evid_limits[0] = mhi_evid_limits[0];
  6268. ipa_drv_res->mhi_evid_limits[1] = mhi_evid_limits[1];
  6269. IPADBG(": mhi-event-ring-id-limits start=%u end=%u\n",
  6270. mhi_evid_limits[0], mhi_evid_limits[1]);
  6271. } else {
  6272. if (elem_num > 0) {
  6273. IPAERR("Invalid mhi event ring id limits number %d\n",
  6274. elem_num);
  6275. return -EINVAL;
  6276. }
  6277. IPADBG("use default mhi evt ring id limits start=%u end=%u\n",
  6278. ipa_drv_res->mhi_evid_limits[0],
  6279. ipa_drv_res->mhi_evid_limits[1]);
  6280. }
  6281. elem_num = of_property_count_elems_of_size(pdev->dev.of_node,
  6282. "qcom,ipa-tz-unlock-reg", sizeof(u32));
  6283. if (elem_num > 0 && elem_num % 2 == 0) {
  6284. ipa_drv_res->ipa_tz_unlock_reg_num = elem_num / 2;
  6285. ipa_tz_unlock_reg = kcalloc(elem_num, sizeof(u32), GFP_KERNEL);
  6286. if (ipa_tz_unlock_reg == NULL)
  6287. return -ENOMEM;
  6288. ipa_drv_res->ipa_tz_unlock_reg = kcalloc(
  6289. ipa_drv_res->ipa_tz_unlock_reg_num,
  6290. sizeof(*ipa_drv_res->ipa_tz_unlock_reg),
  6291. GFP_KERNEL);
  6292. if (ipa_drv_res->ipa_tz_unlock_reg == NULL) {
  6293. kfree(ipa_tz_unlock_reg);
  6294. return -ENOMEM;
  6295. }
  6296. if (of_property_read_u32_array(pdev->dev.of_node,
  6297. "qcom,ipa-tz-unlock-reg", ipa_tz_unlock_reg,
  6298. elem_num)) {
  6299. IPAERR("failed to read register addresses\n");
  6300. kfree(ipa_tz_unlock_reg);
  6301. kfree(ipa_drv_res->ipa_tz_unlock_reg);
  6302. return -EFAULT;
  6303. }
  6304. pos = 0;
  6305. for (i = 0; i < ipa_drv_res->ipa_tz_unlock_reg_num; i++) {
  6306. ipa_drv_res->ipa_tz_unlock_reg[i].reg_addr =
  6307. ipa_tz_unlock_reg[pos++];
  6308. ipa_drv_res->ipa_tz_unlock_reg[i].size =
  6309. ipa_tz_unlock_reg[pos++];
  6310. IPADBG("tz unlock reg %d: addr 0x%pa size %llu\n", i,
  6311. &ipa_drv_res->ipa_tz_unlock_reg[i].reg_addr,
  6312. ipa_drv_res->ipa_tz_unlock_reg[i].size);
  6313. }
  6314. kfree(ipa_tz_unlock_reg);
  6315. }
  6316. /* get IPA PM related information */
  6317. result = get_ipa_dts_pm_info(pdev, ipa_drv_res);
  6318. if (result) {
  6319. IPAERR("failed to get pm info from dts %d\n", result);
  6320. return result;
  6321. }
  6322. ipa_drv_res->wdi_over_pcie =
  6323. of_property_read_bool(pdev->dev.of_node,
  6324. "qcom,wlan-ce-db-over-pcie");
  6325. IPADBG("Is wdi_over_pcie ? (%s)\n",
  6326. ipa_drv_res->wdi_over_pcie ? "Yes":"No");
  6327. /*
  6328. * If we're on emulator, get its interrupt controller's mem
  6329. * start and size
  6330. */
  6331. if (ipa_drv_res->ipa3_hw_mode == IPA_HW_MODE_EMULATION) {
  6332. resource = platform_get_resource_byname(
  6333. pdev, IORESOURCE_MEM, "intctrl-base");
  6334. if (!resource) {
  6335. IPAERR(":Can't find intctrl-base resource\n");
  6336. return -ENODEV;
  6337. }
  6338. ipa_drv_res->emulator_intcntrlr_mem_base =
  6339. resource->start;
  6340. ipa_drv_res->emulator_intcntrlr_mem_size =
  6341. resource_size(resource);
  6342. IPADBG(":using intctrl-base at 0x%x of size 0x%x\n",
  6343. ipa_drv_res->emulator_intcntrlr_mem_base,
  6344. ipa_drv_res->emulator_intcntrlr_mem_size);
  6345. }
  6346. ipa_drv_res->entire_ipa_block_size = 0x100000;
  6347. result = of_property_read_u32(pdev->dev.of_node,
  6348. "qcom,entire-ipa-block-size",
  6349. &ipa_drv_res->entire_ipa_block_size);
  6350. IPADBG(": entire_ipa_block_size = %d\n",
  6351. ipa_drv_res->entire_ipa_block_size);
  6352. /*
  6353. * We'll read register-collection-on-crash here, but log it
  6354. * later below because its value may change based on other
  6355. * subsequent dtsi reads......
  6356. */
  6357. ipa_drv_res->do_register_collection_on_crash =
  6358. of_property_read_bool(pdev->dev.of_node,
  6359. "qcom,register-collection-on-crash");
  6360. /*
  6361. * We'll read testbus-collection-on-crash here...
  6362. */
  6363. ipa_drv_res->do_testbus_collection_on_crash =
  6364. of_property_read_bool(pdev->dev.of_node,
  6365. "qcom,testbus-collection-on-crash");
  6366. IPADBG(": doing testbus collection on crash = %u\n",
  6367. ipa_drv_res->do_testbus_collection_on_crash);
  6368. /*
  6369. * We'll read non-tn-collection-on-crash here...
  6370. */
  6371. ipa_drv_res->do_non_tn_collection_on_crash =
  6372. of_property_read_bool(pdev->dev.of_node,
  6373. "qcom,non-tn-collection-on-crash");
  6374. IPADBG(": doing non-tn collection on crash = %u\n",
  6375. ipa_drv_res->do_non_tn_collection_on_crash);
  6376. /*
  6377. * We'll read ram-collection-on-crash here...
  6378. */
  6379. ipa_drv_res->do_ram_collection_on_crash =
  6380. of_property_read_bool(
  6381. pdev->dev.of_node,
  6382. "qcom,ram-collection-on-crash");
  6383. IPADBG(": doing ram collection on crash = %u\n",
  6384. ipa_drv_res->do_ram_collection_on_crash);
  6385. if (ipa_drv_res->do_testbus_collection_on_crash ||
  6386. ipa_drv_res->do_non_tn_collection_on_crash ||
  6387. ipa_drv_res->do_ram_collection_on_crash)
  6388. ipa_drv_res->do_register_collection_on_crash = true;
  6389. IPADBG(": doing register collection on crash = %u\n",
  6390. ipa_drv_res->do_register_collection_on_crash);
  6391. result = of_property_read_u32(
  6392. pdev->dev.of_node,
  6393. "qcom,secure-debug-check-action",
  6394. &ipa_drv_res->secure_debug_check_action);
  6395. if (result ||
  6396. (ipa_drv_res->secure_debug_check_action != 0 &&
  6397. ipa_drv_res->secure_debug_check_action != 1 &&
  6398. ipa_drv_res->secure_debug_check_action != 2))
  6399. ipa_drv_res->secure_debug_check_action = USE_SCM;
  6400. IPADBG(": secure-debug-check-action = %d\n",
  6401. ipa_drv_res->secure_debug_check_action);
  6402. return 0;
  6403. }
  6404. static int ipa_smmu_wlan_cb_probe(struct device *dev)
  6405. {
  6406. struct ipa_smmu_cb_ctx *cb = ipa3_get_smmu_ctx(IPA_SMMU_CB_WLAN);
  6407. int fast = 0;
  6408. int bypass = 0;
  6409. u32 add_map_size;
  6410. const u32 *add_map;
  6411. int i;
  6412. u32 iova_ap_mapping[2];
  6413. IPADBG("WLAN CB PROBE dev=%pK\n", dev);
  6414. if (!smmu_info.present[IPA_SMMU_CB_WLAN]) {
  6415. IPAERR("WLAN SMMU is disabled\n");
  6416. return 0;
  6417. }
  6418. IPADBG("WLAN CB PROBE dev=%pK retrieving IOMMU mapping\n", dev);
  6419. cb->iommu_domain = iommu_get_domain_for_dev(dev);
  6420. if (IS_ERR_OR_NULL(cb->iommu_domain)) {
  6421. IPAERR("could not get iommu domain\n");
  6422. return -EINVAL;
  6423. }
  6424. IPADBG("WLAN CB PROBE mapping retrieved\n");
  6425. cb->is_cache_coherent = of_property_read_bool(dev->of_node,
  6426. "dma-coherent");
  6427. cb->dev = dev;
  6428. cb->valid = true;
  6429. cb->va_start = cb->va_end = cb->va_size = 0;
  6430. if (of_property_read_u32_array(
  6431. dev->of_node, "qcom,iommu-dma-addr-pool",
  6432. iova_ap_mapping, 2) == 0) {
  6433. cb->va_start = iova_ap_mapping[0];
  6434. cb->va_size = iova_ap_mapping[1];
  6435. cb->va_end = cb->va_start + cb->va_size;
  6436. }
  6437. IPADBG("WLAN CB PROBE dev=%pK va_start=0x%x va_size=0x%x\n",
  6438. dev, cb->va_start, cb->va_size);
  6439. /*
  6440. * Prior to these calls to iommu_domain_get_attr(), these
  6441. * attributes were set in this function relative to dtsi values
  6442. * defined for this driver. In other words, if corresponding ipa
  6443. * driver owned values were found in the dtsi, they were read and
  6444. * set here.
  6445. *
  6446. * In this new world, the developer will use iommu owned dtsi
  6447. * settings to set them there. This new logic below, simply
  6448. * checks to see if they've been set in dtsi. If so, the logic
  6449. * further below acts accordingly...
  6450. */
  6451. iommu_domain_get_attr(cb->iommu_domain, DOMAIN_ATTR_S1_BYPASS, &bypass);
  6452. iommu_domain_get_attr(cb->iommu_domain, DOMAIN_ATTR_FAST, &fast);
  6453. IPADBG(
  6454. "WLAN CB PROBE dev=%pK DOMAIN ATTRS bypass=%d fast=%d\n",
  6455. dev, bypass, fast);
  6456. ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_WLAN] = (bypass != 0);
  6457. /* MAP ipa-uc ram */
  6458. add_map = of_get_property(dev->of_node,
  6459. "qcom,additional-mapping", &add_map_size);
  6460. if (add_map) {
  6461. /* mapping size is an array of 3-tuple of u32 */
  6462. if (add_map_size % (3 * sizeof(u32))) {
  6463. IPAERR("wrong additional mapping format\n");
  6464. cb->valid = false;
  6465. return -EFAULT;
  6466. }
  6467. /* iterate of each entry of the additional mapping array */
  6468. for (i = 0; i < add_map_size / sizeof(u32); i += 3) {
  6469. u32 iova = be32_to_cpu(add_map[i]);
  6470. u32 pa = be32_to_cpu(add_map[i + 1]);
  6471. u32 size = be32_to_cpu(add_map[i + 2]);
  6472. unsigned long iova_p;
  6473. phys_addr_t pa_p;
  6474. u32 size_p;
  6475. IPA_SMMU_ROUND_TO_PAGE(iova, pa, size,
  6476. iova_p, pa_p, size_p);
  6477. IPADBG_LOW("mapping 0x%lx to 0x%pa size %d\n",
  6478. iova_p, &pa_p, size_p);
  6479. ipa3_iommu_map(cb->iommu_domain,
  6480. iova_p, pa_p, size_p,
  6481. IOMMU_READ | IOMMU_WRITE | IOMMU_MMIO);
  6482. }
  6483. }
  6484. return 0;
  6485. }
  6486. static int ipa_smmu_uc_cb_probe(struct device *dev)
  6487. {
  6488. struct ipa_smmu_cb_ctx *cb = ipa3_get_smmu_ctx(IPA_SMMU_CB_UC);
  6489. int bypass = 0;
  6490. int fast = 0;
  6491. u32 iova_ap_mapping[2];
  6492. IPADBG("UC CB PROBE dev=%pK\n", dev);
  6493. if (!smmu_info.present[IPA_SMMU_CB_UC]) {
  6494. IPAERR("UC SMMU is disabled\n");
  6495. return 0;
  6496. }
  6497. if (smmu_info.use_64_bit_dma_mask) {
  6498. if (dma_set_mask(dev, DMA_BIT_MASK(64)) ||
  6499. dma_set_coherent_mask(dev, DMA_BIT_MASK(64))) {
  6500. IPAERR("DMA set 64bit mask failed\n");
  6501. return -EOPNOTSUPP;
  6502. }
  6503. } else {
  6504. if (dma_set_mask(dev, DMA_BIT_MASK(32)) ||
  6505. dma_set_coherent_mask(dev, DMA_BIT_MASK(32))) {
  6506. IPAERR("DMA set 32bit mask failed\n");
  6507. return -EOPNOTSUPP;
  6508. }
  6509. }
  6510. IPADBG("UC CB PROBE dev=%pK retrieving IOMMU mapping\n", dev);
  6511. cb->iommu_domain = iommu_get_domain_for_dev(dev);
  6512. if (IS_ERR_OR_NULL(cb->iommu_domain)) {
  6513. IPAERR("could not get iommu domain\n");
  6514. return -EINVAL;
  6515. }
  6516. IPADBG("UC CB PROBE mapping retrieved\n");
  6517. cb->is_cache_coherent = of_property_read_bool(dev->of_node,
  6518. "dma-coherent");
  6519. cb->dev = dev;
  6520. cb->valid = true;
  6521. cb->va_start = cb->va_end = cb->va_size = 0;
  6522. if (of_property_read_u32_array(
  6523. dev->of_node, "qcom,iommu-dma-addr-pool",
  6524. iova_ap_mapping, 2) == 0) {
  6525. cb->va_start = iova_ap_mapping[0];
  6526. cb->va_size = iova_ap_mapping[1];
  6527. cb->va_end = cb->va_start + cb->va_size;
  6528. }
  6529. IPADBG("UC CB PROBE dev=%pK va_start=0x%x va_size=0x%x\n",
  6530. dev, cb->va_start, cb->va_size);
  6531. /*
  6532. * Prior to these calls to iommu_domain_get_attr(), these
  6533. * attributes were set in this function relative to dtsi values
  6534. * defined for this driver. In other words, if corresponding ipa
  6535. * driver owned values were found in the dtsi, they were read and
  6536. * set here.
  6537. *
  6538. * In this new world, the developer will use iommu owned dtsi
  6539. * settings to set them there. This new logic below, simply
  6540. * checks to see if they've been set in dtsi. If so, the logic
  6541. * further below acts accordingly...
  6542. */
  6543. iommu_domain_get_attr(cb->iommu_domain, DOMAIN_ATTR_S1_BYPASS, &bypass);
  6544. iommu_domain_get_attr(cb->iommu_domain, DOMAIN_ATTR_FAST, &fast);
  6545. IPADBG("UC CB PROBE dev=%pK DOMAIN ATTRS bypass=%d fast=%d\n",
  6546. dev, bypass, fast);
  6547. ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_UC] = (bypass != 0);
  6548. ipa3_ctx->uc_pdev = dev;
  6549. return 0;
  6550. }
  6551. static int ipa_smmu_ap_cb_probe(struct device *dev)
  6552. {
  6553. struct ipa_smmu_cb_ctx *cb = ipa3_get_smmu_ctx(IPA_SMMU_CB_AP);
  6554. int fast = 0;
  6555. int bypass = 0;
  6556. u32 add_map_size;
  6557. const u32 *add_map;
  6558. void *smem_addr;
  6559. size_t smem_size;
  6560. u32 ipa_smem_size = 0;
  6561. int ret;
  6562. int i;
  6563. unsigned long iova_p;
  6564. phys_addr_t pa_p;
  6565. u32 size_p;
  6566. phys_addr_t iova;
  6567. phys_addr_t pa;
  6568. u32 iova_ap_mapping[2];
  6569. IPADBG("AP CB PROBE dev=%pK\n", dev);
  6570. if (!smmu_info.present[IPA_SMMU_CB_AP]) {
  6571. IPAERR("AP SMMU is disabled");
  6572. return 0;
  6573. }
  6574. if (smmu_info.use_64_bit_dma_mask) {
  6575. if (dma_set_mask(dev, DMA_BIT_MASK(64)) ||
  6576. dma_set_coherent_mask(dev, DMA_BIT_MASK(64))) {
  6577. IPAERR("DMA set 64bit mask failed\n");
  6578. return -EOPNOTSUPP;
  6579. }
  6580. } else {
  6581. if (dma_set_mask(dev, DMA_BIT_MASK(32)) ||
  6582. dma_set_coherent_mask(dev, DMA_BIT_MASK(32))) {
  6583. IPAERR("DMA set 32bit mask failed\n");
  6584. return -EOPNOTSUPP;
  6585. }
  6586. }
  6587. IPADBG("AP CB PROBE dev=%pK retrieving IOMMU mapping\n", dev);
  6588. cb->iommu_domain = iommu_get_domain_for_dev(dev);
  6589. if (IS_ERR_OR_NULL(cb->iommu_domain)) {
  6590. IPAERR("could not get iommu domain\n");
  6591. return -EINVAL;
  6592. }
  6593. IPADBG("AP CB PROBE mapping retrieved\n");
  6594. cb->is_cache_coherent = of_property_read_bool(dev->of_node,
  6595. "dma-coherent");
  6596. cb->dev = dev;
  6597. cb->valid = true;
  6598. cb->va_start = cb->va_end = cb->va_size = 0;
  6599. if (of_property_read_u32_array(
  6600. dev->of_node, "qcom,iommu-dma-addr-pool",
  6601. iova_ap_mapping, 2) == 0) {
  6602. cb->va_start = iova_ap_mapping[0];
  6603. cb->va_size = iova_ap_mapping[1];
  6604. cb->va_end = cb->va_start + cb->va_size;
  6605. }
  6606. IPADBG("AP CB PROBE dev=%pK va_start=0x%x va_size=0x%x\n",
  6607. dev, cb->va_start, cb->va_size);
  6608. /*
  6609. * Prior to these calls to iommu_domain_get_attr(), these
  6610. * attributes were set in this function relative to dtsi values
  6611. * defined for this driver. In other words, if corresponding ipa
  6612. * driver owned values were found in the dtsi, they were read and
  6613. * set here.
  6614. *
  6615. * In this new world, the developer will use iommu owned dtsi
  6616. * settings to set them there. This new logic below, simply
  6617. * checks to see if they've been set in dtsi. If so, the logic
  6618. * further below acts accordingly...
  6619. */
  6620. iommu_domain_get_attr(cb->iommu_domain, DOMAIN_ATTR_S1_BYPASS, &bypass);
  6621. iommu_domain_get_attr(cb->iommu_domain, DOMAIN_ATTR_FAST, &fast);
  6622. IPADBG("AP CB PROBE dev=%pK DOMAIN ATTRS bypass=%d fast=%d\n",
  6623. dev, bypass, fast);
  6624. ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_AP] = (bypass != 0);
  6625. add_map = of_get_property(dev->of_node,
  6626. "qcom,additional-mapping", &add_map_size);
  6627. if (add_map) {
  6628. /* mapping size is an array of 3-tuple of u32 */
  6629. if (add_map_size % (3 * sizeof(u32))) {
  6630. IPAERR("wrong additional mapping format\n");
  6631. cb->valid = false;
  6632. return -EFAULT;
  6633. }
  6634. /* iterate of each entry of the additional mapping array */
  6635. for (i = 0; i < add_map_size / sizeof(u32); i += 3) {
  6636. u32 iova = be32_to_cpu(add_map[i]);
  6637. u32 pa = be32_to_cpu(add_map[i + 1]);
  6638. u32 size = be32_to_cpu(add_map[i + 2]);
  6639. unsigned long iova_p;
  6640. phys_addr_t pa_p;
  6641. u32 size_p;
  6642. IPA_SMMU_ROUND_TO_PAGE(iova, pa, size,
  6643. iova_p, pa_p, size_p);
  6644. IPADBG_LOW("mapping 0x%lx to 0x%pa size %d\n",
  6645. iova_p, &pa_p, size_p);
  6646. ipa3_iommu_map(cb->iommu_domain,
  6647. iova_p, pa_p, size_p,
  6648. IOMMU_READ | IOMMU_WRITE | IOMMU_MMIO);
  6649. }
  6650. }
  6651. ret = of_property_read_u32(dev->of_node, "qcom,ipa-q6-smem-size",
  6652. &ipa_smem_size);
  6653. if (ret) {
  6654. IPADBG("ipa q6 smem size (default) = %u\n", IPA_SMEM_SIZE);
  6655. ipa_smem_size = IPA_SMEM_SIZE;
  6656. } else {
  6657. IPADBG("ipa q6 smem size = %u\n", ipa_smem_size);
  6658. }
  6659. if (ipa3_ctx->platform_type != IPA_PLAT_TYPE_APQ) {
  6660. /* map SMEM memory for IPA table accesses */
  6661. ret = qcom_smem_alloc(SMEM_MODEM,
  6662. SMEM_IPA_FILTER_TABLE,
  6663. ipa_smem_size);
  6664. if (ret < 0 && ret != -EEXIST) {
  6665. IPAERR("unable to allocate smem MODEM entry\n");
  6666. cb->valid = false;
  6667. return -EFAULT;
  6668. }
  6669. smem_addr = qcom_smem_get(SMEM_MODEM,
  6670. SMEM_IPA_FILTER_TABLE,
  6671. &smem_size);
  6672. if (IS_ERR(smem_addr)) {
  6673. IPAERR("unable to acquire smem MODEM entry\n");
  6674. cb->valid = false;
  6675. return -EFAULT;
  6676. }
  6677. if (smem_size != ipa_smem_size)
  6678. IPAERR("unexpected read q6 smem size %zu %u\n",
  6679. smem_size, ipa_smem_size);
  6680. iova = qcom_smem_virt_to_phys(smem_addr);
  6681. pa = iova;
  6682. IPA_SMMU_ROUND_TO_PAGE(iova, pa, ipa_smem_size,
  6683. iova_p, pa_p, size_p);
  6684. IPADBG("mapping 0x%lx to 0x%pa size %d\n",
  6685. iova_p, &pa_p, size_p);
  6686. ipa3_iommu_map(cb->iommu_domain,
  6687. iova_p, pa_p, size_p,
  6688. IOMMU_READ | IOMMU_WRITE);
  6689. }
  6690. smmu_info.present[IPA_SMMU_CB_AP] = true;
  6691. ipa3_ctx->pdev = dev;
  6692. cb->next_addr = cb->va_end;
  6693. return 0;
  6694. }
  6695. static int ipa_smmu_11ad_cb_probe(struct device *dev)
  6696. {
  6697. int bypass = 0;
  6698. struct ipa_smmu_cb_ctx *cb = ipa3_get_smmu_ctx(IPA_SMMU_CB_11AD);
  6699. u32 iova_ap_mapping[2];
  6700. IPADBG("11AD CB probe: dev=%pK\n", dev);
  6701. if (!smmu_info.present[IPA_SMMU_CB_11AD]) {
  6702. IPAERR("11AD SMMU is disabled");
  6703. return 0;
  6704. }
  6705. cb->iommu_domain = iommu_get_domain_for_dev(dev);
  6706. if (IS_ERR_OR_NULL(cb->iommu_domain)) {
  6707. IPAERR("could not get iommu domain\n");
  6708. return -EINVAL;
  6709. }
  6710. cb->is_cache_coherent = of_property_read_bool(dev->of_node,
  6711. "dma-coherent");
  6712. cb->dev = dev;
  6713. cb->valid = true;
  6714. cb->va_start = cb->va_end = cb->va_size = 0;
  6715. if (of_property_read_u32_array(
  6716. dev->of_node, "qcom,iommu-dma-addr-pool",
  6717. iova_ap_mapping, 2) == 0) {
  6718. cb->va_start = iova_ap_mapping[0];
  6719. cb->va_size = iova_ap_mapping[1];
  6720. cb->va_end = cb->va_start + cb->va_size;
  6721. }
  6722. IPADBG("11AD CB PROBE dev=%pK va_start=0x%x va_size=0x%x\n",
  6723. dev, cb->va_start, cb->va_size);
  6724. iommu_domain_get_attr(cb->iommu_domain, DOMAIN_ATTR_S1_BYPASS, &bypass);
  6725. IPADBG("11AD CB PROBE dev=%pK DOMAIN ATTRS bypass=%d\n",
  6726. dev, bypass);
  6727. ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_11AD] = (bypass != 0);
  6728. if (of_property_read_bool(dev->of_node, "qcom,shared-cb")) {
  6729. IPADBG("11AD using shared CB\n");
  6730. cb->shared = true;
  6731. }
  6732. return 0;
  6733. }
  6734. static int ipa_smmu_cb_probe(struct device *dev, enum ipa_smmu_cb_type cb_type)
  6735. {
  6736. switch (cb_type) {
  6737. case IPA_SMMU_CB_AP:
  6738. return ipa_smmu_ap_cb_probe(dev);
  6739. case IPA_SMMU_CB_WLAN:
  6740. return ipa_smmu_wlan_cb_probe(dev);
  6741. case IPA_SMMU_CB_UC:
  6742. return ipa_smmu_uc_cb_probe(dev);
  6743. case IPA_SMMU_CB_11AD:
  6744. return ipa_smmu_11ad_cb_probe(dev);
  6745. case IPA_SMMU_CB_MAX:
  6746. IPAERR("Invalid cb_type\n");
  6747. }
  6748. return 0;
  6749. }
  6750. static int ipa3_attach_to_smmu(void)
  6751. {
  6752. struct ipa_smmu_cb_ctx *cb;
  6753. int i, result;
  6754. ipa3_ctx->pdev = &ipa3_ctx->master_pdev->dev;
  6755. ipa3_ctx->uc_pdev = &ipa3_ctx->master_pdev->dev;
  6756. if (smmu_info.arm_smmu) {
  6757. IPADBG("smmu is enabled\n");
  6758. for (i = 0; i < IPA_SMMU_CB_MAX; i++) {
  6759. cb = ipa3_get_smmu_ctx(i);
  6760. result = ipa_smmu_cb_probe(cb->dev, i);
  6761. if (result)
  6762. IPAERR("probe failed for cb %d\n", i);
  6763. }
  6764. } else {
  6765. IPADBG("smmu is disabled\n");
  6766. }
  6767. return 0;
  6768. }
  6769. static irqreturn_t ipa3_smp2p_modem_clk_query_isr(int irq, void *ctxt)
  6770. {
  6771. ipa3_freeze_clock_vote_and_notify_modem();
  6772. return IRQ_HANDLED;
  6773. }
  6774. static int ipa3_smp2p_probe(struct device *dev)
  6775. {
  6776. struct device_node *node = dev->of_node;
  6777. int res;
  6778. int irq = 0;
  6779. if (ipa3_ctx == NULL) {
  6780. IPAERR("ipa3_ctx was not initialized\n");
  6781. return -EPROBE_DEFER;
  6782. }
  6783. IPADBG("node->name=%s\n", node->name);
  6784. if (ipa3_ctx->platform_type == IPA_PLAT_TYPE_APQ) {
  6785. IPADBG("Ignore smp2p on APQ platform\n");
  6786. return 0;
  6787. }
  6788. if (strcmp("qcom,smp2p_map_ipa_1_out", node->name) == 0) {
  6789. if (of_find_property(node, "qcom,smem-states", NULL)) {
  6790. ipa3_ctx->smp2p_info.smem_state =
  6791. qcom_smem_state_get(dev, "ipa-smp2p-out",
  6792. &ipa3_ctx->smp2p_info.smem_bit);
  6793. if (IS_ERR(ipa3_ctx->smp2p_info.smem_state)) {
  6794. IPAERR("fail to get smp2p clk resp bit %ld\n",
  6795. PTR_ERR(ipa3_ctx->smp2p_info.smem_state));
  6796. return PTR_ERR(ipa3_ctx->smp2p_info.smem_state);
  6797. }
  6798. IPADBG("smem_bit=%d\n", ipa3_ctx->smp2p_info.smem_bit);
  6799. }
  6800. } else if (strcmp("qcom,smp2p_map_ipa_1_in", node->name) == 0) {
  6801. res = irq = of_irq_get_byname(node, "ipa-smp2p-in");
  6802. if (res < 0) {
  6803. IPADBG("of_irq_get_byname returned %d\n", irq);
  6804. return res;
  6805. }
  6806. ipa3_ctx->smp2p_info.in_base_id = irq;
  6807. IPADBG("smp2p irq#=%d\n", irq);
  6808. res = devm_request_threaded_irq(dev, irq, NULL,
  6809. (irq_handler_t)ipa3_smp2p_modem_clk_query_isr,
  6810. IRQF_TRIGGER_RISING | IRQF_ONESHOT,
  6811. "ipa_smp2p_clk_vote", dev);
  6812. if (res) {
  6813. IPAERR("fail to register smp2p irq=%d\n", irq);
  6814. return -ENODEV;
  6815. }
  6816. }
  6817. return 0;
  6818. }
  6819. int ipa3_plat_drv_probe(struct platform_device *pdev_p,
  6820. struct ipa_api_controller *api_ctrl,
  6821. const struct of_device_id *pdrv_match)
  6822. {
  6823. int result;
  6824. struct device *dev = &pdev_p->dev;
  6825. struct ipa_smmu_cb_ctx *cb;
  6826. IPADBG("IPA driver probing started\n");
  6827. IPADBG("dev->of_node->name = %s\n", dev->of_node->name);
  6828. if (of_device_is_compatible(dev->of_node, "qcom,ipa-smmu-ap-cb")) {
  6829. if (ipa3_ctx == NULL) {
  6830. IPAERR("ipa3_ctx was not initialized\n");
  6831. return -EPROBE_DEFER;
  6832. }
  6833. cb = ipa3_get_smmu_ctx(IPA_SMMU_CB_AP);
  6834. cb->dev = dev;
  6835. smmu_info.present[IPA_SMMU_CB_AP] = true;
  6836. return 0;
  6837. }
  6838. if (of_device_is_compatible(dev->of_node, "qcom,ipa-smmu-wlan-cb")) {
  6839. if (ipa3_ctx == NULL) {
  6840. IPAERR("ipa3_ctx was not initialized\n");
  6841. return -EPROBE_DEFER;
  6842. }
  6843. cb = ipa3_get_smmu_ctx(IPA_SMMU_CB_WLAN);
  6844. cb->dev = dev;
  6845. smmu_info.present[IPA_SMMU_CB_WLAN] = true;
  6846. return 0;
  6847. }
  6848. if (of_device_is_compatible(dev->of_node, "qcom,ipa-smmu-uc-cb")) {
  6849. if (ipa3_ctx == NULL) {
  6850. IPAERR("ipa3_ctx was not initialized\n");
  6851. return -EPROBE_DEFER;
  6852. }
  6853. cb = ipa3_get_smmu_ctx(IPA_SMMU_CB_UC);
  6854. cb->dev = dev;
  6855. smmu_info.present[IPA_SMMU_CB_UC] = true;
  6856. return 0;
  6857. }
  6858. if (of_device_is_compatible(dev->of_node, "qcom,ipa-smmu-11ad-cb")) {
  6859. cb = ipa3_get_smmu_ctx(IPA_SMMU_CB_11AD);
  6860. cb->dev = dev;
  6861. smmu_info.present[IPA_SMMU_CB_11AD] = true;
  6862. return 0;
  6863. }
  6864. if (of_device_is_compatible(dev->of_node,
  6865. "qcom,smp2p-map-ipa-1-out"))
  6866. return ipa3_smp2p_probe(dev);
  6867. if (of_device_is_compatible(dev->of_node,
  6868. "qcom,smp2p-map-ipa-1-in"))
  6869. return ipa3_smp2p_probe(dev);
  6870. result = get_ipa_dts_configuration(pdev_p, &ipa3_res);
  6871. if (result) {
  6872. IPAERR("IPA dts parsing failed\n");
  6873. return result;
  6874. }
  6875. result = ipa3_bind_api_controller(ipa3_res.ipa_hw_type, api_ctrl);
  6876. if (result) {
  6877. IPAERR("IPA API binding failed\n");
  6878. return result;
  6879. }
  6880. if (of_property_read_bool(pdev_p->dev.of_node, "qcom,arm-smmu")) {
  6881. if (of_property_read_bool(pdev_p->dev.of_node,
  6882. "qcom,use-64-bit-dma-mask"))
  6883. smmu_info.use_64_bit_dma_mask = true;
  6884. smmu_info.arm_smmu = true;
  6885. } else {
  6886. if (of_property_read_bool(pdev_p->dev.of_node,
  6887. "qcom,use-64-bit-dma-mask")) {
  6888. if (dma_set_mask(&pdev_p->dev, DMA_BIT_MASK(64)) ||
  6889. dma_set_coherent_mask(&pdev_p->dev,
  6890. DMA_BIT_MASK(64))) {
  6891. IPAERR("DMA set 64bit mask failed\n");
  6892. return -EOPNOTSUPP;
  6893. }
  6894. } else {
  6895. if (dma_set_mask(&pdev_p->dev, DMA_BIT_MASK(32)) ||
  6896. dma_set_coherent_mask(&pdev_p->dev,
  6897. DMA_BIT_MASK(32))) {
  6898. IPAERR("DMA set 32bit mask failed\n");
  6899. return -EOPNOTSUPP;
  6900. }
  6901. }
  6902. }
  6903. /* Proceed to real initialization */
  6904. result = ipa3_pre_init(&ipa3_res, pdev_p);
  6905. if (result) {
  6906. IPAERR("ipa3_init failed\n");
  6907. return result;
  6908. }
  6909. result = of_platform_populate(pdev_p->dev.of_node,
  6910. pdrv_match, NULL, &pdev_p->dev);
  6911. if (result) {
  6912. IPAERR("failed to populate platform\n");
  6913. return result;
  6914. }
  6915. return result;
  6916. }
  6917. /**
  6918. * ipa3_ap_suspend() - suspend callback for runtime_pm
  6919. * @dev: pointer to device
  6920. *
  6921. * This callback will be invoked by the runtime_pm framework when an AP suspend
  6922. * operation is invoked, usually by pressing a suspend button.
  6923. *
  6924. * Returns -EAGAIN to runtime_pm framework in case IPA is in use by AP.
  6925. * This will postpone the suspend operation until IPA is no longer used by AP.
  6926. */
  6927. int ipa3_ap_suspend(struct device *dev)
  6928. {
  6929. int i;
  6930. IPADBG("Enter...\n");
  6931. /* In case there is a tx/rx handler in polling mode fail to suspend */
  6932. for (i = 0; i < ipa3_ctx->ipa_num_pipes; i++) {
  6933. if (ipa3_ctx->ep[i].sys &&
  6934. atomic_read(&ipa3_ctx->ep[i].sys->curr_polling_state)) {
  6935. IPAERR("EP %d is in polling state, do not suspend\n",
  6936. i);
  6937. return -EAGAIN;
  6938. }
  6939. }
  6940. ipa_pm_deactivate_all_deferred();
  6941. IPADBG("Exit\n");
  6942. return 0;
  6943. }
  6944. /**
  6945. * ipa3_ap_resume() - resume callback for runtime_pm
  6946. * @dev: pointer to device
  6947. *
  6948. * This callback will be invoked by the runtime_pm framework when an AP resume
  6949. * operation is invoked.
  6950. *
  6951. * Always returns 0 since resume should always succeed.
  6952. */
  6953. int ipa3_ap_resume(struct device *dev)
  6954. {
  6955. return 0;
  6956. }
  6957. struct ipa3_context *ipa3_get_ctx(void)
  6958. {
  6959. return ipa3_ctx;
  6960. }
  6961. static void ipa_gsi_notify_cb(struct gsi_per_notify *notify)
  6962. {
  6963. /*
  6964. * These values are reported by hardware. Any error indicates
  6965. * hardware unexpected state.
  6966. */
  6967. switch (notify->evt_id) {
  6968. case GSI_PER_EVT_GLOB_ERROR:
  6969. IPAERR("Got GSI_PER_EVT_GLOB_ERROR\n");
  6970. IPAERR("Err_desc = 0x%04x\n", notify->data.err_desc);
  6971. break;
  6972. case GSI_PER_EVT_GLOB_GP1:
  6973. IPAERR("Got GSI_PER_EVT_GLOB_GP1\n");
  6974. ipa_assert();
  6975. break;
  6976. case GSI_PER_EVT_GLOB_GP2:
  6977. IPAERR("Got GSI_PER_EVT_GLOB_GP2\n");
  6978. ipa_assert();
  6979. break;
  6980. case GSI_PER_EVT_GLOB_GP3:
  6981. IPAERR("Got GSI_PER_EVT_GLOB_GP3\n");
  6982. ipa_assert();
  6983. break;
  6984. case GSI_PER_EVT_GENERAL_BREAK_POINT:
  6985. IPAERR("Got GSI_PER_EVT_GENERAL_BREAK_POINT\n");
  6986. break;
  6987. case GSI_PER_EVT_GENERAL_BUS_ERROR:
  6988. IPAERR("Got GSI_PER_EVT_GENERAL_BUS_ERROR\n");
  6989. ipa_assert();
  6990. break;
  6991. case GSI_PER_EVT_GENERAL_CMD_FIFO_OVERFLOW:
  6992. IPAERR("Got GSI_PER_EVT_GENERAL_CMD_FIFO_OVERFLOW\n");
  6993. ipa_assert();
  6994. break;
  6995. case GSI_PER_EVT_GENERAL_MCS_STACK_OVERFLOW:
  6996. IPAERR("Got GSI_PER_EVT_GENERAL_MCS_STACK_OVERFLOW\n");
  6997. ipa_assert();
  6998. break;
  6999. default:
  7000. IPAERR("Received unexpected evt: %d\n",
  7001. notify->evt_id);
  7002. ipa_assert();
  7003. }
  7004. }
  7005. int ipa3_register_ipa_ready_cb(void (*ipa_ready_cb)(void *), void *user_data)
  7006. {
  7007. struct ipa3_ready_cb_info *cb_info = NULL;
  7008. /* check ipa3_ctx existed or not */
  7009. if (!ipa3_ctx) {
  7010. IPADBG("IPA driver haven't initialized\n");
  7011. return -ENXIO;
  7012. }
  7013. mutex_lock(&ipa3_ctx->lock);
  7014. if (ipa3_ctx->ipa_initialization_complete) {
  7015. mutex_unlock(&ipa3_ctx->lock);
  7016. IPADBG("IPA driver finished initialization already\n");
  7017. return -EEXIST;
  7018. }
  7019. cb_info = kmalloc(sizeof(struct ipa3_ready_cb_info), GFP_KERNEL);
  7020. if (!cb_info) {
  7021. mutex_unlock(&ipa3_ctx->lock);
  7022. return -ENOMEM;
  7023. }
  7024. cb_info->ready_cb = ipa_ready_cb;
  7025. cb_info->user_data = user_data;
  7026. list_add_tail(&cb_info->link, &ipa3_ctx->ipa_ready_cb_list);
  7027. mutex_unlock(&ipa3_ctx->lock);
  7028. return 0;
  7029. }
  7030. int ipa3_iommu_map(struct iommu_domain *domain,
  7031. unsigned long iova, phys_addr_t paddr, size_t size, int prot)
  7032. {
  7033. struct ipa_smmu_cb_ctx *cb = NULL;
  7034. IPADBG_LOW("domain =0x%pK iova 0x%lx\n", domain, iova);
  7035. IPADBG_LOW("paddr =0x%pa size 0x%x\n", &paddr, (u32)size);
  7036. /* make sure no overlapping */
  7037. if (domain == ipa3_get_smmu_domain()) {
  7038. cb = ipa3_get_smmu_ctx(IPA_SMMU_CB_AP);
  7039. if (iova >= cb->va_start && iova < cb->va_end) {
  7040. IPAERR("iommu AP overlap addr 0x%lx\n", iova);
  7041. ipa_assert();
  7042. return -EFAULT;
  7043. }
  7044. } else if (domain == ipa3_get_wlan_smmu_domain()) {
  7045. /* wlan is one time map */
  7046. cb = ipa3_get_smmu_ctx(IPA_SMMU_CB_WLAN);
  7047. } else if (domain == ipa3_get_11ad_smmu_domain()) {
  7048. /* 11ad is one time map */
  7049. cb = ipa3_get_smmu_ctx(IPA_SMMU_CB_11AD);
  7050. } else if (domain == ipa3_get_uc_smmu_domain()) {
  7051. cb = ipa3_get_smmu_ctx(IPA_SMMU_CB_UC);
  7052. if (iova >= cb->va_start && iova < cb->va_end) {
  7053. IPAERR("iommu uC overlap addr 0x%lx\n", iova);
  7054. ipa_assert();
  7055. return -EFAULT;
  7056. }
  7057. } else {
  7058. IPAERR("Unexpected domain 0x%pK\n", domain);
  7059. ipa_assert();
  7060. return -EFAULT;
  7061. }
  7062. if (cb == NULL) {
  7063. IPAERR("Unexpected cb turning NULL for domain 0x%pK\n", domain);
  7064. ipa_assert();
  7065. }
  7066. /*
  7067. * IOMMU_CACHE is needed to make the entries cachable
  7068. * if cache coherency is enabled in dtsi.
  7069. */
  7070. if (cb->is_cache_coherent)
  7071. prot |= IOMMU_CACHE;
  7072. return iommu_map(domain, iova, paddr, size, prot);
  7073. }
  7074. /**
  7075. * ipa3_get_smmu_params()- Return the ipa3 smmu related params.
  7076. */
  7077. int ipa3_get_smmu_params(struct ipa_smmu_in_params *in,
  7078. struct ipa_smmu_out_params *out)
  7079. {
  7080. bool is_smmu_enable = false;
  7081. if (out == NULL || in == NULL) {
  7082. IPAERR("bad parms for Client SMMU out params\n");
  7083. return -EINVAL;
  7084. }
  7085. if (!ipa3_ctx) {
  7086. IPAERR("IPA not yet initialized\n");
  7087. return -EINVAL;
  7088. }
  7089. out->shared_cb = false;
  7090. switch (in->smmu_client) {
  7091. case IPA_SMMU_WLAN_CLIENT:
  7092. if (ipa3_ctx->ipa_wdi3_over_gsi ||
  7093. ipa3_ctx->ipa_wdi2_over_gsi)
  7094. is_smmu_enable =
  7095. !(ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_AP] ||
  7096. ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_WLAN]);
  7097. else
  7098. is_smmu_enable =
  7099. !(ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_UC] ||
  7100. ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_WLAN]);
  7101. break;
  7102. case IPA_SMMU_WIGIG_CLIENT:
  7103. is_smmu_enable = !(ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_UC] ||
  7104. ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_11AD] ||
  7105. ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_AP]);
  7106. if (is_smmu_enable) {
  7107. if (ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_UC] ||
  7108. ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_11AD] ||
  7109. ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_AP]) {
  7110. IPAERR("11AD SMMU Discrepancy (%d %d %d)\n",
  7111. ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_UC],
  7112. ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_AP],
  7113. ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_11AD]);
  7114. WARN_ON(1);
  7115. return -EINVAL;
  7116. }
  7117. } else {
  7118. if (!ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_UC] ||
  7119. !ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_11AD] ||
  7120. !ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_AP]) {
  7121. IPAERR("11AD SMMU Discrepancy (%d %d %d)\n",
  7122. ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_UC],
  7123. ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_AP],
  7124. ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_11AD]);
  7125. WARN_ON(1);
  7126. return -EINVAL;
  7127. }
  7128. }
  7129. out->shared_cb = (ipa3_get_smmu_ctx(IPA_SMMU_CB_11AD))->shared;
  7130. break;
  7131. case IPA_SMMU_AP_CLIENT:
  7132. is_smmu_enable =
  7133. !(ipa3_ctx->s1_bypass_arr[IPA_SMMU_CB_AP]);
  7134. break;
  7135. default:
  7136. is_smmu_enable = false;
  7137. IPAERR("Trying to get illegal clients SMMU status");
  7138. return -EINVAL;
  7139. }
  7140. out->smmu_enable = is_smmu_enable;
  7141. return 0;
  7142. }
  7143. #define MAX_LEN 96
  7144. void ipa_pc_qmp_enable(void)
  7145. {
  7146. char buf[MAX_LEN] = "{class: bcm, res: ipa_pc, val: 1}";
  7147. struct qmp_pkt pkt;
  7148. int ret = 0;
  7149. struct ipa3_pc_mbox_data *mbox_data = &ipa3_ctx->pc_mbox;
  7150. IPADBG("Enter\n");
  7151. /* prepare the mailbox struct */
  7152. mbox_data->mbox_client.dev = &ipa3_ctx->master_pdev->dev;
  7153. mbox_data->mbox_client.tx_block = true;
  7154. mbox_data->mbox_client.tx_tout = MBOX_TOUT_MS;
  7155. mbox_data->mbox_client.knows_txdone = false;
  7156. mbox_data->mbox = mbox_request_channel(&mbox_data->mbox_client, 0);
  7157. if (IS_ERR(mbox_data->mbox)) {
  7158. ret = PTR_ERR(mbox_data->mbox);
  7159. if (ret != -EPROBE_DEFER)
  7160. IPAERR("mailbox channel request failed, ret=%d\n", ret);
  7161. return;
  7162. }
  7163. /* prepare the QMP packet to send */
  7164. pkt.size = MAX_LEN;
  7165. pkt.data = buf;
  7166. /* send the QMP packet to AOP */
  7167. ret = mbox_send_message(mbox_data->mbox, &pkt);
  7168. if (ret < 0)
  7169. IPAERR("qmp message send failed, ret=%d\n", ret);
  7170. if (mbox_data->mbox) {
  7171. mbox_free_channel(mbox_data->mbox);
  7172. mbox_data->mbox = NULL;
  7173. }
  7174. }
  7175. /**************************************************************
  7176. * PCIe Version
  7177. *************************************************************/
  7178. int ipa3_pci_drv_probe(
  7179. struct pci_dev *pci_dev,
  7180. struct ipa_api_controller *api_ctrl,
  7181. const struct of_device_id *pdrv_match)
  7182. {
  7183. int result;
  7184. struct ipa3_plat_drv_res *ipa_drv_res;
  7185. u32 bar0_offset;
  7186. u32 mem_start;
  7187. u32 mem_end;
  7188. uint32_t bits;
  7189. uint32_t ipa_start, gsi_start, intctrl_start;
  7190. struct device *dev;
  7191. static struct platform_device platform_dev;
  7192. if (!pci_dev || !api_ctrl || !pdrv_match) {
  7193. IPAERR(
  7194. "Bad arg: pci_dev (%pK) and/or api_ctrl (%pK) and/or pdrv_match (%pK)\n",
  7195. pci_dev, api_ctrl, pdrv_match);
  7196. return -EOPNOTSUPP;
  7197. }
  7198. dev = &(pci_dev->dev);
  7199. IPADBG("IPA PCI driver probing started\n");
  7200. /*
  7201. * Follow PCI driver flow here.
  7202. * pci_enable_device: Enables device and assigns resources
  7203. * pci_request_region: Makes BAR0 address region usable
  7204. */
  7205. result = pci_enable_device(pci_dev);
  7206. if (result < 0) {
  7207. IPAERR("pci_enable_device() failed\n");
  7208. return -EOPNOTSUPP;
  7209. }
  7210. result = pci_request_region(pci_dev, 0, "IPA Memory");
  7211. if (result < 0) {
  7212. IPAERR("pci_request_region() failed\n");
  7213. pci_disable_device(pci_dev);
  7214. return -EOPNOTSUPP;
  7215. }
  7216. /*
  7217. * When in the PCI/emulation environment, &platform_dev is
  7218. * passed to get_ipa_dts_configuration(), but is unused, since
  7219. * all usages of it in the function are replaced by CPP
  7220. * relative to definitions in ipa_emulation_stubs.h. Passing
  7221. * &platform_dev makes code validity tools happy.
  7222. */
  7223. if (get_ipa_dts_configuration(&platform_dev, &ipa3_res) != 0) {
  7224. IPAERR("get_ipa_dts_configuration() failed\n");
  7225. pci_release_region(pci_dev, 0);
  7226. pci_disable_device(pci_dev);
  7227. return -EOPNOTSUPP;
  7228. }
  7229. ipa_drv_res = &ipa3_res;
  7230. result =
  7231. of_property_read_u32(NULL, "emulator-bar0-offset",
  7232. &bar0_offset);
  7233. if (result) {
  7234. IPAERR(":get resource failed for emulator-bar0-offset!\n");
  7235. pci_release_region(pci_dev, 0);
  7236. pci_disable_device(pci_dev);
  7237. return -ENODEV;
  7238. }
  7239. IPADBG(":using emulator-bar0-offset 0x%08X\n", bar0_offset);
  7240. ipa_start = ipa_drv_res->ipa_mem_base;
  7241. gsi_start = ipa_drv_res->transport_mem_base;
  7242. intctrl_start = ipa_drv_res->emulator_intcntrlr_mem_base;
  7243. /*
  7244. * Where will we be inerrupted at?
  7245. */
  7246. ipa_drv_res->emulator_irq = pci_dev->irq;
  7247. IPADBG(
  7248. "EMULATION PCI_INTERRUPT_PIN(%u)\n",
  7249. ipa_drv_res->emulator_irq);
  7250. /*
  7251. * Set the ipa_mem_base to the PCI base address of BAR0
  7252. */
  7253. mem_start = pci_resource_start(pci_dev, 0);
  7254. mem_end = pci_resource_end(pci_dev, 0);
  7255. IPADBG("PCI START = 0x%x\n", mem_start);
  7256. IPADBG("PCI END = 0x%x\n", mem_end);
  7257. ipa_drv_res->ipa_mem_base = mem_start + bar0_offset;
  7258. smmu_info.ipa_base = ipa_drv_res->ipa_mem_base;
  7259. smmu_info.ipa_size = ipa_drv_res->ipa_mem_size;
  7260. ipa_drv_res->transport_mem_base =
  7261. ipa_drv_res->ipa_mem_base + (gsi_start - ipa_start);
  7262. ipa_drv_res->emulator_intcntrlr_mem_base =
  7263. ipa_drv_res->ipa_mem_base + (intctrl_start - ipa_start);
  7264. IPADBG("ipa_mem_base = 0x%x\n",
  7265. ipa_drv_res->ipa_mem_base);
  7266. IPADBG("ipa_mem_size = 0x%x\n",
  7267. ipa_drv_res->ipa_mem_size);
  7268. IPADBG("transport_mem_base = 0x%x\n",
  7269. ipa_drv_res->transport_mem_base);
  7270. IPADBG("transport_mem_size = 0x%x\n",
  7271. ipa_drv_res->transport_mem_size);
  7272. IPADBG("emulator_intcntrlr_mem_base = 0x%x\n",
  7273. ipa_drv_res->emulator_intcntrlr_mem_base);
  7274. IPADBG("emulator_intcntrlr_mem_size = 0x%x\n",
  7275. ipa_drv_res->emulator_intcntrlr_mem_size);
  7276. result = ipa3_bind_api_controller(ipa_drv_res->ipa_hw_type, api_ctrl);
  7277. if (result != 0) {
  7278. IPAERR("ipa3_bind_api_controller() failed\n");
  7279. pci_release_region(pci_dev, 0);
  7280. pci_disable_device(pci_dev);
  7281. return result;
  7282. }
  7283. bits = (ipa_drv_res->use_64_bit_dma_mask) ? 64 : 32;
  7284. if (dma_set_mask(dev, DMA_BIT_MASK(bits)) != 0) {
  7285. IPAERR("dma_set_mask(%pK, %u) failed\n", dev, bits);
  7286. pci_release_region(pci_dev, 0);
  7287. pci_disable_device(pci_dev);
  7288. return -EOPNOTSUPP;
  7289. }
  7290. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(bits)) != 0) {
  7291. IPAERR("dma_set_coherent_mask(%pK, %u) failed\n", dev, bits);
  7292. pci_release_region(pci_dev, 0);
  7293. pci_disable_device(pci_dev);
  7294. return -EOPNOTSUPP;
  7295. }
  7296. pci_set_master(pci_dev);
  7297. memset(&platform_dev, 0, sizeof(platform_dev));
  7298. platform_dev.dev = *dev;
  7299. /* Proceed to real initialization */
  7300. result = ipa3_pre_init(&ipa3_res, &platform_dev);
  7301. if (result) {
  7302. IPAERR("ipa3_init failed\n");
  7303. pci_clear_master(pci_dev);
  7304. pci_release_region(pci_dev, 0);
  7305. pci_disable_device(pci_dev);
  7306. return result;
  7307. }
  7308. return result;
  7309. }
  7310. /*
  7311. * The following returns transport register memory location and
  7312. * size...
  7313. */
  7314. int ipa3_get_transport_info(
  7315. phys_addr_t *phys_addr_ptr,
  7316. unsigned long *size_ptr)
  7317. {
  7318. if (!phys_addr_ptr || !size_ptr) {
  7319. IPAERR("Bad arg: phys_addr_ptr(%pK) and/or size_ptr(%pK)\n",
  7320. phys_addr_ptr, size_ptr);
  7321. return -EINVAL;
  7322. }
  7323. *phys_addr_ptr = ipa3_res.transport_mem_base;
  7324. *size_ptr = ipa3_res.transport_mem_size;
  7325. return 0;
  7326. }
  7327. EXPORT_SYMBOL(ipa3_get_transport_info);
  7328. static uint emulation_type = IPA_HW_v4_0;
  7329. /*
  7330. * The following returns emulation type...
  7331. */
  7332. uint ipa3_get_emulation_type(void)
  7333. {
  7334. return emulation_type;
  7335. }
  7336. MODULE_LICENSE("GPL v2");
  7337. MODULE_DESCRIPTION("IPA HW device driver");
  7338. /*
  7339. * Module parameter. Invoke as follows:
  7340. * insmod ipat.ko emulation_type=[13|14|17|...|N]
  7341. * Examples:
  7342. * insmod ipat.ko emulation_type=13 # for IPA 3.5.1
  7343. * insmod ipat.ko emulation_type=14 # for IPA 4.0
  7344. * insmod ipat.ko emulation_type=17 # for IPA 4.5
  7345. *
  7346. * NOTE: The emulation_type values need to come from: enum ipa_hw_type
  7347. *
  7348. */
  7349. module_param(emulation_type, uint, 0000);
  7350. MODULE_PARM_DESC(
  7351. emulation_type,
  7352. "emulation_type=N N can be 13 for IPA 3.5.1, 14 for IPA 4.0, 17 for IPA 4.5");