wmi_unified.c 73 KB

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