qmi.c 84 KB

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