main.c 128 KB

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