wmi_unified.c 85 KB

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