wmi_unified.c 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030
  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 "athdefs.h"
  30. #include "osapi_linux.h"
  31. #include "a_types.h"
  32. #include "a_debug.h"
  33. #include "ol_if_athvar.h"
  34. #include "htc_api.h"
  35. #include "htc_api.h"
  36. #include "dbglog_host.h"
  37. #include "wmi_unified_priv.h"
  38. #include "wmi_unified_param.h"
  39. #ifndef WMI_NON_TLV_SUPPORT
  40. #include "wmi_tlv_helper.h"
  41. #endif
  42. #include <linux/debugfs.h>
  43. /* This check for CONFIG_WIN temporary added due to redeclaration compilation
  44. error in MCL. Error is caused due to inclusion of wmi.h in wmi_unified_api.h
  45. which gets included here through ol_if_athvar.h. Eventually it is expected that
  46. wmi.h will be removed from wmi_unified_api.h after cleanup, which will need
  47. WMI_CMD_HDR to be defined here. */
  48. #ifdef CONFIG_WIN
  49. /* Copied from wmi.h */
  50. #undef MS
  51. #define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
  52. #undef SM
  53. #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
  54. #undef WO
  55. #define WO(_f) ((_f##_OFFSET) >> 2)
  56. #undef GET_FIELD
  57. #define GET_FIELD(_addr, _f) MS(*((A_UINT32 *)(_addr) + WO(_f)), _f)
  58. #undef SET_FIELD
  59. #define SET_FIELD(_addr, _f, _val) \
  60. (*((A_UINT32 *)(_addr) + WO(_f)) = \
  61. (*((A_UINT32 *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f))
  62. #define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \
  63. GET_FIELD(_msg_buf, _msg_type ## _ ## _f)
  64. #define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \
  65. SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val)
  66. #define WMI_EP_APASS 0x0
  67. #define WMI_EP_LPASS 0x1
  68. #define WMI_EP_SENSOR 0x2
  69. /*
  70. * * Control Path
  71. * */
  72. typedef PREPACK struct {
  73. A_UINT32 commandId:24,
  74. reserved:2, /* used for WMI endpoint ID */
  75. plt_priv:6; /* platform private */
  76. } POSTPACK WMI_CMD_HDR; /* used for commands and events */
  77. #define WMI_CMD_HDR_COMMANDID_LSB 0
  78. #define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff
  79. #define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000
  80. #define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000
  81. #define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24
  82. #define WMI_CMD_HDR_PLT_PRIV_LSB 24
  83. #define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000
  84. #define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000
  85. /* end of copy wmi.h */
  86. #endif /* CONFIG_WIN */
  87. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
  88. /* TODO Cleanup this backported function */
  89. static int qcacld_bp_seq_printf(struct seq_file *m, const char *f, ...)
  90. {
  91. va_list args;
  92. va_start(args, f);
  93. seq_printf(m, f, args);
  94. va_end(args);
  95. return m->count;
  96. }
  97. #define seq_printf(m, fmt, ...) qcacld_bp_seq_printf((m), fmt, ##__VA_ARGS__)
  98. #endif
  99. #define WMI_MIN_HEAD_ROOM 64
  100. #ifdef WMI_INTERFACE_EVENT_LOGGING
  101. #ifndef MAX_WMI_INSTANCES
  102. #ifdef CONFIG_MCL
  103. #define MAX_WMI_INSTANCES 1
  104. #else
  105. #define MAX_WMI_INSTANCES 3
  106. #endif
  107. #define CUSTOM_MGMT_CMD_DATA_SIZE 4
  108. #endif
  109. #ifdef CONFIG_MCL
  110. /* WMI commands */
  111. uint32_t g_wmi_command_buf_idx = 0;
  112. struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  113. /* WMI commands TX completed */
  114. uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
  115. struct wmi_command_debug
  116. wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  117. /* WMI events when processed */
  118. uint32_t g_wmi_event_buf_idx = 0;
  119. struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  120. /* WMI events when queued */
  121. uint32_t g_wmi_rx_event_buf_idx = 0;
  122. struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  123. #endif
  124. #define WMI_COMMAND_RECORD(h, a, b) { \
  125. if (wmi_log_max_entry <= \
  126. *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
  127. *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
  128. ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
  129. [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
  130. .command = a; \
  131. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  132. wmi_command_log_buf_info.buf) \
  133. [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
  134. b, wmi_record_max_length); \
  135. ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
  136. [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
  137. time = qdf_get_log_timestamp(); \
  138. (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
  139. h->log_info.wmi_command_log_buf_info.length++; \
  140. }
  141. #define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
  142. if (wmi_log_max_entry <= \
  143. *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
  144. *(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  145. p_buf_tail_idx) = 0; \
  146. ((struct wmi_command_debug *)h->log_info. \
  147. wmi_command_tx_cmp_log_buf_info.buf) \
  148. [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  149. p_buf_tail_idx)]. \
  150. command = a; \
  151. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  152. wmi_command_tx_cmp_log_buf_info.buf) \
  153. [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  154. p_buf_tail_idx)]. \
  155. data, b, wmi_record_max_length); \
  156. ((struct wmi_command_debug *)h->log_info. \
  157. wmi_command_tx_cmp_log_buf_info.buf) \
  158. [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  159. p_buf_tail_idx)]. \
  160. time = qdf_get_log_timestamp(); \
  161. (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
  162. h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
  163. }
  164. #define WMI_EVENT_RECORD(h, a, b) { \
  165. if (wmi_log_max_entry <= \
  166. *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
  167. *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
  168. ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
  169. [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
  170. event = a; \
  171. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  172. wmi_event_log_buf_info.buf) \
  173. [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
  174. wmi_record_max_length); \
  175. ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
  176. [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
  177. qdf_get_log_timestamp(); \
  178. (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
  179. h->log_info.wmi_event_log_buf_info.length++; \
  180. }
  181. #define WMI_RX_EVENT_RECORD(h, a, b) { \
  182. if (wmi_log_max_entry <= \
  183. *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
  184. *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
  185. ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
  186. [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
  187. event = a; \
  188. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  189. wmi_rx_event_log_buf_info.buf) \
  190. [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
  191. data, b, wmi_record_max_length); \
  192. ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
  193. [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
  194. time = qdf_get_log_timestamp(); \
  195. (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
  196. h->log_info.wmi_rx_event_log_buf_info.length++; \
  197. }
  198. #ifdef CONFIG_MCL
  199. uint32_t g_wmi_mgmt_command_buf_idx = 0;
  200. struct
  201. wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
  202. /* wmi_mgmt commands TX completed */
  203. uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
  204. struct wmi_command_debug
  205. wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
  206. /* wmi_mgmt events when processed */
  207. uint32_t g_wmi_mgmt_event_buf_idx = 0;
  208. struct wmi_event_debug
  209. wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
  210. #endif
  211. #define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
  212. if (wmi_mgmt_log_max_entry <= \
  213. *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
  214. *(h->log_info.wmi_mgmt_command_log_buf_info. \
  215. p_buf_tail_idx) = 0; \
  216. ((struct wmi_command_debug *)h->log_info. \
  217. wmi_mgmt_command_log_buf_info.buf) \
  218. [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
  219. command = a; \
  220. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  221. wmi_mgmt_command_log_buf_info.buf) \
  222. [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
  223. data, b, \
  224. wmi_record_max_length); \
  225. ((struct wmi_command_debug *)h->log_info. \
  226. wmi_mgmt_command_log_buf_info.buf) \
  227. [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
  228. time = qdf_get_log_timestamp(); \
  229. (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
  230. h->log_info.wmi_mgmt_command_log_buf_info.length++; \
  231. }
  232. #define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
  233. if (wmi_mgmt_log_max_entry <= \
  234. *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  235. p_buf_tail_idx)) \
  236. *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  237. p_buf_tail_idx) = 0; \
  238. ((struct wmi_command_debug *)h->log_info. \
  239. wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
  240. [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  241. p_buf_tail_idx)].command = a; \
  242. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  243. wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
  244. [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  245. p_buf_tail_idx)].data, b, \
  246. wmi_record_max_length); \
  247. ((struct wmi_command_debug *)h->log_info. \
  248. wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
  249. [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  250. p_buf_tail_idx)].time = \
  251. qdf_get_log_timestamp(); \
  252. (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  253. p_buf_tail_idx))++; \
  254. h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
  255. }
  256. #define WMI_MGMT_EVENT_RECORD(h, a, b) { \
  257. if (wmi_mgmt_log_max_entry <= \
  258. *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
  259. *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
  260. ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
  261. [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
  262. .event = a; \
  263. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  264. wmi_mgmt_event_log_buf_info.buf) \
  265. [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
  266. data, b, wmi_record_max_length); \
  267. ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
  268. [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
  269. time = qdf_get_log_timestamp(); \
  270. (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
  271. h->log_info.wmi_mgmt_event_log_buf_info.length++; \
  272. }
  273. /* These are defined to made it as module param, which can be configured */
  274. uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
  275. uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  276. uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
  277. uint32_t wmi_display_size = 100;
  278. static uint8_t *wmi_id_to_name(uint32_t wmi_command);
  279. /**
  280. * wmi_log_init() - Initialize WMI event logging
  281. * @wmi_handle: WMI handle.
  282. *
  283. * Return: Initialization status
  284. */
  285. #ifdef CONFIG_MCL
  286. static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
  287. {
  288. struct wmi_log_buf_t *cmd_log_buf =
  289. &wmi_handle->log_info.wmi_command_log_buf_info;
  290. struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
  291. &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
  292. struct wmi_log_buf_t *event_log_buf =
  293. &wmi_handle->log_info.wmi_event_log_buf_info;
  294. struct wmi_log_buf_t *rx_event_log_buf =
  295. &wmi_handle->log_info.wmi_rx_event_log_buf_info;
  296. struct wmi_log_buf_t *mgmt_cmd_log_buf =
  297. &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
  298. struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
  299. &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
  300. struct wmi_log_buf_t *mgmt_event_log_buf =
  301. &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
  302. /* WMI commands */
  303. cmd_log_buf->length = 0;
  304. cmd_log_buf->buf_tail_idx = 0;
  305. cmd_log_buf->buf = wmi_command_log_buffer;
  306. cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
  307. cmd_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  308. /* WMI commands TX completed */
  309. cmd_tx_cmpl_log_buf->length = 0;
  310. cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
  311. cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
  312. cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
  313. cmd_tx_cmpl_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  314. /* WMI events when processed */
  315. event_log_buf->length = 0;
  316. event_log_buf->buf_tail_idx = 0;
  317. event_log_buf->buf = wmi_event_log_buffer;
  318. event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
  319. event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  320. /* WMI events when queued */
  321. rx_event_log_buf->length = 0;
  322. rx_event_log_buf->buf_tail_idx = 0;
  323. rx_event_log_buf->buf = wmi_rx_event_log_buffer;
  324. rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
  325. rx_event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  326. /* WMI Management commands */
  327. mgmt_cmd_log_buf->length = 0;
  328. mgmt_cmd_log_buf->buf_tail_idx = 0;
  329. mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
  330. mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
  331. mgmt_cmd_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  332. /* WMI Management commands Tx completed*/
  333. mgmt_cmd_tx_cmp_log_buf->length = 0;
  334. mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
  335. mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
  336. mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
  337. &g_wmi_mgmt_command_tx_cmp_buf_idx;
  338. mgmt_cmd_tx_cmp_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  339. /* WMI Management events when processed*/
  340. mgmt_event_log_buf->length = 0;
  341. mgmt_event_log_buf->buf_tail_idx = 0;
  342. mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer;
  343. mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx;
  344. mgmt_event_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  345. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  346. wmi_handle->log_info.wmi_logging_enable = 1;
  347. return QDF_STATUS_SUCCESS;
  348. }
  349. #else
  350. static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
  351. {
  352. struct wmi_log_buf_t *cmd_log_buf =
  353. &wmi_handle->log_info.wmi_command_log_buf_info;
  354. struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
  355. &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
  356. struct wmi_log_buf_t *event_log_buf =
  357. &wmi_handle->log_info.wmi_event_log_buf_info;
  358. struct wmi_log_buf_t *rx_event_log_buf =
  359. &wmi_handle->log_info.wmi_rx_event_log_buf_info;
  360. struct wmi_log_buf_t *mgmt_cmd_log_buf =
  361. &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
  362. struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
  363. &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
  364. struct wmi_log_buf_t *mgmt_event_log_buf =
  365. &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
  366. wmi_handle->log_info.wmi_logging_enable = 0;
  367. /* WMI commands */
  368. cmd_log_buf->length = 0;
  369. cmd_log_buf->buf_tail_idx = 0;
  370. cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
  371. wmi_log_max_entry * sizeof(struct wmi_command_debug));
  372. cmd_log_buf->size = wmi_log_max_entry;
  373. if (!cmd_log_buf->buf) {
  374. qdf_print("no memory for WMI command log buffer..\n");
  375. return QDF_STATUS_E_NOMEM;
  376. }
  377. cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
  378. /* WMI commands TX completed */
  379. cmd_tx_cmpl_log_buf->length = 0;
  380. cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
  381. cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
  382. wmi_log_max_entry * sizeof(struct wmi_command_debug));
  383. cmd_tx_cmpl_log_buf->size = wmi_log_max_entry;
  384. if (!cmd_tx_cmpl_log_buf->buf) {
  385. qdf_print("no memory for WMI Command Tx Complete log buffer..\n");
  386. return QDF_STATUS_E_NOMEM;
  387. }
  388. cmd_tx_cmpl_log_buf->p_buf_tail_idx =
  389. &cmd_tx_cmpl_log_buf->buf_tail_idx;
  390. /* WMI events when processed */
  391. event_log_buf->length = 0;
  392. event_log_buf->buf_tail_idx = 0;
  393. event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  394. wmi_log_max_entry * sizeof(struct wmi_event_debug));
  395. event_log_buf->size = wmi_log_max_entry;
  396. if (!event_log_buf->buf) {
  397. qdf_print("no memory for WMI Event log buffer..\n");
  398. return QDF_STATUS_E_NOMEM;
  399. }
  400. event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
  401. /* WMI events when queued */
  402. rx_event_log_buf->length = 0;
  403. rx_event_log_buf->buf_tail_idx = 0;
  404. rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  405. wmi_log_max_entry * sizeof(struct wmi_event_debug));
  406. rx_event_log_buf->size = wmi_log_max_entry;
  407. if (!rx_event_log_buf->buf) {
  408. qdf_print("no memory for WMI Event Rx log buffer..\n");
  409. return QDF_STATUS_E_NOMEM;
  410. }
  411. rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
  412. /* WMI Management commands */
  413. mgmt_cmd_log_buf->length = 0;
  414. mgmt_cmd_log_buf->buf_tail_idx = 0;
  415. mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
  416. wmi_mgmt_log_max_entry * sizeof(struct wmi_command_debug));
  417. mgmt_cmd_log_buf->size = wmi_mgmt_log_max_entry;
  418. if (!mgmt_cmd_log_buf->buf) {
  419. qdf_print("no memory for WMI Management Command log buffer..\n");
  420. return QDF_STATUS_E_NOMEM;
  421. }
  422. mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
  423. /* WMI Management commands Tx completed*/
  424. mgmt_cmd_tx_cmp_log_buf->length = 0;
  425. mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
  426. mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
  427. qdf_mem_malloc(
  428. wmi_mgmt_log_max_entry *
  429. sizeof(struct wmi_command_debug));
  430. mgmt_cmd_tx_cmp_log_buf->size = wmi_mgmt_log_max_entry;
  431. if (!mgmt_cmd_tx_cmp_log_buf->buf) {
  432. qdf_print("no memory for WMI Management Command Tx complete log buffer..\n");
  433. return QDF_STATUS_E_NOMEM;
  434. }
  435. mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
  436. &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
  437. /* WMI Management events when processed*/
  438. mgmt_event_log_buf->length = 0;
  439. mgmt_event_log_buf->buf_tail_idx = 0;
  440. mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  441. wmi_mgmt_log_max_entry *
  442. sizeof(struct wmi_event_debug));
  443. mgmt_event_log_buf->size = wmi_mgmt_log_max_entry;
  444. if (!mgmt_event_log_buf->buf) {
  445. qdf_print("no memory for WMI Management Event log buffer..\n");
  446. return QDF_STATUS_E_NOMEM;
  447. }
  448. mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
  449. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  450. wmi_handle->log_info.wmi_logging_enable = 1;
  451. return QDF_STATUS_SUCCESS;
  452. }
  453. #endif
  454. /**
  455. * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
  456. * event logging
  457. * @wmi_handle: WMI handle.
  458. *
  459. * Return: None
  460. */
  461. #ifndef CONFIG_MCL
  462. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
  463. {
  464. if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
  465. qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
  466. if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
  467. qdf_mem_free(
  468. wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
  469. if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
  470. qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
  471. if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
  472. qdf_mem_free(
  473. wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
  474. if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
  475. qdf_mem_free(
  476. wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
  477. if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
  478. qdf_mem_free(
  479. wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
  480. if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
  481. qdf_mem_free(
  482. wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
  483. wmi_handle->log_info.wmi_logging_enable = 0;
  484. qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
  485. }
  486. #else
  487. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
  488. {
  489. /* Do Nothing */
  490. }
  491. #endif
  492. /**
  493. * wmi_print_cmd_log_buffer() - an output agnostic wmi command log printer
  494. * @log_buffer: the command log buffer metadata of the buffer to print
  495. * @count: the maximum number of entries to print
  496. * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
  497. * @print_priv: any data required by the print method, e.g. a file handle
  498. *
  499. * Return: None
  500. */
  501. static void
  502. wmi_print_cmd_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
  503. qdf_abstract_print *print, void *print_priv)
  504. {
  505. static const int data_len =
  506. WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
  507. char str[128];
  508. uint32_t idx;
  509. if (count > log_buffer->size)
  510. count = log_buffer->size;
  511. if (count > log_buffer->length)
  512. count = log_buffer->length;
  513. /* subtract count from index, and wrap if necessary */
  514. idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
  515. idx %= log_buffer->size;
  516. print(print_priv, "Time (seconds) Cmd Id Payload");
  517. while (count) {
  518. struct wmi_command_debug *cmd_log = (struct wmi_command_debug *)
  519. &((struct wmi_command_debug *)log_buffer->buf)[idx];
  520. uint64_t secs, usecs;
  521. int len = 0;
  522. int i;
  523. qdf_log_timestamp_to_secs(cmd_log->time, &secs, &usecs);
  524. len += scnprintf(str + len, sizeof(str) - len,
  525. "% 8lld.%06lld %6u (0x%06x) ",
  526. secs, usecs,
  527. cmd_log->command, cmd_log->command);
  528. for (i = 0; i < data_len; ++i) {
  529. len += scnprintf(str + len, sizeof(str) - len,
  530. "0x%08x ", cmd_log->data[i]);
  531. }
  532. print(print_priv, str);
  533. --count;
  534. ++idx;
  535. if (idx >= log_buffer->size)
  536. idx = 0;
  537. }
  538. }
  539. /**
  540. * wmi_print_event_log_buffer() - an output agnostic wmi event log printer
  541. * @log_buffer: the event log buffer metadata of the buffer to print
  542. * @count: the maximum number of entries to print
  543. * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
  544. * @print_priv: any data required by the print method, e.g. a file handle
  545. *
  546. * Return: None
  547. */
  548. static void
  549. wmi_print_event_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
  550. qdf_abstract_print *print, void *print_priv)
  551. {
  552. static const int data_len =
  553. WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
  554. char str[128];
  555. uint32_t idx;
  556. if (count > log_buffer->size)
  557. count = log_buffer->size;
  558. if (count > log_buffer->length)
  559. count = log_buffer->length;
  560. /* subtract count from index, and wrap if necessary */
  561. idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
  562. idx %= log_buffer->size;
  563. print(print_priv, "Time (seconds) Event Id Payload");
  564. while (count) {
  565. struct wmi_event_debug *event_log = (struct wmi_event_debug *)
  566. &((struct wmi_event_debug *)log_buffer->buf)[idx];
  567. uint64_t secs, usecs;
  568. int len = 0;
  569. int i;
  570. qdf_log_timestamp_to_secs(event_log->time, &secs, &usecs);
  571. len += scnprintf(str + len, sizeof(str) - len,
  572. "% 8lld.%06lld %6u (0x%06x) ",
  573. secs, usecs,
  574. event_log->event, event_log->event);
  575. for (i = 0; i < data_len; ++i) {
  576. len += scnprintf(str + len, sizeof(str) - len,
  577. "0x%08x ", event_log->data[i]);
  578. }
  579. print(print_priv, str);
  580. --count;
  581. ++idx;
  582. if (idx >= log_buffer->size)
  583. idx = 0;
  584. }
  585. }
  586. inline void
  587. wmi_print_cmd_log(wmi_unified_t wmi, uint32_t count,
  588. qdf_abstract_print *print, void *print_priv)
  589. {
  590. wmi_print_cmd_log_buffer(
  591. &wmi->log_info.wmi_command_log_buf_info,
  592. count, print, print_priv);
  593. }
  594. inline void
  595. wmi_print_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
  596. qdf_abstract_print *print, void *print_priv)
  597. {
  598. wmi_print_cmd_log_buffer(
  599. &wmi->log_info.wmi_command_tx_cmp_log_buf_info,
  600. count, print, print_priv);
  601. }
  602. inline void
  603. wmi_print_mgmt_cmd_log(wmi_unified_t wmi, uint32_t count,
  604. qdf_abstract_print *print, void *print_priv)
  605. {
  606. wmi_print_cmd_log_buffer(
  607. &wmi->log_info.wmi_mgmt_command_log_buf_info,
  608. count, print, print_priv);
  609. }
  610. inline void
  611. wmi_print_mgmt_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
  612. qdf_abstract_print *print, void *print_priv)
  613. {
  614. wmi_print_cmd_log_buffer(
  615. &wmi->log_info.wmi_mgmt_command_tx_cmp_log_buf_info,
  616. count, print, print_priv);
  617. }
  618. inline void
  619. wmi_print_event_log(wmi_unified_t wmi, uint32_t count,
  620. qdf_abstract_print *print, void *print_priv)
  621. {
  622. wmi_print_event_log_buffer(
  623. &wmi->log_info.wmi_event_log_buf_info,
  624. count, print, print_priv);
  625. }
  626. inline void
  627. wmi_print_rx_event_log(wmi_unified_t wmi, uint32_t count,
  628. qdf_abstract_print *print, void *print_priv)
  629. {
  630. wmi_print_event_log_buffer(
  631. &wmi->log_info.wmi_rx_event_log_buf_info,
  632. count, print, print_priv);
  633. }
  634. inline void
  635. wmi_print_mgmt_event_log(wmi_unified_t wmi, uint32_t count,
  636. qdf_abstract_print *print, void *print_priv)
  637. {
  638. wmi_print_event_log_buffer(
  639. &wmi->log_info.wmi_mgmt_event_log_buf_info,
  640. count, print, print_priv);
  641. }
  642. #ifdef CONFIG_MCL
  643. const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0"};
  644. #else
  645. const int8_t * const debugfs_dir[MAX_WMI_INSTANCES] = {"WMI0", "WMI1", "WMI2"};
  646. #endif
  647. /* debugfs routines*/
  648. /**
  649. * debug_wmi_##func_base##_show() - debugfs functions to display content of
  650. * command and event buffers. Macro uses max buffer length to display
  651. * buffer when it is wraparound.
  652. *
  653. * @m: debugfs handler to access wmi_handle
  654. * @v: Variable arguments (not used)
  655. *
  656. * Return: Length of characters printed
  657. */
  658. #define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
  659. static int debug_wmi_##func_base##_show(struct seq_file *m, \
  660. void *v) \
  661. { \
  662. wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
  663. struct wmi_log_buf_t *wmi_log = \
  664. &wmi_handle->log_info.wmi_##func_base##_buf_info;\
  665. int pos, nread, outlen; \
  666. int i; \
  667. \
  668. qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
  669. if (!wmi_log->length) { \
  670. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
  671. return seq_printf(m, \
  672. "no elements to read from ring buffer!\n"); \
  673. } \
  674. \
  675. if (wmi_log->length <= wmi_ring_size) \
  676. nread = wmi_log->length; \
  677. else \
  678. nread = wmi_ring_size; \
  679. \
  680. if (*(wmi_log->p_buf_tail_idx) == 0) \
  681. /* tail can be 0 after wrap-around */ \
  682. pos = wmi_ring_size - 1; \
  683. else \
  684. pos = *(wmi_log->p_buf_tail_idx) - 1; \
  685. \
  686. outlen = seq_printf(m, "Length = %d\n", wmi_log->length);\
  687. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
  688. while (nread--) { \
  689. struct wmi_command_debug *wmi_record; \
  690. \
  691. wmi_record = (struct wmi_command_debug *) \
  692. &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
  693. outlen += seq_printf(m, "CMD ID = %x\n", \
  694. (wmi_record->command)); \
  695. outlen += seq_printf(m, "CMD = "); \
  696. for (i = 0; i < (wmi_record_max_length/ \
  697. sizeof(uint32_t)); i++) \
  698. outlen += seq_printf(m, "%x ", \
  699. wmi_record->data[i]); \
  700. outlen += seq_printf(m, "\n"); \
  701. \
  702. if (pos == 0) \
  703. pos = wmi_ring_size - 1; \
  704. else \
  705. pos--; \
  706. } \
  707. \
  708. return outlen; \
  709. } \
  710. #define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
  711. static int debug_wmi_##func_base##_show(struct seq_file *m, \
  712. void *v) \
  713. { \
  714. wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
  715. struct wmi_log_buf_t *wmi_log = \
  716. &wmi_handle->log_info.wmi_##func_base##_buf_info;\
  717. int pos, nread, outlen; \
  718. int i; \
  719. \
  720. qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
  721. if (!wmi_log->length) { \
  722. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
  723. return seq_printf(m, \
  724. "no elements to read from ring buffer!\n"); \
  725. } \
  726. \
  727. if (wmi_log->length <= wmi_ring_size) \
  728. nread = wmi_log->length; \
  729. else \
  730. nread = wmi_ring_size; \
  731. \
  732. if (*(wmi_log->p_buf_tail_idx) == 0) \
  733. /* tail can be 0 after wrap-around */ \
  734. pos = wmi_ring_size - 1; \
  735. else \
  736. pos = *(wmi_log->p_buf_tail_idx) - 1; \
  737. \
  738. outlen = seq_printf(m, "Length = %d\n", wmi_log->length);\
  739. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
  740. while (nread--) { \
  741. struct wmi_event_debug *wmi_record; \
  742. \
  743. wmi_record = (struct wmi_event_debug *) \
  744. &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
  745. outlen += seq_printf(m, "Event ID = %x\n", \
  746. (wmi_record->event)); \
  747. outlen += seq_printf(m, "CMD = "); \
  748. for (i = 0; i < (wmi_record_max_length/ \
  749. sizeof(uint32_t)); i++) \
  750. outlen += seq_printf(m, "%x ", \
  751. wmi_record->data[i]); \
  752. outlen += seq_printf(m, "\n"); \
  753. \
  754. if (pos == 0) \
  755. pos = wmi_ring_size - 1; \
  756. else \
  757. pos--; \
  758. } \
  759. \
  760. return outlen; \
  761. }
  762. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
  763. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
  764. GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
  765. GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
  766. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
  767. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
  768. wmi_display_size);
  769. GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
  770. /**
  771. * debug_wmi_enable_show() - debugfs functions to display enable state of
  772. * wmi logging feature.
  773. *
  774. * @m: debugfs handler to access wmi_handle
  775. * @v: Variable arguments (not used)
  776. *
  777. * Return: always 1
  778. */
  779. static int debug_wmi_enable_show(struct seq_file *m, void *v)
  780. {
  781. wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
  782. return seq_printf(m, "%d\n", wmi_handle->log_info.wmi_logging_enable);
  783. }
  784. /**
  785. * debug_wmi_log_size_show() - debugfs functions to display configured size of
  786. * wmi logging command/event buffer and management command/event buffer.
  787. *
  788. * @m: debugfs handler to access wmi_handle
  789. * @v: Variable arguments (not used)
  790. *
  791. * Return: Length of characters printed
  792. */
  793. static int debug_wmi_log_size_show(struct seq_file *m, void *v)
  794. {
  795. seq_printf(m, "WMI command/event log max size:%d\n", wmi_log_max_entry);
  796. return seq_printf(m, "WMI management command/events log max size:%d\n",
  797. wmi_mgmt_log_max_entry);
  798. }
  799. /**
  800. * debug_wmi_##func_base##_write() - debugfs functions to clear
  801. * wmi logging command/event buffer and management command/event buffer.
  802. *
  803. * @file: file handler to access wmi_handle
  804. * @buf: received data buffer
  805. * @count: length of received buffer
  806. * @ppos: Not used
  807. *
  808. * Return: count
  809. */
  810. #define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
  811. static ssize_t debug_wmi_##func_base##_write(struct file *file, \
  812. const char __user *buf, \
  813. size_t count, loff_t *ppos) \
  814. { \
  815. int k, ret; \
  816. wmi_unified_t wmi_handle = \
  817. ((struct seq_file *)file->private_data)->private;\
  818. struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
  819. wmi_##func_base##_buf_info; \
  820. \
  821. ret = sscanf(buf, "%d", &k); \
  822. if ((ret != 1) || (k != 0)) { \
  823. qdf_print("Wrong input, echo 0 to clear the wmi buffer\n");\
  824. return -EINVAL; \
  825. } \
  826. \
  827. qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
  828. qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
  829. sizeof(struct wmi_record_type)); \
  830. wmi_log->length = 0; \
  831. *(wmi_log->p_buf_tail_idx) = 0; \
  832. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
  833. \
  834. return count; \
  835. }
  836. GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
  837. wmi_command_debug);
  838. GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
  839. wmi_command_debug);
  840. GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
  841. wmi_event_debug);
  842. GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
  843. wmi_event_debug);
  844. GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
  845. wmi_command_debug);
  846. GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
  847. wmi_mgmt_log_max_entry, wmi_command_debug);
  848. GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
  849. wmi_event_debug);
  850. /**
  851. * debug_wmi_enable_write() - debugfs functions to enable/disable
  852. * wmi logging feature.
  853. *
  854. * @file: file handler to access wmi_handle
  855. * @buf: received data buffer
  856. * @count: length of received buffer
  857. * @ppos: Not used
  858. *
  859. * Return: count
  860. */
  861. static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
  862. size_t count, loff_t *ppos)
  863. {
  864. wmi_unified_t wmi_handle =
  865. ((struct seq_file *)file->private_data)->private;
  866. int k, ret;
  867. ret = sscanf(buf, "%d", &k);
  868. if ((ret != 1) || ((k != 0) && (k != 1)))
  869. return -EINVAL;
  870. wmi_handle->log_info.wmi_logging_enable = k;
  871. return count;
  872. }
  873. /**
  874. * debug_wmi_log_size_write() - reserved.
  875. *
  876. * @file: file handler to access wmi_handle
  877. * @buf: received data buffer
  878. * @count: length of received buffer
  879. * @ppos: Not used
  880. *
  881. * Return: count
  882. */
  883. static ssize_t debug_wmi_log_size_write(struct file *file,
  884. const char __user *buf, size_t count, loff_t *ppos)
  885. {
  886. return -EINVAL;
  887. }
  888. /* Structure to maintain debug information */
  889. struct wmi_debugfs_info {
  890. const char *name;
  891. struct dentry *de[MAX_WMI_INSTANCES];
  892. const struct file_operations *ops;
  893. };
  894. #define DEBUG_FOO(func_base) { .name = #func_base, \
  895. .ops = &debug_##func_base##_ops }
  896. /**
  897. * debug_##func_base##_open() - Open debugfs entry for respective command
  898. * and event buffer.
  899. *
  900. * @inode: node for debug dir entry
  901. * @file: file handler
  902. *
  903. * Return: open status
  904. */
  905. #define GENERATE_DEBUG_STRUCTS(func_base) \
  906. static int debug_##func_base##_open(struct inode *inode, \
  907. struct file *file) \
  908. { \
  909. return single_open(file, debug_##func_base##_show, \
  910. inode->i_private); \
  911. } \
  912. \
  913. \
  914. static struct file_operations debug_##func_base##_ops = { \
  915. .open = debug_##func_base##_open, \
  916. .read = seq_read, \
  917. .llseek = seq_lseek, \
  918. .write = debug_##func_base##_write, \
  919. .release = single_release, \
  920. };
  921. GENERATE_DEBUG_STRUCTS(wmi_command_log);
  922. GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
  923. GENERATE_DEBUG_STRUCTS(wmi_event_log);
  924. GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
  925. GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
  926. GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
  927. GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
  928. GENERATE_DEBUG_STRUCTS(wmi_enable);
  929. GENERATE_DEBUG_STRUCTS(wmi_log_size);
  930. struct wmi_debugfs_info wmi_debugfs_infos[] = {
  931. DEBUG_FOO(wmi_command_log),
  932. DEBUG_FOO(wmi_command_tx_cmp_log),
  933. DEBUG_FOO(wmi_event_log),
  934. DEBUG_FOO(wmi_rx_event_log),
  935. DEBUG_FOO(wmi_mgmt_command_log),
  936. DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
  937. DEBUG_FOO(wmi_mgmt_event_log),
  938. DEBUG_FOO(wmi_enable),
  939. DEBUG_FOO(wmi_log_size),
  940. };
  941. #define NUM_DEBUG_INFOS (sizeof(wmi_debugfs_infos) / \
  942. sizeof(wmi_debugfs_infos[0]))
  943. /**
  944. * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
  945. *
  946. * @wmi_handle: wmi handle
  947. * @par_entry: debug directory entry
  948. * @id: Index to debug info data array
  949. *
  950. * Return: none
  951. */
  952. static void wmi_debugfs_create(wmi_unified_t wmi_handle,
  953. struct dentry *par_entry, int id)
  954. {
  955. int i;
  956. if (par_entry == NULL || (id < 0) || (id >= MAX_WMI_INSTANCES))
  957. goto out;
  958. for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
  959. wmi_debugfs_infos[i].de[id] = debugfs_create_file(
  960. wmi_debugfs_infos[i].name, 0644, par_entry,
  961. wmi_handle, wmi_debugfs_infos[i].ops);
  962. if (wmi_debugfs_infos[i].de[id] == NULL) {
  963. qdf_print("%s: debug Entry creation failed!\n",
  964. __func__);
  965. goto out;
  966. }
  967. }
  968. return;
  969. out:
  970. qdf_print("%s: debug Entry creation failed!\n", __func__);
  971. wmi_log_buffer_free(wmi_handle);
  972. return;
  973. }
  974. /**
  975. * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
  976. * @wmi_handle: wmi handle
  977. * @dentry: debugfs directory entry
  978. * @id: Index to debug info data array
  979. *
  980. * Return: none
  981. */
  982. static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
  983. {
  984. int i;
  985. struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
  986. int id = wmi_handle->log_info.wmi_instance_id;
  987. if (dentry && (!(id < 0) || (id >= MAX_WMI_INSTANCES))) {
  988. for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
  989. if (wmi_debugfs_infos[i].de[id])
  990. wmi_debugfs_infos[i].de[id] = NULL;
  991. }
  992. }
  993. if (dentry)
  994. debugfs_remove_recursive(dentry);
  995. }
  996. /**
  997. * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
  998. * create debugfs enteries.
  999. *
  1000. * @h: wmi handler
  1001. *
  1002. * Return: init status
  1003. */
  1004. static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle)
  1005. {
  1006. static int wmi_index;
  1007. if (wmi_index < MAX_WMI_INSTANCES)
  1008. wmi_handle->log_info.wmi_log_debugfs_dir =
  1009. debugfs_create_dir(debugfs_dir[wmi_index], NULL);
  1010. if (wmi_handle->log_info.wmi_log_debugfs_dir == NULL) {
  1011. qdf_print("error while creating debugfs dir for %s\n",
  1012. debugfs_dir[wmi_index]);
  1013. return QDF_STATUS_E_FAILURE;
  1014. }
  1015. wmi_debugfs_create(wmi_handle, wmi_handle->log_info.wmi_log_debugfs_dir,
  1016. wmi_index);
  1017. wmi_handle->log_info.wmi_instance_id = wmi_index++;
  1018. return QDF_STATUS_SUCCESS;
  1019. }
  1020. /**
  1021. * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
  1022. *
  1023. * @wmi_handle: wmi handle
  1024. * @cmd: mgmt command
  1025. * @header: pointer to 802.11 header
  1026. * @vdev_id: vdev id
  1027. * @chanfreq: channel frequency
  1028. *
  1029. * Return: none
  1030. */
  1031. void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
  1032. void *header, uint32_t vdev_id, uint32_t chanfreq)
  1033. {
  1034. uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
  1035. data[0] = ((struct wmi_command_header *)header)->type;
  1036. data[1] = ((struct wmi_command_header *)header)->sub_type;
  1037. data[2] = vdev_id;
  1038. data[3] = chanfreq;
  1039. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1040. WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, data);
  1041. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1042. }
  1043. #else
  1044. /**
  1045. * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
  1046. * @wmi_handle: wmi handle
  1047. * @dentry: debugfs directory entry
  1048. * @id: Index to debug info data array
  1049. *
  1050. * Return: none
  1051. */
  1052. static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
  1053. void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
  1054. void *header, uint32_t vdev_id, uint32_t chanfreq) { }
  1055. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
  1056. #endif /*WMI_INTERFACE_EVENT_LOGGING */
  1057. int wmi_get_host_credits(wmi_unified_t wmi_handle);
  1058. /* WMI buffer APIs */
  1059. #ifdef MEMORY_DEBUG
  1060. wmi_buf_t
  1061. wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint16_t len, uint8_t *file_name,
  1062. uint32_t line_num)
  1063. {
  1064. wmi_buf_t wmi_buf;
  1065. if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
  1066. QDF_ASSERT(0);
  1067. return NULL;
  1068. }
  1069. wmi_buf = qdf_nbuf_alloc_debug(NULL,
  1070. roundup(len + WMI_MIN_HEAD_ROOM, 4),
  1071. WMI_MIN_HEAD_ROOM, 4, false, file_name,
  1072. line_num);
  1073. if (!wmi_buf)
  1074. return NULL;
  1075. /* Clear the wmi buffer */
  1076. OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
  1077. /*
  1078. * Set the length of the buffer to match the allocation size.
  1079. */
  1080. qdf_nbuf_set_pktlen(wmi_buf, len);
  1081. return wmi_buf;
  1082. }
  1083. void wmi_buf_free(wmi_buf_t net_buf)
  1084. {
  1085. qdf_nbuf_free(net_buf);
  1086. }
  1087. #else
  1088. wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint16_t len)
  1089. {
  1090. wmi_buf_t wmi_buf;
  1091. if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
  1092. QDF_ASSERT(0);
  1093. return NULL;
  1094. }
  1095. wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
  1096. WMI_MIN_HEAD_ROOM, 4, false);
  1097. if (!wmi_buf)
  1098. return NULL;
  1099. /* Clear the wmi buffer */
  1100. OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
  1101. /*
  1102. * Set the length of the buffer to match the allocation size.
  1103. */
  1104. qdf_nbuf_set_pktlen(wmi_buf, len);
  1105. return wmi_buf;
  1106. }
  1107. void wmi_buf_free(wmi_buf_t net_buf)
  1108. {
  1109. qdf_nbuf_free(net_buf);
  1110. }
  1111. #endif
  1112. /**
  1113. * wmi_get_max_msg_len() - get maximum WMI message length
  1114. * @wmi_handle: WMI handle.
  1115. *
  1116. * This function returns the maximum WMI message length
  1117. *
  1118. * Return: maximum WMI message length
  1119. */
  1120. uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
  1121. {
  1122. return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
  1123. }
  1124. #ifdef CONFIG_MCL
  1125. static uint8_t *wmi_id_to_name(uint32_t wmi_command)
  1126. {
  1127. switch (wmi_command) {
  1128. /* initialize the wlan sub system */
  1129. CASE_RETURN_STRING(WMI_INIT_CMDID);
  1130. /* Scan specific commands */
  1131. /* start scan request to FW */
  1132. CASE_RETURN_STRING(WMI_START_SCAN_CMDID);
  1133. /* stop scan request to FW */
  1134. CASE_RETURN_STRING(WMI_STOP_SCAN_CMDID);
  1135. /* full list of channels as defined by the regulatory
  1136. * that will be used by scanner */
  1137. CASE_RETURN_STRING(WMI_SCAN_CHAN_LIST_CMDID);
  1138. /* overwrite default priority table in scan scheduler */
  1139. CASE_RETURN_STRING(WMI_SCAN_SCH_PRIO_TBL_CMDID);
  1140. /* This command to adjust the priority and min.max_rest_time
  1141. * of an on ongoing scan request.
  1142. */
  1143. CASE_RETURN_STRING(WMI_SCAN_UPDATE_REQUEST_CMDID);
  1144. /* PDEV(physical device) specific commands */
  1145. /* set regulatorty ctl id used by FW to determine the exact
  1146. * ctl power limits */
  1147. CASE_RETURN_STRING(WMI_PDEV_SET_REGDOMAIN_CMDID);
  1148. /* set channel. mainly used for supporting monitor mode */
  1149. CASE_RETURN_STRING(WMI_PDEV_SET_CHANNEL_CMDID);
  1150. /* set pdev specific parameters */
  1151. CASE_RETURN_STRING(WMI_PDEV_SET_PARAM_CMDID);
  1152. /* enable packet log */
  1153. CASE_RETURN_STRING(WMI_PDEV_PKTLOG_ENABLE_CMDID);
  1154. /* disable packet log*/
  1155. CASE_RETURN_STRING(WMI_PDEV_PKTLOG_DISABLE_CMDID);
  1156. /* set wmm parameters */
  1157. CASE_RETURN_STRING(WMI_PDEV_SET_WMM_PARAMS_CMDID);
  1158. /* set HT cap ie that needs to be carried probe requests
  1159. * HT/VHT channels */
  1160. CASE_RETURN_STRING(WMI_PDEV_SET_HT_CAP_IE_CMDID);
  1161. /* set VHT cap ie that needs to be carried on probe
  1162. * requests on VHT channels */
  1163. CASE_RETURN_STRING(WMI_PDEV_SET_VHT_CAP_IE_CMDID);
  1164. /* Command to send the DSCP-to-TID map to the target */
  1165. CASE_RETURN_STRING(WMI_PDEV_SET_DSCP_TID_MAP_CMDID);
  1166. /* set quiet ie parameters. primarily used in AP mode */
  1167. CASE_RETURN_STRING(WMI_PDEV_SET_QUIET_MODE_CMDID);
  1168. /* Enable/Disable Green AP Power Save */
  1169. CASE_RETURN_STRING(WMI_PDEV_GREEN_AP_PS_ENABLE_CMDID);
  1170. /* get TPC config for the current operating channel */
  1171. CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CONFIG_CMDID);
  1172. /* set the base MAC address for the physical device before
  1173. * a VDEV is created. For firmware that does not support
  1174. * this feature and this command, the pdev MAC address will
  1175. * not be changed. */
  1176. CASE_RETURN_STRING(WMI_PDEV_SET_BASE_MACADDR_CMDID);
  1177. /* eeprom content dump , the same to bdboard data */
  1178. CASE_RETURN_STRING(WMI_PDEV_DUMP_CMDID);
  1179. /* VDEV(virtual device) specific commands */
  1180. /* vdev create */
  1181. CASE_RETURN_STRING(WMI_VDEV_CREATE_CMDID);
  1182. /* vdev delete */
  1183. CASE_RETURN_STRING(WMI_VDEV_DELETE_CMDID);
  1184. /* vdev start request */
  1185. CASE_RETURN_STRING(WMI_VDEV_START_REQUEST_CMDID);
  1186. /* vdev restart request (RX only, NO TX, used for CAC period)*/
  1187. CASE_RETURN_STRING(WMI_VDEV_RESTART_REQUEST_CMDID);
  1188. /* vdev up request */
  1189. CASE_RETURN_STRING(WMI_VDEV_UP_CMDID);
  1190. /* vdev stop request */
  1191. CASE_RETURN_STRING(WMI_VDEV_STOP_CMDID);
  1192. /* vdev down request */
  1193. CASE_RETURN_STRING(WMI_VDEV_DOWN_CMDID);
  1194. /* set a vdev param */
  1195. CASE_RETURN_STRING(WMI_VDEV_SET_PARAM_CMDID);
  1196. /* set a key (used for setting per peer unicast
  1197. * and per vdev multicast) */
  1198. CASE_RETURN_STRING(WMI_VDEV_INSTALL_KEY_CMDID);
  1199. /* wnm sleep mode command */
  1200. CASE_RETURN_STRING(WMI_VDEV_WNM_SLEEPMODE_CMDID);
  1201. CASE_RETURN_STRING(WMI_VDEV_WMM_ADDTS_CMDID);
  1202. CASE_RETURN_STRING(WMI_VDEV_WMM_DELTS_CMDID);
  1203. CASE_RETURN_STRING(WMI_VDEV_SET_WMM_PARAMS_CMDID);
  1204. CASE_RETURN_STRING(WMI_VDEV_SET_GTX_PARAMS_CMDID);
  1205. CASE_RETURN_STRING(WMI_VDEV_IPSEC_NATKEEPALIVE_FILTER_CMDID);
  1206. CASE_RETURN_STRING(WMI_VDEV_PLMREQ_START_CMDID);
  1207. CASE_RETURN_STRING(WMI_VDEV_PLMREQ_STOP_CMDID);
  1208. CASE_RETURN_STRING(WMI_VDEV_TSF_TSTAMP_ACTION_CMDID);
  1209. CASE_RETURN_STRING(WMI_VDEV_SET_IE_CMDID);
  1210. /* peer specific commands */
  1211. /** create a peer */
  1212. CASE_RETURN_STRING(WMI_PEER_CREATE_CMDID);
  1213. /** delete a peer */
  1214. CASE_RETURN_STRING(WMI_PEER_DELETE_CMDID);
  1215. /** flush specific tid queues of a peer */
  1216. CASE_RETURN_STRING(WMI_PEER_FLUSH_TIDS_CMDID);
  1217. /** set a parameter of a peer */
  1218. CASE_RETURN_STRING(WMI_PEER_SET_PARAM_CMDID);
  1219. /* set peer to associated state. will cary all parameters
  1220. * determined during assocication time */
  1221. CASE_RETURN_STRING(WMI_PEER_ASSOC_CMDID);
  1222. /* add a wds (4 address ) entry. used only for testing
  1223. * WDS feature on AP products */
  1224. CASE_RETURN_STRING(WMI_PEER_ADD_WDS_ENTRY_CMDID);
  1225. /* remove wds (4 address ) entry. used only for testing WDS
  1226. * feature on AP products */
  1227. CASE_RETURN_STRING(WMI_PEER_REMOVE_WDS_ENTRY_CMDID);
  1228. /* set up mcast info for multicast to unicast conversion */
  1229. CASE_RETURN_STRING(WMI_PEER_MCAST_GROUP_CMDID);
  1230. /* request peer info from FW to get PEER_INFO_EVENTID */
  1231. CASE_RETURN_STRING(WMI_PEER_INFO_REQ_CMDID);
  1232. /* beacon/management specific commands */
  1233. /* transmit beacon by reference. used for transmitting beacon
  1234. * on low latency interface like pcie */
  1235. CASE_RETURN_STRING(WMI_BCN_TX_CMDID);
  1236. /* transmit beacon by value */
  1237. CASE_RETURN_STRING(WMI_PDEV_SEND_BCN_CMDID);
  1238. /* set the beacon template. used in beacon offload mode to setup
  1239. * the common beacon template with the FW to be used by FW to
  1240. * generate beacons */
  1241. CASE_RETURN_STRING(WMI_BCN_TMPL_CMDID);
  1242. /* set beacon filter with FW */
  1243. CASE_RETURN_STRING(WMI_BCN_FILTER_RX_CMDID);
  1244. /* enable/disable filtering of probe requests in the firmware */
  1245. CASE_RETURN_STRING(WMI_PRB_REQ_FILTER_RX_CMDID);
  1246. /* transmit management frame by value. will be deprecated */
  1247. CASE_RETURN_STRING(WMI_MGMT_TX_CMDID);
  1248. /* set the probe response template. used in beacon offload mode
  1249. * to setup the common probe response template with the FW to
  1250. * be used by FW to generate probe responses */
  1251. CASE_RETURN_STRING(WMI_PRB_TMPL_CMDID);
  1252. /* commands to directly control ba negotiation directly from
  1253. * host. only used in test mode */
  1254. /* turn off FW Auto addba mode and let host control addba */
  1255. CASE_RETURN_STRING(WMI_ADDBA_CLEAR_RESP_CMDID);
  1256. /* send add ba request */
  1257. CASE_RETURN_STRING(WMI_ADDBA_SEND_CMDID);
  1258. CASE_RETURN_STRING(WMI_ADDBA_STATUS_CMDID);
  1259. /* send del ba */
  1260. CASE_RETURN_STRING(WMI_DELBA_SEND_CMDID);
  1261. /* set add ba response will be used by FW to generate
  1262. * addba response*/
  1263. CASE_RETURN_STRING(WMI_ADDBA_SET_RESP_CMDID);
  1264. /* send single VHT MPDU with AMSDU */
  1265. CASE_RETURN_STRING(WMI_SEND_SINGLEAMSDU_CMDID);
  1266. /* Station power save specific config */
  1267. /* enable/disable station powersave */
  1268. CASE_RETURN_STRING(WMI_STA_POWERSAVE_MODE_CMDID);
  1269. /* set station power save specific parameter */
  1270. CASE_RETURN_STRING(WMI_STA_POWERSAVE_PARAM_CMDID);
  1271. /* set station mimo powersave mode */
  1272. CASE_RETURN_STRING(WMI_STA_MIMO_PS_MODE_CMDID);
  1273. /* DFS-specific commands */
  1274. /* enable DFS (radar detection)*/
  1275. CASE_RETURN_STRING(WMI_PDEV_DFS_ENABLE_CMDID);
  1276. /* disable DFS (radar detection)*/
  1277. CASE_RETURN_STRING(WMI_PDEV_DFS_DISABLE_CMDID);
  1278. /* enable DFS phyerr/parse filter offload */
  1279. CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_ENA_CMDID);
  1280. /* enable DFS phyerr/parse filter offload */
  1281. CASE_RETURN_STRING(WMI_DFS_PHYERR_FILTER_DIS_CMDID);
  1282. /* Roaming specific commands */
  1283. /* set roam scan mode */
  1284. CASE_RETURN_STRING(WMI_ROAM_SCAN_MODE);
  1285. /* set roam scan rssi threshold below which roam
  1286. * scan is enabled */
  1287. CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_THRESHOLD);
  1288. /* set roam scan period for periodic roam scan mode */
  1289. CASE_RETURN_STRING(WMI_ROAM_SCAN_PERIOD);
  1290. /* set roam scan trigger rssi change threshold */
  1291. CASE_RETURN_STRING(WMI_ROAM_SCAN_RSSI_CHANGE_THRESHOLD);
  1292. /* set roam AP profile */
  1293. CASE_RETURN_STRING(WMI_ROAM_AP_PROFILE);
  1294. /* set channel list for roam scans */
  1295. CASE_RETURN_STRING(WMI_ROAM_CHAN_LIST);
  1296. /* offload scan specific commands */
  1297. /* set offload scan AP profile */
  1298. CASE_RETURN_STRING(WMI_OFL_SCAN_ADD_AP_PROFILE);
  1299. /* remove offload scan AP profile */
  1300. CASE_RETURN_STRING(WMI_OFL_SCAN_REMOVE_AP_PROFILE);
  1301. /* set offload scan period */
  1302. CASE_RETURN_STRING(WMI_OFL_SCAN_PERIOD);
  1303. /* P2P specific commands */
  1304. /* set P2P device info. FW will used by FW to create P2P IE
  1305. * to be carried in probe response generated during p2p listen
  1306. * and for p2p discoverability */
  1307. CASE_RETURN_STRING(WMI_P2P_DEV_SET_DEVICE_INFO);
  1308. /* enable/disable p2p discoverability on STA/AP VDEVs */
  1309. CASE_RETURN_STRING(WMI_P2P_DEV_SET_DISCOVERABILITY);
  1310. /* set p2p ie to be carried in beacons generated by FW for GO */
  1311. CASE_RETURN_STRING(WMI_P2P_GO_SET_BEACON_IE);
  1312. /* set p2p ie to be carried in probe response frames generated
  1313. * by FW for GO */
  1314. CASE_RETURN_STRING(WMI_P2P_GO_SET_PROBE_RESP_IE);
  1315. /* set the vendor specific p2p ie data.
  1316. * FW will use this to parse the P2P NoA
  1317. * attribute in the beacons/probe responses received.
  1318. */
  1319. CASE_RETURN_STRING(WMI_P2P_SET_VENDOR_IE_DATA_CMDID);
  1320. /* set the configure of p2p find offload */
  1321. CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_CONFIG_CMDID);
  1322. /* set the vendor specific p2p ie data for p2p find offload */
  1323. CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_APPIE_CMDID);
  1324. /* set the BSSID/device name pattern of p2p find offload */
  1325. CASE_RETURN_STRING(WMI_P2P_DISC_OFFLOAD_PATTERN_CMDID);
  1326. /* set OppPS related parameters **/
  1327. CASE_RETURN_STRING(WMI_P2P_SET_OPPPS_PARAM_CMDID);
  1328. /* AP power save specific config
  1329. * set AP power save specific param */
  1330. CASE_RETURN_STRING(WMI_AP_PS_PEER_PARAM_CMDID);
  1331. /* set AP UAPSD coex pecific param */
  1332. CASE_RETURN_STRING(WMI_AP_PS_PEER_UAPSD_COEX_CMDID);
  1333. /* Rate-control specific commands */
  1334. CASE_RETURN_STRING(WMI_PEER_RATE_RETRY_SCHED_CMDID);
  1335. /* WLAN Profiling commands. */
  1336. CASE_RETURN_STRING(WMI_WLAN_PROFILE_TRIGGER_CMDID);
  1337. CASE_RETURN_STRING(WMI_WLAN_PROFILE_SET_HIST_INTVL_CMDID);
  1338. CASE_RETURN_STRING(WMI_WLAN_PROFILE_GET_PROFILE_DATA_CMDID);
  1339. CASE_RETURN_STRING(WMI_WLAN_PROFILE_ENABLE_PROFILE_ID_CMDID);
  1340. CASE_RETURN_STRING(WMI_WLAN_PROFILE_LIST_PROFILE_ID_CMDID);
  1341. /* Suspend resume command Ids */
  1342. CASE_RETURN_STRING(WMI_PDEV_SUSPEND_CMDID);
  1343. CASE_RETURN_STRING(WMI_PDEV_RESUME_CMDID);
  1344. /* Beacon filter commands */
  1345. /* add a beacon filter */
  1346. CASE_RETURN_STRING(WMI_ADD_BCN_FILTER_CMDID);
  1347. /* remove a beacon filter */
  1348. CASE_RETURN_STRING(WMI_RMV_BCN_FILTER_CMDID);
  1349. /* WOW Specific WMI commands */
  1350. /* add pattern for awake */
  1351. CASE_RETURN_STRING(WMI_WOW_ADD_WAKE_PATTERN_CMDID);
  1352. /* deleta a wake pattern */
  1353. CASE_RETURN_STRING(WMI_WOW_DEL_WAKE_PATTERN_CMDID);
  1354. /* enable/deisable wake event */
  1355. CASE_RETURN_STRING(WMI_WOW_ENABLE_DISABLE_WAKE_EVENT_CMDID);
  1356. /* enable WOW */
  1357. CASE_RETURN_STRING(WMI_WOW_ENABLE_CMDID);
  1358. /* host woke up from sleep event to FW. Generated in response
  1359. * to WOW Hardware event */
  1360. CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID);
  1361. /* RTT measurement related cmd */
  1362. /* reques to make an RTT measurement */
  1363. CASE_RETURN_STRING(WMI_RTT_MEASREQ_CMDID);
  1364. /* reques to report a tsf measurement */
  1365. CASE_RETURN_STRING(WMI_RTT_TSF_CMDID);
  1366. /* spectral scan command */
  1367. /* configure spectral scan */
  1368. CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_CONFIGURE_CMDID);
  1369. /* enable/disable spectral scan and trigger */
  1370. CASE_RETURN_STRING(WMI_VDEV_SPECTRAL_SCAN_ENABLE_CMDID);
  1371. /* F/W stats */
  1372. /* one time request for stats */
  1373. CASE_RETURN_STRING(WMI_REQUEST_STATS_CMDID);
  1374. /* Push MCC Adaptive Scheduler Stats to Firmware */
  1375. CASE_RETURN_STRING(WMI_MCC_SCHED_TRAFFIC_STATS_CMDID);
  1376. /* ARP OFFLOAD REQUEST*/
  1377. CASE_RETURN_STRING(WMI_SET_ARP_NS_OFFLOAD_CMDID);
  1378. /* Proactive ARP Response Add Pattern Command*/
  1379. CASE_RETURN_STRING(WMI_ADD_PROACTIVE_ARP_RSP_PATTERN_CMDID);
  1380. /* Proactive ARP Response Del Pattern Command*/
  1381. CASE_RETURN_STRING(WMI_DEL_PROACTIVE_ARP_RSP_PATTERN_CMDID);
  1382. /* NS offload confid*/
  1383. CASE_RETURN_STRING(WMI_NETWORK_LIST_OFFLOAD_CONFIG_CMDID);
  1384. /* GTK offload Specific WMI commands */
  1385. CASE_RETURN_STRING(WMI_GTK_OFFLOAD_CMDID);
  1386. /* CSA offload Specific WMI commands */
  1387. /* csa offload enable */
  1388. CASE_RETURN_STRING(WMI_CSA_OFFLOAD_ENABLE_CMDID);
  1389. /* chan switch command */
  1390. CASE_RETURN_STRING(WMI_CSA_OFFLOAD_CHANSWITCH_CMDID);
  1391. /* Chatter commands */
  1392. /* Change chatter mode of operation */
  1393. CASE_RETURN_STRING(WMI_CHATTER_SET_MODE_CMDID);
  1394. /* chatter add coalescing filter command */
  1395. CASE_RETURN_STRING(WMI_CHATTER_ADD_COALESCING_FILTER_CMDID);
  1396. /* chatter delete coalescing filter command */
  1397. CASE_RETURN_STRING(WMI_CHATTER_DELETE_COALESCING_FILTER_CMDID);
  1398. /* chatter coalecing query command */
  1399. CASE_RETURN_STRING(WMI_CHATTER_COALESCING_QUERY_CMDID);
  1400. /* addba specific commands */
  1401. /* start the aggregation on this TID */
  1402. CASE_RETURN_STRING(WMI_PEER_TID_ADDBA_CMDID);
  1403. /* stop the aggregation on this TID */
  1404. CASE_RETURN_STRING(WMI_PEER_TID_DELBA_CMDID);
  1405. /* set station mimo powersave method */
  1406. CASE_RETURN_STRING(WMI_STA_DTIM_PS_METHOD_CMDID);
  1407. /* Configure the Station UAPSD AC Auto Trigger Parameters */
  1408. CASE_RETURN_STRING(WMI_STA_UAPSD_AUTO_TRIG_CMDID);
  1409. /* Configure the Keep Alive Parameters */
  1410. CASE_RETURN_STRING(WMI_STA_KEEPALIVE_CMDID);
  1411. /* Request ssn from target for a sta/tid pair */
  1412. CASE_RETURN_STRING(WMI_BA_REQ_SSN_CMDID);
  1413. /* misc command group */
  1414. /* echo command mainly used for testing */
  1415. CASE_RETURN_STRING(WMI_ECHO_CMDID);
  1416. /* !!IMPORTANT!!
  1417. * If you need to add a new WMI command to the CASE_RETURN_STRING(WMI_GRP_MISC sub-group,
  1418. * please make sure you add it BEHIND CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
  1419. * as we MUST have a fixed value here to maintain compatibility between
  1420. * UTF and the ART2 driver
  1421. */
  1422. /* UTF WMI commands */
  1423. CASE_RETURN_STRING(WMI_PDEV_UTF_CMDID);
  1424. /* set debug log config */
  1425. CASE_RETURN_STRING(WMI_DBGLOG_CFG_CMDID);
  1426. /* QVIT specific command id */
  1427. CASE_RETURN_STRING(WMI_PDEV_QVIT_CMDID);
  1428. /* Factory Testing Mode request command
  1429. * used for integrated chipsets */
  1430. CASE_RETURN_STRING(WMI_PDEV_FTM_INTG_CMDID);
  1431. /* set and get keepalive parameters command */
  1432. CASE_RETURN_STRING(WMI_VDEV_SET_KEEPALIVE_CMDID);
  1433. CASE_RETURN_STRING(WMI_VDEV_GET_KEEPALIVE_CMDID);
  1434. /* For fw recovery test command */
  1435. CASE_RETURN_STRING(WMI_FORCE_FW_HANG_CMDID);
  1436. /* Set Mcast/Bdcast filter */
  1437. CASE_RETURN_STRING(WMI_SET_MCASTBCAST_FILTER_CMDID);
  1438. /* set thermal management params */
  1439. CASE_RETURN_STRING(WMI_THERMAL_MGMT_CMDID);
  1440. CASE_RETURN_STRING(WMI_RSSI_BREACH_MONITOR_CONFIG_CMDID);
  1441. CASE_RETURN_STRING(WMI_LRO_CONFIG_CMDID);
  1442. CASE_RETURN_STRING(WMI_TRANSFER_DATA_TO_FLASH_CMDID);
  1443. CASE_RETURN_STRING(WMI_CONFIG_ENHANCED_MCAST_FILTER_CMDID);
  1444. CASE_RETURN_STRING(WMI_VDEV_WISA_CMDID);
  1445. CASE_RETURN_STRING(WMI_SCAN_ADAPTIVE_DWELL_CONFIG_CMDID);
  1446. CASE_RETURN_STRING(WMI_WOW_SET_ACTION_WAKE_UP_CMDID);
  1447. CASE_RETURN_STRING(WMI_MAWC_SENSOR_REPORT_IND_CMDID);
  1448. CASE_RETURN_STRING(WMI_ROAM_CONFIGURE_MAWC_CMDID);
  1449. CASE_RETURN_STRING(WMI_NLO_CONFIGURE_MAWC_CMDID);
  1450. CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_MAWC_CMDID);
  1451. /* GPIO Configuration */
  1452. CASE_RETURN_STRING(WMI_GPIO_CONFIG_CMDID);
  1453. CASE_RETURN_STRING(WMI_GPIO_OUTPUT_CMDID);
  1454. /* Txbf configuration command */
  1455. CASE_RETURN_STRING(WMI_TXBF_CMDID);
  1456. /* FWTEST Commands */
  1457. CASE_RETURN_STRING(WMI_FWTEST_VDEV_MCC_SET_TBTT_MODE_CMDID);
  1458. /* set NoA descs */
  1459. CASE_RETURN_STRING(WMI_FWTEST_P2P_SET_NOA_PARAM_CMDID);
  1460. /* TDLS Configuration */
  1461. /* enable/disable TDLS */
  1462. CASE_RETURN_STRING(WMI_TDLS_SET_STATE_CMDID);
  1463. /* set tdls peer state */
  1464. CASE_RETURN_STRING(WMI_TDLS_PEER_UPDATE_CMDID);
  1465. /* Resmgr Configuration */
  1466. /* Adaptive OCS is enabled by default in the FW.
  1467. * This command is used to disable FW based adaptive OCS.
  1468. */
  1469. CASE_RETURN_STRING
  1470. (WMI_RESMGR_ADAPTIVE_OCS_ENABLE_DISABLE_CMDID);
  1471. /* set the requested channel time quota for the home channels */
  1472. CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_TIME_QUOTA_CMDID);
  1473. /* set the requested latency for the home channels */
  1474. CASE_RETURN_STRING(WMI_RESMGR_SET_CHAN_LATENCY_CMDID);
  1475. /* STA SMPS Configuration */
  1476. /* force SMPS mode */
  1477. CASE_RETURN_STRING(WMI_STA_SMPS_FORCE_MODE_CMDID);
  1478. /* set SMPS parameters */
  1479. CASE_RETURN_STRING(WMI_STA_SMPS_PARAM_CMDID);
  1480. /* Wlan HB commands */
  1481. /* enalbe/disable wlan HB */
  1482. CASE_RETURN_STRING(WMI_HB_SET_ENABLE_CMDID);
  1483. /* set tcp parameters for wlan HB */
  1484. CASE_RETURN_STRING(WMI_HB_SET_TCP_PARAMS_CMDID);
  1485. /* set tcp pkt filter for wlan HB */
  1486. CASE_RETURN_STRING(WMI_HB_SET_TCP_PKT_FILTER_CMDID);
  1487. /* set udp parameters for wlan HB */
  1488. CASE_RETURN_STRING(WMI_HB_SET_UDP_PARAMS_CMDID);
  1489. /* set udp pkt filter for wlan HB */
  1490. CASE_RETURN_STRING(WMI_HB_SET_UDP_PKT_FILTER_CMDID);
  1491. /* Wlan RMC commands*/
  1492. /* enable/disable RMC */
  1493. CASE_RETURN_STRING(WMI_RMC_SET_MODE_CMDID);
  1494. /* configure action frame period */
  1495. CASE_RETURN_STRING(WMI_RMC_SET_ACTION_PERIOD_CMDID);
  1496. /* For debug/future enhancement purposes only,
  1497. * configures/finetunes RMC algorithms */
  1498. CASE_RETURN_STRING(WMI_RMC_CONFIG_CMDID);
  1499. /* WLAN MHF offload commands */
  1500. /* enable/disable MHF offload */
  1501. CASE_RETURN_STRING(WMI_MHF_OFFLOAD_SET_MODE_CMDID);
  1502. /* Plumb routing table for MHF offload */
  1503. CASE_RETURN_STRING(WMI_MHF_OFFLOAD_PLUMB_ROUTING_TBL_CMDID);
  1504. /* location scan commands */
  1505. /* start batch scan */
  1506. CASE_RETURN_STRING(WMI_BATCH_SCAN_ENABLE_CMDID);
  1507. /* stop batch scan */
  1508. CASE_RETURN_STRING(WMI_BATCH_SCAN_DISABLE_CMDID);
  1509. /* get batch scan result */
  1510. CASE_RETURN_STRING(WMI_BATCH_SCAN_TRIGGER_RESULT_CMDID);
  1511. /* OEM related cmd */
  1512. CASE_RETURN_STRING(WMI_OEM_REQ_CMDID);
  1513. CASE_RETURN_STRING(WMI_OEM_REQUEST_CMDID);
  1514. /* NAN request cmd */
  1515. CASE_RETURN_STRING(WMI_NAN_CMDID);
  1516. /* Modem power state cmd */
  1517. CASE_RETURN_STRING(WMI_MODEM_POWER_STATE_CMDID);
  1518. CASE_RETURN_STRING(WMI_REQUEST_STATS_EXT_CMDID);
  1519. CASE_RETURN_STRING(WMI_OBSS_SCAN_ENABLE_CMDID);
  1520. CASE_RETURN_STRING(WMI_OBSS_SCAN_DISABLE_CMDID);
  1521. CASE_RETURN_STRING(WMI_PEER_GET_ESTIMATED_LINKSPEED_CMDID);
  1522. CASE_RETURN_STRING(WMI_ROAM_SCAN_CMD);
  1523. CASE_RETURN_STRING(WMI_PDEV_SET_LED_CONFIG_CMDID);
  1524. CASE_RETURN_STRING(WMI_HOST_AUTO_SHUTDOWN_CFG_CMDID);
  1525. CASE_RETURN_STRING(WMI_CHAN_AVOID_UPDATE_CMDID);
  1526. CASE_RETURN_STRING(WMI_COEX_CONFIG_CMDID);
  1527. CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_KEEPALIVE_CMDID);
  1528. CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_KEEPALIVE_CMDID);
  1529. CASE_RETURN_STRING(WMI_WOW_IOAC_ADD_WAKE_PATTERN_CMDID);
  1530. CASE_RETURN_STRING(WMI_WOW_IOAC_DEL_WAKE_PATTERN_CMDID);
  1531. CASE_RETURN_STRING(WMI_REQUEST_LINK_STATS_CMDID);
  1532. CASE_RETURN_STRING(WMI_START_LINK_STATS_CMDID);
  1533. CASE_RETURN_STRING(WMI_CLEAR_LINK_STATS_CMDID);
  1534. CASE_RETURN_STRING(WMI_GET_FW_MEM_DUMP_CMDID);
  1535. CASE_RETURN_STRING(WMI_LPI_MGMT_SNOOPING_CONFIG_CMDID);
  1536. CASE_RETURN_STRING(WMI_LPI_START_SCAN_CMDID);
  1537. CASE_RETURN_STRING(WMI_LPI_STOP_SCAN_CMDID);
  1538. CASE_RETURN_STRING(WMI_EXTSCAN_START_CMDID);
  1539. CASE_RETURN_STRING(WMI_EXTSCAN_STOP_CMDID);
  1540. CASE_RETURN_STRING
  1541. (WMI_EXTSCAN_CONFIGURE_WLAN_CHANGE_MONITOR_CMDID);
  1542. CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_MONITOR_CMDID);
  1543. CASE_RETURN_STRING(WMI_EXTSCAN_GET_CACHED_RESULTS_CMDID);
  1544. CASE_RETURN_STRING(WMI_EXTSCAN_GET_WLAN_CHANGE_RESULTS_CMDID);
  1545. CASE_RETURN_STRING(WMI_EXTSCAN_SET_CAPABILITIES_CMDID);
  1546. CASE_RETURN_STRING(WMI_EXTSCAN_GET_CAPABILITIES_CMDID);
  1547. CASE_RETURN_STRING(WMI_EXTSCAN_CONFIGURE_HOTLIST_SSID_MONITOR_CMDID);
  1548. CASE_RETURN_STRING(WMI_ROAM_SYNCH_COMPLETE);
  1549. CASE_RETURN_STRING(WMI_D0_WOW_ENABLE_DISABLE_CMDID);
  1550. CASE_RETURN_STRING(WMI_EXTWOW_ENABLE_CMDID);
  1551. CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE1_PARAMS_CMDID);
  1552. CASE_RETURN_STRING(WMI_EXTWOW_SET_APP_TYPE2_PARAMS_CMDID);
  1553. CASE_RETURN_STRING(WMI_UNIT_TEST_CMDID);
  1554. CASE_RETURN_STRING(WMI_ROAM_SET_RIC_REQUEST_CMDID);
  1555. CASE_RETURN_STRING(WMI_PDEV_GET_TEMPERATURE_CMDID);
  1556. CASE_RETURN_STRING(WMI_SET_DHCP_SERVER_OFFLOAD_CMDID);
  1557. CASE_RETURN_STRING(WMI_TPC_CHAINMASK_CONFIG_CMDID);
  1558. CASE_RETURN_STRING(WMI_IPA_OFFLOAD_ENABLE_DISABLE_CMDID);
  1559. CASE_RETURN_STRING(WMI_SCAN_PROB_REQ_OUI_CMDID);
  1560. CASE_RETURN_STRING(WMI_TDLS_SET_OFFCHAN_MODE_CMDID);
  1561. CASE_RETURN_STRING(WMI_PDEV_SET_LED_FLASHING_CMDID);
  1562. CASE_RETURN_STRING(WMI_MDNS_OFFLOAD_ENABLE_CMDID);
  1563. CASE_RETURN_STRING(WMI_MDNS_SET_FQDN_CMDID);
  1564. CASE_RETURN_STRING(WMI_MDNS_SET_RESPONSE_CMDID);
  1565. CASE_RETURN_STRING(WMI_MDNS_GET_STATS_CMDID);
  1566. CASE_RETURN_STRING(WMI_ROAM_INVOKE_CMDID);
  1567. CASE_RETURN_STRING(WMI_SET_ANTENNA_DIVERSITY_CMDID);
  1568. CASE_RETURN_STRING(WMI_SAP_OFL_ENABLE_CMDID);
  1569. CASE_RETURN_STRING(WMI_APFIND_CMDID);
  1570. CASE_RETURN_STRING(WMI_PASSPOINT_LIST_CONFIG_CMDID);
  1571. CASE_RETURN_STRING(WMI_OCB_SET_SCHED_CMDID);
  1572. CASE_RETURN_STRING(WMI_OCB_SET_CONFIG_CMDID);
  1573. CASE_RETURN_STRING(WMI_OCB_SET_UTC_TIME_CMDID);
  1574. CASE_RETURN_STRING(WMI_OCB_START_TIMING_ADVERT_CMDID);
  1575. CASE_RETURN_STRING(WMI_OCB_STOP_TIMING_ADVERT_CMDID);
  1576. CASE_RETURN_STRING(WMI_OCB_GET_TSF_TIMER_CMDID);
  1577. CASE_RETURN_STRING(WMI_DCC_GET_STATS_CMDID);
  1578. CASE_RETURN_STRING(WMI_DCC_CLEAR_STATS_CMDID);
  1579. CASE_RETURN_STRING(WMI_DCC_UPDATE_NDL_CMDID);
  1580. CASE_RETURN_STRING(WMI_ROAM_FILTER_CMDID);
  1581. CASE_RETURN_STRING(WMI_ROAM_SUBNET_CHANGE_CONFIG_CMDID);
  1582. CASE_RETURN_STRING(WMI_DEBUG_MESG_FLUSH_CMDID);
  1583. CASE_RETURN_STRING(WMI_PEER_SET_RATE_REPORT_CONDITION_CMDID);
  1584. CASE_RETURN_STRING(WMI_SOC_SET_PCL_CMDID);
  1585. CASE_RETURN_STRING(WMI_SOC_SET_HW_MODE_CMDID);
  1586. CASE_RETURN_STRING(WMI_SOC_SET_DUAL_MAC_CONFIG_CMDID);
  1587. CASE_RETURN_STRING(WMI_WOW_ENABLE_ICMPV6_NA_FLT_CMDID);
  1588. CASE_RETURN_STRING(WMI_DIAG_EVENT_LOG_CONFIG_CMDID);
  1589. CASE_RETURN_STRING(WMI_PACKET_FILTER_CONFIG_CMDID);
  1590. CASE_RETURN_STRING(WMI_PACKET_FILTER_ENABLE_CMDID);
  1591. CASE_RETURN_STRING(WMI_SAP_SET_BLACKLIST_PARAM_CMDID);
  1592. CASE_RETURN_STRING(WMI_WOW_UDP_SVC_OFLD_CMDID);
  1593. CASE_RETURN_STRING(WMI_MGMT_TX_SEND_CMDID);
  1594. CASE_RETURN_STRING(WMI_SOC_SET_ANTENNA_MODE_CMDID);
  1595. CASE_RETURN_STRING(WMI_WOW_HOSTWAKEUP_GPIO_PIN_PATTERN_CONFIG_CMDID);
  1596. CASE_RETURN_STRING(WMI_AP_PS_EGAP_PARAM_CMDID);
  1597. CASE_RETURN_STRING(WMI_PMF_OFFLOAD_SET_SA_QUERY_CMDID);
  1598. CASE_RETURN_STRING(WMI_BPF_GET_CAPABILITY_CMDID);
  1599. CASE_RETURN_STRING(WMI_BPF_GET_VDEV_STATS_CMDID);
  1600. CASE_RETURN_STRING(WMI_BPF_SET_VDEV_INSTRUCTIONS_CMDID);
  1601. CASE_RETURN_STRING(WMI_BPF_DEL_VDEV_INSTRUCTIONS_CMDID);
  1602. CASE_RETURN_STRING(WMI_NDI_GET_CAP_REQ_CMDID);
  1603. CASE_RETURN_STRING(WMI_NDP_INITIATOR_REQ_CMDID);
  1604. CASE_RETURN_STRING(WMI_NDP_RESPONDER_REQ_CMDID);
  1605. CASE_RETURN_STRING(WMI_NDP_END_REQ_CMDID);
  1606. CASE_RETURN_STRING(WMI_PEER_UPDATE_WDS_ENTRY_CMDID);
  1607. CASE_RETURN_STRING(WMI_PEER_ADD_PROXY_STA_ENTRY_CMDID);
  1608. CASE_RETURN_STRING(WMI_PDEV_FIPS_CMDID);
  1609. CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_ENABLE_CMDID);
  1610. CASE_RETURN_STRING(WMI_PDEV_SMART_ANT_SET_RX_ANTENNA_CMDID);
  1611. CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_SWITCH_TABLE_CMDID);
  1612. CASE_RETURN_STRING(WMI_PDEV_SET_CTL_TABLE_CMDID);
  1613. CASE_RETURN_STRING(WMI_PDEV_SET_MIMOGAIN_TABLE_CMDID);
  1614. CASE_RETURN_STRING(WMI_PDEV_GET_TPC_CMDID);
  1615. CASE_RETURN_STRING(WMI_MIB_STATS_ENABLE_CMDID);
  1616. CASE_RETURN_STRING(WMI_PDEV_GET_ANI_CCK_CONFIG_CMDID);
  1617. CASE_RETURN_STRING(WMI_PDEV_GET_ANI_OFDM_CONFIG_CMDID);
  1618. CASE_RETURN_STRING(WMI_VDEV_RATEMASK_CMDID);
  1619. CASE_RETURN_STRING(WMI_VDEV_ATF_REQUEST_CMDID);
  1620. CASE_RETURN_STRING(WMI_VDEV_SET_DSCP_TID_MAP_CMDID);
  1621. CASE_RETURN_STRING(WMI_VDEV_FILTER_NEIGHBOR_RX_PACKETS_CMDID);
  1622. CASE_RETURN_STRING(WMI_VDEV_SET_QUIET_MODE_CMDID);
  1623. CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TX_ANTENNA_CMDID);
  1624. CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_TRAIN_INFO_CMDID);
  1625. CASE_RETURN_STRING(WMI_PEER_SMART_ANT_SET_NODE_CONFIG_OPS_CMDID);
  1626. CASE_RETURN_STRING(WMI_PEER_ATF_REQUEST_CMDID);
  1627. CASE_RETURN_STRING(WMI_FWTEST_CMDID);
  1628. CASE_RETURN_STRING(WMI_QBOOST_CFG_CMDID);
  1629. CASE_RETURN_STRING(WMI_PDEV_GET_NFCAL_POWER_CMDID);
  1630. CASE_RETURN_STRING(WMI_PDEV_SET_PCL_CMDID);
  1631. CASE_RETURN_STRING(WMI_PDEV_SET_HW_MODE_CMDID);
  1632. CASE_RETURN_STRING(WMI_PDEV_SET_MAC_CONFIG_CMDID);
  1633. CASE_RETURN_STRING(WMI_PDEV_SET_ANTENNA_MODE_CMDID);
  1634. CASE_RETURN_STRING(WMI_ROAM_SET_MBO_PARAM_CMDID);
  1635. CASE_RETURN_STRING(WMI_CHAN_AVOID_RPT_ALLOW_CMDID);
  1636. CASE_RETURN_STRING(WMI_SET_PERIODIC_CHANNEL_STATS_CONFIG_CMDID);
  1637. CASE_RETURN_STRING(WMI_VDEV_SET_CUSTOM_AGGR_SIZE_CMDID);
  1638. CASE_RETURN_STRING(WMI_PDEV_WAL_POWER_DEBUG_CMDID);
  1639. CASE_RETURN_STRING(WMI_PEER_BWF_REQUEST_CMDID);
  1640. CASE_RETURN_STRING(WMI_DBGLOG_TIME_STAMP_SYNC_CMDID);
  1641. CASE_RETURN_STRING(WMI_P2P_LISTEN_OFFLOAD_START_CMDID);
  1642. CASE_RETURN_STRING(WMI_P2P_LISTEN_OFFLOAD_STOP_CMDID);
  1643. CASE_RETURN_STRING(WMI_PEER_REORDER_QUEUE_SETUP_CMDID);
  1644. CASE_RETURN_STRING(WMI_PEER_REORDER_QUEUE_REMOVE_CMDID);
  1645. CASE_RETURN_STRING(WMI_SET_MULTIPLE_MCAST_FILTER_CMDID);
  1646. CASE_RETURN_STRING(WMI_READ_DATA_FROM_FLASH_CMDID);
  1647. CASE_RETURN_STRING(WMI_PDEV_SET_REORDER_TIMEOUT_VAL_CMDID);
  1648. CASE_RETURN_STRING(WMI_PEER_SET_RX_BLOCKSIZE_CMDID);
  1649. CASE_RETURN_STRING(WMI_PDEV_SET_WAKEUP_CONFIG_CMDID);
  1650. CASE_RETURN_STRING(WMI_PDEV_GET_ANTDIV_STATUS_CMDID);
  1651. CASE_RETURN_STRING(WMI_PEER_ANTDIV_INFO_REQ_CMDID);
  1652. CASE_RETURN_STRING(WMI_MNT_FILTER_CMDID);
  1653. CASE_RETURN_STRING(WMI_PDEV_GET_CHIP_POWER_STATS_CMDID);
  1654. CASE_RETURN_STRING(WMI_COEX_GET_ANTENNA_ISOLATION_CMDID);
  1655. CASE_RETURN_STRING(WMI_PDEV_SET_STATS_THRESHOLD_CMDID);
  1656. CASE_RETURN_STRING(WMI_REQUEST_WLAN_STATS_CMDID);
  1657. CASE_RETURN_STRING(WMI_VDEV_ENCRYPT_DECRYPT_DATA_REQ_CMDID);
  1658. CASE_RETURN_STRING(WMI_PDEV_DFS_PHYERR_OFFLOAD_ENABLE_CMDID);
  1659. CASE_RETURN_STRING(WMI_PDEV_DFS_PHYERR_OFFLOAD_DISABLE_CMDID);
  1660. CASE_RETURN_STRING(WMI_VDEV_ADFS_CH_CFG_CMDID);
  1661. CASE_RETURN_STRING(WMI_VDEV_ADFS_OCAC_ABORT_CMDID);
  1662. CASE_RETURN_STRING(WMI_SAR_LIMITS_CMDID);
  1663. }
  1664. return "Invalid WMI cmd";
  1665. }
  1666. static inline void wma_log_cmd_id(uint32_t cmd_id, uint32_t tag)
  1667. {
  1668. WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
  1669. wmi_id_to_name(cmd_id), cmd_id, tag);
  1670. }
  1671. #else
  1672. static uint8_t *wmi_id_to_name(uint32_t wmi_command)
  1673. {
  1674. return "Invalid WMI cmd";
  1675. }
  1676. #endif
  1677. #ifdef CONFIG_MCL
  1678. /**
  1679. * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
  1680. * @cmd_id: command to check
  1681. *
  1682. * Return: true if the command is part of the resume sequence.
  1683. */
  1684. static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
  1685. {
  1686. switch (cmd_id) {
  1687. case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
  1688. case WMI_PDEV_RESUME_CMDID:
  1689. return true;
  1690. default:
  1691. return false;
  1692. }
  1693. }
  1694. #else
  1695. static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
  1696. {
  1697. return false;
  1698. }
  1699. #endif
  1700. /**
  1701. * wmi_unified_cmd_send() - WMI command API
  1702. * @wmi_handle: handle to wmi
  1703. * @buf: wmi buf
  1704. * @len: wmi buffer length
  1705. * @cmd_id: wmi command id
  1706. *
  1707. * Note, it is NOT safe to access buf after calling this function!
  1708. *
  1709. * Return: 0 on success
  1710. */
  1711. QDF_STATUS wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf,
  1712. uint32_t len, uint32_t cmd_id)
  1713. {
  1714. HTC_PACKET *pkt;
  1715. A_STATUS status;
  1716. uint16_t htc_tag = 0;
  1717. if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
  1718. htc_tag =
  1719. (A_UINT16)wmi_handle->ops->wmi_set_htc_tx_tag(
  1720. wmi_handle, buf, cmd_id);
  1721. } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
  1722. (!wmi_is_pm_resume_cmd(cmd_id))) {
  1723. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1724. "%s: Target is suspended", __func__);
  1725. QDF_ASSERT(0);
  1726. return QDF_STATUS_E_BUSY;
  1727. }
  1728. if (wmi_handle->wmi_stopinprogress) {
  1729. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1730. "WMI stop in progress\n");
  1731. return QDF_STATUS_E_INVAL;
  1732. }
  1733. #ifndef WMI_NON_TLV_SUPPORT
  1734. /* Do sanity check on the TLV parameter structure */
  1735. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  1736. void *buf_ptr = (void *)qdf_nbuf_data(buf);
  1737. if (wmitlv_check_command_tlv_params(NULL, buf_ptr, len, cmd_id)
  1738. != 0) {
  1739. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1740. "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
  1741. __func__, cmd_id);
  1742. return QDF_STATUS_E_INVAL;
  1743. }
  1744. }
  1745. #endif
  1746. if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
  1747. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1748. "%s, Failed to send cmd %x, no memory",
  1749. __func__, cmd_id);
  1750. return QDF_STATUS_E_NOMEM;
  1751. }
  1752. WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
  1753. qdf_atomic_inc(&wmi_handle->pending_cmds);
  1754. if (qdf_atomic_read(&wmi_handle->pending_cmds) >= WMI_MAX_CMDS) {
  1755. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1756. "\n%s: hostcredits = %d", __func__,
  1757. wmi_get_host_credits(wmi_handle));
  1758. htc_dump_counter_info(wmi_handle->htc_handle);
  1759. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1760. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1761. "%s: MAX %d WMI Pending cmds reached.", __func__,
  1762. WMI_MAX_CMDS);
  1763. QDF_BUG(0);
  1764. return QDF_STATUS_E_BUSY;
  1765. }
  1766. pkt = qdf_mem_malloc(sizeof(*pkt));
  1767. if (!pkt) {
  1768. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1769. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1770. "%s, Failed to alloc htc packet %x, no memory",
  1771. __func__, cmd_id);
  1772. return QDF_STATUS_E_NOMEM;
  1773. }
  1774. SET_HTC_PACKET_INFO_TX(pkt,
  1775. NULL,
  1776. qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
  1777. wmi_handle->wmi_endpoint_id, htc_tag);
  1778. SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
  1779. #ifdef CONFIG_MCL
  1780. wma_log_cmd_id(cmd_id, htc_tag);
  1781. #endif
  1782. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1783. if (wmi_handle->log_info.wmi_logging_enable) {
  1784. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1785. /*Record 16 bytes of WMI cmd data -
  1786. * * exclude TLV and WMI headers */
  1787. if (wmi_handle->ops->is_management_record(cmd_id)) {
  1788. WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd_id,
  1789. ((uint32_t *) qdf_nbuf_data(buf) +
  1790. wmi_handle->log_info.buf_offset_command));
  1791. } else {
  1792. WMI_COMMAND_RECORD(wmi_handle, cmd_id,
  1793. ((uint32_t *) qdf_nbuf_data(buf) +
  1794. wmi_handle->log_info.buf_offset_command));
  1795. }
  1796. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1797. }
  1798. #endif
  1799. status = htc_send_pkt(wmi_handle->htc_handle, pkt);
  1800. if (A_OK != status) {
  1801. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1802. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1803. "%s %d, htc_send_pkt failed", __func__, __LINE__);
  1804. qdf_mem_free(pkt);
  1805. }
  1806. if (status)
  1807. return QDF_STATUS_E_FAILURE;
  1808. return QDF_STATUS_SUCCESS;
  1809. }
  1810. /**
  1811. * wmi_unified_get_event_handler_ix() - gives event handler's index
  1812. * @wmi_handle: handle to wmi
  1813. * @event_id: wmi event id
  1814. *
  1815. * Return: event handler's index
  1816. */
  1817. static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
  1818. uint32_t event_id)
  1819. {
  1820. uint32_t idx = 0;
  1821. int32_t invalid_idx = -1;
  1822. struct wmi_soc *soc = wmi_handle->soc;
  1823. for (idx = 0; (idx < soc->max_event_idx &&
  1824. idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
  1825. if (wmi_handle->event_id[idx] == event_id &&
  1826. wmi_handle->event_handler[idx] != NULL) {
  1827. return idx;
  1828. }
  1829. }
  1830. return invalid_idx;
  1831. }
  1832. /**
  1833. * wmi_unified_register_event() - register wmi event handler
  1834. * @wmi_handle: handle to wmi
  1835. * @event_id: wmi event id
  1836. * @handler_func: wmi event handler function
  1837. *
  1838. * Return: 0 on success
  1839. */
  1840. int wmi_unified_register_event(wmi_unified_t wmi_handle,
  1841. uint32_t event_id,
  1842. wmi_unified_event_handler handler_func)
  1843. {
  1844. uint32_t idx = 0;
  1845. uint32_t evt_id;
  1846. struct wmi_soc *soc = wmi_handle->soc;
  1847. if (event_id >= wmi_events_max ||
  1848. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1849. qdf_print("%s: Event id %d is unavailable\n",
  1850. __func__, event_id);
  1851. return QDF_STATUS_E_FAILURE;
  1852. }
  1853. evt_id = wmi_handle->wmi_events[event_id];
  1854. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1855. qdf_print("%s : event handler already registered 0x%x\n",
  1856. __func__, evt_id);
  1857. return QDF_STATUS_E_FAILURE;
  1858. }
  1859. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1860. qdf_print("%s : no more event handlers 0x%x\n",
  1861. __func__, evt_id);
  1862. return QDF_STATUS_E_FAILURE;
  1863. }
  1864. idx = soc->max_event_idx;
  1865. wmi_handle->event_handler[idx] = handler_func;
  1866. wmi_handle->event_id[idx] = evt_id;
  1867. qdf_spin_lock_bh(&soc->ctx_lock);
  1868. wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
  1869. qdf_spin_unlock_bh(&soc->ctx_lock);
  1870. soc->max_event_idx++;
  1871. return 0;
  1872. }
  1873. /**
  1874. * wmi_unified_register_event_handler() - register wmi event handler
  1875. * @wmi_handle: handle to wmi
  1876. * @event_id: wmi event id
  1877. * @handler_func: wmi event handler function
  1878. * @rx_ctx: rx execution context for wmi rx events
  1879. *
  1880. * This API is to support legacy requirements. Will be deprecated in future.
  1881. * Return: 0 on success
  1882. */
  1883. int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
  1884. uint32_t event_id,
  1885. wmi_unified_event_handler handler_func,
  1886. uint8_t rx_ctx)
  1887. {
  1888. uint32_t idx = 0;
  1889. uint32_t evt_id;
  1890. struct wmi_soc *soc = wmi_handle->soc;
  1891. #ifndef CONFIG_MCL
  1892. if (event_id >= wmi_events_max ||
  1893. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1894. qdf_print("%s: Event id %d is unavailable\n",
  1895. __func__, event_id);
  1896. return QDF_STATUS_E_FAILURE;
  1897. }
  1898. evt_id = wmi_handle->wmi_events[event_id];
  1899. #else
  1900. evt_id = event_id;
  1901. #endif
  1902. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1903. qdf_print("%s : event handler already registered 0x%x\n",
  1904. __func__, evt_id);
  1905. return QDF_STATUS_E_FAILURE;
  1906. }
  1907. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1908. qdf_print("%s : no more event handlers 0x%x\n",
  1909. __func__, evt_id);
  1910. return QDF_STATUS_E_FAILURE;
  1911. }
  1912. idx = soc->max_event_idx;
  1913. wmi_handle->event_handler[idx] = handler_func;
  1914. wmi_handle->event_id[idx] = evt_id;
  1915. qdf_spin_lock_bh(&soc->ctx_lock);
  1916. wmi_handle->ctx[idx] = rx_ctx;
  1917. qdf_spin_unlock_bh(&soc->ctx_lock);
  1918. soc->max_event_idx++;
  1919. return 0;
  1920. }
  1921. /**
  1922. * wmi_unified_unregister_event() - unregister wmi event handler
  1923. * @wmi_handle: handle to wmi
  1924. * @event_id: wmi event id
  1925. *
  1926. * Return: 0 on success
  1927. */
  1928. int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
  1929. uint32_t event_id)
  1930. {
  1931. uint32_t idx = 0;
  1932. uint32_t evt_id;
  1933. struct wmi_soc *soc = wmi_handle->soc;
  1934. if (event_id >= wmi_events_max ||
  1935. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1936. qdf_print("%s: Event id %d is unavailable\n",
  1937. __func__, event_id);
  1938. return QDF_STATUS_E_FAILURE;
  1939. }
  1940. evt_id = wmi_handle->wmi_events[event_id];
  1941. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1942. if (idx == -1) {
  1943. qdf_print("%s : event handler is not registered: evt id 0x%x\n",
  1944. __func__, evt_id);
  1945. return QDF_STATUS_E_FAILURE;
  1946. }
  1947. wmi_handle->event_handler[idx] = NULL;
  1948. wmi_handle->event_id[idx] = 0;
  1949. --soc->max_event_idx;
  1950. wmi_handle->event_handler[idx] =
  1951. wmi_handle->event_handler[soc->max_event_idx];
  1952. wmi_handle->event_id[idx] =
  1953. wmi_handle->event_id[soc->max_event_idx];
  1954. return 0;
  1955. }
  1956. /**
  1957. * wmi_unified_unregister_event_handler() - unregister wmi event handler
  1958. * @wmi_handle: handle to wmi
  1959. * @event_id: wmi event id
  1960. *
  1961. * Return: 0 on success
  1962. */
  1963. int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
  1964. uint32_t event_id)
  1965. {
  1966. uint32_t idx = 0;
  1967. uint32_t evt_id;
  1968. struct wmi_soc *soc = wmi_handle->soc;
  1969. #ifndef CONFIG_MCL
  1970. if (event_id >= wmi_events_max ||
  1971. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1972. qdf_print("%s: Event id %d is unavailable\n",
  1973. __func__, event_id);
  1974. return QDF_STATUS_E_FAILURE;
  1975. }
  1976. evt_id = wmi_handle->wmi_events[event_id];
  1977. #else
  1978. evt_id = event_id;
  1979. #endif
  1980. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1981. if (idx == -1) {
  1982. qdf_print("%s : event handler is not registered: evt id 0x%x\n",
  1983. __func__, evt_id);
  1984. return QDF_STATUS_E_FAILURE;
  1985. }
  1986. wmi_handle->event_handler[idx] = NULL;
  1987. wmi_handle->event_id[idx] = 0;
  1988. --soc->max_event_idx;
  1989. wmi_handle->event_handler[idx] =
  1990. wmi_handle->event_handler[soc->max_event_idx];
  1991. wmi_handle->event_id[idx] =
  1992. wmi_handle->event_id[soc->max_event_idx];
  1993. return 0;
  1994. }
  1995. /**
  1996. * wmi_process_fw_event_default_ctx() - process in default caller context
  1997. * @wmi_handle: handle to wmi
  1998. * @htc_packet: pointer to htc packet
  1999. * @exec_ctx: execution context for wmi fw event
  2000. *
  2001. * Event process by below function will be in default caller context.
  2002. * wmi internally provides rx work thread processing context.
  2003. *
  2004. * Return: none
  2005. */
  2006. static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
  2007. HTC_PACKET *htc_packet, uint8_t exec_ctx)
  2008. {
  2009. wmi_buf_t evt_buf;
  2010. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  2011. #ifndef CONFIG_MCL
  2012. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
  2013. (wmi_handle->scn_handle, evt_buf, exec_ctx);
  2014. #else
  2015. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
  2016. evt_buf, exec_ctx);
  2017. #endif
  2018. return;
  2019. }
  2020. /**
  2021. * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
  2022. * @wmi_handle: handle to wmi
  2023. * @htc_packet: pointer to htc packet
  2024. *
  2025. * Event process by below function will be in worker thread context.
  2026. * Use this method for events which are not critical and not
  2027. * handled in protocol stack.
  2028. *
  2029. * Return: none
  2030. */
  2031. static void wmi_process_fw_event_worker_thread_ctx
  2032. (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet)
  2033. {
  2034. wmi_buf_t evt_buf;
  2035. uint32_t id;
  2036. uint8_t *data;
  2037. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  2038. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  2039. data = qdf_nbuf_data(evt_buf);
  2040. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2041. if (wmi_handle->log_info.wmi_logging_enable) {
  2042. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  2043. /* Exclude 4 bytes of TLV header */
  2044. WMI_RX_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
  2045. wmi_handle->log_info.buf_offset_event));
  2046. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  2047. }
  2048. #endif
  2049. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  2050. qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
  2051. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  2052. qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
  2053. &wmi_handle->rx_event_work);
  2054. return;
  2055. }
  2056. /**
  2057. * wmi_get_pdev_ep: Get wmi handle based on endpoint
  2058. * @soc: handle to wmi soc
  2059. * @ep: endpoint id
  2060. *
  2061. * Return: none
  2062. */
  2063. static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
  2064. HTC_ENDPOINT_ID ep)
  2065. {
  2066. uint32_t i;
  2067. for (i = 0; i < WMI_MAX_RADIOS; i++)
  2068. if (soc->wmi_endpoint_id[i] == ep)
  2069. break;
  2070. if (i == WMI_MAX_RADIOS)
  2071. return NULL;
  2072. return soc->wmi_pdev[i];
  2073. }
  2074. /**
  2075. * wmi_control_rx() - process fw events callbacks
  2076. * @ctx: handle to wmi
  2077. * @htc_packet: pointer to htc packet
  2078. *
  2079. * Return: none
  2080. */
  2081. static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
  2082. {
  2083. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  2084. struct wmi_unified *wmi_handle;
  2085. wmi_buf_t evt_buf;
  2086. uint32_t id;
  2087. uint32_t idx = 0;
  2088. enum wmi_rx_exec_ctx exec_ctx;
  2089. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  2090. wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
  2091. if (wmi_handle == NULL) {
  2092. qdf_print
  2093. ("%s :unable to get wmi_handle to Endpoint %d\n",
  2094. __func__, htc_packet->Endpoint);
  2095. qdf_nbuf_free(evt_buf);
  2096. return;
  2097. }
  2098. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  2099. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  2100. if (qdf_unlikely(idx == A_ERROR)) {
  2101. qdf_print
  2102. ("%s :event handler is not registered: event id 0x%x\n",
  2103. __func__, id);
  2104. qdf_nbuf_free(evt_buf);
  2105. return;
  2106. }
  2107. qdf_spin_lock_bh(&soc->ctx_lock);
  2108. exec_ctx = wmi_handle->ctx[idx];
  2109. qdf_spin_unlock_bh(&soc->ctx_lock);
  2110. if (exec_ctx == WMI_RX_WORK_CTX) {
  2111. wmi_process_fw_event_worker_thread_ctx
  2112. (wmi_handle, htc_packet);
  2113. } else if (exec_ctx > WMI_RX_WORK_CTX) {
  2114. wmi_process_fw_event_default_ctx
  2115. (wmi_handle, htc_packet, exec_ctx);
  2116. } else {
  2117. qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
  2118. qdf_nbuf_free(evt_buf);
  2119. }
  2120. }
  2121. /**
  2122. * wmi_process_fw_event() - process any fw event
  2123. * @wmi_handle: wmi handle
  2124. * @evt_buf: fw event buffer
  2125. *
  2126. * This function process fw event in caller context
  2127. *
  2128. * Return: none
  2129. */
  2130. void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  2131. {
  2132. __wmi_control_rx(wmi_handle, evt_buf);
  2133. }
  2134. /**
  2135. * __wmi_control_rx() - process serialize wmi event callback
  2136. * @wmi_handle: wmi handle
  2137. * @evt_buf: fw event buffer
  2138. *
  2139. * Return: none
  2140. */
  2141. void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  2142. {
  2143. uint32_t id;
  2144. uint8_t *data;
  2145. uint32_t len;
  2146. void *wmi_cmd_struct_ptr = NULL;
  2147. #ifndef WMI_NON_TLV_SUPPORT
  2148. int tlv_ok_status = 0;
  2149. #endif
  2150. uint32_t idx = 0;
  2151. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  2152. if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
  2153. goto end;
  2154. data = qdf_nbuf_data(evt_buf);
  2155. len = qdf_nbuf_len(evt_buf);
  2156. #ifndef WMI_NON_TLV_SUPPORT
  2157. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  2158. /* Validate and pad(if necessary) the TLVs */
  2159. tlv_ok_status =
  2160. wmitlv_check_and_pad_event_tlvs(wmi_handle->scn_handle,
  2161. data, len, id,
  2162. &wmi_cmd_struct_ptr);
  2163. if (tlv_ok_status != 0) {
  2164. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  2165. "%s: Error: id=0x%d, wmitlv check status=%d\n",
  2166. __func__, id, tlv_ok_status);
  2167. goto end;
  2168. }
  2169. }
  2170. #endif
  2171. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  2172. if (idx == A_ERROR) {
  2173. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  2174. "%s : event handler is not registered: event id 0x%x\n",
  2175. __func__, id);
  2176. goto end;
  2177. }
  2178. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2179. if (wmi_handle->log_info.wmi_logging_enable) {
  2180. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  2181. /* Exclude 4 bytes of TLV header */
  2182. if (wmi_handle->ops->is_management_record(id)) {
  2183. WMI_MGMT_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data
  2184. + wmi_handle->log_info.buf_offset_event));
  2185. } else {
  2186. WMI_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
  2187. wmi_handle->log_info.buf_offset_event));
  2188. }
  2189. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  2190. }
  2191. #endif
  2192. /* Call the WMI registered event handler */
  2193. if (wmi_handle->target_type == WMI_TLV_TARGET)
  2194. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  2195. wmi_cmd_struct_ptr, len);
  2196. else
  2197. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  2198. data, len);
  2199. end:
  2200. /* Free event buffer and allocated event tlv */
  2201. #ifndef WMI_NON_TLV_SUPPORT
  2202. if (wmi_handle->target_type == WMI_TLV_TARGET)
  2203. wmitlv_free_allocated_event_tlvs(id, &wmi_cmd_struct_ptr);
  2204. #endif
  2205. qdf_nbuf_free(evt_buf);
  2206. }
  2207. /**
  2208. * wmi_rx_event_work() - process rx event in rx work queue context
  2209. * @arg: opaque pointer to wmi handle
  2210. *
  2211. * This function process any fw event to serialize it through rx worker thread.
  2212. *
  2213. * Return: none
  2214. */
  2215. static void wmi_rx_event_work(void *arg)
  2216. {
  2217. wmi_buf_t buf;
  2218. struct wmi_unified *wmi = arg;
  2219. qdf_spin_lock_bh(&wmi->eventq_lock);
  2220. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  2221. qdf_spin_unlock_bh(&wmi->eventq_lock);
  2222. while (buf) {
  2223. __wmi_control_rx(wmi, buf);
  2224. qdf_spin_lock_bh(&wmi->eventq_lock);
  2225. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  2226. qdf_spin_unlock_bh(&wmi->eventq_lock);
  2227. }
  2228. }
  2229. #ifdef FEATURE_RUNTIME_PM
  2230. /**
  2231. * wmi_runtime_pm_init() - initialize runtime pm wmi variables
  2232. * @wmi_handle: wmi context
  2233. */
  2234. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  2235. {
  2236. qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
  2237. }
  2238. /**
  2239. * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
  2240. * @wmi_handle: wmi context
  2241. * @val: runtime pm progress flag
  2242. */
  2243. void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
  2244. {
  2245. qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
  2246. }
  2247. /**
  2248. * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
  2249. * @wmi_handle: wmi context
  2250. */
  2251. inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
  2252. {
  2253. return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
  2254. }
  2255. #else
  2256. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  2257. {
  2258. }
  2259. #endif
  2260. /**
  2261. * wmi_unified_get_soc_handle: Get WMI SoC handle
  2262. * @param wmi_handle: WMI context got from wmi_attach
  2263. *
  2264. * return: Pointer to Soc handle
  2265. */
  2266. void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
  2267. {
  2268. return wmi_handle->soc;
  2269. }
  2270. /**
  2271. * wmi_interface_logging_init: Interface looging init
  2272. * @param wmi_handle: Pointer to wmi handle object
  2273. *
  2274. * return: None
  2275. */
  2276. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2277. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
  2278. {
  2279. if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
  2280. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  2281. wmi_debugfs_init(wmi_handle);
  2282. }
  2283. }
  2284. #else
  2285. void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
  2286. {
  2287. }
  2288. #endif
  2289. /**
  2290. * wmi_target_params_init: Target specific params init
  2291. * @param wmi_soc: Pointer to wmi soc object
  2292. * @param wmi_handle: Pointer to wmi handle object
  2293. *
  2294. * return: None
  2295. */
  2296. #ifndef CONFIG_MCL
  2297. static inline void wmi_target_params_init(struct wmi_soc *soc,
  2298. struct wmi_unified *wmi_handle)
  2299. {
  2300. /* WMI service bitmap recieved from target */
  2301. wmi_handle->wmi_service_bitmap = soc->wmi_service_bitmap;
  2302. wmi_handle->pdev_param = soc->pdev_param;
  2303. wmi_handle->vdev_param = soc->vdev_param;
  2304. wmi_handle->services = soc->services;
  2305. }
  2306. #else
  2307. static inline void wmi_target_params_init(struct wmi_soc *soc,
  2308. struct wmi_unified *wmi_handle)
  2309. {
  2310. }
  2311. #endif
  2312. /**
  2313. * wmi_unified_get_pdev_handle: Get WMI SoC handle
  2314. * @param wmi_soc: Pointer to wmi soc object
  2315. * @param pdev_idx: pdev index
  2316. *
  2317. * return: Pointer to wmi handle or NULL on failure
  2318. */
  2319. void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
  2320. {
  2321. struct wmi_unified *wmi_handle;
  2322. if (pdev_idx >= WMI_MAX_RADIOS)
  2323. return NULL;
  2324. /* If wmi pdev is already allocated, just return the handle */
  2325. if (soc->wmi_pdev[pdev_idx] != NULL)
  2326. return soc->wmi_pdev[pdev_idx];
  2327. wmi_handle =
  2328. (struct wmi_unified *) qdf_mem_malloc(
  2329. sizeof(struct wmi_unified));
  2330. if (wmi_handle == NULL) {
  2331. qdf_print("allocation of wmi handle failed %zu\n",
  2332. sizeof(struct wmi_unified));
  2333. return NULL;
  2334. }
  2335. wmi_handle->scn_handle = soc->scn_handle;
  2336. wmi_handle->event_id = soc->event_id;
  2337. wmi_handle->event_handler = soc->event_handler;
  2338. wmi_handle->ctx = soc->ctx;
  2339. wmi_handle->ops = soc->ops;
  2340. qdf_spinlock_create(&wmi_handle->eventq_lock);
  2341. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  2342. qdf_create_work(0, &wmi_handle->rx_event_work,
  2343. wmi_rx_event_work, wmi_handle);
  2344. wmi_handle->wmi_rx_work_queue =
  2345. qdf_create_workqueue("wmi_rx_event_work_queue");
  2346. if (NULL == wmi_handle->wmi_rx_work_queue) {
  2347. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  2348. goto error;
  2349. }
  2350. wmi_handle->wmi_events = soc->wmi_events;
  2351. wmi_target_params_init(soc, wmi_handle);
  2352. wmi_interface_logging_init(wmi_handle);
  2353. qdf_atomic_init(&wmi_handle->pending_cmds);
  2354. qdf_atomic_init(&wmi_handle->is_target_suspended);
  2355. wmi_handle->target_type = soc->target_type;
  2356. wmi_handle->wmi_stopinprogress = 0;
  2357. wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
  2358. wmi_handle->htc_handle = soc->htc_handle;
  2359. wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
  2360. wmi_handle->soc = soc;
  2361. soc->wmi_pdev[pdev_idx] = wmi_handle;
  2362. return wmi_handle;
  2363. error:
  2364. qdf_mem_free(wmi_handle);
  2365. return NULL;
  2366. }
  2367. /**
  2368. * wmi_unified_attach() - attach for unified WMI
  2369. * @scn_handle: handle to SCN
  2370. * @osdev: OS device context
  2371. * @target_type: TLV or not-TLV based target
  2372. * @use_cookie: cookie based allocation enabled/disabled
  2373. * @ops: umac rx callbacks
  2374. * @psoc: objmgr psoc
  2375. *
  2376. * @Return: wmi handle.
  2377. */
  2378. void *wmi_unified_attach(void *scn_handle,
  2379. osdev_t osdev, enum wmi_target_type target_type,
  2380. bool use_cookie, struct wmi_rx_ops *rx_ops,
  2381. struct wlan_objmgr_psoc *psoc)
  2382. {
  2383. struct wmi_unified *wmi_handle;
  2384. struct wmi_soc *soc;
  2385. soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
  2386. if (soc == NULL) {
  2387. qdf_print("Allocation of wmi_soc failed %zu\n",
  2388. sizeof(struct wmi_soc));
  2389. return NULL;
  2390. }
  2391. #ifdef CONFIG_MCL
  2392. wmi_handle =
  2393. (struct wmi_unified *)os_malloc(NULL,
  2394. sizeof(struct wmi_unified),
  2395. GFP_ATOMIC);
  2396. #else
  2397. wmi_handle =
  2398. (struct wmi_unified *) qdf_mem_malloc(
  2399. sizeof(struct wmi_unified));
  2400. #endif
  2401. if (wmi_handle == NULL) {
  2402. qdf_mem_free(soc);
  2403. qdf_print("allocation of wmi handle failed %zu\n",
  2404. sizeof(struct wmi_unified));
  2405. return NULL;
  2406. }
  2407. wmi_handle->soc = soc;
  2408. wmi_handle->event_id = soc->event_id;
  2409. wmi_handle->event_handler = soc->event_handler;
  2410. wmi_handle->ctx = soc->ctx;
  2411. wmi_handle->wmi_events = soc->wmi_events;
  2412. wmi_target_params_init(soc, wmi_handle);
  2413. wmi_handle->scn_handle = scn_handle;
  2414. soc->scn_handle = scn_handle;
  2415. qdf_atomic_init(&wmi_handle->pending_cmds);
  2416. qdf_atomic_init(&wmi_handle->is_target_suspended);
  2417. wmi_runtime_pm_init(wmi_handle);
  2418. qdf_spinlock_create(&wmi_handle->eventq_lock);
  2419. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  2420. qdf_create_work(0, &wmi_handle->rx_event_work,
  2421. wmi_rx_event_work, wmi_handle);
  2422. wmi_handle->wmi_rx_work_queue =
  2423. qdf_create_workqueue("wmi_rx_event_work_queue");
  2424. if (NULL == wmi_handle->wmi_rx_work_queue) {
  2425. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  2426. goto error;
  2427. }
  2428. wmi_interface_logging_init(wmi_handle);
  2429. /* Attach mc_thread context processing function */
  2430. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
  2431. rx_ops->wma_process_fw_event_handler_cbk;
  2432. wmi_handle->target_type = target_type;
  2433. soc->target_type = target_type;
  2434. if (target_type == WMI_TLV_TARGET)
  2435. wmi_tlv_attach(wmi_handle);
  2436. else
  2437. wmi_non_tlv_attach(wmi_handle);
  2438. /* Assign target cookie capablity */
  2439. wmi_handle->use_cookie = use_cookie;
  2440. wmi_handle->osdev = osdev;
  2441. wmi_handle->wmi_stopinprogress = 0;
  2442. /* Increase the ref count once refcount infra is present */
  2443. soc->wmi_psoc = psoc;
  2444. qdf_spinlock_create(&soc->ctx_lock);
  2445. soc->ops = wmi_handle->ops;
  2446. soc->wmi_pdev[0] = wmi_handle;
  2447. return wmi_handle;
  2448. error:
  2449. qdf_mem_free(soc);
  2450. qdf_mem_free(wmi_handle);
  2451. return NULL;
  2452. }
  2453. /**
  2454. * wmi_unified_detach() - detach for unified WMI
  2455. *
  2456. * @wmi_handle : handle to wmi.
  2457. *
  2458. * @Return: none.
  2459. */
  2460. void wmi_unified_detach(struct wmi_unified *wmi_handle)
  2461. {
  2462. wmi_buf_t buf;
  2463. struct wmi_soc *soc;
  2464. uint8_t i;
  2465. soc = wmi_handle->soc;
  2466. for (i = 0; i < WMI_MAX_RADIOS; i++) {
  2467. if (soc->wmi_pdev[i]) {
  2468. qdf_flush_workqueue(0,
  2469. soc->wmi_pdev[i]->wmi_rx_work_queue);
  2470. qdf_destroy_workqueue(0,
  2471. soc->wmi_pdev[i]->wmi_rx_work_queue);
  2472. wmi_debugfs_remove(soc->wmi_pdev[i]);
  2473. buf = qdf_nbuf_queue_remove(
  2474. &soc->wmi_pdev[i]->event_queue);
  2475. while (buf) {
  2476. qdf_nbuf_free(buf);
  2477. buf = qdf_nbuf_queue_remove(
  2478. &soc->wmi_pdev[i]->event_queue);
  2479. }
  2480. wmi_log_buffer_free(soc->wmi_pdev[i]);
  2481. qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
  2482. qdf_mem_free(soc->wmi_pdev[i]);
  2483. }
  2484. }
  2485. qdf_spinlock_destroy(&soc->ctx_lock);
  2486. /* Decrease the ref count once refcount infra is present */
  2487. soc->wmi_psoc = NULL;
  2488. qdf_mem_free(soc);
  2489. }
  2490. /**
  2491. * wmi_unified_remove_work() - detach for WMI work
  2492. * @wmi_handle: handle to WMI
  2493. *
  2494. * A function that does not fully detach WMI, but just remove work
  2495. * queue items associated with it. This is used to make sure that
  2496. * before any other processing code that may destroy related contexts
  2497. * (HTC, etc), work queue processing on WMI has already been stopped.
  2498. *
  2499. * Return: None
  2500. */
  2501. void
  2502. wmi_unified_remove_work(struct wmi_unified *wmi_handle)
  2503. {
  2504. wmi_buf_t buf;
  2505. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  2506. "Enter: %s", __func__);
  2507. qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
  2508. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  2509. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2510. while (buf) {
  2511. qdf_nbuf_free(buf);
  2512. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2513. }
  2514. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  2515. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  2516. "Done: %s", __func__);
  2517. }
  2518. /**
  2519. * wmi_htc_tx_complete() - Process htc tx completion
  2520. *
  2521. * @ctx: handle to wmi
  2522. * @htc_packet: pointer to htc packet
  2523. *
  2524. * @Return: none.
  2525. */
  2526. static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
  2527. {
  2528. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  2529. wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
  2530. u_int8_t *buf_ptr;
  2531. u_int32_t len;
  2532. struct wmi_unified *wmi_handle;
  2533. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2534. uint32_t cmd_id;
  2535. #endif
  2536. ASSERT(wmi_cmd_buf);
  2537. wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
  2538. if (wmi_handle == NULL) {
  2539. WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
  2540. QDF_ASSERT(0);
  2541. return;
  2542. }
  2543. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2544. if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
  2545. cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
  2546. WMI_CMD_HDR, COMMANDID);
  2547. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  2548. /* Record 16 bytes of WMI cmd tx complete data
  2549. - exclude TLV and WMI headers */
  2550. if (wmi_handle->ops->is_management_record(cmd_id)) {
  2551. WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2552. ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
  2553. wmi_handle->log_info.buf_offset_command));
  2554. } else {
  2555. WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2556. ((uint32_t *) qdf_nbuf_data(wmi_cmd_buf) +
  2557. wmi_handle->log_info.buf_offset_command));
  2558. }
  2559. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  2560. }
  2561. #endif
  2562. buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
  2563. len = qdf_nbuf_len(wmi_cmd_buf);
  2564. qdf_mem_zero(buf_ptr, len);
  2565. qdf_nbuf_free(wmi_cmd_buf);
  2566. qdf_mem_free(htc_pkt);
  2567. qdf_atomic_dec(&wmi_handle->pending_cmds);
  2568. }
  2569. /**
  2570. * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
  2571. *
  2572. * @wmi_handle: handle to WMI.
  2573. * @pdev_idx: Pdev index
  2574. *
  2575. * @Return: status.
  2576. */
  2577. static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
  2578. uint32_t pdev_idx)
  2579. {
  2580. int status;
  2581. uint32_t svc_id[] = {WMI_CONTROL_SVC, WMI_CONTROL_SVC_WMAC1,
  2582. WMI_CONTROL_SVC_WMAC2};
  2583. struct htc_service_connect_resp response;
  2584. struct htc_service_connect_req connect;
  2585. OS_MEMZERO(&connect, sizeof(connect));
  2586. OS_MEMZERO(&response, sizeof(response));
  2587. /* meta data is unused for now */
  2588. connect.pMetaData = NULL;
  2589. connect.MetaDataLength = 0;
  2590. /* these fields are the same for all service endpoints */
  2591. connect.EpCallbacks.pContext = soc;
  2592. connect.EpCallbacks.EpTxCompleteMultiple =
  2593. NULL /* Control path completion ar6000_tx_complete */;
  2594. connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
  2595. connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
  2596. connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
  2597. connect.EpCallbacks.EpTxComplete =
  2598. wmi_htc_tx_complete /* ar6000_tx_queue_full */;
  2599. /* connect to control service */
  2600. connect.service_id = svc_id[pdev_idx];
  2601. status = htc_connect_service(soc->htc_handle, &connect,
  2602. &response);
  2603. if (status != EOK) {
  2604. qdf_print
  2605. ("Failed to connect to WMI CONTROL service status:%d\n",
  2606. status);
  2607. return status;
  2608. }
  2609. soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
  2610. soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
  2611. return 0;
  2612. }
  2613. /**
  2614. * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
  2615. *
  2616. * @wmi_handle: handle to WMI.
  2617. *
  2618. * @Return: status.
  2619. */
  2620. QDF_STATUS
  2621. wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
  2622. void *htc_handle)
  2623. {
  2624. uint32_t i;
  2625. uint8_t wmi_ep_count;
  2626. wmi_handle->soc->htc_handle = htc_handle;
  2627. wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
  2628. if (wmi_ep_count > WMI_MAX_RADIOS)
  2629. return QDF_STATUS_E_FAULT;
  2630. for (i = 0; i < wmi_ep_count; i++)
  2631. wmi_connect_pdev_htc_service(wmi_handle->soc, i);
  2632. wmi_handle->htc_handle = htc_handle;
  2633. wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
  2634. wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
  2635. return QDF_STATUS_SUCCESS;
  2636. }
  2637. /**
  2638. * wmi_get_host_credits() - WMI API to get updated host_credits
  2639. *
  2640. * @wmi_handle: handle to WMI.
  2641. *
  2642. * @Return: updated host_credits.
  2643. */
  2644. int wmi_get_host_credits(wmi_unified_t wmi_handle)
  2645. {
  2646. int host_credits = 0;
  2647. htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
  2648. &host_credits);
  2649. return host_credits;
  2650. }
  2651. /**
  2652. * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
  2653. * queue
  2654. *
  2655. * @wmi_handle: handle to WMI.
  2656. *
  2657. * @Return: Pending Commands in the HTC queue.
  2658. */
  2659. int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
  2660. {
  2661. return qdf_atomic_read(&wmi_handle->pending_cmds);
  2662. }
  2663. /**
  2664. * wmi_set_target_suspend() - WMI API to set target suspend state
  2665. *
  2666. * @wmi_handle: handle to WMI.
  2667. * @val: suspend state boolean.
  2668. *
  2669. * @Return: none.
  2670. */
  2671. void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
  2672. {
  2673. qdf_atomic_set(&wmi_handle->is_target_suspended, val);
  2674. }
  2675. /**
  2676. * WMI API to set crash injection state
  2677. * @param wmi_handle: handle to WMI.
  2678. * @param val: crash injection state boolean.
  2679. */
  2680. void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
  2681. {
  2682. wmi_handle->tag_crash_inject = flag;
  2683. }
  2684. /**
  2685. * WMI API to set bus suspend state
  2686. * @param wmi_handle: handle to WMI.
  2687. * @param val: suspend state boolean.
  2688. */
  2689. void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
  2690. {
  2691. qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
  2692. }
  2693. #ifndef CONFIG_MCL
  2694. /**
  2695. * API to flush all the previous packets associated with the wmi endpoint
  2696. *
  2697. * @param wmi_handle : handle to WMI.
  2698. */
  2699. void
  2700. wmi_flush_endpoint(wmi_unified_t wmi_handle)
  2701. {
  2702. htc_flush_endpoint(wmi_handle->htc_handle,
  2703. wmi_handle->wmi_endpoint_id, 0);
  2704. }
  2705. /**
  2706. * generic function to block unified WMI command
  2707. * @param wmi_handle : handle to WMI.
  2708. * @return 0 on success and -ve on failure.
  2709. */
  2710. int
  2711. wmi_stop(wmi_unified_t wmi_handle)
  2712. {
  2713. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  2714. "WMI Stop\n");
  2715. wmi_handle->wmi_stopinprogress = 1;
  2716. return 0;
  2717. }
  2718. #endif