main.c 128 KB

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