main.c 127 KB

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