main.c 117 KB

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