qmi.c 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/module.h>
  7. #include <linux/soc/qcom/qmi.h>
  8. #include "bus.h"
  9. #include "debug.h"
  10. #include "main.h"
  11. #include "qmi.h"
  12. #include "genl.h"
  13. #define WLFW_SERVICE_INS_ID_V01 1
  14. #define WLFW_CLIENT_ID 0x4b4e454c
  15. #define BDF_FILE_NAME_PREFIX "bdwlan"
  16. #define ELF_BDF_FILE_NAME "bdwlan.elf"
  17. #define ELF_BDF_FILE_NAME_GF "bdwlang.elf"
  18. #define ELF_BDF_FILE_NAME_PREFIX "bdwlan.e"
  19. #define ELF_BDF_FILE_NAME_GF_PREFIX "bdwlang.e"
  20. #define BIN_BDF_FILE_NAME "bdwlan.bin"
  21. #define BIN_BDF_FILE_NAME_GF "bdwlang.bin"
  22. #define BIN_BDF_FILE_NAME_PREFIX "bdwlan.b"
  23. #define BIN_BDF_FILE_NAME_GF_PREFIX "bdwlang.b"
  24. #define REGDB_FILE_NAME "regdb.bin"
  25. #define HDS_FILE_NAME "hds.bin"
  26. #define CHIP_ID_GF_MASK 0x10
  27. #define CONN_ROAM_FILE_NAME "wlan-connection-roaming"
  28. #define INI_EXT ".ini"
  29. #define INI_FILE_NAME_LEN 100
  30. #define QDSS_TRACE_CONFIG_FILE "qdss_trace_config"
  31. #ifdef CONFIG_CNSS2_DEBUG
  32. #define QDSS_DEBUG_FILE_STR "debug_"
  33. #else
  34. #define QDSS_DEBUG_FILE_STR ""
  35. #endif
  36. #define HW_V1_NUMBER "v1"
  37. #define HW_V2_NUMBER "v2"
  38. #define QMI_WLFW_TIMEOUT_MS (plat_priv->ctrl_params.qmi_timeout)
  39. #define QMI_WLFW_TIMEOUT_JF msecs_to_jiffies(QMI_WLFW_TIMEOUT_MS)
  40. #define COEX_TIMEOUT QMI_WLFW_TIMEOUT_JF
  41. #define IMS_TIMEOUT QMI_WLFW_TIMEOUT_JF
  42. #define QMI_WLFW_MAX_RECV_BUF_SIZE SZ_8K
  43. #define IMSPRIVATE_SERVICE_MAX_MSG_LEN SZ_8K
  44. #define DMS_QMI_MAX_MSG_LEN SZ_256
  45. #define MAX_SHADOW_REG_RESERVED 2
  46. #define MAX_NUM_SHADOW_REG_V3 (QMI_WLFW_MAX_NUM_SHADOW_REG_V3_USAGE_V01 - \
  47. MAX_SHADOW_REG_RESERVED)
  48. #define QMI_WLFW_MAC_READY_TIMEOUT_MS 50
  49. #define QMI_WLFW_MAC_READY_MAX_RETRY 200
  50. #ifdef CONFIG_CNSS2_DEBUG
  51. static bool ignore_qmi_failure;
  52. #define CNSS_QMI_ASSERT() CNSS_ASSERT(ignore_qmi_failure)
  53. void cnss_ignore_qmi_failure(bool ignore)
  54. {
  55. ignore_qmi_failure = ignore;
  56. }
  57. #else
  58. #define CNSS_QMI_ASSERT() do { } while (0)
  59. void cnss_ignore_qmi_failure(bool ignore) { }
  60. #endif
  61. static char *cnss_qmi_mode_to_str(enum cnss_driver_mode mode)
  62. {
  63. switch (mode) {
  64. case CNSS_MISSION:
  65. return "MISSION";
  66. case CNSS_FTM:
  67. return "FTM";
  68. case CNSS_EPPING:
  69. return "EPPING";
  70. case CNSS_WALTEST:
  71. return "WALTEST";
  72. case CNSS_OFF:
  73. return "OFF";
  74. case CNSS_CCPM:
  75. return "CCPM";
  76. case CNSS_QVIT:
  77. return "QVIT";
  78. case CNSS_CALIBRATION:
  79. return "CALIBRATION";
  80. default:
  81. return "UNKNOWN";
  82. }
  83. }
  84. static int qmi_send_wait(struct qmi_handle *qmi, void *req, void *rsp,
  85. struct qmi_elem_info *req_ei,
  86. struct qmi_elem_info *rsp_ei,
  87. int req_id, size_t req_len,
  88. unsigned long timeout)
  89. {
  90. struct qmi_txn txn;
  91. int ret;
  92. char *err_msg;
  93. struct qmi_response_type_v01 *resp = rsp;
  94. ret = qmi_txn_init(qmi, &txn, rsp_ei, rsp);
  95. if (ret < 0) {
  96. err_msg = "Qmi fail: fail to init txn,";
  97. goto out;
  98. }
  99. ret = qmi_send_request(qmi, NULL, &txn, req_id,
  100. req_len, req_ei, req);
  101. if (ret < 0) {
  102. qmi_txn_cancel(&txn);
  103. err_msg = "Qmi fail: fail to send req,";
  104. goto out;
  105. }
  106. ret = qmi_txn_wait(&txn, timeout);
  107. if (ret < 0) {
  108. err_msg = "Qmi fail: wait timeout,";
  109. goto out;
  110. } else if (resp->result != QMI_RESULT_SUCCESS_V01) {
  111. err_msg = "Qmi fail: request rejected,";
  112. cnss_pr_err("Qmi fail: respons with error:%d\n",
  113. resp->error);
  114. ret = -resp->result;
  115. goto out;
  116. }
  117. cnss_pr_dbg("req %x success\n", req_id);
  118. return 0;
  119. out:
  120. cnss_pr_err("%s req %x, ret %d\n", err_msg, req_id, ret);
  121. return ret;
  122. }
  123. static int cnss_wlfw_ind_register_send_sync(struct cnss_plat_data *plat_priv)
  124. {
  125. struct wlfw_ind_register_req_msg_v01 *req;
  126. struct wlfw_ind_register_resp_msg_v01 *resp;
  127. struct qmi_txn txn;
  128. int ret = 0;
  129. cnss_pr_dbg("Sending indication register message, state: 0x%lx\n",
  130. plat_priv->driver_state);
  131. req = kzalloc(sizeof(*req), GFP_KERNEL);
  132. if (!req)
  133. return -ENOMEM;
  134. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  135. if (!resp) {
  136. kfree(req);
  137. return -ENOMEM;
  138. }
  139. req->client_id_valid = 1;
  140. req->client_id = WLFW_CLIENT_ID;
  141. req->request_mem_enable_valid = 1;
  142. req->request_mem_enable = 1;
  143. req->fw_mem_ready_enable_valid = 1;
  144. req->fw_mem_ready_enable = 1;
  145. /* fw_ready indication is replaced by fw_init_done in HST/HSP */
  146. req->fw_init_done_enable_valid = 1;
  147. req->fw_init_done_enable = 1;
  148. req->pin_connect_result_enable_valid = 1;
  149. req->pin_connect_result_enable = 1;
  150. req->cal_done_enable_valid = 1;
  151. req->cal_done_enable = 1;
  152. req->qdss_trace_req_mem_enable_valid = 1;
  153. req->qdss_trace_req_mem_enable = 1;
  154. req->qdss_trace_save_enable_valid = 1;
  155. req->qdss_trace_save_enable = 1;
  156. req->qdss_trace_free_enable_valid = 1;
  157. req->qdss_trace_free_enable = 1;
  158. req->respond_get_info_enable_valid = 1;
  159. req->respond_get_info_enable = 1;
  160. req->wfc_call_twt_config_enable_valid = 1;
  161. req->wfc_call_twt_config_enable = 1;
  162. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  163. wlfw_ind_register_resp_msg_v01_ei, resp);
  164. if (ret < 0) {
  165. cnss_pr_err("Failed to initialize txn for indication register request, err: %d\n",
  166. ret);
  167. goto out;
  168. }
  169. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  170. QMI_WLFW_IND_REGISTER_REQ_V01,
  171. WLFW_IND_REGISTER_REQ_MSG_V01_MAX_MSG_LEN,
  172. wlfw_ind_register_req_msg_v01_ei, req);
  173. if (ret < 0) {
  174. qmi_txn_cancel(&txn);
  175. cnss_pr_err("Failed to send indication register request, err: %d\n",
  176. ret);
  177. goto out;
  178. }
  179. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  180. if (ret < 0) {
  181. cnss_pr_err("Failed to wait for response of indication register request, err: %d\n",
  182. ret);
  183. goto out;
  184. }
  185. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  186. cnss_pr_err("Indication register request failed, result: %d, err: %d\n",
  187. resp->resp.result, resp->resp.error);
  188. ret = -resp->resp.result;
  189. goto out;
  190. }
  191. if (resp->fw_status_valid) {
  192. if (resp->fw_status & QMI_WLFW_ALREADY_REGISTERED_V01) {
  193. ret = -EALREADY;
  194. goto qmi_registered;
  195. }
  196. }
  197. kfree(req);
  198. kfree(resp);
  199. return 0;
  200. out:
  201. CNSS_QMI_ASSERT();
  202. qmi_registered:
  203. kfree(req);
  204. kfree(resp);
  205. return ret;
  206. }
  207. static void cnss_wlfw_host_cap_parse_mlo(struct cnss_plat_data *plat_priv,
  208. struct wlfw_host_cap_req_msg_v01 *req)
  209. {
  210. if (plat_priv->device_id == KIWI_DEVICE_ID ||
  211. plat_priv->device_id == MANGO_DEVICE_ID) {
  212. req->mlo_capable_valid = 1;
  213. req->mlo_capable = 1;
  214. req->mlo_chip_id_valid = 1;
  215. req->mlo_chip_id = 0;
  216. req->mlo_group_id_valid = 1;
  217. req->mlo_group_id = 0;
  218. req->max_mlo_peer_valid = 1;
  219. /* Max peer number generally won't change for the same device
  220. * but needs to be synced with host driver.
  221. */
  222. req->max_mlo_peer = 32;
  223. req->mlo_num_chips_valid = 1;
  224. req->mlo_num_chips = 1;
  225. req->mlo_chip_info_valid = 1;
  226. req->mlo_chip_info[0].chip_id = 0;
  227. req->mlo_chip_info[0].num_local_links = 2;
  228. req->mlo_chip_info[0].hw_link_id[0] = 0;
  229. req->mlo_chip_info[0].hw_link_id[1] = 1;
  230. req->mlo_chip_info[0].valid_mlo_link_id[0] = 1;
  231. req->mlo_chip_info[0].valid_mlo_link_id[1] = 1;
  232. }
  233. }
  234. static int cnss_wlfw_host_cap_send_sync(struct cnss_plat_data *plat_priv)
  235. {
  236. struct wlfw_host_cap_req_msg_v01 *req;
  237. struct wlfw_host_cap_resp_msg_v01 *resp;
  238. struct qmi_txn txn;
  239. int ret = 0;
  240. u64 iova_start = 0, iova_size = 0,
  241. iova_ipa_start = 0, iova_ipa_size = 0;
  242. u64 feature_list = 0;
  243. cnss_pr_dbg("Sending host capability message, state: 0x%lx\n",
  244. plat_priv->driver_state);
  245. req = kzalloc(sizeof(*req), GFP_KERNEL);
  246. if (!req)
  247. return -ENOMEM;
  248. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  249. if (!resp) {
  250. kfree(req);
  251. return -ENOMEM;
  252. }
  253. req->num_clients_valid = 1;
  254. req->num_clients = 1;
  255. cnss_pr_dbg("Number of clients is %d\n", req->num_clients);
  256. req->wake_msi = cnss_bus_get_wake_irq(plat_priv);
  257. if (req->wake_msi) {
  258. cnss_pr_dbg("WAKE MSI base data is %d\n", req->wake_msi);
  259. req->wake_msi_valid = 1;
  260. }
  261. req->bdf_support_valid = 1;
  262. req->bdf_support = 1;
  263. req->m3_support_valid = 1;
  264. req->m3_support = 1;
  265. req->m3_cache_support_valid = 1;
  266. req->m3_cache_support = 1;
  267. req->cal_done_valid = 1;
  268. req->cal_done = plat_priv->cal_done;
  269. cnss_pr_dbg("Calibration done is %d\n", plat_priv->cal_done);
  270. if (cnss_bus_is_smmu_s1_enabled(plat_priv) &&
  271. !cnss_bus_get_iova(plat_priv, &iova_start, &iova_size) &&
  272. !cnss_bus_get_iova_ipa(plat_priv, &iova_ipa_start,
  273. &iova_ipa_size)) {
  274. req->ddr_range_valid = 1;
  275. req->ddr_range[0].start = iova_start;
  276. req->ddr_range[0].size = iova_size + iova_ipa_size;
  277. cnss_pr_dbg("Sending iova starting 0x%llx with size 0x%llx\n",
  278. req->ddr_range[0].start, req->ddr_range[0].size);
  279. }
  280. req->host_build_type_valid = 1;
  281. req->host_build_type = cnss_get_host_build_type();
  282. cnss_wlfw_host_cap_parse_mlo(plat_priv, req);
  283. ret = cnss_get_feature_list(plat_priv, &feature_list);
  284. if (!ret) {
  285. req->feature_list_valid = 1;
  286. req->feature_list = feature_list;
  287. cnss_pr_dbg("Sending feature list 0x%llx\n",
  288. req->feature_list);
  289. }
  290. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  291. wlfw_host_cap_resp_msg_v01_ei, resp);
  292. if (ret < 0) {
  293. cnss_pr_err("Failed to initialize txn for host capability request, err: %d\n",
  294. ret);
  295. goto out;
  296. }
  297. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  298. QMI_WLFW_HOST_CAP_REQ_V01,
  299. WLFW_HOST_CAP_REQ_MSG_V01_MAX_MSG_LEN,
  300. wlfw_host_cap_req_msg_v01_ei, req);
  301. if (ret < 0) {
  302. qmi_txn_cancel(&txn);
  303. cnss_pr_err("Failed to send host capability request, err: %d\n",
  304. ret);
  305. goto out;
  306. }
  307. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  308. if (ret < 0) {
  309. cnss_pr_err("Failed to wait for response of host capability request, err: %d\n",
  310. ret);
  311. goto out;
  312. }
  313. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  314. cnss_pr_err("Host capability request failed, result: %d, err: %d\n",
  315. resp->resp.result, resp->resp.error);
  316. ret = -resp->resp.result;
  317. goto out;
  318. }
  319. kfree(req);
  320. kfree(resp);
  321. return 0;
  322. out:
  323. CNSS_QMI_ASSERT();
  324. kfree(req);
  325. kfree(resp);
  326. return ret;
  327. }
  328. int cnss_wlfw_respond_mem_send_sync(struct cnss_plat_data *plat_priv)
  329. {
  330. struct wlfw_respond_mem_req_msg_v01 *req;
  331. struct wlfw_respond_mem_resp_msg_v01 *resp;
  332. struct qmi_txn txn;
  333. struct cnss_fw_mem *fw_mem = plat_priv->fw_mem;
  334. int ret = 0, i;
  335. cnss_pr_dbg("Sending respond memory message, state: 0x%lx\n",
  336. plat_priv->driver_state);
  337. req = kzalloc(sizeof(*req), GFP_KERNEL);
  338. if (!req)
  339. return -ENOMEM;
  340. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  341. if (!resp) {
  342. kfree(req);
  343. return -ENOMEM;
  344. }
  345. req->mem_seg_len = plat_priv->fw_mem_seg_len;
  346. for (i = 0; i < req->mem_seg_len; i++) {
  347. if (!fw_mem[i].pa || !fw_mem[i].size) {
  348. if (fw_mem[i].type == 0) {
  349. cnss_pr_err("Invalid memory for FW type, segment = %d\n",
  350. i);
  351. ret = -EINVAL;
  352. goto out;
  353. }
  354. cnss_pr_err("Memory for FW is not available for type: %u\n",
  355. fw_mem[i].type);
  356. ret = -ENOMEM;
  357. goto out;
  358. }
  359. cnss_pr_dbg("Memory for FW, va: 0x%pK, pa: %pa, size: 0x%zx, type: %u\n",
  360. fw_mem[i].va, &fw_mem[i].pa,
  361. fw_mem[i].size, fw_mem[i].type);
  362. req->mem_seg[i].addr = fw_mem[i].pa;
  363. req->mem_seg[i].size = fw_mem[i].size;
  364. req->mem_seg[i].type = fw_mem[i].type;
  365. }
  366. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  367. wlfw_respond_mem_resp_msg_v01_ei, resp);
  368. if (ret < 0) {
  369. cnss_pr_err("Failed to initialize txn for respond memory request, err: %d\n",
  370. ret);
  371. goto out;
  372. }
  373. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  374. QMI_WLFW_RESPOND_MEM_REQ_V01,
  375. WLFW_RESPOND_MEM_REQ_MSG_V01_MAX_MSG_LEN,
  376. wlfw_respond_mem_req_msg_v01_ei, req);
  377. if (ret < 0) {
  378. qmi_txn_cancel(&txn);
  379. cnss_pr_err("Failed to send respond memory request, err: %d\n",
  380. ret);
  381. goto out;
  382. }
  383. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  384. if (ret < 0) {
  385. cnss_pr_err("Failed to wait for response of respond memory request, err: %d\n",
  386. ret);
  387. goto out;
  388. }
  389. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  390. cnss_pr_err("Respond memory request failed, result: %d, err: %d\n",
  391. resp->resp.result, resp->resp.error);
  392. ret = -resp->resp.result;
  393. goto out;
  394. }
  395. kfree(req);
  396. kfree(resp);
  397. return 0;
  398. out:
  399. CNSS_QMI_ASSERT();
  400. kfree(req);
  401. kfree(resp);
  402. return ret;
  403. }
  404. int cnss_wlfw_tgt_cap_send_sync(struct cnss_plat_data *plat_priv)
  405. {
  406. struct wlfw_cap_req_msg_v01 *req;
  407. struct wlfw_cap_resp_msg_v01 *resp;
  408. struct qmi_txn txn;
  409. char *fw_build_timestamp;
  410. int ret = 0, i;
  411. cnss_pr_dbg("Sending target capability message, state: 0x%lx\n",
  412. plat_priv->driver_state);
  413. req = kzalloc(sizeof(*req), GFP_KERNEL);
  414. if (!req)
  415. return -ENOMEM;
  416. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  417. if (!resp) {
  418. kfree(req);
  419. return -ENOMEM;
  420. }
  421. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  422. wlfw_cap_resp_msg_v01_ei, resp);
  423. if (ret < 0) {
  424. cnss_pr_err("Failed to initialize txn for target capability request, err: %d\n",
  425. ret);
  426. goto out;
  427. }
  428. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  429. QMI_WLFW_CAP_REQ_V01,
  430. WLFW_CAP_REQ_MSG_V01_MAX_MSG_LEN,
  431. wlfw_cap_req_msg_v01_ei, req);
  432. if (ret < 0) {
  433. qmi_txn_cancel(&txn);
  434. cnss_pr_err("Failed to send respond target capability request, err: %d\n",
  435. ret);
  436. goto out;
  437. }
  438. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  439. if (ret < 0) {
  440. cnss_pr_err("Failed to wait for response of target capability request, err: %d\n",
  441. ret);
  442. goto out;
  443. }
  444. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  445. cnss_pr_err("Target capability request failed, result: %d, err: %d\n",
  446. resp->resp.result, resp->resp.error);
  447. ret = -resp->resp.result;
  448. goto out;
  449. }
  450. if (resp->chip_info_valid) {
  451. plat_priv->chip_info.chip_id = resp->chip_info.chip_id;
  452. plat_priv->chip_info.chip_family = resp->chip_info.chip_family;
  453. }
  454. if (resp->board_info_valid)
  455. plat_priv->board_info.board_id = resp->board_info.board_id;
  456. else
  457. plat_priv->board_info.board_id = 0xFF;
  458. if (resp->soc_info_valid)
  459. plat_priv->soc_info.soc_id = resp->soc_info.soc_id;
  460. if (resp->fw_version_info_valid) {
  461. plat_priv->fw_version_info.fw_version =
  462. resp->fw_version_info.fw_version;
  463. fw_build_timestamp = resp->fw_version_info.fw_build_timestamp;
  464. fw_build_timestamp[QMI_WLFW_MAX_TIMESTAMP_LEN] = '\0';
  465. strlcpy(plat_priv->fw_version_info.fw_build_timestamp,
  466. resp->fw_version_info.fw_build_timestamp,
  467. QMI_WLFW_MAX_TIMESTAMP_LEN + 1);
  468. }
  469. if (resp->fw_build_id_valid) {
  470. resp->fw_build_id[QMI_WLFW_MAX_BUILD_ID_LEN] = '\0';
  471. strlcpy(plat_priv->fw_build_id, resp->fw_build_id,
  472. QMI_WLFW_MAX_BUILD_ID_LEN + 1);
  473. }
  474. /* FW will send aop retention volatage for qca6490 */
  475. if (resp->voltage_mv_valid) {
  476. plat_priv->cpr_info.voltage = resp->voltage_mv;
  477. cnss_pr_dbg("Voltage for CPR: %dmV\n",
  478. plat_priv->cpr_info.voltage);
  479. cnss_update_cpr_info(plat_priv);
  480. }
  481. if (resp->time_freq_hz_valid) {
  482. plat_priv->device_freq_hz = resp->time_freq_hz;
  483. cnss_pr_dbg("Device frequency is %d HZ\n",
  484. plat_priv->device_freq_hz);
  485. }
  486. if (resp->otp_version_valid)
  487. plat_priv->otp_version = resp->otp_version;
  488. if (resp->dev_mem_info_valid) {
  489. for (i = 0; i < QMI_WLFW_MAX_DEV_MEM_NUM_V01; i++) {
  490. plat_priv->dev_mem_info[i].start =
  491. resp->dev_mem_info[i].start;
  492. plat_priv->dev_mem_info[i].size =
  493. resp->dev_mem_info[i].size;
  494. cnss_pr_buf("Device memory info[%d]: start = 0x%llx, size = 0x%llx\n",
  495. i, plat_priv->dev_mem_info[i].start,
  496. plat_priv->dev_mem_info[i].size);
  497. }
  498. }
  499. if (resp->fw_caps_valid) {
  500. plat_priv->fw_pcie_gen_switch =
  501. !!(resp->fw_caps & QMI_WLFW_HOST_PCIE_GEN_SWITCH_V01);
  502. plat_priv->fw_caps = resp->fw_caps;
  503. }
  504. if (resp->hang_data_length_valid &&
  505. resp->hang_data_length &&
  506. resp->hang_data_length <= WLFW_MAX_HANG_EVENT_DATA_SIZE)
  507. plat_priv->hang_event_data_len = resp->hang_data_length;
  508. else
  509. plat_priv->hang_event_data_len = 0;
  510. if (resp->hang_data_addr_offset_valid)
  511. plat_priv->hang_data_addr_offset = resp->hang_data_addr_offset;
  512. else
  513. plat_priv->hang_data_addr_offset = 0;
  514. if (resp->hwid_bitmap_valid)
  515. plat_priv->hwid_bitmap = resp->hwid_bitmap;
  516. if (resp->ol_cpr_cfg_valid)
  517. cnss_aop_ol_cpr_cfg_setup(plat_priv, &resp->ol_cpr_cfg);
  518. cnss_pr_dbg("Target capability: chip_id: 0x%x, chip_family: 0x%x, board_id: 0x%x, soc_id: 0x%x, otp_version: 0x%x\n",
  519. plat_priv->chip_info.chip_id,
  520. plat_priv->chip_info.chip_family,
  521. plat_priv->board_info.board_id, plat_priv->soc_info.soc_id,
  522. plat_priv->otp_version);
  523. cnss_pr_dbg("fw_version: 0x%x, fw_build_timestamp: %s, fw_build_id: %s, hwid_bitmap:0x%x\n",
  524. plat_priv->fw_version_info.fw_version,
  525. plat_priv->fw_version_info.fw_build_timestamp,
  526. plat_priv->fw_build_id,
  527. plat_priv->hwid_bitmap);
  528. cnss_pr_dbg("Hang event params, Length: 0x%x, Offset Address: 0x%x\n",
  529. plat_priv->hang_event_data_len,
  530. plat_priv->hang_data_addr_offset);
  531. kfree(req);
  532. kfree(resp);
  533. return 0;
  534. out:
  535. CNSS_QMI_ASSERT();
  536. kfree(req);
  537. kfree(resp);
  538. return ret;
  539. }
  540. static int cnss_get_bdf_file_name(struct cnss_plat_data *plat_priv,
  541. u32 bdf_type, char *filename,
  542. u32 filename_len)
  543. {
  544. char filename_tmp[MAX_FIRMWARE_NAME_LEN];
  545. int ret = 0;
  546. switch (bdf_type) {
  547. case CNSS_BDF_ELF:
  548. /* Board ID will be equal or less than 0xFF in GF mask case */
  549. if (plat_priv->board_info.board_id == 0xFF) {
  550. if (plat_priv->chip_info.chip_id & CHIP_ID_GF_MASK)
  551. snprintf(filename_tmp, filename_len,
  552. ELF_BDF_FILE_NAME_GF);
  553. else
  554. snprintf(filename_tmp, filename_len,
  555. ELF_BDF_FILE_NAME);
  556. } else if (plat_priv->board_info.board_id < 0xFF) {
  557. if (plat_priv->chip_info.chip_id & CHIP_ID_GF_MASK)
  558. snprintf(filename_tmp, filename_len,
  559. ELF_BDF_FILE_NAME_GF_PREFIX "%02x",
  560. plat_priv->board_info.board_id);
  561. else
  562. snprintf(filename_tmp, filename_len,
  563. ELF_BDF_FILE_NAME_PREFIX "%02x",
  564. plat_priv->board_info.board_id);
  565. } else {
  566. snprintf(filename_tmp, filename_len,
  567. BDF_FILE_NAME_PREFIX "%02x.e%02x",
  568. plat_priv->board_info.board_id >> 8 & 0xFF,
  569. plat_priv->board_info.board_id & 0xFF);
  570. }
  571. break;
  572. case CNSS_BDF_BIN:
  573. if (plat_priv->board_info.board_id == 0xFF) {
  574. if (plat_priv->chip_info.chip_id & CHIP_ID_GF_MASK)
  575. snprintf(filename_tmp, filename_len,
  576. BIN_BDF_FILE_NAME_GF);
  577. else
  578. snprintf(filename_tmp, filename_len,
  579. BIN_BDF_FILE_NAME);
  580. } else if (plat_priv->board_info.board_id < 0xFF) {
  581. if (plat_priv->chip_info.chip_id & CHIP_ID_GF_MASK)
  582. snprintf(filename_tmp, filename_len,
  583. BIN_BDF_FILE_NAME_GF_PREFIX "%02x",
  584. plat_priv->board_info.board_id);
  585. else
  586. snprintf(filename_tmp, filename_len,
  587. BIN_BDF_FILE_NAME_PREFIX "%02x",
  588. plat_priv->board_info.board_id);
  589. } else {
  590. snprintf(filename_tmp, filename_len,
  591. BDF_FILE_NAME_PREFIX "%02x.b%02x",
  592. plat_priv->board_info.board_id >> 8 & 0xFF,
  593. plat_priv->board_info.board_id & 0xFF);
  594. }
  595. break;
  596. case CNSS_BDF_REGDB:
  597. snprintf(filename_tmp, filename_len, REGDB_FILE_NAME);
  598. break;
  599. case CNSS_BDF_HDS:
  600. snprintf(filename_tmp, filename_len, HDS_FILE_NAME);
  601. break;
  602. default:
  603. cnss_pr_err("Invalid BDF type: %d\n",
  604. plat_priv->ctrl_params.bdf_type);
  605. ret = -EINVAL;
  606. break;
  607. }
  608. if (!ret)
  609. cnss_bus_add_fw_prefix_name(plat_priv, filename, filename_tmp);
  610. return ret;
  611. }
  612. int cnss_wlfw_ini_file_send_sync(struct cnss_plat_data *plat_priv,
  613. enum wlfw_ini_file_type_v01 file_type)
  614. {
  615. struct wlfw_ini_file_download_req_msg_v01 *req;
  616. struct wlfw_ini_file_download_resp_msg_v01 *resp;
  617. struct qmi_txn txn;
  618. int ret = 0;
  619. const struct firmware *fw;
  620. char filename[INI_FILE_NAME_LEN] = {0};
  621. char tmp_filename[INI_FILE_NAME_LEN] = {0};
  622. const u8 *temp;
  623. unsigned int remaining;
  624. bool backup_supported = false;
  625. cnss_pr_info("INI File %u download\n", file_type);
  626. req = kzalloc(sizeof(*req), GFP_KERNEL);
  627. if (!req)
  628. return -ENOMEM;
  629. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  630. if (!resp) {
  631. kfree(req);
  632. return -ENOMEM;
  633. }
  634. switch (file_type) {
  635. case WLFW_CONN_ROAM_INI_V01:
  636. snprintf(tmp_filename, sizeof(tmp_filename),
  637. CONN_ROAM_FILE_NAME);
  638. backup_supported = true;
  639. break;
  640. default:
  641. cnss_pr_err("Invalid file type: %u\n", file_type);
  642. ret = -EINVAL;
  643. goto err_req_fw;
  644. }
  645. snprintf(filename, sizeof(filename), "%s%s", tmp_filename, INI_EXT);
  646. /* Fetch the file */
  647. ret = firmware_request_nowarn(&fw, filename, &plat_priv->plat_dev->dev);
  648. if (ret) {
  649. cnss_pr_err("Failed to get INI file %s (%d), Backup file: %s",
  650. filename, ret,
  651. backup_supported ? "Supported" : "Not Supported");
  652. if (!backup_supported)
  653. goto err_req_fw;
  654. snprintf(filename, sizeof(filename),
  655. "%s-%s%s", tmp_filename, "backup", INI_EXT);
  656. ret = firmware_request_nowarn(&fw, filename,
  657. &plat_priv->plat_dev->dev);
  658. if (ret) {
  659. cnss_pr_err("Failed to get INI file %s (%d)", filename,
  660. ret);
  661. goto err_req_fw;
  662. }
  663. }
  664. temp = fw->data;
  665. remaining = fw->size;
  666. cnss_pr_dbg("Downloading INI file: %s, size: %u\n", filename,
  667. remaining);
  668. while (remaining) {
  669. req->file_type_valid = 1;
  670. req->file_type = file_type;
  671. req->total_size_valid = 1;
  672. req->total_size = remaining;
  673. req->seg_id_valid = 1;
  674. req->data_valid = 1;
  675. req->end_valid = 1;
  676. if (remaining > QMI_WLFW_MAX_DATA_SIZE_V01) {
  677. req->data_len = QMI_WLFW_MAX_DATA_SIZE_V01;
  678. } else {
  679. req->data_len = remaining;
  680. req->end = 1;
  681. }
  682. memcpy(req->data, temp, req->data_len);
  683. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  684. wlfw_ini_file_download_resp_msg_v01_ei,
  685. resp);
  686. if (ret < 0) {
  687. cnss_pr_err("Failed to initialize txn for INI file download request, err: %d\n",
  688. ret);
  689. goto err;
  690. }
  691. ret = qmi_send_request
  692. (&plat_priv->qmi_wlfw, NULL, &txn,
  693. QMI_WLFW_INI_FILE_DOWNLOAD_REQ_V01,
  694. WLFW_INI_FILE_DOWNLOAD_REQ_MSG_V01_MAX_MSG_LEN,
  695. wlfw_ini_file_download_req_msg_v01_ei, req);
  696. if (ret < 0) {
  697. qmi_txn_cancel(&txn);
  698. cnss_pr_err("Failed to send INI File download request, err: %d\n",
  699. ret);
  700. goto err;
  701. }
  702. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  703. if (ret < 0) {
  704. cnss_pr_err("Failed to wait for response of INI File download request, err: %d\n",
  705. ret);
  706. goto err;
  707. }
  708. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  709. cnss_pr_err("INI file download request failed, result: %d, err: %d\n",
  710. resp->resp.result, resp->resp.error);
  711. ret = -resp->resp.result;
  712. goto err;
  713. }
  714. remaining -= req->data_len;
  715. temp += req->data_len;
  716. req->seg_id++;
  717. }
  718. release_firmware(fw);
  719. kfree(req);
  720. kfree(resp);
  721. return 0;
  722. err:
  723. release_firmware(fw);
  724. err_req_fw:
  725. kfree(req);
  726. kfree(resp);
  727. return ret;
  728. }
  729. int cnss_wlfw_bdf_dnld_send_sync(struct cnss_plat_data *plat_priv,
  730. u32 bdf_type)
  731. {
  732. struct wlfw_bdf_download_req_msg_v01 *req;
  733. struct wlfw_bdf_download_resp_msg_v01 *resp;
  734. struct qmi_txn txn;
  735. char filename[MAX_FIRMWARE_NAME_LEN];
  736. const struct firmware *fw_entry = NULL;
  737. const u8 *temp;
  738. unsigned int remaining;
  739. int ret = 0;
  740. cnss_pr_dbg("Sending BDF download message, state: 0x%lx, type: %d\n",
  741. plat_priv->driver_state, bdf_type);
  742. req = kzalloc(sizeof(*req), GFP_KERNEL);
  743. if (!req)
  744. return -ENOMEM;
  745. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  746. if (!resp) {
  747. kfree(req);
  748. return -ENOMEM;
  749. }
  750. ret = cnss_get_bdf_file_name(plat_priv, bdf_type,
  751. filename, sizeof(filename));
  752. if (ret)
  753. goto err_req_fw;
  754. if (bdf_type == CNSS_BDF_REGDB)
  755. ret = cnss_request_firmware_direct(plat_priv, &fw_entry,
  756. filename);
  757. else
  758. ret = firmware_request_nowarn(&fw_entry, filename,
  759. &plat_priv->plat_dev->dev);
  760. if (ret) {
  761. cnss_pr_err("Failed to load BDF: %s, ret: %d\n", filename, ret);
  762. goto err_req_fw;
  763. }
  764. temp = fw_entry->data;
  765. remaining = fw_entry->size;
  766. cnss_pr_dbg("Downloading BDF: %s, size: %u\n", filename, remaining);
  767. while (remaining) {
  768. req->valid = 1;
  769. req->file_id_valid = 1;
  770. req->file_id = plat_priv->board_info.board_id;
  771. req->total_size_valid = 1;
  772. req->total_size = remaining;
  773. req->seg_id_valid = 1;
  774. req->data_valid = 1;
  775. req->end_valid = 1;
  776. req->bdf_type_valid = 1;
  777. req->bdf_type = bdf_type;
  778. if (remaining > QMI_WLFW_MAX_DATA_SIZE_V01) {
  779. req->data_len = QMI_WLFW_MAX_DATA_SIZE_V01;
  780. } else {
  781. req->data_len = remaining;
  782. req->end = 1;
  783. }
  784. memcpy(req->data, temp, req->data_len);
  785. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  786. wlfw_bdf_download_resp_msg_v01_ei, resp);
  787. if (ret < 0) {
  788. cnss_pr_err("Failed to initialize txn for BDF download request, err: %d\n",
  789. ret);
  790. goto err_send;
  791. }
  792. ret = qmi_send_request
  793. (&plat_priv->qmi_wlfw, NULL, &txn,
  794. QMI_WLFW_BDF_DOWNLOAD_REQ_V01,
  795. WLFW_BDF_DOWNLOAD_REQ_MSG_V01_MAX_MSG_LEN,
  796. wlfw_bdf_download_req_msg_v01_ei, req);
  797. if (ret < 0) {
  798. qmi_txn_cancel(&txn);
  799. cnss_pr_err("Failed to send respond BDF download request, err: %d\n",
  800. ret);
  801. goto err_send;
  802. }
  803. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  804. if (ret < 0) {
  805. cnss_pr_err("Failed to wait for response of BDF download request, err: %d\n",
  806. ret);
  807. goto err_send;
  808. }
  809. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  810. cnss_pr_err("BDF download request failed, result: %d, err: %d\n",
  811. resp->resp.result, resp->resp.error);
  812. ret = -resp->resp.result;
  813. goto err_send;
  814. }
  815. remaining -= req->data_len;
  816. temp += req->data_len;
  817. req->seg_id++;
  818. }
  819. release_firmware(fw_entry);
  820. if (resp->host_bdf_data_valid) {
  821. /* QCA6490 enable S3E regulator for IPA configuration only */
  822. if (!(resp->host_bdf_data & QMI_WLFW_HW_XPA_V01))
  823. cnss_enable_int_pow_amp_vreg(plat_priv);
  824. plat_priv->cbc_file_download =
  825. resp->host_bdf_data & QMI_WLFW_CBC_FILE_DOWNLOAD_V01;
  826. cnss_pr_info("Host BDF config: HW_XPA: %d CalDB: %d\n",
  827. resp->host_bdf_data & QMI_WLFW_HW_XPA_V01,
  828. plat_priv->cbc_file_download);
  829. }
  830. kfree(req);
  831. kfree(resp);
  832. return 0;
  833. err_send:
  834. release_firmware(fw_entry);
  835. err_req_fw:
  836. if (!(bdf_type == CNSS_BDF_REGDB ||
  837. test_bit(CNSS_IN_REBOOT, &plat_priv->driver_state) ||
  838. ret == -EAGAIN))
  839. CNSS_QMI_ASSERT();
  840. kfree(req);
  841. kfree(resp);
  842. return ret;
  843. }
  844. int cnss_wlfw_m3_dnld_send_sync(struct cnss_plat_data *plat_priv)
  845. {
  846. struct wlfw_m3_info_req_msg_v01 *req;
  847. struct wlfw_m3_info_resp_msg_v01 *resp;
  848. struct qmi_txn txn;
  849. struct cnss_fw_mem *m3_mem = &plat_priv->m3_mem;
  850. int ret = 0;
  851. cnss_pr_dbg("Sending M3 information message, state: 0x%lx\n",
  852. plat_priv->driver_state);
  853. req = kzalloc(sizeof(*req), GFP_KERNEL);
  854. if (!req)
  855. return -ENOMEM;
  856. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  857. if (!resp) {
  858. kfree(req);
  859. return -ENOMEM;
  860. }
  861. if (!m3_mem->pa || !m3_mem->size) {
  862. cnss_pr_err("Memory for M3 is not available\n");
  863. ret = -ENOMEM;
  864. goto out;
  865. }
  866. cnss_pr_dbg("M3 memory, va: 0x%pK, pa: %pa, size: 0x%zx\n",
  867. m3_mem->va, &m3_mem->pa, m3_mem->size);
  868. req->addr = plat_priv->m3_mem.pa;
  869. req->size = plat_priv->m3_mem.size;
  870. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  871. wlfw_m3_info_resp_msg_v01_ei, resp);
  872. if (ret < 0) {
  873. cnss_pr_err("Failed to initialize txn for M3 information request, err: %d\n",
  874. ret);
  875. goto out;
  876. }
  877. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  878. QMI_WLFW_M3_INFO_REQ_V01,
  879. WLFW_M3_INFO_REQ_MSG_V01_MAX_MSG_LEN,
  880. wlfw_m3_info_req_msg_v01_ei, req);
  881. if (ret < 0) {
  882. qmi_txn_cancel(&txn);
  883. cnss_pr_err("Failed to send M3 information request, err: %d\n",
  884. ret);
  885. goto out;
  886. }
  887. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  888. if (ret < 0) {
  889. cnss_pr_err("Failed to wait for response of M3 information request, err: %d\n",
  890. ret);
  891. goto out;
  892. }
  893. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  894. cnss_pr_err("M3 information request failed, result: %d, err: %d\n",
  895. resp->resp.result, resp->resp.error);
  896. ret = -resp->resp.result;
  897. goto out;
  898. }
  899. kfree(req);
  900. kfree(resp);
  901. return 0;
  902. out:
  903. CNSS_QMI_ASSERT();
  904. kfree(req);
  905. kfree(resp);
  906. return ret;
  907. }
  908. int cnss_wlfw_wlan_mac_req_send_sync(struct cnss_plat_data *plat_priv,
  909. u8 *mac, u32 mac_len)
  910. {
  911. struct wlfw_mac_addr_req_msg_v01 req;
  912. struct wlfw_mac_addr_resp_msg_v01 resp = {0};
  913. struct qmi_txn txn;
  914. int ret;
  915. if (!plat_priv || !mac || mac_len != QMI_WLFW_MAC_ADDR_SIZE_V01)
  916. return -EINVAL;
  917. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  918. wlfw_mac_addr_resp_msg_v01_ei, &resp);
  919. if (ret < 0) {
  920. cnss_pr_err("Failed to initialize txn for mac req, err: %d\n",
  921. ret);
  922. ret = -EIO;
  923. goto out;
  924. }
  925. cnss_pr_dbg("Sending WLAN mac req [%pM], state: 0x%lx\n",
  926. mac, plat_priv->driver_state);
  927. memcpy(req.mac_addr, mac, mac_len);
  928. req.mac_addr_valid = 1;
  929. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  930. QMI_WLFW_MAC_ADDR_REQ_V01,
  931. WLFW_MAC_ADDR_REQ_MSG_V01_MAX_MSG_LEN,
  932. wlfw_mac_addr_req_msg_v01_ei, &req);
  933. if (ret < 0) {
  934. qmi_txn_cancel(&txn);
  935. cnss_pr_err("Failed to send mac req, err: %d\n", ret);
  936. ret = -EIO;
  937. goto out;
  938. }
  939. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  940. if (ret < 0) {
  941. cnss_pr_err("Failed to wait for resp of mac req, err: %d\n",
  942. ret);
  943. ret = -EIO;
  944. goto out;
  945. }
  946. if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
  947. cnss_pr_err("WLAN mac req failed, result: %d, err: %d\n",
  948. resp.resp.result);
  949. ret = -resp.resp.result;
  950. }
  951. out:
  952. return ret;
  953. }
  954. int cnss_wlfw_qdss_data_send_sync(struct cnss_plat_data *plat_priv, char *file_name,
  955. u32 total_size)
  956. {
  957. int ret = 0;
  958. struct wlfw_qdss_trace_data_req_msg_v01 *req;
  959. struct wlfw_qdss_trace_data_resp_msg_v01 *resp;
  960. unsigned char *p_qdss_trace_data_temp, *p_qdss_trace_data = NULL;
  961. unsigned int remaining;
  962. struct qmi_txn txn;
  963. cnss_pr_dbg("%s\n", __func__);
  964. req = kzalloc(sizeof(*req), GFP_KERNEL);
  965. if (!req)
  966. return -ENOMEM;
  967. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  968. if (!resp) {
  969. kfree(req);
  970. return -ENOMEM;
  971. }
  972. p_qdss_trace_data = kzalloc(total_size, GFP_KERNEL);
  973. if (!p_qdss_trace_data) {
  974. ret = ENOMEM;
  975. goto end;
  976. }
  977. remaining = total_size;
  978. p_qdss_trace_data_temp = p_qdss_trace_data;
  979. while (remaining && resp->end == 0) {
  980. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  981. wlfw_qdss_trace_data_resp_msg_v01_ei, resp);
  982. if (ret < 0) {
  983. cnss_pr_err("Fail to init txn for QDSS trace resp %d\n",
  984. ret);
  985. goto fail;
  986. }
  987. ret = qmi_send_request
  988. (&plat_priv->qmi_wlfw, NULL, &txn,
  989. QMI_WLFW_QDSS_TRACE_DATA_REQ_V01,
  990. WLFW_QDSS_TRACE_DATA_REQ_MSG_V01_MAX_MSG_LEN,
  991. wlfw_qdss_trace_data_req_msg_v01_ei, req);
  992. if (ret < 0) {
  993. qmi_txn_cancel(&txn);
  994. cnss_pr_err("Fail to send QDSS trace data req %d\n",
  995. ret);
  996. goto fail;
  997. }
  998. ret = qmi_txn_wait(&txn, plat_priv->ctrl_params.qmi_timeout);
  999. if (ret < 0) {
  1000. cnss_pr_err("QDSS trace resp wait failed with rc %d\n",
  1001. ret);
  1002. goto fail;
  1003. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1004. cnss_pr_err("QMI QDSS trace request rejected, result:%d error:%d\n",
  1005. resp->resp.result, resp->resp.error);
  1006. ret = -resp->resp.result;
  1007. goto fail;
  1008. } else {
  1009. ret = 0;
  1010. }
  1011. cnss_pr_dbg("%s: response total size %d data len %d",
  1012. __func__, resp->total_size, resp->data_len);
  1013. if ((resp->total_size_valid == 1 &&
  1014. resp->total_size == total_size) &&
  1015. (resp->seg_id_valid == 1 && resp->seg_id == req->seg_id) &&
  1016. (resp->data_valid == 1 &&
  1017. resp->data_len <= QMI_WLFW_MAX_DATA_SIZE_V01)) {
  1018. memcpy(p_qdss_trace_data_temp,
  1019. resp->data, resp->data_len);
  1020. } else {
  1021. cnss_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",
  1022. __func__,
  1023. total_size, req->seg_id,
  1024. resp->total_size_valid,
  1025. resp->total_size,
  1026. resp->seg_id_valid,
  1027. resp->seg_id,
  1028. resp->data_valid,
  1029. resp->data_len);
  1030. ret = -1;
  1031. goto fail;
  1032. }
  1033. remaining -= resp->data_len;
  1034. p_qdss_trace_data_temp += resp->data_len;
  1035. req->seg_id++;
  1036. }
  1037. if (remaining == 0 && (resp->end_valid && resp->end)) {
  1038. ret = cnss_genl_send_msg(p_qdss_trace_data,
  1039. CNSS_GENL_MSG_TYPE_QDSS, file_name,
  1040. total_size);
  1041. if (ret < 0) {
  1042. cnss_pr_err("Fail to save QDSS trace data: %d\n",
  1043. ret);
  1044. ret = -1;
  1045. goto fail;
  1046. }
  1047. } else {
  1048. cnss_pr_err("%s: QDSS trace file corrupted: remaining %u, end_valid %u, end %u",
  1049. __func__,
  1050. remaining, resp->end_valid, resp->end);
  1051. ret = -1;
  1052. goto fail;
  1053. }
  1054. fail:
  1055. kfree(p_qdss_trace_data);
  1056. end:
  1057. kfree(req);
  1058. kfree(resp);
  1059. return ret;
  1060. }
  1061. void cnss_get_qdss_cfg_filename(struct cnss_plat_data *plat_priv,
  1062. char *filename, u32 filename_len)
  1063. {
  1064. char filename_tmp[MAX_FIRMWARE_NAME_LEN];
  1065. char *debug_str = QDSS_DEBUG_FILE_STR;
  1066. if (plat_priv->device_id == KIWI_DEVICE_ID ||
  1067. plat_priv->device_id == MANGO_DEVICE_ID)
  1068. debug_str = "";
  1069. if (plat_priv->device_version.major_version == FW_V2_NUMBER)
  1070. snprintf(filename_tmp, filename_len, QDSS_TRACE_CONFIG_FILE
  1071. "_%s%s.cfg", debug_str, HW_V2_NUMBER);
  1072. else
  1073. snprintf(filename_tmp, filename_len, QDSS_TRACE_CONFIG_FILE
  1074. "_%s%s.cfg", debug_str, HW_V1_NUMBER);
  1075. cnss_bus_add_fw_prefix_name(plat_priv, filename, filename_tmp);
  1076. }
  1077. int cnss_wlfw_qdss_dnld_send_sync(struct cnss_plat_data *plat_priv)
  1078. {
  1079. struct wlfw_qdss_trace_config_download_req_msg_v01 *req;
  1080. struct wlfw_qdss_trace_config_download_resp_msg_v01 *resp;
  1081. struct qmi_txn txn;
  1082. const struct firmware *fw_entry = NULL;
  1083. const u8 *temp;
  1084. char qdss_cfg_filename[MAX_FIRMWARE_NAME_LEN];
  1085. unsigned int remaining;
  1086. int ret = 0;
  1087. cnss_pr_dbg("Sending QDSS config download message, state: 0x%lx\n",
  1088. plat_priv->driver_state);
  1089. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1090. if (!req)
  1091. return -ENOMEM;
  1092. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1093. if (!resp) {
  1094. kfree(req);
  1095. return -ENOMEM;
  1096. }
  1097. cnss_get_qdss_cfg_filename(plat_priv, qdss_cfg_filename, sizeof(qdss_cfg_filename));
  1098. ret = cnss_request_firmware_direct(plat_priv, &fw_entry,
  1099. qdss_cfg_filename);
  1100. if (ret) {
  1101. cnss_pr_dbg("Unable to load %s\n",
  1102. qdss_cfg_filename);
  1103. goto err_req_fw;
  1104. }
  1105. temp = fw_entry->data;
  1106. remaining = fw_entry->size;
  1107. cnss_pr_dbg("Downloading QDSS: %s, size: %u\n",
  1108. qdss_cfg_filename, remaining);
  1109. while (remaining) {
  1110. req->total_size_valid = 1;
  1111. req->total_size = remaining;
  1112. req->seg_id_valid = 1;
  1113. req->data_valid = 1;
  1114. req->end_valid = 1;
  1115. if (remaining > QMI_WLFW_MAX_DATA_SIZE_V01) {
  1116. req->data_len = QMI_WLFW_MAX_DATA_SIZE_V01;
  1117. } else {
  1118. req->data_len = remaining;
  1119. req->end = 1;
  1120. }
  1121. memcpy(req->data, temp, req->data_len);
  1122. ret = qmi_txn_init
  1123. (&plat_priv->qmi_wlfw, &txn,
  1124. wlfw_qdss_trace_config_download_resp_msg_v01_ei,
  1125. resp);
  1126. if (ret < 0) {
  1127. cnss_pr_err("Failed to initialize txn for QDSS download request, err: %d\n",
  1128. ret);
  1129. goto err_send;
  1130. }
  1131. ret = qmi_send_request
  1132. (&plat_priv->qmi_wlfw, NULL, &txn,
  1133. QMI_WLFW_QDSS_TRACE_CONFIG_DOWNLOAD_REQ_V01,
  1134. WLFW_QDSS_TRACE_CONFIG_DOWNLOAD_REQ_MSG_V01_MAX_MSG_LEN,
  1135. wlfw_qdss_trace_config_download_req_msg_v01_ei, req);
  1136. if (ret < 0) {
  1137. qmi_txn_cancel(&txn);
  1138. cnss_pr_err("Failed to send respond QDSS download request, err: %d\n",
  1139. ret);
  1140. goto err_send;
  1141. }
  1142. ret = qmi_txn_wait(&txn, plat_priv->ctrl_params.qmi_timeout);
  1143. if (ret < 0) {
  1144. cnss_pr_err("Failed to wait for response of QDSS download request, err: %d\n",
  1145. ret);
  1146. goto err_send;
  1147. }
  1148. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1149. cnss_pr_err("QDSS download request failed, result: %d, err: %d\n",
  1150. resp->resp.result, resp->resp.error);
  1151. ret = -resp->resp.result;
  1152. goto err_send;
  1153. }
  1154. remaining -= req->data_len;
  1155. temp += req->data_len;
  1156. req->seg_id++;
  1157. }
  1158. release_firmware(fw_entry);
  1159. kfree(req);
  1160. kfree(resp);
  1161. return 0;
  1162. err_send:
  1163. release_firmware(fw_entry);
  1164. err_req_fw:
  1165. kfree(req);
  1166. kfree(resp);
  1167. return ret;
  1168. }
  1169. static int wlfw_send_qdss_trace_mode_req
  1170. (struct cnss_plat_data *plat_priv,
  1171. enum wlfw_qdss_trace_mode_enum_v01 mode,
  1172. unsigned long long option)
  1173. {
  1174. int rc = 0;
  1175. int tmp = 0;
  1176. struct wlfw_qdss_trace_mode_req_msg_v01 *req;
  1177. struct wlfw_qdss_trace_mode_resp_msg_v01 *resp;
  1178. struct qmi_txn txn;
  1179. if (!plat_priv)
  1180. return -ENODEV;
  1181. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1182. if (!req)
  1183. return -ENOMEM;
  1184. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1185. if (!resp) {
  1186. kfree(req);
  1187. return -ENOMEM;
  1188. }
  1189. req->mode_valid = 1;
  1190. req->mode = mode;
  1191. req->option_valid = 1;
  1192. req->option = option;
  1193. tmp = plat_priv->hw_trc_override;
  1194. req->hw_trc_disable_override_valid = 1;
  1195. req->hw_trc_disable_override =
  1196. (tmp > QMI_PARAM_DISABLE_V01 ? QMI_PARAM_DISABLE_V01 :
  1197. (tmp < 0 ? QMI_PARAM_INVALID_V01 : tmp));
  1198. cnss_pr_dbg("%s: mode %u, option %llu, hw_trc_disable_override: %u",
  1199. __func__, mode, option, req->hw_trc_disable_override);
  1200. rc = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  1201. wlfw_qdss_trace_mode_resp_msg_v01_ei, resp);
  1202. if (rc < 0) {
  1203. cnss_pr_err("Fail to init txn for QDSS Mode resp %d\n",
  1204. rc);
  1205. goto out;
  1206. }
  1207. rc = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  1208. QMI_WLFW_QDSS_TRACE_MODE_REQ_V01,
  1209. WLFW_QDSS_TRACE_MODE_REQ_MSG_V01_MAX_MSG_LEN,
  1210. wlfw_qdss_trace_mode_req_msg_v01_ei, req);
  1211. if (rc < 0) {
  1212. qmi_txn_cancel(&txn);
  1213. cnss_pr_err("Fail to send QDSS Mode req %d\n", rc);
  1214. goto out;
  1215. }
  1216. rc = qmi_txn_wait(&txn, plat_priv->ctrl_params.qmi_timeout);
  1217. if (rc < 0) {
  1218. cnss_pr_err("QDSS Mode resp wait failed with rc %d\n",
  1219. rc);
  1220. goto out;
  1221. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1222. cnss_pr_err("QMI QDSS Mode request rejected, result:%d error:%d\n",
  1223. resp->resp.result, resp->resp.error);
  1224. rc = -resp->resp.result;
  1225. goto out;
  1226. }
  1227. kfree(resp);
  1228. kfree(req);
  1229. return rc;
  1230. out:
  1231. kfree(resp);
  1232. kfree(req);
  1233. CNSS_QMI_ASSERT();
  1234. return rc;
  1235. }
  1236. int wlfw_qdss_trace_start(struct cnss_plat_data *plat_priv)
  1237. {
  1238. return wlfw_send_qdss_trace_mode_req(plat_priv,
  1239. QMI_WLFW_QDSS_TRACE_ON_V01, 0);
  1240. }
  1241. int wlfw_qdss_trace_stop(struct cnss_plat_data *plat_priv, unsigned long long option)
  1242. {
  1243. return wlfw_send_qdss_trace_mode_req(plat_priv, QMI_WLFW_QDSS_TRACE_OFF_V01,
  1244. option);
  1245. }
  1246. int cnss_wlfw_wlan_mode_send_sync(struct cnss_plat_data *plat_priv,
  1247. enum cnss_driver_mode mode)
  1248. {
  1249. struct wlfw_wlan_mode_req_msg_v01 *req;
  1250. struct wlfw_wlan_mode_resp_msg_v01 *resp;
  1251. struct qmi_txn txn;
  1252. int ret = 0;
  1253. if (!plat_priv)
  1254. return -ENODEV;
  1255. cnss_pr_dbg("Sending mode message, mode: %s(%d), state: 0x%lx\n",
  1256. cnss_qmi_mode_to_str(mode), mode, plat_priv->driver_state);
  1257. if (mode == CNSS_OFF &&
  1258. test_bit(CNSS_DRIVER_RECOVERY, &plat_priv->driver_state)) {
  1259. cnss_pr_dbg("Recovery is in progress, ignore mode off request\n");
  1260. return 0;
  1261. }
  1262. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1263. if (!req)
  1264. return -ENOMEM;
  1265. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1266. if (!resp) {
  1267. kfree(req);
  1268. return -ENOMEM;
  1269. }
  1270. req->mode = (enum wlfw_driver_mode_enum_v01)mode;
  1271. req->hw_debug_valid = 1;
  1272. req->hw_debug = 0;
  1273. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  1274. wlfw_wlan_mode_resp_msg_v01_ei, resp);
  1275. if (ret < 0) {
  1276. cnss_pr_err("Failed to initialize txn for mode request, mode: %s(%d), err: %d\n",
  1277. cnss_qmi_mode_to_str(mode), mode, ret);
  1278. goto out;
  1279. }
  1280. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  1281. QMI_WLFW_WLAN_MODE_REQ_V01,
  1282. WLFW_WLAN_MODE_REQ_MSG_V01_MAX_MSG_LEN,
  1283. wlfw_wlan_mode_req_msg_v01_ei, req);
  1284. if (ret < 0) {
  1285. qmi_txn_cancel(&txn);
  1286. cnss_pr_err("Failed to send mode request, mode: %s(%d), err: %d\n",
  1287. cnss_qmi_mode_to_str(mode), mode, ret);
  1288. goto out;
  1289. }
  1290. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  1291. if (ret < 0) {
  1292. cnss_pr_err("Failed to wait for response of mode request, mode: %s(%d), err: %d\n",
  1293. cnss_qmi_mode_to_str(mode), mode, ret);
  1294. goto out;
  1295. }
  1296. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1297. cnss_pr_err("Mode request failed, mode: %s(%d), result: %d, err: %d\n",
  1298. cnss_qmi_mode_to_str(mode), mode, resp->resp.result,
  1299. resp->resp.error);
  1300. ret = -resp->resp.result;
  1301. goto out;
  1302. }
  1303. kfree(req);
  1304. kfree(resp);
  1305. return 0;
  1306. out:
  1307. if (mode == CNSS_OFF) {
  1308. cnss_pr_dbg("WLFW service is disconnected while sending mode off request\n");
  1309. ret = 0;
  1310. } else {
  1311. CNSS_QMI_ASSERT();
  1312. }
  1313. kfree(req);
  1314. kfree(resp);
  1315. return ret;
  1316. }
  1317. int cnss_wlfw_wlan_cfg_send_sync(struct cnss_plat_data *plat_priv,
  1318. struct cnss_wlan_enable_cfg *config,
  1319. const char *host_version)
  1320. {
  1321. struct wlfw_wlan_cfg_req_msg_v01 *req;
  1322. struct wlfw_wlan_cfg_resp_msg_v01 *resp;
  1323. struct qmi_txn txn;
  1324. u32 i;
  1325. int ret = 0;
  1326. if (!plat_priv)
  1327. return -ENODEV;
  1328. cnss_pr_dbg("Sending WLAN config message, state: 0x%lx\n",
  1329. plat_priv->driver_state);
  1330. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1331. if (!req)
  1332. return -ENOMEM;
  1333. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1334. if (!resp) {
  1335. kfree(req);
  1336. return -ENOMEM;
  1337. }
  1338. req->host_version_valid = 1;
  1339. strlcpy(req->host_version, host_version,
  1340. QMI_WLFW_MAX_STR_LEN_V01 + 1);
  1341. req->tgt_cfg_valid = 1;
  1342. if (config->num_ce_tgt_cfg > QMI_WLFW_MAX_NUM_CE_V01)
  1343. req->tgt_cfg_len = QMI_WLFW_MAX_NUM_CE_V01;
  1344. else
  1345. req->tgt_cfg_len = config->num_ce_tgt_cfg;
  1346. for (i = 0; i < req->tgt_cfg_len; i++) {
  1347. req->tgt_cfg[i].pipe_num = config->ce_tgt_cfg[i].pipe_num;
  1348. req->tgt_cfg[i].pipe_dir = config->ce_tgt_cfg[i].pipe_dir;
  1349. req->tgt_cfg[i].nentries = config->ce_tgt_cfg[i].nentries;
  1350. req->tgt_cfg[i].nbytes_max = config->ce_tgt_cfg[i].nbytes_max;
  1351. req->tgt_cfg[i].flags = config->ce_tgt_cfg[i].flags;
  1352. }
  1353. req->svc_cfg_valid = 1;
  1354. if (config->num_ce_svc_pipe_cfg > QMI_WLFW_MAX_NUM_SVC_V01)
  1355. req->svc_cfg_len = QMI_WLFW_MAX_NUM_SVC_V01;
  1356. else
  1357. req->svc_cfg_len = config->num_ce_svc_pipe_cfg;
  1358. for (i = 0; i < req->svc_cfg_len; i++) {
  1359. req->svc_cfg[i].service_id = config->ce_svc_cfg[i].service_id;
  1360. req->svc_cfg[i].pipe_dir = config->ce_svc_cfg[i].pipe_dir;
  1361. req->svc_cfg[i].pipe_num = config->ce_svc_cfg[i].pipe_num;
  1362. }
  1363. if (plat_priv->device_id != KIWI_DEVICE_ID &&
  1364. plat_priv->device_id != MANGO_DEVICE_ID) {
  1365. req->shadow_reg_v2_valid = 1;
  1366. if (config->num_shadow_reg_v2_cfg >
  1367. QMI_WLFW_MAX_NUM_SHADOW_REG_V2_V01)
  1368. req->shadow_reg_v2_len = QMI_WLFW_MAX_NUM_SHADOW_REG_V2_V01;
  1369. else
  1370. req->shadow_reg_v2_len = config->num_shadow_reg_v2_cfg;
  1371. memcpy(req->shadow_reg_v2, config->shadow_reg_v2_cfg,
  1372. sizeof(struct wlfw_shadow_reg_v2_cfg_s_v01)
  1373. * req->shadow_reg_v2_len);
  1374. } else {
  1375. req->shadow_reg_v3_valid = 1;
  1376. if (config->num_shadow_reg_v3_cfg >
  1377. MAX_NUM_SHADOW_REG_V3)
  1378. req->shadow_reg_v3_len = MAX_NUM_SHADOW_REG_V3;
  1379. else
  1380. req->shadow_reg_v3_len = config->num_shadow_reg_v3_cfg;
  1381. plat_priv->num_shadow_regs_v3 = req->shadow_reg_v3_len;
  1382. cnss_pr_dbg("Shadow reg v3 len: %d\n",
  1383. plat_priv->num_shadow_regs_v3);
  1384. memcpy(req->shadow_reg_v3, config->shadow_reg_v3_cfg,
  1385. sizeof(struct wlfw_shadow_reg_v3_cfg_s_v01)
  1386. * req->shadow_reg_v3_len);
  1387. }
  1388. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  1389. wlfw_wlan_cfg_resp_msg_v01_ei, resp);
  1390. if (ret < 0) {
  1391. cnss_pr_err("Failed to initialize txn for WLAN config request, err: %d\n",
  1392. ret);
  1393. goto out;
  1394. }
  1395. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  1396. QMI_WLFW_WLAN_CFG_REQ_V01,
  1397. WLFW_WLAN_CFG_REQ_MSG_V01_MAX_MSG_LEN,
  1398. wlfw_wlan_cfg_req_msg_v01_ei, req);
  1399. if (ret < 0) {
  1400. qmi_txn_cancel(&txn);
  1401. cnss_pr_err("Failed to send WLAN config request, err: %d\n",
  1402. ret);
  1403. goto out;
  1404. }
  1405. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  1406. if (ret < 0) {
  1407. cnss_pr_err("Failed to wait for response of WLAN config request, err: %d\n",
  1408. ret);
  1409. goto out;
  1410. }
  1411. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1412. cnss_pr_err("WLAN config request failed, result: %d, err: %d\n",
  1413. resp->resp.result, resp->resp.error);
  1414. ret = -resp->resp.result;
  1415. goto out;
  1416. }
  1417. kfree(req);
  1418. kfree(resp);
  1419. return 0;
  1420. out:
  1421. CNSS_QMI_ASSERT();
  1422. kfree(req);
  1423. kfree(resp);
  1424. return ret;
  1425. }
  1426. int cnss_wlfw_athdiag_read_send_sync(struct cnss_plat_data *plat_priv,
  1427. u32 offset, u32 mem_type,
  1428. u32 data_len, u8 *data)
  1429. {
  1430. struct wlfw_athdiag_read_req_msg_v01 *req;
  1431. struct wlfw_athdiag_read_resp_msg_v01 *resp;
  1432. struct qmi_txn txn;
  1433. int ret = 0;
  1434. if (!plat_priv)
  1435. return -ENODEV;
  1436. if (!data || data_len == 0 || data_len > QMI_WLFW_MAX_DATA_SIZE_V01) {
  1437. cnss_pr_err("Invalid parameters for athdiag read: data %pK, data_len %u\n",
  1438. data, data_len);
  1439. return -EINVAL;
  1440. }
  1441. cnss_pr_dbg("athdiag read: state 0x%lx, offset %x, mem_type %x, data_len %u\n",
  1442. plat_priv->driver_state, offset, mem_type, data_len);
  1443. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1444. if (!req)
  1445. return -ENOMEM;
  1446. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1447. if (!resp) {
  1448. kfree(req);
  1449. return -ENOMEM;
  1450. }
  1451. req->offset = offset;
  1452. req->mem_type = mem_type;
  1453. req->data_len = data_len;
  1454. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  1455. wlfw_athdiag_read_resp_msg_v01_ei, resp);
  1456. if (ret < 0) {
  1457. cnss_pr_err("Failed to initialize txn for athdiag read request, err: %d\n",
  1458. ret);
  1459. goto out;
  1460. }
  1461. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  1462. QMI_WLFW_ATHDIAG_READ_REQ_V01,
  1463. WLFW_ATHDIAG_READ_REQ_MSG_V01_MAX_MSG_LEN,
  1464. wlfw_athdiag_read_req_msg_v01_ei, req);
  1465. if (ret < 0) {
  1466. qmi_txn_cancel(&txn);
  1467. cnss_pr_err("Failed to send athdiag read request, err: %d\n",
  1468. ret);
  1469. goto out;
  1470. }
  1471. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  1472. if (ret < 0) {
  1473. cnss_pr_err("Failed to wait for response of athdiag read request, err: %d\n",
  1474. ret);
  1475. goto out;
  1476. }
  1477. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1478. cnss_pr_err("Athdiag read request failed, result: %d, err: %d\n",
  1479. resp->resp.result, resp->resp.error);
  1480. ret = -resp->resp.result;
  1481. goto out;
  1482. }
  1483. if (!resp->data_valid || resp->data_len != data_len) {
  1484. cnss_pr_err("athdiag read data is invalid, data_valid = %u, data_len = %u\n",
  1485. resp->data_valid, resp->data_len);
  1486. ret = -EINVAL;
  1487. goto out;
  1488. }
  1489. memcpy(data, resp->data, resp->data_len);
  1490. kfree(req);
  1491. kfree(resp);
  1492. return 0;
  1493. out:
  1494. kfree(req);
  1495. kfree(resp);
  1496. return ret;
  1497. }
  1498. int cnss_wlfw_athdiag_write_send_sync(struct cnss_plat_data *plat_priv,
  1499. u32 offset, u32 mem_type,
  1500. u32 data_len, u8 *data)
  1501. {
  1502. struct wlfw_athdiag_write_req_msg_v01 *req;
  1503. struct wlfw_athdiag_write_resp_msg_v01 *resp;
  1504. struct qmi_txn txn;
  1505. int ret = 0;
  1506. if (!plat_priv)
  1507. return -ENODEV;
  1508. if (!data || data_len == 0 || data_len > QMI_WLFW_MAX_DATA_SIZE_V01) {
  1509. cnss_pr_err("Invalid parameters for athdiag write: data %pK, data_len %u\n",
  1510. data, data_len);
  1511. return -EINVAL;
  1512. }
  1513. cnss_pr_dbg("athdiag write: state 0x%lx, offset %x, mem_type %x, data_len %u, data %pK\n",
  1514. plat_priv->driver_state, offset, mem_type, data_len, data);
  1515. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1516. if (!req)
  1517. return -ENOMEM;
  1518. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1519. if (!resp) {
  1520. kfree(req);
  1521. return -ENOMEM;
  1522. }
  1523. req->offset = offset;
  1524. req->mem_type = mem_type;
  1525. req->data_len = data_len;
  1526. memcpy(req->data, data, data_len);
  1527. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  1528. wlfw_athdiag_write_resp_msg_v01_ei, resp);
  1529. if (ret < 0) {
  1530. cnss_pr_err("Failed to initialize txn for athdiag write request, err: %d\n",
  1531. ret);
  1532. goto out;
  1533. }
  1534. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  1535. QMI_WLFW_ATHDIAG_WRITE_REQ_V01,
  1536. WLFW_ATHDIAG_WRITE_REQ_MSG_V01_MAX_MSG_LEN,
  1537. wlfw_athdiag_write_req_msg_v01_ei, req);
  1538. if (ret < 0) {
  1539. qmi_txn_cancel(&txn);
  1540. cnss_pr_err("Failed to send athdiag write request, err: %d\n",
  1541. ret);
  1542. goto out;
  1543. }
  1544. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  1545. if (ret < 0) {
  1546. cnss_pr_err("Failed to wait for response of athdiag write request, err: %d\n",
  1547. ret);
  1548. goto out;
  1549. }
  1550. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1551. cnss_pr_err("Athdiag write request failed, result: %d, err: %d\n",
  1552. resp->resp.result, resp->resp.error);
  1553. ret = -resp->resp.result;
  1554. goto out;
  1555. }
  1556. kfree(req);
  1557. kfree(resp);
  1558. return 0;
  1559. out:
  1560. kfree(req);
  1561. kfree(resp);
  1562. return ret;
  1563. }
  1564. int cnss_wlfw_ini_send_sync(struct cnss_plat_data *plat_priv,
  1565. u8 fw_log_mode)
  1566. {
  1567. struct wlfw_ini_req_msg_v01 *req;
  1568. struct wlfw_ini_resp_msg_v01 *resp;
  1569. struct qmi_txn txn;
  1570. int ret = 0;
  1571. if (!plat_priv)
  1572. return -ENODEV;
  1573. cnss_pr_dbg("Sending ini sync request, state: 0x%lx, fw_log_mode: %d\n",
  1574. plat_priv->driver_state, fw_log_mode);
  1575. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1576. if (!req)
  1577. return -ENOMEM;
  1578. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1579. if (!resp) {
  1580. kfree(req);
  1581. return -ENOMEM;
  1582. }
  1583. req->enablefwlog_valid = 1;
  1584. req->enablefwlog = fw_log_mode;
  1585. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  1586. wlfw_ini_resp_msg_v01_ei, resp);
  1587. if (ret < 0) {
  1588. cnss_pr_err("Failed to initialize txn for ini request, fw_log_mode: %d, err: %d\n",
  1589. fw_log_mode, ret);
  1590. goto out;
  1591. }
  1592. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  1593. QMI_WLFW_INI_REQ_V01,
  1594. WLFW_INI_REQ_MSG_V01_MAX_MSG_LEN,
  1595. wlfw_ini_req_msg_v01_ei, req);
  1596. if (ret < 0) {
  1597. qmi_txn_cancel(&txn);
  1598. cnss_pr_err("Failed to send ini request, fw_log_mode: %d, err: %d\n",
  1599. fw_log_mode, ret);
  1600. goto out;
  1601. }
  1602. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  1603. if (ret < 0) {
  1604. cnss_pr_err("Failed to wait for response of ini request, fw_log_mode: %d, err: %d\n",
  1605. fw_log_mode, ret);
  1606. goto out;
  1607. }
  1608. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1609. cnss_pr_err("Ini request failed, fw_log_mode: %d, result: %d, err: %d\n",
  1610. fw_log_mode, resp->resp.result, resp->resp.error);
  1611. ret = -resp->resp.result;
  1612. goto out;
  1613. }
  1614. kfree(req);
  1615. kfree(resp);
  1616. return 0;
  1617. out:
  1618. kfree(req);
  1619. kfree(resp);
  1620. return ret;
  1621. }
  1622. int cnss_wlfw_send_pcie_gen_speed_sync(struct cnss_plat_data *plat_priv)
  1623. {
  1624. struct wlfw_pcie_gen_switch_req_msg_v01 req;
  1625. struct wlfw_pcie_gen_switch_resp_msg_v01 resp = {0};
  1626. struct qmi_txn txn;
  1627. int ret = 0;
  1628. if (!plat_priv)
  1629. return -ENODEV;
  1630. if (plat_priv->pcie_gen_speed == QMI_PCIE_GEN_SPEED_INVALID_V01 ||
  1631. !plat_priv->fw_pcie_gen_switch) {
  1632. cnss_pr_dbg("PCIE Gen speed not setup\n");
  1633. return 0;
  1634. }
  1635. cnss_pr_dbg("Sending PCIE Gen speed: %d state: 0x%lx\n",
  1636. plat_priv->pcie_gen_speed, plat_priv->driver_state);
  1637. req.pcie_speed = (enum wlfw_pcie_gen_speed_v01)
  1638. plat_priv->pcie_gen_speed;
  1639. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  1640. wlfw_pcie_gen_switch_resp_msg_v01_ei, &resp);
  1641. if (ret < 0) {
  1642. cnss_pr_err("Failed to initialize txn for PCIE speed switch err: %d\n",
  1643. ret);
  1644. goto out;
  1645. }
  1646. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  1647. QMI_WLFW_PCIE_GEN_SWITCH_REQ_V01,
  1648. WLFW_PCIE_GEN_SWITCH_REQ_MSG_V01_MAX_MSG_LEN,
  1649. wlfw_pcie_gen_switch_req_msg_v01_ei, &req);
  1650. if (ret < 0) {
  1651. qmi_txn_cancel(&txn);
  1652. cnss_pr_err("Failed to send PCIE speed switch, err: %d\n", ret);
  1653. goto out;
  1654. }
  1655. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  1656. if (ret < 0) {
  1657. cnss_pr_err("Failed to wait for PCIE Gen switch resp, err: %d\n",
  1658. ret);
  1659. goto out;
  1660. }
  1661. if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
  1662. cnss_pr_err("PCIE Gen Switch req failed, Speed: %d, result: %d, err: %d\n",
  1663. plat_priv->pcie_gen_speed, resp.resp.result,
  1664. resp.resp.error);
  1665. ret = -resp.resp.result;
  1666. }
  1667. out:
  1668. /* Reset PCIE Gen speed after one time use */
  1669. plat_priv->pcie_gen_speed = QMI_PCIE_GEN_SPEED_INVALID_V01;
  1670. return ret;
  1671. }
  1672. int cnss_wlfw_antenna_switch_send_sync(struct cnss_plat_data *plat_priv)
  1673. {
  1674. struct wlfw_antenna_switch_req_msg_v01 *req;
  1675. struct wlfw_antenna_switch_resp_msg_v01 *resp;
  1676. struct qmi_txn txn;
  1677. int ret = 0;
  1678. if (!plat_priv)
  1679. return -ENODEV;
  1680. cnss_pr_dbg("Sending antenna switch sync request, state: 0x%lx\n",
  1681. plat_priv->driver_state);
  1682. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1683. if (!req)
  1684. return -ENOMEM;
  1685. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1686. if (!resp) {
  1687. kfree(req);
  1688. return -ENOMEM;
  1689. }
  1690. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  1691. wlfw_antenna_switch_resp_msg_v01_ei, resp);
  1692. if (ret < 0) {
  1693. cnss_pr_err("Failed to initialize txn for antenna switch request, err: %d\n",
  1694. ret);
  1695. goto out;
  1696. }
  1697. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  1698. QMI_WLFW_ANTENNA_SWITCH_REQ_V01,
  1699. WLFW_ANTENNA_SWITCH_REQ_MSG_V01_MAX_MSG_LEN,
  1700. wlfw_antenna_switch_req_msg_v01_ei, req);
  1701. if (ret < 0) {
  1702. qmi_txn_cancel(&txn);
  1703. cnss_pr_err("Failed to send antenna switch request, err: %d\n",
  1704. ret);
  1705. goto out;
  1706. }
  1707. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  1708. if (ret < 0) {
  1709. cnss_pr_err("Failed to wait for response of antenna switch request, err: %d\n",
  1710. ret);
  1711. goto out;
  1712. }
  1713. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1714. cnss_pr_dbg("Antenna switch request failed, result: %d, err: %d\n",
  1715. resp->resp.result, resp->resp.error);
  1716. ret = -resp->resp.result;
  1717. goto out;
  1718. }
  1719. if (resp->antenna_valid)
  1720. plat_priv->antenna = resp->antenna;
  1721. cnss_pr_dbg("Antenna valid: %u, antenna 0x%llx\n",
  1722. resp->antenna_valid, resp->antenna);
  1723. kfree(req);
  1724. kfree(resp);
  1725. return 0;
  1726. out:
  1727. kfree(req);
  1728. kfree(resp);
  1729. return ret;
  1730. }
  1731. int cnss_wlfw_antenna_grant_send_sync(struct cnss_plat_data *plat_priv)
  1732. {
  1733. struct wlfw_antenna_grant_req_msg_v01 *req;
  1734. struct wlfw_antenna_grant_resp_msg_v01 *resp;
  1735. struct qmi_txn txn;
  1736. int ret = 0;
  1737. if (!plat_priv)
  1738. return -ENODEV;
  1739. cnss_pr_dbg("Sending antenna grant sync request, state: 0x%lx, grant 0x%llx\n",
  1740. plat_priv->driver_state, plat_priv->grant);
  1741. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1742. if (!req)
  1743. return -ENOMEM;
  1744. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1745. if (!resp) {
  1746. kfree(req);
  1747. return -ENOMEM;
  1748. }
  1749. req->grant_valid = 1;
  1750. req->grant = plat_priv->grant;
  1751. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  1752. wlfw_antenna_grant_resp_msg_v01_ei, resp);
  1753. if (ret < 0) {
  1754. cnss_pr_err("Failed to initialize txn for antenna grant request, err: %d\n",
  1755. ret);
  1756. goto out;
  1757. }
  1758. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  1759. QMI_WLFW_ANTENNA_GRANT_REQ_V01,
  1760. WLFW_ANTENNA_GRANT_REQ_MSG_V01_MAX_MSG_LEN,
  1761. wlfw_antenna_grant_req_msg_v01_ei, req);
  1762. if (ret < 0) {
  1763. qmi_txn_cancel(&txn);
  1764. cnss_pr_err("Failed to send antenna grant request, err: %d\n",
  1765. ret);
  1766. goto out;
  1767. }
  1768. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  1769. if (ret < 0) {
  1770. cnss_pr_err("Failed to wait for response of antenna grant request, err: %d\n",
  1771. ret);
  1772. goto out;
  1773. }
  1774. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1775. cnss_pr_err("Antenna grant request failed, result: %d, err: %d\n",
  1776. resp->resp.result, resp->resp.error);
  1777. ret = -resp->resp.result;
  1778. goto out;
  1779. }
  1780. kfree(req);
  1781. kfree(resp);
  1782. return 0;
  1783. out:
  1784. kfree(req);
  1785. kfree(resp);
  1786. return ret;
  1787. }
  1788. int cnss_wlfw_qdss_trace_mem_info_send_sync(struct cnss_plat_data *plat_priv)
  1789. {
  1790. struct wlfw_qdss_trace_mem_info_req_msg_v01 *req;
  1791. struct wlfw_qdss_trace_mem_info_resp_msg_v01 *resp;
  1792. struct qmi_txn txn;
  1793. struct cnss_fw_mem *qdss_mem = plat_priv->qdss_mem;
  1794. int ret = 0;
  1795. int i;
  1796. cnss_pr_dbg("Sending QDSS trace mem info, state: 0x%lx\n",
  1797. plat_priv->driver_state);
  1798. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1799. if (!req)
  1800. return -ENOMEM;
  1801. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1802. if (!resp) {
  1803. kfree(req);
  1804. return -ENOMEM;
  1805. }
  1806. req->mem_seg_len = plat_priv->qdss_mem_seg_len;
  1807. for (i = 0; i < req->mem_seg_len; i++) {
  1808. cnss_pr_dbg("Memory for FW, va: 0x%pK, pa: %pa, size: 0x%zx, type: %u\n",
  1809. qdss_mem[i].va, &qdss_mem[i].pa,
  1810. qdss_mem[i].size, qdss_mem[i].type);
  1811. req->mem_seg[i].addr = qdss_mem[i].pa;
  1812. req->mem_seg[i].size = qdss_mem[i].size;
  1813. req->mem_seg[i].type = qdss_mem[i].type;
  1814. }
  1815. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  1816. wlfw_qdss_trace_mem_info_resp_msg_v01_ei, resp);
  1817. if (ret < 0) {
  1818. cnss_pr_err("Fail to initialize txn for QDSS trace mem request: err %d\n",
  1819. ret);
  1820. goto out;
  1821. }
  1822. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  1823. QMI_WLFW_QDSS_TRACE_MEM_INFO_REQ_V01,
  1824. WLFW_QDSS_TRACE_MEM_INFO_REQ_MSG_V01_MAX_MSG_LEN,
  1825. wlfw_qdss_trace_mem_info_req_msg_v01_ei, req);
  1826. if (ret < 0) {
  1827. qmi_txn_cancel(&txn);
  1828. cnss_pr_err("Fail to send QDSS trace mem info request: err %d\n",
  1829. ret);
  1830. goto out;
  1831. }
  1832. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  1833. if (ret < 0) {
  1834. cnss_pr_err("Fail to wait for response of QDSS trace mem info request, err %d\n",
  1835. ret);
  1836. goto out;
  1837. }
  1838. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1839. cnss_pr_err("QDSS trace mem info request failed, result: %d, err: %d\n",
  1840. resp->resp.result, resp->resp.error);
  1841. ret = -resp->resp.result;
  1842. goto out;
  1843. }
  1844. kfree(req);
  1845. kfree(resp);
  1846. return 0;
  1847. out:
  1848. kfree(req);
  1849. kfree(resp);
  1850. return ret;
  1851. }
  1852. int cnss_wlfw_send_host_wfc_call_status(struct cnss_plat_data *plat_priv,
  1853. struct cnss_wfc_cfg cfg)
  1854. {
  1855. struct wlfw_wfc_call_status_req_msg_v01 *req;
  1856. struct wlfw_wfc_call_status_resp_msg_v01 *resp;
  1857. struct qmi_txn txn;
  1858. int ret = 0;
  1859. if (!test_bit(CNSS_FW_READY, &plat_priv->driver_state)) {
  1860. cnss_pr_err("Drop host WFC indication as FW not initialized\n");
  1861. return -EINVAL;
  1862. }
  1863. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1864. if (!req)
  1865. return -ENOMEM;
  1866. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1867. if (!resp) {
  1868. kfree(req);
  1869. return -ENOMEM;
  1870. }
  1871. req->wfc_call_active_valid = 1;
  1872. req->wfc_call_active = cfg.mode;
  1873. cnss_pr_dbg("CNSS->FW: WFC_CALL_REQ: state: 0x%lx\n",
  1874. plat_priv->driver_state);
  1875. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  1876. wlfw_wfc_call_status_resp_msg_v01_ei, resp);
  1877. if (ret < 0) {
  1878. cnss_pr_err("CNSS->FW: WFC_CALL_REQ: QMI Txn Init: Err %d\n",
  1879. ret);
  1880. goto out;
  1881. }
  1882. cnss_pr_dbg("Send WFC Mode: %d\n", cfg.mode);
  1883. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  1884. QMI_WLFW_WFC_CALL_STATUS_REQ_V01,
  1885. WLFW_WFC_CALL_STATUS_REQ_MSG_V01_MAX_MSG_LEN,
  1886. wlfw_wfc_call_status_req_msg_v01_ei, req);
  1887. if (ret < 0) {
  1888. qmi_txn_cancel(&txn);
  1889. cnss_pr_err("CNSS->FW: WFC_CALL_REQ: QMI Send Err: %d\n",
  1890. ret);
  1891. goto out;
  1892. }
  1893. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  1894. if (ret < 0) {
  1895. cnss_pr_err("FW->CNSS: WFC_CALL_RSP: QMI Wait Err: %d\n",
  1896. ret);
  1897. goto out;
  1898. }
  1899. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1900. cnss_pr_err("FW->CNSS: WFC_CALL_RSP: Result: %d Err: %d\n",
  1901. resp->resp.result, resp->resp.error);
  1902. ret = -EINVAL;
  1903. goto out;
  1904. }
  1905. ret = 0;
  1906. out:
  1907. kfree(req);
  1908. kfree(resp);
  1909. return ret;
  1910. }
  1911. static int cnss_wlfw_wfc_call_status_send_sync
  1912. (struct cnss_plat_data *plat_priv,
  1913. const struct ims_private_service_wfc_call_status_ind_msg_v01 *ind_msg)
  1914. {
  1915. struct wlfw_wfc_call_status_req_msg_v01 *req;
  1916. struct wlfw_wfc_call_status_resp_msg_v01 *resp;
  1917. struct qmi_txn txn;
  1918. int ret = 0;
  1919. if (!test_bit(CNSS_FW_READY, &plat_priv->driver_state)) {
  1920. cnss_pr_err("Drop IMS WFC indication as FW not initialized\n");
  1921. return -EINVAL;
  1922. }
  1923. req = kzalloc(sizeof(*req), GFP_KERNEL);
  1924. if (!req)
  1925. return -ENOMEM;
  1926. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  1927. if (!resp) {
  1928. kfree(req);
  1929. return -ENOMEM;
  1930. }
  1931. /**
  1932. * WFC Call r1 design has CNSS as pass thru using opaque hex buffer.
  1933. * But in r2 update QMI structure is expanded and as an effect qmi
  1934. * decoded structures have padding. Thus we cannot use buffer design.
  1935. * For backward compatibility for r1 design copy only wfc_call_active
  1936. * value in hex buffer.
  1937. */
  1938. req->wfc_call_status_len = sizeof(ind_msg->wfc_call_active);
  1939. req->wfc_call_status[0] = ind_msg->wfc_call_active;
  1940. /* wfc_call_active is mandatory in IMS indication */
  1941. req->wfc_call_active_valid = 1;
  1942. req->wfc_call_active = ind_msg->wfc_call_active;
  1943. req->all_wfc_calls_held_valid = ind_msg->all_wfc_calls_held_valid;
  1944. req->all_wfc_calls_held = ind_msg->all_wfc_calls_held;
  1945. req->is_wfc_emergency_valid = ind_msg->is_wfc_emergency_valid;
  1946. req->is_wfc_emergency = ind_msg->is_wfc_emergency;
  1947. req->twt_ims_start_valid = ind_msg->twt_ims_start_valid;
  1948. req->twt_ims_start = ind_msg->twt_ims_start;
  1949. req->twt_ims_int_valid = ind_msg->twt_ims_int_valid;
  1950. req->twt_ims_int = ind_msg->twt_ims_int;
  1951. req->media_quality_valid = ind_msg->media_quality_valid;
  1952. req->media_quality =
  1953. (enum wlfw_wfc_media_quality_v01)ind_msg->media_quality;
  1954. cnss_pr_dbg("CNSS->FW: WFC_CALL_REQ: state: 0x%lx\n",
  1955. plat_priv->driver_state);
  1956. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  1957. wlfw_wfc_call_status_resp_msg_v01_ei, resp);
  1958. if (ret < 0) {
  1959. cnss_pr_err("CNSS->FW: WFC_CALL_REQ: QMI Txn Init: Err %d\n",
  1960. ret);
  1961. goto out;
  1962. }
  1963. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  1964. QMI_WLFW_WFC_CALL_STATUS_REQ_V01,
  1965. WLFW_WFC_CALL_STATUS_REQ_MSG_V01_MAX_MSG_LEN,
  1966. wlfw_wfc_call_status_req_msg_v01_ei, req);
  1967. if (ret < 0) {
  1968. qmi_txn_cancel(&txn);
  1969. cnss_pr_err("CNSS->FW: WFC_CALL_REQ: QMI Send Err: %d\n",
  1970. ret);
  1971. goto out;
  1972. }
  1973. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  1974. if (ret < 0) {
  1975. cnss_pr_err("FW->CNSS: WFC_CALL_RSP: QMI Wait Err: %d\n",
  1976. ret);
  1977. goto out;
  1978. }
  1979. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  1980. cnss_pr_err("FW->CNSS: WFC_CALL_RSP: Result: %d Err: %d\n",
  1981. resp->resp.result, resp->resp.error);
  1982. ret = -resp->resp.result;
  1983. goto out;
  1984. }
  1985. ret = 0;
  1986. out:
  1987. kfree(req);
  1988. kfree(resp);
  1989. return ret;
  1990. }
  1991. int cnss_wlfw_dynamic_feature_mask_send_sync(struct cnss_plat_data *plat_priv)
  1992. {
  1993. struct wlfw_dynamic_feature_mask_req_msg_v01 *req;
  1994. struct wlfw_dynamic_feature_mask_resp_msg_v01 *resp;
  1995. struct qmi_txn txn;
  1996. int ret = 0;
  1997. cnss_pr_dbg("Sending dynamic feature mask 0x%llx, state: 0x%lx\n",
  1998. plat_priv->dynamic_feature,
  1999. plat_priv->driver_state);
  2000. req = kzalloc(sizeof(*req), GFP_KERNEL);
  2001. if (!req)
  2002. return -ENOMEM;
  2003. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  2004. if (!resp) {
  2005. kfree(req);
  2006. return -ENOMEM;
  2007. }
  2008. req->mask_valid = 1;
  2009. req->mask = plat_priv->dynamic_feature;
  2010. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  2011. wlfw_dynamic_feature_mask_resp_msg_v01_ei, resp);
  2012. if (ret < 0) {
  2013. cnss_pr_err("Fail to initialize txn for dynamic feature mask request: err %d\n",
  2014. ret);
  2015. goto out;
  2016. }
  2017. ret = qmi_send_request
  2018. (&plat_priv->qmi_wlfw, NULL, &txn,
  2019. QMI_WLFW_DYNAMIC_FEATURE_MASK_REQ_V01,
  2020. WLFW_DYNAMIC_FEATURE_MASK_REQ_MSG_V01_MAX_MSG_LEN,
  2021. wlfw_dynamic_feature_mask_req_msg_v01_ei, req);
  2022. if (ret < 0) {
  2023. qmi_txn_cancel(&txn);
  2024. cnss_pr_err("Fail to send dynamic feature mask request: err %d\n",
  2025. ret);
  2026. goto out;
  2027. }
  2028. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  2029. if (ret < 0) {
  2030. cnss_pr_err("Fail to wait for response of dynamic feature mask request, err %d\n",
  2031. ret);
  2032. goto out;
  2033. }
  2034. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  2035. cnss_pr_err("Dynamic feature mask request failed, result: %d, err: %d\n",
  2036. resp->resp.result, resp->resp.error);
  2037. ret = -resp->resp.result;
  2038. goto out;
  2039. }
  2040. out:
  2041. kfree(req);
  2042. kfree(resp);
  2043. return ret;
  2044. }
  2045. int cnss_wlfw_get_info_send_sync(struct cnss_plat_data *plat_priv, int type,
  2046. void *cmd, int cmd_len)
  2047. {
  2048. struct wlfw_get_info_req_msg_v01 *req;
  2049. struct wlfw_get_info_resp_msg_v01 *resp;
  2050. struct qmi_txn txn;
  2051. int ret = 0;
  2052. cnss_pr_buf("Sending get info message, type: %d, cmd length: %d, state: 0x%lx\n",
  2053. type, cmd_len, plat_priv->driver_state);
  2054. if (cmd_len > QMI_WLFW_MAX_DATA_SIZE_V01)
  2055. return -EINVAL;
  2056. req = kzalloc(sizeof(*req), GFP_KERNEL);
  2057. if (!req)
  2058. return -ENOMEM;
  2059. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  2060. if (!resp) {
  2061. kfree(req);
  2062. return -ENOMEM;
  2063. }
  2064. req->type = type;
  2065. req->data_len = cmd_len;
  2066. memcpy(req->data, cmd, req->data_len);
  2067. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  2068. wlfw_get_info_resp_msg_v01_ei, resp);
  2069. if (ret < 0) {
  2070. cnss_pr_err("Failed to initialize txn for get info request, err: %d\n",
  2071. ret);
  2072. goto out;
  2073. }
  2074. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  2075. QMI_WLFW_GET_INFO_REQ_V01,
  2076. WLFW_GET_INFO_REQ_MSG_V01_MAX_MSG_LEN,
  2077. wlfw_get_info_req_msg_v01_ei, req);
  2078. if (ret < 0) {
  2079. qmi_txn_cancel(&txn);
  2080. cnss_pr_err("Failed to send get info request, err: %d\n",
  2081. ret);
  2082. goto out;
  2083. }
  2084. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  2085. if (ret < 0) {
  2086. cnss_pr_err("Failed to wait for response of get info request, err: %d\n",
  2087. ret);
  2088. goto out;
  2089. }
  2090. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  2091. cnss_pr_err("Get info request failed, result: %d, err: %d\n",
  2092. resp->resp.result, resp->resp.error);
  2093. ret = -resp->resp.result;
  2094. goto out;
  2095. }
  2096. kfree(req);
  2097. kfree(resp);
  2098. return 0;
  2099. out:
  2100. kfree(req);
  2101. kfree(resp);
  2102. return ret;
  2103. }
  2104. unsigned int cnss_get_qmi_timeout(struct cnss_plat_data *plat_priv)
  2105. {
  2106. return QMI_WLFW_TIMEOUT_MS;
  2107. }
  2108. static void cnss_wlfw_request_mem_ind_cb(struct qmi_handle *qmi_wlfw,
  2109. struct sockaddr_qrtr *sq,
  2110. struct qmi_txn *txn, const void *data)
  2111. {
  2112. struct cnss_plat_data *plat_priv =
  2113. container_of(qmi_wlfw, struct cnss_plat_data, qmi_wlfw);
  2114. const struct wlfw_request_mem_ind_msg_v01 *ind_msg = data;
  2115. int i;
  2116. cnss_pr_dbg("Received QMI WLFW request memory indication\n");
  2117. if (!txn) {
  2118. cnss_pr_err("Spurious indication\n");
  2119. return;
  2120. }
  2121. plat_priv->fw_mem_seg_len = ind_msg->mem_seg_len;
  2122. for (i = 0; i < plat_priv->fw_mem_seg_len; i++) {
  2123. cnss_pr_dbg("FW requests for memory, size: 0x%x, type: %u\n",
  2124. ind_msg->mem_seg[i].size, ind_msg->mem_seg[i].type);
  2125. plat_priv->fw_mem[i].type = ind_msg->mem_seg[i].type;
  2126. plat_priv->fw_mem[i].size = ind_msg->mem_seg[i].size;
  2127. if (!plat_priv->fw_mem[i].va &&
  2128. plat_priv->fw_mem[i].type == CNSS_MEM_TYPE_DDR)
  2129. plat_priv->fw_mem[i].attrs |=
  2130. DMA_ATTR_FORCE_CONTIGUOUS;
  2131. if (plat_priv->fw_mem[i].type == CNSS_MEM_CAL_V01)
  2132. plat_priv->cal_mem = &plat_priv->fw_mem[i];
  2133. }
  2134. cnss_driver_event_post(plat_priv, CNSS_DRIVER_EVENT_REQUEST_MEM,
  2135. 0, NULL);
  2136. }
  2137. static void cnss_wlfw_fw_mem_ready_ind_cb(struct qmi_handle *qmi_wlfw,
  2138. struct sockaddr_qrtr *sq,
  2139. struct qmi_txn *txn, const void *data)
  2140. {
  2141. struct cnss_plat_data *plat_priv =
  2142. container_of(qmi_wlfw, struct cnss_plat_data, qmi_wlfw);
  2143. cnss_pr_dbg("Received QMI WLFW FW memory ready indication\n");
  2144. if (!txn) {
  2145. cnss_pr_err("Spurious indication\n");
  2146. return;
  2147. }
  2148. cnss_driver_event_post(plat_priv, CNSS_DRIVER_EVENT_FW_MEM_READY,
  2149. 0, NULL);
  2150. }
  2151. /**
  2152. * cnss_wlfw_fw_ready_ind_cb: FW ready indication handler (Helium arch)
  2153. *
  2154. * This event is not required for HST/ HSP as FW calibration done is
  2155. * provided in QMI_WLFW_CAL_DONE_IND_V01
  2156. */
  2157. static void cnss_wlfw_fw_ready_ind_cb(struct qmi_handle *qmi_wlfw,
  2158. struct sockaddr_qrtr *sq,
  2159. struct qmi_txn *txn, const void *data)
  2160. {
  2161. struct cnss_plat_data *plat_priv =
  2162. container_of(qmi_wlfw, struct cnss_plat_data, qmi_wlfw);
  2163. struct cnss_cal_info *cal_info;
  2164. if (!txn) {
  2165. cnss_pr_err("Spurious indication\n");
  2166. return;
  2167. }
  2168. if (plat_priv->device_id == QCA6390_DEVICE_ID ||
  2169. plat_priv->device_id == QCA6490_DEVICE_ID) {
  2170. cnss_pr_dbg("Ignore FW Ready Indication for HST/HSP");
  2171. return;
  2172. }
  2173. cnss_pr_dbg("Received QMI WLFW FW ready indication.\n");
  2174. cal_info = kzalloc(sizeof(*cal_info), GFP_KERNEL);
  2175. if (!cal_info)
  2176. return;
  2177. cal_info->cal_status = CNSS_CAL_DONE;
  2178. cnss_driver_event_post(plat_priv, CNSS_DRIVER_EVENT_COLD_BOOT_CAL_DONE,
  2179. 0, cal_info);
  2180. }
  2181. static void cnss_wlfw_fw_init_done_ind_cb(struct qmi_handle *qmi_wlfw,
  2182. struct sockaddr_qrtr *sq,
  2183. struct qmi_txn *txn, const void *data)
  2184. {
  2185. struct cnss_plat_data *plat_priv =
  2186. container_of(qmi_wlfw, struct cnss_plat_data, qmi_wlfw);
  2187. cnss_pr_dbg("Received QMI WLFW FW initialization done indication\n");
  2188. if (!txn) {
  2189. cnss_pr_err("Spurious indication\n");
  2190. return;
  2191. }
  2192. cnss_driver_event_post(plat_priv, CNSS_DRIVER_EVENT_FW_READY, 0, NULL);
  2193. }
  2194. static void cnss_wlfw_pin_result_ind_cb(struct qmi_handle *qmi_wlfw,
  2195. struct sockaddr_qrtr *sq,
  2196. struct qmi_txn *txn, const void *data)
  2197. {
  2198. struct cnss_plat_data *plat_priv =
  2199. container_of(qmi_wlfw, struct cnss_plat_data, qmi_wlfw);
  2200. const struct wlfw_pin_connect_result_ind_msg_v01 *ind_msg = data;
  2201. cnss_pr_dbg("Received QMI WLFW pin connect result indication\n");
  2202. if (!txn) {
  2203. cnss_pr_err("Spurious indication\n");
  2204. return;
  2205. }
  2206. if (ind_msg->pwr_pin_result_valid)
  2207. plat_priv->pin_result.fw_pwr_pin_result =
  2208. ind_msg->pwr_pin_result;
  2209. if (ind_msg->phy_io_pin_result_valid)
  2210. plat_priv->pin_result.fw_phy_io_pin_result =
  2211. ind_msg->phy_io_pin_result;
  2212. if (ind_msg->rf_pin_result_valid)
  2213. plat_priv->pin_result.fw_rf_pin_result = ind_msg->rf_pin_result;
  2214. cnss_pr_dbg("Pin connect Result: pwr_pin: 0x%x phy_io_pin: 0x%x rf_io_pin: 0x%x\n",
  2215. ind_msg->pwr_pin_result, ind_msg->phy_io_pin_result,
  2216. ind_msg->rf_pin_result);
  2217. }
  2218. int cnss_wlfw_cal_report_req_send_sync(struct cnss_plat_data *plat_priv,
  2219. u32 cal_file_download_size)
  2220. {
  2221. struct wlfw_cal_report_req_msg_v01 req = {0};
  2222. struct wlfw_cal_report_resp_msg_v01 resp = {0};
  2223. struct qmi_txn txn;
  2224. int ret = 0;
  2225. cnss_pr_dbg("Sending cal file report request. File size: %d, state: 0x%lx\n",
  2226. cal_file_download_size, plat_priv->driver_state);
  2227. req.cal_file_download_size_valid = 1;
  2228. req.cal_file_download_size = cal_file_download_size;
  2229. ret = qmi_txn_init(&plat_priv->qmi_wlfw, &txn,
  2230. wlfw_cal_report_resp_msg_v01_ei, &resp);
  2231. if (ret < 0) {
  2232. cnss_pr_err("Failed to initialize txn for Cal Report request, err: %d\n",
  2233. ret);
  2234. goto out;
  2235. }
  2236. ret = qmi_send_request(&plat_priv->qmi_wlfw, NULL, &txn,
  2237. QMI_WLFW_CAL_REPORT_REQ_V01,
  2238. WLFW_CAL_REPORT_REQ_MSG_V01_MAX_MSG_LEN,
  2239. wlfw_cal_report_req_msg_v01_ei, &req);
  2240. if (ret < 0) {
  2241. qmi_txn_cancel(&txn);
  2242. cnss_pr_err("Failed to send Cal Report request, err: %d\n",
  2243. ret);
  2244. goto out;
  2245. }
  2246. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  2247. if (ret < 0) {
  2248. cnss_pr_err("Failed to wait for response of Cal Report request, err: %d\n",
  2249. ret);
  2250. goto out;
  2251. }
  2252. if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
  2253. cnss_pr_err("Cal Report request failed, result: %d, err: %d\n",
  2254. resp.resp.result, resp.resp.error);
  2255. ret = -resp.resp.result;
  2256. goto out;
  2257. }
  2258. out:
  2259. return ret;
  2260. }
  2261. static void cnss_wlfw_cal_done_ind_cb(struct qmi_handle *qmi_wlfw,
  2262. struct sockaddr_qrtr *sq,
  2263. struct qmi_txn *txn, const void *data)
  2264. {
  2265. struct cnss_plat_data *plat_priv =
  2266. container_of(qmi_wlfw, struct cnss_plat_data, qmi_wlfw);
  2267. const struct wlfw_cal_done_ind_msg_v01 *ind = data;
  2268. struct cnss_cal_info *cal_info;
  2269. cnss_pr_dbg("Received Cal done indication. File size: %d\n",
  2270. ind->cal_file_upload_size);
  2271. cnss_pr_info("Calibration took %d ms\n",
  2272. jiffies_to_msecs(jiffies - plat_priv->cal_time));
  2273. if (!txn) {
  2274. cnss_pr_err("Spurious indication\n");
  2275. return;
  2276. }
  2277. if (ind->cal_file_upload_size_valid)
  2278. plat_priv->cal_file_size = ind->cal_file_upload_size;
  2279. cal_info = kzalloc(sizeof(*cal_info), GFP_KERNEL);
  2280. if (!cal_info)
  2281. return;
  2282. cal_info->cal_status = CNSS_CAL_DONE;
  2283. cnss_driver_event_post(plat_priv, CNSS_DRIVER_EVENT_COLD_BOOT_CAL_DONE,
  2284. 0, cal_info);
  2285. }
  2286. static void cnss_wlfw_qdss_trace_req_mem_ind_cb(struct qmi_handle *qmi_wlfw,
  2287. struct sockaddr_qrtr *sq,
  2288. struct qmi_txn *txn,
  2289. const void *data)
  2290. {
  2291. struct cnss_plat_data *plat_priv =
  2292. container_of(qmi_wlfw, struct cnss_plat_data, qmi_wlfw);
  2293. const struct wlfw_qdss_trace_req_mem_ind_msg_v01 *ind_msg = data;
  2294. int i;
  2295. cnss_pr_dbg("Received QMI WLFW QDSS trace request mem indication\n");
  2296. if (!txn) {
  2297. cnss_pr_err("Spurious indication\n");
  2298. return;
  2299. }
  2300. if (plat_priv->qdss_mem_seg_len) {
  2301. cnss_pr_err("Ignore double allocation for QDSS trace, current len %u\n",
  2302. plat_priv->qdss_mem_seg_len);
  2303. return;
  2304. }
  2305. plat_priv->qdss_mem_seg_len = ind_msg->mem_seg_len;
  2306. for (i = 0; i < plat_priv->qdss_mem_seg_len; i++) {
  2307. cnss_pr_dbg("QDSS requests for memory, size: 0x%x, type: %u\n",
  2308. ind_msg->mem_seg[i].size, ind_msg->mem_seg[i].type);
  2309. plat_priv->qdss_mem[i].type = ind_msg->mem_seg[i].type;
  2310. plat_priv->qdss_mem[i].size = ind_msg->mem_seg[i].size;
  2311. }
  2312. cnss_driver_event_post(plat_priv, CNSS_DRIVER_EVENT_QDSS_TRACE_REQ_MEM,
  2313. 0, NULL);
  2314. }
  2315. /**
  2316. * cnss_wlfw_fw_mem_file_save_ind_cb: Save given FW mem to filesystem
  2317. *
  2318. * QDSS_TRACE_SAVE_IND feature is overloaded to provide any host allocated
  2319. * fw memory segment for dumping to file system. Only one type of mem can be
  2320. * saved per indication and is provided in mem seg index 0.
  2321. *
  2322. * Return: None
  2323. */
  2324. static void cnss_wlfw_fw_mem_file_save_ind_cb(struct qmi_handle *qmi_wlfw,
  2325. struct sockaddr_qrtr *sq,
  2326. struct qmi_txn *txn,
  2327. const void *data)
  2328. {
  2329. struct cnss_plat_data *plat_priv =
  2330. container_of(qmi_wlfw, struct cnss_plat_data, qmi_wlfw);
  2331. const struct wlfw_qdss_trace_save_ind_msg_v01 *ind_msg = data;
  2332. struct cnss_qmi_event_fw_mem_file_save_data *event_data;
  2333. int i = 0;
  2334. if (!txn || !data) {
  2335. cnss_pr_err("Spurious indication\n");
  2336. return;
  2337. }
  2338. cnss_pr_dbg("QMI fw_mem_file_save: source: %d mem_seg: %d type: %u len: %u\n",
  2339. ind_msg->source, ind_msg->mem_seg_valid,
  2340. ind_msg->mem_seg[0].type, ind_msg->mem_seg_len);
  2341. event_data = kzalloc(sizeof(*event_data), GFP_KERNEL);
  2342. if (!event_data)
  2343. return;
  2344. event_data->mem_type = ind_msg->mem_seg[0].type;
  2345. event_data->mem_seg_len = ind_msg->mem_seg_len;
  2346. event_data->total_size = ind_msg->total_size;
  2347. if (ind_msg->mem_seg_valid) {
  2348. if (ind_msg->mem_seg_len > QMI_WLFW_MAX_STR_LEN_V01) {
  2349. cnss_pr_err("Invalid seg len indication\n");
  2350. goto free_event_data;
  2351. }
  2352. for (i = 0; i < ind_msg->mem_seg_len; i++) {
  2353. event_data->mem_seg[i].addr = ind_msg->mem_seg[i].addr;
  2354. event_data->mem_seg[i].size = ind_msg->mem_seg[i].size;
  2355. if (event_data->mem_type != ind_msg->mem_seg[i].type) {
  2356. cnss_pr_err("FW Mem file save ind cannot have multiple mem types\n");
  2357. goto free_event_data;
  2358. }
  2359. cnss_pr_dbg("seg-%d: addr 0x%llx size 0x%x\n",
  2360. i, ind_msg->mem_seg[i].addr,
  2361. ind_msg->mem_seg[i].size);
  2362. }
  2363. }
  2364. if (ind_msg->file_name_valid)
  2365. strlcpy(event_data->file_name, ind_msg->file_name,
  2366. QMI_WLFW_MAX_STR_LEN_V01 + 1);
  2367. if (ind_msg->source == 1) {
  2368. if (!ind_msg->file_name_valid)
  2369. strlcpy(event_data->file_name, "qdss_trace_wcss_etb",
  2370. QMI_WLFW_MAX_STR_LEN_V01 + 1);
  2371. cnss_driver_event_post(plat_priv, CNSS_DRIVER_EVENT_QDSS_TRACE_REQ_DATA,
  2372. 0, event_data);
  2373. } else {
  2374. if (event_data->mem_type == QMI_WLFW_MEM_QDSS_V01) {
  2375. if (!ind_msg->file_name_valid)
  2376. strlcpy(event_data->file_name, "qdss_trace_ddr",
  2377. QMI_WLFW_MAX_STR_LEN_V01 + 1);
  2378. } else {
  2379. if (!ind_msg->file_name_valid)
  2380. strlcpy(event_data->file_name, "fw_mem_dump",
  2381. QMI_WLFW_MAX_STR_LEN_V01 + 1);
  2382. }
  2383. cnss_driver_event_post(plat_priv, CNSS_DRIVER_EVENT_FW_MEM_FILE_SAVE,
  2384. 0, event_data);
  2385. }
  2386. return;
  2387. free_event_data:
  2388. kfree(event_data);
  2389. }
  2390. static void cnss_wlfw_qdss_trace_free_ind_cb(struct qmi_handle *qmi_wlfw,
  2391. struct sockaddr_qrtr *sq,
  2392. struct qmi_txn *txn,
  2393. const void *data)
  2394. {
  2395. struct cnss_plat_data *plat_priv =
  2396. container_of(qmi_wlfw, struct cnss_plat_data, qmi_wlfw);
  2397. cnss_driver_event_post(plat_priv, CNSS_DRIVER_EVENT_QDSS_TRACE_FREE,
  2398. 0, NULL);
  2399. }
  2400. static void cnss_wlfw_respond_get_info_ind_cb(struct qmi_handle *qmi_wlfw,
  2401. struct sockaddr_qrtr *sq,
  2402. struct qmi_txn *txn,
  2403. const void *data)
  2404. {
  2405. struct cnss_plat_data *plat_priv =
  2406. container_of(qmi_wlfw, struct cnss_plat_data, qmi_wlfw);
  2407. const struct wlfw_respond_get_info_ind_msg_v01 *ind_msg = data;
  2408. cnss_pr_buf("Received QMI WLFW respond get info indication\n");
  2409. if (!txn) {
  2410. cnss_pr_err("Spurious indication\n");
  2411. return;
  2412. }
  2413. cnss_pr_buf("Extract message with event length: %d, type: %d, is last: %d, seq no: %d\n",
  2414. ind_msg->data_len, ind_msg->type,
  2415. ind_msg->is_last, ind_msg->seq_no);
  2416. if (plat_priv->get_info_cb_ctx && plat_priv->get_info_cb)
  2417. plat_priv->get_info_cb(plat_priv->get_info_cb_ctx,
  2418. (void *)ind_msg->data,
  2419. ind_msg->data_len);
  2420. }
  2421. static int cnss_ims_wfc_call_twt_cfg_send_sync
  2422. (struct cnss_plat_data *plat_priv,
  2423. const struct wlfw_wfc_call_twt_config_ind_msg_v01 *ind_msg)
  2424. {
  2425. struct ims_private_service_wfc_call_twt_config_req_msg_v01 *req;
  2426. struct ims_private_service_wfc_call_twt_config_rsp_msg_v01 *resp;
  2427. struct qmi_txn txn;
  2428. int ret = 0;
  2429. if (!test_bit(CNSS_IMS_CONNECTED, &plat_priv->driver_state)) {
  2430. cnss_pr_err("Drop FW WFC indication as IMS QMI not connected\n");
  2431. return -EINVAL;
  2432. }
  2433. req = kzalloc(sizeof(*req), GFP_KERNEL);
  2434. if (!req)
  2435. return -ENOMEM;
  2436. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  2437. if (!resp) {
  2438. kfree(req);
  2439. return -ENOMEM;
  2440. }
  2441. req->twt_sta_start_valid = ind_msg->twt_sta_start_valid;
  2442. req->twt_sta_start = ind_msg->twt_sta_start;
  2443. req->twt_sta_int_valid = ind_msg->twt_sta_int_valid;
  2444. req->twt_sta_int = ind_msg->twt_sta_int;
  2445. req->twt_sta_upo_valid = ind_msg->twt_sta_upo_valid;
  2446. req->twt_sta_upo = ind_msg->twt_sta_upo;
  2447. req->twt_sta_sp_valid = ind_msg->twt_sta_sp_valid;
  2448. req->twt_sta_sp = ind_msg->twt_sta_sp;
  2449. req->twt_sta_dl_valid = req->twt_sta_dl_valid;
  2450. req->twt_sta_dl = req->twt_sta_dl;
  2451. req->twt_sta_config_changed_valid =
  2452. ind_msg->twt_sta_config_changed_valid;
  2453. req->twt_sta_config_changed = ind_msg->twt_sta_config_changed;
  2454. cnss_pr_dbg("CNSS->IMS: TWT_CFG_REQ: state: 0x%lx\n",
  2455. plat_priv->driver_state);
  2456. ret =
  2457. qmi_txn_init(&plat_priv->ims_qmi, &txn,
  2458. ims_private_service_wfc_call_twt_config_rsp_msg_v01_ei,
  2459. resp);
  2460. if (ret < 0) {
  2461. cnss_pr_err("CNSS->IMS: TWT_CFG_REQ: QMI Txn Init Err: %d\n",
  2462. ret);
  2463. goto out;
  2464. }
  2465. ret =
  2466. qmi_send_request(&plat_priv->ims_qmi, NULL, &txn,
  2467. QMI_IMS_PRIVATE_SERVICE_WFC_CALL_TWT_CONFIG_REQ_V01,
  2468. IMS_PRIVATE_SERVICE_WFC_CALL_TWT_CONFIG_REQ_MSG_V01_MAX_MSG_LEN,
  2469. ims_private_service_wfc_call_twt_config_req_msg_v01_ei, req);
  2470. if (ret < 0) {
  2471. qmi_txn_cancel(&txn);
  2472. cnss_pr_err("CNSS->IMS: TWT_CFG_REQ: QMI Send Err: %d\n", ret);
  2473. goto out;
  2474. }
  2475. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  2476. if (ret < 0) {
  2477. cnss_pr_err("IMS->CNSS: TWT_CFG_RSP: QMI Wait Err: %d\n", ret);
  2478. goto out;
  2479. }
  2480. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  2481. cnss_pr_err("IMS->CNSS: TWT_CFG_RSP: Result: %d Err: %d\n",
  2482. resp->resp.result, resp->resp.error);
  2483. ret = -resp->resp.result;
  2484. goto out;
  2485. }
  2486. ret = 0;
  2487. out:
  2488. kfree(req);
  2489. kfree(resp);
  2490. return ret;
  2491. }
  2492. int cnss_process_twt_cfg_ind_event(struct cnss_plat_data *plat_priv,
  2493. void *data)
  2494. {
  2495. int ret;
  2496. struct wlfw_wfc_call_twt_config_ind_msg_v01 *ind_msg = data;
  2497. ret = cnss_ims_wfc_call_twt_cfg_send_sync(plat_priv, ind_msg);
  2498. kfree(data);
  2499. return ret;
  2500. }
  2501. static void cnss_wlfw_process_twt_cfg_ind(struct qmi_handle *qmi_wlfw,
  2502. struct sockaddr_qrtr *sq,
  2503. struct qmi_txn *txn,
  2504. const void *data)
  2505. {
  2506. struct cnss_plat_data *plat_priv =
  2507. container_of(qmi_wlfw, struct cnss_plat_data, qmi_wlfw);
  2508. const struct wlfw_wfc_call_twt_config_ind_msg_v01 *ind_msg = data;
  2509. struct wlfw_wfc_call_twt_config_ind_msg_v01 *event_data;
  2510. if (!txn) {
  2511. cnss_pr_err("FW->CNSS: TWT_CFG_IND: Spurious indication\n");
  2512. return;
  2513. }
  2514. if (!ind_msg) {
  2515. cnss_pr_err("FW->CNSS: TWT_CFG_IND: Invalid indication\n");
  2516. return;
  2517. }
  2518. cnss_pr_dbg("FW->CNSS: TWT_CFG_IND: %x %llx, %x %x, %x %x, %x %x, %x %x, %x %x\n",
  2519. ind_msg->twt_sta_start_valid, ind_msg->twt_sta_start,
  2520. ind_msg->twt_sta_int_valid, ind_msg->twt_sta_int,
  2521. ind_msg->twt_sta_upo_valid, ind_msg->twt_sta_upo,
  2522. ind_msg->twt_sta_sp_valid, ind_msg->twt_sta_sp,
  2523. ind_msg->twt_sta_dl_valid, ind_msg->twt_sta_dl,
  2524. ind_msg->twt_sta_config_changed_valid,
  2525. ind_msg->twt_sta_config_changed);
  2526. event_data = kmemdup(ind_msg, sizeof(*event_data), GFP_KERNEL);
  2527. if (!event_data)
  2528. return;
  2529. cnss_driver_event_post(plat_priv, CNSS_DRIVER_EVENT_WLFW_TWT_CFG_IND, 0,
  2530. event_data);
  2531. }
  2532. static struct qmi_msg_handler qmi_wlfw_msg_handlers[] = {
  2533. {
  2534. .type = QMI_INDICATION,
  2535. .msg_id = QMI_WLFW_REQUEST_MEM_IND_V01,
  2536. .ei = wlfw_request_mem_ind_msg_v01_ei,
  2537. .decoded_size = sizeof(struct wlfw_request_mem_ind_msg_v01),
  2538. .fn = cnss_wlfw_request_mem_ind_cb
  2539. },
  2540. {
  2541. .type = QMI_INDICATION,
  2542. .msg_id = QMI_WLFW_FW_MEM_READY_IND_V01,
  2543. .ei = wlfw_fw_mem_ready_ind_msg_v01_ei,
  2544. .decoded_size = sizeof(struct wlfw_fw_mem_ready_ind_msg_v01),
  2545. .fn = cnss_wlfw_fw_mem_ready_ind_cb
  2546. },
  2547. {
  2548. .type = QMI_INDICATION,
  2549. .msg_id = QMI_WLFW_FW_READY_IND_V01,
  2550. .ei = wlfw_fw_ready_ind_msg_v01_ei,
  2551. .decoded_size = sizeof(struct wlfw_fw_ready_ind_msg_v01),
  2552. .fn = cnss_wlfw_fw_ready_ind_cb
  2553. },
  2554. {
  2555. .type = QMI_INDICATION,
  2556. .msg_id = QMI_WLFW_FW_INIT_DONE_IND_V01,
  2557. .ei = wlfw_fw_init_done_ind_msg_v01_ei,
  2558. .decoded_size = sizeof(struct wlfw_fw_init_done_ind_msg_v01),
  2559. .fn = cnss_wlfw_fw_init_done_ind_cb
  2560. },
  2561. {
  2562. .type = QMI_INDICATION,
  2563. .msg_id = QMI_WLFW_PIN_CONNECT_RESULT_IND_V01,
  2564. .ei = wlfw_pin_connect_result_ind_msg_v01_ei,
  2565. .decoded_size =
  2566. sizeof(struct wlfw_pin_connect_result_ind_msg_v01),
  2567. .fn = cnss_wlfw_pin_result_ind_cb
  2568. },
  2569. {
  2570. .type = QMI_INDICATION,
  2571. .msg_id = QMI_WLFW_CAL_DONE_IND_V01,
  2572. .ei = wlfw_cal_done_ind_msg_v01_ei,
  2573. .decoded_size = sizeof(struct wlfw_cal_done_ind_msg_v01),
  2574. .fn = cnss_wlfw_cal_done_ind_cb
  2575. },
  2576. {
  2577. .type = QMI_INDICATION,
  2578. .msg_id = QMI_WLFW_QDSS_TRACE_REQ_MEM_IND_V01,
  2579. .ei = wlfw_qdss_trace_req_mem_ind_msg_v01_ei,
  2580. .decoded_size =
  2581. sizeof(struct wlfw_qdss_trace_req_mem_ind_msg_v01),
  2582. .fn = cnss_wlfw_qdss_trace_req_mem_ind_cb
  2583. },
  2584. {
  2585. .type = QMI_INDICATION,
  2586. .msg_id = QMI_WLFW_QDSS_TRACE_SAVE_IND_V01,
  2587. .ei = wlfw_qdss_trace_save_ind_msg_v01_ei,
  2588. .decoded_size =
  2589. sizeof(struct wlfw_qdss_trace_save_ind_msg_v01),
  2590. .fn = cnss_wlfw_fw_mem_file_save_ind_cb
  2591. },
  2592. {
  2593. .type = QMI_INDICATION,
  2594. .msg_id = QMI_WLFW_QDSS_TRACE_FREE_IND_V01,
  2595. .ei = wlfw_qdss_trace_free_ind_msg_v01_ei,
  2596. .decoded_size =
  2597. sizeof(struct wlfw_qdss_trace_free_ind_msg_v01),
  2598. .fn = cnss_wlfw_qdss_trace_free_ind_cb
  2599. },
  2600. {
  2601. .type = QMI_INDICATION,
  2602. .msg_id = QMI_WLFW_RESPOND_GET_INFO_IND_V01,
  2603. .ei = wlfw_respond_get_info_ind_msg_v01_ei,
  2604. .decoded_size =
  2605. sizeof(struct wlfw_respond_get_info_ind_msg_v01),
  2606. .fn = cnss_wlfw_respond_get_info_ind_cb
  2607. },
  2608. {
  2609. .type = QMI_INDICATION,
  2610. .msg_id = QMI_WLFW_WFC_CALL_TWT_CONFIG_IND_V01,
  2611. .ei = wlfw_wfc_call_twt_config_ind_msg_v01_ei,
  2612. .decoded_size =
  2613. sizeof(struct wlfw_wfc_call_twt_config_ind_msg_v01),
  2614. .fn = cnss_wlfw_process_twt_cfg_ind
  2615. },
  2616. {}
  2617. };
  2618. static int cnss_wlfw_connect_to_server(struct cnss_plat_data *plat_priv,
  2619. void *data)
  2620. {
  2621. struct cnss_qmi_event_server_arrive_data *event_data = data;
  2622. struct qmi_handle *qmi_wlfw = &plat_priv->qmi_wlfw;
  2623. struct sockaddr_qrtr sq = { 0 };
  2624. int ret = 0;
  2625. if (!event_data)
  2626. return -EINVAL;
  2627. sq.sq_family = AF_QIPCRTR;
  2628. sq.sq_node = event_data->node;
  2629. sq.sq_port = event_data->port;
  2630. ret = kernel_connect(qmi_wlfw->sock, (struct sockaddr *)&sq,
  2631. sizeof(sq), 0);
  2632. if (ret < 0) {
  2633. cnss_pr_err("Failed to connect to QMI WLFW remote service port\n");
  2634. goto out;
  2635. }
  2636. set_bit(CNSS_QMI_WLFW_CONNECTED, &plat_priv->driver_state);
  2637. cnss_pr_info("QMI WLFW service connected, state: 0x%lx\n",
  2638. plat_priv->driver_state);
  2639. kfree(data);
  2640. return 0;
  2641. out:
  2642. CNSS_QMI_ASSERT();
  2643. kfree(data);
  2644. return ret;
  2645. }
  2646. int cnss_wlfw_server_arrive(struct cnss_plat_data *plat_priv, void *data)
  2647. {
  2648. int ret = 0;
  2649. if (!plat_priv)
  2650. return -ENODEV;
  2651. if (test_bit(CNSS_QMI_WLFW_CONNECTED, &plat_priv->driver_state)) {
  2652. cnss_pr_err("Unexpected WLFW server arrive\n");
  2653. CNSS_ASSERT(0);
  2654. return -EINVAL;
  2655. }
  2656. cnss_ignore_qmi_failure(false);
  2657. ret = cnss_wlfw_connect_to_server(plat_priv, data);
  2658. if (ret < 0)
  2659. goto out;
  2660. ret = cnss_wlfw_ind_register_send_sync(plat_priv);
  2661. if (ret < 0) {
  2662. if (ret == -EALREADY)
  2663. ret = 0;
  2664. goto out;
  2665. }
  2666. ret = cnss_wlfw_host_cap_send_sync(plat_priv);
  2667. if (ret < 0)
  2668. goto out;
  2669. return 0;
  2670. out:
  2671. return ret;
  2672. }
  2673. int cnss_wlfw_server_exit(struct cnss_plat_data *plat_priv)
  2674. {
  2675. int ret;
  2676. if (!plat_priv)
  2677. return -ENODEV;
  2678. clear_bit(CNSS_QMI_WLFW_CONNECTED, &plat_priv->driver_state);
  2679. cnss_pr_info("QMI WLFW service disconnected, state: 0x%lx\n",
  2680. plat_priv->driver_state);
  2681. cnss_qmi_deinit(plat_priv);
  2682. clear_bit(CNSS_QMI_DEL_SERVER, &plat_priv->driver_state);
  2683. ret = cnss_qmi_init(plat_priv);
  2684. if (ret < 0) {
  2685. cnss_pr_err("QMI WLFW service registraton failed, ret\n", ret);
  2686. CNSS_ASSERT(0);
  2687. }
  2688. return 0;
  2689. }
  2690. static int wlfw_new_server(struct qmi_handle *qmi_wlfw,
  2691. struct qmi_service *service)
  2692. {
  2693. struct cnss_plat_data *plat_priv =
  2694. container_of(qmi_wlfw, struct cnss_plat_data, qmi_wlfw);
  2695. struct cnss_qmi_event_server_arrive_data *event_data;
  2696. if (plat_priv && test_bit(CNSS_QMI_DEL_SERVER, &plat_priv->driver_state)) {
  2697. cnss_pr_info("WLFW server delete in progress, Ignore server arrive, state: 0x%lx\n",
  2698. plat_priv->driver_state);
  2699. return 0;
  2700. }
  2701. cnss_pr_dbg("WLFW server arriving: node %u port %u\n",
  2702. service->node, service->port);
  2703. event_data = kzalloc(sizeof(*event_data), GFP_KERNEL);
  2704. if (!event_data)
  2705. return -ENOMEM;
  2706. event_data->node = service->node;
  2707. event_data->port = service->port;
  2708. cnss_driver_event_post(plat_priv, CNSS_DRIVER_EVENT_SERVER_ARRIVE,
  2709. 0, event_data);
  2710. return 0;
  2711. }
  2712. static void wlfw_del_server(struct qmi_handle *qmi_wlfw,
  2713. struct qmi_service *service)
  2714. {
  2715. struct cnss_plat_data *plat_priv =
  2716. container_of(qmi_wlfw, struct cnss_plat_data, qmi_wlfw);
  2717. if (plat_priv && test_bit(CNSS_QMI_DEL_SERVER, &plat_priv->driver_state)) {
  2718. cnss_pr_info("WLFW server delete in progress, Ignore server delete, state: 0x%lx\n",
  2719. plat_priv->driver_state);
  2720. return;
  2721. }
  2722. cnss_pr_dbg("WLFW server exiting\n");
  2723. if (plat_priv) {
  2724. cnss_ignore_qmi_failure(true);
  2725. set_bit(CNSS_QMI_DEL_SERVER, &plat_priv->driver_state);
  2726. }
  2727. cnss_driver_event_post(plat_priv, CNSS_DRIVER_EVENT_SERVER_EXIT,
  2728. 0, NULL);
  2729. }
  2730. static struct qmi_ops qmi_wlfw_ops = {
  2731. .new_server = wlfw_new_server,
  2732. .del_server = wlfw_del_server,
  2733. };
  2734. int cnss_qmi_init(struct cnss_plat_data *plat_priv)
  2735. {
  2736. int ret = 0;
  2737. ret = qmi_handle_init(&plat_priv->qmi_wlfw,
  2738. QMI_WLFW_MAX_RECV_BUF_SIZE,
  2739. &qmi_wlfw_ops, qmi_wlfw_msg_handlers);
  2740. if (ret < 0) {
  2741. cnss_pr_err("Failed to initialize WLFW QMI handle, err: %d\n",
  2742. ret);
  2743. goto out;
  2744. }
  2745. ret = qmi_add_lookup(&plat_priv->qmi_wlfw, WLFW_SERVICE_ID_V01,
  2746. WLFW_SERVICE_VERS_V01, WLFW_SERVICE_INS_ID_V01);
  2747. if (ret < 0)
  2748. cnss_pr_err("Failed to add WLFW QMI lookup, err: %d\n", ret);
  2749. out:
  2750. return ret;
  2751. }
  2752. void cnss_qmi_deinit(struct cnss_plat_data *plat_priv)
  2753. {
  2754. qmi_handle_release(&plat_priv->qmi_wlfw);
  2755. }
  2756. int cnss_qmi_get_dms_mac(struct cnss_plat_data *plat_priv)
  2757. {
  2758. struct dms_get_mac_address_req_msg_v01 req;
  2759. struct dms_get_mac_address_resp_msg_v01 resp;
  2760. struct qmi_txn txn;
  2761. int ret = 0;
  2762. if (!test_bit(CNSS_QMI_DMS_CONNECTED, &plat_priv->driver_state)) {
  2763. cnss_pr_err("DMS QMI connection not established\n");
  2764. return -EINVAL;
  2765. }
  2766. cnss_pr_dbg("Requesting DMS MAC address");
  2767. memset(&resp, 0, sizeof(resp));
  2768. ret = qmi_txn_init(&plat_priv->qmi_dms, &txn,
  2769. dms_get_mac_address_resp_msg_v01_ei, &resp);
  2770. if (ret < 0) {
  2771. cnss_pr_err("Failed to initialize txn for dms, err: %d\n",
  2772. ret);
  2773. goto out;
  2774. }
  2775. req.device = DMS_DEVICE_MAC_WLAN_V01;
  2776. ret = qmi_send_request(&plat_priv->qmi_dms, NULL, &txn,
  2777. QMI_DMS_GET_MAC_ADDRESS_REQ_V01,
  2778. DMS_GET_MAC_ADDRESS_REQ_MSG_V01_MAX_MSG_LEN,
  2779. dms_get_mac_address_req_msg_v01_ei, &req);
  2780. if (ret < 0) {
  2781. qmi_txn_cancel(&txn);
  2782. cnss_pr_err("Failed to send QMI_DMS_GET_MAC_ADDRESS_REQ_V01, err: %d\n",
  2783. ret);
  2784. goto out;
  2785. }
  2786. ret = qmi_txn_wait(&txn, QMI_WLFW_TIMEOUT_JF);
  2787. if (ret < 0) {
  2788. cnss_pr_err("Failed to wait for QMI_DMS_GET_MAC_ADDRESS_RESP_V01, err: %d\n",
  2789. ret);
  2790. goto out;
  2791. }
  2792. if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
  2793. cnss_pr_err("QMI_DMS_GET_MAC_ADDRESS_REQ_V01 failed, result: %d, err: %d\n",
  2794. resp.resp.result, resp.resp.error);
  2795. ret = -resp.resp.result;
  2796. goto out;
  2797. }
  2798. if (!resp.mac_address_valid ||
  2799. resp.mac_address_len != QMI_WLFW_MAC_ADDR_SIZE_V01) {
  2800. cnss_pr_err("Invalid MAC address received from DMS\n");
  2801. plat_priv->dms.mac_valid = false;
  2802. goto out;
  2803. }
  2804. plat_priv->dms.mac_valid = true;
  2805. memcpy(plat_priv->dms.mac, resp.mac_address, QMI_WLFW_MAC_ADDR_SIZE_V01);
  2806. cnss_pr_info("Received DMS MAC: [%pM]\n", plat_priv->dms.mac);
  2807. out:
  2808. return ret;
  2809. }
  2810. static int cnss_dms_connect_to_server(struct cnss_plat_data *plat_priv,
  2811. unsigned int node, unsigned int port)
  2812. {
  2813. struct qmi_handle *qmi_dms = &plat_priv->qmi_dms;
  2814. struct sockaddr_qrtr sq = {0};
  2815. int ret = 0;
  2816. sq.sq_family = AF_QIPCRTR;
  2817. sq.sq_node = node;
  2818. sq.sq_port = port;
  2819. ret = kernel_connect(qmi_dms->sock, (struct sockaddr *)&sq,
  2820. sizeof(sq), 0);
  2821. if (ret < 0) {
  2822. cnss_pr_err("Failed to connect to QMI DMS remote service Node: %d Port: %d\n",
  2823. node, port);
  2824. goto out;
  2825. }
  2826. set_bit(CNSS_QMI_DMS_CONNECTED, &plat_priv->driver_state);
  2827. cnss_pr_info("QMI DMS service connected, state: 0x%lx\n",
  2828. plat_priv->driver_state);
  2829. out:
  2830. return ret;
  2831. }
  2832. static int dms_new_server(struct qmi_handle *qmi_dms,
  2833. struct qmi_service *service)
  2834. {
  2835. struct cnss_plat_data *plat_priv =
  2836. container_of(qmi_dms, struct cnss_plat_data, qmi_dms);
  2837. if (!service)
  2838. return -EINVAL;
  2839. return cnss_dms_connect_to_server(plat_priv, service->node,
  2840. service->port);
  2841. }
  2842. static void cnss_dms_server_exit_work(struct work_struct *work)
  2843. {
  2844. int ret;
  2845. struct cnss_plat_data *plat_priv = cnss_get_plat_priv(NULL);
  2846. cnss_dms_deinit(plat_priv);
  2847. cnss_pr_info("QMI DMS Server Exit");
  2848. clear_bit(CNSS_DMS_DEL_SERVER, &plat_priv->driver_state);
  2849. ret = cnss_dms_init(plat_priv);
  2850. if (ret < 0)
  2851. cnss_pr_err("QMI DMS service registraton failed, ret\n", ret);
  2852. }
  2853. static DECLARE_WORK(cnss_dms_del_work, cnss_dms_server_exit_work);
  2854. static void dms_del_server(struct qmi_handle *qmi_dms,
  2855. struct qmi_service *service)
  2856. {
  2857. struct cnss_plat_data *plat_priv =
  2858. container_of(qmi_dms, struct cnss_plat_data, qmi_dms);
  2859. if (!plat_priv)
  2860. return;
  2861. if (test_bit(CNSS_DMS_DEL_SERVER, &plat_priv->driver_state)) {
  2862. cnss_pr_info("DMS server delete or cnss remove in progress, Ignore server delete: 0x%lx\n",
  2863. plat_priv->driver_state);
  2864. return;
  2865. }
  2866. set_bit(CNSS_DMS_DEL_SERVER, &plat_priv->driver_state);
  2867. clear_bit(CNSS_QMI_DMS_CONNECTED, &plat_priv->driver_state);
  2868. cnss_pr_info("QMI DMS service disconnected, state: 0x%lx\n",
  2869. plat_priv->driver_state);
  2870. schedule_work(&cnss_dms_del_work);
  2871. }
  2872. void cnss_cancel_dms_work(void)
  2873. {
  2874. cancel_work_sync(&cnss_dms_del_work);
  2875. }
  2876. static struct qmi_ops qmi_dms_ops = {
  2877. .new_server = dms_new_server,
  2878. .del_server = dms_del_server,
  2879. };
  2880. int cnss_dms_init(struct cnss_plat_data *plat_priv)
  2881. {
  2882. int ret = 0;
  2883. ret = qmi_handle_init(&plat_priv->qmi_dms, DMS_QMI_MAX_MSG_LEN,
  2884. &qmi_dms_ops, NULL);
  2885. if (ret < 0) {
  2886. cnss_pr_err("Failed to initialize DMS handle, err: %d\n", ret);
  2887. goto out;
  2888. }
  2889. ret = qmi_add_lookup(&plat_priv->qmi_dms, DMS_SERVICE_ID_V01,
  2890. DMS_SERVICE_VERS_V01, 0);
  2891. if (ret < 0)
  2892. cnss_pr_err("Failed to add DMS lookup, err: %d\n", ret);
  2893. out:
  2894. return ret;
  2895. }
  2896. void cnss_dms_deinit(struct cnss_plat_data *plat_priv)
  2897. {
  2898. set_bit(CNSS_DMS_DEL_SERVER, &plat_priv->driver_state);
  2899. qmi_handle_release(&plat_priv->qmi_dms);
  2900. }
  2901. int coex_antenna_switch_to_wlan_send_sync_msg(struct cnss_plat_data *plat_priv)
  2902. {
  2903. int ret;
  2904. struct coex_antenna_switch_to_wlan_req_msg_v01 *req;
  2905. struct coex_antenna_switch_to_wlan_resp_msg_v01 *resp;
  2906. struct qmi_txn txn;
  2907. if (!plat_priv)
  2908. return -ENODEV;
  2909. cnss_pr_dbg("Sending coex antenna switch_to_wlan\n");
  2910. req = kzalloc(sizeof(*req), GFP_KERNEL);
  2911. if (!req)
  2912. return -ENOMEM;
  2913. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  2914. if (!resp) {
  2915. kfree(req);
  2916. return -ENOMEM;
  2917. }
  2918. req->antenna = plat_priv->antenna;
  2919. ret = qmi_txn_init(&plat_priv->coex_qmi, &txn,
  2920. coex_antenna_switch_to_wlan_resp_msg_v01_ei, resp);
  2921. if (ret < 0) {
  2922. cnss_pr_err("Fail to init txn for coex antenna switch_to_wlan resp %d\n",
  2923. ret);
  2924. goto out;
  2925. }
  2926. ret = qmi_send_request
  2927. (&plat_priv->coex_qmi, NULL, &txn,
  2928. QMI_COEX_SWITCH_ANTENNA_TO_WLAN_REQ_V01,
  2929. COEX_ANTENNA_SWITCH_TO_WLAN_REQ_MSG_V01_MAX_MSG_LEN,
  2930. coex_antenna_switch_to_wlan_req_msg_v01_ei, req);
  2931. if (ret < 0) {
  2932. qmi_txn_cancel(&txn);
  2933. cnss_pr_err("Fail to send coex antenna switch_to_wlan req %d\n",
  2934. ret);
  2935. goto out;
  2936. }
  2937. ret = qmi_txn_wait(&txn, COEX_TIMEOUT);
  2938. if (ret < 0) {
  2939. cnss_pr_err("Coex antenna switch_to_wlan resp wait failed with ret %d\n",
  2940. ret);
  2941. goto out;
  2942. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  2943. cnss_pr_err("Coex antenna switch_to_wlan request rejected, result:%d error:%d\n",
  2944. resp->resp.result, resp->resp.error);
  2945. ret = -resp->resp.result;
  2946. goto out;
  2947. }
  2948. if (resp->grant_valid)
  2949. plat_priv->grant = resp->grant;
  2950. cnss_pr_dbg("Coex antenna grant: 0x%llx\n", resp->grant);
  2951. kfree(resp);
  2952. kfree(req);
  2953. return 0;
  2954. out:
  2955. kfree(resp);
  2956. kfree(req);
  2957. return ret;
  2958. }
  2959. int coex_antenna_switch_to_mdm_send_sync_msg(struct cnss_plat_data *plat_priv)
  2960. {
  2961. int ret;
  2962. struct coex_antenna_switch_to_mdm_req_msg_v01 *req;
  2963. struct coex_antenna_switch_to_mdm_resp_msg_v01 *resp;
  2964. struct qmi_txn txn;
  2965. if (!plat_priv)
  2966. return -ENODEV;
  2967. cnss_pr_dbg("Sending coex antenna switch_to_mdm\n");
  2968. req = kzalloc(sizeof(*req), GFP_KERNEL);
  2969. if (!req)
  2970. return -ENOMEM;
  2971. resp = kzalloc(sizeof(*resp), GFP_KERNEL);
  2972. if (!resp) {
  2973. kfree(req);
  2974. return -ENOMEM;
  2975. }
  2976. req->antenna = plat_priv->antenna;
  2977. ret = qmi_txn_init(&plat_priv->coex_qmi, &txn,
  2978. coex_antenna_switch_to_mdm_resp_msg_v01_ei, resp);
  2979. if (ret < 0) {
  2980. cnss_pr_err("Fail to init txn for coex antenna switch_to_mdm resp %d\n",
  2981. ret);
  2982. goto out;
  2983. }
  2984. ret = qmi_send_request
  2985. (&plat_priv->coex_qmi, NULL, &txn,
  2986. QMI_COEX_SWITCH_ANTENNA_TO_MDM_REQ_V01,
  2987. COEX_ANTENNA_SWITCH_TO_MDM_REQ_MSG_V01_MAX_MSG_LEN,
  2988. coex_antenna_switch_to_mdm_req_msg_v01_ei, req);
  2989. if (ret < 0) {
  2990. qmi_txn_cancel(&txn);
  2991. cnss_pr_err("Fail to send coex antenna switch_to_mdm req %d\n",
  2992. ret);
  2993. goto out;
  2994. }
  2995. ret = qmi_txn_wait(&txn, COEX_TIMEOUT);
  2996. if (ret < 0) {
  2997. cnss_pr_err("Coex antenna switch_to_mdm resp wait failed with ret %d\n",
  2998. ret);
  2999. goto out;
  3000. } else if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  3001. cnss_pr_err("Coex antenna switch_to_mdm request rejected, result:%d error:%d\n",
  3002. resp->resp.result, resp->resp.error);
  3003. ret = -resp->resp.result;
  3004. goto out;
  3005. }
  3006. kfree(resp);
  3007. kfree(req);
  3008. return 0;
  3009. out:
  3010. kfree(resp);
  3011. kfree(req);
  3012. return ret;
  3013. }
  3014. int cnss_send_subsys_restart_level_msg(struct cnss_plat_data *plat_priv)
  3015. {
  3016. int ret;
  3017. struct wlfw_subsys_restart_level_req_msg_v01 req;
  3018. struct wlfw_subsys_restart_level_resp_msg_v01 resp;
  3019. u8 pcss_enabled;
  3020. if (!plat_priv)
  3021. return -ENODEV;
  3022. if (!test_bit(CNSS_FW_READY, &plat_priv->driver_state)) {
  3023. cnss_pr_err("Can't send pcss cmd before fw ready\n");
  3024. return -EINVAL;
  3025. }
  3026. pcss_enabled = plat_priv->recovery_pcss_enabled;
  3027. cnss_pr_dbg("Sending pcss recovery status: %d\n", pcss_enabled);
  3028. req.restart_level_type_valid = 1;
  3029. req.restart_level_type = pcss_enabled;
  3030. ret = qmi_send_wait(&plat_priv->qmi_wlfw, &req, &resp,
  3031. wlfw_subsys_restart_level_req_msg_v01_ei,
  3032. wlfw_subsys_restart_level_resp_msg_v01_ei,
  3033. QMI_WLFW_SUBSYS_RESTART_LEVEL_REQ_V01,
  3034. WLFW_SUBSYS_RESTART_LEVEL_REQ_MSG_V01_MAX_MSG_LEN,
  3035. QMI_WLFW_TIMEOUT_JF);
  3036. return ret;
  3037. }
  3038. static int coex_new_server(struct qmi_handle *qmi,
  3039. struct qmi_service *service)
  3040. {
  3041. struct cnss_plat_data *plat_priv =
  3042. container_of(qmi, struct cnss_plat_data, coex_qmi);
  3043. struct sockaddr_qrtr sq = { 0 };
  3044. int ret = 0;
  3045. cnss_pr_dbg("COEX server arrive: node %u port %u\n",
  3046. service->node, service->port);
  3047. sq.sq_family = AF_QIPCRTR;
  3048. sq.sq_node = service->node;
  3049. sq.sq_port = service->port;
  3050. ret = kernel_connect(qmi->sock, (struct sockaddr *)&sq, sizeof(sq), 0);
  3051. if (ret < 0) {
  3052. cnss_pr_err("Fail to connect to remote service port\n");
  3053. return ret;
  3054. }
  3055. set_bit(CNSS_COEX_CONNECTED, &plat_priv->driver_state);
  3056. cnss_pr_dbg("COEX Server Connected: 0x%lx\n",
  3057. plat_priv->driver_state);
  3058. return 0;
  3059. }
  3060. static void coex_del_server(struct qmi_handle *qmi,
  3061. struct qmi_service *service)
  3062. {
  3063. struct cnss_plat_data *plat_priv =
  3064. container_of(qmi, struct cnss_plat_data, coex_qmi);
  3065. cnss_pr_dbg("COEX server exit\n");
  3066. clear_bit(CNSS_COEX_CONNECTED, &plat_priv->driver_state);
  3067. }
  3068. static struct qmi_ops coex_qmi_ops = {
  3069. .new_server = coex_new_server,
  3070. .del_server = coex_del_server,
  3071. };
  3072. int cnss_register_coex_service(struct cnss_plat_data *plat_priv)
  3073. { int ret;
  3074. ret = qmi_handle_init(&plat_priv->coex_qmi,
  3075. COEX_SERVICE_MAX_MSG_LEN,
  3076. &coex_qmi_ops, NULL);
  3077. if (ret < 0)
  3078. return ret;
  3079. ret = qmi_add_lookup(&plat_priv->coex_qmi, COEX_SERVICE_ID_V01,
  3080. COEX_SERVICE_VERS_V01, 0);
  3081. return ret;
  3082. }
  3083. void cnss_unregister_coex_service(struct cnss_plat_data *plat_priv)
  3084. {
  3085. qmi_handle_release(&plat_priv->coex_qmi);
  3086. }
  3087. /* IMS Service */
  3088. int ims_subscribe_for_indication_send_async(struct cnss_plat_data *plat_priv)
  3089. {
  3090. int ret;
  3091. struct ims_private_service_subscribe_for_indications_req_msg_v01 *req;
  3092. struct qmi_txn *txn;
  3093. if (!plat_priv)
  3094. return -ENODEV;
  3095. cnss_pr_dbg("Sending ASYNC ims subscribe for indication\n");
  3096. req = kzalloc(sizeof(*req), GFP_KERNEL);
  3097. if (!req)
  3098. return -ENOMEM;
  3099. req->wfc_call_status_valid = 1;
  3100. req->wfc_call_status = 1;
  3101. txn = &plat_priv->txn;
  3102. ret = qmi_txn_init(&plat_priv->ims_qmi, txn, NULL, NULL);
  3103. if (ret < 0) {
  3104. cnss_pr_err("Fail to init txn for ims subscribe for indication resp %d\n",
  3105. ret);
  3106. goto out;
  3107. }
  3108. ret = qmi_send_request
  3109. (&plat_priv->ims_qmi, NULL, txn,
  3110. QMI_IMS_PRIVATE_SERVICE_SUBSCRIBE_FOR_INDICATIONS_REQ_V01,
  3111. IMS_PRIVATE_SERVICE_SUBSCRIBE_FOR_INDICATIONS_REQ_MSG_V01_MAX_MSG_LEN,
  3112. ims_private_service_subscribe_for_indications_req_msg_v01_ei, req);
  3113. if (ret < 0) {
  3114. qmi_txn_cancel(txn);
  3115. cnss_pr_err("Fail to send ims subscribe for indication req %d\n",
  3116. ret);
  3117. goto out;
  3118. }
  3119. kfree(req);
  3120. return 0;
  3121. out:
  3122. kfree(req);
  3123. return ret;
  3124. }
  3125. static void ims_subscribe_for_indication_resp_cb(struct qmi_handle *qmi,
  3126. struct sockaddr_qrtr *sq,
  3127. struct qmi_txn *txn,
  3128. const void *data)
  3129. {
  3130. const
  3131. struct ims_private_service_subscribe_for_indications_rsp_msg_v01 *resp =
  3132. data;
  3133. cnss_pr_dbg("Received IMS subscribe indication response\n");
  3134. if (!txn) {
  3135. cnss_pr_err("spurious response\n");
  3136. return;
  3137. }
  3138. if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
  3139. cnss_pr_err("IMS subscribe for indication request rejected, result:%d error:%d\n",
  3140. resp->resp.result, resp->resp.error);
  3141. txn->result = -resp->resp.result;
  3142. }
  3143. }
  3144. int cnss_process_wfc_call_ind_event(struct cnss_plat_data *plat_priv,
  3145. void *data)
  3146. {
  3147. int ret;
  3148. struct ims_private_service_wfc_call_status_ind_msg_v01 *ind_msg = data;
  3149. ret = cnss_wlfw_wfc_call_status_send_sync(plat_priv, ind_msg);
  3150. kfree(data);
  3151. return ret;
  3152. }
  3153. static void
  3154. cnss_ims_process_wfc_call_ind_cb(struct qmi_handle *ims_qmi,
  3155. struct sockaddr_qrtr *sq,
  3156. struct qmi_txn *txn, const void *data)
  3157. {
  3158. struct cnss_plat_data *plat_priv =
  3159. container_of(ims_qmi, struct cnss_plat_data, ims_qmi);
  3160. const
  3161. struct ims_private_service_wfc_call_status_ind_msg_v01 *ind_msg = data;
  3162. struct ims_private_service_wfc_call_status_ind_msg_v01 *event_data;
  3163. if (!txn) {
  3164. cnss_pr_err("IMS->CNSS: WFC_CALL_IND: Spurious indication\n");
  3165. return;
  3166. }
  3167. if (!ind_msg) {
  3168. cnss_pr_err("IMS->CNSS: WFC_CALL_IND: Invalid indication\n");
  3169. return;
  3170. }
  3171. cnss_pr_dbg("IMS->CNSS: WFC_CALL_IND: %x, %x %x, %x %x, %x %llx, %x %x, %x %x\n",
  3172. ind_msg->wfc_call_active, ind_msg->all_wfc_calls_held_valid,
  3173. ind_msg->all_wfc_calls_held,
  3174. ind_msg->is_wfc_emergency_valid, ind_msg->is_wfc_emergency,
  3175. ind_msg->twt_ims_start_valid, ind_msg->twt_ims_start,
  3176. ind_msg->twt_ims_int_valid, ind_msg->twt_ims_int,
  3177. ind_msg->media_quality_valid, ind_msg->media_quality);
  3178. event_data = kmemdup(ind_msg, sizeof(*event_data), GFP_KERNEL);
  3179. if (!event_data)
  3180. return;
  3181. cnss_driver_event_post(plat_priv, CNSS_DRIVER_EVENT_IMS_WFC_CALL_IND,
  3182. 0, event_data);
  3183. }
  3184. static struct qmi_msg_handler qmi_ims_msg_handlers[] = {
  3185. {
  3186. .type = QMI_RESPONSE,
  3187. .msg_id =
  3188. QMI_IMS_PRIVATE_SERVICE_SUBSCRIBE_FOR_INDICATIONS_REQ_V01,
  3189. .ei =
  3190. ims_private_service_subscribe_for_indications_rsp_msg_v01_ei,
  3191. .decoded_size = sizeof(struct
  3192. ims_private_service_subscribe_for_indications_rsp_msg_v01),
  3193. .fn = ims_subscribe_for_indication_resp_cb
  3194. },
  3195. {
  3196. .type = QMI_INDICATION,
  3197. .msg_id = QMI_IMS_PRIVATE_SERVICE_WFC_CALL_STATUS_IND_V01,
  3198. .ei = ims_private_service_wfc_call_status_ind_msg_v01_ei,
  3199. .decoded_size =
  3200. sizeof(struct ims_private_service_wfc_call_status_ind_msg_v01),
  3201. .fn = cnss_ims_process_wfc_call_ind_cb
  3202. },
  3203. {}
  3204. };
  3205. static int ims_new_server(struct qmi_handle *qmi,
  3206. struct qmi_service *service)
  3207. {
  3208. struct cnss_plat_data *plat_priv =
  3209. container_of(qmi, struct cnss_plat_data, ims_qmi);
  3210. struct sockaddr_qrtr sq = { 0 };
  3211. int ret = 0;
  3212. cnss_pr_dbg("IMS server arrive: node %u port %u\n",
  3213. service->node, service->port);
  3214. sq.sq_family = AF_QIPCRTR;
  3215. sq.sq_node = service->node;
  3216. sq.sq_port = service->port;
  3217. ret = kernel_connect(qmi->sock, (struct sockaddr *)&sq, sizeof(sq), 0);
  3218. if (ret < 0) {
  3219. cnss_pr_err("Fail to connect to remote service port\n");
  3220. return ret;
  3221. }
  3222. set_bit(CNSS_IMS_CONNECTED, &plat_priv->driver_state);
  3223. cnss_pr_dbg("IMS Server Connected: 0x%lx\n",
  3224. plat_priv->driver_state);
  3225. ret = ims_subscribe_for_indication_send_async(plat_priv);
  3226. return ret;
  3227. }
  3228. static void ims_del_server(struct qmi_handle *qmi,
  3229. struct qmi_service *service)
  3230. {
  3231. struct cnss_plat_data *plat_priv =
  3232. container_of(qmi, struct cnss_plat_data, ims_qmi);
  3233. cnss_pr_dbg("IMS server exit\n");
  3234. clear_bit(CNSS_IMS_CONNECTED, &plat_priv->driver_state);
  3235. }
  3236. static struct qmi_ops ims_qmi_ops = {
  3237. .new_server = ims_new_server,
  3238. .del_server = ims_del_server,
  3239. };
  3240. int cnss_register_ims_service(struct cnss_plat_data *plat_priv)
  3241. { int ret;
  3242. ret = qmi_handle_init(&plat_priv->ims_qmi,
  3243. IMSPRIVATE_SERVICE_MAX_MSG_LEN,
  3244. &ims_qmi_ops, qmi_ims_msg_handlers);
  3245. if (ret < 0)
  3246. return ret;
  3247. ret = qmi_add_lookup(&plat_priv->ims_qmi, IMSPRIVATE_SERVICE_ID_V01,
  3248. IMSPRIVATE_SERVICE_VERS_V01, 0);
  3249. return ret;
  3250. }
  3251. void cnss_unregister_ims_service(struct cnss_plat_data *plat_priv)
  3252. {
  3253. qmi_handle_release(&plat_priv->ims_qmi);
  3254. }