main.c 124 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2020, 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #define pr_fmt(fmt) "icnss2: " fmt
  7. #include <linux/of_address.h>
  8. #include <linux/clk.h>
  9. #include <linux/iommu.h>
  10. #include <linux/export.h>
  11. #include <linux/err.h>
  12. #include <linux/of.h>
  13. #include <linux/of_device.h>
  14. #include <linux/init.h>
  15. #include <linux/io.h>
  16. #include <linux/module.h>
  17. #include <linux/kernel.h>
  18. #include <linux/debugfs.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/slab.h>
  21. #include <linux/regulator/consumer.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/sched.h>
  24. #include <linux/delay.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/thread_info.h>
  27. #include <linux/uaccess.h>
  28. #include <linux/etherdevice.h>
  29. #include <linux/of.h>
  30. #include <linux/of_irq.h>
  31. #include <linux/pm_runtime.h>
  32. #include <linux/soc/qcom/qmi.h>
  33. #include <linux/sysfs.h>
  34. #include <linux/thermal.h>
  35. #include <soc/qcom/memory_dump.h>
  36. #include <soc/qcom/secure_buffer.h>
  37. #include <soc/qcom/socinfo.h>
  38. #include <soc/qcom/qcom_ramdump.h>
  39. #include <linux/soc/qcom/smem.h>
  40. #include <linux/soc/qcom/smem_state.h>
  41. #include <linux/remoteproc.h>
  42. #include <linux/remoteproc/qcom_rproc.h>
  43. #include <linux/soc/qcom/pdr.h>
  44. #include <linux/remoteproc.h>
  45. #include <trace/hooks/remoteproc.h>
  46. #ifdef SLATE_MODULE_ENABLED
  47. #include <linux/soc/qcom/slatecom_interface.h>
  48. #include <linux/soc/qcom/slate_events_bridge_intf.h>
  49. #include <uapi/linux/slatecom_interface.h>
  50. #endif
  51. #include "main.h"
  52. #include "qmi.h"
  53. #include "debug.h"
  54. #include "power.h"
  55. #include "genl.h"
  56. #define MAX_PROP_SIZE 32
  57. #define NUM_LOG_PAGES 10
  58. #define NUM_LOG_LONG_PAGES 4
  59. #define ICNSS_MAGIC 0x5abc5abc
  60. #define ICNSS_WLAN_SERVICE_NAME "wlan/fw"
  61. #define ICNSS_WLANPD_NAME "msm/modem/wlan_pd"
  62. #define ICNSS_DEFAULT_FEATURE_MASK 0x01
  63. #define ICNSS_M3_SEGMENT(segment) "wcnss_"segment
  64. #define ICNSS_M3_SEGMENT_PHYAREG "phyareg"
  65. #define ICNSS_M3_SEGMENT_PHYA "phydbg"
  66. #define ICNSS_M3_SEGMENT_WMACREG "wmac0reg"
  67. #define ICNSS_M3_SEGMENT_WCSSDBG "WCSSDBG"
  68. #define ICNSS_M3_SEGMENT_PHYAM3 "PHYAPDMEM"
  69. #define ICNSS_QUIRKS_DEFAULT BIT(FW_REJUVENATE_ENABLE)
  70. #define ICNSS_MAX_PROBE_CNT 2
  71. #define ICNSS_BDF_TYPE_DEFAULT ICNSS_BDF_ELF
  72. #define PROBE_TIMEOUT 15000
  73. #define SMP2P_SOC_WAKE_TIMEOUT 500
  74. #ifdef CONFIG_ICNSS2_DEBUG
  75. static unsigned long qmi_timeout = 3000;
  76. module_param(qmi_timeout, ulong, 0600);
  77. #define WLFW_TIMEOUT msecs_to_jiffies(qmi_timeout)
  78. #else
  79. #define WLFW_TIMEOUT msecs_to_jiffies(3000)
  80. #endif
  81. #define ICNSS_RECOVERY_TIMEOUT 60000
  82. #define ICNSS_WPSS_SSR_TIMEOUT 5000
  83. #define ICNSS_CAL_TIMEOUT 40000
  84. static struct icnss_priv *penv;
  85. static struct work_struct wpss_loader;
  86. static struct work_struct wpss_ssr_work;
  87. uint64_t dynamic_feature_mask = ICNSS_DEFAULT_FEATURE_MASK;
  88. #define ICNSS_EVENT_PENDING 2989
  89. #define ICNSS_EVENT_SYNC BIT(0)
  90. #define ICNSS_EVENT_UNINTERRUPTIBLE BIT(1)
  91. #define ICNSS_EVENT_SYNC_UNINTERRUPTIBLE (ICNSS_EVENT_UNINTERRUPTIBLE | \
  92. ICNSS_EVENT_SYNC)
  93. #define ICNSS_DMS_QMI_CONNECTION_WAIT_MS 50
  94. #define ICNSS_DMS_QMI_CONNECTION_WAIT_RETRY 200
  95. #define SMP2P_GET_MAX_RETRY 4
  96. #define SMP2P_GET_RETRY_DELAY_MS 500
  97. #define RAMDUMP_NUM_DEVICES 256
  98. #define ICNSS_RAMDUMP_NAME "icnss_ramdump"
  99. #define WLAN_EN_TEMP_THRESHOLD 5000
  100. #define WLAN_EN_DELAY 500
  101. #define ICNSS_RPROC_LEN 10
  102. static DEFINE_IDA(rd_minor_id);
  103. enum icnss_pdr_cause_index {
  104. ICNSS_FW_CRASH,
  105. ICNSS_ROOT_PD_CRASH,
  106. ICNSS_ROOT_PD_SHUTDOWN,
  107. ICNSS_HOST_ERROR,
  108. };
  109. static const char * const icnss_pdr_cause[] = {
  110. [ICNSS_FW_CRASH] = "FW crash",
  111. [ICNSS_ROOT_PD_CRASH] = "Root PD crashed",
  112. [ICNSS_ROOT_PD_SHUTDOWN] = "Root PD shutdown",
  113. [ICNSS_HOST_ERROR] = "Host error",
  114. };
  115. static void icnss_set_plat_priv(struct icnss_priv *priv)
  116. {
  117. penv = priv;
  118. }
  119. static struct icnss_priv *icnss_get_plat_priv(void)
  120. {
  121. return penv;
  122. }
  123. static inline void icnss_wpss_unload(struct icnss_priv *priv)
  124. {
  125. if (priv && priv->rproc) {
  126. rproc_shutdown(priv->rproc);
  127. rproc_put(priv->rproc);
  128. priv->rproc = NULL;
  129. }
  130. }
  131. static ssize_t icnss_sysfs_store(struct kobject *kobj,
  132. struct kobj_attribute *attr,
  133. const char *buf, size_t count)
  134. {
  135. struct icnss_priv *priv = icnss_get_plat_priv();
  136. if (!priv)
  137. return count;
  138. icnss_pr_dbg("Received shutdown indication");
  139. atomic_set(&priv->is_shutdown, true);
  140. if (priv->wpss_supported && priv->device_id == ADRASTEA_DEVICE_ID)
  141. icnss_wpss_unload(priv);
  142. return count;
  143. }
  144. static struct kobj_attribute icnss_sysfs_attribute =
  145. __ATTR(shutdown, 0660, NULL, icnss_sysfs_store);
  146. static void icnss_pm_stay_awake(struct icnss_priv *priv)
  147. {
  148. if (atomic_inc_return(&priv->pm_count) != 1)
  149. return;
  150. icnss_pr_vdbg("PM stay awake, state: 0x%lx, count: %d\n", priv->state,
  151. atomic_read(&priv->pm_count));
  152. pm_stay_awake(&priv->pdev->dev);
  153. priv->stats.pm_stay_awake++;
  154. }
  155. static void icnss_pm_relax(struct icnss_priv *priv)
  156. {
  157. int r = atomic_dec_return(&priv->pm_count);
  158. WARN_ON(r < 0);
  159. if (r != 0)
  160. return;
  161. icnss_pr_vdbg("PM relax, state: 0x%lx, count: %d\n", priv->state,
  162. atomic_read(&priv->pm_count));
  163. pm_relax(&priv->pdev->dev);
  164. priv->stats.pm_relax++;
  165. }
  166. char *icnss_driver_event_to_str(enum icnss_driver_event_type type)
  167. {
  168. switch (type) {
  169. case ICNSS_DRIVER_EVENT_SERVER_ARRIVE:
  170. return "SERVER_ARRIVE";
  171. case ICNSS_DRIVER_EVENT_SERVER_EXIT:
  172. return "SERVER_EXIT";
  173. case ICNSS_DRIVER_EVENT_FW_READY_IND:
  174. return "FW_READY";
  175. case ICNSS_DRIVER_EVENT_REGISTER_DRIVER:
  176. return "REGISTER_DRIVER";
  177. case ICNSS_DRIVER_EVENT_UNREGISTER_DRIVER:
  178. return "UNREGISTER_DRIVER";
  179. case ICNSS_DRIVER_EVENT_PD_SERVICE_DOWN:
  180. return "PD_SERVICE_DOWN";
  181. case ICNSS_DRIVER_EVENT_FW_EARLY_CRASH_IND:
  182. return "FW_EARLY_CRASH_IND";
  183. case ICNSS_DRIVER_EVENT_IDLE_SHUTDOWN:
  184. return "IDLE_SHUTDOWN";
  185. case ICNSS_DRIVER_EVENT_IDLE_RESTART:
  186. return "IDLE_RESTART";
  187. case ICNSS_DRIVER_EVENT_FW_INIT_DONE_IND:
  188. return "FW_INIT_DONE";
  189. case ICNSS_DRIVER_EVENT_QDSS_TRACE_REQ_MEM:
  190. return "QDSS_TRACE_REQ_MEM";
  191. case ICNSS_DRIVER_EVENT_QDSS_TRACE_SAVE:
  192. return "QDSS_TRACE_SAVE";
  193. case ICNSS_DRIVER_EVENT_QDSS_TRACE_FREE:
  194. return "QDSS_TRACE_FREE";
  195. case ICNSS_DRIVER_EVENT_M3_DUMP_UPLOAD_REQ:
  196. return "M3_DUMP_UPLOAD";
  197. case ICNSS_DRIVER_EVENT_QDSS_TRACE_REQ_DATA:
  198. return "QDSS_TRACE_REQ_DATA";
  199. case ICNSS_DRIVER_EVENT_SUBSYS_RESTART_LEVEL:
  200. return "SUBSYS_RESTART_LEVEL";
  201. case ICNSS_DRIVER_EVENT_MAX:
  202. return "EVENT_MAX";
  203. }
  204. return "UNKNOWN";
  205. };
  206. char *icnss_soc_wake_event_to_str(enum icnss_soc_wake_event_type type)
  207. {
  208. switch (type) {
  209. case ICNSS_SOC_WAKE_REQUEST_EVENT:
  210. return "SOC_WAKE_REQUEST";
  211. case ICNSS_SOC_WAKE_RELEASE_EVENT:
  212. return "SOC_WAKE_RELEASE";
  213. case ICNSS_SOC_WAKE_EVENT_MAX:
  214. return "SOC_EVENT_MAX";
  215. }
  216. return "UNKNOWN";
  217. };
  218. int icnss_driver_event_post(struct icnss_priv *priv,
  219. enum icnss_driver_event_type type,
  220. u32 flags, void *data)
  221. {
  222. struct icnss_driver_event *event;
  223. unsigned long irq_flags;
  224. int gfp = GFP_KERNEL;
  225. int ret = 0;
  226. if (!priv)
  227. return -ENODEV;
  228. icnss_pr_dbg("Posting event: %s(%d), %s, flags: 0x%x, state: 0x%lx\n",
  229. icnss_driver_event_to_str(type), type, current->comm,
  230. flags, priv->state);
  231. if (type >= ICNSS_DRIVER_EVENT_MAX) {
  232. icnss_pr_err("Invalid Event type: %d, can't post", type);
  233. return -EINVAL;
  234. }
  235. if (in_interrupt() || irqs_disabled())
  236. gfp = GFP_ATOMIC;
  237. event = kzalloc(sizeof(*event), gfp);
  238. if (event == NULL)
  239. return -ENOMEM;
  240. icnss_pm_stay_awake(priv);
  241. event->type = type;
  242. event->data = data;
  243. init_completion(&event->complete);
  244. event->ret = ICNSS_EVENT_PENDING;
  245. event->sync = !!(flags & ICNSS_EVENT_SYNC);
  246. spin_lock_irqsave(&priv->event_lock, irq_flags);
  247. list_add_tail(&event->list, &priv->event_list);
  248. spin_unlock_irqrestore(&priv->event_lock, irq_flags);
  249. priv->stats.events[type].posted++;
  250. queue_work(priv->event_wq, &priv->event_work);
  251. if (!(flags & ICNSS_EVENT_SYNC))
  252. goto out;
  253. if (flags & ICNSS_EVENT_UNINTERRUPTIBLE)
  254. wait_for_completion(&event->complete);
  255. else
  256. ret = wait_for_completion_interruptible(&event->complete);
  257. icnss_pr_dbg("Completed event: %s(%d), state: 0x%lx, ret: %d/%d\n",
  258. icnss_driver_event_to_str(type), type, priv->state, ret,
  259. event->ret);
  260. spin_lock_irqsave(&priv->event_lock, irq_flags);
  261. if (ret == -ERESTARTSYS && event->ret == ICNSS_EVENT_PENDING) {
  262. event->sync = false;
  263. spin_unlock_irqrestore(&priv->event_lock, irq_flags);
  264. ret = -EINTR;
  265. goto out;
  266. }
  267. spin_unlock_irqrestore(&priv->event_lock, irq_flags);
  268. ret = event->ret;
  269. kfree(event);
  270. out:
  271. icnss_pm_relax(priv);
  272. return ret;
  273. }
  274. int icnss_soc_wake_event_post(struct icnss_priv *priv,
  275. enum icnss_soc_wake_event_type type,
  276. u32 flags, void *data)
  277. {
  278. struct icnss_soc_wake_event *event;
  279. unsigned long irq_flags;
  280. int gfp = GFP_KERNEL;
  281. int ret = 0;
  282. if (!priv)
  283. return -ENODEV;
  284. icnss_pr_soc_wake("Posting event: %s(%d), %s, flags: 0x%x, state: 0x%lx\n",
  285. icnss_soc_wake_event_to_str(type),
  286. type, current->comm, flags, priv->state);
  287. if (type >= ICNSS_SOC_WAKE_EVENT_MAX) {
  288. icnss_pr_err("Invalid Event type: %d, can't post", type);
  289. return -EINVAL;
  290. }
  291. if (in_interrupt() || irqs_disabled())
  292. gfp = GFP_ATOMIC;
  293. event = kzalloc(sizeof(*event), gfp);
  294. if (!event)
  295. return -ENOMEM;
  296. icnss_pm_stay_awake(priv);
  297. event->type = type;
  298. event->data = data;
  299. init_completion(&event->complete);
  300. event->ret = ICNSS_EVENT_PENDING;
  301. event->sync = !!(flags & ICNSS_EVENT_SYNC);
  302. spin_lock_irqsave(&priv->soc_wake_msg_lock, irq_flags);
  303. list_add_tail(&event->list, &priv->soc_wake_msg_list);
  304. spin_unlock_irqrestore(&priv->soc_wake_msg_lock, irq_flags);
  305. priv->stats.soc_wake_events[type].posted++;
  306. queue_work(priv->soc_wake_wq, &priv->soc_wake_msg_work);
  307. if (!(flags & ICNSS_EVENT_SYNC))
  308. goto out;
  309. if (flags & ICNSS_EVENT_UNINTERRUPTIBLE)
  310. wait_for_completion(&event->complete);
  311. else
  312. ret = wait_for_completion_interruptible(&event->complete);
  313. icnss_pr_soc_wake("Completed event: %s(%d), state: 0x%lx, ret: %d/%d\n",
  314. icnss_soc_wake_event_to_str(type),
  315. type, priv->state, ret, event->ret);
  316. spin_lock_irqsave(&priv->soc_wake_msg_lock, irq_flags);
  317. if (ret == -ERESTARTSYS && event->ret == ICNSS_EVENT_PENDING) {
  318. event->sync = false;
  319. spin_unlock_irqrestore(&priv->soc_wake_msg_lock, irq_flags);
  320. ret = -EINTR;
  321. goto out;
  322. }
  323. spin_unlock_irqrestore(&priv->soc_wake_msg_lock, irq_flags);
  324. ret = event->ret;
  325. kfree(event);
  326. out:
  327. icnss_pm_relax(priv);
  328. return ret;
  329. }
  330. bool icnss_is_fw_ready(void)
  331. {
  332. if (!penv)
  333. return false;
  334. else
  335. return test_bit(ICNSS_FW_READY, &penv->state);
  336. }
  337. EXPORT_SYMBOL(icnss_is_fw_ready);
  338. void icnss_block_shutdown(bool status)
  339. {
  340. if (!penv)
  341. return;
  342. if (status) {
  343. set_bit(ICNSS_BLOCK_SHUTDOWN, &penv->state);
  344. reinit_completion(&penv->unblock_shutdown);
  345. } else {
  346. clear_bit(ICNSS_BLOCK_SHUTDOWN, &penv->state);
  347. complete(&penv->unblock_shutdown);
  348. }
  349. }
  350. EXPORT_SYMBOL(icnss_block_shutdown);
  351. bool icnss_is_fw_down(void)
  352. {
  353. struct icnss_priv *priv = icnss_get_plat_priv();
  354. if (!priv)
  355. return false;
  356. return test_bit(ICNSS_FW_DOWN, &priv->state) ||
  357. test_bit(ICNSS_PD_RESTART, &priv->state) ||
  358. test_bit(ICNSS_REJUVENATE, &priv->state);
  359. }
  360. EXPORT_SYMBOL(icnss_is_fw_down);
  361. unsigned long icnss_get_device_config(void)
  362. {
  363. struct icnss_priv *priv = icnss_get_plat_priv();
  364. if (!priv)
  365. return 0;
  366. return priv->device_config;
  367. }
  368. EXPORT_SYMBOL(icnss_get_device_config);
  369. bool icnss_is_rejuvenate(void)
  370. {
  371. if (!penv)
  372. return false;
  373. else
  374. return test_bit(ICNSS_REJUVENATE, &penv->state);
  375. }
  376. EXPORT_SYMBOL(icnss_is_rejuvenate);
  377. bool icnss_is_pdr(void)
  378. {
  379. if (!penv)
  380. return false;
  381. else
  382. return test_bit(ICNSS_PDR, &penv->state);
  383. }
  384. EXPORT_SYMBOL(icnss_is_pdr);
  385. static int icnss_send_smp2p(struct icnss_priv *priv,
  386. enum icnss_smp2p_msg_id msg_id,
  387. enum smp2p_out_entry smp2p_entry)
  388. {
  389. unsigned int value = 0;
  390. int ret;
  391. if (!priv || IS_ERR(priv->smp2p_info[smp2p_entry].smem_state))
  392. return -EINVAL;
  393. /* No Need to check FW_DOWN for ICNSS_RESET_MSG */
  394. if (msg_id == ICNSS_RESET_MSG) {
  395. priv->smp2p_info[smp2p_entry].seq = 0;
  396. ret = qcom_smem_state_update_bits(
  397. priv->smp2p_info[smp2p_entry].smem_state,
  398. ICNSS_SMEM_VALUE_MASK,
  399. 0);
  400. if (ret)
  401. icnss_pr_err("Error in SMP2P sent. ret: %d, %s\n",
  402. ret, icnss_smp2p_str[smp2p_entry]);
  403. return ret;
  404. }
  405. if (test_bit(ICNSS_FW_DOWN, &priv->state) ||
  406. !test_bit(ICNSS_FW_READY, &priv->state)) {
  407. icnss_pr_smp2p("FW down, ignoring sending SMP2P state: 0x%lx\n",
  408. priv->state);
  409. return -EINVAL;
  410. }
  411. value |= priv->smp2p_info[smp2p_entry].seq++;
  412. value <<= ICNSS_SMEM_SEQ_NO_POS;
  413. value |= msg_id;
  414. icnss_pr_smp2p("Sending SMP2P value: 0x%X\n", value);
  415. if (msg_id == ICNSS_SOC_WAKE_REQ || msg_id == ICNSS_SOC_WAKE_REL)
  416. reinit_completion(&penv->smp2p_soc_wake_wait);
  417. ret = qcom_smem_state_update_bits(
  418. priv->smp2p_info[smp2p_entry].smem_state,
  419. ICNSS_SMEM_VALUE_MASK,
  420. value);
  421. if (ret) {
  422. icnss_pr_smp2p("Error in SMP2P send ret: %d, %s\n", ret,
  423. icnss_smp2p_str[smp2p_entry]);
  424. } else {
  425. if (msg_id == ICNSS_SOC_WAKE_REQ ||
  426. msg_id == ICNSS_SOC_WAKE_REL) {
  427. if (!wait_for_completion_timeout(
  428. &priv->smp2p_soc_wake_wait,
  429. msecs_to_jiffies(SMP2P_SOC_WAKE_TIMEOUT))) {
  430. icnss_pr_err("SMP2P Soc Wake timeout msg %d, %s\n", msg_id,
  431. icnss_smp2p_str[smp2p_entry]);
  432. if (!test_bit(ICNSS_FW_DOWN, &priv->state))
  433. ICNSS_ASSERT(0);
  434. }
  435. }
  436. }
  437. return ret;
  438. }
  439. bool icnss_is_low_power(void)
  440. {
  441. if (!penv)
  442. return false;
  443. else
  444. return test_bit(ICNSS_LOW_POWER, &penv->state);
  445. }
  446. EXPORT_SYMBOL(icnss_is_low_power);
  447. static irqreturn_t fw_error_fatal_handler(int irq, void *ctx)
  448. {
  449. struct icnss_priv *priv = ctx;
  450. if (priv)
  451. priv->force_err_fatal = true;
  452. icnss_pr_err("Received force error fatal request from FW\n");
  453. return IRQ_HANDLED;
  454. }
  455. static irqreturn_t fw_crash_indication_handler(int irq, void *ctx)
  456. {
  457. struct icnss_priv *priv = ctx;
  458. struct icnss_uevent_fw_down_data fw_down_data = {0};
  459. icnss_pr_err("Received early crash indication from FW\n");
  460. if (priv) {
  461. if (priv->wpss_self_recovery_enabled)
  462. mod_timer(&priv->wpss_ssr_timer,
  463. jiffies + msecs_to_jiffies(ICNSS_WPSS_SSR_TIMEOUT));
  464. set_bit(ICNSS_FW_DOWN, &priv->state);
  465. icnss_ignore_fw_timeout(true);
  466. if (test_bit(ICNSS_FW_READY, &priv->state)) {
  467. clear_bit(ICNSS_FW_READY, &priv->state);
  468. fw_down_data.crashed = true;
  469. icnss_call_driver_uevent(priv, ICNSS_UEVENT_FW_DOWN,
  470. &fw_down_data);
  471. }
  472. }
  473. icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_FW_EARLY_CRASH_IND,
  474. 0, NULL);
  475. return IRQ_HANDLED;
  476. }
  477. static void register_fw_error_notifications(struct device *dev)
  478. {
  479. struct icnss_priv *priv = dev_get_drvdata(dev);
  480. struct device_node *dev_node;
  481. int irq = 0, ret = 0;
  482. if (!priv)
  483. return;
  484. dev_node = of_find_node_by_name(NULL, "qcom,smp2p_map_wlan_1_in");
  485. if (!dev_node) {
  486. icnss_pr_err("Failed to get smp2p node for force-fatal-error\n");
  487. return;
  488. }
  489. icnss_pr_dbg("smp2p node->name=%s\n", dev_node->name);
  490. if (strcmp("qcom,smp2p_map_wlan_1_in", dev_node->name) == 0) {
  491. ret = irq = of_irq_get_byname(dev_node,
  492. "qcom,smp2p-force-fatal-error");
  493. if (ret < 0) {
  494. icnss_pr_err("Unable to get force-fatal-error irq %d\n",
  495. irq);
  496. return;
  497. }
  498. }
  499. ret = devm_request_threaded_irq(dev, irq, NULL, fw_error_fatal_handler,
  500. IRQF_ONESHOT | IRQF_TRIGGER_RISING,
  501. "wlanfw-err", priv);
  502. if (ret < 0) {
  503. icnss_pr_err("Unable to register for error fatal IRQ handler %d ret = %d",
  504. irq, ret);
  505. return;
  506. }
  507. icnss_pr_dbg("FW force error fatal handler registered irq = %d\n", irq);
  508. priv->fw_error_fatal_irq = irq;
  509. }
  510. static void register_early_crash_notifications(struct device *dev)
  511. {
  512. struct icnss_priv *priv = dev_get_drvdata(dev);
  513. struct device_node *dev_node;
  514. int irq = 0, ret = 0;
  515. if (!priv)
  516. return;
  517. dev_node = of_find_node_by_name(NULL, "qcom,smp2p_map_wlan_1_in");
  518. if (!dev_node) {
  519. icnss_pr_err("Failed to get smp2p node for early-crash-ind\n");
  520. return;
  521. }
  522. icnss_pr_dbg("smp2p node->name=%s\n", dev_node->name);
  523. if (strcmp("qcom,smp2p_map_wlan_1_in", dev_node->name) == 0) {
  524. ret = irq = of_irq_get_byname(dev_node,
  525. "qcom,smp2p-early-crash-ind");
  526. if (ret < 0) {
  527. icnss_pr_err("Unable to get early-crash-ind irq %d\n",
  528. irq);
  529. return;
  530. }
  531. }
  532. ret = devm_request_threaded_irq(dev, irq, NULL,
  533. fw_crash_indication_handler,
  534. IRQF_ONESHOT | IRQF_TRIGGER_RISING,
  535. "wlanfw-early-crash-ind", priv);
  536. if (ret < 0) {
  537. icnss_pr_err("Unable to register for early crash indication IRQ handler %d ret = %d",
  538. irq, ret);
  539. return;
  540. }
  541. icnss_pr_dbg("FW crash indication handler registered irq = %d\n", irq);
  542. priv->fw_early_crash_irq = irq;
  543. }
  544. static int icnss_get_temperature(struct icnss_priv *priv, int *temp)
  545. {
  546. struct thermal_zone_device *thermal_dev;
  547. const char *tsens;
  548. int ret;
  549. ret = of_property_read_string(priv->pdev->dev.of_node,
  550. "tsens",
  551. &tsens);
  552. if (ret)
  553. return ret;
  554. icnss_pr_dbg("Thermal Sensor is %s\n", tsens);
  555. thermal_dev = thermal_zone_get_zone_by_name(tsens);
  556. if (IS_ERR(thermal_dev)) {
  557. icnss_pr_err("Fail to get thermal zone. ret: %d",
  558. PTR_ERR(thermal_dev));
  559. return PTR_ERR(thermal_dev);
  560. }
  561. ret = thermal_zone_get_temp(thermal_dev, temp);
  562. if (ret)
  563. icnss_pr_err("Fail to get temperature. ret: %d", ret);
  564. return ret;
  565. }
  566. static irqreturn_t fw_soc_wake_ack_handler(int irq, void *ctx)
  567. {
  568. struct icnss_priv *priv = ctx;
  569. if (priv)
  570. complete(&priv->smp2p_soc_wake_wait);
  571. return IRQ_HANDLED;
  572. }
  573. static void register_soc_wake_notif(struct device *dev)
  574. {
  575. struct icnss_priv *priv = dev_get_drvdata(dev);
  576. struct device_node *dev_node;
  577. int irq = 0, ret = 0;
  578. if (!priv)
  579. return;
  580. dev_node = of_find_node_by_name(NULL, "qcom,smp2p_map_wlan_2_in");
  581. if (!dev_node) {
  582. icnss_pr_err("Failed to get smp2p node for soc-wake-ack\n");
  583. return;
  584. }
  585. icnss_pr_dbg("smp2p node->name=%s\n", dev_node->name);
  586. if (strcmp("qcom,smp2p_map_wlan_2_in", dev_node->name) == 0) {
  587. ret = irq = of_irq_get_byname(dev_node,
  588. "qcom,smp2p-soc-wake-ack");
  589. if (ret < 0) {
  590. icnss_pr_err("Unable to get soc wake ack irq %d\n",
  591. irq);
  592. return;
  593. }
  594. }
  595. ret = devm_request_threaded_irq(dev, irq, NULL,
  596. fw_soc_wake_ack_handler,
  597. IRQF_ONESHOT | IRQF_TRIGGER_RISING |
  598. IRQF_TRIGGER_FALLING,
  599. "wlanfw-soc-wake-ack", priv);
  600. if (ret < 0) {
  601. icnss_pr_err("Unable to register for SOC Wake ACK IRQ handler %d ret = %d",
  602. irq, ret);
  603. return;
  604. }
  605. icnss_pr_dbg("FW SOC Wake ACK handler registered irq = %d\n", irq);
  606. priv->fw_soc_wake_ack_irq = irq;
  607. }
  608. int icnss_call_driver_uevent(struct icnss_priv *priv,
  609. enum icnss_uevent uevent, void *data)
  610. {
  611. struct icnss_uevent_data uevent_data;
  612. if (!priv->ops || !priv->ops->uevent)
  613. return 0;
  614. icnss_pr_dbg("Calling driver uevent state: 0x%lx, uevent: %d\n",
  615. priv->state, uevent);
  616. uevent_data.uevent = uevent;
  617. uevent_data.data = data;
  618. return priv->ops->uevent(&priv->pdev->dev, &uevent_data);
  619. }
  620. static int icnss_setup_dms_mac(struct icnss_priv *priv)
  621. {
  622. int i;
  623. int ret = 0;
  624. ret = icnss_qmi_get_dms_mac(priv);
  625. if (ret == 0 && priv->dms.mac_valid)
  626. goto qmi_send;
  627. /* DTSI property use-nv-mac is used to force DMS MAC address for WLAN.
  628. * Thus assert on failure to get MAC from DMS even after retries
  629. */
  630. if (priv->use_nv_mac) {
  631. for (i = 0; i < ICNSS_DMS_QMI_CONNECTION_WAIT_RETRY; i++) {
  632. if (priv->dms.mac_valid)
  633. break;
  634. ret = icnss_qmi_get_dms_mac(priv);
  635. if (ret != -EAGAIN)
  636. break;
  637. msleep(ICNSS_DMS_QMI_CONNECTION_WAIT_MS);
  638. }
  639. if (!priv->dms.nv_mac_not_prov && !priv->dms.mac_valid) {
  640. icnss_pr_err("Unable to get MAC from DMS after retries\n");
  641. ICNSS_ASSERT(0);
  642. return -EINVAL;
  643. }
  644. }
  645. qmi_send:
  646. if (priv->dms.mac_valid)
  647. ret =
  648. icnss_wlfw_wlan_mac_req_send_sync(priv, priv->dms.mac,
  649. ARRAY_SIZE(priv->dms.mac));
  650. return ret;
  651. }
  652. static void icnss_get_smp2p_info(struct icnss_priv *priv,
  653. enum smp2p_out_entry smp2p_entry)
  654. {
  655. int retry = 0;
  656. int error;
  657. if (priv->smp2p_info[smp2p_entry].smem_state)
  658. return;
  659. retry:
  660. priv->smp2p_info[smp2p_entry].smem_state =
  661. qcom_smem_state_get(&priv->pdev->dev,
  662. icnss_smp2p_str[smp2p_entry],
  663. &priv->smp2p_info[smp2p_entry].smem_bit);
  664. if (IS_ERR(priv->smp2p_info[smp2p_entry].smem_state)) {
  665. if (retry++ < SMP2P_GET_MAX_RETRY) {
  666. error = PTR_ERR(priv->smp2p_info[smp2p_entry].smem_state);
  667. icnss_pr_err("Failed to get smem state, ret: %d Entry: %s",
  668. error, icnss_smp2p_str[smp2p_entry]);
  669. msleep(SMP2P_GET_RETRY_DELAY_MS);
  670. goto retry;
  671. }
  672. ICNSS_ASSERT(0);
  673. return;
  674. }
  675. icnss_pr_dbg("smem state, Entry: %s", icnss_smp2p_str[smp2p_entry]);
  676. }
  677. static inline
  678. void icnss_set_wlan_en_delay(struct icnss_priv *priv)
  679. {
  680. if (priv->wlan_en_delay_ms_user > WLAN_EN_DELAY) {
  681. priv->wlan_en_delay_ms = priv->wlan_en_delay_ms_user;
  682. } else {
  683. priv->wlan_en_delay_ms = WLAN_EN_DELAY;
  684. }
  685. }
  686. static enum wlfw_wlan_rf_subtype_v01 icnss_rf_subtype_value_to_type(u32 val)
  687. {
  688. switch (val) {
  689. case WLAN_RF_SLATE:
  690. return WLFW_WLAN_RF_SLATE_V01;
  691. case WLAN_RF_APACHE:
  692. return WLFW_WLAN_RF_APACHE_V01;
  693. default:
  694. return WLFW_WLAN_RF_SUBTYPE_MAX_VAL_V01;
  695. }
  696. }
  697. #ifdef SLATE_MODULE_ENABLED
  698. static void icnss_send_wlan_boot_init(void)
  699. {
  700. send_wlan_state(GMI_MGR_WLAN_BOOT_INIT);
  701. icnss_pr_info("sent wlan boot init command\n");
  702. }
  703. static void icnss_send_wlan_boot_complete(void)
  704. {
  705. send_wlan_state(GMI_MGR_WLAN_BOOT_COMPLETE);
  706. icnss_pr_info("sent wlan boot complete command\n");
  707. }
  708. static void icnss_wait_for_slate_complete(struct icnss_priv *priv)
  709. {
  710. if (!test_bit(ICNSS_SLATE_UP, &priv->state)) {
  711. reinit_completion(&priv->slate_boot_complete);
  712. icnss_pr_err("Waiting for slate boot up notification, 0x%lx\n",
  713. priv->state);
  714. wait_for_completion(&priv->slate_boot_complete);
  715. }
  716. icnss_send_wlan_boot_init();
  717. }
  718. #else
  719. static void icnss_send_wlan_boot_complete(void)
  720. {
  721. }
  722. static void icnss_wait_for_slate_complete(struct icnss_priv *priv)
  723. {
  724. }
  725. #endif
  726. static int icnss_driver_event_server_arrive(struct icnss_priv *priv,
  727. void *data)
  728. {
  729. int ret = 0;
  730. int temp = 0;
  731. bool ignore_assert = false;
  732. enum wlfw_wlan_rf_subtype_v01 rf_subtype;
  733. if (!priv)
  734. return -ENODEV;
  735. set_bit(ICNSS_WLFW_EXISTS, &priv->state);
  736. clear_bit(ICNSS_FW_DOWN, &priv->state);
  737. clear_bit(ICNSS_FW_READY, &priv->state);
  738. icnss_ignore_fw_timeout(false);
  739. if (test_bit(ICNSS_WLFW_CONNECTED, &priv->state)) {
  740. icnss_pr_err("QMI Server already in Connected State\n");
  741. ICNSS_ASSERT(0);
  742. }
  743. ret = icnss_connect_to_fw_server(priv, data);
  744. if (ret)
  745. goto fail;
  746. set_bit(ICNSS_WLFW_CONNECTED, &priv->state);
  747. if (priv->is_slate_rfa)
  748. icnss_wait_for_slate_complete(priv);
  749. ret = wlfw_ind_register_send_sync_msg(priv);
  750. if (ret < 0) {
  751. if (ret == -EALREADY) {
  752. ret = 0;
  753. goto qmi_registered;
  754. }
  755. ignore_assert = true;
  756. goto fail;
  757. }
  758. if (priv->is_rf_subtype_valid) {
  759. rf_subtype = icnss_rf_subtype_value_to_type(priv->rf_subtype);
  760. if (rf_subtype != WLFW_WLAN_RF_SUBTYPE_MAX_VAL_V01) {
  761. ret = wlfw_wlan_hw_init_cfg_msg(priv, rf_subtype);
  762. if (ret < 0)
  763. icnss_pr_dbg("Sending rf_subtype failed ret %d\n",
  764. ret);
  765. } else {
  766. icnss_pr_dbg("Invalid rf subtype %d in DT\n",
  767. priv->rf_subtype);
  768. }
  769. }
  770. if (priv->device_id == WCN6750_DEVICE_ID ||
  771. priv->device_id == WCN6450_DEVICE_ID) {
  772. if (!icnss_get_temperature(priv, &temp)) {
  773. icnss_pr_dbg("Temperature: %d\n", temp);
  774. if (temp < WLAN_EN_TEMP_THRESHOLD)
  775. icnss_set_wlan_en_delay(priv);
  776. }
  777. ret = wlfw_host_cap_send_sync(priv);
  778. if (ret < 0)
  779. goto fail;
  780. }
  781. if (priv->device_id == ADRASTEA_DEVICE_ID) {
  782. if (!priv->msa_va) {
  783. icnss_pr_err("Invalid MSA address\n");
  784. ret = -EINVAL;
  785. goto fail;
  786. }
  787. ret = wlfw_msa_mem_info_send_sync_msg(priv);
  788. if (ret < 0) {
  789. ignore_assert = true;
  790. goto fail;
  791. }
  792. ret = wlfw_msa_ready_send_sync_msg(priv);
  793. if (ret < 0) {
  794. ignore_assert = true;
  795. goto fail;
  796. }
  797. }
  798. if (priv->device_id == WCN6450_DEVICE_ID)
  799. icnss_hw_power_off(priv);
  800. ret = wlfw_cap_send_sync_msg(priv);
  801. if (ret < 0) {
  802. ignore_assert = true;
  803. goto fail;
  804. }
  805. ret = icnss_hw_power_on(priv);
  806. if (ret)
  807. goto fail;
  808. if (priv->device_id == WCN6750_DEVICE_ID ||
  809. priv->device_id == WCN6450_DEVICE_ID) {
  810. ret = wlfw_device_info_send_msg(priv);
  811. if (ret < 0) {
  812. ignore_assert = true;
  813. goto device_info_failure;
  814. }
  815. priv->mem_base_va = devm_ioremap(&priv->pdev->dev,
  816. priv->mem_base_pa,
  817. priv->mem_base_size);
  818. if (!priv->mem_base_va) {
  819. icnss_pr_err("Ioremap failed for bar address\n");
  820. goto device_info_failure;
  821. }
  822. icnss_pr_dbg("Non-Secured Bar Address pa: %pa, va: 0x%pK\n",
  823. &priv->mem_base_pa,
  824. priv->mem_base_va);
  825. if (priv->mhi_state_info_pa)
  826. priv->mhi_state_info_va = devm_ioremap(&priv->pdev->dev,
  827. priv->mhi_state_info_pa,
  828. PAGE_SIZE);
  829. if (!priv->mhi_state_info_va)
  830. icnss_pr_err("Ioremap failed for MHI info address\n");
  831. icnss_pr_dbg("MHI state info Address pa: %pa, va: 0x%pK\n",
  832. &priv->mhi_state_info_pa,
  833. priv->mhi_state_info_va);
  834. }
  835. if (priv->bdf_download_support) {
  836. icnss_wlfw_bdf_dnld_send_sync(priv, ICNSS_BDF_REGDB);
  837. ret = icnss_wlfw_bdf_dnld_send_sync(priv,
  838. priv->ctrl_params.bdf_type);
  839. if (ret < 0)
  840. goto device_info_failure;
  841. }
  842. if (priv->device_id == WCN6450_DEVICE_ID) {
  843. ret = icnss_wlfw_qdss_dnld_send_sync(priv);
  844. if (ret < 0)
  845. icnss_pr_info("Failed to download qdss config file for WCN6450, ret = %d\n",
  846. ret);
  847. }
  848. if (priv->device_id == WCN6750_DEVICE_ID ||
  849. priv->device_id == WCN6450_DEVICE_ID) {
  850. if (!priv->fw_soc_wake_ack_irq)
  851. register_soc_wake_notif(&priv->pdev->dev);
  852. icnss_get_smp2p_info(priv, ICNSS_SMP2P_OUT_SOC_WAKE);
  853. icnss_get_smp2p_info(priv, ICNSS_SMP2P_OUT_EP_POWER_SAVE);
  854. }
  855. if (priv->wpss_supported)
  856. icnss_get_smp2p_info(priv, ICNSS_SMP2P_OUT_POWER_SAVE);
  857. if (priv->device_id == ADRASTEA_DEVICE_ID) {
  858. if (priv->bdf_download_support) {
  859. ret = wlfw_cal_report_req(priv);
  860. if (ret < 0)
  861. goto device_info_failure;
  862. }
  863. wlfw_dynamic_feature_mask_send_sync_msg(priv,
  864. dynamic_feature_mask);
  865. }
  866. if (!priv->fw_error_fatal_irq)
  867. register_fw_error_notifications(&priv->pdev->dev);
  868. if (!priv->fw_early_crash_irq)
  869. register_early_crash_notifications(&priv->pdev->dev);
  870. if (priv->psf_supported)
  871. queue_work(priv->soc_update_wq, &priv->soc_update_work);
  872. return ret;
  873. device_info_failure:
  874. icnss_hw_power_off(priv);
  875. fail:
  876. ICNSS_ASSERT(ignore_assert);
  877. qmi_registered:
  878. return ret;
  879. }
  880. static int icnss_driver_event_server_exit(struct icnss_priv *priv)
  881. {
  882. if (!priv)
  883. return -ENODEV;
  884. icnss_pr_info("WLAN FW Service Disconnected: 0x%lx\n", priv->state);
  885. icnss_clear_server(priv);
  886. if (priv->psf_supported)
  887. priv->last_updated_voltage = 0;
  888. return 0;
  889. }
  890. static int icnss_call_driver_probe(struct icnss_priv *priv)
  891. {
  892. int ret = 0;
  893. int probe_cnt = 0;
  894. if (!priv->ops || !priv->ops->probe)
  895. return 0;
  896. if (test_bit(ICNSS_DRIVER_PROBED, &priv->state))
  897. return -EINVAL;
  898. icnss_pr_dbg("Calling driver probe state: 0x%lx\n", priv->state);
  899. icnss_hw_power_on(priv);
  900. icnss_block_shutdown(true);
  901. while (probe_cnt < ICNSS_MAX_PROBE_CNT) {
  902. ret = priv->ops->probe(&priv->pdev->dev);
  903. probe_cnt++;
  904. if (ret != -EPROBE_DEFER)
  905. break;
  906. }
  907. if (ret < 0) {
  908. icnss_pr_err("Driver probe failed: %d, state: 0x%lx, probe_cnt: %d\n",
  909. ret, priv->state, probe_cnt);
  910. icnss_block_shutdown(false);
  911. goto out;
  912. }
  913. icnss_block_shutdown(false);
  914. set_bit(ICNSS_DRIVER_PROBED, &priv->state);
  915. return 0;
  916. out:
  917. icnss_hw_power_off(priv);
  918. return ret;
  919. }
  920. static int icnss_call_driver_shutdown(struct icnss_priv *priv)
  921. {
  922. if (!test_bit(ICNSS_DRIVER_PROBED, &priv->state))
  923. goto out;
  924. if (!priv->ops || !priv->ops->shutdown)
  925. goto out;
  926. if (test_bit(ICNSS_SHUTDOWN_DONE, &priv->state))
  927. goto out;
  928. icnss_pr_dbg("Calling driver shutdown state: 0x%lx\n", priv->state);
  929. priv->ops->shutdown(&priv->pdev->dev);
  930. set_bit(ICNSS_SHUTDOWN_DONE, &priv->state);
  931. out:
  932. return 0;
  933. }
  934. static int icnss_pd_restart_complete(struct icnss_priv *priv)
  935. {
  936. int ret = 0;
  937. icnss_pm_relax(priv);
  938. icnss_call_driver_shutdown(priv);
  939. clear_bit(ICNSS_PDR, &priv->state);
  940. clear_bit(ICNSS_REJUVENATE, &priv->state);
  941. clear_bit(ICNSS_PD_RESTART, &priv->state);
  942. clear_bit(ICNSS_LOW_POWER, &priv->state);
  943. priv->early_crash_ind = false;
  944. priv->is_ssr = false;
  945. if (!priv->ops || !priv->ops->reinit)
  946. goto out;
  947. if (test_bit(ICNSS_FW_DOWN, &priv->state)) {
  948. icnss_pr_err("FW is in bad state, state: 0x%lx\n",
  949. priv->state);
  950. goto out;
  951. }
  952. if (!test_bit(ICNSS_DRIVER_PROBED, &priv->state))
  953. goto call_probe;
  954. icnss_pr_dbg("Calling driver reinit state: 0x%lx\n", priv->state);
  955. icnss_hw_power_on(priv);
  956. icnss_block_shutdown(true);
  957. ret = priv->ops->reinit(&priv->pdev->dev);
  958. if (ret < 0) {
  959. icnss_fatal_err("Driver reinit failed: %d, state: 0x%lx\n",
  960. ret, priv->state);
  961. if (!priv->allow_recursive_recovery)
  962. ICNSS_ASSERT(false);
  963. icnss_block_shutdown(false);
  964. goto out_power_off;
  965. }
  966. icnss_block_shutdown(false);
  967. clear_bit(ICNSS_SHUTDOWN_DONE, &priv->state);
  968. return 0;
  969. call_probe:
  970. return icnss_call_driver_probe(priv);
  971. out_power_off:
  972. icnss_hw_power_off(priv);
  973. out:
  974. return ret;
  975. }
  976. static int icnss_driver_event_fw_ready_ind(struct icnss_priv *priv, void *data)
  977. {
  978. int ret = 0;
  979. if (!priv)
  980. return -ENODEV;
  981. del_timer(&priv->recovery_timer);
  982. set_bit(ICNSS_FW_READY, &priv->state);
  983. clear_bit(ICNSS_MODE_ON, &priv->state);
  984. atomic_set(&priv->soc_wake_ref_count, 0);
  985. if (priv->device_id == WCN6750_DEVICE_ID ||
  986. priv->device_id == WCN6450_DEVICE_ID)
  987. icnss_free_qdss_mem(priv);
  988. icnss_pr_info("WLAN FW is ready: 0x%lx\n", priv->state);
  989. icnss_hw_power_off(priv);
  990. if (!priv->pdev) {
  991. icnss_pr_err("Device is not ready\n");
  992. ret = -ENODEV;
  993. goto out;
  994. }
  995. if (priv->is_slate_rfa && test_bit(ICNSS_SLATE_UP, &priv->state))
  996. icnss_send_wlan_boot_complete();
  997. if (test_bit(ICNSS_PD_RESTART, &priv->state)) {
  998. ret = icnss_pd_restart_complete(priv);
  999. } else {
  1000. if (priv->wpss_supported)
  1001. icnss_setup_dms_mac(priv);
  1002. ret = icnss_call_driver_probe(priv);
  1003. }
  1004. icnss_vreg_unvote(priv);
  1005. out:
  1006. return ret;
  1007. }
  1008. static int icnss_driver_event_fw_init_done(struct icnss_priv *priv, void *data)
  1009. {
  1010. int ret = 0;
  1011. if (!priv)
  1012. return -ENODEV;
  1013. icnss_pr_info("WLAN FW Initialization done: 0x%lx\n", priv->state);
  1014. if (priv->device_id == WCN6750_DEVICE_ID) {
  1015. ret = icnss_wlfw_qdss_dnld_send_sync(priv);
  1016. if (ret < 0)
  1017. icnss_pr_info("Failed to download qdss config file for WCN6750, ret = %d\n",
  1018. ret);
  1019. }
  1020. if (test_bit(ICNSS_COLD_BOOT_CAL, &priv->state)) {
  1021. mod_timer(&priv->recovery_timer,
  1022. jiffies + msecs_to_jiffies(ICNSS_CAL_TIMEOUT));
  1023. ret = wlfw_wlan_mode_send_sync_msg(priv,
  1024. (enum wlfw_driver_mode_enum_v01)ICNSS_CALIBRATION);
  1025. } else {
  1026. icnss_driver_event_fw_ready_ind(priv, NULL);
  1027. }
  1028. return ret;
  1029. }
  1030. int icnss_alloc_qdss_mem(struct icnss_priv *priv)
  1031. {
  1032. struct platform_device *pdev = priv->pdev;
  1033. struct icnss_fw_mem *qdss_mem = priv->qdss_mem;
  1034. int i, j;
  1035. for (i = 0; i < priv->qdss_mem_seg_len; i++) {
  1036. if (!qdss_mem[i].va && qdss_mem[i].size) {
  1037. qdss_mem[i].va =
  1038. dma_alloc_coherent(&pdev->dev,
  1039. qdss_mem[i].size,
  1040. &qdss_mem[i].pa,
  1041. GFP_KERNEL);
  1042. if (!qdss_mem[i].va) {
  1043. icnss_pr_err("Failed to allocate QDSS memory for FW, size: 0x%zx, type: %u, chuck-ID: %d\n",
  1044. qdss_mem[i].size,
  1045. qdss_mem[i].type, i);
  1046. break;
  1047. }
  1048. }
  1049. }
  1050. /* Best-effort allocation for QDSS trace */
  1051. if (i < priv->qdss_mem_seg_len) {
  1052. for (j = i; j < priv->qdss_mem_seg_len; j++) {
  1053. qdss_mem[j].type = 0;
  1054. qdss_mem[j].size = 0;
  1055. }
  1056. priv->qdss_mem_seg_len = i;
  1057. }
  1058. return 0;
  1059. }
  1060. void icnss_free_qdss_mem(struct icnss_priv *priv)
  1061. {
  1062. struct platform_device *pdev = priv->pdev;
  1063. struct icnss_fw_mem *qdss_mem = priv->qdss_mem;
  1064. int i;
  1065. for (i = 0; i < priv->qdss_mem_seg_len; i++) {
  1066. if (qdss_mem[i].va && qdss_mem[i].size) {
  1067. icnss_pr_dbg("Freeing memory for QDSS: pa: %pa, size: 0x%zx, type: %u\n",
  1068. &qdss_mem[i].pa, qdss_mem[i].size,
  1069. qdss_mem[i].type);
  1070. dma_free_coherent(&pdev->dev,
  1071. qdss_mem[i].size, qdss_mem[i].va,
  1072. qdss_mem[i].pa);
  1073. qdss_mem[i].va = NULL;
  1074. qdss_mem[i].pa = 0;
  1075. qdss_mem[i].size = 0;
  1076. qdss_mem[i].type = 0;
  1077. }
  1078. }
  1079. priv->qdss_mem_seg_len = 0;
  1080. }
  1081. static int icnss_qdss_trace_req_mem_hdlr(struct icnss_priv *priv)
  1082. {
  1083. int ret = 0;
  1084. ret = icnss_alloc_qdss_mem(priv);
  1085. if (ret < 0)
  1086. return ret;
  1087. return wlfw_qdss_trace_mem_info_send_sync(priv);
  1088. }
  1089. static void *icnss_qdss_trace_pa_to_va(struct icnss_priv *priv,
  1090. u64 pa, u32 size, int *seg_id)
  1091. {
  1092. int i = 0;
  1093. struct icnss_fw_mem *qdss_mem = priv->qdss_mem;
  1094. u64 offset = 0;
  1095. void *va = NULL;
  1096. u64 local_pa;
  1097. u32 local_size;
  1098. for (i = 0; i < priv->qdss_mem_seg_len; i++) {
  1099. local_pa = (u64)qdss_mem[i].pa;
  1100. local_size = (u32)qdss_mem[i].size;
  1101. if (pa == local_pa && size <= local_size) {
  1102. va = qdss_mem[i].va;
  1103. break;
  1104. }
  1105. if (pa > local_pa &&
  1106. pa < local_pa + local_size &&
  1107. pa + size <= local_pa + local_size) {
  1108. offset = pa - local_pa;
  1109. va = qdss_mem[i].va + offset;
  1110. break;
  1111. }
  1112. }
  1113. *seg_id = i;
  1114. return va;
  1115. }
  1116. static int icnss_qdss_trace_save_hdlr(struct icnss_priv *priv,
  1117. void *data)
  1118. {
  1119. struct icnss_qmi_event_qdss_trace_save_data *event_data = data;
  1120. struct icnss_fw_mem *qdss_mem = priv->qdss_mem;
  1121. int ret = 0;
  1122. int i;
  1123. void *va = NULL;
  1124. u64 pa;
  1125. u32 size;
  1126. int seg_id = 0;
  1127. if (!priv->qdss_mem_seg_len) {
  1128. icnss_pr_err("Memory for QDSS trace is not available\n");
  1129. return -ENOMEM;
  1130. }
  1131. if (event_data->mem_seg_len == 0) {
  1132. for (i = 0; i < priv->qdss_mem_seg_len; i++) {
  1133. ret = icnss_genl_send_msg(qdss_mem[i].va,
  1134. ICNSS_GENL_MSG_TYPE_QDSS,
  1135. event_data->file_name,
  1136. qdss_mem[i].size);
  1137. if (ret < 0) {
  1138. icnss_pr_err("Fail to save QDSS data: %d\n",
  1139. ret);
  1140. break;
  1141. }
  1142. }
  1143. } else {
  1144. for (i = 0; i < event_data->mem_seg_len; i++) {
  1145. pa = event_data->mem_seg[i].addr;
  1146. size = event_data->mem_seg[i].size;
  1147. va = icnss_qdss_trace_pa_to_va(priv, pa,
  1148. size, &seg_id);
  1149. if (!va) {
  1150. icnss_pr_err("Fail to find matching va for pa %pa\n",
  1151. &pa);
  1152. ret = -EINVAL;
  1153. break;
  1154. }
  1155. ret = icnss_genl_send_msg(va, ICNSS_GENL_MSG_TYPE_QDSS,
  1156. event_data->file_name, size);
  1157. if (ret < 0) {
  1158. icnss_pr_err("Fail to save QDSS data: %d\n",
  1159. ret);
  1160. break;
  1161. }
  1162. }
  1163. }
  1164. kfree(data);
  1165. return ret;
  1166. }
  1167. static inline int icnss_atomic_dec_if_greater_one(atomic_t *v)
  1168. {
  1169. int dec, c = atomic_read(v);
  1170. do {
  1171. dec = c - 1;
  1172. if (unlikely(dec < 1))
  1173. break;
  1174. } while (!atomic_try_cmpxchg(v, &c, dec));
  1175. return dec;
  1176. }
  1177. static int icnss_qdss_trace_req_data_hdlr(struct icnss_priv *priv,
  1178. void *data)
  1179. {
  1180. int ret = 0;
  1181. struct icnss_qmi_event_qdss_trace_save_data *event_data = data;
  1182. if (!priv)
  1183. return -ENODEV;
  1184. if (!data)
  1185. return -EINVAL;
  1186. ret = icnss_wlfw_qdss_data_send_sync(priv, event_data->file_name,
  1187. event_data->total_size);
  1188. kfree(data);
  1189. return ret;
  1190. }
  1191. static int icnss_event_soc_wake_request(struct icnss_priv *priv, void *data)
  1192. {
  1193. int ret = 0;
  1194. if (!priv)
  1195. return -ENODEV;
  1196. if (atomic_inc_not_zero(&priv->soc_wake_ref_count)) {
  1197. icnss_pr_soc_wake("SOC awake after posting work, Ref count: %d",
  1198. atomic_read(&priv->soc_wake_ref_count));
  1199. return 0;
  1200. }
  1201. ret = icnss_send_smp2p(priv, ICNSS_SOC_WAKE_REQ,
  1202. ICNSS_SMP2P_OUT_SOC_WAKE);
  1203. if (!ret)
  1204. atomic_inc(&priv->soc_wake_ref_count);
  1205. return ret;
  1206. }
  1207. static int icnss_event_soc_wake_release(struct icnss_priv *priv, void *data)
  1208. {
  1209. int ret = 0;
  1210. if (!priv)
  1211. return -ENODEV;
  1212. if (atomic_dec_if_positive(&priv->soc_wake_ref_count)) {
  1213. icnss_pr_soc_wake("Wake release not called. Ref count: %d",
  1214. priv->soc_wake_ref_count);
  1215. return 0;
  1216. }
  1217. ret = icnss_send_smp2p(priv, ICNSS_SOC_WAKE_REL,
  1218. ICNSS_SMP2P_OUT_SOC_WAKE);
  1219. return ret;
  1220. }
  1221. static int icnss_driver_event_register_driver(struct icnss_priv *priv,
  1222. void *data)
  1223. {
  1224. int ret = 0;
  1225. int probe_cnt = 0;
  1226. if (priv->ops)
  1227. return -EEXIST;
  1228. priv->ops = data;
  1229. if (test_bit(SKIP_QMI, &priv->ctrl_params.quirks))
  1230. set_bit(ICNSS_FW_READY, &priv->state);
  1231. if (test_bit(ICNSS_FW_DOWN, &priv->state)) {
  1232. icnss_pr_err("FW is in bad state, state: 0x%lx\n",
  1233. priv->state);
  1234. return -ENODEV;
  1235. }
  1236. if (!test_bit(ICNSS_FW_READY, &priv->state)) {
  1237. icnss_pr_dbg("FW is not ready yet, state: 0x%lx\n",
  1238. priv->state);
  1239. goto out;
  1240. }
  1241. ret = icnss_hw_power_on(priv);
  1242. if (ret)
  1243. goto out;
  1244. icnss_block_shutdown(true);
  1245. while (probe_cnt < ICNSS_MAX_PROBE_CNT) {
  1246. ret = priv->ops->probe(&priv->pdev->dev);
  1247. probe_cnt++;
  1248. if (ret != -EPROBE_DEFER)
  1249. break;
  1250. }
  1251. if (ret) {
  1252. icnss_pr_err("Driver probe failed: %d, state: 0x%lx, probe_cnt: %d\n",
  1253. ret, priv->state, probe_cnt);
  1254. icnss_block_shutdown(false);
  1255. goto power_off;
  1256. }
  1257. icnss_block_shutdown(false);
  1258. set_bit(ICNSS_DRIVER_PROBED, &priv->state);
  1259. return 0;
  1260. power_off:
  1261. icnss_hw_power_off(priv);
  1262. out:
  1263. return ret;
  1264. }
  1265. static int icnss_driver_event_unregister_driver(struct icnss_priv *priv,
  1266. void *data)
  1267. {
  1268. if (!test_bit(ICNSS_DRIVER_PROBED, &priv->state)) {
  1269. priv->ops = NULL;
  1270. goto out;
  1271. }
  1272. set_bit(ICNSS_DRIVER_UNLOADING, &priv->state);
  1273. icnss_block_shutdown(true);
  1274. if (priv->ops)
  1275. priv->ops->remove(&priv->pdev->dev);
  1276. icnss_block_shutdown(false);
  1277. clear_bit(ICNSS_DRIVER_UNLOADING, &priv->state);
  1278. clear_bit(ICNSS_DRIVER_PROBED, &priv->state);
  1279. priv->ops = NULL;
  1280. icnss_hw_power_off(priv);
  1281. out:
  1282. return 0;
  1283. }
  1284. static int icnss_fw_crashed(struct icnss_priv *priv,
  1285. struct icnss_event_pd_service_down_data *event_data)
  1286. {
  1287. icnss_pr_dbg("FW crashed, state: 0x%lx\n", priv->state);
  1288. set_bit(ICNSS_PD_RESTART, &priv->state);
  1289. clear_bit(ICNSS_FW_READY, &priv->state);
  1290. icnss_pm_stay_awake(priv);
  1291. if (test_bit(ICNSS_DRIVER_PROBED, &priv->state))
  1292. icnss_call_driver_uevent(priv, ICNSS_UEVENT_FW_CRASHED, NULL);
  1293. if (event_data && event_data->fw_rejuvenate)
  1294. wlfw_rejuvenate_ack_send_sync_msg(priv);
  1295. return 0;
  1296. }
  1297. int icnss_update_hang_event_data(struct icnss_priv *priv,
  1298. struct icnss_uevent_hang_data *hang_data)
  1299. {
  1300. if (!priv->hang_event_data_va)
  1301. return -EINVAL;
  1302. priv->hang_event_data = kmemdup(priv->hang_event_data_va,
  1303. priv->hang_event_data_len,
  1304. GFP_ATOMIC);
  1305. if (!priv->hang_event_data)
  1306. return -ENOMEM;
  1307. // Update the hang event params
  1308. hang_data->hang_event_data = priv->hang_event_data;
  1309. hang_data->hang_event_data_len = priv->hang_event_data_len;
  1310. return 0;
  1311. }
  1312. int icnss_send_hang_event_data(struct icnss_priv *priv)
  1313. {
  1314. struct icnss_uevent_hang_data hang_data = {0};
  1315. int ret = 0xFF;
  1316. if (priv->early_crash_ind) {
  1317. ret = icnss_update_hang_event_data(priv, &hang_data);
  1318. if (ret)
  1319. icnss_pr_err("Unable to allocate memory for Hang event data\n");
  1320. }
  1321. icnss_call_driver_uevent(priv, ICNSS_UEVENT_HANG_DATA,
  1322. &hang_data);
  1323. if (!ret) {
  1324. kfree(priv->hang_event_data);
  1325. priv->hang_event_data = NULL;
  1326. }
  1327. return 0;
  1328. }
  1329. static int icnss_driver_event_pd_service_down(struct icnss_priv *priv,
  1330. void *data)
  1331. {
  1332. struct icnss_event_pd_service_down_data *event_data = data;
  1333. if (!test_bit(ICNSS_WLFW_EXISTS, &priv->state)) {
  1334. icnss_ignore_fw_timeout(false);
  1335. goto out;
  1336. }
  1337. if (priv->force_err_fatal)
  1338. ICNSS_ASSERT(0);
  1339. if (priv->device_id == WCN6750_DEVICE_ID ||
  1340. priv->device_id == WCN6450_DEVICE_ID) {
  1341. icnss_send_smp2p(priv, ICNSS_RESET_MSG,
  1342. ICNSS_SMP2P_OUT_SOC_WAKE);
  1343. icnss_send_smp2p(priv, ICNSS_RESET_MSG,
  1344. ICNSS_SMP2P_OUT_EP_POWER_SAVE);
  1345. }
  1346. if (priv->wpss_supported)
  1347. icnss_send_smp2p(priv, ICNSS_RESET_MSG,
  1348. ICNSS_SMP2P_OUT_POWER_SAVE);
  1349. icnss_send_hang_event_data(priv);
  1350. if (priv->early_crash_ind) {
  1351. icnss_pr_dbg("PD Down ignored as early indication is processed: %d, state: 0x%lx\n",
  1352. event_data->crashed, priv->state);
  1353. goto out;
  1354. }
  1355. if (test_bit(ICNSS_PD_RESTART, &priv->state) && event_data->crashed) {
  1356. icnss_fatal_err("PD Down while recovery inprogress, crashed: %d, state: 0x%lx\n",
  1357. event_data->crashed, priv->state);
  1358. if (!priv->allow_recursive_recovery)
  1359. ICNSS_ASSERT(0);
  1360. goto out;
  1361. }
  1362. if (!test_bit(ICNSS_PD_RESTART, &priv->state))
  1363. icnss_fw_crashed(priv, event_data);
  1364. out:
  1365. kfree(data);
  1366. return 0;
  1367. }
  1368. static int icnss_driver_event_early_crash_ind(struct icnss_priv *priv,
  1369. void *data)
  1370. {
  1371. if (!test_bit(ICNSS_WLFW_EXISTS, &priv->state)) {
  1372. icnss_ignore_fw_timeout(false);
  1373. goto out;
  1374. }
  1375. priv->early_crash_ind = true;
  1376. icnss_fw_crashed(priv, NULL);
  1377. out:
  1378. kfree(data);
  1379. return 0;
  1380. }
  1381. static int icnss_driver_event_idle_shutdown(struct icnss_priv *priv,
  1382. void *data)
  1383. {
  1384. int ret = 0;
  1385. if (!priv->ops || !priv->ops->idle_shutdown)
  1386. return 0;
  1387. if (priv->is_ssr || test_bit(ICNSS_PDR, &priv->state) ||
  1388. test_bit(ICNSS_REJUVENATE, &priv->state)) {
  1389. icnss_pr_err("SSR/PDR is already in-progress during idle shutdown callback\n");
  1390. ret = -EBUSY;
  1391. } else {
  1392. icnss_pr_dbg("Calling driver idle shutdown, state: 0x%lx\n",
  1393. priv->state);
  1394. icnss_block_shutdown(true);
  1395. ret = priv->ops->idle_shutdown(&priv->pdev->dev);
  1396. icnss_block_shutdown(false);
  1397. }
  1398. return ret;
  1399. }
  1400. static int icnss_driver_event_idle_restart(struct icnss_priv *priv,
  1401. void *data)
  1402. {
  1403. int ret = 0;
  1404. if (!priv->ops || !priv->ops->idle_restart)
  1405. return 0;
  1406. if (priv->is_ssr || test_bit(ICNSS_PDR, &priv->state) ||
  1407. test_bit(ICNSS_REJUVENATE, &priv->state)) {
  1408. icnss_pr_err("SSR/PDR is already in-progress during idle restart callback\n");
  1409. ret = -EBUSY;
  1410. } else {
  1411. icnss_pr_dbg("Calling driver idle restart, state: 0x%lx\n",
  1412. priv->state);
  1413. icnss_block_shutdown(true);
  1414. ret = priv->ops->idle_restart(&priv->pdev->dev);
  1415. icnss_block_shutdown(false);
  1416. }
  1417. return ret;
  1418. }
  1419. static int icnss_qdss_trace_free_hdlr(struct icnss_priv *priv)
  1420. {
  1421. icnss_free_qdss_mem(priv);
  1422. return 0;
  1423. }
  1424. static int icnss_m3_dump_upload_req_hdlr(struct icnss_priv *priv,
  1425. void *data)
  1426. {
  1427. struct icnss_m3_upload_segments_req_data *event_data = data;
  1428. struct qcom_dump_segment segment;
  1429. int i, status = 0, ret = 0;
  1430. struct list_head head;
  1431. if (!dump_enabled()) {
  1432. icnss_pr_info("Dump collection is not enabled\n");
  1433. return ret;
  1434. }
  1435. if (IS_ERR_OR_NULL(priv->m3_dump_phyareg) ||
  1436. IS_ERR_OR_NULL(priv->m3_dump_phydbg) ||
  1437. IS_ERR_OR_NULL(priv->m3_dump_wmac0reg) ||
  1438. IS_ERR_OR_NULL(priv->m3_dump_wcssdbg) ||
  1439. IS_ERR_OR_NULL(priv->m3_dump_phyapdmem))
  1440. return ret;
  1441. INIT_LIST_HEAD(&head);
  1442. for (i = 0; i < event_data->no_of_valid_segments; i++) {
  1443. memset(&segment, 0, sizeof(segment));
  1444. segment.va = devm_ioremap(&priv->pdev->dev,
  1445. event_data->m3_segment[i].addr,
  1446. event_data->m3_segment[i].size);
  1447. if (!segment.va) {
  1448. icnss_pr_err("Failed to ioremap M3 Dump region");
  1449. ret = -ENOMEM;
  1450. goto send_resp;
  1451. }
  1452. segment.size = event_data->m3_segment[i].size;
  1453. list_add(&segment.node, &head);
  1454. icnss_pr_dbg("Started Dump colletcion for %s segment",
  1455. event_data->m3_segment[i].name);
  1456. switch (event_data->m3_segment[i].type) {
  1457. case QMI_M3_SEGMENT_PHYAREG_V01:
  1458. ret = qcom_dump(&head, priv->m3_dump_phyareg->dev);
  1459. break;
  1460. case QMI_M3_SEGMENT_PHYDBG_V01:
  1461. ret = qcom_dump(&head, priv->m3_dump_phydbg->dev);
  1462. break;
  1463. case QMI_M3_SEGMENT_WMAC0_REG_V01:
  1464. ret = qcom_dump(&head, priv->m3_dump_wmac0reg->dev);
  1465. break;
  1466. case QMI_M3_SEGMENT_WCSSDBG_V01:
  1467. ret = qcom_dump(&head, priv->m3_dump_wcssdbg->dev);
  1468. break;
  1469. case QMI_M3_SEGMENT_PHYAPDMEM_V01:
  1470. ret = qcom_dump(&head, priv->m3_dump_phyapdmem->dev);
  1471. break;
  1472. default:
  1473. icnss_pr_err("Invalid Segment type: %d",
  1474. event_data->m3_segment[i].type);
  1475. }
  1476. if (ret) {
  1477. status = ret;
  1478. icnss_pr_err("Failed to dump m3 %s segment, err = %d\n",
  1479. event_data->m3_segment[i].name, ret);
  1480. }
  1481. list_del(&segment.node);
  1482. }
  1483. send_resp:
  1484. icnss_wlfw_m3_dump_upload_done_send_sync(priv, event_data->pdev_id,
  1485. status);
  1486. return ret;
  1487. }
  1488. static int icnss_subsys_restart_level(struct icnss_priv *priv, void *data)
  1489. {
  1490. int ret = 0;
  1491. struct icnss_subsys_restart_level_data *event_data = data;
  1492. if (!priv)
  1493. return -ENODEV;
  1494. if (!data)
  1495. return -EINVAL;
  1496. ret = wlfw_subsys_restart_level_msg(priv, event_data->restart_level);
  1497. kfree(data);
  1498. return ret;
  1499. }
  1500. static void icnss_wpss_self_recovery(struct work_struct *wpss_load_work)
  1501. {
  1502. int ret;
  1503. struct icnss_priv *priv = icnss_get_plat_priv();
  1504. rproc_shutdown(priv->rproc);
  1505. ret = rproc_boot(priv->rproc);
  1506. if (ret) {
  1507. icnss_pr_err("Failed to self recover wpss rproc, ret: %d", ret);
  1508. rproc_put(priv->rproc);
  1509. }
  1510. }
  1511. static void icnss_driver_event_work(struct work_struct *work)
  1512. {
  1513. struct icnss_priv *priv =
  1514. container_of(work, struct icnss_priv, event_work);
  1515. struct icnss_driver_event *event;
  1516. unsigned long flags;
  1517. int ret;
  1518. icnss_pm_stay_awake(priv);
  1519. spin_lock_irqsave(&priv->event_lock, flags);
  1520. while (!list_empty(&priv->event_list)) {
  1521. event = list_first_entry(&priv->event_list,
  1522. struct icnss_driver_event, list);
  1523. list_del(&event->list);
  1524. spin_unlock_irqrestore(&priv->event_lock, flags);
  1525. icnss_pr_dbg("Processing event: %s%s(%d), state: 0x%lx\n",
  1526. icnss_driver_event_to_str(event->type),
  1527. event->sync ? "-sync" : "", event->type,
  1528. priv->state);
  1529. switch (event->type) {
  1530. case ICNSS_DRIVER_EVENT_SERVER_ARRIVE:
  1531. ret = icnss_driver_event_server_arrive(priv,
  1532. event->data);
  1533. break;
  1534. case ICNSS_DRIVER_EVENT_SERVER_EXIT:
  1535. ret = icnss_driver_event_server_exit(priv);
  1536. break;
  1537. case ICNSS_DRIVER_EVENT_FW_READY_IND:
  1538. ret = icnss_driver_event_fw_ready_ind(priv,
  1539. event->data);
  1540. break;
  1541. case ICNSS_DRIVER_EVENT_REGISTER_DRIVER:
  1542. ret = icnss_driver_event_register_driver(priv,
  1543. event->data);
  1544. break;
  1545. case ICNSS_DRIVER_EVENT_UNREGISTER_DRIVER:
  1546. ret = icnss_driver_event_unregister_driver(priv,
  1547. event->data);
  1548. break;
  1549. case ICNSS_DRIVER_EVENT_PD_SERVICE_DOWN:
  1550. ret = icnss_driver_event_pd_service_down(priv,
  1551. event->data);
  1552. break;
  1553. case ICNSS_DRIVER_EVENT_FW_EARLY_CRASH_IND:
  1554. ret = icnss_driver_event_early_crash_ind(priv,
  1555. event->data);
  1556. break;
  1557. case ICNSS_DRIVER_EVENT_IDLE_SHUTDOWN:
  1558. ret = icnss_driver_event_idle_shutdown(priv,
  1559. event->data);
  1560. break;
  1561. case ICNSS_DRIVER_EVENT_IDLE_RESTART:
  1562. ret = icnss_driver_event_idle_restart(priv,
  1563. event->data);
  1564. break;
  1565. case ICNSS_DRIVER_EVENT_FW_INIT_DONE_IND:
  1566. ret = icnss_driver_event_fw_init_done(priv,
  1567. event->data);
  1568. break;
  1569. case ICNSS_DRIVER_EVENT_QDSS_TRACE_REQ_MEM:
  1570. ret = icnss_qdss_trace_req_mem_hdlr(priv);
  1571. break;
  1572. case ICNSS_DRIVER_EVENT_QDSS_TRACE_SAVE:
  1573. ret = icnss_qdss_trace_save_hdlr(priv,
  1574. event->data);
  1575. break;
  1576. case ICNSS_DRIVER_EVENT_QDSS_TRACE_FREE:
  1577. ret = icnss_qdss_trace_free_hdlr(priv);
  1578. break;
  1579. case ICNSS_DRIVER_EVENT_M3_DUMP_UPLOAD_REQ:
  1580. ret = icnss_m3_dump_upload_req_hdlr(priv, event->data);
  1581. break;
  1582. case ICNSS_DRIVER_EVENT_QDSS_TRACE_REQ_DATA:
  1583. ret = icnss_qdss_trace_req_data_hdlr(priv,
  1584. event->data);
  1585. break;
  1586. case ICNSS_DRIVER_EVENT_SUBSYS_RESTART_LEVEL:
  1587. ret = icnss_subsys_restart_level(priv, event->data);
  1588. break;
  1589. default:
  1590. icnss_pr_err("Invalid Event type: %d", event->type);
  1591. kfree(event);
  1592. continue;
  1593. }
  1594. priv->stats.events[event->type].processed++;
  1595. icnss_pr_dbg("Event Processed: %s%s(%d), ret: %d, state: 0x%lx\n",
  1596. icnss_driver_event_to_str(event->type),
  1597. event->sync ? "-sync" : "", event->type, ret,
  1598. priv->state);
  1599. spin_lock_irqsave(&priv->event_lock, flags);
  1600. if (event->sync) {
  1601. event->ret = ret;
  1602. complete(&event->complete);
  1603. continue;
  1604. }
  1605. spin_unlock_irqrestore(&priv->event_lock, flags);
  1606. kfree(event);
  1607. spin_lock_irqsave(&priv->event_lock, flags);
  1608. }
  1609. spin_unlock_irqrestore(&priv->event_lock, flags);
  1610. icnss_pm_relax(priv);
  1611. }
  1612. static void icnss_soc_wake_msg_work(struct work_struct *work)
  1613. {
  1614. struct icnss_priv *priv =
  1615. container_of(work, struct icnss_priv, soc_wake_msg_work);
  1616. struct icnss_soc_wake_event *event;
  1617. unsigned long flags;
  1618. int ret;
  1619. icnss_pm_stay_awake(priv);
  1620. spin_lock_irqsave(&priv->soc_wake_msg_lock, flags);
  1621. while (!list_empty(&priv->soc_wake_msg_list)) {
  1622. event = list_first_entry(&priv->soc_wake_msg_list,
  1623. struct icnss_soc_wake_event, list);
  1624. list_del(&event->list);
  1625. spin_unlock_irqrestore(&priv->soc_wake_msg_lock, flags);
  1626. icnss_pr_soc_wake("Processing event: %s%s(%d), state: 0x%lx\n",
  1627. icnss_soc_wake_event_to_str(event->type),
  1628. event->sync ? "-sync" : "", event->type,
  1629. priv->state);
  1630. switch (event->type) {
  1631. case ICNSS_SOC_WAKE_REQUEST_EVENT:
  1632. ret = icnss_event_soc_wake_request(priv,
  1633. event->data);
  1634. break;
  1635. case ICNSS_SOC_WAKE_RELEASE_EVENT:
  1636. ret = icnss_event_soc_wake_release(priv,
  1637. event->data);
  1638. break;
  1639. default:
  1640. icnss_pr_err("Invalid Event type: %d", event->type);
  1641. kfree(event);
  1642. continue;
  1643. }
  1644. priv->stats.soc_wake_events[event->type].processed++;
  1645. icnss_pr_soc_wake("Event Processed: %s%s(%d), ret: %d, state: 0x%lx\n",
  1646. icnss_soc_wake_event_to_str(event->type),
  1647. event->sync ? "-sync" : "", event->type, ret,
  1648. priv->state);
  1649. spin_lock_irqsave(&priv->soc_wake_msg_lock, flags);
  1650. if (event->sync) {
  1651. event->ret = ret;
  1652. complete(&event->complete);
  1653. continue;
  1654. }
  1655. spin_unlock_irqrestore(&priv->soc_wake_msg_lock, flags);
  1656. kfree(event);
  1657. spin_lock_irqsave(&priv->soc_wake_msg_lock, flags);
  1658. }
  1659. spin_unlock_irqrestore(&priv->soc_wake_msg_lock, flags);
  1660. icnss_pm_relax(priv);
  1661. }
  1662. static int icnss_msa0_ramdump(struct icnss_priv *priv)
  1663. {
  1664. int ret = 0;
  1665. struct qcom_dump_segment segment;
  1666. struct icnss_ramdump_info *msa0_dump_dev = priv->msa0_dump_dev;
  1667. struct list_head head;
  1668. if (!dump_enabled()) {
  1669. icnss_pr_info("Dump collection is not enabled\n");
  1670. return ret;
  1671. }
  1672. if (IS_ERR_OR_NULL(msa0_dump_dev))
  1673. return ret;
  1674. INIT_LIST_HEAD(&head);
  1675. memset(&segment, 0, sizeof(segment));
  1676. segment.va = priv->msa_va;
  1677. segment.size = priv->msa_mem_size;
  1678. list_add(&segment.node, &head);
  1679. if (!msa0_dump_dev->dev) {
  1680. icnss_pr_err("Created Dump Device not found\n");
  1681. return 0;
  1682. }
  1683. ret = qcom_dump(&head, msa0_dump_dev->dev);
  1684. if (ret) {
  1685. icnss_pr_err("Failed to dump msa0, err = %d\n", ret);
  1686. return ret;
  1687. }
  1688. list_del(&segment.node);
  1689. return ret;
  1690. }
  1691. static void icnss_update_state_send_modem_shutdown(struct icnss_priv *priv,
  1692. void *data)
  1693. {
  1694. struct qcom_ssr_notify_data *notif = data;
  1695. int ret = 0;
  1696. if (!notif->crashed) {
  1697. if (atomic_read(&priv->is_shutdown)) {
  1698. atomic_set(&priv->is_shutdown, false);
  1699. if (!test_bit(ICNSS_PD_RESTART, &priv->state) &&
  1700. !test_bit(ICNSS_SHUTDOWN_DONE, &priv->state) &&
  1701. !test_bit(ICNSS_BLOCK_SHUTDOWN, &priv->state)) {
  1702. clear_bit(ICNSS_FW_READY, &priv->state);
  1703. icnss_driver_event_post(priv,
  1704. ICNSS_DRIVER_EVENT_UNREGISTER_DRIVER,
  1705. ICNSS_EVENT_SYNC_UNINTERRUPTIBLE,
  1706. NULL);
  1707. }
  1708. }
  1709. if (test_bit(ICNSS_BLOCK_SHUTDOWN, &priv->state)) {
  1710. if (!wait_for_completion_timeout(
  1711. &priv->unblock_shutdown,
  1712. msecs_to_jiffies(PROBE_TIMEOUT)))
  1713. icnss_pr_err("modem block shutdown timeout\n");
  1714. }
  1715. ret = wlfw_send_modem_shutdown_msg(priv);
  1716. if (ret < 0)
  1717. icnss_pr_err("Fail to send modem shutdown Indication %d\n",
  1718. ret);
  1719. }
  1720. }
  1721. static char *icnss_qcom_ssr_notify_state_to_str(enum qcom_ssr_notify_type code)
  1722. {
  1723. switch (code) {
  1724. case QCOM_SSR_BEFORE_POWERUP:
  1725. return "BEFORE_POWERUP";
  1726. case QCOM_SSR_AFTER_POWERUP:
  1727. return "AFTER_POWERUP";
  1728. case QCOM_SSR_BEFORE_SHUTDOWN:
  1729. return "BEFORE_SHUTDOWN";
  1730. case QCOM_SSR_AFTER_SHUTDOWN:
  1731. return "AFTER_SHUTDOWN";
  1732. default:
  1733. return "UNKNOWN";
  1734. }
  1735. };
  1736. static int icnss_wpss_early_notifier_nb(struct notifier_block *nb,
  1737. unsigned long code,
  1738. void *data)
  1739. {
  1740. struct icnss_priv *priv = container_of(nb, struct icnss_priv,
  1741. wpss_early_ssr_nb);
  1742. icnss_pr_vdbg("WPSS-EARLY-Notify: event %s(%lu)\n",
  1743. icnss_qcom_ssr_notify_state_to_str(code), code);
  1744. if (code == QCOM_SSR_BEFORE_SHUTDOWN) {
  1745. set_bit(ICNSS_FW_DOWN, &priv->state);
  1746. icnss_ignore_fw_timeout(true);
  1747. }
  1748. return NOTIFY_DONE;
  1749. }
  1750. static int icnss_wpss_notifier_nb(struct notifier_block *nb,
  1751. unsigned long code,
  1752. void *data)
  1753. {
  1754. struct icnss_event_pd_service_down_data *event_data;
  1755. struct qcom_ssr_notify_data *notif = data;
  1756. struct icnss_priv *priv = container_of(nb, struct icnss_priv,
  1757. wpss_ssr_nb);
  1758. struct icnss_uevent_fw_down_data fw_down_data = {0};
  1759. icnss_pr_vdbg("WPSS-Notify: event %s(%lu)\n",
  1760. icnss_qcom_ssr_notify_state_to_str(code), code);
  1761. if (code == QCOM_SSR_AFTER_SHUTDOWN) {
  1762. icnss_pr_info("Collecting msa0 segment dump\n");
  1763. icnss_msa0_ramdump(priv);
  1764. goto out;
  1765. }
  1766. if (code != QCOM_SSR_BEFORE_SHUTDOWN)
  1767. goto out;
  1768. if (priv->wpss_self_recovery_enabled)
  1769. del_timer(&priv->wpss_ssr_timer);
  1770. priv->is_ssr = true;
  1771. icnss_pr_info("WPSS went down, state: 0x%lx, crashed: %d\n",
  1772. priv->state, notif->crashed);
  1773. if (priv->device_id == ADRASTEA_DEVICE_ID)
  1774. icnss_update_state_send_modem_shutdown(priv, data);
  1775. set_bit(ICNSS_FW_DOWN, &priv->state);
  1776. icnss_ignore_fw_timeout(true);
  1777. if (notif->crashed)
  1778. priv->stats.recovery.root_pd_crash++;
  1779. else
  1780. priv->stats.recovery.root_pd_shutdown++;
  1781. event_data = kzalloc(sizeof(*event_data), GFP_KERNEL);
  1782. if (event_data == NULL)
  1783. return notifier_from_errno(-ENOMEM);
  1784. event_data->crashed = notif->crashed;
  1785. fw_down_data.crashed = !!notif->crashed;
  1786. if (test_bit(ICNSS_FW_READY, &priv->state)) {
  1787. clear_bit(ICNSS_FW_READY, &priv->state);
  1788. fw_down_data.crashed = !!notif->crashed;
  1789. icnss_call_driver_uevent(priv,
  1790. ICNSS_UEVENT_FW_DOWN,
  1791. &fw_down_data);
  1792. }
  1793. icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_PD_SERVICE_DOWN,
  1794. ICNSS_EVENT_SYNC, event_data);
  1795. if (notif->crashed)
  1796. mod_timer(&priv->recovery_timer,
  1797. jiffies + msecs_to_jiffies(ICNSS_RECOVERY_TIMEOUT));
  1798. out:
  1799. icnss_pr_vdbg("Exit %s,state: 0x%lx\n", __func__, priv->state);
  1800. return NOTIFY_OK;
  1801. }
  1802. static int icnss_modem_notifier_nb(struct notifier_block *nb,
  1803. unsigned long code,
  1804. void *data)
  1805. {
  1806. struct icnss_event_pd_service_down_data *event_data;
  1807. struct qcom_ssr_notify_data *notif = data;
  1808. struct icnss_priv *priv = container_of(nb, struct icnss_priv,
  1809. modem_ssr_nb);
  1810. struct icnss_uevent_fw_down_data fw_down_data = {0};
  1811. icnss_pr_vdbg("Modem-Notify: event %s(%lu)\n",
  1812. icnss_qcom_ssr_notify_state_to_str(code), code);
  1813. switch (code) {
  1814. case QCOM_SSR_BEFORE_SHUTDOWN:
  1815. if (!notif->crashed &&
  1816. priv->low_power_support) { /* Hibernate */
  1817. if (test_bit(ICNSS_MODE_ON, &priv->state))
  1818. icnss_driver_event_post(
  1819. priv, ICNSS_DRIVER_EVENT_IDLE_SHUTDOWN,
  1820. ICNSS_EVENT_SYNC_UNINTERRUPTIBLE, NULL);
  1821. set_bit(ICNSS_LOW_POWER, &priv->state);
  1822. }
  1823. break;
  1824. case QCOM_SSR_AFTER_SHUTDOWN:
  1825. /* Collect ramdump only when there was a crash. */
  1826. if (notif->crashed) {
  1827. icnss_pr_info("Collecting msa0 segment dump\n");
  1828. icnss_msa0_ramdump(priv);
  1829. }
  1830. goto out;
  1831. default:
  1832. goto out;
  1833. }
  1834. priv->is_ssr = true;
  1835. if (notif->crashed) {
  1836. priv->stats.recovery.root_pd_crash++;
  1837. priv->root_pd_shutdown = false;
  1838. } else {
  1839. priv->stats.recovery.root_pd_shutdown++;
  1840. priv->root_pd_shutdown = true;
  1841. }
  1842. icnss_update_state_send_modem_shutdown(priv, data);
  1843. if (test_bit(ICNSS_PDR_REGISTERED, &priv->state)) {
  1844. set_bit(ICNSS_FW_DOWN, &priv->state);
  1845. icnss_ignore_fw_timeout(true);
  1846. if (test_bit(ICNSS_FW_READY, &priv->state)) {
  1847. clear_bit(ICNSS_FW_READY, &priv->state);
  1848. fw_down_data.crashed = !!notif->crashed;
  1849. icnss_call_driver_uevent(priv,
  1850. ICNSS_UEVENT_FW_DOWN,
  1851. &fw_down_data);
  1852. }
  1853. goto out;
  1854. }
  1855. icnss_pr_info("Modem went down, state: 0x%lx, crashed: %d\n",
  1856. priv->state, notif->crashed);
  1857. set_bit(ICNSS_FW_DOWN, &priv->state);
  1858. icnss_ignore_fw_timeout(true);
  1859. event_data = kzalloc(sizeof(*event_data), GFP_KERNEL);
  1860. if (event_data == NULL)
  1861. return notifier_from_errno(-ENOMEM);
  1862. event_data->crashed = notif->crashed;
  1863. fw_down_data.crashed = !!notif->crashed;
  1864. if (test_bit(ICNSS_FW_READY, &priv->state)) {
  1865. clear_bit(ICNSS_FW_READY, &priv->state);
  1866. fw_down_data.crashed = !!notif->crashed;
  1867. icnss_call_driver_uevent(priv,
  1868. ICNSS_UEVENT_FW_DOWN,
  1869. &fw_down_data);
  1870. }
  1871. icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_PD_SERVICE_DOWN,
  1872. ICNSS_EVENT_SYNC, event_data);
  1873. if (notif->crashed)
  1874. mod_timer(&priv->recovery_timer,
  1875. jiffies + msecs_to_jiffies(ICNSS_RECOVERY_TIMEOUT));
  1876. out:
  1877. icnss_pr_vdbg("Exit %s,state: 0x%lx\n", __func__, priv->state);
  1878. return NOTIFY_OK;
  1879. }
  1880. static int icnss_wpss_early_ssr_register_notifier(struct icnss_priv *priv)
  1881. {
  1882. int ret = 0;
  1883. priv->wpss_early_ssr_nb.notifier_call = icnss_wpss_early_notifier_nb;
  1884. priv->wpss_early_notify_handler =
  1885. qcom_register_early_ssr_notifier("wpss",
  1886. &priv->wpss_early_ssr_nb);
  1887. if (IS_ERR(priv->wpss_early_notify_handler)) {
  1888. ret = PTR_ERR(priv->wpss_early_notify_handler);
  1889. icnss_pr_err("WPSS register early notifier failed: %d\n", ret);
  1890. }
  1891. return ret;
  1892. }
  1893. static int icnss_wpss_ssr_register_notifier(struct icnss_priv *priv)
  1894. {
  1895. int ret = 0;
  1896. priv->wpss_ssr_nb.notifier_call = icnss_wpss_notifier_nb;
  1897. /*
  1898. * Assign priority of icnss wpss notifier callback over IPA
  1899. * modem notifier callback which is 0
  1900. */
  1901. priv->wpss_ssr_nb.priority = 1;
  1902. priv->wpss_notify_handler =
  1903. qcom_register_ssr_notifier("wpss", &priv->wpss_ssr_nb);
  1904. if (IS_ERR(priv->wpss_notify_handler)) {
  1905. ret = PTR_ERR(priv->wpss_notify_handler);
  1906. icnss_pr_err("WPSS register notifier failed: %d\n", ret);
  1907. }
  1908. set_bit(ICNSS_SSR_REGISTERED, &priv->state);
  1909. return ret;
  1910. }
  1911. #ifdef SLATE_MODULE_ENABLED
  1912. static int icnss_slate_event_notifier_nb(struct notifier_block *nb,
  1913. unsigned long event, void *data)
  1914. {
  1915. icnss_pr_info("Received slate event 0x%x\n", event);
  1916. if (event == SLATE_STATUS) {
  1917. struct icnss_priv *priv = container_of(nb, struct icnss_priv,
  1918. seb_nb);
  1919. enum boot_status status = *(enum boot_status *)data;
  1920. if (status == SLATE_READY) {
  1921. icnss_pr_dbg("Slate ready received, state: 0x%lx\n",
  1922. priv->state);
  1923. set_bit(ICNSS_SLATE_READY, &priv->state);
  1924. set_bit(ICNSS_SLATE_UP, &priv->state);
  1925. complete(&priv->slate_boot_complete);
  1926. }
  1927. }
  1928. return NOTIFY_OK;
  1929. }
  1930. static int icnss_register_slate_event_notifier(struct icnss_priv *priv)
  1931. {
  1932. int ret = 0;
  1933. priv->seb_nb.notifier_call = icnss_slate_event_notifier_nb;
  1934. priv->seb_handle = seb_register_for_slate_event(SLATE_STATUS,
  1935. &priv->seb_nb);
  1936. if (IS_ERR_OR_NULL(priv->seb_handle)) {
  1937. ret = priv->seb_handle ? PTR_ERR(priv->seb_handle) : -EINVAL;
  1938. icnss_pr_err("SLATE event register notifier failed: %d\n",
  1939. ret);
  1940. }
  1941. return ret;
  1942. }
  1943. static int icnss_unregister_slate_event_notifier(struct icnss_priv *priv)
  1944. {
  1945. int ret = 0;
  1946. ret = seb_unregister_for_slate_event(priv->seb_handle, &priv->seb_nb);
  1947. if (ret < 0)
  1948. icnss_pr_err("Slate event unregister failed: %d\n", ret);
  1949. return ret;
  1950. }
  1951. static int icnss_slate_notifier_nb(struct notifier_block *nb,
  1952. unsigned long code,
  1953. void *data)
  1954. {
  1955. struct icnss_priv *priv = container_of(nb, struct icnss_priv,
  1956. slate_ssr_nb);
  1957. int ret = 0;
  1958. icnss_pr_vdbg("Slate-subsys-notify: event %lu\n", code);
  1959. if (code == QCOM_SSR_AFTER_POWERUP &&
  1960. test_bit(ICNSS_SLATE_READY, &priv->state)) {
  1961. set_bit(ICNSS_SLATE_UP, &priv->state);
  1962. complete(&priv->slate_boot_complete);
  1963. icnss_pr_dbg("Slate boot complete, state: 0x%lx\n",
  1964. priv->state);
  1965. } else if (code == QCOM_SSR_BEFORE_SHUTDOWN &&
  1966. test_bit(ICNSS_SLATE_UP, &priv->state)) {
  1967. clear_bit(ICNSS_SLATE_UP, &priv->state);
  1968. if (test_bit(ICNSS_PD_RESTART, &priv->state)) {
  1969. icnss_pr_err("PD_RESTART in progress 0x%lx\n",
  1970. priv->state);
  1971. goto skip_pdr;
  1972. }
  1973. icnss_pr_dbg("Initiating PDR 0x%lx\n", priv->state);
  1974. ret = icnss_trigger_recovery(&priv->pdev->dev);
  1975. if (ret < 0) {
  1976. icnss_fatal_err("Fail to trigger PDR: ret: %d, state: 0x%lx\n",
  1977. ret, priv->state);
  1978. goto skip_pdr;
  1979. }
  1980. }
  1981. skip_pdr:
  1982. return NOTIFY_OK;
  1983. }
  1984. static int icnss_slate_ssr_register_notifier(struct icnss_priv *priv)
  1985. {
  1986. int ret = 0;
  1987. priv->slate_ssr_nb.notifier_call = icnss_slate_notifier_nb;
  1988. priv->slate_notify_handler =
  1989. qcom_register_ssr_notifier("slatefw", &priv->slate_ssr_nb);
  1990. if (IS_ERR(priv->slate_notify_handler)) {
  1991. ret = PTR_ERR(priv->slate_notify_handler);
  1992. icnss_pr_err("SLATE register notifier failed: %d\n", ret);
  1993. }
  1994. set_bit(ICNSS_SLATE_SSR_REGISTERED, &priv->state);
  1995. return ret;
  1996. }
  1997. static int icnss_slate_ssr_unregister_notifier(struct icnss_priv *priv)
  1998. {
  1999. if (!test_and_clear_bit(ICNSS_SLATE_SSR_REGISTERED, &priv->state))
  2000. return 0;
  2001. qcom_unregister_ssr_notifier(priv->slate_notify_handler,
  2002. &priv->slate_ssr_nb);
  2003. priv->slate_notify_handler = NULL;
  2004. return 0;
  2005. }
  2006. #else
  2007. static int icnss_register_slate_event_notifier(struct icnss_priv *priv)
  2008. {
  2009. return 0;
  2010. }
  2011. static int icnss_unregister_slate_event_notifier(struct icnss_priv *priv)
  2012. {
  2013. return 0;
  2014. }
  2015. static int icnss_slate_ssr_register_notifier(struct icnss_priv *priv)
  2016. {
  2017. return 0;
  2018. }
  2019. static int icnss_slate_ssr_unregister_notifier(struct icnss_priv *priv)
  2020. {
  2021. return 0;
  2022. }
  2023. #endif
  2024. static int icnss_modem_ssr_register_notifier(struct icnss_priv *priv)
  2025. {
  2026. int ret = 0;
  2027. priv->modem_ssr_nb.notifier_call = icnss_modem_notifier_nb;
  2028. /*
  2029. * Assign priority of icnss modem notifier callback over IPA
  2030. * modem notifier callback which is 0
  2031. */
  2032. priv->modem_ssr_nb.priority = 1;
  2033. priv->modem_notify_handler =
  2034. qcom_register_ssr_notifier("mpss", &priv->modem_ssr_nb);
  2035. if (IS_ERR(priv->modem_notify_handler)) {
  2036. ret = PTR_ERR(priv->modem_notify_handler);
  2037. icnss_pr_err("Modem register notifier failed: %d\n", ret);
  2038. }
  2039. set_bit(ICNSS_SSR_REGISTERED, &priv->state);
  2040. return ret;
  2041. }
  2042. static void icnss_wpss_early_ssr_unregister_notifier(struct icnss_priv *priv)
  2043. {
  2044. if (IS_ERR(priv->wpss_early_notify_handler))
  2045. return;
  2046. qcom_unregister_early_ssr_notifier(priv->wpss_early_notify_handler,
  2047. &priv->wpss_early_ssr_nb);
  2048. priv->wpss_early_notify_handler = NULL;
  2049. }
  2050. static int icnss_wpss_ssr_unregister_notifier(struct icnss_priv *priv)
  2051. {
  2052. if (!test_and_clear_bit(ICNSS_SSR_REGISTERED, &priv->state))
  2053. return 0;
  2054. qcom_unregister_ssr_notifier(priv->wpss_notify_handler,
  2055. &priv->wpss_ssr_nb);
  2056. priv->wpss_notify_handler = NULL;
  2057. return 0;
  2058. }
  2059. static int icnss_modem_ssr_unregister_notifier(struct icnss_priv *priv)
  2060. {
  2061. if (!test_and_clear_bit(ICNSS_SSR_REGISTERED, &priv->state))
  2062. return 0;
  2063. qcom_unregister_ssr_notifier(priv->modem_notify_handler,
  2064. &priv->modem_ssr_nb);
  2065. priv->modem_notify_handler = NULL;
  2066. return 0;
  2067. }
  2068. static void icnss_pdr_notifier_cb(int state, char *service_path, void *priv_cb)
  2069. {
  2070. struct icnss_priv *priv = priv_cb;
  2071. struct icnss_event_pd_service_down_data *event_data;
  2072. struct icnss_uevent_fw_down_data fw_down_data = {0};
  2073. enum icnss_pdr_cause_index cause = ICNSS_ROOT_PD_CRASH;
  2074. if (!priv)
  2075. return;
  2076. icnss_pr_dbg("PD service notification: 0x%lx state: 0x%lx\n",
  2077. state, priv->state);
  2078. switch (state) {
  2079. case SERVREG_SERVICE_STATE_DOWN:
  2080. event_data = kzalloc(sizeof(*event_data), GFP_KERNEL);
  2081. if (!event_data)
  2082. return;
  2083. event_data->crashed = true;
  2084. if (!priv->is_ssr) {
  2085. set_bit(ICNSS_PDR, &penv->state);
  2086. if (test_bit(ICNSS_HOST_TRIGGERED_PDR, &priv->state)) {
  2087. cause = ICNSS_HOST_ERROR;
  2088. priv->stats.recovery.pdr_host_error++;
  2089. } else {
  2090. cause = ICNSS_FW_CRASH;
  2091. priv->stats.recovery.pdr_fw_crash++;
  2092. }
  2093. } else if (priv->root_pd_shutdown) {
  2094. cause = ICNSS_ROOT_PD_SHUTDOWN;
  2095. event_data->crashed = false;
  2096. }
  2097. icnss_pr_info("PD service down, state: 0x%lx: cause: %s\n",
  2098. priv->state, icnss_pdr_cause[cause]);
  2099. if (!test_bit(ICNSS_FW_DOWN, &priv->state)) {
  2100. set_bit(ICNSS_FW_DOWN, &priv->state);
  2101. icnss_ignore_fw_timeout(true);
  2102. if (test_bit(ICNSS_FW_READY, &priv->state)) {
  2103. clear_bit(ICNSS_FW_READY, &priv->state);
  2104. fw_down_data.crashed = event_data->crashed;
  2105. icnss_call_driver_uevent(priv,
  2106. ICNSS_UEVENT_FW_DOWN,
  2107. &fw_down_data);
  2108. }
  2109. }
  2110. clear_bit(ICNSS_HOST_TRIGGERED_PDR, &priv->state);
  2111. if (event_data->crashed)
  2112. mod_timer(&priv->recovery_timer,
  2113. jiffies +
  2114. msecs_to_jiffies(ICNSS_RECOVERY_TIMEOUT));
  2115. icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_PD_SERVICE_DOWN,
  2116. ICNSS_EVENT_SYNC, event_data);
  2117. break;
  2118. case SERVREG_SERVICE_STATE_UP:
  2119. clear_bit(ICNSS_FW_DOWN, &priv->state);
  2120. break;
  2121. default:
  2122. break;
  2123. }
  2124. return;
  2125. }
  2126. static int icnss_pd_restart_enable(struct icnss_priv *priv)
  2127. {
  2128. struct pdr_handle *handle = NULL;
  2129. struct pdr_service *service = NULL;
  2130. int err = 0;
  2131. handle = pdr_handle_alloc(icnss_pdr_notifier_cb, priv);
  2132. if (IS_ERR_OR_NULL(handle)) {
  2133. err = PTR_ERR(handle);
  2134. icnss_pr_err("Failed to alloc pdr handle, err %d", err);
  2135. goto out;
  2136. }
  2137. service = pdr_add_lookup(handle, ICNSS_WLAN_SERVICE_NAME, ICNSS_WLANPD_NAME);
  2138. if (IS_ERR_OR_NULL(service)) {
  2139. err = PTR_ERR(service);
  2140. icnss_pr_err("Failed to add lookup, err %d", err);
  2141. goto out;
  2142. }
  2143. priv->pdr_handle = handle;
  2144. priv->pdr_service = service;
  2145. set_bit(ICNSS_PDR_REGISTERED, &priv->state);
  2146. icnss_pr_info("PDR registration happened");
  2147. out:
  2148. return err;
  2149. }
  2150. static void icnss_pdr_unregister_notifier(struct icnss_priv *priv)
  2151. {
  2152. if (!test_and_clear_bit(ICNSS_PDR_REGISTERED, &priv->state))
  2153. return;
  2154. pdr_handle_release(priv->pdr_handle);
  2155. }
  2156. static int icnss_ramdump_devnode_init(struct icnss_priv *priv)
  2157. {
  2158. int ret = 0;
  2159. priv->icnss_ramdump_class = class_create(THIS_MODULE, ICNSS_RAMDUMP_NAME);
  2160. if (IS_ERR_OR_NULL(priv->icnss_ramdump_class)) {
  2161. ret = PTR_ERR(priv->icnss_ramdump_class);
  2162. icnss_pr_err("%s:Class create failed for ramdump devices (%d)\n", __func__, ret);
  2163. return ret;
  2164. }
  2165. ret = alloc_chrdev_region(&priv->icnss_ramdump_dev, 0, RAMDUMP_NUM_DEVICES,
  2166. ICNSS_RAMDUMP_NAME);
  2167. if (ret < 0) {
  2168. icnss_pr_err("%s: Unable to allocate major\n", __func__);
  2169. goto fail_alloc_major;
  2170. }
  2171. return 0;
  2172. fail_alloc_major:
  2173. class_destroy(priv->icnss_ramdump_class);
  2174. return ret;
  2175. }
  2176. void *icnss_create_ramdump_device(struct icnss_priv *priv, const char *dev_name)
  2177. {
  2178. int ret = 0;
  2179. struct icnss_ramdump_info *ramdump_info;
  2180. ramdump_info = kzalloc(sizeof(*ramdump_info), GFP_KERNEL);
  2181. if (!ramdump_info)
  2182. return ERR_PTR(-ENOMEM);
  2183. if (!dev_name) {
  2184. icnss_pr_err("%s: Invalid device name.\n", __func__);
  2185. return NULL;
  2186. }
  2187. snprintf(ramdump_info->name, ARRAY_SIZE(ramdump_info->name), "icnss_%s", dev_name);
  2188. ramdump_info->minor = ida_simple_get(&rd_minor_id, 0, RAMDUMP_NUM_DEVICES, GFP_KERNEL);
  2189. if (ramdump_info->minor < 0) {
  2190. icnss_pr_err("%s: No more minor numbers left! rc:%d\n", __func__,
  2191. ramdump_info->minor);
  2192. ret = -ENODEV;
  2193. goto fail_out_of_minors;
  2194. }
  2195. ramdump_info->dev = device_create(priv->icnss_ramdump_class, NULL,
  2196. MKDEV(MAJOR(priv->icnss_ramdump_dev),
  2197. ramdump_info->minor),
  2198. ramdump_info, ramdump_info->name);
  2199. if (IS_ERR_OR_NULL(ramdump_info->dev)) {
  2200. ret = PTR_ERR(ramdump_info->dev);
  2201. icnss_pr_err("%s: Device create failed for %s (%d)\n", __func__,
  2202. ramdump_info->name, ret);
  2203. goto fail_device_create;
  2204. }
  2205. return (void *)ramdump_info;
  2206. fail_device_create:
  2207. ida_simple_remove(&rd_minor_id, ramdump_info->minor);
  2208. fail_out_of_minors:
  2209. kfree(ramdump_info);
  2210. return ERR_PTR(ret);
  2211. }
  2212. static int icnss_register_ramdump_devices(struct icnss_priv *priv)
  2213. {
  2214. int ret = 0;
  2215. if (!priv || !priv->pdev) {
  2216. icnss_pr_err("Platform priv or pdev is NULL\n");
  2217. return -EINVAL;
  2218. }
  2219. ret = icnss_ramdump_devnode_init(priv);
  2220. if (ret)
  2221. return ret;
  2222. priv->msa0_dump_dev = icnss_create_ramdump_device(priv, "wcss_msa0");
  2223. if (IS_ERR_OR_NULL(priv->msa0_dump_dev) || !priv->msa0_dump_dev->dev) {
  2224. icnss_pr_err("Failed to create msa0 dump device!");
  2225. return -ENOMEM;
  2226. }
  2227. if (priv->device_id == WCN6750_DEVICE_ID ||
  2228. priv->device_id == WCN6450_DEVICE_ID) {
  2229. priv->m3_dump_phyareg = icnss_create_ramdump_device(priv,
  2230. ICNSS_M3_SEGMENT(
  2231. ICNSS_M3_SEGMENT_PHYAREG));
  2232. if (IS_ERR_OR_NULL(priv->m3_dump_phyareg) ||
  2233. !priv->m3_dump_phyareg->dev) {
  2234. icnss_pr_err("Failed to create m3 dump for Phyareg segment device!");
  2235. return -ENOMEM;
  2236. }
  2237. priv->m3_dump_phydbg = icnss_create_ramdump_device(priv,
  2238. ICNSS_M3_SEGMENT(
  2239. ICNSS_M3_SEGMENT_PHYA));
  2240. if (IS_ERR_OR_NULL(priv->m3_dump_phydbg) ||
  2241. !priv->m3_dump_phydbg->dev) {
  2242. icnss_pr_err("Failed to create m3 dump for Phydbg segment device!");
  2243. return -ENOMEM;
  2244. }
  2245. priv->m3_dump_wmac0reg = icnss_create_ramdump_device(priv,
  2246. ICNSS_M3_SEGMENT(
  2247. ICNSS_M3_SEGMENT_WMACREG));
  2248. if (IS_ERR_OR_NULL(priv->m3_dump_wmac0reg) ||
  2249. !priv->m3_dump_wmac0reg->dev) {
  2250. icnss_pr_err("Failed to create m3 dump for Wmac0reg segment device!");
  2251. return -ENOMEM;
  2252. }
  2253. priv->m3_dump_wcssdbg = icnss_create_ramdump_device(priv,
  2254. ICNSS_M3_SEGMENT(
  2255. ICNSS_M3_SEGMENT_WCSSDBG));
  2256. if (IS_ERR_OR_NULL(priv->m3_dump_wcssdbg) ||
  2257. !priv->m3_dump_wcssdbg->dev) {
  2258. icnss_pr_err("Failed to create m3 dump for Wcssdbg segment device!");
  2259. return -ENOMEM;
  2260. }
  2261. priv->m3_dump_phyapdmem = icnss_create_ramdump_device(priv,
  2262. ICNSS_M3_SEGMENT(
  2263. ICNSS_M3_SEGMENT_PHYAM3));
  2264. if (IS_ERR_OR_NULL(priv->m3_dump_phyapdmem) ||
  2265. !priv->m3_dump_phyapdmem->dev) {
  2266. icnss_pr_err("Failed to create m3 dump for Phyapdmem segment device!");
  2267. return -ENOMEM;
  2268. }
  2269. }
  2270. return 0;
  2271. }
  2272. static int icnss_enable_recovery(struct icnss_priv *priv)
  2273. {
  2274. int ret;
  2275. if (test_bit(RECOVERY_DISABLE, &priv->ctrl_params.quirks)) {
  2276. icnss_pr_dbg("Recovery disabled through module parameter\n");
  2277. return 0;
  2278. }
  2279. if (test_bit(PDR_ONLY, &priv->ctrl_params.quirks)) {
  2280. icnss_pr_dbg("SSR disabled through module parameter\n");
  2281. goto enable_pdr;
  2282. }
  2283. ret = icnss_register_ramdump_devices(priv);
  2284. if (ret)
  2285. return ret;
  2286. if (priv->wpss_supported) {
  2287. icnss_wpss_early_ssr_register_notifier(priv);
  2288. icnss_wpss_ssr_register_notifier(priv);
  2289. return 0;
  2290. }
  2291. icnss_modem_ssr_register_notifier(priv);
  2292. if (priv->is_slate_rfa) {
  2293. icnss_slate_ssr_register_notifier(priv);
  2294. icnss_register_slate_event_notifier(priv);
  2295. }
  2296. if (test_bit(SSR_ONLY, &priv->ctrl_params.quirks)) {
  2297. icnss_pr_dbg("PDR disabled through module parameter\n");
  2298. return 0;
  2299. }
  2300. enable_pdr:
  2301. ret = icnss_pd_restart_enable(priv);
  2302. if (ret)
  2303. return ret;
  2304. return 0;
  2305. }
  2306. static int icnss_dev_id_match(struct icnss_priv *priv,
  2307. struct device_info *dev_info)
  2308. {
  2309. while (dev_info->device_id) {
  2310. if (priv->device_id == dev_info->device_id)
  2311. return 1;
  2312. dev_info++;
  2313. }
  2314. return 0;
  2315. }
  2316. static int icnss_tcdev_get_max_state(struct thermal_cooling_device *tcdev,
  2317. unsigned long *thermal_state)
  2318. {
  2319. struct icnss_thermal_cdev *icnss_tcdev = tcdev->devdata;
  2320. *thermal_state = icnss_tcdev->max_thermal_state;
  2321. return 0;
  2322. }
  2323. static int icnss_tcdev_get_cur_state(struct thermal_cooling_device *tcdev,
  2324. unsigned long *thermal_state)
  2325. {
  2326. struct icnss_thermal_cdev *icnss_tcdev = tcdev->devdata;
  2327. *thermal_state = icnss_tcdev->curr_thermal_state;
  2328. return 0;
  2329. }
  2330. static int icnss_tcdev_set_cur_state(struct thermal_cooling_device *tcdev,
  2331. unsigned long thermal_state)
  2332. {
  2333. struct icnss_thermal_cdev *icnss_tcdev = tcdev->devdata;
  2334. struct device *dev = &penv->pdev->dev;
  2335. int ret = 0;
  2336. if (!penv->ops || !penv->ops->set_therm_cdev_state)
  2337. return 0;
  2338. if (thermal_state > icnss_tcdev->max_thermal_state)
  2339. return -EINVAL;
  2340. icnss_pr_vdbg("Cooling device set current state: %ld,for cdev id %d",
  2341. thermal_state, icnss_tcdev->tcdev_id);
  2342. mutex_lock(&penv->tcdev_lock);
  2343. ret = penv->ops->set_therm_cdev_state(dev, thermal_state,
  2344. icnss_tcdev->tcdev_id);
  2345. if (!ret)
  2346. icnss_tcdev->curr_thermal_state = thermal_state;
  2347. mutex_unlock(&penv->tcdev_lock);
  2348. if (ret) {
  2349. icnss_pr_err("Setting Current Thermal State Failed: %d,for cdev id %d",
  2350. ret, icnss_tcdev->tcdev_id);
  2351. return ret;
  2352. }
  2353. return 0;
  2354. }
  2355. static struct thermal_cooling_device_ops icnss_cooling_ops = {
  2356. .get_max_state = icnss_tcdev_get_max_state,
  2357. .get_cur_state = icnss_tcdev_get_cur_state,
  2358. .set_cur_state = icnss_tcdev_set_cur_state,
  2359. };
  2360. int icnss_thermal_cdev_register(struct device *dev, unsigned long max_state,
  2361. int tcdev_id)
  2362. {
  2363. struct icnss_priv *priv = dev_get_drvdata(dev);
  2364. struct icnss_thermal_cdev *icnss_tcdev = NULL;
  2365. char cdev_node_name[THERMAL_NAME_LENGTH] = "";
  2366. struct device_node *dev_node;
  2367. int ret = 0;
  2368. icnss_tcdev = kzalloc(sizeof(*icnss_tcdev), GFP_KERNEL);
  2369. if (!icnss_tcdev)
  2370. return -ENOMEM;
  2371. icnss_tcdev->tcdev_id = tcdev_id;
  2372. icnss_tcdev->max_thermal_state = max_state;
  2373. snprintf(cdev_node_name, THERMAL_NAME_LENGTH,
  2374. "qcom,icnss_cdev%d", tcdev_id);
  2375. dev_node = of_find_node_by_name(NULL, cdev_node_name);
  2376. if (!dev_node) {
  2377. icnss_pr_err("Failed to get cooling device node\n");
  2378. return -EINVAL;
  2379. }
  2380. icnss_pr_dbg("tcdev node->name=%s\n", dev_node->name);
  2381. if (of_find_property(dev_node, "#cooling-cells", NULL)) {
  2382. icnss_tcdev->tcdev = thermal_of_cooling_device_register(
  2383. dev_node,
  2384. cdev_node_name, icnss_tcdev,
  2385. &icnss_cooling_ops);
  2386. if (IS_ERR_OR_NULL(icnss_tcdev->tcdev)) {
  2387. ret = PTR_ERR(icnss_tcdev->tcdev);
  2388. icnss_pr_err("Cooling device register failed: %d, for cdev id %d\n",
  2389. ret, icnss_tcdev->tcdev_id);
  2390. } else {
  2391. icnss_pr_dbg("Cooling device registered for cdev id %d",
  2392. icnss_tcdev->tcdev_id);
  2393. list_add(&icnss_tcdev->tcdev_list,
  2394. &priv->icnss_tcdev_list);
  2395. }
  2396. } else {
  2397. icnss_pr_dbg("Cooling device registration not supported");
  2398. ret = -EOPNOTSUPP;
  2399. }
  2400. return ret;
  2401. }
  2402. EXPORT_SYMBOL(icnss_thermal_cdev_register);
  2403. void icnss_thermal_cdev_unregister(struct device *dev, int tcdev_id)
  2404. {
  2405. struct icnss_priv *priv = dev_get_drvdata(dev);
  2406. struct icnss_thermal_cdev *icnss_tcdev = NULL;
  2407. while (!list_empty(&priv->icnss_tcdev_list)) {
  2408. icnss_tcdev = list_first_entry(&priv->icnss_tcdev_list,
  2409. struct icnss_thermal_cdev,
  2410. tcdev_list);
  2411. thermal_cooling_device_unregister(icnss_tcdev->tcdev);
  2412. list_del(&icnss_tcdev->tcdev_list);
  2413. kfree(icnss_tcdev);
  2414. }
  2415. }
  2416. EXPORT_SYMBOL(icnss_thermal_cdev_unregister);
  2417. int icnss_get_curr_therm_cdev_state(struct device *dev,
  2418. unsigned long *thermal_state,
  2419. int tcdev_id)
  2420. {
  2421. struct icnss_priv *priv = dev_get_drvdata(dev);
  2422. struct icnss_thermal_cdev *icnss_tcdev = NULL;
  2423. mutex_lock(&priv->tcdev_lock);
  2424. list_for_each_entry(icnss_tcdev, &priv->icnss_tcdev_list, tcdev_list) {
  2425. if (icnss_tcdev->tcdev_id != tcdev_id)
  2426. continue;
  2427. *thermal_state = icnss_tcdev->curr_thermal_state;
  2428. mutex_unlock(&priv->tcdev_lock);
  2429. icnss_pr_dbg("Cooling device current state: %ld, for cdev id %d",
  2430. icnss_tcdev->curr_thermal_state, tcdev_id);
  2431. return 0;
  2432. }
  2433. mutex_unlock(&priv->tcdev_lock);
  2434. icnss_pr_dbg("Cooling device ID not found: %d", tcdev_id);
  2435. return -EINVAL;
  2436. }
  2437. EXPORT_SYMBOL(icnss_get_curr_therm_cdev_state);
  2438. int icnss_qmi_send(struct device *dev, int type, void *cmd,
  2439. int cmd_len, void *cb_ctx,
  2440. int (*cb)(void *ctx, void *event, int event_len))
  2441. {
  2442. struct icnss_priv *priv = icnss_get_plat_priv();
  2443. int ret;
  2444. if (!priv)
  2445. return -ENODEV;
  2446. if (!test_bit(ICNSS_WLFW_CONNECTED, &priv->state))
  2447. return -EINVAL;
  2448. priv->get_info_cb = cb;
  2449. priv->get_info_cb_ctx = cb_ctx;
  2450. ret = icnss_wlfw_get_info_send_sync(priv, type, cmd, cmd_len);
  2451. if (ret) {
  2452. priv->get_info_cb = NULL;
  2453. priv->get_info_cb_ctx = NULL;
  2454. }
  2455. return ret;
  2456. }
  2457. EXPORT_SYMBOL(icnss_qmi_send);
  2458. int __icnss_register_driver(struct icnss_driver_ops *ops,
  2459. struct module *owner, const char *mod_name)
  2460. {
  2461. int ret = 0;
  2462. struct icnss_priv *priv = icnss_get_plat_priv();
  2463. if (!priv || !priv->pdev) {
  2464. ret = -ENODEV;
  2465. goto out;
  2466. }
  2467. icnss_pr_dbg("Registering driver, state: 0x%lx\n", priv->state);
  2468. if (priv->ops) {
  2469. icnss_pr_err("Driver already registered\n");
  2470. ret = -EEXIST;
  2471. goto out;
  2472. }
  2473. if (!ops->dev_info) {
  2474. icnss_pr_err("WLAN driver devinfo is null, Reject wlan driver loading");
  2475. return -EINVAL;
  2476. }
  2477. if (!icnss_dev_id_match(priv, ops->dev_info)) {
  2478. icnss_pr_err("WLAN driver dev name is %s, not supported by platform driver\n",
  2479. ops->dev_info->name);
  2480. return -ENODEV;
  2481. }
  2482. if (!ops->probe || !ops->remove) {
  2483. ret = -EINVAL;
  2484. goto out;
  2485. }
  2486. ret = icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_REGISTER_DRIVER,
  2487. 0, ops);
  2488. if (ret == -EINTR)
  2489. ret = 0;
  2490. out:
  2491. return ret;
  2492. }
  2493. EXPORT_SYMBOL(__icnss_register_driver);
  2494. int icnss_unregister_driver(struct icnss_driver_ops *ops)
  2495. {
  2496. int ret;
  2497. struct icnss_priv *priv = icnss_get_plat_priv();
  2498. if (!priv || !priv->pdev) {
  2499. ret = -ENODEV;
  2500. goto out;
  2501. }
  2502. icnss_pr_dbg("Unregistering driver, state: 0x%lx\n", priv->state);
  2503. if (!priv->ops) {
  2504. icnss_pr_err("Driver not registered\n");
  2505. ret = -ENOENT;
  2506. goto out;
  2507. }
  2508. ret = icnss_driver_event_post(priv,
  2509. ICNSS_DRIVER_EVENT_UNREGISTER_DRIVER,
  2510. ICNSS_EVENT_SYNC_UNINTERRUPTIBLE, NULL);
  2511. out:
  2512. return ret;
  2513. }
  2514. EXPORT_SYMBOL(icnss_unregister_driver);
  2515. static struct icnss_msi_config msi_config_wcn6750 = {
  2516. .total_vectors = 28,
  2517. .total_users = 2,
  2518. .users = (struct icnss_msi_user[]) {
  2519. { .name = "CE", .num_vectors = 10, .base_vector = 0 },
  2520. { .name = "DP", .num_vectors = 18, .base_vector = 10 },
  2521. },
  2522. };
  2523. static struct icnss_msi_config msi_config_wcn6450 = {
  2524. .total_vectors = 10,
  2525. .total_users = 1,
  2526. .users = (struct icnss_msi_user[]) {
  2527. { .name = "CE", .num_vectors = 10, .base_vector = 0 },
  2528. },
  2529. };
  2530. static int icnss_get_msi_assignment(struct icnss_priv *priv)
  2531. {
  2532. if (priv->device_id == WCN6750_DEVICE_ID)
  2533. priv->msi_config = &msi_config_wcn6750;
  2534. else
  2535. priv->msi_config = &msi_config_wcn6450;
  2536. return 0;
  2537. }
  2538. int icnss_get_user_msi_assignment(struct device *dev, char *user_name,
  2539. int *num_vectors, u32 *user_base_data,
  2540. u32 *base_vector)
  2541. {
  2542. struct icnss_priv *priv = dev_get_drvdata(dev);
  2543. struct icnss_msi_config *msi_config;
  2544. int idx;
  2545. if (!priv)
  2546. return -ENODEV;
  2547. msi_config = priv->msi_config;
  2548. if (!msi_config) {
  2549. icnss_pr_err("MSI is not supported.\n");
  2550. return -EINVAL;
  2551. }
  2552. for (idx = 0; idx < msi_config->total_users; idx++) {
  2553. if (strcmp(user_name, msi_config->users[idx].name) == 0) {
  2554. *num_vectors = msi_config->users[idx].num_vectors;
  2555. *user_base_data = msi_config->users[idx].base_vector
  2556. + priv->msi_base_data;
  2557. *base_vector = msi_config->users[idx].base_vector;
  2558. icnss_pr_dbg("Assign MSI to user: %s, num_vectors: %d, user_base_data: %u, base_vector: %u\n",
  2559. user_name, *num_vectors, *user_base_data,
  2560. *base_vector);
  2561. return 0;
  2562. }
  2563. }
  2564. icnss_pr_err("Failed to find MSI assignment for %s!\n", user_name);
  2565. return -EINVAL;
  2566. }
  2567. EXPORT_SYMBOL(icnss_get_user_msi_assignment);
  2568. int icnss_get_msi_irq(struct device *dev, unsigned int vector)
  2569. {
  2570. struct icnss_priv *priv = dev_get_drvdata(dev);
  2571. int irq_num;
  2572. irq_num = priv->srng_irqs[vector];
  2573. icnss_pr_dbg("Get IRQ number %d for vector index %d\n",
  2574. irq_num, vector);
  2575. return irq_num;
  2576. }
  2577. EXPORT_SYMBOL(icnss_get_msi_irq);
  2578. void icnss_get_msi_address(struct device *dev, u32 *msi_addr_low,
  2579. u32 *msi_addr_high)
  2580. {
  2581. struct icnss_priv *priv = dev_get_drvdata(dev);
  2582. *msi_addr_low = lower_32_bits(priv->msi_addr_iova);
  2583. *msi_addr_high = upper_32_bits(priv->msi_addr_iova);
  2584. }
  2585. EXPORT_SYMBOL(icnss_get_msi_address);
  2586. int icnss_ce_request_irq(struct device *dev, unsigned int ce_id,
  2587. irqreturn_t (*handler)(int, void *),
  2588. unsigned long flags, const char *name, void *ctx)
  2589. {
  2590. int ret = 0;
  2591. unsigned int irq;
  2592. struct ce_irq_list *irq_entry;
  2593. struct icnss_priv *priv = dev_get_drvdata(dev);
  2594. if (!priv || !priv->pdev) {
  2595. ret = -ENODEV;
  2596. goto out;
  2597. }
  2598. icnss_pr_vdbg("CE request IRQ: %d, state: 0x%lx\n", ce_id, priv->state);
  2599. if (ce_id >= ICNSS_MAX_IRQ_REGISTRATIONS) {
  2600. icnss_pr_err("Invalid CE ID, ce_id: %d\n", ce_id);
  2601. ret = -EINVAL;
  2602. goto out;
  2603. }
  2604. irq = priv->ce_irqs[ce_id];
  2605. irq_entry = &priv->ce_irq_list[ce_id];
  2606. if (irq_entry->handler || irq_entry->irq) {
  2607. icnss_pr_err("IRQ already requested: %d, ce_id: %d\n",
  2608. irq, ce_id);
  2609. ret = -EEXIST;
  2610. goto out;
  2611. }
  2612. ret = request_irq(irq, handler, flags, name, ctx);
  2613. if (ret) {
  2614. icnss_pr_err("IRQ request failed: %d, ce_id: %d, ret: %d\n",
  2615. irq, ce_id, ret);
  2616. goto out;
  2617. }
  2618. irq_entry->irq = irq;
  2619. irq_entry->handler = handler;
  2620. icnss_pr_vdbg("IRQ requested: %d, ce_id: %d\n", irq, ce_id);
  2621. penv->stats.ce_irqs[ce_id].request++;
  2622. out:
  2623. return ret;
  2624. }
  2625. EXPORT_SYMBOL(icnss_ce_request_irq);
  2626. int icnss_ce_free_irq(struct device *dev, unsigned int ce_id, void *ctx)
  2627. {
  2628. int ret = 0;
  2629. unsigned int irq;
  2630. struct ce_irq_list *irq_entry;
  2631. if (!penv || !penv->pdev || !dev) {
  2632. ret = -ENODEV;
  2633. goto out;
  2634. }
  2635. icnss_pr_vdbg("CE free IRQ: %d, state: 0x%lx\n", ce_id, penv->state);
  2636. if (ce_id >= ICNSS_MAX_IRQ_REGISTRATIONS) {
  2637. icnss_pr_err("Invalid CE ID to free, ce_id: %d\n", ce_id);
  2638. ret = -EINVAL;
  2639. goto out;
  2640. }
  2641. irq = penv->ce_irqs[ce_id];
  2642. irq_entry = &penv->ce_irq_list[ce_id];
  2643. if (!irq_entry->handler || !irq_entry->irq) {
  2644. icnss_pr_err("IRQ not requested: %d, ce_id: %d\n", irq, ce_id);
  2645. ret = -EEXIST;
  2646. goto out;
  2647. }
  2648. free_irq(irq, ctx);
  2649. irq_entry->irq = 0;
  2650. irq_entry->handler = NULL;
  2651. penv->stats.ce_irqs[ce_id].free++;
  2652. out:
  2653. return ret;
  2654. }
  2655. EXPORT_SYMBOL(icnss_ce_free_irq);
  2656. void icnss_enable_irq(struct device *dev, unsigned int ce_id)
  2657. {
  2658. unsigned int irq;
  2659. if (!penv || !penv->pdev || !dev) {
  2660. icnss_pr_err("Platform driver not initialized\n");
  2661. return;
  2662. }
  2663. icnss_pr_vdbg("Enable IRQ: ce_id: %d, state: 0x%lx\n", ce_id,
  2664. penv->state);
  2665. if (ce_id >= ICNSS_MAX_IRQ_REGISTRATIONS) {
  2666. icnss_pr_err("Invalid CE ID to enable IRQ, ce_id: %d\n", ce_id);
  2667. return;
  2668. }
  2669. penv->stats.ce_irqs[ce_id].enable++;
  2670. irq = penv->ce_irqs[ce_id];
  2671. enable_irq(irq);
  2672. }
  2673. EXPORT_SYMBOL(icnss_enable_irq);
  2674. void icnss_disable_irq(struct device *dev, unsigned int ce_id)
  2675. {
  2676. unsigned int irq;
  2677. if (!penv || !penv->pdev || !dev) {
  2678. icnss_pr_err("Platform driver not initialized\n");
  2679. return;
  2680. }
  2681. icnss_pr_vdbg("Disable IRQ: ce_id: %d, state: 0x%lx\n", ce_id,
  2682. penv->state);
  2683. if (ce_id >= ICNSS_MAX_IRQ_REGISTRATIONS) {
  2684. icnss_pr_err("Invalid CE ID to disable IRQ, ce_id: %d\n",
  2685. ce_id);
  2686. return;
  2687. }
  2688. irq = penv->ce_irqs[ce_id];
  2689. disable_irq(irq);
  2690. penv->stats.ce_irqs[ce_id].disable++;
  2691. }
  2692. EXPORT_SYMBOL(icnss_disable_irq);
  2693. int icnss_get_soc_info(struct device *dev, struct icnss_soc_info *info)
  2694. {
  2695. char *fw_build_timestamp = NULL;
  2696. struct icnss_priv *priv = dev_get_drvdata(dev);
  2697. if (!priv) {
  2698. icnss_pr_err("Platform driver not initialized\n");
  2699. return -EINVAL;
  2700. }
  2701. info->v_addr = priv->mem_base_va;
  2702. info->p_addr = priv->mem_base_pa;
  2703. info->chip_id = priv->chip_info.chip_id;
  2704. info->chip_family = priv->chip_info.chip_family;
  2705. info->board_id = priv->board_id;
  2706. info->soc_id = priv->soc_id;
  2707. info->fw_version = priv->fw_version_info.fw_version;
  2708. fw_build_timestamp = priv->fw_version_info.fw_build_timestamp;
  2709. fw_build_timestamp[WLFW_MAX_TIMESTAMP_LEN] = '\0';
  2710. strlcpy(info->fw_build_timestamp,
  2711. priv->fw_version_info.fw_build_timestamp,
  2712. WLFW_MAX_TIMESTAMP_LEN + 1);
  2713. strlcpy(info->fw_build_id, priv->fw_build_id,
  2714. ICNSS_WLFW_MAX_BUILD_ID_LEN + 1);
  2715. return 0;
  2716. }
  2717. EXPORT_SYMBOL(icnss_get_soc_info);
  2718. int icnss_get_mhi_state(struct device *dev)
  2719. {
  2720. struct icnss_priv *priv = dev_get_drvdata(dev);
  2721. if (!priv) {
  2722. icnss_pr_err("Platform driver not initialized\n");
  2723. return -EINVAL;
  2724. }
  2725. if (!priv->mhi_state_info_va)
  2726. return -ENOMEM;
  2727. return ioread32(priv->mhi_state_info_va);
  2728. }
  2729. EXPORT_SYMBOL(icnss_get_mhi_state);
  2730. int icnss_set_fw_log_mode(struct device *dev, uint8_t fw_log_mode)
  2731. {
  2732. int ret;
  2733. struct icnss_priv *priv;
  2734. if (!dev)
  2735. return -ENODEV;
  2736. priv = dev_get_drvdata(dev);
  2737. if (!priv) {
  2738. icnss_pr_err("Platform driver not initialized\n");
  2739. return -EINVAL;
  2740. }
  2741. if (test_bit(ICNSS_FW_DOWN, &penv->state) ||
  2742. !test_bit(ICNSS_FW_READY, &penv->state)) {
  2743. icnss_pr_err("FW down, ignoring fw_log_mode state: 0x%lx\n",
  2744. priv->state);
  2745. return -EINVAL;
  2746. }
  2747. icnss_pr_dbg("FW log mode: %u\n", fw_log_mode);
  2748. ret = wlfw_ini_send_sync_msg(priv, fw_log_mode);
  2749. if (ret)
  2750. icnss_pr_err("Fail to send ini, ret = %d, fw_log_mode: %u\n",
  2751. ret, fw_log_mode);
  2752. return ret;
  2753. }
  2754. EXPORT_SYMBOL(icnss_set_fw_log_mode);
  2755. int icnss_force_wake_request(struct device *dev)
  2756. {
  2757. struct icnss_priv *priv;
  2758. if (!dev)
  2759. return -ENODEV;
  2760. priv = dev_get_drvdata(dev);
  2761. if (!priv) {
  2762. icnss_pr_err("Platform driver not initialized\n");
  2763. return -EINVAL;
  2764. }
  2765. if (test_bit(ICNSS_FW_DOWN, &priv->state) ||
  2766. !test_bit(ICNSS_FW_READY, &priv->state)) {
  2767. icnss_pr_soc_wake("FW down, ignoring SOC Wake request state: 0x%lx\n",
  2768. priv->state);
  2769. return -EINVAL;
  2770. }
  2771. if (atomic_inc_not_zero(&priv->soc_wake_ref_count)) {
  2772. icnss_pr_soc_wake("SOC already awake, Ref count: %d",
  2773. atomic_read(&priv->soc_wake_ref_count));
  2774. return 0;
  2775. }
  2776. icnss_pr_soc_wake("Calling SOC Wake request");
  2777. icnss_soc_wake_event_post(priv, ICNSS_SOC_WAKE_REQUEST_EVENT,
  2778. 0, NULL);
  2779. return 0;
  2780. }
  2781. EXPORT_SYMBOL(icnss_force_wake_request);
  2782. int icnss_force_wake_release(struct device *dev)
  2783. {
  2784. struct icnss_priv *priv;
  2785. if (!dev)
  2786. return -ENODEV;
  2787. priv = dev_get_drvdata(dev);
  2788. if (!priv) {
  2789. icnss_pr_err("Platform driver not initialized\n");
  2790. return -EINVAL;
  2791. }
  2792. if (test_bit(ICNSS_FW_DOWN, &priv->state) ||
  2793. !test_bit(ICNSS_FW_READY, &priv->state)) {
  2794. icnss_pr_soc_wake("FW down, ignoring SOC Wake release state: 0x%lx\n",
  2795. priv->state);
  2796. return -EINVAL;
  2797. }
  2798. icnss_pr_soc_wake("Calling SOC Wake response");
  2799. if (atomic_read(&priv->soc_wake_ref_count) &&
  2800. icnss_atomic_dec_if_greater_one(&priv->soc_wake_ref_count)) {
  2801. icnss_pr_soc_wake("SOC previous release pending, Ref count: %d",
  2802. atomic_read(&priv->soc_wake_ref_count));
  2803. return 0;
  2804. }
  2805. icnss_soc_wake_event_post(priv, ICNSS_SOC_WAKE_RELEASE_EVENT,
  2806. 0, NULL);
  2807. return 0;
  2808. }
  2809. EXPORT_SYMBOL(icnss_force_wake_release);
  2810. int icnss_is_device_awake(struct device *dev)
  2811. {
  2812. struct icnss_priv *priv = dev_get_drvdata(dev);
  2813. if (!priv) {
  2814. icnss_pr_err("Platform driver not initialized\n");
  2815. return -EINVAL;
  2816. }
  2817. return atomic_read(&priv->soc_wake_ref_count);
  2818. }
  2819. EXPORT_SYMBOL(icnss_is_device_awake);
  2820. int icnss_is_pci_ep_awake(struct device *dev)
  2821. {
  2822. struct icnss_priv *priv = dev_get_drvdata(dev);
  2823. if (!priv) {
  2824. icnss_pr_err("Platform driver not initialized\n");
  2825. return -EINVAL;
  2826. }
  2827. if (!priv->mhi_state_info_va)
  2828. return -ENOMEM;
  2829. return ioread32(priv->mhi_state_info_va + ICNSS_PCI_EP_WAKE_OFFSET);
  2830. }
  2831. EXPORT_SYMBOL(icnss_is_pci_ep_awake);
  2832. int icnss_athdiag_read(struct device *dev, uint32_t offset,
  2833. uint32_t mem_type, uint32_t data_len,
  2834. uint8_t *output)
  2835. {
  2836. int ret = 0;
  2837. struct icnss_priv *priv = dev_get_drvdata(dev);
  2838. if (priv->magic != ICNSS_MAGIC) {
  2839. icnss_pr_err("Invalid drvdata for diag read: dev %pK, data %pK, magic 0x%x\n",
  2840. dev, priv, priv->magic);
  2841. return -EINVAL;
  2842. }
  2843. if (!output || data_len == 0
  2844. || data_len > WLFW_MAX_DATA_SIZE) {
  2845. icnss_pr_err("Invalid parameters for diag read: output %pK, data_len %u\n",
  2846. output, data_len);
  2847. ret = -EINVAL;
  2848. goto out;
  2849. }
  2850. if (!test_bit(ICNSS_FW_READY, &priv->state) ||
  2851. !test_bit(ICNSS_POWER_ON, &priv->state)) {
  2852. icnss_pr_err("Invalid state for diag read: 0x%lx\n",
  2853. priv->state);
  2854. ret = -EINVAL;
  2855. goto out;
  2856. }
  2857. ret = wlfw_athdiag_read_send_sync_msg(priv, offset, mem_type,
  2858. data_len, output);
  2859. out:
  2860. return ret;
  2861. }
  2862. EXPORT_SYMBOL(icnss_athdiag_read);
  2863. int icnss_athdiag_write(struct device *dev, uint32_t offset,
  2864. uint32_t mem_type, uint32_t data_len,
  2865. uint8_t *input)
  2866. {
  2867. int ret = 0;
  2868. struct icnss_priv *priv = dev_get_drvdata(dev);
  2869. if (priv->magic != ICNSS_MAGIC) {
  2870. icnss_pr_err("Invalid drvdata for diag write: dev %pK, data %pK, magic 0x%x\n",
  2871. dev, priv, priv->magic);
  2872. return -EINVAL;
  2873. }
  2874. if (!input || data_len == 0
  2875. || data_len > WLFW_MAX_DATA_SIZE) {
  2876. icnss_pr_err("Invalid parameters for diag write: input %pK, data_len %u\n",
  2877. input, data_len);
  2878. ret = -EINVAL;
  2879. goto out;
  2880. }
  2881. if (!test_bit(ICNSS_FW_READY, &priv->state) ||
  2882. !test_bit(ICNSS_POWER_ON, &priv->state)) {
  2883. icnss_pr_err("Invalid state for diag write: 0x%lx\n",
  2884. priv->state);
  2885. ret = -EINVAL;
  2886. goto out;
  2887. }
  2888. ret = wlfw_athdiag_write_send_sync_msg(priv, offset, mem_type,
  2889. data_len, input);
  2890. out:
  2891. return ret;
  2892. }
  2893. EXPORT_SYMBOL(icnss_athdiag_write);
  2894. int icnss_wlan_enable(struct device *dev, struct icnss_wlan_enable_cfg *config,
  2895. enum icnss_driver_mode mode,
  2896. const char *host_version)
  2897. {
  2898. struct icnss_priv *priv = dev_get_drvdata(dev);
  2899. int temp = 0, ret = 0;
  2900. if (test_bit(ICNSS_FW_DOWN, &priv->state) ||
  2901. !test_bit(ICNSS_FW_READY, &priv->state)) {
  2902. icnss_pr_err("FW down, ignoring wlan_enable state: 0x%lx\n",
  2903. priv->state);
  2904. return -EINVAL;
  2905. }
  2906. if (test_bit(ICNSS_MODE_ON, &priv->state)) {
  2907. icnss_pr_err("Already Mode on, ignoring wlan_enable state: 0x%lx\n",
  2908. priv->state);
  2909. return -EINVAL;
  2910. }
  2911. if (priv->wpss_supported &&
  2912. !priv->dms.nv_mac_not_prov && !priv->dms.mac_valid)
  2913. icnss_setup_dms_mac(priv);
  2914. if (priv->device_id == WCN6750_DEVICE_ID) {
  2915. if (!icnss_get_temperature(priv, &temp)) {
  2916. icnss_pr_dbg("Temperature: %d\n", temp);
  2917. if (temp < WLAN_EN_TEMP_THRESHOLD)
  2918. icnss_set_wlan_en_delay(priv);
  2919. }
  2920. }
  2921. if (priv->device_id == WCN6450_DEVICE_ID)
  2922. icnss_hw_power_off(priv);
  2923. ret = icnss_send_wlan_enable_to_fw(priv, config, mode, host_version);
  2924. if (priv->device_id == WCN6450_DEVICE_ID)
  2925. icnss_hw_power_on(priv);
  2926. return ret;
  2927. }
  2928. EXPORT_SYMBOL(icnss_wlan_enable);
  2929. int icnss_wlan_disable(struct device *dev, enum icnss_driver_mode mode)
  2930. {
  2931. struct icnss_priv *priv = dev_get_drvdata(dev);
  2932. if (test_bit(ICNSS_FW_DOWN, &priv->state)) {
  2933. icnss_pr_dbg("FW down, ignoring wlan_disable state: 0x%lx\n",
  2934. priv->state);
  2935. return 0;
  2936. }
  2937. return icnss_send_wlan_disable_to_fw(priv);
  2938. }
  2939. EXPORT_SYMBOL(icnss_wlan_disable);
  2940. bool icnss_is_qmi_disable(struct device *dev)
  2941. {
  2942. return test_bit(SKIP_QMI, &penv->ctrl_params.quirks) ? true : false;
  2943. }
  2944. EXPORT_SYMBOL(icnss_is_qmi_disable);
  2945. int icnss_get_ce_id(struct device *dev, int irq)
  2946. {
  2947. int i;
  2948. if (!penv || !penv->pdev || !dev)
  2949. return -ENODEV;
  2950. for (i = 0; i < ICNSS_MAX_IRQ_REGISTRATIONS; i++) {
  2951. if (penv->ce_irqs[i] == irq)
  2952. return i;
  2953. }
  2954. icnss_pr_err("No matching CE id for irq %d\n", irq);
  2955. return -EINVAL;
  2956. }
  2957. EXPORT_SYMBOL(icnss_get_ce_id);
  2958. int icnss_get_irq(struct device *dev, int ce_id)
  2959. {
  2960. int irq;
  2961. if (!penv || !penv->pdev || !dev)
  2962. return -ENODEV;
  2963. if (ce_id >= ICNSS_MAX_IRQ_REGISTRATIONS)
  2964. return -EINVAL;
  2965. irq = penv->ce_irqs[ce_id];
  2966. return irq;
  2967. }
  2968. EXPORT_SYMBOL(icnss_get_irq);
  2969. struct iommu_domain *icnss_smmu_get_domain(struct device *dev)
  2970. {
  2971. struct icnss_priv *priv = dev_get_drvdata(dev);
  2972. if (!priv) {
  2973. icnss_pr_err("Invalid drvdata: dev %pK\n", dev);
  2974. return NULL;
  2975. }
  2976. return priv->iommu_domain;
  2977. }
  2978. EXPORT_SYMBOL(icnss_smmu_get_domain);
  2979. int icnss_smmu_map(struct device *dev,
  2980. phys_addr_t paddr, uint32_t *iova_addr, size_t size)
  2981. {
  2982. struct icnss_priv *priv = dev_get_drvdata(dev);
  2983. int flag = IOMMU_READ | IOMMU_WRITE;
  2984. bool dma_coherent = false;
  2985. unsigned long iova;
  2986. int prop_len = 0;
  2987. size_t len;
  2988. int ret = 0;
  2989. if (!priv) {
  2990. icnss_pr_err("Invalid drvdata: dev %pK, data %pK\n",
  2991. dev, priv);
  2992. return -EINVAL;
  2993. }
  2994. if (!iova_addr) {
  2995. icnss_pr_err("iova_addr is NULL, paddr %pa, size %zu\n",
  2996. &paddr, size);
  2997. return -EINVAL;
  2998. }
  2999. len = roundup(size + paddr - rounddown(paddr, PAGE_SIZE), PAGE_SIZE);
  3000. iova = roundup(priv->smmu_iova_ipa_current, PAGE_SIZE);
  3001. if (of_get_property(dev->of_node, "qcom,iommu-geometry", &prop_len) &&
  3002. iova >= priv->smmu_iova_ipa_start + priv->smmu_iova_ipa_len) {
  3003. icnss_pr_err("No IOVA space to map, iova %lx, smmu_iova_ipa_start %pad, smmu_iova_ipa_len %zu\n",
  3004. iova,
  3005. &priv->smmu_iova_ipa_start,
  3006. priv->smmu_iova_ipa_len);
  3007. return -ENOMEM;
  3008. }
  3009. dma_coherent = of_property_read_bool(dev->of_node, "dma-coherent");
  3010. icnss_pr_dbg("dma-coherent is %s\n",
  3011. dma_coherent ? "enabled" : "disabled");
  3012. if (dma_coherent)
  3013. flag |= IOMMU_CACHE;
  3014. icnss_pr_dbg("IOMMU Map: iova %lx, len %zu\n", iova, len);
  3015. ret = iommu_map(priv->iommu_domain, iova,
  3016. rounddown(paddr, PAGE_SIZE), len,
  3017. flag);
  3018. if (ret) {
  3019. icnss_pr_err("PA to IOVA mapping failed, ret %d\n", ret);
  3020. return ret;
  3021. }
  3022. priv->smmu_iova_ipa_current = iova + len;
  3023. *iova_addr = (uint32_t)(iova + paddr - rounddown(paddr, PAGE_SIZE));
  3024. icnss_pr_dbg("IOVA addr mapped to physical addr %lx\n", *iova_addr);
  3025. return 0;
  3026. }
  3027. EXPORT_SYMBOL(icnss_smmu_map);
  3028. int icnss_smmu_unmap(struct device *dev,
  3029. uint32_t iova_addr, size_t size)
  3030. {
  3031. struct icnss_priv *priv = dev_get_drvdata(dev);
  3032. unsigned long iova;
  3033. size_t len, unmapped_len;
  3034. if (!priv) {
  3035. icnss_pr_err("Invalid drvdata: dev %pK, data %pK\n",
  3036. dev, priv);
  3037. return -EINVAL;
  3038. }
  3039. if (!iova_addr) {
  3040. icnss_pr_err("iova_addr is NULL, size %zu\n",
  3041. size);
  3042. return -EINVAL;
  3043. }
  3044. len = roundup(size + iova_addr - rounddown(iova_addr, PAGE_SIZE),
  3045. PAGE_SIZE);
  3046. iova = rounddown(iova_addr, PAGE_SIZE);
  3047. if (iova >= priv->smmu_iova_ipa_start + priv->smmu_iova_ipa_len) {
  3048. icnss_pr_err("Out of IOVA space during unmap, iova %lx, smmu_iova_ipa_start %pad, smmu_iova_ipa_len %zu\n",
  3049. iova,
  3050. &priv->smmu_iova_ipa_start,
  3051. priv->smmu_iova_ipa_len);
  3052. return -ENOMEM;
  3053. }
  3054. icnss_pr_dbg("IOMMU Unmap: iova %lx, len %zu\n",
  3055. iova, len);
  3056. unmapped_len = iommu_unmap(priv->iommu_domain, iova, len);
  3057. if (unmapped_len != len) {
  3058. icnss_pr_err("Failed to unmap, %zu\n", unmapped_len);
  3059. return -EINVAL;
  3060. }
  3061. priv->smmu_iova_ipa_current = iova;
  3062. return 0;
  3063. }
  3064. EXPORT_SYMBOL(icnss_smmu_unmap);
  3065. unsigned int icnss_socinfo_get_serial_number(struct device *dev)
  3066. {
  3067. return socinfo_get_serial_number();
  3068. }
  3069. EXPORT_SYMBOL(icnss_socinfo_get_serial_number);
  3070. int icnss_trigger_recovery(struct device *dev)
  3071. {
  3072. int ret = 0;
  3073. struct icnss_priv *priv = dev_get_drvdata(dev);
  3074. if (priv->magic != ICNSS_MAGIC) {
  3075. icnss_pr_err("Invalid drvdata: magic 0x%x\n", priv->magic);
  3076. ret = -EINVAL;
  3077. goto out;
  3078. }
  3079. if (test_bit(ICNSS_PD_RESTART, &priv->state)) {
  3080. icnss_pr_err("PD recovery already in progress: state: 0x%lx\n",
  3081. priv->state);
  3082. ret = -EPERM;
  3083. goto out;
  3084. }
  3085. if (priv->wpss_supported) {
  3086. icnss_pr_vdbg("Initiate Root PD restart");
  3087. ret = icnss_send_smp2p(priv, ICNSS_TRIGGER_SSR,
  3088. ICNSS_SMP2P_OUT_POWER_SAVE);
  3089. if (!ret)
  3090. set_bit(ICNSS_HOST_TRIGGERED_PDR, &priv->state);
  3091. return ret;
  3092. }
  3093. if (!test_bit(ICNSS_PDR_REGISTERED, &priv->state)) {
  3094. icnss_pr_err("PD restart not enabled to trigger recovery: state: 0x%lx\n",
  3095. priv->state);
  3096. ret = -EOPNOTSUPP;
  3097. goto out;
  3098. }
  3099. icnss_pr_warn("Initiate PD restart at WLAN FW, state: 0x%lx\n",
  3100. priv->state);
  3101. ret = pdr_restart_pd(priv->pdr_handle, priv->pdr_service);
  3102. if (!ret)
  3103. set_bit(ICNSS_HOST_TRIGGERED_PDR, &priv->state);
  3104. out:
  3105. return ret;
  3106. }
  3107. EXPORT_SYMBOL(icnss_trigger_recovery);
  3108. int icnss_idle_shutdown(struct device *dev)
  3109. {
  3110. struct icnss_priv *priv = dev_get_drvdata(dev);
  3111. if (!priv) {
  3112. icnss_pr_err("Invalid drvdata: dev %pK", dev);
  3113. return -EINVAL;
  3114. }
  3115. if (priv->is_ssr || test_bit(ICNSS_PDR, &priv->state) ||
  3116. test_bit(ICNSS_REJUVENATE, &priv->state)) {
  3117. icnss_pr_err("SSR/PDR is already in-progress during idle shutdown\n");
  3118. return -EBUSY;
  3119. }
  3120. return icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_IDLE_SHUTDOWN,
  3121. ICNSS_EVENT_SYNC_UNINTERRUPTIBLE, NULL);
  3122. }
  3123. EXPORT_SYMBOL(icnss_idle_shutdown);
  3124. int icnss_idle_restart(struct device *dev)
  3125. {
  3126. struct icnss_priv *priv = dev_get_drvdata(dev);
  3127. if (!priv) {
  3128. icnss_pr_err("Invalid drvdata: dev %pK", dev);
  3129. return -EINVAL;
  3130. }
  3131. if (priv->is_ssr || test_bit(ICNSS_PDR, &priv->state) ||
  3132. test_bit(ICNSS_REJUVENATE, &priv->state)) {
  3133. icnss_pr_err("SSR/PDR is already in-progress during idle restart\n");
  3134. return -EBUSY;
  3135. }
  3136. return icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_IDLE_RESTART,
  3137. ICNSS_EVENT_SYNC_UNINTERRUPTIBLE, NULL);
  3138. }
  3139. EXPORT_SYMBOL(icnss_idle_restart);
  3140. int icnss_exit_power_save(struct device *dev)
  3141. {
  3142. struct icnss_priv *priv = dev_get_drvdata(dev);
  3143. icnss_pr_vdbg("Calling Exit Power Save\n");
  3144. if (test_bit(ICNSS_PD_RESTART, &priv->state) ||
  3145. !test_bit(ICNSS_MODE_ON, &priv->state))
  3146. return 0;
  3147. return icnss_send_smp2p(priv, ICNSS_POWER_SAVE_EXIT,
  3148. ICNSS_SMP2P_OUT_POWER_SAVE);
  3149. }
  3150. EXPORT_SYMBOL(icnss_exit_power_save);
  3151. int icnss_prevent_l1(struct device *dev)
  3152. {
  3153. struct icnss_priv *priv = dev_get_drvdata(dev);
  3154. if (test_bit(ICNSS_PD_RESTART, &priv->state) ||
  3155. !test_bit(ICNSS_MODE_ON, &priv->state))
  3156. return 0;
  3157. return icnss_send_smp2p(priv, ICNSS_PCI_EP_POWER_SAVE_EXIT,
  3158. ICNSS_SMP2P_OUT_EP_POWER_SAVE);
  3159. }
  3160. EXPORT_SYMBOL(icnss_prevent_l1);
  3161. void icnss_allow_l1(struct device *dev)
  3162. {
  3163. struct icnss_priv *priv = dev_get_drvdata(dev);
  3164. if (test_bit(ICNSS_PD_RESTART, &priv->state) ||
  3165. !test_bit(ICNSS_MODE_ON, &priv->state))
  3166. return;
  3167. icnss_send_smp2p(priv, ICNSS_PCI_EP_POWER_SAVE_ENTER,
  3168. ICNSS_SMP2P_OUT_EP_POWER_SAVE);
  3169. }
  3170. EXPORT_SYMBOL(icnss_allow_l1);
  3171. void icnss_allow_recursive_recovery(struct device *dev)
  3172. {
  3173. struct icnss_priv *priv = dev_get_drvdata(dev);
  3174. priv->allow_recursive_recovery = true;
  3175. icnss_pr_info("Recursive recovery allowed for WLAN\n");
  3176. }
  3177. void icnss_disallow_recursive_recovery(struct device *dev)
  3178. {
  3179. struct icnss_priv *priv = dev_get_drvdata(dev);
  3180. priv->allow_recursive_recovery = false;
  3181. icnss_pr_info("Recursive recovery disallowed for WLAN\n");
  3182. }
  3183. static int icnss_create_shutdown_sysfs(struct icnss_priv *priv)
  3184. {
  3185. struct kobject *icnss_kobject;
  3186. int ret = 0;
  3187. atomic_set(&priv->is_shutdown, false);
  3188. icnss_kobject = kobject_create_and_add("shutdown_wlan", kernel_kobj);
  3189. if (!icnss_kobject) {
  3190. icnss_pr_err("Unable to create shutdown_wlan kernel object");
  3191. return -EINVAL;
  3192. }
  3193. priv->icnss_kobject = icnss_kobject;
  3194. ret = sysfs_create_file(icnss_kobject, &icnss_sysfs_attribute.attr);
  3195. if (ret) {
  3196. icnss_pr_err("Unable to create icnss sysfs file err:%d", ret);
  3197. return ret;
  3198. }
  3199. return ret;
  3200. }
  3201. static void icnss_destroy_shutdown_sysfs(struct icnss_priv *priv)
  3202. {
  3203. struct kobject *icnss_kobject;
  3204. icnss_kobject = priv->icnss_kobject;
  3205. if (icnss_kobject)
  3206. kobject_put(icnss_kobject);
  3207. }
  3208. static ssize_t qdss_tr_start_store(struct device *dev,
  3209. struct device_attribute *attr,
  3210. const char *buf, size_t count)
  3211. {
  3212. struct icnss_priv *priv = dev_get_drvdata(dev);
  3213. wlfw_qdss_trace_start(priv);
  3214. icnss_pr_dbg("Received QDSS start command\n");
  3215. return count;
  3216. }
  3217. static ssize_t qdss_tr_stop_store(struct device *dev,
  3218. struct device_attribute *attr,
  3219. const char *user_buf, size_t count)
  3220. {
  3221. struct icnss_priv *priv = dev_get_drvdata(dev);
  3222. u32 option = 0;
  3223. if (sscanf(user_buf, "%du", &option) != 1)
  3224. return -EINVAL;
  3225. wlfw_qdss_trace_stop(priv, option);
  3226. icnss_pr_dbg("Received QDSS stop command\n");
  3227. return count;
  3228. }
  3229. static ssize_t qdss_conf_download_store(struct device *dev,
  3230. struct device_attribute *attr,
  3231. const char *buf, size_t count)
  3232. {
  3233. struct icnss_priv *priv = dev_get_drvdata(dev);
  3234. icnss_wlfw_qdss_dnld_send_sync(priv);
  3235. icnss_pr_dbg("Received QDSS download config command\n");
  3236. return count;
  3237. }
  3238. static ssize_t hw_trc_override_store(struct device *dev,
  3239. struct device_attribute *attr,
  3240. const char *buf, size_t count)
  3241. {
  3242. struct icnss_priv *priv = dev_get_drvdata(dev);
  3243. int tmp = 0;
  3244. if (sscanf(buf, "%du", &tmp) != 1)
  3245. return -EINVAL;
  3246. priv->hw_trc_override = tmp;
  3247. icnss_pr_dbg("Received QDSS hw_trc_override indication\n");
  3248. return count;
  3249. }
  3250. static void icnss_wpss_load(struct work_struct *wpss_load_work)
  3251. {
  3252. struct icnss_priv *priv = icnss_get_plat_priv();
  3253. phandle rproc_phandle;
  3254. int ret;
  3255. if (of_property_read_u32(priv->pdev->dev.of_node, "qcom,rproc-handle",
  3256. &rproc_phandle)) {
  3257. icnss_pr_err("error reading rproc phandle\n");
  3258. return;
  3259. }
  3260. priv->rproc = rproc_get_by_phandle(rproc_phandle);
  3261. if (IS_ERR_OR_NULL(priv->rproc)) {
  3262. icnss_pr_err("rproc not found");
  3263. return;
  3264. }
  3265. ret = rproc_boot(priv->rproc);
  3266. if (ret) {
  3267. icnss_pr_err("Failed to boot wpss rproc, ret: %d", ret);
  3268. rproc_put(priv->rproc);
  3269. }
  3270. }
  3271. static ssize_t wpss_boot_store(struct device *dev,
  3272. struct device_attribute *attr,
  3273. const char *buf, size_t count)
  3274. {
  3275. struct icnss_priv *priv = dev_get_drvdata(dev);
  3276. int wpss_rproc = 0;
  3277. if (!priv->wpss_supported)
  3278. return count;
  3279. if (sscanf(buf, "%du", &wpss_rproc) != 1) {
  3280. icnss_pr_err("Failed to read wpss rproc info");
  3281. return -EINVAL;
  3282. }
  3283. icnss_pr_dbg("WPSS Remote Processor: %s", wpss_rproc ? "GET" : "PUT");
  3284. if (wpss_rproc == 1)
  3285. schedule_work(&wpss_loader);
  3286. else if (wpss_rproc == 0)
  3287. icnss_wpss_unload(priv);
  3288. return count;
  3289. }
  3290. static ssize_t wlan_en_delay_store(struct device *dev,
  3291. struct device_attribute *attr,
  3292. const char *buf, size_t count)
  3293. {
  3294. struct icnss_priv *priv = dev_get_drvdata(dev);
  3295. uint32_t wlan_en_delay = 0;
  3296. if (priv->device_id == ADRASTEA_DEVICE_ID)
  3297. return count;
  3298. if (sscanf(buf, "%du", &wlan_en_delay) != 1) {
  3299. icnss_pr_err("Failed to read wlan_en_delay");
  3300. return -EINVAL;
  3301. }
  3302. icnss_pr_dbg("WLAN_EN delay: %dms", wlan_en_delay);
  3303. priv->wlan_en_delay_ms_user = wlan_en_delay;
  3304. return count;
  3305. }
  3306. static DEVICE_ATTR_WO(qdss_tr_start);
  3307. static DEVICE_ATTR_WO(qdss_tr_stop);
  3308. static DEVICE_ATTR_WO(qdss_conf_download);
  3309. static DEVICE_ATTR_WO(hw_trc_override);
  3310. static DEVICE_ATTR_WO(wpss_boot);
  3311. static DEVICE_ATTR_WO(wlan_en_delay);
  3312. static struct attribute *icnss_attrs[] = {
  3313. &dev_attr_qdss_tr_start.attr,
  3314. &dev_attr_qdss_tr_stop.attr,
  3315. &dev_attr_qdss_conf_download.attr,
  3316. &dev_attr_hw_trc_override.attr,
  3317. &dev_attr_wpss_boot.attr,
  3318. &dev_attr_wlan_en_delay.attr,
  3319. NULL,
  3320. };
  3321. static struct attribute_group icnss_attr_group = {
  3322. .attrs = icnss_attrs,
  3323. };
  3324. static int icnss_create_sysfs_link(struct icnss_priv *priv)
  3325. {
  3326. struct device *dev = &priv->pdev->dev;
  3327. int ret;
  3328. ret = sysfs_create_link(kernel_kobj, &dev->kobj, "icnss");
  3329. if (ret) {
  3330. icnss_pr_err("Failed to create icnss link, err = %d\n",
  3331. ret);
  3332. goto out;
  3333. }
  3334. return 0;
  3335. out:
  3336. return ret;
  3337. }
  3338. static void icnss_remove_sysfs_link(struct icnss_priv *priv)
  3339. {
  3340. sysfs_remove_link(kernel_kobj, "icnss");
  3341. }
  3342. static int icnss_sysfs_create(struct icnss_priv *priv)
  3343. {
  3344. int ret = 0;
  3345. ret = devm_device_add_group(&priv->pdev->dev,
  3346. &icnss_attr_group);
  3347. if (ret) {
  3348. icnss_pr_err("Failed to create icnss device group, err = %d\n",
  3349. ret);
  3350. goto out;
  3351. }
  3352. icnss_create_sysfs_link(priv);
  3353. ret = icnss_create_shutdown_sysfs(priv);
  3354. if (ret)
  3355. goto remove_icnss_group;
  3356. return 0;
  3357. remove_icnss_group:
  3358. devm_device_remove_group(&priv->pdev->dev, &icnss_attr_group);
  3359. out:
  3360. return ret;
  3361. }
  3362. static void icnss_sysfs_destroy(struct icnss_priv *priv)
  3363. {
  3364. icnss_destroy_shutdown_sysfs(priv);
  3365. icnss_remove_sysfs_link(priv);
  3366. devm_device_remove_group(&priv->pdev->dev, &icnss_attr_group);
  3367. }
  3368. static int icnss_resource_parse(struct icnss_priv *priv)
  3369. {
  3370. int ret = 0, i = 0;
  3371. struct platform_device *pdev = priv->pdev;
  3372. struct device *dev = &pdev->dev;
  3373. struct resource *res;
  3374. u32 int_prop;
  3375. ret = icnss_get_vreg(priv);
  3376. if (ret) {
  3377. icnss_pr_err("Failed to get vreg, err = %d\n", ret);
  3378. goto out;
  3379. }
  3380. ret = icnss_get_clk(priv);
  3381. if (ret) {
  3382. icnss_pr_err("Failed to get clocks, err = %d\n", ret);
  3383. goto put_vreg;
  3384. }
  3385. if (of_property_read_bool(pdev->dev.of_node, "qcom,psf-supported")) {
  3386. ret = icnss_get_psf_info(priv);
  3387. if (ret < 0)
  3388. goto out;
  3389. priv->psf_supported = true;
  3390. }
  3391. if (priv->device_id == ADRASTEA_DEVICE_ID) {
  3392. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  3393. "membase");
  3394. if (!res) {
  3395. icnss_pr_err("Memory base not found in DT\n");
  3396. ret = -EINVAL;
  3397. goto put_clk;
  3398. }
  3399. priv->mem_base_pa = res->start;
  3400. priv->mem_base_va = devm_ioremap(dev, priv->mem_base_pa,
  3401. resource_size(res));
  3402. if (!priv->mem_base_va) {
  3403. icnss_pr_err("Memory base ioremap failed: phy addr: %pa\n",
  3404. &priv->mem_base_pa);
  3405. ret = -EINVAL;
  3406. goto put_clk;
  3407. }
  3408. icnss_pr_dbg("MEM_BASE pa: %pa, va: 0x%pK\n",
  3409. &priv->mem_base_pa,
  3410. priv->mem_base_va);
  3411. for (i = 0; i < ICNSS_MAX_IRQ_REGISTRATIONS; i++) {
  3412. res = platform_get_resource(priv->pdev,
  3413. IORESOURCE_IRQ, i);
  3414. if (!res) {
  3415. icnss_pr_err("Fail to get IRQ-%d\n", i);
  3416. ret = -ENODEV;
  3417. goto put_clk;
  3418. } else {
  3419. priv->ce_irqs[i] = res->start;
  3420. }
  3421. }
  3422. if (of_property_read_bool(pdev->dev.of_node,
  3423. "qcom,is_low_power")) {
  3424. priv->low_power_support = true;
  3425. icnss_pr_dbg("Deep Sleep/Hibernate mode supported\n");
  3426. }
  3427. if (of_property_read_u32(pdev->dev.of_node, "qcom,rf_subtype",
  3428. &priv->rf_subtype) == 0) {
  3429. priv->is_rf_subtype_valid = true;
  3430. icnss_pr_dbg("RF subtype 0x%x\n", priv->rf_subtype);
  3431. }
  3432. if (of_property_read_bool(pdev->dev.of_node,
  3433. "qcom,is_slate_rfa")) {
  3434. priv->is_slate_rfa = true;
  3435. icnss_pr_err("SLATE rfa is enabled\n");
  3436. }
  3437. } else if (priv->device_id == WCN6750_DEVICE_ID ||
  3438. priv->device_id == WCN6450_DEVICE_ID) {
  3439. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  3440. "msi_addr");
  3441. if (!res) {
  3442. icnss_pr_err("MSI address not found in DT\n");
  3443. ret = -EINVAL;
  3444. goto put_clk;
  3445. }
  3446. priv->msi_addr_pa = res->start;
  3447. priv->msi_addr_iova = dma_map_resource(dev, priv->msi_addr_pa,
  3448. PAGE_SIZE,
  3449. DMA_FROM_DEVICE, 0);
  3450. if (dma_mapping_error(dev, priv->msi_addr_iova)) {
  3451. icnss_pr_err("MSI: failed to map msi address\n");
  3452. priv->msi_addr_iova = 0;
  3453. ret = -ENOMEM;
  3454. goto put_clk;
  3455. }
  3456. icnss_pr_dbg("MSI Addr pa: %pa, iova: 0x%pK\n",
  3457. &priv->msi_addr_pa,
  3458. priv->msi_addr_iova);
  3459. ret = of_property_read_u32_index(dev->of_node,
  3460. "interrupts",
  3461. 1,
  3462. &int_prop);
  3463. if (ret) {
  3464. icnss_pr_dbg("Read interrupt prop failed");
  3465. goto put_clk;
  3466. }
  3467. priv->msi_base_data = int_prop + 32;
  3468. icnss_pr_dbg(" MSI Base Data: %d, IRQ Index: %d\n",
  3469. priv->msi_base_data, int_prop);
  3470. icnss_get_msi_assignment(priv);
  3471. for (i = 0; i < priv->msi_config->total_vectors; i++) {
  3472. res = platform_get_resource(priv->pdev,
  3473. IORESOURCE_IRQ, i);
  3474. if (!res) {
  3475. icnss_pr_err("Fail to get IRQ-%d\n", i);
  3476. ret = -ENODEV;
  3477. goto put_clk;
  3478. } else {
  3479. priv->srng_irqs[i] = res->start;
  3480. }
  3481. }
  3482. }
  3483. return 0;
  3484. put_clk:
  3485. icnss_put_clk(priv);
  3486. put_vreg:
  3487. icnss_put_vreg(priv);
  3488. out:
  3489. return ret;
  3490. }
  3491. static int icnss_msa_dt_parse(struct icnss_priv *priv)
  3492. {
  3493. int ret = 0;
  3494. struct platform_device *pdev = priv->pdev;
  3495. struct device *dev = &pdev->dev;
  3496. struct device_node *np = NULL;
  3497. u64 prop_size = 0;
  3498. const __be32 *addrp = NULL;
  3499. np = of_parse_phandle(dev->of_node,
  3500. "qcom,wlan-msa-fixed-region", 0);
  3501. if (np) {
  3502. addrp = of_get_address(np, 0, &prop_size, NULL);
  3503. if (!addrp) {
  3504. icnss_pr_err("Failed to get assigned-addresses or property\n");
  3505. ret = -EINVAL;
  3506. of_node_put(np);
  3507. goto out;
  3508. }
  3509. priv->msa_pa = of_translate_address(np, addrp);
  3510. if (priv->msa_pa == OF_BAD_ADDR) {
  3511. icnss_pr_err("Failed to translate MSA PA from device-tree\n");
  3512. ret = -EINVAL;
  3513. of_node_put(np);
  3514. goto out;
  3515. }
  3516. of_node_put(np);
  3517. priv->msa_va = memremap(priv->msa_pa,
  3518. (unsigned long)prop_size, MEMREMAP_WT);
  3519. if (!priv->msa_va) {
  3520. icnss_pr_err("MSA PA ioremap failed: phy addr: %pa\n",
  3521. &priv->msa_pa);
  3522. ret = -EINVAL;
  3523. goto out;
  3524. }
  3525. priv->msa_mem_size = prop_size;
  3526. } else {
  3527. ret = of_property_read_u32(dev->of_node, "qcom,wlan-msa-memory",
  3528. &priv->msa_mem_size);
  3529. if (ret || priv->msa_mem_size == 0) {
  3530. icnss_pr_err("Fail to get MSA Memory Size: %u ret: %d\n",
  3531. priv->msa_mem_size, ret);
  3532. goto out;
  3533. }
  3534. priv->msa_va = dmam_alloc_coherent(&pdev->dev,
  3535. priv->msa_mem_size, &priv->msa_pa, GFP_KERNEL);
  3536. if (!priv->msa_va) {
  3537. icnss_pr_err("DMA alloc failed for MSA\n");
  3538. ret = -ENOMEM;
  3539. goto out;
  3540. }
  3541. }
  3542. icnss_pr_dbg("MSA pa: %pa, MSA va: 0x%pK MSA Memory Size: 0x%x\n",
  3543. &priv->msa_pa, (void *)priv->msa_va, priv->msa_mem_size);
  3544. priv->use_prefix_path = of_property_read_bool(priv->pdev->dev.of_node,
  3545. "qcom,fw-prefix");
  3546. return 0;
  3547. out:
  3548. return ret;
  3549. }
  3550. static int icnss_smmu_fault_handler(struct iommu_domain *domain,
  3551. struct device *dev, unsigned long iova,
  3552. int flags, void *handler_token)
  3553. {
  3554. struct icnss_priv *priv = handler_token;
  3555. struct icnss_uevent_fw_down_data fw_down_data = {0};
  3556. icnss_fatal_err("SMMU fault happened with IOVA 0x%lx\n", iova);
  3557. if (!priv) {
  3558. icnss_pr_err("priv is NULL\n");
  3559. return -ENODEV;
  3560. }
  3561. if (test_bit(ICNSS_FW_READY, &priv->state)) {
  3562. fw_down_data.crashed = true;
  3563. icnss_call_driver_uevent(priv, ICNSS_UEVENT_SMMU_FAULT,
  3564. &fw_down_data);
  3565. icnss_call_driver_uevent(priv, ICNSS_UEVENT_FW_DOWN,
  3566. &fw_down_data);
  3567. }
  3568. icnss_trigger_recovery(&priv->pdev->dev);
  3569. /* IOMMU driver requires -ENOSYS return value to print debug info. */
  3570. return -ENOSYS;
  3571. }
  3572. static int icnss_smmu_dt_parse(struct icnss_priv *priv)
  3573. {
  3574. int ret = 0;
  3575. struct platform_device *pdev = priv->pdev;
  3576. struct device *dev = &pdev->dev;
  3577. const char *iommu_dma_type;
  3578. struct resource *res;
  3579. u32 addr_win[2];
  3580. ret = of_property_read_u32_array(dev->of_node,
  3581. "qcom,iommu-dma-addr-pool",
  3582. addr_win,
  3583. ARRAY_SIZE(addr_win));
  3584. if (ret) {
  3585. icnss_pr_err("SMMU IOVA base not found\n");
  3586. } else {
  3587. priv->smmu_iova_start = addr_win[0];
  3588. priv->smmu_iova_len = addr_win[1];
  3589. icnss_pr_dbg("SMMU IOVA start: %pa, len: %zx\n",
  3590. &priv->smmu_iova_start,
  3591. priv->smmu_iova_len);
  3592. priv->iommu_domain =
  3593. iommu_get_domain_for_dev(&pdev->dev);
  3594. ret = of_property_read_string(dev->of_node, "qcom,iommu-dma",
  3595. &iommu_dma_type);
  3596. if (!ret && !strcmp("fastmap", iommu_dma_type)) {
  3597. icnss_pr_dbg("SMMU S1 stage enabled\n");
  3598. priv->smmu_s1_enable = true;
  3599. if (priv->device_id == WCN6750_DEVICE_ID ||
  3600. priv->device_id == WCN6450_DEVICE_ID)
  3601. iommu_set_fault_handler(priv->iommu_domain,
  3602. icnss_smmu_fault_handler,
  3603. priv);
  3604. }
  3605. res = platform_get_resource_byname(pdev,
  3606. IORESOURCE_MEM,
  3607. "smmu_iova_ipa");
  3608. if (!res) {
  3609. icnss_pr_err("SMMU IOVA IPA not found\n");
  3610. } else {
  3611. priv->smmu_iova_ipa_start = res->start;
  3612. priv->smmu_iova_ipa_current = res->start;
  3613. priv->smmu_iova_ipa_len = resource_size(res);
  3614. icnss_pr_dbg("SMMU IOVA IPA start: %pa, len: %zx\n",
  3615. &priv->smmu_iova_ipa_start,
  3616. priv->smmu_iova_ipa_len);
  3617. }
  3618. }
  3619. return 0;
  3620. }
  3621. int icnss_get_iova(struct icnss_priv *priv, u64 *addr, u64 *size)
  3622. {
  3623. if (!priv)
  3624. return -ENODEV;
  3625. if (!priv->smmu_iova_len)
  3626. return -EINVAL;
  3627. *addr = priv->smmu_iova_start;
  3628. *size = priv->smmu_iova_len;
  3629. return 0;
  3630. }
  3631. int icnss_get_iova_ipa(struct icnss_priv *priv, u64 *addr, u64 *size)
  3632. {
  3633. if (!priv)
  3634. return -ENODEV;
  3635. if (!priv->smmu_iova_ipa_len)
  3636. return -EINVAL;
  3637. *addr = priv->smmu_iova_ipa_start;
  3638. *size = priv->smmu_iova_ipa_len;
  3639. return 0;
  3640. }
  3641. void icnss_add_fw_prefix_name(struct icnss_priv *priv, char *prefix_name,
  3642. char *name)
  3643. {
  3644. if (!priv)
  3645. return;
  3646. if (!priv->use_prefix_path) {
  3647. scnprintf(prefix_name, ICNSS_MAX_FILE_NAME, "%s", name);
  3648. return;
  3649. }
  3650. if (priv->device_id == ADRASTEA_DEVICE_ID)
  3651. scnprintf(prefix_name, ICNSS_MAX_FILE_NAME,
  3652. ADRASTEA_PATH_PREFIX "%s", name);
  3653. else if (priv->device_id == WCN6750_DEVICE_ID)
  3654. scnprintf(prefix_name, ICNSS_MAX_FILE_NAME,
  3655. QCA6750_PATH_PREFIX "%s", name);
  3656. else if (priv->device_id == WCN6450_DEVICE_ID)
  3657. scnprintf(prefix_name, ICNSS_MAX_FILE_NAME,
  3658. WCN6450_PATH_PREFIX "%s", name);
  3659. icnss_pr_dbg("File added with prefix: %s\n", prefix_name);
  3660. }
  3661. static const struct platform_device_id icnss_platform_id_table[] = {
  3662. { .name = "wcn6750", .driver_data = WCN6750_DEVICE_ID, },
  3663. { .name = "adrastea", .driver_data = ADRASTEA_DEVICE_ID, },
  3664. { .name = "wcn6450", .driver_data = WCN6450_DEVICE_ID, },
  3665. { },
  3666. };
  3667. static const struct of_device_id icnss_dt_match[] = {
  3668. {
  3669. .compatible = "qcom,wcn6750",
  3670. .data = (void *)&icnss_platform_id_table[0]},
  3671. {
  3672. .compatible = "qcom,icnss",
  3673. .data = (void *)&icnss_platform_id_table[1]},
  3674. {
  3675. .compatible = "qcom,wcn6450",
  3676. .data = (void *)&icnss_platform_id_table[2]},
  3677. { },
  3678. };
  3679. MODULE_DEVICE_TABLE(of, icnss_dt_match);
  3680. static void icnss_init_control_params(struct icnss_priv *priv)
  3681. {
  3682. priv->ctrl_params.qmi_timeout = WLFW_TIMEOUT;
  3683. priv->ctrl_params.quirks = ICNSS_QUIRKS_DEFAULT;
  3684. priv->ctrl_params.bdf_type = ICNSS_BDF_TYPE_DEFAULT;
  3685. if (priv->device_id == WCN6750_DEVICE_ID ||
  3686. of_property_read_bool(priv->pdev->dev.of_node,
  3687. "wpss-support-enable"))
  3688. priv->wpss_supported = true;
  3689. if (of_property_read_bool(priv->pdev->dev.of_node,
  3690. "bdf-download-support"))
  3691. priv->bdf_download_support = true;
  3692. if (priv->bdf_download_support && priv->device_id == ADRASTEA_DEVICE_ID)
  3693. priv->ctrl_params.bdf_type = ICNSS_BDF_BIN;
  3694. }
  3695. static void icnss_read_device_configs(struct icnss_priv *priv)
  3696. {
  3697. if (of_property_read_bool(priv->pdev->dev.of_node,
  3698. "wlan-ipa-disabled")) {
  3699. set_bit(ICNSS_IPA_DISABLED, &priv->device_config);
  3700. }
  3701. if (of_property_read_bool(priv->pdev->dev.of_node,
  3702. "qcom,wpss-self-recovery"))
  3703. priv->wpss_self_recovery_enabled = true;
  3704. }
  3705. static inline void icnss_runtime_pm_init(struct icnss_priv *priv)
  3706. {
  3707. pm_runtime_get_sync(&priv->pdev->dev);
  3708. pm_runtime_forbid(&priv->pdev->dev);
  3709. pm_runtime_set_active(&priv->pdev->dev);
  3710. pm_runtime_enable(&priv->pdev->dev);
  3711. }
  3712. static inline void icnss_runtime_pm_deinit(struct icnss_priv *priv)
  3713. {
  3714. pm_runtime_disable(&priv->pdev->dev);
  3715. pm_runtime_allow(&priv->pdev->dev);
  3716. pm_runtime_put_sync(&priv->pdev->dev);
  3717. }
  3718. static inline bool icnss_use_nv_mac(struct icnss_priv *priv)
  3719. {
  3720. return of_property_read_bool(priv->pdev->dev.of_node,
  3721. "use-nv-mac");
  3722. }
  3723. static void rproc_restart_level_notifier(void *data, struct rproc *rproc)
  3724. {
  3725. struct icnss_subsys_restart_level_data *restart_level_data;
  3726. icnss_pr_info("rproc name: %s recovery disable: %d",
  3727. rproc->name, rproc->recovery_disabled);
  3728. restart_level_data = kzalloc(sizeof(*restart_level_data), GFP_ATOMIC);
  3729. if (!restart_level_data)
  3730. return;
  3731. if (strnstr(rproc->name, "wpss", ICNSS_RPROC_LEN)) {
  3732. if (rproc->recovery_disabled)
  3733. restart_level_data->restart_level = ICNSS_DISABLE_M3_SSR;
  3734. else
  3735. restart_level_data->restart_level = ICNSS_ENABLE_M3_SSR;
  3736. icnss_driver_event_post(penv, ICNSS_DRIVER_EVENT_SUBSYS_RESTART_LEVEL,
  3737. 0, restart_level_data);
  3738. }
  3739. }
  3740. #ifdef CONFIG_WCNSS_MEM_PRE_ALLOC
  3741. static void icnss_initialize_mem_pool(unsigned long device_id)
  3742. {
  3743. cnss_initialize_prealloc_pool(device_id);
  3744. }
  3745. static void icnss_deinitialize_mem_pool(void)
  3746. {
  3747. cnss_deinitialize_prealloc_pool();
  3748. }
  3749. #else
  3750. static void icnss_initialize_mem_pool(unsigned long device_id)
  3751. {
  3752. }
  3753. static void icnss_deinitialize_mem_pool(void)
  3754. {
  3755. }
  3756. #endif
  3757. static int icnss_probe(struct platform_device *pdev)
  3758. {
  3759. int ret = 0;
  3760. struct device *dev = &pdev->dev;
  3761. struct icnss_priv *priv;
  3762. const struct of_device_id *of_id;
  3763. const struct platform_device_id *device_id;
  3764. if (dev_get_drvdata(dev)) {
  3765. icnss_pr_err("Driver is already initialized\n");
  3766. return -EEXIST;
  3767. }
  3768. of_id = of_match_device(icnss_dt_match, &pdev->dev);
  3769. if (!of_id || !of_id->data) {
  3770. icnss_pr_err("Failed to find of match device!\n");
  3771. ret = -ENODEV;
  3772. goto out_reset_drvdata;
  3773. }
  3774. device_id = of_id->data;
  3775. icnss_pr_dbg("Platform driver probe\n");
  3776. priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  3777. if (!priv)
  3778. return -ENOMEM;
  3779. priv->magic = ICNSS_MAGIC;
  3780. dev_set_drvdata(dev, priv);
  3781. priv->pdev = pdev;
  3782. priv->device_id = device_id->driver_data;
  3783. priv->is_chain1_supported = true;
  3784. INIT_LIST_HEAD(&priv->vreg_list);
  3785. INIT_LIST_HEAD(&priv->clk_list);
  3786. icnss_allow_recursive_recovery(dev);
  3787. icnss_initialize_mem_pool(priv->device_id);
  3788. icnss_init_control_params(priv);
  3789. icnss_read_device_configs(priv);
  3790. ret = icnss_resource_parse(priv);
  3791. if (ret)
  3792. goto out_reset_drvdata;
  3793. ret = icnss_msa_dt_parse(priv);
  3794. if (ret)
  3795. goto out_free_resources;
  3796. ret = icnss_smmu_dt_parse(priv);
  3797. if (ret)
  3798. goto out_free_resources;
  3799. spin_lock_init(&priv->event_lock);
  3800. spin_lock_init(&priv->on_off_lock);
  3801. spin_lock_init(&priv->soc_wake_msg_lock);
  3802. mutex_init(&priv->dev_lock);
  3803. mutex_init(&priv->tcdev_lock);
  3804. priv->event_wq = alloc_workqueue("icnss_driver_event", WQ_UNBOUND, 1);
  3805. if (!priv->event_wq) {
  3806. icnss_pr_err("Workqueue creation failed\n");
  3807. ret = -EFAULT;
  3808. goto smmu_cleanup;
  3809. }
  3810. INIT_WORK(&priv->event_work, icnss_driver_event_work);
  3811. INIT_LIST_HEAD(&priv->event_list);
  3812. if (priv->is_slate_rfa)
  3813. init_completion(&priv->slate_boot_complete);
  3814. ret = icnss_register_fw_service(priv);
  3815. if (ret < 0) {
  3816. icnss_pr_err("fw service registration failed: %d\n", ret);
  3817. goto out_destroy_wq;
  3818. }
  3819. icnss_enable_recovery(priv);
  3820. icnss_debugfs_create(priv);
  3821. icnss_sysfs_create(priv);
  3822. ret = device_init_wakeup(&priv->pdev->dev, true);
  3823. if (ret)
  3824. icnss_pr_err("Failed to init platform device wakeup source, err = %d\n",
  3825. ret);
  3826. icnss_set_plat_priv(priv);
  3827. init_completion(&priv->unblock_shutdown);
  3828. if (priv->device_id == WCN6750_DEVICE_ID ||
  3829. priv->device_id == WCN6450_DEVICE_ID) {
  3830. priv->soc_wake_wq = alloc_workqueue("icnss_soc_wake_event",
  3831. WQ_UNBOUND|WQ_HIGHPRI, 1);
  3832. if (!priv->soc_wake_wq) {
  3833. icnss_pr_err("Soc wake Workqueue creation failed\n");
  3834. ret = -EFAULT;
  3835. goto out_unregister_fw_service;
  3836. }
  3837. INIT_WORK(&priv->soc_wake_msg_work, icnss_soc_wake_msg_work);
  3838. INIT_LIST_HEAD(&priv->soc_wake_msg_list);
  3839. ret = icnss_genl_init();
  3840. if (ret < 0)
  3841. icnss_pr_err("ICNSS genl init failed %d\n", ret);
  3842. init_completion(&priv->smp2p_soc_wake_wait);
  3843. icnss_runtime_pm_init(priv);
  3844. icnss_aop_mbox_init(priv);
  3845. set_bit(ICNSS_COLD_BOOT_CAL, &priv->state);
  3846. priv->bdf_download_support = true;
  3847. register_trace_android_vh_rproc_recovery_set(rproc_restart_level_notifier, NULL);
  3848. }
  3849. if (priv->wpss_supported) {
  3850. ret = icnss_dms_init(priv);
  3851. if (ret)
  3852. icnss_pr_err("ICNSS DMS init failed %d\n", ret);
  3853. priv->use_nv_mac = icnss_use_nv_mac(priv);
  3854. icnss_pr_dbg("NV MAC feature is %s\n",
  3855. priv->use_nv_mac ? "Mandatory":"Not Mandatory");
  3856. INIT_WORK(&wpss_loader, icnss_wpss_load);
  3857. }
  3858. timer_setup(&priv->recovery_timer,
  3859. icnss_recovery_timeout_hdlr, 0);
  3860. if (priv->wpss_self_recovery_enabled) {
  3861. INIT_WORK(&wpss_ssr_work, icnss_wpss_self_recovery);
  3862. timer_setup(&priv->wpss_ssr_timer,
  3863. icnss_wpss_ssr_timeout_hdlr, 0);
  3864. }
  3865. INIT_LIST_HEAD(&priv->icnss_tcdev_list);
  3866. icnss_pr_info("Platform driver probed successfully\n");
  3867. return 0;
  3868. out_unregister_fw_service:
  3869. icnss_unregister_fw_service(priv);
  3870. out_destroy_wq:
  3871. destroy_workqueue(priv->event_wq);
  3872. smmu_cleanup:
  3873. priv->iommu_domain = NULL;
  3874. out_free_resources:
  3875. icnss_put_resources(priv);
  3876. out_reset_drvdata:
  3877. icnss_deinitialize_mem_pool();
  3878. dev_set_drvdata(dev, NULL);
  3879. return ret;
  3880. }
  3881. void icnss_destroy_ramdump_device(struct icnss_ramdump_info *ramdump_info)
  3882. {
  3883. if (IS_ERR_OR_NULL(ramdump_info))
  3884. return;
  3885. device_unregister(ramdump_info->dev);
  3886. ida_simple_remove(&rd_minor_id, ramdump_info->minor);
  3887. kfree(ramdump_info);
  3888. }
  3889. static void icnss_unregister_power_supply_notifier(struct icnss_priv *priv)
  3890. {
  3891. if (priv->batt_psy)
  3892. power_supply_put(penv->batt_psy);
  3893. if (priv->psf_supported) {
  3894. flush_workqueue(priv->soc_update_wq);
  3895. destroy_workqueue(priv->soc_update_wq);
  3896. power_supply_unreg_notifier(&priv->psf_nb);
  3897. }
  3898. }
  3899. static int icnss_remove(struct platform_device *pdev)
  3900. {
  3901. struct icnss_priv *priv = dev_get_drvdata(&pdev->dev);
  3902. icnss_pr_info("Removing driver: state: 0x%lx\n", priv->state);
  3903. del_timer(&priv->recovery_timer);
  3904. if (priv->wpss_self_recovery_enabled)
  3905. del_timer(&priv->wpss_ssr_timer);
  3906. device_init_wakeup(&priv->pdev->dev, false);
  3907. icnss_debugfs_destroy(priv);
  3908. icnss_unregister_power_supply_notifier(penv);
  3909. icnss_sysfs_destroy(priv);
  3910. complete_all(&priv->unblock_shutdown);
  3911. if (priv->is_slate_rfa) {
  3912. icnss_slate_ssr_unregister_notifier(priv);
  3913. icnss_unregister_slate_event_notifier(priv);
  3914. }
  3915. icnss_destroy_ramdump_device(priv->msa0_dump_dev);
  3916. if (priv->wpss_supported) {
  3917. icnss_dms_deinit(priv);
  3918. icnss_wpss_early_ssr_unregister_notifier(priv);
  3919. icnss_wpss_ssr_unregister_notifier(priv);
  3920. } else {
  3921. icnss_modem_ssr_unregister_notifier(priv);
  3922. icnss_pdr_unregister_notifier(priv);
  3923. }
  3924. if (priv->device_id == WCN6750_DEVICE_ID ||
  3925. priv->device_id == WCN6450_DEVICE_ID) {
  3926. icnss_genl_exit();
  3927. icnss_runtime_pm_deinit(priv);
  3928. if (!IS_ERR_OR_NULL(priv->mbox_chan))
  3929. mbox_free_channel(priv->mbox_chan);
  3930. unregister_trace_android_vh_rproc_recovery_set(rproc_restart_level_notifier, NULL);
  3931. complete_all(&priv->smp2p_soc_wake_wait);
  3932. icnss_destroy_ramdump_device(priv->m3_dump_phyareg);
  3933. icnss_destroy_ramdump_device(priv->m3_dump_phydbg);
  3934. icnss_destroy_ramdump_device(priv->m3_dump_wmac0reg);
  3935. icnss_destroy_ramdump_device(priv->m3_dump_wcssdbg);
  3936. icnss_destroy_ramdump_device(priv->m3_dump_phyapdmem);
  3937. if (priv->soc_wake_wq)
  3938. destroy_workqueue(priv->soc_wake_wq);
  3939. }
  3940. class_destroy(priv->icnss_ramdump_class);
  3941. unregister_chrdev_region(priv->icnss_ramdump_dev, RAMDUMP_NUM_DEVICES);
  3942. icnss_unregister_fw_service(priv);
  3943. if (priv->event_wq)
  3944. destroy_workqueue(priv->event_wq);
  3945. priv->iommu_domain = NULL;
  3946. icnss_hw_power_off(priv);
  3947. icnss_put_resources(priv);
  3948. icnss_deinitialize_mem_pool();
  3949. dev_set_drvdata(&pdev->dev, NULL);
  3950. return 0;
  3951. }
  3952. void icnss_recovery_timeout_hdlr(struct timer_list *t)
  3953. {
  3954. struct icnss_priv *priv = from_timer(priv, t, recovery_timer);
  3955. icnss_pr_err("Timeout waiting for FW Ready 0x%lx\n", priv->state);
  3956. ICNSS_ASSERT(0);
  3957. }
  3958. void icnss_wpss_ssr_timeout_hdlr(struct timer_list *t)
  3959. {
  3960. struct icnss_priv *priv = from_timer(priv, t, wpss_ssr_timer);
  3961. icnss_pr_err("Timeout waiting for WPSS SSR notification 0x%lx\n",
  3962. priv->state);
  3963. schedule_work(&wpss_ssr_work);
  3964. }
  3965. #ifdef CONFIG_PM_SLEEP
  3966. static int icnss_pm_suspend(struct device *dev)
  3967. {
  3968. struct icnss_priv *priv = dev_get_drvdata(dev);
  3969. int ret = 0;
  3970. if (priv->magic != ICNSS_MAGIC) {
  3971. icnss_pr_err("Invalid drvdata for pm suspend: dev %pK, data %pK, magic 0x%x\n",
  3972. dev, priv, priv->magic);
  3973. return -EINVAL;
  3974. }
  3975. icnss_pr_vdbg("PM Suspend, state: 0x%lx\n", priv->state);
  3976. if (!priv->ops || !priv->ops->pm_suspend ||
  3977. IS_ERR(priv->smp2p_info[ICNSS_SMP2P_OUT_POWER_SAVE].smem_state) ||
  3978. !test_bit(ICNSS_DRIVER_PROBED, &priv->state))
  3979. return 0;
  3980. ret = priv->ops->pm_suspend(dev);
  3981. if (ret == 0) {
  3982. if (priv->device_id == WCN6750_DEVICE_ID ||
  3983. priv->device_id == WCN6450_DEVICE_ID) {
  3984. if (test_bit(ICNSS_PD_RESTART, &priv->state) ||
  3985. !test_bit(ICNSS_MODE_ON, &priv->state))
  3986. return 0;
  3987. ret = icnss_send_smp2p(priv, ICNSS_POWER_SAVE_ENTER,
  3988. ICNSS_SMP2P_OUT_POWER_SAVE);
  3989. }
  3990. priv->stats.pm_suspend++;
  3991. set_bit(ICNSS_PM_SUSPEND, &priv->state);
  3992. } else {
  3993. priv->stats.pm_suspend_err++;
  3994. }
  3995. return ret;
  3996. }
  3997. static int icnss_pm_resume(struct device *dev)
  3998. {
  3999. struct icnss_priv *priv = dev_get_drvdata(dev);
  4000. int ret = 0;
  4001. if (priv->magic != ICNSS_MAGIC) {
  4002. icnss_pr_err("Invalid drvdata for pm resume: dev %pK, data %pK, magic 0x%x\n",
  4003. dev, priv, priv->magic);
  4004. return -EINVAL;
  4005. }
  4006. icnss_pr_vdbg("PM resume, state: 0x%lx\n", priv->state);
  4007. if (!priv->ops || !priv->ops->pm_resume ||
  4008. IS_ERR(priv->smp2p_info[ICNSS_SMP2P_OUT_POWER_SAVE].smem_state) ||
  4009. !test_bit(ICNSS_DRIVER_PROBED, &priv->state))
  4010. goto out;
  4011. ret = priv->ops->pm_resume(dev);
  4012. out:
  4013. if (ret == 0) {
  4014. priv->stats.pm_resume++;
  4015. clear_bit(ICNSS_PM_SUSPEND, &priv->state);
  4016. } else {
  4017. priv->stats.pm_resume_err++;
  4018. }
  4019. return ret;
  4020. }
  4021. static int icnss_pm_suspend_noirq(struct device *dev)
  4022. {
  4023. struct icnss_priv *priv = dev_get_drvdata(dev);
  4024. int ret = 0;
  4025. if (priv->magic != ICNSS_MAGIC) {
  4026. icnss_pr_err("Invalid drvdata for pm suspend_noirq: dev %pK, data %pK, magic 0x%x\n",
  4027. dev, priv, priv->magic);
  4028. return -EINVAL;
  4029. }
  4030. icnss_pr_vdbg("PM suspend_noirq, state: 0x%lx\n", priv->state);
  4031. if (!priv->ops || !priv->ops->suspend_noirq ||
  4032. !test_bit(ICNSS_DRIVER_PROBED, &priv->state))
  4033. goto out;
  4034. ret = priv->ops->suspend_noirq(dev);
  4035. out:
  4036. if (ret == 0) {
  4037. priv->stats.pm_suspend_noirq++;
  4038. set_bit(ICNSS_PM_SUSPEND_NOIRQ, &priv->state);
  4039. } else {
  4040. priv->stats.pm_suspend_noirq_err++;
  4041. }
  4042. return ret;
  4043. }
  4044. static int icnss_pm_resume_noirq(struct device *dev)
  4045. {
  4046. struct icnss_priv *priv = dev_get_drvdata(dev);
  4047. int ret = 0;
  4048. if (priv->magic != ICNSS_MAGIC) {
  4049. icnss_pr_err("Invalid drvdata for pm resume_noirq: dev %pK, data %pK, magic 0x%x\n",
  4050. dev, priv, priv->magic);
  4051. return -EINVAL;
  4052. }
  4053. icnss_pr_vdbg("PM resume_noirq, state: 0x%lx\n", priv->state);
  4054. if (!priv->ops || !priv->ops->resume_noirq ||
  4055. !test_bit(ICNSS_DRIVER_PROBED, &priv->state))
  4056. goto out;
  4057. ret = priv->ops->resume_noirq(dev);
  4058. out:
  4059. if (ret == 0) {
  4060. priv->stats.pm_resume_noirq++;
  4061. clear_bit(ICNSS_PM_SUSPEND_NOIRQ, &priv->state);
  4062. } else {
  4063. priv->stats.pm_resume_noirq_err++;
  4064. }
  4065. return ret;
  4066. }
  4067. static int icnss_pm_runtime_suspend(struct device *dev)
  4068. {
  4069. struct icnss_priv *priv = dev_get_drvdata(dev);
  4070. int ret = 0;
  4071. if (priv->device_id == ADRASTEA_DEVICE_ID) {
  4072. icnss_pr_err("Ignore runtime suspend:\n");
  4073. goto out;
  4074. }
  4075. if (priv->magic != ICNSS_MAGIC) {
  4076. icnss_pr_err("Invalid drvdata for runtime suspend: dev %pK, data %pK, magic 0x%x\n",
  4077. dev, priv, priv->magic);
  4078. return -EINVAL;
  4079. }
  4080. if (!priv->ops || !priv->ops->runtime_suspend ||
  4081. IS_ERR(priv->smp2p_info[ICNSS_SMP2P_OUT_POWER_SAVE].smem_state))
  4082. goto out;
  4083. icnss_pr_vdbg("Runtime suspend\n");
  4084. ret = priv->ops->runtime_suspend(dev);
  4085. if (!ret) {
  4086. if (test_bit(ICNSS_PD_RESTART, &priv->state) ||
  4087. !test_bit(ICNSS_MODE_ON, &priv->state))
  4088. return 0;
  4089. ret = icnss_send_smp2p(priv, ICNSS_POWER_SAVE_ENTER,
  4090. ICNSS_SMP2P_OUT_POWER_SAVE);
  4091. }
  4092. out:
  4093. return ret;
  4094. }
  4095. static int icnss_pm_runtime_resume(struct device *dev)
  4096. {
  4097. struct icnss_priv *priv = dev_get_drvdata(dev);
  4098. int ret = 0;
  4099. if (priv->device_id == ADRASTEA_DEVICE_ID) {
  4100. icnss_pr_err("Ignore runtime resume\n");
  4101. goto out;
  4102. }
  4103. if (priv->magic != ICNSS_MAGIC) {
  4104. icnss_pr_err("Invalid drvdata for runtime resume: dev %pK, data %pK, magic 0x%x\n",
  4105. dev, priv, priv->magic);
  4106. return -EINVAL;
  4107. }
  4108. if (!priv->ops || !priv->ops->runtime_resume ||
  4109. IS_ERR(priv->smp2p_info[ICNSS_SMP2P_OUT_POWER_SAVE].smem_state))
  4110. goto out;
  4111. icnss_pr_vdbg("Runtime resume, state: 0x%lx\n", priv->state);
  4112. ret = priv->ops->runtime_resume(dev);
  4113. out:
  4114. return ret;
  4115. }
  4116. static int icnss_pm_runtime_idle(struct device *dev)
  4117. {
  4118. struct icnss_priv *priv = dev_get_drvdata(dev);
  4119. if (priv->device_id == ADRASTEA_DEVICE_ID) {
  4120. icnss_pr_err("Ignore runtime idle\n");
  4121. goto out;
  4122. }
  4123. icnss_pr_vdbg("Runtime idle\n");
  4124. pm_request_autosuspend(dev);
  4125. out:
  4126. return -EBUSY;
  4127. }
  4128. #endif
  4129. static const struct dev_pm_ops icnss_pm_ops = {
  4130. SET_SYSTEM_SLEEP_PM_OPS(icnss_pm_suspend,
  4131. icnss_pm_resume)
  4132. SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(icnss_pm_suspend_noirq,
  4133. icnss_pm_resume_noirq)
  4134. SET_RUNTIME_PM_OPS(icnss_pm_runtime_suspend, icnss_pm_runtime_resume,
  4135. icnss_pm_runtime_idle)
  4136. };
  4137. static struct platform_driver icnss_driver = {
  4138. .probe = icnss_probe,
  4139. .remove = icnss_remove,
  4140. .driver = {
  4141. .name = "icnss2",
  4142. .pm = &icnss_pm_ops,
  4143. .of_match_table = icnss_dt_match,
  4144. },
  4145. };
  4146. static int __init icnss_initialize(void)
  4147. {
  4148. icnss_debug_init();
  4149. return platform_driver_register(&icnss_driver);
  4150. }
  4151. static void __exit icnss_exit(void)
  4152. {
  4153. platform_driver_unregister(&icnss_driver);
  4154. icnss_debug_deinit();
  4155. }
  4156. module_init(icnss_initialize);
  4157. module_exit(icnss_exit);
  4158. MODULE_LICENSE("GPL v2");
  4159. MODULE_DESCRIPTION("iWCN CORE platform driver");