wmi_unified.c 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790
  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_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_control_rx() - process fw events callbacks
  1743. * @ctx: handle to wmi
  1744. * @htc_packet: pointer to htc packet
  1745. *
  1746. * Return: none
  1747. */
  1748. static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
  1749. {
  1750. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  1751. struct wmi_unified *wmi_handle;
  1752. wmi_buf_t evt_buf;
  1753. uint32_t id;
  1754. uint32_t idx = 0;
  1755. enum wmi_rx_exec_ctx exec_ctx;
  1756. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1757. wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
  1758. if (wmi_handle == NULL) {
  1759. qdf_print
  1760. ("unable to get wmi_handle to Endpoint %d\n",
  1761. htc_packet->Endpoint);
  1762. qdf_nbuf_free(evt_buf);
  1763. return;
  1764. }
  1765. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  1766. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  1767. if (qdf_unlikely(idx == A_ERROR)) {
  1768. WMI_LOGD("%s :event handler is not registered: event id 0x%x\n",
  1769. __func__, id);
  1770. qdf_nbuf_free(evt_buf);
  1771. return;
  1772. }
  1773. qdf_spin_lock_bh(&soc->ctx_lock);
  1774. exec_ctx = wmi_handle->ctx[idx];
  1775. qdf_spin_unlock_bh(&soc->ctx_lock);
  1776. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1777. if (wmi_handle->log_info.wmi_logging_enable) {
  1778. uint8_t *data;
  1779. data = qdf_nbuf_data(evt_buf);
  1780. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1781. /* Exclude 4 bytes of TLV header */
  1782. WMI_RX_EVENT_RECORD(wmi_handle, id, data +
  1783. wmi_handle->log_info.buf_offset_event);
  1784. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1785. }
  1786. #endif
  1787. if (exec_ctx == WMI_RX_WORK_CTX) {
  1788. wmi_process_fw_event_worker_thread_ctx
  1789. (wmi_handle, htc_packet);
  1790. } else if (exec_ctx > WMI_RX_WORK_CTX) {
  1791. wmi_process_fw_event_default_ctx
  1792. (wmi_handle, htc_packet, exec_ctx);
  1793. } else {
  1794. qdf_print("Invalid event context %d", exec_ctx);
  1795. qdf_nbuf_free(evt_buf);
  1796. }
  1797. }
  1798. /**
  1799. * wmi_process_fw_event() - process any fw event
  1800. * @wmi_handle: wmi handle
  1801. * @evt_buf: fw event buffer
  1802. *
  1803. * This function process fw event in caller context
  1804. *
  1805. * Return: none
  1806. */
  1807. void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  1808. {
  1809. __wmi_control_rx(wmi_handle, evt_buf);
  1810. }
  1811. /**
  1812. * __wmi_control_rx() - process serialize wmi event callback
  1813. * @wmi_handle: wmi handle
  1814. * @evt_buf: fw event buffer
  1815. *
  1816. * Return: none
  1817. */
  1818. void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  1819. {
  1820. uint32_t id;
  1821. uint8_t *data;
  1822. uint32_t len;
  1823. void *wmi_cmd_struct_ptr = NULL;
  1824. #ifndef WMI_NON_TLV_SUPPORT
  1825. int tlv_ok_status = 0;
  1826. #endif
  1827. uint32_t idx = 0;
  1828. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  1829. wmi_ext_dbg_msg_event_record(wmi_handle, qdf_nbuf_data(evt_buf),
  1830. qdf_nbuf_len(evt_buf));
  1831. if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
  1832. goto end;
  1833. data = qdf_nbuf_data(evt_buf);
  1834. len = qdf_nbuf_len(evt_buf);
  1835. #ifndef WMI_NON_TLV_SUPPORT
  1836. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  1837. /* Validate and pad(if necessary) the TLVs */
  1838. tlv_ok_status =
  1839. wmi_handle->ops->wmi_check_and_pad_event(wmi_handle->scn_handle,
  1840. data, len, id,
  1841. &wmi_cmd_struct_ptr);
  1842. if (tlv_ok_status != 0) {
  1843. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1844. "%s: Error: id=0x%x, wmitlv check status=%d",
  1845. __func__, id, tlv_ok_status);
  1846. goto end;
  1847. }
  1848. }
  1849. #endif
  1850. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  1851. if (idx == A_ERROR) {
  1852. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1853. "%s : event handler is not registered: event id 0x%x",
  1854. __func__, id);
  1855. goto end;
  1856. }
  1857. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1858. if (wmi_handle->log_info.wmi_logging_enable) {
  1859. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1860. /* Exclude 4 bytes of TLV header */
  1861. if (wmi_handle->ops->is_management_record(id)) {
  1862. WMI_MGMT_EVENT_RECORD(wmi_handle, id, data
  1863. + wmi_handle->log_info.buf_offset_event);
  1864. } else {
  1865. WMI_EVENT_RECORD(wmi_handle, id, data +
  1866. wmi_handle->log_info.buf_offset_event);
  1867. }
  1868. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1869. }
  1870. #endif
  1871. /* Call the WMI registered event handler */
  1872. if (wmi_handle->target_type == WMI_TLV_TARGET)
  1873. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  1874. wmi_cmd_struct_ptr, len);
  1875. else
  1876. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  1877. data, len);
  1878. end:
  1879. /* Free event buffer and allocated event tlv */
  1880. #ifndef WMI_NON_TLV_SUPPORT
  1881. if (wmi_handle->target_type == WMI_TLV_TARGET)
  1882. wmi_handle->ops->wmi_free_allocated_event(id, &wmi_cmd_struct_ptr);
  1883. #endif
  1884. qdf_nbuf_free(evt_buf);
  1885. }
  1886. #define WMI_WQ_WD_TIMEOUT (30 * 1000) /* 30s */
  1887. static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id)
  1888. {
  1889. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  1890. "%s: WLAN_BUG_RCA: Message type %x has exceeded its alloted time of %ds",
  1891. __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000);
  1892. }
  1893. #ifdef CONFIG_SLUB_DEBUG_ON
  1894. static void wmi_workqueue_watchdog_bite(void *arg)
  1895. {
  1896. struct wmi_wq_dbg_info *info = arg;
  1897. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  1898. qdf_print_thread_trace(info->task);
  1899. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  1900. "%s: Going down for WMI WQ Watchdog Bite!", __func__);
  1901. QDF_BUG(0);
  1902. }
  1903. #else
  1904. static inline void wmi_workqueue_watchdog_bite(void *arg)
  1905. {
  1906. struct wmi_wq_dbg_info *info = arg;
  1907. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  1908. }
  1909. #endif
  1910. /**
  1911. * wmi_rx_event_work() - process rx event in rx work queue context
  1912. * @arg: opaque pointer to wmi handle
  1913. *
  1914. * This function process any fw event to serialize it through rx worker thread.
  1915. *
  1916. * Return: none
  1917. */
  1918. static void wmi_rx_event_work(void *arg)
  1919. {
  1920. wmi_buf_t buf;
  1921. struct wmi_unified *wmi = arg;
  1922. qdf_timer_t wd_timer;
  1923. struct wmi_wq_dbg_info info;
  1924. /* initialize WMI workqueue watchdog timer */
  1925. qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite,
  1926. &info, QDF_TIMER_TYPE_SW);
  1927. qdf_spin_lock_bh(&wmi->eventq_lock);
  1928. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  1929. qdf_spin_unlock_bh(&wmi->eventq_lock);
  1930. while (buf) {
  1931. qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT);
  1932. info.wd_msg_type_id =
  1933. WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID);
  1934. info.wmi_wq = wmi->wmi_rx_work_queue;
  1935. info.task = qdf_get_current_task();
  1936. __wmi_control_rx(wmi, buf);
  1937. qdf_timer_stop(&wd_timer);
  1938. qdf_spin_lock_bh(&wmi->eventq_lock);
  1939. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  1940. qdf_spin_unlock_bh(&wmi->eventq_lock);
  1941. }
  1942. qdf_timer_free(&wd_timer);
  1943. }
  1944. #ifdef FEATURE_RUNTIME_PM
  1945. /**
  1946. * wmi_runtime_pm_init() - initialize runtime pm wmi variables
  1947. * @wmi_handle: wmi context
  1948. */
  1949. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  1950. {
  1951. qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
  1952. }
  1953. /**
  1954. * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
  1955. * @wmi_handle: wmi context
  1956. * @val: runtime pm progress flag
  1957. */
  1958. void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
  1959. {
  1960. qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
  1961. }
  1962. /**
  1963. * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
  1964. * @wmi_handle: wmi context
  1965. */
  1966. inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
  1967. {
  1968. return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
  1969. }
  1970. #else
  1971. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  1972. {
  1973. }
  1974. #endif
  1975. /**
  1976. * wmi_unified_get_soc_handle: Get WMI SoC handle
  1977. * @param wmi_handle: WMI context got from wmi_attach
  1978. *
  1979. * return: Pointer to Soc handle
  1980. */
  1981. void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
  1982. {
  1983. return wmi_handle->soc;
  1984. }
  1985. /**
  1986. * wmi_interface_logging_init: Interface looging init
  1987. * @param wmi_handle: Pointer to wmi handle object
  1988. *
  1989. * return: None
  1990. */
  1991. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1992. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
  1993. uint32_t pdev_idx)
  1994. {
  1995. if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
  1996. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  1997. wmi_debugfs_init(wmi_handle, pdev_idx);
  1998. }
  1999. }
  2000. #else
  2001. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
  2002. uint32_t pdev_idx)
  2003. {
  2004. }
  2005. #endif
  2006. /**
  2007. * wmi_target_params_init: Target specific params init
  2008. * @param wmi_soc: Pointer to wmi soc object
  2009. * @param wmi_handle: Pointer to wmi handle object
  2010. *
  2011. * return: None
  2012. */
  2013. #ifndef CONFIG_MCL
  2014. static inline void wmi_target_params_init(struct wmi_soc *soc,
  2015. struct wmi_unified *wmi_handle)
  2016. {
  2017. wmi_handle->pdev_param = soc->pdev_param;
  2018. wmi_handle->vdev_param = soc->vdev_param;
  2019. wmi_handle->services = soc->services;
  2020. }
  2021. #else
  2022. static inline void wmi_target_params_init(struct wmi_soc *soc,
  2023. struct wmi_unified *wmi_handle)
  2024. {
  2025. wmi_handle->services = soc->services;
  2026. }
  2027. #endif
  2028. /**
  2029. * wmi_unified_get_pdev_handle: Get WMI SoC handle
  2030. * @param wmi_soc: Pointer to wmi soc object
  2031. * @param pdev_idx: pdev index
  2032. *
  2033. * return: Pointer to wmi handle or NULL on failure
  2034. */
  2035. void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
  2036. {
  2037. struct wmi_unified *wmi_handle;
  2038. if (pdev_idx >= WMI_MAX_RADIOS)
  2039. return NULL;
  2040. if (soc->wmi_pdev[pdev_idx] == NULL) {
  2041. wmi_handle =
  2042. (struct wmi_unified *) qdf_mem_malloc(
  2043. sizeof(struct wmi_unified));
  2044. if (wmi_handle == NULL) {
  2045. qdf_print("allocation of wmi handle failed %zu",
  2046. sizeof(struct wmi_unified));
  2047. return NULL;
  2048. }
  2049. wmi_handle->scn_handle = soc->scn_handle;
  2050. wmi_handle->event_id = soc->event_id;
  2051. wmi_handle->event_handler = soc->event_handler;
  2052. wmi_handle->ctx = soc->ctx;
  2053. wmi_handle->ops = soc->ops;
  2054. qdf_spinlock_create(&wmi_handle->eventq_lock);
  2055. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  2056. qdf_create_work(0, &wmi_handle->rx_event_work,
  2057. wmi_rx_event_work, wmi_handle);
  2058. wmi_handle->wmi_rx_work_queue =
  2059. qdf_create_workqueue("wmi_rx_event_work_queue");
  2060. if (NULL == wmi_handle->wmi_rx_work_queue) {
  2061. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  2062. goto error;
  2063. }
  2064. wmi_handle->wmi_events = soc->wmi_events;
  2065. wmi_target_params_init(soc, wmi_handle);
  2066. wmi_handle->soc = soc;
  2067. wmi_interface_logging_init(wmi_handle, pdev_idx);
  2068. qdf_atomic_init(&wmi_handle->pending_cmds);
  2069. qdf_atomic_init(&wmi_handle->is_target_suspended);
  2070. wmi_handle->target_type = soc->target_type;
  2071. wmi_handle->wmi_max_cmds = soc->wmi_max_cmds;
  2072. soc->wmi_pdev[pdev_idx] = wmi_handle;
  2073. } else
  2074. wmi_handle = soc->wmi_pdev[pdev_idx];
  2075. wmi_handle->wmi_stopinprogress = 0;
  2076. wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
  2077. wmi_handle->htc_handle = soc->htc_handle;
  2078. wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
  2079. return wmi_handle;
  2080. error:
  2081. qdf_mem_free(wmi_handle);
  2082. return NULL;
  2083. }
  2084. qdf_export_symbol(wmi_unified_get_pdev_handle);
  2085. static void (*wmi_attach_register[WMI_MAX_TARGET_TYPE])(wmi_unified_t);
  2086. void wmi_unified_register_module(enum wmi_target_type target_type,
  2087. void (*wmi_attach)(wmi_unified_t wmi_handle))
  2088. {
  2089. if (target_type < WMI_MAX_TARGET_TYPE)
  2090. wmi_attach_register[target_type] = wmi_attach;
  2091. return;
  2092. }
  2093. qdf_export_symbol(wmi_unified_register_module);
  2094. /**
  2095. * wmi_unified_attach() - attach for unified WMI
  2096. * @scn_handle: handle to SCN
  2097. * @osdev: OS device context
  2098. * @target_type: TLV or not-TLV based target
  2099. * @use_cookie: cookie based allocation enabled/disabled
  2100. * @ops: umac rx callbacks
  2101. * @psoc: objmgr psoc
  2102. *
  2103. * @Return: wmi handle.
  2104. */
  2105. void *wmi_unified_attach(void *scn_handle,
  2106. struct wmi_unified_attach_params *param)
  2107. {
  2108. struct wmi_unified *wmi_handle;
  2109. struct wmi_soc *soc;
  2110. soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
  2111. if (soc == NULL) {
  2112. qdf_print("Allocation of wmi_soc failed %zu",
  2113. sizeof(struct wmi_soc));
  2114. return NULL;
  2115. }
  2116. wmi_handle =
  2117. (struct wmi_unified *) qdf_mem_malloc(
  2118. sizeof(struct wmi_unified));
  2119. if (wmi_handle == NULL) {
  2120. qdf_mem_free(soc);
  2121. qdf_print("allocation of wmi handle failed %zu",
  2122. sizeof(struct wmi_unified));
  2123. return NULL;
  2124. }
  2125. wmi_handle->soc = soc;
  2126. wmi_handle->soc->soc_idx = param->soc_id;
  2127. wmi_handle->event_id = soc->event_id;
  2128. wmi_handle->event_handler = soc->event_handler;
  2129. wmi_handle->ctx = soc->ctx;
  2130. wmi_handle->wmi_events = soc->wmi_events;
  2131. wmi_target_params_init(soc, wmi_handle);
  2132. wmi_handle->scn_handle = scn_handle;
  2133. soc->scn_handle = scn_handle;
  2134. qdf_atomic_init(&wmi_handle->pending_cmds);
  2135. qdf_atomic_init(&wmi_handle->is_target_suspended);
  2136. wmi_runtime_pm_init(wmi_handle);
  2137. qdf_spinlock_create(&wmi_handle->eventq_lock);
  2138. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  2139. qdf_create_work(0, &wmi_handle->rx_event_work,
  2140. wmi_rx_event_work, wmi_handle);
  2141. wmi_handle->wmi_rx_work_queue =
  2142. qdf_create_workqueue("wmi_rx_event_work_queue");
  2143. if (NULL == wmi_handle->wmi_rx_work_queue) {
  2144. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  2145. goto error;
  2146. }
  2147. wmi_interface_logging_init(wmi_handle, WMI_HOST_PDEV_ID_0);
  2148. /* Attach mc_thread context processing function */
  2149. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
  2150. param->rx_ops->wma_process_fw_event_handler_cbk;
  2151. wmi_handle->target_type = param->target_type;
  2152. soc->target_type = param->target_type;
  2153. if (param->target_type >= WMI_MAX_TARGET_TYPE)
  2154. goto error;
  2155. if (wmi_attach_register[param->target_type]) {
  2156. wmi_attach_register[param->target_type](wmi_handle);
  2157. } else {
  2158. WMI_LOGE("wmi attach is not registered");
  2159. goto error;
  2160. }
  2161. /* Assign target cookie capablity */
  2162. wmi_handle->use_cookie = param->use_cookie;
  2163. wmi_handle->osdev = param->osdev;
  2164. wmi_handle->wmi_stopinprogress = 0;
  2165. wmi_handle->wmi_max_cmds = param->max_commands;
  2166. soc->wmi_max_cmds = param->max_commands;
  2167. /* Increase the ref count once refcount infra is present */
  2168. soc->wmi_psoc = param->psoc;
  2169. qdf_spinlock_create(&soc->ctx_lock);
  2170. soc->ops = wmi_handle->ops;
  2171. soc->wmi_pdev[0] = wmi_handle;
  2172. if (wmi_ext_dbgfs_init(wmi_handle) != QDF_STATUS_SUCCESS)
  2173. qdf_print("failed to initialize wmi extended debugfs");
  2174. return wmi_handle;
  2175. error:
  2176. qdf_mem_free(soc);
  2177. qdf_mem_free(wmi_handle);
  2178. return NULL;
  2179. }
  2180. /**
  2181. * wmi_unified_detach() - detach for unified WMI
  2182. *
  2183. * @wmi_handle : handle to wmi.
  2184. *
  2185. * @Return: none.
  2186. */
  2187. void wmi_unified_detach(struct wmi_unified *wmi_handle)
  2188. {
  2189. wmi_buf_t buf;
  2190. struct wmi_soc *soc;
  2191. uint8_t i;
  2192. wmi_ext_dbgfs_deinit(wmi_handle);
  2193. soc = wmi_handle->soc;
  2194. for (i = 0; i < WMI_MAX_RADIOS; i++) {
  2195. if (soc->wmi_pdev[i]) {
  2196. qdf_flush_workqueue(0,
  2197. soc->wmi_pdev[i]->wmi_rx_work_queue);
  2198. qdf_destroy_workqueue(0,
  2199. soc->wmi_pdev[i]->wmi_rx_work_queue);
  2200. wmi_debugfs_remove(soc->wmi_pdev[i]);
  2201. buf = qdf_nbuf_queue_remove(
  2202. &soc->wmi_pdev[i]->event_queue);
  2203. while (buf) {
  2204. qdf_nbuf_free(buf);
  2205. buf = qdf_nbuf_queue_remove(
  2206. &soc->wmi_pdev[i]->event_queue);
  2207. }
  2208. wmi_log_buffer_free(soc->wmi_pdev[i]);
  2209. /* Free events logs list */
  2210. if (soc->wmi_pdev[i]->events_logs_list)
  2211. qdf_mem_free(
  2212. soc->wmi_pdev[i]->events_logs_list);
  2213. qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
  2214. qdf_mem_free(soc->wmi_pdev[i]);
  2215. }
  2216. }
  2217. qdf_spinlock_destroy(&soc->ctx_lock);
  2218. if (soc->wmi_service_bitmap) {
  2219. qdf_mem_free(soc->wmi_service_bitmap);
  2220. soc->wmi_service_bitmap = NULL;
  2221. }
  2222. if (soc->wmi_ext_service_bitmap) {
  2223. qdf_mem_free(soc->wmi_ext_service_bitmap);
  2224. soc->wmi_ext_service_bitmap = NULL;
  2225. }
  2226. /* Decrease the ref count once refcount infra is present */
  2227. soc->wmi_psoc = NULL;
  2228. qdf_mem_free(soc);
  2229. }
  2230. /**
  2231. * wmi_unified_remove_work() - detach for WMI work
  2232. * @wmi_handle: handle to WMI
  2233. *
  2234. * A function that does not fully detach WMI, but just remove work
  2235. * queue items associated with it. This is used to make sure that
  2236. * before any other processing code that may destroy related contexts
  2237. * (HTC, etc), work queue processing on WMI has already been stopped.
  2238. *
  2239. * Return: None
  2240. */
  2241. void
  2242. wmi_unified_remove_work(struct wmi_unified *wmi_handle)
  2243. {
  2244. wmi_buf_t buf;
  2245. qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
  2246. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  2247. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2248. while (buf) {
  2249. qdf_nbuf_free(buf);
  2250. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2251. }
  2252. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  2253. }
  2254. /**
  2255. * wmi_htc_tx_complete() - Process htc tx completion
  2256. *
  2257. * @ctx: handle to wmi
  2258. * @htc_packet: pointer to htc packet
  2259. *
  2260. * @Return: none.
  2261. */
  2262. static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
  2263. {
  2264. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  2265. wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
  2266. u_int8_t *buf_ptr;
  2267. u_int32_t len;
  2268. struct wmi_unified *wmi_handle;
  2269. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2270. uint32_t cmd_id;
  2271. #endif
  2272. ASSERT(wmi_cmd_buf);
  2273. wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
  2274. if (wmi_handle == NULL) {
  2275. WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
  2276. QDF_ASSERT(0);
  2277. return;
  2278. }
  2279. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2280. if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
  2281. cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
  2282. WMI_CMD_HDR, COMMANDID);
  2283. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  2284. /* Record 16 bytes of WMI cmd tx complete data
  2285. - exclude TLV and WMI headers */
  2286. if (wmi_handle->ops->is_management_record(cmd_id)) {
  2287. WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2288. qdf_nbuf_data(wmi_cmd_buf) +
  2289. wmi_handle->log_info.buf_offset_command);
  2290. } else {
  2291. WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2292. qdf_nbuf_data(wmi_cmd_buf) +
  2293. wmi_handle->log_info.buf_offset_command);
  2294. }
  2295. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  2296. }
  2297. #endif
  2298. buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
  2299. len = qdf_nbuf_len(wmi_cmd_buf);
  2300. qdf_mem_zero(buf_ptr, len);
  2301. qdf_nbuf_free(wmi_cmd_buf);
  2302. qdf_mem_free(htc_pkt);
  2303. qdf_atomic_dec(&wmi_handle->pending_cmds);
  2304. }
  2305. /**
  2306. * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
  2307. *
  2308. * @wmi_handle: handle to WMI.
  2309. * @pdev_idx: Pdev index
  2310. *
  2311. * @Return: status.
  2312. */
  2313. static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
  2314. uint32_t pdev_idx)
  2315. {
  2316. int status;
  2317. struct htc_service_connect_resp response;
  2318. struct htc_service_connect_req connect;
  2319. OS_MEMZERO(&connect, sizeof(connect));
  2320. OS_MEMZERO(&response, sizeof(response));
  2321. /* meta data is unused for now */
  2322. connect.pMetaData = NULL;
  2323. connect.MetaDataLength = 0;
  2324. /* these fields are the same for all service endpoints */
  2325. connect.EpCallbacks.pContext = soc;
  2326. connect.EpCallbacks.EpTxCompleteMultiple =
  2327. NULL /* Control path completion ar6000_tx_complete */;
  2328. connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
  2329. connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
  2330. connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
  2331. connect.EpCallbacks.EpTxComplete =
  2332. wmi_htc_tx_complete /* ar6000_tx_queue_full */;
  2333. /* connect to control service */
  2334. connect.service_id = soc->svc_ids[pdev_idx];
  2335. status = htc_connect_service(soc->htc_handle, &connect,
  2336. &response);
  2337. if (status != EOK) {
  2338. qdf_print
  2339. ("Failed to connect to WMI CONTROL service status:%d\n",
  2340. status);
  2341. return status;
  2342. }
  2343. soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
  2344. soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
  2345. return 0;
  2346. }
  2347. /**
  2348. * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
  2349. *
  2350. * @wmi_handle: handle to WMI.
  2351. *
  2352. * @Return: status.
  2353. */
  2354. QDF_STATUS
  2355. wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
  2356. void *htc_handle)
  2357. {
  2358. uint32_t i;
  2359. uint8_t wmi_ep_count;
  2360. wmi_handle->soc->htc_handle = htc_handle;
  2361. wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
  2362. if (wmi_ep_count > WMI_MAX_RADIOS)
  2363. return QDF_STATUS_E_FAULT;
  2364. for (i = 0; i < wmi_ep_count; i++)
  2365. wmi_connect_pdev_htc_service(wmi_handle->soc, i);
  2366. wmi_handle->htc_handle = htc_handle;
  2367. wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
  2368. wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
  2369. return QDF_STATUS_SUCCESS;
  2370. }
  2371. /**
  2372. * wmi_get_host_credits() - WMI API to get updated host_credits
  2373. *
  2374. * @wmi_handle: handle to WMI.
  2375. *
  2376. * @Return: updated host_credits.
  2377. */
  2378. int wmi_get_host_credits(wmi_unified_t wmi_handle)
  2379. {
  2380. int host_credits = 0;
  2381. htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
  2382. &host_credits);
  2383. return host_credits;
  2384. }
  2385. /**
  2386. * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
  2387. * queue
  2388. *
  2389. * @wmi_handle: handle to WMI.
  2390. *
  2391. * @Return: Pending Commands in the HTC queue.
  2392. */
  2393. int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
  2394. {
  2395. return qdf_atomic_read(&wmi_handle->pending_cmds);
  2396. }
  2397. /**
  2398. * wmi_set_target_suspend() - WMI API to set target suspend state
  2399. *
  2400. * @wmi_handle: handle to WMI.
  2401. * @val: suspend state boolean.
  2402. *
  2403. * @Return: none.
  2404. */
  2405. void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
  2406. {
  2407. qdf_atomic_set(&wmi_handle->is_target_suspended, val);
  2408. }
  2409. /**
  2410. * WMI API to set crash injection state
  2411. * @param wmi_handle: handle to WMI.
  2412. * @param val: crash injection state boolean.
  2413. */
  2414. void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
  2415. {
  2416. wmi_handle->tag_crash_inject = flag;
  2417. }
  2418. /**
  2419. * WMI API to set bus suspend state
  2420. * @param wmi_handle: handle to WMI.
  2421. * @param val: suspend state boolean.
  2422. */
  2423. void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
  2424. {
  2425. qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
  2426. }
  2427. void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val)
  2428. {
  2429. wmi_handle->tgt_force_assert_enable = val;
  2430. }
  2431. /**
  2432. * wmi_stop() - generic function to block unified WMI command
  2433. * @wmi_handle: handle to WMI.
  2434. *
  2435. * @Return: success always.
  2436. */
  2437. int
  2438. wmi_stop(wmi_unified_t wmi_handle)
  2439. {
  2440. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  2441. "WMI Stop");
  2442. wmi_handle->wmi_stopinprogress = 1;
  2443. return 0;
  2444. }
  2445. #ifndef CONFIG_MCL
  2446. /**
  2447. * API to flush all the previous packets associated with the wmi endpoint
  2448. *
  2449. * @param wmi_handle : handle to WMI.
  2450. */
  2451. void
  2452. wmi_flush_endpoint(wmi_unified_t wmi_handle)
  2453. {
  2454. htc_flush_endpoint(wmi_handle->htc_handle,
  2455. wmi_handle->wmi_endpoint_id, 0);
  2456. }
  2457. qdf_export_symbol(wmi_flush_endpoint);
  2458. /**
  2459. * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI
  2460. * By default pdev_id conversion is not done in WMI.
  2461. * This API can be used enable conversion in WMI.
  2462. * @param wmi_handle : handle to WMI
  2463. * Return none
  2464. */
  2465. void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle)
  2466. {
  2467. if (wmi_handle->target_type == WMI_TLV_TARGET)
  2468. wmi_handle->ops->wmi_pdev_id_conversion_enable(wmi_handle);
  2469. }
  2470. #endif