wmi_unified.c 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546
  1. /*
  2. * Copyright (c) 2015-2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /*
  19. * Host WMI unified implementation
  20. */
  21. #include "htc_api.h"
  22. #include "htc_api.h"
  23. #include "wmi_unified_priv.h"
  24. #include "qdf_module.h"
  25. #ifndef WMI_NON_TLV_SUPPORT
  26. #include "wmi_tlv_helper.h"
  27. #endif
  28. #include <linux/debugfs.h>
  29. /* This check for CONFIG_WIN temporary added due to redeclaration compilation
  30. error in MCL. Error is caused due to inclusion of wmi.h in wmi_unified_api.h
  31. which gets included here through ol_if_athvar.h. Eventually it is expected that
  32. wmi.h will be removed from wmi_unified_api.h after cleanup, which will need
  33. WMI_CMD_HDR to be defined here. */
  34. #ifdef CONFIG_WIN
  35. /* Copied from wmi.h */
  36. #undef MS
  37. #define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
  38. #undef SM
  39. #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
  40. #undef WO
  41. #define WO(_f) ((_f##_OFFSET) >> 2)
  42. #undef GET_FIELD
  43. #define GET_FIELD(_addr, _f) MS(*((uint32_t *)(_addr) + WO(_f)), _f)
  44. #undef SET_FIELD
  45. #define SET_FIELD(_addr, _f, _val) \
  46. (*((uint32_t *)(_addr) + WO(_f)) = \
  47. (*((uint32_t *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f))
  48. #define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \
  49. GET_FIELD(_msg_buf, _msg_type ## _ ## _f)
  50. #define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \
  51. SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val)
  52. #define WMI_EP_APASS 0x0
  53. #define WMI_EP_LPASS 0x1
  54. #define WMI_EP_SENSOR 0x2
  55. /*
  56. * * Control Path
  57. * */
  58. typedef PREPACK struct {
  59. uint32_t commandId:24,
  60. reserved:2, /* used for WMI endpoint ID */
  61. plt_priv:6; /* platform private */
  62. } POSTPACK WMI_CMD_HDR; /* used for commands and events */
  63. #define WMI_CMD_HDR_COMMANDID_LSB 0
  64. #define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff
  65. #define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000
  66. #define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000
  67. #define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24
  68. #define WMI_CMD_HDR_PLT_PRIV_LSB 24
  69. #define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000
  70. #define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000
  71. /* end of copy wmi.h */
  72. #endif /* CONFIG_WIN */
  73. #define WMI_MIN_HEAD_ROOM 64
  74. #ifdef WMI_INTERFACE_EVENT_LOGGING
  75. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
  76. /* TODO Cleanup this backported function */
  77. static int wmi_bp_seq_printf(struct seq_file *m, const char *f, ...)
  78. {
  79. va_list args;
  80. va_start(args, f);
  81. seq_vprintf(m, f, args);
  82. va_end(args);
  83. return 0;
  84. }
  85. #else
  86. #define wmi_bp_seq_printf(m, fmt, ...) seq_printf((m), fmt, ##__VA_ARGS__)
  87. #endif
  88. #ifndef MAX_WMI_INSTANCES
  89. #ifdef CONFIG_MCL
  90. #define MAX_WMI_INSTANCES 1
  91. #else
  92. #define MAX_WMI_INSTANCES 3
  93. #endif
  94. #define CUSTOM_MGMT_CMD_DATA_SIZE 4
  95. #endif
  96. #ifdef CONFIG_MCL
  97. /* WMI commands */
  98. uint32_t g_wmi_command_buf_idx = 0;
  99. struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  100. /* WMI commands TX completed */
  101. uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
  102. struct wmi_command_debug
  103. wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  104. /* WMI events when processed */
  105. uint32_t g_wmi_event_buf_idx = 0;
  106. struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  107. /* WMI events when queued */
  108. uint32_t g_wmi_rx_event_buf_idx = 0;
  109. struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  110. #endif
  111. #define WMI_COMMAND_RECORD(h, a, b) { \
  112. if (wmi_log_max_entry <= \
  113. *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
  114. *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
  115. ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
  116. [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
  117. .command = a; \
  118. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  119. wmi_command_log_buf_info.buf) \
  120. [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
  121. b, wmi_record_max_length); \
  122. ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
  123. [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
  124. time = qdf_get_log_timestamp(); \
  125. (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
  126. h->log_info.wmi_command_log_buf_info.length++; \
  127. }
  128. #define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
  129. if (wmi_log_max_entry <= \
  130. *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
  131. *(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  132. p_buf_tail_idx) = 0; \
  133. ((struct wmi_command_debug *)h->log_info. \
  134. wmi_command_tx_cmp_log_buf_info.buf) \
  135. [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  136. p_buf_tail_idx)]. \
  137. command = a; \
  138. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  139. wmi_command_tx_cmp_log_buf_info.buf) \
  140. [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  141. p_buf_tail_idx)]. \
  142. data, b, wmi_record_max_length); \
  143. ((struct wmi_command_debug *)h->log_info. \
  144. wmi_command_tx_cmp_log_buf_info.buf) \
  145. [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  146. p_buf_tail_idx)]. \
  147. time = qdf_get_log_timestamp(); \
  148. (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
  149. h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
  150. }
  151. #define WMI_EVENT_RECORD(h, a, b) { \
  152. if (wmi_log_max_entry <= \
  153. *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
  154. *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
  155. ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
  156. [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
  157. event = a; \
  158. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  159. wmi_event_log_buf_info.buf) \
  160. [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
  161. wmi_record_max_length); \
  162. ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
  163. [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
  164. qdf_get_log_timestamp(); \
  165. (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
  166. h->log_info.wmi_event_log_buf_info.length++; \
  167. }
  168. #define WMI_RX_EVENT_RECORD(h, a, b) { \
  169. if (wmi_log_max_entry <= \
  170. *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
  171. *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
  172. ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
  173. [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
  174. event = a; \
  175. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  176. wmi_rx_event_log_buf_info.buf) \
  177. [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
  178. data, b, wmi_record_max_length); \
  179. ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
  180. [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
  181. time = qdf_get_log_timestamp(); \
  182. (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
  183. h->log_info.wmi_rx_event_log_buf_info.length++; \
  184. }
  185. #ifdef CONFIG_MCL
  186. uint32_t g_wmi_mgmt_command_buf_idx = 0;
  187. struct
  188. wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
  189. /* wmi_mgmt commands TX completed */
  190. uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
  191. struct wmi_command_debug
  192. wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
  193. /* wmi_mgmt events when processed */
  194. uint32_t g_wmi_mgmt_event_buf_idx = 0;
  195. struct wmi_event_debug
  196. wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
  197. #endif
  198. #define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
  199. if (wmi_mgmt_log_max_entry <= \
  200. *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
  201. *(h->log_info.wmi_mgmt_command_log_buf_info. \
  202. p_buf_tail_idx) = 0; \
  203. ((struct wmi_command_debug *)h->log_info. \
  204. wmi_mgmt_command_log_buf_info.buf) \
  205. [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
  206. command = a; \
  207. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  208. wmi_mgmt_command_log_buf_info.buf) \
  209. [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
  210. data, b, \
  211. wmi_record_max_length); \
  212. ((struct wmi_command_debug *)h->log_info. \
  213. wmi_mgmt_command_log_buf_info.buf) \
  214. [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
  215. time = qdf_get_log_timestamp(); \
  216. (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
  217. h->log_info.wmi_mgmt_command_log_buf_info.length++; \
  218. }
  219. #define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
  220. if (wmi_mgmt_log_max_entry <= \
  221. *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  222. p_buf_tail_idx)) \
  223. *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  224. p_buf_tail_idx) = 0; \
  225. ((struct wmi_command_debug *)h->log_info. \
  226. wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
  227. [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  228. p_buf_tail_idx)].command = a; \
  229. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  230. wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
  231. [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  232. p_buf_tail_idx)].data, b, \
  233. wmi_record_max_length); \
  234. ((struct wmi_command_debug *)h->log_info. \
  235. wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
  236. [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  237. p_buf_tail_idx)].time = \
  238. qdf_get_log_timestamp(); \
  239. (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  240. p_buf_tail_idx))++; \
  241. h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
  242. }
  243. #define WMI_MGMT_EVENT_RECORD(h, a, b) { \
  244. if (wmi_mgmt_log_max_entry <= \
  245. *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
  246. *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
  247. ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
  248. [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
  249. .event = a; \
  250. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  251. wmi_mgmt_event_log_buf_info.buf) \
  252. [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
  253. data, b, wmi_record_max_length); \
  254. ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
  255. [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
  256. time = qdf_get_log_timestamp(); \
  257. (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
  258. h->log_info.wmi_mgmt_event_log_buf_info.length++; \
  259. }
  260. /* These are defined to made it as module param, which can be configured */
  261. uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
  262. uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  263. uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
  264. uint32_t wmi_display_size = 100;
  265. /**
  266. * wmi_log_init() - Initialize WMI event logging
  267. * @wmi_handle: WMI handle.
  268. *
  269. * Return: Initialization status
  270. */
  271. #ifdef CONFIG_MCL
  272. static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
  273. {
  274. struct wmi_log_buf_t *cmd_log_buf =
  275. &wmi_handle->log_info.wmi_command_log_buf_info;
  276. struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
  277. &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
  278. struct wmi_log_buf_t *event_log_buf =
  279. &wmi_handle->log_info.wmi_event_log_buf_info;
  280. struct wmi_log_buf_t *rx_event_log_buf =
  281. &wmi_handle->log_info.wmi_rx_event_log_buf_info;
  282. struct wmi_log_buf_t *mgmt_cmd_log_buf =
  283. &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
  284. struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
  285. &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
  286. struct wmi_log_buf_t *mgmt_event_log_buf =
  287. &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
  288. /* WMI commands */
  289. cmd_log_buf->length = 0;
  290. cmd_log_buf->buf_tail_idx = 0;
  291. cmd_log_buf->buf = wmi_command_log_buffer;
  292. cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
  293. cmd_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  294. /* WMI commands TX completed */
  295. cmd_tx_cmpl_log_buf->length = 0;
  296. cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
  297. cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
  298. cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
  299. cmd_tx_cmpl_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  300. /* WMI events when processed */
  301. event_log_buf->length = 0;
  302. event_log_buf->buf_tail_idx = 0;
  303. event_log_buf->buf = wmi_event_log_buffer;
  304. event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
  305. event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  306. /* WMI events when queued */
  307. rx_event_log_buf->length = 0;
  308. rx_event_log_buf->buf_tail_idx = 0;
  309. rx_event_log_buf->buf = wmi_rx_event_log_buffer;
  310. rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
  311. rx_event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  312. /* WMI Management commands */
  313. mgmt_cmd_log_buf->length = 0;
  314. mgmt_cmd_log_buf->buf_tail_idx = 0;
  315. mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
  316. mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
  317. mgmt_cmd_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  318. /* WMI Management commands Tx completed*/
  319. mgmt_cmd_tx_cmp_log_buf->length = 0;
  320. mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
  321. mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
  322. mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
  323. &g_wmi_mgmt_command_tx_cmp_buf_idx;
  324. mgmt_cmd_tx_cmp_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  325. /* WMI Management events when processed*/
  326. mgmt_event_log_buf->length = 0;
  327. mgmt_event_log_buf->buf_tail_idx = 0;
  328. mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer;
  329. mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx;
  330. mgmt_event_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  331. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  332. wmi_handle->log_info.wmi_logging_enable = 1;
  333. return QDF_STATUS_SUCCESS;
  334. }
  335. #else
  336. static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
  337. {
  338. struct wmi_log_buf_t *cmd_log_buf =
  339. &wmi_handle->log_info.wmi_command_log_buf_info;
  340. struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
  341. &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
  342. struct wmi_log_buf_t *event_log_buf =
  343. &wmi_handle->log_info.wmi_event_log_buf_info;
  344. struct wmi_log_buf_t *rx_event_log_buf =
  345. &wmi_handle->log_info.wmi_rx_event_log_buf_info;
  346. struct wmi_log_buf_t *mgmt_cmd_log_buf =
  347. &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
  348. struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
  349. &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
  350. struct wmi_log_buf_t *mgmt_event_log_buf =
  351. &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
  352. wmi_handle->log_info.wmi_logging_enable = 0;
  353. /* WMI commands */
  354. cmd_log_buf->length = 0;
  355. cmd_log_buf->buf_tail_idx = 0;
  356. cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
  357. wmi_log_max_entry * sizeof(struct wmi_command_debug));
  358. cmd_log_buf->size = wmi_log_max_entry;
  359. if (!cmd_log_buf->buf) {
  360. qdf_print("no memory for WMI command log buffer..\n");
  361. return QDF_STATUS_E_NOMEM;
  362. }
  363. cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
  364. /* WMI commands TX completed */
  365. cmd_tx_cmpl_log_buf->length = 0;
  366. cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
  367. cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
  368. wmi_log_max_entry * sizeof(struct wmi_command_debug));
  369. cmd_tx_cmpl_log_buf->size = wmi_log_max_entry;
  370. if (!cmd_tx_cmpl_log_buf->buf) {
  371. qdf_print("no memory for WMI Command Tx Complete log buffer..\n");
  372. return QDF_STATUS_E_NOMEM;
  373. }
  374. cmd_tx_cmpl_log_buf->p_buf_tail_idx =
  375. &cmd_tx_cmpl_log_buf->buf_tail_idx;
  376. /* WMI events when processed */
  377. event_log_buf->length = 0;
  378. event_log_buf->buf_tail_idx = 0;
  379. event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  380. wmi_log_max_entry * sizeof(struct wmi_event_debug));
  381. event_log_buf->size = wmi_log_max_entry;
  382. if (!event_log_buf->buf) {
  383. qdf_print("no memory for WMI Event log buffer..\n");
  384. return QDF_STATUS_E_NOMEM;
  385. }
  386. event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
  387. /* WMI events when queued */
  388. rx_event_log_buf->length = 0;
  389. rx_event_log_buf->buf_tail_idx = 0;
  390. rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  391. wmi_log_max_entry * sizeof(struct wmi_event_debug));
  392. rx_event_log_buf->size = wmi_log_max_entry;
  393. if (!rx_event_log_buf->buf) {
  394. qdf_print("no memory for WMI Event Rx log buffer..\n");
  395. return QDF_STATUS_E_NOMEM;
  396. }
  397. rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
  398. /* WMI Management commands */
  399. mgmt_cmd_log_buf->length = 0;
  400. mgmt_cmd_log_buf->buf_tail_idx = 0;
  401. mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
  402. wmi_mgmt_log_max_entry * sizeof(struct wmi_command_debug));
  403. mgmt_cmd_log_buf->size = wmi_mgmt_log_max_entry;
  404. if (!mgmt_cmd_log_buf->buf) {
  405. qdf_print("no memory for WMI Management Command log buffer..\n");
  406. return QDF_STATUS_E_NOMEM;
  407. }
  408. mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
  409. /* WMI Management commands Tx completed*/
  410. mgmt_cmd_tx_cmp_log_buf->length = 0;
  411. mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
  412. mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
  413. qdf_mem_malloc(
  414. wmi_mgmt_log_max_entry *
  415. sizeof(struct wmi_command_debug));
  416. mgmt_cmd_tx_cmp_log_buf->size = wmi_mgmt_log_max_entry;
  417. if (!mgmt_cmd_tx_cmp_log_buf->buf) {
  418. qdf_print("no memory for WMI Management Command Tx complete log buffer..\n");
  419. return QDF_STATUS_E_NOMEM;
  420. }
  421. mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
  422. &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
  423. /* WMI Management events when processed*/
  424. mgmt_event_log_buf->length = 0;
  425. mgmt_event_log_buf->buf_tail_idx = 0;
  426. mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  427. wmi_mgmt_log_max_entry *
  428. sizeof(struct wmi_event_debug));
  429. mgmt_event_log_buf->size = wmi_mgmt_log_max_entry;
  430. if (!mgmt_event_log_buf->buf) {
  431. qdf_print("no memory for WMI Management Event log buffer..\n");
  432. return QDF_STATUS_E_NOMEM;
  433. }
  434. mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
  435. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  436. wmi_handle->log_info.wmi_logging_enable = 1;
  437. return QDF_STATUS_SUCCESS;
  438. }
  439. #endif
  440. /**
  441. * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
  442. * event logging
  443. * @wmi_handle: WMI handle.
  444. *
  445. * Return: None
  446. */
  447. #ifndef CONFIG_MCL
  448. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
  449. {
  450. if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
  451. qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
  452. if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
  453. qdf_mem_free(
  454. wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
  455. if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
  456. qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
  457. if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
  458. qdf_mem_free(
  459. wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
  460. if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
  461. qdf_mem_free(
  462. wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
  463. if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
  464. qdf_mem_free(
  465. wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
  466. if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
  467. qdf_mem_free(
  468. wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
  469. wmi_handle->log_info.wmi_logging_enable = 0;
  470. qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
  471. }
  472. #else
  473. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
  474. {
  475. /* Do Nothing */
  476. }
  477. #endif
  478. /**
  479. * wmi_print_cmd_log_buffer() - an output agnostic wmi command log printer
  480. * @log_buffer: the command log buffer metadata of the buffer to print
  481. * @count: the maximum number of entries to print
  482. * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
  483. * @print_priv: any data required by the print method, e.g. a file handle
  484. *
  485. * Return: None
  486. */
  487. static void
  488. wmi_print_cmd_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
  489. qdf_abstract_print *print, void *print_priv)
  490. {
  491. static const int data_len =
  492. WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
  493. char str[128];
  494. uint32_t idx;
  495. if (count > log_buffer->size)
  496. count = log_buffer->size;
  497. if (count > log_buffer->length)
  498. count = log_buffer->length;
  499. /* subtract count from index, and wrap if necessary */
  500. idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
  501. idx %= log_buffer->size;
  502. print(print_priv, "Time (seconds) Cmd Id Payload");
  503. while (count) {
  504. struct wmi_command_debug *cmd_log = (struct wmi_command_debug *)
  505. &((struct wmi_command_debug *)log_buffer->buf)[idx];
  506. uint64_t secs, usecs;
  507. int len = 0;
  508. int i;
  509. qdf_log_timestamp_to_secs(cmd_log->time, &secs, &usecs);
  510. len += scnprintf(str + len, sizeof(str) - len,
  511. "% 8lld.%06lld %6u (0x%06x) ",
  512. secs, usecs,
  513. cmd_log->command, cmd_log->command);
  514. for (i = 0; i < data_len; ++i) {
  515. len += scnprintf(str + len, sizeof(str) - len,
  516. "0x%08x ", cmd_log->data[i]);
  517. }
  518. print(print_priv, str);
  519. --count;
  520. ++idx;
  521. if (idx >= log_buffer->size)
  522. idx = 0;
  523. }
  524. }
  525. /**
  526. * wmi_print_event_log_buffer() - an output agnostic wmi event log printer
  527. * @log_buffer: the event log buffer metadata of the buffer to print
  528. * @count: the maximum number of entries to print
  529. * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
  530. * @print_priv: any data required by the print method, e.g. a file handle
  531. *
  532. * Return: None
  533. */
  534. static void
  535. wmi_print_event_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
  536. qdf_abstract_print *print, void *print_priv)
  537. {
  538. static const int data_len =
  539. WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
  540. char str[128];
  541. uint32_t idx;
  542. if (count > log_buffer->size)
  543. count = log_buffer->size;
  544. if (count > log_buffer->length)
  545. count = log_buffer->length;
  546. /* subtract count from index, and wrap if necessary */
  547. idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
  548. idx %= log_buffer->size;
  549. print(print_priv, "Time (seconds) Event Id Payload");
  550. while (count) {
  551. struct wmi_event_debug *event_log = (struct wmi_event_debug *)
  552. &((struct wmi_event_debug *)log_buffer->buf)[idx];
  553. uint64_t secs, usecs;
  554. int len = 0;
  555. int i;
  556. qdf_log_timestamp_to_secs(event_log->time, &secs, &usecs);
  557. len += scnprintf(str + len, sizeof(str) - len,
  558. "% 8lld.%06lld %6u (0x%06x) ",
  559. secs, usecs,
  560. event_log->event, event_log->event);
  561. for (i = 0; i < data_len; ++i) {
  562. len += scnprintf(str + len, sizeof(str) - len,
  563. "0x%08x ", event_log->data[i]);
  564. }
  565. print(print_priv, str);
  566. --count;
  567. ++idx;
  568. if (idx >= log_buffer->size)
  569. idx = 0;
  570. }
  571. }
  572. inline void
  573. wmi_print_cmd_log(wmi_unified_t wmi, uint32_t count,
  574. qdf_abstract_print *print, void *print_priv)
  575. {
  576. wmi_print_cmd_log_buffer(
  577. &wmi->log_info.wmi_command_log_buf_info,
  578. count, print, print_priv);
  579. }
  580. inline void
  581. wmi_print_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
  582. qdf_abstract_print *print, void *print_priv)
  583. {
  584. wmi_print_cmd_log_buffer(
  585. &wmi->log_info.wmi_command_tx_cmp_log_buf_info,
  586. count, print, print_priv);
  587. }
  588. inline void
  589. wmi_print_mgmt_cmd_log(wmi_unified_t wmi, uint32_t count,
  590. qdf_abstract_print *print, void *print_priv)
  591. {
  592. wmi_print_cmd_log_buffer(
  593. &wmi->log_info.wmi_mgmt_command_log_buf_info,
  594. count, print, print_priv);
  595. }
  596. inline void
  597. wmi_print_mgmt_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
  598. qdf_abstract_print *print, void *print_priv)
  599. {
  600. wmi_print_cmd_log_buffer(
  601. &wmi->log_info.wmi_mgmt_command_tx_cmp_log_buf_info,
  602. count, print, print_priv);
  603. }
  604. inline void
  605. wmi_print_event_log(wmi_unified_t wmi, uint32_t count,
  606. qdf_abstract_print *print, void *print_priv)
  607. {
  608. wmi_print_event_log_buffer(
  609. &wmi->log_info.wmi_event_log_buf_info,
  610. count, print, print_priv);
  611. }
  612. inline void
  613. wmi_print_rx_event_log(wmi_unified_t wmi, uint32_t count,
  614. qdf_abstract_print *print, void *print_priv)
  615. {
  616. wmi_print_event_log_buffer(
  617. &wmi->log_info.wmi_rx_event_log_buf_info,
  618. count, print, print_priv);
  619. }
  620. inline void
  621. wmi_print_mgmt_event_log(wmi_unified_t wmi, uint32_t count,
  622. qdf_abstract_print *print, void *print_priv)
  623. {
  624. wmi_print_event_log_buffer(
  625. &wmi->log_info.wmi_mgmt_event_log_buf_info,
  626. count, print, print_priv);
  627. }
  628. #ifdef CONFIG_MCL
  629. const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0"};
  630. #else
  631. const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0", "WMI1", "WMI2"};
  632. #endif
  633. /* debugfs routines*/
  634. /**
  635. * debug_wmi_##func_base##_show() - debugfs functions to display content of
  636. * command and event buffers. Macro uses max buffer length to display
  637. * buffer when it is wraparound.
  638. *
  639. * @m: debugfs handler to access wmi_handle
  640. * @v: Variable arguments (not used)
  641. *
  642. * Return: Length of characters printed
  643. */
  644. #define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
  645. static int debug_wmi_##func_base##_show(struct seq_file *m, \
  646. void *v) \
  647. { \
  648. wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
  649. struct wmi_log_buf_t *wmi_log = \
  650. &wmi_handle->log_info.wmi_##func_base##_buf_info;\
  651. int pos, nread, outlen; \
  652. int i; \
  653. uint64_t secs, usecs; \
  654. \
  655. qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
  656. if (!wmi_log->length) { \
  657. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
  658. return wmi_bp_seq_printf(m, \
  659. "no elements to read from ring buffer!\n"); \
  660. } \
  661. \
  662. if (wmi_log->length <= wmi_ring_size) \
  663. nread = wmi_log->length; \
  664. else \
  665. nread = wmi_ring_size; \
  666. \
  667. if (*(wmi_log->p_buf_tail_idx) == 0) \
  668. /* tail can be 0 after wrap-around */ \
  669. pos = wmi_ring_size - 1; \
  670. else \
  671. pos = *(wmi_log->p_buf_tail_idx) - 1; \
  672. \
  673. outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
  674. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
  675. while (nread--) { \
  676. struct wmi_command_debug *wmi_record; \
  677. \
  678. wmi_record = (struct wmi_command_debug *) \
  679. &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
  680. outlen += wmi_bp_seq_printf(m, "CMD ID = %x\n", \
  681. (wmi_record->command)); \
  682. qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
  683. &usecs); \
  684. outlen += \
  685. wmi_bp_seq_printf(m, "CMD TIME = [%llu.%06llu]\n",\
  686. secs, usecs); \
  687. outlen += wmi_bp_seq_printf(m, "CMD = "); \
  688. for (i = 0; i < (wmi_record_max_length/ \
  689. sizeof(uint32_t)); i++) \
  690. outlen += wmi_bp_seq_printf(m, "%x ", \
  691. wmi_record->data[i]); \
  692. outlen += wmi_bp_seq_printf(m, "\n"); \
  693. \
  694. if (pos == 0) \
  695. pos = wmi_ring_size - 1; \
  696. else \
  697. pos--; \
  698. } \
  699. return outlen; \
  700. } \
  701. #define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
  702. static int debug_wmi_##func_base##_show(struct seq_file *m, \
  703. void *v) \
  704. { \
  705. wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
  706. struct wmi_log_buf_t *wmi_log = \
  707. &wmi_handle->log_info.wmi_##func_base##_buf_info;\
  708. int pos, nread, outlen; \
  709. int i; \
  710. uint64_t secs, usecs; \
  711. \
  712. qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
  713. if (!wmi_log->length) { \
  714. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
  715. return wmi_bp_seq_printf(m, \
  716. "no elements to read from ring buffer!\n"); \
  717. } \
  718. \
  719. if (wmi_log->length <= wmi_ring_size) \
  720. nread = wmi_log->length; \
  721. else \
  722. nread = wmi_ring_size; \
  723. \
  724. if (*(wmi_log->p_buf_tail_idx) == 0) \
  725. /* tail can be 0 after wrap-around */ \
  726. pos = wmi_ring_size - 1; \
  727. else \
  728. pos = *(wmi_log->p_buf_tail_idx) - 1; \
  729. \
  730. outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
  731. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
  732. while (nread--) { \
  733. struct wmi_event_debug *wmi_record; \
  734. \
  735. wmi_record = (struct wmi_event_debug *) \
  736. &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
  737. qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
  738. &usecs); \
  739. outlen += wmi_bp_seq_printf(m, "Event ID = %x\n",\
  740. (wmi_record->event)); \
  741. outlen += \
  742. wmi_bp_seq_printf(m, "Event TIME = [%llu.%06llu]\n",\
  743. secs, usecs); \
  744. outlen += wmi_bp_seq_printf(m, "CMD = "); \
  745. for (i = 0; i < (wmi_record_max_length/ \
  746. sizeof(uint32_t)); i++) \
  747. outlen += wmi_bp_seq_printf(m, "%x ", \
  748. wmi_record->data[i]); \
  749. outlen += wmi_bp_seq_printf(m, "\n"); \
  750. \
  751. if (pos == 0) \
  752. pos = wmi_ring_size - 1; \
  753. else \
  754. pos--; \
  755. } \
  756. return outlen; \
  757. }
  758. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
  759. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
  760. GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
  761. GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
  762. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
  763. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
  764. wmi_display_size);
  765. GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
  766. /**
  767. * debug_wmi_enable_show() - debugfs functions to display enable state of
  768. * wmi logging feature.
  769. *
  770. * @m: debugfs handler to access wmi_handle
  771. * @v: Variable arguments (not used)
  772. *
  773. * Return: always 1
  774. */
  775. static int debug_wmi_enable_show(struct seq_file *m, void *v)
  776. {
  777. wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
  778. return wmi_bp_seq_printf(m, "%d\n",
  779. wmi_handle->log_info.wmi_logging_enable);
  780. }
  781. /**
  782. * debug_wmi_log_size_show() - debugfs functions to display configured size of
  783. * wmi logging command/event buffer and management command/event buffer.
  784. *
  785. * @m: debugfs handler to access wmi_handle
  786. * @v: Variable arguments (not used)
  787. *
  788. * Return: Length of characters printed
  789. */
  790. static int debug_wmi_log_size_show(struct seq_file *m, void *v)
  791. {
  792. wmi_bp_seq_printf(m, "WMI command/event log max size:%d\n",
  793. wmi_log_max_entry);
  794. return wmi_bp_seq_printf(m,
  795. "WMI management command/events log max size:%d\n",
  796. wmi_mgmt_log_max_entry);
  797. }
  798. /**
  799. * debug_wmi_##func_base##_write() - debugfs functions to clear
  800. * wmi logging command/event buffer and management command/event buffer.
  801. *
  802. * @file: file handler to access wmi_handle
  803. * @buf: received data buffer
  804. * @count: length of received buffer
  805. * @ppos: Not used
  806. *
  807. * Return: count
  808. */
  809. #define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
  810. static ssize_t debug_wmi_##func_base##_write(struct file *file, \
  811. const char __user *buf, \
  812. size_t count, loff_t *ppos) \
  813. { \
  814. int k, ret; \
  815. wmi_unified_t wmi_handle = \
  816. ((struct seq_file *)file->private_data)->private;\
  817. struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
  818. wmi_##func_base##_buf_info; \
  819. char locbuf[50]; \
  820. \
  821. if ((!buf) || (count > 50)) \
  822. return -EFAULT; \
  823. \
  824. if (copy_from_user(locbuf, buf, count)) \
  825. return -EFAULT; \
  826. \
  827. ret = sscanf(locbuf, "%d", &k); \
  828. if ((ret != 1) || (k != 0)) { \
  829. qdf_print("Wrong input, echo 0 to clear the wmi buffer\n");\
  830. return -EINVAL; \
  831. } \
  832. \
  833. qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
  834. qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
  835. sizeof(struct wmi_record_type)); \
  836. wmi_log->length = 0; \
  837. *(wmi_log->p_buf_tail_idx) = 0; \
  838. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
  839. \
  840. return count; \
  841. }
  842. GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
  843. wmi_command_debug);
  844. GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
  845. wmi_command_debug);
  846. GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
  847. wmi_event_debug);
  848. GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
  849. wmi_event_debug);
  850. GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
  851. wmi_command_debug);
  852. GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
  853. wmi_mgmt_log_max_entry, wmi_command_debug);
  854. GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
  855. wmi_event_debug);
  856. /**
  857. * debug_wmi_enable_write() - debugfs functions to enable/disable
  858. * wmi logging feature.
  859. *
  860. * @file: file handler to access wmi_handle
  861. * @buf: received data buffer
  862. * @count: length of received buffer
  863. * @ppos: Not used
  864. *
  865. * Return: count
  866. */
  867. static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
  868. size_t count, loff_t *ppos)
  869. {
  870. wmi_unified_t wmi_handle =
  871. ((struct seq_file *)file->private_data)->private;
  872. int k, ret;
  873. char locbuf[50];
  874. if ((!buf) || (count > 50))
  875. return -EFAULT;
  876. if (copy_from_user(locbuf, buf, count))
  877. return -EFAULT;
  878. ret = sscanf(locbuf, "%d", &k);
  879. if ((ret != 1) || ((k != 0) && (k != 1)))
  880. return -EINVAL;
  881. wmi_handle->log_info.wmi_logging_enable = k;
  882. return count;
  883. }
  884. /**
  885. * debug_wmi_log_size_write() - reserved.
  886. *
  887. * @file: file handler to access wmi_handle
  888. * @buf: received data buffer
  889. * @count: length of received buffer
  890. * @ppos: Not used
  891. *
  892. * Return: count
  893. */
  894. static ssize_t debug_wmi_log_size_write(struct file *file,
  895. const char __user *buf, size_t count, loff_t *ppos)
  896. {
  897. return -EINVAL;
  898. }
  899. /* Structure to maintain debug information */
  900. struct wmi_debugfs_info {
  901. const char *name;
  902. struct dentry *de[MAX_WMI_INSTANCES];
  903. const struct file_operations *ops;
  904. };
  905. #define DEBUG_FOO(func_base) { .name = #func_base, \
  906. .ops = &debug_##func_base##_ops }
  907. /**
  908. * debug_##func_base##_open() - Open debugfs entry for respective command
  909. * and event buffer.
  910. *
  911. * @inode: node for debug dir entry
  912. * @file: file handler
  913. *
  914. * Return: open status
  915. */
  916. #define GENERATE_DEBUG_STRUCTS(func_base) \
  917. static int debug_##func_base##_open(struct inode *inode, \
  918. struct file *file) \
  919. { \
  920. return single_open(file, debug_##func_base##_show, \
  921. inode->i_private); \
  922. } \
  923. \
  924. \
  925. static struct file_operations debug_##func_base##_ops = { \
  926. .open = debug_##func_base##_open, \
  927. .read = seq_read, \
  928. .llseek = seq_lseek, \
  929. .write = debug_##func_base##_write, \
  930. .release = single_release, \
  931. };
  932. GENERATE_DEBUG_STRUCTS(wmi_command_log);
  933. GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
  934. GENERATE_DEBUG_STRUCTS(wmi_event_log);
  935. GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
  936. GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
  937. GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
  938. GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
  939. GENERATE_DEBUG_STRUCTS(wmi_enable);
  940. GENERATE_DEBUG_STRUCTS(wmi_log_size);
  941. struct wmi_debugfs_info wmi_debugfs_infos[] = {
  942. DEBUG_FOO(wmi_command_log),
  943. DEBUG_FOO(wmi_command_tx_cmp_log),
  944. DEBUG_FOO(wmi_event_log),
  945. DEBUG_FOO(wmi_rx_event_log),
  946. DEBUG_FOO(wmi_mgmt_command_log),
  947. DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
  948. DEBUG_FOO(wmi_mgmt_event_log),
  949. DEBUG_FOO(wmi_enable),
  950. DEBUG_FOO(wmi_log_size),
  951. };
  952. #define NUM_DEBUG_INFOS (sizeof(wmi_debugfs_infos) / \
  953. sizeof(wmi_debugfs_infos[0]))
  954. /**
  955. * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
  956. *
  957. * @wmi_handle: wmi handle
  958. * @par_entry: debug directory entry
  959. * @id: Index to debug info data array
  960. *
  961. * Return: none
  962. */
  963. static void wmi_debugfs_create(wmi_unified_t wmi_handle,
  964. struct dentry *par_entry, int id)
  965. {
  966. int i;
  967. if (par_entry == NULL || (id < 0) || (id >= MAX_WMI_INSTANCES))
  968. goto out;
  969. for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
  970. wmi_debugfs_infos[i].de[id] = debugfs_create_file(
  971. wmi_debugfs_infos[i].name, 0644, par_entry,
  972. wmi_handle, wmi_debugfs_infos[i].ops);
  973. if (wmi_debugfs_infos[i].de[id] == NULL) {
  974. qdf_print("%s: debug Entry creation failed!\n",
  975. __func__);
  976. goto out;
  977. }
  978. }
  979. return;
  980. out:
  981. qdf_print("%s: debug Entry creation failed!\n", __func__);
  982. wmi_log_buffer_free(wmi_handle);
  983. return;
  984. }
  985. /**
  986. * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
  987. * @wmi_handle: wmi handle
  988. * @dentry: debugfs directory entry
  989. * @id: Index to debug info data array
  990. *
  991. * Return: none
  992. */
  993. static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
  994. {
  995. int i;
  996. struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
  997. int id;
  998. if (!wmi_handle->log_info.wmi_instance_id)
  999. return;
  1000. id = wmi_handle->log_info.wmi_instance_id - 1;
  1001. if (dentry && (!(id < 0) || (id >= MAX_WMI_INSTANCES))) {
  1002. for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
  1003. if (wmi_debugfs_infos[i].de[id])
  1004. wmi_debugfs_infos[i].de[id] = NULL;
  1005. }
  1006. }
  1007. if (dentry)
  1008. debugfs_remove_recursive(dentry);
  1009. if (wmi_handle->log_info.wmi_instance_id)
  1010. wmi_handle->log_info.wmi_instance_id--;
  1011. }
  1012. /**
  1013. * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
  1014. * create debugfs enteries.
  1015. *
  1016. * @h: wmi handler
  1017. *
  1018. * Return: init status
  1019. */
  1020. static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle)
  1021. {
  1022. int wmi_index = wmi_handle->log_info.wmi_instance_id;
  1023. if (wmi_index < MAX_WMI_INSTANCES) {
  1024. wmi_handle->log_info.wmi_log_debugfs_dir =
  1025. debugfs_create_dir(debugfs_dir[wmi_index], NULL);
  1026. if (!wmi_handle->log_info.wmi_log_debugfs_dir) {
  1027. qdf_print("error while creating debugfs dir for %s\n",
  1028. debugfs_dir[wmi_index]);
  1029. return QDF_STATUS_E_FAILURE;
  1030. }
  1031. wmi_debugfs_create(wmi_handle,
  1032. wmi_handle->log_info.wmi_log_debugfs_dir,
  1033. wmi_index);
  1034. wmi_handle->log_info.wmi_instance_id++;
  1035. }
  1036. return QDF_STATUS_SUCCESS;
  1037. }
  1038. /**
  1039. * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
  1040. *
  1041. * @wmi_handle: wmi handle
  1042. * @cmd: mgmt command
  1043. * @header: pointer to 802.11 header
  1044. * @vdev_id: vdev id
  1045. * @chanfreq: channel frequency
  1046. *
  1047. * Return: none
  1048. */
  1049. void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
  1050. void *header, uint32_t vdev_id, uint32_t chanfreq)
  1051. {
  1052. uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
  1053. data[0] = ((struct wmi_command_header *)header)->type;
  1054. data[1] = ((struct wmi_command_header *)header)->sub_type;
  1055. data[2] = vdev_id;
  1056. data[3] = chanfreq;
  1057. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1058. WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, (uint8_t *)data);
  1059. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1060. }
  1061. #else
  1062. /**
  1063. * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
  1064. * @wmi_handle: wmi handle
  1065. * @dentry: debugfs directory entry
  1066. * @id: Index to debug info data array
  1067. *
  1068. * Return: none
  1069. */
  1070. static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
  1071. void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
  1072. void *header, uint32_t vdev_id, uint32_t chanfreq) { }
  1073. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
  1074. #endif /*WMI_INTERFACE_EVENT_LOGGING */
  1075. qdf_export_symbol(wmi_mgmt_cmd_record);
  1076. int wmi_get_host_credits(wmi_unified_t wmi_handle);
  1077. /* WMI buffer APIs */
  1078. #ifdef NBUF_MEMORY_DEBUG
  1079. wmi_buf_t
  1080. wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint16_t len, uint8_t *file_name,
  1081. uint32_t line_num)
  1082. {
  1083. wmi_buf_t wmi_buf;
  1084. if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
  1085. QDF_ASSERT(0);
  1086. return NULL;
  1087. }
  1088. wmi_buf = qdf_nbuf_alloc_debug(NULL,
  1089. roundup(len + WMI_MIN_HEAD_ROOM, 4),
  1090. WMI_MIN_HEAD_ROOM, 4, false, file_name,
  1091. line_num);
  1092. if (!wmi_buf)
  1093. return NULL;
  1094. /* Clear the wmi buffer */
  1095. OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
  1096. /*
  1097. * Set the length of the buffer to match the allocation size.
  1098. */
  1099. qdf_nbuf_set_pktlen(wmi_buf, len);
  1100. return wmi_buf;
  1101. }
  1102. qdf_export_symbol(wmi_buf_alloc_debug);
  1103. void wmi_buf_free(wmi_buf_t net_buf)
  1104. {
  1105. qdf_nbuf_free(net_buf);
  1106. }
  1107. qdf_export_symbol(wmi_buf_free);
  1108. #else
  1109. wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint16_t len)
  1110. {
  1111. wmi_buf_t wmi_buf;
  1112. if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
  1113. QDF_ASSERT(0);
  1114. return NULL;
  1115. }
  1116. wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
  1117. WMI_MIN_HEAD_ROOM, 4, false);
  1118. if (!wmi_buf)
  1119. return NULL;
  1120. /* Clear the wmi buffer */
  1121. OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
  1122. /*
  1123. * Set the length of the buffer to match the allocation size.
  1124. */
  1125. qdf_nbuf_set_pktlen(wmi_buf, len);
  1126. return wmi_buf;
  1127. }
  1128. qdf_export_symbol(wmi_buf_alloc);
  1129. void wmi_buf_free(wmi_buf_t net_buf)
  1130. {
  1131. qdf_nbuf_free(net_buf);
  1132. }
  1133. qdf_export_symbol(wmi_buf_free);
  1134. #endif
  1135. /**
  1136. * wmi_get_max_msg_len() - get maximum WMI message length
  1137. * @wmi_handle: WMI handle.
  1138. *
  1139. * This function returns the maximum WMI message length
  1140. *
  1141. * Return: maximum WMI message length
  1142. */
  1143. uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
  1144. {
  1145. return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
  1146. }
  1147. qdf_export_symbol(wmi_get_max_msg_len);
  1148. #ifndef WMI_CMD_STRINGS
  1149. static uint8_t *wmi_id_to_name(uint32_t wmi_command)
  1150. {
  1151. return "Invalid WMI cmd";
  1152. }
  1153. #endif
  1154. #ifdef CONFIG_MCL
  1155. static inline void wmi_log_cmd_id(uint32_t cmd_id, uint32_t tag)
  1156. {
  1157. WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
  1158. wmi_id_to_name(cmd_id), cmd_id, tag);
  1159. }
  1160. /**
  1161. * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
  1162. * @cmd_id: command to check
  1163. *
  1164. * Return: true if the command is part of the resume sequence.
  1165. */
  1166. static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
  1167. {
  1168. switch (cmd_id) {
  1169. case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
  1170. case WMI_PDEV_RESUME_CMDID:
  1171. return true;
  1172. default:
  1173. return false;
  1174. }
  1175. }
  1176. #else
  1177. static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
  1178. {
  1179. return false;
  1180. }
  1181. #endif
  1182. /**
  1183. * wmi_unified_cmd_send() - WMI command API
  1184. * @wmi_handle: handle to wmi
  1185. * @buf: wmi buf
  1186. * @len: wmi buffer length
  1187. * @cmd_id: wmi command id
  1188. *
  1189. * Note, it is NOT safe to access buf after calling this function!
  1190. *
  1191. * Return: 0 on success
  1192. */
  1193. QDF_STATUS wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf,
  1194. uint32_t len, uint32_t cmd_id)
  1195. {
  1196. HTC_PACKET *pkt;
  1197. QDF_STATUS status;
  1198. uint16_t htc_tag = 0;
  1199. if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
  1200. htc_tag =
  1201. (uint16_t)wmi_handle->ops->wmi_set_htc_tx_tag(
  1202. wmi_handle, buf, cmd_id);
  1203. } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
  1204. (!wmi_is_pm_resume_cmd(cmd_id))) {
  1205. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1206. "%s: Target is suspended", __func__);
  1207. QDF_ASSERT(0);
  1208. return QDF_STATUS_E_BUSY;
  1209. }
  1210. if (wmi_handle->wmi_stopinprogress) {
  1211. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1212. "WMI stop in progress\n");
  1213. return QDF_STATUS_E_INVAL;
  1214. }
  1215. #ifndef WMI_NON_TLV_SUPPORT
  1216. /* Do sanity check on the TLV parameter structure */
  1217. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  1218. void *buf_ptr = (void *)qdf_nbuf_data(buf);
  1219. if (wmi_handle->ops->wmi_check_command_params(NULL, buf_ptr, len, cmd_id)
  1220. != 0) {
  1221. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1222. "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
  1223. __func__, cmd_id);
  1224. return QDF_STATUS_E_INVAL;
  1225. }
  1226. }
  1227. #endif
  1228. if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
  1229. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1230. "%s, Failed to send cmd %x, no memory",
  1231. __func__, cmd_id);
  1232. return QDF_STATUS_E_NOMEM;
  1233. }
  1234. WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
  1235. qdf_atomic_inc(&wmi_handle->pending_cmds);
  1236. if (qdf_atomic_read(&wmi_handle->pending_cmds) >=
  1237. wmi_handle->wmi_max_cmds) {
  1238. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1239. "\n%s: hostcredits = %d", __func__,
  1240. wmi_get_host_credits(wmi_handle));
  1241. htc_dump_counter_info(wmi_handle->htc_handle);
  1242. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1243. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1244. "%s: MAX %d WMI Pending cmds reached.", __func__,
  1245. wmi_handle->wmi_max_cmds);
  1246. QDF_BUG(0);
  1247. return QDF_STATUS_E_BUSY;
  1248. }
  1249. pkt = qdf_mem_malloc(sizeof(*pkt));
  1250. if (!pkt) {
  1251. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1252. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1253. "%s, Failed to alloc htc packet %x, no memory",
  1254. __func__, cmd_id);
  1255. return QDF_STATUS_E_NOMEM;
  1256. }
  1257. SET_HTC_PACKET_INFO_TX(pkt,
  1258. NULL,
  1259. qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
  1260. wmi_handle->wmi_endpoint_id, htc_tag);
  1261. SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
  1262. #ifdef CONFIG_MCL
  1263. wmi_log_cmd_id(cmd_id, htc_tag);
  1264. #endif
  1265. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1266. if (wmi_handle->log_info.wmi_logging_enable) {
  1267. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1268. /*
  1269. * Record 16 bytes of WMI cmd data -
  1270. * exclude TLV and WMI headers
  1271. *
  1272. * WMI mgmt command already recorded in wmi_mgmt_cmd_record
  1273. */
  1274. if (wmi_handle->ops->is_management_record(cmd_id) == false) {
  1275. WMI_COMMAND_RECORD(wmi_handle, cmd_id,
  1276. qdf_nbuf_data(buf) +
  1277. wmi_handle->log_info.buf_offset_command);
  1278. }
  1279. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1280. }
  1281. #endif
  1282. status = htc_send_pkt(wmi_handle->htc_handle, pkt);
  1283. if (QDF_STATUS_SUCCESS != status) {
  1284. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1285. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1286. "%s %d, htc_send_pkt failed", __func__, __LINE__);
  1287. qdf_mem_free(pkt);
  1288. return status;
  1289. }
  1290. return QDF_STATUS_SUCCESS;
  1291. }
  1292. qdf_export_symbol(wmi_unified_cmd_send);
  1293. /**
  1294. * wmi_unified_get_event_handler_ix() - gives event handler's index
  1295. * @wmi_handle: handle to wmi
  1296. * @event_id: wmi event id
  1297. *
  1298. * Return: event handler's index
  1299. */
  1300. static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
  1301. uint32_t event_id)
  1302. {
  1303. uint32_t idx = 0;
  1304. int32_t invalid_idx = -1;
  1305. struct wmi_soc *soc = wmi_handle->soc;
  1306. for (idx = 0; (idx < soc->max_event_idx &&
  1307. idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
  1308. if (wmi_handle->event_id[idx] == event_id &&
  1309. wmi_handle->event_handler[idx] != NULL) {
  1310. return idx;
  1311. }
  1312. }
  1313. return invalid_idx;
  1314. }
  1315. /**
  1316. * wmi_unified_register_event() - register wmi event handler
  1317. * @wmi_handle: handle to wmi
  1318. * @event_id: wmi event id
  1319. * @handler_func: wmi event handler function
  1320. *
  1321. * Return: 0 on success
  1322. */
  1323. int wmi_unified_register_event(wmi_unified_t wmi_handle,
  1324. uint32_t event_id,
  1325. wmi_unified_event_handler handler_func)
  1326. {
  1327. uint32_t idx = 0;
  1328. uint32_t evt_id;
  1329. struct wmi_soc *soc = wmi_handle->soc;
  1330. if (event_id >= wmi_events_max ||
  1331. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1332. qdf_print("%s: Event id %d is unavailable\n",
  1333. __func__, event_id);
  1334. return QDF_STATUS_E_FAILURE;
  1335. }
  1336. evt_id = wmi_handle->wmi_events[event_id];
  1337. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1338. qdf_print("%s : event handler already registered 0x%x\n",
  1339. __func__, evt_id);
  1340. return QDF_STATUS_E_FAILURE;
  1341. }
  1342. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1343. qdf_print("%s : no more event handlers 0x%x\n",
  1344. __func__, evt_id);
  1345. return QDF_STATUS_E_FAILURE;
  1346. }
  1347. idx = soc->max_event_idx;
  1348. wmi_handle->event_handler[idx] = handler_func;
  1349. wmi_handle->event_id[idx] = evt_id;
  1350. qdf_spin_lock_bh(&soc->ctx_lock);
  1351. wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
  1352. qdf_spin_unlock_bh(&soc->ctx_lock);
  1353. soc->max_event_idx++;
  1354. return 0;
  1355. }
  1356. /**
  1357. * wmi_unified_register_event_handler() - register wmi event handler
  1358. * @wmi_handle: handle to wmi
  1359. * @event_id: wmi event id
  1360. * @handler_func: wmi event handler function
  1361. * @rx_ctx: rx execution context for wmi rx events
  1362. *
  1363. * This API is to support legacy requirements. Will be deprecated in future.
  1364. * Return: 0 on success
  1365. */
  1366. int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
  1367. wmi_conv_event_id event_id,
  1368. wmi_unified_event_handler handler_func,
  1369. uint8_t rx_ctx)
  1370. {
  1371. uint32_t idx = 0;
  1372. uint32_t evt_id;
  1373. struct wmi_soc *soc = wmi_handle->soc;
  1374. if (event_id >= wmi_events_max ||
  1375. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1376. qdf_print("%s: Event id %d is unavailable\n",
  1377. __func__, event_id);
  1378. return QDF_STATUS_E_FAILURE;
  1379. }
  1380. evt_id = wmi_handle->wmi_events[event_id];
  1381. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1382. qdf_print("%s : event handler already registered 0x%x\n",
  1383. __func__, evt_id);
  1384. return QDF_STATUS_E_FAILURE;
  1385. }
  1386. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1387. qdf_print("%s : no more event handlers 0x%x\n",
  1388. __func__, evt_id);
  1389. return QDF_STATUS_E_FAILURE;
  1390. }
  1391. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
  1392. "Registered event handler for event 0x%8x\n", evt_id);
  1393. idx = soc->max_event_idx;
  1394. wmi_handle->event_handler[idx] = handler_func;
  1395. wmi_handle->event_id[idx] = evt_id;
  1396. qdf_spin_lock_bh(&soc->ctx_lock);
  1397. wmi_handle->ctx[idx] = rx_ctx;
  1398. qdf_spin_unlock_bh(&soc->ctx_lock);
  1399. soc->max_event_idx++;
  1400. return 0;
  1401. }
  1402. qdf_export_symbol(wmi_unified_register_event_handler);
  1403. /**
  1404. * wmi_unified_unregister_event() - unregister wmi event handler
  1405. * @wmi_handle: handle to wmi
  1406. * @event_id: wmi event id
  1407. *
  1408. * Return: 0 on success
  1409. */
  1410. int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
  1411. uint32_t event_id)
  1412. {
  1413. uint32_t idx = 0;
  1414. uint32_t evt_id;
  1415. struct wmi_soc *soc = wmi_handle->soc;
  1416. if (event_id >= wmi_events_max ||
  1417. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1418. qdf_print("%s: Event id %d is unavailable\n",
  1419. __func__, event_id);
  1420. return QDF_STATUS_E_FAILURE;
  1421. }
  1422. evt_id = wmi_handle->wmi_events[event_id];
  1423. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1424. if (idx == -1) {
  1425. qdf_print("%s : event handler is not registered: evt id 0x%x\n",
  1426. __func__, evt_id);
  1427. return QDF_STATUS_E_FAILURE;
  1428. }
  1429. wmi_handle->event_handler[idx] = NULL;
  1430. wmi_handle->event_id[idx] = 0;
  1431. --soc->max_event_idx;
  1432. wmi_handle->event_handler[idx] =
  1433. wmi_handle->event_handler[soc->max_event_idx];
  1434. wmi_handle->event_id[idx] =
  1435. wmi_handle->event_id[soc->max_event_idx];
  1436. return 0;
  1437. }
  1438. /**
  1439. * wmi_unified_unregister_event_handler() - unregister wmi event handler
  1440. * @wmi_handle: handle to wmi
  1441. * @event_id: wmi event id
  1442. *
  1443. * Return: 0 on success
  1444. */
  1445. int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
  1446. wmi_conv_event_id event_id)
  1447. {
  1448. uint32_t idx = 0;
  1449. uint32_t evt_id;
  1450. struct wmi_soc *soc = wmi_handle->soc;
  1451. if (event_id >= wmi_events_max ||
  1452. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1453. qdf_print("%s: Event id %d is unavailable\n",
  1454. __func__, event_id);
  1455. return QDF_STATUS_E_FAILURE;
  1456. }
  1457. evt_id = wmi_handle->wmi_events[event_id];
  1458. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1459. if (idx == -1) {
  1460. qdf_print("%s : event handler is not registered: evt id 0x%x\n",
  1461. __func__, evt_id);
  1462. return QDF_STATUS_E_FAILURE;
  1463. }
  1464. wmi_handle->event_handler[idx] = NULL;
  1465. wmi_handle->event_id[idx] = 0;
  1466. --soc->max_event_idx;
  1467. wmi_handle->event_handler[idx] =
  1468. wmi_handle->event_handler[soc->max_event_idx];
  1469. wmi_handle->event_id[idx] =
  1470. wmi_handle->event_id[soc->max_event_idx];
  1471. return 0;
  1472. }
  1473. qdf_export_symbol(wmi_unified_unregister_event_handler);
  1474. /**
  1475. * wmi_process_fw_event_default_ctx() - process in default caller context
  1476. * @wmi_handle: handle to wmi
  1477. * @htc_packet: pointer to htc packet
  1478. * @exec_ctx: execution context for wmi fw event
  1479. *
  1480. * Event process by below function will be in default caller context.
  1481. * wmi internally provides rx work thread processing context.
  1482. *
  1483. * Return: none
  1484. */
  1485. static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
  1486. HTC_PACKET *htc_packet, uint8_t exec_ctx)
  1487. {
  1488. wmi_buf_t evt_buf;
  1489. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1490. #ifndef CONFIG_MCL
  1491. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
  1492. (wmi_handle->scn_handle, evt_buf, exec_ctx);
  1493. #else
  1494. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
  1495. evt_buf, exec_ctx);
  1496. #endif
  1497. return;
  1498. }
  1499. /**
  1500. * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
  1501. * @wmi_handle: handle to wmi
  1502. * @htc_packet: pointer to htc packet
  1503. *
  1504. * Event process by below function will be in worker thread context.
  1505. * Use this method for events which are not critical and not
  1506. * handled in protocol stack.
  1507. *
  1508. * Return: none
  1509. */
  1510. static void wmi_process_fw_event_worker_thread_ctx
  1511. (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet)
  1512. {
  1513. wmi_buf_t evt_buf;
  1514. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1515. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  1516. qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
  1517. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  1518. qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
  1519. &wmi_handle->rx_event_work);
  1520. return;
  1521. }
  1522. /**
  1523. * wmi_get_pdev_ep: Get wmi handle based on endpoint
  1524. * @soc: handle to wmi soc
  1525. * @ep: endpoint id
  1526. *
  1527. * Return: none
  1528. */
  1529. static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
  1530. HTC_ENDPOINT_ID ep)
  1531. {
  1532. uint32_t i;
  1533. for (i = 0; i < WMI_MAX_RADIOS; i++)
  1534. if (soc->wmi_endpoint_id[i] == ep)
  1535. break;
  1536. if (i == WMI_MAX_RADIOS)
  1537. return NULL;
  1538. return soc->wmi_pdev[i];
  1539. }
  1540. /**
  1541. * wmi_control_rx() - process fw events callbacks
  1542. * @ctx: handle to wmi
  1543. * @htc_packet: pointer to htc packet
  1544. *
  1545. * Return: none
  1546. */
  1547. static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
  1548. {
  1549. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  1550. struct wmi_unified *wmi_handle;
  1551. wmi_buf_t evt_buf;
  1552. uint32_t id;
  1553. uint32_t idx = 0;
  1554. enum wmi_rx_exec_ctx exec_ctx;
  1555. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1556. wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
  1557. if (wmi_handle == NULL) {
  1558. qdf_print
  1559. ("%s :unable to get wmi_handle to Endpoint %d\n",
  1560. __func__, htc_packet->Endpoint);
  1561. qdf_nbuf_free(evt_buf);
  1562. return;
  1563. }
  1564. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  1565. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  1566. if (qdf_unlikely(idx == A_ERROR)) {
  1567. WMI_LOGD("%s :event handler is not registered: event id 0x%x\n",
  1568. __func__, id);
  1569. qdf_nbuf_free(evt_buf);
  1570. return;
  1571. }
  1572. qdf_spin_lock_bh(&soc->ctx_lock);
  1573. exec_ctx = wmi_handle->ctx[idx];
  1574. qdf_spin_unlock_bh(&soc->ctx_lock);
  1575. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1576. if (wmi_handle->log_info.wmi_logging_enable) {
  1577. uint8_t *data;
  1578. data = qdf_nbuf_data(evt_buf);
  1579. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1580. /* Exclude 4 bytes of TLV header */
  1581. WMI_RX_EVENT_RECORD(wmi_handle, id, data +
  1582. wmi_handle->log_info.buf_offset_event);
  1583. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1584. }
  1585. #endif
  1586. if (exec_ctx == WMI_RX_WORK_CTX) {
  1587. wmi_process_fw_event_worker_thread_ctx
  1588. (wmi_handle, htc_packet);
  1589. } else if (exec_ctx > WMI_RX_WORK_CTX) {
  1590. wmi_process_fw_event_default_ctx
  1591. (wmi_handle, htc_packet, exec_ctx);
  1592. } else {
  1593. qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
  1594. qdf_nbuf_free(evt_buf);
  1595. }
  1596. }
  1597. /**
  1598. * wmi_process_fw_event() - process any fw event
  1599. * @wmi_handle: wmi handle
  1600. * @evt_buf: fw event buffer
  1601. *
  1602. * This function process fw event in caller context
  1603. *
  1604. * Return: none
  1605. */
  1606. void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  1607. {
  1608. __wmi_control_rx(wmi_handle, evt_buf);
  1609. }
  1610. /**
  1611. * __wmi_control_rx() - process serialize wmi event callback
  1612. * @wmi_handle: wmi handle
  1613. * @evt_buf: fw event buffer
  1614. *
  1615. * Return: none
  1616. */
  1617. void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  1618. {
  1619. uint32_t id;
  1620. uint8_t *data;
  1621. uint32_t len;
  1622. void *wmi_cmd_struct_ptr = NULL;
  1623. #ifndef WMI_NON_TLV_SUPPORT
  1624. int tlv_ok_status = 0;
  1625. #endif
  1626. uint32_t idx = 0;
  1627. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  1628. if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
  1629. goto end;
  1630. data = qdf_nbuf_data(evt_buf);
  1631. len = qdf_nbuf_len(evt_buf);
  1632. #ifndef WMI_NON_TLV_SUPPORT
  1633. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  1634. /* Validate and pad(if necessary) the TLVs */
  1635. tlv_ok_status =
  1636. wmi_handle->ops->wmi_check_and_pad_event(wmi_handle->scn_handle,
  1637. data, len, id,
  1638. &wmi_cmd_struct_ptr);
  1639. if (tlv_ok_status != 0) {
  1640. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1641. "%s: Error: id=0x%d, wmitlv check status=%d\n",
  1642. __func__, id, tlv_ok_status);
  1643. goto end;
  1644. }
  1645. }
  1646. #endif
  1647. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  1648. if (idx == A_ERROR) {
  1649. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1650. "%s : event handler is not registered: event id 0x%x\n",
  1651. __func__, id);
  1652. goto end;
  1653. }
  1654. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1655. if (wmi_handle->log_info.wmi_logging_enable) {
  1656. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1657. /* Exclude 4 bytes of TLV header */
  1658. if (wmi_handle->ops->is_management_record(id)) {
  1659. WMI_MGMT_EVENT_RECORD(wmi_handle, id, data
  1660. + wmi_handle->log_info.buf_offset_event);
  1661. } else {
  1662. WMI_EVENT_RECORD(wmi_handle, id, data +
  1663. wmi_handle->log_info.buf_offset_event);
  1664. }
  1665. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1666. }
  1667. #endif
  1668. /* Call the WMI registered event handler */
  1669. if (wmi_handle->target_type == WMI_TLV_TARGET)
  1670. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  1671. wmi_cmd_struct_ptr, len);
  1672. else
  1673. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  1674. data, len);
  1675. end:
  1676. /* Free event buffer and allocated event tlv */
  1677. #ifndef WMI_NON_TLV_SUPPORT
  1678. if (wmi_handle->target_type == WMI_TLV_TARGET)
  1679. wmi_handle->ops->wmi_free_allocated_event(id, &wmi_cmd_struct_ptr);
  1680. #endif
  1681. qdf_nbuf_free(evt_buf);
  1682. }
  1683. #define WMI_WQ_WD_TIMEOUT (30 * 1000) /* 30s */
  1684. static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id)
  1685. {
  1686. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  1687. "%s: WLAN_BUG_RCA: Message type %x has exceeded its alloted time of %ds",
  1688. __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000);
  1689. }
  1690. #ifdef CONFIG_SLUB_DEBUG_ON
  1691. static void wmi_workqueue_watchdog_bite(void *arg)
  1692. {
  1693. struct wmi_wq_dbg_info *info = arg;
  1694. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  1695. qdf_print_thread_trace(info->task);
  1696. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  1697. "%s: Going down for WMI WQ Watchdog Bite!", __func__);
  1698. QDF_BUG(0);
  1699. }
  1700. #else
  1701. static inline void wmi_workqueue_watchdog_bite(void *arg)
  1702. {
  1703. struct wmi_wq_dbg_info *info = arg;
  1704. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  1705. }
  1706. #endif
  1707. /**
  1708. * wmi_rx_event_work() - process rx event in rx work queue context
  1709. * @arg: opaque pointer to wmi handle
  1710. *
  1711. * This function process any fw event to serialize it through rx worker thread.
  1712. *
  1713. * Return: none
  1714. */
  1715. static void wmi_rx_event_work(void *arg)
  1716. {
  1717. wmi_buf_t buf;
  1718. struct wmi_unified *wmi = arg;
  1719. qdf_timer_t wd_timer;
  1720. struct wmi_wq_dbg_info info;
  1721. /* initialize WMI workqueue watchdog timer */
  1722. qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite,
  1723. &info, QDF_TIMER_TYPE_SW);
  1724. qdf_spin_lock_bh(&wmi->eventq_lock);
  1725. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  1726. qdf_spin_unlock_bh(&wmi->eventq_lock);
  1727. while (buf) {
  1728. qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT);
  1729. info.wd_msg_type_id =
  1730. WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID);
  1731. info.wmi_wq = wmi->wmi_rx_work_queue;
  1732. info.task = qdf_get_current_task();
  1733. __wmi_control_rx(wmi, buf);
  1734. qdf_timer_stop(&wd_timer);
  1735. qdf_spin_lock_bh(&wmi->eventq_lock);
  1736. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  1737. qdf_spin_unlock_bh(&wmi->eventq_lock);
  1738. }
  1739. qdf_timer_free(&wd_timer);
  1740. }
  1741. #ifdef FEATURE_RUNTIME_PM
  1742. /**
  1743. * wmi_runtime_pm_init() - initialize runtime pm wmi variables
  1744. * @wmi_handle: wmi context
  1745. */
  1746. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  1747. {
  1748. qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
  1749. }
  1750. /**
  1751. * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
  1752. * @wmi_handle: wmi context
  1753. * @val: runtime pm progress flag
  1754. */
  1755. void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
  1756. {
  1757. qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
  1758. }
  1759. /**
  1760. * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
  1761. * @wmi_handle: wmi context
  1762. */
  1763. inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
  1764. {
  1765. return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
  1766. }
  1767. #else
  1768. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  1769. {
  1770. }
  1771. #endif
  1772. /**
  1773. * wmi_unified_get_soc_handle: Get WMI SoC handle
  1774. * @param wmi_handle: WMI context got from wmi_attach
  1775. *
  1776. * return: Pointer to Soc handle
  1777. */
  1778. void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
  1779. {
  1780. return wmi_handle->soc;
  1781. }
  1782. /**
  1783. * wmi_interface_logging_init: Interface looging init
  1784. * @param wmi_handle: Pointer to wmi handle object
  1785. *
  1786. * return: None
  1787. */
  1788. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1789. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
  1790. {
  1791. if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
  1792. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  1793. wmi_debugfs_init(wmi_handle);
  1794. }
  1795. }
  1796. #else
  1797. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
  1798. {
  1799. }
  1800. #endif
  1801. /**
  1802. * wmi_target_params_init: Target specific params init
  1803. * @param wmi_soc: Pointer to wmi soc object
  1804. * @param wmi_handle: Pointer to wmi handle object
  1805. *
  1806. * return: None
  1807. */
  1808. #ifndef CONFIG_MCL
  1809. static inline void wmi_target_params_init(struct wmi_soc *soc,
  1810. struct wmi_unified *wmi_handle)
  1811. {
  1812. wmi_handle->pdev_param = soc->pdev_param;
  1813. wmi_handle->vdev_param = soc->vdev_param;
  1814. wmi_handle->services = soc->services;
  1815. }
  1816. #else
  1817. static inline void wmi_target_params_init(struct wmi_soc *soc,
  1818. struct wmi_unified *wmi_handle)
  1819. {
  1820. wmi_handle->services = soc->services;
  1821. }
  1822. #endif
  1823. /**
  1824. * wmi_unified_get_pdev_handle: Get WMI SoC handle
  1825. * @param wmi_soc: Pointer to wmi soc object
  1826. * @param pdev_idx: pdev index
  1827. *
  1828. * return: Pointer to wmi handle or NULL on failure
  1829. */
  1830. void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
  1831. {
  1832. struct wmi_unified *wmi_handle;
  1833. if (pdev_idx >= WMI_MAX_RADIOS)
  1834. return NULL;
  1835. if (soc->wmi_pdev[pdev_idx] == NULL) {
  1836. wmi_handle =
  1837. (struct wmi_unified *) qdf_mem_malloc(
  1838. sizeof(struct wmi_unified));
  1839. if (wmi_handle == NULL) {
  1840. qdf_print("allocation of wmi handle failed %zu\n",
  1841. sizeof(struct wmi_unified));
  1842. return NULL;
  1843. }
  1844. wmi_handle->scn_handle = soc->scn_handle;
  1845. wmi_handle->event_id = soc->event_id;
  1846. wmi_handle->event_handler = soc->event_handler;
  1847. wmi_handle->ctx = soc->ctx;
  1848. wmi_handle->ops = soc->ops;
  1849. qdf_spinlock_create(&wmi_handle->eventq_lock);
  1850. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  1851. qdf_create_work(0, &wmi_handle->rx_event_work,
  1852. wmi_rx_event_work, wmi_handle);
  1853. wmi_handle->wmi_rx_work_queue =
  1854. qdf_create_workqueue("wmi_rx_event_work_queue");
  1855. if (NULL == wmi_handle->wmi_rx_work_queue) {
  1856. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  1857. goto error;
  1858. }
  1859. wmi_handle->wmi_events = soc->wmi_events;
  1860. wmi_target_params_init(soc, wmi_handle);
  1861. wmi_interface_logging_init(wmi_handle);
  1862. qdf_atomic_init(&wmi_handle->pending_cmds);
  1863. qdf_atomic_init(&wmi_handle->is_target_suspended);
  1864. wmi_handle->target_type = soc->target_type;
  1865. wmi_handle->wmi_max_cmds = soc->wmi_max_cmds;
  1866. wmi_handle->soc = soc;
  1867. soc->wmi_pdev[pdev_idx] = wmi_handle;
  1868. } else
  1869. wmi_handle = soc->wmi_pdev[pdev_idx];
  1870. wmi_handle->wmi_stopinprogress = 0;
  1871. wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
  1872. wmi_handle->htc_handle = soc->htc_handle;
  1873. wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
  1874. return wmi_handle;
  1875. error:
  1876. qdf_mem_free(wmi_handle);
  1877. return NULL;
  1878. }
  1879. qdf_export_symbol(wmi_unified_get_pdev_handle);
  1880. static void (*wmi_attach_register[WMI_MAX_TARGET_TYPE])(wmi_unified_t);
  1881. void wmi_unified_register_module(enum wmi_target_type target_type,
  1882. void (*wmi_attach)(wmi_unified_t wmi_handle))
  1883. {
  1884. if (target_type < WMI_MAX_TARGET_TYPE)
  1885. wmi_attach_register[target_type] = wmi_attach;
  1886. return;
  1887. }
  1888. qdf_export_symbol(wmi_unified_register_module);
  1889. /**
  1890. * wmi_unified_attach() - attach for unified WMI
  1891. * @scn_handle: handle to SCN
  1892. * @osdev: OS device context
  1893. * @target_type: TLV or not-TLV based target
  1894. * @use_cookie: cookie based allocation enabled/disabled
  1895. * @ops: umac rx callbacks
  1896. * @psoc: objmgr psoc
  1897. *
  1898. * @Return: wmi handle.
  1899. */
  1900. void *wmi_unified_attach(void *scn_handle,
  1901. struct wmi_unified_attach_params *param)
  1902. {
  1903. struct wmi_unified *wmi_handle;
  1904. struct wmi_soc *soc;
  1905. soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
  1906. if (soc == NULL) {
  1907. qdf_print("Allocation of wmi_soc failed %zu\n",
  1908. sizeof(struct wmi_soc));
  1909. return NULL;
  1910. }
  1911. wmi_handle =
  1912. (struct wmi_unified *) qdf_mem_malloc(
  1913. sizeof(struct wmi_unified));
  1914. if (wmi_handle == NULL) {
  1915. qdf_mem_free(soc);
  1916. qdf_print("allocation of wmi handle failed %zu\n",
  1917. sizeof(struct wmi_unified));
  1918. return NULL;
  1919. }
  1920. wmi_handle->soc = soc;
  1921. wmi_handle->event_id = soc->event_id;
  1922. wmi_handle->event_handler = soc->event_handler;
  1923. wmi_handle->ctx = soc->ctx;
  1924. wmi_handle->wmi_events = soc->wmi_events;
  1925. wmi_target_params_init(soc, wmi_handle);
  1926. wmi_handle->scn_handle = scn_handle;
  1927. soc->scn_handle = scn_handle;
  1928. qdf_atomic_init(&wmi_handle->pending_cmds);
  1929. qdf_atomic_init(&wmi_handle->is_target_suspended);
  1930. wmi_runtime_pm_init(wmi_handle);
  1931. qdf_spinlock_create(&wmi_handle->eventq_lock);
  1932. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  1933. qdf_create_work(0, &wmi_handle->rx_event_work,
  1934. wmi_rx_event_work, wmi_handle);
  1935. wmi_handle->wmi_rx_work_queue =
  1936. qdf_create_workqueue("wmi_rx_event_work_queue");
  1937. if (NULL == wmi_handle->wmi_rx_work_queue) {
  1938. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  1939. goto error;
  1940. }
  1941. wmi_interface_logging_init(wmi_handle);
  1942. /* Attach mc_thread context processing function */
  1943. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
  1944. param->rx_ops->wma_process_fw_event_handler_cbk;
  1945. wmi_handle->target_type = param->target_type;
  1946. soc->target_type = param->target_type;
  1947. if (param->target_type >= WMI_MAX_TARGET_TYPE)
  1948. goto error;
  1949. if (wmi_attach_register[param->target_type]) {
  1950. wmi_attach_register[param->target_type](wmi_handle);
  1951. } else {
  1952. WMI_LOGE("wmi attach is not registered");
  1953. goto error;
  1954. }
  1955. /* Assign target cookie capablity */
  1956. wmi_handle->use_cookie = param->use_cookie;
  1957. wmi_handle->osdev = param->osdev;
  1958. wmi_handle->wmi_stopinprogress = 0;
  1959. wmi_handle->wmi_max_cmds = param->max_commands;
  1960. soc->wmi_max_cmds = param->max_commands;
  1961. /* Increase the ref count once refcount infra is present */
  1962. soc->wmi_psoc = param->psoc;
  1963. qdf_spinlock_create(&soc->ctx_lock);
  1964. soc->ops = wmi_handle->ops;
  1965. soc->wmi_pdev[0] = wmi_handle;
  1966. return wmi_handle;
  1967. error:
  1968. qdf_mem_free(soc);
  1969. qdf_mem_free(wmi_handle);
  1970. return NULL;
  1971. }
  1972. /**
  1973. * wmi_unified_detach() - detach for unified WMI
  1974. *
  1975. * @wmi_handle : handle to wmi.
  1976. *
  1977. * @Return: none.
  1978. */
  1979. void wmi_unified_detach(struct wmi_unified *wmi_handle)
  1980. {
  1981. wmi_buf_t buf;
  1982. struct wmi_soc *soc;
  1983. uint8_t i;
  1984. soc = wmi_handle->soc;
  1985. for (i = 0; i < WMI_MAX_RADIOS; i++) {
  1986. if (soc->wmi_pdev[i]) {
  1987. qdf_flush_workqueue(0,
  1988. soc->wmi_pdev[i]->wmi_rx_work_queue);
  1989. qdf_destroy_workqueue(0,
  1990. soc->wmi_pdev[i]->wmi_rx_work_queue);
  1991. wmi_debugfs_remove(soc->wmi_pdev[i]);
  1992. buf = qdf_nbuf_queue_remove(
  1993. &soc->wmi_pdev[i]->event_queue);
  1994. while (buf) {
  1995. qdf_nbuf_free(buf);
  1996. buf = qdf_nbuf_queue_remove(
  1997. &soc->wmi_pdev[i]->event_queue);
  1998. }
  1999. wmi_log_buffer_free(soc->wmi_pdev[i]);
  2000. /* Free events logs list */
  2001. if (soc->wmi_pdev[i]->events_logs_list)
  2002. qdf_mem_free(
  2003. soc->wmi_pdev[i]->events_logs_list);
  2004. qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
  2005. qdf_mem_free(soc->wmi_pdev[i]);
  2006. }
  2007. }
  2008. qdf_spinlock_destroy(&soc->ctx_lock);
  2009. if (soc->wmi_service_bitmap) {
  2010. qdf_mem_free(soc->wmi_service_bitmap);
  2011. soc->wmi_service_bitmap = NULL;
  2012. }
  2013. if (soc->wmi_ext_service_bitmap) {
  2014. qdf_mem_free(soc->wmi_ext_service_bitmap);
  2015. soc->wmi_ext_service_bitmap = NULL;
  2016. }
  2017. /* Decrease the ref count once refcount infra is present */
  2018. soc->wmi_psoc = NULL;
  2019. qdf_mem_free(soc);
  2020. }
  2021. /**
  2022. * wmi_unified_remove_work() - detach for WMI work
  2023. * @wmi_handle: handle to WMI
  2024. *
  2025. * A function that does not fully detach WMI, but just remove work
  2026. * queue items associated with it. This is used to make sure that
  2027. * before any other processing code that may destroy related contexts
  2028. * (HTC, etc), work queue processing on WMI has already been stopped.
  2029. *
  2030. * Return: None
  2031. */
  2032. void
  2033. wmi_unified_remove_work(struct wmi_unified *wmi_handle)
  2034. {
  2035. wmi_buf_t buf;
  2036. qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
  2037. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  2038. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2039. while (buf) {
  2040. qdf_nbuf_free(buf);
  2041. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2042. }
  2043. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  2044. }
  2045. /**
  2046. * wmi_htc_tx_complete() - Process htc tx completion
  2047. *
  2048. * @ctx: handle to wmi
  2049. * @htc_packet: pointer to htc packet
  2050. *
  2051. * @Return: none.
  2052. */
  2053. static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
  2054. {
  2055. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  2056. wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
  2057. u_int8_t *buf_ptr;
  2058. u_int32_t len;
  2059. struct wmi_unified *wmi_handle;
  2060. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2061. uint32_t cmd_id;
  2062. #endif
  2063. ASSERT(wmi_cmd_buf);
  2064. wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
  2065. if (wmi_handle == NULL) {
  2066. WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
  2067. QDF_ASSERT(0);
  2068. return;
  2069. }
  2070. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2071. if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
  2072. cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
  2073. WMI_CMD_HDR, COMMANDID);
  2074. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  2075. /* Record 16 bytes of WMI cmd tx complete data
  2076. - exclude TLV and WMI headers */
  2077. if (wmi_handle->ops->is_management_record(cmd_id)) {
  2078. WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2079. qdf_nbuf_data(wmi_cmd_buf) +
  2080. wmi_handle->log_info.buf_offset_command);
  2081. } else {
  2082. WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2083. qdf_nbuf_data(wmi_cmd_buf) +
  2084. wmi_handle->log_info.buf_offset_command);
  2085. }
  2086. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  2087. }
  2088. #endif
  2089. buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
  2090. len = qdf_nbuf_len(wmi_cmd_buf);
  2091. qdf_mem_zero(buf_ptr, len);
  2092. qdf_nbuf_free(wmi_cmd_buf);
  2093. qdf_mem_free(htc_pkt);
  2094. qdf_atomic_dec(&wmi_handle->pending_cmds);
  2095. }
  2096. /**
  2097. * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
  2098. *
  2099. * @wmi_handle: handle to WMI.
  2100. * @pdev_idx: Pdev index
  2101. *
  2102. * @Return: status.
  2103. */
  2104. static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
  2105. uint32_t pdev_idx)
  2106. {
  2107. int status;
  2108. struct htc_service_connect_resp response;
  2109. struct htc_service_connect_req connect;
  2110. OS_MEMZERO(&connect, sizeof(connect));
  2111. OS_MEMZERO(&response, sizeof(response));
  2112. /* meta data is unused for now */
  2113. connect.pMetaData = NULL;
  2114. connect.MetaDataLength = 0;
  2115. /* these fields are the same for all service endpoints */
  2116. connect.EpCallbacks.pContext = soc;
  2117. connect.EpCallbacks.EpTxCompleteMultiple =
  2118. NULL /* Control path completion ar6000_tx_complete */;
  2119. connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
  2120. connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
  2121. connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
  2122. connect.EpCallbacks.EpTxComplete =
  2123. wmi_htc_tx_complete /* ar6000_tx_queue_full */;
  2124. /* connect to control service */
  2125. connect.service_id = soc->svc_ids[pdev_idx];
  2126. status = htc_connect_service(soc->htc_handle, &connect,
  2127. &response);
  2128. if (status != EOK) {
  2129. qdf_print
  2130. ("Failed to connect to WMI CONTROL service status:%d\n",
  2131. status);
  2132. return status;
  2133. }
  2134. soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
  2135. soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
  2136. return 0;
  2137. }
  2138. /**
  2139. * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
  2140. *
  2141. * @wmi_handle: handle to WMI.
  2142. *
  2143. * @Return: status.
  2144. */
  2145. QDF_STATUS
  2146. wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
  2147. void *htc_handle)
  2148. {
  2149. uint32_t i;
  2150. uint8_t wmi_ep_count;
  2151. wmi_handle->soc->htc_handle = htc_handle;
  2152. wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
  2153. if (wmi_ep_count > WMI_MAX_RADIOS)
  2154. return QDF_STATUS_E_FAULT;
  2155. for (i = 0; i < wmi_ep_count; i++)
  2156. wmi_connect_pdev_htc_service(wmi_handle->soc, i);
  2157. wmi_handle->htc_handle = htc_handle;
  2158. wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
  2159. wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
  2160. return QDF_STATUS_SUCCESS;
  2161. }
  2162. /**
  2163. * wmi_get_host_credits() - WMI API to get updated host_credits
  2164. *
  2165. * @wmi_handle: handle to WMI.
  2166. *
  2167. * @Return: updated host_credits.
  2168. */
  2169. int wmi_get_host_credits(wmi_unified_t wmi_handle)
  2170. {
  2171. int host_credits = 0;
  2172. htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
  2173. &host_credits);
  2174. return host_credits;
  2175. }
  2176. /**
  2177. * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
  2178. * queue
  2179. *
  2180. * @wmi_handle: handle to WMI.
  2181. *
  2182. * @Return: Pending Commands in the HTC queue.
  2183. */
  2184. int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
  2185. {
  2186. return qdf_atomic_read(&wmi_handle->pending_cmds);
  2187. }
  2188. /**
  2189. * wmi_set_target_suspend() - WMI API to set target suspend state
  2190. *
  2191. * @wmi_handle: handle to WMI.
  2192. * @val: suspend state boolean.
  2193. *
  2194. * @Return: none.
  2195. */
  2196. void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
  2197. {
  2198. qdf_atomic_set(&wmi_handle->is_target_suspended, val);
  2199. }
  2200. /**
  2201. * WMI API to set crash injection state
  2202. * @param wmi_handle: handle to WMI.
  2203. * @param val: crash injection state boolean.
  2204. */
  2205. void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
  2206. {
  2207. wmi_handle->tag_crash_inject = flag;
  2208. }
  2209. /**
  2210. * WMI API to set bus suspend state
  2211. * @param wmi_handle: handle to WMI.
  2212. * @param val: suspend state boolean.
  2213. */
  2214. void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
  2215. {
  2216. qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
  2217. }
  2218. void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val)
  2219. {
  2220. wmi_handle->tgt_force_assert_enable = val;
  2221. }
  2222. /**
  2223. * wmi_stop() - generic function to block unified WMI command
  2224. * @wmi_handle: handle to WMI.
  2225. *
  2226. * @Return: success always.
  2227. */
  2228. int
  2229. wmi_stop(wmi_unified_t wmi_handle)
  2230. {
  2231. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  2232. "WMI Stop\n");
  2233. wmi_handle->wmi_stopinprogress = 1;
  2234. return 0;
  2235. }
  2236. #ifndef CONFIG_MCL
  2237. /**
  2238. * API to flush all the previous packets associated with the wmi endpoint
  2239. *
  2240. * @param wmi_handle : handle to WMI.
  2241. */
  2242. void
  2243. wmi_flush_endpoint(wmi_unified_t wmi_handle)
  2244. {
  2245. htc_flush_endpoint(wmi_handle->htc_handle,
  2246. wmi_handle->wmi_endpoint_id, 0);
  2247. }
  2248. qdf_export_symbol(wmi_flush_endpoint);
  2249. /**
  2250. * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI
  2251. * By default pdev_id conversion is not done in WMI.
  2252. * This API can be used enable conversion in WMI.
  2253. * @param wmi_handle : handle to WMI
  2254. * Return none
  2255. */
  2256. void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle)
  2257. {
  2258. if (wmi_handle->target_type == WMI_TLV_TARGET)
  2259. wmi_handle->ops->wmi_pdev_id_conversion_enable(wmi_handle);
  2260. }
  2261. #endif