wmi_unified.c 85 KB

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