wmi_unified.c 96 KB

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