wmi_unified.c 72 KB

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