wmi_unified.c 95 KB

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