wmi_unified.c 72 KB

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