qmi.c 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #define pr_fmt(fmt) "icnss2_qmi: " fmt
  7. #include <linux/export.h>
  8. #include <linux/err.h>
  9. #include <linux/of.h>
  10. #include <linux/init.h>
  11. #include <linux/io.h>
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/etherdevice.h>
  15. #include <linux/seq_file.h>
  16. #include <linux/slab.h>
  17. #include <linux/delay.h>
  18. #include <linux/ipc_logging.h>
  19. #include <linux/thread_info.h>
  20. #include <linux/firmware.h>
  21. #include <linux/soc/qcom/qmi.h>
  22. #include <linux/platform_device.h>
  23. #ifdef CONFIG_CNSS_OUT_OF_TREE
  24. #include "icnss2.h"
  25. #else
  26. #include <soc/qcom/icnss2.h>
  27. #endif
  28. #include <soc/qcom/of_common.h>
  29. #include "wlan_firmware_service_v01.h"
  30. #include "main.h"
  31. #include "qmi.h"
  32. #include "debug.h"
  33. #include "genl.h"
  34. #define WLFW_SERVICE_WCN_INS_ID_V01 3
  35. #define WLFW_SERVICE_INS_ID_V01 0
  36. #define WLFW_CLIENT_ID 0x4b4e454c
  37. #define QMI_ERR_PLAT_CCPM_CLK_INIT_FAILED 0x77
  38. #define BDF_FILE_NAME_PREFIX "bdwlan"
  39. #define ELF_BDF_FILE_NAME "bdwlan.elf"
  40. #define ELF_BDF_FILE_NAME_PREFIX "bdwlan.e"
  41. #define BIN_BDF_FILE_NAME "bdwlan.bin"
  42. #define BIN_BDF_FILE_NAME_PREFIX "bdwlan."
  43. #define REGDB_FILE_NAME "regdb.bin"
  44. #define QDSS_TRACE_CONFIG_FILE "qdss_trace_config.cfg"
  45. #define WLAN_BOARD_ID_INDEX 0x100
  46. #define DEVICE_BAR_SIZE 0x200000
  47. #define M3_SEGMENT_ADDR_MASK 0xFFFFFFFF
  48. #define DMS_QMI_MAX_MSG_LEN SZ_256
  49. #define DMS_MAC_NOT_PROVISIONED 16
  50. #define BDWLAN_SIZE 6
  51. #define UMC_CHIP_ID 0x4320
  52. #define MAX_SHADOW_REG_RESERVED 2
  53. #define MAX_NUM_SHADOW_REG_V3 (QMI_WLFW_MAX_NUM_SHADOW_REG_V3_USAGE_V01 - \
  54. MAX_SHADOW_REG_RESERVED)
  55. #define IMSPRIVATE_SERVICE_MAX_MSG_LEN SZ_8K
  56. #ifdef CONFIG_ICNSS2_DEBUG
  57. bool ignore_fw_timeout;
  58. #define ICNSS_QMI_ASSERT() ICNSS_ASSERT(ignore_fw_timeout)
  59. #else
  60. #define ICNSS_QMI_ASSERT() do { } while (0)
  61. #endif
  62. #ifdef CONFIG_ICNSS2_DEBUG
  63. void icnss_ignore_fw_timeout(bool ignore)
  64. {
  65. ignore_fw_timeout = ignore;
  66. }
  67. #else
  68. void icnss_ignore_fw_timeout(bool ignore) { }
  69. #endif
  70. #define icnss_qmi_fatal_err(_fmt, ...) do { \
  71. icnss_pr_err("fatal: "_fmt, ##__VA_ARGS__); \
  72. ICNSS_QMI_ASSERT(); \
  73. } while (0)
  74. int wlfw_msa_mem_info_send_sync_msg(struct icnss_priv *priv)
  75. {
  76. int ret;
  77. int i;
  78. struct wlfw_msa_info_req_msg_v01 *req;
  79. struct wlfw_msa_info_resp_msg_v01 *resp;
  80. struct qmi_txn txn;
  81. uint64_t max_mapped_addr;
  82. if (!priv)
  83. return -ENODEV;
  84. icnss_pr_dbg("Sending MSA mem info, state: 0x%lx\n", priv->state);
  85. req = kzalloc(sizeof(*req), GFP_KERNEL);
  86. if (!req)
  87. return -ENOMEM;
  88. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  89. if (!resp) {
  90. kfree(req);
  91. return -ENOMEM;
  92. }
  93. req->msa_addr = priv->msa_pa;
  94. req->size = priv->msa_mem_size;
  95. priv->stats.msa_info_req++;
  96. ret = qmi_txn_init(&priv->qmi, &txn,
  97. wlfw_msa_info_resp_msg_v01_ei, resp);
  98. if (ret < 0) {
  99. icnss_qmi_fatal_err(
  100. "Fail to init txn for MSA Mem info resp %d\n",
  101. ret);
  102. goto out;
  103. }
  104. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  105. QMI_WLFW_MSA_INFO_REQ_V01,
  106. WLFW_MSA_INFO_REQ_MSG_V01_MAX_MSG_LEN,
  107. wlfw_msa_info_req_msg_v01_ei, req);
  108. if (ret < 0) {
  109. qmi_txn_cancel(&txn);
  110. icnss_qmi_fatal_err("Fail to send MSA Mem info req %d\n", ret);
  111. goto out;
  112. }
  113. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  114. if (ret < 0) {
  115. icnss_qmi_fatal_err("MSA Mem info resp wait failed ret %d\n",
  116. ret);
  117. goto out;
  118. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  119. icnss_qmi_fatal_err(
  120. "QMI MSA Mem info request rejected, result:%d error:%d\n",
  121. resp->resp.result, resp->resp.error);
  122. ret = -resp->resp.result;
  123. goto out;
  124. }
  125. icnss_pr_dbg("Receive mem_region_info_len: %d\n",
  126. resp->mem_region_info_len);
  127. if (resp->mem_region_info_len > QMI_WLFW_MAX_NUM_MEMORY_REGIONS_V01) {
  128. icnss_qmi_fatal_err(
  129. "Invalid memory region length received: %d\n",
  130. resp->mem_region_info_len);
  131. ret = -EINVAL;
  132. goto out;
  133. }
  134. max_mapped_addr = priv->msa_pa + priv->msa_mem_size;
  135. priv->stats.msa_info_resp++;
  136. priv->nr_mem_region = resp->mem_region_info_len;
  137. for (i = 0; i < resp->mem_region_info_len; i++) {
  138. if (resp->mem_region_info[i].size > priv->msa_mem_size ||
  139. resp->mem_region_info[i].region_addr >= max_mapped_addr ||
  140. resp->mem_region_info[i].region_addr < priv->msa_pa ||
  141. resp->mem_region_info[i].size +
  142. resp->mem_region_info[i].region_addr > max_mapped_addr) {
  143. icnss_pr_dbg("Received out of range Addr: 0x%llx Size: 0x%x\n",
  144. resp->mem_region_info[i].region_addr,
  145. resp->mem_region_info[i].size);
  146. ret = -EINVAL;
  147. goto fail_unwind;
  148. }
  149. priv->mem_region[i].reg_addr =
  150. resp->mem_region_info[i].region_addr;
  151. priv->mem_region[i].size =
  152. resp->mem_region_info[i].size;
  153. priv->mem_region[i].secure_flag =
  154. resp->mem_region_info[i].secure_flag;
  155. icnss_pr_dbg("Memory Region: %d Addr: 0x%llx Size: 0x%x Flag: 0x%08x\n",
  156. i, priv->mem_region[i].reg_addr,
  157. priv->mem_region[i].size,
  158. priv->mem_region[i].secure_flag);
  159. }
  160. kfree(resp);
  161. kfree(req);
  162. return 0;
  163. fail_unwind:
  164. memset(&priv->mem_region[0], 0, sizeof(priv->mem_region[0]) * i);
  165. out:
  166. kfree(resp);
  167. kfree(req);
  168. priv->stats.msa_info_err++;
  169. return ret;
  170. }
  171. int wlfw_msa_ready_send_sync_msg(struct icnss_priv *priv)
  172. {
  173. int ret;
  174. struct wlfw_msa_ready_req_msg_v01 *req;
  175. struct wlfw_msa_ready_resp_msg_v01 *resp;
  176. struct qmi_txn txn;
  177. if (!priv)
  178. return -ENODEV;
  179. icnss_pr_dbg("Sending MSA ready request message, state: 0x%lx\n",
  180. priv->state);
  181. req = kzalloc(sizeof(*req), GFP_KERNEL);
  182. if (!req)
  183. return -ENOMEM;
  184. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  185. if (!resp) {
  186. kfree(req);
  187. return -ENOMEM;
  188. }
  189. priv->stats.msa_ready_req++;
  190. ret = qmi_txn_init(&priv->qmi, &txn,
  191. wlfw_msa_ready_resp_msg_v01_ei, resp);
  192. if (ret < 0) {
  193. icnss_qmi_fatal_err(
  194. "Fail to init txn for MSA Mem Ready resp %d\n",
  195. ret);
  196. goto out;
  197. }
  198. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  199. QMI_WLFW_MSA_READY_REQ_V01,
  200. WLFW_MSA_READY_REQ_MSG_V01_MAX_MSG_LEN,
  201. wlfw_msa_ready_req_msg_v01_ei, req);
  202. if (ret < 0) {
  203. qmi_txn_cancel(&txn);
  204. icnss_qmi_fatal_err("Fail to send MSA Mem Ready req %d\n", ret);
  205. goto out;
  206. }
  207. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  208. if (ret < 0) {
  209. icnss_qmi_fatal_err(
  210. "MSA Mem Ready resp wait failed with ret %d\n",
  211. ret);
  212. goto out;
  213. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  214. icnss_qmi_fatal_err(
  215. "QMI MSA Mem Ready request rejected, result:%d error:%d\n",
  216. resp->resp.result, resp->resp.error);
  217. ret = -resp->resp.result;
  218. goto out;
  219. }
  220. priv->stats.msa_ready_resp++;
  221. kfree(resp);
  222. kfree(req);
  223. return 0;
  224. out:
  225. kfree(resp);
  226. kfree(req);
  227. priv->stats.msa_ready_err++;
  228. return ret;
  229. }
  230. int wlfw_device_info_send_msg(struct icnss_priv *priv)
  231. {
  232. int ret;
  233. struct wlfw_device_info_req_msg_v01 *req;
  234. struct wlfw_device_info_resp_msg_v01 *resp;
  235. struct qmi_txn txn;
  236. if (!priv)
  237. return -ENODEV;
  238. icnss_pr_dbg("Sending Device Info request message, state: 0x%lx\n",
  239. priv->state);
  240. req = kzalloc(sizeof(*req), GFP_KERNEL);
  241. if (!req)
  242. return -ENOMEM;
  243. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  244. if (!resp) {
  245. kfree(req);
  246. return -ENOMEM;
  247. }
  248. priv->stats.device_info_req++;
  249. ret = qmi_txn_init(&priv->qmi, &txn,
  250. wlfw_device_info_resp_msg_v01_ei, resp);
  251. if (ret < 0) {
  252. icnss_qmi_fatal_err(
  253. "Fail to init txn for Device Info resp %d\n",
  254. ret);
  255. goto out;
  256. }
  257. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  258. QMI_WLFW_DEVICE_INFO_REQ_V01,
  259. WLFW_DEVICE_INFO_REQ_MSG_V01_MAX_MSG_LEN,
  260. wlfw_device_info_req_msg_v01_ei, req);
  261. if (ret < 0) {
  262. qmi_txn_cancel(&txn);
  263. icnss_qmi_fatal_err("Fail to send device info req %d\n", ret);
  264. goto out;
  265. }
  266. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  267. if (ret < 0) {
  268. icnss_qmi_fatal_err(
  269. "Device Info resp wait failed with ret %d\n",
  270. ret);
  271. goto out;
  272. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  273. icnss_qmi_fatal_err(
  274. "QMI Device info request rejected, result:%d error:%d\n",
  275. resp->resp.result, resp->resp.error);
  276. ret = -resp->resp.result;
  277. goto out;
  278. }
  279. priv->stats.device_info_resp++;
  280. if (resp->bar_addr_valid)
  281. priv->mem_base_pa = resp->bar_addr;
  282. if (resp->bar_size_valid)
  283. priv->mem_base_size = resp->bar_size;
  284. if (!priv->mem_base_pa) {
  285. ret = -EINVAL;
  286. icnss_qmi_fatal_err("Fail to get bar address\n");
  287. goto out;
  288. }
  289. if (priv->mem_base_size < DEVICE_BAR_SIZE) {
  290. ret = -EINVAL;
  291. icnss_qmi_fatal_err("Bar size is not proper 0x%x\n",
  292. priv->mem_base_size);
  293. goto out;
  294. }
  295. if (resp->mhi_state_info_addr_valid)
  296. priv->mhi_state_info_pa = resp->mhi_state_info_addr;
  297. if (resp->mhi_state_info_size_valid)
  298. priv->mhi_state_info_size = resp->mhi_state_info_size;
  299. if (!priv->mhi_state_info_pa)
  300. icnss_pr_err("Fail to get MHI info address\n");
  301. kfree(resp);
  302. kfree(req);
  303. return 0;
  304. out:
  305. kfree(resp);
  306. kfree(req);
  307. priv->stats.device_info_err++;
  308. return ret;
  309. }
  310. int wlfw_power_save_send_msg(struct icnss_priv *priv,
  311. enum wlfw_power_save_mode_v01 mode)
  312. {
  313. int ret;
  314. struct wlfw_power_save_req_msg_v01 *req;
  315. struct qmi_txn txn;
  316. if (!priv)
  317. return -ENODEV;
  318. if (test_bit(ICNSS_FW_DOWN, &priv->state))
  319. return -EINVAL;
  320. if (test_bit(ICNSS_PD_RESTART, &priv->state) ||
  321. !test_bit(ICNSS_MODE_ON, &priv->state))
  322. return 0;
  323. icnss_pr_dbg("Sending power save mode: %d, state: 0x%lx\n",
  324. mode, priv->state);
  325. req = kzalloc(sizeof(*req), GFP_KERNEL);
  326. if (!req)
  327. return -ENOMEM;
  328. req->power_save_mode_valid = 1;
  329. req->power_save_mode = mode;
  330. if (mode == WLFW_POWER_SAVE_EXIT_V01)
  331. priv->stats.exit_power_save_req++;
  332. else
  333. priv->stats.enter_power_save_req++;
  334. ret = qmi_txn_init(&priv->qmi, &txn,
  335. NULL, NULL);
  336. if (ret < 0) {
  337. icnss_qmi_fatal_err("Fail to init txn for exit power save%d\n",
  338. ret);
  339. goto out;
  340. }
  341. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  342. QMI_WLFW_POWER_SAVE_REQ_V01,
  343. WLFW_POWER_SAVE_REQ_MSG_V01_MAX_MSG_LEN,
  344. wlfw_power_save_req_msg_v01_ei, req);
  345. if (ret < 0) {
  346. qmi_txn_cancel(&txn);
  347. icnss_qmi_fatal_err("Fail to send exit power save req %d\n",
  348. ret);
  349. goto out;
  350. }
  351. qmi_txn_cancel(&txn);
  352. if (mode == WLFW_POWER_SAVE_EXIT_V01)
  353. priv->stats.exit_power_save_resp++;
  354. else
  355. priv->stats.enter_power_save_resp++;
  356. kfree(req);
  357. return 0;
  358. out:
  359. kfree(req);
  360. if (mode == WLFW_POWER_SAVE_EXIT_V01)
  361. priv->stats.exit_power_save_err++;
  362. else
  363. priv->stats.enter_power_save_err++;
  364. return ret;
  365. }
  366. int wlfw_send_soc_wake_msg(struct icnss_priv *priv,
  367. enum wlfw_soc_wake_enum_v01 type)
  368. {
  369. int ret;
  370. struct wlfw_soc_wake_req_msg_v01 *req;
  371. struct wlfw_soc_wake_resp_msg_v01 *resp;
  372. struct qmi_txn txn;
  373. if (!priv)
  374. return -ENODEV;
  375. if (test_bit(ICNSS_FW_DOWN, &priv->state))
  376. return -EINVAL;
  377. icnss_pr_soc_wake("Sending soc wake msg, type: 0x%x\n",
  378. type);
  379. req = kzalloc(sizeof(*req), GFP_KERNEL);
  380. if (!req)
  381. return -ENOMEM;
  382. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  383. if (!resp) {
  384. kfree(req);
  385. return -ENOMEM;
  386. }
  387. req->wake_valid = 1;
  388. req->wake = type;
  389. priv->stats.soc_wake_req++;
  390. ret = qmi_txn_init(&priv->qmi, &txn,
  391. wlfw_soc_wake_resp_msg_v01_ei, resp);
  392. if (ret < 0) {
  393. icnss_pr_err("Fail to init txn for wake msg resp %d\n",
  394. ret);
  395. goto out;
  396. }
  397. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  398. QMI_WLFW_SOC_WAKE_REQ_V01,
  399. WLFW_SOC_WAKE_REQ_MSG_V01_MAX_MSG_LEN,
  400. wlfw_soc_wake_req_msg_v01_ei, req);
  401. if (ret < 0) {
  402. qmi_txn_cancel(&txn);
  403. icnss_pr_err("Fail to send soc wake msg %d\n", ret);
  404. goto out;
  405. }
  406. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  407. if (ret < 0) {
  408. icnss_qmi_fatal_err("SOC wake timed out with ret %d\n",
  409. ret);
  410. goto out;
  411. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  412. icnss_qmi_fatal_err(
  413. "SOC wake request rejected,result:%d error:%d\n",
  414. resp->resp.result, resp->resp.error);
  415. ret = -resp->resp.result;
  416. goto out;
  417. }
  418. priv->stats.soc_wake_resp++;
  419. kfree(resp);
  420. kfree(req);
  421. return 0;
  422. out:
  423. kfree(req);
  424. kfree(resp);
  425. priv->stats.soc_wake_err++;
  426. return ret;
  427. }
  428. int wlfw_ind_register_send_sync_msg(struct icnss_priv *priv)
  429. {
  430. int ret;
  431. struct wlfw_ind_register_req_msg_v01 *req;
  432. struct wlfw_ind_register_resp_msg_v01 *resp;
  433. struct qmi_txn txn;
  434. if (!priv)
  435. return -ENODEV;
  436. icnss_pr_dbg("Sending indication register message, state: 0x%lx\n",
  437. priv->state);
  438. req = kzalloc(sizeof(*req), GFP_KERNEL);
  439. if (!req)
  440. return -ENOMEM;
  441. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  442. if (!resp) {
  443. kfree(req);
  444. return -ENOMEM;
  445. }
  446. req->client_id_valid = 1;
  447. req->client_id = WLFW_CLIENT_ID;
  448. req->fw_ready_enable_valid = 1;
  449. req->fw_ready_enable = 1;
  450. req->pin_connect_result_enable_valid = 1;
  451. req->pin_connect_result_enable = 1;
  452. if (priv->device_id == ADRASTEA_DEVICE_ID) {
  453. req->msa_ready_enable_valid = 1;
  454. req->msa_ready_enable = 1;
  455. if (test_bit(FW_REJUVENATE_ENABLE,
  456. &priv->ctrl_params.quirks)) {
  457. req->rejuvenate_enable_valid = 1;
  458. req->rejuvenate_enable = 1;
  459. }
  460. } else if (priv->device_id == WCN6750_DEVICE_ID ||
  461. priv->device_id == WCN6450_DEVICE_ID) {
  462. req->fw_init_done_enable_valid = 1;
  463. req->fw_init_done_enable = 1;
  464. req->cal_done_enable_valid = 1;
  465. req->cal_done_enable = 1;
  466. req->qdss_trace_req_mem_enable_valid = 1;
  467. req->qdss_trace_req_mem_enable = 1;
  468. req->qdss_trace_save_enable_valid = 1;
  469. req->qdss_trace_save_enable = 1;
  470. req->qdss_trace_free_enable_valid = 1;
  471. req->qdss_trace_free_enable = 1;
  472. req->respond_get_info_enable_valid = 1;
  473. req->respond_get_info_enable = 1;
  474. req->m3_dump_upload_segments_req_enable_valid = 1;
  475. req->m3_dump_upload_segments_req_enable = 1;
  476. }
  477. priv->stats.ind_register_req++;
  478. ret = qmi_txn_init(&priv->qmi, &txn,
  479. wlfw_ind_register_resp_msg_v01_ei, resp);
  480. if (ret < 0) {
  481. icnss_qmi_fatal_err(
  482. "Fail to init txn for Ind Register resp %d\n",
  483. ret);
  484. goto out;
  485. }
  486. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  487. QMI_WLFW_IND_REGISTER_REQ_V01,
  488. WLFW_IND_REGISTER_REQ_MSG_V01_MAX_MSG_LEN,
  489. wlfw_ind_register_req_msg_v01_ei, req);
  490. if (ret < 0) {
  491. qmi_txn_cancel(&txn);
  492. icnss_qmi_fatal_err("Fail to send Ind Register req %d\n", ret);
  493. goto out;
  494. }
  495. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  496. if (ret < 0) {
  497. icnss_qmi_fatal_err(
  498. "Ind Register resp wait failed with ret %d\n",
  499. ret);
  500. goto out;
  501. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  502. icnss_qmi_fatal_err(
  503. "QMI Ind Register request rejected, result:%d error:%d\n",
  504. resp->resp.result, resp->resp.error);
  505. ret = -resp->resp.result;
  506. goto out;
  507. }
  508. priv->stats.ind_register_resp++;
  509. if (resp->fw_status_valid &&
  510. (resp->fw_status & QMI_WLFW_ALREADY_REGISTERED_V01)) {
  511. ret = -EALREADY;
  512. icnss_pr_dbg("WLFW already registered\n");
  513. goto qmi_registered;
  514. }
  515. kfree(resp);
  516. kfree(req);
  517. return 0;
  518. out:
  519. priv->stats.ind_register_err++;
  520. qmi_registered:
  521. kfree(resp);
  522. kfree(req);
  523. return ret;
  524. }
  525. int wlfw_cal_report_req(struct icnss_priv *priv)
  526. {
  527. int ret;
  528. struct wlfw_cal_report_req_msg_v01 *req;
  529. struct wlfw_cal_report_resp_msg_v01 *resp;
  530. struct qmi_txn txn;
  531. if (!priv)
  532. return -ENODEV;
  533. if (test_bit(ICNSS_FW_DOWN, &priv->state))
  534. return -EINVAL;
  535. icnss_pr_info("Sending cal report request, state: 0x%lx\n",
  536. priv->state);
  537. req = kzalloc(sizeof(*req), GFP_KERNEL);
  538. if (!req)
  539. return -ENOMEM;
  540. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  541. if (!resp) {
  542. kfree(req);
  543. return -ENOMEM;
  544. }
  545. req->meta_data_len = 0;
  546. ret = qmi_txn_init(&priv->qmi, &txn,
  547. wlfw_cal_report_resp_msg_v01_ei, resp);
  548. if (ret < 0) {
  549. icnss_qmi_fatal_err("Fail to init txn for cal report req %d\n",
  550. ret);
  551. goto out;
  552. }
  553. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  554. QMI_WLFW_CAL_REPORT_REQ_V01,
  555. WLFW_CAL_REPORT_REQ_MSG_V01_MAX_MSG_LEN,
  556. wlfw_cal_report_req_msg_v01_ei, req);
  557. if (ret < 0) {
  558. qmi_txn_cancel(&txn);
  559. icnss_qmi_fatal_err("Fail to send cal report req %d\n", ret);
  560. goto out;
  561. }
  562. ret = qmi_txn_wait(&txn,
  563. priv->ctrl_params.qmi_timeout);
  564. if (ret < 0) {
  565. icnss_qmi_fatal_err("Cal report wait failed with ret %d\n",
  566. ret);
  567. goto out;
  568. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  569. icnss_qmi_fatal_err("QMI cal report request rejected, result:%d error:%d\n",
  570. resp->resp.result, resp->resp.error);
  571. ret = -resp->resp.result;
  572. goto out;
  573. }
  574. kfree(resp);
  575. kfree(req);
  576. return 0;
  577. out:
  578. return ret;
  579. }
  580. int wlfw_cap_send_sync_msg(struct icnss_priv *priv)
  581. {
  582. int ret;
  583. struct wlfw_cap_req_msg_v01 *req;
  584. struct wlfw_cap_resp_msg_v01 *resp;
  585. struct qmi_txn txn;
  586. if (!priv)
  587. return -ENODEV;
  588. icnss_pr_dbg("Sending target capability message, state: 0x%lx\n",
  589. priv->state);
  590. req = kzalloc(sizeof(*req), GFP_KERNEL);
  591. if (!req)
  592. return -ENOMEM;
  593. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  594. if (!resp) {
  595. kfree(req);
  596. return -ENOMEM;
  597. }
  598. priv->stats.cap_req++;
  599. ret = qmi_txn_init(&priv->qmi, &txn, wlfw_cap_resp_msg_v01_ei, resp);
  600. if (ret < 0) {
  601. icnss_qmi_fatal_err("Fail to init txn for Capability resp %d\n",
  602. ret);
  603. goto out;
  604. }
  605. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  606. QMI_WLFW_CAP_REQ_V01,
  607. WLFW_CAP_REQ_MSG_V01_MAX_MSG_LEN,
  608. wlfw_cap_req_msg_v01_ei, req);
  609. if (ret < 0) {
  610. qmi_txn_cancel(&txn);
  611. icnss_qmi_fatal_err("Fail to send Capability req %d\n", ret);
  612. goto out;
  613. }
  614. ret = qmi_txn_wait(&txn,
  615. priv->ctrl_params.qmi_timeout +
  616. msecs_to_jiffies(priv->wlan_en_delay_ms));
  617. if (ret < 0) {
  618. icnss_qmi_fatal_err("Capability resp wait failed with ret %d\n",
  619. ret);
  620. goto out;
  621. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  622. ret = -resp->resp.result;
  623. if (resp->resp.error == QMI_ERR_PLAT_CCPM_CLK_INIT_FAILED) {
  624. icnss_pr_err("RF card not present\n");
  625. goto out;
  626. }
  627. icnss_qmi_fatal_err(
  628. "QMI Capability request rejected, result:%d error:%d\n",
  629. resp->resp.result, resp->resp.error);
  630. goto out;
  631. }
  632. priv->stats.cap_resp++;
  633. if (resp->chip_info_valid) {
  634. priv->chip_info.chip_id = resp->chip_info.chip_id;
  635. priv->chip_info.chip_family = resp->chip_info.chip_family;
  636. }
  637. if (resp->board_info_valid)
  638. priv->board_id = resp->board_info.board_id;
  639. else
  640. priv->board_id = 0xFF;
  641. if (resp->soc_info_valid)
  642. priv->soc_id = resp->soc_info.soc_id;
  643. if (resp->fw_version_info_valid) {
  644. priv->fw_version_info.fw_version =
  645. resp->fw_version_info.fw_version;
  646. strlcpy(priv->fw_version_info.fw_build_timestamp,
  647. resp->fw_version_info.fw_build_timestamp,
  648. WLFW_MAX_TIMESTAMP_LEN + 1);
  649. }
  650. if (resp->voltage_mv_valid) {
  651. priv->cpr_info.voltage = resp->voltage_mv;
  652. icnss_pr_dbg("Voltage for CPR: %dmV\n",
  653. priv->cpr_info.voltage);
  654. icnss_update_cpr_info(priv);
  655. }
  656. if (resp->fw_build_id_valid)
  657. strlcpy(priv->fw_build_id, resp->fw_build_id,
  658. QMI_WLFW_MAX_BUILD_ID_LEN_V01 + 1);
  659. if (resp->rd_card_chain_cap_valid) {
  660. priv->rd_card_chain_cap = (enum icnss_rd_card_chain_cap)resp->rd_card_chain_cap;
  661. if (resp->rd_card_chain_cap == WLFW_RD_CARD_CHAIN_CAP_1x1_V01)
  662. priv->is_chain1_supported = false;
  663. }
  664. if (resp->foundry_name_valid)
  665. priv->foundry_name = resp->foundry_name[0];
  666. else if (resp->chip_info_valid && priv->chip_info.chip_id == UMC_CHIP_ID)
  667. priv->foundry_name = 'u';
  668. if (resp->he_channel_width_cap_valid)
  669. priv->phy_he_channel_width_cap =
  670. (enum icnss_phy_he_channel_width_cap)resp->he_channel_width_cap;
  671. if (resp->phy_qam_cap_valid)
  672. priv->phy_qam_cap = (enum icnss_phy_qam_cap)resp->phy_qam_cap;
  673. icnss_pr_dbg("Capability, chip_id: 0x%x, chip_family: 0x%x, board_id: 0x%x, soc_id: 0x%x",
  674. priv->chip_info.chip_id, priv->chip_info.chip_family,
  675. priv->board_id, priv->soc_id);
  676. icnss_pr_dbg("fw_version: 0x%x, fw_build_timestamp: %s, fw_build_id: %s",
  677. priv->fw_version_info.fw_version,
  678. priv->fw_version_info.fw_build_timestamp,
  679. priv->fw_build_id);
  680. icnss_pr_dbg("RD card chain cap: %d, PHY HE channel width cap: %d, PHY QAM cap: %d",
  681. priv->rd_card_chain_cap, priv->phy_he_channel_width_cap,
  682. priv->phy_qam_cap);
  683. kfree(resp);
  684. kfree(req);
  685. return 0;
  686. out:
  687. kfree(resp);
  688. kfree(req);
  689. priv->stats.cap_err++;
  690. return ret;
  691. }
  692. int icnss_qmi_get_dms_mac(struct icnss_priv *priv)
  693. {
  694. struct dms_get_mac_address_req_msg_v01 req;
  695. struct dms_get_mac_address_resp_msg_v01 resp;
  696. struct qmi_txn txn;
  697. int ret = 0;
  698. if (!test_bit(ICNSS_QMI_DMS_CONNECTED, &priv->state)) {
  699. icnss_pr_err("DMS QMI connection not established\n");
  700. return -EAGAIN;
  701. }
  702. icnss_pr_dbg("Requesting DMS MAC address");
  703. memset(&resp, 0, sizeof(resp));
  704. ret = qmi_txn_init(&priv->qmi_dms, &txn,
  705. dms_get_mac_address_resp_msg_v01_ei, &resp);
  706. if (ret < 0) {
  707. icnss_pr_err("Failed to initialize txn for dms, err: %d\n",
  708. ret);
  709. goto out;
  710. }
  711. req.device = DMS_DEVICE_MAC_WLAN_V01;
  712. ret = qmi_send_request(&priv->qmi_dms, NULL, &txn,
  713. QMI_DMS_GET_MAC_ADDRESS_REQ_V01,
  714. DMS_GET_MAC_ADDRESS_REQ_MSG_V01_MAX_MSG_LEN,
  715. dms_get_mac_address_req_msg_v01_ei, &req);
  716. if (ret < 0) {
  717. qmi_txn_cancel(&txn);
  718. icnss_pr_err("Failed to send QMI_DMS_GET_MAC_ADDRESS_REQ_V01, err: %d\n",
  719. ret);
  720. goto out;
  721. }
  722. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  723. if (ret < 0) {
  724. icnss_pr_err("Failed to wait for QMI_DMS_GET_MAC_ADDRESS_RESP_V01, err: %d\n",
  725. ret);
  726. goto out;
  727. }
  728. if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
  729. if (resp.resp.error == DMS_MAC_NOT_PROVISIONED) {
  730. icnss_pr_err("NV MAC address is not provisioned");
  731. priv->dms.nv_mac_not_prov = 1;
  732. } else {
  733. icnss_pr_err("QMI_DMS_GET_MAC_ADDRESS_REQ_V01 failed, result: %d, err: %d\n",
  734. resp.resp.result, resp.resp.error);
  735. }
  736. ret = -resp.resp.result;
  737. goto out;
  738. }
  739. if (!resp.mac_address_valid ||
  740. resp.mac_address_len != QMI_WLFW_MAC_ADDR_SIZE_V01) {
  741. icnss_pr_err("Invalid MAC address received from DMS\n");
  742. priv->dms.mac_valid = false;
  743. goto out;
  744. }
  745. priv->dms.mac_valid = true;
  746. memcpy(priv->dms.mac, resp.mac_address, QMI_WLFW_MAC_ADDR_SIZE_V01);
  747. icnss_pr_info("Received DMS MAC: [%pM]\n", priv->dms.mac);
  748. out:
  749. return ret;
  750. }
  751. int icnss_wlfw_wlan_mac_req_send_sync(struct icnss_priv *priv,
  752. u8 *mac, u32 mac_len)
  753. {
  754. struct wlfw_mac_addr_req_msg_v01 req;
  755. struct wlfw_mac_addr_resp_msg_v01 resp = {0};
  756. struct qmi_txn txn;
  757. int ret;
  758. if (!priv || !mac || mac_len != QMI_WLFW_MAC_ADDR_SIZE_V01)
  759. return -EINVAL;
  760. ret = qmi_txn_init(&priv->qmi, &txn,
  761. wlfw_mac_addr_resp_msg_v01_ei, &resp);
  762. if (ret < 0) {
  763. icnss_pr_err("Failed to initialize txn for mac req, err: %d\n",
  764. ret);
  765. ret = -EIO;
  766. goto out;
  767. }
  768. icnss_pr_dbg("Sending WLAN mac req [%pM], state: 0x%lx\n",
  769. mac, priv->state);
  770. memcpy(req.mac_addr, mac, mac_len);
  771. req.mac_addr_valid = 1;
  772. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  773. QMI_WLFW_MAC_ADDR_REQ_V01,
  774. WLFW_MAC_ADDR_REQ_MSG_V01_MAX_MSG_LEN,
  775. wlfw_mac_addr_req_msg_v01_ei, &req);
  776. if (ret < 0) {
  777. qmi_txn_cancel(&txn);
  778. icnss_pr_err("Failed to send mac req, err: %d\n", ret);
  779. ret = -EIO;
  780. goto out;
  781. }
  782. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  783. if (ret < 0) {
  784. icnss_pr_err("Failed to wait for resp of mac req, err: %d\n",
  785. ret);
  786. ret = -EIO;
  787. goto out;
  788. }
  789. if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
  790. icnss_pr_err("WLAN mac req failed, result: %d\n",
  791. resp.resp.result);
  792. ret = -resp.resp.result;
  793. }
  794. out:
  795. return ret;
  796. }
  797. static int icnss_dms_connect_to_server(struct icnss_priv *priv,
  798. unsigned int node, unsigned int port)
  799. {
  800. struct qmi_handle *qmi_dms = &priv->qmi_dms;
  801. struct sockaddr_qrtr sq = {0};
  802. int ret = 0;
  803. sq.sq_family = AF_QIPCRTR;
  804. sq.sq_node = node;
  805. sq.sq_port = port;
  806. ret = kernel_connect(qmi_dms->sock, (struct sockaddr *)&sq,
  807. sizeof(sq), 0);
  808. if (ret < 0) {
  809. icnss_pr_err("Failed to connect to QMI DMS remote service Node: %d Port: %d\n",
  810. node, port);
  811. goto out;
  812. }
  813. set_bit(ICNSS_QMI_DMS_CONNECTED, &priv->state);
  814. icnss_pr_info("QMI DMS service connected, state: 0x%lx\n",
  815. priv->state);
  816. out:
  817. return ret;
  818. }
  819. static int dms_new_server(struct qmi_handle *qmi_dms,
  820. struct qmi_service *service)
  821. {
  822. struct icnss_priv *priv =
  823. container_of(qmi_dms, struct icnss_priv, qmi_dms);
  824. if (!service)
  825. return -EINVAL;
  826. return icnss_dms_connect_to_server(priv, service->node,
  827. service->port);
  828. }
  829. static void dms_del_server(struct qmi_handle *qmi_dms,
  830. struct qmi_service *service)
  831. {
  832. struct icnss_priv *priv =
  833. container_of(qmi_dms, struct icnss_priv, qmi_dms);
  834. clear_bit(ICNSS_QMI_DMS_CONNECTED, &priv->state);
  835. icnss_pr_info("QMI DMS service disconnected, state: 0x%lx\n",
  836. priv->state);
  837. }
  838. static struct qmi_ops qmi_dms_ops = {
  839. .new_server = dms_new_server,
  840. .del_server = dms_del_server,
  841. };
  842. int icnss_dms_init(struct icnss_priv *priv)
  843. {
  844. int ret = 0;
  845. ret = qmi_handle_init(&priv->qmi_dms, DMS_QMI_MAX_MSG_LEN,
  846. &qmi_dms_ops, NULL);
  847. if (ret < 0) {
  848. icnss_pr_err("Failed to initialize DMS handle, err: %d\n", ret);
  849. goto out;
  850. }
  851. ret = qmi_add_lookup(&priv->qmi_dms, DMS_SERVICE_ID_V01,
  852. DMS_SERVICE_VERS_V01, 0);
  853. if (ret < 0)
  854. icnss_pr_err("Failed to add DMS lookup, err: %d\n", ret);
  855. out:
  856. return ret;
  857. }
  858. void icnss_dms_deinit(struct icnss_priv *priv)
  859. {
  860. qmi_handle_release(&priv->qmi_dms);
  861. }
  862. static int icnss_get_bdf_file_name(struct icnss_priv *priv,
  863. u32 bdf_type, char *filename,
  864. u32 filename_len)
  865. {
  866. char filename_tmp[ICNSS_MAX_FILE_NAME];
  867. char foundry_specific_filename[ICNSS_MAX_FILE_NAME];
  868. int ret = 0;
  869. switch (bdf_type) {
  870. case ICNSS_BDF_ELF:
  871. if (priv->board_id == 0xFF)
  872. snprintf(filename_tmp, filename_len, ELF_BDF_FILE_NAME);
  873. else if (priv->board_id < 0xFF)
  874. snprintf(filename_tmp, filename_len,
  875. ELF_BDF_FILE_NAME_PREFIX "%02x",
  876. priv->board_id);
  877. else
  878. snprintf(filename_tmp, filename_len,
  879. BDF_FILE_NAME_PREFIX "%02x.e%02x",
  880. priv->board_id >> 8 & 0xFF,
  881. priv->board_id & 0xFF);
  882. break;
  883. case ICNSS_BDF_BIN:
  884. if (priv->board_id == 0xFF)
  885. snprintf(filename_tmp, filename_len, BIN_BDF_FILE_NAME);
  886. else if (priv->board_id >= WLAN_BOARD_ID_INDEX)
  887. snprintf(filename_tmp, filename_len,
  888. BIN_BDF_FILE_NAME_PREFIX "%03x",
  889. priv->board_id);
  890. else
  891. snprintf(filename_tmp, filename_len,
  892. BIN_BDF_FILE_NAME_PREFIX "b%02x",
  893. priv->board_id);
  894. if (priv->foundry_name) {
  895. strlcpy(foundry_specific_filename, filename_tmp, ICNSS_MAX_FILE_NAME);
  896. memmove(foundry_specific_filename + BDWLAN_SIZE + 1,
  897. foundry_specific_filename + BDWLAN_SIZE,
  898. BDWLAN_SIZE - 1);
  899. foundry_specific_filename[BDWLAN_SIZE] = priv->foundry_name;
  900. foundry_specific_filename[ICNSS_MAX_FILE_NAME - 1] = '\0';
  901. strlcpy(filename_tmp, foundry_specific_filename, ICNSS_MAX_FILE_NAME);
  902. }
  903. break;
  904. case ICNSS_BDF_REGDB:
  905. snprintf(filename_tmp, filename_len, REGDB_FILE_NAME);
  906. break;
  907. default:
  908. icnss_pr_err("Invalid BDF type: %d\n",
  909. priv->ctrl_params.bdf_type);
  910. ret = -EINVAL;
  911. break;
  912. }
  913. if (!ret)
  914. icnss_add_fw_prefix_name(priv, filename, filename_tmp);
  915. return ret;
  916. }
  917. static char *icnss_bdf_type_to_str(enum icnss_bdf_type bdf_type)
  918. {
  919. switch (bdf_type) {
  920. case ICNSS_BDF_BIN:
  921. return "BDF";
  922. case ICNSS_BDF_ELF:
  923. return "BDF";
  924. case ICNSS_BDF_REGDB:
  925. return "REGDB";
  926. default:
  927. return "UNKNOWN";
  928. }
  929. };
  930. int icnss_wlfw_bdf_dnld_send_sync(struct icnss_priv *priv, u32 bdf_type)
  931. {
  932. struct wlfw_bdf_download_req_msg_v01 *req;
  933. struct wlfw_bdf_download_resp_msg_v01 *resp;
  934. struct qmi_txn txn;
  935. char filename[ICNSS_MAX_FILE_NAME];
  936. const struct firmware *fw_entry = NULL;
  937. const u8 *temp;
  938. unsigned int remaining;
  939. int ret = 0;
  940. icnss_pr_dbg("Sending %s download message, state: 0x%lx, type: %d\n",
  941. icnss_bdf_type_to_str(bdf_type), priv->state, bdf_type);
  942. req = kzalloc(sizeof(*req), GFP_KERNEL);
  943. if (!req)
  944. return -ENOMEM;
  945. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  946. if (!resp) {
  947. kfree(req);
  948. return -ENOMEM;
  949. }
  950. ret = icnss_get_bdf_file_name(priv, bdf_type,
  951. filename, sizeof(filename));
  952. if (ret)
  953. goto err_req_fw;
  954. ret = firmware_request_nowarn(&fw_entry, filename, &priv->pdev->dev);
  955. if (ret) {
  956. icnss_pr_err("Failed to load %s: %s ret:%d\n",
  957. icnss_bdf_type_to_str(bdf_type), filename, ret);
  958. goto err_req_fw;
  959. }
  960. temp = fw_entry->data;
  961. remaining = fw_entry->size;
  962. icnss_pr_dbg("Downloading %s: %s, size: %u\n",
  963. icnss_bdf_type_to_str(bdf_type), filename, remaining);
  964. while (remaining) {
  965. req->valid = 1;
  966. req->file_id_valid = 1;
  967. req->file_id = priv->board_id;
  968. req->total_size_valid = 1;
  969. req->total_size = fw_entry->size;
  970. req->seg_id_valid = 1;
  971. req->data_valid = 1;
  972. req->end_valid = 1;
  973. req->bdf_type_valid = 1;
  974. req->bdf_type = bdf_type;
  975. if (remaining > QMI_WLFW_MAX_DATA_SIZE_V01) {
  976. req->data_len = QMI_WLFW_MAX_DATA_SIZE_V01;
  977. } else {
  978. req->data_len = remaining;
  979. req->end = 1;
  980. }
  981. memcpy(req->data, temp, req->data_len);
  982. ret = qmi_txn_init(&priv->qmi, &txn,
  983. wlfw_bdf_download_resp_msg_v01_ei, resp);
  984. if (ret < 0) {
  985. icnss_pr_err("Failed to initialize txn for %s download request, err: %d\n",
  986. icnss_bdf_type_to_str(bdf_type), ret);
  987. goto err_send;
  988. }
  989. ret = qmi_send_request
  990. (&priv->qmi, NULL, &txn,
  991. QMI_WLFW_BDF_DOWNLOAD_REQ_V01,
  992. WLFW_BDF_DOWNLOAD_REQ_MSG_V01_MAX_MSG_LEN,
  993. wlfw_bdf_download_req_msg_v01_ei, req);
  994. if (ret < 0) {
  995. qmi_txn_cancel(&txn);
  996. icnss_pr_err("Failed to send respond %s download request, err: %d\n",
  997. icnss_bdf_type_to_str(bdf_type), ret);
  998. goto err_send;
  999. }
  1000. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  1001. if (ret < 0) {
  1002. icnss_pr_err("Failed to wait for response of %s download request, err: %d\n",
  1003. icnss_bdf_type_to_str(bdf_type), ret);
  1004. goto err_send;
  1005. }
  1006. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1007. icnss_pr_err("%s download request failed, result: %d, err: %d\n",
  1008. icnss_bdf_type_to_str(bdf_type), resp->resp.result,
  1009. resp->resp.error);
  1010. ret = -resp->resp.result;
  1011. goto err_send;
  1012. }
  1013. remaining -= req->data_len;
  1014. temp += req->data_len;
  1015. req->seg_id++;
  1016. }
  1017. release_firmware(fw_entry);
  1018. kfree(req);
  1019. kfree(resp);
  1020. return 0;
  1021. err_send:
  1022. release_firmware(fw_entry);
  1023. err_req_fw:
  1024. if (bdf_type != ICNSS_BDF_REGDB)
  1025. ICNSS_QMI_ASSERT();
  1026. kfree(req);
  1027. kfree(resp);
  1028. return ret;
  1029. }
  1030. int icnss_wlfw_qdss_data_send_sync(struct icnss_priv *priv, char *file_name,
  1031. u32 total_size)
  1032. {
  1033. int ret = 0;
  1034. struct wlfw_qdss_trace_data_req_msg_v01 *req;
  1035. struct wlfw_qdss_trace_data_resp_msg_v01 *resp;
  1036. unsigned char *p_qdss_trace_data_temp, *p_qdss_trace_data = NULL;
  1037. unsigned int remaining;
  1038. struct qmi_txn txn;
  1039. icnss_pr_dbg("%s", __func__);
  1040. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1041. if (!req)
  1042. return -ENOMEM;
  1043. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1044. if (!resp) {
  1045. kfree(req);
  1046. return -ENOMEM;
  1047. }
  1048. p_qdss_trace_data = kzalloc(total_size, GFP_KERNEL);
  1049. if (!p_qdss_trace_data) {
  1050. ret = ENOMEM;
  1051. goto end;
  1052. }
  1053. remaining = total_size;
  1054. p_qdss_trace_data_temp = p_qdss_trace_data;
  1055. while (remaining && resp->end == 0) {
  1056. ret = qmi_txn_init(&priv->qmi, &txn,
  1057. wlfw_qdss_trace_data_resp_msg_v01_ei, resp);
  1058. if (ret < 0) {
  1059. icnss_pr_err("Fail to init txn for QDSS trace resp %d\n",
  1060. ret);
  1061. goto fail;
  1062. }
  1063. ret = qmi_send_request
  1064. (&priv->qmi, NULL, &txn,
  1065. QMI_WLFW_QDSS_TRACE_DATA_REQ_V01,
  1066. WLFW_QDSS_TRACE_DATA_REQ_MSG_V01_MAX_MSG_LEN,
  1067. wlfw_qdss_trace_data_req_msg_v01_ei, req);
  1068. if (ret < 0) {
  1069. qmi_txn_cancel(&txn);
  1070. icnss_pr_err("Fail to send QDSS trace data req %d\n",
  1071. ret);
  1072. goto fail;
  1073. }
  1074. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  1075. if (ret < 0) {
  1076. icnss_pr_err("QDSS trace resp wait failed with rc %d\n",
  1077. ret);
  1078. goto fail;
  1079. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1080. icnss_pr_err("QMI QDSS trace request rejected, result:%d error:%d\n",
  1081. resp->resp.result, resp->resp.error);
  1082. ret = -resp->resp.result;
  1083. goto fail;
  1084. } else {
  1085. ret = 0;
  1086. }
  1087. icnss_pr_dbg("%s: response total size %d data len %d",
  1088. __func__, resp->total_size, resp->data_len);
  1089. if ((resp->total_size_valid == 1 &&
  1090. resp->total_size == total_size) &&
  1091. (resp->seg_id_valid == 1 && resp->seg_id == req->seg_id) &&
  1092. (resp->data_valid == 1 &&
  1093. resp->data_len <= QMI_WLFW_MAX_DATA_SIZE_V01) &&
  1094. resp->data_len <= remaining) {
  1095. memcpy(p_qdss_trace_data_temp,
  1096. resp->data, resp->data_len);
  1097. } else {
  1098. icnss_pr_err("%s: Unmatched qdss trace data, Expect total_size %u, seg_id %u, Recv total_size_valid %u, total_size %u, seg_id_valid %u, seg_id %u, data_len_valid %u, data_len %u",
  1099. __func__,
  1100. total_size, req->seg_id,
  1101. resp->total_size_valid,
  1102. resp->total_size,
  1103. resp->seg_id_valid,
  1104. resp->seg_id,
  1105. resp->data_valid,
  1106. resp->data_len);
  1107. ret = -EINVAL;
  1108. goto fail;
  1109. }
  1110. remaining -= resp->data_len;
  1111. p_qdss_trace_data_temp += resp->data_len;
  1112. req->seg_id++;
  1113. }
  1114. if (remaining == 0 && (resp->end_valid && resp->end)) {
  1115. ret = icnss_genl_send_msg(p_qdss_trace_data,
  1116. ICNSS_GENL_MSG_TYPE_QDSS, file_name,
  1117. total_size);
  1118. if (ret < 0) {
  1119. icnss_pr_err("Fail to save QDSS trace data: %d\n",
  1120. ret);
  1121. ret = -EINVAL;
  1122. }
  1123. } else {
  1124. icnss_pr_err("%s: QDSS trace file corrupted: remaining %u, end_valid %u, end %u",
  1125. __func__,
  1126. remaining, resp->end_valid, resp->end);
  1127. ret = -EINVAL;
  1128. }
  1129. fail:
  1130. kfree(p_qdss_trace_data);
  1131. end:
  1132. kfree(req);
  1133. kfree(resp);
  1134. return ret;
  1135. }
  1136. int icnss_wlfw_qdss_dnld_send_sync(struct icnss_priv *priv)
  1137. {
  1138. struct wlfw_qdss_trace_config_download_req_msg_v01 *req;
  1139. struct wlfw_qdss_trace_config_download_resp_msg_v01 *resp;
  1140. struct qmi_txn txn;
  1141. char filename[ICNSS_MAX_FILE_NAME];
  1142. const struct firmware *fw_entry = NULL;
  1143. const u8 *temp;
  1144. unsigned int remaining;
  1145. int ret = 0;
  1146. icnss_pr_dbg("Sending QDSS config download message, state: 0x%lx\n",
  1147. priv->state);
  1148. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1149. if (!req)
  1150. return -ENOMEM;
  1151. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1152. if (!resp) {
  1153. kfree(req);
  1154. return -ENOMEM;
  1155. }
  1156. icnss_add_fw_prefix_name(priv, filename, QDSS_TRACE_CONFIG_FILE);
  1157. ret = firmware_request_nowarn(&fw_entry, filename,
  1158. &priv->pdev->dev);
  1159. if (ret) {
  1160. icnss_pr_err("Failed to load QDSS: %s ret:%d\n",
  1161. filename, ret);
  1162. goto err_req_fw;
  1163. }
  1164. temp = fw_entry->data;
  1165. remaining = fw_entry->size;
  1166. icnss_pr_dbg("Downloading QDSS: %s, size: %u\n",
  1167. filename, remaining);
  1168. while (remaining) {
  1169. req->total_size_valid = 1;
  1170. req->total_size = remaining;
  1171. req->seg_id_valid = 1;
  1172. req->data_valid = 1;
  1173. req->end_valid = 1;
  1174. if (remaining > QMI_WLFW_MAX_DATA_SIZE_V01) {
  1175. req->data_len = QMI_WLFW_MAX_DATA_SIZE_V01;
  1176. } else {
  1177. req->data_len = remaining;
  1178. req->end = 1;
  1179. }
  1180. memcpy(req->data, temp, req->data_len);
  1181. ret = qmi_txn_init
  1182. (&priv->qmi, &txn,
  1183. wlfw_qdss_trace_config_download_resp_msg_v01_ei,
  1184. resp);
  1185. if (ret < 0) {
  1186. icnss_pr_err("Failed to initialize txn for QDSS download request, err: %d\n",
  1187. ret);
  1188. goto err_send;
  1189. }
  1190. ret = qmi_send_request
  1191. (&priv->qmi, NULL, &txn,
  1192. QMI_WLFW_QDSS_TRACE_CONFIG_DOWNLOAD_REQ_V01,
  1193. WLFW_QDSS_TRACE_CONFIG_DOWNLOAD_REQ_MSG_V01_MAX_MSG_LEN,
  1194. wlfw_qdss_trace_config_download_req_msg_v01_ei, req);
  1195. if (ret < 0) {
  1196. qmi_txn_cancel(&txn);
  1197. icnss_pr_err("Failed to send respond QDSS download request, err: %d\n",
  1198. ret);
  1199. goto err_send;
  1200. }
  1201. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  1202. if (ret < 0) {
  1203. icnss_pr_err("Failed to wait for response of QDSS download request, err: %d\n",
  1204. ret);
  1205. goto err_send;
  1206. }
  1207. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1208. icnss_pr_err("QDSS download request failed, result: %d, err: %d\n",
  1209. resp->resp.result, resp->resp.error);
  1210. ret = -resp->resp.result;
  1211. goto err_send;
  1212. }
  1213. remaining -= req->data_len;
  1214. temp += req->data_len;
  1215. req->seg_id++;
  1216. }
  1217. release_firmware(fw_entry);
  1218. kfree(req);
  1219. kfree(resp);
  1220. return 0;
  1221. err_send:
  1222. release_firmware(fw_entry);
  1223. err_req_fw:
  1224. kfree(req);
  1225. kfree(resp);
  1226. return ret;
  1227. }
  1228. int wlfw_wlan_mode_send_sync_msg(struct icnss_priv *priv,
  1229. enum wlfw_driver_mode_enum_v01 mode)
  1230. {
  1231. int ret;
  1232. struct wlfw_wlan_mode_req_msg_v01 *req;
  1233. struct wlfw_wlan_mode_resp_msg_v01 *resp;
  1234. struct qmi_txn txn;
  1235. if (!priv)
  1236. return -ENODEV;
  1237. /* During recovery do not send mode request for WLAN OFF as
  1238. * FW not able to process it.
  1239. */
  1240. if (test_bit(ICNSS_PD_RESTART, &priv->state) &&
  1241. mode == QMI_WLFW_OFF_V01)
  1242. return 0;
  1243. if (!test_bit(ICNSS_MODE_ON, &priv->state) &&
  1244. mode == QMI_WLFW_OFF_V01)
  1245. return 0;
  1246. icnss_pr_dbg("Sending Mode request, state: 0x%lx, mode: %d\n",
  1247. priv->state, mode);
  1248. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1249. if (!req)
  1250. return -ENOMEM;
  1251. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1252. if (!resp) {
  1253. kfree(req);
  1254. return -ENOMEM;
  1255. }
  1256. req->mode = mode;
  1257. req->hw_debug_valid = 1;
  1258. req->hw_debug = !!test_bit(HW_DEBUG_ENABLE, &priv->ctrl_params.quirks);
  1259. if (priv->wlan_en_delay_ms >= 100) {
  1260. icnss_pr_dbg("Setting WLAN_EN delay: %d ms\n",
  1261. priv->wlan_en_delay_ms);
  1262. req->wlan_en_delay_valid = 1;
  1263. req->wlan_en_delay = priv->wlan_en_delay_ms;
  1264. }
  1265. priv->stats.mode_req++;
  1266. ret = qmi_txn_init(&priv->qmi, &txn,
  1267. wlfw_wlan_mode_resp_msg_v01_ei, resp);
  1268. if (ret < 0) {
  1269. icnss_qmi_fatal_err("Fail to init txn for Mode resp %d\n", ret);
  1270. goto out;
  1271. }
  1272. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  1273. QMI_WLFW_WLAN_MODE_REQ_V01,
  1274. WLFW_WLAN_MODE_REQ_MSG_V01_MAX_MSG_LEN,
  1275. wlfw_wlan_mode_req_msg_v01_ei, req);
  1276. if (ret < 0) {
  1277. qmi_txn_cancel(&txn);
  1278. icnss_qmi_fatal_err("Fail to send Mode req %d\n", ret);
  1279. goto out;
  1280. }
  1281. ret = qmi_txn_wait(&txn,
  1282. priv->ctrl_params.qmi_timeout +
  1283. msecs_to_jiffies(priv->wlan_en_delay_ms));
  1284. if (ret < 0) {
  1285. icnss_qmi_fatal_err("Mode resp wait failed with ret %d\n", ret);
  1286. goto out;
  1287. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1288. icnss_qmi_fatal_err(
  1289. "QMI Mode request rejected, result:%d error:%d\n",
  1290. resp->resp.result, resp->resp.error);
  1291. ret = -resp->resp.result;
  1292. goto out;
  1293. }
  1294. priv->stats.mode_resp++;
  1295. if (mode == QMI_WLFW_OFF_V01) {
  1296. icnss_pr_dbg("Clear mode on 0x%lx, mode: %d\n",
  1297. priv->state, mode);
  1298. clear_bit(ICNSS_MODE_ON, &priv->state);
  1299. } else {
  1300. icnss_pr_dbg("Set mode on 0x%lx, mode: %d\n",
  1301. priv->state, mode);
  1302. set_bit(ICNSS_MODE_ON, &priv->state);
  1303. }
  1304. kfree(resp);
  1305. kfree(req);
  1306. return 0;
  1307. out:
  1308. kfree(resp);
  1309. kfree(req);
  1310. priv->stats.mode_req_err++;
  1311. return ret;
  1312. }
  1313. static int wlfw_send_qdss_trace_mode_req
  1314. (struct icnss_priv *priv,
  1315. enum wlfw_qdss_trace_mode_enum_v01 mode,
  1316. unsigned long long option)
  1317. {
  1318. int rc = 0;
  1319. int tmp = 0;
  1320. struct wlfw_qdss_trace_mode_req_msg_v01 *req;
  1321. struct wlfw_qdss_trace_mode_resp_msg_v01 *resp;
  1322. struct qmi_txn txn;
  1323. if (!priv)
  1324. return -ENODEV;
  1325. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1326. if (!req)
  1327. return -ENOMEM;
  1328. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1329. if (!resp) {
  1330. kfree(req);
  1331. return -ENOMEM;
  1332. }
  1333. req->mode_valid = 1;
  1334. req->mode = mode;
  1335. req->option_valid = 1;
  1336. req->option = option;
  1337. tmp = priv->hw_trc_override;
  1338. req->hw_trc_disable_override_valid = 1;
  1339. req->hw_trc_disable_override =
  1340. (tmp > QMI_PARAM_DISABLE_V01 ? QMI_PARAM_DISABLE_V01 :
  1341. (tmp < 0 ? QMI_PARAM_INVALID_V01 : tmp));
  1342. icnss_pr_dbg("%s: mode %u, option %llu, hw_trc_disable_override: %u",
  1343. __func__, mode, option, req->hw_trc_disable_override);
  1344. rc = qmi_txn_init(&priv->qmi, &txn,
  1345. wlfw_qdss_trace_mode_resp_msg_v01_ei, resp);
  1346. if (rc < 0) {
  1347. icnss_qmi_fatal_err("Fail to init txn for QDSS Mode resp %d\n",
  1348. rc);
  1349. goto out;
  1350. }
  1351. rc = qmi_send_request(&priv->qmi, NULL, &txn,
  1352. QMI_WLFW_QDSS_TRACE_MODE_REQ_V01,
  1353. WLFW_QDSS_TRACE_MODE_REQ_MSG_V01_MAX_MSG_LEN,
  1354. wlfw_qdss_trace_mode_req_msg_v01_ei, req);
  1355. if (rc < 0) {
  1356. qmi_txn_cancel(&txn);
  1357. icnss_qmi_fatal_err("Fail to send QDSS Mode req %d\n", rc);
  1358. goto out;
  1359. }
  1360. rc = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  1361. if (rc < 0) {
  1362. icnss_qmi_fatal_err("QDSS Mode resp wait failed with rc %d\n",
  1363. rc);
  1364. goto out;
  1365. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1366. icnss_qmi_fatal_err(
  1367. "QMI QDSS Mode request rejected, result:%d error:%d\n",
  1368. resp->resp.result, resp->resp.error);
  1369. rc = -resp->resp.result;
  1370. goto out;
  1371. }
  1372. out:
  1373. kfree(resp);
  1374. kfree(req);
  1375. return rc;
  1376. }
  1377. int wlfw_qdss_trace_start(struct icnss_priv *priv)
  1378. {
  1379. return wlfw_send_qdss_trace_mode_req(priv,
  1380. QMI_WLFW_QDSS_TRACE_ON_V01, 0);
  1381. }
  1382. int wlfw_qdss_trace_stop(struct icnss_priv *priv, unsigned long long option)
  1383. {
  1384. return wlfw_send_qdss_trace_mode_req(priv, QMI_WLFW_QDSS_TRACE_OFF_V01,
  1385. option);
  1386. }
  1387. int wlfw_wlan_cfg_send_sync_msg(struct icnss_priv *priv,
  1388. struct wlfw_wlan_cfg_req_msg_v01 *data)
  1389. {
  1390. int ret;
  1391. struct wlfw_wlan_cfg_req_msg_v01 *req;
  1392. struct wlfw_wlan_cfg_resp_msg_v01 *resp;
  1393. struct qmi_txn txn;
  1394. if (!priv)
  1395. return -ENODEV;
  1396. icnss_pr_dbg("Sending config request, state: 0x%lx\n", priv->state);
  1397. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1398. if (!req)
  1399. return -ENOMEM;
  1400. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1401. if (!resp) {
  1402. kfree(req);
  1403. return -ENOMEM;
  1404. }
  1405. memcpy(req, data, sizeof(*req));
  1406. priv->stats.cfg_req++;
  1407. ret = qmi_txn_init(&priv->qmi, &txn,
  1408. wlfw_wlan_cfg_resp_msg_v01_ei, resp);
  1409. if (ret < 0) {
  1410. icnss_qmi_fatal_err("Fail to init txn for Config resp %d\n",
  1411. ret);
  1412. goto out;
  1413. }
  1414. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  1415. QMI_WLFW_WLAN_CFG_REQ_V01,
  1416. WLFW_WLAN_CFG_REQ_MSG_V01_MAX_MSG_LEN,
  1417. wlfw_wlan_cfg_req_msg_v01_ei, req);
  1418. if (ret < 0) {
  1419. qmi_txn_cancel(&txn);
  1420. icnss_qmi_fatal_err("Fail to send Config req %d\n", ret);
  1421. goto out;
  1422. }
  1423. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  1424. if (ret < 0) {
  1425. icnss_qmi_fatal_err("Config resp wait failed with ret %d\n",
  1426. ret);
  1427. goto out;
  1428. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1429. icnss_qmi_fatal_err(
  1430. "QMI Config request rejected, result:%d error:%d\n",
  1431. resp->resp.result, resp->resp.error);
  1432. ret = -resp->resp.result;
  1433. goto out;
  1434. }
  1435. priv->stats.cfg_resp++;
  1436. kfree(resp);
  1437. kfree(req);
  1438. return 0;
  1439. out:
  1440. kfree(resp);
  1441. kfree(req);
  1442. priv->stats.cfg_req_err++;
  1443. return ret;
  1444. }
  1445. int wlfw_send_modem_shutdown_msg(struct icnss_priv *priv)
  1446. {
  1447. int ret;
  1448. struct wlfw_shutdown_req_msg_v01 *req;
  1449. struct wlfw_shutdown_resp_msg_v01 *resp;
  1450. struct qmi_txn txn;
  1451. if (!priv)
  1452. return -ENODEV;
  1453. if (test_bit(ICNSS_FW_DOWN, &priv->state))
  1454. return -EINVAL;
  1455. icnss_pr_dbg("Sending modem shutdown request, state: 0x%lx\n",
  1456. priv->state);
  1457. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1458. if (!req)
  1459. return -ENOMEM;
  1460. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1461. if (!resp) {
  1462. kfree(req);
  1463. return -ENOMEM;
  1464. }
  1465. req->shutdown_valid = 1;
  1466. req->shutdown = 1;
  1467. ret = qmi_txn_init(&priv->qmi, &txn,
  1468. wlfw_shutdown_resp_msg_v01_ei, resp);
  1469. if (ret < 0) {
  1470. icnss_pr_err("Fail to init txn for shutdown resp %d\n",
  1471. ret);
  1472. goto out;
  1473. }
  1474. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  1475. QMI_WLFW_SHUTDOWN_REQ_V01,
  1476. WLFW_SHUTDOWN_REQ_MSG_V01_MAX_MSG_LEN,
  1477. wlfw_shutdown_req_msg_v01_ei, req);
  1478. if (ret < 0) {
  1479. qmi_txn_cancel(&txn);
  1480. icnss_pr_err("Fail to send Shutdown req %d\n", ret);
  1481. goto out;
  1482. }
  1483. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  1484. if (ret < 0) {
  1485. icnss_pr_err("Shutdown resp wait failed with ret %d\n",
  1486. ret);
  1487. goto out;
  1488. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1489. icnss_pr_err("QMI modem shutdown request rejected result:%d error:%d\n",
  1490. resp->resp.result, resp->resp.error);
  1491. ret = -resp->resp.result;
  1492. goto out;
  1493. }
  1494. out:
  1495. kfree(resp);
  1496. kfree(req);
  1497. return ret;
  1498. }
  1499. int wlfw_ini_send_sync_msg(struct icnss_priv *priv, uint8_t fw_log_mode)
  1500. {
  1501. int ret;
  1502. struct wlfw_ini_req_msg_v01 *req;
  1503. struct wlfw_ini_resp_msg_v01 *resp;
  1504. struct qmi_txn txn;
  1505. if (!priv)
  1506. return -ENODEV;
  1507. icnss_pr_dbg("Sending ini sync request, state: 0x%lx, fw_log_mode: %d\n",
  1508. priv->state, fw_log_mode);
  1509. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1510. if (!req)
  1511. return -ENOMEM;
  1512. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1513. if (!resp) {
  1514. kfree(req);
  1515. return -ENOMEM;
  1516. }
  1517. req->enablefwlog_valid = 1;
  1518. req->enablefwlog = fw_log_mode;
  1519. priv->stats.ini_req++;
  1520. ret = qmi_txn_init(&priv->qmi, &txn, wlfw_ini_resp_msg_v01_ei, resp);
  1521. if (ret < 0) {
  1522. icnss_qmi_fatal_err("Fail to init txn for INI resp %d\n", ret);
  1523. goto out;
  1524. }
  1525. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  1526. QMI_WLFW_INI_REQ_V01,
  1527. WLFW_INI_REQ_MSG_V01_MAX_MSG_LEN,
  1528. wlfw_ini_req_msg_v01_ei, req);
  1529. if (ret < 0) {
  1530. qmi_txn_cancel(&txn);
  1531. icnss_qmi_fatal_err("Fail to send INI req %d\n", ret);
  1532. goto out;
  1533. }
  1534. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  1535. if (ret < 0) {
  1536. icnss_qmi_fatal_err("INI resp wait failed with ret %d\n", ret);
  1537. goto out;
  1538. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1539. icnss_qmi_fatal_err(
  1540. "QMI INI request rejected, result:%d error:%d\n",
  1541. resp->resp.result, resp->resp.error);
  1542. ret = -resp->resp.result;
  1543. goto out;
  1544. }
  1545. priv->stats.ini_resp++;
  1546. kfree(resp);
  1547. kfree(req);
  1548. return 0;
  1549. out:
  1550. kfree(resp);
  1551. kfree(req);
  1552. priv->stats.ini_req_err++;
  1553. return ret;
  1554. }
  1555. int wlfw_athdiag_read_send_sync_msg(struct icnss_priv *priv,
  1556. uint32_t offset, uint32_t mem_type,
  1557. uint32_t data_len, uint8_t *data)
  1558. {
  1559. int ret;
  1560. struct wlfw_athdiag_read_req_msg_v01 *req;
  1561. struct wlfw_athdiag_read_resp_msg_v01 *resp;
  1562. struct qmi_txn txn;
  1563. if (!priv)
  1564. return -ENODEV;
  1565. icnss_pr_dbg("Diag read: state 0x%lx, offset %x, mem_type %x, data_len %u\n",
  1566. priv->state, offset, mem_type, data_len);
  1567. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1568. if (!req)
  1569. return -ENOMEM;
  1570. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1571. if (!resp) {
  1572. kfree(req);
  1573. return -ENOMEM;
  1574. }
  1575. req->offset = offset;
  1576. req->mem_type = mem_type;
  1577. req->data_len = data_len;
  1578. ret = qmi_txn_init(&priv->qmi, &txn,
  1579. wlfw_athdiag_read_resp_msg_v01_ei, resp);
  1580. if (ret < 0) {
  1581. icnss_pr_err("Fail to init txn for Athdiag Read resp %d\n",
  1582. ret);
  1583. goto out;
  1584. }
  1585. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  1586. QMI_WLFW_ATHDIAG_READ_REQ_V01,
  1587. WLFW_ATHDIAG_READ_REQ_MSG_V01_MAX_MSG_LEN,
  1588. wlfw_athdiag_read_req_msg_v01_ei, req);
  1589. if (ret < 0) {
  1590. qmi_txn_cancel(&txn);
  1591. icnss_pr_err("Fail to send Athdiag Read req %d\n", ret);
  1592. goto out;
  1593. }
  1594. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  1595. if (ret < 0) {
  1596. icnss_pr_err("Athdaig Read resp wait failed with ret %d\n",
  1597. ret);
  1598. goto out;
  1599. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1600. icnss_pr_err("QMI Athdiag Read request rejected, result:%d error:%d\n",
  1601. resp->resp.result, resp->resp.error);
  1602. ret = -resp->resp.result;
  1603. goto out;
  1604. } else {
  1605. ret = 0;
  1606. }
  1607. if (!resp->data_valid || resp->data_len < data_len) {
  1608. icnss_pr_err("Athdiag read data is invalid, data_valid = %u, data_len = %u\n",
  1609. resp->data_valid, resp->data_len);
  1610. ret = -EINVAL;
  1611. goto out;
  1612. }
  1613. memcpy(data, resp->data, resp->data_len);
  1614. out:
  1615. kfree(resp);
  1616. kfree(req);
  1617. return ret;
  1618. }
  1619. int wlfw_athdiag_write_send_sync_msg(struct icnss_priv *priv,
  1620. uint32_t offset, uint32_t mem_type,
  1621. uint32_t data_len, uint8_t *data)
  1622. {
  1623. int ret;
  1624. struct wlfw_athdiag_write_req_msg_v01 *req;
  1625. struct wlfw_athdiag_write_resp_msg_v01 *resp;
  1626. struct qmi_txn txn;
  1627. if (!priv)
  1628. return -ENODEV;
  1629. icnss_pr_dbg("Diag write: state 0x%lx, offset %x, mem_type %x, data_len %u, data %pK\n",
  1630. priv->state, offset, mem_type, data_len, data);
  1631. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1632. if (!req)
  1633. return -ENOMEM;
  1634. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1635. if (!resp) {
  1636. kfree(req);
  1637. return -ENOMEM;
  1638. }
  1639. req->offset = offset;
  1640. req->mem_type = mem_type;
  1641. req->data_len = data_len;
  1642. memcpy(req->data, data, data_len);
  1643. ret = qmi_txn_init(&priv->qmi, &txn,
  1644. wlfw_athdiag_write_resp_msg_v01_ei, resp);
  1645. if (ret < 0) {
  1646. icnss_pr_err("Fail to init txn for Athdiag Write resp %d\n",
  1647. ret);
  1648. goto out;
  1649. }
  1650. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  1651. QMI_WLFW_ATHDIAG_WRITE_REQ_V01,
  1652. WLFW_ATHDIAG_WRITE_REQ_MSG_V01_MAX_MSG_LEN,
  1653. wlfw_athdiag_write_req_msg_v01_ei, req);
  1654. if (ret < 0) {
  1655. qmi_txn_cancel(&txn);
  1656. icnss_pr_err("Fail to send Athdiag Write req %d\n", ret);
  1657. goto out;
  1658. }
  1659. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  1660. if (ret < 0) {
  1661. icnss_pr_err("Athdiag Write resp wait failed with ret %d\n",
  1662. ret);
  1663. goto out;
  1664. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1665. icnss_pr_err("QMI Athdiag Write request rejected, result:%d error:%d\n",
  1666. resp->resp.result, resp->resp.error);
  1667. ret = -resp->resp.result;
  1668. goto out;
  1669. } else {
  1670. ret = 0;
  1671. }
  1672. out:
  1673. kfree(resp);
  1674. kfree(req);
  1675. return ret;
  1676. }
  1677. int wlfw_rejuvenate_ack_send_sync_msg(struct icnss_priv *priv)
  1678. {
  1679. int ret;
  1680. struct wlfw_rejuvenate_ack_req_msg_v01 *req;
  1681. struct wlfw_rejuvenate_ack_resp_msg_v01 *resp;
  1682. struct qmi_txn txn;
  1683. if (!priv)
  1684. return -ENODEV;
  1685. icnss_pr_dbg("Sending rejuvenate ack request, state: 0x%lx\n",
  1686. priv->state);
  1687. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1688. if (!req)
  1689. return -ENOMEM;
  1690. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1691. if (!resp) {
  1692. kfree(req);
  1693. return -ENOMEM;
  1694. }
  1695. priv->stats.rejuvenate_ack_req++;
  1696. ret = qmi_txn_init(&priv->qmi, &txn,
  1697. wlfw_rejuvenate_ack_resp_msg_v01_ei, resp);
  1698. if (ret < 0) {
  1699. icnss_qmi_fatal_err(
  1700. "Fail to init txn for Rejuvenate Ack resp %d\n",
  1701. ret);
  1702. goto out;
  1703. }
  1704. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  1705. QMI_WLFW_REJUVENATE_ACK_REQ_V01,
  1706. WLFW_REJUVENATE_ACK_REQ_MSG_V01_MAX_MSG_LEN,
  1707. wlfw_rejuvenate_ack_req_msg_v01_ei, req);
  1708. if (ret < 0) {
  1709. qmi_txn_cancel(&txn);
  1710. icnss_qmi_fatal_err("Fail to send Rejuvenate Ack req %d\n",
  1711. ret);
  1712. goto out;
  1713. }
  1714. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  1715. if (ret < 0) {
  1716. icnss_qmi_fatal_err(
  1717. "Rejuvenate Ack resp wait failed with ret %d\n",
  1718. ret);
  1719. goto out;
  1720. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1721. icnss_qmi_fatal_err(
  1722. "QMI Rejuvenate Ack request rejected, result:%d error:%d\n",
  1723. resp->resp.result, resp->resp.error);
  1724. ret = -resp->resp.result;
  1725. goto out;
  1726. }
  1727. priv->stats.rejuvenate_ack_resp++;
  1728. kfree(resp);
  1729. kfree(req);
  1730. return 0;
  1731. out:
  1732. kfree(resp);
  1733. kfree(req);
  1734. priv->stats.rejuvenate_ack_err++;
  1735. return ret;
  1736. }
  1737. int wlfw_dynamic_feature_mask_send_sync_msg(struct icnss_priv *priv,
  1738. uint64_t dynamic_feature_mask)
  1739. {
  1740. int ret;
  1741. struct wlfw_dynamic_feature_mask_req_msg_v01 *req;
  1742. struct wlfw_dynamic_feature_mask_resp_msg_v01 *resp;
  1743. struct qmi_txn txn;
  1744. if (!priv)
  1745. return -ENODEV;
  1746. if (!test_bit(ICNSS_WLFW_CONNECTED, &priv->state)) {
  1747. icnss_pr_err("Invalid state for dynamic feature: 0x%lx\n",
  1748. priv->state);
  1749. return -EINVAL;
  1750. }
  1751. if (!test_bit(FW_REJUVENATE_ENABLE, &priv->ctrl_params.quirks)) {
  1752. icnss_pr_dbg("FW rejuvenate is disabled from quirks\n");
  1753. return 0;
  1754. }
  1755. icnss_pr_dbg("Sending dynamic feature mask request, val 0x%llx, state: 0x%lx\n",
  1756. dynamic_feature_mask, priv->state);
  1757. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1758. if (!req)
  1759. return -ENOMEM;
  1760. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1761. if (!resp) {
  1762. kfree(req);
  1763. return -ENOMEM;
  1764. }
  1765. req->mask_valid = 1;
  1766. req->mask = dynamic_feature_mask;
  1767. ret = qmi_txn_init(&priv->qmi, &txn,
  1768. wlfw_dynamic_feature_mask_resp_msg_v01_ei, resp);
  1769. if (ret < 0) {
  1770. icnss_pr_err("Fail to init txn for Dynamic Feature Mask resp %d\n",
  1771. ret);
  1772. goto out;
  1773. }
  1774. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  1775. QMI_WLFW_DYNAMIC_FEATURE_MASK_REQ_V01,
  1776. WLFW_DYNAMIC_FEATURE_MASK_REQ_MSG_V01_MAX_MSG_LEN,
  1777. wlfw_dynamic_feature_mask_req_msg_v01_ei, req);
  1778. if (ret < 0) {
  1779. qmi_txn_cancel(&txn);
  1780. icnss_pr_err("Fail to send Dynamic Feature Mask req %d\n", ret);
  1781. goto out;
  1782. }
  1783. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  1784. if (ret < 0) {
  1785. icnss_pr_err("Dynamic Feature Mask resp wait failed with ret %d\n",
  1786. ret);
  1787. goto out;
  1788. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1789. icnss_pr_err("QMI Dynamic Feature Mask request rejected, result:%d error:%d\n",
  1790. resp->resp.result, resp->resp.error);
  1791. ret = -resp->resp.result;
  1792. goto out;
  1793. }
  1794. icnss_pr_dbg("prev_mask_valid %u, prev_mask 0x%llx, curr_maks_valid %u, curr_mask 0x%llx\n",
  1795. resp->prev_mask_valid, resp->prev_mask,
  1796. resp->curr_mask_valid, resp->curr_mask);
  1797. out:
  1798. kfree(resp);
  1799. kfree(req);
  1800. return ret;
  1801. }
  1802. void icnss_handle_rejuvenate(struct icnss_priv *priv)
  1803. {
  1804. struct icnss_event_pd_service_down_data *event_data;
  1805. struct icnss_uevent_fw_down_data fw_down_data = {0};
  1806. event_data = kzalloc(sizeof(*event_data), GFP_KERNEL);
  1807. if (event_data == NULL)
  1808. return;
  1809. event_data->crashed = true;
  1810. event_data->fw_rejuvenate = true;
  1811. fw_down_data.crashed = true;
  1812. set_bit(ICNSS_REJUVENATE, &priv->state);
  1813. icnss_call_driver_uevent(priv, ICNSS_UEVENT_FW_DOWN,
  1814. &fw_down_data);
  1815. icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_PD_SERVICE_DOWN,
  1816. 0, event_data);
  1817. }
  1818. int wlfw_qdss_trace_mem_info_send_sync(struct icnss_priv *priv)
  1819. {
  1820. struct wlfw_qdss_trace_mem_info_req_msg_v01 *req;
  1821. struct wlfw_qdss_trace_mem_info_resp_msg_v01 *resp;
  1822. struct qmi_txn txn;
  1823. struct icnss_fw_mem *qdss_mem = priv->qdss_mem;
  1824. int ret = 0;
  1825. int i;
  1826. if (test_bit(ICNSS_FW_DOWN, &priv->state))
  1827. return -EINVAL;
  1828. icnss_pr_dbg("Sending QDSS trace mem info, state: 0x%lx\n",
  1829. priv->state);
  1830. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1831. if (!req)
  1832. return -ENOMEM;
  1833. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1834. if (!resp) {
  1835. kfree(req);
  1836. return -ENOMEM;
  1837. }
  1838. req->mem_seg_len = priv->qdss_mem_seg_len;
  1839. if (priv->qdss_mem_seg_len > QMI_WLFW_MAX_NUM_MEM_SEG_V01) {
  1840. icnss_pr_err("Invalid seg len %u\n",
  1841. priv->qdss_mem_seg_len);
  1842. ret = -EINVAL;
  1843. goto out;
  1844. }
  1845. for (i = 0; i < req->mem_seg_len; i++) {
  1846. icnss_pr_dbg("Memory for FW, va: 0x%pK, pa: %pa, size: 0x%zx, type: %u\n",
  1847. qdss_mem[i].va, &qdss_mem[i].pa,
  1848. qdss_mem[i].size, qdss_mem[i].type);
  1849. req->mem_seg[i].addr = qdss_mem[i].pa;
  1850. req->mem_seg[i].size = qdss_mem[i].size;
  1851. req->mem_seg[i].type = qdss_mem[i].type;
  1852. }
  1853. ret = qmi_txn_init(&priv->qmi, &txn,
  1854. wlfw_qdss_trace_mem_info_resp_msg_v01_ei, resp);
  1855. if (ret < 0) {
  1856. icnss_pr_err("Fail to initialize txn for QDSS trace mem request: err %d\n",
  1857. ret);
  1858. goto out;
  1859. }
  1860. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  1861. QMI_WLFW_QDSS_TRACE_MEM_INFO_REQ_V01,
  1862. WLFW_QDSS_TRACE_MEM_INFO_REQ_MSG_V01_MAX_MSG_LEN,
  1863. wlfw_qdss_trace_mem_info_req_msg_v01_ei, req);
  1864. if (ret < 0) {
  1865. qmi_txn_cancel(&txn);
  1866. icnss_pr_err("Fail to send QDSS trace mem info request: err %d\n",
  1867. ret);
  1868. goto out;
  1869. }
  1870. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  1871. if (ret < 0) {
  1872. icnss_pr_err("Fail to wait for response of QDSS trace mem info request, err %d\n",
  1873. ret);
  1874. goto out;
  1875. }
  1876. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1877. icnss_pr_err("QDSS trace mem info request failed, result: %d, err: %d\n",
  1878. resp->resp.result, resp->resp.error);
  1879. ret = -resp->resp.result;
  1880. goto out;
  1881. }
  1882. kfree(req);
  1883. kfree(resp);
  1884. return 0;
  1885. out:
  1886. kfree(req);
  1887. kfree(resp);
  1888. return ret;
  1889. }
  1890. int icnss_wlfw_m3_dump_upload_done_send_sync(struct icnss_priv *priv,
  1891. u32 pdev_id, int status)
  1892. {
  1893. struct wlfw_m3_dump_upload_done_req_msg_v01 *req;
  1894. struct wlfw_m3_dump_upload_done_resp_msg_v01 *resp;
  1895. struct qmi_txn txn;
  1896. int ret = 0;
  1897. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1898. if (!req)
  1899. return -ENOMEM;
  1900. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1901. if (!resp) {
  1902. kfree(req);
  1903. return -ENOMEM;
  1904. }
  1905. icnss_pr_dbg("Sending M3 Upload done req, pdev %d, status %d\n",
  1906. pdev_id, status);
  1907. req->pdev_id = pdev_id;
  1908. req->status = status;
  1909. ret = qmi_txn_init(&priv->qmi, &txn,
  1910. wlfw_m3_dump_upload_done_resp_msg_v01_ei, resp);
  1911. if (ret < 0) {
  1912. icnss_pr_err("Fail to initialize txn for M3 dump upload done req: err %d\n",
  1913. ret);
  1914. goto out;
  1915. }
  1916. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  1917. QMI_WLFW_M3_DUMP_UPLOAD_DONE_REQ_V01,
  1918. WLFW_M3_DUMP_UPLOAD_DONE_REQ_MSG_V01_MAX_MSG_LEN,
  1919. wlfw_m3_dump_upload_done_req_msg_v01_ei, req);
  1920. if (ret < 0) {
  1921. qmi_txn_cancel(&txn);
  1922. icnss_pr_err("Fail to send M3 dump upload done request: err %d\n",
  1923. ret);
  1924. goto out;
  1925. }
  1926. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  1927. if (ret < 0) {
  1928. icnss_pr_err("Fail to wait for response of M3 dump upload done request, err %d\n",
  1929. ret);
  1930. goto out;
  1931. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1932. icnss_pr_err("M3 Dump Upload Done Req failed, result: %d, err: 0x%X\n",
  1933. resp->resp.result, resp->resp.error);
  1934. ret = -resp->resp.result;
  1935. goto out;
  1936. }
  1937. out:
  1938. kfree(req);
  1939. kfree(resp);
  1940. return ret;
  1941. }
  1942. static void fw_ready_ind_cb(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
  1943. struct qmi_txn *txn, const void *data)
  1944. {
  1945. struct icnss_priv *priv =
  1946. container_of(qmi, struct icnss_priv, qmi);
  1947. icnss_pr_dbg("Received FW Ready Indication\n");
  1948. if (!txn) {
  1949. pr_err("spurious indication\n");
  1950. return;
  1951. }
  1952. icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_FW_READY_IND,
  1953. 0, NULL);
  1954. }
  1955. static void msa_ready_ind_cb(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
  1956. struct qmi_txn *txn, const void *data)
  1957. {
  1958. struct icnss_priv *priv = container_of(qmi, struct icnss_priv, qmi);
  1959. struct device *dev = &priv->pdev->dev;
  1960. const struct wlfw_msa_ready_ind_msg_v01 *ind_msg = data;
  1961. uint64_t msa_base_addr = priv->msa_pa;
  1962. phys_addr_t hang_data_phy_addr;
  1963. icnss_pr_dbg("Received MSA Ready Indication\n");
  1964. if (!txn) {
  1965. pr_err("spurious indication\n");
  1966. return;
  1967. }
  1968. priv->stats.msa_ready_ind++;
  1969. /* Check if the length is valid &
  1970. * the length should not be 0 and
  1971. * should be <= WLFW_MAX_HANG_EVENT_DATA_SIZE(400)
  1972. */
  1973. if (ind_msg->hang_data_length_valid &&
  1974. ind_msg->hang_data_length &&
  1975. ind_msg->hang_data_length <= WLFW_MAX_HANG_EVENT_DATA_SIZE)
  1976. priv->hang_event_data_len = ind_msg->hang_data_length;
  1977. else
  1978. goto out;
  1979. /* Check if the offset is valid &
  1980. * the offset should be in range of 0 to msa_mem_size-hang_data_length
  1981. */
  1982. if (ind_msg->hang_data_addr_offset_valid &&
  1983. (ind_msg->hang_data_addr_offset <= (priv->msa_mem_size -
  1984. ind_msg->hang_data_length)))
  1985. hang_data_phy_addr = msa_base_addr +
  1986. ind_msg->hang_data_addr_offset;
  1987. else
  1988. goto out;
  1989. if (priv->hang_event_data_pa == hang_data_phy_addr)
  1990. goto exit;
  1991. priv->hang_event_data_pa = hang_data_phy_addr;
  1992. priv->hang_event_data_va = devm_ioremap(dev, priv->hang_event_data_pa,
  1993. ind_msg->hang_data_length);
  1994. if (!priv->hang_event_data_va) {
  1995. icnss_pr_err("Hang Data ioremap failed: phy addr: %pa\n",
  1996. &priv->hang_event_data_pa);
  1997. goto fail;
  1998. }
  1999. exit:
  2000. icnss_pr_dbg("Hang Event Data details,Offset:0x%x, Length:0x%x,va_addr: 0x%pK\n",
  2001. ind_msg->hang_data_addr_offset,
  2002. ind_msg->hang_data_length,
  2003. priv->hang_event_data_va);
  2004. return;
  2005. out:
  2006. icnss_pr_err("Invalid Hang Data details, Offset:0x%x, Length:0x%x",
  2007. ind_msg->hang_data_addr_offset,
  2008. ind_msg->hang_data_length);
  2009. fail:
  2010. priv->hang_event_data_va = NULL;
  2011. priv->hang_event_data_pa = 0;
  2012. priv->hang_event_data_len = 0;
  2013. }
  2014. static void pin_connect_result_ind_cb(struct qmi_handle *qmi,
  2015. struct sockaddr_qrtr *sq,
  2016. struct qmi_txn *txn, const void *data)
  2017. {
  2018. struct icnss_priv *priv = container_of(qmi, struct icnss_priv, qmi);
  2019. const struct wlfw_pin_connect_result_ind_msg_v01 *ind_msg = data;
  2020. icnss_pr_dbg("Received Pin Connect Result Indication\n");
  2021. if (!txn) {
  2022. pr_err("spurious indication\n");
  2023. return;
  2024. }
  2025. if (ind_msg->pwr_pin_result_valid)
  2026. priv->pwr_pin_result = ind_msg->pwr_pin_result;
  2027. if (ind_msg->phy_io_pin_result_valid)
  2028. priv->phy_io_pin_result = ind_msg->phy_io_pin_result;
  2029. if (ind_msg->rf_pin_result_valid)
  2030. priv->rf_pin_result = ind_msg->rf_pin_result;
  2031. icnss_pr_dbg("Pin connect Result: pwr_pin: 0x%x phy_io_pin: 0x%x rf_io_pin: 0x%x\n",
  2032. ind_msg->pwr_pin_result, ind_msg->phy_io_pin_result,
  2033. ind_msg->rf_pin_result);
  2034. priv->stats.pin_connect_result++;
  2035. }
  2036. static void rejuvenate_ind_cb(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
  2037. struct qmi_txn *txn, const void *data)
  2038. {
  2039. struct icnss_priv *priv = container_of(qmi, struct icnss_priv, qmi);
  2040. const struct wlfw_rejuvenate_ind_msg_v01 *ind_msg = data;
  2041. icnss_pr_dbg("Received Rejuvenate Indication\n");
  2042. if (!txn) {
  2043. pr_err("spurious indication\n");
  2044. return;
  2045. }
  2046. icnss_ignore_fw_timeout(true);
  2047. if (ind_msg->cause_for_rejuvenation_valid)
  2048. priv->cause_for_rejuvenation = ind_msg->cause_for_rejuvenation;
  2049. else
  2050. priv->cause_for_rejuvenation = 0;
  2051. if (ind_msg->requesting_sub_system_valid)
  2052. priv->requesting_sub_system = ind_msg->requesting_sub_system;
  2053. else
  2054. priv->requesting_sub_system = 0;
  2055. if (ind_msg->line_number_valid)
  2056. priv->line_number = ind_msg->line_number;
  2057. else
  2058. priv->line_number = 0;
  2059. if (ind_msg->function_name_valid)
  2060. memcpy(priv->function_name, ind_msg->function_name,
  2061. QMI_WLFW_FUNCTION_NAME_LEN_V01 + 1);
  2062. else
  2063. memset(priv->function_name, 0,
  2064. QMI_WLFW_FUNCTION_NAME_LEN_V01 + 1);
  2065. icnss_pr_info("Cause for rejuvenation: 0x%x, requesting sub-system: 0x%x, line number: %u, function name: %s\n",
  2066. priv->cause_for_rejuvenation,
  2067. priv->requesting_sub_system,
  2068. priv->line_number,
  2069. priv->function_name);
  2070. priv->stats.rejuvenate_ind++;
  2071. icnss_handle_rejuvenate(priv);
  2072. }
  2073. static void cal_done_ind_cb(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
  2074. struct qmi_txn *txn, const void *data)
  2075. {
  2076. struct icnss_priv *priv = container_of(qmi, struct icnss_priv, qmi);
  2077. icnss_pr_dbg("Received QMI WLFW calibration done indication\n");
  2078. if (!txn) {
  2079. icnss_pr_err("Spurious indication\n");
  2080. return;
  2081. }
  2082. priv->cal_done = true;
  2083. clear_bit(ICNSS_COLD_BOOT_CAL, &priv->state);
  2084. }
  2085. static void fw_init_done_ind_cb(struct qmi_handle *qmi,
  2086. struct sockaddr_qrtr *sq,
  2087. struct qmi_txn *txn, const void *data)
  2088. {
  2089. struct icnss_priv *priv = container_of(qmi, struct icnss_priv, qmi);
  2090. struct device *dev = &priv->pdev->dev;
  2091. const struct wlfw_fw_init_done_ind_msg_v01 *ind_msg = data;
  2092. uint64_t msa_base_addr = priv->msa_pa;
  2093. phys_addr_t hang_data_phy_addr;
  2094. icnss_pr_dbg("Received QMI WLFW FW initialization done indication\n");
  2095. if (!txn) {
  2096. icnss_pr_err("Spurious indication\n");
  2097. return;
  2098. }
  2099. /* Check if the length is valid &
  2100. * the length should not be 0 and
  2101. * should be <= WLFW_MAX_HANG_EVENT_DATA_SIZE(400)
  2102. */
  2103. if (ind_msg->hang_data_length_valid &&
  2104. ind_msg->hang_data_length &&
  2105. ind_msg->hang_data_length <= WLFW_MAX_HANG_EVENT_DATA_SIZE)
  2106. priv->hang_event_data_len = ind_msg->hang_data_length;
  2107. else
  2108. goto out;
  2109. /* Check if the offset is valid &
  2110. * the offset should be in range of 0 to msa_mem_size-hang_data_length
  2111. */
  2112. if (ind_msg->hang_data_addr_offset_valid &&
  2113. (ind_msg->hang_data_addr_offset <= (priv->msa_mem_size -
  2114. ind_msg->hang_data_length)))
  2115. hang_data_phy_addr = msa_base_addr +
  2116. ind_msg->hang_data_addr_offset;
  2117. else
  2118. goto out;
  2119. if (priv->hang_event_data_pa == hang_data_phy_addr)
  2120. goto exit;
  2121. priv->hang_event_data_pa = hang_data_phy_addr;
  2122. priv->hang_event_data_va = devm_ioremap(dev, priv->hang_event_data_pa,
  2123. ind_msg->hang_data_length);
  2124. if (!priv->hang_event_data_va) {
  2125. icnss_pr_err("Hang Data ioremap failed: phy addr: %pa\n",
  2126. &priv->hang_event_data_pa);
  2127. goto fail;
  2128. }
  2129. exit:
  2130. icnss_pr_dbg("Hang Event Data details,Offset:0x%x, Length:0x%x,va_addr: 0x%pK\n",
  2131. ind_msg->hang_data_addr_offset,
  2132. ind_msg->hang_data_length,
  2133. priv->hang_event_data_va);
  2134. goto post;
  2135. out:
  2136. icnss_pr_err("Invalid Hang Data details, Offset:0x%x, Length:0x%x",
  2137. ind_msg->hang_data_addr_offset,
  2138. ind_msg->hang_data_length);
  2139. fail:
  2140. priv->hang_event_data_va = NULL;
  2141. priv->hang_event_data_pa = 0;
  2142. priv->hang_event_data_len = 0;
  2143. post:
  2144. icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_FW_INIT_DONE_IND,
  2145. 0, NULL);
  2146. }
  2147. static void wlfw_qdss_trace_req_mem_ind_cb(struct qmi_handle *qmi,
  2148. struct sockaddr_qrtr *sq,
  2149. struct qmi_txn *txn,
  2150. const void *data)
  2151. {
  2152. struct icnss_priv *priv =
  2153. container_of(qmi, struct icnss_priv, qmi);
  2154. const struct wlfw_qdss_trace_req_mem_ind_msg_v01 *ind_msg = data;
  2155. int i;
  2156. icnss_pr_dbg("Received QMI WLFW QDSS trace request mem indication\n");
  2157. if (!txn) {
  2158. icnss_pr_err("Spurious indication\n");
  2159. return;
  2160. }
  2161. if (priv->qdss_mem_seg_len) {
  2162. icnss_pr_err("Ignore double allocation for QDSS trace, current len %u\n",
  2163. priv->qdss_mem_seg_len);
  2164. return;
  2165. }
  2166. priv->qdss_mem_seg_len = ind_msg->mem_seg_len;
  2167. if (priv->qdss_mem_seg_len > QMI_WLFW_MAX_NUM_MEM_SEG_V01) {
  2168. icnss_pr_err("Invalid seg len %u\n",
  2169. priv->qdss_mem_seg_len);
  2170. return;
  2171. }
  2172. for (i = 0; i < priv->qdss_mem_seg_len; i++) {
  2173. icnss_pr_dbg("QDSS requests for memory, size: 0x%x, type: %u\n",
  2174. ind_msg->mem_seg[i].size,
  2175. ind_msg->mem_seg[i].type);
  2176. priv->qdss_mem[i].type = ind_msg->mem_seg[i].type;
  2177. priv->qdss_mem[i].size = ind_msg->mem_seg[i].size;
  2178. }
  2179. icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_QDSS_TRACE_REQ_MEM,
  2180. 0, NULL);
  2181. }
  2182. static void wlfw_qdss_trace_save_ind_cb(struct qmi_handle *qmi,
  2183. struct sockaddr_qrtr *sq,
  2184. struct qmi_txn *txn,
  2185. const void *data)
  2186. {
  2187. struct icnss_priv *priv =
  2188. container_of(qmi, struct icnss_priv, qmi);
  2189. const struct wlfw_qdss_trace_save_ind_msg_v01 *ind_msg = data;
  2190. struct icnss_qmi_event_qdss_trace_save_data *event_data;
  2191. int i = 0;
  2192. icnss_pr_dbg("Received QMI WLFW QDSS trace save indication\n");
  2193. if (!txn) {
  2194. icnss_pr_err("Spurious indication\n");
  2195. return;
  2196. }
  2197. icnss_pr_dbg("QDSS_trace_save info: source %u, total_size %u, file_name_valid %u, file_name %s\n",
  2198. ind_msg->source, ind_msg->total_size,
  2199. ind_msg->file_name_valid, ind_msg->file_name);
  2200. event_data = kzalloc(sizeof(*event_data), GFP_KERNEL);
  2201. if (!event_data)
  2202. return;
  2203. if (ind_msg->mem_seg_valid) {
  2204. if (ind_msg->mem_seg_len > QDSS_TRACE_SEG_LEN_MAX) {
  2205. icnss_pr_err("Invalid seg len %u\n",
  2206. ind_msg->mem_seg_len);
  2207. goto free_event_data;
  2208. }
  2209. icnss_pr_dbg("QDSS_trace_save seg len %u\n",
  2210. ind_msg->mem_seg_len);
  2211. event_data->mem_seg_len = ind_msg->mem_seg_len;
  2212. for (i = 0; i < ind_msg->mem_seg_len; i++) {
  2213. event_data->mem_seg[i].addr = ind_msg->mem_seg[i].addr;
  2214. event_data->mem_seg[i].size = ind_msg->mem_seg[i].size;
  2215. icnss_pr_dbg("seg-%d: addr 0x%llx size 0x%x\n",
  2216. i, ind_msg->mem_seg[i].addr,
  2217. ind_msg->mem_seg[i].size);
  2218. }
  2219. }
  2220. event_data->total_size = ind_msg->total_size;
  2221. if (ind_msg->file_name_valid)
  2222. strlcpy(event_data->file_name, ind_msg->file_name,
  2223. QDSS_TRACE_FILE_NAME_MAX + 1);
  2224. if (ind_msg->source == 1) {
  2225. if (!ind_msg->file_name_valid)
  2226. strlcpy(event_data->file_name, "qdss_trace_wcss_etb",
  2227. QDSS_TRACE_FILE_NAME_MAX + 1);
  2228. icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_QDSS_TRACE_REQ_DATA,
  2229. 0, event_data);
  2230. } else {
  2231. if (!ind_msg->file_name_valid)
  2232. strlcpy(event_data->file_name, "qdss_trace_ddr",
  2233. QDSS_TRACE_FILE_NAME_MAX + 1);
  2234. icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_QDSS_TRACE_SAVE,
  2235. 0, event_data);
  2236. }
  2237. return;
  2238. free_event_data:
  2239. kfree(event_data);
  2240. }
  2241. static void wlfw_qdss_trace_free_ind_cb(struct qmi_handle *qmi,
  2242. struct sockaddr_qrtr *sq,
  2243. struct qmi_txn *txn,
  2244. const void *data)
  2245. {
  2246. struct icnss_priv *priv =
  2247. container_of(qmi, struct icnss_priv, qmi);
  2248. icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_QDSS_TRACE_FREE,
  2249. 0, NULL);
  2250. }
  2251. static void icnss_wlfw_respond_get_info_ind_cb(struct qmi_handle *qmi,
  2252. struct sockaddr_qrtr *sq,
  2253. struct qmi_txn *txn,
  2254. const void *data)
  2255. {
  2256. struct icnss_priv *priv = container_of(qmi, struct icnss_priv, qmi);
  2257. const struct wlfw_respond_get_info_ind_msg_v01 *ind_msg = data;
  2258. if (!txn) {
  2259. icnss_pr_err("Spurious indication\n");
  2260. return;
  2261. }
  2262. icnss_pr_vdbg("Extract message with event length: %d, type: %d, is last: %d, seq no: %d\n",
  2263. ind_msg->data_len, ind_msg->type,
  2264. ind_msg->is_last, ind_msg->seq_no);
  2265. if (priv->get_info_cb_ctx && priv->get_info_cb)
  2266. priv->get_info_cb(priv->get_info_cb_ctx,
  2267. (void *)ind_msg->data,
  2268. ind_msg->data_len);
  2269. }
  2270. static void icnss_wlfw_m3_dump_upload_segs_req_ind_cb(struct qmi_handle *qmi,
  2271. struct sockaddr_qrtr *sq,
  2272. struct qmi_txn *txn,
  2273. const void *d)
  2274. {
  2275. struct icnss_priv *priv = container_of(qmi, struct icnss_priv, qmi);
  2276. const struct wlfw_m3_dump_upload_segments_req_ind_msg_v01 *ind_msg = d;
  2277. struct icnss_m3_upload_segments_req_data *event_data = NULL;
  2278. u64 max_mapped_addr = 0;
  2279. u64 segment_addr = 0;
  2280. int i = 0;
  2281. icnss_pr_dbg("Received QMI WLFW M3 dump upload sigments indication\n");
  2282. if (!txn) {
  2283. icnss_pr_err("Spurious indication\n");
  2284. return;
  2285. }
  2286. icnss_pr_dbg("M3 Dump upload info: pdev_id: %d no_of_segments: %d\n",
  2287. ind_msg->pdev_id, ind_msg->no_of_valid_segments);
  2288. if (ind_msg->no_of_valid_segments > QMI_WLFW_MAX_M3_SEGMENTS_SIZE_V01)
  2289. return;
  2290. event_data = kzalloc(sizeof(*event_data), GFP_KERNEL);
  2291. if (!event_data)
  2292. return;
  2293. event_data->pdev_id = ind_msg->pdev_id;
  2294. event_data->no_of_valid_segments = ind_msg->no_of_valid_segments;
  2295. max_mapped_addr = priv->msa_pa + priv->msa_mem_size;
  2296. for (i = 0; i < ind_msg->no_of_valid_segments; i++) {
  2297. segment_addr = ind_msg->m3_segment[i].addr &
  2298. M3_SEGMENT_ADDR_MASK;
  2299. if (ind_msg->m3_segment[i].size > priv->msa_mem_size ||
  2300. segment_addr >= max_mapped_addr ||
  2301. segment_addr < priv->msa_pa ||
  2302. ind_msg->m3_segment[i].size +
  2303. segment_addr > max_mapped_addr) {
  2304. icnss_pr_dbg("Received out of range Segment %d Addr: 0x%llx Size: 0x%x, Name: %s, type: %d\n",
  2305. (i + 1), segment_addr,
  2306. ind_msg->m3_segment[i].size,
  2307. ind_msg->m3_segment[i].name,
  2308. ind_msg->m3_segment[i].type);
  2309. goto out;
  2310. }
  2311. event_data->m3_segment[i].addr = segment_addr;
  2312. event_data->m3_segment[i].size = ind_msg->m3_segment[i].size;
  2313. event_data->m3_segment[i].type = ind_msg->m3_segment[i].type;
  2314. strlcpy(event_data->m3_segment[i].name,
  2315. ind_msg->m3_segment[i].name,
  2316. WLFW_MAX_STR_LEN + 1);
  2317. icnss_pr_dbg("Received Segment %d Addr: 0x%llx Size: 0x%x, Name: %s, type: %d\n",
  2318. (i + 1), segment_addr,
  2319. ind_msg->m3_segment[i].size,
  2320. ind_msg->m3_segment[i].name,
  2321. ind_msg->m3_segment[i].type);
  2322. }
  2323. icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_M3_DUMP_UPLOAD_REQ,
  2324. 0, event_data);
  2325. return;
  2326. out:
  2327. kfree(event_data);
  2328. }
  2329. static int icnss_wlfw_wfc_call_status_send_sync
  2330. (struct icnss_priv *priv,
  2331. const struct ims_private_service_wfc_call_status_ind_msg_v01 *ind_msg)
  2332. {
  2333. struct wlfw_wfc_call_status_req_msg_v01 *req;
  2334. struct wlfw_wfc_call_status_resp_msg_v01 *resp;
  2335. struct qmi_txn txn;
  2336. int ret = 0;
  2337. if (!test_bit(ICNSS_FW_READY, &priv->state)) {
  2338. icnss_pr_err("Drop IMS WFC indication as FW not initialized\n");
  2339. return -EINVAL;
  2340. }
  2341. req = kzalloc(sizeof(*req), GFP_KERNEL);
  2342. if (!req)
  2343. return -ENOMEM;
  2344. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  2345. if (!resp) {
  2346. kfree(req);
  2347. return -ENOMEM;
  2348. }
  2349. /**
  2350. * WFC Call r1 design has CNSS as pass thru using opaque hex buffer.
  2351. * But in r2 update QMI structure is expanded and as an effect qmi
  2352. * decoded structures have padding. Thus we cannot use buffer design.
  2353. * For backward compatibility for r1 design copy only wfc_call_active
  2354. * value in hex buffer.
  2355. */
  2356. req->wfc_call_status_len = sizeof(ind_msg->wfc_call_active);
  2357. req->wfc_call_status[0] = ind_msg->wfc_call_active;
  2358. /* wfc_call_active is mandatory in IMS indication */
  2359. req->wfc_call_active_valid = 1;
  2360. req->wfc_call_active = ind_msg->wfc_call_active;
  2361. req->all_wfc_calls_held_valid = ind_msg->all_wfc_calls_held_valid;
  2362. req->all_wfc_calls_held = ind_msg->all_wfc_calls_held;
  2363. req->is_wfc_emergency_valid = ind_msg->is_wfc_emergency_valid;
  2364. req->is_wfc_emergency = ind_msg->is_wfc_emergency;
  2365. req->twt_ims_start_valid = ind_msg->twt_ims_start_valid;
  2366. req->twt_ims_start = ind_msg->twt_ims_start;
  2367. req->twt_ims_int_valid = ind_msg->twt_ims_int_valid;
  2368. req->twt_ims_int = ind_msg->twt_ims_int;
  2369. req->media_quality_valid = ind_msg->media_quality_valid;
  2370. req->media_quality =
  2371. (enum wlfw_wfc_media_quality_v01)ind_msg->media_quality;
  2372. icnss_pr_dbg("CNSS->FW: WFC_CALL_REQ: state: 0x%lx\n",
  2373. priv->state);
  2374. ret = qmi_txn_init(&priv->qmi, &txn,
  2375. wlfw_wfc_call_status_resp_msg_v01_ei, resp);
  2376. if (ret < 0) {
  2377. icnss_pr_err("CNSS->FW: WFC_CALL_REQ: QMI Txn Init: Err %d\n",
  2378. ret);
  2379. goto out;
  2380. }
  2381. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  2382. QMI_WLFW_WFC_CALL_STATUS_REQ_V01,
  2383. WLFW_WFC_CALL_STATUS_REQ_MSG_V01_MAX_MSG_LEN,
  2384. wlfw_wfc_call_status_req_msg_v01_ei, req);
  2385. if (ret < 0) {
  2386. qmi_txn_cancel(&txn);
  2387. icnss_pr_err("CNSS->FW: WFC_CALL_REQ: QMI Send Err: %d\n",
  2388. ret);
  2389. goto out;
  2390. }
  2391. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  2392. if (ret < 0) {
  2393. icnss_pr_err("FW->CNSS: WFC_CALL_RSP: QMI Wait Err: %d\n",
  2394. ret);
  2395. goto out;
  2396. }
  2397. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  2398. icnss_pr_err("FW->CNSS: WFC_CALL_RSP: Result: %d Err: %d\n",
  2399. resp->resp.result, resp->resp.error);
  2400. ret = -resp->resp.result;
  2401. goto out;
  2402. }
  2403. ret = 0;
  2404. out:
  2405. kfree(req);
  2406. kfree(resp);
  2407. return ret;
  2408. }
  2409. static int icnss_ims_wfc_call_twt_cfg_send_sync
  2410. (struct icnss_priv *priv,
  2411. const struct wlfw_wfc_call_twt_config_ind_msg_v01 *ind_msg)
  2412. {
  2413. struct ims_private_service_wfc_call_twt_config_req_msg_v01 *req;
  2414. struct ims_private_service_wfc_call_twt_config_rsp_msg_v01 *resp;
  2415. struct qmi_txn txn;
  2416. int ret = 0;
  2417. if (!test_bit(ICNSS_IMS_CONNECTED, &priv->state)) {
  2418. icnss_pr_err("Drop FW WFC indication as IMS QMI not connected\n");
  2419. return -EINVAL;
  2420. }
  2421. req = kzalloc(sizeof(*req), GFP_KERNEL);
  2422. if (!req)
  2423. return -ENOMEM;
  2424. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  2425. if (!resp) {
  2426. kfree(req);
  2427. return -ENOMEM;
  2428. }
  2429. req->twt_sta_start_valid = ind_msg->twt_sta_start_valid;
  2430. req->twt_sta_start = ind_msg->twt_sta_start;
  2431. req->twt_sta_int_valid = ind_msg->twt_sta_int_valid;
  2432. req->twt_sta_int = ind_msg->twt_sta_int;
  2433. req->twt_sta_upo_valid = ind_msg->twt_sta_upo_valid;
  2434. req->twt_sta_upo = ind_msg->twt_sta_upo;
  2435. req->twt_sta_sp_valid = ind_msg->twt_sta_sp_valid;
  2436. req->twt_sta_sp = ind_msg->twt_sta_sp;
  2437. req->twt_sta_dl_valid = req->twt_sta_dl_valid;
  2438. req->twt_sta_dl = req->twt_sta_dl;
  2439. req->twt_sta_config_changed_valid =
  2440. ind_msg->twt_sta_config_changed_valid;
  2441. req->twt_sta_config_changed = ind_msg->twt_sta_config_changed;
  2442. icnss_pr_dbg("CNSS->IMS: TWT_CFG_REQ: state: 0x%lx\n",
  2443. priv->state);
  2444. ret =
  2445. qmi_txn_init(&priv->ims_qmi, &txn,
  2446. ims_private_service_wfc_call_twt_config_rsp_msg_v01_ei,
  2447. resp);
  2448. if (ret < 0) {
  2449. icnss_pr_err("CNSS->IMS: TWT_CFG_REQ: QMI Txn Init Err: %d\n",
  2450. ret);
  2451. goto out;
  2452. }
  2453. ret =
  2454. qmi_send_request(&priv->ims_qmi, NULL, &txn,
  2455. QMI_IMS_PRIVATE_SERVICE_WFC_CALL_TWT_CONFIG_REQ_V01,
  2456. IMS_PRIVATE_SERVICE_WFC_CALL_TWT_CONFIG_REQ_MSG_V01_MAX_MSG_LEN,
  2457. ims_private_service_wfc_call_twt_config_req_msg_v01_ei, req);
  2458. if (ret < 0) {
  2459. qmi_txn_cancel(&txn);
  2460. icnss_pr_err("CNSS->IMS: TWT_CFG_REQ: QMI Send Err: %d\n", ret);
  2461. goto out;
  2462. }
  2463. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  2464. if (ret < 0) {
  2465. icnss_pr_err("IMS->CNSS: TWT_CFG_RSP: QMI Wait Err: %d\n", ret);
  2466. goto out;
  2467. }
  2468. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  2469. icnss_pr_err("IMS->CNSS: TWT_CFG_RSP: Result: %d Err: %d\n",
  2470. resp->resp.result, resp->resp.error);
  2471. ret = -resp->resp.result;
  2472. goto out;
  2473. }
  2474. ret = 0;
  2475. out:
  2476. kfree(req);
  2477. kfree(resp);
  2478. return ret;
  2479. }
  2480. int icnss_process_twt_cfg_ind_event(struct icnss_priv *priv,
  2481. void *data)
  2482. {
  2483. int ret;
  2484. struct wlfw_wfc_call_twt_config_ind_msg_v01 *ind_msg = data;
  2485. ret = icnss_ims_wfc_call_twt_cfg_send_sync(priv, ind_msg);
  2486. kfree(data);
  2487. return ret;
  2488. }
  2489. static void icnss_wlfw_process_twt_cfg_ind(struct qmi_handle *qmi,
  2490. struct sockaddr_qrtr *sq,
  2491. struct qmi_txn *txn,
  2492. const void *data)
  2493. {
  2494. struct icnss_priv *priv =
  2495. container_of(qmi, struct icnss_priv, qmi);
  2496. const struct wlfw_wfc_call_twt_config_ind_msg_v01 *ind_msg = data;
  2497. struct wlfw_wfc_call_twt_config_ind_msg_v01 *event_data;
  2498. if (!txn) {
  2499. icnss_pr_err("FW->CNSS: TWT_CFG_IND: Spurious indication\n");
  2500. return;
  2501. }
  2502. if (!ind_msg) {
  2503. icnss_pr_err("FW->CNSS: TWT_CFG_IND: Invalid indication\n");
  2504. return;
  2505. }
  2506. icnss_pr_dbg("FW->CNSS: TWT_CFG_IND: %x %llx, %x %x, %x %x, %x %x, %x %x, %x %x\n",
  2507. ind_msg->twt_sta_start_valid, ind_msg->twt_sta_start,
  2508. ind_msg->twt_sta_int_valid, ind_msg->twt_sta_int,
  2509. ind_msg->twt_sta_upo_valid, ind_msg->twt_sta_upo,
  2510. ind_msg->twt_sta_sp_valid, ind_msg->twt_sta_sp,
  2511. ind_msg->twt_sta_dl_valid, ind_msg->twt_sta_dl,
  2512. ind_msg->twt_sta_config_changed_valid,
  2513. ind_msg->twt_sta_config_changed);
  2514. event_data = kmemdup(ind_msg, sizeof(*event_data), GFP_KERNEL);
  2515. if (!event_data)
  2516. return;
  2517. icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_WLFW_TWT_CFG_IND, 0,
  2518. event_data);
  2519. }
  2520. static struct qmi_msg_handler wlfw_msg_handlers[] = {
  2521. {
  2522. .type = QMI_INDICATION,
  2523. .msg_id = QMI_WLFW_FW_READY_IND_V01,
  2524. .ei = wlfw_fw_ready_ind_msg_v01_ei,
  2525. .decoded_size = sizeof(struct wlfw_fw_ready_ind_msg_v01),
  2526. .fn = fw_ready_ind_cb
  2527. },
  2528. {
  2529. .type = QMI_INDICATION,
  2530. .msg_id = QMI_WLFW_MSA_READY_IND_V01,
  2531. .ei = wlfw_msa_ready_ind_msg_v01_ei,
  2532. .decoded_size = sizeof(struct wlfw_msa_ready_ind_msg_v01),
  2533. .fn = msa_ready_ind_cb
  2534. },
  2535. {
  2536. .type = QMI_INDICATION,
  2537. .msg_id = QMI_WLFW_PIN_CONNECT_RESULT_IND_V01,
  2538. .ei = wlfw_pin_connect_result_ind_msg_v01_ei,
  2539. .decoded_size =
  2540. sizeof(struct wlfw_pin_connect_result_ind_msg_v01),
  2541. .fn = pin_connect_result_ind_cb
  2542. },
  2543. {
  2544. .type = QMI_INDICATION,
  2545. .msg_id = QMI_WLFW_REJUVENATE_IND_V01,
  2546. .ei = wlfw_rejuvenate_ind_msg_v01_ei,
  2547. .decoded_size = sizeof(struct wlfw_rejuvenate_ind_msg_v01),
  2548. .fn = rejuvenate_ind_cb
  2549. },
  2550. {
  2551. .type = QMI_INDICATION,
  2552. .msg_id = QMI_WLFW_CAL_DONE_IND_V01,
  2553. .ei = wlfw_cal_done_ind_msg_v01_ei,
  2554. .decoded_size = sizeof(struct wlfw_cal_done_ind_msg_v01),
  2555. .fn = cal_done_ind_cb
  2556. },
  2557. {
  2558. .type = QMI_INDICATION,
  2559. .msg_id = QMI_WLFW_FW_INIT_DONE_IND_V01,
  2560. .ei = wlfw_fw_init_done_ind_msg_v01_ei,
  2561. .decoded_size = sizeof(struct wlfw_fw_init_done_ind_msg_v01),
  2562. .fn = fw_init_done_ind_cb
  2563. },
  2564. {
  2565. .type = QMI_INDICATION,
  2566. .msg_id = QMI_WLFW_QDSS_TRACE_REQ_MEM_IND_V01,
  2567. .ei = wlfw_qdss_trace_req_mem_ind_msg_v01_ei,
  2568. .decoded_size =
  2569. sizeof(struct wlfw_qdss_trace_req_mem_ind_msg_v01),
  2570. .fn = wlfw_qdss_trace_req_mem_ind_cb
  2571. },
  2572. {
  2573. .type = QMI_INDICATION,
  2574. .msg_id = QMI_WLFW_QDSS_TRACE_SAVE_IND_V01,
  2575. .ei = wlfw_qdss_trace_save_ind_msg_v01_ei,
  2576. .decoded_size =
  2577. sizeof(struct wlfw_qdss_trace_save_ind_msg_v01),
  2578. .fn = wlfw_qdss_trace_save_ind_cb
  2579. },
  2580. {
  2581. .type = QMI_INDICATION,
  2582. .msg_id = QMI_WLFW_QDSS_TRACE_FREE_IND_V01,
  2583. .ei = wlfw_qdss_trace_free_ind_msg_v01_ei,
  2584. .decoded_size =
  2585. sizeof(struct wlfw_qdss_trace_free_ind_msg_v01),
  2586. .fn = wlfw_qdss_trace_free_ind_cb
  2587. },
  2588. {
  2589. .type = QMI_INDICATION,
  2590. .msg_id = QMI_WLFW_RESPOND_GET_INFO_IND_V01,
  2591. .ei = wlfw_respond_get_info_ind_msg_v01_ei,
  2592. .decoded_size =
  2593. sizeof(struct wlfw_respond_get_info_ind_msg_v01),
  2594. .fn = icnss_wlfw_respond_get_info_ind_cb
  2595. },
  2596. {
  2597. .type = QMI_INDICATION,
  2598. .msg_id = QMI_WLFW_M3_DUMP_UPLOAD_SEGMENTS_REQ_IND_V01,
  2599. .ei = wlfw_m3_dump_upload_segments_req_ind_msg_v01_ei,
  2600. .decoded_size =
  2601. sizeof(struct wlfw_m3_dump_upload_segments_req_ind_msg_v01),
  2602. .fn = icnss_wlfw_m3_dump_upload_segs_req_ind_cb
  2603. },
  2604. {
  2605. .type = QMI_INDICATION,
  2606. .msg_id = QMI_WLFW_WFC_CALL_TWT_CONFIG_IND_V01,
  2607. .ei = wlfw_wfc_call_twt_config_ind_msg_v01_ei,
  2608. .decoded_size =
  2609. sizeof(struct wlfw_wfc_call_twt_config_ind_msg_v01),
  2610. .fn = icnss_wlfw_process_twt_cfg_ind
  2611. },
  2612. {}
  2613. };
  2614. int icnss_connect_to_fw_server(struct icnss_priv *priv, void *data)
  2615. {
  2616. struct icnss_event_server_arrive_data *event_data = data;
  2617. struct qmi_handle *qmi = &priv->qmi;
  2618. struct sockaddr_qrtr sq = { 0 };
  2619. int ret = 0;
  2620. if (!priv) {
  2621. ret = -ENODEV;
  2622. goto out;
  2623. }
  2624. sq.sq_family = AF_QIPCRTR;
  2625. sq.sq_node = event_data->node;
  2626. sq.sq_port = event_data->port;
  2627. ret = kernel_connect(qmi->sock, (struct sockaddr *)&sq, sizeof(sq), 0);
  2628. if (ret < 0) {
  2629. icnss_pr_err("Fail to connect to remote service port\n");
  2630. goto out;
  2631. }
  2632. icnss_pr_info("QMI Server Connected: state: 0x%lx\n", priv->state);
  2633. kfree(data);
  2634. return 0;
  2635. out:
  2636. kfree(data);
  2637. ICNSS_ASSERT(0);
  2638. return ret;
  2639. }
  2640. int icnss_clear_server(struct icnss_priv *priv)
  2641. {
  2642. int ret;
  2643. if (!priv)
  2644. return -ENODEV;
  2645. icnss_pr_info("QMI Service Disconnected: 0x%lx\n", priv->state);
  2646. clear_bit(ICNSS_WLFW_CONNECTED, &priv->state);
  2647. icnss_unregister_fw_service(priv);
  2648. clear_bit(ICNSS_DEL_SERVER, &priv->state);
  2649. ret = icnss_register_fw_service(priv);
  2650. if (ret < 0) {
  2651. icnss_pr_err("WLFW server registration failed\n");
  2652. ICNSS_ASSERT(0);
  2653. }
  2654. return 0;
  2655. }
  2656. static int wlfw_new_server(struct qmi_handle *qmi,
  2657. struct qmi_service *service)
  2658. {
  2659. struct icnss_priv *priv =
  2660. container_of(qmi, struct icnss_priv, qmi);
  2661. struct icnss_event_server_arrive_data *event_data;
  2662. if (priv && test_bit(ICNSS_DEL_SERVER, &priv->state)) {
  2663. icnss_pr_info("WLFW server delete in progress, Ignore server arrive: 0x%lx\n",
  2664. priv->state);
  2665. return 0;
  2666. }
  2667. icnss_pr_dbg("WLFW server arrive: node %u port %u\n",
  2668. service->node, service->port);
  2669. event_data = kzalloc(sizeof(*event_data), GFP_KERNEL);
  2670. if (event_data == NULL)
  2671. return -ENOMEM;
  2672. event_data->node = service->node;
  2673. event_data->port = service->port;
  2674. icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_SERVER_ARRIVE,
  2675. 0, event_data);
  2676. return 0;
  2677. }
  2678. static void wlfw_del_server(struct qmi_handle *qmi,
  2679. struct qmi_service *service)
  2680. {
  2681. struct icnss_priv *priv = container_of(qmi, struct icnss_priv, qmi);
  2682. if (priv && test_bit(ICNSS_DEL_SERVER, &priv->state)) {
  2683. icnss_pr_info("WLFW server delete / icnss remove in progress, Ignore server delete: 0x%lx\n",
  2684. priv->state);
  2685. return;
  2686. }
  2687. icnss_pr_dbg("WLFW server delete\n");
  2688. if (priv) {
  2689. set_bit(ICNSS_DEL_SERVER, &priv->state);
  2690. set_bit(ICNSS_FW_DOWN, &priv->state);
  2691. icnss_ignore_fw_timeout(true);
  2692. }
  2693. icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_SERVER_EXIT,
  2694. 0, NULL);
  2695. }
  2696. static struct qmi_ops wlfw_qmi_ops = {
  2697. .new_server = wlfw_new_server,
  2698. .del_server = wlfw_del_server,
  2699. };
  2700. int icnss_register_fw_service(struct icnss_priv *priv)
  2701. {
  2702. int ret;
  2703. ret = qmi_handle_init(&priv->qmi,
  2704. WLFW_BDF_DOWNLOAD_REQ_MSG_V01_MAX_MSG_LEN,
  2705. &wlfw_qmi_ops, wlfw_msg_handlers);
  2706. if (ret < 0)
  2707. return ret;
  2708. if (priv->device_id == WCN6750_DEVICE_ID ||
  2709. priv->device_id == WCN6450_DEVICE_ID)
  2710. ret = qmi_add_lookup(&priv->qmi, WLFW_SERVICE_ID_V01,
  2711. WLFW_SERVICE_VERS_V01,
  2712. WLFW_SERVICE_WCN_INS_ID_V01);
  2713. else
  2714. ret = qmi_add_lookup(&priv->qmi, WLFW_SERVICE_ID_V01,
  2715. WLFW_SERVICE_VERS_V01,
  2716. WLFW_SERVICE_INS_ID_V01);
  2717. return ret;
  2718. }
  2719. void icnss_unregister_fw_service(struct icnss_priv *priv)
  2720. {
  2721. set_bit(ICNSS_DEL_SERVER, &priv->state);
  2722. qmi_handle_release(&priv->qmi);
  2723. }
  2724. int icnss_send_wlan_enable_to_fw(struct icnss_priv *priv,
  2725. struct icnss_wlan_enable_cfg *config,
  2726. enum icnss_driver_mode mode,
  2727. const char *host_version)
  2728. {
  2729. struct wlfw_wlan_cfg_req_msg_v01 req;
  2730. u32 i;
  2731. int ret;
  2732. icnss_pr_dbg("Mode: %d, config: %pK, host_version: %s\n",
  2733. mode, config, host_version);
  2734. memset(&req, 0, sizeof(req));
  2735. if (mode == ICNSS_WALTEST || mode == ICNSS_CCPM)
  2736. goto skip;
  2737. if (!config || !host_version) {
  2738. icnss_pr_err("Invalid cfg pointer, config: %pK, host_version: %pK\n",
  2739. config, host_version);
  2740. ret = -EINVAL;
  2741. goto out;
  2742. }
  2743. req.host_version_valid = 1;
  2744. strlcpy(req.host_version, host_version,
  2745. WLFW_MAX_STR_LEN + 1);
  2746. req.tgt_cfg_valid = 1;
  2747. if (config->num_ce_tgt_cfg > WLFW_MAX_NUM_CE)
  2748. req.tgt_cfg_len = WLFW_MAX_NUM_CE;
  2749. else
  2750. req.tgt_cfg_len = config->num_ce_tgt_cfg;
  2751. for (i = 0; i < req.tgt_cfg_len; i++) {
  2752. req.tgt_cfg[i].pipe_num = config->ce_tgt_cfg[i].pipe_num;
  2753. req.tgt_cfg[i].pipe_dir = config->ce_tgt_cfg[i].pipe_dir;
  2754. req.tgt_cfg[i].nentries = config->ce_tgt_cfg[i].nentries;
  2755. req.tgt_cfg[i].nbytes_max = config->ce_tgt_cfg[i].nbytes_max;
  2756. req.tgt_cfg[i].flags = config->ce_tgt_cfg[i].flags;
  2757. }
  2758. req.svc_cfg_valid = 1;
  2759. if (config->num_ce_svc_pipe_cfg > WLFW_MAX_NUM_SVC)
  2760. req.svc_cfg_len = WLFW_MAX_NUM_SVC;
  2761. else
  2762. req.svc_cfg_len = config->num_ce_svc_pipe_cfg;
  2763. for (i = 0; i < req.svc_cfg_len; i++) {
  2764. req.svc_cfg[i].service_id = config->ce_svc_cfg[i].service_id;
  2765. req.svc_cfg[i].pipe_dir = config->ce_svc_cfg[i].pipe_dir;
  2766. req.svc_cfg[i].pipe_num = config->ce_svc_cfg[i].pipe_num;
  2767. }
  2768. if (priv->device_id == WCN6750_DEVICE_ID) {
  2769. req.shadow_reg_v2_valid = 1;
  2770. if (config->num_shadow_reg_v2_cfg >
  2771. QMI_WLFW_MAX_NUM_SHADOW_REG_V2_V01)
  2772. req.shadow_reg_v2_len =
  2773. QMI_WLFW_MAX_NUM_SHADOW_REG_V2_V01;
  2774. else
  2775. req.shadow_reg_v2_len = config->num_shadow_reg_v2_cfg;
  2776. memcpy(req.shadow_reg_v2, config->shadow_reg_v2_cfg,
  2777. sizeof(struct wlfw_shadow_reg_v2_cfg_s_v01) *
  2778. req.shadow_reg_v2_len);
  2779. } else if (priv->device_id == ADRASTEA_DEVICE_ID) {
  2780. req.shadow_reg_valid = 1;
  2781. if (config->num_shadow_reg_cfg >
  2782. QMI_WLFW_MAX_NUM_SHADOW_REG_V01)
  2783. req.shadow_reg_len = QMI_WLFW_MAX_NUM_SHADOW_REG_V01;
  2784. else
  2785. req.shadow_reg_len = config->num_shadow_reg_cfg;
  2786. memcpy(req.shadow_reg, config->shadow_reg_cfg,
  2787. sizeof(struct wlfw_msi_cfg_s_v01) * req.shadow_reg_len);
  2788. } else if (priv->device_id == WCN6450_DEVICE_ID) {
  2789. req.shadow_reg_v3_valid = 1;
  2790. if (config->num_shadow_reg_v3_cfg >
  2791. MAX_NUM_SHADOW_REG_V3)
  2792. req.shadow_reg_v3_len = MAX_NUM_SHADOW_REG_V3;
  2793. else
  2794. req.shadow_reg_v3_len = config->num_shadow_reg_v3_cfg;
  2795. memcpy(req.shadow_reg_v3, config->shadow_reg_v3_cfg,
  2796. sizeof(struct wlfw_shadow_reg_v3_cfg_s_v01)
  2797. * req.shadow_reg_v3_len);
  2798. }
  2799. ret = wlfw_wlan_cfg_send_sync_msg(priv, &req);
  2800. if (ret)
  2801. goto out;
  2802. skip:
  2803. ret = wlfw_wlan_mode_send_sync_msg(priv,
  2804. (enum wlfw_driver_mode_enum_v01)mode);
  2805. out:
  2806. if (test_bit(SKIP_QMI, &priv->ctrl_params.quirks))
  2807. ret = 0;
  2808. return ret;
  2809. }
  2810. int icnss_send_wlan_disable_to_fw(struct icnss_priv *priv)
  2811. {
  2812. enum wlfw_driver_mode_enum_v01 mode = QMI_WLFW_OFF_V01;
  2813. return wlfw_wlan_mode_send_sync_msg(priv, mode);
  2814. }
  2815. #ifdef CONFIG_ICNSS2_DEBUG
  2816. static inline u32 icnss_get_host_build_type(void)
  2817. {
  2818. return QMI_HOST_BUILD_TYPE_PRIMARY_V01;
  2819. }
  2820. #else
  2821. static inline u32 icnss_get_host_build_type(void)
  2822. {
  2823. return QMI_HOST_BUILD_TYPE_SECONDARY_V01;
  2824. }
  2825. #endif
  2826. int wlfw_host_cap_send_sync(struct icnss_priv *priv)
  2827. {
  2828. struct wlfw_host_cap_req_msg_v01 *req;
  2829. struct wlfw_host_cap_resp_msg_v01 *resp;
  2830. struct qmi_txn txn;
  2831. int ddr_type;
  2832. u32 gpio;
  2833. int ret = 0;
  2834. u64 iova_start = 0, iova_size = 0,
  2835. iova_ipa_start = 0, iova_ipa_size = 0;
  2836. icnss_pr_dbg("Sending host capability message, state: 0x%lx\n",
  2837. priv->state);
  2838. req = kzalloc(sizeof(*req), GFP_KERNEL);
  2839. if (!req)
  2840. return -ENOMEM;
  2841. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  2842. if (!resp) {
  2843. kfree(req);
  2844. return -ENOMEM;
  2845. }
  2846. req->num_clients_valid = 1;
  2847. req->num_clients = 1;
  2848. req->bdf_support_valid = 1;
  2849. req->bdf_support = 1;
  2850. req->cal_done_valid = 1;
  2851. req->cal_done = priv->cal_done;
  2852. icnss_pr_dbg("Calibration done is %d\n", priv->cal_done);
  2853. if (priv->smmu_s1_enable &&
  2854. !icnss_get_iova(priv, &iova_start, &iova_size) &&
  2855. !icnss_get_iova_ipa(priv, &iova_ipa_start,
  2856. &iova_ipa_size)) {
  2857. req->ddr_range_valid = 1;
  2858. req->ddr_range[0].start = iova_start;
  2859. req->ddr_range[0].size = iova_size + iova_ipa_size;
  2860. req->ddr_range[1].start = priv->msa_pa;
  2861. req->ddr_range[1].size = priv->msa_mem_size;
  2862. icnss_pr_dbg("Sending iova starting 0x%llx with size 0x%llx\n",
  2863. req->ddr_range[0].start, req->ddr_range[0].size);
  2864. icnss_pr_dbg("Sending msa starting 0x%llx with size 0x%llx\n",
  2865. req->ddr_range[1].start, req->ddr_range[1].size);
  2866. }
  2867. req->host_build_type_valid = 1;
  2868. req->host_build_type = icnss_get_host_build_type();
  2869. if (priv->wlan_en_delay_ms >= 100) {
  2870. icnss_pr_dbg("Setting WLAN_EN delay: %d ms\n",
  2871. priv->wlan_en_delay_ms);
  2872. req->wlan_enable_delay_valid = 1;
  2873. req->wlan_enable_delay = priv->wlan_en_delay_ms;
  2874. }
  2875. /* ddr_type = 7(LPDDR4) and 8(LPDDR5) */
  2876. ddr_type = of_fdt_get_ddrtype();
  2877. if (ddr_type > 0) {
  2878. icnss_pr_dbg("DDR Type: %d\n", ddr_type);
  2879. req->ddr_type_valid = 1;
  2880. req->ddr_type = ddr_type;
  2881. }
  2882. ret = of_property_read_u32(priv->pdev->dev.of_node, "wlan-en-gpio",
  2883. &gpio);
  2884. if (!ret) {
  2885. icnss_pr_dbg("WLAN_EN_GPIO modified through DT: %d\n", gpio);
  2886. req->gpio_info_valid = 1;
  2887. req->gpio_info[WLAN_EN_GPIO_V01] = gpio;
  2888. } else {
  2889. req->gpio_info[WLAN_EN_GPIO_V01] = 0xFFFF;
  2890. }
  2891. ret = of_property_read_u32(priv->pdev->dev.of_node, "bt-en-gpio",
  2892. &gpio);
  2893. if (!ret) {
  2894. icnss_pr_dbg("BT_EN_GPIO modified through DT: %d\n", gpio);
  2895. req->gpio_info_valid = 1;
  2896. req->gpio_info[BT_EN_GPIO_V01] = gpio;
  2897. } else {
  2898. req->gpio_info[BT_EN_GPIO_V01] = 0xFFFF;
  2899. }
  2900. ret = of_property_read_u32(priv->pdev->dev.of_node, "host-sol-gpio",
  2901. &gpio);
  2902. if (!ret) {
  2903. icnss_pr_dbg("HOST_SOL_GPIO modified through DT: %d\n", gpio);
  2904. req->gpio_info_valid = 1;
  2905. req->gpio_info[HOST_SOL_GPIO_V01] = gpio;
  2906. } else {
  2907. req->gpio_info[HOST_SOL_GPIO_V01] = 0xFFFF;
  2908. }
  2909. ret = of_property_read_u32(priv->pdev->dev.of_node, "target-sol-gpio",
  2910. &gpio);
  2911. if (!ret) {
  2912. icnss_pr_dbg("TARGET_SOL_GPIO modified through DT: %d\n", gpio);
  2913. req->gpio_info_valid = 1;
  2914. req->gpio_info[TARGET_SOL_GPIO_V01] = gpio;
  2915. } else {
  2916. req->gpio_info[TARGET_SOL_GPIO_V01] = 0xFFFF;
  2917. }
  2918. req->gpio_info_len = GPIO_TYPE_MAX_V01;
  2919. ret = qmi_txn_init(&priv->qmi, &txn,
  2920. wlfw_host_cap_resp_msg_v01_ei, resp);
  2921. if (ret < 0) {
  2922. icnss_pr_err("Failed to initialize txn for host capability request, err: %d\n",
  2923. ret);
  2924. goto out;
  2925. }
  2926. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  2927. QMI_WLFW_HOST_CAP_REQ_V01,
  2928. WLFW_HOST_CAP_REQ_MSG_V01_MAX_MSG_LEN,
  2929. wlfw_host_cap_req_msg_v01_ei, req);
  2930. if (ret < 0) {
  2931. qmi_txn_cancel(&txn);
  2932. icnss_pr_err("Failed to send host capability request, err: %d\n",
  2933. ret);
  2934. goto out;
  2935. }
  2936. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  2937. if (ret < 0) {
  2938. icnss_pr_err("Failed to wait for response of host capability request, err: %d\n",
  2939. ret);
  2940. goto out;
  2941. }
  2942. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  2943. icnss_pr_err("Host capability request failed, result: %d, err: %d\n",
  2944. resp->resp.result, resp->resp.error);
  2945. ret = -resp->resp.result;
  2946. goto out;
  2947. }
  2948. kfree(req);
  2949. kfree(resp);
  2950. return 0;
  2951. out:
  2952. ICNSS_QMI_ASSERT();
  2953. kfree(req);
  2954. kfree(resp);
  2955. return ret;
  2956. }
  2957. int icnss_wlfw_get_info_send_sync(struct icnss_priv *plat_priv, int type,
  2958. void *cmd, int cmd_len)
  2959. {
  2960. struct wlfw_get_info_req_msg_v01 *req;
  2961. struct wlfw_get_info_resp_msg_v01 *resp;
  2962. struct qmi_txn txn;
  2963. int ret = 0;
  2964. int flags = GFP_KERNEL & ~__GFP_DIRECT_RECLAIM;
  2965. if (cmd_len > QMI_WLFW_MAX_DATA_SIZE_V01)
  2966. return -EINVAL;
  2967. if (test_bit(ICNSS_FW_DOWN, &plat_priv->state))
  2968. return -EINVAL;
  2969. req = kzalloc(sizeof(*req), flags);
  2970. if (!req)
  2971. return -ENOMEM;
  2972. resp = kzalloc(sizeof(*resp), flags);
  2973. if (!resp) {
  2974. kfree(req);
  2975. return -ENOMEM;
  2976. }
  2977. req->type = type;
  2978. req->data_len = cmd_len;
  2979. memcpy(req->data, cmd, req->data_len);
  2980. ret = qmi_txn_init(&plat_priv->qmi, &txn,
  2981. wlfw_get_info_resp_msg_v01_ei, resp);
  2982. if (ret < 0) {
  2983. icnss_pr_err("Failed to initialize txn for get info request, err: %d\n",
  2984. ret);
  2985. goto out;
  2986. }
  2987. ret = qmi_send_request(&plat_priv->qmi, NULL, &txn,
  2988. QMI_WLFW_GET_INFO_REQ_V01,
  2989. WLFW_GET_INFO_REQ_MSG_V01_MAX_MSG_LEN,
  2990. wlfw_get_info_req_msg_v01_ei, req);
  2991. if (ret < 0) {
  2992. qmi_txn_cancel(&txn);
  2993. icnss_pr_err("Failed to send get info request, err: %d\n",
  2994. ret);
  2995. goto out;
  2996. }
  2997. ret = qmi_txn_wait(&txn, plat_priv->ctrl_params.qmi_timeout);
  2998. if (ret < 0) {
  2999. icnss_pr_err("Failed to wait for response of get info request, err: %d\n",
  3000. ret);
  3001. goto out;
  3002. }
  3003. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  3004. icnss_pr_err("Get info request failed, result: %d, err: %d\n",
  3005. resp->resp.result, resp->resp.error);
  3006. ret = -resp->resp.result;
  3007. goto out;
  3008. }
  3009. kfree(req);
  3010. kfree(resp);
  3011. return 0;
  3012. out:
  3013. kfree(req);
  3014. kfree(resp);
  3015. return ret;
  3016. }
  3017. int wlfw_subsys_restart_level_msg(struct icnss_priv *penv, uint8_t restart_level)
  3018. {
  3019. int ret;
  3020. struct wlfw_subsys_restart_level_req_msg_v01 *req;
  3021. struct wlfw_subsys_restart_level_resp_msg_v01 *resp;
  3022. struct qmi_txn txn;
  3023. if (!penv)
  3024. return -ENODEV;
  3025. if (test_bit(ICNSS_FW_DOWN, &penv->state))
  3026. return -EINVAL;
  3027. icnss_pr_dbg("Sending subsystem restart level: 0x%x\n", restart_level);
  3028. req = kzalloc(sizeof(*req), GFP_KERNEL);
  3029. if (!req)
  3030. return -ENOMEM;
  3031. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  3032. if (!resp) {
  3033. kfree(req);
  3034. return -ENOMEM;
  3035. }
  3036. req->restart_level_type_valid = 1;
  3037. req->restart_level_type = restart_level;
  3038. penv->stats.restart_level_req++;
  3039. ret = qmi_txn_init(&penv->qmi, &txn,
  3040. wlfw_subsys_restart_level_resp_msg_v01_ei, resp);
  3041. if (ret < 0) {
  3042. icnss_pr_err("Fail to init txn for subsystem restart level, resp %d\n",
  3043. ret);
  3044. goto out;
  3045. }
  3046. ret = qmi_send_request(&penv->qmi, NULL, &txn,
  3047. QMI_WLFW_SUBSYS_RESTART_LEVEL_REQ_V01,
  3048. WLFW_SUBSYS_RESTART_LEVEL_REQ_MSG_V01_MAX_MSG_LEN,
  3049. wlfw_subsys_restart_level_req_msg_v01_ei, req);
  3050. if (ret < 0) {
  3051. qmi_txn_cancel(&txn);
  3052. icnss_pr_err("Fail to send subsystem restart level %d\n",
  3053. ret);
  3054. goto out;
  3055. }
  3056. ret = qmi_txn_wait(&txn, penv->ctrl_params.qmi_timeout);
  3057. if (ret < 0) {
  3058. icnss_pr_err("Subsystem restart level timed out with ret %d\n",
  3059. ret);
  3060. goto out;
  3061. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  3062. icnss_pr_err("Subsystem restart level request rejected,result:%d error:%d\n",
  3063. resp->resp.result, resp->resp.error);
  3064. ret = -resp->resp.result;
  3065. goto out;
  3066. }
  3067. penv->stats.restart_level_resp++;
  3068. kfree(resp);
  3069. kfree(req);
  3070. return 0;
  3071. out:
  3072. kfree(req);
  3073. kfree(resp);
  3074. penv->stats.restart_level_err++;
  3075. return ret;
  3076. }
  3077. int icnss_send_vbatt_update(struct icnss_priv *priv, uint64_t voltage_uv)
  3078. {
  3079. int ret;
  3080. struct wlfw_vbatt_req_msg_v01 *req;
  3081. struct wlfw_vbatt_resp_msg_v01 *resp;
  3082. struct qmi_txn txn;
  3083. if (!priv)
  3084. return -ENODEV;
  3085. if (test_bit(ICNSS_FW_DOWN, &priv->state))
  3086. return -EINVAL;
  3087. icnss_pr_dbg("Sending Vbatt message, state: 0x%lx\n", priv->state);
  3088. req = kzalloc(sizeof(*req), GFP_KERNEL);
  3089. if (!req)
  3090. return -ENOMEM;
  3091. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  3092. if (!resp) {
  3093. kfree(req);
  3094. return -ENOMEM;
  3095. }
  3096. req->voltage_uv = voltage_uv;
  3097. ret = qmi_txn_init(&priv->qmi, &txn, wlfw_vbatt_resp_msg_v01_ei, resp);
  3098. if (ret < 0) {
  3099. icnss_pr_err("Fail to init txn for Vbatt message resp %d\n",
  3100. ret);
  3101. goto out;
  3102. }
  3103. ret = qmi_send_request(&priv->qmi, NULL, &txn,
  3104. QMI_WLFW_VBATT_REQ_V01,
  3105. WLFW_VBATT_REQ_MSG_V01_MAX_MSG_LEN,
  3106. wlfw_vbatt_req_msg_v01_ei, req);
  3107. if (ret < 0) {
  3108. qmi_txn_cancel(&txn);
  3109. icnss_pr_err("Fail to send Vbatt message req %d\n", ret);
  3110. goto out;
  3111. }
  3112. ret = qmi_txn_wait(&txn, priv->ctrl_params.qmi_timeout);
  3113. if (ret < 0) {
  3114. icnss_pr_err("VBATT message resp wait failed with ret %d\n",
  3115. ret);
  3116. goto out;
  3117. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  3118. icnss_pr_err("QMI Vbatt message request rejected, result:%d error:%d\n",
  3119. resp->resp.result, resp->resp.error);
  3120. ret = -resp->resp.result;
  3121. goto out;
  3122. }
  3123. kfree(resp);
  3124. kfree(req);
  3125. return 0;
  3126. out:
  3127. kfree(resp);
  3128. kfree(req);
  3129. return ret;
  3130. }
  3131. int wlfw_wlan_hw_init_cfg_msg(struct icnss_priv *penv,
  3132. enum wlfw_wlan_rf_subtype_v01 type)
  3133. {
  3134. int ret;
  3135. struct wlfw_wlan_hw_init_cfg_req_msg_v01 *req;
  3136. struct wlfw_wlan_hw_init_cfg_resp_msg_v01 *resp;
  3137. struct qmi_txn txn;
  3138. if (!penv)
  3139. return -ENODEV;
  3140. icnss_pr_dbg("Sending hw init cfg, rf_subtype: 0x%x\n", type);
  3141. req = kzalloc(sizeof(*req), GFP_KERNEL);
  3142. if (!req)
  3143. return -ENOMEM;
  3144. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  3145. if (!resp) {
  3146. kfree(req);
  3147. return -ENOMEM;
  3148. }
  3149. req->rf_subtype_valid = 1;
  3150. req->rf_subtype = type;
  3151. ret = qmi_txn_init(&penv->qmi, &txn,
  3152. wlfw_wlan_hw_init_cfg_resp_msg_v01_ei, resp);
  3153. if (ret < 0) {
  3154. icnss_pr_err("Fail to init txn for hw init cfg, resp %d\n",
  3155. ret);
  3156. goto out;
  3157. }
  3158. ret = qmi_send_request(&penv->qmi, NULL, &txn,
  3159. QMI_WLFW_WLAN_HW_INIT_CFG_REQ_V01,
  3160. WLFW_WLAN_HW_INIT_CFG_REQ_MSG_V01_MAX_MSG_LEN,
  3161. wlfw_wlan_hw_init_cfg_req_msg_v01_ei, req);
  3162. if (ret < 0) {
  3163. qmi_txn_cancel(&txn);
  3164. icnss_pr_err("Fail to send hw init cfg %d\n", ret);
  3165. goto out;
  3166. }
  3167. ret = qmi_txn_wait(&txn, penv->ctrl_params.qmi_timeout);
  3168. if (ret < 0) {
  3169. icnss_pr_err("HW init cfg timed out with ret %d\n",
  3170. ret);
  3171. goto out;
  3172. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  3173. icnss_pr_err("HW init cfg request rejected,result:%d error:%d\n",
  3174. resp->resp.result, resp->resp.error);
  3175. ret = -resp->resp.result;
  3176. goto out;
  3177. }
  3178. kfree(resp);
  3179. kfree(req);
  3180. return 0;
  3181. out:
  3182. kfree(req);
  3183. kfree(resp);
  3184. return ret;
  3185. }
  3186. /* IMS Service */
  3187. int ims_subscribe_for_indication_send_async(struct icnss_priv *priv)
  3188. {
  3189. int ret;
  3190. struct ims_private_service_subscribe_for_indications_req_msg_v01 *req;
  3191. struct qmi_txn *txn;
  3192. if (!priv)
  3193. return -ENODEV;
  3194. icnss_pr_dbg("Sending ASYNC ims subscribe for indication\n");
  3195. req = kzalloc(sizeof(*req), GFP_KERNEL);
  3196. if (!req)
  3197. return -ENOMEM;
  3198. req->wfc_call_status_valid = 1;
  3199. req->wfc_call_status = 1;
  3200. txn = &priv->ims_async_txn;
  3201. ret = qmi_txn_init(&priv->ims_qmi, txn, NULL, NULL);
  3202. if (ret < 0) {
  3203. icnss_pr_err("Fail to init txn for ims subscribe for indication resp %d\n",
  3204. ret);
  3205. goto out;
  3206. }
  3207. ret = qmi_send_request
  3208. (&priv->ims_qmi, NULL, txn,
  3209. QMI_IMS_PRIVATE_SERVICE_SUBSCRIBE_FOR_INDICATIONS_REQ_V01,
  3210. IMS_PRIVATE_SERVICE_SUBSCRIBE_FOR_INDICATIONS_REQ_MSG_V01_MAX_MSG_LEN,
  3211. ims_private_service_subscribe_ind_req_msg_v01_ei, req);
  3212. if (ret < 0) {
  3213. qmi_txn_cancel(txn);
  3214. icnss_pr_err("Fail to send ims subscribe for indication req %d\n",
  3215. ret);
  3216. goto out;
  3217. }
  3218. kfree(req);
  3219. return 0;
  3220. out:
  3221. kfree(req);
  3222. return ret;
  3223. }
  3224. static void ims_subscribe_for_indication_resp_cb(struct qmi_handle *qmi,
  3225. struct sockaddr_qrtr *sq,
  3226. struct qmi_txn *txn,
  3227. const void *data)
  3228. {
  3229. const
  3230. struct ims_private_service_subscribe_for_indications_rsp_msg_v01 *resp =
  3231. data;
  3232. icnss_pr_dbg("Received IMS subscribe indication response\n");
  3233. if (!txn) {
  3234. icnss_pr_err("spurious response\n");
  3235. return;
  3236. }
  3237. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  3238. icnss_pr_err("IMS subscribe for indication request rejected, result:%d error:%d\n",
  3239. resp->resp.result, resp->resp.error);
  3240. txn->result = -resp->resp.result;
  3241. }
  3242. }
  3243. int icnss_process_wfc_call_ind_event(struct icnss_priv *priv,
  3244. void *data)
  3245. {
  3246. int ret;
  3247. struct ims_private_service_wfc_call_status_ind_msg_v01 *ind_msg = data;
  3248. ret = icnss_wlfw_wfc_call_status_send_sync(priv, ind_msg);
  3249. kfree(data);
  3250. return ret;
  3251. }
  3252. static void
  3253. icnss_ims_process_wfc_call_ind_cb(struct qmi_handle *ims_qmi,
  3254. struct sockaddr_qrtr *sq,
  3255. struct qmi_txn *txn, const void *data)
  3256. {
  3257. struct icnss_priv *priv =
  3258. container_of(ims_qmi, struct icnss_priv, ims_qmi);
  3259. const
  3260. struct ims_private_service_wfc_call_status_ind_msg_v01 *ind_msg = data;
  3261. struct ims_private_service_wfc_call_status_ind_msg_v01 *event_data;
  3262. if (!txn) {
  3263. icnss_pr_err("IMS->CNSS: WFC_CALL_IND: Spurious indication\n");
  3264. return;
  3265. }
  3266. if (!ind_msg) {
  3267. icnss_pr_err("IMS->CNSS: WFC_CALL_IND: Invalid indication\n");
  3268. return;
  3269. }
  3270. icnss_pr_dbg("IMS->CNSS: WFC_CALL_IND: %x, %x %x, %x %x, %x %llx, %x %x, %x %x\n",
  3271. ind_msg->wfc_call_active, ind_msg->all_wfc_calls_held_valid,
  3272. ind_msg->all_wfc_calls_held,
  3273. ind_msg->is_wfc_emergency_valid, ind_msg->is_wfc_emergency,
  3274. ind_msg->twt_ims_start_valid, ind_msg->twt_ims_start,
  3275. ind_msg->twt_ims_int_valid, ind_msg->twt_ims_int,
  3276. ind_msg->media_quality_valid, ind_msg->media_quality);
  3277. event_data = kmemdup(ind_msg, sizeof(*event_data), GFP_KERNEL);
  3278. if (!event_data)
  3279. return;
  3280. icnss_driver_event_post(priv, ICNSS_DRIVER_EVENT_IMS_WFC_CALL_IND,
  3281. 0, event_data);
  3282. }
  3283. static struct qmi_msg_handler qmi_ims_msg_handlers[] = {
  3284. {
  3285. .type = QMI_RESPONSE,
  3286. .msg_id =
  3287. QMI_IMS_PRIVATE_SERVICE_SUBSCRIBE_FOR_INDICATIONS_REQ_V01,
  3288. .ei =
  3289. ims_private_service_subscribe_ind_rsp_msg_v01_ei,
  3290. .decoded_size = sizeof(struct
  3291. ims_private_service_subscribe_for_indications_rsp_msg_v01),
  3292. .fn = ims_subscribe_for_indication_resp_cb
  3293. },
  3294. {
  3295. .type = QMI_INDICATION,
  3296. .msg_id = QMI_IMS_PRIVATE_SERVICE_WFC_CALL_STATUS_IND_V01,
  3297. .ei = ims_private_service_wfc_call_status_ind_msg_v01_ei,
  3298. .decoded_size =
  3299. sizeof(struct ims_private_service_wfc_call_status_ind_msg_v01),
  3300. .fn = icnss_ims_process_wfc_call_ind_cb
  3301. },
  3302. {}
  3303. };
  3304. static int ims_new_server(struct qmi_handle *qmi,
  3305. struct qmi_service *service)
  3306. {
  3307. struct icnss_priv *priv =
  3308. container_of(qmi, struct icnss_priv, ims_qmi);
  3309. struct sockaddr_qrtr sq = { 0 };
  3310. int ret = 0;
  3311. icnss_pr_dbg("IMS server arrive: node %u port %u\n",
  3312. service->node, service->port);
  3313. sq.sq_family = AF_QIPCRTR;
  3314. sq.sq_node = service->node;
  3315. sq.sq_port = service->port;
  3316. ret = kernel_connect(qmi->sock, (struct sockaddr *)&sq, sizeof(sq), 0);
  3317. if (ret < 0) {
  3318. icnss_pr_err("Fail to connect to remote service port\n");
  3319. return ret;
  3320. }
  3321. set_bit(ICNSS_IMS_CONNECTED, &priv->state);
  3322. icnss_pr_dbg("IMS Server Connected: 0x%lx\n",
  3323. priv->state);
  3324. ret = ims_subscribe_for_indication_send_async(priv);
  3325. return ret;
  3326. }
  3327. static void ims_del_server(struct qmi_handle *qmi,
  3328. struct qmi_service *service)
  3329. {
  3330. struct icnss_priv *priv =
  3331. container_of(qmi, struct icnss_priv, ims_qmi);
  3332. icnss_pr_dbg("IMS server exit\n");
  3333. clear_bit(ICNSS_IMS_CONNECTED, &priv->state);
  3334. }
  3335. static struct qmi_ops ims_qmi_ops = {
  3336. .new_server = ims_new_server,
  3337. .del_server = ims_del_server,
  3338. };
  3339. int icnss_register_ims_service(struct icnss_priv *priv)
  3340. {
  3341. int ret;
  3342. ret = qmi_handle_init(&priv->ims_qmi,
  3343. IMSPRIVATE_SERVICE_MAX_MSG_LEN,
  3344. &ims_qmi_ops, qmi_ims_msg_handlers);
  3345. if (ret < 0)
  3346. return ret;
  3347. ret = qmi_add_lookup(&priv->ims_qmi, IMSPRIVATE_SERVICE_ID_V01,
  3348. IMSPRIVATE_SERVICE_VERS_V01, 0);
  3349. return ret;
  3350. }
  3351. void icnss_unregister_ims_service(struct icnss_priv *priv)
  3352. {
  3353. qmi_handle_release(&priv->ims_qmi);
  3354. }