wmi_unified.c 72 KB

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