qmi.c 97 KB

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