qmi.c 88 KB

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