qmi.c 89 KB

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