wmi_unified.c 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524
  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. uint64_t secs, usecs; \
  661. \
  662. qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
  663. if (!wmi_log->length) { \
  664. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
  665. return wmi_bp_seq_printf(m, \
  666. "no elements to read from ring buffer!\n"); \
  667. } \
  668. \
  669. if (wmi_log->length <= wmi_ring_size) \
  670. nread = wmi_log->length; \
  671. else \
  672. nread = wmi_ring_size; \
  673. \
  674. if (*(wmi_log->p_buf_tail_idx) == 0) \
  675. /* tail can be 0 after wrap-around */ \
  676. pos = wmi_ring_size - 1; \
  677. else \
  678. pos = *(wmi_log->p_buf_tail_idx) - 1; \
  679. \
  680. outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
  681. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
  682. while (nread--) { \
  683. struct wmi_command_debug *wmi_record; \
  684. \
  685. wmi_record = (struct wmi_command_debug *) \
  686. &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
  687. outlen += wmi_bp_seq_printf(m, "CMD ID = %x\n", \
  688. (wmi_record->command)); \
  689. qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
  690. &usecs); \
  691. outlen += \
  692. wmi_bp_seq_printf(m, "CMD TIME = [%llu.%06llu]\n",\
  693. secs, usecs); \
  694. outlen += wmi_bp_seq_printf(m, "CMD = "); \
  695. for (i = 0; i < (wmi_record_max_length/ \
  696. sizeof(uint32_t)); i++) \
  697. outlen += wmi_bp_seq_printf(m, "%x ", \
  698. wmi_record->data[i]); \
  699. outlen += wmi_bp_seq_printf(m, "\n"); \
  700. \
  701. if (pos == 0) \
  702. pos = wmi_ring_size - 1; \
  703. else \
  704. pos--; \
  705. } \
  706. return outlen; \
  707. } \
  708. #define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
  709. static int debug_wmi_##func_base##_show(struct seq_file *m, \
  710. void *v) \
  711. { \
  712. wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
  713. struct wmi_log_buf_t *wmi_log = \
  714. &wmi_handle->log_info.wmi_##func_base##_buf_info;\
  715. int pos, nread, outlen; \
  716. int i; \
  717. uint64_t secs, usecs; \
  718. \
  719. qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
  720. if (!wmi_log->length) { \
  721. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock);\
  722. return wmi_bp_seq_printf(m, \
  723. "no elements to read from ring buffer!\n"); \
  724. } \
  725. \
  726. if (wmi_log->length <= wmi_ring_size) \
  727. nread = wmi_log->length; \
  728. else \
  729. nread = wmi_ring_size; \
  730. \
  731. if (*(wmi_log->p_buf_tail_idx) == 0) \
  732. /* tail can be 0 after wrap-around */ \
  733. pos = wmi_ring_size - 1; \
  734. else \
  735. pos = *(wmi_log->p_buf_tail_idx) - 1; \
  736. \
  737. outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
  738. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
  739. while (nread--) { \
  740. struct wmi_event_debug *wmi_record; \
  741. \
  742. wmi_record = (struct wmi_event_debug *) \
  743. &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
  744. qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
  745. &usecs); \
  746. outlen += wmi_bp_seq_printf(m, "Event ID = %x\n",\
  747. (wmi_record->event)); \
  748. outlen += \
  749. wmi_bp_seq_printf(m, "Event TIME = [%llu.%06llu]\n",\
  750. secs, usecs); \
  751. outlen += wmi_bp_seq_printf(m, "CMD = "); \
  752. for (i = 0; i < (wmi_record_max_length/ \
  753. sizeof(uint32_t)); i++) \
  754. outlen += wmi_bp_seq_printf(m, "%x ", \
  755. wmi_record->data[i]); \
  756. outlen += wmi_bp_seq_printf(m, "\n"); \
  757. \
  758. if (pos == 0) \
  759. pos = wmi_ring_size - 1; \
  760. else \
  761. pos--; \
  762. } \
  763. return outlen; \
  764. }
  765. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
  766. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
  767. GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
  768. GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
  769. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
  770. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
  771. wmi_display_size);
  772. GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
  773. /**
  774. * debug_wmi_enable_show() - debugfs functions to display enable state of
  775. * wmi logging feature.
  776. *
  777. * @m: debugfs handler to access wmi_handle
  778. * @v: Variable arguments (not used)
  779. *
  780. * Return: always 1
  781. */
  782. static int debug_wmi_enable_show(struct seq_file *m, void *v)
  783. {
  784. wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
  785. return wmi_bp_seq_printf(m, "%d\n",
  786. wmi_handle->log_info.wmi_logging_enable);
  787. }
  788. /**
  789. * debug_wmi_log_size_show() - debugfs functions to display configured size of
  790. * wmi logging command/event buffer and management command/event buffer.
  791. *
  792. * @m: debugfs handler to access wmi_handle
  793. * @v: Variable arguments (not used)
  794. *
  795. * Return: Length of characters printed
  796. */
  797. static int debug_wmi_log_size_show(struct seq_file *m, void *v)
  798. {
  799. wmi_bp_seq_printf(m, "WMI command/event log max size:%d\n",
  800. wmi_log_max_entry);
  801. return wmi_bp_seq_printf(m,
  802. "WMI management command/events log max size:%d\n",
  803. wmi_mgmt_log_max_entry);
  804. }
  805. /**
  806. * debug_wmi_##func_base##_write() - debugfs functions to clear
  807. * wmi logging command/event buffer and management command/event buffer.
  808. *
  809. * @file: file handler to access wmi_handle
  810. * @buf: received data buffer
  811. * @count: length of received buffer
  812. * @ppos: Not used
  813. *
  814. * Return: count
  815. */
  816. #define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
  817. static ssize_t debug_wmi_##func_base##_write(struct file *file, \
  818. const char __user *buf, \
  819. size_t count, loff_t *ppos) \
  820. { \
  821. int k, ret; \
  822. wmi_unified_t wmi_handle = \
  823. ((struct seq_file *)file->private_data)->private;\
  824. struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
  825. wmi_##func_base##_buf_info; \
  826. char locbuf[50]; \
  827. \
  828. if ((!buf) || (count > 50)) \
  829. return -EFAULT; \
  830. \
  831. if (copy_from_user(locbuf, buf, count)) \
  832. return -EFAULT; \
  833. \
  834. ret = sscanf(locbuf, "%d", &k); \
  835. if ((ret != 1) || (k != 0)) { \
  836. qdf_print("Wrong input, echo 0 to clear the wmi buffer\n");\
  837. return -EINVAL; \
  838. } \
  839. \
  840. qdf_spin_lock(&wmi_handle->log_info.wmi_record_lock); \
  841. qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
  842. sizeof(struct wmi_record_type)); \
  843. wmi_log->length = 0; \
  844. *(wmi_log->p_buf_tail_idx) = 0; \
  845. qdf_spin_unlock(&wmi_handle->log_info.wmi_record_lock); \
  846. \
  847. return count; \
  848. }
  849. GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
  850. wmi_command_debug);
  851. GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
  852. wmi_command_debug);
  853. GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
  854. wmi_event_debug);
  855. GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
  856. wmi_event_debug);
  857. GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
  858. wmi_command_debug);
  859. GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
  860. wmi_mgmt_log_max_entry, wmi_command_debug);
  861. GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
  862. wmi_event_debug);
  863. /**
  864. * debug_wmi_enable_write() - debugfs functions to enable/disable
  865. * wmi logging feature.
  866. *
  867. * @file: file handler to access wmi_handle
  868. * @buf: received data buffer
  869. * @count: length of received buffer
  870. * @ppos: Not used
  871. *
  872. * Return: count
  873. */
  874. static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
  875. size_t count, loff_t *ppos)
  876. {
  877. wmi_unified_t wmi_handle =
  878. ((struct seq_file *)file->private_data)->private;
  879. int k, ret;
  880. char locbuf[50];
  881. if ((!buf) || (count > 50))
  882. return -EFAULT;
  883. if (copy_from_user(locbuf, buf, count))
  884. return -EFAULT;
  885. ret = sscanf(locbuf, "%d", &k);
  886. if ((ret != 1) || ((k != 0) && (k != 1)))
  887. return -EINVAL;
  888. wmi_handle->log_info.wmi_logging_enable = k;
  889. return count;
  890. }
  891. /**
  892. * debug_wmi_log_size_write() - reserved.
  893. *
  894. * @file: file handler to access wmi_handle
  895. * @buf: received data buffer
  896. * @count: length of received buffer
  897. * @ppos: Not used
  898. *
  899. * Return: count
  900. */
  901. static ssize_t debug_wmi_log_size_write(struct file *file,
  902. const char __user *buf, size_t count, loff_t *ppos)
  903. {
  904. return -EINVAL;
  905. }
  906. /* Structure to maintain debug information */
  907. struct wmi_debugfs_info {
  908. const char *name;
  909. struct dentry *de[MAX_WMI_INSTANCES];
  910. const struct file_operations *ops;
  911. };
  912. #define DEBUG_FOO(func_base) { .name = #func_base, \
  913. .ops = &debug_##func_base##_ops }
  914. /**
  915. * debug_##func_base##_open() - Open debugfs entry for respective command
  916. * and event buffer.
  917. *
  918. * @inode: node for debug dir entry
  919. * @file: file handler
  920. *
  921. * Return: open status
  922. */
  923. #define GENERATE_DEBUG_STRUCTS(func_base) \
  924. static int debug_##func_base##_open(struct inode *inode, \
  925. struct file *file) \
  926. { \
  927. return single_open(file, debug_##func_base##_show, \
  928. inode->i_private); \
  929. } \
  930. \
  931. \
  932. static struct file_operations debug_##func_base##_ops = { \
  933. .open = debug_##func_base##_open, \
  934. .read = seq_read, \
  935. .llseek = seq_lseek, \
  936. .write = debug_##func_base##_write, \
  937. .release = single_release, \
  938. };
  939. GENERATE_DEBUG_STRUCTS(wmi_command_log);
  940. GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
  941. GENERATE_DEBUG_STRUCTS(wmi_event_log);
  942. GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
  943. GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
  944. GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
  945. GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
  946. GENERATE_DEBUG_STRUCTS(wmi_enable);
  947. GENERATE_DEBUG_STRUCTS(wmi_log_size);
  948. struct wmi_debugfs_info wmi_debugfs_infos[] = {
  949. DEBUG_FOO(wmi_command_log),
  950. DEBUG_FOO(wmi_command_tx_cmp_log),
  951. DEBUG_FOO(wmi_event_log),
  952. DEBUG_FOO(wmi_rx_event_log),
  953. DEBUG_FOO(wmi_mgmt_command_log),
  954. DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
  955. DEBUG_FOO(wmi_mgmt_event_log),
  956. DEBUG_FOO(wmi_enable),
  957. DEBUG_FOO(wmi_log_size),
  958. };
  959. #define NUM_DEBUG_INFOS (sizeof(wmi_debugfs_infos) / \
  960. sizeof(wmi_debugfs_infos[0]))
  961. /**
  962. * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
  963. *
  964. * @wmi_handle: wmi handle
  965. * @par_entry: debug directory entry
  966. * @id: Index to debug info data array
  967. *
  968. * Return: none
  969. */
  970. static void wmi_debugfs_create(wmi_unified_t wmi_handle,
  971. struct dentry *par_entry, int id)
  972. {
  973. int i;
  974. if (par_entry == NULL || (id < 0) || (id >= MAX_WMI_INSTANCES))
  975. goto out;
  976. for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
  977. wmi_debugfs_infos[i].de[id] = debugfs_create_file(
  978. wmi_debugfs_infos[i].name, 0644, par_entry,
  979. wmi_handle, wmi_debugfs_infos[i].ops);
  980. if (wmi_debugfs_infos[i].de[id] == NULL) {
  981. qdf_print("%s: debug Entry creation failed!\n",
  982. __func__);
  983. goto out;
  984. }
  985. }
  986. return;
  987. out:
  988. qdf_print("%s: debug Entry creation failed!\n", __func__);
  989. wmi_log_buffer_free(wmi_handle);
  990. return;
  991. }
  992. /**
  993. * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
  994. * @wmi_handle: wmi handle
  995. * @dentry: debugfs directory entry
  996. * @id: Index to debug info data array
  997. *
  998. * Return: none
  999. */
  1000. static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
  1001. {
  1002. int i;
  1003. struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
  1004. int id;
  1005. if (!wmi_handle->log_info.wmi_instance_id)
  1006. return;
  1007. id = wmi_handle->log_info.wmi_instance_id - 1;
  1008. if (dentry && (!(id < 0) || (id >= MAX_WMI_INSTANCES))) {
  1009. for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
  1010. if (wmi_debugfs_infos[i].de[id])
  1011. wmi_debugfs_infos[i].de[id] = NULL;
  1012. }
  1013. }
  1014. if (dentry)
  1015. debugfs_remove_recursive(dentry);
  1016. if (wmi_handle->log_info.wmi_instance_id)
  1017. wmi_handle->log_info.wmi_instance_id--;
  1018. }
  1019. /**
  1020. * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
  1021. * create debugfs enteries.
  1022. *
  1023. * @h: wmi handler
  1024. *
  1025. * Return: init status
  1026. */
  1027. static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle)
  1028. {
  1029. int wmi_index = wmi_handle->log_info.wmi_instance_id;
  1030. if (wmi_index < MAX_WMI_INSTANCES) {
  1031. wmi_handle->log_info.wmi_log_debugfs_dir =
  1032. debugfs_create_dir(debugfs_dir[wmi_index], NULL);
  1033. if (!wmi_handle->log_info.wmi_log_debugfs_dir) {
  1034. qdf_print("error while creating debugfs dir for %s\n",
  1035. debugfs_dir[wmi_index]);
  1036. return QDF_STATUS_E_FAILURE;
  1037. }
  1038. wmi_debugfs_create(wmi_handle,
  1039. wmi_handle->log_info.wmi_log_debugfs_dir,
  1040. wmi_index);
  1041. wmi_handle->log_info.wmi_instance_id++;
  1042. }
  1043. return QDF_STATUS_SUCCESS;
  1044. }
  1045. /**
  1046. * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
  1047. *
  1048. * @wmi_handle: wmi handle
  1049. * @cmd: mgmt command
  1050. * @header: pointer to 802.11 header
  1051. * @vdev_id: vdev id
  1052. * @chanfreq: channel frequency
  1053. *
  1054. * Return: none
  1055. */
  1056. void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
  1057. void *header, uint32_t vdev_id, uint32_t chanfreq)
  1058. {
  1059. uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
  1060. data[0] = ((struct wmi_command_header *)header)->type;
  1061. data[1] = ((struct wmi_command_header *)header)->sub_type;
  1062. data[2] = vdev_id;
  1063. data[3] = chanfreq;
  1064. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1065. WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, (uint8_t *)data);
  1066. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1067. }
  1068. #else
  1069. /**
  1070. * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
  1071. * @wmi_handle: wmi handle
  1072. * @dentry: debugfs directory entry
  1073. * @id: Index to debug info data array
  1074. *
  1075. * Return: none
  1076. */
  1077. static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
  1078. void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
  1079. void *header, uint32_t vdev_id, uint32_t chanfreq) { }
  1080. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
  1081. #endif /*WMI_INTERFACE_EVENT_LOGGING */
  1082. int wmi_get_host_credits(wmi_unified_t wmi_handle);
  1083. /* WMI buffer APIs */
  1084. #ifdef MEMORY_DEBUG
  1085. wmi_buf_t
  1086. wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint16_t len, uint8_t *file_name,
  1087. uint32_t line_num)
  1088. {
  1089. wmi_buf_t wmi_buf;
  1090. if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
  1091. QDF_ASSERT(0);
  1092. return NULL;
  1093. }
  1094. wmi_buf = qdf_nbuf_alloc_debug(NULL,
  1095. roundup(len + WMI_MIN_HEAD_ROOM, 4),
  1096. WMI_MIN_HEAD_ROOM, 4, false, file_name,
  1097. line_num);
  1098. if (!wmi_buf)
  1099. return NULL;
  1100. /* Clear the wmi buffer */
  1101. OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
  1102. /*
  1103. * Set the length of the buffer to match the allocation size.
  1104. */
  1105. qdf_nbuf_set_pktlen(wmi_buf, len);
  1106. return wmi_buf;
  1107. }
  1108. void wmi_buf_free(wmi_buf_t net_buf)
  1109. {
  1110. qdf_nbuf_free(net_buf);
  1111. }
  1112. #else
  1113. wmi_buf_t wmi_buf_alloc(wmi_unified_t wmi_handle, uint16_t len)
  1114. {
  1115. wmi_buf_t wmi_buf;
  1116. if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
  1117. QDF_ASSERT(0);
  1118. return NULL;
  1119. }
  1120. wmi_buf = qdf_nbuf_alloc(NULL, roundup(len + WMI_MIN_HEAD_ROOM, 4),
  1121. WMI_MIN_HEAD_ROOM, 4, false);
  1122. if (!wmi_buf)
  1123. return NULL;
  1124. /* Clear the wmi buffer */
  1125. OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
  1126. /*
  1127. * Set the length of the buffer to match the allocation size.
  1128. */
  1129. qdf_nbuf_set_pktlen(wmi_buf, len);
  1130. return wmi_buf;
  1131. }
  1132. void wmi_buf_free(wmi_buf_t net_buf)
  1133. {
  1134. qdf_nbuf_free(net_buf);
  1135. }
  1136. #endif
  1137. /**
  1138. * wmi_get_max_msg_len() - get maximum WMI message length
  1139. * @wmi_handle: WMI handle.
  1140. *
  1141. * This function returns the maximum WMI message length
  1142. *
  1143. * Return: maximum WMI message length
  1144. */
  1145. uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
  1146. {
  1147. return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
  1148. }
  1149. #ifndef WMI_CMD_STRINGS
  1150. static uint8_t *wmi_id_to_name(uint32_t wmi_command)
  1151. {
  1152. return "Invalid WMI cmd";
  1153. }
  1154. #endif
  1155. #ifdef CONFIG_MCL
  1156. static inline void wmi_log_cmd_id(uint32_t cmd_id, uint32_t tag)
  1157. {
  1158. WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
  1159. wmi_id_to_name(cmd_id), cmd_id, tag);
  1160. }
  1161. /**
  1162. * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
  1163. * @cmd_id: command to check
  1164. *
  1165. * Return: true if the command is part of the resume sequence.
  1166. */
  1167. static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
  1168. {
  1169. switch (cmd_id) {
  1170. case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
  1171. case WMI_PDEV_RESUME_CMDID:
  1172. return true;
  1173. default:
  1174. return false;
  1175. }
  1176. }
  1177. #else
  1178. static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
  1179. {
  1180. return false;
  1181. }
  1182. #endif
  1183. /**
  1184. * wmi_unified_cmd_send() - WMI command API
  1185. * @wmi_handle: handle to wmi
  1186. * @buf: wmi buf
  1187. * @len: wmi buffer length
  1188. * @cmd_id: wmi command id
  1189. *
  1190. * Note, it is NOT safe to access buf after calling this function!
  1191. *
  1192. * Return: 0 on success
  1193. */
  1194. QDF_STATUS wmi_unified_cmd_send(wmi_unified_t wmi_handle, wmi_buf_t buf,
  1195. uint32_t len, uint32_t cmd_id)
  1196. {
  1197. HTC_PACKET *pkt;
  1198. QDF_STATUS status;
  1199. uint16_t htc_tag = 0;
  1200. if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
  1201. htc_tag =
  1202. (A_UINT16)wmi_handle->ops->wmi_set_htc_tx_tag(
  1203. wmi_handle, buf, cmd_id);
  1204. } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
  1205. (!wmi_is_pm_resume_cmd(cmd_id))) {
  1206. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1207. "%s: Target is suspended", __func__);
  1208. QDF_ASSERT(0);
  1209. return QDF_STATUS_E_BUSY;
  1210. }
  1211. if (wmi_handle->wmi_stopinprogress) {
  1212. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1213. "WMI stop in progress\n");
  1214. return QDF_STATUS_E_INVAL;
  1215. }
  1216. #ifndef WMI_NON_TLV_SUPPORT
  1217. /* Do sanity check on the TLV parameter structure */
  1218. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  1219. void *buf_ptr = (void *)qdf_nbuf_data(buf);
  1220. if (wmitlv_check_command_tlv_params(NULL, buf_ptr, len, cmd_id)
  1221. != 0) {
  1222. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1223. "\nERROR: %s: Invalid WMI Param Buffer for Cmd:%d",
  1224. __func__, cmd_id);
  1225. return QDF_STATUS_E_INVAL;
  1226. }
  1227. }
  1228. #endif
  1229. if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
  1230. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1231. "%s, Failed to send cmd %x, no memory",
  1232. __func__, cmd_id);
  1233. return QDF_STATUS_E_NOMEM;
  1234. }
  1235. WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
  1236. qdf_atomic_inc(&wmi_handle->pending_cmds);
  1237. if (qdf_atomic_read(&wmi_handle->pending_cmds) >= WMI_MAX_CMDS) {
  1238. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1239. "\n%s: hostcredits = %d", __func__,
  1240. wmi_get_host_credits(wmi_handle));
  1241. htc_dump_counter_info(wmi_handle->htc_handle);
  1242. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1243. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1244. "%s: MAX %d WMI Pending cmds reached.", __func__,
  1245. WMI_MAX_CMDS);
  1246. QDF_BUG(0);
  1247. return QDF_STATUS_E_BUSY;
  1248. }
  1249. pkt = qdf_mem_malloc(sizeof(*pkt));
  1250. if (!pkt) {
  1251. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1252. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1253. "%s, Failed to alloc htc packet %x, no memory",
  1254. __func__, cmd_id);
  1255. return QDF_STATUS_E_NOMEM;
  1256. }
  1257. SET_HTC_PACKET_INFO_TX(pkt,
  1258. NULL,
  1259. qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
  1260. wmi_handle->wmi_endpoint_id, htc_tag);
  1261. SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
  1262. #ifdef CONFIG_MCL
  1263. wmi_log_cmd_id(cmd_id, htc_tag);
  1264. #endif
  1265. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1266. if (wmi_handle->log_info.wmi_logging_enable) {
  1267. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1268. /*
  1269. * Record 16 bytes of WMI cmd data -
  1270. * exclude TLV and WMI headers
  1271. *
  1272. * WMI mgmt command already recorded in wmi_mgmt_cmd_record
  1273. */
  1274. if (wmi_handle->ops->is_management_record(cmd_id) == false) {
  1275. WMI_COMMAND_RECORD(wmi_handle, cmd_id,
  1276. qdf_nbuf_data(buf) +
  1277. wmi_handle->log_info.buf_offset_command);
  1278. }
  1279. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1280. }
  1281. #endif
  1282. status = htc_send_pkt(wmi_handle->htc_handle, pkt);
  1283. if (QDF_STATUS_SUCCESS != status) {
  1284. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1285. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1286. "%s %d, htc_send_pkt failed", __func__, __LINE__);
  1287. qdf_mem_free(pkt);
  1288. return status;
  1289. }
  1290. return QDF_STATUS_SUCCESS;
  1291. }
  1292. /**
  1293. * wmi_unified_get_event_handler_ix() - gives event handler's index
  1294. * @wmi_handle: handle to wmi
  1295. * @event_id: wmi event id
  1296. *
  1297. * Return: event handler's index
  1298. */
  1299. static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
  1300. uint32_t event_id)
  1301. {
  1302. uint32_t idx = 0;
  1303. int32_t invalid_idx = -1;
  1304. struct wmi_soc *soc = wmi_handle->soc;
  1305. for (idx = 0; (idx < soc->max_event_idx &&
  1306. idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
  1307. if (wmi_handle->event_id[idx] == event_id &&
  1308. wmi_handle->event_handler[idx] != NULL) {
  1309. return idx;
  1310. }
  1311. }
  1312. return invalid_idx;
  1313. }
  1314. /**
  1315. * wmi_unified_register_event() - register wmi event handler
  1316. * @wmi_handle: handle to wmi
  1317. * @event_id: wmi event id
  1318. * @handler_func: wmi event handler function
  1319. *
  1320. * Return: 0 on success
  1321. */
  1322. int wmi_unified_register_event(wmi_unified_t wmi_handle,
  1323. uint32_t event_id,
  1324. wmi_unified_event_handler handler_func)
  1325. {
  1326. uint32_t idx = 0;
  1327. uint32_t evt_id;
  1328. struct wmi_soc *soc = wmi_handle->soc;
  1329. if (event_id >= wmi_events_max ||
  1330. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1331. qdf_print("%s: Event id %d is unavailable\n",
  1332. __func__, event_id);
  1333. return QDF_STATUS_E_FAILURE;
  1334. }
  1335. evt_id = wmi_handle->wmi_events[event_id];
  1336. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1337. qdf_print("%s : event handler already registered 0x%x\n",
  1338. __func__, evt_id);
  1339. return QDF_STATUS_E_FAILURE;
  1340. }
  1341. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1342. qdf_print("%s : no more event handlers 0x%x\n",
  1343. __func__, evt_id);
  1344. return QDF_STATUS_E_FAILURE;
  1345. }
  1346. idx = soc->max_event_idx;
  1347. wmi_handle->event_handler[idx] = handler_func;
  1348. wmi_handle->event_id[idx] = evt_id;
  1349. qdf_spin_lock_bh(&soc->ctx_lock);
  1350. wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
  1351. qdf_spin_unlock_bh(&soc->ctx_lock);
  1352. soc->max_event_idx++;
  1353. return 0;
  1354. }
  1355. /**
  1356. * wmi_unified_register_event_handler() - register wmi event handler
  1357. * @wmi_handle: handle to wmi
  1358. * @event_id: wmi event id
  1359. * @handler_func: wmi event handler function
  1360. * @rx_ctx: rx execution context for wmi rx events
  1361. *
  1362. * This API is to support legacy requirements. Will be deprecated in future.
  1363. * Return: 0 on success
  1364. */
  1365. int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
  1366. wmi_conv_event_id event_id,
  1367. wmi_unified_event_handler handler_func,
  1368. uint8_t rx_ctx)
  1369. {
  1370. uint32_t idx = 0;
  1371. uint32_t evt_id;
  1372. struct wmi_soc *soc = wmi_handle->soc;
  1373. if (event_id >= wmi_events_max ||
  1374. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1375. qdf_print("%s: Event id %d is unavailable\n",
  1376. __func__, event_id);
  1377. return QDF_STATUS_E_FAILURE;
  1378. }
  1379. evt_id = wmi_handle->wmi_events[event_id];
  1380. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1381. qdf_print("%s : event handler already registered 0x%x\n",
  1382. __func__, evt_id);
  1383. return QDF_STATUS_E_FAILURE;
  1384. }
  1385. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1386. qdf_print("%s : no more event handlers 0x%x\n",
  1387. __func__, evt_id);
  1388. return QDF_STATUS_E_FAILURE;
  1389. }
  1390. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
  1391. "Registered event handler for event 0x%8x\n", evt_id);
  1392. idx = soc->max_event_idx;
  1393. wmi_handle->event_handler[idx] = handler_func;
  1394. wmi_handle->event_id[idx] = evt_id;
  1395. qdf_spin_lock_bh(&soc->ctx_lock);
  1396. wmi_handle->ctx[idx] = rx_ctx;
  1397. qdf_spin_unlock_bh(&soc->ctx_lock);
  1398. soc->max_event_idx++;
  1399. return 0;
  1400. }
  1401. /**
  1402. * wmi_unified_unregister_event() - unregister wmi event handler
  1403. * @wmi_handle: handle to wmi
  1404. * @event_id: wmi event id
  1405. *
  1406. * Return: 0 on success
  1407. */
  1408. int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
  1409. uint32_t event_id)
  1410. {
  1411. uint32_t idx = 0;
  1412. uint32_t evt_id;
  1413. struct wmi_soc *soc = wmi_handle->soc;
  1414. if (event_id >= wmi_events_max ||
  1415. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1416. qdf_print("%s: Event id %d is unavailable\n",
  1417. __func__, event_id);
  1418. return QDF_STATUS_E_FAILURE;
  1419. }
  1420. evt_id = wmi_handle->wmi_events[event_id];
  1421. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1422. if (idx == -1) {
  1423. qdf_print("%s : event handler is not registered: evt id 0x%x\n",
  1424. __func__, evt_id);
  1425. return QDF_STATUS_E_FAILURE;
  1426. }
  1427. wmi_handle->event_handler[idx] = NULL;
  1428. wmi_handle->event_id[idx] = 0;
  1429. --soc->max_event_idx;
  1430. wmi_handle->event_handler[idx] =
  1431. wmi_handle->event_handler[soc->max_event_idx];
  1432. wmi_handle->event_id[idx] =
  1433. wmi_handle->event_id[soc->max_event_idx];
  1434. return 0;
  1435. }
  1436. /**
  1437. * wmi_unified_unregister_event_handler() - unregister wmi event handler
  1438. * @wmi_handle: handle to wmi
  1439. * @event_id: wmi event id
  1440. *
  1441. * Return: 0 on success
  1442. */
  1443. int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
  1444. wmi_conv_event_id event_id)
  1445. {
  1446. uint32_t idx = 0;
  1447. uint32_t evt_id;
  1448. struct wmi_soc *soc = wmi_handle->soc;
  1449. if (event_id >= wmi_events_max ||
  1450. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1451. qdf_print("%s: Event id %d is unavailable\n",
  1452. __func__, event_id);
  1453. return QDF_STATUS_E_FAILURE;
  1454. }
  1455. evt_id = wmi_handle->wmi_events[event_id];
  1456. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1457. if (idx == -1) {
  1458. qdf_print("%s : event handler is not registered: evt id 0x%x\n",
  1459. __func__, evt_id);
  1460. return QDF_STATUS_E_FAILURE;
  1461. }
  1462. wmi_handle->event_handler[idx] = NULL;
  1463. wmi_handle->event_id[idx] = 0;
  1464. --soc->max_event_idx;
  1465. wmi_handle->event_handler[idx] =
  1466. wmi_handle->event_handler[soc->max_event_idx];
  1467. wmi_handle->event_id[idx] =
  1468. wmi_handle->event_id[soc->max_event_idx];
  1469. return 0;
  1470. }
  1471. /**
  1472. * wmi_process_fw_event_default_ctx() - process in default caller context
  1473. * @wmi_handle: handle to wmi
  1474. * @htc_packet: pointer to htc packet
  1475. * @exec_ctx: execution context for wmi fw event
  1476. *
  1477. * Event process by below function will be in default caller context.
  1478. * wmi internally provides rx work thread processing context.
  1479. *
  1480. * Return: none
  1481. */
  1482. static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
  1483. HTC_PACKET *htc_packet, uint8_t exec_ctx)
  1484. {
  1485. wmi_buf_t evt_buf;
  1486. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1487. #ifndef CONFIG_MCL
  1488. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
  1489. (wmi_handle->scn_handle, evt_buf, exec_ctx);
  1490. #else
  1491. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
  1492. evt_buf, exec_ctx);
  1493. #endif
  1494. return;
  1495. }
  1496. /**
  1497. * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
  1498. * @wmi_handle: handle to wmi
  1499. * @htc_packet: pointer to htc packet
  1500. *
  1501. * Event process by below function will be in worker thread context.
  1502. * Use this method for events which are not critical and not
  1503. * handled in protocol stack.
  1504. *
  1505. * Return: none
  1506. */
  1507. static void wmi_process_fw_event_worker_thread_ctx
  1508. (struct wmi_unified *wmi_handle, HTC_PACKET *htc_packet)
  1509. {
  1510. wmi_buf_t evt_buf;
  1511. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1512. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  1513. qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
  1514. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  1515. qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
  1516. &wmi_handle->rx_event_work);
  1517. return;
  1518. }
  1519. /**
  1520. * wmi_get_pdev_ep: Get wmi handle based on endpoint
  1521. * @soc: handle to wmi soc
  1522. * @ep: endpoint id
  1523. *
  1524. * Return: none
  1525. */
  1526. static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
  1527. HTC_ENDPOINT_ID ep)
  1528. {
  1529. uint32_t i;
  1530. for (i = 0; i < WMI_MAX_RADIOS; i++)
  1531. if (soc->wmi_endpoint_id[i] == ep)
  1532. break;
  1533. if (i == WMI_MAX_RADIOS)
  1534. return NULL;
  1535. return soc->wmi_pdev[i];
  1536. }
  1537. /**
  1538. * wmi_control_rx() - process fw events callbacks
  1539. * @ctx: handle to wmi
  1540. * @htc_packet: pointer to htc packet
  1541. *
  1542. * Return: none
  1543. */
  1544. static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
  1545. {
  1546. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  1547. struct wmi_unified *wmi_handle;
  1548. wmi_buf_t evt_buf;
  1549. uint32_t id;
  1550. uint32_t idx = 0;
  1551. enum wmi_rx_exec_ctx exec_ctx;
  1552. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1553. wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
  1554. if (wmi_handle == NULL) {
  1555. qdf_print
  1556. ("%s :unable to get wmi_handle to Endpoint %d\n",
  1557. __func__, htc_packet->Endpoint);
  1558. qdf_nbuf_free(evt_buf);
  1559. return;
  1560. }
  1561. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  1562. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  1563. if (qdf_unlikely(idx == A_ERROR)) {
  1564. WMI_LOGD("%s :event handler is not registered: event id 0x%x\n",
  1565. __func__, id);
  1566. qdf_nbuf_free(evt_buf);
  1567. return;
  1568. }
  1569. qdf_spin_lock_bh(&soc->ctx_lock);
  1570. exec_ctx = wmi_handle->ctx[idx];
  1571. qdf_spin_unlock_bh(&soc->ctx_lock);
  1572. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1573. if (wmi_handle->log_info.wmi_logging_enable) {
  1574. uint8_t *data;
  1575. data = qdf_nbuf_data(evt_buf);
  1576. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1577. /* Exclude 4 bytes of TLV header */
  1578. WMI_RX_EVENT_RECORD(wmi_handle, id, data +
  1579. wmi_handle->log_info.buf_offset_event);
  1580. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1581. }
  1582. #endif
  1583. if (exec_ctx == WMI_RX_WORK_CTX) {
  1584. wmi_process_fw_event_worker_thread_ctx
  1585. (wmi_handle, htc_packet);
  1586. } else if (exec_ctx > WMI_RX_WORK_CTX) {
  1587. wmi_process_fw_event_default_ctx
  1588. (wmi_handle, htc_packet, exec_ctx);
  1589. } else {
  1590. qdf_print("%s :Invalid event context %d\n", __func__, exec_ctx);
  1591. qdf_nbuf_free(evt_buf);
  1592. }
  1593. }
  1594. /**
  1595. * wmi_process_fw_event() - process any fw event
  1596. * @wmi_handle: wmi handle
  1597. * @evt_buf: fw event buffer
  1598. *
  1599. * This function process fw event in caller context
  1600. *
  1601. * Return: none
  1602. */
  1603. void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  1604. {
  1605. __wmi_control_rx(wmi_handle, evt_buf);
  1606. }
  1607. /**
  1608. * __wmi_control_rx() - process serialize wmi event callback
  1609. * @wmi_handle: wmi handle
  1610. * @evt_buf: fw event buffer
  1611. *
  1612. * Return: none
  1613. */
  1614. void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  1615. {
  1616. uint32_t id;
  1617. uint8_t *data;
  1618. uint32_t len;
  1619. void *wmi_cmd_struct_ptr = NULL;
  1620. #ifndef WMI_NON_TLV_SUPPORT
  1621. int tlv_ok_status = 0;
  1622. #endif
  1623. uint32_t idx = 0;
  1624. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  1625. if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
  1626. goto end;
  1627. data = qdf_nbuf_data(evt_buf);
  1628. len = qdf_nbuf_len(evt_buf);
  1629. #ifndef WMI_NON_TLV_SUPPORT
  1630. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  1631. /* Validate and pad(if necessary) the TLVs */
  1632. tlv_ok_status =
  1633. wmitlv_check_and_pad_event_tlvs(wmi_handle->scn_handle,
  1634. data, len, id,
  1635. &wmi_cmd_struct_ptr);
  1636. if (tlv_ok_status != 0) {
  1637. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1638. "%s: Error: id=0x%d, wmitlv check status=%d\n",
  1639. __func__, id, tlv_ok_status);
  1640. goto end;
  1641. }
  1642. }
  1643. #endif
  1644. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  1645. if (idx == A_ERROR) {
  1646. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1647. "%s : event handler is not registered: event id 0x%x\n",
  1648. __func__, id);
  1649. goto end;
  1650. }
  1651. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1652. if (wmi_handle->log_info.wmi_logging_enable) {
  1653. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1654. /* Exclude 4 bytes of TLV header */
  1655. if (wmi_handle->ops->is_management_record(id)) {
  1656. WMI_MGMT_EVENT_RECORD(wmi_handle, id, data
  1657. + wmi_handle->log_info.buf_offset_event);
  1658. } else {
  1659. WMI_EVENT_RECORD(wmi_handle, id, data +
  1660. wmi_handle->log_info.buf_offset_event);
  1661. }
  1662. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1663. }
  1664. #endif
  1665. /* Call the WMI registered event handler */
  1666. if (wmi_handle->target_type == WMI_TLV_TARGET)
  1667. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  1668. wmi_cmd_struct_ptr, len);
  1669. else
  1670. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  1671. data, len);
  1672. end:
  1673. /* Free event buffer and allocated event tlv */
  1674. #ifndef WMI_NON_TLV_SUPPORT
  1675. if (wmi_handle->target_type == WMI_TLV_TARGET)
  1676. wmitlv_free_allocated_event_tlvs(id, &wmi_cmd_struct_ptr);
  1677. #endif
  1678. qdf_nbuf_free(evt_buf);
  1679. }
  1680. #define WMI_WQ_WD_TIMEOUT (10 * 1000) /* 10s */
  1681. static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id)
  1682. {
  1683. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  1684. "%s: Message type %x has exceeded its alloted time of %ds",
  1685. __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000);
  1686. }
  1687. #ifdef CONFIG_SLUB_DEBUG_ON
  1688. static 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. qdf_print_thread_trace(info->task);
  1693. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  1694. "%s: Going down for WMI WQ Watchdog Bite!", __func__);
  1695. QDF_BUG(0);
  1696. }
  1697. #else
  1698. static inline void wmi_workqueue_watchdog_bite(void *arg)
  1699. {
  1700. struct wmi_wq_dbg_info *info = arg;
  1701. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  1702. }
  1703. #endif
  1704. /**
  1705. * wmi_rx_event_work() - process rx event in rx work queue context
  1706. * @arg: opaque pointer to wmi handle
  1707. *
  1708. * This function process any fw event to serialize it through rx worker thread.
  1709. *
  1710. * Return: none
  1711. */
  1712. static void wmi_rx_event_work(void *arg)
  1713. {
  1714. wmi_buf_t buf;
  1715. struct wmi_unified *wmi = arg;
  1716. qdf_timer_t wd_timer;
  1717. struct wmi_wq_dbg_info info;
  1718. /* initialize WMI workqueue watchdog timer */
  1719. qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite,
  1720. &info, QDF_TIMER_TYPE_SW);
  1721. qdf_spin_lock_bh(&wmi->eventq_lock);
  1722. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  1723. qdf_spin_unlock_bh(&wmi->eventq_lock);
  1724. while (buf) {
  1725. qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT);
  1726. info.wd_msg_type_id =
  1727. WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID);
  1728. info.wmi_wq = wmi->wmi_rx_work_queue;
  1729. info.task = qdf_get_current_task();
  1730. __wmi_control_rx(wmi, buf);
  1731. qdf_timer_stop(&wd_timer);
  1732. qdf_spin_lock_bh(&wmi->eventq_lock);
  1733. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  1734. qdf_spin_unlock_bh(&wmi->eventq_lock);
  1735. }
  1736. qdf_timer_free(&wd_timer);
  1737. }
  1738. #ifdef FEATURE_RUNTIME_PM
  1739. /**
  1740. * wmi_runtime_pm_init() - initialize runtime pm wmi variables
  1741. * @wmi_handle: wmi context
  1742. */
  1743. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  1744. {
  1745. qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
  1746. }
  1747. /**
  1748. * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
  1749. * @wmi_handle: wmi context
  1750. * @val: runtime pm progress flag
  1751. */
  1752. void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
  1753. {
  1754. qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
  1755. }
  1756. /**
  1757. * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
  1758. * @wmi_handle: wmi context
  1759. */
  1760. inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
  1761. {
  1762. return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
  1763. }
  1764. #else
  1765. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  1766. {
  1767. }
  1768. #endif
  1769. /**
  1770. * wmi_unified_get_soc_handle: Get WMI SoC handle
  1771. * @param wmi_handle: WMI context got from wmi_attach
  1772. *
  1773. * return: Pointer to Soc handle
  1774. */
  1775. void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
  1776. {
  1777. return wmi_handle->soc;
  1778. }
  1779. /**
  1780. * wmi_interface_logging_init: Interface looging init
  1781. * @param wmi_handle: Pointer to wmi handle object
  1782. *
  1783. * return: None
  1784. */
  1785. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1786. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
  1787. {
  1788. if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
  1789. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  1790. wmi_debugfs_init(wmi_handle);
  1791. }
  1792. }
  1793. #else
  1794. void wmi_interface_logging_init(struct wmi_unified *wmi_handle)
  1795. {
  1796. }
  1797. #endif
  1798. /**
  1799. * wmi_target_params_init: Target specific params init
  1800. * @param wmi_soc: Pointer to wmi soc object
  1801. * @param wmi_handle: Pointer to wmi handle object
  1802. *
  1803. * return: None
  1804. */
  1805. #ifndef CONFIG_MCL
  1806. static inline void wmi_target_params_init(struct wmi_soc *soc,
  1807. struct wmi_unified *wmi_handle)
  1808. {
  1809. wmi_handle->pdev_param = soc->pdev_param;
  1810. wmi_handle->vdev_param = soc->vdev_param;
  1811. wmi_handle->services = soc->services;
  1812. }
  1813. #else
  1814. static inline void wmi_target_params_init(struct wmi_soc *soc,
  1815. struct wmi_unified *wmi_handle)
  1816. {
  1817. wmi_handle->services = soc->services;
  1818. }
  1819. #endif
  1820. /**
  1821. * wmi_unified_get_pdev_handle: Get WMI SoC handle
  1822. * @param wmi_soc: Pointer to wmi soc object
  1823. * @param pdev_idx: pdev index
  1824. *
  1825. * return: Pointer to wmi handle or NULL on failure
  1826. */
  1827. void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
  1828. {
  1829. struct wmi_unified *wmi_handle;
  1830. if (pdev_idx >= WMI_MAX_RADIOS)
  1831. return NULL;
  1832. if (soc->wmi_pdev[pdev_idx] == NULL) {
  1833. wmi_handle =
  1834. (struct wmi_unified *) qdf_mem_malloc(
  1835. sizeof(struct wmi_unified));
  1836. if (wmi_handle == NULL) {
  1837. qdf_print("allocation of wmi handle failed %zu\n",
  1838. sizeof(struct wmi_unified));
  1839. return NULL;
  1840. }
  1841. wmi_handle->scn_handle = soc->scn_handle;
  1842. wmi_handle->event_id = soc->event_id;
  1843. wmi_handle->event_handler = soc->event_handler;
  1844. wmi_handle->ctx = soc->ctx;
  1845. wmi_handle->ops = soc->ops;
  1846. qdf_spinlock_create(&wmi_handle->eventq_lock);
  1847. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  1848. qdf_create_work(0, &wmi_handle->rx_event_work,
  1849. wmi_rx_event_work, wmi_handle);
  1850. wmi_handle->wmi_rx_work_queue =
  1851. qdf_create_workqueue("wmi_rx_event_work_queue");
  1852. if (NULL == wmi_handle->wmi_rx_work_queue) {
  1853. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  1854. goto error;
  1855. }
  1856. wmi_handle->wmi_events = soc->wmi_events;
  1857. wmi_target_params_init(soc, wmi_handle);
  1858. wmi_interface_logging_init(wmi_handle);
  1859. qdf_atomic_init(&wmi_handle->pending_cmds);
  1860. qdf_atomic_init(&wmi_handle->is_target_suspended);
  1861. wmi_handle->target_type = soc->target_type;
  1862. wmi_handle->soc = soc;
  1863. soc->wmi_pdev[pdev_idx] = wmi_handle;
  1864. } else
  1865. wmi_handle = soc->wmi_pdev[pdev_idx];
  1866. wmi_handle->wmi_stopinprogress = 0;
  1867. wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
  1868. wmi_handle->htc_handle = soc->htc_handle;
  1869. wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
  1870. return wmi_handle;
  1871. error:
  1872. qdf_mem_free(wmi_handle);
  1873. return NULL;
  1874. }
  1875. /**
  1876. * wmi_unified_attach() - attach for unified WMI
  1877. * @scn_handle: handle to SCN
  1878. * @osdev: OS device context
  1879. * @target_type: TLV or not-TLV based target
  1880. * @use_cookie: cookie based allocation enabled/disabled
  1881. * @ops: umac rx callbacks
  1882. * @psoc: objmgr psoc
  1883. *
  1884. * @Return: wmi handle.
  1885. */
  1886. void *wmi_unified_attach(void *scn_handle,
  1887. osdev_t osdev, enum wmi_target_type target_type,
  1888. bool use_cookie, struct wmi_rx_ops *rx_ops,
  1889. struct wlan_objmgr_psoc *psoc)
  1890. {
  1891. struct wmi_unified *wmi_handle;
  1892. struct wmi_soc *soc;
  1893. soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
  1894. if (soc == NULL) {
  1895. qdf_print("Allocation of wmi_soc failed %zu\n",
  1896. sizeof(struct wmi_soc));
  1897. return NULL;
  1898. }
  1899. wmi_handle =
  1900. (struct wmi_unified *) qdf_mem_malloc(
  1901. sizeof(struct wmi_unified));
  1902. if (wmi_handle == NULL) {
  1903. qdf_mem_free(soc);
  1904. qdf_print("allocation of wmi handle failed %zu\n",
  1905. sizeof(struct wmi_unified));
  1906. return NULL;
  1907. }
  1908. wmi_handle->soc = soc;
  1909. wmi_handle->event_id = soc->event_id;
  1910. wmi_handle->event_handler = soc->event_handler;
  1911. wmi_handle->ctx = soc->ctx;
  1912. wmi_handle->wmi_events = soc->wmi_events;
  1913. wmi_target_params_init(soc, wmi_handle);
  1914. wmi_handle->scn_handle = scn_handle;
  1915. soc->scn_handle = scn_handle;
  1916. qdf_atomic_init(&wmi_handle->pending_cmds);
  1917. qdf_atomic_init(&wmi_handle->is_target_suspended);
  1918. wmi_runtime_pm_init(wmi_handle);
  1919. qdf_spinlock_create(&wmi_handle->eventq_lock);
  1920. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  1921. qdf_create_work(0, &wmi_handle->rx_event_work,
  1922. wmi_rx_event_work, wmi_handle);
  1923. wmi_handle->wmi_rx_work_queue =
  1924. qdf_create_workqueue("wmi_rx_event_work_queue");
  1925. if (NULL == wmi_handle->wmi_rx_work_queue) {
  1926. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  1927. goto error;
  1928. }
  1929. wmi_interface_logging_init(wmi_handle);
  1930. /* Attach mc_thread context processing function */
  1931. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
  1932. rx_ops->wma_process_fw_event_handler_cbk;
  1933. wmi_handle->target_type = target_type;
  1934. soc->target_type = target_type;
  1935. if (target_type == WMI_TLV_TARGET)
  1936. wmi_tlv_attach(wmi_handle);
  1937. else
  1938. wmi_non_tlv_attach(wmi_handle);
  1939. /* Assign target cookie capablity */
  1940. wmi_handle->use_cookie = use_cookie;
  1941. wmi_handle->osdev = osdev;
  1942. wmi_handle->wmi_stopinprogress = 0;
  1943. /* Increase the ref count once refcount infra is present */
  1944. soc->wmi_psoc = psoc;
  1945. qdf_spinlock_create(&soc->ctx_lock);
  1946. soc->ops = wmi_handle->ops;
  1947. soc->wmi_pdev[0] = wmi_handle;
  1948. return wmi_handle;
  1949. error:
  1950. qdf_mem_free(soc);
  1951. qdf_mem_free(wmi_handle);
  1952. return NULL;
  1953. }
  1954. /**
  1955. * wmi_unified_detach() - detach for unified WMI
  1956. *
  1957. * @wmi_handle : handle to wmi.
  1958. *
  1959. * @Return: none.
  1960. */
  1961. void wmi_unified_detach(struct wmi_unified *wmi_handle)
  1962. {
  1963. wmi_buf_t buf;
  1964. struct wmi_soc *soc;
  1965. uint8_t i;
  1966. soc = wmi_handle->soc;
  1967. for (i = 0; i < WMI_MAX_RADIOS; i++) {
  1968. if (soc->wmi_pdev[i]) {
  1969. qdf_flush_workqueue(0,
  1970. soc->wmi_pdev[i]->wmi_rx_work_queue);
  1971. qdf_destroy_workqueue(0,
  1972. soc->wmi_pdev[i]->wmi_rx_work_queue);
  1973. wmi_debugfs_remove(soc->wmi_pdev[i]);
  1974. buf = qdf_nbuf_queue_remove(
  1975. &soc->wmi_pdev[i]->event_queue);
  1976. while (buf) {
  1977. qdf_nbuf_free(buf);
  1978. buf = qdf_nbuf_queue_remove(
  1979. &soc->wmi_pdev[i]->event_queue);
  1980. }
  1981. wmi_log_buffer_free(soc->wmi_pdev[i]);
  1982. /* Free events logs list */
  1983. if (soc->wmi_pdev[i]->events_logs_list)
  1984. qdf_mem_free(
  1985. soc->wmi_pdev[i]->events_logs_list);
  1986. qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
  1987. qdf_mem_free(soc->wmi_pdev[i]);
  1988. }
  1989. }
  1990. qdf_spinlock_destroy(&soc->ctx_lock);
  1991. if (soc->wmi_service_bitmap) {
  1992. qdf_mem_free(soc->wmi_service_bitmap);
  1993. soc->wmi_service_bitmap = NULL;
  1994. }
  1995. if (soc->wmi_ext_service_bitmap) {
  1996. qdf_mem_free(soc->wmi_ext_service_bitmap);
  1997. soc->wmi_ext_service_bitmap = NULL;
  1998. }
  1999. /* Decrease the ref count once refcount infra is present */
  2000. soc->wmi_psoc = NULL;
  2001. qdf_mem_free(soc);
  2002. }
  2003. /**
  2004. * wmi_unified_remove_work() - detach for WMI work
  2005. * @wmi_handle: handle to WMI
  2006. *
  2007. * A function that does not fully detach WMI, but just remove work
  2008. * queue items associated with it. This is used to make sure that
  2009. * before any other processing code that may destroy related contexts
  2010. * (HTC, etc), work queue processing on WMI has already been stopped.
  2011. *
  2012. * Return: None
  2013. */
  2014. void
  2015. wmi_unified_remove_work(struct wmi_unified *wmi_handle)
  2016. {
  2017. wmi_buf_t buf;
  2018. qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
  2019. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  2020. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2021. while (buf) {
  2022. qdf_nbuf_free(buf);
  2023. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2024. }
  2025. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  2026. }
  2027. /**
  2028. * wmi_htc_tx_complete() - Process htc tx completion
  2029. *
  2030. * @ctx: handle to wmi
  2031. * @htc_packet: pointer to htc packet
  2032. *
  2033. * @Return: none.
  2034. */
  2035. static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
  2036. {
  2037. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  2038. wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
  2039. u_int8_t *buf_ptr;
  2040. u_int32_t len;
  2041. struct wmi_unified *wmi_handle;
  2042. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2043. uint32_t cmd_id;
  2044. #endif
  2045. ASSERT(wmi_cmd_buf);
  2046. wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
  2047. if (wmi_handle == NULL) {
  2048. WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
  2049. QDF_ASSERT(0);
  2050. return;
  2051. }
  2052. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2053. if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
  2054. cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
  2055. WMI_CMD_HDR, COMMANDID);
  2056. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  2057. /* Record 16 bytes of WMI cmd tx complete data
  2058. - exclude TLV and WMI headers */
  2059. if (wmi_handle->ops->is_management_record(cmd_id)) {
  2060. WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2061. qdf_nbuf_data(wmi_cmd_buf) +
  2062. wmi_handle->log_info.buf_offset_command);
  2063. } else {
  2064. WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2065. qdf_nbuf_data(wmi_cmd_buf) +
  2066. wmi_handle->log_info.buf_offset_command);
  2067. }
  2068. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  2069. }
  2070. #endif
  2071. buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
  2072. len = qdf_nbuf_len(wmi_cmd_buf);
  2073. qdf_mem_zero(buf_ptr, len);
  2074. qdf_nbuf_free(wmi_cmd_buf);
  2075. qdf_mem_free(htc_pkt);
  2076. qdf_atomic_dec(&wmi_handle->pending_cmds);
  2077. }
  2078. /**
  2079. * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
  2080. *
  2081. * @wmi_handle: handle to WMI.
  2082. * @pdev_idx: Pdev index
  2083. *
  2084. * @Return: status.
  2085. */
  2086. static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
  2087. uint32_t pdev_idx)
  2088. {
  2089. int status;
  2090. uint32_t svc_id[] = {WMI_CONTROL_SVC, WMI_CONTROL_SVC_WMAC1,
  2091. WMI_CONTROL_SVC_WMAC2};
  2092. struct htc_service_connect_resp response;
  2093. struct htc_service_connect_req connect;
  2094. OS_MEMZERO(&connect, sizeof(connect));
  2095. OS_MEMZERO(&response, sizeof(response));
  2096. /* meta data is unused for now */
  2097. connect.pMetaData = NULL;
  2098. connect.MetaDataLength = 0;
  2099. /* these fields are the same for all service endpoints */
  2100. connect.EpCallbacks.pContext = soc;
  2101. connect.EpCallbacks.EpTxCompleteMultiple =
  2102. NULL /* Control path completion ar6000_tx_complete */;
  2103. connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
  2104. connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
  2105. connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
  2106. connect.EpCallbacks.EpTxComplete =
  2107. wmi_htc_tx_complete /* ar6000_tx_queue_full */;
  2108. /* connect to control service */
  2109. connect.service_id = svc_id[pdev_idx];
  2110. status = htc_connect_service(soc->htc_handle, &connect,
  2111. &response);
  2112. if (status != EOK) {
  2113. qdf_print
  2114. ("Failed to connect to WMI CONTROL service status:%d\n",
  2115. status);
  2116. return status;
  2117. }
  2118. soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
  2119. soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
  2120. return 0;
  2121. }
  2122. /**
  2123. * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
  2124. *
  2125. * @wmi_handle: handle to WMI.
  2126. *
  2127. * @Return: status.
  2128. */
  2129. QDF_STATUS
  2130. wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
  2131. void *htc_handle)
  2132. {
  2133. uint32_t i;
  2134. uint8_t wmi_ep_count;
  2135. wmi_handle->soc->htc_handle = htc_handle;
  2136. wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
  2137. if (wmi_ep_count > WMI_MAX_RADIOS)
  2138. return QDF_STATUS_E_FAULT;
  2139. for (i = 0; i < wmi_ep_count; i++)
  2140. wmi_connect_pdev_htc_service(wmi_handle->soc, i);
  2141. wmi_handle->htc_handle = htc_handle;
  2142. wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
  2143. wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
  2144. return QDF_STATUS_SUCCESS;
  2145. }
  2146. /**
  2147. * wmi_get_host_credits() - WMI API to get updated host_credits
  2148. *
  2149. * @wmi_handle: handle to WMI.
  2150. *
  2151. * @Return: updated host_credits.
  2152. */
  2153. int wmi_get_host_credits(wmi_unified_t wmi_handle)
  2154. {
  2155. int host_credits = 0;
  2156. htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
  2157. &host_credits);
  2158. return host_credits;
  2159. }
  2160. /**
  2161. * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
  2162. * queue
  2163. *
  2164. * @wmi_handle: handle to WMI.
  2165. *
  2166. * @Return: Pending Commands in the HTC queue.
  2167. */
  2168. int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
  2169. {
  2170. return qdf_atomic_read(&wmi_handle->pending_cmds);
  2171. }
  2172. /**
  2173. * wmi_set_target_suspend() - WMI API to set target suspend state
  2174. *
  2175. * @wmi_handle: handle to WMI.
  2176. * @val: suspend state boolean.
  2177. *
  2178. * @Return: none.
  2179. */
  2180. void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
  2181. {
  2182. qdf_atomic_set(&wmi_handle->is_target_suspended, val);
  2183. }
  2184. /**
  2185. * WMI API to set crash injection state
  2186. * @param wmi_handle: handle to WMI.
  2187. * @param val: crash injection state boolean.
  2188. */
  2189. void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
  2190. {
  2191. wmi_handle->tag_crash_inject = flag;
  2192. }
  2193. /**
  2194. * WMI API to set bus suspend state
  2195. * @param wmi_handle: handle to WMI.
  2196. * @param val: suspend state boolean.
  2197. */
  2198. void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
  2199. {
  2200. qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
  2201. }
  2202. void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val)
  2203. {
  2204. wmi_handle->tgt_force_assert_enable = val;
  2205. }
  2206. #ifndef CONFIG_MCL
  2207. /**
  2208. * API to flush all the previous packets associated with the wmi endpoint
  2209. *
  2210. * @param wmi_handle : handle to WMI.
  2211. */
  2212. void
  2213. wmi_flush_endpoint(wmi_unified_t wmi_handle)
  2214. {
  2215. htc_flush_endpoint(wmi_handle->htc_handle,
  2216. wmi_handle->wmi_endpoint_id, 0);
  2217. }
  2218. /**
  2219. * generic function to block unified WMI command
  2220. * @param wmi_handle : handle to WMI.
  2221. * @return 0 on success and -ve on failure.
  2222. */
  2223. int
  2224. wmi_stop(wmi_unified_t wmi_handle)
  2225. {
  2226. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  2227. "WMI Stop\n");
  2228. wmi_handle->wmi_stopinprogress = 1;
  2229. return 0;
  2230. }
  2231. /**
  2232. * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI
  2233. * By default pdev_id conversion is not done in WMI.
  2234. * This API can be used enable conversion in WMI.
  2235. * @param wmi_handle : handle to WMI
  2236. * Return none
  2237. */
  2238. void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle)
  2239. {
  2240. if (wmi_handle->target_type == WMI_TLV_TARGET)
  2241. wmi_tlv_pdev_id_conversion_enable(wmi_handle);
  2242. }
  2243. #endif