wmi_unified.c 80 KB

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