wmi_unified.c 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975
  1. /*
  2. * Copyright (c) 2015-2019 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,
  1346. const char *func_name,
  1347. uint32_t line_num)
  1348. {
  1349. wmi_buf_t wmi_buf;
  1350. if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
  1351. QDF_ASSERT(0);
  1352. return NULL;
  1353. }
  1354. wmi_buf = wbuff_buff_get(wmi_handle->wbuff_handle, len, func_name,
  1355. line_num);
  1356. if (!wmi_buf)
  1357. wmi_buf = qdf_nbuf_alloc_debug(NULL,
  1358. roundup(len + WMI_MIN_HEAD_ROOM,
  1359. 4),
  1360. WMI_MIN_HEAD_ROOM, 4, false,
  1361. func_name, line_num);
  1362. if (!wmi_buf)
  1363. return NULL;
  1364. /* Clear the wmi buffer */
  1365. OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
  1366. /*
  1367. * Set the length of the buffer to match the allocation size.
  1368. */
  1369. qdf_nbuf_set_pktlen(wmi_buf, len);
  1370. return wmi_buf;
  1371. }
  1372. qdf_export_symbol(wmi_buf_alloc_debug);
  1373. void wmi_buf_free(wmi_buf_t net_buf)
  1374. {
  1375. net_buf = wbuff_buff_put(net_buf);
  1376. if (net_buf)
  1377. qdf_nbuf_free(net_buf);
  1378. }
  1379. qdf_export_symbol(wmi_buf_free);
  1380. #else
  1381. wmi_buf_t wmi_buf_alloc_fl(wmi_unified_t wmi_handle, uint32_t len,
  1382. const char *func, uint32_t line)
  1383. {
  1384. wmi_buf_t wmi_buf;
  1385. if (roundup(len + WMI_MIN_HEAD_ROOM, 4) > wmi_handle->max_msg_len) {
  1386. wmi_nofl_err("%s:%d, Invalid len:%d", func, line, len);
  1387. QDF_DEBUG_PANIC();
  1388. return NULL;
  1389. }
  1390. wmi_buf = wbuff_buff_get(wmi_handle->wbuff_handle, len, __func__,
  1391. __LINE__);
  1392. if (!wmi_buf)
  1393. wmi_buf = qdf_nbuf_alloc_fl(NULL, roundup(len +
  1394. WMI_MIN_HEAD_ROOM, 4), WMI_MIN_HEAD_ROOM, 4,
  1395. false, func, line);
  1396. if (!wmi_buf)
  1397. return NULL;
  1398. /* Clear the wmi buffer */
  1399. OS_MEMZERO(qdf_nbuf_data(wmi_buf), len);
  1400. /*
  1401. * Set the length of the buffer to match the allocation size.
  1402. */
  1403. qdf_nbuf_set_pktlen(wmi_buf, len);
  1404. return wmi_buf;
  1405. }
  1406. qdf_export_symbol(wmi_buf_alloc_fl);
  1407. void wmi_buf_free(wmi_buf_t net_buf)
  1408. {
  1409. net_buf = wbuff_buff_put(net_buf);
  1410. if (net_buf)
  1411. qdf_nbuf_free(net_buf);
  1412. }
  1413. qdf_export_symbol(wmi_buf_free);
  1414. #endif
  1415. /**
  1416. * wmi_get_max_msg_len() - get maximum WMI message length
  1417. * @wmi_handle: WMI handle.
  1418. *
  1419. * This function returns the maximum WMI message length
  1420. *
  1421. * Return: maximum WMI message length
  1422. */
  1423. uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle)
  1424. {
  1425. return wmi_handle->max_msg_len - WMI_MIN_HEAD_ROOM;
  1426. }
  1427. qdf_export_symbol(wmi_get_max_msg_len);
  1428. #ifndef WMI_CMD_STRINGS
  1429. static uint8_t *wmi_id_to_name(uint32_t wmi_command)
  1430. {
  1431. return "Invalid WMI cmd";
  1432. }
  1433. #endif
  1434. #ifdef CONFIG_MCL
  1435. static inline void wmi_log_cmd_id(uint32_t cmd_id, uint32_t tag)
  1436. {
  1437. WMI_LOGD("Send WMI command:%s command_id:%d htc_tag:%d\n",
  1438. wmi_id_to_name(cmd_id), cmd_id, tag);
  1439. }
  1440. /**
  1441. * wmi_is_pm_resume_cmd() - check if a cmd is part of the resume sequence
  1442. * @cmd_id: command to check
  1443. *
  1444. * Return: true if the command is part of the resume sequence.
  1445. */
  1446. static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
  1447. {
  1448. switch (cmd_id) {
  1449. case WMI_WOW_HOSTWAKEUP_FROM_SLEEP_CMDID:
  1450. case WMI_PDEV_RESUME_CMDID:
  1451. return true;
  1452. default:
  1453. return false;
  1454. }
  1455. }
  1456. #else
  1457. static bool wmi_is_pm_resume_cmd(uint32_t cmd_id)
  1458. {
  1459. return false;
  1460. }
  1461. #endif
  1462. QDF_STATUS wmi_unified_cmd_send_fl(wmi_unified_t wmi_handle, wmi_buf_t buf,
  1463. uint32_t len, uint32_t cmd_id,
  1464. const char *func, uint32_t line)
  1465. {
  1466. HTC_PACKET *pkt;
  1467. QDF_STATUS status;
  1468. uint16_t htc_tag = 0;
  1469. if (wmi_get_runtime_pm_inprogress(wmi_handle)) {
  1470. htc_tag =
  1471. (uint16_t)wmi_handle->ops->wmi_set_htc_tx_tag(
  1472. wmi_handle, buf, cmd_id);
  1473. } else if (qdf_atomic_read(&wmi_handle->is_target_suspended) &&
  1474. (!wmi_is_pm_resume_cmd(cmd_id))) {
  1475. wmi_nofl_err("%s:%d, Target is suspended", func, line);
  1476. QDF_DEBUG_PANIC();
  1477. return QDF_STATUS_E_BUSY;
  1478. }
  1479. if (wmi_handle->wmi_stopinprogress) {
  1480. wmi_nofl_err("%s:%d, WMI stop in progress", func, line);
  1481. return QDF_STATUS_E_INVAL;
  1482. }
  1483. #ifndef WMI_NON_TLV_SUPPORT
  1484. /* Do sanity check on the TLV parameter structure */
  1485. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  1486. void *buf_ptr = (void *)qdf_nbuf_data(buf);
  1487. if (wmi_handle->ops->wmi_check_command_params(NULL, buf_ptr, len, cmd_id)
  1488. != 0) {
  1489. wmi_nofl_err("%s:%d, Invalid WMI Param Buffer for Cmd:%d",
  1490. func, line, cmd_id);
  1491. return QDF_STATUS_E_INVAL;
  1492. }
  1493. }
  1494. #endif
  1495. if (qdf_nbuf_push_head(buf, sizeof(WMI_CMD_HDR)) == NULL) {
  1496. wmi_nofl_err("%s:%d, Failed to send cmd %x, no memory",
  1497. func, line, cmd_id);
  1498. return QDF_STATUS_E_NOMEM;
  1499. }
  1500. qdf_mem_zero(qdf_nbuf_data(buf), sizeof(WMI_CMD_HDR));
  1501. WMI_SET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID, cmd_id);
  1502. qdf_atomic_inc(&wmi_handle->pending_cmds);
  1503. if (qdf_atomic_read(&wmi_handle->pending_cmds) >=
  1504. wmi_handle->wmi_max_cmds) {
  1505. wmi_nofl_err("hostcredits = %d",
  1506. wmi_get_host_credits(wmi_handle));
  1507. htc_dump_counter_info(wmi_handle->htc_handle);
  1508. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1509. wmi_nofl_err("%s:%d, MAX %d WMI Pending cmds reached",
  1510. func, line, wmi_handle->wmi_max_cmds);
  1511. QDF_BUG(0);
  1512. return QDF_STATUS_E_BUSY;
  1513. }
  1514. pkt = qdf_mem_malloc_fl(sizeof(*pkt), func, line);
  1515. if (!pkt) {
  1516. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1517. return QDF_STATUS_E_NOMEM;
  1518. }
  1519. SET_HTC_PACKET_INFO_TX(pkt,
  1520. NULL,
  1521. qdf_nbuf_data(buf), len + sizeof(WMI_CMD_HDR),
  1522. wmi_handle->wmi_endpoint_id, htc_tag);
  1523. SET_HTC_PACKET_NET_BUF_CONTEXT(pkt, buf);
  1524. #ifdef CONFIG_MCL
  1525. wmi_log_cmd_id(cmd_id, htc_tag);
  1526. #endif
  1527. wmi_ext_dbg_msg_cmd_record(wmi_handle,
  1528. qdf_nbuf_data(buf), qdf_nbuf_len(buf));
  1529. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1530. if (wmi_handle->log_info.wmi_logging_enable) {
  1531. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1532. /*
  1533. * Record 16 bytes of WMI cmd data -
  1534. * exclude TLV and WMI headers
  1535. *
  1536. * WMI mgmt command already recorded in wmi_mgmt_cmd_record
  1537. */
  1538. if (wmi_handle->ops->is_management_record(cmd_id) == false) {
  1539. WMI_COMMAND_RECORD(wmi_handle, cmd_id,
  1540. qdf_nbuf_data(buf) +
  1541. wmi_handle->soc->buf_offset_command);
  1542. }
  1543. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1544. }
  1545. #endif
  1546. status = htc_send_pkt(wmi_handle->htc_handle, pkt);
  1547. if (QDF_STATUS_SUCCESS != status) {
  1548. qdf_atomic_dec(&wmi_handle->pending_cmds);
  1549. wmi_nofl_err("%s:%d, htc_send_pkt failed, status:%d",
  1550. func, line, status);
  1551. qdf_mem_free(pkt);
  1552. return status;
  1553. }
  1554. return QDF_STATUS_SUCCESS;
  1555. }
  1556. qdf_export_symbol(wmi_unified_cmd_send_fl);
  1557. /**
  1558. * wmi_unified_get_event_handler_ix() - gives event handler's index
  1559. * @wmi_handle: handle to wmi
  1560. * @event_id: wmi event id
  1561. *
  1562. * Return: event handler's index
  1563. */
  1564. static int wmi_unified_get_event_handler_ix(wmi_unified_t wmi_handle,
  1565. uint32_t event_id)
  1566. {
  1567. uint32_t idx = 0;
  1568. int32_t invalid_idx = -1;
  1569. struct wmi_soc *soc = wmi_handle->soc;
  1570. for (idx = 0; (idx < soc->max_event_idx &&
  1571. idx < WMI_UNIFIED_MAX_EVENT); ++idx) {
  1572. if (wmi_handle->event_id[idx] == event_id &&
  1573. wmi_handle->event_handler[idx] != NULL) {
  1574. return idx;
  1575. }
  1576. }
  1577. return invalid_idx;
  1578. }
  1579. /**
  1580. * wmi_unified_register_event() - register wmi event handler
  1581. * @wmi_handle: handle to wmi
  1582. * @event_id: wmi event id
  1583. * @handler_func: wmi event handler function
  1584. *
  1585. * Return: 0 on success
  1586. */
  1587. int wmi_unified_register_event(wmi_unified_t wmi_handle,
  1588. uint32_t event_id,
  1589. wmi_unified_event_handler handler_func)
  1590. {
  1591. uint32_t idx = 0;
  1592. uint32_t evt_id;
  1593. struct wmi_soc *soc;
  1594. if (!wmi_handle) {
  1595. WMI_LOGE("WMI handle is NULL");
  1596. return QDF_STATUS_E_FAILURE;
  1597. }
  1598. soc = wmi_handle->soc;
  1599. if (event_id >= wmi_events_max ||
  1600. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1601. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1602. "%s: Event id %d is unavailable",
  1603. __func__, event_id);
  1604. return QDF_STATUS_E_FAILURE;
  1605. }
  1606. evt_id = wmi_handle->wmi_events[event_id];
  1607. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1608. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1609. "%s : event handler already registered 0x%x",
  1610. __func__, evt_id);
  1611. return QDF_STATUS_E_FAILURE;
  1612. }
  1613. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1614. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1615. "%s : no more event handlers 0x%x",
  1616. __func__, evt_id);
  1617. return QDF_STATUS_E_FAILURE;
  1618. }
  1619. idx = soc->max_event_idx;
  1620. wmi_handle->event_handler[idx] = handler_func;
  1621. wmi_handle->event_id[idx] = evt_id;
  1622. qdf_spin_lock_bh(&soc->ctx_lock);
  1623. wmi_handle->ctx[idx] = WMI_RX_UMAC_CTX;
  1624. qdf_spin_unlock_bh(&soc->ctx_lock);
  1625. soc->max_event_idx++;
  1626. return 0;
  1627. }
  1628. /**
  1629. * wmi_unified_register_event_handler() - register wmi event handler
  1630. * @wmi_handle: handle to wmi
  1631. * @event_id: wmi event id
  1632. * @handler_func: wmi event handler function
  1633. * @rx_ctx: rx execution context for wmi rx events
  1634. *
  1635. * This API is to support legacy requirements. Will be deprecated in future.
  1636. * Return: 0 on success
  1637. */
  1638. int wmi_unified_register_event_handler(wmi_unified_t wmi_handle,
  1639. wmi_conv_event_id event_id,
  1640. wmi_unified_event_handler handler_func,
  1641. uint8_t rx_ctx)
  1642. {
  1643. uint32_t idx = 0;
  1644. uint32_t evt_id;
  1645. struct wmi_soc *soc;
  1646. if (!wmi_handle) {
  1647. WMI_LOGE("WMI handle is NULL");
  1648. return QDF_STATUS_E_FAILURE;
  1649. }
  1650. soc = wmi_handle->soc;
  1651. if (event_id >= wmi_events_max ||
  1652. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1653. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1654. "%s: Event id %d is unavailable",
  1655. __func__, event_id);
  1656. return QDF_STATUS_E_FAILURE;
  1657. }
  1658. evt_id = wmi_handle->wmi_events[event_id];
  1659. if (wmi_unified_get_event_handler_ix(wmi_handle, evt_id) != -1) {
  1660. WMI_LOGE("event handler already registered 0x%x",
  1661. evt_id);
  1662. return QDF_STATUS_E_FAILURE;
  1663. }
  1664. if (soc->max_event_idx == WMI_UNIFIED_MAX_EVENT) {
  1665. WMI_LOGE("no more event handlers 0x%x",
  1666. evt_id);
  1667. return QDF_STATUS_E_FAILURE;
  1668. }
  1669. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_DEBUG,
  1670. "Registered event handler for event 0x%8x", evt_id);
  1671. idx = soc->max_event_idx;
  1672. wmi_handle->event_handler[idx] = handler_func;
  1673. wmi_handle->event_id[idx] = evt_id;
  1674. qdf_spin_lock_bh(&soc->ctx_lock);
  1675. wmi_handle->ctx[idx] = rx_ctx;
  1676. qdf_spin_unlock_bh(&soc->ctx_lock);
  1677. soc->max_event_idx++;
  1678. return 0;
  1679. }
  1680. qdf_export_symbol(wmi_unified_register_event_handler);
  1681. /**
  1682. * wmi_unified_unregister_event() - unregister wmi event handler
  1683. * @wmi_handle: handle to wmi
  1684. * @event_id: wmi event id
  1685. *
  1686. * Return: 0 on success
  1687. */
  1688. int wmi_unified_unregister_event(wmi_unified_t wmi_handle,
  1689. uint32_t event_id)
  1690. {
  1691. uint32_t idx = 0;
  1692. uint32_t evt_id;
  1693. struct wmi_soc *soc = wmi_handle->soc;
  1694. if (event_id >= wmi_events_max ||
  1695. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1696. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1697. "%s: Event id %d is unavailable",
  1698. __func__, event_id);
  1699. return QDF_STATUS_E_FAILURE;
  1700. }
  1701. evt_id = wmi_handle->wmi_events[event_id];
  1702. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1703. if (idx == -1) {
  1704. WMI_LOGE("event handler is not registered: evt id 0x%x",
  1705. evt_id);
  1706. return QDF_STATUS_E_FAILURE;
  1707. }
  1708. wmi_handle->event_handler[idx] = NULL;
  1709. wmi_handle->event_id[idx] = 0;
  1710. --soc->max_event_idx;
  1711. wmi_handle->event_handler[idx] =
  1712. wmi_handle->event_handler[soc->max_event_idx];
  1713. wmi_handle->event_id[idx] =
  1714. wmi_handle->event_id[soc->max_event_idx];
  1715. return 0;
  1716. }
  1717. /**
  1718. * wmi_unified_unregister_event_handler() - unregister wmi event handler
  1719. * @wmi_handle: handle to wmi
  1720. * @event_id: wmi event id
  1721. *
  1722. * Return: 0 on success
  1723. */
  1724. int wmi_unified_unregister_event_handler(wmi_unified_t wmi_handle,
  1725. wmi_conv_event_id event_id)
  1726. {
  1727. uint32_t idx = 0;
  1728. uint32_t evt_id;
  1729. struct wmi_soc *soc;
  1730. if (!wmi_handle) {
  1731. WMI_LOGE("WMI handle is NULL");
  1732. return QDF_STATUS_E_FAILURE;
  1733. }
  1734. soc = wmi_handle->soc;
  1735. if (event_id >= wmi_events_max ||
  1736. wmi_handle->wmi_events[event_id] == WMI_EVENT_ID_INVALID) {
  1737. WMI_LOGE("Event id %d is unavailable",
  1738. event_id);
  1739. return QDF_STATUS_E_FAILURE;
  1740. }
  1741. evt_id = wmi_handle->wmi_events[event_id];
  1742. idx = wmi_unified_get_event_handler_ix(wmi_handle, evt_id);
  1743. if (idx == -1) {
  1744. WMI_LOGE("event handler is not registered: evt id 0x%x",
  1745. evt_id);
  1746. return QDF_STATUS_E_FAILURE;
  1747. }
  1748. wmi_handle->event_handler[idx] = NULL;
  1749. wmi_handle->event_id[idx] = 0;
  1750. --soc->max_event_idx;
  1751. wmi_handle->event_handler[idx] =
  1752. wmi_handle->event_handler[soc->max_event_idx];
  1753. wmi_handle->event_id[idx] =
  1754. wmi_handle->event_id[soc->max_event_idx];
  1755. return 0;
  1756. }
  1757. qdf_export_symbol(wmi_unified_unregister_event_handler);
  1758. /**
  1759. * wmi_process_fw_event_default_ctx() - process in default caller context
  1760. * @wmi_handle: handle to wmi
  1761. * @htc_packet: pointer to htc packet
  1762. * @exec_ctx: execution context for wmi fw event
  1763. *
  1764. * Event process by below function will be in default caller context.
  1765. * wmi internally provides rx work thread processing context.
  1766. *
  1767. * Return: none
  1768. */
  1769. static void wmi_process_fw_event_default_ctx(struct wmi_unified *wmi_handle,
  1770. HTC_PACKET *htc_packet, uint8_t exec_ctx)
  1771. {
  1772. wmi_buf_t evt_buf;
  1773. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1774. #ifndef CONFIG_MCL
  1775. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk
  1776. (wmi_handle->scn_handle, evt_buf, exec_ctx);
  1777. #else
  1778. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk(wmi_handle,
  1779. htc_packet, exec_ctx);
  1780. #endif
  1781. return;
  1782. }
  1783. /**
  1784. * wmi_process_fw_event_worker_thread_ctx() - process in worker thread context
  1785. * @wmi_handle: handle to wmi
  1786. * @htc_packet: pointer to htc packet
  1787. *
  1788. * Event process by below function will be in worker thread context.
  1789. * Use this method for events which are not critical and not
  1790. * handled in protocol stack.
  1791. *
  1792. * Return: none
  1793. */
  1794. void wmi_process_fw_event_worker_thread_ctx(struct wmi_unified *wmi_handle,
  1795. HTC_PACKET *htc_packet)
  1796. {
  1797. wmi_buf_t evt_buf;
  1798. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1799. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  1800. qdf_nbuf_queue_add(&wmi_handle->event_queue, evt_buf);
  1801. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  1802. qdf_queue_work(0, wmi_handle->wmi_rx_work_queue,
  1803. &wmi_handle->rx_event_work);
  1804. return;
  1805. }
  1806. qdf_export_symbol(wmi_process_fw_event_worker_thread_ctx);
  1807. /**
  1808. * wmi_get_pdev_ep: Get wmi handle based on endpoint
  1809. * @soc: handle to wmi soc
  1810. * @ep: endpoint id
  1811. *
  1812. * Return: none
  1813. */
  1814. static struct wmi_unified *wmi_get_pdev_ep(struct wmi_soc *soc,
  1815. HTC_ENDPOINT_ID ep)
  1816. {
  1817. uint32_t i;
  1818. for (i = 0; i < WMI_MAX_RADIOS; i++)
  1819. if (soc->wmi_endpoint_id[i] == ep)
  1820. break;
  1821. if (i == WMI_MAX_RADIOS)
  1822. return NULL;
  1823. return soc->wmi_pdev[i];
  1824. }
  1825. /**
  1826. * wmi_mtrace_rx() - Wrappper function for qdf_mtrace api
  1827. * @message_id: 32-Bit Wmi message ID
  1828. * @vdev_id: Vdev ID
  1829. * @data: Actual message contents
  1830. *
  1831. * This function converts the 32-bit WMI message ID in 15-bit message ID
  1832. * format for qdf_mtrace as in qdf_mtrace message there are only 15
  1833. * bits reserved for message ID.
  1834. * out of these 15-bits, 8-bits (From LSB) specifies the WMI_GRP_ID
  1835. * and remaining 7-bits specifies the actual WMI command. With this
  1836. * notation there can be maximum 256 groups and each group can have
  1837. * max 128 commands can be supported.
  1838. *
  1839. * Return: None
  1840. */
  1841. static void wmi_mtrace_rx(uint32_t message_id, uint16_t vdev_id, uint32_t data)
  1842. {
  1843. uint16_t mtrace_message_id;
  1844. mtrace_message_id = QDF_WMI_MTRACE_CMD_ID(message_id) |
  1845. (QDF_WMI_MTRACE_GRP_ID(message_id) <<
  1846. QDF_WMI_MTRACE_CMD_NUM_BITS);
  1847. qdf_mtrace(QDF_MODULE_ID_WMI, QDF_MODULE_ID_WMA,
  1848. mtrace_message_id, vdev_id, data);
  1849. }
  1850. /**
  1851. * wmi_control_rx() - process fw events callbacks
  1852. * @ctx: handle to wmi
  1853. * @htc_packet: pointer to htc packet
  1854. *
  1855. * Return: none
  1856. */
  1857. static void wmi_control_rx(void *ctx, HTC_PACKET *htc_packet)
  1858. {
  1859. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  1860. struct wmi_unified *wmi_handle;
  1861. wmi_buf_t evt_buf;
  1862. uint32_t id;
  1863. uint32_t idx = 0;
  1864. enum wmi_rx_exec_ctx exec_ctx;
  1865. evt_buf = (wmi_buf_t) htc_packet->pPktContext;
  1866. wmi_handle = wmi_get_pdev_ep(soc, htc_packet->Endpoint);
  1867. if (wmi_handle == NULL) {
  1868. WMI_LOGE
  1869. ("unable to get wmi_handle to Endpoint %d\n",
  1870. htc_packet->Endpoint);
  1871. qdf_nbuf_free(evt_buf);
  1872. return;
  1873. }
  1874. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  1875. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  1876. if (qdf_unlikely(idx == A_ERROR)) {
  1877. wmi_debug("no handler registered for event id 0x%x", id);
  1878. qdf_nbuf_free(evt_buf);
  1879. return;
  1880. }
  1881. wmi_mtrace_rx(id, 0xFF, idx);
  1882. qdf_spin_lock_bh(&soc->ctx_lock);
  1883. exec_ctx = wmi_handle->ctx[idx];
  1884. qdf_spin_unlock_bh(&soc->ctx_lock);
  1885. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1886. if (wmi_handle->log_info.wmi_logging_enable) {
  1887. uint8_t *data;
  1888. data = qdf_nbuf_data(evt_buf);
  1889. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1890. /* Exclude 4 bytes of TLV header */
  1891. if (wmi_handle->ops->is_diag_event(id)) {
  1892. WMI_DIAG_RX_EVENT_RECORD(wmi_handle, id,
  1893. ((uint8_t *) data +
  1894. wmi_handle->soc->buf_offset_event));
  1895. } else if (wmi_handle->ops->is_management_record(id)) {
  1896. WMI_MGMT_RX_EVENT_RECORD(wmi_handle, id,
  1897. ((uint8_t *) data +
  1898. wmi_handle->soc->buf_offset_event));
  1899. } else {
  1900. WMI_RX_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
  1901. wmi_handle->soc->buf_offset_event));
  1902. }
  1903. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1904. }
  1905. #endif
  1906. if (exec_ctx == WMI_RX_WORK_CTX) {
  1907. wmi_process_fw_event_worker_thread_ctx
  1908. (wmi_handle, htc_packet);
  1909. } else if (exec_ctx > WMI_RX_WORK_CTX) {
  1910. wmi_process_fw_event_default_ctx
  1911. (wmi_handle, htc_packet, exec_ctx);
  1912. } else {
  1913. WMI_LOGE("Invalid event context %d", exec_ctx);
  1914. qdf_nbuf_free(evt_buf);
  1915. }
  1916. }
  1917. /**
  1918. * wmi_process_fw_event() - process any fw event
  1919. * @wmi_handle: wmi handle
  1920. * @evt_buf: fw event buffer
  1921. *
  1922. * This function process fw event in caller context
  1923. *
  1924. * Return: none
  1925. */
  1926. void wmi_process_fw_event(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  1927. {
  1928. __wmi_control_rx(wmi_handle, evt_buf);
  1929. }
  1930. /**
  1931. * __wmi_control_rx() - process serialize wmi event callback
  1932. * @wmi_handle: wmi handle
  1933. * @evt_buf: fw event buffer
  1934. *
  1935. * Return: none
  1936. */
  1937. void __wmi_control_rx(struct wmi_unified *wmi_handle, wmi_buf_t evt_buf)
  1938. {
  1939. uint32_t id;
  1940. uint8_t *data;
  1941. uint32_t len;
  1942. void *wmi_cmd_struct_ptr = NULL;
  1943. #ifndef WMI_NON_TLV_SUPPORT
  1944. int tlv_ok_status = 0;
  1945. #endif
  1946. uint32_t idx = 0;
  1947. id = WMI_GET_FIELD(qdf_nbuf_data(evt_buf), WMI_CMD_HDR, COMMANDID);
  1948. wmi_ext_dbg_msg_event_record(wmi_handle, qdf_nbuf_data(evt_buf),
  1949. qdf_nbuf_len(evt_buf));
  1950. if (qdf_nbuf_pull_head(evt_buf, sizeof(WMI_CMD_HDR)) == NULL)
  1951. goto end;
  1952. data = qdf_nbuf_data(evt_buf);
  1953. len = qdf_nbuf_len(evt_buf);
  1954. #ifndef WMI_NON_TLV_SUPPORT
  1955. if (wmi_handle->target_type == WMI_TLV_TARGET) {
  1956. /* Validate and pad(if necessary) the TLVs */
  1957. tlv_ok_status =
  1958. wmi_handle->ops->wmi_check_and_pad_event(wmi_handle->scn_handle,
  1959. data, len, id,
  1960. &wmi_cmd_struct_ptr);
  1961. if (tlv_ok_status != 0) {
  1962. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1963. "%s: Error: id=0x%x, wmitlv check status=%d",
  1964. __func__, id, tlv_ok_status);
  1965. goto end;
  1966. }
  1967. }
  1968. #endif
  1969. idx = wmi_unified_get_event_handler_ix(wmi_handle, id);
  1970. if (idx == A_ERROR) {
  1971. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_ERROR,
  1972. "%s : event handler is not registered: event id 0x%x",
  1973. __func__, id);
  1974. goto end;
  1975. }
  1976. #ifdef WMI_INTERFACE_EVENT_LOGGING
  1977. if (wmi_handle->log_info.wmi_logging_enable) {
  1978. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  1979. /* Exclude 4 bytes of TLV header */
  1980. if (wmi_handle->ops->is_diag_event(id)) {
  1981. /*
  1982. * skip diag event logging in WMI event buffer
  1983. * as its already logged in WMI RX event buffer
  1984. */
  1985. } else if (wmi_handle->ops->is_management_record(id)) {
  1986. /*
  1987. * skip wmi mgmt event logging in WMI event buffer
  1988. * as its already logged in WMI RX event buffer
  1989. */
  1990. } else {
  1991. WMI_EVENT_RECORD(wmi_handle, id, ((uint8_t *) data +
  1992. wmi_handle->soc->buf_offset_event));
  1993. }
  1994. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  1995. }
  1996. #endif
  1997. /* Call the WMI registered event handler */
  1998. if (wmi_handle->target_type == WMI_TLV_TARGET)
  1999. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  2000. wmi_cmd_struct_ptr, len);
  2001. else
  2002. wmi_handle->event_handler[idx] (wmi_handle->scn_handle,
  2003. data, len);
  2004. end:
  2005. /* Free event buffer and allocated event tlv */
  2006. #ifndef WMI_NON_TLV_SUPPORT
  2007. if (wmi_handle->target_type == WMI_TLV_TARGET)
  2008. wmi_handle->ops->wmi_free_allocated_event(id, &wmi_cmd_struct_ptr);
  2009. #endif
  2010. qdf_nbuf_free(evt_buf);
  2011. }
  2012. #define WMI_WQ_WD_TIMEOUT (30 * 1000) /* 30s */
  2013. static inline void wmi_workqueue_watchdog_warn(uint32_t msg_type_id)
  2014. {
  2015. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  2016. "%s: WLAN_BUG_RCA: Message type %x has exceeded its alloted time of %ds",
  2017. __func__, msg_type_id, WMI_WQ_WD_TIMEOUT / 1000);
  2018. }
  2019. #ifdef CONFIG_SLUB_DEBUG_ON
  2020. static void wmi_workqueue_watchdog_bite(void *arg)
  2021. {
  2022. struct wmi_wq_dbg_info *info = arg;
  2023. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  2024. qdf_print_thread_trace(info->task);
  2025. QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
  2026. "%s: Going down for WMI WQ Watchdog Bite!", __func__);
  2027. QDF_BUG(0);
  2028. }
  2029. #else
  2030. static inline void wmi_workqueue_watchdog_bite(void *arg)
  2031. {
  2032. struct wmi_wq_dbg_info *info = arg;
  2033. wmi_workqueue_watchdog_warn(info->wd_msg_type_id);
  2034. }
  2035. #endif
  2036. /**
  2037. * wmi_rx_event_work() - process rx event in rx work queue context
  2038. * @arg: opaque pointer to wmi handle
  2039. *
  2040. * This function process any fw event to serialize it through rx worker thread.
  2041. *
  2042. * Return: none
  2043. */
  2044. static void wmi_rx_event_work(void *arg)
  2045. {
  2046. wmi_buf_t buf;
  2047. struct wmi_unified *wmi = arg;
  2048. qdf_timer_t wd_timer;
  2049. struct wmi_wq_dbg_info info;
  2050. /* initialize WMI workqueue watchdog timer */
  2051. qdf_timer_init(NULL, &wd_timer, &wmi_workqueue_watchdog_bite,
  2052. &info, QDF_TIMER_TYPE_SW);
  2053. qdf_spin_lock_bh(&wmi->eventq_lock);
  2054. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  2055. qdf_spin_unlock_bh(&wmi->eventq_lock);
  2056. while (buf) {
  2057. qdf_timer_start(&wd_timer, WMI_WQ_WD_TIMEOUT);
  2058. info.wd_msg_type_id =
  2059. WMI_GET_FIELD(qdf_nbuf_data(buf), WMI_CMD_HDR, COMMANDID);
  2060. info.wmi_wq = wmi->wmi_rx_work_queue;
  2061. info.task = qdf_get_current_task();
  2062. __wmi_control_rx(wmi, buf);
  2063. qdf_timer_stop(&wd_timer);
  2064. qdf_spin_lock_bh(&wmi->eventq_lock);
  2065. buf = qdf_nbuf_queue_remove(&wmi->event_queue);
  2066. qdf_spin_unlock_bh(&wmi->eventq_lock);
  2067. }
  2068. qdf_timer_free(&wd_timer);
  2069. }
  2070. #ifdef FEATURE_RUNTIME_PM
  2071. /**
  2072. * wmi_runtime_pm_init() - initialize runtime pm wmi variables
  2073. * @wmi_handle: wmi context
  2074. */
  2075. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  2076. {
  2077. qdf_atomic_init(&wmi_handle->runtime_pm_inprogress);
  2078. }
  2079. /**
  2080. * wmi_set_runtime_pm_inprogress() - set runtime pm progress flag
  2081. * @wmi_handle: wmi context
  2082. * @val: runtime pm progress flag
  2083. */
  2084. void wmi_set_runtime_pm_inprogress(wmi_unified_t wmi_handle, A_BOOL val)
  2085. {
  2086. qdf_atomic_set(&wmi_handle->runtime_pm_inprogress, val);
  2087. }
  2088. /**
  2089. * wmi_get_runtime_pm_inprogress() - get runtime pm progress flag
  2090. * @wmi_handle: wmi context
  2091. */
  2092. inline bool wmi_get_runtime_pm_inprogress(wmi_unified_t wmi_handle)
  2093. {
  2094. return qdf_atomic_read(&wmi_handle->runtime_pm_inprogress);
  2095. }
  2096. #else
  2097. static void wmi_runtime_pm_init(struct wmi_unified *wmi_handle)
  2098. {
  2099. }
  2100. #endif
  2101. /**
  2102. * wmi_unified_get_soc_handle: Get WMI SoC handle
  2103. * @param wmi_handle: WMI context got from wmi_attach
  2104. *
  2105. * return: Pointer to Soc handle
  2106. */
  2107. void *wmi_unified_get_soc_handle(struct wmi_unified *wmi_handle)
  2108. {
  2109. return wmi_handle->soc;
  2110. }
  2111. /**
  2112. * wmi_interface_logging_init: Interface looging init
  2113. * @param wmi_handle: Pointer to wmi handle object
  2114. *
  2115. * return: None
  2116. */
  2117. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2118. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
  2119. uint32_t pdev_idx)
  2120. {
  2121. if (QDF_STATUS_SUCCESS == wmi_log_init(wmi_handle)) {
  2122. qdf_spinlock_create(&wmi_handle->log_info.wmi_record_lock);
  2123. wmi_debugfs_init(wmi_handle, pdev_idx);
  2124. }
  2125. }
  2126. #else
  2127. static inline void wmi_interface_logging_init(struct wmi_unified *wmi_handle,
  2128. uint32_t pdev_idx)
  2129. {
  2130. }
  2131. #endif
  2132. /**
  2133. * wmi_target_params_init: Target specific params init
  2134. * @param wmi_soc: Pointer to wmi soc object
  2135. * @param wmi_handle: Pointer to wmi handle object
  2136. *
  2137. * return: None
  2138. */
  2139. #ifndef CONFIG_MCL
  2140. static inline void wmi_target_params_init(struct wmi_soc *soc,
  2141. struct wmi_unified *wmi_handle)
  2142. {
  2143. wmi_handle->pdev_param = soc->pdev_param;
  2144. wmi_handle->vdev_param = soc->vdev_param;
  2145. wmi_handle->services = soc->services;
  2146. }
  2147. #else
  2148. static inline void wmi_target_params_init(struct wmi_soc *soc,
  2149. struct wmi_unified *wmi_handle)
  2150. {
  2151. wmi_handle->services = soc->services;
  2152. }
  2153. #endif
  2154. /**
  2155. * wmi_unified_get_pdev_handle: Get WMI SoC handle
  2156. * @param wmi_soc: Pointer to wmi soc object
  2157. * @param pdev_idx: pdev index
  2158. *
  2159. * return: Pointer to wmi handle or NULL on failure
  2160. */
  2161. void *wmi_unified_get_pdev_handle(struct wmi_soc *soc, uint32_t pdev_idx)
  2162. {
  2163. struct wmi_unified *wmi_handle;
  2164. if (pdev_idx >= WMI_MAX_RADIOS)
  2165. return NULL;
  2166. if (soc->wmi_pdev[pdev_idx] == NULL) {
  2167. wmi_handle =
  2168. (struct wmi_unified *) qdf_mem_malloc(
  2169. sizeof(struct wmi_unified));
  2170. if (wmi_handle == NULL) {
  2171. WMI_LOGE("allocation of wmi handle failed %zu",
  2172. sizeof(struct wmi_unified));
  2173. return NULL;
  2174. }
  2175. wmi_handle->scn_handle = soc->scn_handle;
  2176. wmi_handle->event_id = soc->event_id;
  2177. wmi_handle->event_handler = soc->event_handler;
  2178. wmi_handle->ctx = soc->ctx;
  2179. wmi_handle->ops = soc->ops;
  2180. qdf_spinlock_create(&wmi_handle->eventq_lock);
  2181. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  2182. qdf_create_work(0, &wmi_handle->rx_event_work,
  2183. wmi_rx_event_work, wmi_handle);
  2184. wmi_handle->wmi_rx_work_queue =
  2185. qdf_alloc_unbound_workqueue("wmi_rx_event_work_queue");
  2186. if (NULL == wmi_handle->wmi_rx_work_queue) {
  2187. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  2188. goto error;
  2189. }
  2190. wmi_handle->wmi_events = soc->wmi_events;
  2191. wmi_target_params_init(soc, wmi_handle);
  2192. wmi_handle->soc = soc;
  2193. wmi_interface_logging_init(wmi_handle, pdev_idx);
  2194. qdf_atomic_init(&wmi_handle->pending_cmds);
  2195. qdf_atomic_init(&wmi_handle->is_target_suspended);
  2196. wmi_handle->target_type = soc->target_type;
  2197. wmi_handle->wmi_max_cmds = soc->wmi_max_cmds;
  2198. soc->wmi_pdev[pdev_idx] = wmi_handle;
  2199. } else
  2200. wmi_handle = soc->wmi_pdev[pdev_idx];
  2201. wmi_handle->wmi_stopinprogress = 0;
  2202. wmi_handle->wmi_endpoint_id = soc->wmi_endpoint_id[pdev_idx];
  2203. wmi_handle->htc_handle = soc->htc_handle;
  2204. wmi_handle->max_msg_len = soc->max_msg_len[pdev_idx];
  2205. return wmi_handle;
  2206. error:
  2207. qdf_mem_free(wmi_handle);
  2208. return NULL;
  2209. }
  2210. qdf_export_symbol(wmi_unified_get_pdev_handle);
  2211. static void (*wmi_attach_register[WMI_MAX_TARGET_TYPE])(wmi_unified_t);
  2212. void wmi_unified_register_module(enum wmi_target_type target_type,
  2213. void (*wmi_attach)(wmi_unified_t wmi_handle))
  2214. {
  2215. if (target_type < WMI_MAX_TARGET_TYPE)
  2216. wmi_attach_register[target_type] = wmi_attach;
  2217. return;
  2218. }
  2219. qdf_export_symbol(wmi_unified_register_module);
  2220. /**
  2221. * wmi_wbuff_register() - register wmi with wbuff
  2222. * @wmi_handle: handle to wmi
  2223. *
  2224. * @Return: void
  2225. */
  2226. static void wmi_wbuff_register(struct wmi_unified *wmi_handle)
  2227. {
  2228. struct wbuff_alloc_request wbuff_alloc[4];
  2229. wbuff_alloc[0].slot = WBUFF_POOL_0;
  2230. wbuff_alloc[0].size = WMI_WBUFF_POOL_0_SIZE;
  2231. wbuff_alloc[1].slot = WBUFF_POOL_1;
  2232. wbuff_alloc[1].size = WMI_WBUFF_POOL_1_SIZE;
  2233. wbuff_alloc[2].slot = WBUFF_POOL_2;
  2234. wbuff_alloc[2].size = WMI_WBUFF_POOL_2_SIZE;
  2235. wbuff_alloc[3].slot = WBUFF_POOL_3;
  2236. wbuff_alloc[3].size = WMI_WBUFF_POOL_3_SIZE;
  2237. wmi_handle->wbuff_handle = wbuff_module_register(wbuff_alloc, 4,
  2238. WMI_MIN_HEAD_ROOM, 4);
  2239. }
  2240. /**
  2241. * wmi_wbuff_deregister() - deregister wmi with wbuff
  2242. * @wmi_handle: handle to wmi
  2243. *
  2244. * @Return: void
  2245. */
  2246. static inline void wmi_wbuff_deregister(struct wmi_unified *wmi_handle)
  2247. {
  2248. wbuff_module_deregister(wmi_handle->wbuff_handle);
  2249. wmi_handle->wbuff_handle = NULL;
  2250. }
  2251. /**
  2252. * wmi_unified_attach() - attach for unified WMI
  2253. * @scn_handle: handle to SCN
  2254. * @osdev: OS device context
  2255. * @target_type: TLV or not-TLV based target
  2256. * @use_cookie: cookie based allocation enabled/disabled
  2257. * @ops: umac rx callbacks
  2258. * @psoc: objmgr psoc
  2259. *
  2260. * @Return: wmi handle.
  2261. */
  2262. void *wmi_unified_attach(void *scn_handle,
  2263. struct wmi_unified_attach_params *param)
  2264. {
  2265. struct wmi_unified *wmi_handle;
  2266. struct wmi_soc *soc;
  2267. soc = (struct wmi_soc *) qdf_mem_malloc(sizeof(struct wmi_soc));
  2268. if (soc == NULL) {
  2269. WMI_LOGE("Allocation of wmi_soc failed %zu",
  2270. sizeof(struct wmi_soc));
  2271. return NULL;
  2272. }
  2273. wmi_handle =
  2274. (struct wmi_unified *) qdf_mem_malloc(
  2275. sizeof(struct wmi_unified));
  2276. if (wmi_handle == NULL) {
  2277. qdf_mem_free(soc);
  2278. WMI_LOGE("allocation of wmi handle failed %zu",
  2279. sizeof(struct wmi_unified));
  2280. return NULL;
  2281. }
  2282. wmi_handle->soc = soc;
  2283. wmi_handle->soc->soc_idx = param->soc_id;
  2284. wmi_handle->soc->is_async_ep = param->is_async_ep;
  2285. wmi_handle->event_id = soc->event_id;
  2286. wmi_handle->event_handler = soc->event_handler;
  2287. wmi_handle->ctx = soc->ctx;
  2288. wmi_handle->wmi_events = soc->wmi_events;
  2289. wmi_target_params_init(soc, wmi_handle);
  2290. wmi_handle->scn_handle = scn_handle;
  2291. soc->scn_handle = scn_handle;
  2292. qdf_atomic_init(&wmi_handle->pending_cmds);
  2293. qdf_atomic_init(&wmi_handle->is_target_suspended);
  2294. wmi_runtime_pm_init(wmi_handle);
  2295. qdf_spinlock_create(&wmi_handle->eventq_lock);
  2296. qdf_nbuf_queue_init(&wmi_handle->event_queue);
  2297. qdf_create_work(0, &wmi_handle->rx_event_work,
  2298. wmi_rx_event_work, wmi_handle);
  2299. wmi_handle->wmi_rx_work_queue =
  2300. qdf_alloc_unbound_workqueue("wmi_rx_event_work_queue");
  2301. if (NULL == wmi_handle->wmi_rx_work_queue) {
  2302. WMI_LOGE("failed to create wmi_rx_event_work_queue");
  2303. goto error;
  2304. }
  2305. wmi_interface_logging_init(wmi_handle, WMI_HOST_PDEV_ID_0);
  2306. /* Attach mc_thread context processing function */
  2307. wmi_handle->rx_ops.wma_process_fw_event_handler_cbk =
  2308. param->rx_ops->wma_process_fw_event_handler_cbk;
  2309. wmi_handle->target_type = param->target_type;
  2310. soc->target_type = param->target_type;
  2311. if (param->target_type >= WMI_MAX_TARGET_TYPE)
  2312. goto error;
  2313. if (wmi_attach_register[param->target_type]) {
  2314. wmi_attach_register[param->target_type](wmi_handle);
  2315. } else {
  2316. WMI_LOGE("wmi attach is not registered");
  2317. goto error;
  2318. }
  2319. /* Assign target cookie capablity */
  2320. wmi_handle->use_cookie = param->use_cookie;
  2321. wmi_handle->osdev = param->osdev;
  2322. wmi_handle->wmi_stopinprogress = 0;
  2323. wmi_handle->wmi_max_cmds = param->max_commands;
  2324. soc->wmi_max_cmds = param->max_commands;
  2325. /* Increase the ref count once refcount infra is present */
  2326. soc->wmi_psoc = param->psoc;
  2327. qdf_spinlock_create(&soc->ctx_lock);
  2328. soc->ops = wmi_handle->ops;
  2329. soc->wmi_pdev[0] = wmi_handle;
  2330. if (wmi_ext_dbgfs_init(wmi_handle) != QDF_STATUS_SUCCESS)
  2331. WMI_LOGE("failed to initialize wmi extended debugfs");
  2332. wmi_wbuff_register(wmi_handle);
  2333. return wmi_handle;
  2334. error:
  2335. qdf_mem_free(soc);
  2336. qdf_mem_free(wmi_handle);
  2337. return NULL;
  2338. }
  2339. /**
  2340. * wmi_unified_detach() - detach for unified WMI
  2341. *
  2342. * @wmi_handle : handle to wmi.
  2343. *
  2344. * @Return: none.
  2345. */
  2346. void wmi_unified_detach(struct wmi_unified *wmi_handle)
  2347. {
  2348. wmi_buf_t buf;
  2349. struct wmi_soc *soc;
  2350. uint8_t i;
  2351. wmi_wbuff_deregister(wmi_handle);
  2352. wmi_ext_dbgfs_deinit(wmi_handle);
  2353. soc = wmi_handle->soc;
  2354. for (i = 0; i < WMI_MAX_RADIOS; i++) {
  2355. if (soc->wmi_pdev[i]) {
  2356. qdf_flush_workqueue(0,
  2357. soc->wmi_pdev[i]->wmi_rx_work_queue);
  2358. qdf_destroy_workqueue(0,
  2359. soc->wmi_pdev[i]->wmi_rx_work_queue);
  2360. wmi_debugfs_remove(soc->wmi_pdev[i]);
  2361. buf = qdf_nbuf_queue_remove(
  2362. &soc->wmi_pdev[i]->event_queue);
  2363. while (buf) {
  2364. qdf_nbuf_free(buf);
  2365. buf = qdf_nbuf_queue_remove(
  2366. &soc->wmi_pdev[i]->event_queue);
  2367. }
  2368. wmi_log_buffer_free(soc->wmi_pdev[i]);
  2369. /* Free events logs list */
  2370. if (soc->wmi_pdev[i]->events_logs_list)
  2371. qdf_mem_free(
  2372. soc->wmi_pdev[i]->events_logs_list);
  2373. qdf_spinlock_destroy(&soc->wmi_pdev[i]->eventq_lock);
  2374. qdf_mem_free(soc->wmi_pdev[i]);
  2375. }
  2376. }
  2377. qdf_spinlock_destroy(&soc->ctx_lock);
  2378. if (soc->wmi_service_bitmap) {
  2379. qdf_mem_free(soc->wmi_service_bitmap);
  2380. soc->wmi_service_bitmap = NULL;
  2381. }
  2382. if (soc->wmi_ext_service_bitmap) {
  2383. qdf_mem_free(soc->wmi_ext_service_bitmap);
  2384. soc->wmi_ext_service_bitmap = NULL;
  2385. }
  2386. /* Decrease the ref count once refcount infra is present */
  2387. soc->wmi_psoc = NULL;
  2388. qdf_mem_free(soc);
  2389. }
  2390. /**
  2391. * wmi_unified_remove_work() - detach for WMI work
  2392. * @wmi_handle: handle to WMI
  2393. *
  2394. * A function that does not fully detach WMI, but just remove work
  2395. * queue items associated with it. This is used to make sure that
  2396. * before any other processing code that may destroy related contexts
  2397. * (HTC, etc), work queue processing on WMI has already been stopped.
  2398. *
  2399. * Return: None
  2400. */
  2401. void
  2402. wmi_unified_remove_work(struct wmi_unified *wmi_handle)
  2403. {
  2404. wmi_buf_t buf;
  2405. qdf_flush_workqueue(0, wmi_handle->wmi_rx_work_queue);
  2406. qdf_spin_lock_bh(&wmi_handle->eventq_lock);
  2407. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2408. while (buf) {
  2409. qdf_nbuf_free(buf);
  2410. buf = qdf_nbuf_queue_remove(&wmi_handle->event_queue);
  2411. }
  2412. qdf_spin_unlock_bh(&wmi_handle->eventq_lock);
  2413. }
  2414. /**
  2415. * wmi_htc_tx_complete() - Process htc tx completion
  2416. *
  2417. * @ctx: handle to wmi
  2418. * @htc_packet: pointer to htc packet
  2419. *
  2420. * @Return: none.
  2421. */
  2422. static void wmi_htc_tx_complete(void *ctx, HTC_PACKET *htc_pkt)
  2423. {
  2424. struct wmi_soc *soc = (struct wmi_soc *) ctx;
  2425. wmi_buf_t wmi_cmd_buf = GET_HTC_PACKET_NET_BUF_CONTEXT(htc_pkt);
  2426. u_int8_t *buf_ptr;
  2427. u_int32_t len;
  2428. struct wmi_unified *wmi_handle;
  2429. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2430. uint32_t cmd_id;
  2431. #endif
  2432. ASSERT(wmi_cmd_buf);
  2433. wmi_handle = wmi_get_pdev_ep(soc, htc_pkt->Endpoint);
  2434. if (wmi_handle == NULL) {
  2435. WMI_LOGE("%s: Unable to get wmi handle\n", __func__);
  2436. QDF_ASSERT(0);
  2437. return;
  2438. }
  2439. #ifdef WMI_INTERFACE_EVENT_LOGGING
  2440. if (wmi_handle && wmi_handle->log_info.wmi_logging_enable) {
  2441. cmd_id = WMI_GET_FIELD(qdf_nbuf_data(wmi_cmd_buf),
  2442. WMI_CMD_HDR, COMMANDID);
  2443. qdf_spin_lock_bh(&wmi_handle->log_info.wmi_record_lock);
  2444. /* Record 16 bytes of WMI cmd tx complete data
  2445. - exclude TLV and WMI headers */
  2446. if (wmi_handle->ops->is_management_record(cmd_id)) {
  2447. WMI_MGMT_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2448. qdf_nbuf_data(wmi_cmd_buf) +
  2449. wmi_handle->soc->buf_offset_command);
  2450. } else {
  2451. WMI_COMMAND_TX_CMP_RECORD(wmi_handle, cmd_id,
  2452. qdf_nbuf_data(wmi_cmd_buf) +
  2453. wmi_handle->soc->buf_offset_command);
  2454. }
  2455. qdf_spin_unlock_bh(&wmi_handle->log_info.wmi_record_lock);
  2456. }
  2457. #endif
  2458. buf_ptr = (u_int8_t *) wmi_buf_data(wmi_cmd_buf);
  2459. len = qdf_nbuf_len(wmi_cmd_buf);
  2460. qdf_mem_zero(buf_ptr, len);
  2461. wmi_buf_free(wmi_cmd_buf);
  2462. qdf_mem_free(htc_pkt);
  2463. qdf_atomic_dec(&wmi_handle->pending_cmds);
  2464. }
  2465. /**
  2466. * wmi_connect_pdev_htc_service() - WMI API to get connect to HTC service
  2467. *
  2468. * @wmi_handle: handle to WMI.
  2469. * @pdev_idx: Pdev index
  2470. *
  2471. * @Return: status.
  2472. */
  2473. static int wmi_connect_pdev_htc_service(struct wmi_soc *soc,
  2474. uint32_t pdev_idx)
  2475. {
  2476. int status;
  2477. struct htc_service_connect_resp response;
  2478. struct htc_service_connect_req connect;
  2479. OS_MEMZERO(&connect, sizeof(connect));
  2480. OS_MEMZERO(&response, sizeof(response));
  2481. /* meta data is unused for now */
  2482. connect.pMetaData = NULL;
  2483. connect.MetaDataLength = 0;
  2484. /* these fields are the same for all service endpoints */
  2485. connect.EpCallbacks.pContext = soc;
  2486. connect.EpCallbacks.EpTxCompleteMultiple =
  2487. NULL /* Control path completion ar6000_tx_complete */;
  2488. connect.EpCallbacks.EpRecv = wmi_control_rx /* Control path rx */;
  2489. connect.EpCallbacks.EpRecvRefill = NULL /* ar6000_rx_refill */;
  2490. connect.EpCallbacks.EpSendFull = NULL /* ar6000_tx_queue_full */;
  2491. connect.EpCallbacks.EpTxComplete =
  2492. wmi_htc_tx_complete /* ar6000_tx_queue_full */;
  2493. /* connect to control service */
  2494. connect.service_id = soc->svc_ids[pdev_idx];
  2495. status = htc_connect_service(soc->htc_handle, &connect,
  2496. &response);
  2497. if (status != EOK) {
  2498. WMI_LOGE
  2499. ("Failed to connect to WMI CONTROL service status:%d\n",
  2500. status);
  2501. return status;
  2502. }
  2503. if (soc->is_async_ep)
  2504. htc_set_async_ep(soc->htc_handle, response.Endpoint, true);
  2505. soc->wmi_endpoint_id[pdev_idx] = response.Endpoint;
  2506. soc->max_msg_len[pdev_idx] = response.MaxMsgLength;
  2507. return 0;
  2508. }
  2509. /**
  2510. * wmi_unified_connect_htc_service() - WMI API to get connect to HTC service
  2511. *
  2512. * @wmi_handle: handle to WMI.
  2513. *
  2514. * @Return: status.
  2515. */
  2516. QDF_STATUS
  2517. wmi_unified_connect_htc_service(struct wmi_unified *wmi_handle,
  2518. void *htc_handle)
  2519. {
  2520. uint32_t i;
  2521. uint8_t wmi_ep_count;
  2522. wmi_handle->soc->htc_handle = htc_handle;
  2523. wmi_ep_count = htc_get_wmi_endpoint_count(htc_handle);
  2524. if (wmi_ep_count > WMI_MAX_RADIOS)
  2525. return QDF_STATUS_E_FAULT;
  2526. for (i = 0; i < wmi_ep_count; i++)
  2527. wmi_connect_pdev_htc_service(wmi_handle->soc, i);
  2528. wmi_handle->htc_handle = htc_handle;
  2529. wmi_handle->wmi_endpoint_id = wmi_handle->soc->wmi_endpoint_id[0];
  2530. wmi_handle->max_msg_len = wmi_handle->soc->max_msg_len[0];
  2531. return QDF_STATUS_SUCCESS;
  2532. }
  2533. /**
  2534. * wmi_get_host_credits() - WMI API to get updated host_credits
  2535. *
  2536. * @wmi_handle: handle to WMI.
  2537. *
  2538. * @Return: updated host_credits.
  2539. */
  2540. int wmi_get_host_credits(wmi_unified_t wmi_handle)
  2541. {
  2542. int host_credits = 0;
  2543. htc_get_control_endpoint_tx_host_credits(wmi_handle->htc_handle,
  2544. &host_credits);
  2545. return host_credits;
  2546. }
  2547. /**
  2548. * wmi_get_pending_cmds() - WMI API to get WMI Pending Commands in the HTC
  2549. * queue
  2550. *
  2551. * @wmi_handle: handle to WMI.
  2552. *
  2553. * @Return: Pending Commands in the HTC queue.
  2554. */
  2555. int wmi_get_pending_cmds(wmi_unified_t wmi_handle)
  2556. {
  2557. return qdf_atomic_read(&wmi_handle->pending_cmds);
  2558. }
  2559. /**
  2560. * wmi_set_target_suspend() - WMI API to set target suspend state
  2561. *
  2562. * @wmi_handle: handle to WMI.
  2563. * @val: suspend state boolean.
  2564. *
  2565. * @Return: none.
  2566. */
  2567. void wmi_set_target_suspend(wmi_unified_t wmi_handle, A_BOOL val)
  2568. {
  2569. qdf_atomic_set(&wmi_handle->is_target_suspended, val);
  2570. }
  2571. /**
  2572. * WMI API to set crash injection state
  2573. * @param wmi_handle: handle to WMI.
  2574. * @param val: crash injection state boolean.
  2575. */
  2576. void wmi_tag_crash_inject(wmi_unified_t wmi_handle, A_BOOL flag)
  2577. {
  2578. wmi_handle->tag_crash_inject = flag;
  2579. }
  2580. /**
  2581. * WMI API to set bus suspend state
  2582. * @param wmi_handle: handle to WMI.
  2583. * @param val: suspend state boolean.
  2584. */
  2585. void wmi_set_is_wow_bus_suspended(wmi_unified_t wmi_handle, A_BOOL val)
  2586. {
  2587. qdf_atomic_set(&wmi_handle->is_wow_bus_suspended, val);
  2588. }
  2589. void wmi_set_tgt_assert(wmi_unified_t wmi_handle, bool val)
  2590. {
  2591. wmi_handle->tgt_force_assert_enable = val;
  2592. }
  2593. /**
  2594. * wmi_stop() - generic function to block unified WMI command
  2595. * @wmi_handle: handle to WMI.
  2596. *
  2597. * @Return: success always.
  2598. */
  2599. int
  2600. wmi_stop(wmi_unified_t wmi_handle)
  2601. {
  2602. QDF_TRACE(QDF_MODULE_ID_WMI, QDF_TRACE_LEVEL_INFO,
  2603. "WMI Stop");
  2604. wmi_handle->wmi_stopinprogress = 1;
  2605. return 0;
  2606. }
  2607. #ifndef CONFIG_MCL
  2608. /**
  2609. * API to flush all the previous packets associated with the wmi endpoint
  2610. *
  2611. * @param wmi_handle : handle to WMI.
  2612. */
  2613. void
  2614. wmi_flush_endpoint(wmi_unified_t wmi_handle)
  2615. {
  2616. htc_flush_endpoint(wmi_handle->htc_handle,
  2617. wmi_handle->wmi_endpoint_id, 0);
  2618. }
  2619. qdf_export_symbol(wmi_flush_endpoint);
  2620. /**
  2621. * wmi_pdev_id_conversion_enable() - API to enable pdev_id conversion in WMI
  2622. * By default pdev_id conversion is not done in WMI.
  2623. * This API can be used enable conversion in WMI.
  2624. * @param wmi_handle : handle to WMI
  2625. * Return none
  2626. */
  2627. void wmi_pdev_id_conversion_enable(wmi_unified_t wmi_handle)
  2628. {
  2629. if (wmi_handle->target_type == WMI_TLV_TARGET)
  2630. wmi_handle->ops->wmi_pdev_id_conversion_enable(wmi_handle);
  2631. }
  2632. #endif