qmi.c 84 KB

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