wmi_unified.c 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528
  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..\n");
  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..\n");
  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..\n");
  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..\n");
  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..\n");
  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..\n");
  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..\n");
  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\n");\
  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("%s: debug Entry creation failed!\n",
  963. __func__);
  964. goto out;
  965. }
  966. }
  967. return;
  968. out:
  969. qdf_print("%s: debug Entry creation failed!\n", __func__);
  970. wmi_log_buffer_free(wmi_handle);
  971. return;
  972. }
  973. /**
  974. * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
  975. * @wmi_handle: wmi handle
  976. * @dentry: debugfs directory entry
  977. * @id: Index to debug info data array
  978. *
  979. * Return: none
  980. */
  981. static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
  982. {
  983. int i;
  984. struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
  985. if (dentry) {
  986. for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
  987. if (wmi_handle->debugfs_de[i])
  988. wmi_handle->debugfs_de[i] = NULL;
  989. }
  990. }
  991. if (dentry)
  992. debugfs_remove_recursive(dentry);
  993. }
  994. /**
  995. * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
  996. * create debugfs enteries.
  997. *
  998. * @h: wmi handler
  999. *
  1000. * Return: init status
  1001. */
  1002. static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle, uint32_t pdev_idx)
  1003. {
  1004. char buf[32];
  1005. snprintf(buf, sizeof(buf), "WMI_SOC%u_PDEV%u",
  1006. wmi_handle->soc->soc_idx, pdev_idx);
  1007. wmi_handle->log_info.wmi_log_debugfs_dir =
  1008. debugfs_create_dir(buf, NULL);
  1009. if (!wmi_handle->log_info.wmi_log_debugfs_dir) {
  1010. qdf_print("error while creating debugfs dir for %s\n", buf);
  1011. return QDF_STATUS_E_FAILURE;
  1012. }
  1013. wmi_debugfs_create(wmi_handle,
  1014. wmi_handle->log_info.wmi_log_debugfs_dir);
  1015. return QDF_STATUS_SUCCESS;
  1016. }
  1017. /**
  1018. * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
  1019. *
  1020. * @wmi_handle: wmi handle
  1021. * @cmd: mgmt command
  1022. * @header: pointer to 802.11 header
  1023. * @vdev_id: vdev id
  1024. * @chanfreq: channel frequency
  1025. *
  1026. * Return: none
  1027. */
  1028. void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
  1029. void *header, uint32_t vdev_id, uint32_t chanfreq)
  1030. {
  1031. uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
  1032. data[0] = ((struct wmi_command_header *)header)->type;
  1033. data[1] = ((struct wmi_command_header *)header)->sub_type;
  1034. data[2] = vdev_id;
  1035. data[3] = chanfreq;
  1036. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1037. WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, (uint8_t *)data);
  1038. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1039. }
  1040. #else
  1041. /**
  1042. * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
  1043. * @wmi_handle: wmi handle
  1044. * @dentry: debugfs directory entry
  1045. * @id: Index to debug info data array
  1046. *
  1047. * Return: none
  1048. */
  1049. static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
  1050. void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
  1051. void *header, uint32_t vdev_id, uint32_t chanfreq) { }
  1052. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
  1053. #endif /*WMI_INTERFACE_EVENT_LOGGING */
  1054. qdf_export_symbol(wmi_mgmt_cmd_record);
  1055. int wmi_get_host_credits(wmi_unified_t wmi_handle);
  1056. /* WMI buffer APIs */
  1057. #ifdef NBUF_MEMORY_DEBUG
  1058. wmi_buf_t
  1059. wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint32_t len, uint8_t *file_name,
  1060. uint32_t line_num)
  1061. {
  1062. wmi_buf_t wmi_buf;
  1063. if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
  1064. QDF_ASSERT(0);
  1065. return NULL;
  1066. }
  1067. wmi_buf = qdf_nbuf_alloc_debug(NULL,
  1068. roundup(len + WMI_MIN_HEAD_ROOM, 4),
  1069. WMI_MIN_HEAD_ROOM, 4, false, file_name,
  1070. line_num);
  1071. if (!wmi_buf)
  1072. return NULL;
  1073. /* Clear the wmi buffer */
  1074. OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
  1075. /*
  1076. * Set the length of the buffer to match the allocation size.
  1077. */
  1078. qdf_nbuf_set_pktlen(wmi_buf, len);
  1079. return wmi_buf;
  1080. }
  1081. qdf_export_symbol(wmi_buf_alloc_debug);
  1082. void wmi_buf_free(wmi_buf_t net_buf)
  1083. {
  1084. qdf_nbuf_free(net_buf);
  1085. }
  1086. qdf_export_symbol(wmi_buf_free);
  1087. #else
  1088. wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint32_t len)
  1089. {
  1090. wmi_buf_t wmi_buf;
  1091. if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
  1092. QDF_ASSERT(0);
  1093. return NULL;
  1094. }
  1095. wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
  1096. WMI_MIN_HEAD_ROOM, 4, false);
  1097. if (!wmi_buf)
  1098. return NULL;
  1099. /* Clear the wmi buffer */
  1100. OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
  1101. /*
  1102. * Set the length of the buffer to match the allocation size.
  1103. */
  1104. qdf_nbuf_set_pktlen(wmi_buf, len);
  1105. return wmi_buf;
  1106. }
  1107. qdf_export_symbol(wmi_buf_alloc);
  1108. void wmi_buf_free(wmi_buf_t net_buf)
  1109. {
  1110. qdf_nbuf_free(net_buf);
  1111. }
  1112. qdf_export_symbol(wmi_buf_free);
  1113. #endif
  1114. /**
  1115. * wmi_get_max_msg_len() - get maximum WMI message length
  1116. * @wmi_handle: WMI handle.
  1117. *
  1118. * This function returns the maximum WMI message length
  1119. *
  1120. * Return: maximum WMI message length
  1121. */
  1122. uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
  1123. {
  1124. return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
  1125. }
  1126. qdf_export_symbol(wmi_get_max_msg_len);
  1127. #ifndef WMI_CMD_STRINGS
  1128. static uint8_t *wmi_id_to_name(uint32_t wmi_command)
  1129. {
  1130. return "Invalid WMI cmd";
  1131. }
  1132. #endif
  1133. #ifdef CONFIG_MCL
  1134. static inline void wmi_log_cmd_id(uint32_t cmd_id, uint32_t tag)
  1135. {
  1136. WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
  1137. wmi_id_to_name(cmd_id), cmd_id, tag);
  1138. }
  1139. /**
  1140. * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
  1141. * @cmd_id: command to check
  1142. *
  1143. * Return: true if the command is part of the resume sequence.
  1144. */
  1145. static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
  1146. {
  1147. switch (cmd_id) {
  1148. case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
  1149. case WMI_PDEV_RESUME_CMDID:
  1150. return true;
  1151. default:
  1152. return false;
  1153. }
  1154. }
  1155. #else
  1156. static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
  1157. {
  1158. return false;
  1159. }
  1160. #endif
  1161. /**
  1162. * wmi_unified_cmd_send() - WMI command API
  1163. * @wmi_handle: handle to wmi
  1164. * @buf: wmi buf
  1165. * @len: wmi buffer length
  1166. * @cmd_id: wmi command id
  1167. *
  1168. * Note, it is NOT safe to access buf after calling this function!
  1169. *
  1170. * Return: 0 on success
  1171. */
  1172. QDF_STATUS wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf,
  1173. uint32_t len, uint32_t cmd_id)
  1174. {
  1175. HTC_PACKET *pkt;
  1176. QDF_STATUS status;
  1177. uint16_t htc_tag = 0;
  1178. if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
  1179. htc_tag =
  1180. (uint16_t)wmi_handle->ops->wmi_set_htc_tx_tag(
  1181. wmi_handle, buf, cmd_id);
  1182. } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
  1183. (!wmi_is_pm_resume_cmd(cmd_id))) {
  1184. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1185. "%s: Target is suspended", __func__);
  1186. QDF_ASSERT(0);
  1187. return QDF_STATUS_E_BUSY;
  1188. }
  1189. if (wmi_handle->wmi_stopinprogress) {
  1190. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1191. "WMI stop in progress\n");
  1192. return QDF_STATUS_E_INVAL;
  1193. }
  1194. #ifndef WMI_NON_TLV_SUPPORT
  1195. /* Do sanity check on the TLV parameter structure */
  1196. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  1197. void *buf_ptr = (void *)qdf_nbuf_data(buf);
  1198. if (wmi_handle->ops->wmi_check_command_params(NULL, buf_ptr, len, cmd_id)
  1199. != 0) {
  1200. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1201. "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
  1202. __func__, cmd_id);
  1203. return QDF_STATUS_E_INVAL;
  1204. }
  1205. }
  1206. #endif
  1207. if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
  1208. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1209. "%s, Failed to send cmd %x, no memory",
  1210. __func__, cmd_id);
  1211. return QDF_STATUS_E_NOMEM;
  1212. }
  1213. qdf_mem_zero(qdf_nbuf_data(buf), sizeof(WMI_CMD_HDR));
  1214. WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
  1215. qdf_atomic_inc(&wmi_handle->pending_cmds);
  1216. if (qdf_atomic_read(&wmi_handle->pending_cmds) >=
  1217. wmi_handle->wmi_max_cmds) {
  1218. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1219. "\n%s: hostcredits = %d", __func__,
  1220. wmi_get_host_credits(wmi_handle));
  1221. htc_dump_counter_info(wmi_handle->htc_handle);
  1222. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1223. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1224. "%s: MAX %d WMI Pending cmds reached.", __func__,
  1225. wmi_handle->wmi_max_cmds);
  1226. QDF_BUG(0);
  1227. return QDF_STATUS_E_BUSY;
  1228. }
  1229. pkt = qdf_mem_malloc(sizeof(*pkt));
  1230. if (!pkt) {
  1231. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1232. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1233. "%s, Failed to alloc htc packet %x, no memory",
  1234. __func__, cmd_id);
  1235. return QDF_STATUS_E_NOMEM;
  1236. }
  1237. SET_HTC_PACKET_INFO_TX(pkt,
  1238. NULL,
  1239. qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
  1240. wmi_handle->wmi_endpoint_id, htc_tag);
  1241. SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
  1242. #ifdef CONFIG_MCL
  1243. wmi_log_cmd_id(cmd_id, htc_tag);
  1244. #endif
  1245. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1246. if (wmi_handle->log_info.wmi_logging_enable) {
  1247. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1248. /*
  1249. * Record 16 bytes of WMI cmd data -
  1250. * exclude TLV and WMI headers
  1251. *
  1252. * WMI mgmt command already recorded in wmi_mgmt_cmd_record
  1253. */
  1254. if (wmi_handle->ops->is_management_record(cmd_id) == false) {
  1255. WMI_COMMAND_RECORD(wmi_handle, cmd_id,
  1256. qdf_nbuf_data(buf) +
  1257. wmi_handle->log_info.buf_offset_command);
  1258. }
  1259. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1260. }
  1261. #endif
  1262. status = htc_send_pkt(wmi_handle->htc_handle, pkt);
  1263. if (QDF_STATUS_SUCCESS != status) {
  1264. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1265. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1266. "%s %d, htc_send_pkt failed", __func__, __LINE__);
  1267. qdf_mem_free(pkt);
  1268. return status;
  1269. }
  1270. return QDF_STATUS_SUCCESS;
  1271. }
  1272. qdf_export_symbol(wmi_unified_cmd_send);
  1273. /**
  1274. * wmi_unified_get_event_handler_ix() - gives event handler's index
  1275. * @wmi_handle: handle to wmi
  1276. * @event_id: wmi event id
  1277. *
  1278. * Return: event handler's index
  1279. */
  1280. static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
  1281. uint32_t event_id)
  1282. {
  1283. uint32_t idx = 0;
  1284. int32_t invalid_idx = -1;
  1285. struct wmi_soc *soc = wmi_handle->soc;
  1286. for (idx = 0; (idx < soc->max_event_idx &&
  1287. idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
  1288. if (wmi_handle->event_id[idx] == event_id &&
  1289. wmi_handle->event_handler[idx] != NULL) {
  1290. return idx;
  1291. }
  1292. }
  1293. return invalid_idx;
  1294. }
  1295. /**
  1296. * wmi_unified_register_event() - register wmi event handler
  1297. * @wmi_handle: handle to wmi
  1298. * @event_id: wmi event id
  1299. * @handler_func: wmi event handler function
  1300. *
  1301. * Return: 0 on success
  1302. */
  1303. int wmi_unified_register_event(wmi_unified_t wmi_handle,
  1304. uint32_t event_id,
  1305. wmi_unified_event_handler handler_func)
  1306. {
  1307. uint32_t idx = 0;
  1308. uint32_t evt_id;
  1309. struct wmi_soc *soc = wmi_handle->soc;
  1310. if (event_id >= wmi_events_max ||
  1311. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1312. qdf_print("%s: Event id %d is unavailable\n",
  1313. __func__, event_id);
  1314. return QDF_STATUS_E_FAILURE;
  1315. }
  1316. evt_id = wmi_handle->wmi_events[event_id];
  1317. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1318. qdf_print("%s : event handler already registered 0x%x\n",
  1319. __func__, evt_id);
  1320. return QDF_STATUS_E_FAILURE;
  1321. }
  1322. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1323. qdf_print("%s : no more event handlers 0x%x\n",
  1324. __func__, evt_id);
  1325. return QDF_STATUS_E_FAILURE;
  1326. }
  1327. idx = soc->max_event_idx;
  1328. wmi_handle->event_handler[idx] = handler_func;
  1329. wmi_handle->event_id[idx] = evt_id;
  1330. qdf_spin_lock_bh(&soc->ctx_lock);
  1331. wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
  1332. qdf_spin_unlock_bh(&soc->ctx_lock);
  1333. soc->max_event_idx++;
  1334. return 0;
  1335. }
  1336. /**
  1337. * wmi_unified_register_event_handler() - register wmi event handler
  1338. * @wmi_handle: handle to wmi
  1339. * @event_id: wmi event id
  1340. * @handler_func: wmi event handler function
  1341. * @rx_ctx: rx execution context for wmi rx events
  1342. *
  1343. * This API is to support legacy requirements. Will be deprecated in future.
  1344. * Return: 0 on success
  1345. */
  1346. int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
  1347. wmi_conv_event_id event_id,
  1348. wmi_unified_event_handler handler_func,
  1349. uint8_t rx_ctx)
  1350. {
  1351. uint32_t idx = 0;
  1352. uint32_t evt_id;
  1353. struct wmi_soc *soc = wmi_handle->soc;
  1354. if (event_id >= wmi_events_max ||
  1355. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1356. qdf_print("%s: Event id %d is unavailable\n",
  1357. __func__, event_id);
  1358. return QDF_STATUS_E_FAILURE;
  1359. }
  1360. evt_id = wmi_handle->wmi_events[event_id];
  1361. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1362. qdf_print("%s : event handler already registered 0x%x\n",
  1363. __func__, evt_id);
  1364. return QDF_STATUS_E_FAILURE;
  1365. }
  1366. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1367. qdf_print("%s : no more event handlers 0x%x\n",
  1368. __func__, evt_id);
  1369. return QDF_STATUS_E_FAILURE;
  1370. }
  1371. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
  1372. "Registered event handler for event 0x%8x\n", evt_id);
  1373. idx = soc->max_event_idx;
  1374. wmi_handle->event_handler[idx] = handler_func;
  1375. wmi_handle->event_id[idx] = evt_id;
  1376. qdf_spin_lock_bh(&soc->ctx_lock);
  1377. wmi_handle->ctx[idx] = rx_ctx;
  1378. qdf_spin_unlock_bh(&soc->ctx_lock);
  1379. soc->max_event_idx++;
  1380. return 0;
  1381. }
  1382. qdf_export_symbol(wmi_unified_register_event_handler);
  1383. /**
  1384. * wmi_unified_unregister_event() - unregister wmi event handler
  1385. * @wmi_handle: handle to wmi
  1386. * @event_id: wmi event id
  1387. *
  1388. * Return: 0 on success
  1389. */
  1390. int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
  1391. uint32_t event_id)
  1392. {
  1393. uint32_t idx = 0;
  1394. uint32_t evt_id;
  1395. struct wmi_soc *soc = wmi_handle->soc;
  1396. if (event_id >= wmi_events_max ||
  1397. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1398. qdf_print("%s: Event id %d is unavailable\n",
  1399. __func__, event_id);
  1400. return QDF_STATUS_E_FAILURE;
  1401. }
  1402. evt_id = wmi_handle->wmi_events[event_id];
  1403. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1404. if (idx == -1) {
  1405. qdf_print("%s : event handler is not registered: evt id 0x%x\n",
  1406. __func__, evt_id);
  1407. return QDF_STATUS_E_FAILURE;
  1408. }
  1409. wmi_handle->event_handler[idx] = NULL;
  1410. wmi_handle->event_id[idx] = 0;
  1411. --soc->max_event_idx;
  1412. wmi_handle->event_handler[idx] =
  1413. wmi_handle->event_handler[soc->max_event_idx];
  1414. wmi_handle->event_id[idx] =
  1415. wmi_handle->event_id[soc->max_event_idx];
  1416. return 0;
  1417. }
  1418. /**
  1419. * wmi_unified_unregister_event_handler() - unregister wmi event handler
  1420. * @wmi_handle: handle to wmi
  1421. * @event_id: wmi event id
  1422. *
  1423. * Return: 0 on success
  1424. */
  1425. int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
  1426. wmi_conv_event_id event_id)
  1427. {
  1428. uint32_t idx = 0;
  1429. uint32_t evt_id;
  1430. struct wmi_soc *soc = wmi_handle->soc;
  1431. if (event_id >= wmi_events_max ||
  1432. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1433. qdf_print("%s: Event id %d is unavailable\n",
  1434. __func__, event_id);
  1435. return QDF_STATUS_E_FAILURE;
  1436. }
  1437. evt_id = wmi_handle->wmi_events[event_id];
  1438. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1439. if (idx == -1) {
  1440. qdf_print("%s : event handler is not registered: evt id 0x%x\n",
  1441. __func__, evt_id);
  1442. return QDF_STATUS_E_FAILURE;
  1443. }
  1444. wmi_handle->event_handler[idx] = NULL;
  1445. wmi_handle->event_id[idx] = 0;
  1446. --soc->max_event_idx;
  1447. wmi_handle->event_handler[idx] =
  1448. wmi_handle->event_handler[soc->max_event_idx];
  1449. wmi_handle->event_id[idx] =
  1450. wmi_handle->event_id[soc->max_event_idx];
  1451. return 0;
  1452. }
  1453. qdf_export_symbol(wmi_unified_unregister_event_handler);
  1454. /**
  1455. * wmi_process_fw_event_default_ctx() - process in default caller context
  1456. * @wmi_handle: handle to wmi
  1457. * @htc_packet: pointer to htc packet
  1458. * @exec_ctx: execution context for wmi fw event
  1459. *
  1460. * Event process by below function will be in default caller context.
  1461. * wmi internally provides rx work thread processing context.
  1462. *
  1463. * Return: none
  1464. */
  1465. static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
  1466. HTC_PACKET *htc_packet, uint8_t exec_ctx)
  1467. {
  1468. wmi_buf_t evt_buf;
  1469. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1470. #ifndef CONFIG_MCL
  1471. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
  1472. (wmi_handle->scn_handle, evt_buf, exec_ctx);
  1473. #else
  1474. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
  1475. htc_packet, exec_ctx);
  1476. #endif
  1477. return;
  1478. }
  1479. /**
  1480. * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
  1481. * @wmi_handle: handle to wmi
  1482. * @htc_packet: pointer to htc packet
  1483. *
  1484. * Event process by below function will be in worker thread context.
  1485. * Use this method for events which are not critical and not
  1486. * handled in protocol stack.
  1487. *
  1488. * Return: none
  1489. */
  1490. void wmi_process_fw_event_worker_thread_ctx(struct wmi_unified *wmi_handle,
  1491. HTC_PACKET *htc_packet)
  1492. {
  1493. wmi_buf_t evt_buf;
  1494. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1495. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  1496. qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
  1497. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  1498. qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
  1499. &wmi_handle->rx_event_work);
  1500. return;
  1501. }
  1502. qdf_export_symbol(wmi_process_fw_event_worker_thread_ctx);
  1503. /**
  1504. * wmi_get_pdev_ep: Get wmi handle based on endpoint
  1505. * @soc: handle to wmi soc
  1506. * @ep: endpoint id
  1507. *
  1508. * Return: none
  1509. */
  1510. static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
  1511. HTC_ENDPOINT_ID ep)
  1512. {
  1513. uint32_t i;
  1514. for (i = 0; i < WMI_MAX_RADIOS; i++)
  1515. if (soc->wmi_endpoint_id[i] == ep)
  1516. break;
  1517. if (i == WMI_MAX_RADIOS)
  1518. return NULL;
  1519. return soc->wmi_pdev[i];
  1520. }
  1521. /**
  1522. * wmi_control_rx() - process fw events callbacks
  1523. * @ctx: handle to wmi
  1524. * @htc_packet: pointer to htc packet
  1525. *
  1526. * Return: none
  1527. */
  1528. static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
  1529. {
  1530. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  1531. struct wmi_unified *wmi_handle;
  1532. wmi_buf_t evt_buf;
  1533. uint32_t id;
  1534. uint32_t idx = 0;
  1535. enum wmi_rx_exec_ctx exec_ctx;
  1536. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1537. wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
  1538. if (wmi_handle == NULL) {
  1539. qdf_print
  1540. ("%s :unable to get wmi_handle to Endpoint %d\n",
  1541. __func__, htc_packet->Endpoint);
  1542. qdf_nbuf_free(evt_buf);
  1543. return;
  1544. }
  1545. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  1546. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  1547. if (qdf_unlikely(idx == A_ERROR)) {
  1548. WMI_LOGD("%s :event handler is not registered: event id 0x%x\n",
  1549. __func__, id);
  1550. qdf_nbuf_free(evt_buf);
  1551. return;
  1552. }
  1553. qdf_spin_lock_bh(&soc->ctx_lock);
  1554. exec_ctx = wmi_handle->ctx[idx];
  1555. qdf_spin_unlock_bh(&soc->ctx_lock);
  1556. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1557. if (wmi_handle->log_info.wmi_logging_enable) {
  1558. uint8_t *data;
  1559. data = qdf_nbuf_data(evt_buf);
  1560. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1561. /* Exclude 4 bytes of TLV header */
  1562. WMI_RX_EVENT_RECORD(wmi_handle, id, data +
  1563. wmi_handle->log_info.buf_offset_event);
  1564. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1565. }
  1566. #endif
  1567. if (exec_ctx == WMI_RX_WORK_CTX) {
  1568. wmi_process_fw_event_worker_thread_ctx
  1569. (wmi_handle, htc_packet);
  1570. } else if (exec_ctx > WMI_RX_WORK_CTX) {
  1571. wmi_process_fw_event_default_ctx
  1572. (wmi_handle, htc_packet, exec_ctx);
  1573. } else {
  1574. qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
  1575. qdf_nbuf_free(evt_buf);
  1576. }
  1577. }
  1578. /**
  1579. * wmi_process_fw_event() - process any fw event
  1580. * @wmi_handle: wmi handle
  1581. * @evt_buf: fw event buffer
  1582. *
  1583. * This function process fw event in caller context
  1584. *
  1585. * Return: none
  1586. */
  1587. void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  1588. {
  1589. __wmi_control_rx(wmi_handle, evt_buf);
  1590. }
  1591. /**
  1592. * __wmi_control_rx() - process serialize wmi event callback
  1593. * @wmi_handle: wmi handle
  1594. * @evt_buf: fw event buffer
  1595. *
  1596. * Return: none
  1597. */
  1598. void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  1599. {
  1600. uint32_t id;
  1601. uint8_t *data;
  1602. uint32_t len;
  1603. void *wmi_cmd_struct_ptr = NULL;
  1604. #ifndef WMI_NON_TLV_SUPPORT
  1605. int tlv_ok_status = 0;
  1606. #endif
  1607. uint32_t idx = 0;
  1608. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  1609. if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
  1610. goto end;
  1611. data = qdf_nbuf_data(evt_buf);
  1612. len = qdf_nbuf_len(evt_buf);
  1613. #ifndef WMI_NON_TLV_SUPPORT
  1614. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  1615. /* Validate and pad(if necessary) the TLVs */
  1616. tlv_ok_status =
  1617. wmi_handle->ops->wmi_check_and_pad_event(wmi_handle->scn_handle,
  1618. data, len, id,
  1619. &wmi_cmd_struct_ptr);
  1620. if (tlv_ok_status != 0) {
  1621. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1622. "%s: Error: id=0x%d, wmitlv check status=%d\n",
  1623. __func__, id, tlv_ok_status);
  1624. goto end;
  1625. }
  1626. }
  1627. #endif
  1628. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  1629. if (idx == A_ERROR) {
  1630. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1631. "%s : event handler is not registered: event id 0x%x\n",
  1632. __func__, id);
  1633. goto end;
  1634. }
  1635. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1636. if (wmi_handle->log_info.wmi_logging_enable) {
  1637. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1638. /* Exclude 4 bytes of TLV header */
  1639. if (wmi_handle->ops->is_management_record(id)) {
  1640. WMI_MGMT_EVENT_RECORD(wmi_handle, id, data
  1641. + wmi_handle->log_info.buf_offset_event);
  1642. } else {
  1643. WMI_EVENT_RECORD(wmi_handle, id, data +
  1644. wmi_handle->log_info.buf_offset_event);
  1645. }
  1646. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1647. }
  1648. #endif
  1649. /* Call the WMI registered event handler */
  1650. if (wmi_handle->target_type == WMI_TLV_TARGET)
  1651. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  1652. wmi_cmd_struct_ptr, len);
  1653. else
  1654. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  1655. data, len);
  1656. end:
  1657. /* Free event buffer and allocated event tlv */
  1658. #ifndef WMI_NON_TLV_SUPPORT
  1659. if (wmi_handle->target_type == WMI_TLV_TARGET)
  1660. wmi_handle->ops->wmi_free_allocated_event(id, &wmi_cmd_struct_ptr);
  1661. #endif
  1662. qdf_nbuf_free(evt_buf);
  1663. }
  1664. #define WMI_WQ_WD_TIMEOUT (30 * 1000) /* 30s */
  1665. static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id)
  1666. {
  1667. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  1668. "%s: WLAN_BUG_RCA: Message type %x has exceeded its alloted time of %ds",
  1669. __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000);
  1670. }
  1671. #ifdef CONFIG_SLUB_DEBUG_ON
  1672. static void wmi_workqueue_watchdog_bite(void *arg)
  1673. {
  1674. struct wmi_wq_dbg_info *info = arg;
  1675. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  1676. qdf_print_thread_trace(info->task);
  1677. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  1678. "%s: Going down for WMI WQ Watchdog Bite!", __func__);
  1679. QDF_BUG(0);
  1680. }
  1681. #else
  1682. static inline void wmi_workqueue_watchdog_bite(void *arg)
  1683. {
  1684. struct wmi_wq_dbg_info *info = arg;
  1685. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  1686. }
  1687. #endif
  1688. /**
  1689. * wmi_rx_event_work() - process rx event in rx work queue context
  1690. * @arg: opaque pointer to wmi handle
  1691. *
  1692. * This function process any fw event to serialize it through rx worker thread.
  1693. *
  1694. * Return: none
  1695. */
  1696. static void wmi_rx_event_work(void *arg)
  1697. {
  1698. wmi_buf_t buf;
  1699. struct wmi_unified *wmi = arg;
  1700. qdf_timer_t wd_timer;
  1701. struct wmi_wq_dbg_info info;
  1702. /* initialize WMI workqueue watchdog timer */
  1703. qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite,
  1704. &info, QDF_TIMER_TYPE_SW);
  1705. qdf_spin_lock_bh(&wmi->eventq_lock);
  1706. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  1707. qdf_spin_unlock_bh(&wmi->eventq_lock);
  1708. while (buf) {
  1709. qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT);
  1710. info.wd_msg_type_id =
  1711. WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID);
  1712. info.wmi_wq = wmi->wmi_rx_work_queue;
  1713. info.task = qdf_get_current_task();
  1714. __wmi_control_rx(wmi, buf);
  1715. qdf_timer_stop(&wd_timer);
  1716. qdf_spin_lock_bh(&wmi->eventq_lock);
  1717. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  1718. qdf_spin_unlock_bh(&wmi->eventq_lock);
  1719. }
  1720. qdf_timer_free(&wd_timer);
  1721. }
  1722. #ifdef FEATURE_RUNTIME_PM
  1723. /**
  1724. * wmi_runtime_pm_init() - initialize runtime pm wmi variables
  1725. * @wmi_handle: wmi context
  1726. */
  1727. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  1728. {
  1729. qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
  1730. }
  1731. /**
  1732. * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
  1733. * @wmi_handle: wmi context
  1734. * @val: runtime pm progress flag
  1735. */
  1736. void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
  1737. {
  1738. qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
  1739. }
  1740. /**
  1741. * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
  1742. * @wmi_handle: wmi context
  1743. */
  1744. inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
  1745. {
  1746. return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
  1747. }
  1748. #else
  1749. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  1750. {
  1751. }
  1752. #endif
  1753. /**
  1754. * wmi_unified_get_soc_handle: Get WMI SoC handle
  1755. * @param wmi_handle: WMI context got from wmi_attach
  1756. *
  1757. * return: Pointer to Soc handle
  1758. */
  1759. void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
  1760. {
  1761. return wmi_handle->soc;
  1762. }
  1763. /**
  1764. * wmi_interface_logging_init: Interface looging init
  1765. * @param wmi_handle: Pointer to wmi handle object
  1766. *
  1767. * return: None
  1768. */
  1769. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1770. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
  1771. uint32_t pdev_idx)
  1772. {
  1773. if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
  1774. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  1775. wmi_debugfs_init(wmi_handle, pdev_idx);
  1776. }
  1777. }
  1778. #else
  1779. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
  1780. uint32_t pdev_idx)
  1781. {
  1782. }
  1783. #endif
  1784. /**
  1785. * wmi_target_params_init: Target specific params init
  1786. * @param wmi_soc: Pointer to wmi soc object
  1787. * @param wmi_handle: Pointer to wmi handle object
  1788. *
  1789. * return: None
  1790. */
  1791. #ifndef CONFIG_MCL
  1792. static inline void wmi_target_params_init(struct wmi_soc *soc,
  1793. struct wmi_unified *wmi_handle)
  1794. {
  1795. wmi_handle->pdev_param = soc->pdev_param;
  1796. wmi_handle->vdev_param = soc->vdev_param;
  1797. wmi_handle->services = soc->services;
  1798. }
  1799. #else
  1800. static inline void wmi_target_params_init(struct wmi_soc *soc,
  1801. struct wmi_unified *wmi_handle)
  1802. {
  1803. wmi_handle->services = soc->services;
  1804. }
  1805. #endif
  1806. /**
  1807. * wmi_unified_get_pdev_handle: Get WMI SoC handle
  1808. * @param wmi_soc: Pointer to wmi soc object
  1809. * @param pdev_idx: pdev index
  1810. *
  1811. * return: Pointer to wmi handle or NULL on failure
  1812. */
  1813. void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
  1814. {
  1815. struct wmi_unified *wmi_handle;
  1816. if (pdev_idx >= WMI_MAX_RADIOS)
  1817. return NULL;
  1818. if (soc->wmi_pdev[pdev_idx] == NULL) {
  1819. wmi_handle =
  1820. (struct wmi_unified *) qdf_mem_malloc(
  1821. sizeof(struct wmi_unified));
  1822. if (wmi_handle == NULL) {
  1823. qdf_print("allocation of wmi handle failed %zu\n",
  1824. sizeof(struct wmi_unified));
  1825. return NULL;
  1826. }
  1827. wmi_handle->scn_handle = soc->scn_handle;
  1828. wmi_handle->event_id = soc->event_id;
  1829. wmi_handle->event_handler = soc->event_handler;
  1830. wmi_handle->ctx = soc->ctx;
  1831. wmi_handle->ops = soc->ops;
  1832. qdf_spinlock_create(&wmi_handle->eventq_lock);
  1833. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  1834. qdf_create_work(0, &wmi_handle->rx_event_work,
  1835. wmi_rx_event_work, wmi_handle);
  1836. wmi_handle->wmi_rx_work_queue =
  1837. qdf_create_workqueue("wmi_rx_event_work_queue");
  1838. if (NULL == wmi_handle->wmi_rx_work_queue) {
  1839. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  1840. goto error;
  1841. }
  1842. wmi_handle->wmi_events = soc->wmi_events;
  1843. wmi_target_params_init(soc, wmi_handle);
  1844. wmi_handle->soc = soc;
  1845. wmi_interface_logging_init(wmi_handle, pdev_idx);
  1846. qdf_atomic_init(&wmi_handle->pending_cmds);
  1847. qdf_atomic_init(&wmi_handle->is_target_suspended);
  1848. wmi_handle->target_type = soc->target_type;
  1849. wmi_handle->wmi_max_cmds = soc->wmi_max_cmds;
  1850. soc->wmi_pdev[pdev_idx] = wmi_handle;
  1851. } else
  1852. wmi_handle = soc->wmi_pdev[pdev_idx];
  1853. wmi_handle->wmi_stopinprogress = 0;
  1854. wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
  1855. wmi_handle->htc_handle = soc->htc_handle;
  1856. wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
  1857. return wmi_handle;
  1858. error:
  1859. qdf_mem_free(wmi_handle);
  1860. return NULL;
  1861. }
  1862. qdf_export_symbol(wmi_unified_get_pdev_handle);
  1863. static void (*wmi_attach_register[WMI_MAX_TARGET_TYPE])(wmi_unified_t);
  1864. void wmi_unified_register_module(enum wmi_target_type target_type,
  1865. void (*wmi_attach)(wmi_unified_t wmi_handle))
  1866. {
  1867. if (target_type < WMI_MAX_TARGET_TYPE)
  1868. wmi_attach_register[target_type] = wmi_attach;
  1869. return;
  1870. }
  1871. qdf_export_symbol(wmi_unified_register_module);
  1872. /**
  1873. * wmi_unified_attach() - attach for unified WMI
  1874. * @scn_handle: handle to SCN
  1875. * @osdev: OS device context
  1876. * @target_type: TLV or not-TLV based target
  1877. * @use_cookie: cookie based allocation enabled/disabled
  1878. * @ops: umac rx callbacks
  1879. * @psoc: objmgr psoc
  1880. *
  1881. * @Return: wmi handle.
  1882. */
  1883. void *wmi_unified_attach(void *scn_handle,
  1884. struct wmi_unified_attach_params *param)
  1885. {
  1886. struct wmi_unified *wmi_handle;
  1887. struct wmi_soc *soc;
  1888. soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
  1889. if (soc == NULL) {
  1890. qdf_print("Allocation of wmi_soc failed %zu\n",
  1891. sizeof(struct wmi_soc));
  1892. return NULL;
  1893. }
  1894. wmi_handle =
  1895. (struct wmi_unified *) qdf_mem_malloc(
  1896. sizeof(struct wmi_unified));
  1897. if (wmi_handle == NULL) {
  1898. qdf_mem_free(soc);
  1899. qdf_print("allocation of wmi handle failed %zu\n",
  1900. sizeof(struct wmi_unified));
  1901. return NULL;
  1902. }
  1903. wmi_handle->soc = soc;
  1904. wmi_handle->soc->soc_idx = param->soc_id;
  1905. wmi_handle->event_id = soc->event_id;
  1906. wmi_handle->event_handler = soc->event_handler;
  1907. wmi_handle->ctx = soc->ctx;
  1908. wmi_handle->wmi_events = soc->wmi_events;
  1909. wmi_target_params_init(soc, wmi_handle);
  1910. wmi_handle->scn_handle = scn_handle;
  1911. soc->scn_handle = scn_handle;
  1912. qdf_atomic_init(&wmi_handle->pending_cmds);
  1913. qdf_atomic_init(&wmi_handle->is_target_suspended);
  1914. wmi_runtime_pm_init(wmi_handle);
  1915. qdf_spinlock_create(&wmi_handle->eventq_lock);
  1916. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  1917. qdf_create_work(0, &wmi_handle->rx_event_work,
  1918. wmi_rx_event_work, wmi_handle);
  1919. wmi_handle->wmi_rx_work_queue =
  1920. qdf_create_workqueue("wmi_rx_event_work_queue");
  1921. if (NULL == wmi_handle->wmi_rx_work_queue) {
  1922. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  1923. goto error;
  1924. }
  1925. wmi_interface_logging_init(wmi_handle, WMI_HOST_PDEV_ID_0);
  1926. /* Attach mc_thread context processing function */
  1927. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
  1928. param->rx_ops->wma_process_fw_event_handler_cbk;
  1929. wmi_handle->target_type = param->target_type;
  1930. soc->target_type = param->target_type;
  1931. if (param->target_type >= WMI_MAX_TARGET_TYPE)
  1932. goto error;
  1933. if (wmi_attach_register[param->target_type]) {
  1934. wmi_attach_register[param->target_type](wmi_handle);
  1935. } else {
  1936. WMI_LOGE("wmi attach is not registered");
  1937. goto error;
  1938. }
  1939. /* Assign target cookie capablity */
  1940. wmi_handle->use_cookie = param->use_cookie;
  1941. wmi_handle->osdev = param->osdev;
  1942. wmi_handle->wmi_stopinprogress = 0;
  1943. wmi_handle->wmi_max_cmds = param->max_commands;
  1944. soc->wmi_max_cmds = param->max_commands;
  1945. /* Increase the ref count once refcount infra is present */
  1946. soc->wmi_psoc = param->psoc;
  1947. qdf_spinlock_create(&soc->ctx_lock);
  1948. soc->ops = wmi_handle->ops;
  1949. soc->wmi_pdev[0] = wmi_handle;
  1950. return wmi_handle;
  1951. error:
  1952. qdf_mem_free(soc);
  1953. qdf_mem_free(wmi_handle);
  1954. return NULL;
  1955. }
  1956. /**
  1957. * wmi_unified_detach() - detach for unified WMI
  1958. *
  1959. * @wmi_handle : handle to wmi.
  1960. *
  1961. * @Return: none.
  1962. */
  1963. void wmi_unified_detach(struct wmi_unified *wmi_handle)
  1964. {
  1965. wmi_buf_t buf;
  1966. struct wmi_soc *soc;
  1967. uint8_t i;
  1968. soc = wmi_handle->soc;
  1969. for (i = 0; i < WMI_MAX_RADIOS; i++) {
  1970. if (soc->wmi_pdev[i]) {
  1971. qdf_flush_workqueue(0,
  1972. soc->wmi_pdev[i]->wmi_rx_work_queue);
  1973. qdf_destroy_workqueue(0,
  1974. soc->wmi_pdev[i]->wmi_rx_work_queue);
  1975. wmi_debugfs_remove(soc->wmi_pdev[i]);
  1976. buf = qdf_nbuf_queue_remove(
  1977. &soc->wmi_pdev[i]->event_queue);
  1978. while (buf) {
  1979. qdf_nbuf_free(buf);
  1980. buf = qdf_nbuf_queue_remove(
  1981. &soc->wmi_pdev[i]->event_queue);
  1982. }
  1983. wmi_log_buffer_free(soc->wmi_pdev[i]);
  1984. /* Free events logs list */
  1985. if (soc->wmi_pdev[i]->events_logs_list)
  1986. qdf_mem_free(
  1987. soc->wmi_pdev[i]->events_logs_list);
  1988. qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
  1989. qdf_mem_free(soc->wmi_pdev[i]);
  1990. }
  1991. }
  1992. qdf_spinlock_destroy(&soc->ctx_lock);
  1993. if (soc->wmi_service_bitmap) {
  1994. qdf_mem_free(soc->wmi_service_bitmap);
  1995. soc->wmi_service_bitmap = NULL;
  1996. }
  1997. if (soc->wmi_ext_service_bitmap) {
  1998. qdf_mem_free(soc->wmi_ext_service_bitmap);
  1999. soc->wmi_ext_service_bitmap = NULL;
  2000. }
  2001. /* Decrease the ref count once refcount infra is present */
  2002. soc->wmi_psoc = NULL;
  2003. qdf_mem_free(soc);
  2004. }
  2005. /**
  2006. * wmi_unified_remove_work() - detach for WMI work
  2007. * @wmi_handle: handle to WMI
  2008. *
  2009. * A function that does not fully detach WMI, but just remove work
  2010. * queue items associated with it. This is used to make sure that
  2011. * before any other processing code that may destroy related contexts
  2012. * (HTC, etc), work queue processing on WMI has already been stopped.
  2013. *
  2014. * Return: None
  2015. */
  2016. void
  2017. wmi_unified_remove_work(struct wmi_unified *wmi_handle)
  2018. {
  2019. wmi_buf_t buf;
  2020. qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
  2021. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  2022. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2023. while (buf) {
  2024. qdf_nbuf_free(buf);
  2025. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2026. }
  2027. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  2028. }
  2029. /**
  2030. * wmi_htc_tx_complete() - Process htc tx completion
  2031. *
  2032. * @ctx: handle to wmi
  2033. * @htc_packet: pointer to htc packet
  2034. *
  2035. * @Return: none.
  2036. */
  2037. static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
  2038. {
  2039. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  2040. wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
  2041. u_int8_t *buf_ptr;
  2042. u_int32_t len;
  2043. struct wmi_unified *wmi_handle;
  2044. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2045. uint32_t cmd_id;
  2046. #endif
  2047. ASSERT(wmi_cmd_buf);
  2048. wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
  2049. if (wmi_handle == NULL) {
  2050. WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
  2051. QDF_ASSERT(0);
  2052. return;
  2053. }
  2054. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2055. if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
  2056. cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
  2057. WMI_CMD_HDR, COMMANDID);
  2058. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  2059. /* Record 16 bytes of WMI cmd tx complete data
  2060. - exclude TLV and WMI headers */
  2061. if (wmi_handle->ops->is_management_record(cmd_id)) {
  2062. WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2063. qdf_nbuf_data(wmi_cmd_buf) +
  2064. wmi_handle->log_info.buf_offset_command);
  2065. } else {
  2066. WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2067. qdf_nbuf_data(wmi_cmd_buf) +
  2068. wmi_handle->log_info.buf_offset_command);
  2069. }
  2070. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  2071. }
  2072. #endif
  2073. buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
  2074. len = qdf_nbuf_len(wmi_cmd_buf);
  2075. qdf_mem_zero(buf_ptr, len);
  2076. qdf_nbuf_free(wmi_cmd_buf);
  2077. qdf_mem_free(htc_pkt);
  2078. qdf_atomic_dec(&wmi_handle->pending_cmds);
  2079. }
  2080. /**
  2081. * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
  2082. *
  2083. * @wmi_handle: handle to WMI.
  2084. * @pdev_idx: Pdev index
  2085. *
  2086. * @Return: status.
  2087. */
  2088. static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
  2089. uint32_t pdev_idx)
  2090. {
  2091. int status;
  2092. struct htc_service_connect_resp response;
  2093. struct htc_service_connect_req connect;
  2094. OS_MEMZERO(&connect, sizeof(connect));
  2095. OS_MEMZERO(&response, sizeof(response));
  2096. /* meta data is unused for now */
  2097. connect.pMetaData = NULL;
  2098. connect.MetaDataLength = 0;
  2099. /* these fields are the same for all service endpoints */
  2100. connect.EpCallbacks.pContext = soc;
  2101. connect.EpCallbacks.EpTxCompleteMultiple =
  2102. NULL /* Control path completion ar6000_tx_complete */;
  2103. connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
  2104. connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
  2105. connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
  2106. connect.EpCallbacks.EpTxComplete =
  2107. wmi_htc_tx_complete /* ar6000_tx_queue_full */;
  2108. /* connect to control service */
  2109. connect.service_id = soc->svc_ids[pdev_idx];
  2110. status = htc_connect_service(soc->htc_handle, &connect,
  2111. &response);
  2112. if (status != EOK) {
  2113. qdf_print
  2114. ("Failed to connect to WMI CONTROL service status:%d\n",
  2115. status);
  2116. return status;
  2117. }
  2118. soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
  2119. soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
  2120. return 0;
  2121. }
  2122. /**
  2123. * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
  2124. *
  2125. * @wmi_handle: handle to WMI.
  2126. *
  2127. * @Return: status.
  2128. */
  2129. QDF_STATUS
  2130. wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
  2131. void *htc_handle)
  2132. {
  2133. uint32_t i;
  2134. uint8_t wmi_ep_count;
  2135. wmi_handle->soc->htc_handle = htc_handle;
  2136. wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
  2137. if (wmi_ep_count > WMI_MAX_RADIOS)
  2138. return QDF_STATUS_E_FAULT;
  2139. for (i = 0; i < wmi_ep_count; i++)
  2140. wmi_connect_pdev_htc_service(wmi_handle->soc, i);
  2141. wmi_handle->htc_handle = htc_handle;
  2142. wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
  2143. wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
  2144. return QDF_STATUS_SUCCESS;
  2145. }
  2146. /**
  2147. * wmi_get_host_credits() - WMI API to get updated host_credits
  2148. *
  2149. * @wmi_handle: handle to WMI.
  2150. *
  2151. * @Return: updated host_credits.
  2152. */
  2153. int wmi_get_host_credits(wmi_unified_t wmi_handle)
  2154. {
  2155. int host_credits = 0;
  2156. htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
  2157. &host_credits);
  2158. return host_credits;
  2159. }
  2160. /**
  2161. * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
  2162. * queue
  2163. *
  2164. * @wmi_handle: handle to WMI.
  2165. *
  2166. * @Return: Pending Commands in the HTC queue.
  2167. */
  2168. int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
  2169. {
  2170. return qdf_atomic_read(&wmi_handle->pending_cmds);
  2171. }
  2172. /**
  2173. * wmi_set_target_suspend() - WMI API to set target suspend state
  2174. *
  2175. * @wmi_handle: handle to WMI.
  2176. * @val: suspend state boolean.
  2177. *
  2178. * @Return: none.
  2179. */
  2180. void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
  2181. {
  2182. qdf_atomic_set(&wmi_handle->is_target_suspended, val);
  2183. }
  2184. /**
  2185. * WMI API to set crash injection state
  2186. * @param wmi_handle: handle to WMI.
  2187. * @param val: crash injection state boolean.
  2188. */
  2189. void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
  2190. {
  2191. wmi_handle->tag_crash_inject = flag;
  2192. }
  2193. /**
  2194. * WMI API to set bus suspend state
  2195. * @param wmi_handle: handle to WMI.
  2196. * @param val: suspend state boolean.
  2197. */
  2198. void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
  2199. {
  2200. qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
  2201. }
  2202. void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val)
  2203. {
  2204. wmi_handle->tgt_force_assert_enable = val;
  2205. }
  2206. /**
  2207. * wmi_stop() - generic function to block unified WMI command
  2208. * @wmi_handle: handle to WMI.
  2209. *
  2210. * @Return: success always.
  2211. */
  2212. int
  2213. wmi_stop(wmi_unified_t wmi_handle)
  2214. {
  2215. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  2216. "WMI Stop\n");
  2217. wmi_handle->wmi_stopinprogress = 1;
  2218. return 0;
  2219. }
  2220. #ifndef CONFIG_MCL
  2221. /**
  2222. * API to flush all the previous packets associated with the wmi endpoint
  2223. *
  2224. * @param wmi_handle : handle to WMI.
  2225. */
  2226. void
  2227. wmi_flush_endpoint(wmi_unified_t wmi_handle)
  2228. {
  2229. htc_flush_endpoint(wmi_handle->htc_handle,
  2230. wmi_handle->wmi_endpoint_id, 0);
  2231. }
  2232. qdf_export_symbol(wmi_flush_endpoint);
  2233. /**
  2234. * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI
  2235. * By default pdev_id conversion is not done in WMI.
  2236. * This API can be used enable conversion in WMI.
  2237. * @param wmi_handle : handle to WMI
  2238. * Return none
  2239. */
  2240. void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle)
  2241. {
  2242. if (wmi_handle->target_type == WMI_TLV_TARGET)
  2243. wmi_handle->ops->wmi_pdev_id_conversion_enable(wmi_handle);
  2244. }
  2245. #endif