main.c 116 KB

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