wmi_unified.c 72 KB

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