qmi.c 100 KB

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