wmi_unified.c 81 KB

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