main.c 129 KB

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