wmi_unified.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547
  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, uint32_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, uint32_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. qdf_mem_zero(qdf_nbuf_data(buf), sizeof(WMI_CMD_HDR));
  1235. WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
  1236. qdf_atomic_inc(&wmi_handle->pending_cmds);
  1237. if (qdf_atomic_read(&wmi_handle->pending_cmds) >=
  1238. wmi_handle->wmi_max_cmds) {
  1239. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1240. "\n%s: hostcredits = %d", __func__,
  1241. wmi_get_host_credits(wmi_handle));
  1242. htc_dump_counter_info(wmi_handle->htc_handle);
  1243. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1244. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1245. "%s: MAX %d WMI Pending cmds reached.", __func__,
  1246. wmi_handle->wmi_max_cmds);
  1247. QDF_BUG(0);
  1248. return QDF_STATUS_E_BUSY;
  1249. }
  1250. pkt = qdf_mem_malloc(sizeof(*pkt));
  1251. if (!pkt) {
  1252. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1253. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1254. "%s, Failed to alloc htc packet %x, no memory",
  1255. __func__, cmd_id);
  1256. return QDF_STATUS_E_NOMEM;
  1257. }
  1258. SET_HTC_PACKET_INFO_TX(pkt,
  1259. NULL,
  1260. qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
  1261. wmi_handle->wmi_endpoint_id, htc_tag);
  1262. SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
  1263. #ifdef CONFIG_MCL
  1264. wmi_log_cmd_id(cmd_id, htc_tag);
  1265. #endif
  1266. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1267. if (wmi_handle->log_info.wmi_logging_enable) {
  1268. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1269. /*
  1270. * Record 16 bytes of WMI cmd data -
  1271. * exclude TLV and WMI headers
  1272. *
  1273. * WMI mgmt command already recorded in wmi_mgmt_cmd_record
  1274. */
  1275. if (wmi_handle->ops->is_management_record(cmd_id) == false) {
  1276. WMI_COMMAND_RECORD(wmi_handle, cmd_id,
  1277. qdf_nbuf_data(buf) +
  1278. wmi_handle->log_info.buf_offset_command);
  1279. }
  1280. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1281. }
  1282. #endif
  1283. status = htc_send_pkt(wmi_handle->htc_handle, pkt);
  1284. if (QDF_STATUS_SUCCESS != status) {
  1285. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1286. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1287. "%s %d, htc_send_pkt failed", __func__, __LINE__);
  1288. qdf_mem_free(pkt);
  1289. return status;
  1290. }
  1291. return QDF_STATUS_SUCCESS;
  1292. }
  1293. qdf_export_symbol(wmi_unified_cmd_send);
  1294. /**
  1295. * wmi_unified_get_event_handler_ix() - gives event handler's index
  1296. * @wmi_handle: handle to wmi
  1297. * @event_id: wmi event id
  1298. *
  1299. * Return: event handler's index
  1300. */
  1301. static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
  1302. uint32_t event_id)
  1303. {
  1304. uint32_t idx = 0;
  1305. int32_t invalid_idx = -1;
  1306. struct wmi_soc *soc = wmi_handle->soc;
  1307. for (idx = 0; (idx < soc->max_event_idx &&
  1308. idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
  1309. if (wmi_handle->event_id[idx] == event_id &&
  1310. wmi_handle->event_handler[idx] != NULL) {
  1311. return idx;
  1312. }
  1313. }
  1314. return invalid_idx;
  1315. }
  1316. /**
  1317. * wmi_unified_register_event() - register wmi event handler
  1318. * @wmi_handle: handle to wmi
  1319. * @event_id: wmi event id
  1320. * @handler_func: wmi event handler function
  1321. *
  1322. * Return: 0 on success
  1323. */
  1324. int wmi_unified_register_event(wmi_unified_t wmi_handle,
  1325. uint32_t event_id,
  1326. wmi_unified_event_handler handler_func)
  1327. {
  1328. uint32_t idx = 0;
  1329. uint32_t evt_id;
  1330. struct wmi_soc *soc = wmi_handle->soc;
  1331. if (event_id >= wmi_events_max ||
  1332. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1333. qdf_print("%s: Event id %d is unavailable\n",
  1334. __func__, event_id);
  1335. return QDF_STATUS_E_FAILURE;
  1336. }
  1337. evt_id = wmi_handle->wmi_events[event_id];
  1338. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1339. qdf_print("%s : event handler already registered 0x%x\n",
  1340. __func__, evt_id);
  1341. return QDF_STATUS_E_FAILURE;
  1342. }
  1343. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1344. qdf_print("%s : no more event handlers 0x%x\n",
  1345. __func__, evt_id);
  1346. return QDF_STATUS_E_FAILURE;
  1347. }
  1348. idx = soc->max_event_idx;
  1349. wmi_handle->event_handler[idx] = handler_func;
  1350. wmi_handle->event_id[idx] = evt_id;
  1351. qdf_spin_lock_bh(&soc->ctx_lock);
  1352. wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
  1353. qdf_spin_unlock_bh(&soc->ctx_lock);
  1354. soc->max_event_idx++;
  1355. return 0;
  1356. }
  1357. /**
  1358. * wmi_unified_register_event_handler() - register wmi event handler
  1359. * @wmi_handle: handle to wmi
  1360. * @event_id: wmi event id
  1361. * @handler_func: wmi event handler function
  1362. * @rx_ctx: rx execution context for wmi rx events
  1363. *
  1364. * This API is to support legacy requirements. Will be deprecated in future.
  1365. * Return: 0 on success
  1366. */
  1367. int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
  1368. wmi_conv_event_id event_id,
  1369. wmi_unified_event_handler handler_func,
  1370. uint8_t rx_ctx)
  1371. {
  1372. uint32_t idx = 0;
  1373. uint32_t evt_id;
  1374. struct wmi_soc *soc = wmi_handle->soc;
  1375. if (event_id >= wmi_events_max ||
  1376. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1377. qdf_print("%s: Event id %d is unavailable\n",
  1378. __func__, event_id);
  1379. return QDF_STATUS_E_FAILURE;
  1380. }
  1381. evt_id = wmi_handle->wmi_events[event_id];
  1382. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1383. qdf_print("%s : event handler already registered 0x%x\n",
  1384. __func__, evt_id);
  1385. return QDF_STATUS_E_FAILURE;
  1386. }
  1387. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1388. qdf_print("%s : no more event handlers 0x%x\n",
  1389. __func__, evt_id);
  1390. return QDF_STATUS_E_FAILURE;
  1391. }
  1392. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
  1393. "Registered event handler for event 0x%8x\n", evt_id);
  1394. idx = soc->max_event_idx;
  1395. wmi_handle->event_handler[idx] = handler_func;
  1396. wmi_handle->event_id[idx] = evt_id;
  1397. qdf_spin_lock_bh(&soc->ctx_lock);
  1398. wmi_handle->ctx[idx] = rx_ctx;
  1399. qdf_spin_unlock_bh(&soc->ctx_lock);
  1400. soc->max_event_idx++;
  1401. return 0;
  1402. }
  1403. qdf_export_symbol(wmi_unified_register_event_handler);
  1404. /**
  1405. * wmi_unified_unregister_event() - unregister wmi event handler
  1406. * @wmi_handle: handle to wmi
  1407. * @event_id: wmi event id
  1408. *
  1409. * Return: 0 on success
  1410. */
  1411. int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
  1412. uint32_t event_id)
  1413. {
  1414. uint32_t idx = 0;
  1415. uint32_t evt_id;
  1416. struct wmi_soc *soc = wmi_handle->soc;
  1417. if (event_id >= wmi_events_max ||
  1418. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1419. qdf_print("%s: Event id %d is unavailable\n",
  1420. __func__, event_id);
  1421. return QDF_STATUS_E_FAILURE;
  1422. }
  1423. evt_id = wmi_handle->wmi_events[event_id];
  1424. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1425. if (idx == -1) {
  1426. qdf_print("%s : event handler is not registered: evt id 0x%x\n",
  1427. __func__, evt_id);
  1428. return QDF_STATUS_E_FAILURE;
  1429. }
  1430. wmi_handle->event_handler[idx] = NULL;
  1431. wmi_handle->event_id[idx] = 0;
  1432. --soc->max_event_idx;
  1433. wmi_handle->event_handler[idx] =
  1434. wmi_handle->event_handler[soc->max_event_idx];
  1435. wmi_handle->event_id[idx] =
  1436. wmi_handle->event_id[soc->max_event_idx];
  1437. return 0;
  1438. }
  1439. /**
  1440. * wmi_unified_unregister_event_handler() - unregister wmi event handler
  1441. * @wmi_handle: handle to wmi
  1442. * @event_id: wmi event id
  1443. *
  1444. * Return: 0 on success
  1445. */
  1446. int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
  1447. wmi_conv_event_id event_id)
  1448. {
  1449. uint32_t idx = 0;
  1450. uint32_t evt_id;
  1451. struct wmi_soc *soc = wmi_handle->soc;
  1452. if (event_id >= wmi_events_max ||
  1453. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1454. qdf_print("%s: Event id %d is unavailable\n",
  1455. __func__, event_id);
  1456. return QDF_STATUS_E_FAILURE;
  1457. }
  1458. evt_id = wmi_handle->wmi_events[event_id];
  1459. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1460. if (idx == -1) {
  1461. qdf_print("%s : event handler is not registered: evt id 0x%x\n",
  1462. __func__, evt_id);
  1463. return QDF_STATUS_E_FAILURE;
  1464. }
  1465. wmi_handle->event_handler[idx] = NULL;
  1466. wmi_handle->event_id[idx] = 0;
  1467. --soc->max_event_idx;
  1468. wmi_handle->event_handler[idx] =
  1469. wmi_handle->event_handler[soc->max_event_idx];
  1470. wmi_handle->event_id[idx] =
  1471. wmi_handle->event_id[soc->max_event_idx];
  1472. return 0;
  1473. }
  1474. qdf_export_symbol(wmi_unified_unregister_event_handler);
  1475. /**
  1476. * wmi_process_fw_event_default_ctx() - process in default caller context
  1477. * @wmi_handle: handle to wmi
  1478. * @htc_packet: pointer to htc packet
  1479. * @exec_ctx: execution context for wmi fw event
  1480. *
  1481. * Event process by below function will be in default caller context.
  1482. * wmi internally provides rx work thread processing context.
  1483. *
  1484. * Return: none
  1485. */
  1486. static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
  1487. HTC_PACKET *htc_packet, uint8_t exec_ctx)
  1488. {
  1489. wmi_buf_t evt_buf;
  1490. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1491. #ifndef CONFIG_MCL
  1492. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
  1493. (wmi_handle->scn_handle, evt_buf, exec_ctx);
  1494. #else
  1495. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
  1496. evt_buf, exec_ctx);
  1497. #endif
  1498. return;
  1499. }
  1500. /**
  1501. * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
  1502. * @wmi_handle: handle to wmi
  1503. * @htc_packet: pointer to htc packet
  1504. *
  1505. * Event process by below function will be in worker thread context.
  1506. * Use this method for events which are not critical and not
  1507. * handled in protocol stack.
  1508. *
  1509. * Return: none
  1510. */
  1511. static void wmi_process_fw_event_worker_thread_ctx
  1512. (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet)
  1513. {
  1514. wmi_buf_t evt_buf;
  1515. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1516. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  1517. qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
  1518. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  1519. qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
  1520. &wmi_handle->rx_event_work);
  1521. return;
  1522. }
  1523. /**
  1524. * wmi_get_pdev_ep: Get wmi handle based on endpoint
  1525. * @soc: handle to wmi soc
  1526. * @ep: endpoint id
  1527. *
  1528. * Return: none
  1529. */
  1530. static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
  1531. HTC_ENDPOINT_ID ep)
  1532. {
  1533. uint32_t i;
  1534. for (i = 0; i < WMI_MAX_RADIOS; i++)
  1535. if (soc->wmi_endpoint_id[i] == ep)
  1536. break;
  1537. if (i == WMI_MAX_RADIOS)
  1538. return NULL;
  1539. return soc->wmi_pdev[i];
  1540. }
  1541. /**
  1542. * wmi_control_rx() - process fw events callbacks
  1543. * @ctx: handle to wmi
  1544. * @htc_packet: pointer to htc packet
  1545. *
  1546. * Return: none
  1547. */
  1548. static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
  1549. {
  1550. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  1551. struct wmi_unified *wmi_handle;
  1552. wmi_buf_t evt_buf;
  1553. uint32_t id;
  1554. uint32_t idx = 0;
  1555. enum wmi_rx_exec_ctx exec_ctx;
  1556. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1557. wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
  1558. if (wmi_handle == NULL) {
  1559. qdf_print
  1560. ("%s :unable to get wmi_handle to Endpoint %d\n",
  1561. __func__, htc_packet->Endpoint);
  1562. qdf_nbuf_free(evt_buf);
  1563. return;
  1564. }
  1565. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  1566. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  1567. if (qdf_unlikely(idx == A_ERROR)) {
  1568. WMI_LOGD("%s :event handler is not registered: event id 0x%x\n",
  1569. __func__, id);
  1570. qdf_nbuf_free(evt_buf);
  1571. return;
  1572. }
  1573. qdf_spin_lock_bh(&soc->ctx_lock);
  1574. exec_ctx = wmi_handle->ctx[idx];
  1575. qdf_spin_unlock_bh(&soc->ctx_lock);
  1576. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1577. if (wmi_handle->log_info.wmi_logging_enable) {
  1578. uint8_t *data;
  1579. data = qdf_nbuf_data(evt_buf);
  1580. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1581. /* Exclude 4 bytes of TLV header */
  1582. WMI_RX_EVENT_RECORD(wmi_handle, id, data +
  1583. wmi_handle->log_info.buf_offset_event);
  1584. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1585. }
  1586. #endif
  1587. if (exec_ctx == WMI_RX_WORK_CTX) {
  1588. wmi_process_fw_event_worker_thread_ctx
  1589. (wmi_handle, htc_packet);
  1590. } else if (exec_ctx > WMI_RX_WORK_CTX) {
  1591. wmi_process_fw_event_default_ctx
  1592. (wmi_handle, htc_packet, exec_ctx);
  1593. } else {
  1594. qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
  1595. qdf_nbuf_free(evt_buf);
  1596. }
  1597. }
  1598. /**
  1599. * wmi_process_fw_event() - process any fw event
  1600. * @wmi_handle: wmi handle
  1601. * @evt_buf: fw event buffer
  1602. *
  1603. * This function process fw event in caller context
  1604. *
  1605. * Return: none
  1606. */
  1607. void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  1608. {
  1609. __wmi_control_rx(wmi_handle, evt_buf);
  1610. }
  1611. /**
  1612. * __wmi_control_rx() - process serialize wmi event callback
  1613. * @wmi_handle: wmi handle
  1614. * @evt_buf: fw event buffer
  1615. *
  1616. * Return: none
  1617. */
  1618. void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  1619. {
  1620. uint32_t id;
  1621. uint8_t *data;
  1622. uint32_t len;
  1623. void *wmi_cmd_struct_ptr = NULL;
  1624. #ifndef WMI_NON_TLV_SUPPORT
  1625. int tlv_ok_status = 0;
  1626. #endif
  1627. uint32_t idx = 0;
  1628. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  1629. if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
  1630. goto end;
  1631. data = qdf_nbuf_data(evt_buf);
  1632. len = qdf_nbuf_len(evt_buf);
  1633. #ifndef WMI_NON_TLV_SUPPORT
  1634. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  1635. /* Validate and pad(if necessary) the TLVs */
  1636. tlv_ok_status =
  1637. wmi_handle->ops->wmi_check_and_pad_event(wmi_handle->scn_handle,
  1638. data, len, id,
  1639. &wmi_cmd_struct_ptr);
  1640. if (tlv_ok_status != 0) {
  1641. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1642. "%s: Error: id=0x%d, wmitlv check status=%d\n",
  1643. __func__, id, tlv_ok_status);
  1644. goto end;
  1645. }
  1646. }
  1647. #endif
  1648. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  1649. if (idx == A_ERROR) {
  1650. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1651. "%s : event handler is not registered: event id 0x%x\n",
  1652. __func__, id);
  1653. goto end;
  1654. }
  1655. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1656. if (wmi_handle->log_info.wmi_logging_enable) {
  1657. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1658. /* Exclude 4 bytes of TLV header */
  1659. if (wmi_handle->ops->is_management_record(id)) {
  1660. WMI_MGMT_EVENT_RECORD(wmi_handle, id, data
  1661. + wmi_handle->log_info.buf_offset_event);
  1662. } else {
  1663. WMI_EVENT_RECORD(wmi_handle, id, data +
  1664. wmi_handle->log_info.buf_offset_event);
  1665. }
  1666. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1667. }
  1668. #endif
  1669. /* Call the WMI registered event handler */
  1670. if (wmi_handle->target_type == WMI_TLV_TARGET)
  1671. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  1672. wmi_cmd_struct_ptr, len);
  1673. else
  1674. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  1675. data, len);
  1676. end:
  1677. /* Free event buffer and allocated event tlv */
  1678. #ifndef WMI_NON_TLV_SUPPORT
  1679. if (wmi_handle->target_type == WMI_TLV_TARGET)
  1680. wmi_handle->ops->wmi_free_allocated_event(id, &wmi_cmd_struct_ptr);
  1681. #endif
  1682. qdf_nbuf_free(evt_buf);
  1683. }
  1684. #define WMI_WQ_WD_TIMEOUT (30 * 1000) /* 30s */
  1685. static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id)
  1686. {
  1687. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  1688. "%s: WLAN_BUG_RCA: Message type %x has exceeded its alloted time of %ds",
  1689. __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000);
  1690. }
  1691. #ifdef CONFIG_SLUB_DEBUG_ON
  1692. static void wmi_workqueue_watchdog_bite(void *arg)
  1693. {
  1694. struct wmi_wq_dbg_info *info = arg;
  1695. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  1696. qdf_print_thread_trace(info->task);
  1697. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  1698. "%s: Going down for WMI WQ Watchdog Bite!", __func__);
  1699. QDF_BUG(0);
  1700. }
  1701. #else
  1702. static inline void wmi_workqueue_watchdog_bite(void *arg)
  1703. {
  1704. struct wmi_wq_dbg_info *info = arg;
  1705. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  1706. }
  1707. #endif
  1708. /**
  1709. * wmi_rx_event_work() - process rx event in rx work queue context
  1710. * @arg: opaque pointer to wmi handle
  1711. *
  1712. * This function process any fw event to serialize it through rx worker thread.
  1713. *
  1714. * Return: none
  1715. */
  1716. static void wmi_rx_event_work(void *arg)
  1717. {
  1718. wmi_buf_t buf;
  1719. struct wmi_unified *wmi = arg;
  1720. qdf_timer_t wd_timer;
  1721. struct wmi_wq_dbg_info info;
  1722. /* initialize WMI workqueue watchdog timer */
  1723. qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite,
  1724. &info, QDF_TIMER_TYPE_SW);
  1725. qdf_spin_lock_bh(&wmi->eventq_lock);
  1726. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  1727. qdf_spin_unlock_bh(&wmi->eventq_lock);
  1728. while (buf) {
  1729. qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT);
  1730. info.wd_msg_type_id =
  1731. WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID);
  1732. info.wmi_wq = wmi->wmi_rx_work_queue;
  1733. info.task = qdf_get_current_task();
  1734. __wmi_control_rx(wmi, buf);
  1735. qdf_timer_stop(&wd_timer);
  1736. qdf_spin_lock_bh(&wmi->eventq_lock);
  1737. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  1738. qdf_spin_unlock_bh(&wmi->eventq_lock);
  1739. }
  1740. qdf_timer_free(&wd_timer);
  1741. }
  1742. #ifdef FEATURE_RUNTIME_PM
  1743. /**
  1744. * wmi_runtime_pm_init() - initialize runtime pm wmi variables
  1745. * @wmi_handle: wmi context
  1746. */
  1747. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  1748. {
  1749. qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
  1750. }
  1751. /**
  1752. * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
  1753. * @wmi_handle: wmi context
  1754. * @val: runtime pm progress flag
  1755. */
  1756. void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
  1757. {
  1758. qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
  1759. }
  1760. /**
  1761. * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
  1762. * @wmi_handle: wmi context
  1763. */
  1764. inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
  1765. {
  1766. return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
  1767. }
  1768. #else
  1769. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  1770. {
  1771. }
  1772. #endif
  1773. /**
  1774. * wmi_unified_get_soc_handle: Get WMI SoC handle
  1775. * @param wmi_handle: WMI context got from wmi_attach
  1776. *
  1777. * return: Pointer to Soc handle
  1778. */
  1779. void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
  1780. {
  1781. return wmi_handle->soc;
  1782. }
  1783. /**
  1784. * wmi_interface_logging_init: Interface looging init
  1785. * @param wmi_handle: Pointer to wmi handle object
  1786. *
  1787. * return: None
  1788. */
  1789. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1790. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
  1791. {
  1792. if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
  1793. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  1794. wmi_debugfs_init(wmi_handle);
  1795. }
  1796. }
  1797. #else
  1798. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
  1799. {
  1800. }
  1801. #endif
  1802. /**
  1803. * wmi_target_params_init: Target specific params init
  1804. * @param wmi_soc: Pointer to wmi soc object
  1805. * @param wmi_handle: Pointer to wmi handle object
  1806. *
  1807. * return: None
  1808. */
  1809. #ifndef CONFIG_MCL
  1810. static inline void wmi_target_params_init(struct wmi_soc *soc,
  1811. struct wmi_unified *wmi_handle)
  1812. {
  1813. wmi_handle->pdev_param = soc->pdev_param;
  1814. wmi_handle->vdev_param = soc->vdev_param;
  1815. wmi_handle->services = soc->services;
  1816. }
  1817. #else
  1818. static inline void wmi_target_params_init(struct wmi_soc *soc,
  1819. struct wmi_unified *wmi_handle)
  1820. {
  1821. wmi_handle->services = soc->services;
  1822. }
  1823. #endif
  1824. /**
  1825. * wmi_unified_get_pdev_handle: Get WMI SoC handle
  1826. * @param wmi_soc: Pointer to wmi soc object
  1827. * @param pdev_idx: pdev index
  1828. *
  1829. * return: Pointer to wmi handle or NULL on failure
  1830. */
  1831. void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
  1832. {
  1833. struct wmi_unified *wmi_handle;
  1834. if (pdev_idx >= WMI_MAX_RADIOS)
  1835. return NULL;
  1836. if (soc->wmi_pdev[pdev_idx] == NULL) {
  1837. wmi_handle =
  1838. (struct wmi_unified *) qdf_mem_malloc(
  1839. sizeof(struct wmi_unified));
  1840. if (wmi_handle == NULL) {
  1841. qdf_print("allocation of wmi handle failed %zu\n",
  1842. sizeof(struct wmi_unified));
  1843. return NULL;
  1844. }
  1845. wmi_handle->scn_handle = soc->scn_handle;
  1846. wmi_handle->event_id = soc->event_id;
  1847. wmi_handle->event_handler = soc->event_handler;
  1848. wmi_handle->ctx = soc->ctx;
  1849. wmi_handle->ops = soc->ops;
  1850. qdf_spinlock_create(&wmi_handle->eventq_lock);
  1851. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  1852. qdf_create_work(0, &wmi_handle->rx_event_work,
  1853. wmi_rx_event_work, wmi_handle);
  1854. wmi_handle->wmi_rx_work_queue =
  1855. qdf_create_workqueue("wmi_rx_event_work_queue");
  1856. if (NULL == wmi_handle->wmi_rx_work_queue) {
  1857. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  1858. goto error;
  1859. }
  1860. wmi_handle->wmi_events = soc->wmi_events;
  1861. wmi_target_params_init(soc, wmi_handle);
  1862. wmi_interface_logging_init(wmi_handle);
  1863. qdf_atomic_init(&wmi_handle->pending_cmds);
  1864. qdf_atomic_init(&wmi_handle->is_target_suspended);
  1865. wmi_handle->target_type = soc->target_type;
  1866. wmi_handle->wmi_max_cmds = soc->wmi_max_cmds;
  1867. wmi_handle->soc = soc;
  1868. soc->wmi_pdev[pdev_idx] = wmi_handle;
  1869. } else
  1870. wmi_handle = soc->wmi_pdev[pdev_idx];
  1871. wmi_handle->wmi_stopinprogress = 0;
  1872. wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
  1873. wmi_handle->htc_handle = soc->htc_handle;
  1874. wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
  1875. return wmi_handle;
  1876. error:
  1877. qdf_mem_free(wmi_handle);
  1878. return NULL;
  1879. }
  1880. qdf_export_symbol(wmi_unified_get_pdev_handle);
  1881. static void (*wmi_attach_register[WMI_MAX_TARGET_TYPE])(wmi_unified_t);
  1882. void wmi_unified_register_module(enum wmi_target_type target_type,
  1883. void (*wmi_attach)(wmi_unified_t wmi_handle))
  1884. {
  1885. if (target_type < WMI_MAX_TARGET_TYPE)
  1886. wmi_attach_register[target_type] = wmi_attach;
  1887. return;
  1888. }
  1889. qdf_export_symbol(wmi_unified_register_module);
  1890. /**
  1891. * wmi_unified_attach() - attach for unified WMI
  1892. * @scn_handle: handle to SCN
  1893. * @osdev: OS device context
  1894. * @target_type: TLV or not-TLV based target
  1895. * @use_cookie: cookie based allocation enabled/disabled
  1896. * @ops: umac rx callbacks
  1897. * @psoc: objmgr psoc
  1898. *
  1899. * @Return: wmi handle.
  1900. */
  1901. void *wmi_unified_attach(void *scn_handle,
  1902. struct wmi_unified_attach_params *param)
  1903. {
  1904. struct wmi_unified *wmi_handle;
  1905. struct wmi_soc *soc;
  1906. soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
  1907. if (soc == NULL) {
  1908. qdf_print("Allocation of wmi_soc failed %zu\n",
  1909. sizeof(struct wmi_soc));
  1910. return NULL;
  1911. }
  1912. wmi_handle =
  1913. (struct wmi_unified *) qdf_mem_malloc(
  1914. sizeof(struct wmi_unified));
  1915. if (wmi_handle == NULL) {
  1916. qdf_mem_free(soc);
  1917. qdf_print("allocation of wmi handle failed %zu\n",
  1918. sizeof(struct wmi_unified));
  1919. return NULL;
  1920. }
  1921. wmi_handle->soc = soc;
  1922. wmi_handle->event_id = soc->event_id;
  1923. wmi_handle->event_handler = soc->event_handler;
  1924. wmi_handle->ctx = soc->ctx;
  1925. wmi_handle->wmi_events = soc->wmi_events;
  1926. wmi_target_params_init(soc, wmi_handle);
  1927. wmi_handle->scn_handle = scn_handle;
  1928. soc->scn_handle = scn_handle;
  1929. qdf_atomic_init(&wmi_handle->pending_cmds);
  1930. qdf_atomic_init(&wmi_handle->is_target_suspended);
  1931. wmi_runtime_pm_init(wmi_handle);
  1932. qdf_spinlock_create(&wmi_handle->eventq_lock);
  1933. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  1934. qdf_create_work(0, &wmi_handle->rx_event_work,
  1935. wmi_rx_event_work, wmi_handle);
  1936. wmi_handle->wmi_rx_work_queue =
  1937. qdf_create_workqueue("wmi_rx_event_work_queue");
  1938. if (NULL == wmi_handle->wmi_rx_work_queue) {
  1939. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  1940. goto error;
  1941. }
  1942. wmi_interface_logging_init(wmi_handle);
  1943. /* Attach mc_thread context processing function */
  1944. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
  1945. param->rx_ops->wma_process_fw_event_handler_cbk;
  1946. wmi_handle->target_type = param->target_type;
  1947. soc->target_type = param->target_type;
  1948. if (param->target_type >= WMI_MAX_TARGET_TYPE)
  1949. goto error;
  1950. if (wmi_attach_register[param->target_type]) {
  1951. wmi_attach_register[param->target_type](wmi_handle);
  1952. } else {
  1953. WMI_LOGE("wmi attach is not registered");
  1954. goto error;
  1955. }
  1956. /* Assign target cookie capablity */
  1957. wmi_handle->use_cookie = param->use_cookie;
  1958. wmi_handle->osdev = param->osdev;
  1959. wmi_handle->wmi_stopinprogress = 0;
  1960. wmi_handle->wmi_max_cmds = param->max_commands;
  1961. soc->wmi_max_cmds = param->max_commands;
  1962. /* Increase the ref count once refcount infra is present */
  1963. soc->wmi_psoc = param->psoc;
  1964. qdf_spinlock_create(&soc->ctx_lock);
  1965. soc->ops = wmi_handle->ops;
  1966. soc->wmi_pdev[0] = wmi_handle;
  1967. return wmi_handle;
  1968. error:
  1969. qdf_mem_free(soc);
  1970. qdf_mem_free(wmi_handle);
  1971. return NULL;
  1972. }
  1973. /**
  1974. * wmi_unified_detach() - detach for unified WMI
  1975. *
  1976. * @wmi_handle : handle to wmi.
  1977. *
  1978. * @Return: none.
  1979. */
  1980. void wmi_unified_detach(struct wmi_unified *wmi_handle)
  1981. {
  1982. wmi_buf_t buf;
  1983. struct wmi_soc *soc;
  1984. uint8_t i;
  1985. soc = wmi_handle->soc;
  1986. for (i = 0; i < WMI_MAX_RADIOS; i++) {
  1987. if (soc->wmi_pdev[i]) {
  1988. qdf_flush_workqueue(0,
  1989. soc->wmi_pdev[i]->wmi_rx_work_queue);
  1990. qdf_destroy_workqueue(0,
  1991. soc->wmi_pdev[i]->wmi_rx_work_queue);
  1992. wmi_debugfs_remove(soc->wmi_pdev[i]);
  1993. buf = qdf_nbuf_queue_remove(
  1994. &soc->wmi_pdev[i]->event_queue);
  1995. while (buf) {
  1996. qdf_nbuf_free(buf);
  1997. buf = qdf_nbuf_queue_remove(
  1998. &soc->wmi_pdev[i]->event_queue);
  1999. }
  2000. wmi_log_buffer_free(soc->wmi_pdev[i]);
  2001. /* Free events logs list */
  2002. if (soc->wmi_pdev[i]->events_logs_list)
  2003. qdf_mem_free(
  2004. soc->wmi_pdev[i]->events_logs_list);
  2005. qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
  2006. qdf_mem_free(soc->wmi_pdev[i]);
  2007. }
  2008. }
  2009. qdf_spinlock_destroy(&soc->ctx_lock);
  2010. if (soc->wmi_service_bitmap) {
  2011. qdf_mem_free(soc->wmi_service_bitmap);
  2012. soc->wmi_service_bitmap = NULL;
  2013. }
  2014. if (soc->wmi_ext_service_bitmap) {
  2015. qdf_mem_free(soc->wmi_ext_service_bitmap);
  2016. soc->wmi_ext_service_bitmap = NULL;
  2017. }
  2018. /* Decrease the ref count once refcount infra is present */
  2019. soc->wmi_psoc = NULL;
  2020. qdf_mem_free(soc);
  2021. }
  2022. /**
  2023. * wmi_unified_remove_work() - detach for WMI work
  2024. * @wmi_handle: handle to WMI
  2025. *
  2026. * A function that does not fully detach WMI, but just remove work
  2027. * queue items associated with it. This is used to make sure that
  2028. * before any other processing code that may destroy related contexts
  2029. * (HTC, etc), work queue processing on WMI has already been stopped.
  2030. *
  2031. * Return: None
  2032. */
  2033. void
  2034. wmi_unified_remove_work(struct wmi_unified *wmi_handle)
  2035. {
  2036. wmi_buf_t buf;
  2037. qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
  2038. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  2039. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2040. while (buf) {
  2041. qdf_nbuf_free(buf);
  2042. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2043. }
  2044. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  2045. }
  2046. /**
  2047. * wmi_htc_tx_complete() - Process htc tx completion
  2048. *
  2049. * @ctx: handle to wmi
  2050. * @htc_packet: pointer to htc packet
  2051. *
  2052. * @Return: none.
  2053. */
  2054. static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
  2055. {
  2056. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  2057. wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
  2058. u_int8_t *buf_ptr;
  2059. u_int32_t len;
  2060. struct wmi_unified *wmi_handle;
  2061. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2062. uint32_t cmd_id;
  2063. #endif
  2064. ASSERT(wmi_cmd_buf);
  2065. wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
  2066. if (wmi_handle == NULL) {
  2067. WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
  2068. QDF_ASSERT(0);
  2069. return;
  2070. }
  2071. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2072. if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
  2073. cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
  2074. WMI_CMD_HDR, COMMANDID);
  2075. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  2076. /* Record 16 bytes of WMI cmd tx complete data
  2077. - exclude TLV and WMI headers */
  2078. if (wmi_handle->ops->is_management_record(cmd_id)) {
  2079. WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2080. qdf_nbuf_data(wmi_cmd_buf) +
  2081. wmi_handle->log_info.buf_offset_command);
  2082. } else {
  2083. WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2084. qdf_nbuf_data(wmi_cmd_buf) +
  2085. wmi_handle->log_info.buf_offset_command);
  2086. }
  2087. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  2088. }
  2089. #endif
  2090. buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
  2091. len = qdf_nbuf_len(wmi_cmd_buf);
  2092. qdf_mem_zero(buf_ptr, len);
  2093. qdf_nbuf_free(wmi_cmd_buf);
  2094. qdf_mem_free(htc_pkt);
  2095. qdf_atomic_dec(&wmi_handle->pending_cmds);
  2096. }
  2097. /**
  2098. * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
  2099. *
  2100. * @wmi_handle: handle to WMI.
  2101. * @pdev_idx: Pdev index
  2102. *
  2103. * @Return: status.
  2104. */
  2105. static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
  2106. uint32_t pdev_idx)
  2107. {
  2108. int status;
  2109. struct htc_service_connect_resp response;
  2110. struct htc_service_connect_req connect;
  2111. OS_MEMZERO(&connect, sizeof(connect));
  2112. OS_MEMZERO(&response, sizeof(response));
  2113. /* meta data is unused for now */
  2114. connect.pMetaData = NULL;
  2115. connect.MetaDataLength = 0;
  2116. /* these fields are the same for all service endpoints */
  2117. connect.EpCallbacks.pContext = soc;
  2118. connect.EpCallbacks.EpTxCompleteMultiple =
  2119. NULL /* Control path completion ar6000_tx_complete */;
  2120. connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
  2121. connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
  2122. connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
  2123. connect.EpCallbacks.EpTxComplete =
  2124. wmi_htc_tx_complete /* ar6000_tx_queue_full */;
  2125. /* connect to control service */
  2126. connect.service_id = soc->svc_ids[pdev_idx];
  2127. status = htc_connect_service(soc->htc_handle, &connect,
  2128. &response);
  2129. if (status != EOK) {
  2130. qdf_print
  2131. ("Failed to connect to WMI CONTROL service status:%d\n",
  2132. status);
  2133. return status;
  2134. }
  2135. soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
  2136. soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
  2137. return 0;
  2138. }
  2139. /**
  2140. * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
  2141. *
  2142. * @wmi_handle: handle to WMI.
  2143. *
  2144. * @Return: status.
  2145. */
  2146. QDF_STATUS
  2147. wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
  2148. void *htc_handle)
  2149. {
  2150. uint32_t i;
  2151. uint8_t wmi_ep_count;
  2152. wmi_handle->soc->htc_handle = htc_handle;
  2153. wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
  2154. if (wmi_ep_count > WMI_MAX_RADIOS)
  2155. return QDF_STATUS_E_FAULT;
  2156. for (i = 0; i < wmi_ep_count; i++)
  2157. wmi_connect_pdev_htc_service(wmi_handle->soc, i);
  2158. wmi_handle->htc_handle = htc_handle;
  2159. wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
  2160. wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
  2161. return QDF_STATUS_SUCCESS;
  2162. }
  2163. /**
  2164. * wmi_get_host_credits() - WMI API to get updated host_credits
  2165. *
  2166. * @wmi_handle: handle to WMI.
  2167. *
  2168. * @Return: updated host_credits.
  2169. */
  2170. int wmi_get_host_credits(wmi_unified_t wmi_handle)
  2171. {
  2172. int host_credits = 0;
  2173. htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
  2174. &host_credits);
  2175. return host_credits;
  2176. }
  2177. /**
  2178. * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
  2179. * queue
  2180. *
  2181. * @wmi_handle: handle to WMI.
  2182. *
  2183. * @Return: Pending Commands in the HTC queue.
  2184. */
  2185. int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
  2186. {
  2187. return qdf_atomic_read(&wmi_handle->pending_cmds);
  2188. }
  2189. /**
  2190. * wmi_set_target_suspend() - WMI API to set target suspend state
  2191. *
  2192. * @wmi_handle: handle to WMI.
  2193. * @val: suspend state boolean.
  2194. *
  2195. * @Return: none.
  2196. */
  2197. void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
  2198. {
  2199. qdf_atomic_set(&wmi_handle->is_target_suspended, val);
  2200. }
  2201. /**
  2202. * WMI API to set crash injection state
  2203. * @param wmi_handle: handle to WMI.
  2204. * @param val: crash injection state boolean.
  2205. */
  2206. void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
  2207. {
  2208. wmi_handle->tag_crash_inject = flag;
  2209. }
  2210. /**
  2211. * WMI API to set bus suspend state
  2212. * @param wmi_handle: handle to WMI.
  2213. * @param val: suspend state boolean.
  2214. */
  2215. void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
  2216. {
  2217. qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
  2218. }
  2219. void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val)
  2220. {
  2221. wmi_handle->tgt_force_assert_enable = val;
  2222. }
  2223. /**
  2224. * wmi_stop() - generic function to block unified WMI command
  2225. * @wmi_handle: handle to WMI.
  2226. *
  2227. * @Return: success always.
  2228. */
  2229. int
  2230. wmi_stop(wmi_unified_t wmi_handle)
  2231. {
  2232. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  2233. "WMI Stop\n");
  2234. wmi_handle->wmi_stopinprogress = 1;
  2235. return 0;
  2236. }
  2237. #ifndef CONFIG_MCL
  2238. /**
  2239. * API to flush all the previous packets associated with the wmi endpoint
  2240. *
  2241. * @param wmi_handle : handle to WMI.
  2242. */
  2243. void
  2244. wmi_flush_endpoint(wmi_unified_t wmi_handle)
  2245. {
  2246. htc_flush_endpoint(wmi_handle->htc_handle,
  2247. wmi_handle->wmi_endpoint_id, 0);
  2248. }
  2249. qdf_export_symbol(wmi_flush_endpoint);
  2250. /**
  2251. * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI
  2252. * By default pdev_id conversion is not done in WMI.
  2253. * This API can be used enable conversion in WMI.
  2254. * @param wmi_handle : handle to WMI
  2255. * Return none
  2256. */
  2257. void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle)
  2258. {
  2259. if (wmi_handle->target_type == WMI_TLV_TARGET)
  2260. wmi_handle->ops->wmi_pdev_id_conversion_enable(wmi_handle);
  2261. }
  2262. #endif