wmi_unified.c 82 KB

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