qmi.c 84 KB

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