wmi_unified.c 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534
  1. /*
  2. * Copyright (c) 2015-2018 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. #ifndef WMI_NON_TLV_SUPPORT
  27. #include "wmi_tlv_helper.h"
  28. #endif
  29. #include <linux/debugfs.h>
  30. /* This check for CONFIG_WIN temporary added due to redeclaration compilation
  31. error in MCL. Error is caused due to inclusion of wmi.h in wmi_unified_api.h
  32. which gets included here through ol_if_athvar.h. Eventually it is expected that
  33. wmi.h will be removed from wmi_unified_api.h after cleanup, which will need
  34. WMI_CMD_HDR to be defined here. */
  35. #ifdef CONFIG_WIN
  36. /* Copied from wmi.h */
  37. #undef MS
  38. #define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
  39. #undef SM
  40. #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
  41. #undef WO
  42. #define WO(_f) ((_f##_OFFSET) >> 2)
  43. #undef GET_FIELD
  44. #define GET_FIELD(_addr, _f) MS(*((uint32_t *)(_addr) + WO(_f)), _f)
  45. #undef SET_FIELD
  46. #define SET_FIELD(_addr, _f, _val) \
  47. (*((uint32_t *)(_addr) + WO(_f)) = \
  48. (*((uint32_t *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f))
  49. #define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \
  50. GET_FIELD(_msg_buf, _msg_type ## _ ## _f)
  51. #define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \
  52. SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val)
  53. #define WMI_EP_APASS 0x0
  54. #define WMI_EP_LPASS 0x1
  55. #define WMI_EP_SENSOR 0x2
  56. /*
  57. * * Control Path
  58. * */
  59. typedef PREPACK struct {
  60. uint32_t commandId:24,
  61. reserved:2, /* used for WMI endpoint ID */
  62. plt_priv:6; /* platform private */
  63. } POSTPACK WMI_CMD_HDR; /* used for commands and events */
  64. #define WMI_CMD_HDR_COMMANDID_LSB 0
  65. #define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff
  66. #define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000
  67. #define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000
  68. #define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24
  69. #define WMI_CMD_HDR_PLT_PRIV_LSB 24
  70. #define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000
  71. #define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000
  72. /* end of copy wmi.h */
  73. #endif /* CONFIG_WIN */
  74. #define WMI_MIN_HEAD_ROOM 64
  75. #ifdef WMI_INTERFACE_EVENT_LOGGING
  76. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
  77. /* TODO Cleanup this backported function */
  78. static int wmi_bp_seq_printf(struct seq_file *m, const char *f, ...)
  79. {
  80. va_list args;
  81. va_start(args, f);
  82. seq_vprintf(m, f, args);
  83. va_end(args);
  84. return 0;
  85. }
  86. #else
  87. #define wmi_bp_seq_printf(m, fmt, ...) seq_printf((m), fmt, ##__VA_ARGS__)
  88. #endif
  89. #ifndef MAX_WMI_INSTANCES
  90. #define CUSTOM_MGMT_CMD_DATA_SIZE 4
  91. #endif
  92. #ifdef CONFIG_MCL
  93. /* WMI commands */
  94. uint32_t g_wmi_command_buf_idx = 0;
  95. struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  96. /* WMI commands TX completed */
  97. uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
  98. struct wmi_command_debug
  99. wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  100. /* WMI events when processed */
  101. uint32_t g_wmi_event_buf_idx = 0;
  102. struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  103. /* WMI events when queued */
  104. uint32_t g_wmi_rx_event_buf_idx = 0;
  105. struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  106. #endif
  107. #define WMI_COMMAND_RECORD(h, a, b) { \
  108. if (wmi_log_max_entry <= \
  109. *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
  110. *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
  111. ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
  112. [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
  113. .command = a; \
  114. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  115. wmi_command_log_buf_info.buf) \
  116. [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
  117. b, wmi_record_max_length); \
  118. ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
  119. [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
  120. time = qdf_get_log_timestamp(); \
  121. (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
  122. h->log_info.wmi_command_log_buf_info.length++; \
  123. }
  124. #define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
  125. if (wmi_log_max_entry <= \
  126. *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
  127. *(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  128. p_buf_tail_idx) = 0; \
  129. ((struct wmi_command_debug *)h->log_info. \
  130. wmi_command_tx_cmp_log_buf_info.buf) \
  131. [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  132. p_buf_tail_idx)]. \
  133. command = a; \
  134. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  135. wmi_command_tx_cmp_log_buf_info.buf) \
  136. [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  137. p_buf_tail_idx)]. \
  138. data, b, wmi_record_max_length); \
  139. ((struct wmi_command_debug *)h->log_info. \
  140. wmi_command_tx_cmp_log_buf_info.buf) \
  141. [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  142. p_buf_tail_idx)]. \
  143. time = qdf_get_log_timestamp(); \
  144. (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
  145. h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
  146. }
  147. #define WMI_EVENT_RECORD(h, a, b) { \
  148. if (wmi_log_max_entry <= \
  149. *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
  150. *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
  151. ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
  152. [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
  153. event = a; \
  154. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  155. wmi_event_log_buf_info.buf) \
  156. [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
  157. wmi_record_max_length); \
  158. ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
  159. [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
  160. qdf_get_log_timestamp(); \
  161. (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
  162. h->log_info.wmi_event_log_buf_info.length++; \
  163. }
  164. #define WMI_RX_EVENT_RECORD(h, a, b) { \
  165. if (wmi_log_max_entry <= \
  166. *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
  167. *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
  168. ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
  169. [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
  170. event = a; \
  171. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  172. wmi_rx_event_log_buf_info.buf) \
  173. [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
  174. data, b, wmi_record_max_length); \
  175. ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
  176. [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
  177. time = qdf_get_log_timestamp(); \
  178. (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
  179. h->log_info.wmi_rx_event_log_buf_info.length++; \
  180. }
  181. #ifdef CONFIG_MCL
  182. uint32_t g_wmi_mgmt_command_buf_idx = 0;
  183. struct
  184. wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
  185. /* wmi_mgmt commands TX completed */
  186. uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
  187. struct wmi_command_debug
  188. wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
  189. /* wmi_mgmt events when processed */
  190. uint32_t g_wmi_mgmt_event_buf_idx = 0;
  191. struct wmi_event_debug
  192. wmi_mgmt_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
  193. #endif
  194. #define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
  195. if (wmi_mgmt_log_max_entry <= \
  196. *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
  197. *(h->log_info.wmi_mgmt_command_log_buf_info. \
  198. p_buf_tail_idx) = 0; \
  199. ((struct wmi_command_debug *)h->log_info. \
  200. wmi_mgmt_command_log_buf_info.buf) \
  201. [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
  202. command = a; \
  203. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  204. wmi_mgmt_command_log_buf_info.buf) \
  205. [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
  206. data, b, \
  207. wmi_record_max_length); \
  208. ((struct wmi_command_debug *)h->log_info. \
  209. wmi_mgmt_command_log_buf_info.buf) \
  210. [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
  211. time = qdf_get_log_timestamp(); \
  212. (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
  213. h->log_info.wmi_mgmt_command_log_buf_info.length++; \
  214. }
  215. #define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
  216. if (wmi_mgmt_log_max_entry <= \
  217. *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  218. p_buf_tail_idx)) \
  219. *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  220. p_buf_tail_idx) = 0; \
  221. ((struct wmi_command_debug *)h->log_info. \
  222. wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
  223. [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  224. p_buf_tail_idx)].command = a; \
  225. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  226. wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
  227. [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  228. p_buf_tail_idx)].data, b, \
  229. wmi_record_max_length); \
  230. ((struct wmi_command_debug *)h->log_info. \
  231. wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
  232. [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  233. p_buf_tail_idx)].time = \
  234. qdf_get_log_timestamp(); \
  235. (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  236. p_buf_tail_idx))++; \
  237. h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
  238. }
  239. #define WMI_MGMT_EVENT_RECORD(h, a, b) { \
  240. if (wmi_mgmt_log_max_entry <= \
  241. *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
  242. *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
  243. ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
  244. [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
  245. .event = a; \
  246. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  247. wmi_mgmt_event_log_buf_info.buf) \
  248. [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
  249. data, b, wmi_record_max_length); \
  250. ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
  251. [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
  252. time = qdf_get_log_timestamp(); \
  253. (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
  254. h->log_info.wmi_mgmt_event_log_buf_info.length++; \
  255. }
  256. /* These are defined to made it as module param, which can be configured */
  257. uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
  258. uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  259. uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
  260. uint32_t wmi_display_size = 100;
  261. /**
  262. * wmi_log_init() - Initialize WMI event logging
  263. * @wmi_handle: WMI handle.
  264. *
  265. * Return: Initialization status
  266. */
  267. #ifdef CONFIG_MCL
  268. static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
  269. {
  270. struct wmi_log_buf_t *cmd_log_buf =
  271. &wmi_handle->log_info.wmi_command_log_buf_info;
  272. struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
  273. &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
  274. struct wmi_log_buf_t *event_log_buf =
  275. &wmi_handle->log_info.wmi_event_log_buf_info;
  276. struct wmi_log_buf_t *rx_event_log_buf =
  277. &wmi_handle->log_info.wmi_rx_event_log_buf_info;
  278. struct wmi_log_buf_t *mgmt_cmd_log_buf =
  279. &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
  280. struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
  281. &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
  282. struct wmi_log_buf_t *mgmt_event_log_buf =
  283. &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
  284. /* WMI commands */
  285. cmd_log_buf->length = 0;
  286. cmd_log_buf->buf_tail_idx = 0;
  287. cmd_log_buf->buf = wmi_command_log_buffer;
  288. cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
  289. cmd_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  290. /* WMI commands TX completed */
  291. cmd_tx_cmpl_log_buf->length = 0;
  292. cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
  293. cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
  294. cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
  295. cmd_tx_cmpl_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  296. /* WMI events when processed */
  297. event_log_buf->length = 0;
  298. event_log_buf->buf_tail_idx = 0;
  299. event_log_buf->buf = wmi_event_log_buffer;
  300. event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
  301. event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  302. /* WMI events when queued */
  303. rx_event_log_buf->length = 0;
  304. rx_event_log_buf->buf_tail_idx = 0;
  305. rx_event_log_buf->buf = wmi_rx_event_log_buffer;
  306. rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
  307. rx_event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  308. /* WMI Management commands */
  309. mgmt_cmd_log_buf->length = 0;
  310. mgmt_cmd_log_buf->buf_tail_idx = 0;
  311. mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
  312. mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
  313. mgmt_cmd_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  314. /* WMI Management commands Tx completed*/
  315. mgmt_cmd_tx_cmp_log_buf->length = 0;
  316. mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
  317. mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
  318. mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
  319. &g_wmi_mgmt_command_tx_cmp_buf_idx;
  320. mgmt_cmd_tx_cmp_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  321. /* WMI Management events when processed*/
  322. mgmt_event_log_buf->length = 0;
  323. mgmt_event_log_buf->buf_tail_idx = 0;
  324. mgmt_event_log_buf->buf = wmi_mgmt_event_log_buffer;
  325. mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_event_buf_idx;
  326. mgmt_event_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  327. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  328. wmi_handle->log_info.wmi_logging_enable = 1;
  329. return QDF_STATUS_SUCCESS;
  330. }
  331. #else
  332. static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
  333. {
  334. struct wmi_log_buf_t *cmd_log_buf =
  335. &wmi_handle->log_info.wmi_command_log_buf_info;
  336. struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
  337. &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
  338. struct wmi_log_buf_t *event_log_buf =
  339. &wmi_handle->log_info.wmi_event_log_buf_info;
  340. struct wmi_log_buf_t *rx_event_log_buf =
  341. &wmi_handle->log_info.wmi_rx_event_log_buf_info;
  342. struct wmi_log_buf_t *mgmt_cmd_log_buf =
  343. &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
  344. struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
  345. &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
  346. struct wmi_log_buf_t *mgmt_event_log_buf =
  347. &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
  348. wmi_handle->log_info.wmi_logging_enable = 0;
  349. /* WMI commands */
  350. cmd_log_buf->length = 0;
  351. cmd_log_buf->buf_tail_idx = 0;
  352. cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
  353. wmi_log_max_entry * sizeof(struct wmi_command_debug));
  354. cmd_log_buf->size = wmi_log_max_entry;
  355. if (!cmd_log_buf->buf) {
  356. qdf_print("no memory for WMI command log buffer..");
  357. return QDF_STATUS_E_NOMEM;
  358. }
  359. cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
  360. /* WMI commands TX completed */
  361. cmd_tx_cmpl_log_buf->length = 0;
  362. cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
  363. cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
  364. wmi_log_max_entry * sizeof(struct wmi_command_debug));
  365. cmd_tx_cmpl_log_buf->size = wmi_log_max_entry;
  366. if (!cmd_tx_cmpl_log_buf->buf) {
  367. qdf_print("no memory for WMI Command Tx Complete log buffer..");
  368. return QDF_STATUS_E_NOMEM;
  369. }
  370. cmd_tx_cmpl_log_buf->p_buf_tail_idx =
  371. &cmd_tx_cmpl_log_buf->buf_tail_idx;
  372. /* WMI events when processed */
  373. event_log_buf->length = 0;
  374. event_log_buf->buf_tail_idx = 0;
  375. event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  376. wmi_log_max_entry * sizeof(struct wmi_event_debug));
  377. event_log_buf->size = wmi_log_max_entry;
  378. if (!event_log_buf->buf) {
  379. qdf_print("no memory for WMI Event log buffer..");
  380. return QDF_STATUS_E_NOMEM;
  381. }
  382. event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
  383. /* WMI events when queued */
  384. rx_event_log_buf->length = 0;
  385. rx_event_log_buf->buf_tail_idx = 0;
  386. rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  387. wmi_log_max_entry * sizeof(struct wmi_event_debug));
  388. rx_event_log_buf->size = wmi_log_max_entry;
  389. if (!rx_event_log_buf->buf) {
  390. qdf_print("no memory for WMI Event Rx log buffer..");
  391. return QDF_STATUS_E_NOMEM;
  392. }
  393. rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
  394. /* WMI Management commands */
  395. mgmt_cmd_log_buf->length = 0;
  396. mgmt_cmd_log_buf->buf_tail_idx = 0;
  397. mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
  398. wmi_mgmt_log_max_entry * sizeof(struct wmi_command_debug));
  399. mgmt_cmd_log_buf->size = wmi_mgmt_log_max_entry;
  400. if (!mgmt_cmd_log_buf->buf) {
  401. qdf_print("no memory for WMI Management Command log buffer..");
  402. return QDF_STATUS_E_NOMEM;
  403. }
  404. mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
  405. /* WMI Management commands Tx completed*/
  406. mgmt_cmd_tx_cmp_log_buf->length = 0;
  407. mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
  408. mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
  409. qdf_mem_malloc(
  410. wmi_mgmt_log_max_entry *
  411. sizeof(struct wmi_command_debug));
  412. mgmt_cmd_tx_cmp_log_buf->size = wmi_mgmt_log_max_entry;
  413. if (!mgmt_cmd_tx_cmp_log_buf->buf) {
  414. qdf_print("no memory for WMI Management Command Tx complete log buffer..");
  415. return QDF_STATUS_E_NOMEM;
  416. }
  417. mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
  418. &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
  419. /* WMI Management events when processed*/
  420. mgmt_event_log_buf->length = 0;
  421. mgmt_event_log_buf->buf_tail_idx = 0;
  422. mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  423. wmi_mgmt_log_max_entry *
  424. sizeof(struct wmi_event_debug));
  425. mgmt_event_log_buf->size = wmi_mgmt_log_max_entry;
  426. if (!mgmt_event_log_buf->buf) {
  427. qdf_print("no memory for WMI Management Event log buffer..");
  428. return QDF_STATUS_E_NOMEM;
  429. }
  430. mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
  431. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  432. wmi_handle->log_info.wmi_logging_enable = 1;
  433. return QDF_STATUS_SUCCESS;
  434. }
  435. #endif
  436. /**
  437. * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
  438. * event logging
  439. * @wmi_handle: WMI handle.
  440. *
  441. * Return: None
  442. */
  443. #ifndef CONFIG_MCL
  444. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
  445. {
  446. if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
  447. qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
  448. if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
  449. qdf_mem_free(
  450. wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
  451. if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
  452. qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
  453. if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
  454. qdf_mem_free(
  455. wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
  456. if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
  457. qdf_mem_free(
  458. wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
  459. if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
  460. qdf_mem_free(
  461. wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
  462. if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
  463. qdf_mem_free(
  464. wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
  465. wmi_handle->log_info.wmi_logging_enable = 0;
  466. qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
  467. }
  468. #else
  469. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
  470. {
  471. /* Do Nothing */
  472. }
  473. #endif
  474. /**
  475. * wmi_print_cmd_log_buffer() - an output agnostic wmi command log printer
  476. * @log_buffer: the command log buffer metadata of the buffer to print
  477. * @count: the maximum number of entries to print
  478. * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
  479. * @print_priv: any data required by the print method, e.g. a file handle
  480. *
  481. * Return: None
  482. */
  483. static void
  484. wmi_print_cmd_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
  485. qdf_abstract_print *print, void *print_priv)
  486. {
  487. static const int data_len =
  488. WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
  489. char str[128];
  490. uint32_t idx;
  491. if (count > log_buffer->size)
  492. count = log_buffer->size;
  493. if (count > log_buffer->length)
  494. count = log_buffer->length;
  495. /* subtract count from index, and wrap if necessary */
  496. idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
  497. idx %= log_buffer->size;
  498. print(print_priv, "Time (seconds) Cmd Id Payload");
  499. while (count) {
  500. struct wmi_command_debug *cmd_log = (struct wmi_command_debug *)
  501. &((struct wmi_command_debug *)log_buffer->buf)[idx];
  502. uint64_t secs, usecs;
  503. int len = 0;
  504. int i;
  505. qdf_log_timestamp_to_secs(cmd_log->time, &secs, &usecs);
  506. len += scnprintf(str + len, sizeof(str) - len,
  507. "% 8lld.%06lld %6u (0x%06x) ",
  508. secs, usecs,
  509. cmd_log->command, cmd_log->command);
  510. for (i = 0; i < data_len; ++i) {
  511. len += scnprintf(str + len, sizeof(str) - len,
  512. "0x%08x ", cmd_log->data[i]);
  513. }
  514. print(print_priv, str);
  515. --count;
  516. ++idx;
  517. if (idx >= log_buffer->size)
  518. idx = 0;
  519. }
  520. }
  521. /**
  522. * wmi_print_event_log_buffer() - an output agnostic wmi event log printer
  523. * @log_buffer: the event log buffer metadata of the buffer to print
  524. * @count: the maximum number of entries to print
  525. * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
  526. * @print_priv: any data required by the print method, e.g. a file handle
  527. *
  528. * Return: None
  529. */
  530. static void
  531. wmi_print_event_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
  532. qdf_abstract_print *print, void *print_priv)
  533. {
  534. static const int data_len =
  535. WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
  536. char str[128];
  537. uint32_t idx;
  538. if (count > log_buffer->size)
  539. count = log_buffer->size;
  540. if (count > log_buffer->length)
  541. count = log_buffer->length;
  542. /* subtract count from index, and wrap if necessary */
  543. idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
  544. idx %= log_buffer->size;
  545. print(print_priv, "Time (seconds) Event Id Payload");
  546. while (count) {
  547. struct wmi_event_debug *event_log = (struct wmi_event_debug *)
  548. &((struct wmi_event_debug *)log_buffer->buf)[idx];
  549. uint64_t secs, usecs;
  550. int len = 0;
  551. int i;
  552. qdf_log_timestamp_to_secs(event_log->time, &secs, &usecs);
  553. len += scnprintf(str + len, sizeof(str) - len,
  554. "% 8lld.%06lld %6u (0x%06x) ",
  555. secs, usecs,
  556. event_log->event, event_log->event);
  557. for (i = 0; i < data_len; ++i) {
  558. len += scnprintf(str + len, sizeof(str) - len,
  559. "0x%08x ", event_log->data[i]);
  560. }
  561. print(print_priv, str);
  562. --count;
  563. ++idx;
  564. if (idx >= log_buffer->size)
  565. idx = 0;
  566. }
  567. }
  568. inline void
  569. wmi_print_cmd_log(wmi_unified_t wmi, uint32_t count,
  570. qdf_abstract_print *print, void *print_priv)
  571. {
  572. wmi_print_cmd_log_buffer(
  573. &wmi->log_info.wmi_command_log_buf_info,
  574. count, print, print_priv);
  575. }
  576. inline void
  577. wmi_print_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
  578. qdf_abstract_print *print, void *print_priv)
  579. {
  580. wmi_print_cmd_log_buffer(
  581. &wmi->log_info.wmi_command_tx_cmp_log_buf_info,
  582. count, print, print_priv);
  583. }
  584. inline void
  585. wmi_print_mgmt_cmd_log(wmi_unified_t wmi, uint32_t count,
  586. qdf_abstract_print *print, void *print_priv)
  587. {
  588. wmi_print_cmd_log_buffer(
  589. &wmi->log_info.wmi_mgmt_command_log_buf_info,
  590. count, print, print_priv);
  591. }
  592. inline void
  593. wmi_print_mgmt_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
  594. qdf_abstract_print *print, void *print_priv)
  595. {
  596. wmi_print_cmd_log_buffer(
  597. &wmi->log_info.wmi_mgmt_command_tx_cmp_log_buf_info,
  598. count, print, print_priv);
  599. }
  600. inline void
  601. wmi_print_event_log(wmi_unified_t wmi, uint32_t count,
  602. qdf_abstract_print *print, void *print_priv)
  603. {
  604. wmi_print_event_log_buffer(
  605. &wmi->log_info.wmi_event_log_buf_info,
  606. count, print, print_priv);
  607. }
  608. inline void
  609. wmi_print_rx_event_log(wmi_unified_t wmi, uint32_t count,
  610. qdf_abstract_print *print, void *print_priv)
  611. {
  612. wmi_print_event_log_buffer(
  613. &wmi->log_info.wmi_rx_event_log_buf_info,
  614. count, print, print_priv);
  615. }
  616. inline void
  617. wmi_print_mgmt_event_log(wmi_unified_t wmi, uint32_t count,
  618. qdf_abstract_print *print, void *print_priv)
  619. {
  620. wmi_print_event_log_buffer(
  621. &wmi->log_info.wmi_mgmt_event_log_buf_info,
  622. count, print, print_priv);
  623. }
  624. /* debugfs routines*/
  625. /**
  626. * debug_wmi_##func_base##_show() - debugfs functions to display content of
  627. * command and event buffers. Macro uses max buffer length to display
  628. * buffer when it is wraparound.
  629. *
  630. * @m: debugfs handler to access wmi_handle
  631. * @v: Variable arguments (not used)
  632. *
  633. * Return: Length of characters printed
  634. */
  635. #define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
  636. static int debug_wmi_##func_base##_show(struct seq_file *m, \
  637. void *v) \
  638. { \
  639. wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
  640. struct wmi_log_buf_t *wmi_log = \
  641. &wmi_handle->log_info.wmi_##func_base##_buf_info;\
  642. int pos, nread, outlen; \
  643. int i; \
  644. uint64_t secs, usecs; \
  645. \
  646. qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
  647. if (!wmi_log->length) { \
  648. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
  649. return wmi_bp_seq_printf(m, \
  650. "no elements to read from ring buffer!\n"); \
  651. } \
  652. \
  653. if (wmi_log->length <= wmi_ring_size) \
  654. nread = wmi_log->length; \
  655. else \
  656. nread = wmi_ring_size; \
  657. \
  658. if (*(wmi_log->p_buf_tail_idx) == 0) \
  659. /* tail can be 0 after wrap-around */ \
  660. pos = wmi_ring_size - 1; \
  661. else \
  662. pos = *(wmi_log->p_buf_tail_idx) - 1; \
  663. \
  664. outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
  665. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
  666. while (nread--) { \
  667. struct wmi_command_debug *wmi_record; \
  668. \
  669. wmi_record = (struct wmi_command_debug *) \
  670. &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
  671. outlen += wmi_bp_seq_printf(m, "CMD ID = %x\n", \
  672. (wmi_record->command)); \
  673. qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
  674. &usecs); \
  675. outlen += \
  676. wmi_bp_seq_printf(m, "CMD TIME = [%llu.%06llu]\n",\
  677. secs, usecs); \
  678. outlen += wmi_bp_seq_printf(m, "CMD = "); \
  679. for (i = 0; i < (wmi_record_max_length/ \
  680. sizeof(uint32_t)); i++) \
  681. outlen += wmi_bp_seq_printf(m, "%x ", \
  682. wmi_record->data[i]); \
  683. outlen += wmi_bp_seq_printf(m, "\n"); \
  684. \
  685. if (pos == 0) \
  686. pos = wmi_ring_size - 1; \
  687. else \
  688. pos--; \
  689. } \
  690. return outlen; \
  691. } \
  692. #define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
  693. static int debug_wmi_##func_base##_show(struct seq_file *m, \
  694. void *v) \
  695. { \
  696. wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
  697. struct wmi_log_buf_t *wmi_log = \
  698. &wmi_handle->log_info.wmi_##func_base##_buf_info;\
  699. int pos, nread, outlen; \
  700. int i; \
  701. uint64_t secs, usecs; \
  702. \
  703. qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
  704. if (!wmi_log->length) { \
  705. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
  706. return wmi_bp_seq_printf(m, \
  707. "no elements to read from ring buffer!\n"); \
  708. } \
  709. \
  710. if (wmi_log->length <= wmi_ring_size) \
  711. nread = wmi_log->length; \
  712. else \
  713. nread = wmi_ring_size; \
  714. \
  715. if (*(wmi_log->p_buf_tail_idx) == 0) \
  716. /* tail can be 0 after wrap-around */ \
  717. pos = wmi_ring_size - 1; \
  718. else \
  719. pos = *(wmi_log->p_buf_tail_idx) - 1; \
  720. \
  721. outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
  722. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
  723. while (nread--) { \
  724. struct wmi_event_debug *wmi_record; \
  725. \
  726. wmi_record = (struct wmi_event_debug *) \
  727. &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
  728. qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
  729. &usecs); \
  730. outlen += wmi_bp_seq_printf(m, "Event ID = %x\n",\
  731. (wmi_record->event)); \
  732. outlen += \
  733. wmi_bp_seq_printf(m, "Event TIME = [%llu.%06llu]\n",\
  734. secs, usecs); \
  735. outlen += wmi_bp_seq_printf(m, "CMD = "); \
  736. for (i = 0; i < (wmi_record_max_length/ \
  737. sizeof(uint32_t)); i++) \
  738. outlen += wmi_bp_seq_printf(m, "%x ", \
  739. wmi_record->data[i]); \
  740. outlen += wmi_bp_seq_printf(m, "\n"); \
  741. \
  742. if (pos == 0) \
  743. pos = wmi_ring_size - 1; \
  744. else \
  745. pos--; \
  746. } \
  747. return outlen; \
  748. }
  749. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
  750. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
  751. GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
  752. GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
  753. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
  754. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
  755. wmi_display_size);
  756. GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
  757. /**
  758. * debug_wmi_enable_show() - debugfs functions to display enable state of
  759. * wmi logging feature.
  760. *
  761. * @m: debugfs handler to access wmi_handle
  762. * @v: Variable arguments (not used)
  763. *
  764. * Return: always 1
  765. */
  766. static int debug_wmi_enable_show(struct seq_file *m, void *v)
  767. {
  768. wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
  769. return wmi_bp_seq_printf(m, "%d\n",
  770. wmi_handle->log_info.wmi_logging_enable);
  771. }
  772. /**
  773. * debug_wmi_log_size_show() - debugfs functions to display configured size of
  774. * wmi logging command/event buffer and management command/event buffer.
  775. *
  776. * @m: debugfs handler to access wmi_handle
  777. * @v: Variable arguments (not used)
  778. *
  779. * Return: Length of characters printed
  780. */
  781. static int debug_wmi_log_size_show(struct seq_file *m, void *v)
  782. {
  783. wmi_bp_seq_printf(m, "WMI command/event log max size:%d\n",
  784. wmi_log_max_entry);
  785. return wmi_bp_seq_printf(m,
  786. "WMI management command/events log max size:%d\n",
  787. wmi_mgmt_log_max_entry);
  788. }
  789. /**
  790. * debug_wmi_##func_base##_write() - debugfs functions to clear
  791. * wmi logging command/event buffer and management command/event buffer.
  792. *
  793. * @file: file handler to access wmi_handle
  794. * @buf: received data buffer
  795. * @count: length of received buffer
  796. * @ppos: Not used
  797. *
  798. * Return: count
  799. */
  800. #define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
  801. static ssize_t debug_wmi_##func_base##_write(struct file *file, \
  802. const char __user *buf, \
  803. size_t count, loff_t *ppos) \
  804. { \
  805. int k, ret; \
  806. wmi_unified_t wmi_handle = \
  807. ((struct seq_file *)file->private_data)->private;\
  808. struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
  809. wmi_##func_base##_buf_info; \
  810. char locbuf[50]; \
  811. \
  812. if ((!buf) || (count > 50)) \
  813. return -EFAULT; \
  814. \
  815. if (copy_from_user(locbuf, buf, count)) \
  816. return -EFAULT; \
  817. \
  818. ret = sscanf(locbuf, "%d", &k); \
  819. if ((ret != 1) || (k != 0)) { \
  820. qdf_print("Wrong input, echo 0 to clear the wmi buffer");\
  821. return -EINVAL; \
  822. } \
  823. \
  824. qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
  825. qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
  826. sizeof(struct wmi_record_type)); \
  827. wmi_log->length = 0; \
  828. *(wmi_log->p_buf_tail_idx) = 0; \
  829. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
  830. \
  831. return count; \
  832. }
  833. GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
  834. wmi_command_debug);
  835. GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
  836. wmi_command_debug);
  837. GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
  838. wmi_event_debug);
  839. GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
  840. wmi_event_debug);
  841. GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
  842. wmi_command_debug);
  843. GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
  844. wmi_mgmt_log_max_entry, wmi_command_debug);
  845. GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
  846. wmi_event_debug);
  847. /**
  848. * debug_wmi_enable_write() - debugfs functions to enable/disable
  849. * wmi logging feature.
  850. *
  851. * @file: file handler to access wmi_handle
  852. * @buf: received data buffer
  853. * @count: length of received buffer
  854. * @ppos: Not used
  855. *
  856. * Return: count
  857. */
  858. static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
  859. size_t count, loff_t *ppos)
  860. {
  861. wmi_unified_t wmi_handle =
  862. ((struct seq_file *)file->private_data)->private;
  863. int k, ret;
  864. char locbuf[50];
  865. if ((!buf) || (count > 50))
  866. return -EFAULT;
  867. if (copy_from_user(locbuf, buf, count))
  868. return -EFAULT;
  869. ret = sscanf(locbuf, "%d", &k);
  870. if ((ret != 1) || ((k != 0) && (k != 1)))
  871. return -EINVAL;
  872. wmi_handle->log_info.wmi_logging_enable = k;
  873. return count;
  874. }
  875. /**
  876. * debug_wmi_log_size_write() - reserved.
  877. *
  878. * @file: file handler to access wmi_handle
  879. * @buf: received data buffer
  880. * @count: length of received buffer
  881. * @ppos: Not used
  882. *
  883. * Return: count
  884. */
  885. static ssize_t debug_wmi_log_size_write(struct file *file,
  886. const char __user *buf, size_t count, loff_t *ppos)
  887. {
  888. return -EINVAL;
  889. }
  890. /* Structure to maintain debug information */
  891. struct wmi_debugfs_info {
  892. const char *name;
  893. const struct file_operations *ops;
  894. };
  895. #define DEBUG_FOO(func_base) { .name = #func_base, \
  896. .ops = &debug_##func_base##_ops }
  897. /**
  898. * debug_##func_base##_open() - Open debugfs entry for respective command
  899. * and event buffer.
  900. *
  901. * @inode: node for debug dir entry
  902. * @file: file handler
  903. *
  904. * Return: open status
  905. */
  906. #define GENERATE_DEBUG_STRUCTS(func_base) \
  907. static int debug_##func_base##_open(struct inode *inode, \
  908. struct file *file) \
  909. { \
  910. return single_open(file, debug_##func_base##_show, \
  911. inode->i_private); \
  912. } \
  913. \
  914. \
  915. static struct file_operations debug_##func_base##_ops = { \
  916. .open = debug_##func_base##_open, \
  917. .read = seq_read, \
  918. .llseek = seq_lseek, \
  919. .write = debug_##func_base##_write, \
  920. .release = single_release, \
  921. };
  922. GENERATE_DEBUG_STRUCTS(wmi_command_log);
  923. GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
  924. GENERATE_DEBUG_STRUCTS(wmi_event_log);
  925. GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
  926. GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
  927. GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
  928. GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
  929. GENERATE_DEBUG_STRUCTS(wmi_enable);
  930. GENERATE_DEBUG_STRUCTS(wmi_log_size);
  931. struct wmi_debugfs_info wmi_debugfs_infos[NUM_DEBUG_INFOS] = {
  932. DEBUG_FOO(wmi_command_log),
  933. DEBUG_FOO(wmi_command_tx_cmp_log),
  934. DEBUG_FOO(wmi_event_log),
  935. DEBUG_FOO(wmi_rx_event_log),
  936. DEBUG_FOO(wmi_mgmt_command_log),
  937. DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
  938. DEBUG_FOO(wmi_mgmt_event_log),
  939. DEBUG_FOO(wmi_enable),
  940. DEBUG_FOO(wmi_log_size),
  941. };
  942. /**
  943. * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
  944. *
  945. * @wmi_handle: wmi handle
  946. * @par_entry: debug directory entry
  947. * @id: Index to debug info data array
  948. *
  949. * Return: none
  950. */
  951. static void wmi_debugfs_create(wmi_unified_t wmi_handle,
  952. struct dentry *par_entry)
  953. {
  954. int i;
  955. if (!par_entry)
  956. goto out;
  957. for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
  958. wmi_handle->debugfs_de[i] = debugfs_create_file(
  959. wmi_debugfs_infos[i].name, 0644, par_entry,
  960. wmi_handle, wmi_debugfs_infos[i].ops);
  961. if (!wmi_handle->debugfs_de[i]) {
  962. qdf_print("debug Entry creation failed!");
  963. goto out;
  964. }
  965. }
  966. return;
  967. out:
  968. qdf_print("debug Entry creation failed!");
  969. wmi_log_buffer_free(wmi_handle);
  970. return;
  971. }
  972. /**
  973. * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
  974. * @wmi_handle: wmi handle
  975. * @dentry: debugfs directory entry
  976. * @id: Index to debug info data array
  977. *
  978. * Return: none
  979. */
  980. static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
  981. {
  982. int i;
  983. struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
  984. if (dentry) {
  985. for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
  986. if (wmi_handle->debugfs_de[i])
  987. wmi_handle->debugfs_de[i] = NULL;
  988. }
  989. }
  990. if (dentry)
  991. debugfs_remove_recursive(dentry);
  992. }
  993. /**
  994. * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
  995. * create debugfs enteries.
  996. *
  997. * @h: wmi handler
  998. *
  999. * Return: init status
  1000. */
  1001. static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle, uint32_t pdev_idx)
  1002. {
  1003. char buf[32];
  1004. snprintf(buf, sizeof(buf), "WMI_SOC%u_PDEV%u",
  1005. wmi_handle->soc->soc_idx, pdev_idx);
  1006. wmi_handle->log_info.wmi_log_debugfs_dir =
  1007. debugfs_create_dir(buf, NULL);
  1008. if (!wmi_handle->log_info.wmi_log_debugfs_dir) {
  1009. qdf_print("error while creating debugfs dir for %s", buf);
  1010. return QDF_STATUS_E_FAILURE;
  1011. }
  1012. wmi_debugfs_create(wmi_handle,
  1013. wmi_handle->log_info.wmi_log_debugfs_dir);
  1014. return QDF_STATUS_SUCCESS;
  1015. }
  1016. /**
  1017. * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
  1018. *
  1019. * @wmi_handle: wmi handle
  1020. * @cmd: mgmt command
  1021. * @header: pointer to 802.11 header
  1022. * @vdev_id: vdev id
  1023. * @chanfreq: channel frequency
  1024. *
  1025. * Return: none
  1026. */
  1027. void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
  1028. void *header, uint32_t vdev_id, uint32_t chanfreq)
  1029. {
  1030. uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
  1031. data[0] = ((struct wmi_command_header *)header)->type;
  1032. data[1] = ((struct wmi_command_header *)header)->sub_type;
  1033. data[2] = vdev_id;
  1034. data[3] = chanfreq;
  1035. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1036. WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, (uint8_t *)data);
  1037. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1038. }
  1039. #else
  1040. /**
  1041. * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
  1042. * @wmi_handle: wmi handle
  1043. * @dentry: debugfs directory entry
  1044. * @id: Index to debug info data array
  1045. *
  1046. * Return: none
  1047. */
  1048. static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
  1049. void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
  1050. void *header, uint32_t vdev_id, uint32_t chanfreq) { }
  1051. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
  1052. #endif /*WMI_INTERFACE_EVENT_LOGGING */
  1053. qdf_export_symbol(wmi_mgmt_cmd_record);
  1054. int wmi_get_host_credits(wmi_unified_t wmi_handle);
  1055. /* WMI buffer APIs */
  1056. #ifdef NBUF_MEMORY_DEBUG
  1057. wmi_buf_t
  1058. wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint32_t len, uint8_t *file_name,
  1059. uint32_t line_num)
  1060. {
  1061. wmi_buf_t wmi_buf;
  1062. if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
  1063. QDF_ASSERT(0);
  1064. return NULL;
  1065. }
  1066. wmi_buf = qdf_nbuf_alloc_debug(NULL,
  1067. roundup(len + WMI_MIN_HEAD_ROOM, 4),
  1068. WMI_MIN_HEAD_ROOM, 4, false, file_name,
  1069. line_num);
  1070. if (!wmi_buf)
  1071. return NULL;
  1072. /* Clear the wmi buffer */
  1073. OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
  1074. /*
  1075. * Set the length of the buffer to match the allocation size.
  1076. */
  1077. qdf_nbuf_set_pktlen(wmi_buf, len);
  1078. return wmi_buf;
  1079. }
  1080. qdf_export_symbol(wmi_buf_alloc_debug);
  1081. void wmi_buf_free(wmi_buf_t net_buf)
  1082. {
  1083. qdf_nbuf_free(net_buf);
  1084. }
  1085. qdf_export_symbol(wmi_buf_free);
  1086. #else
  1087. wmi_buf_t wmi_buf_alloc_fl(wmi_unified_t wmi_handle, uint32_t len,
  1088. const char *func, uint32_t line)
  1089. {
  1090. wmi_buf_t wmi_buf;
  1091. if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
  1092. wmi_nofl_err("%s:%d, Invalid len:%d", func, line, len);
  1093. QDF_DEBUG_PANIC();
  1094. return NULL;
  1095. }
  1096. wmi_buf = qdf_nbuf_alloc_fl(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
  1097. WMI_MIN_HEAD_ROOM, 4, false, func, line);
  1098. if (!wmi_buf)
  1099. return NULL;
  1100. /* Clear the wmi buffer */
  1101. OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
  1102. /*
  1103. * Set the length of the buffer to match the allocation size.
  1104. */
  1105. qdf_nbuf_set_pktlen(wmi_buf, len);
  1106. return wmi_buf;
  1107. }
  1108. qdf_export_symbol(wmi_buf_alloc_fl);
  1109. void wmi_buf_free(wmi_buf_t net_buf)
  1110. {
  1111. qdf_nbuf_free(net_buf);
  1112. }
  1113. qdf_export_symbol(wmi_buf_free);
  1114. #endif
  1115. /**
  1116. * wmi_get_max_msg_len() - get maximum WMI message length
  1117. * @wmi_handle: WMI handle.
  1118. *
  1119. * This function returns the maximum WMI message length
  1120. *
  1121. * Return: maximum WMI message length
  1122. */
  1123. uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
  1124. {
  1125. return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
  1126. }
  1127. qdf_export_symbol(wmi_get_max_msg_len);
  1128. #ifndef WMI_CMD_STRINGS
  1129. static uint8_t *wmi_id_to_name(uint32_t wmi_command)
  1130. {
  1131. return "Invalid WMI cmd";
  1132. }
  1133. #endif
  1134. #ifdef CONFIG_MCL
  1135. static inline void wmi_log_cmd_id(uint32_t cmd_id, uint32_t tag)
  1136. {
  1137. WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
  1138. wmi_id_to_name(cmd_id), cmd_id, tag);
  1139. }
  1140. /**
  1141. * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
  1142. * @cmd_id: command to check
  1143. *
  1144. * Return: true if the command is part of the resume sequence.
  1145. */
  1146. static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
  1147. {
  1148. switch (cmd_id) {
  1149. case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
  1150. case WMI_PDEV_RESUME_CMDID:
  1151. return true;
  1152. default:
  1153. return false;
  1154. }
  1155. }
  1156. #else
  1157. static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
  1158. {
  1159. return false;
  1160. }
  1161. #endif
  1162. /**
  1163. * wmi_unified_cmd_send() - WMI command API
  1164. * @wmi_handle: handle to wmi
  1165. * @buf: wmi buf
  1166. * @len: wmi buffer length
  1167. * @cmd_id: wmi command id
  1168. *
  1169. * Note, it is NOT safe to access buf after calling this function!
  1170. *
  1171. * Return: 0 on success
  1172. */
  1173. QDF_STATUS wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf,
  1174. uint32_t len, uint32_t cmd_id)
  1175. {
  1176. HTC_PACKET *pkt;
  1177. QDF_STATUS status;
  1178. uint16_t htc_tag = 0;
  1179. if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
  1180. htc_tag =
  1181. (uint16_t)wmi_handle->ops->wmi_set_htc_tx_tag(
  1182. wmi_handle, buf, cmd_id);
  1183. } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
  1184. (!wmi_is_pm_resume_cmd(cmd_id))) {
  1185. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1186. "%s: Target is suspended", __func__);
  1187. QDF_ASSERT(0);
  1188. return QDF_STATUS_E_BUSY;
  1189. }
  1190. if (wmi_handle->wmi_stopinprogress) {
  1191. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1192. "WMI stop in progress");
  1193. return QDF_STATUS_E_INVAL;
  1194. }
  1195. #ifndef WMI_NON_TLV_SUPPORT
  1196. /* Do sanity check on the TLV parameter structure */
  1197. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  1198. void *buf_ptr = (void *)qdf_nbuf_data(buf);
  1199. if (wmi_handle->ops->wmi_check_command_params(NULL, buf_ptr, len, cmd_id)
  1200. != 0) {
  1201. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1202. "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
  1203. __func__, cmd_id);
  1204. return QDF_STATUS_E_INVAL;
  1205. }
  1206. }
  1207. #endif
  1208. if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
  1209. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1210. "%s, Failed to send cmd %x, no memory",
  1211. __func__, cmd_id);
  1212. return QDF_STATUS_E_NOMEM;
  1213. }
  1214. qdf_mem_zero(qdf_nbuf_data(buf), sizeof(WMI_CMD_HDR));
  1215. WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
  1216. qdf_atomic_inc(&wmi_handle->pending_cmds);
  1217. if (qdf_atomic_read(&wmi_handle->pending_cmds) >=
  1218. wmi_handle->wmi_max_cmds) {
  1219. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1220. "\n%s: hostcredits = %d", __func__,
  1221. wmi_get_host_credits(wmi_handle));
  1222. htc_dump_counter_info(wmi_handle->htc_handle);
  1223. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1224. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1225. "%s: MAX %d WMI Pending cmds reached.", __func__,
  1226. wmi_handle->wmi_max_cmds);
  1227. QDF_BUG(0);
  1228. return QDF_STATUS_E_BUSY;
  1229. }
  1230. pkt = qdf_mem_malloc(sizeof(*pkt));
  1231. if (!pkt) {
  1232. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1233. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1234. "%s, Failed to alloc htc packet %x, no memory",
  1235. __func__, cmd_id);
  1236. return QDF_STATUS_E_NOMEM;
  1237. }
  1238. SET_HTC_PACKET_INFO_TX(pkt,
  1239. NULL,
  1240. qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
  1241. wmi_handle->wmi_endpoint_id, htc_tag);
  1242. SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
  1243. #ifdef CONFIG_MCL
  1244. wmi_log_cmd_id(cmd_id, htc_tag);
  1245. #endif
  1246. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1247. if (wmi_handle->log_info.wmi_logging_enable) {
  1248. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1249. /*
  1250. * Record 16 bytes of WMI cmd data -
  1251. * exclude TLV and WMI headers
  1252. *
  1253. * WMI mgmt command already recorded in wmi_mgmt_cmd_record
  1254. */
  1255. if (wmi_handle->ops->is_management_record(cmd_id) == false) {
  1256. WMI_COMMAND_RECORD(wmi_handle, cmd_id,
  1257. qdf_nbuf_data(buf) +
  1258. wmi_handle->log_info.buf_offset_command);
  1259. }
  1260. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1261. }
  1262. #endif
  1263. status = htc_send_pkt(wmi_handle->htc_handle, pkt);
  1264. if (QDF_STATUS_SUCCESS != status) {
  1265. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1266. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1267. "%s %d, htc_send_pkt failed", __func__, __LINE__);
  1268. qdf_mem_free(pkt);
  1269. return status;
  1270. }
  1271. return QDF_STATUS_SUCCESS;
  1272. }
  1273. qdf_export_symbol(wmi_unified_cmd_send);
  1274. /**
  1275. * wmi_unified_get_event_handler_ix() - gives event handler's index
  1276. * @wmi_handle: handle to wmi
  1277. * @event_id: wmi event id
  1278. *
  1279. * Return: event handler's index
  1280. */
  1281. static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
  1282. uint32_t event_id)
  1283. {
  1284. uint32_t idx = 0;
  1285. int32_t invalid_idx = -1;
  1286. struct wmi_soc *soc = wmi_handle->soc;
  1287. for (idx = 0; (idx < soc->max_event_idx &&
  1288. idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
  1289. if (wmi_handle->event_id[idx] == event_id &&
  1290. wmi_handle->event_handler[idx] != NULL) {
  1291. return idx;
  1292. }
  1293. }
  1294. return invalid_idx;
  1295. }
  1296. /**
  1297. * wmi_unified_register_event() - register wmi event handler
  1298. * @wmi_handle: handle to wmi
  1299. * @event_id: wmi event id
  1300. * @handler_func: wmi event handler function
  1301. *
  1302. * Return: 0 on success
  1303. */
  1304. int wmi_unified_register_event(wmi_unified_t wmi_handle,
  1305. uint32_t event_id,
  1306. wmi_unified_event_handler handler_func)
  1307. {
  1308. uint32_t idx = 0;
  1309. uint32_t evt_id;
  1310. struct wmi_soc *soc = wmi_handle->soc;
  1311. if (event_id >= wmi_events_max ||
  1312. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1313. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1314. "%s: Event id %d is unavailable",
  1315. __func__, event_id);
  1316. return QDF_STATUS_E_FAILURE;
  1317. }
  1318. evt_id = wmi_handle->wmi_events[event_id];
  1319. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1320. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1321. "%s : event handler already registered 0x%x",
  1322. __func__, evt_id);
  1323. return QDF_STATUS_E_FAILURE;
  1324. }
  1325. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1326. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1327. "%s : no more event handlers 0x%x",
  1328. __func__, evt_id);
  1329. return QDF_STATUS_E_FAILURE;
  1330. }
  1331. idx = soc->max_event_idx;
  1332. wmi_handle->event_handler[idx] = handler_func;
  1333. wmi_handle->event_id[idx] = evt_id;
  1334. qdf_spin_lock_bh(&soc->ctx_lock);
  1335. wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
  1336. qdf_spin_unlock_bh(&soc->ctx_lock);
  1337. soc->max_event_idx++;
  1338. return 0;
  1339. }
  1340. /**
  1341. * wmi_unified_register_event_handler() - register wmi event handler
  1342. * @wmi_handle: handle to wmi
  1343. * @event_id: wmi event id
  1344. * @handler_func: wmi event handler function
  1345. * @rx_ctx: rx execution context for wmi rx events
  1346. *
  1347. * This API is to support legacy requirements. Will be deprecated in future.
  1348. * Return: 0 on success
  1349. */
  1350. int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
  1351. wmi_conv_event_id event_id,
  1352. wmi_unified_event_handler handler_func,
  1353. uint8_t rx_ctx)
  1354. {
  1355. uint32_t idx = 0;
  1356. uint32_t evt_id;
  1357. struct wmi_soc *soc = wmi_handle->soc;
  1358. if (event_id >= wmi_events_max ||
  1359. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1360. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1361. "%s: Event id %d is unavailable",
  1362. __func__, event_id);
  1363. return QDF_STATUS_E_FAILURE;
  1364. }
  1365. evt_id = wmi_handle->wmi_events[event_id];
  1366. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1367. qdf_print("event handler already registered 0x%x",
  1368. evt_id);
  1369. return QDF_STATUS_E_FAILURE;
  1370. }
  1371. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1372. qdf_print("no more event handlers 0x%x",
  1373. evt_id);
  1374. return QDF_STATUS_E_FAILURE;
  1375. }
  1376. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
  1377. "Registered event handler for event 0x%8x", evt_id);
  1378. idx = soc->max_event_idx;
  1379. wmi_handle->event_handler[idx] = handler_func;
  1380. wmi_handle->event_id[idx] = evt_id;
  1381. qdf_spin_lock_bh(&soc->ctx_lock);
  1382. wmi_handle->ctx[idx] = rx_ctx;
  1383. qdf_spin_unlock_bh(&soc->ctx_lock);
  1384. soc->max_event_idx++;
  1385. return 0;
  1386. }
  1387. qdf_export_symbol(wmi_unified_register_event_handler);
  1388. /**
  1389. * wmi_unified_unregister_event() - unregister wmi event handler
  1390. * @wmi_handle: handle to wmi
  1391. * @event_id: wmi event id
  1392. *
  1393. * Return: 0 on success
  1394. */
  1395. int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
  1396. uint32_t event_id)
  1397. {
  1398. uint32_t idx = 0;
  1399. uint32_t evt_id;
  1400. struct wmi_soc *soc = wmi_handle->soc;
  1401. if (event_id >= wmi_events_max ||
  1402. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1403. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1404. "%s: Event id %d is unavailable",
  1405. __func__, event_id);
  1406. return QDF_STATUS_E_FAILURE;
  1407. }
  1408. evt_id = wmi_handle->wmi_events[event_id];
  1409. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1410. if (idx == -1) {
  1411. qdf_print("event handler is not registered: evt id 0x%x",
  1412. evt_id);
  1413. return QDF_STATUS_E_FAILURE;
  1414. }
  1415. wmi_handle->event_handler[idx] = NULL;
  1416. wmi_handle->event_id[idx] = 0;
  1417. --soc->max_event_idx;
  1418. wmi_handle->event_handler[idx] =
  1419. wmi_handle->event_handler[soc->max_event_idx];
  1420. wmi_handle->event_id[idx] =
  1421. wmi_handle->event_id[soc->max_event_idx];
  1422. return 0;
  1423. }
  1424. /**
  1425. * wmi_unified_unregister_event_handler() - unregister wmi event handler
  1426. * @wmi_handle: handle to wmi
  1427. * @event_id: wmi event id
  1428. *
  1429. * Return: 0 on success
  1430. */
  1431. int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
  1432. wmi_conv_event_id event_id)
  1433. {
  1434. uint32_t idx = 0;
  1435. uint32_t evt_id;
  1436. struct wmi_soc *soc = wmi_handle->soc;
  1437. if (event_id >= wmi_events_max ||
  1438. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1439. qdf_print("Event id %d is unavailable",
  1440. event_id);
  1441. return QDF_STATUS_E_FAILURE;
  1442. }
  1443. evt_id = wmi_handle->wmi_events[event_id];
  1444. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1445. if (idx == -1) {
  1446. qdf_print("event handler is not registered: evt id 0x%x",
  1447. evt_id);
  1448. return QDF_STATUS_E_FAILURE;
  1449. }
  1450. wmi_handle->event_handler[idx] = NULL;
  1451. wmi_handle->event_id[idx] = 0;
  1452. --soc->max_event_idx;
  1453. wmi_handle->event_handler[idx] =
  1454. wmi_handle->event_handler[soc->max_event_idx];
  1455. wmi_handle->event_id[idx] =
  1456. wmi_handle->event_id[soc->max_event_idx];
  1457. return 0;
  1458. }
  1459. qdf_export_symbol(wmi_unified_unregister_event_handler);
  1460. /**
  1461. * wmi_process_fw_event_default_ctx() - process in default caller context
  1462. * @wmi_handle: handle to wmi
  1463. * @htc_packet: pointer to htc packet
  1464. * @exec_ctx: execution context for wmi fw event
  1465. *
  1466. * Event process by below function will be in default caller context.
  1467. * wmi internally provides rx work thread processing context.
  1468. *
  1469. * Return: none
  1470. */
  1471. static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
  1472. HTC_PACKET *htc_packet, uint8_t exec_ctx)
  1473. {
  1474. wmi_buf_t evt_buf;
  1475. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1476. #ifndef CONFIG_MCL
  1477. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
  1478. (wmi_handle->scn_handle, evt_buf, exec_ctx);
  1479. #else
  1480. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
  1481. htc_packet, exec_ctx);
  1482. #endif
  1483. return;
  1484. }
  1485. /**
  1486. * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
  1487. * @wmi_handle: handle to wmi
  1488. * @htc_packet: pointer to htc packet
  1489. *
  1490. * Event process by below function will be in worker thread context.
  1491. * Use this method for events which are not critical and not
  1492. * handled in protocol stack.
  1493. *
  1494. * Return: none
  1495. */
  1496. void wmi_process_fw_event_worker_thread_ctx(struct wmi_unified *wmi_handle,
  1497. HTC_PACKET *htc_packet)
  1498. {
  1499. wmi_buf_t evt_buf;
  1500. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1501. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  1502. qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
  1503. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  1504. qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
  1505. &wmi_handle->rx_event_work);
  1506. return;
  1507. }
  1508. qdf_export_symbol(wmi_process_fw_event_worker_thread_ctx);
  1509. /**
  1510. * wmi_get_pdev_ep: Get wmi handle based on endpoint
  1511. * @soc: handle to wmi soc
  1512. * @ep: endpoint id
  1513. *
  1514. * Return: none
  1515. */
  1516. static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
  1517. HTC_ENDPOINT_ID ep)
  1518. {
  1519. uint32_t i;
  1520. for (i = 0; i < WMI_MAX_RADIOS; i++)
  1521. if (soc->wmi_endpoint_id[i] == ep)
  1522. break;
  1523. if (i == WMI_MAX_RADIOS)
  1524. return NULL;
  1525. return soc->wmi_pdev[i];
  1526. }
  1527. /**
  1528. * wmi_control_rx() - process fw events callbacks
  1529. * @ctx: handle to wmi
  1530. * @htc_packet: pointer to htc packet
  1531. *
  1532. * Return: none
  1533. */
  1534. static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
  1535. {
  1536. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  1537. struct wmi_unified *wmi_handle;
  1538. wmi_buf_t evt_buf;
  1539. uint32_t id;
  1540. uint32_t idx = 0;
  1541. enum wmi_rx_exec_ctx exec_ctx;
  1542. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1543. wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
  1544. if (wmi_handle == NULL) {
  1545. qdf_print
  1546. ("unable to get wmi_handle to Endpoint %d\n",
  1547. htc_packet->Endpoint);
  1548. qdf_nbuf_free(evt_buf);
  1549. return;
  1550. }
  1551. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  1552. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  1553. if (qdf_unlikely(idx == A_ERROR)) {
  1554. WMI_LOGD("%s :event handler is not registered: event id 0x%x\n",
  1555. __func__, id);
  1556. qdf_nbuf_free(evt_buf);
  1557. return;
  1558. }
  1559. qdf_spin_lock_bh(&soc->ctx_lock);
  1560. exec_ctx = wmi_handle->ctx[idx];
  1561. qdf_spin_unlock_bh(&soc->ctx_lock);
  1562. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1563. if (wmi_handle->log_info.wmi_logging_enable) {
  1564. uint8_t *data;
  1565. data = qdf_nbuf_data(evt_buf);
  1566. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1567. /* Exclude 4 bytes of TLV header */
  1568. WMI_RX_EVENT_RECORD(wmi_handle, id, data +
  1569. wmi_handle->log_info.buf_offset_event);
  1570. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1571. }
  1572. #endif
  1573. if (exec_ctx == WMI_RX_WORK_CTX) {
  1574. wmi_process_fw_event_worker_thread_ctx
  1575. (wmi_handle, htc_packet);
  1576. } else if (exec_ctx > WMI_RX_WORK_CTX) {
  1577. wmi_process_fw_event_default_ctx
  1578. (wmi_handle, htc_packet, exec_ctx);
  1579. } else {
  1580. qdf_print("Invalid event context %d", exec_ctx);
  1581. qdf_nbuf_free(evt_buf);
  1582. }
  1583. }
  1584. /**
  1585. * wmi_process_fw_event() - process any fw event
  1586. * @wmi_handle: wmi handle
  1587. * @evt_buf: fw event buffer
  1588. *
  1589. * This function process fw event in caller context
  1590. *
  1591. * Return: none
  1592. */
  1593. void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  1594. {
  1595. __wmi_control_rx(wmi_handle, evt_buf);
  1596. }
  1597. /**
  1598. * __wmi_control_rx() - process serialize wmi event callback
  1599. * @wmi_handle: wmi handle
  1600. * @evt_buf: fw event buffer
  1601. *
  1602. * Return: none
  1603. */
  1604. void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  1605. {
  1606. uint32_t id;
  1607. uint8_t *data;
  1608. uint32_t len;
  1609. void *wmi_cmd_struct_ptr = NULL;
  1610. #ifndef WMI_NON_TLV_SUPPORT
  1611. int tlv_ok_status = 0;
  1612. #endif
  1613. uint32_t idx = 0;
  1614. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  1615. if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
  1616. goto end;
  1617. data = qdf_nbuf_data(evt_buf);
  1618. len = qdf_nbuf_len(evt_buf);
  1619. #ifndef WMI_NON_TLV_SUPPORT
  1620. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  1621. /* Validate and pad(if necessary) the TLVs */
  1622. tlv_ok_status =
  1623. wmi_handle->ops->wmi_check_and_pad_event(wmi_handle->scn_handle,
  1624. data, len, id,
  1625. &wmi_cmd_struct_ptr);
  1626. if (tlv_ok_status != 0) {
  1627. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1628. "%s: Error: id=0x%x, wmitlv check status=%d",
  1629. __func__, id, tlv_ok_status);
  1630. goto end;
  1631. }
  1632. }
  1633. #endif
  1634. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  1635. if (idx == A_ERROR) {
  1636. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1637. "%s : event handler is not registered: event id 0x%x",
  1638. __func__, id);
  1639. goto end;
  1640. }
  1641. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1642. if (wmi_handle->log_info.wmi_logging_enable) {
  1643. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1644. /* Exclude 4 bytes of TLV header */
  1645. if (wmi_handle->ops->is_management_record(id)) {
  1646. WMI_MGMT_EVENT_RECORD(wmi_handle, id, data
  1647. + wmi_handle->log_info.buf_offset_event);
  1648. } else {
  1649. WMI_EVENT_RECORD(wmi_handle, id, data +
  1650. wmi_handle->log_info.buf_offset_event);
  1651. }
  1652. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1653. }
  1654. #endif
  1655. /* Call the WMI registered event handler */
  1656. if (wmi_handle->target_type == WMI_TLV_TARGET)
  1657. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  1658. wmi_cmd_struct_ptr, len);
  1659. else
  1660. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  1661. data, len);
  1662. end:
  1663. /* Free event buffer and allocated event tlv */
  1664. #ifndef WMI_NON_TLV_SUPPORT
  1665. if (wmi_handle->target_type == WMI_TLV_TARGET)
  1666. wmi_handle->ops->wmi_free_allocated_event(id, &wmi_cmd_struct_ptr);
  1667. #endif
  1668. qdf_nbuf_free(evt_buf);
  1669. }
  1670. #define WMI_WQ_WD_TIMEOUT (30 * 1000) /* 30s */
  1671. static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id)
  1672. {
  1673. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  1674. "%s: WLAN_BUG_RCA: Message type %x has exceeded its alloted time of %ds",
  1675. __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000);
  1676. }
  1677. #ifdef CONFIG_SLUB_DEBUG_ON
  1678. static void wmi_workqueue_watchdog_bite(void *arg)
  1679. {
  1680. struct wmi_wq_dbg_info *info = arg;
  1681. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  1682. qdf_print_thread_trace(info->task);
  1683. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  1684. "%s: Going down for WMI WQ Watchdog Bite!", __func__);
  1685. QDF_BUG(0);
  1686. }
  1687. #else
  1688. static inline void wmi_workqueue_watchdog_bite(void *arg)
  1689. {
  1690. struct wmi_wq_dbg_info *info = arg;
  1691. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  1692. }
  1693. #endif
  1694. /**
  1695. * wmi_rx_event_work() - process rx event in rx work queue context
  1696. * @arg: opaque pointer to wmi handle
  1697. *
  1698. * This function process any fw event to serialize it through rx worker thread.
  1699. *
  1700. * Return: none
  1701. */
  1702. static void wmi_rx_event_work(void *arg)
  1703. {
  1704. wmi_buf_t buf;
  1705. struct wmi_unified *wmi = arg;
  1706. qdf_timer_t wd_timer;
  1707. struct wmi_wq_dbg_info info;
  1708. /* initialize WMI workqueue watchdog timer */
  1709. qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite,
  1710. &info, QDF_TIMER_TYPE_SW);
  1711. qdf_spin_lock_bh(&wmi->eventq_lock);
  1712. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  1713. qdf_spin_unlock_bh(&wmi->eventq_lock);
  1714. while (buf) {
  1715. qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT);
  1716. info.wd_msg_type_id =
  1717. WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID);
  1718. info.wmi_wq = wmi->wmi_rx_work_queue;
  1719. info.task = qdf_get_current_task();
  1720. __wmi_control_rx(wmi, buf);
  1721. qdf_timer_stop(&wd_timer);
  1722. qdf_spin_lock_bh(&wmi->eventq_lock);
  1723. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  1724. qdf_spin_unlock_bh(&wmi->eventq_lock);
  1725. }
  1726. qdf_timer_free(&wd_timer);
  1727. }
  1728. #ifdef FEATURE_RUNTIME_PM
  1729. /**
  1730. * wmi_runtime_pm_init() - initialize runtime pm wmi variables
  1731. * @wmi_handle: wmi context
  1732. */
  1733. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  1734. {
  1735. qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
  1736. }
  1737. /**
  1738. * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
  1739. * @wmi_handle: wmi context
  1740. * @val: runtime pm progress flag
  1741. */
  1742. void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
  1743. {
  1744. qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
  1745. }
  1746. /**
  1747. * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
  1748. * @wmi_handle: wmi context
  1749. */
  1750. inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
  1751. {
  1752. return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
  1753. }
  1754. #else
  1755. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  1756. {
  1757. }
  1758. #endif
  1759. /**
  1760. * wmi_unified_get_soc_handle: Get WMI SoC handle
  1761. * @param wmi_handle: WMI context got from wmi_attach
  1762. *
  1763. * return: Pointer to Soc handle
  1764. */
  1765. void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
  1766. {
  1767. return wmi_handle->soc;
  1768. }
  1769. /**
  1770. * wmi_interface_logging_init: Interface looging init
  1771. * @param wmi_handle: Pointer to wmi handle object
  1772. *
  1773. * return: None
  1774. */
  1775. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1776. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
  1777. uint32_t pdev_idx)
  1778. {
  1779. if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
  1780. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  1781. wmi_debugfs_init(wmi_handle, pdev_idx);
  1782. }
  1783. }
  1784. #else
  1785. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
  1786. uint32_t pdev_idx)
  1787. {
  1788. }
  1789. #endif
  1790. /**
  1791. * wmi_target_params_init: Target specific params init
  1792. * @param wmi_soc: Pointer to wmi soc object
  1793. * @param wmi_handle: Pointer to wmi handle object
  1794. *
  1795. * return: None
  1796. */
  1797. #ifndef CONFIG_MCL
  1798. static inline void wmi_target_params_init(struct wmi_soc *soc,
  1799. struct wmi_unified *wmi_handle)
  1800. {
  1801. wmi_handle->pdev_param = soc->pdev_param;
  1802. wmi_handle->vdev_param = soc->vdev_param;
  1803. wmi_handle->services = soc->services;
  1804. }
  1805. #else
  1806. static inline void wmi_target_params_init(struct wmi_soc *soc,
  1807. struct wmi_unified *wmi_handle)
  1808. {
  1809. wmi_handle->services = soc->services;
  1810. }
  1811. #endif
  1812. /**
  1813. * wmi_unified_get_pdev_handle: Get WMI SoC handle
  1814. * @param wmi_soc: Pointer to wmi soc object
  1815. * @param pdev_idx: pdev index
  1816. *
  1817. * return: Pointer to wmi handle or NULL on failure
  1818. */
  1819. void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
  1820. {
  1821. struct wmi_unified *wmi_handle;
  1822. if (pdev_idx >= WMI_MAX_RADIOS)
  1823. return NULL;
  1824. if (soc->wmi_pdev[pdev_idx] == NULL) {
  1825. wmi_handle =
  1826. (struct wmi_unified *) qdf_mem_malloc(
  1827. sizeof(struct wmi_unified));
  1828. if (wmi_handle == NULL) {
  1829. qdf_print("allocation of wmi handle failed %zu",
  1830. sizeof(struct wmi_unified));
  1831. return NULL;
  1832. }
  1833. wmi_handle->scn_handle = soc->scn_handle;
  1834. wmi_handle->event_id = soc->event_id;
  1835. wmi_handle->event_handler = soc->event_handler;
  1836. wmi_handle->ctx = soc->ctx;
  1837. wmi_handle->ops = soc->ops;
  1838. qdf_spinlock_create(&wmi_handle->eventq_lock);
  1839. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  1840. qdf_create_work(0, &wmi_handle->rx_event_work,
  1841. wmi_rx_event_work, wmi_handle);
  1842. wmi_handle->wmi_rx_work_queue =
  1843. qdf_create_workqueue("wmi_rx_event_work_queue");
  1844. if (NULL == wmi_handle->wmi_rx_work_queue) {
  1845. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  1846. goto error;
  1847. }
  1848. wmi_handle->wmi_events = soc->wmi_events;
  1849. wmi_target_params_init(soc, wmi_handle);
  1850. wmi_handle->soc = soc;
  1851. wmi_interface_logging_init(wmi_handle, pdev_idx);
  1852. qdf_atomic_init(&wmi_handle->pending_cmds);
  1853. qdf_atomic_init(&wmi_handle->is_target_suspended);
  1854. wmi_handle->target_type = soc->target_type;
  1855. wmi_handle->wmi_max_cmds = soc->wmi_max_cmds;
  1856. soc->wmi_pdev[pdev_idx] = wmi_handle;
  1857. } else
  1858. wmi_handle = soc->wmi_pdev[pdev_idx];
  1859. wmi_handle->wmi_stopinprogress = 0;
  1860. wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
  1861. wmi_handle->htc_handle = soc->htc_handle;
  1862. wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
  1863. return wmi_handle;
  1864. error:
  1865. qdf_mem_free(wmi_handle);
  1866. return NULL;
  1867. }
  1868. qdf_export_symbol(wmi_unified_get_pdev_handle);
  1869. static void (*wmi_attach_register[WMI_MAX_TARGET_TYPE])(wmi_unified_t);
  1870. void wmi_unified_register_module(enum wmi_target_type target_type,
  1871. void (*wmi_attach)(wmi_unified_t wmi_handle))
  1872. {
  1873. if (target_type < WMI_MAX_TARGET_TYPE)
  1874. wmi_attach_register[target_type] = wmi_attach;
  1875. return;
  1876. }
  1877. qdf_export_symbol(wmi_unified_register_module);
  1878. /**
  1879. * wmi_unified_attach() - attach for unified WMI
  1880. * @scn_handle: handle to SCN
  1881. * @osdev: OS device context
  1882. * @target_type: TLV or not-TLV based target
  1883. * @use_cookie: cookie based allocation enabled/disabled
  1884. * @ops: umac rx callbacks
  1885. * @psoc: objmgr psoc
  1886. *
  1887. * @Return: wmi handle.
  1888. */
  1889. void *wmi_unified_attach(void *scn_handle,
  1890. struct wmi_unified_attach_params *param)
  1891. {
  1892. struct wmi_unified *wmi_handle;
  1893. struct wmi_soc *soc;
  1894. soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
  1895. if (soc == NULL) {
  1896. qdf_print("Allocation of wmi_soc failed %zu",
  1897. sizeof(struct wmi_soc));
  1898. return NULL;
  1899. }
  1900. wmi_handle =
  1901. (struct wmi_unified *) qdf_mem_malloc(
  1902. sizeof(struct wmi_unified));
  1903. if (wmi_handle == NULL) {
  1904. qdf_mem_free(soc);
  1905. qdf_print("allocation of wmi handle failed %zu",
  1906. sizeof(struct wmi_unified));
  1907. return NULL;
  1908. }
  1909. wmi_handle->soc = soc;
  1910. wmi_handle->soc->soc_idx = param->soc_id;
  1911. wmi_handle->event_id = soc->event_id;
  1912. wmi_handle->event_handler = soc->event_handler;
  1913. wmi_handle->ctx = soc->ctx;
  1914. wmi_handle->wmi_events = soc->wmi_events;
  1915. wmi_target_params_init(soc, wmi_handle);
  1916. wmi_handle->scn_handle = scn_handle;
  1917. soc->scn_handle = scn_handle;
  1918. qdf_atomic_init(&wmi_handle->pending_cmds);
  1919. qdf_atomic_init(&wmi_handle->is_target_suspended);
  1920. wmi_runtime_pm_init(wmi_handle);
  1921. qdf_spinlock_create(&wmi_handle->eventq_lock);
  1922. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  1923. qdf_create_work(0, &wmi_handle->rx_event_work,
  1924. wmi_rx_event_work, wmi_handle);
  1925. wmi_handle->wmi_rx_work_queue =
  1926. qdf_create_workqueue("wmi_rx_event_work_queue");
  1927. if (NULL == wmi_handle->wmi_rx_work_queue) {
  1928. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  1929. goto error;
  1930. }
  1931. wmi_interface_logging_init(wmi_handle, WMI_HOST_PDEV_ID_0);
  1932. /* Attach mc_thread context processing function */
  1933. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
  1934. param->rx_ops->wma_process_fw_event_handler_cbk;
  1935. wmi_handle->target_type = param->target_type;
  1936. soc->target_type = param->target_type;
  1937. if (param->target_type >= WMI_MAX_TARGET_TYPE)
  1938. goto error;
  1939. if (wmi_attach_register[param->target_type]) {
  1940. wmi_attach_register[param->target_type](wmi_handle);
  1941. } else {
  1942. WMI_LOGE("wmi attach is not registered");
  1943. goto error;
  1944. }
  1945. /* Assign target cookie capablity */
  1946. wmi_handle->use_cookie = param->use_cookie;
  1947. wmi_handle->osdev = param->osdev;
  1948. wmi_handle->wmi_stopinprogress = 0;
  1949. wmi_handle->wmi_max_cmds = param->max_commands;
  1950. soc->wmi_max_cmds = param->max_commands;
  1951. /* Increase the ref count once refcount infra is present */
  1952. soc->wmi_psoc = param->psoc;
  1953. qdf_spinlock_create(&soc->ctx_lock);
  1954. soc->ops = wmi_handle->ops;
  1955. soc->wmi_pdev[0] = wmi_handle;
  1956. return wmi_handle;
  1957. error:
  1958. qdf_mem_free(soc);
  1959. qdf_mem_free(wmi_handle);
  1960. return NULL;
  1961. }
  1962. /**
  1963. * wmi_unified_detach() - detach for unified WMI
  1964. *
  1965. * @wmi_handle : handle to wmi.
  1966. *
  1967. * @Return: none.
  1968. */
  1969. void wmi_unified_detach(struct wmi_unified *wmi_handle)
  1970. {
  1971. wmi_buf_t buf;
  1972. struct wmi_soc *soc;
  1973. uint8_t i;
  1974. soc = wmi_handle->soc;
  1975. for (i = 0; i < WMI_MAX_RADIOS; i++) {
  1976. if (soc->wmi_pdev[i]) {
  1977. qdf_flush_workqueue(0,
  1978. soc->wmi_pdev[i]->wmi_rx_work_queue);
  1979. qdf_destroy_workqueue(0,
  1980. soc->wmi_pdev[i]->wmi_rx_work_queue);
  1981. wmi_debugfs_remove(soc->wmi_pdev[i]);
  1982. buf = qdf_nbuf_queue_remove(
  1983. &soc->wmi_pdev[i]->event_queue);
  1984. while (buf) {
  1985. qdf_nbuf_free(buf);
  1986. buf = qdf_nbuf_queue_remove(
  1987. &soc->wmi_pdev[i]->event_queue);
  1988. }
  1989. wmi_log_buffer_free(soc->wmi_pdev[i]);
  1990. /* Free events logs list */
  1991. if (soc->wmi_pdev[i]->events_logs_list)
  1992. qdf_mem_free(
  1993. soc->wmi_pdev[i]->events_logs_list);
  1994. qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
  1995. qdf_mem_free(soc->wmi_pdev[i]);
  1996. }
  1997. }
  1998. qdf_spinlock_destroy(&soc->ctx_lock);
  1999. if (soc->wmi_service_bitmap) {
  2000. qdf_mem_free(soc->wmi_service_bitmap);
  2001. soc->wmi_service_bitmap = NULL;
  2002. }
  2003. if (soc->wmi_ext_service_bitmap) {
  2004. qdf_mem_free(soc->wmi_ext_service_bitmap);
  2005. soc->wmi_ext_service_bitmap = NULL;
  2006. }
  2007. /* Decrease the ref count once refcount infra is present */
  2008. soc->wmi_psoc = NULL;
  2009. qdf_mem_free(soc);
  2010. }
  2011. /**
  2012. * wmi_unified_remove_work() - detach for WMI work
  2013. * @wmi_handle: handle to WMI
  2014. *
  2015. * A function that does not fully detach WMI, but just remove work
  2016. * queue items associated with it. This is used to make sure that
  2017. * before any other processing code that may destroy related contexts
  2018. * (HTC, etc), work queue processing on WMI has already been stopped.
  2019. *
  2020. * Return: None
  2021. */
  2022. void
  2023. wmi_unified_remove_work(struct wmi_unified *wmi_handle)
  2024. {
  2025. wmi_buf_t buf;
  2026. qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
  2027. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  2028. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2029. while (buf) {
  2030. qdf_nbuf_free(buf);
  2031. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2032. }
  2033. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  2034. }
  2035. /**
  2036. * wmi_htc_tx_complete() - Process htc tx completion
  2037. *
  2038. * @ctx: handle to wmi
  2039. * @htc_packet: pointer to htc packet
  2040. *
  2041. * @Return: none.
  2042. */
  2043. static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
  2044. {
  2045. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  2046. wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
  2047. u_int8_t *buf_ptr;
  2048. u_int32_t len;
  2049. struct wmi_unified *wmi_handle;
  2050. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2051. uint32_t cmd_id;
  2052. #endif
  2053. ASSERT(wmi_cmd_buf);
  2054. wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
  2055. if (wmi_handle == NULL) {
  2056. WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
  2057. QDF_ASSERT(0);
  2058. return;
  2059. }
  2060. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2061. if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
  2062. cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
  2063. WMI_CMD_HDR, COMMANDID);
  2064. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  2065. /* Record 16 bytes of WMI cmd tx complete data
  2066. - exclude TLV and WMI headers */
  2067. if (wmi_handle->ops->is_management_record(cmd_id)) {
  2068. WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2069. qdf_nbuf_data(wmi_cmd_buf) +
  2070. wmi_handle->log_info.buf_offset_command);
  2071. } else {
  2072. WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2073. qdf_nbuf_data(wmi_cmd_buf) +
  2074. wmi_handle->log_info.buf_offset_command);
  2075. }
  2076. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  2077. }
  2078. #endif
  2079. buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
  2080. len = qdf_nbuf_len(wmi_cmd_buf);
  2081. qdf_mem_zero(buf_ptr, len);
  2082. qdf_nbuf_free(wmi_cmd_buf);
  2083. qdf_mem_free(htc_pkt);
  2084. qdf_atomic_dec(&wmi_handle->pending_cmds);
  2085. }
  2086. /**
  2087. * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
  2088. *
  2089. * @wmi_handle: handle to WMI.
  2090. * @pdev_idx: Pdev index
  2091. *
  2092. * @Return: status.
  2093. */
  2094. static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
  2095. uint32_t pdev_idx)
  2096. {
  2097. int status;
  2098. struct htc_service_connect_resp response;
  2099. struct htc_service_connect_req connect;
  2100. OS_MEMZERO(&connect, sizeof(connect));
  2101. OS_MEMZERO(&response, sizeof(response));
  2102. /* meta data is unused for now */
  2103. connect.pMetaData = NULL;
  2104. connect.MetaDataLength = 0;
  2105. /* these fields are the same for all service endpoints */
  2106. connect.EpCallbacks.pContext = soc;
  2107. connect.EpCallbacks.EpTxCompleteMultiple =
  2108. NULL /* Control path completion ar6000_tx_complete */;
  2109. connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
  2110. connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
  2111. connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
  2112. connect.EpCallbacks.EpTxComplete =
  2113. wmi_htc_tx_complete /* ar6000_tx_queue_full */;
  2114. /* connect to control service */
  2115. connect.service_id = soc->svc_ids[pdev_idx];
  2116. status = htc_connect_service(soc->htc_handle, &connect,
  2117. &response);
  2118. if (status != EOK) {
  2119. qdf_print
  2120. ("Failed to connect to WMI CONTROL service status:%d\n",
  2121. status);
  2122. return status;
  2123. }
  2124. soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
  2125. soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
  2126. return 0;
  2127. }
  2128. /**
  2129. * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
  2130. *
  2131. * @wmi_handle: handle to WMI.
  2132. *
  2133. * @Return: status.
  2134. */
  2135. QDF_STATUS
  2136. wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
  2137. void *htc_handle)
  2138. {
  2139. uint32_t i;
  2140. uint8_t wmi_ep_count;
  2141. wmi_handle->soc->htc_handle = htc_handle;
  2142. wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
  2143. if (wmi_ep_count > WMI_MAX_RADIOS)
  2144. return QDF_STATUS_E_FAULT;
  2145. for (i = 0; i < wmi_ep_count; i++)
  2146. wmi_connect_pdev_htc_service(wmi_handle->soc, i);
  2147. wmi_handle->htc_handle = htc_handle;
  2148. wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
  2149. wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
  2150. return QDF_STATUS_SUCCESS;
  2151. }
  2152. /**
  2153. * wmi_get_host_credits() - WMI API to get updated host_credits
  2154. *
  2155. * @wmi_handle: handle to WMI.
  2156. *
  2157. * @Return: updated host_credits.
  2158. */
  2159. int wmi_get_host_credits(wmi_unified_t wmi_handle)
  2160. {
  2161. int host_credits = 0;
  2162. htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
  2163. &host_credits);
  2164. return host_credits;
  2165. }
  2166. /**
  2167. * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
  2168. * queue
  2169. *
  2170. * @wmi_handle: handle to WMI.
  2171. *
  2172. * @Return: Pending Commands in the HTC queue.
  2173. */
  2174. int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
  2175. {
  2176. return qdf_atomic_read(&wmi_handle->pending_cmds);
  2177. }
  2178. /**
  2179. * wmi_set_target_suspend() - WMI API to set target suspend state
  2180. *
  2181. * @wmi_handle: handle to WMI.
  2182. * @val: suspend state boolean.
  2183. *
  2184. * @Return: none.
  2185. */
  2186. void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
  2187. {
  2188. qdf_atomic_set(&wmi_handle->is_target_suspended, val);
  2189. }
  2190. /**
  2191. * WMI API to set crash injection state
  2192. * @param wmi_handle: handle to WMI.
  2193. * @param val: crash injection state boolean.
  2194. */
  2195. void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
  2196. {
  2197. wmi_handle->tag_crash_inject = flag;
  2198. }
  2199. /**
  2200. * WMI API to set bus suspend state
  2201. * @param wmi_handle: handle to WMI.
  2202. * @param val: suspend state boolean.
  2203. */
  2204. void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
  2205. {
  2206. qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
  2207. }
  2208. void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val)
  2209. {
  2210. wmi_handle->tgt_force_assert_enable = val;
  2211. }
  2212. /**
  2213. * wmi_stop() - generic function to block unified WMI command
  2214. * @wmi_handle: handle to WMI.
  2215. *
  2216. * @Return: success always.
  2217. */
  2218. int
  2219. wmi_stop(wmi_unified_t wmi_handle)
  2220. {
  2221. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  2222. "WMI Stop");
  2223. wmi_handle->wmi_stopinprogress = 1;
  2224. return 0;
  2225. }
  2226. #ifndef CONFIG_MCL
  2227. /**
  2228. * API to flush all the previous packets associated with the wmi endpoint
  2229. *
  2230. * @param wmi_handle : handle to WMI.
  2231. */
  2232. void
  2233. wmi_flush_endpoint(wmi_unified_t wmi_handle)
  2234. {
  2235. htc_flush_endpoint(wmi_handle->htc_handle,
  2236. wmi_handle->wmi_endpoint_id, 0);
  2237. }
  2238. qdf_export_symbol(wmi_flush_endpoint);
  2239. /**
  2240. * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI
  2241. * By default pdev_id conversion is not done in WMI.
  2242. * This API can be used enable conversion in WMI.
  2243. * @param wmi_handle : handle to WMI
  2244. * Return none
  2245. */
  2246. void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle)
  2247. {
  2248. if (wmi_handle->target_type == WMI_TLV_TARGET)
  2249. wmi_handle->ops->wmi_pdev_id_conversion_enable(wmi_handle);
  2250. }
  2251. #endif