main.c 129 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/delay.h>
  7. #include <linux/devcoredump.h>
  8. #include <linux/elf.h>
  9. #include <linux/jiffies.h>
  10. #include <linux/module.h>
  11. #include <linux/of.h>
  12. #include <linux/of_device.h>
  13. #include <linux/of_gpio.h>
  14. #include <linux/pm_wakeup.h>
  15. #include <linux/reboot.h>
  16. #include <linux/rwsem.h>
  17. #include <linux/suspend.h>
  18. #include <linux/timer.h>
  19. #include <linux/thermal.h>
  20. #include <linux/version.h>
  21. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0))
  22. #include <linux/panic_notifier.h>
  23. #endif
  24. #if IS_ENABLED(CONFIG_QCOM_MINIDUMP)
  25. #include <soc/qcom/minidump.h>
  26. #endif
  27. #include "cnss_plat_ipc_qmi.h"
  28. #include "cnss_utils.h"
  29. #include "main.h"
  30. #include "bus.h"
  31. #include "debug.h"
  32. #include "genl.h"
  33. #include "reg.h"
  34. #ifdef CONFIG_CNSS_HW_SECURE_DISABLE
  35. #include "smcinvoke.h"
  36. #include "smcinvoke_object.h"
  37. #include "IClientEnv.h"
  38. #define HW_STATE_UID 0x108
  39. #define HW_OP_GET_STATE 1
  40. #define HW_WIFI_UID 0x508
  41. #define FEATURE_NOT_SUPPORTED 12
  42. #define PERIPHERAL_NOT_FOUND 10
  43. #endif
  44. #define CNSS_DUMP_FORMAT_VER 0x11
  45. #define CNSS_DUMP_FORMAT_VER_V2 0x22
  46. #define CNSS_DUMP_MAGIC_VER_V2 0x42445953
  47. #define CNSS_DUMP_NAME "CNSS_WLAN"
  48. #define CNSS_DUMP_DESC_SIZE 0x1000
  49. #define CNSS_DUMP_SEG_VER 0x1
  50. #define FILE_SYSTEM_READY 1
  51. #define FW_READY_TIMEOUT 20000
  52. #define FW_ASSERT_TIMEOUT 5000
  53. #define CNSS_EVENT_PENDING 2989
  54. #define POWER_RESET_MIN_DELAY_MS 100
  55. #define CNSS_QUIRKS_DEFAULT 0
  56. #ifdef CONFIG_CNSS_EMULATION
  57. #define CNSS_MHI_TIMEOUT_DEFAULT 90000
  58. #define CNSS_MHI_M2_TIMEOUT_DEFAULT 2000
  59. #define CNSS_QMI_TIMEOUT_DEFAULT 90000
  60. #else
  61. #define CNSS_MHI_TIMEOUT_DEFAULT 0
  62. #define CNSS_MHI_M2_TIMEOUT_DEFAULT 25
  63. #define CNSS_QMI_TIMEOUT_DEFAULT 10000
  64. #endif
  65. #define CNSS_BDF_TYPE_DEFAULT CNSS_BDF_ELF
  66. #define CNSS_TIME_SYNC_PERIOD_DEFAULT 900000
  67. #define CNSS_MIN_TIME_SYNC_PERIOD 2000
  68. #define CNSS_DMS_QMI_CONNECTION_WAIT_MS 50
  69. #define CNSS_DMS_QMI_CONNECTION_WAIT_RETRY 200
  70. #define CNSS_DAEMON_CONNECT_TIMEOUT_MS 30000
  71. #define CNSS_CAL_DB_FILE_NAME "wlfw_cal_db.bin"
  72. #define CNSS_CAL_START_PROBE_WAIT_RETRY_MAX 100
  73. #define CNSS_CAL_START_PROBE_WAIT_MS 500
  74. enum cnss_cal_db_op {
  75. CNSS_CAL_DB_UPLOAD,
  76. CNSS_CAL_DB_DOWNLOAD,
  77. CNSS_CAL_DB_INVALID_OP,
  78. };
  79. enum cnss_recovery_type {
  80. CNSS_WLAN_RECOVERY = 0x1,
  81. CNSS_PCSS_RECOVERY = 0x2,
  82. };
  83. #ifdef CONFIG_CNSS_SUPPORT_DUAL_DEV
  84. #define CNSS_MAX_DEV_NUM 2
  85. static struct cnss_plat_data *plat_env[CNSS_MAX_DEV_NUM];
  86. static int plat_env_count;
  87. #else
  88. static struct cnss_plat_data *plat_env;
  89. #endif
  90. static bool cnss_allow_driver_loading;
  91. static struct cnss_fw_files FW_FILES_QCA6174_FW_3_0 = {
  92. "qwlan30.bin", "bdwlan30.bin", "otp30.bin", "utf30.bin",
  93. "utfbd30.bin", "epping30.bin", "evicted30.bin"
  94. };
  95. static struct cnss_fw_files FW_FILES_DEFAULT = {
  96. "qwlan.bin", "bdwlan.bin", "otp.bin", "utf.bin",
  97. "utfbd.bin", "epping.bin", "evicted.bin"
  98. };
  99. struct cnss_driver_event {
  100. struct list_head list;
  101. enum cnss_driver_event_type type;
  102. bool sync;
  103. struct completion complete;
  104. int ret;
  105. void *data;
  106. };
  107. bool cnss_check_driver_loading_allowed(void)
  108. {
  109. return cnss_allow_driver_loading;
  110. }
  111. #ifdef CONFIG_CNSS_SUPPORT_DUAL_DEV
  112. static void cnss_set_plat_priv(struct platform_device *plat_dev,
  113. struct cnss_plat_data *plat_priv)
  114. {
  115. cnss_pr_dbg("Set plat_priv at %d", plat_env_count);
  116. if (plat_priv) {
  117. plat_priv->plat_idx = plat_env_count;
  118. plat_env[plat_priv->plat_idx] = plat_priv;
  119. plat_env_count++;
  120. }
  121. }
  122. struct cnss_plat_data *cnss_get_plat_priv(struct platform_device
  123. *plat_dev)
  124. {
  125. int i;
  126. if (!plat_dev)
  127. return NULL;
  128. for (i = 0; i < plat_env_count; i++) {
  129. if (plat_env[i]->plat_dev == plat_dev)
  130. return plat_env[i];
  131. }
  132. return NULL;
  133. }
  134. struct cnss_plat_data *cnss_get_first_plat_priv(struct platform_device
  135. *plat_dev)
  136. {
  137. int i;
  138. if (!plat_dev) {
  139. for (i = 0; i < plat_env_count; i++) {
  140. if (plat_env[i])
  141. return plat_env[i];
  142. }
  143. }
  144. return NULL;
  145. }
  146. static void cnss_clear_plat_priv(struct cnss_plat_data *plat_priv)
  147. {
  148. cnss_pr_dbg("Clear plat_priv at %d", plat_priv->plat_idx);
  149. plat_env[plat_priv->plat_idx] = NULL;
  150. plat_env_count--;
  151. }
  152. static int cnss_set_device_name(struct cnss_plat_data *plat_priv)
  153. {
  154. snprintf(plat_priv->device_name, sizeof(plat_priv->device_name),
  155. "wlan_%d", plat_priv->plat_idx);
  156. return 0;
  157. }
  158. static int cnss_plat_env_available(void)
  159. {
  160. int ret = 0;
  161. if (plat_env_count >= CNSS_MAX_DEV_NUM) {
  162. cnss_pr_err("ERROR: No space to store plat_priv\n");
  163. ret = -ENOMEM;
  164. }
  165. return ret;
  166. }
  167. int cnss_get_plat_env_count(void)
  168. {
  169. return plat_env_count;
  170. }
  171. struct cnss_plat_data *cnss_get_plat_env(int index)
  172. {
  173. return plat_env[index];
  174. }
  175. struct cnss_plat_data *cnss_get_plat_priv_by_rc_num(int rc_num)
  176. {
  177. int i;
  178. for (i = 0; i < plat_env_count; i++) {
  179. if (plat_env[i]->rc_num == rc_num)
  180. return plat_env[i];
  181. }
  182. return NULL;
  183. }
  184. static inline int
  185. cnss_get_qrtr_node_id(struct cnss_plat_data *plat_priv)
  186. {
  187. return of_property_read_u32(plat_priv->dev_node,
  188. "qcom,qrtr_node_id", &plat_priv->qrtr_node_id);
  189. }
  190. void cnss_get_qrtr_info(struct cnss_plat_data *plat_priv)
  191. {
  192. int ret = 0;
  193. ret = cnss_get_qrtr_node_id(plat_priv);
  194. if (ret) {
  195. cnss_pr_warn("Failed to find qrtr_node_id err=%d\n", ret);
  196. plat_priv->qrtr_node_id = 0;
  197. plat_priv->wlfw_service_instance_id = 0;
  198. } else {
  199. plat_priv->wlfw_service_instance_id = plat_priv->qrtr_node_id +
  200. QRTR_NODE_FW_ID_BASE;
  201. cnss_pr_dbg("service_instance_id=0x%x\n",
  202. plat_priv->wlfw_service_instance_id);
  203. }
  204. }
  205. static inline int
  206. cnss_get_pld_bus_ops_name(struct cnss_plat_data *plat_priv)
  207. {
  208. return of_property_read_string(plat_priv->plat_dev->dev.of_node,
  209. "qcom,pld_bus_ops_name",
  210. &plat_priv->pld_bus_ops_name);
  211. }
  212. #else
  213. static void cnss_set_plat_priv(struct platform_device *plat_dev,
  214. struct cnss_plat_data *plat_priv)
  215. {
  216. plat_env = plat_priv;
  217. }
  218. struct cnss_plat_data *cnss_get_plat_priv(struct platform_device *plat_dev)
  219. {
  220. return plat_env;
  221. }
  222. static void cnss_clear_plat_priv(struct cnss_plat_data *plat_priv)
  223. {
  224. plat_env = NULL;
  225. }
  226. static int cnss_set_device_name(struct cnss_plat_data *plat_priv)
  227. {
  228. snprintf(plat_priv->device_name, sizeof(plat_priv->device_name),
  229. "wlan");
  230. return 0;
  231. }
  232. static int cnss_plat_env_available(void)
  233. {
  234. return 0;
  235. }
  236. struct cnss_plat_data *cnss_get_plat_priv_by_rc_num(int rc_num)
  237. {
  238. return cnss_bus_dev_to_plat_priv(NULL);
  239. }
  240. void cnss_get_qrtr_info(struct cnss_plat_data *plat_priv)
  241. {
  242. }
  243. static int
  244. cnss_get_pld_bus_ops_name(struct cnss_plat_data *plat_priv)
  245. {
  246. return 0;
  247. }
  248. #endif
  249. void cnss_get_sleep_clk_supported(struct cnss_plat_data *plat_priv)
  250. {
  251. plat_priv->sleep_clk = of_property_read_bool(plat_priv->dev_node,
  252. "qcom,sleep-clk-support");
  253. cnss_pr_dbg("qcom,sleep-clk-support is %d\n",
  254. plat_priv->sleep_clk);
  255. }
  256. void cnss_get_bwscal_info(struct cnss_plat_data *plat_priv)
  257. {
  258. plat_priv->no_bwscale = of_property_read_bool(plat_priv->dev_node,
  259. "qcom,no-bwscale");
  260. }
  261. static inline int
  262. cnss_get_rc_num(struct cnss_plat_data *plat_priv)
  263. {
  264. return of_property_read_u32(plat_priv->plat_dev->dev.of_node,
  265. "qcom,wlan-rc-num", &plat_priv->rc_num);
  266. }
  267. bool cnss_is_dual_wlan_enabled(void)
  268. {
  269. return IS_ENABLED(CONFIG_CNSS_SUPPORT_DUAL_DEV);
  270. }
  271. /**
  272. * cnss_get_mem_seg_count - Get segment count of memory
  273. * @type: memory type
  274. * @seg: segment count
  275. *
  276. * Return: 0 on success, negative value on failure
  277. */
  278. int cnss_get_mem_seg_count(enum cnss_remote_mem_type type, u32 *seg)
  279. {
  280. struct cnss_plat_data *plat_priv;
  281. plat_priv = cnss_get_plat_priv(NULL);
  282. if (!plat_priv)
  283. return -ENODEV;
  284. switch (type) {
  285. case CNSS_REMOTE_MEM_TYPE_FW:
  286. *seg = plat_priv->fw_mem_seg_len;
  287. break;
  288. case CNSS_REMOTE_MEM_TYPE_QDSS:
  289. *seg = plat_priv->qdss_mem_seg_len;
  290. break;
  291. default:
  292. return -EINVAL;
  293. }
  294. return 0;
  295. }
  296. EXPORT_SYMBOL(cnss_get_mem_seg_count);
  297. /**
  298. * cnss_get_wifi_kobject -return wifi kobject
  299. * Return: Null, to maintain driver comnpatibilty
  300. */
  301. struct kobject *cnss_get_wifi_kobj(struct device *dev)
  302. {
  303. struct cnss_plat_data *plat_priv;
  304. plat_priv = cnss_get_plat_priv(NULL);
  305. if (!plat_priv)
  306. return NULL;
  307. return plat_priv->wifi_kobj;
  308. }
  309. EXPORT_SYMBOL(cnss_get_wifi_kobj);
  310. /**
  311. * cnss_get_mem_segment_info - Get memory info of different type
  312. * @type: memory type
  313. * @segment: array to save the segment info
  314. * @seg: segment count
  315. *
  316. * Return: 0 on success, negative value on failure
  317. */
  318. int cnss_get_mem_segment_info(enum cnss_remote_mem_type type,
  319. struct cnss_mem_segment segment[],
  320. u32 segment_count)
  321. {
  322. struct cnss_plat_data *plat_priv;
  323. u32 i;
  324. plat_priv = cnss_get_plat_priv(NULL);
  325. if (!plat_priv)
  326. return -ENODEV;
  327. switch (type) {
  328. case CNSS_REMOTE_MEM_TYPE_FW:
  329. if (segment_count > plat_priv->fw_mem_seg_len)
  330. segment_count = plat_priv->fw_mem_seg_len;
  331. for (i = 0; i < segment_count; i++) {
  332. segment[i].size = plat_priv->fw_mem[i].size;
  333. segment[i].va = plat_priv->fw_mem[i].va;
  334. segment[i].pa = plat_priv->fw_mem[i].pa;
  335. }
  336. break;
  337. case CNSS_REMOTE_MEM_TYPE_QDSS:
  338. if (segment_count > plat_priv->qdss_mem_seg_len)
  339. segment_count = plat_priv->qdss_mem_seg_len;
  340. for (i = 0; i < segment_count; i++) {
  341. segment[i].size = plat_priv->qdss_mem[i].size;
  342. segment[i].va = plat_priv->qdss_mem[i].va;
  343. segment[i].pa = plat_priv->qdss_mem[i].pa;
  344. }
  345. break;
  346. default:
  347. return -EINVAL;
  348. }
  349. return 0;
  350. }
  351. EXPORT_SYMBOL(cnss_get_mem_segment_info);
  352. static int cnss_get_audio_iommu_domain(struct cnss_plat_data *plat_priv)
  353. {
  354. struct device_node *audio_ion_node;
  355. struct platform_device *audio_ion_pdev;
  356. audio_ion_node = of_find_compatible_node(NULL, NULL,
  357. "qcom,msm-audio-ion");
  358. if (!audio_ion_node) {
  359. cnss_pr_err("Unable to get Audio ion node");
  360. return -EINVAL;
  361. }
  362. audio_ion_pdev = of_find_device_by_node(audio_ion_node);
  363. of_node_put(audio_ion_node);
  364. if (!audio_ion_pdev) {
  365. cnss_pr_err("Unable to get Audio ion platform device");
  366. return -EINVAL;
  367. }
  368. plat_priv->audio_iommu_domain =
  369. iommu_get_domain_for_dev(&audio_ion_pdev->dev);
  370. put_device(&audio_ion_pdev->dev);
  371. if (!plat_priv->audio_iommu_domain) {
  372. cnss_pr_err("Unable to get Audio ion iommu domain");
  373. return -EINVAL;
  374. }
  375. return 0;
  376. }
  377. int cnss_set_feature_list(struct cnss_plat_data *plat_priv,
  378. enum cnss_feature_v01 feature)
  379. {
  380. if (unlikely(!plat_priv || feature >= CNSS_MAX_FEATURE_V01))
  381. return -EINVAL;
  382. plat_priv->feature_list |= 1 << feature;
  383. return 0;
  384. }
  385. int cnss_clear_feature_list(struct cnss_plat_data *plat_priv,
  386. enum cnss_feature_v01 feature)
  387. {
  388. if (unlikely(!plat_priv || feature >= CNSS_MAX_FEATURE_V01))
  389. return -EINVAL;
  390. plat_priv->feature_list &= ~(1 << feature);
  391. return 0;
  392. }
  393. int cnss_get_feature_list(struct cnss_plat_data *plat_priv,
  394. u64 *feature_list)
  395. {
  396. if (unlikely(!plat_priv))
  397. return -EINVAL;
  398. *feature_list = plat_priv->feature_list;
  399. return 0;
  400. }
  401. void cnss_pm_stay_awake(struct cnss_plat_data *plat_priv)
  402. {
  403. if (atomic_inc_return(&plat_priv->pm_count) != 1)
  404. return;
  405. cnss_pr_dbg("PM stay awake, state: 0x%lx, count: %d\n",
  406. plat_priv->driver_state,
  407. atomic_read(&plat_priv->pm_count));
  408. pm_stay_awake(&plat_priv->plat_dev->dev);
  409. }
  410. void cnss_pm_relax(struct cnss_plat_data *plat_priv)
  411. {
  412. int r = atomic_dec_return(&plat_priv->pm_count);
  413. WARN_ON(r < 0);
  414. if (r != 0)
  415. return;
  416. cnss_pr_dbg("PM relax, state: 0x%lx, count: %d\n",
  417. plat_priv->driver_state,
  418. atomic_read(&plat_priv->pm_count));
  419. pm_relax(&plat_priv->plat_dev->dev);
  420. }
  421. int cnss_get_fw_files_for_target(struct device *dev,
  422. struct cnss_fw_files *pfw_files,
  423. u32 target_type, u32 target_version)
  424. {
  425. if (!pfw_files)
  426. return -ENODEV;
  427. switch (target_version) {
  428. case QCA6174_REV3_VERSION:
  429. case QCA6174_REV3_2_VERSION:
  430. memcpy(pfw_files, &FW_FILES_QCA6174_FW_3_0, sizeof(*pfw_files));
  431. break;
  432. default:
  433. memcpy(pfw_files, &FW_FILES_DEFAULT, sizeof(*pfw_files));
  434. cnss_pr_err("Unknown target version, type: 0x%X, version: 0x%X",
  435. target_type, target_version);
  436. break;
  437. }
  438. return 0;
  439. }
  440. EXPORT_SYMBOL(cnss_get_fw_files_for_target);
  441. int cnss_get_platform_cap(struct device *dev, struct cnss_platform_cap *cap)
  442. {
  443. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  444. if (!plat_priv)
  445. return -ENODEV;
  446. if (!cap)
  447. return -EINVAL;
  448. *cap = plat_priv->cap;
  449. cnss_pr_dbg("Platform cap_flag is 0x%x\n", cap->cap_flag);
  450. return 0;
  451. }
  452. EXPORT_SYMBOL(cnss_get_platform_cap);
  453. /**
  454. * cnss_get_fw_cap - Check whether FW supports specific capability or not
  455. * @dev: Device
  456. * @fw_cap: FW Capability which needs to be checked
  457. *
  458. * Return: TRUE if supported, FALSE on failure or if not supported
  459. */
  460. bool cnss_get_fw_cap(struct device *dev, enum cnss_fw_caps fw_cap)
  461. {
  462. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  463. bool is_supported = false;
  464. if (!plat_priv)
  465. return is_supported;
  466. if (!plat_priv->fw_caps)
  467. return is_supported;
  468. switch (fw_cap) {
  469. case CNSS_FW_CAP_DIRECT_LINK_SUPPORT:
  470. is_supported = !!(plat_priv->fw_caps &
  471. QMI_WLFW_DIRECT_LINK_SUPPORT_V01);
  472. if (is_supported && cnss_get_audio_iommu_domain(plat_priv))
  473. is_supported = false;
  474. break;
  475. default:
  476. cnss_pr_err("Invalid FW Capability: 0x%x\n", fw_cap);
  477. }
  478. cnss_pr_dbg("FW Capability 0x%x is %s\n", fw_cap,
  479. is_supported ? "supported" : "not supported");
  480. return is_supported;
  481. }
  482. EXPORT_SYMBOL(cnss_get_fw_cap);
  483. void cnss_request_pm_qos(struct device *dev, u32 qos_val)
  484. {
  485. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  486. if (!plat_priv)
  487. return;
  488. cpu_latency_qos_add_request(&plat_priv->qos_request, qos_val);
  489. }
  490. EXPORT_SYMBOL(cnss_request_pm_qos);
  491. void cnss_remove_pm_qos(struct device *dev)
  492. {
  493. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  494. if (!plat_priv)
  495. return;
  496. cpu_latency_qos_remove_request(&plat_priv->qos_request);
  497. }
  498. EXPORT_SYMBOL(cnss_remove_pm_qos);
  499. int cnss_wlan_enable(struct device *dev,
  500. struct cnss_wlan_enable_cfg *config,
  501. enum cnss_driver_mode mode,
  502. const char *host_version)
  503. {
  504. int ret = 0;
  505. struct cnss_plat_data *plat_priv;
  506. if (!dev) {
  507. cnss_pr_err("Invalid dev pointer\n");
  508. return -EINVAL;
  509. }
  510. plat_priv = cnss_bus_dev_to_plat_priv(dev);
  511. if (!plat_priv)
  512. return -ENODEV;
  513. if (plat_priv->device_id == QCA6174_DEVICE_ID)
  514. return 0;
  515. if (test_bit(QMI_BYPASS, &plat_priv->ctrl_params.quirks))
  516. return 0;
  517. if (!config || !host_version) {
  518. cnss_pr_err("Invalid config or host_version pointer\n");
  519. return -EINVAL;
  520. }
  521. cnss_pr_dbg("Mode: %d, config: %pK, host_version: %s\n",
  522. mode, config, host_version);
  523. if (mode == CNSS_WALTEST || mode == CNSS_CCPM)
  524. goto skip_cfg;
  525. if (plat_priv->device_id == QCN7605_DEVICE_ID)
  526. config->send_msi_ce = true;
  527. ret = cnss_wlfw_wlan_cfg_send_sync(plat_priv, config, host_version);
  528. if (ret)
  529. goto out;
  530. skip_cfg:
  531. ret = cnss_wlfw_wlan_mode_send_sync(plat_priv, mode);
  532. out:
  533. return ret;
  534. }
  535. EXPORT_SYMBOL(cnss_wlan_enable);
  536. int cnss_wlan_disable(struct device *dev, enum cnss_driver_mode mode)
  537. {
  538. int ret = 0;
  539. struct cnss_plat_data *plat_priv;
  540. if (!dev) {
  541. cnss_pr_err("Invalid dev pointer\n");
  542. return -EINVAL;
  543. }
  544. plat_priv = cnss_bus_dev_to_plat_priv(dev);
  545. if (!plat_priv)
  546. return -ENODEV;
  547. if (plat_priv->device_id == QCA6174_DEVICE_ID)
  548. return 0;
  549. if (test_bit(QMI_BYPASS, &plat_priv->ctrl_params.quirks))
  550. return 0;
  551. ret = cnss_wlfw_wlan_mode_send_sync(plat_priv, CNSS_OFF);
  552. cnss_bus_free_qdss_mem(plat_priv);
  553. return ret;
  554. }
  555. EXPORT_SYMBOL(cnss_wlan_disable);
  556. int cnss_audio_smmu_map(struct device *dev, phys_addr_t paddr,
  557. dma_addr_t iova, size_t size)
  558. {
  559. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  560. uint32_t page_offset;
  561. if (!plat_priv)
  562. return -ENODEV;
  563. if (!plat_priv->audio_iommu_domain)
  564. return -EINVAL;
  565. page_offset = iova & (PAGE_SIZE - 1);
  566. if (page_offset + size > PAGE_SIZE)
  567. size += PAGE_SIZE;
  568. iova -= page_offset;
  569. paddr -= page_offset;
  570. return iommu_map(plat_priv->audio_iommu_domain, iova, paddr,
  571. roundup(size, PAGE_SIZE), IOMMU_READ | IOMMU_WRITE |
  572. IOMMU_CACHE);
  573. }
  574. EXPORT_SYMBOL(cnss_audio_smmu_map);
  575. void cnss_audio_smmu_unmap(struct device *dev, dma_addr_t iova, size_t size)
  576. {
  577. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  578. uint32_t page_offset;
  579. if (!plat_priv)
  580. return;
  581. if (!plat_priv->audio_iommu_domain)
  582. return;
  583. page_offset = iova & (PAGE_SIZE - 1);
  584. if (page_offset + size > PAGE_SIZE)
  585. size += PAGE_SIZE;
  586. iova -= page_offset;
  587. iommu_unmap(plat_priv->audio_iommu_domain, iova,
  588. roundup(size, PAGE_SIZE));
  589. }
  590. EXPORT_SYMBOL(cnss_audio_smmu_unmap);
  591. int cnss_athdiag_read(struct device *dev, u32 offset, u32 mem_type,
  592. u32 data_len, u8 *output)
  593. {
  594. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  595. int ret = 0;
  596. if (!plat_priv) {
  597. cnss_pr_err("plat_priv is NULL!\n");
  598. return -EINVAL;
  599. }
  600. if (plat_priv->device_id == QCA6174_DEVICE_ID)
  601. return 0;
  602. if (!test_bit(CNSS_FW_READY, &plat_priv->driver_state)) {
  603. cnss_pr_err("Invalid state for athdiag read: 0x%lx\n",
  604. plat_priv->driver_state);
  605. ret = -EINVAL;
  606. goto out;
  607. }
  608. ret = cnss_wlfw_athdiag_read_send_sync(plat_priv, offset, mem_type,
  609. data_len, output);
  610. out:
  611. return ret;
  612. }
  613. EXPORT_SYMBOL(cnss_athdiag_read);
  614. int cnss_athdiag_write(struct device *dev, u32 offset, u32 mem_type,
  615. u32 data_len, u8 *input)
  616. {
  617. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  618. int ret = 0;
  619. if (!plat_priv) {
  620. cnss_pr_err("plat_priv is NULL!\n");
  621. return -EINVAL;
  622. }
  623. if (plat_priv->device_id == QCA6174_DEVICE_ID)
  624. return 0;
  625. if (!test_bit(CNSS_FW_READY, &plat_priv->driver_state)) {
  626. cnss_pr_err("Invalid state for athdiag write: 0x%lx\n",
  627. plat_priv->driver_state);
  628. ret = -EINVAL;
  629. goto out;
  630. }
  631. ret = cnss_wlfw_athdiag_write_send_sync(plat_priv, offset, mem_type,
  632. data_len, input);
  633. out:
  634. return ret;
  635. }
  636. EXPORT_SYMBOL(cnss_athdiag_write);
  637. int cnss_set_fw_log_mode(struct device *dev, u8 fw_log_mode)
  638. {
  639. struct cnss_plat_data *plat_priv;
  640. if (!dev) {
  641. cnss_pr_err("Invalid dev pointer\n");
  642. return -EINVAL;
  643. }
  644. plat_priv = cnss_bus_dev_to_plat_priv(dev);
  645. if (!plat_priv)
  646. return -ENODEV;
  647. if (plat_priv->device_id == QCA6174_DEVICE_ID)
  648. return 0;
  649. return cnss_wlfw_ini_send_sync(plat_priv, fw_log_mode);
  650. }
  651. EXPORT_SYMBOL(cnss_set_fw_log_mode);
  652. int cnss_set_pcie_gen_speed(struct device *dev, u8 pcie_gen_speed)
  653. {
  654. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  655. if (!plat_priv)
  656. return -EINVAL;
  657. if (!plat_priv->fw_pcie_gen_switch) {
  658. cnss_pr_err("Firmware does not support PCIe gen switch\n");
  659. return -EOPNOTSUPP;
  660. }
  661. if (pcie_gen_speed < QMI_PCIE_GEN_SPEED_1_V01 ||
  662. pcie_gen_speed > QMI_PCIE_GEN_SPEED_3_V01)
  663. return -EINVAL;
  664. cnss_pr_dbg("WLAN provided PCIE gen speed: %d\n", pcie_gen_speed);
  665. plat_priv->pcie_gen_speed = pcie_gen_speed;
  666. return 0;
  667. }
  668. EXPORT_SYMBOL(cnss_set_pcie_gen_speed);
  669. static int cnss_fw_mem_ready_hdlr(struct cnss_plat_data *plat_priv)
  670. {
  671. int ret = 0;
  672. if (!plat_priv)
  673. return -ENODEV;
  674. set_bit(CNSS_FW_MEM_READY, &plat_priv->driver_state);
  675. ret = cnss_wlfw_tgt_cap_send_sync(plat_priv);
  676. if (ret)
  677. goto out;
  678. if (plat_priv->hds_enabled)
  679. cnss_wlfw_bdf_dnld_send_sync(plat_priv, CNSS_BDF_HDS);
  680. cnss_wlfw_bdf_dnld_send_sync(plat_priv, CNSS_BDF_REGDB);
  681. if (plat_priv->device_id == QCN7605_DEVICE_ID)
  682. plat_priv->ctrl_params.bdf_type = CNSS_BDF_BIN;
  683. cnss_wlfw_ini_file_send_sync(plat_priv, WLFW_CONN_ROAM_INI_V01);
  684. ret = cnss_wlfw_bdf_dnld_send_sync(plat_priv,
  685. plat_priv->ctrl_params.bdf_type);
  686. if (ret)
  687. goto out;
  688. if (plat_priv->device_id == QCN7605_DEVICE_ID)
  689. return 0;
  690. ret = cnss_bus_load_m3(plat_priv);
  691. if (ret)
  692. goto out;
  693. ret = cnss_wlfw_m3_dnld_send_sync(plat_priv);
  694. if (ret)
  695. goto out;
  696. cnss_wlfw_qdss_dnld_send_sync(plat_priv);
  697. return 0;
  698. out:
  699. return ret;
  700. }
  701. static int cnss_request_antenna_sharing(struct cnss_plat_data *plat_priv)
  702. {
  703. int ret = 0;
  704. if (!plat_priv->antenna) {
  705. ret = cnss_wlfw_antenna_switch_send_sync(plat_priv);
  706. if (ret)
  707. goto out;
  708. }
  709. if (test_bit(CNSS_COEX_CONNECTED, &plat_priv->driver_state)) {
  710. ret = coex_antenna_switch_to_wlan_send_sync_msg(plat_priv);
  711. if (ret)
  712. goto out;
  713. }
  714. ret = cnss_wlfw_antenna_grant_send_sync(plat_priv);
  715. if (ret)
  716. goto out;
  717. return 0;
  718. out:
  719. return ret;
  720. }
  721. static void cnss_release_antenna_sharing(struct cnss_plat_data *plat_priv)
  722. {
  723. if (test_bit(CNSS_COEX_CONNECTED, &plat_priv->driver_state))
  724. coex_antenna_switch_to_mdm_send_sync_msg(plat_priv);
  725. }
  726. static int cnss_setup_dms_mac(struct cnss_plat_data *plat_priv)
  727. {
  728. u32 i;
  729. int ret = 0;
  730. struct cnss_plat_ipc_daemon_config *cfg;
  731. ret = cnss_qmi_get_dms_mac(plat_priv);
  732. if (ret == 0 && plat_priv->dms.mac_valid)
  733. goto qmi_send;
  734. /* DTSI property use-nv-mac is used to force DMS MAC address for WLAN.
  735. * Thus assert on failure to get MAC from DMS even after retries
  736. */
  737. if (plat_priv->use_nv_mac) {
  738. /* Check if Daemon says platform support DMS MAC provisioning */
  739. cfg = cnss_plat_ipc_qmi_daemon_config();
  740. if (cfg) {
  741. if (!cfg->dms_mac_addr_supported) {
  742. cnss_pr_err("DMS MAC address not supported\n");
  743. CNSS_ASSERT(0);
  744. return -EINVAL;
  745. }
  746. }
  747. for (i = 0; i < CNSS_DMS_QMI_CONNECTION_WAIT_RETRY; i++) {
  748. if (plat_priv->dms.mac_valid)
  749. break;
  750. ret = cnss_qmi_get_dms_mac(plat_priv);
  751. if (ret == 0)
  752. break;
  753. msleep(CNSS_DMS_QMI_CONNECTION_WAIT_MS);
  754. }
  755. if (!plat_priv->dms.mac_valid) {
  756. cnss_pr_err("Unable to get MAC from DMS after retries\n");
  757. CNSS_ASSERT(0);
  758. return -EINVAL;
  759. }
  760. }
  761. qmi_send:
  762. if (plat_priv->dms.mac_valid)
  763. ret =
  764. cnss_wlfw_wlan_mac_req_send_sync(plat_priv, plat_priv->dms.mac,
  765. ARRAY_SIZE(plat_priv->dms.mac));
  766. return ret;
  767. }
  768. static int cnss_cal_db_mem_update(struct cnss_plat_data *plat_priv,
  769. enum cnss_cal_db_op op, u32 *size)
  770. {
  771. int ret = 0;
  772. u32 timeout = cnss_get_timeout(plat_priv,
  773. CNSS_TIMEOUT_DAEMON_CONNECTION);
  774. enum cnss_plat_ipc_qmi_client_id_v01 client_id =
  775. CNSS_PLAT_IPC_DAEMON_QMI_CLIENT_V01;
  776. if (op >= CNSS_CAL_DB_INVALID_OP)
  777. return -EINVAL;
  778. if (!plat_priv->cbc_file_download) {
  779. cnss_pr_info("CAL DB file not required as per BDF\n");
  780. return 0;
  781. }
  782. if (*size == 0) {
  783. cnss_pr_err("Invalid cal file size\n");
  784. return -EINVAL;
  785. }
  786. if (!test_bit(CNSS_DAEMON_CONNECTED, &plat_priv->driver_state)) {
  787. cnss_pr_info("Waiting for CNSS Daemon connection\n");
  788. ret = wait_for_completion_timeout(&plat_priv->daemon_connected,
  789. msecs_to_jiffies(timeout));
  790. if (!ret) {
  791. cnss_pr_err("Daemon not yet connected\n");
  792. CNSS_ASSERT(0);
  793. return ret;
  794. }
  795. }
  796. if (!plat_priv->cal_mem->va) {
  797. cnss_pr_err("CAL DB Memory not setup for FW\n");
  798. return -EINVAL;
  799. }
  800. /* Copy CAL DB file contents to/from CAL_TYPE_DDR mem allocated to FW */
  801. if (op == CNSS_CAL_DB_DOWNLOAD) {
  802. cnss_pr_dbg("Initiating Calibration file download to mem\n");
  803. ret = cnss_plat_ipc_qmi_file_download(client_id,
  804. CNSS_CAL_DB_FILE_NAME,
  805. plat_priv->cal_mem->va,
  806. size);
  807. } else {
  808. cnss_pr_dbg("Initiating Calibration mem upload to file\n");
  809. ret = cnss_plat_ipc_qmi_file_upload(client_id,
  810. CNSS_CAL_DB_FILE_NAME,
  811. plat_priv->cal_mem->va,
  812. *size);
  813. }
  814. if (ret)
  815. cnss_pr_err("Cal DB file %s %s failure\n",
  816. CNSS_CAL_DB_FILE_NAME,
  817. op == CNSS_CAL_DB_DOWNLOAD ? "download" : "upload");
  818. else
  819. cnss_pr_dbg("Cal DB file %s %s size %d done\n",
  820. CNSS_CAL_DB_FILE_NAME,
  821. op == CNSS_CAL_DB_DOWNLOAD ? "download" : "upload",
  822. *size);
  823. return ret;
  824. }
  825. static int cnss_cal_mem_upload_to_file(struct cnss_plat_data *plat_priv)
  826. {
  827. if (plat_priv->cal_file_size > plat_priv->cal_mem->size) {
  828. cnss_pr_err("Cal file size is larger than Cal DB Mem size\n");
  829. return -EINVAL;
  830. }
  831. return cnss_cal_db_mem_update(plat_priv, CNSS_CAL_DB_UPLOAD,
  832. &plat_priv->cal_file_size);
  833. }
  834. static int cnss_cal_file_download_to_mem(struct cnss_plat_data *plat_priv,
  835. u32 *cal_file_size)
  836. {
  837. /* To download pass the total size of cal DB mem allocated.
  838. * After cal file is download to mem, its size is updated in
  839. * return pointer
  840. */
  841. *cal_file_size = plat_priv->cal_mem->size;
  842. return cnss_cal_db_mem_update(plat_priv, CNSS_CAL_DB_DOWNLOAD,
  843. cal_file_size);
  844. }
  845. static int cnss_fw_ready_hdlr(struct cnss_plat_data *plat_priv)
  846. {
  847. int ret = 0;
  848. u32 cal_file_size = 0;
  849. if (!plat_priv)
  850. return -ENODEV;
  851. if (test_bit(CNSS_IN_REBOOT, &plat_priv->driver_state)) {
  852. cnss_pr_err("Reboot is in progress, ignore FW ready\n");
  853. return -EINVAL;
  854. }
  855. cnss_pr_dbg("Processing FW Init Done..\n");
  856. del_timer(&plat_priv->fw_boot_timer);
  857. set_bit(CNSS_FW_READY, &plat_priv->driver_state);
  858. clear_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state);
  859. cnss_wlfw_send_pcie_gen_speed_sync(plat_priv);
  860. cnss_send_subsys_restart_level_msg(plat_priv);
  861. if (test_bit(CNSS_FW_BOOT_RECOVERY, &plat_priv->driver_state)) {
  862. clear_bit(CNSS_FW_BOOT_RECOVERY, &plat_priv->driver_state);
  863. clear_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state);
  864. }
  865. if (test_bit(ENABLE_WALTEST, &plat_priv->ctrl_params.quirks)) {
  866. ret = cnss_wlfw_wlan_mode_send_sync(plat_priv,
  867. CNSS_WALTEST);
  868. } else if (test_bit(CNSS_IN_COLD_BOOT_CAL, &plat_priv->driver_state)) {
  869. cnss_request_antenna_sharing(plat_priv);
  870. cnss_cal_file_download_to_mem(plat_priv, &cal_file_size);
  871. cnss_wlfw_cal_report_req_send_sync(plat_priv, cal_file_size);
  872. plat_priv->cal_time = jiffies;
  873. ret = cnss_wlfw_wlan_mode_send_sync(plat_priv,
  874. CNSS_CALIBRATION);
  875. } else {
  876. ret = cnss_setup_dms_mac(plat_priv);
  877. ret = cnss_bus_call_driver_probe(plat_priv);
  878. }
  879. if (ret && test_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state))
  880. goto out;
  881. else if (ret)
  882. goto shutdown;
  883. cnss_vreg_unvote_type(plat_priv, CNSS_VREG_PRIM);
  884. return 0;
  885. shutdown:
  886. cnss_bus_dev_shutdown(plat_priv);
  887. clear_bit(CNSS_FW_READY, &plat_priv->driver_state);
  888. clear_bit(CNSS_FW_MEM_READY, &plat_priv->driver_state);
  889. out:
  890. return ret;
  891. }
  892. static char *cnss_driver_event_to_str(enum cnss_driver_event_type type)
  893. {
  894. switch (type) {
  895. case CNSS_DRIVER_EVENT_SERVER_ARRIVE:
  896. return "SERVER_ARRIVE";
  897. case CNSS_DRIVER_EVENT_SERVER_EXIT:
  898. return "SERVER_EXIT";
  899. case CNSS_DRIVER_EVENT_REQUEST_MEM:
  900. return "REQUEST_MEM";
  901. case CNSS_DRIVER_EVENT_FW_MEM_READY:
  902. return "FW_MEM_READY";
  903. case CNSS_DRIVER_EVENT_FW_READY:
  904. return "FW_READY";
  905. case CNSS_DRIVER_EVENT_COLD_BOOT_CAL_START:
  906. return "COLD_BOOT_CAL_START";
  907. case CNSS_DRIVER_EVENT_COLD_BOOT_CAL_DONE:
  908. return "COLD_BOOT_CAL_DONE";
  909. case CNSS_DRIVER_EVENT_REGISTER_DRIVER:
  910. return "REGISTER_DRIVER";
  911. case CNSS_DRIVER_EVENT_UNREGISTER_DRIVER:
  912. return "UNREGISTER_DRIVER";
  913. case CNSS_DRIVER_EVENT_RECOVERY:
  914. return "RECOVERY";
  915. case CNSS_DRIVER_EVENT_FORCE_FW_ASSERT:
  916. return "FORCE_FW_ASSERT";
  917. case CNSS_DRIVER_EVENT_POWER_UP:
  918. return "POWER_UP";
  919. case CNSS_DRIVER_EVENT_POWER_DOWN:
  920. return "POWER_DOWN";
  921. case CNSS_DRIVER_EVENT_IDLE_RESTART:
  922. return "IDLE_RESTART";
  923. case CNSS_DRIVER_EVENT_IDLE_SHUTDOWN:
  924. return "IDLE_SHUTDOWN";
  925. case CNSS_DRIVER_EVENT_IMS_WFC_CALL_IND:
  926. return "IMS_WFC_CALL_IND";
  927. case CNSS_DRIVER_EVENT_WLFW_TWT_CFG_IND:
  928. return "WLFW_TWC_CFG_IND";
  929. case CNSS_DRIVER_EVENT_QDSS_TRACE_REQ_MEM:
  930. return "QDSS_TRACE_REQ_MEM";
  931. case CNSS_DRIVER_EVENT_FW_MEM_FILE_SAVE:
  932. return "FW_MEM_FILE_SAVE";
  933. case CNSS_DRIVER_EVENT_QDSS_TRACE_FREE:
  934. return "QDSS_TRACE_FREE";
  935. case CNSS_DRIVER_EVENT_QDSS_TRACE_REQ_DATA:
  936. return "QDSS_TRACE_REQ_DATA";
  937. case CNSS_DRIVER_EVENT_MAX:
  938. return "EVENT_MAX";
  939. }
  940. return "UNKNOWN";
  941. };
  942. int cnss_driver_event_post(struct cnss_plat_data *plat_priv,
  943. enum cnss_driver_event_type type,
  944. u32 flags, void *data)
  945. {
  946. struct cnss_driver_event *event;
  947. unsigned long irq_flags;
  948. int gfp = GFP_KERNEL;
  949. int ret = 0;
  950. if (!plat_priv)
  951. return -ENODEV;
  952. cnss_pr_dbg("Posting event: %s(%d)%s, state: 0x%lx flags: 0x%0x\n",
  953. cnss_driver_event_to_str(type), type,
  954. flags ? "-sync" : "", plat_priv->driver_state, flags);
  955. if (type >= CNSS_DRIVER_EVENT_MAX) {
  956. cnss_pr_err("Invalid Event type: %d, can't post", type);
  957. return -EINVAL;
  958. }
  959. if (in_interrupt() || irqs_disabled())
  960. gfp = GFP_ATOMIC;
  961. event = kzalloc(sizeof(*event), gfp);
  962. if (!event)
  963. return -ENOMEM;
  964. cnss_pm_stay_awake(plat_priv);
  965. event->type = type;
  966. event->data = data;
  967. init_completion(&event->complete);
  968. event->ret = CNSS_EVENT_PENDING;
  969. event->sync = !!(flags & CNSS_EVENT_SYNC);
  970. spin_lock_irqsave(&plat_priv->event_lock, irq_flags);
  971. list_add_tail(&event->list, &plat_priv->event_list);
  972. spin_unlock_irqrestore(&plat_priv->event_lock, irq_flags);
  973. queue_work(plat_priv->event_wq, &plat_priv->event_work);
  974. if (!(flags & CNSS_EVENT_SYNC))
  975. goto out;
  976. if (flags & CNSS_EVENT_UNKILLABLE)
  977. wait_for_completion(&event->complete);
  978. else if (flags & CNSS_EVENT_UNINTERRUPTIBLE)
  979. ret = wait_for_completion_killable(&event->complete);
  980. else
  981. ret = wait_for_completion_interruptible(&event->complete);
  982. cnss_pr_dbg("Completed event: %s(%d), state: 0x%lx, ret: %d/%d\n",
  983. cnss_driver_event_to_str(type), type,
  984. plat_priv->driver_state, ret, event->ret);
  985. spin_lock_irqsave(&plat_priv->event_lock, irq_flags);
  986. if (ret == -ERESTARTSYS && event->ret == CNSS_EVENT_PENDING) {
  987. event->sync = false;
  988. spin_unlock_irqrestore(&plat_priv->event_lock, irq_flags);
  989. ret = -EINTR;
  990. goto out;
  991. }
  992. spin_unlock_irqrestore(&plat_priv->event_lock, irq_flags);
  993. ret = event->ret;
  994. kfree(event);
  995. out:
  996. cnss_pm_relax(plat_priv);
  997. return ret;
  998. }
  999. /**
  1000. * cnss_get_timeout - Get timeout for corresponding type.
  1001. * @plat_priv: Pointer to platform driver context.
  1002. * @cnss_timeout_type: Timeout type.
  1003. *
  1004. * Return: Timeout in milliseconds.
  1005. */
  1006. unsigned int cnss_get_timeout(struct cnss_plat_data *plat_priv,
  1007. enum cnss_timeout_type timeout_type)
  1008. {
  1009. unsigned int qmi_timeout = cnss_get_qmi_timeout(plat_priv);
  1010. switch (timeout_type) {
  1011. case CNSS_TIMEOUT_QMI:
  1012. return qmi_timeout;
  1013. case CNSS_TIMEOUT_POWER_UP:
  1014. return (qmi_timeout << 2);
  1015. case CNSS_TIMEOUT_IDLE_RESTART:
  1016. /* In idle restart power up sequence, we have fw_boot_timer to
  1017. * handle FW initialization failure.
  1018. * It uses WLAN_MISSION_MODE_TIMEOUT, so setup 3x that time to
  1019. * account for FW dump collection and FW re-initialization on
  1020. * retry.
  1021. */
  1022. return (qmi_timeout + WLAN_MISSION_MODE_TIMEOUT * 3);
  1023. case CNSS_TIMEOUT_CALIBRATION:
  1024. /* Similar to mission mode, in CBC if FW init fails
  1025. * fw recovery is tried. Thus return 2x the CBC timeout.
  1026. */
  1027. return (qmi_timeout + WLAN_COLD_BOOT_CAL_TIMEOUT * 2);
  1028. case CNSS_TIMEOUT_WLAN_WATCHDOG:
  1029. return ((qmi_timeout << 1) + WLAN_WD_TIMEOUT_MS);
  1030. case CNSS_TIMEOUT_RDDM:
  1031. return CNSS_RDDM_TIMEOUT_MS;
  1032. case CNSS_TIMEOUT_RECOVERY:
  1033. return RECOVERY_TIMEOUT;
  1034. case CNSS_TIMEOUT_DAEMON_CONNECTION:
  1035. return qmi_timeout + CNSS_DAEMON_CONNECT_TIMEOUT_MS;
  1036. default:
  1037. return qmi_timeout;
  1038. }
  1039. }
  1040. unsigned int cnss_get_boot_timeout(struct device *dev)
  1041. {
  1042. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  1043. if (!plat_priv) {
  1044. cnss_pr_err("plat_priv is NULL\n");
  1045. return 0;
  1046. }
  1047. return cnss_get_timeout(plat_priv, CNSS_TIMEOUT_QMI);
  1048. }
  1049. EXPORT_SYMBOL(cnss_get_boot_timeout);
  1050. int cnss_power_up(struct device *dev)
  1051. {
  1052. int ret = 0;
  1053. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  1054. unsigned int timeout;
  1055. if (!plat_priv) {
  1056. cnss_pr_err("plat_priv is NULL\n");
  1057. return -ENODEV;
  1058. }
  1059. cnss_pr_dbg("Powering up device\n");
  1060. ret = cnss_driver_event_post(plat_priv,
  1061. CNSS_DRIVER_EVENT_POWER_UP,
  1062. CNSS_EVENT_SYNC, NULL);
  1063. if (ret)
  1064. goto out;
  1065. if (plat_priv->device_id == QCA6174_DEVICE_ID)
  1066. goto out;
  1067. timeout = cnss_get_timeout(plat_priv, CNSS_TIMEOUT_POWER_UP);
  1068. reinit_completion(&plat_priv->power_up_complete);
  1069. ret = wait_for_completion_timeout(&plat_priv->power_up_complete,
  1070. msecs_to_jiffies(timeout));
  1071. if (!ret) {
  1072. cnss_pr_err("Timeout (%ums) waiting for power up to complete\n",
  1073. timeout);
  1074. ret = -EAGAIN;
  1075. goto out;
  1076. }
  1077. return 0;
  1078. out:
  1079. return ret;
  1080. }
  1081. EXPORT_SYMBOL(cnss_power_up);
  1082. int cnss_power_down(struct device *dev)
  1083. {
  1084. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  1085. if (!plat_priv) {
  1086. cnss_pr_err("plat_priv is NULL\n");
  1087. return -ENODEV;
  1088. }
  1089. cnss_pr_dbg("Powering down device\n");
  1090. return cnss_driver_event_post(plat_priv,
  1091. CNSS_DRIVER_EVENT_POWER_DOWN,
  1092. CNSS_EVENT_SYNC, NULL);
  1093. }
  1094. EXPORT_SYMBOL(cnss_power_down);
  1095. int cnss_idle_restart(struct device *dev)
  1096. {
  1097. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  1098. unsigned int timeout;
  1099. int ret = 0;
  1100. if (!plat_priv) {
  1101. cnss_pr_err("plat_priv is NULL\n");
  1102. return -ENODEV;
  1103. }
  1104. if (!mutex_trylock(&plat_priv->driver_ops_lock)) {
  1105. cnss_pr_dbg("Another driver operation is in progress, ignore idle restart\n");
  1106. return -EBUSY;
  1107. }
  1108. cnss_pr_dbg("Doing idle restart\n");
  1109. reinit_completion(&plat_priv->power_up_complete);
  1110. if (test_bit(CNSS_IN_REBOOT, &plat_priv->driver_state)) {
  1111. cnss_pr_dbg("Reboot or shutdown is in progress, ignore idle restart\n");
  1112. ret = -EINVAL;
  1113. goto out;
  1114. }
  1115. ret = cnss_driver_event_post(plat_priv,
  1116. CNSS_DRIVER_EVENT_IDLE_RESTART,
  1117. CNSS_EVENT_SYNC_UNINTERRUPTIBLE, NULL);
  1118. if (ret)
  1119. goto out;
  1120. if (plat_priv->device_id == QCA6174_DEVICE_ID) {
  1121. ret = cnss_bus_call_driver_probe(plat_priv);
  1122. goto out;
  1123. }
  1124. timeout = cnss_get_timeout(plat_priv, CNSS_TIMEOUT_IDLE_RESTART);
  1125. ret = wait_for_completion_timeout(&plat_priv->power_up_complete,
  1126. msecs_to_jiffies(timeout));
  1127. if (plat_priv->power_up_error) {
  1128. ret = plat_priv->power_up_error;
  1129. clear_bit(CNSS_DRIVER_IDLE_RESTART, &plat_priv->driver_state);
  1130. cnss_pr_dbg("Power up error:%d, exiting\n",
  1131. plat_priv->power_up_error);
  1132. goto out;
  1133. }
  1134. if (!ret) {
  1135. /* This exception occurs after attempting retry of FW recovery.
  1136. * Thus we can safely power off the device.
  1137. */
  1138. cnss_fatal_err("Timeout (%ums) waiting for idle restart to complete\n",
  1139. timeout);
  1140. ret = -ETIMEDOUT;
  1141. cnss_power_down(dev);
  1142. CNSS_ASSERT(0);
  1143. goto out;
  1144. }
  1145. if (test_bit(CNSS_IN_REBOOT, &plat_priv->driver_state)) {
  1146. cnss_pr_dbg("Reboot or shutdown is in progress, ignore idle restart\n");
  1147. del_timer(&plat_priv->fw_boot_timer);
  1148. ret = -EINVAL;
  1149. goto out;
  1150. }
  1151. /* In non-DRV mode, remove MHI satellite configuration. Switching to
  1152. * non-DRV is supported only once after device reboots and before wifi
  1153. * is turned on. We do not allow switching back to DRV.
  1154. * To bring device back into DRV, user needs to reboot device.
  1155. */
  1156. if (test_bit(DISABLE_DRV, &plat_priv->ctrl_params.quirks)) {
  1157. cnss_pr_dbg("DRV is disabled\n");
  1158. cnss_bus_disable_mhi_satellite_cfg(plat_priv);
  1159. }
  1160. mutex_unlock(&plat_priv->driver_ops_lock);
  1161. return 0;
  1162. out:
  1163. mutex_unlock(&plat_priv->driver_ops_lock);
  1164. return ret;
  1165. }
  1166. EXPORT_SYMBOL(cnss_idle_restart);
  1167. int cnss_idle_shutdown(struct device *dev)
  1168. {
  1169. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  1170. if (!plat_priv) {
  1171. cnss_pr_err("plat_priv is NULL\n");
  1172. return -ENODEV;
  1173. }
  1174. if (test_bit(CNSS_IN_SUSPEND_RESUME, &plat_priv->driver_state)) {
  1175. cnss_pr_dbg("System suspend or resume in progress, ignore idle shutdown\n");
  1176. return -EAGAIN;
  1177. }
  1178. cnss_pr_dbg("Doing idle shutdown\n");
  1179. if (test_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state) ||
  1180. test_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state)) {
  1181. cnss_pr_dbg("Recovery in progress. Ignore IDLE Shutdown\n");
  1182. return -EBUSY;
  1183. }
  1184. return cnss_driver_event_post(plat_priv,
  1185. CNSS_DRIVER_EVENT_IDLE_SHUTDOWN,
  1186. CNSS_EVENT_SYNC_UNINTERRUPTIBLE, NULL);
  1187. }
  1188. EXPORT_SYMBOL(cnss_idle_shutdown);
  1189. static int cnss_get_resources(struct cnss_plat_data *plat_priv)
  1190. {
  1191. int ret = 0;
  1192. ret = cnss_get_vreg_type(plat_priv, CNSS_VREG_PRIM);
  1193. if (ret < 0) {
  1194. cnss_pr_err("Failed to get vreg, err = %d\n", ret);
  1195. goto out;
  1196. }
  1197. ret = cnss_get_clk(plat_priv);
  1198. if (ret) {
  1199. cnss_pr_err("Failed to get clocks, err = %d\n", ret);
  1200. goto put_vreg;
  1201. }
  1202. ret = cnss_get_pinctrl(plat_priv);
  1203. if (ret) {
  1204. cnss_pr_err("Failed to get pinctrl, err = %d\n", ret);
  1205. goto put_clk;
  1206. }
  1207. return 0;
  1208. put_clk:
  1209. cnss_put_clk(plat_priv);
  1210. put_vreg:
  1211. cnss_put_vreg_type(plat_priv, CNSS_VREG_PRIM);
  1212. out:
  1213. return ret;
  1214. }
  1215. static void cnss_put_resources(struct cnss_plat_data *plat_priv)
  1216. {
  1217. cnss_put_clk(plat_priv);
  1218. cnss_put_vreg_type(plat_priv, CNSS_VREG_PRIM);
  1219. }
  1220. #if IS_ENABLED(CONFIG_ESOC) && IS_ENABLED(CONFIG_MSM_SUBSYSTEM_RESTART)
  1221. static int cnss_modem_notifier_nb(struct notifier_block *nb,
  1222. unsigned long code,
  1223. void *ss_handle)
  1224. {
  1225. struct cnss_plat_data *plat_priv =
  1226. container_of(nb, struct cnss_plat_data, modem_nb);
  1227. struct cnss_esoc_info *esoc_info;
  1228. cnss_pr_dbg("Modem notifier: event %lu\n", code);
  1229. if (!plat_priv)
  1230. return NOTIFY_DONE;
  1231. esoc_info = &plat_priv->esoc_info;
  1232. if (code == SUBSYS_AFTER_POWERUP)
  1233. esoc_info->modem_current_status = 1;
  1234. else if (code == SUBSYS_BEFORE_SHUTDOWN)
  1235. esoc_info->modem_current_status = 0;
  1236. else
  1237. return NOTIFY_DONE;
  1238. if (!cnss_bus_call_driver_modem_status(plat_priv,
  1239. esoc_info->modem_current_status))
  1240. return NOTIFY_DONE;
  1241. return NOTIFY_OK;
  1242. }
  1243. static int cnss_register_esoc(struct cnss_plat_data *plat_priv)
  1244. {
  1245. int ret = 0;
  1246. struct device *dev;
  1247. struct cnss_esoc_info *esoc_info;
  1248. struct esoc_desc *esoc_desc;
  1249. const char *client_desc;
  1250. dev = &plat_priv->plat_dev->dev;
  1251. esoc_info = &plat_priv->esoc_info;
  1252. esoc_info->notify_modem_status =
  1253. of_property_read_bool(dev->of_node,
  1254. "qcom,notify-modem-status");
  1255. if (!esoc_info->notify_modem_status)
  1256. goto out;
  1257. ret = of_property_read_string_index(dev->of_node, "esoc-names", 0,
  1258. &client_desc);
  1259. if (ret) {
  1260. cnss_pr_dbg("esoc-names is not defined in DT, skip!\n");
  1261. } else {
  1262. esoc_desc = devm_register_esoc_client(dev, client_desc);
  1263. if (IS_ERR_OR_NULL(esoc_desc)) {
  1264. ret = PTR_RET(esoc_desc);
  1265. cnss_pr_err("Failed to register esoc_desc, err = %d\n",
  1266. ret);
  1267. goto out;
  1268. }
  1269. esoc_info->esoc_desc = esoc_desc;
  1270. }
  1271. plat_priv->modem_nb.notifier_call = cnss_modem_notifier_nb;
  1272. esoc_info->modem_current_status = 0;
  1273. esoc_info->modem_notify_handler =
  1274. subsys_notif_register_notifier(esoc_info->esoc_desc ?
  1275. esoc_info->esoc_desc->name :
  1276. "modem", &plat_priv->modem_nb);
  1277. if (IS_ERR(esoc_info->modem_notify_handler)) {
  1278. ret = PTR_ERR(esoc_info->modem_notify_handler);
  1279. cnss_pr_err("Failed to register esoc notifier, err = %d\n",
  1280. ret);
  1281. goto unreg_esoc;
  1282. }
  1283. return 0;
  1284. unreg_esoc:
  1285. if (esoc_info->esoc_desc)
  1286. devm_unregister_esoc_client(dev, esoc_info->esoc_desc);
  1287. out:
  1288. return ret;
  1289. }
  1290. static void cnss_unregister_esoc(struct cnss_plat_data *plat_priv)
  1291. {
  1292. struct device *dev;
  1293. struct cnss_esoc_info *esoc_info;
  1294. dev = &plat_priv->plat_dev->dev;
  1295. esoc_info = &plat_priv->esoc_info;
  1296. if (esoc_info->notify_modem_status)
  1297. subsys_notif_unregister_notifier
  1298. (esoc_info->modem_notify_handler,
  1299. &plat_priv->modem_nb);
  1300. if (esoc_info->esoc_desc)
  1301. devm_unregister_esoc_client(dev, esoc_info->esoc_desc);
  1302. }
  1303. #else
  1304. static inline int cnss_register_esoc(struct cnss_plat_data *plat_priv)
  1305. {
  1306. return 0;
  1307. }
  1308. static inline void cnss_unregister_esoc(struct cnss_plat_data *plat_priv) {}
  1309. #endif
  1310. int cnss_enable_dev_sol_irq(struct cnss_plat_data *plat_priv)
  1311. {
  1312. struct cnss_sol_gpio *sol_gpio = &plat_priv->sol_gpio;
  1313. int ret = 0;
  1314. if (sol_gpio->dev_sol_gpio < 0 || sol_gpio->dev_sol_irq <= 0)
  1315. return 0;
  1316. enable_irq(sol_gpio->dev_sol_irq);
  1317. ret = enable_irq_wake(sol_gpio->dev_sol_irq);
  1318. if (ret)
  1319. cnss_pr_err("Failed to enable device SOL as wake IRQ, err = %d\n",
  1320. ret);
  1321. return ret;
  1322. }
  1323. int cnss_disable_dev_sol_irq(struct cnss_plat_data *plat_priv)
  1324. {
  1325. struct cnss_sol_gpio *sol_gpio = &plat_priv->sol_gpio;
  1326. int ret = 0;
  1327. if (sol_gpio->dev_sol_gpio < 0 || sol_gpio->dev_sol_irq <= 0)
  1328. return 0;
  1329. ret = disable_irq_wake(sol_gpio->dev_sol_irq);
  1330. if (ret)
  1331. cnss_pr_err("Failed to disable device SOL as wake IRQ, err = %d\n",
  1332. ret);
  1333. disable_irq(sol_gpio->dev_sol_irq);
  1334. return ret;
  1335. }
  1336. int cnss_get_dev_sol_value(struct cnss_plat_data *plat_priv)
  1337. {
  1338. struct cnss_sol_gpio *sol_gpio = &plat_priv->sol_gpio;
  1339. if (sol_gpio->dev_sol_gpio < 0)
  1340. return -EINVAL;
  1341. return gpio_get_value(sol_gpio->dev_sol_gpio);
  1342. }
  1343. static irqreturn_t cnss_dev_sol_handler(int irq, void *data)
  1344. {
  1345. struct cnss_plat_data *plat_priv = data;
  1346. struct cnss_sol_gpio *sol_gpio = &plat_priv->sol_gpio;
  1347. sol_gpio->dev_sol_counter++;
  1348. cnss_pr_dbg("WLAN device SOL IRQ (%u) is asserted #%u\n",
  1349. irq, sol_gpio->dev_sol_counter);
  1350. /* Make sure abort current suspend */
  1351. cnss_pm_stay_awake(plat_priv);
  1352. cnss_pm_relax(plat_priv);
  1353. pm_system_wakeup();
  1354. cnss_bus_handle_dev_sol_irq(plat_priv);
  1355. return IRQ_HANDLED;
  1356. }
  1357. static int cnss_init_dev_sol_gpio(struct cnss_plat_data *plat_priv)
  1358. {
  1359. struct device *dev = &plat_priv->plat_dev->dev;
  1360. struct cnss_sol_gpio *sol_gpio = &plat_priv->sol_gpio;
  1361. int ret = 0;
  1362. sol_gpio->dev_sol_gpio = of_get_named_gpio(dev->of_node,
  1363. "wlan-dev-sol-gpio", 0);
  1364. if (sol_gpio->dev_sol_gpio < 0)
  1365. goto out;
  1366. cnss_pr_dbg("Get device SOL GPIO (%d) from device node\n",
  1367. sol_gpio->dev_sol_gpio);
  1368. ret = gpio_request(sol_gpio->dev_sol_gpio, "wlan_dev_sol_gpio");
  1369. if (ret) {
  1370. cnss_pr_err("Failed to request device SOL GPIO, err = %d\n",
  1371. ret);
  1372. goto out;
  1373. }
  1374. gpio_direction_input(sol_gpio->dev_sol_gpio);
  1375. sol_gpio->dev_sol_irq = gpio_to_irq(sol_gpio->dev_sol_gpio);
  1376. ret = request_irq(sol_gpio->dev_sol_irq, cnss_dev_sol_handler,
  1377. IRQF_TRIGGER_FALLING, "wlan_dev_sol_irq", plat_priv);
  1378. if (ret) {
  1379. cnss_pr_err("Failed to request device SOL IRQ, err = %d\n", ret);
  1380. goto free_gpio;
  1381. }
  1382. return 0;
  1383. free_gpio:
  1384. gpio_free(sol_gpio->dev_sol_gpio);
  1385. out:
  1386. return ret;
  1387. }
  1388. static void cnss_deinit_dev_sol_gpio(struct cnss_plat_data *plat_priv)
  1389. {
  1390. struct cnss_sol_gpio *sol_gpio = &plat_priv->sol_gpio;
  1391. if (sol_gpio->dev_sol_gpio < 0)
  1392. return;
  1393. free_irq(sol_gpio->dev_sol_irq, plat_priv);
  1394. gpio_free(sol_gpio->dev_sol_gpio);
  1395. }
  1396. int cnss_set_host_sol_value(struct cnss_plat_data *plat_priv, int value)
  1397. {
  1398. struct cnss_sol_gpio *sol_gpio = &plat_priv->sol_gpio;
  1399. if (sol_gpio->host_sol_gpio < 0)
  1400. return -EINVAL;
  1401. if (value)
  1402. cnss_pr_dbg("Assert host SOL GPIO\n");
  1403. gpio_set_value(sol_gpio->host_sol_gpio, value);
  1404. return 0;
  1405. }
  1406. int cnss_get_host_sol_value(struct cnss_plat_data *plat_priv)
  1407. {
  1408. struct cnss_sol_gpio *sol_gpio = &plat_priv->sol_gpio;
  1409. if (sol_gpio->host_sol_gpio < 0)
  1410. return -EINVAL;
  1411. return gpio_get_value(sol_gpio->host_sol_gpio);
  1412. }
  1413. static int cnss_init_host_sol_gpio(struct cnss_plat_data *plat_priv)
  1414. {
  1415. struct device *dev = &plat_priv->plat_dev->dev;
  1416. struct cnss_sol_gpio *sol_gpio = &plat_priv->sol_gpio;
  1417. int ret = 0;
  1418. sol_gpio->host_sol_gpio = of_get_named_gpio(dev->of_node,
  1419. "wlan-host-sol-gpio", 0);
  1420. if (sol_gpio->host_sol_gpio < 0)
  1421. goto out;
  1422. cnss_pr_dbg("Get host SOL GPIO (%d) from device node\n",
  1423. sol_gpio->host_sol_gpio);
  1424. ret = gpio_request(sol_gpio->host_sol_gpio, "wlan_host_sol_gpio");
  1425. if (ret) {
  1426. cnss_pr_err("Failed to request host SOL GPIO, err = %d\n",
  1427. ret);
  1428. goto out;
  1429. }
  1430. gpio_direction_output(sol_gpio->host_sol_gpio, 0);
  1431. return 0;
  1432. out:
  1433. return ret;
  1434. }
  1435. static void cnss_deinit_host_sol_gpio(struct cnss_plat_data *plat_priv)
  1436. {
  1437. struct cnss_sol_gpio *sol_gpio = &plat_priv->sol_gpio;
  1438. if (sol_gpio->host_sol_gpio < 0)
  1439. return;
  1440. gpio_free(sol_gpio->host_sol_gpio);
  1441. }
  1442. static int cnss_init_sol_gpio(struct cnss_plat_data *plat_priv)
  1443. {
  1444. int ret;
  1445. ret = cnss_init_dev_sol_gpio(plat_priv);
  1446. if (ret)
  1447. goto out;
  1448. ret = cnss_init_host_sol_gpio(plat_priv);
  1449. if (ret)
  1450. goto deinit_dev_sol;
  1451. return 0;
  1452. deinit_dev_sol:
  1453. cnss_deinit_dev_sol_gpio(plat_priv);
  1454. out:
  1455. return ret;
  1456. }
  1457. static void cnss_deinit_sol_gpio(struct cnss_plat_data *plat_priv)
  1458. {
  1459. cnss_deinit_host_sol_gpio(plat_priv);
  1460. cnss_deinit_dev_sol_gpio(plat_priv);
  1461. }
  1462. #if IS_ENABLED(CONFIG_MSM_SUBSYSTEM_RESTART)
  1463. static int cnss_subsys_powerup(const struct subsys_desc *subsys_desc)
  1464. {
  1465. struct cnss_plat_data *plat_priv;
  1466. int ret = 0;
  1467. if (!subsys_desc->dev) {
  1468. cnss_pr_err("dev from subsys_desc is NULL\n");
  1469. return -ENODEV;
  1470. }
  1471. plat_priv = dev_get_drvdata(subsys_desc->dev);
  1472. if (!plat_priv) {
  1473. cnss_pr_err("plat_priv is NULL\n");
  1474. return -ENODEV;
  1475. }
  1476. if (!plat_priv->driver_state) {
  1477. cnss_pr_dbg("subsys powerup is ignored\n");
  1478. return 0;
  1479. }
  1480. ret = cnss_bus_dev_powerup(plat_priv);
  1481. if (ret)
  1482. __pm_relax(plat_priv->recovery_ws);
  1483. return ret;
  1484. }
  1485. static int cnss_subsys_shutdown(const struct subsys_desc *subsys_desc,
  1486. bool force_stop)
  1487. {
  1488. struct cnss_plat_data *plat_priv;
  1489. if (!subsys_desc->dev) {
  1490. cnss_pr_err("dev from subsys_desc is NULL\n");
  1491. return -ENODEV;
  1492. }
  1493. plat_priv = dev_get_drvdata(subsys_desc->dev);
  1494. if (!plat_priv) {
  1495. cnss_pr_err("plat_priv is NULL\n");
  1496. return -ENODEV;
  1497. }
  1498. if (!plat_priv->driver_state) {
  1499. cnss_pr_dbg("subsys shutdown is ignored\n");
  1500. return 0;
  1501. }
  1502. return cnss_bus_dev_shutdown(plat_priv);
  1503. }
  1504. void cnss_device_crashed(struct device *dev)
  1505. {
  1506. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  1507. struct cnss_subsys_info *subsys_info;
  1508. if (!plat_priv)
  1509. return;
  1510. subsys_info = &plat_priv->subsys_info;
  1511. if (subsys_info->subsys_device) {
  1512. set_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state);
  1513. subsys_set_crash_status(subsys_info->subsys_device, true);
  1514. subsystem_restart_dev(subsys_info->subsys_device);
  1515. }
  1516. }
  1517. EXPORT_SYMBOL(cnss_device_crashed);
  1518. static void cnss_subsys_crash_shutdown(const struct subsys_desc *subsys_desc)
  1519. {
  1520. struct cnss_plat_data *plat_priv = dev_get_drvdata(subsys_desc->dev);
  1521. if (!plat_priv) {
  1522. cnss_pr_err("plat_priv is NULL\n");
  1523. return;
  1524. }
  1525. cnss_bus_dev_crash_shutdown(plat_priv);
  1526. }
  1527. static int cnss_subsys_ramdump(int enable,
  1528. const struct subsys_desc *subsys_desc)
  1529. {
  1530. struct cnss_plat_data *plat_priv = dev_get_drvdata(subsys_desc->dev);
  1531. if (!plat_priv) {
  1532. cnss_pr_err("plat_priv is NULL\n");
  1533. return -ENODEV;
  1534. }
  1535. if (!enable)
  1536. return 0;
  1537. return cnss_bus_dev_ramdump(plat_priv);
  1538. }
  1539. static void cnss_recovery_work_handler(struct work_struct *work)
  1540. {
  1541. }
  1542. #else
  1543. static void cnss_recovery_work_handler(struct work_struct *work)
  1544. {
  1545. int ret;
  1546. struct cnss_plat_data *plat_priv =
  1547. container_of(work, struct cnss_plat_data, recovery_work);
  1548. if (!plat_priv->recovery_enabled)
  1549. panic("subsys-restart: Resetting the SoC wlan crashed\n");
  1550. cnss_bus_dev_shutdown(plat_priv);
  1551. cnss_bus_dev_ramdump(plat_priv);
  1552. msleep(POWER_RESET_MIN_DELAY_MS);
  1553. ret = cnss_bus_dev_powerup(plat_priv);
  1554. if (ret)
  1555. __pm_relax(plat_priv->recovery_ws);
  1556. return;
  1557. }
  1558. void cnss_device_crashed(struct device *dev)
  1559. {
  1560. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  1561. if (!plat_priv)
  1562. return;
  1563. set_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state);
  1564. schedule_work(&plat_priv->recovery_work);
  1565. }
  1566. EXPORT_SYMBOL(cnss_device_crashed);
  1567. #endif /* CONFIG_MSM_SUBSYSTEM_RESTART */
  1568. void *cnss_get_virt_ramdump_mem(struct device *dev, unsigned long *size)
  1569. {
  1570. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  1571. struct cnss_ramdump_info *ramdump_info;
  1572. if (!plat_priv)
  1573. return NULL;
  1574. ramdump_info = &plat_priv->ramdump_info;
  1575. *size = ramdump_info->ramdump_size;
  1576. return ramdump_info->ramdump_va;
  1577. }
  1578. EXPORT_SYMBOL(cnss_get_virt_ramdump_mem);
  1579. static const char *cnss_recovery_reason_to_str(enum cnss_recovery_reason reason)
  1580. {
  1581. switch (reason) {
  1582. case CNSS_REASON_DEFAULT:
  1583. return "DEFAULT";
  1584. case CNSS_REASON_LINK_DOWN:
  1585. return "LINK_DOWN";
  1586. case CNSS_REASON_RDDM:
  1587. return "RDDM";
  1588. case CNSS_REASON_TIMEOUT:
  1589. return "TIMEOUT";
  1590. }
  1591. return "UNKNOWN";
  1592. };
  1593. static int cnss_do_recovery(struct cnss_plat_data *plat_priv,
  1594. enum cnss_recovery_reason reason)
  1595. {
  1596. plat_priv->recovery_count++;
  1597. if (plat_priv->device_id == QCA6174_DEVICE_ID)
  1598. goto self_recovery;
  1599. if (test_bit(SKIP_RECOVERY, &plat_priv->ctrl_params.quirks)) {
  1600. cnss_pr_dbg("Skip device recovery\n");
  1601. return 0;
  1602. }
  1603. /* FW recovery sequence has multiple steps and firmware load requires
  1604. * linux PM in awake state. Thus hold the cnss wake source until
  1605. * WLAN MISSION enabled. CNSS_TIMEOUT_RECOVERY option should cover all
  1606. * time taken in this process.
  1607. */
  1608. pm_wakeup_ws_event(plat_priv->recovery_ws,
  1609. cnss_get_timeout(plat_priv, CNSS_TIMEOUT_RECOVERY),
  1610. true);
  1611. switch (reason) {
  1612. case CNSS_REASON_LINK_DOWN:
  1613. if (!cnss_bus_check_link_status(plat_priv)) {
  1614. cnss_pr_dbg("Skip link down recovery as link is already up\n");
  1615. return 0;
  1616. }
  1617. if (test_bit(LINK_DOWN_SELF_RECOVERY,
  1618. &plat_priv->ctrl_params.quirks))
  1619. goto self_recovery;
  1620. if (!cnss_bus_recover_link_down(plat_priv)) {
  1621. /* clear recovery bit here to avoid skipping
  1622. * the recovery work for RDDM later
  1623. */
  1624. clear_bit(CNSS_DRIVER_RECOVERY,
  1625. &plat_priv->driver_state);
  1626. return 0;
  1627. }
  1628. break;
  1629. case CNSS_REASON_RDDM:
  1630. cnss_bus_collect_dump_info(plat_priv, false);
  1631. break;
  1632. case CNSS_REASON_DEFAULT:
  1633. case CNSS_REASON_TIMEOUT:
  1634. break;
  1635. default:
  1636. cnss_pr_err("Unsupported recovery reason: %s(%d)\n",
  1637. cnss_recovery_reason_to_str(reason), reason);
  1638. break;
  1639. }
  1640. cnss_bus_device_crashed(plat_priv);
  1641. return 0;
  1642. self_recovery:
  1643. cnss_pr_dbg("Going for self recovery\n");
  1644. cnss_bus_dev_shutdown(plat_priv);
  1645. if (test_bit(LINK_DOWN_SELF_RECOVERY, &plat_priv->ctrl_params.quirks))
  1646. clear_bit(LINK_DOWN_SELF_RECOVERY,
  1647. &plat_priv->ctrl_params.quirks);
  1648. cnss_bus_dev_powerup(plat_priv);
  1649. return 0;
  1650. }
  1651. static int cnss_driver_recovery_hdlr(struct cnss_plat_data *plat_priv,
  1652. void *data)
  1653. {
  1654. struct cnss_recovery_data *recovery_data = data;
  1655. int ret = 0;
  1656. cnss_pr_dbg("Driver recovery is triggered with reason: %s(%d)\n",
  1657. cnss_recovery_reason_to_str(recovery_data->reason),
  1658. recovery_data->reason);
  1659. if (!plat_priv->driver_state) {
  1660. cnss_pr_err("Improper driver state, ignore recovery\n");
  1661. ret = -EINVAL;
  1662. goto out;
  1663. }
  1664. if (test_bit(CNSS_IN_REBOOT, &plat_priv->driver_state)) {
  1665. cnss_pr_err("Reboot is in progress, ignore recovery\n");
  1666. ret = -EINVAL;
  1667. goto out;
  1668. }
  1669. if (test_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state)) {
  1670. cnss_pr_err("Recovery is already in progress\n");
  1671. CNSS_ASSERT(0);
  1672. ret = -EINVAL;
  1673. goto out;
  1674. }
  1675. if (test_bit(CNSS_DRIVER_UNLOADING, &plat_priv->driver_state) ||
  1676. test_bit(CNSS_DRIVER_IDLE_SHUTDOWN, &plat_priv->driver_state)) {
  1677. cnss_pr_err("Driver unload or idle shutdown is in progress, ignore recovery\n");
  1678. ret = -EINVAL;
  1679. goto out;
  1680. }
  1681. switch (plat_priv->device_id) {
  1682. case QCA6174_DEVICE_ID:
  1683. if (test_bit(CNSS_DRIVER_LOADING, &plat_priv->driver_state) ||
  1684. test_bit(CNSS_DRIVER_IDLE_RESTART,
  1685. &plat_priv->driver_state)) {
  1686. cnss_pr_err("Driver load or idle restart is in progress, ignore recovery\n");
  1687. ret = -EINVAL;
  1688. goto out;
  1689. }
  1690. break;
  1691. default:
  1692. if (!test_bit(CNSS_FW_READY, &plat_priv->driver_state)) {
  1693. set_bit(CNSS_FW_BOOT_RECOVERY,
  1694. &plat_priv->driver_state);
  1695. }
  1696. break;
  1697. }
  1698. set_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state);
  1699. ret = cnss_do_recovery(plat_priv, recovery_data->reason);
  1700. out:
  1701. kfree(data);
  1702. return ret;
  1703. }
  1704. int cnss_self_recovery(struct device *dev,
  1705. enum cnss_recovery_reason reason)
  1706. {
  1707. cnss_schedule_recovery(dev, reason);
  1708. return 0;
  1709. }
  1710. EXPORT_SYMBOL(cnss_self_recovery);
  1711. void cnss_schedule_recovery(struct device *dev,
  1712. enum cnss_recovery_reason reason)
  1713. {
  1714. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  1715. struct cnss_recovery_data *data;
  1716. int gfp = GFP_KERNEL;
  1717. if (!test_bit(CNSS_DEV_ERR_NOTIFY, &plat_priv->driver_state))
  1718. cnss_bus_update_status(plat_priv, CNSS_FW_DOWN);
  1719. if (test_bit(CNSS_DRIVER_UNLOADING, &plat_priv->driver_state) ||
  1720. test_bit(CNSS_DRIVER_IDLE_SHUTDOWN, &plat_priv->driver_state)) {
  1721. cnss_pr_dbg("Driver unload or idle shutdown is in progress, ignore schedule recovery\n");
  1722. return;
  1723. }
  1724. if (in_interrupt() || irqs_disabled())
  1725. gfp = GFP_ATOMIC;
  1726. data = kzalloc(sizeof(*data), gfp);
  1727. if (!data)
  1728. return;
  1729. data->reason = reason;
  1730. cnss_driver_event_post(plat_priv,
  1731. CNSS_DRIVER_EVENT_RECOVERY,
  1732. 0, data);
  1733. }
  1734. EXPORT_SYMBOL(cnss_schedule_recovery);
  1735. int cnss_force_fw_assert(struct device *dev)
  1736. {
  1737. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  1738. if (!plat_priv) {
  1739. cnss_pr_err("plat_priv is NULL\n");
  1740. return -ENODEV;
  1741. }
  1742. if (plat_priv->device_id == QCA6174_DEVICE_ID) {
  1743. cnss_pr_info("Forced FW assert is not supported\n");
  1744. return -EOPNOTSUPP;
  1745. }
  1746. if (cnss_bus_is_device_down(plat_priv)) {
  1747. cnss_pr_info("Device is already in bad state, ignore force assert\n");
  1748. return 0;
  1749. }
  1750. if (test_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state)) {
  1751. cnss_pr_info("Recovery is already in progress, ignore forced FW assert\n");
  1752. return 0;
  1753. }
  1754. if (in_interrupt() || irqs_disabled())
  1755. cnss_driver_event_post(plat_priv,
  1756. CNSS_DRIVER_EVENT_FORCE_FW_ASSERT,
  1757. 0, NULL);
  1758. else
  1759. cnss_bus_force_fw_assert_hdlr(plat_priv);
  1760. return 0;
  1761. }
  1762. EXPORT_SYMBOL(cnss_force_fw_assert);
  1763. int cnss_force_collect_rddm(struct device *dev)
  1764. {
  1765. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  1766. unsigned int timeout;
  1767. int ret = 0;
  1768. if (!plat_priv) {
  1769. cnss_pr_err("plat_priv is NULL\n");
  1770. return -ENODEV;
  1771. }
  1772. if (plat_priv->device_id == QCA6174_DEVICE_ID) {
  1773. cnss_pr_info("Force collect rddm is not supported\n");
  1774. return -EOPNOTSUPP;
  1775. }
  1776. if (cnss_bus_is_device_down(plat_priv)) {
  1777. cnss_pr_info("Device is already in bad state, wait to collect rddm\n");
  1778. goto wait_rddm;
  1779. }
  1780. if (test_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state)) {
  1781. cnss_pr_info("Recovery is already in progress, wait to collect rddm\n");
  1782. goto wait_rddm;
  1783. }
  1784. if (test_bit(CNSS_DRIVER_LOADING, &plat_priv->driver_state) ||
  1785. test_bit(CNSS_DRIVER_UNLOADING, &plat_priv->driver_state) ||
  1786. test_bit(CNSS_DRIVER_IDLE_RESTART, &plat_priv->driver_state) ||
  1787. test_bit(CNSS_DRIVER_IDLE_SHUTDOWN, &plat_priv->driver_state)) {
  1788. cnss_pr_info("Loading/Unloading/idle restart/shutdown is in progress, ignore forced collect rddm\n");
  1789. return 0;
  1790. }
  1791. ret = cnss_bus_force_fw_assert_hdlr(plat_priv);
  1792. if (ret)
  1793. return ret;
  1794. wait_rddm:
  1795. reinit_completion(&plat_priv->rddm_complete);
  1796. timeout = cnss_get_timeout(plat_priv, CNSS_TIMEOUT_RDDM);
  1797. ret = wait_for_completion_timeout(&plat_priv->rddm_complete,
  1798. msecs_to_jiffies(timeout));
  1799. if (!ret) {
  1800. cnss_pr_err("Timeout (%ums) waiting for RDDM to complete\n",
  1801. timeout);
  1802. ret = -ETIMEDOUT;
  1803. } else if (ret > 0) {
  1804. ret = 0;
  1805. }
  1806. return ret;
  1807. }
  1808. EXPORT_SYMBOL(cnss_force_collect_rddm);
  1809. int cnss_qmi_send_get(struct device *dev)
  1810. {
  1811. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  1812. if (!test_bit(CNSS_QMI_WLFW_CONNECTED, &plat_priv->driver_state))
  1813. return 0;
  1814. return cnss_bus_qmi_send_get(plat_priv);
  1815. }
  1816. EXPORT_SYMBOL(cnss_qmi_send_get);
  1817. int cnss_qmi_send_put(struct device *dev)
  1818. {
  1819. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  1820. if (!test_bit(CNSS_QMI_WLFW_CONNECTED, &plat_priv->driver_state))
  1821. return 0;
  1822. return cnss_bus_qmi_send_put(plat_priv);
  1823. }
  1824. EXPORT_SYMBOL(cnss_qmi_send_put);
  1825. int cnss_qmi_send(struct device *dev, int type, void *cmd,
  1826. int cmd_len, void *cb_ctx,
  1827. int (*cb)(void *ctx, void *event, int event_len))
  1828. {
  1829. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  1830. int ret;
  1831. if (!plat_priv)
  1832. return -ENODEV;
  1833. if (!test_bit(CNSS_QMI_WLFW_CONNECTED, &plat_priv->driver_state))
  1834. return -EINVAL;
  1835. plat_priv->get_info_cb = cb;
  1836. plat_priv->get_info_cb_ctx = cb_ctx;
  1837. ret = cnss_wlfw_get_info_send_sync(plat_priv, type, cmd, cmd_len);
  1838. if (ret) {
  1839. plat_priv->get_info_cb = NULL;
  1840. plat_priv->get_info_cb_ctx = NULL;
  1841. }
  1842. return ret;
  1843. }
  1844. EXPORT_SYMBOL(cnss_qmi_send);
  1845. static int cnss_cold_boot_cal_start_hdlr(struct cnss_plat_data *plat_priv)
  1846. {
  1847. int ret = 0;
  1848. u32 retry = 0, timeout;
  1849. if (test_bit(CNSS_COLD_BOOT_CAL_DONE, &plat_priv->driver_state)) {
  1850. cnss_pr_dbg("Calibration complete. Ignore calibration req\n");
  1851. goto out;
  1852. } else if (test_bit(CNSS_IN_COLD_BOOT_CAL, &plat_priv->driver_state)) {
  1853. cnss_pr_dbg("Calibration in progress. Ignore new calibration req\n");
  1854. goto out;
  1855. } else if (test_bit(CNSS_WLAN_HW_DISABLED, &plat_priv->driver_state)) {
  1856. cnss_pr_dbg("Calibration deferred as WLAN device disabled\n");
  1857. goto out;
  1858. }
  1859. if (test_bit(CNSS_DRIVER_LOADING, &plat_priv->driver_state) ||
  1860. test_bit(CNSS_DRIVER_PROBED, &plat_priv->driver_state) ||
  1861. test_bit(CNSS_FW_READY, &plat_priv->driver_state)) {
  1862. cnss_pr_err("WLAN in mission mode before cold boot calibration\n");
  1863. CNSS_ASSERT(0);
  1864. return -EINVAL;
  1865. }
  1866. while (retry++ < CNSS_CAL_START_PROBE_WAIT_RETRY_MAX) {
  1867. if (test_bit(CNSS_PCI_PROBE_DONE, &plat_priv->driver_state))
  1868. break;
  1869. msleep(CNSS_CAL_START_PROBE_WAIT_MS);
  1870. if (retry == CNSS_CAL_START_PROBE_WAIT_RETRY_MAX) {
  1871. cnss_pr_err("Calibration start failed as PCI probe not complete\n");
  1872. CNSS_ASSERT(0);
  1873. ret = -EINVAL;
  1874. goto mark_cal_fail;
  1875. }
  1876. }
  1877. switch (plat_priv->device_id) {
  1878. case QCA6290_DEVICE_ID:
  1879. case QCA6390_DEVICE_ID:
  1880. case QCA6490_DEVICE_ID:
  1881. case KIWI_DEVICE_ID:
  1882. case MANGO_DEVICE_ID:
  1883. case PEACH_DEVICE_ID:
  1884. break;
  1885. default:
  1886. cnss_pr_err("Not supported for device ID 0x%lx\n",
  1887. plat_priv->device_id);
  1888. ret = -EINVAL;
  1889. goto mark_cal_fail;
  1890. }
  1891. set_bit(CNSS_IN_COLD_BOOT_CAL, &plat_priv->driver_state);
  1892. if (test_bit(CNSS_DRIVER_REGISTER, &plat_priv->driver_state)) {
  1893. timeout = cnss_get_timeout(plat_priv,
  1894. CNSS_TIMEOUT_CALIBRATION);
  1895. cnss_pr_dbg("Restarting calibration %ds timeout\n",
  1896. timeout / 1000);
  1897. if (cancel_delayed_work_sync(&plat_priv->wlan_reg_driver_work))
  1898. schedule_delayed_work(&plat_priv->wlan_reg_driver_work,
  1899. msecs_to_jiffies(timeout));
  1900. }
  1901. reinit_completion(&plat_priv->cal_complete);
  1902. ret = cnss_bus_dev_powerup(plat_priv);
  1903. mark_cal_fail:
  1904. if (ret) {
  1905. complete(&plat_priv->cal_complete);
  1906. clear_bit(CNSS_IN_COLD_BOOT_CAL, &plat_priv->driver_state);
  1907. /* Set CBC done in driver state to mark attempt and note error
  1908. * since calibration cannot be retried at boot.
  1909. */
  1910. plat_priv->cal_done = CNSS_CAL_FAILURE;
  1911. set_bit(CNSS_COLD_BOOT_CAL_DONE, &plat_priv->driver_state);
  1912. if (plat_priv->device_id == QCA6174_DEVICE_ID ||
  1913. plat_priv->device_id == QCN7605_DEVICE_ID) {
  1914. if (!test_bit(CNSS_DRIVER_REGISTER, &plat_priv->driver_state))
  1915. goto out;
  1916. cnss_pr_info("Schedule WLAN driver load\n");
  1917. if (cancel_delayed_work_sync(&plat_priv->wlan_reg_driver_work))
  1918. schedule_delayed_work(&plat_priv->wlan_reg_driver_work,
  1919. 0);
  1920. }
  1921. }
  1922. out:
  1923. return ret;
  1924. }
  1925. static int cnss_cold_boot_cal_done_hdlr(struct cnss_plat_data *plat_priv,
  1926. void *data)
  1927. {
  1928. struct cnss_cal_info *cal_info = data;
  1929. if (!test_bit(CNSS_IN_COLD_BOOT_CAL, &plat_priv->driver_state) ||
  1930. test_bit(CNSS_COLD_BOOT_CAL_DONE, &plat_priv->driver_state))
  1931. goto out;
  1932. switch (cal_info->cal_status) {
  1933. case CNSS_CAL_DONE:
  1934. cnss_pr_dbg("Calibration completed successfully\n");
  1935. plat_priv->cal_done = true;
  1936. break;
  1937. case CNSS_CAL_TIMEOUT:
  1938. case CNSS_CAL_FAILURE:
  1939. cnss_pr_dbg("Calibration failed. Status: %d, force shutdown\n",
  1940. cal_info->cal_status);
  1941. break;
  1942. default:
  1943. cnss_pr_err("Unknown calibration status: %u\n",
  1944. cal_info->cal_status);
  1945. break;
  1946. }
  1947. cnss_wlfw_wlan_mode_send_sync(plat_priv, CNSS_OFF);
  1948. cnss_bus_free_qdss_mem(plat_priv);
  1949. cnss_release_antenna_sharing(plat_priv);
  1950. if (plat_priv->device_id == QCN7605_DEVICE_ID)
  1951. goto skip_shutdown;
  1952. cnss_bus_dev_shutdown(plat_priv);
  1953. msleep(POWER_RESET_MIN_DELAY_MS);
  1954. skip_shutdown:
  1955. complete(&plat_priv->cal_complete);
  1956. clear_bit(CNSS_IN_COLD_BOOT_CAL, &plat_priv->driver_state);
  1957. set_bit(CNSS_COLD_BOOT_CAL_DONE, &plat_priv->driver_state);
  1958. if (cal_info->cal_status == CNSS_CAL_DONE) {
  1959. cnss_cal_mem_upload_to_file(plat_priv);
  1960. if (!test_bit(CNSS_DRIVER_REGISTER, &plat_priv->driver_state))
  1961. goto out;
  1962. cnss_pr_dbg("Schedule WLAN driver load\n");
  1963. if (cancel_delayed_work_sync(&plat_priv->wlan_reg_driver_work))
  1964. schedule_delayed_work(&plat_priv->wlan_reg_driver_work,
  1965. 0);
  1966. }
  1967. out:
  1968. kfree(data);
  1969. return 0;
  1970. }
  1971. static int cnss_power_up_hdlr(struct cnss_plat_data *plat_priv)
  1972. {
  1973. int ret;
  1974. ret = cnss_bus_dev_powerup(plat_priv);
  1975. if (ret)
  1976. clear_bit(CNSS_DRIVER_IDLE_RESTART, &plat_priv->driver_state);
  1977. return ret;
  1978. }
  1979. static int cnss_power_down_hdlr(struct cnss_plat_data *plat_priv)
  1980. {
  1981. cnss_bus_dev_shutdown(plat_priv);
  1982. return 0;
  1983. }
  1984. static int cnss_qdss_trace_req_mem_hdlr(struct cnss_plat_data *plat_priv)
  1985. {
  1986. int ret = 0;
  1987. ret = cnss_bus_alloc_qdss_mem(plat_priv);
  1988. if (ret < 0)
  1989. return ret;
  1990. return cnss_wlfw_qdss_trace_mem_info_send_sync(plat_priv);
  1991. }
  1992. static void *cnss_get_fw_mem_pa_to_va(struct cnss_fw_mem *fw_mem,
  1993. u32 mem_seg_len, u64 pa, u32 size)
  1994. {
  1995. int i = 0;
  1996. u64 offset = 0;
  1997. void *va = NULL;
  1998. u64 local_pa;
  1999. u32 local_size;
  2000. for (i = 0; i < mem_seg_len; i++) {
  2001. local_pa = (u64)fw_mem[i].pa;
  2002. local_size = (u32)fw_mem[i].size;
  2003. if (pa == local_pa && size <= local_size) {
  2004. va = fw_mem[i].va;
  2005. break;
  2006. }
  2007. if (pa > local_pa &&
  2008. pa < local_pa + local_size &&
  2009. pa + size <= local_pa + local_size) {
  2010. offset = pa - local_pa;
  2011. va = fw_mem[i].va + offset;
  2012. break;
  2013. }
  2014. }
  2015. return va;
  2016. }
  2017. static int cnss_fw_mem_file_save_hdlr(struct cnss_plat_data *plat_priv,
  2018. void *data)
  2019. {
  2020. struct cnss_qmi_event_fw_mem_file_save_data *event_data = data;
  2021. struct cnss_fw_mem *fw_mem_seg;
  2022. int ret = 0L;
  2023. void *va = NULL;
  2024. u32 i, fw_mem_seg_len;
  2025. switch (event_data->mem_type) {
  2026. case QMI_WLFW_MEM_TYPE_DDR_V01:
  2027. if (!plat_priv->fw_mem_seg_len)
  2028. goto invalid_mem_save;
  2029. fw_mem_seg = plat_priv->fw_mem;
  2030. fw_mem_seg_len = plat_priv->fw_mem_seg_len;
  2031. break;
  2032. case QMI_WLFW_MEM_QDSS_V01:
  2033. if (!plat_priv->qdss_mem_seg_len)
  2034. goto invalid_mem_save;
  2035. fw_mem_seg = plat_priv->qdss_mem;
  2036. fw_mem_seg_len = plat_priv->qdss_mem_seg_len;
  2037. break;
  2038. default:
  2039. goto invalid_mem_save;
  2040. }
  2041. for (i = 0; i < event_data->mem_seg_len; i++) {
  2042. va = cnss_get_fw_mem_pa_to_va(fw_mem_seg, fw_mem_seg_len,
  2043. event_data->mem_seg[i].addr,
  2044. event_data->mem_seg[i].size);
  2045. if (!va) {
  2046. cnss_pr_err("Fail to find matching va of pa %pa for mem type: %d\n",
  2047. &event_data->mem_seg[i].addr,
  2048. event_data->mem_type);
  2049. ret = -EINVAL;
  2050. break;
  2051. }
  2052. ret = cnss_genl_send_msg(va, CNSS_GENL_MSG_TYPE_QDSS,
  2053. event_data->file_name,
  2054. event_data->mem_seg[i].size);
  2055. if (ret < 0) {
  2056. cnss_pr_err("Fail to save fw mem data: %d\n",
  2057. ret);
  2058. break;
  2059. }
  2060. }
  2061. kfree(data);
  2062. return ret;
  2063. invalid_mem_save:
  2064. cnss_pr_err("FW Mem type %d not allocated. Invalid save request\n",
  2065. event_data->mem_type);
  2066. kfree(data);
  2067. return -EINVAL;
  2068. }
  2069. static int cnss_qdss_trace_free_hdlr(struct cnss_plat_data *plat_priv)
  2070. {
  2071. cnss_bus_free_qdss_mem(plat_priv);
  2072. return 0;
  2073. }
  2074. static int cnss_qdss_trace_req_data_hdlr(struct cnss_plat_data *plat_priv,
  2075. void *data)
  2076. {
  2077. int ret = 0;
  2078. struct cnss_qmi_event_fw_mem_file_save_data *event_data = data;
  2079. if (!plat_priv)
  2080. return -ENODEV;
  2081. ret = cnss_wlfw_qdss_data_send_sync(plat_priv, event_data->file_name,
  2082. event_data->total_size);
  2083. kfree(data);
  2084. return ret;
  2085. }
  2086. static void cnss_driver_event_work(struct work_struct *work)
  2087. {
  2088. struct cnss_plat_data *plat_priv =
  2089. container_of(work, struct cnss_plat_data, event_work);
  2090. struct cnss_driver_event *event;
  2091. unsigned long flags;
  2092. int ret = 0;
  2093. if (!plat_priv) {
  2094. cnss_pr_err("plat_priv is NULL!\n");
  2095. return;
  2096. }
  2097. cnss_pm_stay_awake(plat_priv);
  2098. spin_lock_irqsave(&plat_priv->event_lock, flags);
  2099. while (!list_empty(&plat_priv->event_list)) {
  2100. event = list_first_entry(&plat_priv->event_list,
  2101. struct cnss_driver_event, list);
  2102. list_del(&event->list);
  2103. spin_unlock_irqrestore(&plat_priv->event_lock, flags);
  2104. cnss_pr_dbg("Processing driver event: %s%s(%d), state: 0x%lx\n",
  2105. cnss_driver_event_to_str(event->type),
  2106. event->sync ? "-sync" : "", event->type,
  2107. plat_priv->driver_state);
  2108. switch (event->type) {
  2109. case CNSS_DRIVER_EVENT_SERVER_ARRIVE:
  2110. ret = cnss_wlfw_server_arrive(plat_priv, event->data);
  2111. break;
  2112. case CNSS_DRIVER_EVENT_SERVER_EXIT:
  2113. ret = cnss_wlfw_server_exit(plat_priv);
  2114. break;
  2115. case CNSS_DRIVER_EVENT_REQUEST_MEM:
  2116. ret = cnss_bus_alloc_fw_mem(plat_priv);
  2117. if (ret)
  2118. break;
  2119. ret = cnss_wlfw_respond_mem_send_sync(plat_priv);
  2120. break;
  2121. case CNSS_DRIVER_EVENT_FW_MEM_READY:
  2122. ret = cnss_fw_mem_ready_hdlr(plat_priv);
  2123. break;
  2124. case CNSS_DRIVER_EVENT_FW_READY:
  2125. ret = cnss_fw_ready_hdlr(plat_priv);
  2126. break;
  2127. case CNSS_DRIVER_EVENT_COLD_BOOT_CAL_START:
  2128. ret = cnss_cold_boot_cal_start_hdlr(plat_priv);
  2129. break;
  2130. case CNSS_DRIVER_EVENT_COLD_BOOT_CAL_DONE:
  2131. ret = cnss_cold_boot_cal_done_hdlr(plat_priv,
  2132. event->data);
  2133. break;
  2134. case CNSS_DRIVER_EVENT_REGISTER_DRIVER:
  2135. ret = cnss_bus_register_driver_hdlr(plat_priv,
  2136. event->data);
  2137. break;
  2138. case CNSS_DRIVER_EVENT_UNREGISTER_DRIVER:
  2139. ret = cnss_bus_unregister_driver_hdlr(plat_priv);
  2140. break;
  2141. case CNSS_DRIVER_EVENT_RECOVERY:
  2142. ret = cnss_driver_recovery_hdlr(plat_priv,
  2143. event->data);
  2144. break;
  2145. case CNSS_DRIVER_EVENT_FORCE_FW_ASSERT:
  2146. ret = cnss_bus_force_fw_assert_hdlr(plat_priv);
  2147. break;
  2148. case CNSS_DRIVER_EVENT_IDLE_RESTART:
  2149. set_bit(CNSS_DRIVER_IDLE_RESTART,
  2150. &plat_priv->driver_state);
  2151. fallthrough;
  2152. case CNSS_DRIVER_EVENT_POWER_UP:
  2153. ret = cnss_power_up_hdlr(plat_priv);
  2154. break;
  2155. case CNSS_DRIVER_EVENT_IDLE_SHUTDOWN:
  2156. set_bit(CNSS_DRIVER_IDLE_SHUTDOWN,
  2157. &plat_priv->driver_state);
  2158. fallthrough;
  2159. case CNSS_DRIVER_EVENT_POWER_DOWN:
  2160. ret = cnss_power_down_hdlr(plat_priv);
  2161. break;
  2162. case CNSS_DRIVER_EVENT_IMS_WFC_CALL_IND:
  2163. ret = cnss_process_wfc_call_ind_event(plat_priv,
  2164. event->data);
  2165. break;
  2166. case CNSS_DRIVER_EVENT_WLFW_TWT_CFG_IND:
  2167. ret = cnss_process_twt_cfg_ind_event(plat_priv,
  2168. event->data);
  2169. break;
  2170. case CNSS_DRIVER_EVENT_QDSS_TRACE_REQ_MEM:
  2171. ret = cnss_qdss_trace_req_mem_hdlr(plat_priv);
  2172. break;
  2173. case CNSS_DRIVER_EVENT_FW_MEM_FILE_SAVE:
  2174. ret = cnss_fw_mem_file_save_hdlr(plat_priv,
  2175. event->data);
  2176. break;
  2177. case CNSS_DRIVER_EVENT_QDSS_TRACE_FREE:
  2178. ret = cnss_qdss_trace_free_hdlr(plat_priv);
  2179. break;
  2180. case CNSS_DRIVER_EVENT_QDSS_TRACE_REQ_DATA:
  2181. ret = cnss_qdss_trace_req_data_hdlr(plat_priv,
  2182. event->data);
  2183. break;
  2184. default:
  2185. cnss_pr_err("Invalid driver event type: %d",
  2186. event->type);
  2187. kfree(event);
  2188. spin_lock_irqsave(&plat_priv->event_lock, flags);
  2189. continue;
  2190. }
  2191. spin_lock_irqsave(&plat_priv->event_lock, flags);
  2192. if (event->sync) {
  2193. event->ret = ret;
  2194. complete(&event->complete);
  2195. continue;
  2196. }
  2197. spin_unlock_irqrestore(&plat_priv->event_lock, flags);
  2198. kfree(event);
  2199. spin_lock_irqsave(&plat_priv->event_lock, flags);
  2200. }
  2201. spin_unlock_irqrestore(&plat_priv->event_lock, flags);
  2202. cnss_pm_relax(plat_priv);
  2203. }
  2204. #if IS_ENABLED(CONFIG_MSM_SUBSYSTEM_RESTART)
  2205. int cnss_register_subsys(struct cnss_plat_data *plat_priv)
  2206. {
  2207. int ret = 0;
  2208. struct cnss_subsys_info *subsys_info;
  2209. subsys_info = &plat_priv->subsys_info;
  2210. subsys_info->subsys_desc.name = plat_priv->device_name;
  2211. subsys_info->subsys_desc.owner = THIS_MODULE;
  2212. subsys_info->subsys_desc.powerup = cnss_subsys_powerup;
  2213. subsys_info->subsys_desc.shutdown = cnss_subsys_shutdown;
  2214. subsys_info->subsys_desc.ramdump = cnss_subsys_ramdump;
  2215. subsys_info->subsys_desc.crash_shutdown = cnss_subsys_crash_shutdown;
  2216. subsys_info->subsys_desc.dev = &plat_priv->plat_dev->dev;
  2217. subsys_info->subsys_device = subsys_register(&subsys_info->subsys_desc);
  2218. if (IS_ERR(subsys_info->subsys_device)) {
  2219. ret = PTR_ERR(subsys_info->subsys_device);
  2220. cnss_pr_err("Failed to register subsys, err = %d\n", ret);
  2221. goto out;
  2222. }
  2223. subsys_info->subsys_handle =
  2224. subsystem_get(subsys_info->subsys_desc.name);
  2225. if (!subsys_info->subsys_handle) {
  2226. cnss_pr_err("Failed to get subsys_handle!\n");
  2227. ret = -EINVAL;
  2228. goto unregister_subsys;
  2229. } else if (IS_ERR(subsys_info->subsys_handle)) {
  2230. ret = PTR_ERR(subsys_info->subsys_handle);
  2231. cnss_pr_err("Failed to do subsystem_get, err = %d\n", ret);
  2232. goto unregister_subsys;
  2233. }
  2234. return 0;
  2235. unregister_subsys:
  2236. subsys_unregister(subsys_info->subsys_device);
  2237. out:
  2238. return ret;
  2239. }
  2240. void cnss_unregister_subsys(struct cnss_plat_data *plat_priv)
  2241. {
  2242. struct cnss_subsys_info *subsys_info;
  2243. subsys_info = &plat_priv->subsys_info;
  2244. subsystem_put(subsys_info->subsys_handle);
  2245. subsys_unregister(subsys_info->subsys_device);
  2246. }
  2247. static void *cnss_create_ramdump_device(struct cnss_plat_data *plat_priv)
  2248. {
  2249. struct cnss_subsys_info *subsys_info = &plat_priv->subsys_info;
  2250. return create_ramdump_device(subsys_info->subsys_desc.name,
  2251. subsys_info->subsys_desc.dev);
  2252. }
  2253. static void cnss_destroy_ramdump_device(struct cnss_plat_data *plat_priv,
  2254. void *ramdump_dev)
  2255. {
  2256. destroy_ramdump_device(ramdump_dev);
  2257. }
  2258. int cnss_do_ramdump(struct cnss_plat_data *plat_priv)
  2259. {
  2260. struct cnss_ramdump_info *ramdump_info = &plat_priv->ramdump_info;
  2261. struct ramdump_segment segment;
  2262. memset(&segment, 0, sizeof(segment));
  2263. segment.v_address = (void __iomem *)ramdump_info->ramdump_va;
  2264. segment.size = ramdump_info->ramdump_size;
  2265. return qcom_ramdump(ramdump_info->ramdump_dev, &segment, 1);
  2266. }
  2267. int cnss_do_elf_ramdump(struct cnss_plat_data *plat_priv)
  2268. {
  2269. struct cnss_ramdump_info_v2 *info_v2 = &plat_priv->ramdump_info_v2;
  2270. struct cnss_dump_data *dump_data = &info_v2->dump_data;
  2271. struct cnss_dump_seg *dump_seg = info_v2->dump_data_vaddr;
  2272. struct ramdump_segment *ramdump_segs, *s;
  2273. struct cnss_dump_meta_info meta_info = {0};
  2274. int i, ret = 0;
  2275. ramdump_segs = kcalloc(dump_data->nentries + 1,
  2276. sizeof(*ramdump_segs),
  2277. GFP_KERNEL);
  2278. if (!ramdump_segs)
  2279. return -ENOMEM;
  2280. s = ramdump_segs + 1;
  2281. for (i = 0; i < dump_data->nentries; i++) {
  2282. if (dump_seg->type >= CNSS_FW_DUMP_TYPE_MAX) {
  2283. cnss_pr_err("Unsupported dump type: %d",
  2284. dump_seg->type);
  2285. continue;
  2286. }
  2287. if (meta_info.entry[dump_seg->type].entry_start == 0) {
  2288. meta_info.entry[dump_seg->type].type = dump_seg->type;
  2289. meta_info.entry[dump_seg->type].entry_start = i + 1;
  2290. }
  2291. meta_info.entry[dump_seg->type].entry_num++;
  2292. s->address = dump_seg->address;
  2293. s->v_address = (void __iomem *)dump_seg->v_address;
  2294. s->size = dump_seg->size;
  2295. s++;
  2296. dump_seg++;
  2297. }
  2298. meta_info.magic = CNSS_RAMDUMP_MAGIC;
  2299. meta_info.version = CNSS_RAMDUMP_VERSION;
  2300. meta_info.chipset = plat_priv->device_id;
  2301. meta_info.total_entries = CNSS_FW_DUMP_TYPE_MAX;
  2302. ramdump_segs->v_address = (void __iomem *)(&meta_info);
  2303. ramdump_segs->size = sizeof(meta_info);
  2304. ret = qcom_elf_ramdump(info_v2->ramdump_dev, ramdump_segs,
  2305. dump_data->nentries + 1);
  2306. kfree(ramdump_segs);
  2307. return ret;
  2308. }
  2309. #else
  2310. static int cnss_panic_handler(struct notifier_block *nb, unsigned long action,
  2311. void *data)
  2312. {
  2313. struct cnss_plat_data *plat_priv =
  2314. container_of(nb, struct cnss_plat_data, panic_nb);
  2315. cnss_bus_dev_crash_shutdown(plat_priv);
  2316. return NOTIFY_DONE;
  2317. }
  2318. int cnss_register_subsys(struct cnss_plat_data *plat_priv)
  2319. {
  2320. int ret;
  2321. if (!plat_priv)
  2322. return -ENODEV;
  2323. plat_priv->panic_nb.notifier_call = cnss_panic_handler;
  2324. ret = atomic_notifier_chain_register(&panic_notifier_list,
  2325. &plat_priv->panic_nb);
  2326. if (ret) {
  2327. cnss_pr_err("Failed to register panic handler\n");
  2328. return -EINVAL;
  2329. }
  2330. return 0;
  2331. }
  2332. void cnss_unregister_subsys(struct cnss_plat_data *plat_priv)
  2333. {
  2334. int ret;
  2335. ret = atomic_notifier_chain_unregister(&panic_notifier_list,
  2336. &plat_priv->panic_nb);
  2337. if (ret)
  2338. cnss_pr_err("Failed to unregister panic handler\n");
  2339. }
  2340. #if IS_ENABLED(CONFIG_QCOM_MEMORY_DUMP_V2)
  2341. static void *cnss_create_ramdump_device(struct cnss_plat_data *plat_priv)
  2342. {
  2343. return &plat_priv->plat_dev->dev;
  2344. }
  2345. static void cnss_destroy_ramdump_device(struct cnss_plat_data *plat_priv,
  2346. void *ramdump_dev)
  2347. {
  2348. }
  2349. #endif
  2350. #if IS_ENABLED(CONFIG_QCOM_RAMDUMP)
  2351. int cnss_do_ramdump(struct cnss_plat_data *plat_priv)
  2352. {
  2353. struct cnss_ramdump_info *ramdump_info = &plat_priv->ramdump_info;
  2354. struct qcom_dump_segment segment;
  2355. struct list_head head;
  2356. INIT_LIST_HEAD(&head);
  2357. memset(&segment, 0, sizeof(segment));
  2358. segment.va = ramdump_info->ramdump_va;
  2359. segment.size = ramdump_info->ramdump_size;
  2360. list_add(&segment.node, &head);
  2361. return qcom_dump(&head, ramdump_info->ramdump_dev);
  2362. }
  2363. #else
  2364. int cnss_do_ramdump(struct cnss_plat_data *plat_priv)
  2365. {
  2366. return 0;
  2367. }
  2368. /* Using completion event inside dynamically allocated ramdump_desc
  2369. * may result a race between freeing the event after setting it to
  2370. * complete inside dev coredump free callback and the thread that is
  2371. * waiting for completion.
  2372. */
  2373. DECLARE_COMPLETION(dump_done);
  2374. #define TIMEOUT_SAVE_DUMP_MS 30000
  2375. #define SIZEOF_ELF_STRUCT(__xhdr) \
  2376. static inline size_t sizeof_elf_##__xhdr(unsigned char class) \
  2377. { \
  2378. if (class == ELFCLASS32) \
  2379. return sizeof(struct elf32_##__xhdr); \
  2380. else \
  2381. return sizeof(struct elf64_##__xhdr); \
  2382. }
  2383. SIZEOF_ELF_STRUCT(phdr)
  2384. SIZEOF_ELF_STRUCT(hdr)
  2385. #define set_xhdr_property(__xhdr, arg, class, member, value) \
  2386. do { \
  2387. if (class == ELFCLASS32) \
  2388. ((struct elf32_##__xhdr *)arg)->member = value; \
  2389. else \
  2390. ((struct elf64_##__xhdr *)arg)->member = value; \
  2391. } while (0)
  2392. #define set_ehdr_property(arg, class, member, value) \
  2393. set_xhdr_property(hdr, arg, class, member, value)
  2394. #define set_phdr_property(arg, class, member, value) \
  2395. set_xhdr_property(phdr, arg, class, member, value)
  2396. /* These replace qcom_ramdump driver APIs called from common API
  2397. * cnss_do_elf_dump() by the ones defined here.
  2398. */
  2399. #define qcom_dump_segment cnss_qcom_dump_segment
  2400. #define qcom_elf_dump cnss_qcom_elf_dump
  2401. #define dump_enabled cnss_dump_enabled
  2402. struct cnss_qcom_dump_segment {
  2403. struct list_head node;
  2404. dma_addr_t da;
  2405. void *va;
  2406. size_t size;
  2407. };
  2408. struct cnss_qcom_ramdump_desc {
  2409. void *data;
  2410. struct completion dump_done;
  2411. };
  2412. static ssize_t cnss_qcom_devcd_readv(char *buffer, loff_t offset, size_t count,
  2413. void *data, size_t datalen)
  2414. {
  2415. struct cnss_qcom_ramdump_desc *desc = data;
  2416. return memory_read_from_buffer(buffer, count, &offset, desc->data,
  2417. datalen);
  2418. }
  2419. static void cnss_qcom_devcd_freev(void *data)
  2420. {
  2421. struct cnss_qcom_ramdump_desc *desc = data;
  2422. cnss_pr_dbg("Free dump data for dev coredump\n");
  2423. complete(&dump_done);
  2424. vfree(desc->data);
  2425. kfree(desc);
  2426. }
  2427. static int cnss_qcom_devcd_dump(struct device *dev, void *data, size_t datalen,
  2428. gfp_t gfp)
  2429. {
  2430. struct cnss_qcom_ramdump_desc *desc;
  2431. unsigned int timeout = TIMEOUT_SAVE_DUMP_MS;
  2432. int ret;
  2433. desc = kmalloc(sizeof(*desc), GFP_KERNEL);
  2434. if (!desc)
  2435. return -ENOMEM;
  2436. desc->data = data;
  2437. reinit_completion(&dump_done);
  2438. dev_coredumpm(dev, NULL, desc, datalen, gfp,
  2439. cnss_qcom_devcd_readv, cnss_qcom_devcd_freev);
  2440. ret = wait_for_completion_timeout(&dump_done,
  2441. msecs_to_jiffies(timeout));
  2442. if (!ret)
  2443. cnss_pr_err("Timeout waiting (%dms) for saving dump to file system\n",
  2444. timeout);
  2445. return ret ? 0 : -ETIMEDOUT;
  2446. }
  2447. /* Since the elf32 and elf64 identification is identical apart from
  2448. * the class, use elf32 by default.
  2449. */
  2450. static void init_elf_identification(struct elf32_hdr *ehdr, unsigned char class)
  2451. {
  2452. memcpy(ehdr->e_ident, ELFMAG, SELFMAG);
  2453. ehdr->e_ident[EI_CLASS] = class;
  2454. ehdr->e_ident[EI_DATA] = ELFDATA2LSB;
  2455. ehdr->e_ident[EI_VERSION] = EV_CURRENT;
  2456. ehdr->e_ident[EI_OSABI] = ELFOSABI_NONE;
  2457. }
  2458. int cnss_qcom_elf_dump(struct list_head *segs, struct device *dev,
  2459. unsigned char class)
  2460. {
  2461. struct cnss_qcom_dump_segment *segment;
  2462. void *phdr, *ehdr;
  2463. size_t data_size, offset;
  2464. int phnum = 0;
  2465. void *data;
  2466. void __iomem *ptr;
  2467. if (!segs || list_empty(segs))
  2468. return -EINVAL;
  2469. data_size = sizeof_elf_hdr(class);
  2470. list_for_each_entry(segment, segs, node) {
  2471. data_size += sizeof_elf_phdr(class) + segment->size;
  2472. phnum++;
  2473. }
  2474. data = vmalloc(data_size);
  2475. if (!data)
  2476. return -ENOMEM;
  2477. cnss_pr_dbg("Creating ELF file with size %d\n", data_size);
  2478. ehdr = data;
  2479. memset(ehdr, 0, sizeof_elf_hdr(class));
  2480. init_elf_identification(ehdr, class);
  2481. set_ehdr_property(ehdr, class, e_type, ET_CORE);
  2482. set_ehdr_property(ehdr, class, e_machine, EM_NONE);
  2483. set_ehdr_property(ehdr, class, e_version, EV_CURRENT);
  2484. set_ehdr_property(ehdr, class, e_phoff, sizeof_elf_hdr(class));
  2485. set_ehdr_property(ehdr, class, e_ehsize, sizeof_elf_hdr(class));
  2486. set_ehdr_property(ehdr, class, e_phentsize, sizeof_elf_phdr(class));
  2487. set_ehdr_property(ehdr, class, e_phnum, phnum);
  2488. phdr = data + sizeof_elf_hdr(class);
  2489. offset = sizeof_elf_hdr(class) + sizeof_elf_phdr(class) * phnum;
  2490. list_for_each_entry(segment, segs, node) {
  2491. memset(phdr, 0, sizeof_elf_phdr(class));
  2492. set_phdr_property(phdr, class, p_type, PT_LOAD);
  2493. set_phdr_property(phdr, class, p_offset, offset);
  2494. set_phdr_property(phdr, class, p_vaddr, segment->da);
  2495. set_phdr_property(phdr, class, p_paddr, segment->da);
  2496. set_phdr_property(phdr, class, p_filesz, segment->size);
  2497. set_phdr_property(phdr, class, p_memsz, segment->size);
  2498. set_phdr_property(phdr, class, p_flags, PF_R | PF_W | PF_X);
  2499. set_phdr_property(phdr, class, p_align, 0);
  2500. if (segment->va) {
  2501. memcpy(data + offset, segment->va, segment->size);
  2502. } else {
  2503. ptr = devm_ioremap(dev, segment->da, segment->size);
  2504. if (!ptr) {
  2505. cnss_pr_err("Invalid coredump segment (%pad, %zu)\n",
  2506. &segment->da, segment->size);
  2507. memset(data + offset, 0xff, segment->size);
  2508. } else {
  2509. memcpy_fromio(data + offset, ptr,
  2510. segment->size);
  2511. }
  2512. }
  2513. offset += segment->size;
  2514. phdr += sizeof_elf_phdr(class);
  2515. }
  2516. return cnss_qcom_devcd_dump(dev, data, data_size, GFP_KERNEL);
  2517. }
  2518. /* Saving dump to file system is always needed in this case. */
  2519. static bool cnss_dump_enabled(void)
  2520. {
  2521. return true;
  2522. }
  2523. #endif /* CONFIG_QCOM_RAMDUMP */
  2524. int cnss_do_elf_ramdump(struct cnss_plat_data *plat_priv)
  2525. {
  2526. struct cnss_ramdump_info_v2 *info_v2 = &plat_priv->ramdump_info_v2;
  2527. struct cnss_dump_data *dump_data = &info_v2->dump_data;
  2528. struct cnss_dump_seg *dump_seg = info_v2->dump_data_vaddr;
  2529. struct qcom_dump_segment *seg;
  2530. struct cnss_dump_meta_info meta_info = {0};
  2531. struct list_head head;
  2532. int i, ret = 0;
  2533. if (!dump_enabled()) {
  2534. cnss_pr_info("Dump collection is not enabled\n");
  2535. return ret;
  2536. }
  2537. INIT_LIST_HEAD(&head);
  2538. for (i = 0; i < dump_data->nentries; i++) {
  2539. if (dump_seg->type >= CNSS_FW_DUMP_TYPE_MAX) {
  2540. cnss_pr_err("Unsupported dump type: %d",
  2541. dump_seg->type);
  2542. continue;
  2543. }
  2544. seg = kcalloc(1, sizeof(*seg), GFP_KERNEL);
  2545. if (!seg) {
  2546. cnss_pr_err("%s: Failed to allocate mem for seg %d\n",
  2547. __func__, i);
  2548. continue;
  2549. }
  2550. if (meta_info.entry[dump_seg->type].entry_start == 0) {
  2551. meta_info.entry[dump_seg->type].type = dump_seg->type;
  2552. meta_info.entry[dump_seg->type].entry_start = i + 1;
  2553. }
  2554. meta_info.entry[dump_seg->type].entry_num++;
  2555. seg->da = dump_seg->address;
  2556. seg->va = dump_seg->v_address;
  2557. seg->size = dump_seg->size;
  2558. list_add_tail(&seg->node, &head);
  2559. dump_seg++;
  2560. }
  2561. seg = kcalloc(1, sizeof(*seg), GFP_KERNEL);
  2562. if (!seg) {
  2563. cnss_pr_err("%s: Failed to allocate mem for elf ramdump seg\n",
  2564. __func__);
  2565. goto skip_elf_dump;
  2566. }
  2567. meta_info.magic = CNSS_RAMDUMP_MAGIC;
  2568. meta_info.version = CNSS_RAMDUMP_VERSION;
  2569. meta_info.chipset = plat_priv->device_id;
  2570. meta_info.total_entries = CNSS_FW_DUMP_TYPE_MAX;
  2571. seg->va = &meta_info;
  2572. seg->size = sizeof(meta_info);
  2573. list_add(&seg->node, &head);
  2574. ret = qcom_elf_dump(&head, info_v2->ramdump_dev, ELF_CLASS);
  2575. skip_elf_dump:
  2576. while (!list_empty(&head)) {
  2577. seg = list_first_entry(&head, struct qcom_dump_segment, node);
  2578. list_del(&seg->node);
  2579. kfree(seg);
  2580. }
  2581. return ret;
  2582. }
  2583. #ifdef CONFIG_CNSS2_SSR_DRIVER_DUMP
  2584. int cnss_do_host_ramdump(struct cnss_plat_data *plat_priv,
  2585. struct cnss_ssr_driver_dump_entry *ssr_entry,
  2586. size_t num_entries_loaded)
  2587. {
  2588. struct qcom_dump_segment *seg;
  2589. struct cnss_host_dump_meta_info meta_info = {0};
  2590. struct list_head head;
  2591. int dev_ret = 0;
  2592. struct device *new_device;
  2593. static const char * const wlan_str[] = {
  2594. [CNSS_HOST_WLAN_LOGS] = "wlan_logs",
  2595. [CNSS_HOST_HTC_CREDIT] = "htc_credit",
  2596. [CNSS_HOST_WMI_TX_CMP] = "wmi_tx_cmp",
  2597. [CNSS_HOST_WMI_COMMAND_LOG] = "wmi_command_log",
  2598. [CNSS_HOST_WMI_EVENT_LOG] = "wmi_event_log",
  2599. [CNSS_HOST_WMI_RX_EVENT] = "wmi_rx_event",
  2600. [CNSS_HOST_HAL_SOC] = "hal_soc",
  2601. [CNSS_HOST_GWLAN_LOGGING] = "gwlan_logging",
  2602. [CNSS_HOST_WMI_DEBUG_LOG_INFO] = "wmi_debug_log_info",
  2603. [CNSS_HOST_HTC_CREDIT_IDX] = "htc_credit_history_idx",
  2604. [CNSS_HOST_HTC_CREDIT_LEN] = "htc_credit_history_length",
  2605. [CNSS_HOST_WMI_TX_CMP_IDX] = "wmi_tx_cmp_idx",
  2606. [CNSS_HOST_WMI_COMMAND_LOG_IDX] = "wmi_command_log_idx",
  2607. [CNSS_HOST_WMI_EVENT_LOG_IDX] = "wmi_event_log_idx",
  2608. [CNSS_HOST_WMI_RX_EVENT_IDX] = "wmi_rx_event_idx",
  2609. [CNSS_HOST_HIF_CE_DESC_HISTORY] = "hif_ce_desc_history",
  2610. [CNSS_HOST_HIF_CE_DESC_HISTORY_BUFF] = "hif_ce_desc_history_buff",
  2611. [CNSS_HOST_HANG_EVENT_DATA] = "hang_event_data"
  2612. };
  2613. int i;
  2614. int ret = 0;
  2615. enum cnss_host_dump_type j;
  2616. if (!dump_enabled()) {
  2617. cnss_pr_info("Dump collection is not enabled\n");
  2618. return ret;
  2619. }
  2620. new_device = kcalloc(1, sizeof(*new_device), GFP_KERNEL);
  2621. if (!new_device) {
  2622. cnss_pr_err("Failed to alloc device mem\n");
  2623. return -ENOMEM;
  2624. }
  2625. device_initialize(new_device);
  2626. dev_set_name(new_device, "wlan_driver");
  2627. dev_ret = device_add(new_device);
  2628. if (dev_ret) {
  2629. cnss_pr_err("Failed to add new device\n");
  2630. goto put_device;
  2631. }
  2632. INIT_LIST_HEAD(&head);
  2633. for (i = 0; i < num_entries_loaded; i++) {
  2634. seg = kcalloc(1, sizeof(*seg), GFP_KERNEL);
  2635. if (!seg) {
  2636. cnss_pr_err("Failed to alloc seg entry %d\n", i);
  2637. continue;
  2638. }
  2639. seg->va = ssr_entry[i].buffer_pointer;
  2640. seg->da = (dma_addr_t)ssr_entry[i].buffer_pointer;
  2641. seg->size = ssr_entry[i].buffer_size;
  2642. for (j = 0; j < CNSS_HOST_DUMP_TYPE_MAX; j++) {
  2643. if (strncmp(ssr_entry[i].region_name, wlan_str[j],
  2644. strlen(wlan_str[j])) == 0) {
  2645. meta_info.entry[i].type = j;
  2646. }
  2647. }
  2648. meta_info.entry[i].entry_start = i + 1;
  2649. meta_info.entry[i].entry_num++;
  2650. list_add_tail(&seg->node, &head);
  2651. }
  2652. seg = kcalloc(1, sizeof(*seg), GFP_KERNEL);
  2653. if (!seg) {
  2654. cnss_pr_err("%s: Failed to allocate mem for host dump seg\n",
  2655. __func__);
  2656. goto skip_host_dump;
  2657. }
  2658. meta_info.magic = CNSS_RAMDUMP_MAGIC;
  2659. meta_info.version = CNSS_RAMDUMP_VERSION;
  2660. meta_info.chipset = plat_priv->device_id;
  2661. meta_info.total_entries = num_entries_loaded;
  2662. seg->va = &meta_info;
  2663. seg->da = (dma_addr_t)&meta_info;
  2664. seg->size = sizeof(meta_info);
  2665. list_add(&seg->node, &head);
  2666. ret = qcom_elf_dump(&head, new_device, ELF_CLASS);
  2667. skip_host_dump:
  2668. while (!list_empty(&head)) {
  2669. seg = list_first_entry(&head, struct qcom_dump_segment, node);
  2670. list_del(&seg->node);
  2671. kfree(seg);
  2672. }
  2673. device_del(new_device);
  2674. put_device:
  2675. put_device(new_device);
  2676. kfree(new_device);
  2677. return ret;
  2678. }
  2679. #endif
  2680. #endif /* CONFIG_MSM_SUBSYSTEM_RESTART */
  2681. #if IS_ENABLED(CONFIG_QCOM_MEMORY_DUMP_V2)
  2682. static int cnss_init_dump_entry(struct cnss_plat_data *plat_priv)
  2683. {
  2684. struct cnss_ramdump_info *ramdump_info;
  2685. struct msm_dump_entry dump_entry;
  2686. ramdump_info = &plat_priv->ramdump_info;
  2687. ramdump_info->dump_data.addr = ramdump_info->ramdump_pa;
  2688. ramdump_info->dump_data.len = ramdump_info->ramdump_size;
  2689. ramdump_info->dump_data.version = CNSS_DUMP_FORMAT_VER;
  2690. ramdump_info->dump_data.magic = CNSS_DUMP_MAGIC_VER_V2;
  2691. strlcpy(ramdump_info->dump_data.name, CNSS_DUMP_NAME,
  2692. sizeof(ramdump_info->dump_data.name));
  2693. dump_entry.id = MSM_DUMP_DATA_CNSS_WLAN;
  2694. dump_entry.addr = virt_to_phys(&ramdump_info->dump_data);
  2695. return msm_dump_data_register_nominidump(MSM_DUMP_TABLE_APPS,
  2696. &dump_entry);
  2697. }
  2698. static int cnss_register_ramdump_v1(struct cnss_plat_data *plat_priv)
  2699. {
  2700. int ret = 0;
  2701. struct device *dev;
  2702. struct cnss_ramdump_info *ramdump_info;
  2703. u32 ramdump_size = 0;
  2704. dev = &plat_priv->plat_dev->dev;
  2705. ramdump_info = &plat_priv->ramdump_info;
  2706. if (plat_priv->dt_type != CNSS_DTT_MULTIEXCHG) {
  2707. /* dt type: legacy or converged */
  2708. ret = of_property_read_u32(dev->of_node,
  2709. "qcom,wlan-ramdump-dynamic",
  2710. &ramdump_size);
  2711. } else {
  2712. ret = of_property_read_u32(plat_priv->dev_node,
  2713. "qcom,wlan-ramdump-dynamic",
  2714. &ramdump_size);
  2715. }
  2716. if (ret == 0) {
  2717. ramdump_info->ramdump_va =
  2718. dma_alloc_coherent(dev, ramdump_size,
  2719. &ramdump_info->ramdump_pa,
  2720. GFP_KERNEL);
  2721. if (ramdump_info->ramdump_va)
  2722. ramdump_info->ramdump_size = ramdump_size;
  2723. }
  2724. cnss_pr_dbg("ramdump va: %pK, pa: %pa\n",
  2725. ramdump_info->ramdump_va, &ramdump_info->ramdump_pa);
  2726. if (ramdump_info->ramdump_size == 0) {
  2727. cnss_pr_info("Ramdump will not be collected");
  2728. goto out;
  2729. }
  2730. ret = cnss_init_dump_entry(plat_priv);
  2731. if (ret) {
  2732. cnss_pr_err("Failed to setup dump table, err = %d\n", ret);
  2733. goto free_ramdump;
  2734. }
  2735. ramdump_info->ramdump_dev = cnss_create_ramdump_device(plat_priv);
  2736. if (!ramdump_info->ramdump_dev) {
  2737. cnss_pr_err("Failed to create ramdump device!");
  2738. ret = -ENOMEM;
  2739. goto free_ramdump;
  2740. }
  2741. return 0;
  2742. free_ramdump:
  2743. dma_free_coherent(dev, ramdump_info->ramdump_size,
  2744. ramdump_info->ramdump_va, ramdump_info->ramdump_pa);
  2745. out:
  2746. return ret;
  2747. }
  2748. static void cnss_unregister_ramdump_v1(struct cnss_plat_data *plat_priv)
  2749. {
  2750. struct device *dev;
  2751. struct cnss_ramdump_info *ramdump_info;
  2752. dev = &plat_priv->plat_dev->dev;
  2753. ramdump_info = &plat_priv->ramdump_info;
  2754. if (ramdump_info->ramdump_dev)
  2755. cnss_destroy_ramdump_device(plat_priv,
  2756. ramdump_info->ramdump_dev);
  2757. if (ramdump_info->ramdump_va)
  2758. dma_free_coherent(dev, ramdump_info->ramdump_size,
  2759. ramdump_info->ramdump_va,
  2760. ramdump_info->ramdump_pa);
  2761. }
  2762. /**
  2763. * cnss_ignore_dump_data_reg_fail - Ignore Ramdump table register failure
  2764. * @ret: Error returned by msm_dump_data_register_nominidump
  2765. *
  2766. * For Lahaina GKI boot, we dont have support for mem dump feature. So
  2767. * ignore failure.
  2768. *
  2769. * Return: Same given error code if mem dump feature enabled, 0 otherwise
  2770. */
  2771. static int cnss_ignore_dump_data_reg_fail(int ret)
  2772. {
  2773. return ret;
  2774. }
  2775. static int cnss_register_ramdump_v2(struct cnss_plat_data *plat_priv)
  2776. {
  2777. int ret = 0;
  2778. struct cnss_ramdump_info_v2 *info_v2;
  2779. struct cnss_dump_data *dump_data;
  2780. struct msm_dump_entry dump_entry;
  2781. struct device *dev = &plat_priv->plat_dev->dev;
  2782. u32 ramdump_size = 0;
  2783. info_v2 = &plat_priv->ramdump_info_v2;
  2784. dump_data = &info_v2->dump_data;
  2785. if (plat_priv->dt_type != CNSS_DTT_MULTIEXCHG) {
  2786. /* dt type: legacy or converged */
  2787. ret = of_property_read_u32(dev->of_node,
  2788. "qcom,wlan-ramdump-dynamic",
  2789. &ramdump_size);
  2790. } else {
  2791. ret = of_property_read_u32(plat_priv->dev_node,
  2792. "qcom,wlan-ramdump-dynamic",
  2793. &ramdump_size);
  2794. }
  2795. if (ret == 0)
  2796. info_v2->ramdump_size = ramdump_size;
  2797. cnss_pr_dbg("Ramdump size 0x%lx\n", info_v2->ramdump_size);
  2798. info_v2->dump_data_vaddr = kzalloc(CNSS_DUMP_DESC_SIZE, GFP_KERNEL);
  2799. if (!info_v2->dump_data_vaddr)
  2800. return -ENOMEM;
  2801. dump_data->paddr = virt_to_phys(info_v2->dump_data_vaddr);
  2802. dump_data->version = CNSS_DUMP_FORMAT_VER_V2;
  2803. dump_data->magic = CNSS_DUMP_MAGIC_VER_V2;
  2804. dump_data->seg_version = CNSS_DUMP_SEG_VER;
  2805. strlcpy(dump_data->name, CNSS_DUMP_NAME,
  2806. sizeof(dump_data->name));
  2807. dump_entry.id = MSM_DUMP_DATA_CNSS_WLAN;
  2808. dump_entry.addr = virt_to_phys(dump_data);
  2809. ret = msm_dump_data_register_nominidump(MSM_DUMP_TABLE_APPS,
  2810. &dump_entry);
  2811. if (ret) {
  2812. ret = cnss_ignore_dump_data_reg_fail(ret);
  2813. cnss_pr_err("Failed to setup dump table, %s (%d)\n",
  2814. ret ? "Error" : "Ignoring", ret);
  2815. goto free_ramdump;
  2816. }
  2817. info_v2->ramdump_dev = cnss_create_ramdump_device(plat_priv);
  2818. if (!info_v2->ramdump_dev) {
  2819. cnss_pr_err("Failed to create ramdump device!\n");
  2820. ret = -ENOMEM;
  2821. goto free_ramdump;
  2822. }
  2823. return 0;
  2824. free_ramdump:
  2825. kfree(info_v2->dump_data_vaddr);
  2826. info_v2->dump_data_vaddr = NULL;
  2827. return ret;
  2828. }
  2829. static void cnss_unregister_ramdump_v2(struct cnss_plat_data *plat_priv)
  2830. {
  2831. struct cnss_ramdump_info_v2 *info_v2;
  2832. info_v2 = &plat_priv->ramdump_info_v2;
  2833. if (info_v2->ramdump_dev)
  2834. cnss_destroy_ramdump_device(plat_priv, info_v2->ramdump_dev);
  2835. kfree(info_v2->dump_data_vaddr);
  2836. info_v2->dump_data_vaddr = NULL;
  2837. info_v2->dump_data_valid = false;
  2838. }
  2839. int cnss_register_ramdump(struct cnss_plat_data *plat_priv)
  2840. {
  2841. int ret = 0;
  2842. switch (plat_priv->device_id) {
  2843. case QCA6174_DEVICE_ID:
  2844. ret = cnss_register_ramdump_v1(plat_priv);
  2845. break;
  2846. case QCA6290_DEVICE_ID:
  2847. case QCA6390_DEVICE_ID:
  2848. case QCN7605_DEVICE_ID:
  2849. case QCA6490_DEVICE_ID:
  2850. case KIWI_DEVICE_ID:
  2851. case MANGO_DEVICE_ID:
  2852. case PEACH_DEVICE_ID:
  2853. ret = cnss_register_ramdump_v2(plat_priv);
  2854. break;
  2855. default:
  2856. cnss_pr_err("Unknown device ID: 0x%lx\n", plat_priv->device_id);
  2857. ret = -ENODEV;
  2858. break;
  2859. }
  2860. return ret;
  2861. }
  2862. void cnss_unregister_ramdump(struct cnss_plat_data *plat_priv)
  2863. {
  2864. switch (plat_priv->device_id) {
  2865. case QCA6174_DEVICE_ID:
  2866. cnss_unregister_ramdump_v1(plat_priv);
  2867. break;
  2868. case QCA6290_DEVICE_ID:
  2869. case QCA6390_DEVICE_ID:
  2870. case QCN7605_DEVICE_ID:
  2871. case QCA6490_DEVICE_ID:
  2872. case KIWI_DEVICE_ID:
  2873. case MANGO_DEVICE_ID:
  2874. case PEACH_DEVICE_ID:
  2875. cnss_unregister_ramdump_v2(plat_priv);
  2876. break;
  2877. default:
  2878. cnss_pr_err("Unknown device ID: 0x%lx\n", plat_priv->device_id);
  2879. break;
  2880. }
  2881. }
  2882. #else
  2883. int cnss_register_ramdump(struct cnss_plat_data *plat_priv)
  2884. {
  2885. struct cnss_ramdump_info_v2 *info_v2 = &plat_priv->ramdump_info_v2;
  2886. struct cnss_dump_data *dump_data = dump_data = &info_v2->dump_data;
  2887. struct device *dev = &plat_priv->plat_dev->dev;
  2888. u32 ramdump_size = 0;
  2889. if (of_property_read_u32(dev->of_node, "qcom,wlan-ramdump-dynamic",
  2890. &ramdump_size) == 0)
  2891. info_v2->ramdump_size = ramdump_size;
  2892. cnss_pr_dbg("Ramdump size 0x%lx\n", info_v2->ramdump_size);
  2893. info_v2->dump_data_vaddr = kzalloc(CNSS_DUMP_DESC_SIZE, GFP_KERNEL);
  2894. if (!info_v2->dump_data_vaddr)
  2895. return -ENOMEM;
  2896. dump_data->paddr = virt_to_phys(info_v2->dump_data_vaddr);
  2897. dump_data->version = CNSS_DUMP_FORMAT_VER_V2;
  2898. dump_data->magic = CNSS_DUMP_MAGIC_VER_V2;
  2899. dump_data->seg_version = CNSS_DUMP_SEG_VER;
  2900. strlcpy(dump_data->name, CNSS_DUMP_NAME,
  2901. sizeof(dump_data->name));
  2902. info_v2->ramdump_dev = dev;
  2903. return 0;
  2904. }
  2905. void cnss_unregister_ramdump(struct cnss_plat_data *plat_priv)
  2906. {
  2907. struct cnss_ramdump_info_v2 *info_v2 = &plat_priv->ramdump_info_v2;
  2908. info_v2->ramdump_dev = NULL;
  2909. kfree(info_v2->dump_data_vaddr);
  2910. info_v2->dump_data_vaddr = NULL;
  2911. info_v2->dump_data_valid = false;
  2912. }
  2913. #endif /* CONFIG_QCOM_MEMORY_DUMP_V2 */
  2914. #if IS_ENABLED(CONFIG_QCOM_MINIDUMP)
  2915. int cnss_va_to_pa(struct device *dev, size_t size, void *va, dma_addr_t dma,
  2916. phys_addr_t *pa, unsigned long attrs)
  2917. {
  2918. struct sg_table sgt;
  2919. int ret;
  2920. ret = dma_get_sgtable_attrs(dev, &sgt, va, dma, size, attrs);
  2921. if (ret) {
  2922. cnss_pr_err("Failed to get sgtable for va: 0x%pK, dma: %pa, size: 0x%zx, attrs: 0x%x\n",
  2923. va, &dma, size, attrs);
  2924. return -EINVAL;
  2925. }
  2926. *pa = page_to_phys(sg_page(sgt.sgl));
  2927. sg_free_table(&sgt);
  2928. return 0;
  2929. }
  2930. int cnss_minidump_add_region(struct cnss_plat_data *plat_priv,
  2931. enum cnss_fw_dump_type type, int seg_no,
  2932. void *va, phys_addr_t pa, size_t size)
  2933. {
  2934. struct md_region md_entry;
  2935. int ret;
  2936. switch (type) {
  2937. case CNSS_FW_IMAGE:
  2938. snprintf(md_entry.name, sizeof(md_entry.name), "FBC_%X",
  2939. seg_no);
  2940. break;
  2941. case CNSS_FW_RDDM:
  2942. snprintf(md_entry.name, sizeof(md_entry.name), "RDDM_%X",
  2943. seg_no);
  2944. break;
  2945. case CNSS_FW_REMOTE_HEAP:
  2946. snprintf(md_entry.name, sizeof(md_entry.name), "RHEAP_%X",
  2947. seg_no);
  2948. break;
  2949. default:
  2950. cnss_pr_err("Unknown dump type ID: %d\n", type);
  2951. return -EINVAL;
  2952. }
  2953. md_entry.phys_addr = pa;
  2954. md_entry.virt_addr = (uintptr_t)va;
  2955. md_entry.size = size;
  2956. md_entry.id = MSM_DUMP_DATA_CNSS_WLAN;
  2957. cnss_pr_dbg("Mini dump region: %s, va: %pK, pa: %pa, size: 0x%zx\n",
  2958. md_entry.name, va, &pa, size);
  2959. ret = msm_minidump_add_region(&md_entry);
  2960. if (ret < 0)
  2961. cnss_pr_err("Failed to add mini dump region, err = %d\n", ret);
  2962. return ret;
  2963. }
  2964. int cnss_minidump_remove_region(struct cnss_plat_data *plat_priv,
  2965. enum cnss_fw_dump_type type, int seg_no,
  2966. void *va, phys_addr_t pa, size_t size)
  2967. {
  2968. struct md_region md_entry;
  2969. int ret;
  2970. switch (type) {
  2971. case CNSS_FW_IMAGE:
  2972. snprintf(md_entry.name, sizeof(md_entry.name), "FBC_%X",
  2973. seg_no);
  2974. break;
  2975. case CNSS_FW_RDDM:
  2976. snprintf(md_entry.name, sizeof(md_entry.name), "RDDM_%X",
  2977. seg_no);
  2978. break;
  2979. case CNSS_FW_REMOTE_HEAP:
  2980. snprintf(md_entry.name, sizeof(md_entry.name), "RHEAP_%X",
  2981. seg_no);
  2982. break;
  2983. default:
  2984. cnss_pr_err("Unknown dump type ID: %d\n", type);
  2985. return -EINVAL;
  2986. }
  2987. md_entry.phys_addr = pa;
  2988. md_entry.virt_addr = (uintptr_t)va;
  2989. md_entry.size = size;
  2990. md_entry.id = MSM_DUMP_DATA_CNSS_WLAN;
  2991. cnss_pr_dbg("Remove mini dump region: %s, va: %pK, pa: %pa, size: 0x%zx\n",
  2992. md_entry.name, va, &pa, size);
  2993. ret = msm_minidump_remove_region(&md_entry);
  2994. if (ret)
  2995. cnss_pr_err("Failed to remove mini dump region, err = %d\n",
  2996. ret);
  2997. return ret;
  2998. }
  2999. #else
  3000. int cnss_va_to_pa(struct device *dev, size_t size, void *va, dma_addr_t dma,
  3001. phys_addr_t *pa, unsigned long attrs)
  3002. {
  3003. return 0;
  3004. }
  3005. int cnss_minidump_add_region(struct cnss_plat_data *plat_priv,
  3006. enum cnss_fw_dump_type type, int seg_no,
  3007. void *va, phys_addr_t pa, size_t size)
  3008. {
  3009. return 0;
  3010. }
  3011. int cnss_minidump_remove_region(struct cnss_plat_data *plat_priv,
  3012. enum cnss_fw_dump_type type, int seg_no,
  3013. void *va, phys_addr_t pa, size_t size)
  3014. {
  3015. return 0;
  3016. }
  3017. #endif /* CONFIG_QCOM_MINIDUMP */
  3018. int cnss_request_firmware_direct(struct cnss_plat_data *plat_priv,
  3019. const struct firmware **fw_entry,
  3020. const char *filename)
  3021. {
  3022. if (IS_ENABLED(CONFIG_CNSS_REQ_FW_DIRECT))
  3023. return request_firmware_direct(fw_entry, filename,
  3024. &plat_priv->plat_dev->dev);
  3025. else
  3026. return firmware_request_nowarn(fw_entry, filename,
  3027. &plat_priv->plat_dev->dev);
  3028. }
  3029. #if IS_ENABLED(CONFIG_INTERCONNECT)
  3030. /**
  3031. * cnss_register_bus_scale() - Setup interconnect voting data
  3032. * @plat_priv: Platform data structure
  3033. *
  3034. * For different interconnect path configured in device tree setup voting data
  3035. * for list of bandwidth requirements.
  3036. *
  3037. * Result: 0 for success. -EINVAL if not configured
  3038. */
  3039. static int cnss_register_bus_scale(struct cnss_plat_data *plat_priv)
  3040. {
  3041. int ret = -EINVAL;
  3042. u32 idx, i, j, cfg_arr_size, *cfg_arr = NULL;
  3043. struct cnss_bus_bw_info *bus_bw_info, *tmp;
  3044. struct device *dev = &plat_priv->plat_dev->dev;
  3045. INIT_LIST_HEAD(&plat_priv->icc.list_head);
  3046. ret = of_property_read_u32(dev->of_node,
  3047. "qcom,icc-path-count",
  3048. &plat_priv->icc.path_count);
  3049. if (ret) {
  3050. cnss_pr_dbg("Platform Bus Interconnect path not configured\n");
  3051. return 0;
  3052. }
  3053. ret = of_property_read_u32(plat_priv->plat_dev->dev.of_node,
  3054. "qcom,bus-bw-cfg-count",
  3055. &plat_priv->icc.bus_bw_cfg_count);
  3056. if (ret) {
  3057. cnss_pr_err("Failed to get Bus BW Config table size\n");
  3058. goto cleanup;
  3059. }
  3060. cfg_arr_size = plat_priv->icc.path_count *
  3061. plat_priv->icc.bus_bw_cfg_count * CNSS_ICC_VOTE_MAX;
  3062. cfg_arr = kcalloc(cfg_arr_size, sizeof(*cfg_arr), GFP_KERNEL);
  3063. if (!cfg_arr) {
  3064. cnss_pr_err("Failed to alloc cfg table mem\n");
  3065. ret = -ENOMEM;
  3066. goto cleanup;
  3067. }
  3068. ret = of_property_read_u32_array(plat_priv->plat_dev->dev.of_node,
  3069. "qcom,bus-bw-cfg", cfg_arr,
  3070. cfg_arr_size);
  3071. if (ret) {
  3072. cnss_pr_err("Invalid Bus BW Config Table\n");
  3073. goto cleanup;
  3074. }
  3075. cnss_pr_dbg("ICC Path_Count: %d BW_CFG_Count: %d\n",
  3076. plat_priv->icc.path_count, plat_priv->icc.bus_bw_cfg_count);
  3077. for (idx = 0; idx < plat_priv->icc.path_count; idx++) {
  3078. bus_bw_info = devm_kzalloc(dev, sizeof(*bus_bw_info),
  3079. GFP_KERNEL);
  3080. if (!bus_bw_info) {
  3081. ret = -ENOMEM;
  3082. goto out;
  3083. }
  3084. ret = of_property_read_string_index(dev->of_node,
  3085. "interconnect-names", idx,
  3086. &bus_bw_info->icc_name);
  3087. if (ret)
  3088. goto out;
  3089. bus_bw_info->icc_path =
  3090. of_icc_get(&plat_priv->plat_dev->dev,
  3091. bus_bw_info->icc_name);
  3092. if (IS_ERR(bus_bw_info->icc_path)) {
  3093. ret = PTR_ERR(bus_bw_info->icc_path);
  3094. if (ret != -EPROBE_DEFER) {
  3095. cnss_pr_err("Failed to get Interconnect path for %s. Err: %d\n",
  3096. bus_bw_info->icc_name, ret);
  3097. goto out;
  3098. }
  3099. }
  3100. bus_bw_info->cfg_table =
  3101. devm_kcalloc(dev, plat_priv->icc.bus_bw_cfg_count,
  3102. sizeof(*bus_bw_info->cfg_table),
  3103. GFP_KERNEL);
  3104. if (!bus_bw_info->cfg_table) {
  3105. ret = -ENOMEM;
  3106. goto out;
  3107. }
  3108. cnss_pr_dbg("ICC Vote CFG for path: %s\n",
  3109. bus_bw_info->icc_name);
  3110. for (i = 0, j = (idx * plat_priv->icc.bus_bw_cfg_count *
  3111. CNSS_ICC_VOTE_MAX);
  3112. i < plat_priv->icc.bus_bw_cfg_count;
  3113. i++, j += 2) {
  3114. bus_bw_info->cfg_table[i].avg_bw = cfg_arr[j];
  3115. bus_bw_info->cfg_table[i].peak_bw = cfg_arr[j + 1];
  3116. cnss_pr_dbg("ICC Vote BW: %d avg: %d peak: %d\n",
  3117. i, bus_bw_info->cfg_table[i].avg_bw,
  3118. bus_bw_info->cfg_table[i].peak_bw);
  3119. }
  3120. list_add_tail(&bus_bw_info->list,
  3121. &plat_priv->icc.list_head);
  3122. }
  3123. kfree(cfg_arr);
  3124. return 0;
  3125. out:
  3126. list_for_each_entry_safe(bus_bw_info, tmp,
  3127. &plat_priv->icc.list_head, list) {
  3128. list_del(&bus_bw_info->list);
  3129. }
  3130. cleanup:
  3131. kfree(cfg_arr);
  3132. memset(&plat_priv->icc, 0, sizeof(plat_priv->icc));
  3133. return ret;
  3134. }
  3135. static void cnss_unregister_bus_scale(struct cnss_plat_data *plat_priv)
  3136. {
  3137. struct cnss_bus_bw_info *bus_bw_info, *tmp;
  3138. list_for_each_entry_safe(bus_bw_info, tmp,
  3139. &plat_priv->icc.list_head, list) {
  3140. list_del(&bus_bw_info->list);
  3141. if (bus_bw_info->icc_path)
  3142. icc_put(bus_bw_info->icc_path);
  3143. }
  3144. memset(&plat_priv->icc, 0, sizeof(plat_priv->icc));
  3145. }
  3146. #else
  3147. static int cnss_register_bus_scale(struct cnss_plat_data *plat_priv)
  3148. {
  3149. return 0;
  3150. }
  3151. static void cnss_unregister_bus_scale(struct cnss_plat_data *plat_priv) {}
  3152. #endif /* CONFIG_INTERCONNECT */
  3153. void cnss_daemon_connection_update_cb(void *cb_ctx, bool status)
  3154. {
  3155. struct cnss_plat_data *plat_priv = cb_ctx;
  3156. if (!plat_priv) {
  3157. cnss_pr_err("%s: Invalid context\n", __func__);
  3158. return;
  3159. }
  3160. if (status) {
  3161. cnss_pr_info("CNSS Daemon connected\n");
  3162. set_bit(CNSS_DAEMON_CONNECTED, &plat_priv->driver_state);
  3163. complete(&plat_priv->daemon_connected);
  3164. } else {
  3165. cnss_pr_info("CNSS Daemon disconnected\n");
  3166. reinit_completion(&plat_priv->daemon_connected);
  3167. clear_bit(CNSS_DAEMON_CONNECTED, &plat_priv->driver_state);
  3168. }
  3169. }
  3170. static ssize_t enable_hds_store(struct device *dev,
  3171. struct device_attribute *attr,
  3172. const char *buf, size_t count)
  3173. {
  3174. struct cnss_plat_data *plat_priv = dev_get_drvdata(dev);
  3175. unsigned int enable_hds = 0;
  3176. if (!plat_priv)
  3177. return -ENODEV;
  3178. if (sscanf(buf, "%du", &enable_hds) != 1) {
  3179. cnss_pr_err("Invalid enable_hds sysfs command\n");
  3180. return -EINVAL;
  3181. }
  3182. if (enable_hds)
  3183. plat_priv->hds_enabled = true;
  3184. else
  3185. plat_priv->hds_enabled = false;
  3186. cnss_pr_dbg("%s HDS file download, count is %zu\n",
  3187. plat_priv->hds_enabled ? "Enable" : "Disable", count);
  3188. return count;
  3189. }
  3190. static ssize_t recovery_show(struct device *dev,
  3191. struct device_attribute *attr,
  3192. char *buf)
  3193. {
  3194. struct cnss_plat_data *plat_priv = dev_get_drvdata(dev);
  3195. u32 buf_size = PAGE_SIZE;
  3196. u32 curr_len = 0;
  3197. u32 buf_written = 0;
  3198. if (!plat_priv)
  3199. return -ENODEV;
  3200. buf_written = scnprintf(buf, buf_size,
  3201. "Usage: echo [recovery_bitmap] > /sys/kernel/cnss/recovery\n"
  3202. "BIT0 -- wlan fw recovery\n"
  3203. "BIT1 -- wlan pcss recovery\n"
  3204. "---------------------------------\n");
  3205. curr_len += buf_written;
  3206. buf_written = scnprintf(buf + curr_len, buf_size - curr_len,
  3207. "WLAN recovery %s[%d]\n",
  3208. plat_priv->recovery_enabled ? "Enabled" : "Disabled",
  3209. plat_priv->recovery_enabled);
  3210. curr_len += buf_written;
  3211. buf_written = scnprintf(buf + curr_len, buf_size - curr_len,
  3212. "WLAN PCSS recovery %s[%d]\n",
  3213. plat_priv->recovery_pcss_enabled ? "Enabled" : "Disabled",
  3214. plat_priv->recovery_pcss_enabled);
  3215. curr_len += buf_written;
  3216. /*
  3217. * Now size of curr_len is not over page size for sure,
  3218. * later if new item or none-fixed size item added, need
  3219. * add check to make sure curr_len is not over page size.
  3220. */
  3221. return curr_len;
  3222. }
  3223. static ssize_t time_sync_period_show(struct device *dev,
  3224. struct device_attribute *attr,
  3225. char *buf)
  3226. {
  3227. struct cnss_plat_data *plat_priv = dev_get_drvdata(dev);
  3228. return scnprintf(buf, PAGE_SIZE, "%u ms\n",
  3229. plat_priv->ctrl_params.time_sync_period);
  3230. }
  3231. static ssize_t time_sync_period_store(struct device *dev,
  3232. struct device_attribute *attr,
  3233. const char *buf, size_t count)
  3234. {
  3235. struct cnss_plat_data *plat_priv = dev_get_drvdata(dev);
  3236. unsigned int time_sync_period = 0;
  3237. if (!plat_priv)
  3238. return -ENODEV;
  3239. if (sscanf(buf, "%du", &time_sync_period) != 1) {
  3240. cnss_pr_err("Invalid time sync sysfs command\n");
  3241. return -EINVAL;
  3242. }
  3243. if (time_sync_period >= CNSS_MIN_TIME_SYNC_PERIOD)
  3244. cnss_bus_update_time_sync_period(plat_priv, time_sync_period);
  3245. return count;
  3246. }
  3247. static ssize_t recovery_store(struct device *dev,
  3248. struct device_attribute *attr,
  3249. const char *buf, size_t count)
  3250. {
  3251. struct cnss_plat_data *plat_priv = dev_get_drvdata(dev);
  3252. unsigned int recovery = 0;
  3253. if (!plat_priv)
  3254. return -ENODEV;
  3255. if (sscanf(buf, "%du", &recovery) != 1) {
  3256. cnss_pr_err("Invalid recovery sysfs command\n");
  3257. return -EINVAL;
  3258. }
  3259. plat_priv->recovery_enabled = !!(recovery & CNSS_WLAN_RECOVERY);
  3260. plat_priv->recovery_pcss_enabled = !!(recovery & CNSS_PCSS_RECOVERY);
  3261. cnss_pr_dbg("%s WLAN recovery, count is %zu\n",
  3262. plat_priv->recovery_enabled ? "Enable" : "Disable", count);
  3263. cnss_pr_dbg("%s PCSS recovery, count is %zu\n",
  3264. plat_priv->recovery_pcss_enabled ? "Enable" : "Disable", count);
  3265. cnss_send_subsys_restart_level_msg(plat_priv);
  3266. return count;
  3267. }
  3268. static ssize_t shutdown_store(struct device *dev,
  3269. struct device_attribute *attr,
  3270. const char *buf, size_t count)
  3271. {
  3272. struct cnss_plat_data *plat_priv = dev_get_drvdata(dev);
  3273. if (plat_priv) {
  3274. set_bit(CNSS_IN_REBOOT, &plat_priv->driver_state);
  3275. del_timer(&plat_priv->fw_boot_timer);
  3276. complete_all(&plat_priv->power_up_complete);
  3277. complete_all(&plat_priv->cal_complete);
  3278. }
  3279. cnss_pr_dbg("Received shutdown notification\n");
  3280. return count;
  3281. }
  3282. static ssize_t fs_ready_store(struct device *dev,
  3283. struct device_attribute *attr,
  3284. const char *buf, size_t count)
  3285. {
  3286. int fs_ready = 0;
  3287. struct cnss_plat_data *plat_priv = dev_get_drvdata(dev);
  3288. if (sscanf(buf, "%du", &fs_ready) != 1)
  3289. return -EINVAL;
  3290. cnss_pr_dbg("File system is ready, fs_ready is %d, count is %zu\n",
  3291. fs_ready, count);
  3292. if (!plat_priv) {
  3293. cnss_pr_err("plat_priv is NULL\n");
  3294. return count;
  3295. }
  3296. if (test_bit(QMI_BYPASS, &plat_priv->ctrl_params.quirks)) {
  3297. cnss_pr_dbg("QMI is bypassed\n");
  3298. return count;
  3299. }
  3300. set_bit(CNSS_FS_READY, &plat_priv->driver_state);
  3301. if (fs_ready == FILE_SYSTEM_READY && plat_priv->cbc_enabled) {
  3302. cnss_driver_event_post(plat_priv,
  3303. CNSS_DRIVER_EVENT_COLD_BOOT_CAL_START,
  3304. 0, NULL);
  3305. }
  3306. return count;
  3307. }
  3308. static ssize_t qdss_trace_start_store(struct device *dev,
  3309. struct device_attribute *attr,
  3310. const char *buf, size_t count)
  3311. {
  3312. struct cnss_plat_data *plat_priv = dev_get_drvdata(dev);
  3313. wlfw_qdss_trace_start(plat_priv);
  3314. cnss_pr_dbg("Received QDSS start command\n");
  3315. return count;
  3316. }
  3317. static ssize_t qdss_trace_stop_store(struct device *dev,
  3318. struct device_attribute *attr,
  3319. const char *buf, size_t count)
  3320. {
  3321. struct cnss_plat_data *plat_priv = dev_get_drvdata(dev);
  3322. u32 option = 0;
  3323. if (sscanf(buf, "%du", &option) != 1)
  3324. return -EINVAL;
  3325. wlfw_qdss_trace_stop(plat_priv, option);
  3326. cnss_pr_dbg("Received QDSS stop command\n");
  3327. return count;
  3328. }
  3329. static ssize_t qdss_conf_download_store(struct device *dev,
  3330. struct device_attribute *attr,
  3331. const char *buf, size_t count)
  3332. {
  3333. struct cnss_plat_data *plat_priv = dev_get_drvdata(dev);
  3334. cnss_wlfw_qdss_dnld_send_sync(plat_priv);
  3335. cnss_pr_dbg("Received QDSS download config command\n");
  3336. return count;
  3337. }
  3338. static ssize_t hw_trace_override_store(struct device *dev,
  3339. struct device_attribute *attr,
  3340. const char *buf, size_t count)
  3341. {
  3342. struct cnss_plat_data *plat_priv = dev_get_drvdata(dev);
  3343. int tmp = 0;
  3344. if (sscanf(buf, "%du", &tmp) != 1)
  3345. return -EINVAL;
  3346. plat_priv->hw_trc_override = tmp;
  3347. cnss_pr_dbg("Received QDSS hw_trc_override indication\n");
  3348. return count;
  3349. }
  3350. static ssize_t charger_mode_store(struct device *dev,
  3351. struct device_attribute *attr,
  3352. const char *buf, size_t count)
  3353. {
  3354. struct cnss_plat_data *plat_priv = dev_get_drvdata(dev);
  3355. int tmp = 0;
  3356. if (sscanf(buf, "%du", &tmp) != 1)
  3357. return -EINVAL;
  3358. plat_priv->charger_mode = tmp;
  3359. cnss_pr_dbg("Received Charger Mode: %d\n", tmp);
  3360. return count;
  3361. }
  3362. static DEVICE_ATTR_WO(fs_ready);
  3363. static DEVICE_ATTR_WO(shutdown);
  3364. static DEVICE_ATTR_RW(recovery);
  3365. static DEVICE_ATTR_WO(enable_hds);
  3366. static DEVICE_ATTR_WO(qdss_trace_start);
  3367. static DEVICE_ATTR_WO(qdss_trace_stop);
  3368. static DEVICE_ATTR_WO(qdss_conf_download);
  3369. static DEVICE_ATTR_WO(hw_trace_override);
  3370. static DEVICE_ATTR_WO(charger_mode);
  3371. static DEVICE_ATTR_RW(time_sync_period);
  3372. static struct attribute *cnss_attrs[] = {
  3373. &dev_attr_fs_ready.attr,
  3374. &dev_attr_shutdown.attr,
  3375. &dev_attr_recovery.attr,
  3376. &dev_attr_enable_hds.attr,
  3377. &dev_attr_qdss_trace_start.attr,
  3378. &dev_attr_qdss_trace_stop.attr,
  3379. &dev_attr_qdss_conf_download.attr,
  3380. &dev_attr_hw_trace_override.attr,
  3381. &dev_attr_charger_mode.attr,
  3382. &dev_attr_time_sync_period.attr,
  3383. NULL,
  3384. };
  3385. static struct attribute_group cnss_attr_group = {
  3386. .attrs = cnss_attrs,
  3387. };
  3388. static int cnss_create_sysfs_link(struct cnss_plat_data *plat_priv)
  3389. {
  3390. struct device *dev = &plat_priv->plat_dev->dev;
  3391. int ret;
  3392. char cnss_name[CNSS_FS_NAME_SIZE];
  3393. char shutdown_name[32];
  3394. if (cnss_is_dual_wlan_enabled()) {
  3395. snprintf(cnss_name, CNSS_FS_NAME_SIZE,
  3396. CNSS_FS_NAME "_%d", plat_priv->plat_idx);
  3397. snprintf(shutdown_name, sizeof(shutdown_name),
  3398. "shutdown_wlan_%d", plat_priv->plat_idx);
  3399. } else {
  3400. snprintf(cnss_name, CNSS_FS_NAME_SIZE, CNSS_FS_NAME);
  3401. snprintf(shutdown_name, sizeof(shutdown_name),
  3402. "shutdown_wlan");
  3403. }
  3404. ret = sysfs_create_link(kernel_kobj, &dev->kobj, cnss_name);
  3405. if (ret) {
  3406. cnss_pr_err("Failed to create cnss link, err = %d\n",
  3407. ret);
  3408. goto out;
  3409. }
  3410. /* This is only for backward compatibility. */
  3411. ret = sysfs_create_link(kernel_kobj, &dev->kobj, shutdown_name);
  3412. if (ret) {
  3413. cnss_pr_err("Failed to create shutdown_wlan link, err = %d\n",
  3414. ret);
  3415. goto rm_cnss_link;
  3416. }
  3417. return 0;
  3418. rm_cnss_link:
  3419. sysfs_remove_link(kernel_kobj, cnss_name);
  3420. out:
  3421. return ret;
  3422. }
  3423. static void cnss_remove_sysfs_link(struct cnss_plat_data *plat_priv)
  3424. {
  3425. char cnss_name[CNSS_FS_NAME_SIZE];
  3426. char shutdown_name[32];
  3427. if (cnss_is_dual_wlan_enabled()) {
  3428. snprintf(cnss_name, CNSS_FS_NAME_SIZE,
  3429. CNSS_FS_NAME "_%d", plat_priv->plat_idx);
  3430. snprintf(shutdown_name, sizeof(shutdown_name),
  3431. "shutdown_wlan_%d", plat_priv->plat_idx);
  3432. } else {
  3433. snprintf(cnss_name, CNSS_FS_NAME_SIZE, CNSS_FS_NAME);
  3434. snprintf(shutdown_name, sizeof(shutdown_name),
  3435. "shutdown_wlan");
  3436. }
  3437. sysfs_remove_link(kernel_kobj, shutdown_name);
  3438. sysfs_remove_link(kernel_kobj, cnss_name);
  3439. }
  3440. static int cnss_create_sysfs(struct cnss_plat_data *plat_priv)
  3441. {
  3442. int ret = 0;
  3443. ret = devm_device_add_group(&plat_priv->plat_dev->dev,
  3444. &cnss_attr_group);
  3445. if (ret) {
  3446. cnss_pr_err("Failed to create cnss device group, err = %d\n",
  3447. ret);
  3448. goto out;
  3449. }
  3450. cnss_create_sysfs_link(plat_priv);
  3451. return 0;
  3452. out:
  3453. return ret;
  3454. }
  3455. static void cnss_remove_sysfs(struct cnss_plat_data *plat_priv)
  3456. {
  3457. cnss_remove_sysfs_link(plat_priv);
  3458. devm_device_remove_group(&plat_priv->plat_dev->dev, &cnss_attr_group);
  3459. }
  3460. static int cnss_event_work_init(struct cnss_plat_data *plat_priv)
  3461. {
  3462. spin_lock_init(&plat_priv->event_lock);
  3463. plat_priv->event_wq = alloc_workqueue("cnss_driver_event",
  3464. WQ_UNBOUND, 1);
  3465. if (!plat_priv->event_wq) {
  3466. cnss_pr_err("Failed to create event workqueue!\n");
  3467. return -EFAULT;
  3468. }
  3469. INIT_WORK(&plat_priv->event_work, cnss_driver_event_work);
  3470. INIT_LIST_HEAD(&plat_priv->event_list);
  3471. return 0;
  3472. }
  3473. static void cnss_event_work_deinit(struct cnss_plat_data *plat_priv)
  3474. {
  3475. destroy_workqueue(plat_priv->event_wq);
  3476. }
  3477. static int cnss_reboot_notifier(struct notifier_block *nb,
  3478. unsigned long action,
  3479. void *data)
  3480. {
  3481. struct cnss_plat_data *plat_priv =
  3482. container_of(nb, struct cnss_plat_data, reboot_nb);
  3483. set_bit(CNSS_IN_REBOOT, &plat_priv->driver_state);
  3484. del_timer(&plat_priv->fw_boot_timer);
  3485. complete_all(&plat_priv->power_up_complete);
  3486. complete_all(&plat_priv->cal_complete);
  3487. cnss_pr_dbg("Reboot is in progress with action %d\n", action);
  3488. return NOTIFY_DONE;
  3489. }
  3490. #ifdef CONFIG_CNSS_HW_SECURE_DISABLE
  3491. int cnss_wlan_hw_disable_check(struct cnss_plat_data *plat_priv)
  3492. {
  3493. struct Object client_env;
  3494. struct Object app_object;
  3495. u32 wifi_uid = HW_WIFI_UID;
  3496. union ObjectArg obj_arg[2] = {{{0, 0}}};
  3497. int ret;
  3498. u8 state = 0;
  3499. /* Once this flag is set, secure peripheral feature
  3500. * will not be supported till next reboot
  3501. */
  3502. if (plat_priv->sec_peri_feature_disable)
  3503. return 0;
  3504. /* get rootObj */
  3505. ret = get_client_env_object(&client_env);
  3506. if (ret) {
  3507. cnss_pr_dbg("Failed to get client_env_object, ret: %d\n", ret);
  3508. goto end;
  3509. }
  3510. ret = IClientEnv_open(client_env, HW_STATE_UID, &app_object);
  3511. if (ret) {
  3512. cnss_pr_dbg("Failed to get app_object, ret: %d\n", ret);
  3513. if (ret == FEATURE_NOT_SUPPORTED) {
  3514. ret = 0; /* Do not Assert */
  3515. plat_priv->sec_peri_feature_disable = true;
  3516. cnss_pr_dbg("Secure HW feature not supported\n");
  3517. }
  3518. goto exit_release_clientenv;
  3519. }
  3520. obj_arg[0].b = (struct ObjectBuf) {&wifi_uid, sizeof(u32)};
  3521. obj_arg[1].b = (struct ObjectBuf) {&state, sizeof(u8)};
  3522. ret = Object_invoke(app_object, HW_OP_GET_STATE, obj_arg,
  3523. ObjectCounts_pack(1, 1, 0, 0));
  3524. cnss_pr_dbg("SMC invoke ret: %d state: %d\n", ret, state);
  3525. if (ret) {
  3526. if (ret == PERIPHERAL_NOT_FOUND) {
  3527. ret = 0; /* Do not Assert */
  3528. plat_priv->sec_peri_feature_disable = true;
  3529. cnss_pr_dbg("Secure HW mode is not updated. Peripheral not found\n");
  3530. }
  3531. goto exit_release_app_obj;
  3532. }
  3533. if (state == 1)
  3534. set_bit(CNSS_WLAN_HW_DISABLED,
  3535. &plat_priv->driver_state);
  3536. else
  3537. clear_bit(CNSS_WLAN_HW_DISABLED,
  3538. &plat_priv->driver_state);
  3539. exit_release_app_obj:
  3540. Object_release(app_object);
  3541. exit_release_clientenv:
  3542. Object_release(client_env);
  3543. end:
  3544. if (ret) {
  3545. cnss_pr_err("Unable to get HW disable status\n");
  3546. CNSS_ASSERT(0);
  3547. }
  3548. return ret;
  3549. }
  3550. #else
  3551. int cnss_wlan_hw_disable_check(struct cnss_plat_data *plat_priv)
  3552. {
  3553. return 0;
  3554. }
  3555. #endif
  3556. #ifdef CONFIG_DISABLE_CNSS_SRAM_DUMP
  3557. static void cnss_sram_dump_init(struct cnss_plat_data *plat_priv)
  3558. {
  3559. }
  3560. #else
  3561. static void cnss_sram_dump_init(struct cnss_plat_data *plat_priv)
  3562. {
  3563. if (plat_priv->device_id == QCA6490_DEVICE_ID &&
  3564. cnss_get_host_build_type() == QMI_HOST_BUILD_TYPE_PRIMARY_V01)
  3565. plat_priv->sram_dump = kcalloc(SRAM_DUMP_SIZE, 1, GFP_KERNEL);
  3566. }
  3567. #endif
  3568. static int cnss_misc_init(struct cnss_plat_data *plat_priv)
  3569. {
  3570. int ret;
  3571. ret = cnss_init_sol_gpio(plat_priv);
  3572. if (ret)
  3573. return ret;
  3574. timer_setup(&plat_priv->fw_boot_timer,
  3575. cnss_bus_fw_boot_timeout_hdlr, 0);
  3576. plat_priv->reboot_nb.notifier_call = cnss_reboot_notifier;
  3577. ret = register_reboot_notifier(&plat_priv->reboot_nb);
  3578. if (ret)
  3579. cnss_pr_err("Failed to register reboot notifier, err = %d\n",
  3580. ret);
  3581. ret = device_init_wakeup(&plat_priv->plat_dev->dev, true);
  3582. if (ret)
  3583. cnss_pr_err("Failed to init platform device wakeup source, err = %d\n",
  3584. ret);
  3585. INIT_WORK(&plat_priv->recovery_work, cnss_recovery_work_handler);
  3586. init_completion(&plat_priv->power_up_complete);
  3587. init_completion(&plat_priv->cal_complete);
  3588. init_completion(&plat_priv->rddm_complete);
  3589. init_completion(&plat_priv->recovery_complete);
  3590. init_completion(&plat_priv->daemon_connected);
  3591. mutex_init(&plat_priv->dev_lock);
  3592. mutex_init(&plat_priv->driver_ops_lock);
  3593. plat_priv->recovery_ws =
  3594. wakeup_source_register(&plat_priv->plat_dev->dev,
  3595. "CNSS_FW_RECOVERY");
  3596. if (!plat_priv->recovery_ws)
  3597. cnss_pr_err("Failed to setup FW recovery wake source\n");
  3598. ret = cnss_plat_ipc_register(CNSS_PLAT_IPC_DAEMON_QMI_CLIENT_V01,
  3599. cnss_daemon_connection_update_cb,
  3600. plat_priv);
  3601. if (ret)
  3602. cnss_pr_err("QMI IPC connection call back register failed, err = %d\n",
  3603. ret);
  3604. cnss_sram_dump_init(plat_priv);
  3605. if (of_property_read_bool(plat_priv->plat_dev->dev.of_node,
  3606. "qcom,rc-ep-short-channel"))
  3607. cnss_set_feature_list(plat_priv, CNSS_RC_EP_ULTRASHORT_CHANNEL_V01);
  3608. return 0;
  3609. }
  3610. #ifdef CONFIG_DISABLE_CNSS_SRAM_DUMP
  3611. static void cnss_sram_dump_deinit(struct cnss_plat_data *plat_priv)
  3612. {
  3613. }
  3614. #else
  3615. static void cnss_sram_dump_deinit(struct cnss_plat_data *plat_priv)
  3616. {
  3617. if (plat_priv->device_id == QCA6490_DEVICE_ID &&
  3618. cnss_get_host_build_type() == QMI_HOST_BUILD_TYPE_PRIMARY_V01)
  3619. kfree(plat_priv->sram_dump);
  3620. }
  3621. #endif
  3622. static void cnss_misc_deinit(struct cnss_plat_data *plat_priv)
  3623. {
  3624. cnss_plat_ipc_unregister(CNSS_PLAT_IPC_DAEMON_QMI_CLIENT_V01,
  3625. plat_priv);
  3626. complete_all(&plat_priv->recovery_complete);
  3627. complete_all(&plat_priv->rddm_complete);
  3628. complete_all(&plat_priv->cal_complete);
  3629. complete_all(&plat_priv->power_up_complete);
  3630. complete_all(&plat_priv->daemon_connected);
  3631. device_init_wakeup(&plat_priv->plat_dev->dev, false);
  3632. unregister_reboot_notifier(&plat_priv->reboot_nb);
  3633. del_timer(&plat_priv->fw_boot_timer);
  3634. wakeup_source_unregister(plat_priv->recovery_ws);
  3635. cnss_deinit_sol_gpio(plat_priv);
  3636. cnss_sram_dump_deinit(plat_priv);
  3637. kfree(plat_priv->on_chip_pmic_board_ids);
  3638. }
  3639. static void cnss_init_control_params(struct cnss_plat_data *plat_priv)
  3640. {
  3641. plat_priv->ctrl_params.quirks = CNSS_QUIRKS_DEFAULT;
  3642. plat_priv->cbc_enabled = !IS_ENABLED(CONFIG_CNSS_EMULATION) &&
  3643. of_property_read_bool(plat_priv->plat_dev->dev.of_node,
  3644. "qcom,wlan-cbc-enabled");
  3645. plat_priv->ctrl_params.mhi_timeout = CNSS_MHI_TIMEOUT_DEFAULT;
  3646. plat_priv->ctrl_params.mhi_m2_timeout = CNSS_MHI_M2_TIMEOUT_DEFAULT;
  3647. plat_priv->ctrl_params.qmi_timeout = CNSS_QMI_TIMEOUT_DEFAULT;
  3648. plat_priv->ctrl_params.bdf_type = CNSS_BDF_TYPE_DEFAULT;
  3649. plat_priv->ctrl_params.time_sync_period = CNSS_TIME_SYNC_PERIOD_DEFAULT;
  3650. /* Set adsp_pc_enabled default value to true as ADSP pc is always
  3651. * enabled by default
  3652. */
  3653. plat_priv->adsp_pc_enabled = true;
  3654. }
  3655. static void cnss_get_pm_domain_info(struct cnss_plat_data *plat_priv)
  3656. {
  3657. struct device *dev = &plat_priv->plat_dev->dev;
  3658. plat_priv->use_pm_domain =
  3659. of_property_read_bool(dev->of_node, "use-pm-domain");
  3660. cnss_pr_dbg("use-pm-domain is %d\n", plat_priv->use_pm_domain);
  3661. }
  3662. static void cnss_get_wlaon_pwr_ctrl_info(struct cnss_plat_data *plat_priv)
  3663. {
  3664. struct device *dev = &plat_priv->plat_dev->dev;
  3665. plat_priv->set_wlaon_pwr_ctrl =
  3666. of_property_read_bool(dev->of_node, "qcom,set-wlaon-pwr-ctrl");
  3667. cnss_pr_dbg("set_wlaon_pwr_ctrl is %d\n",
  3668. plat_priv->set_wlaon_pwr_ctrl);
  3669. }
  3670. static bool cnss_use_fw_path_with_prefix(struct cnss_plat_data *plat_priv)
  3671. {
  3672. return (of_property_read_bool(plat_priv->plat_dev->dev.of_node,
  3673. "qcom,converged-dt") ||
  3674. of_property_read_bool(plat_priv->plat_dev->dev.of_node,
  3675. "qcom,same-dt-multi-dev") ||
  3676. of_property_read_bool(plat_priv->plat_dev->dev.of_node,
  3677. "qcom,multi-wlan-exchg"));
  3678. }
  3679. static const struct platform_device_id cnss_platform_id_table[] = {
  3680. { .name = "qca6174", .driver_data = QCA6174_DEVICE_ID, },
  3681. { .name = "qca6290", .driver_data = QCA6290_DEVICE_ID, },
  3682. { .name = "qca6390", .driver_data = QCA6390_DEVICE_ID, },
  3683. { .name = "qca6490", .driver_data = QCA6490_DEVICE_ID, },
  3684. { .name = "kiwi", .driver_data = KIWI_DEVICE_ID, },
  3685. { .name = "mango", .driver_data = MANGO_DEVICE_ID, },
  3686. { .name = "peach", .driver_data = PEACH_DEVICE_ID, },
  3687. { .name = "qcaconv", .driver_data = 0, },
  3688. { },
  3689. };
  3690. static const struct of_device_id cnss_of_match_table[] = {
  3691. {
  3692. .compatible = "qcom,cnss",
  3693. .data = (void *)&cnss_platform_id_table[0]},
  3694. {
  3695. .compatible = "qcom,cnss-qca6290",
  3696. .data = (void *)&cnss_platform_id_table[1]},
  3697. {
  3698. .compatible = "qcom,cnss-qca6390",
  3699. .data = (void *)&cnss_platform_id_table[2]},
  3700. {
  3701. .compatible = "qcom,cnss-qca6490",
  3702. .data = (void *)&cnss_platform_id_table[3]},
  3703. {
  3704. .compatible = "qcom,cnss-kiwi",
  3705. .data = (void *)&cnss_platform_id_table[4]},
  3706. {
  3707. .compatible = "qcom,cnss-mango",
  3708. .data = (void *)&cnss_platform_id_table[5]},
  3709. {
  3710. .compatible = "qcom,cnss-peach",
  3711. .data = (void *)&cnss_platform_id_table[6]},
  3712. {
  3713. .compatible = "qcom,cnss-qca-converged",
  3714. .data = (void *)&cnss_platform_id_table[7]},
  3715. { },
  3716. };
  3717. MODULE_DEVICE_TABLE(of, cnss_of_match_table);
  3718. static inline bool
  3719. cnss_use_nv_mac(struct cnss_plat_data *plat_priv)
  3720. {
  3721. return of_property_read_bool(plat_priv->plat_dev->dev.of_node,
  3722. "use-nv-mac");
  3723. }
  3724. static int cnss_get_dev_cfg_node(struct cnss_plat_data *plat_priv)
  3725. {
  3726. struct device_node *child;
  3727. u32 id, i;
  3728. int id_n, device_identifier_gpio, ret;
  3729. u8 gpio_value;
  3730. if (plat_priv->dt_type != CNSS_DTT_CONVERGED)
  3731. return 0;
  3732. /* Parses the wlan_sw_ctrl gpio which is used to identify device */
  3733. ret = cnss_get_wlan_sw_ctrl(plat_priv);
  3734. if (ret) {
  3735. cnss_pr_dbg("Failed to parse wlan_sw_ctrl gpio, error:%d", ret);
  3736. return ret;
  3737. }
  3738. device_identifier_gpio = plat_priv->pinctrl_info.wlan_sw_ctrl_gpio;
  3739. gpio_value = gpio_get_value(device_identifier_gpio);
  3740. cnss_pr_dbg("Value of Device Identifier GPIO: %d\n", gpio_value);
  3741. for_each_available_child_of_node(plat_priv->plat_dev->dev.of_node,
  3742. child) {
  3743. if (strcmp(child->name, "chip_cfg"))
  3744. continue;
  3745. id_n = of_property_count_u32_elems(child, "supported-ids");
  3746. if (id_n <= 0) {
  3747. cnss_pr_err("Device id is NOT set\n");
  3748. return -EINVAL;
  3749. }
  3750. for (i = 0; i < id_n; i++) {
  3751. ret = of_property_read_u32_index(child,
  3752. "supported-ids",
  3753. i, &id);
  3754. if (ret) {
  3755. cnss_pr_err("Failed to read supported ids\n");
  3756. return -EINVAL;
  3757. }
  3758. if (gpio_value && id == QCA6490_DEVICE_ID) {
  3759. plat_priv->plat_dev->dev.of_node = child;
  3760. plat_priv->device_id = QCA6490_DEVICE_ID;
  3761. cnss_utils_update_device_type(CNSS_HSP_DEVICE_TYPE);
  3762. cnss_pr_dbg("got node[%s@%d] for device[0x%x]\n",
  3763. child->name, i, id);
  3764. return 0;
  3765. } else if (!gpio_value && id == KIWI_DEVICE_ID) {
  3766. plat_priv->plat_dev->dev.of_node = child;
  3767. plat_priv->device_id = KIWI_DEVICE_ID;
  3768. cnss_utils_update_device_type(CNSS_HMT_DEVICE_TYPE);
  3769. cnss_pr_dbg("got node[%s@%d] for device[0x%x]\n",
  3770. child->name, i, id);
  3771. return 0;
  3772. }
  3773. }
  3774. }
  3775. return -EINVAL;
  3776. }
  3777. static inline u32
  3778. cnss_dt_type(struct cnss_plat_data *plat_priv)
  3779. {
  3780. bool is_converged_dt = of_property_read_bool(
  3781. plat_priv->plat_dev->dev.of_node, "qcom,converged-dt");
  3782. bool is_multi_wlan_xchg;
  3783. if (is_converged_dt)
  3784. return CNSS_DTT_CONVERGED;
  3785. is_multi_wlan_xchg = of_property_read_bool(
  3786. plat_priv->plat_dev->dev.of_node, "qcom,multi-wlan-exchg");
  3787. if (is_multi_wlan_xchg)
  3788. return CNSS_DTT_MULTIEXCHG;
  3789. return CNSS_DTT_LEGACY;
  3790. }
  3791. static int cnss_wlan_device_init(struct cnss_plat_data *plat_priv)
  3792. {
  3793. int ret = 0;
  3794. int retry = 0;
  3795. if (test_bit(SKIP_DEVICE_BOOT, &plat_priv->ctrl_params.quirks))
  3796. return 0;
  3797. retry:
  3798. ret = cnss_power_on_device(plat_priv, true);
  3799. if (ret)
  3800. goto end;
  3801. ret = cnss_bus_init(plat_priv);
  3802. if (ret) {
  3803. if ((ret != -EPROBE_DEFER) &&
  3804. retry++ < POWER_ON_RETRY_MAX_TIMES) {
  3805. cnss_power_off_device(plat_priv);
  3806. cnss_pr_dbg("Retry cnss_bus_init #%d\n", retry);
  3807. msleep(POWER_ON_RETRY_DELAY_MS * retry);
  3808. goto retry;
  3809. }
  3810. goto power_off;
  3811. }
  3812. return 0;
  3813. power_off:
  3814. cnss_power_off_device(plat_priv);
  3815. end:
  3816. return ret;
  3817. }
  3818. int cnss_wlan_hw_enable(void)
  3819. {
  3820. struct cnss_plat_data *plat_priv;
  3821. int ret = 0;
  3822. if (cnss_is_dual_wlan_enabled())
  3823. plat_priv = cnss_get_first_plat_priv(NULL);
  3824. else
  3825. plat_priv = cnss_get_plat_priv(NULL);
  3826. if (!plat_priv)
  3827. return -ENODEV;
  3828. clear_bit(CNSS_WLAN_HW_DISABLED, &plat_priv->driver_state);
  3829. if (test_bit(CNSS_PCI_PROBE_DONE, &plat_priv->driver_state))
  3830. goto register_driver;
  3831. ret = cnss_wlan_device_init(plat_priv);
  3832. if (ret) {
  3833. if (!test_bit(CNSS_WLAN_HW_DISABLED, &plat_priv->driver_state))
  3834. CNSS_ASSERT(0);
  3835. return ret;
  3836. }
  3837. if (test_bit(CNSS_FS_READY, &plat_priv->driver_state))
  3838. cnss_driver_event_post(plat_priv,
  3839. CNSS_DRIVER_EVENT_COLD_BOOT_CAL_START,
  3840. 0, NULL);
  3841. register_driver:
  3842. if (plat_priv->driver_ops)
  3843. ret = cnss_wlan_register_driver(plat_priv->driver_ops);
  3844. return ret;
  3845. }
  3846. EXPORT_SYMBOL(cnss_wlan_hw_enable);
  3847. int cnss_set_wfc_mode(struct device *dev, struct cnss_wfc_cfg cfg)
  3848. {
  3849. struct cnss_plat_data *plat_priv = cnss_bus_dev_to_plat_priv(dev);
  3850. int ret = 0;
  3851. if (!plat_priv)
  3852. return -ENODEV;
  3853. /* If IMS server is connected, return success without QMI send */
  3854. if (test_bit(CNSS_IMS_CONNECTED, &plat_priv->driver_state)) {
  3855. cnss_pr_dbg("Ignore host request as IMS server is connected");
  3856. return ret;
  3857. }
  3858. ret = cnss_wlfw_send_host_wfc_call_status(plat_priv, cfg);
  3859. return ret;
  3860. }
  3861. EXPORT_SYMBOL(cnss_set_wfc_mode);
  3862. static int cnss_tcdev_get_max_state(struct thermal_cooling_device *tcdev,
  3863. unsigned long *thermal_state)
  3864. {
  3865. struct cnss_thermal_cdev *cnss_tcdev = NULL;
  3866. if (!tcdev || !tcdev->devdata) {
  3867. cnss_pr_err("tcdev or tcdev->devdata is null!\n");
  3868. return -EINVAL;
  3869. }
  3870. cnss_tcdev = tcdev->devdata;
  3871. *thermal_state = cnss_tcdev->max_thermal_state;
  3872. return 0;
  3873. }
  3874. static int cnss_tcdev_get_cur_state(struct thermal_cooling_device *tcdev,
  3875. unsigned long *thermal_state)
  3876. {
  3877. struct cnss_thermal_cdev *cnss_tcdev = NULL;
  3878. if (!tcdev || !tcdev->devdata) {
  3879. cnss_pr_err("tcdev or tcdev->devdata is null!\n");
  3880. return -EINVAL;
  3881. }
  3882. cnss_tcdev = tcdev->devdata;
  3883. *thermal_state = cnss_tcdev->curr_thermal_state;
  3884. return 0;
  3885. }
  3886. static int cnss_tcdev_set_cur_state(struct thermal_cooling_device *tcdev,
  3887. unsigned long thermal_state)
  3888. {
  3889. struct cnss_thermal_cdev *cnss_tcdev = NULL;
  3890. struct cnss_plat_data *plat_priv = cnss_get_plat_priv(NULL);
  3891. int ret = 0;
  3892. if (!tcdev || !tcdev->devdata) {
  3893. cnss_pr_err("tcdev or tcdev->devdata is null!\n");
  3894. return -EINVAL;
  3895. }
  3896. cnss_tcdev = tcdev->devdata;
  3897. if (thermal_state > cnss_tcdev->max_thermal_state)
  3898. return -EINVAL;
  3899. cnss_pr_vdbg("Cooling device set current state: %ld,for cdev id %d",
  3900. thermal_state, cnss_tcdev->tcdev_id);
  3901. mutex_lock(&plat_priv->tcdev_lock);
  3902. ret = cnss_bus_set_therm_cdev_state(plat_priv,
  3903. thermal_state,
  3904. cnss_tcdev->tcdev_id);
  3905. if (!ret)
  3906. cnss_tcdev->curr_thermal_state = thermal_state;
  3907. mutex_unlock(&plat_priv->tcdev_lock);
  3908. if (ret) {
  3909. cnss_pr_err("Setting Current Thermal State Failed: %d,for cdev id %d",
  3910. ret, cnss_tcdev->tcdev_id);
  3911. return ret;
  3912. }
  3913. return 0;
  3914. }
  3915. static struct thermal_cooling_device_ops cnss_cooling_ops = {
  3916. .get_max_state = cnss_tcdev_get_max_state,
  3917. .get_cur_state = cnss_tcdev_get_cur_state,
  3918. .set_cur_state = cnss_tcdev_set_cur_state,
  3919. };
  3920. int cnss_thermal_cdev_register(struct device *dev, unsigned long max_state,
  3921. int tcdev_id)
  3922. {
  3923. struct cnss_plat_data *priv = cnss_get_plat_priv(NULL);
  3924. struct cnss_thermal_cdev *cnss_tcdev = NULL;
  3925. char cdev_node_name[THERMAL_NAME_LENGTH] = "";
  3926. struct device_node *dev_node;
  3927. int ret = 0;
  3928. if (!priv) {
  3929. cnss_pr_err("Platform driver is not initialized!\n");
  3930. return -ENODEV;
  3931. }
  3932. cnss_tcdev = kzalloc(sizeof(*cnss_tcdev), GFP_KERNEL);
  3933. if (!cnss_tcdev) {
  3934. cnss_pr_err("Failed to allocate cnss_tcdev object!\n");
  3935. return -ENOMEM;
  3936. }
  3937. cnss_tcdev->tcdev_id = tcdev_id;
  3938. cnss_tcdev->max_thermal_state = max_state;
  3939. snprintf(cdev_node_name, THERMAL_NAME_LENGTH,
  3940. "qcom,cnss_cdev%d", tcdev_id);
  3941. dev_node = of_find_node_by_name(NULL, cdev_node_name);
  3942. if (!dev_node) {
  3943. cnss_pr_err("Failed to get cooling device node\n");
  3944. kfree(cnss_tcdev);
  3945. return -EINVAL;
  3946. }
  3947. cnss_pr_dbg("tcdev node->name=%s\n", dev_node->name);
  3948. if (of_find_property(dev_node, "#cooling-cells", NULL)) {
  3949. cnss_tcdev->tcdev = thermal_of_cooling_device_register(dev_node,
  3950. cdev_node_name,
  3951. cnss_tcdev,
  3952. &cnss_cooling_ops);
  3953. if (IS_ERR_OR_NULL(cnss_tcdev->tcdev)) {
  3954. ret = PTR_ERR(cnss_tcdev->tcdev);
  3955. cnss_pr_err("Cooling device register failed: %d, for cdev id %d\n",
  3956. ret, cnss_tcdev->tcdev_id);
  3957. kfree(cnss_tcdev);
  3958. } else {
  3959. cnss_pr_dbg("Cooling device registered for cdev id %d",
  3960. cnss_tcdev->tcdev_id);
  3961. mutex_lock(&priv->tcdev_lock);
  3962. list_add(&cnss_tcdev->tcdev_list,
  3963. &priv->cnss_tcdev_list);
  3964. mutex_unlock(&priv->tcdev_lock);
  3965. }
  3966. } else {
  3967. cnss_pr_dbg("Cooling device registration not supported");
  3968. kfree(cnss_tcdev);
  3969. ret = -EOPNOTSUPP;
  3970. }
  3971. return ret;
  3972. }
  3973. EXPORT_SYMBOL(cnss_thermal_cdev_register);
  3974. void cnss_thermal_cdev_unregister(struct device *dev, int tcdev_id)
  3975. {
  3976. struct cnss_plat_data *priv = cnss_get_plat_priv(NULL);
  3977. struct cnss_thermal_cdev *cnss_tcdev = NULL;
  3978. if (!priv) {
  3979. cnss_pr_err("Platform driver is not initialized!\n");
  3980. return;
  3981. }
  3982. mutex_lock(&priv->tcdev_lock);
  3983. while (!list_empty(&priv->cnss_tcdev_list)) {
  3984. cnss_tcdev = list_first_entry(&priv->cnss_tcdev_list,
  3985. struct cnss_thermal_cdev,
  3986. tcdev_list);
  3987. thermal_cooling_device_unregister(cnss_tcdev->tcdev);
  3988. list_del(&cnss_tcdev->tcdev_list);
  3989. kfree(cnss_tcdev);
  3990. }
  3991. mutex_unlock(&priv->tcdev_lock);
  3992. }
  3993. EXPORT_SYMBOL(cnss_thermal_cdev_unregister);
  3994. int cnss_get_curr_therm_cdev_state(struct device *dev,
  3995. unsigned long *thermal_state,
  3996. int tcdev_id)
  3997. {
  3998. struct cnss_plat_data *priv = cnss_get_plat_priv(NULL);
  3999. struct cnss_thermal_cdev *cnss_tcdev = NULL;
  4000. if (!priv) {
  4001. cnss_pr_err("Platform driver is not initialized!\n");
  4002. return -ENODEV;
  4003. }
  4004. mutex_lock(&priv->tcdev_lock);
  4005. list_for_each_entry(cnss_tcdev, &priv->cnss_tcdev_list, tcdev_list) {
  4006. if (cnss_tcdev->tcdev_id != tcdev_id)
  4007. continue;
  4008. *thermal_state = cnss_tcdev->curr_thermal_state;
  4009. mutex_unlock(&priv->tcdev_lock);
  4010. cnss_pr_dbg("Cooling device current state: %ld, for cdev id %d",
  4011. cnss_tcdev->curr_thermal_state, tcdev_id);
  4012. return 0;
  4013. }
  4014. mutex_unlock(&priv->tcdev_lock);
  4015. cnss_pr_dbg("Cooling device ID not found: %d", tcdev_id);
  4016. return -EINVAL;
  4017. }
  4018. EXPORT_SYMBOL(cnss_get_curr_therm_cdev_state);
  4019. static int cnss_probe(struct platform_device *plat_dev)
  4020. {
  4021. int ret = 0;
  4022. struct cnss_plat_data *plat_priv;
  4023. const struct of_device_id *of_id;
  4024. const struct platform_device_id *device_id;
  4025. if (cnss_get_plat_priv(plat_dev)) {
  4026. cnss_pr_err("Driver is already initialized!\n");
  4027. ret = -EEXIST;
  4028. goto out;
  4029. }
  4030. ret = cnss_plat_env_available();
  4031. if (ret)
  4032. goto out;
  4033. of_id = of_match_device(cnss_of_match_table, &plat_dev->dev);
  4034. if (!of_id || !of_id->data) {
  4035. cnss_pr_err("Failed to find of match device!\n");
  4036. ret = -ENODEV;
  4037. goto out;
  4038. }
  4039. device_id = of_id->data;
  4040. plat_priv = devm_kzalloc(&plat_dev->dev, sizeof(*plat_priv),
  4041. GFP_KERNEL);
  4042. if (!plat_priv) {
  4043. ret = -ENOMEM;
  4044. goto out;
  4045. }
  4046. plat_priv->plat_dev = plat_dev;
  4047. plat_priv->dev_node = NULL;
  4048. plat_priv->device_id = device_id->driver_data;
  4049. plat_priv->dt_type = cnss_dt_type(plat_priv);
  4050. cnss_pr_dbg("Probing platform driver from dt type: %d\n",
  4051. plat_priv->dt_type);
  4052. plat_priv->use_fw_path_with_prefix =
  4053. cnss_use_fw_path_with_prefix(plat_priv);
  4054. ret = cnss_get_dev_cfg_node(plat_priv);
  4055. if (ret) {
  4056. cnss_pr_err("Failed to get device cfg node, err = %d\n", ret);
  4057. goto reset_plat_dev;
  4058. }
  4059. ret = cnss_get_pld_bus_ops_name(plat_priv);
  4060. if (ret)
  4061. cnss_pr_err("Failed to find bus ops name, err = %d\n",
  4062. ret);
  4063. ret = cnss_get_rc_num(plat_priv);
  4064. if (ret)
  4065. cnss_pr_err("Failed to find PCIe RC number, err = %d\n", ret);
  4066. cnss_pr_dbg("rc_num=%d\n", plat_priv->rc_num);
  4067. plat_priv->bus_type = cnss_get_bus_type(plat_priv);
  4068. plat_priv->use_nv_mac = cnss_use_nv_mac(plat_priv);
  4069. plat_priv->driver_mode = CNSS_DRIVER_MODE_MAX;
  4070. cnss_set_plat_priv(plat_dev, plat_priv);
  4071. cnss_set_device_name(plat_priv);
  4072. platform_set_drvdata(plat_dev, plat_priv);
  4073. INIT_LIST_HEAD(&plat_priv->vreg_list);
  4074. INIT_LIST_HEAD(&plat_priv->clk_list);
  4075. cnss_get_pm_domain_info(plat_priv);
  4076. cnss_get_wlaon_pwr_ctrl_info(plat_priv);
  4077. cnss_power_misc_params_init(plat_priv);
  4078. cnss_get_tcs_info(plat_priv);
  4079. cnss_get_cpr_info(plat_priv);
  4080. cnss_aop_mbox_init(plat_priv);
  4081. cnss_init_control_params(plat_priv);
  4082. ret = cnss_get_resources(plat_priv);
  4083. if (ret)
  4084. goto reset_ctx;
  4085. ret = cnss_register_esoc(plat_priv);
  4086. if (ret)
  4087. goto free_res;
  4088. ret = cnss_register_bus_scale(plat_priv);
  4089. if (ret)
  4090. goto unreg_esoc;
  4091. ret = cnss_create_sysfs(plat_priv);
  4092. if (ret)
  4093. goto unreg_bus_scale;
  4094. ret = cnss_event_work_init(plat_priv);
  4095. if (ret)
  4096. goto remove_sysfs;
  4097. ret = cnss_dms_init(plat_priv);
  4098. if (ret)
  4099. goto deinit_event_work;
  4100. ret = cnss_debugfs_create(plat_priv);
  4101. if (ret)
  4102. goto deinit_dms;
  4103. ret = cnss_misc_init(plat_priv);
  4104. if (ret)
  4105. goto destroy_debugfs;
  4106. ret = cnss_wlan_hw_disable_check(plat_priv);
  4107. if (ret)
  4108. goto deinit_misc;
  4109. /* Make sure all platform related init are done before
  4110. * device power on and bus init.
  4111. */
  4112. if (!test_bit(CNSS_WLAN_HW_DISABLED, &plat_priv->driver_state)) {
  4113. ret = cnss_wlan_device_init(plat_priv);
  4114. if (ret)
  4115. goto deinit_misc;
  4116. } else {
  4117. cnss_pr_info("WLAN HW Disabled. Defer PCI enumeration\n");
  4118. }
  4119. cnss_register_coex_service(plat_priv);
  4120. cnss_register_ims_service(plat_priv);
  4121. mutex_init(&plat_priv->tcdev_lock);
  4122. INIT_LIST_HEAD(&plat_priv->cnss_tcdev_list);
  4123. cnss_pr_info("Platform driver probed successfully.\n");
  4124. return 0;
  4125. deinit_misc:
  4126. cnss_misc_deinit(plat_priv);
  4127. destroy_debugfs:
  4128. cnss_debugfs_destroy(plat_priv);
  4129. deinit_dms:
  4130. cnss_dms_deinit(plat_priv);
  4131. deinit_event_work:
  4132. cnss_event_work_deinit(plat_priv);
  4133. remove_sysfs:
  4134. cnss_remove_sysfs(plat_priv);
  4135. unreg_bus_scale:
  4136. cnss_unregister_bus_scale(plat_priv);
  4137. unreg_esoc:
  4138. cnss_unregister_esoc(plat_priv);
  4139. free_res:
  4140. cnss_put_resources(plat_priv);
  4141. reset_ctx:
  4142. platform_set_drvdata(plat_dev, NULL);
  4143. reset_plat_dev:
  4144. cnss_clear_plat_priv(plat_priv);
  4145. out:
  4146. return ret;
  4147. }
  4148. static int cnss_remove(struct platform_device *plat_dev)
  4149. {
  4150. struct cnss_plat_data *plat_priv = platform_get_drvdata(plat_dev);
  4151. plat_priv->audio_iommu_domain = NULL;
  4152. cnss_genl_exit();
  4153. cnss_unregister_ims_service(plat_priv);
  4154. cnss_unregister_coex_service(plat_priv);
  4155. cnss_bus_deinit(plat_priv);
  4156. cnss_misc_deinit(plat_priv);
  4157. cnss_debugfs_destroy(plat_priv);
  4158. cnss_dms_deinit(plat_priv);
  4159. cnss_qmi_deinit(plat_priv);
  4160. cnss_event_work_deinit(plat_priv);
  4161. cnss_cancel_dms_work();
  4162. cnss_remove_sysfs(plat_priv);
  4163. cnss_unregister_bus_scale(plat_priv);
  4164. cnss_unregister_esoc(plat_priv);
  4165. cnss_put_resources(plat_priv);
  4166. if (!IS_ERR_OR_NULL(plat_priv->mbox_chan))
  4167. mbox_free_channel(plat_priv->mbox_chan);
  4168. platform_set_drvdata(plat_dev, NULL);
  4169. cnss_clear_plat_priv(plat_priv);
  4170. return 0;
  4171. }
  4172. static struct platform_driver cnss_platform_driver = {
  4173. .probe = cnss_probe,
  4174. .remove = cnss_remove,
  4175. .driver = {
  4176. .name = "cnss2",
  4177. .of_match_table = cnss_of_match_table,
  4178. #ifdef CONFIG_CNSS_ASYNC
  4179. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  4180. #endif
  4181. },
  4182. };
  4183. static bool cnss_check_compatible_node(void)
  4184. {
  4185. struct device_node *dn = NULL;
  4186. for_each_matching_node(dn, cnss_of_match_table) {
  4187. if (of_device_is_available(dn)) {
  4188. cnss_allow_driver_loading = true;
  4189. return true;
  4190. }
  4191. }
  4192. return false;
  4193. }
  4194. /**
  4195. * cnss_is_valid_dt_node_found - Check if valid device tree node present
  4196. *
  4197. * Valid device tree node means a node with "compatible" property from the
  4198. * device match table and "status" property is not disabled.
  4199. *
  4200. * Return: true if valid device tree node found, false if not found
  4201. */
  4202. static bool cnss_is_valid_dt_node_found(void)
  4203. {
  4204. struct device_node *dn = NULL;
  4205. for_each_matching_node(dn, cnss_of_match_table) {
  4206. if (of_device_is_available(dn))
  4207. break;
  4208. }
  4209. if (dn)
  4210. return true;
  4211. return false;
  4212. }
  4213. static int __init cnss_initialize(void)
  4214. {
  4215. int ret = 0;
  4216. if (!cnss_is_valid_dt_node_found())
  4217. return -ENODEV;
  4218. if (!cnss_check_compatible_node())
  4219. return ret;
  4220. cnss_debug_init();
  4221. ret = platform_driver_register(&cnss_platform_driver);
  4222. if (ret)
  4223. cnss_debug_deinit();
  4224. ret = cnss_genl_init();
  4225. if (ret < 0)
  4226. cnss_pr_err("CNSS genl init failed %d\n", ret);
  4227. return ret;
  4228. }
  4229. static void __exit cnss_exit(void)
  4230. {
  4231. cnss_genl_exit();
  4232. platform_driver_unregister(&cnss_platform_driver);
  4233. cnss_debug_deinit();
  4234. }
  4235. module_init(cnss_initialize);
  4236. module_exit(cnss_exit);
  4237. MODULE_LICENSE("GPL v2");
  4238. MODULE_DESCRIPTION("CNSS2 Platform Driver");