wmi_unified.c 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184
  1. /*
  2. * Copyright (c) 2015-2020 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /*
  19. * Host WMI unified implementation
  20. */
  21. #include "htc_api.h"
  22. #include "htc_api.h"
  23. #include "wmi_unified_priv.h"
  24. #include "wmi_unified_api.h"
  25. #include "qdf_module.h"
  26. #include "qdf_platform.h"
  27. #ifdef WMI_EXT_DBG
  28. #include "qdf_list.h"
  29. #include "qdf_atomic.h"
  30. #endif
  31. #ifndef WMI_NON_TLV_SUPPORT
  32. #include "wmi_tlv_helper.h"
  33. #endif
  34. #include <linux/debugfs.h>
  35. #include <target_if.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. /* Copied from wmi.h */
  42. #undef MS
  43. #define MS(_v, _f) (((_v) & _f##_MASK) >> _f##_LSB)
  44. #undef SM
  45. #define SM(_v, _f) (((_v) << _f##_LSB) & _f##_MASK)
  46. #undef WO
  47. #define WO(_f) ((_f##_OFFSET) >> 2)
  48. #undef GET_FIELD
  49. #define GET_FIELD(_addr, _f) MS(*((uint32_t *)(_addr) + WO(_f)), _f)
  50. #undef SET_FIELD
  51. #define SET_FIELD(_addr, _f, _val) \
  52. (*((uint32_t *)(_addr) + WO(_f)) = \
  53. (*((uint32_t *)(_addr) + WO(_f)) & ~_f##_MASK) | SM(_val, _f))
  54. #define WMI_GET_FIELD(_msg_buf, _msg_type, _f) \
  55. GET_FIELD(_msg_buf, _msg_type ## _ ## _f)
  56. #define WMI_SET_FIELD(_msg_buf, _msg_type, _f, _val) \
  57. SET_FIELD(_msg_buf, _msg_type ## _ ## _f, _val)
  58. #define WMI_EP_APASS 0x0
  59. #define WMI_EP_LPASS 0x1
  60. #define WMI_EP_SENSOR 0x2
  61. /*
  62. * * Control Path
  63. * */
  64. typedef PREPACK struct {
  65. uint32_t commandId:24,
  66. reserved:2, /* used for WMI endpoint ID */
  67. plt_priv:6; /* platform private */
  68. } POSTPACK WMI_CMD_HDR; /* used for commands and events */
  69. #define WMI_CMD_HDR_COMMANDID_LSB 0
  70. #define WMI_CMD_HDR_COMMANDID_MASK 0x00ffffff
  71. #define WMI_CMD_HDR_COMMANDID_OFFSET 0x00000000
  72. #define WMI_CMD_HDR_WMI_ENDPOINTID_MASK 0x03000000
  73. #define WMI_CMD_HDR_WMI_ENDPOINTID_OFFSET 24
  74. #define WMI_CMD_HDR_PLT_PRIV_LSB 24
  75. #define WMI_CMD_HDR_PLT_PRIV_MASK 0xff000000
  76. #define WMI_CMD_HDR_PLT_PRIV_OFFSET 0x00000000
  77. /* end of copy wmi.h */
  78. #define WMI_MIN_HEAD_ROOM 64
  79. /* WBUFF pool sizes for WMI */
  80. /* Allocation of size 256 bytes */
  81. #define WMI_WBUFF_POOL_0_SIZE 128
  82. /* Allocation of size 512 bytes */
  83. #define WMI_WBUFF_POOL_1_SIZE 16
  84. /* Allocation of size 1024 bytes */
  85. #define WMI_WBUFF_POOL_2_SIZE 8
  86. /* Allocation of size 2048 bytes */
  87. #define WMI_WBUFF_POOL_3_SIZE 8
  88. #ifdef WMI_INTERFACE_EVENT_LOGGING
  89. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0))
  90. /* TODO Cleanup this backported function */
  91. static int wmi_bp_seq_printf(struct seq_file *m, const char *f, ...)
  92. {
  93. va_list args;
  94. va_start(args, f);
  95. seq_vprintf(m, f, args);
  96. va_end(args);
  97. return 0;
  98. }
  99. #else
  100. #define wmi_bp_seq_printf(m, fmt, ...) seq_printf((m), fmt, ##__VA_ARGS__)
  101. #endif
  102. #ifndef MAX_WMI_INSTANCES
  103. #define CUSTOM_MGMT_CMD_DATA_SIZE 4
  104. #endif
  105. #ifndef WMI_INTERFACE_EVENT_LOGGING_DYNAMIC_ALLOC
  106. /* WMI commands */
  107. uint32_t g_wmi_command_buf_idx = 0;
  108. struct wmi_command_debug wmi_command_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  109. /* WMI commands TX completed */
  110. uint32_t g_wmi_command_tx_cmp_buf_idx = 0;
  111. struct wmi_command_debug
  112. wmi_command_tx_cmp_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  113. /* WMI events when processed */
  114. uint32_t g_wmi_event_buf_idx = 0;
  115. struct wmi_event_debug wmi_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  116. /* WMI events when queued */
  117. uint32_t g_wmi_rx_event_buf_idx = 0;
  118. struct wmi_event_debug wmi_rx_event_log_buffer[WMI_EVENT_DEBUG_MAX_ENTRY];
  119. #endif
  120. #define WMI_COMMAND_RECORD(h, a, b) { \
  121. if (wmi_log_max_entry <= \
  122. *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)) \
  123. *(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx) = 0;\
  124. ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
  125. [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)]\
  126. .command = a; \
  127. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  128. wmi_command_log_buf_info.buf) \
  129. [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].data,\
  130. b, wmi_record_max_length); \
  131. ((struct wmi_command_debug *)h->log_info.wmi_command_log_buf_info.buf)\
  132. [*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx)].\
  133. time = qdf_get_log_timestamp(); \
  134. (*(h->log_info.wmi_command_log_buf_info.p_buf_tail_idx))++; \
  135. h->log_info.wmi_command_log_buf_info.length++; \
  136. }
  137. #define WMI_COMMAND_TX_CMP_RECORD(h, a, b) { \
  138. if (wmi_log_max_entry <= \
  139. *(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))\
  140. *(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  141. p_buf_tail_idx) = 0; \
  142. ((struct wmi_command_debug *)h->log_info. \
  143. wmi_command_tx_cmp_log_buf_info.buf) \
  144. [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  145. p_buf_tail_idx)]. \
  146. command = a; \
  147. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  148. wmi_command_tx_cmp_log_buf_info.buf) \
  149. [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  150. p_buf_tail_idx)]. \
  151. data, b, wmi_record_max_length); \
  152. ((struct wmi_command_debug *)h->log_info. \
  153. wmi_command_tx_cmp_log_buf_info.buf) \
  154. [*(h->log_info.wmi_command_tx_cmp_log_buf_info. \
  155. p_buf_tail_idx)]. \
  156. time = qdf_get_log_timestamp(); \
  157. (*(h->log_info.wmi_command_tx_cmp_log_buf_info.p_buf_tail_idx))++;\
  158. h->log_info.wmi_command_tx_cmp_log_buf_info.length++; \
  159. }
  160. #define WMI_EVENT_RECORD(h, a, b) { \
  161. if (wmi_log_max_entry <= \
  162. *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)) \
  163. *(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx) = 0;\
  164. ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
  165. [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)]. \
  166. event = a; \
  167. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  168. wmi_event_log_buf_info.buf) \
  169. [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].data, b,\
  170. wmi_record_max_length); \
  171. ((struct wmi_event_debug *)h->log_info.wmi_event_log_buf_info.buf)\
  172. [*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx)].time =\
  173. qdf_get_log_timestamp(); \
  174. (*(h->log_info.wmi_event_log_buf_info.p_buf_tail_idx))++; \
  175. h->log_info.wmi_event_log_buf_info.length++; \
  176. }
  177. #define WMI_RX_EVENT_RECORD(h, a, b) { \
  178. if (wmi_log_max_entry <= \
  179. *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))\
  180. *(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx) = 0;\
  181. ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
  182. [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
  183. event = a; \
  184. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  185. wmi_rx_event_log_buf_info.buf) \
  186. [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
  187. data, b, wmi_record_max_length); \
  188. ((struct wmi_event_debug *)h->log_info.wmi_rx_event_log_buf_info.buf)\
  189. [*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx)].\
  190. time = qdf_get_log_timestamp(); \
  191. (*(h->log_info.wmi_rx_event_log_buf_info.p_buf_tail_idx))++; \
  192. h->log_info.wmi_rx_event_log_buf_info.length++; \
  193. }
  194. #ifndef WMI_INTERFACE_EVENT_LOGGING_DYNAMIC_ALLOC
  195. uint32_t g_wmi_mgmt_command_buf_idx = 0;
  196. struct
  197. wmi_command_debug wmi_mgmt_command_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
  198. /* wmi_mgmt commands TX completed */
  199. uint32_t g_wmi_mgmt_command_tx_cmp_buf_idx = 0;
  200. struct wmi_command_debug
  201. wmi_mgmt_command_tx_cmp_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
  202. /* wmi_mgmt events when received */
  203. uint32_t g_wmi_mgmt_rx_event_buf_idx = 0;
  204. struct wmi_event_debug
  205. wmi_mgmt_rx_event_log_buffer[WMI_MGMT_EVENT_DEBUG_MAX_ENTRY];
  206. /* wmi_diag events when received */
  207. uint32_t g_wmi_diag_rx_event_buf_idx = 0;
  208. struct wmi_event_debug
  209. wmi_diag_rx_event_log_buffer[WMI_DIAG_RX_EVENT_DEBUG_MAX_ENTRY];
  210. #endif
  211. #define WMI_MGMT_COMMAND_RECORD(h, a, b) { \
  212. if (wmi_mgmt_log_max_entry <= \
  213. *(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)) \
  214. *(h->log_info.wmi_mgmt_command_log_buf_info. \
  215. p_buf_tail_idx) = 0; \
  216. ((struct wmi_command_debug *)h->log_info. \
  217. wmi_mgmt_command_log_buf_info.buf) \
  218. [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
  219. command = a; \
  220. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  221. wmi_mgmt_command_log_buf_info.buf) \
  222. [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
  223. data, b, \
  224. wmi_record_max_length); \
  225. ((struct wmi_command_debug *)h->log_info. \
  226. wmi_mgmt_command_log_buf_info.buf) \
  227. [*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx)].\
  228. time = qdf_get_log_timestamp(); \
  229. (*(h->log_info.wmi_mgmt_command_log_buf_info.p_buf_tail_idx))++;\
  230. h->log_info.wmi_mgmt_command_log_buf_info.length++; \
  231. }
  232. #define WMI_MGMT_COMMAND_TX_CMP_RECORD(h, a, b) { \
  233. if (wmi_mgmt_log_max_entry <= \
  234. *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  235. p_buf_tail_idx)) \
  236. *(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  237. p_buf_tail_idx) = 0; \
  238. ((struct wmi_command_debug *)h->log_info. \
  239. wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
  240. [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  241. p_buf_tail_idx)].command = a; \
  242. qdf_mem_copy(((struct wmi_command_debug *)h->log_info. \
  243. wmi_mgmt_command_tx_cmp_log_buf_info.buf)\
  244. [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  245. p_buf_tail_idx)].data, b, \
  246. wmi_record_max_length); \
  247. ((struct wmi_command_debug *)h->log_info. \
  248. wmi_mgmt_command_tx_cmp_log_buf_info.buf) \
  249. [*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  250. p_buf_tail_idx)].time = \
  251. qdf_get_log_timestamp(); \
  252. (*(h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info. \
  253. p_buf_tail_idx))++; \
  254. h->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.length++; \
  255. }
  256. #define WMI_MGMT_RX_EVENT_RECORD(h, a, b) do { \
  257. if (wmi_mgmt_log_max_entry <= \
  258. *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))\
  259. *(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx) = 0;\
  260. ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
  261. [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)]\
  262. .event = a; \
  263. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  264. wmi_mgmt_event_log_buf_info.buf) \
  265. [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
  266. data, b, wmi_record_max_length); \
  267. ((struct wmi_event_debug *)h->log_info.wmi_mgmt_event_log_buf_info.buf)\
  268. [*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx)].\
  269. time = qdf_get_log_timestamp(); \
  270. (*(h->log_info.wmi_mgmt_event_log_buf_info.p_buf_tail_idx))++; \
  271. h->log_info.wmi_mgmt_event_log_buf_info.length++; \
  272. } while (0);
  273. #define WMI_DIAG_RX_EVENT_RECORD(h, a, b) do { \
  274. if (wmi_diag_log_max_entry <= \
  275. *(h->log_info.wmi_diag_event_log_buf_info.p_buf_tail_idx))\
  276. *(h->log_info.wmi_diag_event_log_buf_info.p_buf_tail_idx) = 0;\
  277. ((struct wmi_event_debug *)h->log_info.wmi_diag_event_log_buf_info.buf)\
  278. [*(h->log_info.wmi_diag_event_log_buf_info.p_buf_tail_idx)]\
  279. .event = a; \
  280. qdf_mem_copy(((struct wmi_event_debug *)h->log_info. \
  281. wmi_diag_event_log_buf_info.buf) \
  282. [*(h->log_info.wmi_diag_event_log_buf_info.p_buf_tail_idx)].\
  283. data, b, wmi_record_max_length); \
  284. ((struct wmi_event_debug *)h->log_info.wmi_diag_event_log_buf_info.buf)\
  285. [*(h->log_info.wmi_diag_event_log_buf_info.p_buf_tail_idx)].\
  286. time = qdf_get_log_timestamp(); \
  287. (*(h->log_info.wmi_diag_event_log_buf_info.p_buf_tail_idx))++; \
  288. h->log_info.wmi_diag_event_log_buf_info.length++; \
  289. } while (0);
  290. /* These are defined to made it as module param, which can be configured */
  291. uint32_t wmi_log_max_entry = WMI_EVENT_DEBUG_MAX_ENTRY;
  292. uint32_t wmi_mgmt_log_max_entry = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  293. uint32_t wmi_diag_log_max_entry = WMI_DIAG_RX_EVENT_DEBUG_MAX_ENTRY;
  294. uint32_t wmi_record_max_length = WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH;
  295. uint32_t wmi_display_size = 100;
  296. #ifdef WMI_EXT_DBG
  297. /**
  298. * wmi_ext_dbg_msg_enqueue() - enqueue wmi message
  299. *
  300. * @wmi_handle: wmi handler
  301. *
  302. * Return: size of wmi message queue after enqueue
  303. */
  304. static uint32_t wmi_ext_dbg_msg_enqueue(struct wmi_unified *wmi_handle,
  305. struct wmi_ext_dbg_msg *msg)
  306. {
  307. uint32_t list_size;
  308. qdf_spinlock_acquire(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
  309. qdf_list_insert_back_size(&wmi_handle->wmi_ext_dbg_msg_queue,
  310. &msg->node, &list_size);
  311. qdf_spinlock_release(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
  312. return list_size;
  313. }
  314. /**
  315. * wmi_ext_dbg_msg_dequeue() - dequeue wmi message
  316. *
  317. * @wmi_handle: wmi handler
  318. *
  319. * Return: wmi msg on success else NULL
  320. */
  321. static struct wmi_ext_dbg_msg *wmi_ext_dbg_msg_dequeue(struct wmi_unified
  322. *wmi_handle)
  323. {
  324. qdf_list_node_t *list_node = NULL;
  325. qdf_spinlock_acquire(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
  326. qdf_list_remove_front(&wmi_handle->wmi_ext_dbg_msg_queue, &list_node);
  327. qdf_spinlock_release(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
  328. if (!list_node)
  329. return NULL;
  330. return qdf_container_of(list_node, struct wmi_ext_dbg_msg, node);
  331. }
  332. /**
  333. * wmi_ext_dbg_msg_record() - record wmi messages
  334. *
  335. * @wmi_handle: wmi handler
  336. * @buf: wmi message buffer
  337. * @len: wmi message length
  338. * @type: wmi message type
  339. *
  340. * Return: QDF_STATUS_SUCCESS on successful recording else failure.
  341. */
  342. static QDF_STATUS wmi_ext_dbg_msg_record(struct wmi_unified *wmi_handle,
  343. uint8_t *buf, uint32_t len,
  344. enum WMI_MSG_TYPE type)
  345. {
  346. struct wmi_ext_dbg_msg *msg;
  347. uint32_t list_size;
  348. msg = wmi_ext_dbg_msg_get(len);
  349. if (!msg)
  350. return QDF_STATUS_E_NOMEM;
  351. msg->len = len;
  352. msg->type = type;
  353. qdf_mem_copy(msg->buf, buf, len);
  354. msg->ts = qdf_get_log_timestamp();
  355. list_size = wmi_ext_dbg_msg_enqueue(wmi_handle, msg);
  356. if (list_size >= wmi_handle->wmi_ext_dbg_msg_queue_size) {
  357. msg = wmi_ext_dbg_msg_dequeue(wmi_handle);
  358. wmi_ext_dbg_msg_put(msg);
  359. }
  360. return QDF_STATUS_SUCCESS;
  361. }
  362. /**
  363. * wmi_ext_dbg_msg_cmd_record() - record wmi command messages
  364. *
  365. * @wmi_handle: wmi handler
  366. * @buf: wmi command buffer
  367. * @len: wmi command message length
  368. *
  369. * Return: QDF_STATUS_SUCCESS on successful recording else failure.
  370. */
  371. static QDF_STATUS wmi_ext_dbg_msg_cmd_record(struct wmi_unified *wmi_handle,
  372. uint8_t *buf, uint32_t len)
  373. {
  374. return wmi_ext_dbg_msg_record(wmi_handle, buf, len,
  375. WMI_MSG_TYPE_CMD);
  376. }
  377. /**
  378. * wmi_ext_dbg_msg_event_record() - record wmi event messages
  379. *
  380. * @wmi_handle: wmi handler
  381. * @buf: wmi event buffer
  382. * @len: wmi event message length
  383. *
  384. * Return: QDF_STATUS_SUCCESS on successful recording else failure.
  385. */
  386. static QDF_STATUS wmi_ext_dbg_msg_event_record(struct wmi_unified *wmi_handle,
  387. uint8_t *buf, uint32_t len)
  388. {
  389. uint32_t id;
  390. id = WMI_GET_FIELD(buf, WMI_CMD_HDR, COMMANDID);
  391. if (id != wmi_handle->wmi_events[wmi_diag_event_id])
  392. return wmi_ext_dbg_msg_record(wmi_handle, buf, len,
  393. WMI_MSG_TYPE_EVENT);
  394. return QDF_STATUS_SUCCESS;
  395. }
  396. /**
  397. * wmi_ext_dbg_msg_queue_init() - create debugfs queue and associated lock
  398. *
  399. * @wmi_handle: wmi handler
  400. *
  401. * Return: none
  402. */
  403. static void wmi_ext_dbg_msg_queue_init(struct wmi_unified *wmi_handle)
  404. {
  405. qdf_list_create(&wmi_handle->wmi_ext_dbg_msg_queue,
  406. wmi_handle->wmi_ext_dbg_msg_queue_size);
  407. qdf_spinlock_create(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
  408. }
  409. /**
  410. * wmi_ext_dbg_msg_queue_deinit() - destroy debugfs queue and associated lock
  411. *
  412. * @wmi_handle: wmi handler
  413. *
  414. * Return: none
  415. */
  416. static void wmi_ext_dbg_msg_queue_deinit(struct wmi_unified *wmi_handle)
  417. {
  418. qdf_list_destroy(&wmi_handle->wmi_ext_dbg_msg_queue);
  419. qdf_spinlock_destroy(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
  420. }
  421. /**
  422. * wmi_ext_dbg_msg_show() - debugfs function to display whole content of
  423. * wmi command/event messages including headers.
  424. *
  425. * @file: qdf debugfs file handler
  426. * @arg: pointer to wmi handler
  427. *
  428. * Return: QDF_STATUS_SUCCESS if all the messages are shown successfully,
  429. * else QDF_STATUS_E_AGAIN if more data to show.
  430. */
  431. static QDF_STATUS wmi_ext_dbg_msg_show(qdf_debugfs_file_t file, void *arg)
  432. {
  433. struct wmi_unified *wmi_handle = (struct wmi_unified *)arg;
  434. struct wmi_ext_dbg_msg *msg;
  435. uint64_t secs, usecs;
  436. msg = wmi_ext_dbg_msg_dequeue(wmi_handle);
  437. if (!msg)
  438. return QDF_STATUS_SUCCESS;
  439. qdf_debugfs_printf(file, "%s: 0x%x\n",
  440. msg->type == WMI_MSG_TYPE_CMD ? "COMMAND" :
  441. "EVENT", WMI_GET_FIELD(msg->buf, WMI_CMD_HDR,
  442. COMMANDID));
  443. qdf_log_timestamp_to_secs(msg->ts, &secs, &usecs);
  444. qdf_debugfs_printf(file, "Time: %llu.%llu\n", secs, usecs);
  445. qdf_debugfs_printf(file, "Length:%d\n", msg->len);
  446. qdf_debugfs_hexdump(file, msg->buf, msg->len,
  447. WMI_EXT_DBG_DUMP_ROW_SIZE,
  448. WMI_EXT_DBG_DUMP_GROUP_SIZE);
  449. qdf_debugfs_printf(file, "\n");
  450. if (qdf_debugfs_overflow(file)) {
  451. qdf_spinlock_acquire(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
  452. qdf_list_insert_front(&wmi_handle->wmi_ext_dbg_msg_queue,
  453. &msg->node);
  454. qdf_spinlock_release(&wmi_handle->wmi_ext_dbg_msg_queue_lock);
  455. } else {
  456. wmi_ext_dbg_msg_put(msg);
  457. }
  458. return QDF_STATUS_E_AGAIN;
  459. }
  460. /**
  461. * wmi_ext_dbg_msg_write() - debugfs write not supported
  462. *
  463. * @priv: private data
  464. * @buf: received data buffer
  465. * @len: length of received buffer
  466. *
  467. * Return: QDF_STATUS_E_NOSUPPORT.
  468. */
  469. static QDF_STATUS wmi_ext_dbg_msg_write(void *priv, const char *buf,
  470. qdf_size_t len)
  471. {
  472. return QDF_STATUS_E_NOSUPPORT;
  473. }
  474. static struct qdf_debugfs_fops wmi_ext_dbgfs_ops = {
  475. .show = wmi_ext_dbg_msg_show,
  476. .write = wmi_ext_dbg_msg_write,
  477. .priv = NULL,
  478. };
  479. /**
  480. * wmi_ext_debugfs_init() - init debugfs items for extended wmi dump.
  481. *
  482. * @wmi_handle: wmi handler
  483. *
  484. * Return: QDF_STATUS_SUCCESS if debugfs is initialized else
  485. * QDF_STATUS_E_FAILURE
  486. */
  487. static QDF_STATUS wmi_ext_dbgfs_init(struct wmi_unified *wmi_handle)
  488. {
  489. qdf_dentry_t dentry;
  490. dentry = qdf_debugfs_create_dir(WMI_EXT_DBG_DIR, NULL);
  491. if (!dentry) {
  492. WMI_LOGE("error while creating extended wmi debugfs dir");
  493. return QDF_STATUS_E_FAILURE;
  494. }
  495. wmi_ext_dbgfs_ops.priv = wmi_handle;
  496. if (!qdf_debugfs_create_file(WMI_EXT_DBG_FILE, WMI_EXT_DBG_FILE_PERM,
  497. dentry, &wmi_ext_dbgfs_ops)) {
  498. qdf_debugfs_remove_dir(dentry);
  499. WMI_LOGE("error while creating extended wmi debugfs file");
  500. return QDF_STATUS_E_FAILURE;
  501. }
  502. wmi_handle->wmi_ext_dbg_dentry = dentry;
  503. wmi_handle->wmi_ext_dbg_msg_queue_size = WMI_EXT_DBG_QUEUE_SIZE;
  504. wmi_ext_dbg_msg_queue_init(wmi_handle);
  505. return QDF_STATUS_SUCCESS;
  506. }
  507. /**
  508. * wmi_ext_debugfs_deinit() - cleanup/deinit debugfs items of extended wmi dump.
  509. *
  510. * @wmi_handle: wmi handler
  511. *
  512. * Return: QDF_STATUS_SUCCESS if cleanup is successful
  513. */
  514. static QDF_STATUS wmi_ext_dbgfs_deinit(struct wmi_unified *wmi_handle)
  515. {
  516. struct wmi_ext_dbg_msg *msg;
  517. while ((msg = wmi_ext_dbg_msg_dequeue(wmi_handle)))
  518. wmi_ext_dbg_msg_put(msg);
  519. wmi_ext_dbg_msg_queue_deinit(wmi_handle);
  520. qdf_debugfs_remove_dir_recursive(wmi_handle->wmi_ext_dbg_dentry);
  521. return QDF_STATUS_SUCCESS;
  522. }
  523. #endif /*WMI_EXT_DBG */
  524. /**
  525. * wmi_log_init() - Initialize WMI event logging
  526. * @wmi_handle: WMI handle.
  527. *
  528. * Return: Initialization status
  529. */
  530. #ifndef WMI_INTERFACE_EVENT_LOGGING_DYNAMIC_ALLOC
  531. static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
  532. {
  533. struct wmi_log_buf_t *cmd_log_buf =
  534. &wmi_handle->log_info.wmi_command_log_buf_info;
  535. struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
  536. &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
  537. struct wmi_log_buf_t *event_log_buf =
  538. &wmi_handle->log_info.wmi_event_log_buf_info;
  539. struct wmi_log_buf_t *rx_event_log_buf =
  540. &wmi_handle->log_info.wmi_rx_event_log_buf_info;
  541. struct wmi_log_buf_t *mgmt_cmd_log_buf =
  542. &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
  543. struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
  544. &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
  545. struct wmi_log_buf_t *mgmt_event_log_buf =
  546. &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
  547. struct wmi_log_buf_t *diag_event_log_buf =
  548. &wmi_handle->log_info.wmi_diag_event_log_buf_info;
  549. /* WMI commands */
  550. cmd_log_buf->length = 0;
  551. cmd_log_buf->buf_tail_idx = 0;
  552. cmd_log_buf->buf = wmi_command_log_buffer;
  553. cmd_log_buf->p_buf_tail_idx = &g_wmi_command_buf_idx;
  554. cmd_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  555. /* WMI commands TX completed */
  556. cmd_tx_cmpl_log_buf->length = 0;
  557. cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
  558. cmd_tx_cmpl_log_buf->buf = wmi_command_tx_cmp_log_buffer;
  559. cmd_tx_cmpl_log_buf->p_buf_tail_idx = &g_wmi_command_tx_cmp_buf_idx;
  560. cmd_tx_cmpl_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  561. /* WMI events when processed */
  562. event_log_buf->length = 0;
  563. event_log_buf->buf_tail_idx = 0;
  564. event_log_buf->buf = wmi_event_log_buffer;
  565. event_log_buf->p_buf_tail_idx = &g_wmi_event_buf_idx;
  566. event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  567. /* WMI events when queued */
  568. rx_event_log_buf->length = 0;
  569. rx_event_log_buf->buf_tail_idx = 0;
  570. rx_event_log_buf->buf = wmi_rx_event_log_buffer;
  571. rx_event_log_buf->p_buf_tail_idx = &g_wmi_rx_event_buf_idx;
  572. rx_event_log_buf->size = WMI_EVENT_DEBUG_MAX_ENTRY;
  573. /* WMI Management commands */
  574. mgmt_cmd_log_buf->length = 0;
  575. mgmt_cmd_log_buf->buf_tail_idx = 0;
  576. mgmt_cmd_log_buf->buf = wmi_mgmt_command_log_buffer;
  577. mgmt_cmd_log_buf->p_buf_tail_idx = &g_wmi_mgmt_command_buf_idx;
  578. mgmt_cmd_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  579. /* WMI Management commands Tx completed*/
  580. mgmt_cmd_tx_cmp_log_buf->length = 0;
  581. mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
  582. mgmt_cmd_tx_cmp_log_buf->buf = wmi_mgmt_command_tx_cmp_log_buffer;
  583. mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
  584. &g_wmi_mgmt_command_tx_cmp_buf_idx;
  585. mgmt_cmd_tx_cmp_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  586. /* WMI Management events when received */
  587. mgmt_event_log_buf->length = 0;
  588. mgmt_event_log_buf->buf_tail_idx = 0;
  589. mgmt_event_log_buf->buf = wmi_mgmt_rx_event_log_buffer;
  590. mgmt_event_log_buf->p_buf_tail_idx = &g_wmi_mgmt_rx_event_buf_idx;
  591. mgmt_event_log_buf->size = WMI_MGMT_EVENT_DEBUG_MAX_ENTRY;
  592. /* WMI diag events when received */
  593. diag_event_log_buf->length = 0;
  594. diag_event_log_buf->buf_tail_idx = 0;
  595. diag_event_log_buf->buf = wmi_diag_rx_event_log_buffer;
  596. diag_event_log_buf->p_buf_tail_idx = &g_wmi_diag_rx_event_buf_idx;
  597. diag_event_log_buf->size = WMI_DIAG_RX_EVENT_DEBUG_MAX_ENTRY;
  598. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  599. wmi_handle->log_info.wmi_logging_enable = 1;
  600. return QDF_STATUS_SUCCESS;
  601. }
  602. #else
  603. static QDF_STATUS wmi_log_init(struct wmi_unified *wmi_handle)
  604. {
  605. struct wmi_log_buf_t *cmd_log_buf =
  606. &wmi_handle->log_info.wmi_command_log_buf_info;
  607. struct wmi_log_buf_t *cmd_tx_cmpl_log_buf =
  608. &wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info;
  609. struct wmi_log_buf_t *event_log_buf =
  610. &wmi_handle->log_info.wmi_event_log_buf_info;
  611. struct wmi_log_buf_t *rx_event_log_buf =
  612. &wmi_handle->log_info.wmi_rx_event_log_buf_info;
  613. struct wmi_log_buf_t *mgmt_cmd_log_buf =
  614. &wmi_handle->log_info.wmi_mgmt_command_log_buf_info;
  615. struct wmi_log_buf_t *mgmt_cmd_tx_cmp_log_buf =
  616. &wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info;
  617. struct wmi_log_buf_t *mgmt_event_log_buf =
  618. &wmi_handle->log_info.wmi_mgmt_event_log_buf_info;
  619. struct wmi_log_buf_t *diag_event_log_buf =
  620. &wmi_handle->log_info.wmi_diag_event_log_buf_info;
  621. wmi_handle->log_info.wmi_logging_enable = 0;
  622. /* WMI commands */
  623. cmd_log_buf->length = 0;
  624. cmd_log_buf->buf_tail_idx = 0;
  625. cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
  626. wmi_log_max_entry * sizeof(struct wmi_command_debug));
  627. cmd_log_buf->size = wmi_log_max_entry;
  628. if (!cmd_log_buf->buf)
  629. return QDF_STATUS_E_NOMEM;
  630. cmd_log_buf->p_buf_tail_idx = &cmd_log_buf->buf_tail_idx;
  631. /* WMI commands TX completed */
  632. cmd_tx_cmpl_log_buf->length = 0;
  633. cmd_tx_cmpl_log_buf->buf_tail_idx = 0;
  634. cmd_tx_cmpl_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
  635. wmi_log_max_entry * sizeof(struct wmi_command_debug));
  636. cmd_tx_cmpl_log_buf->size = wmi_log_max_entry;
  637. if (!cmd_tx_cmpl_log_buf->buf)
  638. return QDF_STATUS_E_NOMEM;
  639. cmd_tx_cmpl_log_buf->p_buf_tail_idx =
  640. &cmd_tx_cmpl_log_buf->buf_tail_idx;
  641. /* WMI events when processed */
  642. event_log_buf->length = 0;
  643. event_log_buf->buf_tail_idx = 0;
  644. event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  645. wmi_log_max_entry * sizeof(struct wmi_event_debug));
  646. event_log_buf->size = wmi_log_max_entry;
  647. if (!event_log_buf->buf)
  648. return QDF_STATUS_E_NOMEM;
  649. event_log_buf->p_buf_tail_idx = &event_log_buf->buf_tail_idx;
  650. /* WMI events when queued */
  651. rx_event_log_buf->length = 0;
  652. rx_event_log_buf->buf_tail_idx = 0;
  653. rx_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  654. wmi_log_max_entry * sizeof(struct wmi_event_debug));
  655. rx_event_log_buf->size = wmi_log_max_entry;
  656. if (!rx_event_log_buf->buf)
  657. return QDF_STATUS_E_NOMEM;
  658. rx_event_log_buf->p_buf_tail_idx = &rx_event_log_buf->buf_tail_idx;
  659. /* WMI Management commands */
  660. mgmt_cmd_log_buf->length = 0;
  661. mgmt_cmd_log_buf->buf_tail_idx = 0;
  662. mgmt_cmd_log_buf->buf = (struct wmi_command_debug *) qdf_mem_malloc(
  663. wmi_mgmt_log_max_entry * sizeof(struct wmi_command_debug));
  664. mgmt_cmd_log_buf->size = wmi_mgmt_log_max_entry;
  665. if (!mgmt_cmd_log_buf->buf)
  666. return QDF_STATUS_E_NOMEM;
  667. mgmt_cmd_log_buf->p_buf_tail_idx = &mgmt_cmd_log_buf->buf_tail_idx;
  668. /* WMI Management commands Tx completed*/
  669. mgmt_cmd_tx_cmp_log_buf->length = 0;
  670. mgmt_cmd_tx_cmp_log_buf->buf_tail_idx = 0;
  671. mgmt_cmd_tx_cmp_log_buf->buf = (struct wmi_command_debug *)
  672. qdf_mem_malloc(
  673. wmi_mgmt_log_max_entry *
  674. sizeof(struct wmi_command_debug));
  675. mgmt_cmd_tx_cmp_log_buf->size = wmi_mgmt_log_max_entry;
  676. if (!mgmt_cmd_tx_cmp_log_buf->buf)
  677. return QDF_STATUS_E_NOMEM;
  678. mgmt_cmd_tx_cmp_log_buf->p_buf_tail_idx =
  679. &mgmt_cmd_tx_cmp_log_buf->buf_tail_idx;
  680. /* WMI Management events when received */
  681. mgmt_event_log_buf->length = 0;
  682. mgmt_event_log_buf->buf_tail_idx = 0;
  683. mgmt_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  684. wmi_mgmt_log_max_entry *
  685. sizeof(struct wmi_event_debug));
  686. mgmt_event_log_buf->size = wmi_mgmt_log_max_entry;
  687. if (!mgmt_event_log_buf->buf)
  688. return QDF_STATUS_E_NOMEM;
  689. mgmt_event_log_buf->p_buf_tail_idx = &mgmt_event_log_buf->buf_tail_idx;
  690. /* WMI diag events when received */
  691. diag_event_log_buf->length = 0;
  692. diag_event_log_buf->buf_tail_idx = 0;
  693. diag_event_log_buf->buf = (struct wmi_event_debug *) qdf_mem_malloc(
  694. wmi_diag_log_max_entry *
  695. sizeof(struct wmi_event_debug));
  696. diag_event_log_buf->size = wmi_diag_log_max_entry;
  697. if (!diag_event_log_buf->buf)
  698. return QDF_STATUS_E_NOMEM;
  699. diag_event_log_buf->p_buf_tail_idx = &diag_event_log_buf->buf_tail_idx;
  700. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  701. wmi_handle->log_info.wmi_logging_enable = 1;
  702. return QDF_STATUS_SUCCESS;
  703. }
  704. #endif
  705. /**
  706. * wmi_log_buffer_free() - Free all dynamic allocated buffer memory for
  707. * event logging
  708. * @wmi_handle: WMI handle.
  709. *
  710. * Return: None
  711. */
  712. #ifdef WMI_INTERFACE_EVENT_LOGGING_DYNAMIC_ALLOC
  713. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
  714. {
  715. if (wmi_handle->log_info.wmi_command_log_buf_info.buf)
  716. qdf_mem_free(wmi_handle->log_info.wmi_command_log_buf_info.buf);
  717. if (wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf)
  718. qdf_mem_free(
  719. wmi_handle->log_info.wmi_command_tx_cmp_log_buf_info.buf);
  720. if (wmi_handle->log_info.wmi_event_log_buf_info.buf)
  721. qdf_mem_free(wmi_handle->log_info.wmi_event_log_buf_info.buf);
  722. if (wmi_handle->log_info.wmi_rx_event_log_buf_info.buf)
  723. qdf_mem_free(
  724. wmi_handle->log_info.wmi_rx_event_log_buf_info.buf);
  725. if (wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf)
  726. qdf_mem_free(
  727. wmi_handle->log_info.wmi_mgmt_command_log_buf_info.buf);
  728. if (wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf)
  729. qdf_mem_free(
  730. wmi_handle->log_info.wmi_mgmt_command_tx_cmp_log_buf_info.buf);
  731. if (wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf)
  732. qdf_mem_free(
  733. wmi_handle->log_info.wmi_mgmt_event_log_buf_info.buf);
  734. if (wmi_handle->log_info.wmi_diag_event_log_buf_info.buf)
  735. qdf_mem_free(
  736. wmi_handle->log_info.wmi_diag_event_log_buf_info.buf);
  737. wmi_handle->log_info.wmi_logging_enable = 0;
  738. qdf_spinlock_destroy(&wmi_handle->log_info.wmi_record_lock);
  739. }
  740. #else
  741. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle)
  742. {
  743. /* Do Nothing */
  744. }
  745. #endif
  746. /**
  747. * wmi_print_cmd_log_buffer() - an output agnostic wmi command log printer
  748. * @log_buffer: the command log buffer metadata of the buffer to print
  749. * @count: the maximum number of entries to print
  750. * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
  751. * @print_priv: any data required by the print method, e.g. a file handle
  752. *
  753. * Return: None
  754. */
  755. static void
  756. wmi_print_cmd_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
  757. qdf_abstract_print *print, void *print_priv)
  758. {
  759. static const int data_len =
  760. WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
  761. char str[128];
  762. uint32_t idx;
  763. if (count > log_buffer->size)
  764. count = log_buffer->size;
  765. if (count > log_buffer->length)
  766. count = log_buffer->length;
  767. /* subtract count from index, and wrap if necessary */
  768. idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
  769. idx %= log_buffer->size;
  770. print(print_priv, "Time (seconds) Cmd Id Payload");
  771. while (count) {
  772. struct wmi_command_debug *cmd_log = (struct wmi_command_debug *)
  773. &((struct wmi_command_debug *)log_buffer->buf)[idx];
  774. uint64_t secs, usecs;
  775. int len = 0;
  776. int i;
  777. qdf_log_timestamp_to_secs(cmd_log->time, &secs, &usecs);
  778. len += scnprintf(str + len, sizeof(str) - len,
  779. "% 8lld.%06lld %6u (0x%06x) ",
  780. secs, usecs,
  781. cmd_log->command, cmd_log->command);
  782. for (i = 0; i < data_len; ++i) {
  783. len += scnprintf(str + len, sizeof(str) - len,
  784. "0x%08x ", cmd_log->data[i]);
  785. }
  786. print(print_priv, str);
  787. --count;
  788. ++idx;
  789. if (idx >= log_buffer->size)
  790. idx = 0;
  791. }
  792. }
  793. /**
  794. * wmi_print_event_log_buffer() - an output agnostic wmi event log printer
  795. * @log_buffer: the event log buffer metadata of the buffer to print
  796. * @count: the maximum number of entries to print
  797. * @print: an abstract print method, e.g. a qdf_print() or seq_printf() wrapper
  798. * @print_priv: any data required by the print method, e.g. a file handle
  799. *
  800. * Return: None
  801. */
  802. static void
  803. wmi_print_event_log_buffer(struct wmi_log_buf_t *log_buffer, uint32_t count,
  804. qdf_abstract_print *print, void *print_priv)
  805. {
  806. static const int data_len =
  807. WMI_EVENT_DEBUG_ENTRY_MAX_LENGTH / sizeof(uint32_t);
  808. char str[128];
  809. uint32_t idx;
  810. if (count > log_buffer->size)
  811. count = log_buffer->size;
  812. if (count > log_buffer->length)
  813. count = log_buffer->length;
  814. /* subtract count from index, and wrap if necessary */
  815. idx = log_buffer->size + *log_buffer->p_buf_tail_idx - count;
  816. idx %= log_buffer->size;
  817. print(print_priv, "Time (seconds) Event Id Payload");
  818. while (count) {
  819. struct wmi_event_debug *event_log = (struct wmi_event_debug *)
  820. &((struct wmi_event_debug *)log_buffer->buf)[idx];
  821. uint64_t secs, usecs;
  822. int len = 0;
  823. int i;
  824. qdf_log_timestamp_to_secs(event_log->time, &secs, &usecs);
  825. len += scnprintf(str + len, sizeof(str) - len,
  826. "% 8lld.%06lld %6u (0x%06x) ",
  827. secs, usecs,
  828. event_log->event, event_log->event);
  829. for (i = 0; i < data_len; ++i) {
  830. len += scnprintf(str + len, sizeof(str) - len,
  831. "0x%08x ", event_log->data[i]);
  832. }
  833. print(print_priv, str);
  834. --count;
  835. ++idx;
  836. if (idx >= log_buffer->size)
  837. idx = 0;
  838. }
  839. }
  840. inline void
  841. wmi_print_cmd_log(wmi_unified_t wmi, uint32_t count,
  842. qdf_abstract_print *print, void *print_priv)
  843. {
  844. wmi_print_cmd_log_buffer(
  845. &wmi->log_info.wmi_command_log_buf_info,
  846. count, print, print_priv);
  847. }
  848. inline void
  849. wmi_print_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
  850. qdf_abstract_print *print, void *print_priv)
  851. {
  852. wmi_print_cmd_log_buffer(
  853. &wmi->log_info.wmi_command_tx_cmp_log_buf_info,
  854. count, print, print_priv);
  855. }
  856. inline void
  857. wmi_print_mgmt_cmd_log(wmi_unified_t wmi, uint32_t count,
  858. qdf_abstract_print *print, void *print_priv)
  859. {
  860. wmi_print_cmd_log_buffer(
  861. &wmi->log_info.wmi_mgmt_command_log_buf_info,
  862. count, print, print_priv);
  863. }
  864. inline void
  865. wmi_print_mgmt_cmd_tx_cmp_log(wmi_unified_t wmi, uint32_t count,
  866. qdf_abstract_print *print, void *print_priv)
  867. {
  868. wmi_print_cmd_log_buffer(
  869. &wmi->log_info.wmi_mgmt_command_tx_cmp_log_buf_info,
  870. count, print, print_priv);
  871. }
  872. inline void
  873. wmi_print_event_log(wmi_unified_t wmi, uint32_t count,
  874. qdf_abstract_print *print, void *print_priv)
  875. {
  876. wmi_print_event_log_buffer(
  877. &wmi->log_info.wmi_event_log_buf_info,
  878. count, print, print_priv);
  879. }
  880. inline void
  881. wmi_print_rx_event_log(wmi_unified_t wmi, uint32_t count,
  882. qdf_abstract_print *print, void *print_priv)
  883. {
  884. wmi_print_event_log_buffer(
  885. &wmi->log_info.wmi_rx_event_log_buf_info,
  886. count, print, print_priv);
  887. }
  888. inline void
  889. wmi_print_mgmt_event_log(wmi_unified_t wmi, uint32_t count,
  890. qdf_abstract_print *print, void *print_priv)
  891. {
  892. wmi_print_event_log_buffer(
  893. &wmi->log_info.wmi_mgmt_event_log_buf_info,
  894. count, print, print_priv);
  895. }
  896. /* debugfs routines*/
  897. /**
  898. * debug_wmi_##func_base##_show() - debugfs functions to display content of
  899. * command and event buffers. Macro uses max buffer length to display
  900. * buffer when it is wraparound.
  901. *
  902. * @m: debugfs handler to access wmi_handle
  903. * @v: Variable arguments (not used)
  904. *
  905. * Return: Length of characters printed
  906. */
  907. #define GENERATE_COMMAND_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
  908. static int debug_wmi_##func_base##_show(struct seq_file *m, \
  909. void *v) \
  910. { \
  911. wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
  912. struct wmi_log_buf_t *wmi_log = \
  913. &wmi_handle->log_info.wmi_##func_base##_buf_info;\
  914. int pos, nread, outlen; \
  915. int i; \
  916. uint64_t secs, usecs; \
  917. \
  918. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);\
  919. if (!wmi_log->length) { \
  920. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);\
  921. return wmi_bp_seq_printf(m, \
  922. "no elements to read from ring buffer!\n"); \
  923. } \
  924. \
  925. if (wmi_log->length <= wmi_ring_size) \
  926. nread = wmi_log->length; \
  927. else \
  928. nread = wmi_ring_size; \
  929. \
  930. if (*(wmi_log->p_buf_tail_idx) == 0) \
  931. /* tail can be 0 after wrap-around */ \
  932. pos = wmi_ring_size - 1; \
  933. else \
  934. pos = *(wmi_log->p_buf_tail_idx) - 1; \
  935. \
  936. outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
  937. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);\
  938. while (nread--) { \
  939. struct wmi_command_debug *wmi_record; \
  940. \
  941. wmi_record = (struct wmi_command_debug *) \
  942. &(((struct wmi_command_debug *)wmi_log->buf)[pos]);\
  943. outlen += wmi_bp_seq_printf(m, "CMD ID = %x\n", \
  944. (wmi_record->command)); \
  945. qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
  946. &usecs); \
  947. outlen += \
  948. wmi_bp_seq_printf(m, "CMD TIME = [%llu.%06llu]\n",\
  949. secs, usecs); \
  950. outlen += wmi_bp_seq_printf(m, "CMD = "); \
  951. for (i = 0; i < (wmi_record_max_length/ \
  952. sizeof(uint32_t)); i++) \
  953. outlen += wmi_bp_seq_printf(m, "%x ", \
  954. wmi_record->data[i]); \
  955. outlen += wmi_bp_seq_printf(m, "\n"); \
  956. \
  957. if (pos == 0) \
  958. pos = wmi_ring_size - 1; \
  959. else \
  960. pos--; \
  961. } \
  962. return outlen; \
  963. } \
  964. #define GENERATE_EVENT_DEBUG_SHOW_FUNCS(func_base, wmi_ring_size) \
  965. static int debug_wmi_##func_base##_show(struct seq_file *m, \
  966. void *v) \
  967. { \
  968. wmi_unified_t wmi_handle = (wmi_unified_t) m->private; \
  969. struct wmi_log_buf_t *wmi_log = \
  970. &wmi_handle->log_info.wmi_##func_base##_buf_info;\
  971. int pos, nread, outlen; \
  972. int i; \
  973. uint64_t secs, usecs; \
  974. \
  975. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);\
  976. if (!wmi_log->length) { \
  977. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);\
  978. return wmi_bp_seq_printf(m, \
  979. "no elements to read from ring buffer!\n"); \
  980. } \
  981. \
  982. if (wmi_log->length <= wmi_ring_size) \
  983. nread = wmi_log->length; \
  984. else \
  985. nread = wmi_ring_size; \
  986. \
  987. if (*(wmi_log->p_buf_tail_idx) == 0) \
  988. /* tail can be 0 after wrap-around */ \
  989. pos = wmi_ring_size - 1; \
  990. else \
  991. pos = *(wmi_log->p_buf_tail_idx) - 1; \
  992. \
  993. outlen = wmi_bp_seq_printf(m, "Length = %d\n", wmi_log->length);\
  994. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);\
  995. while (nread--) { \
  996. struct wmi_event_debug *wmi_record; \
  997. \
  998. wmi_record = (struct wmi_event_debug *) \
  999. &(((struct wmi_event_debug *)wmi_log->buf)[pos]);\
  1000. qdf_log_timestamp_to_secs(wmi_record->time, &secs,\
  1001. &usecs); \
  1002. outlen += wmi_bp_seq_printf(m, "Event ID = %x\n",\
  1003. (wmi_record->event)); \
  1004. outlen += \
  1005. wmi_bp_seq_printf(m, "Event TIME = [%llu.%06llu]\n",\
  1006. secs, usecs); \
  1007. outlen += wmi_bp_seq_printf(m, "CMD = "); \
  1008. for (i = 0; i < (wmi_record_max_length/ \
  1009. sizeof(uint32_t)); i++) \
  1010. outlen += wmi_bp_seq_printf(m, "%x ", \
  1011. wmi_record->data[i]); \
  1012. outlen += wmi_bp_seq_printf(m, "\n"); \
  1013. \
  1014. if (pos == 0) \
  1015. pos = wmi_ring_size - 1; \
  1016. else \
  1017. pos--; \
  1018. } \
  1019. return outlen; \
  1020. }
  1021. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_log, wmi_display_size);
  1022. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(command_tx_cmp_log, wmi_display_size);
  1023. GENERATE_EVENT_DEBUG_SHOW_FUNCS(event_log, wmi_display_size);
  1024. GENERATE_EVENT_DEBUG_SHOW_FUNCS(rx_event_log, wmi_display_size);
  1025. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_log, wmi_display_size);
  1026. GENERATE_COMMAND_DEBUG_SHOW_FUNCS(mgmt_command_tx_cmp_log,
  1027. wmi_display_size);
  1028. GENERATE_EVENT_DEBUG_SHOW_FUNCS(mgmt_event_log, wmi_display_size);
  1029. /**
  1030. * debug_wmi_enable_show() - debugfs functions to display enable state of
  1031. * wmi logging feature.
  1032. *
  1033. * @m: debugfs handler to access wmi_handle
  1034. * @v: Variable arguments (not used)
  1035. *
  1036. * Return: always 1
  1037. */
  1038. static int debug_wmi_enable_show(struct seq_file *m, void *v)
  1039. {
  1040. wmi_unified_t wmi_handle = (wmi_unified_t) m->private;
  1041. return wmi_bp_seq_printf(m, "%d\n",
  1042. wmi_handle->log_info.wmi_logging_enable);
  1043. }
  1044. /**
  1045. * debug_wmi_log_size_show() - debugfs functions to display configured size of
  1046. * wmi logging command/event buffer and management command/event buffer.
  1047. *
  1048. * @m: debugfs handler to access wmi_handle
  1049. * @v: Variable arguments (not used)
  1050. *
  1051. * Return: Length of characters printed
  1052. */
  1053. static int debug_wmi_log_size_show(struct seq_file *m, void *v)
  1054. {
  1055. wmi_bp_seq_printf(m, "WMI command/event log max size:%d\n",
  1056. wmi_log_max_entry);
  1057. return wmi_bp_seq_printf(m,
  1058. "WMI management command/events log max size:%d\n",
  1059. wmi_mgmt_log_max_entry);
  1060. }
  1061. /**
  1062. * debug_wmi_##func_base##_write() - debugfs functions to clear
  1063. * wmi logging command/event buffer and management command/event buffer.
  1064. *
  1065. * @file: file handler to access wmi_handle
  1066. * @buf: received data buffer
  1067. * @count: length of received buffer
  1068. * @ppos: Not used
  1069. *
  1070. * Return: count
  1071. */
  1072. #define GENERATE_DEBUG_WRITE_FUNCS(func_base, wmi_ring_size, wmi_record_type)\
  1073. static ssize_t debug_wmi_##func_base##_write(struct file *file, \
  1074. const char __user *buf, \
  1075. size_t count, loff_t *ppos) \
  1076. { \
  1077. int k, ret; \
  1078. wmi_unified_t wmi_handle = \
  1079. ((struct seq_file *)file->private_data)->private;\
  1080. struct wmi_log_buf_t *wmi_log = &wmi_handle->log_info. \
  1081. wmi_##func_base##_buf_info; \
  1082. char locbuf[50]; \
  1083. \
  1084. if ((!buf) || (count > 50)) \
  1085. return -EFAULT; \
  1086. \
  1087. if (copy_from_user(locbuf, buf, count)) \
  1088. return -EFAULT; \
  1089. \
  1090. ret = sscanf(locbuf, "%d", &k); \
  1091. if ((ret != 1) || (k != 0)) { \
  1092. WMI_LOGE("Wrong input, echo 0 to clear the wmi buffer");\
  1093. return -EINVAL; \
  1094. } \
  1095. \
  1096. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);\
  1097. qdf_mem_zero(wmi_log->buf, wmi_ring_size * \
  1098. sizeof(struct wmi_record_type)); \
  1099. wmi_log->length = 0; \
  1100. *(wmi_log->p_buf_tail_idx) = 0; \
  1101. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);\
  1102. \
  1103. return count; \
  1104. }
  1105. GENERATE_DEBUG_WRITE_FUNCS(command_log, wmi_log_max_entry,
  1106. wmi_command_debug);
  1107. GENERATE_DEBUG_WRITE_FUNCS(command_tx_cmp_log, wmi_log_max_entry,
  1108. wmi_command_debug);
  1109. GENERATE_DEBUG_WRITE_FUNCS(event_log, wmi_log_max_entry,
  1110. wmi_event_debug);
  1111. GENERATE_DEBUG_WRITE_FUNCS(rx_event_log, wmi_log_max_entry,
  1112. wmi_event_debug);
  1113. GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_log, wmi_mgmt_log_max_entry,
  1114. wmi_command_debug);
  1115. GENERATE_DEBUG_WRITE_FUNCS(mgmt_command_tx_cmp_log,
  1116. wmi_mgmt_log_max_entry, wmi_command_debug);
  1117. GENERATE_DEBUG_WRITE_FUNCS(mgmt_event_log, wmi_mgmt_log_max_entry,
  1118. wmi_event_debug);
  1119. /**
  1120. * debug_wmi_enable_write() - debugfs functions to enable/disable
  1121. * wmi logging feature.
  1122. *
  1123. * @file: file handler to access wmi_handle
  1124. * @buf: received data buffer
  1125. * @count: length of received buffer
  1126. * @ppos: Not used
  1127. *
  1128. * Return: count
  1129. */
  1130. static ssize_t debug_wmi_enable_write(struct file *file, const char __user *buf,
  1131. size_t count, loff_t *ppos)
  1132. {
  1133. wmi_unified_t wmi_handle =
  1134. ((struct seq_file *)file->private_data)->private;
  1135. int k, ret;
  1136. char locbuf[50];
  1137. if ((!buf) || (count > 50))
  1138. return -EFAULT;
  1139. if (copy_from_user(locbuf, buf, count))
  1140. return -EFAULT;
  1141. ret = sscanf(locbuf, "%d", &k);
  1142. if ((ret != 1) || ((k != 0) && (k != 1)))
  1143. return -EINVAL;
  1144. wmi_handle->log_info.wmi_logging_enable = k;
  1145. return count;
  1146. }
  1147. /**
  1148. * debug_wmi_log_size_write() - reserved.
  1149. *
  1150. * @file: file handler to access wmi_handle
  1151. * @buf: received data buffer
  1152. * @count: length of received buffer
  1153. * @ppos: Not used
  1154. *
  1155. * Return: count
  1156. */
  1157. static ssize_t debug_wmi_log_size_write(struct file *file,
  1158. const char __user *buf, size_t count, loff_t *ppos)
  1159. {
  1160. return -EINVAL;
  1161. }
  1162. /* Structure to maintain debug information */
  1163. struct wmi_debugfs_info {
  1164. const char *name;
  1165. const struct file_operations *ops;
  1166. };
  1167. #define DEBUG_FOO(func_base) { .name = #func_base, \
  1168. .ops = &debug_##func_base##_ops }
  1169. /**
  1170. * debug_##func_base##_open() - Open debugfs entry for respective command
  1171. * and event buffer.
  1172. *
  1173. * @inode: node for debug dir entry
  1174. * @file: file handler
  1175. *
  1176. * Return: open status
  1177. */
  1178. #define GENERATE_DEBUG_STRUCTS(func_base) \
  1179. static int debug_##func_base##_open(struct inode *inode, \
  1180. struct file *file) \
  1181. { \
  1182. return single_open(file, debug_##func_base##_show, \
  1183. inode->i_private); \
  1184. } \
  1185. \
  1186. \
  1187. static struct file_operations debug_##func_base##_ops = { \
  1188. .open = debug_##func_base##_open, \
  1189. .read = seq_read, \
  1190. .llseek = seq_lseek, \
  1191. .write = debug_##func_base##_write, \
  1192. .release = single_release, \
  1193. };
  1194. GENERATE_DEBUG_STRUCTS(wmi_command_log);
  1195. GENERATE_DEBUG_STRUCTS(wmi_command_tx_cmp_log);
  1196. GENERATE_DEBUG_STRUCTS(wmi_event_log);
  1197. GENERATE_DEBUG_STRUCTS(wmi_rx_event_log);
  1198. GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_log);
  1199. GENERATE_DEBUG_STRUCTS(wmi_mgmt_command_tx_cmp_log);
  1200. GENERATE_DEBUG_STRUCTS(wmi_mgmt_event_log);
  1201. GENERATE_DEBUG_STRUCTS(wmi_enable);
  1202. GENERATE_DEBUG_STRUCTS(wmi_log_size);
  1203. struct wmi_debugfs_info wmi_debugfs_infos[NUM_DEBUG_INFOS] = {
  1204. DEBUG_FOO(wmi_command_log),
  1205. DEBUG_FOO(wmi_command_tx_cmp_log),
  1206. DEBUG_FOO(wmi_event_log),
  1207. DEBUG_FOO(wmi_rx_event_log),
  1208. DEBUG_FOO(wmi_mgmt_command_log),
  1209. DEBUG_FOO(wmi_mgmt_command_tx_cmp_log),
  1210. DEBUG_FOO(wmi_mgmt_event_log),
  1211. DEBUG_FOO(wmi_enable),
  1212. DEBUG_FOO(wmi_log_size),
  1213. };
  1214. /**
  1215. * wmi_debugfs_create() - Create debug_fs entry for wmi logging.
  1216. *
  1217. * @wmi_handle: wmi handle
  1218. * @par_entry: debug directory entry
  1219. * @id: Index to debug info data array
  1220. *
  1221. * Return: none
  1222. */
  1223. static void wmi_debugfs_create(wmi_unified_t wmi_handle,
  1224. struct dentry *par_entry)
  1225. {
  1226. int i;
  1227. if (!par_entry)
  1228. goto out;
  1229. for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
  1230. wmi_handle->debugfs_de[i] = debugfs_create_file(
  1231. wmi_debugfs_infos[i].name, 0644, par_entry,
  1232. wmi_handle, wmi_debugfs_infos[i].ops);
  1233. if (!wmi_handle->debugfs_de[i]) {
  1234. WMI_LOGE("debug Entry creation failed!");
  1235. goto out;
  1236. }
  1237. }
  1238. return;
  1239. out:
  1240. WMI_LOGE("debug Entry creation failed!");
  1241. wmi_log_buffer_free(wmi_handle);
  1242. return;
  1243. }
  1244. /**
  1245. * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
  1246. * @wmi_handle: wmi handle
  1247. * @dentry: debugfs directory entry
  1248. * @id: Index to debug info data array
  1249. *
  1250. * Return: none
  1251. */
  1252. static void wmi_debugfs_remove(wmi_unified_t wmi_handle)
  1253. {
  1254. int i;
  1255. struct dentry *dentry = wmi_handle->log_info.wmi_log_debugfs_dir;
  1256. if (dentry) {
  1257. for (i = 0; i < NUM_DEBUG_INFOS; ++i) {
  1258. if (wmi_handle->debugfs_de[i])
  1259. wmi_handle->debugfs_de[i] = NULL;
  1260. }
  1261. }
  1262. if (dentry)
  1263. debugfs_remove_recursive(dentry);
  1264. }
  1265. /**
  1266. * wmi_debugfs_init() - debugfs functions to create debugfs directory and to
  1267. * create debugfs enteries.
  1268. *
  1269. * @h: wmi handler
  1270. *
  1271. * Return: init status
  1272. */
  1273. static QDF_STATUS wmi_debugfs_init(wmi_unified_t wmi_handle, uint32_t pdev_idx)
  1274. {
  1275. char buf[32];
  1276. snprintf(buf, sizeof(buf), "WMI_SOC%u_PDEV%u",
  1277. wmi_handle->soc->soc_idx, pdev_idx);
  1278. wmi_handle->log_info.wmi_log_debugfs_dir =
  1279. debugfs_create_dir(buf, NULL);
  1280. if (!wmi_handle->log_info.wmi_log_debugfs_dir) {
  1281. WMI_LOGE("error while creating debugfs dir for %s", buf);
  1282. return QDF_STATUS_E_FAILURE;
  1283. }
  1284. wmi_debugfs_create(wmi_handle,
  1285. wmi_handle->log_info.wmi_log_debugfs_dir);
  1286. return QDF_STATUS_SUCCESS;
  1287. }
  1288. /**
  1289. * wmi_mgmt_cmd_record() - Wrapper function for mgmt command logging macro
  1290. *
  1291. * @wmi_handle: wmi handle
  1292. * @cmd: mgmt command
  1293. * @header: pointer to 802.11 header
  1294. * @vdev_id: vdev id
  1295. * @chanfreq: channel frequency
  1296. *
  1297. * Return: none
  1298. */
  1299. void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
  1300. void *header, uint32_t vdev_id, uint32_t chanfreq)
  1301. {
  1302. uint32_t data[CUSTOM_MGMT_CMD_DATA_SIZE];
  1303. data[0] = ((struct wmi_command_header *)header)->type;
  1304. data[1] = ((struct wmi_command_header *)header)->sub_type;
  1305. data[2] = vdev_id;
  1306. data[3] = chanfreq;
  1307. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1308. WMI_MGMT_COMMAND_RECORD(wmi_handle, cmd, (uint8_t *)data);
  1309. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1310. }
  1311. #else
  1312. /**
  1313. * wmi_debugfs_remove() - Remove debugfs entry for wmi logging.
  1314. * @wmi_handle: wmi handle
  1315. * @dentry: debugfs directory entry
  1316. * @id: Index to debug info data array
  1317. *
  1318. * Return: none
  1319. */
  1320. static void wmi_debugfs_remove(wmi_unified_t wmi_handle) { }
  1321. void wmi_mgmt_cmd_record(wmi_unified_t wmi_handle, uint32_t cmd,
  1322. void *header, uint32_t vdev_id, uint32_t chanfreq) { }
  1323. static inline void wmi_log_buffer_free(struct wmi_unified *wmi_handle) { }
  1324. #endif /*WMI_INTERFACE_EVENT_LOGGING */
  1325. qdf_export_symbol(wmi_mgmt_cmd_record);
  1326. int wmi_get_host_credits(wmi_unified_t wmi_handle);
  1327. /* WMI buffer APIs */
  1328. #ifdef NBUF_MEMORY_DEBUG
  1329. wmi_buf_t
  1330. wmi_buf_alloc_debug(wmi_unified_t wmi_handle, uint32_t len,
  1331. const char *func_name,
  1332. uint32_t line_num)
  1333. {
  1334. wmi_buf_t wmi_buf;
  1335. if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
  1336. QDF_ASSERT(0);
  1337. return NULL;
  1338. }
  1339. wmi_buf = wbuff_buff_get(wmi_handle->wbuff_handle, len, func_name,
  1340. line_num);
  1341. if (!wmi_buf)
  1342. wmi_buf = qdf_nbuf_alloc_debug(NULL,
  1343. roundup(len + WMI_MIN_HEAD_ROOM,
  1344. 4),
  1345. WMI_MIN_HEAD_ROOM, 4, false,
  1346. func_name, line_num);
  1347. if (!wmi_buf)
  1348. return NULL;
  1349. /* Clear the wmi buffer */
  1350. OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
  1351. /*
  1352. * Set the length of the buffer to match the allocation size.
  1353. */
  1354. qdf_nbuf_set_pktlen(wmi_buf, len);
  1355. return wmi_buf;
  1356. }
  1357. qdf_export_symbol(wmi_buf_alloc_debug);
  1358. void wmi_buf_free(wmi_buf_t net_buf)
  1359. {
  1360. net_buf = wbuff_buff_put(net_buf);
  1361. if (net_buf)
  1362. qdf_nbuf_free(net_buf);
  1363. }
  1364. qdf_export_symbol(wmi_buf_free);
  1365. #else
  1366. wmi_buf_t wmi_buf_alloc_fl(wmi_unified_t wmi_handle, uint32_t len,
  1367. const char *func, uint32_t line)
  1368. {
  1369. wmi_buf_t wmi_buf;
  1370. if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
  1371. QDF_DEBUG_PANIC("Invalid length %u (via %s:%u)",
  1372. len, func, line);
  1373. return NULL;
  1374. }
  1375. wmi_buf = wbuff_buff_get(wmi_handle->wbuff_handle, len, __func__,
  1376. __LINE__);
  1377. if (!wmi_buf)
  1378. wmi_buf = qdf_nbuf_alloc_fl(NULL, roundup(len +
  1379. WMI_MIN_HEAD_ROOM, 4), WMI_MIN_HEAD_ROOM, 4,
  1380. false, func, line);
  1381. if (!wmi_buf) {
  1382. wmi_nofl_err("%s:%d, failed to alloc len:%d", func, line, len);
  1383. return NULL;
  1384. }
  1385. /* Clear the wmi buffer */
  1386. OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
  1387. /*
  1388. * Set the length of the buffer to match the allocation size.
  1389. */
  1390. qdf_nbuf_set_pktlen(wmi_buf, len);
  1391. return wmi_buf;
  1392. }
  1393. qdf_export_symbol(wmi_buf_alloc_fl);
  1394. void wmi_buf_free(wmi_buf_t net_buf)
  1395. {
  1396. net_buf = wbuff_buff_put(net_buf);
  1397. if (net_buf)
  1398. qdf_nbuf_free(net_buf);
  1399. }
  1400. qdf_export_symbol(wmi_buf_free);
  1401. #endif
  1402. /**
  1403. * wmi_get_max_msg_len() - get maximum WMI message length
  1404. * @wmi_handle: WMI handle.
  1405. *
  1406. * This function returns the maximum WMI message length
  1407. *
  1408. * Return: maximum WMI message length
  1409. */
  1410. uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
  1411. {
  1412. return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
  1413. }
  1414. qdf_export_symbol(wmi_get_max_msg_len);
  1415. #ifndef WMI_CMD_STRINGS
  1416. static uint8_t *wmi_id_to_name(uint32_t wmi_command)
  1417. {
  1418. return "Invalid WMI cmd";
  1419. }
  1420. #endif
  1421. static inline void wmi_log_cmd_id(uint32_t cmd_id, uint32_t tag)
  1422. {
  1423. WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d",
  1424. wmi_id_to_name(cmd_id), cmd_id, tag);
  1425. }
  1426. /**
  1427. * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
  1428. * @cmd_id: command to check
  1429. *
  1430. * Return: true if the command is part of the resume sequence.
  1431. */
  1432. #ifdef WLAN_POWER_MANAGEMENT_OFFLOAD
  1433. static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
  1434. {
  1435. switch (cmd_id) {
  1436. case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
  1437. case WMI_PDEV_RESUME_CMDID:
  1438. return true;
  1439. default:
  1440. return false;
  1441. }
  1442. }
  1443. #else
  1444. static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
  1445. {
  1446. return false;
  1447. }
  1448. #endif
  1449. #ifdef FEATURE_WLAN_D0WOW
  1450. static bool wmi_is_legacy_d0wow_disable_cmd(wmi_buf_t buf, uint32_t cmd_id)
  1451. {
  1452. wmi_d0_wow_enable_disable_cmd_fixed_param *cmd;
  1453. if (cmd_id == WMI_D0_WOW_ENABLE_DISABLE_CMDID) {
  1454. cmd = (wmi_d0_wow_enable_disable_cmd_fixed_param *)
  1455. wmi_buf_data(buf);
  1456. if (!cmd->enable)
  1457. return true;
  1458. else
  1459. return false;
  1460. }
  1461. return false;
  1462. }
  1463. #else
  1464. static bool wmi_is_legacy_d0wow_disable_cmd(wmi_buf_t buf, uint32_t cmd_id)
  1465. {
  1466. return false;
  1467. }
  1468. #endif
  1469. static inline void wmi_unified_debug_dump(wmi_unified_t wmi_handle)
  1470. {
  1471. wmi_nofl_err("Endpoint ID = %d, Tx Queue Depth = %d, soc_id = %u, target type = %s",
  1472. wmi_handle->wmi_endpoint_id,
  1473. htc_get_tx_queue_depth(wmi_handle->htc_handle,
  1474. wmi_handle->wmi_endpoint_id),
  1475. wmi_handle->soc->soc_idx,
  1476. (wmi_handle->target_type ==
  1477. WMI_TLV_TARGET ? "WMI_TLV_TARGET" :
  1478. "WMI_NON_TLV_TARGET"));
  1479. }
  1480. #ifdef WLAN_FEATURE_WMI_SEND_RECV_QMI
  1481. QDF_STATUS wmi_unified_cmd_send_over_qmi(struct wmi_unified *wmi_handle,
  1482. wmi_buf_t buf, uint32_t buflen,
  1483. uint32_t cmd_id)
  1484. {
  1485. QDF_STATUS status;
  1486. int32_t ret;
  1487. if (!qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR))) {
  1488. wmi_err("Failed to send cmd %x, no memory", cmd_id);
  1489. return QDF_STATUS_E_NOMEM;
  1490. }
  1491. qdf_mem_zero(qdf_nbuf_data(buf), sizeof(WMI_CMD_HDR));
  1492. WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
  1493. wmi_debug("Sending WMI_CMD_ID: %d over qmi", cmd_id);
  1494. status = qdf_wmi_send_recv_qmi(qdf_nbuf_data(buf),
  1495. buflen + sizeof(WMI_CMD_HDR),
  1496. wmi_handle,
  1497. wmi_process_qmi_fw_event);
  1498. if (QDF_IS_STATUS_ERROR(status)) {
  1499. qdf_nbuf_pull_head(buf, sizeof(WMI_CMD_HDR));
  1500. wmi_warn("WMI send on QMI failed. Retrying WMI on HTC");
  1501. } else {
  1502. ret = qdf_atomic_inc_return(&wmi_handle->num_stats_over_qmi);
  1503. wmi_debug("num stats over qmi: %d", ret);
  1504. wmi_buf_free(buf);
  1505. }
  1506. return status;
  1507. }
  1508. static int __wmi_process_qmi_fw_event(void *wmi_cb_ctx, void *buf, int len)
  1509. {
  1510. struct wmi_unified *wmi_handle = wmi_cb_ctx;
  1511. wmi_buf_t evt_buf;
  1512. uint32_t evt_id;
  1513. if (!wmi_handle || !buf)
  1514. return -EINVAL;
  1515. evt_buf = wmi_buf_alloc(wmi_handle, len);
  1516. if (!evt_buf)
  1517. return -ENOMEM;
  1518. qdf_mem_copy(qdf_nbuf_data(evt_buf), buf, len);
  1519. evt_id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  1520. wmi_debug("Received WMI_EVT_ID: %d over qmi", evt_id);
  1521. wmi_process_fw_event(wmi_handle, evt_buf);
  1522. return 0;
  1523. }
  1524. int wmi_process_qmi_fw_event(void *wmi_cb_ctx, void *buf, int len)
  1525. {
  1526. struct qdf_op_sync *op_sync;
  1527. int ret;
  1528. if (qdf_op_protect(&op_sync))
  1529. return -EINVAL;
  1530. ret = __wmi_process_qmi_fw_event(wmi_cb_ctx, buf, len);
  1531. qdf_op_unprotect(op_sync);
  1532. return ret;
  1533. }
  1534. #endif
  1535. QDF_STATUS wmi_unified_cmd_send_fl(wmi_unified_t wmi_handle, wmi_buf_t buf,
  1536. uint32_t len, uint32_t cmd_id,
  1537. const char *func, uint32_t line)
  1538. {
  1539. HTC_PACKET *pkt;
  1540. QDF_STATUS status;
  1541. uint16_t htc_tag = 0;
  1542. if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
  1543. htc_tag = wmi_handle->ops->wmi_set_htc_tx_tag(wmi_handle, buf,
  1544. cmd_id);
  1545. } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
  1546. !wmi_is_pm_resume_cmd(cmd_id) &&
  1547. !wmi_is_legacy_d0wow_disable_cmd(buf, cmd_id)) {
  1548. wmi_nofl_err("Target is suspended (via %s:%u)",
  1549. func, line);
  1550. return QDF_STATUS_E_BUSY;
  1551. }
  1552. if (wmi_handle->wmi_stopinprogress) {
  1553. wmi_nofl_err("%s:%d, WMI stop in progress, wmi_handle:%pK",
  1554. func, line, wmi_handle);
  1555. return QDF_STATUS_E_INVAL;
  1556. }
  1557. #ifndef WMI_NON_TLV_SUPPORT
  1558. /* Do sanity check on the TLV parameter structure */
  1559. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  1560. void *buf_ptr = (void *)qdf_nbuf_data(buf);
  1561. if (wmi_handle->ops->wmi_check_command_params(NULL, buf_ptr, len, cmd_id)
  1562. != 0) {
  1563. wmi_nofl_err("%s:%d, Invalid WMI Param Buffer for Cmd:%d",
  1564. func, line, cmd_id);
  1565. return QDF_STATUS_E_INVAL;
  1566. }
  1567. }
  1568. #endif
  1569. if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
  1570. wmi_nofl_err("%s:%d, Failed to send cmd %x, no memory",
  1571. func, line, cmd_id);
  1572. return QDF_STATUS_E_NOMEM;
  1573. }
  1574. qdf_mem_zero(qdf_nbuf_data(buf), sizeof(WMI_CMD_HDR));
  1575. WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
  1576. qdf_atomic_inc(&wmi_handle->pending_cmds);
  1577. if (qdf_atomic_read(&wmi_handle->pending_cmds) >=
  1578. wmi_handle->wmi_max_cmds) {
  1579. wmi_nofl_err("hostcredits = %d",
  1580. wmi_get_host_credits(wmi_handle));
  1581. htc_dump_counter_info(wmi_handle->htc_handle);
  1582. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1583. wmi_nofl_err("%s:%d, MAX %d WMI Pending cmds reached",
  1584. func, line, wmi_handle->wmi_max_cmds);
  1585. wmi_unified_debug_dump(wmi_handle);
  1586. htc_ce_tasklet_debug_dump(wmi_handle->htc_handle);
  1587. qdf_trigger_self_recovery(QDF_WMI_EXCEED_MAX_PENDING_CMDS);
  1588. return QDF_STATUS_E_BUSY;
  1589. }
  1590. pkt = qdf_mem_malloc_fl(sizeof(*pkt), func, line);
  1591. if (!pkt) {
  1592. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1593. return QDF_STATUS_E_NOMEM;
  1594. }
  1595. SET_HTC_PACKET_INFO_TX(pkt,
  1596. NULL,
  1597. qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
  1598. wmi_handle->wmi_endpoint_id, htc_tag);
  1599. SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
  1600. wmi_log_cmd_id(cmd_id, htc_tag);
  1601. wmi_ext_dbg_msg_cmd_record(wmi_handle,
  1602. qdf_nbuf_data(buf), qdf_nbuf_len(buf));
  1603. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1604. if (wmi_handle->log_info.wmi_logging_enable) {
  1605. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1606. /*
  1607. * Record 16 bytes of WMI cmd data -
  1608. * exclude TLV and WMI headers
  1609. *
  1610. * WMI mgmt command already recorded in wmi_mgmt_cmd_record
  1611. */
  1612. if (wmi_handle->ops->is_management_record(cmd_id) == false) {
  1613. WMI_COMMAND_RECORD(wmi_handle, cmd_id,
  1614. qdf_nbuf_data(buf) +
  1615. wmi_handle->soc->buf_offset_command);
  1616. }
  1617. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1618. }
  1619. #endif
  1620. status = htc_send_pkt(wmi_handle->htc_handle, pkt);
  1621. if (QDF_STATUS_SUCCESS != status) {
  1622. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1623. wmi_nofl_err("%s:%d, htc_send_pkt failed, status:%d",
  1624. func, line, status);
  1625. qdf_mem_free(pkt);
  1626. return status;
  1627. }
  1628. return QDF_STATUS_SUCCESS;
  1629. }
  1630. qdf_export_symbol(wmi_unified_cmd_send_fl);
  1631. /**
  1632. * wmi_unified_get_event_handler_ix() - gives event handler's index
  1633. * @wmi_handle: handle to wmi
  1634. * @event_id: wmi event id
  1635. *
  1636. * Return: event handler's index
  1637. */
  1638. static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
  1639. uint32_t event_id)
  1640. {
  1641. uint32_t idx = 0;
  1642. int32_t invalid_idx = -1;
  1643. struct wmi_soc *soc = wmi_handle->soc;
  1644. for (idx = 0; (idx < soc->max_event_idx &&
  1645. idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
  1646. if (wmi_handle->event_id[idx] == event_id &&
  1647. wmi_handle->event_handler[idx]) {
  1648. return idx;
  1649. }
  1650. }
  1651. return invalid_idx;
  1652. }
  1653. /**
  1654. * wmi_unified_register_event() - register wmi event handler
  1655. * @wmi_handle: handle to wmi
  1656. * @event_id: wmi event id
  1657. * @handler_func: wmi event handler function
  1658. *
  1659. * Return: 0 on success
  1660. */
  1661. int wmi_unified_register_event(wmi_unified_t wmi_handle,
  1662. uint32_t event_id,
  1663. wmi_unified_event_handler handler_func)
  1664. {
  1665. uint32_t idx = 0;
  1666. uint32_t evt_id;
  1667. struct wmi_soc *soc;
  1668. if (!wmi_handle) {
  1669. WMI_LOGE("WMI handle is NULL");
  1670. return QDF_STATUS_E_FAILURE;
  1671. }
  1672. soc = wmi_handle->soc;
  1673. if (event_id >= wmi_events_max ||
  1674. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1675. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  1676. "%s: Event id %d is unavailable",
  1677. __func__, event_id);
  1678. return QDF_STATUS_E_FAILURE;
  1679. }
  1680. evt_id = wmi_handle->wmi_events[event_id];
  1681. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1682. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  1683. "%s : event handler already registered 0x%x",
  1684. __func__, evt_id);
  1685. return QDF_STATUS_E_FAILURE;
  1686. }
  1687. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1688. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1689. "%s : no more event handlers 0x%x",
  1690. __func__, evt_id);
  1691. return QDF_STATUS_E_FAILURE;
  1692. }
  1693. idx = soc->max_event_idx;
  1694. wmi_handle->event_handler[idx] = handler_func;
  1695. wmi_handle->event_id[idx] = evt_id;
  1696. qdf_spin_lock_bh(&soc->ctx_lock);
  1697. wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
  1698. qdf_spin_unlock_bh(&soc->ctx_lock);
  1699. soc->max_event_idx++;
  1700. return 0;
  1701. }
  1702. /**
  1703. * wmi_unified_register_event_handler() - register wmi event handler
  1704. * @wmi_handle: handle to wmi
  1705. * @event_id: wmi event id
  1706. * @handler_func: wmi event handler function
  1707. * @rx_ctx: rx execution context for wmi rx events
  1708. *
  1709. * This API is to support legacy requirements. Will be deprecated in future.
  1710. * Return: 0 on success
  1711. */
  1712. int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
  1713. wmi_conv_event_id event_id,
  1714. wmi_unified_event_handler handler_func,
  1715. uint8_t rx_ctx)
  1716. {
  1717. uint32_t idx = 0;
  1718. uint32_t evt_id;
  1719. struct wmi_soc *soc;
  1720. if (!wmi_handle) {
  1721. WMI_LOGE("WMI handle is NULL");
  1722. return QDF_STATUS_E_FAILURE;
  1723. }
  1724. soc = wmi_handle->soc;
  1725. if (event_id >= wmi_events_max ||
  1726. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1727. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  1728. "%s: Event id %d is unavailable",
  1729. __func__, event_id);
  1730. return QDF_STATUS_E_FAILURE;
  1731. }
  1732. evt_id = wmi_handle->wmi_events[event_id];
  1733. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1734. WMI_LOGI("event handler already registered 0x%x",
  1735. evt_id);
  1736. return QDF_STATUS_E_FAILURE;
  1737. }
  1738. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1739. WMI_LOGE("no more event handlers 0x%x",
  1740. evt_id);
  1741. return QDF_STATUS_E_FAILURE;
  1742. }
  1743. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
  1744. "Registered event handler for event 0x%8x", evt_id);
  1745. idx = soc->max_event_idx;
  1746. wmi_handle->event_handler[idx] = handler_func;
  1747. wmi_handle->event_id[idx] = evt_id;
  1748. qdf_spin_lock_bh(&soc->ctx_lock);
  1749. wmi_handle->ctx[idx] = rx_ctx;
  1750. qdf_spin_unlock_bh(&soc->ctx_lock);
  1751. soc->max_event_idx++;
  1752. return 0;
  1753. }
  1754. qdf_export_symbol(wmi_unified_register_event_handler);
  1755. /**
  1756. * wmi_unified_unregister_event() - unregister wmi event handler
  1757. * @wmi_handle: handle to wmi
  1758. * @event_id: wmi event id
  1759. *
  1760. * Return: 0 on success
  1761. */
  1762. int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
  1763. uint32_t event_id)
  1764. {
  1765. uint32_t idx = 0;
  1766. uint32_t evt_id;
  1767. struct wmi_soc *soc = wmi_handle->soc;
  1768. if (event_id >= wmi_events_max ||
  1769. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1770. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  1771. "%s: Event id %d is unavailable",
  1772. __func__, event_id);
  1773. return QDF_STATUS_E_FAILURE;
  1774. }
  1775. evt_id = wmi_handle->wmi_events[event_id];
  1776. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1777. if (idx == -1) {
  1778. WMI_LOGI("event handler is not registered: evt id 0x%x",
  1779. evt_id);
  1780. return QDF_STATUS_E_FAILURE;
  1781. }
  1782. wmi_handle->event_handler[idx] = NULL;
  1783. wmi_handle->event_id[idx] = 0;
  1784. --soc->max_event_idx;
  1785. wmi_handle->event_handler[idx] =
  1786. wmi_handle->event_handler[soc->max_event_idx];
  1787. wmi_handle->event_id[idx] =
  1788. wmi_handle->event_id[soc->max_event_idx];
  1789. return 0;
  1790. }
  1791. /**
  1792. * wmi_unified_unregister_event_handler() - unregister wmi event handler
  1793. * @wmi_handle: handle to wmi
  1794. * @event_id: wmi event id
  1795. *
  1796. * Return: 0 on success
  1797. */
  1798. int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
  1799. wmi_conv_event_id event_id)
  1800. {
  1801. uint32_t idx = 0;
  1802. uint32_t evt_id;
  1803. struct wmi_soc *soc;
  1804. if (!wmi_handle) {
  1805. WMI_LOGE("WMI handle is NULL");
  1806. return QDF_STATUS_E_FAILURE;
  1807. }
  1808. soc = wmi_handle->soc;
  1809. if (event_id >= wmi_events_max ||
  1810. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1811. WMI_LOGI("Event id %d is unavailable",
  1812. event_id);
  1813. return QDF_STATUS_E_FAILURE;
  1814. }
  1815. evt_id = wmi_handle->wmi_events[event_id];
  1816. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1817. if (idx == -1) {
  1818. WMI_LOGI("event handler is not registered: evt id 0x%x",
  1819. evt_id);
  1820. return QDF_STATUS_E_FAILURE;
  1821. }
  1822. wmi_handle->event_handler[idx] = NULL;
  1823. wmi_handle->event_id[idx] = 0;
  1824. --soc->max_event_idx;
  1825. wmi_handle->event_handler[idx] =
  1826. wmi_handle->event_handler[soc->max_event_idx];
  1827. wmi_handle->event_id[idx] =
  1828. wmi_handle->event_id[soc->max_event_idx];
  1829. return 0;
  1830. }
  1831. qdf_export_symbol(wmi_unified_unregister_event_handler);
  1832. void wmi_process_fw_event_worker_thread_ctx(struct wmi_unified *wmi_handle,
  1833. void *evt_buf)
  1834. {
  1835. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  1836. qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
  1837. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  1838. qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
  1839. &wmi_handle->rx_event_work);
  1840. return;
  1841. }
  1842. qdf_export_symbol(wmi_process_fw_event_worker_thread_ctx);
  1843. uint32_t wmi_critical_events_in_flight(struct wmi_unified *wmi)
  1844. {
  1845. return qdf_atomic_read(&wmi->critical_events_in_flight);
  1846. }
  1847. static bool
  1848. wmi_is_event_critical(struct wmi_unified *wmi_handle, uint32_t event_id)
  1849. {
  1850. if (wmi_handle->wmi_events[wmi_roam_synch_event_id] == event_id)
  1851. return true;
  1852. return false;
  1853. }
  1854. static void wmi_discard_fw_event(struct scheduler_msg *msg)
  1855. {
  1856. struct wmi_process_fw_event_params *event_param;
  1857. if (!msg->bodyptr)
  1858. return;
  1859. event_param = (struct wmi_process_fw_event_params *)msg->bodyptr;
  1860. qdf_nbuf_free(event_param->evt_buf);
  1861. qdf_mem_free(msg->bodyptr);
  1862. msg->bodyptr = NULL;
  1863. msg->bodyval = 0;
  1864. msg->type = 0;
  1865. }
  1866. static int wmi_process_fw_event_handler(struct scheduler_msg *msg)
  1867. {
  1868. struct wmi_process_fw_event_params *params =
  1869. (struct wmi_process_fw_event_params *)msg->bodyptr;
  1870. struct wmi_unified *wmi_handle;
  1871. uint32_t event_id;
  1872. wmi_handle = (struct wmi_unified *)params->wmi_handle;
  1873. event_id = WMI_GET_FIELD(qdf_nbuf_data(params->evt_buf),
  1874. WMI_CMD_HDR, COMMANDID);
  1875. wmi_process_fw_event(wmi_handle, params->evt_buf);
  1876. if (wmi_is_event_critical(wmi_handle, event_id))
  1877. qdf_atomic_dec(&wmi_handle->critical_events_in_flight);
  1878. qdf_mem_free(msg->bodyptr);
  1879. return 0;
  1880. }
  1881. /**
  1882. * wmi_process_fw_event_sched_thread_ctx() - common event handler to serialize
  1883. * event processing through scheduler thread
  1884. * @ctx: wmi context
  1885. * @ev: event buffer
  1886. * @rx_ctx: rx execution context
  1887. *
  1888. * Return: 0 on success, errno on failure
  1889. */
  1890. static QDF_STATUS
  1891. wmi_process_fw_event_sched_thread_ctx(struct wmi_unified *wmi,
  1892. void *ev)
  1893. {
  1894. struct wmi_process_fw_event_params *params_buf;
  1895. struct scheduler_msg msg = { 0 };
  1896. uint32_t event_id;
  1897. struct target_psoc_info *tgt_hdl;
  1898. bool is_wmi_ready = false;
  1899. struct wlan_objmgr_psoc *psoc;
  1900. psoc = target_if_get_psoc_from_scn_hdl(wmi->scn_handle);
  1901. if (!psoc) {
  1902. target_if_err("psoc is null");
  1903. qdf_nbuf_free(ev);
  1904. return QDF_STATUS_E_INVAL;
  1905. }
  1906. tgt_hdl = wlan_psoc_get_tgt_if_handle(psoc);
  1907. if (!tgt_hdl) {
  1908. wmi_err("target_psoc_info is null");
  1909. qdf_nbuf_free(ev);
  1910. return QDF_STATUS_E_INVAL;
  1911. }
  1912. is_wmi_ready = target_psoc_get_wmi_ready(tgt_hdl);
  1913. if (!is_wmi_ready) {
  1914. wmi_debug("fw event recvd before ready event processed");
  1915. wmi_debug("therefore use worker thread");
  1916. wmi_process_fw_event_worker_thread_ctx(wmi, ev);
  1917. return QDF_STATUS_E_INVAL;
  1918. }
  1919. params_buf = qdf_mem_malloc(sizeof(struct wmi_process_fw_event_params));
  1920. if (!params_buf) {
  1921. wmi_err("malloc failed");
  1922. qdf_nbuf_free(ev);
  1923. return QDF_STATUS_E_NOMEM;
  1924. }
  1925. params_buf->wmi_handle = wmi;
  1926. params_buf->evt_buf = ev;
  1927. event_id = WMI_GET_FIELD(qdf_nbuf_data(params_buf->evt_buf),
  1928. WMI_CMD_HDR, COMMANDID);
  1929. if (wmi_is_event_critical(wmi, event_id))
  1930. qdf_atomic_inc(&wmi->critical_events_in_flight);
  1931. msg.bodyptr = params_buf;
  1932. msg.bodyval = 0;
  1933. msg.callback = wmi_process_fw_event_handler;
  1934. msg.flush_callback = wmi_discard_fw_event;
  1935. if (QDF_STATUS_SUCCESS !=
  1936. scheduler_post_message(QDF_MODULE_ID_TARGET_IF,
  1937. QDF_MODULE_ID_TARGET_IF,
  1938. QDF_MODULE_ID_TARGET_IF, &msg)) {
  1939. qdf_nbuf_free(ev);
  1940. qdf_mem_free(params_buf);
  1941. return QDF_STATUS_E_FAULT;
  1942. }
  1943. return QDF_STATUS_SUCCESS;
  1944. }
  1945. /**
  1946. * wmi_get_pdev_ep: Get wmi handle based on endpoint
  1947. * @soc: handle to wmi soc
  1948. * @ep: endpoint id
  1949. *
  1950. * Return: none
  1951. */
  1952. static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
  1953. HTC_ENDPOINT_ID ep)
  1954. {
  1955. uint32_t i;
  1956. for (i = 0; i < WMI_MAX_RADIOS; i++)
  1957. if (soc->wmi_endpoint_id[i] == ep)
  1958. break;
  1959. if (i == WMI_MAX_RADIOS)
  1960. return NULL;
  1961. return soc->wmi_pdev[i];
  1962. }
  1963. /**
  1964. * wmi_mtrace_rx() - Wrappper function for qdf_mtrace api
  1965. * @message_id: 32-Bit Wmi message ID
  1966. * @vdev_id: Vdev ID
  1967. * @data: Actual message contents
  1968. *
  1969. * This function converts the 32-bit WMI message ID in 15-bit message ID
  1970. * format for qdf_mtrace as in qdf_mtrace message there are only 15
  1971. * bits reserved for message ID.
  1972. * out of these 15-bits, 8-bits (From LSB) specifies the WMI_GRP_ID
  1973. * and remaining 7-bits specifies the actual WMI command. With this
  1974. * notation there can be maximum 256 groups and each group can have
  1975. * max 128 commands can be supported.
  1976. *
  1977. * Return: None
  1978. */
  1979. static void wmi_mtrace_rx(uint32_t message_id, uint16_t vdev_id, uint32_t data)
  1980. {
  1981. uint16_t mtrace_message_id;
  1982. mtrace_message_id = QDF_WMI_MTRACE_CMD_ID(message_id) |
  1983. (QDF_WMI_MTRACE_GRP_ID(message_id) <<
  1984. QDF_WMI_MTRACE_CMD_NUM_BITS);
  1985. qdf_mtrace(QDF_MODULE_ID_WMI, QDF_MODULE_ID_WMA,
  1986. mtrace_message_id, vdev_id, data);
  1987. }
  1988. /**
  1989. * wmi_control_rx() - process fw events callbacks
  1990. * @ctx: handle to wmi
  1991. * @htc_packet: pointer to htc packet
  1992. *
  1993. * Return: none
  1994. */
  1995. static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
  1996. {
  1997. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  1998. struct wmi_unified *wmi_handle;
  1999. wmi_buf_t evt_buf;
  2000. uint32_t id;
  2001. uint32_t idx = 0;
  2002. enum wmi_rx_exec_ctx exec_ctx;
  2003. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  2004. wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
  2005. if (!wmi_handle) {
  2006. WMI_LOGE
  2007. ("unable to get wmi_handle to Endpoint %d\n",
  2008. htc_packet->Endpoint);
  2009. qdf_nbuf_free(evt_buf);
  2010. return;
  2011. }
  2012. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  2013. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  2014. if (qdf_unlikely(idx == A_ERROR)) {
  2015. wmi_debug("no handler registered for event id 0x%x", id);
  2016. qdf_nbuf_free(evt_buf);
  2017. return;
  2018. }
  2019. wmi_mtrace_rx(id, 0xFF, idx);
  2020. qdf_spin_lock_bh(&soc->ctx_lock);
  2021. exec_ctx = wmi_handle->ctx[idx];
  2022. qdf_spin_unlock_bh(&soc->ctx_lock);
  2023. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2024. if (wmi_handle->log_info.wmi_logging_enable) {
  2025. uint8_t *data;
  2026. data = qdf_nbuf_data(evt_buf);
  2027. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  2028. /* Exclude 4 bytes of TLV header */
  2029. if (wmi_handle->ops->is_diag_event(id)) {
  2030. WMI_DIAG_RX_EVENT_RECORD(wmi_handle, id,
  2031. ((uint8_t *) data +
  2032. wmi_handle->soc->buf_offset_event));
  2033. } else if (wmi_handle->ops->is_management_record(id)) {
  2034. WMI_MGMT_RX_EVENT_RECORD(wmi_handle, id,
  2035. ((uint8_t *) data +
  2036. wmi_handle->soc->buf_offset_event));
  2037. } else {
  2038. WMI_RX_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
  2039. wmi_handle->soc->buf_offset_event));
  2040. }
  2041. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  2042. }
  2043. #endif
  2044. if (exec_ctx == WMI_RX_WORK_CTX) {
  2045. wmi_process_fw_event_worker_thread_ctx
  2046. (wmi_handle, evt_buf);
  2047. } else if (exec_ctx == WMI_RX_TASKLET_CTX) {
  2048. wmi_process_fw_event(wmi_handle, evt_buf);
  2049. } else if (exec_ctx == WMI_RX_SERIALIZER_CTX) {
  2050. wmi_process_fw_event_sched_thread_ctx(wmi_handle, evt_buf);
  2051. } else {
  2052. WMI_LOGE("Invalid event context %d", exec_ctx);
  2053. qdf_nbuf_free(evt_buf);
  2054. }
  2055. }
  2056. /**
  2057. * wmi_process_fw_event() - process any fw event
  2058. * @wmi_handle: wmi handle
  2059. * @evt_buf: fw event buffer
  2060. *
  2061. * This function process fw event in caller context
  2062. *
  2063. * Return: none
  2064. */
  2065. void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  2066. {
  2067. __wmi_control_rx(wmi_handle, evt_buf);
  2068. }
  2069. /**
  2070. * __wmi_control_rx() - process serialize wmi event callback
  2071. * @wmi_handle: wmi handle
  2072. * @evt_buf: fw event buffer
  2073. *
  2074. * Return: none
  2075. */
  2076. void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  2077. {
  2078. uint32_t id;
  2079. uint8_t *data;
  2080. uint32_t len;
  2081. void *wmi_cmd_struct_ptr = NULL;
  2082. #ifndef WMI_NON_TLV_SUPPORT
  2083. int tlv_ok_status = 0;
  2084. #endif
  2085. uint32_t idx = 0;
  2086. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  2087. wmi_ext_dbg_msg_event_record(wmi_handle, qdf_nbuf_data(evt_buf),
  2088. qdf_nbuf_len(evt_buf));
  2089. if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
  2090. goto end;
  2091. data = qdf_nbuf_data(evt_buf);
  2092. len = qdf_nbuf_len(evt_buf);
  2093. #ifndef WMI_NON_TLV_SUPPORT
  2094. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  2095. /* Validate and pad(if necessary) the TLVs */
  2096. tlv_ok_status =
  2097. wmi_handle->ops->wmi_check_and_pad_event(wmi_handle->scn_handle,
  2098. data, len, id,
  2099. &wmi_cmd_struct_ptr);
  2100. if (tlv_ok_status != 0) {
  2101. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  2102. "%s: Error: id=0x%x, wmitlv check status=%d",
  2103. __func__, id, tlv_ok_status);
  2104. goto end;
  2105. }
  2106. }
  2107. #endif
  2108. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  2109. if (idx == A_ERROR) {
  2110. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  2111. "%s : event handler is not registered: event id 0x%x",
  2112. __func__, id);
  2113. goto end;
  2114. }
  2115. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2116. if (wmi_handle->log_info.wmi_logging_enable) {
  2117. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  2118. /* Exclude 4 bytes of TLV header */
  2119. if (wmi_handle->ops->is_diag_event(id)) {
  2120. /*
  2121. * skip diag event logging in WMI event buffer
  2122. * as its already logged in WMI RX event buffer
  2123. */
  2124. } else if (wmi_handle->ops->is_management_record(id)) {
  2125. /*
  2126. * skip wmi mgmt event logging in WMI event buffer
  2127. * as its already logged in WMI RX event buffer
  2128. */
  2129. } else {
  2130. WMI_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
  2131. wmi_handle->soc->buf_offset_event));
  2132. }
  2133. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  2134. }
  2135. #endif
  2136. /* Call the WMI registered event handler */
  2137. if (wmi_handle->target_type == WMI_TLV_TARGET)
  2138. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  2139. wmi_cmd_struct_ptr, len);
  2140. else
  2141. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  2142. data, len);
  2143. end:
  2144. /* Free event buffer and allocated event tlv */
  2145. #ifndef WMI_NON_TLV_SUPPORT
  2146. if (wmi_handle->target_type == WMI_TLV_TARGET)
  2147. wmi_handle->ops->wmi_free_allocated_event(id, &wmi_cmd_struct_ptr);
  2148. #endif
  2149. qdf_nbuf_free(evt_buf);
  2150. }
  2151. #define WMI_WQ_WD_TIMEOUT (30 * 1000) /* 30s */
  2152. static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id)
  2153. {
  2154. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  2155. "%s: WLAN_BUG_RCA: Message type %x has exceeded its alloted time of %ds",
  2156. __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000);
  2157. }
  2158. #ifdef CONFIG_SLUB_DEBUG_ON
  2159. static void wmi_workqueue_watchdog_bite(void *arg)
  2160. {
  2161. struct wmi_wq_dbg_info *info = arg;
  2162. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  2163. qdf_print_thread_trace(info->task);
  2164. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  2165. "%s: Going down for WMI WQ Watchdog Bite!", __func__);
  2166. QDF_BUG(0);
  2167. }
  2168. #else
  2169. static inline void wmi_workqueue_watchdog_bite(void *arg)
  2170. {
  2171. struct wmi_wq_dbg_info *info = arg;
  2172. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  2173. }
  2174. #endif
  2175. /**
  2176. * wmi_rx_event_work() - process rx event in rx work queue context
  2177. * @arg: opaque pointer to wmi handle
  2178. *
  2179. * This function process any fw event to serialize it through rx worker thread.
  2180. *
  2181. * Return: none
  2182. */
  2183. static void wmi_rx_event_work(void *arg)
  2184. {
  2185. wmi_buf_t buf;
  2186. struct wmi_unified *wmi = arg;
  2187. qdf_timer_t wd_timer;
  2188. struct wmi_wq_dbg_info info;
  2189. /* initialize WMI workqueue watchdog timer */
  2190. qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite,
  2191. &info, QDF_TIMER_TYPE_SW);
  2192. qdf_spin_lock_bh(&wmi->eventq_lock);
  2193. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  2194. qdf_spin_unlock_bh(&wmi->eventq_lock);
  2195. while (buf) {
  2196. qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT);
  2197. info.wd_msg_type_id =
  2198. WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID);
  2199. info.wmi_wq = wmi->wmi_rx_work_queue;
  2200. info.task = qdf_get_current_task();
  2201. __wmi_control_rx(wmi, buf);
  2202. qdf_timer_stop(&wd_timer);
  2203. qdf_spin_lock_bh(&wmi->eventq_lock);
  2204. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  2205. qdf_spin_unlock_bh(&wmi->eventq_lock);
  2206. }
  2207. qdf_timer_free(&wd_timer);
  2208. }
  2209. #ifdef FEATURE_RUNTIME_PM
  2210. /**
  2211. * wmi_runtime_pm_init() - initialize runtime pm wmi variables
  2212. * @wmi_handle: wmi context
  2213. */
  2214. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  2215. {
  2216. qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
  2217. }
  2218. /**
  2219. * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
  2220. * @wmi_handle: wmi context
  2221. * @val: runtime pm progress flag
  2222. */
  2223. void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
  2224. {
  2225. qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
  2226. }
  2227. /**
  2228. * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
  2229. * @wmi_handle: wmi context
  2230. */
  2231. inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
  2232. {
  2233. return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
  2234. }
  2235. #else
  2236. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  2237. {
  2238. }
  2239. #endif
  2240. /**
  2241. * wmi_unified_get_soc_handle: Get WMI SoC handle
  2242. * @param wmi_handle: WMI context got from wmi_attach
  2243. *
  2244. * return: Pointer to Soc handle
  2245. */
  2246. void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
  2247. {
  2248. return wmi_handle->soc;
  2249. }
  2250. /**
  2251. * wmi_interface_logging_init: Interface looging init
  2252. * @param wmi_handle: Pointer to wmi handle object
  2253. *
  2254. * return: None
  2255. */
  2256. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2257. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
  2258. uint32_t pdev_idx)
  2259. {
  2260. if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
  2261. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  2262. wmi_debugfs_init(wmi_handle, pdev_idx);
  2263. }
  2264. }
  2265. #else
  2266. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
  2267. uint32_t pdev_idx)
  2268. {
  2269. }
  2270. #endif
  2271. /**
  2272. * wmi_unified_get_pdev_handle: Get WMI SoC handle
  2273. * @param wmi_soc: Pointer to wmi soc object
  2274. * @param pdev_idx: pdev index
  2275. *
  2276. * return: Pointer to wmi handle or NULL on failure
  2277. */
  2278. void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
  2279. {
  2280. struct wmi_unified *wmi_handle;
  2281. if (pdev_idx >= WMI_MAX_RADIOS)
  2282. return NULL;
  2283. if (!soc->wmi_pdev[pdev_idx]) {
  2284. wmi_handle =
  2285. (struct wmi_unified *) qdf_mem_malloc(
  2286. sizeof(struct wmi_unified));
  2287. if (!wmi_handle)
  2288. return NULL;
  2289. wmi_handle->scn_handle = soc->scn_handle;
  2290. wmi_handle->event_id = soc->event_id;
  2291. wmi_handle->event_handler = soc->event_handler;
  2292. wmi_handle->ctx = soc->ctx;
  2293. wmi_handle->ops = soc->ops;
  2294. qdf_spinlock_create(&wmi_handle->eventq_lock);
  2295. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  2296. qdf_create_work(0, &wmi_handle->rx_event_work,
  2297. wmi_rx_event_work, wmi_handle);
  2298. wmi_handle->wmi_rx_work_queue =
  2299. qdf_alloc_unbound_workqueue("wmi_rx_event_work_queue");
  2300. if (!wmi_handle->wmi_rx_work_queue) {
  2301. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  2302. goto error;
  2303. }
  2304. wmi_handle->wmi_events = soc->wmi_events;
  2305. wmi_handle->services = soc->services;
  2306. wmi_handle->soc = soc;
  2307. wmi_handle->cmd_pdev_id_map = soc->cmd_pdev_id_map;
  2308. wmi_handle->evt_pdev_id_map = soc->evt_pdev_id_map;
  2309. wmi_handle->cmd_phy_id_map = soc->cmd_phy_id_map;
  2310. wmi_handle->evt_phy_id_map = soc->evt_phy_id_map;
  2311. wmi_interface_logging_init(wmi_handle, pdev_idx);
  2312. qdf_atomic_init(&wmi_handle->pending_cmds);
  2313. qdf_atomic_init(&wmi_handle->is_target_suspended);
  2314. wmi_handle->target_type = soc->target_type;
  2315. wmi_handle->wmi_max_cmds = soc->wmi_max_cmds;
  2316. soc->wmi_pdev[pdev_idx] = wmi_handle;
  2317. } else
  2318. wmi_handle = soc->wmi_pdev[pdev_idx];
  2319. wmi_handle->wmi_stopinprogress = 0;
  2320. wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
  2321. wmi_handle->htc_handle = soc->htc_handle;
  2322. wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
  2323. return wmi_handle;
  2324. error:
  2325. qdf_mem_free(wmi_handle);
  2326. return NULL;
  2327. }
  2328. qdf_export_symbol(wmi_unified_get_pdev_handle);
  2329. static void (*wmi_attach_register[WMI_MAX_TARGET_TYPE])(wmi_unified_t);
  2330. void wmi_unified_register_module(enum wmi_target_type target_type,
  2331. void (*wmi_attach)(wmi_unified_t wmi_handle))
  2332. {
  2333. if (target_type < WMI_MAX_TARGET_TYPE)
  2334. wmi_attach_register[target_type] = wmi_attach;
  2335. return;
  2336. }
  2337. qdf_export_symbol(wmi_unified_register_module);
  2338. /**
  2339. * wmi_wbuff_register() - register wmi with wbuff
  2340. * @wmi_handle: handle to wmi
  2341. *
  2342. * @Return: void
  2343. */
  2344. static void wmi_wbuff_register(struct wmi_unified *wmi_handle)
  2345. {
  2346. struct wbuff_alloc_request wbuff_alloc[4];
  2347. wbuff_alloc[0].slot = WBUFF_POOL_0;
  2348. wbuff_alloc[0].size = WMI_WBUFF_POOL_0_SIZE;
  2349. wbuff_alloc[1].slot = WBUFF_POOL_1;
  2350. wbuff_alloc[1].size = WMI_WBUFF_POOL_1_SIZE;
  2351. wbuff_alloc[2].slot = WBUFF_POOL_2;
  2352. wbuff_alloc[2].size = WMI_WBUFF_POOL_2_SIZE;
  2353. wbuff_alloc[3].slot = WBUFF_POOL_3;
  2354. wbuff_alloc[3].size = WMI_WBUFF_POOL_3_SIZE;
  2355. wmi_handle->wbuff_handle = wbuff_module_register(wbuff_alloc, 4,
  2356. WMI_MIN_HEAD_ROOM, 4);
  2357. }
  2358. /**
  2359. * wmi_wbuff_deregister() - deregister wmi with wbuff
  2360. * @wmi_handle: handle to wmi
  2361. *
  2362. * @Return: void
  2363. */
  2364. static inline void wmi_wbuff_deregister(struct wmi_unified *wmi_handle)
  2365. {
  2366. wbuff_module_deregister(wmi_handle->wbuff_handle);
  2367. wmi_handle->wbuff_handle = NULL;
  2368. }
  2369. /**
  2370. * wmi_unified_attach() - attach for unified WMI
  2371. * @scn_handle: handle to SCN
  2372. * @osdev: OS device context
  2373. * @target_type: TLV or not-TLV based target
  2374. * @use_cookie: cookie based allocation enabled/disabled
  2375. * @ops: umac rx callbacks
  2376. * @psoc: objmgr psoc
  2377. *
  2378. * @Return: wmi handle.
  2379. */
  2380. void *wmi_unified_attach(void *scn_handle,
  2381. struct wmi_unified_attach_params *param)
  2382. {
  2383. struct wmi_unified *wmi_handle;
  2384. struct wmi_soc *soc;
  2385. soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
  2386. if (!soc)
  2387. return NULL;
  2388. wmi_handle =
  2389. (struct wmi_unified *) qdf_mem_malloc(
  2390. sizeof(struct wmi_unified));
  2391. if (!wmi_handle) {
  2392. qdf_mem_free(soc);
  2393. return NULL;
  2394. }
  2395. wmi_handle->soc = soc;
  2396. wmi_handle->soc->soc_idx = param->soc_id;
  2397. wmi_handle->soc->is_async_ep = param->is_async_ep;
  2398. wmi_handle->event_id = soc->event_id;
  2399. wmi_handle->event_handler = soc->event_handler;
  2400. wmi_handle->ctx = soc->ctx;
  2401. wmi_handle->wmi_events = soc->wmi_events;
  2402. wmi_handle->services = soc->services;
  2403. wmi_handle->scn_handle = scn_handle;
  2404. wmi_handle->cmd_pdev_id_map = soc->cmd_pdev_id_map;
  2405. wmi_handle->evt_pdev_id_map = soc->evt_pdev_id_map;
  2406. wmi_handle->cmd_phy_id_map = soc->cmd_phy_id_map;
  2407. wmi_handle->evt_phy_id_map = soc->evt_phy_id_map;
  2408. soc->scn_handle = scn_handle;
  2409. qdf_atomic_init(&wmi_handle->pending_cmds);
  2410. qdf_atomic_init(&wmi_handle->is_target_suspended);
  2411. qdf_atomic_init(&wmi_handle->num_stats_over_qmi);
  2412. wmi_runtime_pm_init(wmi_handle);
  2413. qdf_spinlock_create(&wmi_handle->eventq_lock);
  2414. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  2415. qdf_create_work(0, &wmi_handle->rx_event_work,
  2416. wmi_rx_event_work, wmi_handle);
  2417. wmi_handle->wmi_rx_work_queue =
  2418. qdf_alloc_unbound_workqueue("wmi_rx_event_work_queue");
  2419. if (!wmi_handle->wmi_rx_work_queue) {
  2420. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  2421. goto error;
  2422. }
  2423. wmi_interface_logging_init(wmi_handle, WMI_HOST_PDEV_ID_0);
  2424. wmi_handle->target_type = param->target_type;
  2425. soc->target_type = param->target_type;
  2426. if (param->target_type >= WMI_MAX_TARGET_TYPE)
  2427. goto error;
  2428. if (wmi_attach_register[param->target_type]) {
  2429. wmi_attach_register[param->target_type](wmi_handle);
  2430. } else {
  2431. WMI_LOGE("wmi attach is not registered");
  2432. goto error;
  2433. }
  2434. /* Assign target cookie capablity */
  2435. wmi_handle->use_cookie = param->use_cookie;
  2436. wmi_handle->osdev = param->osdev;
  2437. wmi_handle->wmi_stopinprogress = 0;
  2438. wmi_handle->wmi_max_cmds = param->max_commands;
  2439. soc->wmi_max_cmds = param->max_commands;
  2440. /* Increase the ref count once refcount infra is present */
  2441. soc->wmi_psoc = param->psoc;
  2442. qdf_spinlock_create(&soc->ctx_lock);
  2443. soc->ops = wmi_handle->ops;
  2444. soc->wmi_pdev[0] = wmi_handle;
  2445. if (wmi_ext_dbgfs_init(wmi_handle) != QDF_STATUS_SUCCESS)
  2446. WMI_LOGE("failed to initialize wmi extended debugfs");
  2447. wmi_wbuff_register(wmi_handle);
  2448. return wmi_handle;
  2449. error:
  2450. qdf_mem_free(soc);
  2451. qdf_mem_free(wmi_handle);
  2452. return NULL;
  2453. }
  2454. /**
  2455. * wmi_unified_detach() - detach for unified WMI
  2456. *
  2457. * @wmi_handle : handle to wmi.
  2458. *
  2459. * @Return: none.
  2460. */
  2461. void wmi_unified_detach(struct wmi_unified *wmi_handle)
  2462. {
  2463. wmi_buf_t buf;
  2464. struct wmi_soc *soc;
  2465. uint8_t i;
  2466. wmi_wbuff_deregister(wmi_handle);
  2467. wmi_ext_dbgfs_deinit(wmi_handle);
  2468. soc = wmi_handle->soc;
  2469. for (i = 0; i < WMI_MAX_RADIOS; i++) {
  2470. if (soc->wmi_pdev[i]) {
  2471. qdf_flush_workqueue(0,
  2472. soc->wmi_pdev[i]->wmi_rx_work_queue);
  2473. qdf_destroy_workqueue(0,
  2474. soc->wmi_pdev[i]->wmi_rx_work_queue);
  2475. wmi_debugfs_remove(soc->wmi_pdev[i]);
  2476. buf = qdf_nbuf_queue_remove(
  2477. &soc->wmi_pdev[i]->event_queue);
  2478. while (buf) {
  2479. qdf_nbuf_free(buf);
  2480. buf = qdf_nbuf_queue_remove(
  2481. &soc->wmi_pdev[i]->event_queue);
  2482. }
  2483. wmi_log_buffer_free(soc->wmi_pdev[i]);
  2484. /* Free events logs list */
  2485. if (soc->wmi_pdev[i]->events_logs_list)
  2486. qdf_mem_free(
  2487. soc->wmi_pdev[i]->events_logs_list);
  2488. qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
  2489. qdf_mem_free(soc->wmi_pdev[i]);
  2490. }
  2491. }
  2492. qdf_spinlock_destroy(&soc->ctx_lock);
  2493. if (soc->wmi_service_bitmap) {
  2494. qdf_mem_free(soc->wmi_service_bitmap);
  2495. soc->wmi_service_bitmap = NULL;
  2496. }
  2497. if (soc->wmi_ext_service_bitmap) {
  2498. qdf_mem_free(soc->wmi_ext_service_bitmap);
  2499. soc->wmi_ext_service_bitmap = NULL;
  2500. }
  2501. /* Decrease the ref count once refcount infra is present */
  2502. soc->wmi_psoc = NULL;
  2503. qdf_mem_free(soc);
  2504. }
  2505. /**
  2506. * wmi_unified_remove_work() - detach for WMI work
  2507. * @wmi_handle: handle to WMI
  2508. *
  2509. * A function that does not fully detach WMI, but just remove work
  2510. * queue items associated with it. This is used to make sure that
  2511. * before any other processing code that may destroy related contexts
  2512. * (HTC, etc), work queue processing on WMI has already been stopped.
  2513. *
  2514. * Return: None
  2515. */
  2516. void
  2517. wmi_unified_remove_work(struct wmi_unified *wmi_handle)
  2518. {
  2519. wmi_buf_t buf;
  2520. qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
  2521. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  2522. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2523. while (buf) {
  2524. qdf_nbuf_free(buf);
  2525. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2526. }
  2527. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  2528. }
  2529. /**
  2530. * wmi_htc_tx_complete() - Process htc tx completion
  2531. *
  2532. * @ctx: handle to wmi
  2533. * @htc_packet: pointer to htc packet
  2534. *
  2535. * @Return: none.
  2536. */
  2537. static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
  2538. {
  2539. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  2540. wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
  2541. u_int8_t *buf_ptr;
  2542. u_int32_t len;
  2543. struct wmi_unified *wmi_handle;
  2544. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2545. uint32_t cmd_id;
  2546. #endif
  2547. ASSERT(wmi_cmd_buf);
  2548. wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
  2549. if (!wmi_handle) {
  2550. WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
  2551. QDF_ASSERT(0);
  2552. return;
  2553. }
  2554. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2555. if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
  2556. cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
  2557. WMI_CMD_HDR, COMMANDID);
  2558. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  2559. /* Record 16 bytes of WMI cmd tx complete data
  2560. - exclude TLV and WMI headers */
  2561. if (wmi_handle->ops->is_management_record(cmd_id)) {
  2562. WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2563. qdf_nbuf_data(wmi_cmd_buf) +
  2564. wmi_handle->soc->buf_offset_command);
  2565. } else {
  2566. WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2567. qdf_nbuf_data(wmi_cmd_buf) +
  2568. wmi_handle->soc->buf_offset_command);
  2569. }
  2570. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  2571. }
  2572. #endif
  2573. buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
  2574. len = qdf_nbuf_len(wmi_cmd_buf);
  2575. qdf_mem_zero(buf_ptr, len);
  2576. wmi_buf_free(wmi_cmd_buf);
  2577. qdf_mem_free(htc_pkt);
  2578. qdf_atomic_dec(&wmi_handle->pending_cmds);
  2579. }
  2580. #ifdef FEATURE_RUNTIME_PM
  2581. /**
  2582. * wmi_htc_log_pkt() - Print information of WMI command from HTC packet
  2583. *
  2584. * @ctx: handle of WMI context
  2585. * @htc_pkt: handle of HTC packet
  2586. *
  2587. * @Return: none
  2588. */
  2589. static void wmi_htc_log_pkt(void *ctx, HTC_PACKET *htc_pkt)
  2590. {
  2591. wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
  2592. uint32_t cmd_id;
  2593. ASSERT(wmi_cmd_buf);
  2594. cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf), WMI_CMD_HDR,
  2595. COMMANDID);
  2596. WMI_LOGD("WMI command from HTC packet: %s, ID: %d\n",
  2597. wmi_id_to_name(cmd_id), cmd_id);
  2598. }
  2599. #else
  2600. static void wmi_htc_log_pkt(void *ctx, HTC_PACKET *htc_pkt)
  2601. {
  2602. }
  2603. #endif
  2604. /**
  2605. * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
  2606. *
  2607. * @wmi_handle: handle to WMI.
  2608. * @pdev_idx: Pdev index
  2609. *
  2610. * @Return: QDF_STATUS
  2611. */
  2612. static QDF_STATUS wmi_connect_pdev_htc_service(struct wmi_soc *soc,
  2613. uint32_t pdev_idx)
  2614. {
  2615. QDF_STATUS status;
  2616. struct htc_service_connect_resp response;
  2617. struct htc_service_connect_req connect;
  2618. OS_MEMZERO(&connect, sizeof(connect));
  2619. OS_MEMZERO(&response, sizeof(response));
  2620. /* meta data is unused for now */
  2621. connect.pMetaData = NULL;
  2622. connect.MetaDataLength = 0;
  2623. /* these fields are the same for all service endpoints */
  2624. connect.EpCallbacks.pContext = soc;
  2625. connect.EpCallbacks.EpTxCompleteMultiple =
  2626. NULL /* Control path completion ar6000_tx_complete */;
  2627. connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
  2628. connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
  2629. connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
  2630. connect.EpCallbacks.EpTxComplete =
  2631. wmi_htc_tx_complete /* ar6000_tx_queue_full */;
  2632. connect.EpCallbacks.ep_log_pkt = wmi_htc_log_pkt;
  2633. /* connect to control service */
  2634. connect.service_id = soc->svc_ids[pdev_idx];
  2635. status = htc_connect_service(soc->htc_handle, &connect, &response);
  2636. if (QDF_IS_STATUS_ERROR(status)) {
  2637. WMI_LOGE("Failed to connect to WMI CONTROL service status:%d\n",
  2638. status);
  2639. return status;
  2640. }
  2641. if (soc->is_async_ep)
  2642. htc_set_async_ep(soc->htc_handle, response.Endpoint, true);
  2643. soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
  2644. soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
  2645. return QDF_STATUS_SUCCESS;
  2646. }
  2647. QDF_STATUS
  2648. wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
  2649. HTC_HANDLE htc_handle)
  2650. {
  2651. uint32_t i;
  2652. uint8_t wmi_ep_count;
  2653. wmi_handle->soc->htc_handle = htc_handle;
  2654. wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
  2655. if (wmi_ep_count > WMI_MAX_RADIOS)
  2656. return QDF_STATUS_E_FAULT;
  2657. for (i = 0; i < wmi_ep_count; i++)
  2658. wmi_connect_pdev_htc_service(wmi_handle->soc, i);
  2659. wmi_handle->htc_handle = htc_handle;
  2660. wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
  2661. wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
  2662. return QDF_STATUS_SUCCESS;
  2663. }
  2664. /**
  2665. * wmi_get_host_credits() - WMI API to get updated host_credits
  2666. *
  2667. * @wmi_handle: handle to WMI.
  2668. *
  2669. * @Return: updated host_credits.
  2670. */
  2671. int wmi_get_host_credits(wmi_unified_t wmi_handle)
  2672. {
  2673. int host_credits = 0;
  2674. htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
  2675. &host_credits);
  2676. return host_credits;
  2677. }
  2678. /**
  2679. * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
  2680. * queue
  2681. *
  2682. * @wmi_handle: handle to WMI.
  2683. *
  2684. * @Return: Pending Commands in the HTC queue.
  2685. */
  2686. int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
  2687. {
  2688. return qdf_atomic_read(&wmi_handle->pending_cmds);
  2689. }
  2690. /**
  2691. * wmi_set_target_suspend() - WMI API to set target suspend state
  2692. *
  2693. * @wmi_handle: handle to WMI.
  2694. * @val: suspend state boolean.
  2695. *
  2696. * @Return: none.
  2697. */
  2698. void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
  2699. {
  2700. qdf_atomic_set(&wmi_handle->is_target_suspended, val);
  2701. }
  2702. /**
  2703. * wmi_is_target_suspended() - WMI API to check target suspend state
  2704. * @wmi_handle: handle to WMI.
  2705. *
  2706. * WMI API to check target suspend state
  2707. *
  2708. * Return: true if target is suspended, else false.
  2709. */
  2710. bool wmi_is_target_suspended(struct wmi_unified *wmi_handle)
  2711. {
  2712. return qdf_atomic_read(&wmi_handle->is_target_suspended);
  2713. }
  2714. /**
  2715. * WMI API to set crash injection state
  2716. * @param wmi_handle: handle to WMI.
  2717. * @param val: crash injection state boolean.
  2718. */
  2719. void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
  2720. {
  2721. wmi_handle->tag_crash_inject = flag;
  2722. }
  2723. /**
  2724. * WMI API to set bus suspend state
  2725. * @param wmi_handle: handle to WMI.
  2726. * @param val: suspend state boolean.
  2727. */
  2728. void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
  2729. {
  2730. qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
  2731. }
  2732. void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val)
  2733. {
  2734. wmi_handle->tgt_force_assert_enable = val;
  2735. }
  2736. /**
  2737. * wmi_stop() - generic function to block unified WMI command
  2738. * @wmi_handle: handle to WMI.
  2739. *
  2740. * @Return: success always.
  2741. */
  2742. int
  2743. wmi_stop(wmi_unified_t wmi_handle)
  2744. {
  2745. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  2746. "WMI Stop");
  2747. wmi_handle->wmi_stopinprogress = 1;
  2748. return 0;
  2749. }
  2750. /**
  2751. * wmi_start() - generic function to allow unified WMI command
  2752. * @wmi_handle: handle to WMI.
  2753. *
  2754. * @Return: success always.
  2755. */
  2756. int
  2757. wmi_start(wmi_unified_t wmi_handle)
  2758. {
  2759. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  2760. "WMI Start");
  2761. wmi_handle->wmi_stopinprogress = 0;
  2762. return 0;
  2763. }
  2764. /**
  2765. * API to flush all the previous packets associated with the wmi endpoint
  2766. *
  2767. * @param wmi_handle : handle to WMI.
  2768. */
  2769. void
  2770. wmi_flush_endpoint(wmi_unified_t wmi_handle)
  2771. {
  2772. htc_flush_endpoint(wmi_handle->htc_handle,
  2773. wmi_handle->wmi_endpoint_id, 0);
  2774. }
  2775. qdf_export_symbol(wmi_flush_endpoint);
  2776. /**
  2777. * wmi_pdev_id_conversion_enable() - API to enable pdev_id/phy_id conversion
  2778. * in WMI. By default pdev_id conversion is not done in WMI.
  2779. * This API can be used enable conversion in WMI.
  2780. * @param wmi_handle : handle to WMI
  2781. * @param pdev_map : pointer to pdev_map
  2782. * @size : size of pdev_id_map
  2783. * Return none
  2784. */
  2785. void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle,
  2786. uint32_t *pdev_id_map,
  2787. uint8_t size)
  2788. {
  2789. if (wmi_handle->target_type == WMI_TLV_TARGET)
  2790. wmi_handle->ops->wmi_pdev_id_conversion_enable(wmi_handle,
  2791. pdev_id_map,
  2792. size);
  2793. }