wmi_unified.c 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233
  1. /*
  2. * Copyright (c) 2015-2020 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /*
  19. * Host WMI unified implementation
  20. */
  21. #include "htc_api.h"
  22. #include "htc_api.h"
  23. #include "wmi_unified_priv.h"
  24. #include "wmi_unified_api.h"
  25. #include "qdf_module.h"
  26. #include "qdf_platform.h"
  27. #ifdef WMI_EXT_DBG
  28. #include "qdf_list.h"
  29. #include "qdf_atomic.h"
  30. #endif
  31. #ifndef WMI_NON_TLV_SUPPORT
  32. #include "wmi_tlv_helper.h"
  33. #endif
  34. #include <linux/debugfs.h>
  35. #include <target_if.h>
  36. #include <qdf_debugfs.h>
  37. #include "wmi_filtered_logging.h"
  38. #include <wmi_hang_event.h>
  39. /* This check for CONFIG_WIN temporary added due to redeclaration compilation
  40. error in MCL. Error is caused due to inclusion of wmi.h in wmi_unified_api.h
  41. which gets included here through ol_if_athvar.h. Eventually it is expected that
  42. wmi.h will be removed from wmi_unified_api.h after cleanup, which will need
  43. WMI_CMD_HDR to be defined here. */
  44. /* Copied from wmi.h */
  45. #undef MS
  46. #define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
  47. #undef SM
  48. #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
  49. #undef WO
  50. #define WO(_f) ((_f##_OFFSET) >> 2)
  51. #undef GET_FIELD
  52. #define GET_FIELD(_addr, _f) MS(*((uint32_t *)(_addr) + WO(_f)), _f)
  53. #undef SET_FIELD
  54. #define SET_FIELD(_addr, _f, _val) \
  55. (*((uint32_t *)(_addr) + WO(_f)) = \
  56. (*((uint32_t *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f))
  57. #define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \
  58. GET_FIELD(_msg_buf, _msg_type ## _ ## _f)
  59. #define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \
  60. SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val)
  61. #define WMI_EP_APASS 0x0
  62. #define WMI_EP_LPASS 0x1
  63. #define WMI_EP_SENSOR 0x2
  64. /*
  65. * * Control Path
  66. * */
  67. typedef PREPACK struct {
  68. uint32_t commandId:24,
  69. reserved:2, /* used for WMI endpoint ID */
  70. plt_priv:6; /* platform private */
  71. } POSTPACK WMI_CMD_HDR; /* used for commands and events */
  72. #define WMI_CMD_HDR_COMMANDID_LSB 0
  73. #define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff
  74. #define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000
  75. #define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000
  76. #define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24
  77. #define WMI_CMD_HDR_PLT_PRIV_LSB 24
  78. #define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000
  79. #define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000
  80. /* end of copy wmi.h */
  81. #define WMI_MIN_HEAD_ROOM 64
  82. /* WBUFF pool sizes for WMI */
  83. /* Allocation of size 256 bytes */
  84. #define WMI_WBUFF_POOL_0_SIZE 128
  85. /* Allocation of size 512 bytes */
  86. #define WMI_WBUFF_POOL_1_SIZE 16
  87. /* Allocation of size 1024 bytes */
  88. #define WMI_WBUFF_POOL_2_SIZE 8
  89. /* Allocation of size 2048 bytes */
  90. #define WMI_WBUFF_POOL_3_SIZE 8
  91. #ifdef WMI_INTERFACE_EVENT_LOGGING
  92. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
  93. /* TODO Cleanup this backported function */
  94. static int wmi_bp_seq_printf(qdf_debugfs_file_t m, const char *f, ...)
  95. {
  96. va_list args;
  97. va_start(args, f);
  98. seq_vprintf(m, f, args);
  99. va_end(args);
  100. return 0;
  101. }
  102. #else
  103. #define wmi_bp_seq_printf(m, fmt, ...) seq_printf((m), fmt, ##__VA_ARGS__)
  104. #endif
  105. #ifndef MAX_WMI_INSTANCES
  106. #define CUSTOM_MGMT_CMD_DATA_SIZE 4
  107. #endif
  108. #ifndef WMI_INTERFACE_EVENT_LOGGING_DYNAMIC_ALLOC
  109. /* WMI commands */
  110. uint32_t g_wmi_command_buf_idx = 0;
  111. struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  112. /* WMI commands TX completed */
  113. uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
  114. struct wmi_command_debug
  115. wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  116. /* WMI events when processed */
  117. uint32_t g_wmi_event_buf_idx = 0;
  118. struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  119. /* WMI events when queued */
  120. uint32_t g_wmi_rx_event_buf_idx = 0;
  121. struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  122. #endif
  123. #define WMI_COMMAND_RECORD(h, a, b) { \
  124. if (wmi_log_max_entry <= \
  125. *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
  126. *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
  127. ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
  128. [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
  129. .command = a; \
  130. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  131. wmi_command_log_buf_info.buf) \
  132. [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
  133. b, wmi_record_max_length); \
  134. ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
  135. [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
  136. time = qdf_get_log_timestamp(); \
  137. (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
  138. h->log_info.wmi_command_log_buf_info.length++; \
  139. }
  140. #define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
  141. if (wmi_log_max_entry <= \
  142. *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
  143. *(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  144. p_buf_tail_idx) = 0; \
  145. ((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. command = a; \
  150. qdf_mem_copy(((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. data, b, wmi_record_max_length); \
  155. ((struct wmi_command_debug *)h->log_info. \
  156. wmi_command_tx_cmp_log_buf_info.buf) \
  157. [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  158. p_buf_tail_idx)]. \
  159. time = qdf_get_log_timestamp(); \
  160. (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
  161. h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
  162. }
  163. #define WMI_EVENT_RECORD(h, a, b) { \
  164. if (wmi_log_max_entry <= \
  165. *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
  166. *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
  167. ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
  168. [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
  169. event = a; \
  170. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  171. wmi_event_log_buf_info.buf) \
  172. [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
  173. wmi_record_max_length); \
  174. ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
  175. [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
  176. qdf_get_log_timestamp(); \
  177. (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
  178. h->log_info.wmi_event_log_buf_info.length++; \
  179. }
  180. #define WMI_RX_EVENT_RECORD(h, a, b) { \
  181. if (wmi_log_max_entry <= \
  182. *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
  183. *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
  184. ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
  185. [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
  186. event = a; \
  187. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  188. wmi_rx_event_log_buf_info.buf) \
  189. [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
  190. data, b, wmi_record_max_length); \
  191. ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
  192. [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
  193. time = qdf_get_log_timestamp(); \
  194. (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
  195. h->log_info.wmi_rx_event_log_buf_info.length++; \
  196. }
  197. #ifndef WMI_INTERFACE_EVENT_LOGGING_DYNAMIC_ALLOC
  198. uint32_t g_wmi_mgmt_command_buf_idx = 0;
  199. struct
  200. wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
  201. /* wmi_mgmt commands TX completed */
  202. uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
  203. struct wmi_command_debug
  204. wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
  205. /* wmi_mgmt events when received */
  206. uint32_t g_wmi_mgmt_rx_event_buf_idx = 0;
  207. struct wmi_event_debug
  208. wmi_mgmt_rx_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
  209. /* wmi_diag events when received */
  210. uint32_t g_wmi_diag_rx_event_buf_idx = 0;
  211. struct wmi_event_debug
  212. wmi_diag_rx_event_log_buffer[WMI_DIAG_RX_EVENT_DEBUG_MAX_ENTRY];
  213. #endif
  214. #define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
  215. if (wmi_mgmt_log_max_entry <= \
  216. *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
  217. *(h->log_info.wmi_mgmt_command_log_buf_info. \
  218. p_buf_tail_idx) = 0; \
  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. command = a; \
  223. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  224. wmi_mgmt_command_log_buf_info.buf) \
  225. [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
  226. data, b, \
  227. wmi_record_max_length); \
  228. ((struct wmi_command_debug *)h->log_info. \
  229. wmi_mgmt_command_log_buf_info.buf) \
  230. [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
  231. time = qdf_get_log_timestamp(); \
  232. (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
  233. h->log_info.wmi_mgmt_command_log_buf_info.length++; \
  234. }
  235. #define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
  236. if (wmi_mgmt_log_max_entry <= \
  237. *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  238. p_buf_tail_idx)) \
  239. *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  240. p_buf_tail_idx) = 0; \
  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)].command = a; \
  245. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  246. wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
  247. [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  248. p_buf_tail_idx)].data, b, \
  249. wmi_record_max_length); \
  250. ((struct wmi_command_debug *)h->log_info. \
  251. wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
  252. [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  253. p_buf_tail_idx)].time = \
  254. qdf_get_log_timestamp(); \
  255. (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  256. p_buf_tail_idx))++; \
  257. h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
  258. }
  259. #define WMI_MGMT_RX_EVENT_RECORD(h, a, b) do { \
  260. if (wmi_mgmt_log_max_entry <= \
  261. *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
  262. *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
  263. ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
  264. [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
  265. .event = a; \
  266. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  267. wmi_mgmt_event_log_buf_info.buf) \
  268. [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
  269. data, b, wmi_record_max_length); \
  270. ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
  271. [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
  272. time = qdf_get_log_timestamp(); \
  273. (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
  274. h->log_info.wmi_mgmt_event_log_buf_info.length++; \
  275. } while (0);
  276. #define WMI_DIAG_RX_EVENT_RECORD(h, a, b) do { \
  277. if (wmi_diag_log_max_entry <= \
  278. *(h->log_info.wmi_diag_event_log_buf_info.p_buf_tail_idx))\
  279. *(h->log_info.wmi_diag_event_log_buf_info.p_buf_tail_idx) = 0;\
  280. ((struct wmi_event_debug *)h->log_info.wmi_diag_event_log_buf_info.buf)\
  281. [*(h->log_info.wmi_diag_event_log_buf_info.p_buf_tail_idx)]\
  282. .event = a; \
  283. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  284. wmi_diag_event_log_buf_info.buf) \
  285. [*(h->log_info.wmi_diag_event_log_buf_info.p_buf_tail_idx)].\
  286. data, b, wmi_record_max_length); \
  287. ((struct wmi_event_debug *)h->log_info.wmi_diag_event_log_buf_info.buf)\
  288. [*(h->log_info.wmi_diag_event_log_buf_info.p_buf_tail_idx)].\
  289. time = qdf_get_log_timestamp(); \
  290. (*(h->log_info.wmi_diag_event_log_buf_info.p_buf_tail_idx))++; \
  291. h->log_info.wmi_diag_event_log_buf_info.length++; \
  292. } while (0);
  293. /* These are defined to made it as module param, which can be configured */
  294. uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
  295. uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  296. uint32_t wmi_diag_log_max_entry = WMI_DIAG_RX_EVENT_DEBUG_MAX_ENTRY;
  297. uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
  298. uint32_t wmi_display_size = 100;
  299. #ifdef WMI_EXT_DBG
  300. /**
  301. * wmi_ext_dbg_msg_enqueue() - enqueue wmi message
  302. *
  303. * @wmi_handle: wmi handler
  304. *
  305. * Return: size of wmi message queue after enqueue
  306. */
  307. static uint32_t wmi_ext_dbg_msg_enqueue(struct wmi_unified *wmi_handle,
  308. struct wmi_ext_dbg_msg *msg)
  309. {
  310. uint32_t list_size;
  311. qdf_spinlock_acquire(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
  312. qdf_list_insert_back_size(&wmi_handle->wmi_ext_dbg_msg_queue,
  313. &msg->node, &list_size);
  314. qdf_spinlock_release(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
  315. return list_size;
  316. }
  317. /**
  318. * wmi_ext_dbg_msg_dequeue() - dequeue wmi message
  319. *
  320. * @wmi_handle: wmi handler
  321. *
  322. * Return: wmi msg on success else NULL
  323. */
  324. static struct wmi_ext_dbg_msg *wmi_ext_dbg_msg_dequeue(struct wmi_unified
  325. *wmi_handle)
  326. {
  327. qdf_list_node_t *list_node = NULL;
  328. qdf_spinlock_acquire(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
  329. qdf_list_remove_front(&wmi_handle->wmi_ext_dbg_msg_queue, &list_node);
  330. qdf_spinlock_release(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
  331. if (!list_node)
  332. return NULL;
  333. return qdf_container_of(list_node, struct wmi_ext_dbg_msg, node);
  334. }
  335. /**
  336. * wmi_ext_dbg_msg_record() - record wmi messages
  337. *
  338. * @wmi_handle: wmi handler
  339. * @buf: wmi message buffer
  340. * @len: wmi message length
  341. * @type: wmi message type
  342. *
  343. * Return: QDF_STATUS_SUCCESS on successful recording else failure.
  344. */
  345. static QDF_STATUS wmi_ext_dbg_msg_record(struct wmi_unified *wmi_handle,
  346. uint8_t *buf, uint32_t len,
  347. enum WMI_MSG_TYPE type)
  348. {
  349. struct wmi_ext_dbg_msg *msg;
  350. uint32_t list_size;
  351. msg = wmi_ext_dbg_msg_get(len);
  352. if (!msg)
  353. return QDF_STATUS_E_NOMEM;
  354. msg->len = len;
  355. msg->type = type;
  356. qdf_mem_copy(msg->buf, buf, len);
  357. msg->ts = qdf_get_log_timestamp();
  358. list_size = wmi_ext_dbg_msg_enqueue(wmi_handle, msg);
  359. if (list_size >= wmi_handle->wmi_ext_dbg_msg_queue_size) {
  360. msg = wmi_ext_dbg_msg_dequeue(wmi_handle);
  361. wmi_ext_dbg_msg_put(msg);
  362. }
  363. return QDF_STATUS_SUCCESS;
  364. }
  365. /**
  366. * wmi_ext_dbg_msg_cmd_record() - record wmi command messages
  367. *
  368. * @wmi_handle: wmi handler
  369. * @buf: wmi command buffer
  370. * @len: wmi command message length
  371. *
  372. * Return: QDF_STATUS_SUCCESS on successful recording else failure.
  373. */
  374. static QDF_STATUS wmi_ext_dbg_msg_cmd_record(struct wmi_unified *wmi_handle,
  375. uint8_t *buf, uint32_t len)
  376. {
  377. return wmi_ext_dbg_msg_record(wmi_handle, buf, len,
  378. WMI_MSG_TYPE_CMD);
  379. }
  380. /**
  381. * wmi_ext_dbg_msg_event_record() - record wmi event messages
  382. *
  383. * @wmi_handle: wmi handler
  384. * @buf: wmi event buffer
  385. * @len: wmi event message length
  386. *
  387. * Return: QDF_STATUS_SUCCESS on successful recording else failure.
  388. */
  389. static QDF_STATUS wmi_ext_dbg_msg_event_record(struct wmi_unified *wmi_handle,
  390. uint8_t *buf, uint32_t len)
  391. {
  392. uint32_t id;
  393. id = WMI_GET_FIELD(buf, WMI_CMD_HDR, COMMANDID);
  394. if (id != wmi_handle->wmi_events[wmi_diag_event_id])
  395. return wmi_ext_dbg_msg_record(wmi_handle, buf, len,
  396. WMI_MSG_TYPE_EVENT);
  397. return QDF_STATUS_SUCCESS;
  398. }
  399. /**
  400. * wmi_ext_dbg_msg_queue_init() - create debugfs queue and associated lock
  401. *
  402. * @wmi_handle: wmi handler
  403. *
  404. * Return: none
  405. */
  406. static void wmi_ext_dbg_msg_queue_init(struct wmi_unified *wmi_handle)
  407. {
  408. qdf_list_create(&wmi_handle->wmi_ext_dbg_msg_queue,
  409. wmi_handle->wmi_ext_dbg_msg_queue_size);
  410. qdf_spinlock_create(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
  411. }
  412. /**
  413. * wmi_ext_dbg_msg_queue_deinit() - destroy debugfs queue and associated lock
  414. *
  415. * @wmi_handle: wmi handler
  416. *
  417. * Return: none
  418. */
  419. static void wmi_ext_dbg_msg_queue_deinit(struct wmi_unified *wmi_handle)
  420. {
  421. qdf_list_destroy(&wmi_handle->wmi_ext_dbg_msg_queue);
  422. qdf_spinlock_destroy(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
  423. }
  424. /**
  425. * wmi_ext_dbg_msg_show() - debugfs function to display whole content of
  426. * wmi command/event messages including headers.
  427. *
  428. * @file: qdf debugfs file handler
  429. * @arg: pointer to wmi handler
  430. *
  431. * Return: QDF_STATUS_SUCCESS if all the messages are shown successfully,
  432. * else QDF_STATUS_E_AGAIN if more data to show.
  433. */
  434. static QDF_STATUS wmi_ext_dbg_msg_show(qdf_debugfs_file_t file, void *arg)
  435. {
  436. struct wmi_unified *wmi_handle = (struct wmi_unified *)arg;
  437. struct wmi_ext_dbg_msg *msg;
  438. uint64_t secs, usecs;
  439. msg = wmi_ext_dbg_msg_dequeue(wmi_handle);
  440. if (!msg)
  441. return QDF_STATUS_SUCCESS;
  442. qdf_debugfs_printf(file, "%s: 0x%x\n",
  443. msg->type == WMI_MSG_TYPE_CMD ? "COMMAND" :
  444. "EVENT", WMI_GET_FIELD(msg->buf, WMI_CMD_HDR,
  445. COMMANDID));
  446. qdf_log_timestamp_to_secs(msg->ts, &secs, &usecs);
  447. qdf_debugfs_printf(file, "Time: %llu.%llu\n", secs, usecs);
  448. qdf_debugfs_printf(file, "Length:%d\n", msg->len);
  449. qdf_debugfs_hexdump(file, msg->buf, msg->len,
  450. WMI_EXT_DBG_DUMP_ROW_SIZE,
  451. WMI_EXT_DBG_DUMP_GROUP_SIZE);
  452. qdf_debugfs_printf(file, "\n");
  453. if (qdf_debugfs_overflow(file)) {
  454. qdf_spinlock_acquire(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
  455. qdf_list_insert_front(&wmi_handle->wmi_ext_dbg_msg_queue,
  456. &msg->node);
  457. qdf_spinlock_release(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
  458. } else {
  459. wmi_ext_dbg_msg_put(msg);
  460. }
  461. return QDF_STATUS_E_AGAIN;
  462. }
  463. /**
  464. * wmi_ext_dbg_msg_write() - debugfs write not supported
  465. *
  466. * @priv: private data
  467. * @buf: received data buffer
  468. * @len: length of received buffer
  469. *
  470. * Return: QDF_STATUS_E_NOSUPPORT.
  471. */
  472. static QDF_STATUS wmi_ext_dbg_msg_write(void *priv, const char *buf,
  473. qdf_size_t len)
  474. {
  475. return QDF_STATUS_E_NOSUPPORT;
  476. }
  477. static struct qdf_debugfs_fops wmi_ext_dbgfs_ops = {
  478. .show = wmi_ext_dbg_msg_show,
  479. .write = wmi_ext_dbg_msg_write,
  480. .priv = NULL,
  481. };
  482. /**
  483. * wmi_ext_debugfs_init() - init debugfs items for extended wmi dump.
  484. *
  485. * @wmi_handle: wmi handler
  486. *
  487. * Return: QDF_STATUS_SUCCESS if debugfs is initialized else
  488. * QDF_STATUS_E_FAILURE
  489. */
  490. static QDF_STATUS wmi_ext_dbgfs_init(struct wmi_unified *wmi_handle)
  491. {
  492. qdf_dentry_t dentry;
  493. dentry = qdf_debugfs_create_dir(WMI_EXT_DBG_DIR, NULL);
  494. if (!dentry) {
  495. WMI_LOGE("error while creating extended wmi debugfs dir");
  496. return QDF_STATUS_E_FAILURE;
  497. }
  498. wmi_ext_dbgfs_ops.priv = wmi_handle;
  499. if (!qdf_debugfs_create_file(WMI_EXT_DBG_FILE, WMI_EXT_DBG_FILE_PERM,
  500. dentry, &wmi_ext_dbgfs_ops)) {
  501. qdf_debugfs_remove_dir(dentry);
  502. WMI_LOGE("error while creating extended wmi debugfs file");
  503. return QDF_STATUS_E_FAILURE;
  504. }
  505. wmi_handle->wmi_ext_dbg_dentry = dentry;
  506. wmi_handle->wmi_ext_dbg_msg_queue_size = WMI_EXT_DBG_QUEUE_SIZE;
  507. wmi_ext_dbg_msg_queue_init(wmi_handle);
  508. return QDF_STATUS_SUCCESS;
  509. }
  510. /**
  511. * wmi_ext_debugfs_deinit() - cleanup/deinit debugfs items of extended wmi dump.
  512. *
  513. * @wmi_handle: wmi handler
  514. *
  515. * Return: QDF_STATUS_SUCCESS if cleanup is successful
  516. */
  517. static QDF_STATUS wmi_ext_dbgfs_deinit(struct wmi_unified *wmi_handle)
  518. {
  519. struct wmi_ext_dbg_msg *msg;
  520. while ((msg = wmi_ext_dbg_msg_dequeue(wmi_handle)))
  521. wmi_ext_dbg_msg_put(msg);
  522. wmi_ext_dbg_msg_queue_deinit(wmi_handle);
  523. qdf_debugfs_remove_dir_recursive(wmi_handle->wmi_ext_dbg_dentry);
  524. return QDF_STATUS_SUCCESS;
  525. }
  526. #endif /*WMI_EXT_DBG */
  527. /**
  528. * wmi_log_init() - Initialize WMI event logging
  529. * @wmi_handle: WMI handle.
  530. *
  531. * Return: Initialization status
  532. */
  533. #ifndef WMI_INTERFACE_EVENT_LOGGING_DYNAMIC_ALLOC
  534. static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
  535. {
  536. struct wmi_log_buf_t *cmd_log_buf =
  537. &wmi_handle->log_info.wmi_command_log_buf_info;
  538. struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
  539. &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
  540. struct wmi_log_buf_t *event_log_buf =
  541. &wmi_handle->log_info.wmi_event_log_buf_info;
  542. struct wmi_log_buf_t *rx_event_log_buf =
  543. &wmi_handle->log_info.wmi_rx_event_log_buf_info;
  544. struct wmi_log_buf_t *mgmt_cmd_log_buf =
  545. &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
  546. struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
  547. &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
  548. struct wmi_log_buf_t *mgmt_event_log_buf =
  549. &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
  550. struct wmi_log_buf_t *diag_event_log_buf =
  551. &wmi_handle->log_info.wmi_diag_event_log_buf_info;
  552. /* WMI commands */
  553. cmd_log_buf->length = 0;
  554. cmd_log_buf->buf_tail_idx = 0;
  555. cmd_log_buf->buf = wmi_command_log_buffer;
  556. cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
  557. cmd_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  558. /* WMI commands TX completed */
  559. cmd_tx_cmpl_log_buf->length = 0;
  560. cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
  561. cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
  562. cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
  563. cmd_tx_cmpl_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  564. /* WMI events when processed */
  565. event_log_buf->length = 0;
  566. event_log_buf->buf_tail_idx = 0;
  567. event_log_buf->buf = wmi_event_log_buffer;
  568. event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
  569. event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  570. /* WMI events when queued */
  571. rx_event_log_buf->length = 0;
  572. rx_event_log_buf->buf_tail_idx = 0;
  573. rx_event_log_buf->buf = wmi_rx_event_log_buffer;
  574. rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
  575. rx_event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  576. /* WMI Management commands */
  577. mgmt_cmd_log_buf->length = 0;
  578. mgmt_cmd_log_buf->buf_tail_idx = 0;
  579. mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
  580. mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
  581. mgmt_cmd_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  582. /* WMI Management commands Tx completed*/
  583. mgmt_cmd_tx_cmp_log_buf->length = 0;
  584. mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
  585. mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
  586. mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
  587. &g_wmi_mgmt_command_tx_cmp_buf_idx;
  588. mgmt_cmd_tx_cmp_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  589. /* WMI Management events when received */
  590. mgmt_event_log_buf->length = 0;
  591. mgmt_event_log_buf->buf_tail_idx = 0;
  592. mgmt_event_log_buf->buf = wmi_mgmt_rx_event_log_buffer;
  593. mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_rx_event_buf_idx;
  594. mgmt_event_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  595. /* WMI diag events when received */
  596. diag_event_log_buf->length = 0;
  597. diag_event_log_buf->buf_tail_idx = 0;
  598. diag_event_log_buf->buf = wmi_diag_rx_event_log_buffer;
  599. diag_event_log_buf->p_buf_tail_idx = &g_wmi_diag_rx_event_buf_idx;
  600. diag_event_log_buf->size = WMI_DIAG_RX_EVENT_DEBUG_MAX_ENTRY;
  601. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  602. wmi_handle->log_info.wmi_logging_enable = 1;
  603. return QDF_STATUS_SUCCESS;
  604. }
  605. #else
  606. static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
  607. {
  608. struct wmi_log_buf_t *cmd_log_buf =
  609. &wmi_handle->log_info.wmi_command_log_buf_info;
  610. struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
  611. &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
  612. struct wmi_log_buf_t *event_log_buf =
  613. &wmi_handle->log_info.wmi_event_log_buf_info;
  614. struct wmi_log_buf_t *rx_event_log_buf =
  615. &wmi_handle->log_info.wmi_rx_event_log_buf_info;
  616. struct wmi_log_buf_t *mgmt_cmd_log_buf =
  617. &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
  618. struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
  619. &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
  620. struct wmi_log_buf_t *mgmt_event_log_buf =
  621. &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
  622. struct wmi_log_buf_t *diag_event_log_buf =
  623. &wmi_handle->log_info.wmi_diag_event_log_buf_info;
  624. wmi_handle->log_info.wmi_logging_enable = 0;
  625. /* WMI commands */
  626. cmd_log_buf->length = 0;
  627. cmd_log_buf->buf_tail_idx = 0;
  628. cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
  629. wmi_log_max_entry * sizeof(struct wmi_command_debug));
  630. cmd_log_buf->size = wmi_log_max_entry;
  631. if (!cmd_log_buf->buf)
  632. return QDF_STATUS_E_NOMEM;
  633. cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
  634. /* WMI commands TX completed */
  635. cmd_tx_cmpl_log_buf->length = 0;
  636. cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
  637. cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
  638. wmi_log_max_entry * sizeof(struct wmi_command_debug));
  639. cmd_tx_cmpl_log_buf->size = wmi_log_max_entry;
  640. if (!cmd_tx_cmpl_log_buf->buf)
  641. return QDF_STATUS_E_NOMEM;
  642. cmd_tx_cmpl_log_buf->p_buf_tail_idx =
  643. &cmd_tx_cmpl_log_buf->buf_tail_idx;
  644. /* WMI events when processed */
  645. event_log_buf->length = 0;
  646. event_log_buf->buf_tail_idx = 0;
  647. event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  648. wmi_log_max_entry * sizeof(struct wmi_event_debug));
  649. event_log_buf->size = wmi_log_max_entry;
  650. if (!event_log_buf->buf)
  651. return QDF_STATUS_E_NOMEM;
  652. event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
  653. /* WMI events when queued */
  654. rx_event_log_buf->length = 0;
  655. rx_event_log_buf->buf_tail_idx = 0;
  656. rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  657. wmi_log_max_entry * sizeof(struct wmi_event_debug));
  658. rx_event_log_buf->size = wmi_log_max_entry;
  659. if (!rx_event_log_buf->buf)
  660. return QDF_STATUS_E_NOMEM;
  661. rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
  662. /* WMI Management commands */
  663. mgmt_cmd_log_buf->length = 0;
  664. mgmt_cmd_log_buf->buf_tail_idx = 0;
  665. mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
  666. wmi_mgmt_log_max_entry * sizeof(struct wmi_command_debug));
  667. mgmt_cmd_log_buf->size = wmi_mgmt_log_max_entry;
  668. if (!mgmt_cmd_log_buf->buf)
  669. return QDF_STATUS_E_NOMEM;
  670. mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
  671. /* WMI Management commands Tx completed*/
  672. mgmt_cmd_tx_cmp_log_buf->length = 0;
  673. mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
  674. mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
  675. qdf_mem_malloc(
  676. wmi_mgmt_log_max_entry *
  677. sizeof(struct wmi_command_debug));
  678. mgmt_cmd_tx_cmp_log_buf->size = wmi_mgmt_log_max_entry;
  679. if (!mgmt_cmd_tx_cmp_log_buf->buf)
  680. return QDF_STATUS_E_NOMEM;
  681. mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
  682. &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
  683. /* WMI Management events when received */
  684. mgmt_event_log_buf->length = 0;
  685. mgmt_event_log_buf->buf_tail_idx = 0;
  686. mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  687. wmi_mgmt_log_max_entry *
  688. sizeof(struct wmi_event_debug));
  689. mgmt_event_log_buf->size = wmi_mgmt_log_max_entry;
  690. if (!mgmt_event_log_buf->buf)
  691. return QDF_STATUS_E_NOMEM;
  692. mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
  693. /* WMI diag events when received */
  694. diag_event_log_buf->length = 0;
  695. diag_event_log_buf->buf_tail_idx = 0;
  696. diag_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  697. wmi_diag_log_max_entry *
  698. sizeof(struct wmi_event_debug));
  699. diag_event_log_buf->size = wmi_diag_log_max_entry;
  700. if (!diag_event_log_buf->buf)
  701. return QDF_STATUS_E_NOMEM;
  702. diag_event_log_buf->p_buf_tail_idx = &diag_event_log_buf->buf_tail_idx;
  703. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  704. wmi_handle->log_info.wmi_logging_enable = 1;
  705. wmi_filtered_logging_init(wmi_handle);
  706. return QDF_STATUS_SUCCESS;
  707. }
  708. #endif
  709. /**
  710. * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
  711. * event logging
  712. * @wmi_handle: WMI handle.
  713. *
  714. * Return: None
  715. */
  716. #ifdef WMI_INTERFACE_EVENT_LOGGING_DYNAMIC_ALLOC
  717. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
  718. {
  719. wmi_filtered_logging_free(wmi_handle);
  720. if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
  721. qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
  722. if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
  723. qdf_mem_free(
  724. wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
  725. if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
  726. qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
  727. if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
  728. qdf_mem_free(
  729. wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
  730. if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
  731. qdf_mem_free(
  732. wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
  733. if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
  734. qdf_mem_free(
  735. wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
  736. if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
  737. qdf_mem_free(
  738. wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
  739. if (wmi_handle->log_info.wmi_diag_event_log_buf_info.buf)
  740. qdf_mem_free(
  741. wmi_handle->log_info.wmi_diag_event_log_buf_info.buf);
  742. wmi_handle->log_info.wmi_logging_enable = 0;
  743. qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
  744. }
  745. #else
  746. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
  747. {
  748. /* Do Nothing */
  749. }
  750. #endif
  751. /**
  752. * wmi_print_cmd_log_buffer() - an output agnostic wmi command log printer
  753. * @log_buffer: the command log buffer metadata of the buffer to print
  754. * @count: the maximum number of entries to print
  755. * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
  756. * @print_priv: any data required by the print method, e.g. a file handle
  757. *
  758. * Return: None
  759. */
  760. static void
  761. wmi_print_cmd_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
  762. qdf_abstract_print *print, void *print_priv)
  763. {
  764. static const int data_len =
  765. WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
  766. char str[128];
  767. uint32_t idx;
  768. if (count > log_buffer->size)
  769. count = log_buffer->size;
  770. if (count > log_buffer->length)
  771. count = log_buffer->length;
  772. /* subtract count from index, and wrap if necessary */
  773. idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
  774. idx %= log_buffer->size;
  775. print(print_priv, "Time (seconds) Cmd Id Payload");
  776. while (count) {
  777. struct wmi_command_debug *cmd_log = (struct wmi_command_debug *)
  778. &((struct wmi_command_debug *)log_buffer->buf)[idx];
  779. uint64_t secs, usecs;
  780. int len = 0;
  781. int i;
  782. qdf_log_timestamp_to_secs(cmd_log->time, &secs, &usecs);
  783. len += scnprintf(str + len, sizeof(str) - len,
  784. "% 8lld.%06lld %6u (0x%06x) ",
  785. secs, usecs,
  786. cmd_log->command, cmd_log->command);
  787. for (i = 0; i < data_len; ++i) {
  788. len += scnprintf(str + len, sizeof(str) - len,
  789. "0x%08x ", cmd_log->data[i]);
  790. }
  791. print(print_priv, str);
  792. --count;
  793. ++idx;
  794. if (idx >= log_buffer->size)
  795. idx = 0;
  796. }
  797. }
  798. /**
  799. * wmi_print_event_log_buffer() - an output agnostic wmi event log printer
  800. * @log_buffer: the event log buffer metadata of the buffer to print
  801. * @count: the maximum number of entries to print
  802. * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
  803. * @print_priv: any data required by the print method, e.g. a file handle
  804. *
  805. * Return: None
  806. */
  807. static void
  808. wmi_print_event_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
  809. qdf_abstract_print *print, void *print_priv)
  810. {
  811. static const int data_len =
  812. WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
  813. char str[128];
  814. uint32_t idx;
  815. if (count > log_buffer->size)
  816. count = log_buffer->size;
  817. if (count > log_buffer->length)
  818. count = log_buffer->length;
  819. /* subtract count from index, and wrap if necessary */
  820. idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
  821. idx %= log_buffer->size;
  822. print(print_priv, "Time (seconds) Event Id Payload");
  823. while (count) {
  824. struct wmi_event_debug *event_log = (struct wmi_event_debug *)
  825. &((struct wmi_event_debug *)log_buffer->buf)[idx];
  826. uint64_t secs, usecs;
  827. int len = 0;
  828. int i;
  829. qdf_log_timestamp_to_secs(event_log->time, &secs, &usecs);
  830. len += scnprintf(str + len, sizeof(str) - len,
  831. "% 8lld.%06lld %6u (0x%06x) ",
  832. secs, usecs,
  833. event_log->event, event_log->event);
  834. for (i = 0; i < data_len; ++i) {
  835. len += scnprintf(str + len, sizeof(str) - len,
  836. "0x%08x ", event_log->data[i]);
  837. }
  838. print(print_priv, str);
  839. --count;
  840. ++idx;
  841. if (idx >= log_buffer->size)
  842. idx = 0;
  843. }
  844. }
  845. inline void
  846. wmi_print_cmd_log(wmi_unified_t wmi, uint32_t count,
  847. qdf_abstract_print *print, void *print_priv)
  848. {
  849. wmi_print_cmd_log_buffer(
  850. &wmi->log_info.wmi_command_log_buf_info,
  851. count, print, print_priv);
  852. }
  853. inline void
  854. wmi_print_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
  855. qdf_abstract_print *print, void *print_priv)
  856. {
  857. wmi_print_cmd_log_buffer(
  858. &wmi->log_info.wmi_command_tx_cmp_log_buf_info,
  859. count, print, print_priv);
  860. }
  861. inline void
  862. wmi_print_mgmt_cmd_log(wmi_unified_t wmi, uint32_t count,
  863. qdf_abstract_print *print, void *print_priv)
  864. {
  865. wmi_print_cmd_log_buffer(
  866. &wmi->log_info.wmi_mgmt_command_log_buf_info,
  867. count, print, print_priv);
  868. }
  869. inline void
  870. wmi_print_mgmt_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
  871. qdf_abstract_print *print, void *print_priv)
  872. {
  873. wmi_print_cmd_log_buffer(
  874. &wmi->log_info.wmi_mgmt_command_tx_cmp_log_buf_info,
  875. count, print, print_priv);
  876. }
  877. inline void
  878. wmi_print_event_log(wmi_unified_t wmi, uint32_t count,
  879. qdf_abstract_print *print, void *print_priv)
  880. {
  881. wmi_print_event_log_buffer(
  882. &wmi->log_info.wmi_event_log_buf_info,
  883. count, print, print_priv);
  884. }
  885. inline void
  886. wmi_print_rx_event_log(wmi_unified_t wmi, uint32_t count,
  887. qdf_abstract_print *print, void *print_priv)
  888. {
  889. wmi_print_event_log_buffer(
  890. &wmi->log_info.wmi_rx_event_log_buf_info,
  891. count, print, print_priv);
  892. }
  893. inline void
  894. wmi_print_mgmt_event_log(wmi_unified_t wmi, uint32_t count,
  895. qdf_abstract_print *print, void *print_priv)
  896. {
  897. wmi_print_event_log_buffer(
  898. &wmi->log_info.wmi_mgmt_event_log_buf_info,
  899. count, print, print_priv);
  900. }
  901. /* debugfs routines*/
  902. /**
  903. * debug_wmi_##func_base##_show() - debugfs functions to display content of
  904. * command and event buffers. Macro uses max buffer length to display
  905. * buffer when it is wraparound.
  906. *
  907. * @m: debugfs handler to access wmi_handle
  908. * @v: Variable arguments (not used)
  909. *
  910. * Return: Length of characters printed
  911. */
  912. #define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
  913. static int debug_wmi_##func_base##_show(struct seq_file *m, \
  914. void *v) \
  915. { \
  916. wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
  917. struct wmi_log_buf_t *wmi_log = \
  918. &wmi_handle->log_info.wmi_##func_base##_buf_info;\
  919. int pos, nread, outlen; \
  920. int i; \
  921. uint64_t secs, usecs; \
  922. \
  923. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);\
  924. if (!wmi_log->length) { \
  925. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);\
  926. return wmi_bp_seq_printf(m, \
  927. "no elements to read from ring buffer!\n"); \
  928. } \
  929. \
  930. if (wmi_log->length <= wmi_ring_size) \
  931. nread = wmi_log->length; \
  932. else \
  933. nread = wmi_ring_size; \
  934. \
  935. if (*(wmi_log->p_buf_tail_idx) == 0) \
  936. /* tail can be 0 after wrap-around */ \
  937. pos = wmi_ring_size - 1; \
  938. else \
  939. pos = *(wmi_log->p_buf_tail_idx) - 1; \
  940. \
  941. outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
  942. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);\
  943. while (nread--) { \
  944. struct wmi_command_debug *wmi_record; \
  945. \
  946. wmi_record = (struct wmi_command_debug *) \
  947. &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
  948. outlen += wmi_bp_seq_printf(m, "CMD ID = %x\n", \
  949. (wmi_record->command)); \
  950. qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
  951. &usecs); \
  952. outlen += \
  953. wmi_bp_seq_printf(m, "CMD TIME = [%llu.%06llu]\n",\
  954. secs, usecs); \
  955. outlen += wmi_bp_seq_printf(m, "CMD = "); \
  956. for (i = 0; i < (wmi_record_max_length/ \
  957. sizeof(uint32_t)); i++) \
  958. outlen += wmi_bp_seq_printf(m, "%x ", \
  959. wmi_record->data[i]); \
  960. outlen += wmi_bp_seq_printf(m, "\n"); \
  961. \
  962. if (pos == 0) \
  963. pos = wmi_ring_size - 1; \
  964. else \
  965. pos--; \
  966. } \
  967. return outlen; \
  968. } \
  969. #define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
  970. static int debug_wmi_##func_base##_show(struct seq_file *m, \
  971. void *v) \
  972. { \
  973. wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
  974. struct wmi_log_buf_t *wmi_log = \
  975. &wmi_handle->log_info.wmi_##func_base##_buf_info;\
  976. int pos, nread, outlen; \
  977. int i; \
  978. uint64_t secs, usecs; \
  979. \
  980. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);\
  981. if (!wmi_log->length) { \
  982. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);\
  983. return wmi_bp_seq_printf(m, \
  984. "no elements to read from ring buffer!\n"); \
  985. } \
  986. \
  987. if (wmi_log->length <= wmi_ring_size) \
  988. nread = wmi_log->length; \
  989. else \
  990. nread = wmi_ring_size; \
  991. \
  992. if (*(wmi_log->p_buf_tail_idx) == 0) \
  993. /* tail can be 0 after wrap-around */ \
  994. pos = wmi_ring_size - 1; \
  995. else \
  996. pos = *(wmi_log->p_buf_tail_idx) - 1; \
  997. \
  998. outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
  999. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);\
  1000. while (nread--) { \
  1001. struct wmi_event_debug *wmi_record; \
  1002. \
  1003. wmi_record = (struct wmi_event_debug *) \
  1004. &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
  1005. qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
  1006. &usecs); \
  1007. outlen += wmi_bp_seq_printf(m, "Event ID = %x\n",\
  1008. (wmi_record->event)); \
  1009. outlen += \
  1010. wmi_bp_seq_printf(m, "Event TIME = [%llu.%06llu]\n",\
  1011. secs, usecs); \
  1012. outlen += wmi_bp_seq_printf(m, "CMD = "); \
  1013. for (i = 0; i < (wmi_record_max_length/ \
  1014. sizeof(uint32_t)); i++) \
  1015. outlen += wmi_bp_seq_printf(m, "%x ", \
  1016. wmi_record->data[i]); \
  1017. outlen += wmi_bp_seq_printf(m, "\n"); \
  1018. \
  1019. if (pos == 0) \
  1020. pos = wmi_ring_size - 1; \
  1021. else \
  1022. pos--; \
  1023. } \
  1024. return outlen; \
  1025. }
  1026. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
  1027. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
  1028. GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
  1029. GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
  1030. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
  1031. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
  1032. wmi_display_size);
  1033. GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
  1034. /**
  1035. * debug_wmi_enable_show() - debugfs functions to display enable state of
  1036. * wmi logging feature.
  1037. *
  1038. * @m: debugfs handler to access wmi_handle
  1039. * @v: Variable arguments (not used)
  1040. *
  1041. * Return: always 1
  1042. */
  1043. static int debug_wmi_enable_show(struct seq_file *m, void *v)
  1044. {
  1045. wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
  1046. return wmi_bp_seq_printf(m, "%d\n",
  1047. wmi_handle->log_info.wmi_logging_enable);
  1048. }
  1049. /**
  1050. * debug_wmi_log_size_show() - debugfs functions to display configured size of
  1051. * wmi logging command/event buffer and management command/event buffer.
  1052. *
  1053. * @m: debugfs handler to access wmi_handle
  1054. * @v: Variable arguments (not used)
  1055. *
  1056. * Return: Length of characters printed
  1057. */
  1058. static int debug_wmi_log_size_show(struct seq_file *m, void *v)
  1059. {
  1060. wmi_bp_seq_printf(m, "WMI command/event log max size:%d\n",
  1061. wmi_log_max_entry);
  1062. return wmi_bp_seq_printf(m,
  1063. "WMI management command/events log max size:%d\n",
  1064. wmi_mgmt_log_max_entry);
  1065. }
  1066. /**
  1067. * debug_wmi_##func_base##_write() - debugfs functions to clear
  1068. * wmi logging command/event buffer and management command/event buffer.
  1069. *
  1070. * @file: file handler to access wmi_handle
  1071. * @buf: received data buffer
  1072. * @count: length of received buffer
  1073. * @ppos: Not used
  1074. *
  1075. * Return: count
  1076. */
  1077. #define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
  1078. static ssize_t debug_wmi_##func_base##_write(struct file *file, \
  1079. const char __user *buf, \
  1080. size_t count, loff_t *ppos) \
  1081. { \
  1082. int k, ret; \
  1083. wmi_unified_t wmi_handle = \
  1084. ((struct seq_file *)file->private_data)->private;\
  1085. struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
  1086. wmi_##func_base##_buf_info; \
  1087. char locbuf[50]; \
  1088. \
  1089. if ((!buf) || (count > 50)) \
  1090. return -EFAULT; \
  1091. \
  1092. if (copy_from_user(locbuf, buf, count)) \
  1093. return -EFAULT; \
  1094. \
  1095. ret = sscanf(locbuf, "%d", &k); \
  1096. if ((ret != 1) || (k != 0)) { \
  1097. WMI_LOGE("Wrong input, echo 0 to clear the wmi buffer");\
  1098. return -EINVAL; \
  1099. } \
  1100. \
  1101. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);\
  1102. qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
  1103. sizeof(struct wmi_record_type)); \
  1104. wmi_log->length = 0; \
  1105. *(wmi_log->p_buf_tail_idx) = 0; \
  1106. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);\
  1107. \
  1108. return count; \
  1109. }
  1110. GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
  1111. wmi_command_debug);
  1112. GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
  1113. wmi_command_debug);
  1114. GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
  1115. wmi_event_debug);
  1116. GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
  1117. wmi_event_debug);
  1118. GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
  1119. wmi_command_debug);
  1120. GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
  1121. wmi_mgmt_log_max_entry, wmi_command_debug);
  1122. GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
  1123. wmi_event_debug);
  1124. /**
  1125. * debug_wmi_enable_write() - debugfs functions to enable/disable
  1126. * wmi logging feature.
  1127. *
  1128. * @file: file handler to access wmi_handle
  1129. * @buf: received data buffer
  1130. * @count: length of received buffer
  1131. * @ppos: Not used
  1132. *
  1133. * Return: count
  1134. */
  1135. static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
  1136. size_t count, loff_t *ppos)
  1137. {
  1138. wmi_unified_t wmi_handle =
  1139. ((struct seq_file *)file->private_data)->private;
  1140. int k, ret;
  1141. char locbuf[50];
  1142. if ((!buf) || (count > 50))
  1143. return -EFAULT;
  1144. if (copy_from_user(locbuf, buf, count))
  1145. return -EFAULT;
  1146. ret = sscanf(locbuf, "%d", &k);
  1147. if ((ret != 1) || ((k != 0) && (k != 1)))
  1148. return -EINVAL;
  1149. wmi_handle->log_info.wmi_logging_enable = k;
  1150. return count;
  1151. }
  1152. /**
  1153. * debug_wmi_log_size_write() - reserved.
  1154. *
  1155. * @file: file handler to access wmi_handle
  1156. * @buf: received data buffer
  1157. * @count: length of received buffer
  1158. * @ppos: Not used
  1159. *
  1160. * Return: count
  1161. */
  1162. static ssize_t debug_wmi_log_size_write(struct file *file,
  1163. const char __user *buf, size_t count, loff_t *ppos)
  1164. {
  1165. return -EINVAL;
  1166. }
  1167. /* Structure to maintain debug information */
  1168. struct wmi_debugfs_info {
  1169. const char *name;
  1170. const struct file_operations *ops;
  1171. };
  1172. #define DEBUG_FOO(func_base) { .name = #func_base, \
  1173. .ops = &debug_##func_base##_ops }
  1174. /**
  1175. * debug_##func_base##_open() - Open debugfs entry for respective command
  1176. * and event buffer.
  1177. *
  1178. * @inode: node for debug dir entry
  1179. * @file: file handler
  1180. *
  1181. * Return: open status
  1182. */
  1183. #define GENERATE_DEBUG_STRUCTS(func_base) \
  1184. static int debug_##func_base##_open(struct inode *inode, \
  1185. struct file *file) \
  1186. { \
  1187. return single_open(file, debug_##func_base##_show, \
  1188. inode->i_private); \
  1189. } \
  1190. \
  1191. \
  1192. static struct file_operations debug_##func_base##_ops = { \
  1193. .open = debug_##func_base##_open, \
  1194. .read = seq_read, \
  1195. .llseek = seq_lseek, \
  1196. .write = debug_##func_base##_write, \
  1197. .release = single_release, \
  1198. };
  1199. GENERATE_DEBUG_STRUCTS(wmi_command_log);
  1200. GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
  1201. GENERATE_DEBUG_STRUCTS(wmi_event_log);
  1202. GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
  1203. GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
  1204. GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
  1205. GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
  1206. GENERATE_DEBUG_STRUCTS(wmi_enable);
  1207. GENERATE_DEBUG_STRUCTS(wmi_log_size);
  1208. #ifdef WMI_INTERFACE_FILTERED_EVENT_LOGGING
  1209. GENERATE_DEBUG_STRUCTS(filtered_wmi_cmds);
  1210. GENERATE_DEBUG_STRUCTS(filtered_wmi_evts);
  1211. GENERATE_DEBUG_STRUCTS(wmi_filtered_command_log);
  1212. GENERATE_DEBUG_STRUCTS(wmi_filtered_event_log);
  1213. #endif
  1214. struct wmi_debugfs_info wmi_debugfs_infos[NUM_DEBUG_INFOS] = {
  1215. DEBUG_FOO(wmi_command_log),
  1216. DEBUG_FOO(wmi_command_tx_cmp_log),
  1217. DEBUG_FOO(wmi_event_log),
  1218. DEBUG_FOO(wmi_rx_event_log),
  1219. DEBUG_FOO(wmi_mgmt_command_log),
  1220. DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
  1221. DEBUG_FOO(wmi_mgmt_event_log),
  1222. DEBUG_FOO(wmi_enable),
  1223. DEBUG_FOO(wmi_log_size),
  1224. #ifdef WMI_INTERFACE_FILTERED_EVENT_LOGGING
  1225. DEBUG_FOO(filtered_wmi_cmds),
  1226. DEBUG_FOO(filtered_wmi_evts),
  1227. DEBUG_FOO(wmi_filtered_command_log),
  1228. DEBUG_FOO(wmi_filtered_event_log),
  1229. #endif
  1230. };
  1231. /**
  1232. * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
  1233. *
  1234. * @wmi_handle: wmi handle
  1235. * @par_entry: debug directory entry
  1236. * @id: Index to debug info data array
  1237. *
  1238. * Return: none
  1239. */
  1240. static void wmi_debugfs_create(wmi_unified_t wmi_handle,
  1241. struct dentry *par_entry)
  1242. {
  1243. int i;
  1244. if (!par_entry)
  1245. goto out;
  1246. for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
  1247. wmi_handle->debugfs_de[i] = debugfs_create_file(
  1248. wmi_debugfs_infos[i].name, 0644, par_entry,
  1249. wmi_handle, wmi_debugfs_infos[i].ops);
  1250. if (!wmi_handle->debugfs_de[i]) {
  1251. WMI_LOGE("debug Entry creation failed!");
  1252. goto out;
  1253. }
  1254. }
  1255. return;
  1256. out:
  1257. WMI_LOGE("debug Entry creation failed!");
  1258. wmi_log_buffer_free(wmi_handle);
  1259. return;
  1260. }
  1261. /**
  1262. * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
  1263. * @wmi_handle: wmi handle
  1264. * @dentry: debugfs directory entry
  1265. * @id: Index to debug info data array
  1266. *
  1267. * Return: none
  1268. */
  1269. static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
  1270. {
  1271. int i;
  1272. struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
  1273. if (dentry) {
  1274. for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
  1275. if (wmi_handle->debugfs_de[i])
  1276. wmi_handle->debugfs_de[i] = NULL;
  1277. }
  1278. }
  1279. if (dentry)
  1280. debugfs_remove_recursive(dentry);
  1281. }
  1282. /**
  1283. * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
  1284. * create debugfs enteries.
  1285. *
  1286. * @h: wmi handler
  1287. *
  1288. * Return: init status
  1289. */
  1290. static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle, uint32_t pdev_idx)
  1291. {
  1292. char buf[32];
  1293. snprintf(buf, sizeof(buf), "WMI_SOC%u_PDEV%u",
  1294. wmi_handle->soc->soc_idx, pdev_idx);
  1295. wmi_handle->log_info.wmi_log_debugfs_dir =
  1296. debugfs_create_dir(buf, NULL);
  1297. if (!wmi_handle->log_info.wmi_log_debugfs_dir) {
  1298. WMI_LOGE("error while creating debugfs dir for %s", buf);
  1299. return QDF_STATUS_E_FAILURE;
  1300. }
  1301. wmi_debugfs_create(wmi_handle,
  1302. wmi_handle->log_info.wmi_log_debugfs_dir);
  1303. return QDF_STATUS_SUCCESS;
  1304. }
  1305. /**
  1306. * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
  1307. *
  1308. * @wmi_handle: wmi handle
  1309. * @cmd: mgmt command
  1310. * @header: pointer to 802.11 header
  1311. * @vdev_id: vdev id
  1312. * @chanfreq: channel frequency
  1313. *
  1314. * Return: none
  1315. */
  1316. void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
  1317. void *header, uint32_t vdev_id, uint32_t chanfreq)
  1318. {
  1319. uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
  1320. data[0] = ((struct wmi_command_header *)header)->type;
  1321. data[1] = ((struct wmi_command_header *)header)->sub_type;
  1322. data[2] = vdev_id;
  1323. data[3] = chanfreq;
  1324. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1325. WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, (uint8_t *)data);
  1326. wmi_specific_cmd_record(wmi_handle, cmd, (uint8_t *)data);
  1327. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1328. }
  1329. #else
  1330. /**
  1331. * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
  1332. * @wmi_handle: wmi handle
  1333. * @dentry: debugfs directory entry
  1334. * @id: Index to debug info data array
  1335. *
  1336. * Return: none
  1337. */
  1338. static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
  1339. void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
  1340. void *header, uint32_t vdev_id, uint32_t chanfreq) { }
  1341. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
  1342. #endif /*WMI_INTERFACE_EVENT_LOGGING */
  1343. qdf_export_symbol(wmi_mgmt_cmd_record);
  1344. int wmi_get_host_credits(wmi_unified_t wmi_handle);
  1345. /* WMI buffer APIs */
  1346. #ifdef NBUF_MEMORY_DEBUG
  1347. wmi_buf_t
  1348. wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint32_t len,
  1349. const char *func_name,
  1350. uint32_t line_num)
  1351. {
  1352. wmi_buf_t wmi_buf;
  1353. if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
  1354. QDF_ASSERT(0);
  1355. return NULL;
  1356. }
  1357. wmi_buf = wbuff_buff_get(wmi_handle->wbuff_handle, len, func_name,
  1358. line_num);
  1359. if (!wmi_buf)
  1360. wmi_buf = qdf_nbuf_alloc_debug(NULL,
  1361. roundup(len + WMI_MIN_HEAD_ROOM,
  1362. 4),
  1363. WMI_MIN_HEAD_ROOM, 4, false,
  1364. func_name, line_num);
  1365. if (!wmi_buf)
  1366. return NULL;
  1367. /* Clear the wmi buffer */
  1368. OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
  1369. /*
  1370. * Set the length of the buffer to match the allocation size.
  1371. */
  1372. qdf_nbuf_set_pktlen(wmi_buf, len);
  1373. return wmi_buf;
  1374. }
  1375. qdf_export_symbol(wmi_buf_alloc_debug);
  1376. void wmi_buf_free(wmi_buf_t net_buf)
  1377. {
  1378. net_buf = wbuff_buff_put(net_buf);
  1379. if (net_buf)
  1380. qdf_nbuf_free(net_buf);
  1381. }
  1382. qdf_export_symbol(wmi_buf_free);
  1383. #else
  1384. wmi_buf_t wmi_buf_alloc_fl(wmi_unified_t wmi_handle, uint32_t len,
  1385. const char *func, uint32_t line)
  1386. {
  1387. wmi_buf_t wmi_buf;
  1388. if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
  1389. QDF_DEBUG_PANIC("Invalid length %u (via %s:%u)",
  1390. len, func, line);
  1391. return NULL;
  1392. }
  1393. wmi_buf = wbuff_buff_get(wmi_handle->wbuff_handle, len, __func__,
  1394. __LINE__);
  1395. if (!wmi_buf)
  1396. wmi_buf = qdf_nbuf_alloc_fl(NULL, roundup(len +
  1397. WMI_MIN_HEAD_ROOM, 4), WMI_MIN_HEAD_ROOM, 4,
  1398. false, func, line);
  1399. if (!wmi_buf) {
  1400. wmi_nofl_err("%s:%d, failed to alloc len:%d", func, line, len);
  1401. return NULL;
  1402. }
  1403. /* Clear the wmi buffer */
  1404. OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
  1405. /*
  1406. * Set the length of the buffer to match the allocation size.
  1407. */
  1408. qdf_nbuf_set_pktlen(wmi_buf, len);
  1409. return wmi_buf;
  1410. }
  1411. qdf_export_symbol(wmi_buf_alloc_fl);
  1412. void wmi_buf_free(wmi_buf_t net_buf)
  1413. {
  1414. net_buf = wbuff_buff_put(net_buf);
  1415. if (net_buf)
  1416. qdf_nbuf_free(net_buf);
  1417. }
  1418. qdf_export_symbol(wmi_buf_free);
  1419. #endif
  1420. /**
  1421. * wmi_get_max_msg_len() - get maximum WMI message length
  1422. * @wmi_handle: WMI handle.
  1423. *
  1424. * This function returns the maximum WMI message length
  1425. *
  1426. * Return: maximum WMI message length
  1427. */
  1428. uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
  1429. {
  1430. return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
  1431. }
  1432. qdf_export_symbol(wmi_get_max_msg_len);
  1433. #ifndef WMI_CMD_STRINGS
  1434. static uint8_t *wmi_id_to_name(uint32_t wmi_command)
  1435. {
  1436. return "Invalid WMI cmd";
  1437. }
  1438. #endif
  1439. static inline void wmi_log_cmd_id(uint32_t cmd_id, uint32_t tag)
  1440. {
  1441. WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d",
  1442. wmi_id_to_name(cmd_id), cmd_id, tag);
  1443. }
  1444. /**
  1445. * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
  1446. * @cmd_id: command to check
  1447. *
  1448. * Return: true if the command is part of the resume sequence.
  1449. */
  1450. #ifdef WLAN_POWER_MANAGEMENT_OFFLOAD
  1451. static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
  1452. {
  1453. switch (cmd_id) {
  1454. case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
  1455. case WMI_PDEV_RESUME_CMDID:
  1456. return true;
  1457. default:
  1458. return false;
  1459. }
  1460. }
  1461. #else
  1462. static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
  1463. {
  1464. return false;
  1465. }
  1466. #endif
  1467. #ifdef FEATURE_WLAN_D0WOW
  1468. static bool wmi_is_legacy_d0wow_disable_cmd(wmi_buf_t buf, uint32_t cmd_id)
  1469. {
  1470. wmi_d0_wow_enable_disable_cmd_fixed_param *cmd;
  1471. if (cmd_id == WMI_D0_WOW_ENABLE_DISABLE_CMDID) {
  1472. cmd = (wmi_d0_wow_enable_disable_cmd_fixed_param *)
  1473. wmi_buf_data(buf);
  1474. if (!cmd->enable)
  1475. return true;
  1476. else
  1477. return false;
  1478. }
  1479. return false;
  1480. }
  1481. #else
  1482. static bool wmi_is_legacy_d0wow_disable_cmd(wmi_buf_t buf, uint32_t cmd_id)
  1483. {
  1484. return false;
  1485. }
  1486. #endif
  1487. static inline void wmi_unified_debug_dump(wmi_unified_t wmi_handle)
  1488. {
  1489. wmi_nofl_err("Endpoint ID = %d, Tx Queue Depth = %d, soc_id = %u, target type = %s",
  1490. wmi_handle->wmi_endpoint_id,
  1491. htc_get_tx_queue_depth(wmi_handle->htc_handle,
  1492. wmi_handle->wmi_endpoint_id),
  1493. wmi_handle->soc->soc_idx,
  1494. (wmi_handle->target_type ==
  1495. WMI_TLV_TARGET ? "WMI_TLV_TARGET" :
  1496. "WMI_NON_TLV_TARGET"));
  1497. }
  1498. QDF_STATUS wmi_unified_cmd_send_fl(wmi_unified_t wmi_handle, wmi_buf_t buf,
  1499. uint32_t len, uint32_t cmd_id,
  1500. const char *func, uint32_t line)
  1501. {
  1502. HTC_PACKET *pkt;
  1503. QDF_STATUS status;
  1504. uint16_t htc_tag = 0;
  1505. if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
  1506. htc_tag = wmi_handle->ops->wmi_set_htc_tx_tag(wmi_handle, buf,
  1507. cmd_id);
  1508. } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
  1509. !wmi_is_pm_resume_cmd(cmd_id) &&
  1510. !wmi_is_legacy_d0wow_disable_cmd(buf, cmd_id)) {
  1511. wmi_nofl_err("Target is suspended (via %s:%u)",
  1512. func, line);
  1513. return QDF_STATUS_E_BUSY;
  1514. }
  1515. if (wmi_handle->wmi_stopinprogress) {
  1516. wmi_nofl_err("%s:%d, WMI stop in progress, wmi_handle:%pK",
  1517. func, line, wmi_handle);
  1518. return QDF_STATUS_E_INVAL;
  1519. }
  1520. #ifndef WMI_NON_TLV_SUPPORT
  1521. /* Do sanity check on the TLV parameter structure */
  1522. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  1523. void *buf_ptr = (void *)qdf_nbuf_data(buf);
  1524. if (wmi_handle->ops->wmi_check_command_params(NULL, buf_ptr, len, cmd_id)
  1525. != 0) {
  1526. wmi_nofl_err("%s:%d, Invalid WMI Param Buffer for Cmd:%d",
  1527. func, line, cmd_id);
  1528. return QDF_STATUS_E_INVAL;
  1529. }
  1530. }
  1531. #endif
  1532. if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
  1533. wmi_nofl_err("%s:%d, Failed to send cmd %x, no memory",
  1534. func, line, cmd_id);
  1535. return QDF_STATUS_E_NOMEM;
  1536. }
  1537. qdf_mem_zero(qdf_nbuf_data(buf), sizeof(WMI_CMD_HDR));
  1538. WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
  1539. qdf_atomic_inc(&wmi_handle->pending_cmds);
  1540. if (qdf_atomic_read(&wmi_handle->pending_cmds) >=
  1541. wmi_handle->wmi_max_cmds) {
  1542. wmi_nofl_err("hostcredits = %d",
  1543. wmi_get_host_credits(wmi_handle));
  1544. htc_dump_counter_info(wmi_handle->htc_handle);
  1545. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1546. wmi_nofl_err("%s:%d, MAX %d WMI Pending cmds reached",
  1547. func, line, wmi_handle->wmi_max_cmds);
  1548. wmi_unified_debug_dump(wmi_handle);
  1549. htc_ce_tasklet_debug_dump(wmi_handle->htc_handle);
  1550. qdf_trigger_self_recovery(wmi_handle->soc->wmi_psoc,
  1551. QDF_WMI_EXCEED_MAX_PENDING_CMDS);
  1552. return QDF_STATUS_E_BUSY;
  1553. }
  1554. pkt = qdf_mem_malloc_fl(sizeof(*pkt), func, line);
  1555. if (!pkt) {
  1556. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1557. return QDF_STATUS_E_NOMEM;
  1558. }
  1559. SET_HTC_PACKET_INFO_TX(pkt,
  1560. NULL,
  1561. qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
  1562. wmi_handle->wmi_endpoint_id, htc_tag);
  1563. SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
  1564. wmi_log_cmd_id(cmd_id, htc_tag);
  1565. wmi_ext_dbg_msg_cmd_record(wmi_handle,
  1566. qdf_nbuf_data(buf), qdf_nbuf_len(buf));
  1567. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1568. if (wmi_handle->log_info.wmi_logging_enable) {
  1569. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1570. /*
  1571. * Record 16 bytes of WMI cmd data -
  1572. * exclude TLV and WMI headers
  1573. *
  1574. * WMI mgmt command already recorded in wmi_mgmt_cmd_record
  1575. */
  1576. if (wmi_handle->ops->is_management_record(cmd_id) == false) {
  1577. uint8_t *tmpbuf = (uint8_t *)qdf_nbuf_data(buf) +
  1578. wmi_handle->soc->buf_offset_command;
  1579. WMI_COMMAND_RECORD(wmi_handle, cmd_id, tmpbuf);
  1580. wmi_specific_cmd_record(wmi_handle, cmd_id, tmpbuf);
  1581. }
  1582. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1583. }
  1584. #endif
  1585. status = htc_send_pkt(wmi_handle->htc_handle, pkt);
  1586. if (QDF_STATUS_SUCCESS != status) {
  1587. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1588. wmi_nofl_err("%s:%d, htc_send_pkt failed, status:%d",
  1589. func, line, status);
  1590. qdf_mem_free(pkt);
  1591. return status;
  1592. }
  1593. return QDF_STATUS_SUCCESS;
  1594. }
  1595. qdf_export_symbol(wmi_unified_cmd_send_fl);
  1596. /**
  1597. * wmi_unified_get_event_handler_ix() - gives event handler's index
  1598. * @wmi_handle: handle to wmi
  1599. * @event_id: wmi event id
  1600. *
  1601. * Return: event handler's index
  1602. */
  1603. static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
  1604. uint32_t event_id)
  1605. {
  1606. uint32_t idx = 0;
  1607. int32_t invalid_idx = -1;
  1608. struct wmi_soc *soc = wmi_handle->soc;
  1609. for (idx = 0; (idx < soc->max_event_idx &&
  1610. idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
  1611. if (wmi_handle->event_id[idx] == event_id &&
  1612. wmi_handle->event_handler[idx]) {
  1613. return idx;
  1614. }
  1615. }
  1616. return invalid_idx;
  1617. }
  1618. /**
  1619. * wmi_register_event_handler_with_ctx() - register event handler with
  1620. * exec ctx and buffer type
  1621. * @wmi_handle: handle to wmi
  1622. * @event_id: wmi event id
  1623. * @handler_func: wmi event handler function
  1624. * @rx_ctx: rx execution context for wmi rx events
  1625. * @rx_buf_type: rx execution context for wmi rx events
  1626. *
  1627. * Return: QDF_STATUS_SUCCESS on successful register event else failure.
  1628. */
  1629. static QDF_STATUS
  1630. wmi_register_event_handler_with_ctx(wmi_unified_t wmi_handle,
  1631. uint32_t event_id,
  1632. wmi_unified_event_handler handler_func,
  1633. enum wmi_rx_exec_ctx rx_ctx,
  1634. enum wmi_rx_buff_type rx_buf_type)
  1635. {
  1636. uint32_t idx = 0;
  1637. uint32_t evt_id;
  1638. struct wmi_soc *soc;
  1639. if (!wmi_handle) {
  1640. WMI_LOGE("WMI handle is NULL");
  1641. return QDF_STATUS_E_FAILURE;
  1642. }
  1643. soc = wmi_handle->soc;
  1644. if (event_id >= wmi_events_max ||
  1645. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1646. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  1647. "%s: Event id %d is unavailable",
  1648. __func__, event_id);
  1649. return QDF_STATUS_E_FAILURE;
  1650. }
  1651. evt_id = wmi_handle->wmi_events[event_id];
  1652. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1653. WMI_LOGI("event handler already registered 0x%x",
  1654. evt_id);
  1655. return QDF_STATUS_E_FAILURE;
  1656. }
  1657. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1658. WMI_LOGE("no more event handlers 0x%x",
  1659. evt_id);
  1660. return QDF_STATUS_E_FAILURE;
  1661. }
  1662. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
  1663. "Registered event handler for event 0x%8x", evt_id);
  1664. idx = soc->max_event_idx;
  1665. wmi_handle->event_handler[idx] = handler_func;
  1666. wmi_handle->event_id[idx] = evt_id;
  1667. qdf_spin_lock_bh(&soc->ctx_lock);
  1668. wmi_handle->ctx[idx].exec_ctx = rx_ctx;
  1669. wmi_handle->ctx[idx].buff_type = rx_buf_type;
  1670. qdf_spin_unlock_bh(&soc->ctx_lock);
  1671. soc->max_event_idx++;
  1672. return QDF_STATUS_SUCCESS;
  1673. }
  1674. int wmi_unified_register_event(wmi_unified_t wmi_handle,
  1675. uint32_t event_id,
  1676. wmi_unified_event_handler handler_func)
  1677. {
  1678. return wmi_register_event_handler_with_ctx(wmi_handle, event_id,
  1679. handler_func,
  1680. WMI_RX_UMAC_CTX,
  1681. WMI_RX_PROCESSED_BUFF);
  1682. }
  1683. int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
  1684. wmi_conv_event_id event_id,
  1685. wmi_unified_event_handler handler_func,
  1686. uint8_t rx_ctx)
  1687. {
  1688. return wmi_register_event_handler_with_ctx(wmi_handle, event_id,
  1689. handler_func, rx_ctx,
  1690. WMI_RX_PROCESSED_BUFF);
  1691. }
  1692. qdf_export_symbol(wmi_unified_register_event_handler);
  1693. int
  1694. wmi_unified_register_raw_event_handler(wmi_unified_t wmi_handle,
  1695. wmi_conv_event_id event_id,
  1696. wmi_unified_event_handler handler_func,
  1697. enum wmi_rx_exec_ctx rx_ctx)
  1698. {
  1699. return wmi_register_event_handler_with_ctx(wmi_handle, event_id,
  1700. handler_func, rx_ctx,
  1701. WMI_RX_RAW_BUFF);
  1702. }
  1703. qdf_export_symbol(wmi_unified_register_raw_event_handler);
  1704. /**
  1705. * wmi_unified_unregister_event() - unregister wmi event handler
  1706. * @wmi_handle: handle to wmi
  1707. * @event_id: wmi event id
  1708. *
  1709. * Return: 0 on success
  1710. */
  1711. int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
  1712. uint32_t event_id)
  1713. {
  1714. uint32_t idx = 0;
  1715. uint32_t evt_id;
  1716. struct wmi_soc *soc = wmi_handle->soc;
  1717. if (event_id >= wmi_events_max ||
  1718. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1719. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  1720. "%s: Event id %d is unavailable",
  1721. __func__, event_id);
  1722. return QDF_STATUS_E_FAILURE;
  1723. }
  1724. evt_id = wmi_handle->wmi_events[event_id];
  1725. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1726. if (idx == -1) {
  1727. WMI_LOGI("event handler is not registered: evt id 0x%x",
  1728. evt_id);
  1729. return QDF_STATUS_E_FAILURE;
  1730. }
  1731. wmi_handle->event_handler[idx] = NULL;
  1732. wmi_handle->event_id[idx] = 0;
  1733. --soc->max_event_idx;
  1734. wmi_handle->event_handler[idx] =
  1735. wmi_handle->event_handler[soc->max_event_idx];
  1736. wmi_handle->event_id[idx] =
  1737. wmi_handle->event_id[soc->max_event_idx];
  1738. return 0;
  1739. }
  1740. /**
  1741. * wmi_unified_unregister_event_handler() - unregister wmi event handler
  1742. * @wmi_handle: handle to wmi
  1743. * @event_id: wmi event id
  1744. *
  1745. * Return: 0 on success
  1746. */
  1747. int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
  1748. wmi_conv_event_id event_id)
  1749. {
  1750. uint32_t idx = 0;
  1751. uint32_t evt_id;
  1752. struct wmi_soc *soc;
  1753. if (!wmi_handle) {
  1754. WMI_LOGE("WMI handle is NULL");
  1755. return QDF_STATUS_E_FAILURE;
  1756. }
  1757. soc = wmi_handle->soc;
  1758. if (event_id >= wmi_events_max ||
  1759. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1760. WMI_LOGI("Event id %d is unavailable",
  1761. event_id);
  1762. return QDF_STATUS_E_FAILURE;
  1763. }
  1764. evt_id = wmi_handle->wmi_events[event_id];
  1765. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1766. if (idx == -1) {
  1767. WMI_LOGI("event handler is not registered: evt id 0x%x",
  1768. evt_id);
  1769. return QDF_STATUS_E_FAILURE;
  1770. }
  1771. wmi_handle->event_handler[idx] = NULL;
  1772. wmi_handle->event_id[idx] = 0;
  1773. --soc->max_event_idx;
  1774. wmi_handle->event_handler[idx] =
  1775. wmi_handle->event_handler[soc->max_event_idx];
  1776. wmi_handle->event_id[idx] =
  1777. wmi_handle->event_id[soc->max_event_idx];
  1778. return 0;
  1779. }
  1780. qdf_export_symbol(wmi_unified_unregister_event_handler);
  1781. void wmi_process_fw_event_worker_thread_ctx(struct wmi_unified *wmi_handle,
  1782. void *evt_buf)
  1783. {
  1784. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  1785. qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
  1786. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  1787. qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
  1788. &wmi_handle->rx_event_work);
  1789. return;
  1790. }
  1791. qdf_export_symbol(wmi_process_fw_event_worker_thread_ctx);
  1792. uint32_t wmi_critical_events_in_flight(struct wmi_unified *wmi)
  1793. {
  1794. return qdf_atomic_read(&wmi->critical_events_in_flight);
  1795. }
  1796. static bool
  1797. wmi_is_event_critical(struct wmi_unified *wmi_handle, uint32_t event_id)
  1798. {
  1799. if (wmi_handle->wmi_events[wmi_roam_synch_event_id] == event_id)
  1800. return true;
  1801. return false;
  1802. }
  1803. static QDF_STATUS wmi_discard_fw_event(struct scheduler_msg *msg)
  1804. {
  1805. struct wmi_process_fw_event_params *event_param;
  1806. if (!msg->bodyptr)
  1807. return QDF_STATUS_E_INVAL;
  1808. event_param = (struct wmi_process_fw_event_params *)msg->bodyptr;
  1809. qdf_nbuf_free(event_param->evt_buf);
  1810. qdf_mem_free(msg->bodyptr);
  1811. msg->bodyptr = NULL;
  1812. msg->bodyval = 0;
  1813. msg->type = 0;
  1814. return QDF_STATUS_SUCCESS;
  1815. }
  1816. static QDF_STATUS wmi_process_fw_event_handler(struct scheduler_msg *msg)
  1817. {
  1818. struct wmi_process_fw_event_params *params =
  1819. (struct wmi_process_fw_event_params *)msg->bodyptr;
  1820. struct wmi_unified *wmi_handle;
  1821. uint32_t event_id;
  1822. wmi_handle = (struct wmi_unified *)params->wmi_handle;
  1823. event_id = WMI_GET_FIELD(qdf_nbuf_data(params->evt_buf),
  1824. WMI_CMD_HDR, COMMANDID);
  1825. wmi_process_fw_event(wmi_handle, params->evt_buf);
  1826. if (wmi_is_event_critical(wmi_handle, event_id))
  1827. qdf_atomic_dec(&wmi_handle->critical_events_in_flight);
  1828. qdf_mem_free(msg->bodyptr);
  1829. return QDF_STATUS_SUCCESS;
  1830. }
  1831. /**
  1832. * wmi_process_fw_event_sched_thread_ctx() - common event handler to serialize
  1833. * event processing through scheduler thread
  1834. * @ctx: wmi context
  1835. * @ev: event buffer
  1836. * @rx_ctx: rx execution context
  1837. *
  1838. * Return: 0 on success, errno on failure
  1839. */
  1840. static QDF_STATUS
  1841. wmi_process_fw_event_sched_thread_ctx(struct wmi_unified *wmi,
  1842. void *ev)
  1843. {
  1844. struct wmi_process_fw_event_params *params_buf;
  1845. struct scheduler_msg msg = { 0 };
  1846. uint32_t event_id;
  1847. params_buf = qdf_mem_malloc(sizeof(struct wmi_process_fw_event_params));
  1848. if (!params_buf) {
  1849. wmi_err("malloc failed");
  1850. qdf_nbuf_free(ev);
  1851. return QDF_STATUS_E_NOMEM;
  1852. }
  1853. params_buf->wmi_handle = wmi;
  1854. params_buf->evt_buf = ev;
  1855. event_id = WMI_GET_FIELD(qdf_nbuf_data(params_buf->evt_buf),
  1856. WMI_CMD_HDR, COMMANDID);
  1857. if (wmi_is_event_critical(wmi, event_id))
  1858. qdf_atomic_inc(&wmi->critical_events_in_flight);
  1859. msg.bodyptr = params_buf;
  1860. msg.bodyval = 0;
  1861. msg.callback = wmi_process_fw_event_handler;
  1862. msg.flush_callback = wmi_discard_fw_event;
  1863. if (QDF_STATUS_SUCCESS !=
  1864. scheduler_post_message(QDF_MODULE_ID_TARGET_IF,
  1865. QDF_MODULE_ID_TARGET_IF,
  1866. QDF_MODULE_ID_TARGET_IF, &msg)) {
  1867. qdf_nbuf_free(ev);
  1868. qdf_mem_free(params_buf);
  1869. return QDF_STATUS_E_FAULT;
  1870. }
  1871. return QDF_STATUS_SUCCESS;
  1872. }
  1873. /**
  1874. * wmi_get_pdev_ep: Get wmi handle based on endpoint
  1875. * @soc: handle to wmi soc
  1876. * @ep: endpoint id
  1877. *
  1878. * Return: none
  1879. */
  1880. static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
  1881. HTC_ENDPOINT_ID ep)
  1882. {
  1883. uint32_t i;
  1884. for (i = 0; i < WMI_MAX_RADIOS; i++)
  1885. if (soc->wmi_endpoint_id[i] == ep)
  1886. break;
  1887. if (i == WMI_MAX_RADIOS)
  1888. return NULL;
  1889. return soc->wmi_pdev[i];
  1890. }
  1891. /**
  1892. * wmi_mtrace_rx() - Wrappper function for qdf_mtrace api
  1893. * @message_id: 32-Bit Wmi message ID
  1894. * @vdev_id: Vdev ID
  1895. * @data: Actual message contents
  1896. *
  1897. * This function converts the 32-bit WMI message ID in 15-bit message ID
  1898. * format for qdf_mtrace as in qdf_mtrace message there are only 15
  1899. * bits reserved for message ID.
  1900. * out of these 15-bits, 8-bits (From LSB) specifies the WMI_GRP_ID
  1901. * and remaining 7-bits specifies the actual WMI command. With this
  1902. * notation there can be maximum 256 groups and each group can have
  1903. * max 128 commands can be supported.
  1904. *
  1905. * Return: None
  1906. */
  1907. static void wmi_mtrace_rx(uint32_t message_id, uint16_t vdev_id, uint32_t data)
  1908. {
  1909. uint16_t mtrace_message_id;
  1910. mtrace_message_id = QDF_WMI_MTRACE_CMD_ID(message_id) |
  1911. (QDF_WMI_MTRACE_GRP_ID(message_id) <<
  1912. QDF_WMI_MTRACE_CMD_NUM_BITS);
  1913. qdf_mtrace(QDF_MODULE_ID_WMI, QDF_MODULE_ID_WMA,
  1914. mtrace_message_id, vdev_id, data);
  1915. }
  1916. /**
  1917. * wmi_process_control_rx() - process fw events callbacks
  1918. * @wmi_handle: handle to wmi_unified
  1919. * @evt_buf: handle to wmi_buf_t
  1920. *
  1921. * Return: none
  1922. */
  1923. static void wmi_process_control_rx(struct wmi_unified *wmi_handle,
  1924. wmi_buf_t evt_buf)
  1925. {
  1926. struct wmi_soc *soc = wmi_handle->soc;
  1927. uint32_t id;
  1928. uint32_t idx;
  1929. enum wmi_rx_exec_ctx exec_ctx;
  1930. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  1931. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  1932. if (qdf_unlikely(idx == A_ERROR)) {
  1933. wmi_debug("no handler registered for event id 0x%x", id);
  1934. qdf_nbuf_free(evt_buf);
  1935. return;
  1936. }
  1937. wmi_mtrace_rx(id, 0xFF, idx);
  1938. qdf_spin_lock_bh(&soc->ctx_lock);
  1939. exec_ctx = wmi_handle->ctx[idx].exec_ctx;
  1940. qdf_spin_unlock_bh(&soc->ctx_lock);
  1941. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1942. if (wmi_handle->log_info.wmi_logging_enable) {
  1943. uint8_t *data;
  1944. data = qdf_nbuf_data(evt_buf);
  1945. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1946. /* Exclude 4 bytes of TLV header */
  1947. if (wmi_handle->ops->is_diag_event(id)) {
  1948. WMI_DIAG_RX_EVENT_RECORD(wmi_handle, id,
  1949. ((uint8_t *) data +
  1950. wmi_handle->soc->buf_offset_event));
  1951. } else if (wmi_handle->ops->is_management_record(id)) {
  1952. WMI_MGMT_RX_EVENT_RECORD(wmi_handle, id,
  1953. ((uint8_t *) data +
  1954. wmi_handle->soc->buf_offset_event));
  1955. } else {
  1956. WMI_RX_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
  1957. wmi_handle->soc->buf_offset_event));
  1958. }
  1959. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1960. }
  1961. #endif
  1962. if (exec_ctx == WMI_RX_WORK_CTX) {
  1963. wmi_process_fw_event_worker_thread_ctx
  1964. (wmi_handle, evt_buf);
  1965. } else if (exec_ctx == WMI_RX_TASKLET_CTX) {
  1966. wmi_process_fw_event(wmi_handle, evt_buf);
  1967. } else if (exec_ctx == WMI_RX_SERIALIZER_CTX) {
  1968. wmi_process_fw_event_sched_thread_ctx(wmi_handle, evt_buf);
  1969. } else {
  1970. WMI_LOGE("Invalid event context %d", exec_ctx);
  1971. qdf_nbuf_free(evt_buf);
  1972. }
  1973. }
  1974. /**
  1975. * wmi_control_rx() - process fw events callbacks
  1976. * @ctx: handle to wmi
  1977. * @htc_packet: pointer to htc packet
  1978. *
  1979. * Return: none
  1980. */
  1981. static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
  1982. {
  1983. struct wmi_soc *soc = (struct wmi_soc *)ctx;
  1984. struct wmi_unified *wmi_handle;
  1985. wmi_buf_t evt_buf;
  1986. evt_buf = (wmi_buf_t)htc_packet->pPktContext;
  1987. wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
  1988. if (!wmi_handle) {
  1989. WMI_LOGE
  1990. ("unable to get wmi_handle to Endpoint %d\n",
  1991. htc_packet->Endpoint);
  1992. qdf_nbuf_free(evt_buf);
  1993. return;
  1994. }
  1995. wmi_process_control_rx(wmi_handle, evt_buf);
  1996. }
  1997. #ifdef WLAN_FEATURE_WMI_SEND_RECV_QMI
  1998. QDF_STATUS wmi_unified_cmd_send_over_qmi(struct wmi_unified *wmi_handle,
  1999. wmi_buf_t buf, uint32_t buflen,
  2000. uint32_t cmd_id)
  2001. {
  2002. QDF_STATUS status;
  2003. int32_t ret;
  2004. if (!qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR))) {
  2005. wmi_err("Failed to send cmd %x, no memory", cmd_id);
  2006. return QDF_STATUS_E_NOMEM;
  2007. }
  2008. qdf_mem_zero(qdf_nbuf_data(buf), sizeof(WMI_CMD_HDR));
  2009. WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
  2010. wmi_debug("Sending WMI_CMD_ID: 0x%x over qmi", cmd_id);
  2011. status = qdf_wmi_send_recv_qmi(qdf_nbuf_data(buf),
  2012. buflen + sizeof(WMI_CMD_HDR),
  2013. wmi_handle,
  2014. wmi_process_qmi_fw_event);
  2015. if (QDF_IS_STATUS_ERROR(status)) {
  2016. qdf_nbuf_pull_head(buf, sizeof(WMI_CMD_HDR));
  2017. wmi_warn("WMI send on QMI failed. Retrying WMI on HTC");
  2018. } else {
  2019. ret = qdf_atomic_inc_return(&wmi_handle->num_stats_over_qmi);
  2020. wmi_debug("num stats over qmi: %d", ret);
  2021. wmi_buf_free(buf);
  2022. }
  2023. return status;
  2024. }
  2025. static int __wmi_process_qmi_fw_event(void *wmi_cb_ctx, void *buf, int len)
  2026. {
  2027. struct wmi_unified *wmi_handle = wmi_cb_ctx;
  2028. wmi_buf_t evt_buf;
  2029. uint32_t evt_id;
  2030. if (!wmi_handle || !buf)
  2031. return -EINVAL;
  2032. evt_buf = wmi_buf_alloc(wmi_handle, len);
  2033. if (!evt_buf)
  2034. return -ENOMEM;
  2035. qdf_mem_copy(qdf_nbuf_data(evt_buf), buf, len);
  2036. evt_id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  2037. wmi_debug("Received WMI_EVT_ID: %d over qmi", evt_id);
  2038. wmi_process_control_rx(wmi_handle, evt_buf);
  2039. return 0;
  2040. }
  2041. int wmi_process_qmi_fw_event(void *wmi_cb_ctx, void *buf, int len)
  2042. {
  2043. struct qdf_op_sync *op_sync;
  2044. int ret;
  2045. if (qdf_op_protect(&op_sync))
  2046. return -EINVAL;
  2047. ret = __wmi_process_qmi_fw_event(wmi_cb_ctx, buf, len);
  2048. qdf_op_unprotect(op_sync);
  2049. return ret;
  2050. }
  2051. #endif
  2052. /**
  2053. * wmi_process_fw_event() - process any fw event
  2054. * @wmi_handle: wmi handle
  2055. * @evt_buf: fw event buffer
  2056. *
  2057. * This function process fw event in caller context
  2058. *
  2059. * Return: none
  2060. */
  2061. void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  2062. {
  2063. __wmi_control_rx(wmi_handle, evt_buf);
  2064. }
  2065. /**
  2066. * __wmi_control_rx() - process serialize wmi event callback
  2067. * @wmi_handle: wmi handle
  2068. * @evt_buf: fw event buffer
  2069. *
  2070. * Return: none
  2071. */
  2072. void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  2073. {
  2074. uint32_t id;
  2075. uint8_t *data;
  2076. uint32_t len;
  2077. void *wmi_cmd_struct_ptr = NULL;
  2078. #ifndef WMI_NON_TLV_SUPPORT
  2079. int tlv_ok_status = 0;
  2080. #endif
  2081. uint32_t idx = 0;
  2082. struct wmi_raw_event_buffer ev_buf;
  2083. enum wmi_rx_buff_type ev_buff_type;
  2084. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  2085. wmi_ext_dbg_msg_event_record(wmi_handle, qdf_nbuf_data(evt_buf),
  2086. qdf_nbuf_len(evt_buf));
  2087. if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
  2088. goto end;
  2089. data = qdf_nbuf_data(evt_buf);
  2090. len = qdf_nbuf_len(evt_buf);
  2091. #ifndef WMI_NON_TLV_SUPPORT
  2092. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  2093. /* Validate and pad(if necessary) the TLVs */
  2094. tlv_ok_status =
  2095. wmi_handle->ops->wmi_check_and_pad_event(wmi_handle->scn_handle,
  2096. data, len, id,
  2097. &wmi_cmd_struct_ptr);
  2098. if (tlv_ok_status != 0) {
  2099. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  2100. "%s: Error: id=0x%x, wmitlv check status=%d",
  2101. __func__, id, tlv_ok_status);
  2102. goto end;
  2103. }
  2104. }
  2105. #endif
  2106. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  2107. if (idx == A_ERROR) {
  2108. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  2109. "%s : event handler is not registered: event id 0x%x",
  2110. __func__, id);
  2111. goto end;
  2112. }
  2113. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2114. if (wmi_handle->log_info.wmi_logging_enable) {
  2115. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  2116. /* Exclude 4 bytes of TLV header */
  2117. if (wmi_handle->ops->is_diag_event(id)) {
  2118. /*
  2119. * skip diag event logging in WMI event buffer
  2120. * as its already logged in WMI RX event buffer
  2121. */
  2122. } else if (wmi_handle->ops->is_management_record(id)) {
  2123. /*
  2124. * skip wmi mgmt event logging in WMI event buffer
  2125. * as its already logged in WMI RX event buffer
  2126. */
  2127. } else {
  2128. uint8_t *tmpbuf = (uint8_t *)data +
  2129. wmi_handle->soc->buf_offset_event;
  2130. WMI_EVENT_RECORD(wmi_handle, id, tmpbuf);
  2131. wmi_specific_evt_record(wmi_handle, id, tmpbuf);
  2132. }
  2133. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  2134. }
  2135. #endif
  2136. /* Call the WMI registered event handler */
  2137. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  2138. ev_buff_type = wmi_handle->ctx[idx].buff_type;
  2139. if (ev_buff_type == WMI_RX_PROCESSED_BUFF) {
  2140. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  2141. wmi_cmd_struct_ptr, len);
  2142. } else if (ev_buff_type == WMI_RX_RAW_BUFF) {
  2143. ev_buf.evt_raw_buf = data;
  2144. ev_buf.evt_processed_buf = wmi_cmd_struct_ptr;
  2145. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  2146. (void *)&ev_buf, len);
  2147. }
  2148. }
  2149. else
  2150. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  2151. data, len);
  2152. end:
  2153. /* Free event buffer and allocated event tlv */
  2154. #ifndef WMI_NON_TLV_SUPPORT
  2155. if (wmi_handle->target_type == WMI_TLV_TARGET)
  2156. wmi_handle->ops->wmi_free_allocated_event(id, &wmi_cmd_struct_ptr);
  2157. #endif
  2158. qdf_nbuf_free(evt_buf);
  2159. }
  2160. #define WMI_WQ_WD_TIMEOUT (30 * 1000) /* 30s */
  2161. static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id)
  2162. {
  2163. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  2164. "%s: WLAN_BUG_RCA: Message type %x has exceeded its alloted time of %ds",
  2165. __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000);
  2166. }
  2167. #ifdef CONFIG_SLUB_DEBUG_ON
  2168. static void wmi_workqueue_watchdog_bite(void *arg)
  2169. {
  2170. struct wmi_wq_dbg_info *info = arg;
  2171. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  2172. qdf_print_thread_trace(info->task);
  2173. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  2174. "%s: Going down for WMI WQ Watchdog Bite!", __func__);
  2175. QDF_BUG(0);
  2176. }
  2177. #else
  2178. static inline void wmi_workqueue_watchdog_bite(void *arg)
  2179. {
  2180. struct wmi_wq_dbg_info *info = arg;
  2181. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  2182. }
  2183. #endif
  2184. /**
  2185. * wmi_rx_event_work() - process rx event in rx work queue context
  2186. * @arg: opaque pointer to wmi handle
  2187. *
  2188. * This function process any fw event to serialize it through rx worker thread.
  2189. *
  2190. * Return: none
  2191. */
  2192. static void wmi_rx_event_work(void *arg)
  2193. {
  2194. wmi_buf_t buf;
  2195. struct wmi_unified *wmi = arg;
  2196. qdf_timer_t wd_timer;
  2197. struct wmi_wq_dbg_info info;
  2198. /* initialize WMI workqueue watchdog timer */
  2199. qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite,
  2200. &info, QDF_TIMER_TYPE_SW);
  2201. qdf_spin_lock_bh(&wmi->eventq_lock);
  2202. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  2203. qdf_spin_unlock_bh(&wmi->eventq_lock);
  2204. while (buf) {
  2205. qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT);
  2206. info.wd_msg_type_id =
  2207. WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID);
  2208. info.wmi_wq = wmi->wmi_rx_work_queue;
  2209. info.task = qdf_get_current_task();
  2210. __wmi_control_rx(wmi, buf);
  2211. qdf_timer_stop(&wd_timer);
  2212. qdf_spin_lock_bh(&wmi->eventq_lock);
  2213. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  2214. qdf_spin_unlock_bh(&wmi->eventq_lock);
  2215. }
  2216. qdf_timer_free(&wd_timer);
  2217. }
  2218. #ifdef FEATURE_RUNTIME_PM
  2219. /**
  2220. * wmi_runtime_pm_init() - initialize runtime pm wmi variables
  2221. * @wmi_handle: wmi context
  2222. */
  2223. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  2224. {
  2225. qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
  2226. }
  2227. /**
  2228. * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
  2229. * @wmi_handle: wmi context
  2230. * @val: runtime pm progress flag
  2231. */
  2232. void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
  2233. {
  2234. qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
  2235. }
  2236. /**
  2237. * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
  2238. * @wmi_handle: wmi context
  2239. */
  2240. inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
  2241. {
  2242. return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
  2243. }
  2244. #else
  2245. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  2246. {
  2247. }
  2248. #endif
  2249. /**
  2250. * wmi_unified_get_soc_handle: Get WMI SoC handle
  2251. * @param wmi_handle: WMI context got from wmi_attach
  2252. *
  2253. * return: Pointer to Soc handle
  2254. */
  2255. void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
  2256. {
  2257. return wmi_handle->soc;
  2258. }
  2259. /**
  2260. * wmi_interface_logging_init: Interface looging init
  2261. * @param wmi_handle: Pointer to wmi handle object
  2262. *
  2263. * return: None
  2264. */
  2265. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2266. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
  2267. uint32_t pdev_idx)
  2268. {
  2269. if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
  2270. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  2271. wmi_debugfs_init(wmi_handle, pdev_idx);
  2272. }
  2273. }
  2274. #else
  2275. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
  2276. uint32_t pdev_idx)
  2277. {
  2278. }
  2279. #endif
  2280. /**
  2281. * wmi_unified_get_pdev_handle: Get WMI SoC handle
  2282. * @param wmi_soc: Pointer to wmi soc object
  2283. * @param pdev_idx: pdev index
  2284. *
  2285. * return: Pointer to wmi handle or NULL on failure
  2286. */
  2287. void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
  2288. {
  2289. struct wmi_unified *wmi_handle;
  2290. if (pdev_idx >= WMI_MAX_RADIOS)
  2291. return NULL;
  2292. if (!soc->wmi_pdev[pdev_idx]) {
  2293. wmi_handle =
  2294. (struct wmi_unified *) qdf_mem_malloc(
  2295. sizeof(struct wmi_unified));
  2296. if (!wmi_handle)
  2297. return NULL;
  2298. wmi_handle->scn_handle = soc->scn_handle;
  2299. wmi_handle->event_id = soc->event_id;
  2300. wmi_handle->event_handler = soc->event_handler;
  2301. wmi_handle->ctx = soc->ctx;
  2302. wmi_handle->ops = soc->ops;
  2303. qdf_spinlock_create(&wmi_handle->eventq_lock);
  2304. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  2305. qdf_create_work(0, &wmi_handle->rx_event_work,
  2306. wmi_rx_event_work, wmi_handle);
  2307. wmi_handle->wmi_rx_work_queue =
  2308. qdf_alloc_unbound_workqueue("wmi_rx_event_work_queue");
  2309. if (!wmi_handle->wmi_rx_work_queue) {
  2310. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  2311. goto error;
  2312. }
  2313. wmi_handle->wmi_events = soc->wmi_events;
  2314. wmi_handle->services = soc->services;
  2315. wmi_handle->soc = soc;
  2316. wmi_handle->cmd_pdev_id_map = soc->cmd_pdev_id_map;
  2317. wmi_handle->evt_pdev_id_map = soc->evt_pdev_id_map;
  2318. wmi_handle->cmd_phy_id_map = soc->cmd_phy_id_map;
  2319. wmi_handle->evt_phy_id_map = soc->evt_phy_id_map;
  2320. wmi_interface_logging_init(wmi_handle, pdev_idx);
  2321. qdf_atomic_init(&wmi_handle->pending_cmds);
  2322. qdf_atomic_init(&wmi_handle->is_target_suspended);
  2323. wmi_handle->target_type = soc->target_type;
  2324. wmi_handle->wmi_max_cmds = soc->wmi_max_cmds;
  2325. soc->wmi_pdev[pdev_idx] = wmi_handle;
  2326. } else
  2327. wmi_handle = soc->wmi_pdev[pdev_idx];
  2328. wmi_handle->wmi_stopinprogress = 0;
  2329. wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
  2330. wmi_handle->htc_handle = soc->htc_handle;
  2331. wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
  2332. wmi_handle->tag_crash_inject = false;
  2333. return wmi_handle;
  2334. error:
  2335. qdf_mem_free(wmi_handle);
  2336. return NULL;
  2337. }
  2338. qdf_export_symbol(wmi_unified_get_pdev_handle);
  2339. static void (*wmi_attach_register[WMI_MAX_TARGET_TYPE])(wmi_unified_t);
  2340. void wmi_unified_register_module(enum wmi_target_type target_type,
  2341. void (*wmi_attach)(wmi_unified_t wmi_handle))
  2342. {
  2343. if (target_type < WMI_MAX_TARGET_TYPE)
  2344. wmi_attach_register[target_type] = wmi_attach;
  2345. return;
  2346. }
  2347. qdf_export_symbol(wmi_unified_register_module);
  2348. /**
  2349. * wmi_wbuff_register() - register wmi with wbuff
  2350. * @wmi_handle: handle to wmi
  2351. *
  2352. * @Return: void
  2353. */
  2354. static void wmi_wbuff_register(struct wmi_unified *wmi_handle)
  2355. {
  2356. struct wbuff_alloc_request wbuff_alloc[4];
  2357. wbuff_alloc[0].slot = WBUFF_POOL_0;
  2358. wbuff_alloc[0].size = WMI_WBUFF_POOL_0_SIZE;
  2359. wbuff_alloc[1].slot = WBUFF_POOL_1;
  2360. wbuff_alloc[1].size = WMI_WBUFF_POOL_1_SIZE;
  2361. wbuff_alloc[2].slot = WBUFF_POOL_2;
  2362. wbuff_alloc[2].size = WMI_WBUFF_POOL_2_SIZE;
  2363. wbuff_alloc[3].slot = WBUFF_POOL_3;
  2364. wbuff_alloc[3].size = WMI_WBUFF_POOL_3_SIZE;
  2365. wmi_handle->wbuff_handle = wbuff_module_register(wbuff_alloc, 4,
  2366. WMI_MIN_HEAD_ROOM, 4);
  2367. }
  2368. /**
  2369. * wmi_wbuff_deregister() - deregister wmi with wbuff
  2370. * @wmi_handle: handle to wmi
  2371. *
  2372. * @Return: void
  2373. */
  2374. static inline void wmi_wbuff_deregister(struct wmi_unified *wmi_handle)
  2375. {
  2376. wbuff_module_deregister(wmi_handle->wbuff_handle);
  2377. wmi_handle->wbuff_handle = NULL;
  2378. }
  2379. /**
  2380. * wmi_unified_attach() - attach for unified WMI
  2381. * @scn_handle: handle to SCN
  2382. * @osdev: OS device context
  2383. * @target_type: TLV or not-TLV based target
  2384. * @use_cookie: cookie based allocation enabled/disabled
  2385. * @ops: umac rx callbacks
  2386. * @psoc: objmgr psoc
  2387. *
  2388. * @Return: wmi handle.
  2389. */
  2390. void *wmi_unified_attach(void *scn_handle,
  2391. struct wmi_unified_attach_params *param)
  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)
  2397. return NULL;
  2398. wmi_handle =
  2399. (struct wmi_unified *) qdf_mem_malloc(
  2400. sizeof(struct wmi_unified));
  2401. if (!wmi_handle) {
  2402. qdf_mem_free(soc);
  2403. return NULL;
  2404. }
  2405. wmi_handle->soc = soc;
  2406. wmi_handle->soc->soc_idx = param->soc_id;
  2407. wmi_handle->soc->is_async_ep = param->is_async_ep;
  2408. wmi_handle->event_id = soc->event_id;
  2409. wmi_handle->event_handler = soc->event_handler;
  2410. wmi_handle->ctx = soc->ctx;
  2411. wmi_handle->wmi_events = soc->wmi_events;
  2412. wmi_handle->services = soc->services;
  2413. wmi_handle->scn_handle = scn_handle;
  2414. wmi_handle->cmd_pdev_id_map = soc->cmd_pdev_id_map;
  2415. wmi_handle->evt_pdev_id_map = soc->evt_pdev_id_map;
  2416. wmi_handle->cmd_phy_id_map = soc->cmd_phy_id_map;
  2417. wmi_handle->evt_phy_id_map = soc->evt_phy_id_map;
  2418. soc->scn_handle = scn_handle;
  2419. qdf_atomic_init(&wmi_handle->pending_cmds);
  2420. qdf_atomic_init(&wmi_handle->is_target_suspended);
  2421. qdf_atomic_init(&wmi_handle->num_stats_over_qmi);
  2422. wmi_runtime_pm_init(wmi_handle);
  2423. qdf_spinlock_create(&wmi_handle->eventq_lock);
  2424. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  2425. qdf_create_work(0, &wmi_handle->rx_event_work,
  2426. wmi_rx_event_work, wmi_handle);
  2427. wmi_handle->wmi_rx_work_queue =
  2428. qdf_alloc_unbound_workqueue("wmi_rx_event_work_queue");
  2429. if (!wmi_handle->wmi_rx_work_queue) {
  2430. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  2431. goto error;
  2432. }
  2433. wmi_interface_logging_init(wmi_handle, WMI_HOST_PDEV_ID_0);
  2434. wmi_handle->target_type = param->target_type;
  2435. soc->target_type = param->target_type;
  2436. if (param->target_type >= WMI_MAX_TARGET_TYPE)
  2437. goto error;
  2438. if (wmi_attach_register[param->target_type]) {
  2439. wmi_attach_register[param->target_type](wmi_handle);
  2440. } else {
  2441. WMI_LOGE("wmi attach is not registered");
  2442. goto error;
  2443. }
  2444. /* Assign target cookie capablity */
  2445. wmi_handle->use_cookie = param->use_cookie;
  2446. wmi_handle->osdev = param->osdev;
  2447. wmi_handle->wmi_stopinprogress = 0;
  2448. wmi_handle->wmi_max_cmds = param->max_commands;
  2449. soc->wmi_max_cmds = param->max_commands;
  2450. /* Increase the ref count once refcount infra is present */
  2451. soc->wmi_psoc = param->psoc;
  2452. qdf_spinlock_create(&soc->ctx_lock);
  2453. soc->ops = wmi_handle->ops;
  2454. soc->wmi_pdev[0] = wmi_handle;
  2455. if (wmi_ext_dbgfs_init(wmi_handle) != QDF_STATUS_SUCCESS)
  2456. WMI_LOGE("failed to initialize wmi extended debugfs");
  2457. wmi_wbuff_register(wmi_handle);
  2458. wmi_hang_event_notifier_register(wmi_handle);
  2459. return wmi_handle;
  2460. error:
  2461. qdf_mem_free(soc);
  2462. qdf_mem_free(wmi_handle);
  2463. return NULL;
  2464. }
  2465. /**
  2466. * wmi_unified_detach() - detach for unified WMI
  2467. *
  2468. * @wmi_handle : handle to wmi.
  2469. *
  2470. * @Return: none.
  2471. */
  2472. void wmi_unified_detach(struct wmi_unified *wmi_handle)
  2473. {
  2474. wmi_buf_t buf;
  2475. struct wmi_soc *soc;
  2476. uint8_t i;
  2477. wmi_hang_event_notifier_unregister();
  2478. wmi_wbuff_deregister(wmi_handle);
  2479. wmi_ext_dbgfs_deinit(wmi_handle);
  2480. soc = wmi_handle->soc;
  2481. for (i = 0; i < WMI_MAX_RADIOS; i++) {
  2482. if (soc->wmi_pdev[i]) {
  2483. qdf_flush_workqueue(0,
  2484. soc->wmi_pdev[i]->wmi_rx_work_queue);
  2485. qdf_destroy_workqueue(0,
  2486. soc->wmi_pdev[i]->wmi_rx_work_queue);
  2487. wmi_debugfs_remove(soc->wmi_pdev[i]);
  2488. buf = qdf_nbuf_queue_remove(
  2489. &soc->wmi_pdev[i]->event_queue);
  2490. while (buf) {
  2491. qdf_nbuf_free(buf);
  2492. buf = qdf_nbuf_queue_remove(
  2493. &soc->wmi_pdev[i]->event_queue);
  2494. }
  2495. wmi_log_buffer_free(soc->wmi_pdev[i]);
  2496. /* Free events logs list */
  2497. if (soc->wmi_pdev[i]->events_logs_list)
  2498. qdf_mem_free(
  2499. soc->wmi_pdev[i]->events_logs_list);
  2500. qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
  2501. qdf_mem_free(soc->wmi_pdev[i]);
  2502. }
  2503. }
  2504. qdf_spinlock_destroy(&soc->ctx_lock);
  2505. if (soc->wmi_service_bitmap) {
  2506. qdf_mem_free(soc->wmi_service_bitmap);
  2507. soc->wmi_service_bitmap = NULL;
  2508. }
  2509. if (soc->wmi_ext_service_bitmap) {
  2510. qdf_mem_free(soc->wmi_ext_service_bitmap);
  2511. soc->wmi_ext_service_bitmap = NULL;
  2512. }
  2513. if (soc->wmi_ext2_service_bitmap) {
  2514. qdf_mem_free(soc->wmi_ext2_service_bitmap);
  2515. soc->wmi_ext2_service_bitmap = NULL;
  2516. }
  2517. /* Decrease the ref count once refcount infra is present */
  2518. soc->wmi_psoc = NULL;
  2519. qdf_mem_free(soc);
  2520. }
  2521. /**
  2522. * wmi_unified_remove_work() - detach for WMI work
  2523. * @wmi_handle: handle to WMI
  2524. *
  2525. * A function that does not fully detach WMI, but just remove work
  2526. * queue items associated with it. This is used to make sure that
  2527. * before any other processing code that may destroy related contexts
  2528. * (HTC, etc), work queue processing on WMI has already been stopped.
  2529. *
  2530. * Return: None
  2531. */
  2532. void
  2533. wmi_unified_remove_work(struct wmi_unified *wmi_handle)
  2534. {
  2535. wmi_buf_t buf;
  2536. qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
  2537. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  2538. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2539. while (buf) {
  2540. qdf_nbuf_free(buf);
  2541. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2542. }
  2543. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  2544. }
  2545. /**
  2546. * wmi_htc_tx_complete() - Process htc tx completion
  2547. *
  2548. * @ctx: handle to wmi
  2549. * @htc_packet: pointer to htc packet
  2550. *
  2551. * @Return: none.
  2552. */
  2553. static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
  2554. {
  2555. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  2556. wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
  2557. u_int8_t *buf_ptr;
  2558. u_int32_t len;
  2559. struct wmi_unified *wmi_handle;
  2560. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2561. uint32_t cmd_id;
  2562. #endif
  2563. ASSERT(wmi_cmd_buf);
  2564. wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
  2565. if (!wmi_handle) {
  2566. WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
  2567. QDF_ASSERT(0);
  2568. return;
  2569. }
  2570. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2571. if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
  2572. cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
  2573. WMI_CMD_HDR, COMMANDID);
  2574. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  2575. /* Record 16 bytes of WMI cmd tx complete data
  2576. - exclude TLV and WMI headers */
  2577. if (wmi_handle->ops->is_management_record(cmd_id)) {
  2578. WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2579. qdf_nbuf_data(wmi_cmd_buf) +
  2580. wmi_handle->soc->buf_offset_command);
  2581. } else {
  2582. WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2583. qdf_nbuf_data(wmi_cmd_buf) +
  2584. wmi_handle->soc->buf_offset_command);
  2585. }
  2586. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  2587. }
  2588. #endif
  2589. buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
  2590. len = qdf_nbuf_len(wmi_cmd_buf);
  2591. qdf_mem_zero(buf_ptr, len);
  2592. wmi_buf_free(wmi_cmd_buf);
  2593. qdf_mem_free(htc_pkt);
  2594. qdf_atomic_dec(&wmi_handle->pending_cmds);
  2595. }
  2596. #ifdef FEATURE_RUNTIME_PM
  2597. /**
  2598. * wmi_htc_log_pkt() - Print information of WMI command from HTC packet
  2599. *
  2600. * @ctx: handle of WMI context
  2601. * @htc_pkt: handle of HTC packet
  2602. *
  2603. * @Return: none
  2604. */
  2605. static void wmi_htc_log_pkt(void *ctx, HTC_PACKET *htc_pkt)
  2606. {
  2607. wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
  2608. uint32_t cmd_id;
  2609. ASSERT(wmi_cmd_buf);
  2610. cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf), WMI_CMD_HDR,
  2611. COMMANDID);
  2612. WMI_LOGD("WMI command from HTC packet: %s, ID: %d\n",
  2613. wmi_id_to_name(cmd_id), cmd_id);
  2614. }
  2615. #else
  2616. static void wmi_htc_log_pkt(void *ctx, HTC_PACKET *htc_pkt)
  2617. {
  2618. }
  2619. #endif
  2620. /**
  2621. * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
  2622. *
  2623. * @wmi_handle: handle to WMI.
  2624. * @pdev_idx: Pdev index
  2625. *
  2626. * @Return: QDF_STATUS
  2627. */
  2628. static QDF_STATUS wmi_connect_pdev_htc_service(struct wmi_soc *soc,
  2629. uint32_t pdev_idx)
  2630. {
  2631. QDF_STATUS status;
  2632. struct htc_service_connect_resp response;
  2633. struct htc_service_connect_req connect;
  2634. OS_MEMZERO(&connect, sizeof(connect));
  2635. OS_MEMZERO(&response, sizeof(response));
  2636. /* meta data is unused for now */
  2637. connect.pMetaData = NULL;
  2638. connect.MetaDataLength = 0;
  2639. /* these fields are the same for all service endpoints */
  2640. connect.EpCallbacks.pContext = soc;
  2641. connect.EpCallbacks.EpTxCompleteMultiple =
  2642. NULL /* Control path completion ar6000_tx_complete */;
  2643. connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
  2644. connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
  2645. connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
  2646. connect.EpCallbacks.EpTxComplete =
  2647. wmi_htc_tx_complete /* ar6000_tx_queue_full */;
  2648. connect.EpCallbacks.ep_log_pkt = wmi_htc_log_pkt;
  2649. /* connect to control service */
  2650. connect.service_id = soc->svc_ids[pdev_idx];
  2651. status = htc_connect_service(soc->htc_handle, &connect, &response);
  2652. if (QDF_IS_STATUS_ERROR(status)) {
  2653. WMI_LOGE("Failed to connect to WMI CONTROL service status:%d\n",
  2654. status);
  2655. return status;
  2656. }
  2657. if (soc->is_async_ep)
  2658. htc_set_async_ep(soc->htc_handle, response.Endpoint, true);
  2659. soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
  2660. soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
  2661. return QDF_STATUS_SUCCESS;
  2662. }
  2663. QDF_STATUS
  2664. wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
  2665. HTC_HANDLE htc_handle)
  2666. {
  2667. uint32_t i;
  2668. uint8_t wmi_ep_count;
  2669. wmi_handle->soc->htc_handle = htc_handle;
  2670. wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
  2671. if (wmi_ep_count > WMI_MAX_RADIOS)
  2672. return QDF_STATUS_E_FAULT;
  2673. for (i = 0; i < wmi_ep_count; i++)
  2674. wmi_connect_pdev_htc_service(wmi_handle->soc, i);
  2675. wmi_handle->htc_handle = htc_handle;
  2676. wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
  2677. wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
  2678. return QDF_STATUS_SUCCESS;
  2679. }
  2680. /**
  2681. * wmi_get_host_credits() - WMI API to get updated host_credits
  2682. *
  2683. * @wmi_handle: handle to WMI.
  2684. *
  2685. * @Return: updated host_credits.
  2686. */
  2687. int wmi_get_host_credits(wmi_unified_t wmi_handle)
  2688. {
  2689. int host_credits = 0;
  2690. htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
  2691. &host_credits);
  2692. return host_credits;
  2693. }
  2694. /**
  2695. * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
  2696. * queue
  2697. *
  2698. * @wmi_handle: handle to WMI.
  2699. *
  2700. * @Return: Pending Commands in the HTC queue.
  2701. */
  2702. int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
  2703. {
  2704. return qdf_atomic_read(&wmi_handle->pending_cmds);
  2705. }
  2706. /**
  2707. * wmi_set_target_suspend() - WMI API to set target suspend state
  2708. *
  2709. * @wmi_handle: handle to WMI.
  2710. * @val: suspend state boolean.
  2711. *
  2712. * @Return: none.
  2713. */
  2714. void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
  2715. {
  2716. qdf_atomic_set(&wmi_handle->is_target_suspended, val);
  2717. }
  2718. /**
  2719. * wmi_is_target_suspended() - WMI API to check target suspend state
  2720. * @wmi_handle: handle to WMI.
  2721. *
  2722. * WMI API to check target suspend state
  2723. *
  2724. * Return: true if target is suspended, else false.
  2725. */
  2726. bool wmi_is_target_suspended(struct wmi_unified *wmi_handle)
  2727. {
  2728. return qdf_atomic_read(&wmi_handle->is_target_suspended);
  2729. }
  2730. qdf_export_symbol(wmi_is_target_suspended);
  2731. #ifdef WLAN_FEATURE_WMI_SEND_RECV_QMI
  2732. void wmi_set_qmi_stats(wmi_unified_t wmi_handle, bool val)
  2733. {
  2734. wmi_handle->is_qmi_stats_enabled = val;
  2735. }
  2736. bool wmi_is_qmi_stats_enabled(struct wmi_unified *wmi_handle)
  2737. {
  2738. return wmi_handle->is_qmi_stats_enabled;
  2739. }
  2740. #endif
  2741. /**
  2742. * WMI API to set crash injection state
  2743. * @param wmi_handle: handle to WMI.
  2744. * @param val: crash injection state boolean.
  2745. */
  2746. void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
  2747. {
  2748. wmi_handle->tag_crash_inject = flag;
  2749. }
  2750. /**
  2751. * WMI API to set bus suspend state
  2752. * @param wmi_handle: handle to WMI.
  2753. * @param val: suspend state boolean.
  2754. */
  2755. void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
  2756. {
  2757. qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
  2758. }
  2759. void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val)
  2760. {
  2761. wmi_handle->tgt_force_assert_enable = val;
  2762. }
  2763. /**
  2764. * wmi_stop() - generic function to block unified WMI command
  2765. * @wmi_handle: handle to WMI.
  2766. *
  2767. * @Return: success always.
  2768. */
  2769. int
  2770. wmi_stop(wmi_unified_t wmi_handle)
  2771. {
  2772. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  2773. "WMI Stop");
  2774. wmi_handle->wmi_stopinprogress = 1;
  2775. return 0;
  2776. }
  2777. /**
  2778. * wmi_start() - generic function to allow unified WMI command
  2779. * @wmi_handle: handle to WMI.
  2780. *
  2781. * @Return: success always.
  2782. */
  2783. int
  2784. wmi_start(wmi_unified_t wmi_handle)
  2785. {
  2786. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  2787. "WMI Start");
  2788. wmi_handle->wmi_stopinprogress = 0;
  2789. return 0;
  2790. }
  2791. /**
  2792. * wmi_is_blocked() - generic function to check if WMI is blocked
  2793. * @wmi_handle: handle to WMI.
  2794. *
  2795. * @Return: true, if blocked, false if not blocked
  2796. */
  2797. bool
  2798. wmi_is_blocked(wmi_unified_t wmi_handle)
  2799. {
  2800. return (!(!wmi_handle->wmi_stopinprogress));
  2801. }
  2802. /**
  2803. * API to flush all the previous packets associated with the wmi endpoint
  2804. *
  2805. * @param wmi_handle : handle to WMI.
  2806. */
  2807. void
  2808. wmi_flush_endpoint(wmi_unified_t wmi_handle)
  2809. {
  2810. htc_flush_endpoint(wmi_handle->htc_handle,
  2811. wmi_handle->wmi_endpoint_id, 0);
  2812. }
  2813. qdf_export_symbol(wmi_flush_endpoint);
  2814. /**
  2815. * wmi_pdev_id_conversion_enable() - API to enable pdev_id/phy_id conversion
  2816. * in WMI. By default pdev_id conversion is not done in WMI.
  2817. * This API can be used enable conversion in WMI.
  2818. * @param wmi_handle : handle to WMI
  2819. * @param pdev_map : pointer to pdev_map
  2820. * @size : size of pdev_id_map
  2821. * Return none
  2822. */
  2823. void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle,
  2824. uint32_t *pdev_id_map,
  2825. uint8_t size)
  2826. {
  2827. if (wmi_handle->target_type == WMI_TLV_TARGET)
  2828. wmi_handle->ops->wmi_pdev_id_conversion_enable(wmi_handle,
  2829. pdev_id_map,
  2830. size);
  2831. }